As I planned, I wrote a plugin to monitor Google PageRank for arbitrary URLs.
You can display the PageRanks for a configurable number of pages. It's also possible to display the PR of the current page. You can see how it looks in the right column.
As for my MBM5 plugin, the main piece of code is quite simple. Function generate_content() displays the PageRank for the URLs in a list. The styling is done in the CSS.
function generate_content(&$title)
{
$title = $this->title;
// PR for the current page
if ($this->get_config('this_page') == 'yes') {
$page = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
print '<li>' . PLUGIN_PAGERANK_THIS_PAGE_CAPTION .
': ';
print '<span class="PageRank">' .
$this->
getrank($page) .
'</span></li>';
}
// Warning: loop starts at 1
for ($i = 1, $n = $this->get_config('page_count'); $i <= $n; ++$i) {
$caption = $this->get_config('capt' . $i);
$page = $this->get_config('page' . $i);
print '<li>' .
$caption .
': ';
print '<span class="PageRank">' .
$this->
getrank($page) .
'</span></li>';
}
}
Line 10 checks whether the PR for the current page is required (a radio button with values yes and no). If it is, we grab the page URL from $_SERVER and compute the PR with function getrank().
Lines 17-22 loop through the URLs. There is no provision for a variable number of configuration properties in Serendipity, so we use the same trick as in the MBM5 plugin, indexing properties. Here we use 'page1', 'page2'... for the URLs, and 'capt1', 'capt2'... for the captions.
Of course, we can't use the static declaration of properties anymore. We do it with a loop:
$properties =
array('page_count',
'this_page');
// Warning: loop starts at 1
for ($i = 1, $n = $this->get_config('page_count'); $i <= $n; ++$i) {
$properties[] = 'page' . $i;
$properties[] = 'capt' . $i;
}
$propbag->add('configuration', $properties);
and the code of the corresponding introspect_config_item() function:
if ($name == 'page_count') {
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_PAGERANK_PAGE_COUNT);
$propbag->add('description', PLUGIN_PAGERANK_PAGE_COUNT_DESC);
$propbag->add('default', '1');
} else if ($name == 'this_page') {
$propbag->add('type', 'radio');
$propbag->add('name', PLUGIN_PAGERANK_THIS_PAGE);
$propbag->add('description', PLUGIN_PAGERANK_THIS_PAGE_DESC);
$propbag->
add('radio',
array( 'value' =>
array('yes',
'no'),
'desc' =>
array(PLUGIN_PAGERANK_THIS_PAGE_YES, PLUGIN_PAGERANK_THIS_PAGE_NO
)));
$propbag->add('default', 'yes');
} else if (substr($name,
0,
4) ==
'page') { $propbag->add('type', 'string');
$propbag->
add('name',
sprintf(PLUGIN_PAGERANK_PAGE_URL,
$index));
$propbag->
add('description',
sprintf(PLUGIN_PAGERANK_PAGE_URL_DESC,
$index));
$propbag->add('default', 'http://' . $_SERVER['SERVER_NAME'] . '/');
} else if (substr($name,
0,
4) ==
'capt') { $propbag->add('type', 'string');
$propbag->
add('name',
sprintf(PLUGIN_PAGERANK_PAGE_CAPTION,
$index));
$propbag->add('default', 'Page d\'accueil');
} else {
return false;
}
The first two cases are usual, but we can't use a switch here, as we need to accomodate our “indexed” properties (lines 14 and 20).
The algorithm for the PR request was written by Alex Stapleton, Andy Doctorow, Tarakan,
Bill Zeller, Vijay "Cyberax" Bhatter, traB. It's available all over the web.
Check new version.