Hey,
stworzyłem plugin, który szuka w Postach użytkowników nie działające linki.
Mam problem ponieważ u mnie loklanie dla 6 Postów, ładnie znajduje nie działające linki.
Nie stety podesłałem go do klienta i okazało się że dla 500 postów plugin coś zamula wogule nie wyświetla wyniku, nie jestem pewien czy to problem z większą ilości danych czy może coś innego.
Podaje link do Plugina:
http://szymoon.nazwa.pl/plugins/BrokenLinksChecker.zipOraz tutaj kod:
if ( is_admin() ) {
add_action('admin_menu', 'broken_links_checker_options');
function broken_links_checker_options() {
add_options_page('Broken-links-checker-options', 'Broken-links-checker', 'manage_options', 'broken_links_checker', 'broken_links_options');
}
}
?>
<?php
function check_url($nodes) {
$master = curl_multi_init();
for($i = 0
, $count=count($nodes); $i < $count; $i++) {
$url = $nodes[$i];
$curl_arr[$i] = curl_init();
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_arr[$i], CURLOPT_URL, $nodes[$i] );
curl_setopt($curl_arr[$i], CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl_arr[$i], CURLOPT_NOBODY, true);
curl_setopt($curl_arr[$i], CURLOPT_HEADER, true);
curl_multi_add_handle($master, $curl_arr[$i]);
}
do {
curl_multi_exec($master,$running);
} while($running > 0);
for($i = 0; $i < $count; $i++)
{
$results = curl_multi_getcontent ( $curl_arr[$i] );
//var_dump();
if($results == null) {
$szymon[] = '0 ';
} else {
$replace = substr($results, 0
, 13
); $szymon[]= $text = str_replace('HTTP/1.1', '', $replace); }
}
return $szymon;
}
?>
<?php function broken_links_options() {
$pass = $_GET['url'];
?>
<a href="<?php bloginfo('wpurl');?>/wp-admin/options-general.php?page=broken_links_checker&url=find" class="button-primary" style="margin:10px 0 0 0;float:left;">Check Links</a>
<?php
<?php if($pass == 'find') : ?>
<?php $myrows = $wpdb->get_results( "SELECT * FROM wp_posts where post_status = 'publish'" );?>
<table style="float:left;clear:both;">
<tr>
<th>Title post</th>
<th>URL in post</th>
<th>Link too edit</th>
<th>Status</th>
</tr>
<?php
$good = 0;
$bad = 0;
?>
<?php foreach($myrows as $a):?>
<?php $qwe = $a->post_content ?>
<?php preg_match_all("/<a.*?href\s*=\s*['\"](.*?)['\"]/", $qwe, $res, PREG_SET_ORDER
);?> <?php
foreach($res as $key => $val):?>
<?php
$nodes[links][] = $val[1];
$nodes[title][] = $a->post_title;
$nodes[id][] = $a->ID;
?>
<?php endforeach ?>
<?php endforeach ?>
<?php foreach (check_url($nodes[links]) as $h): ?>
<?php $nodes[status][] = $h;?>
<?php endforeach ?>
<?php for($i=0; $i < count($nodes['status']); $i++) : ?> <tr>
<?php $good++;?>
<?php if(trim($nodes['status'][$i]) != 200) : ?> <?php $bad++?>
<td>
<?php
echo $nodes['title'][$i]; ?>
</td>
<td>
<?php
echo $nodes['links'][$i]; ?>
</td>
<td>
<a href="
<?php bloginfo
('wpurl');?>/wp-admin/post.php?post=
<?php echo $nodes['id'][$i]; ?>&action=edit" target="_blank" >Edit Post</a>
</td>
<td>
<?php echo $nodes['status'][$i]; ?> </td>
<?php endif ?>
</tr>
<?php endfor ?>
</table>
<br />
<p style="float:left;clear:both;">Good links
<?php echo $good-$bad ?></p>
<p style="float:left;clear:both;">Bad links
<?php echo $bad;?></p>
<?php endif ?>
<?php } ?>