Update of /cvsroot/php-blog/additional_plugins/serendipity_plugin_popularentries
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21524/serendipity_plugin_popularentries
Added Files:
serendipity_plugin_popularentries.php
Log Message:
This plugin lists a n number of entries(user-configurable) most popular entries calculated according to the entries most commented on. The list shows as a sidebar plugin with the titles of the entries and the number of comments each entry has received. Also, the user can choose to show only the most popular entries in a particular category or only to show those which do not appear on the front-page of the blog.
--- NEW FILE: serendipity_plugin_popularentries.php ---
<?php
switch ($serendipity['lang']) {
case 'en':
case 'es':
default:
@define('PLUGIN_POPULARENTRIES_TITLE', 'Popular Entries');
@define('PLUGIN_POPULARENTRIES_BLAHBLAH', 'Shows the titles and number of comments of the most popular entries calculated according to the
entries most commented on.');
@define('PLUGIN_POPULARENTRIES_NUMBER', 'Number of entries');
@define('PLUGIN_POPULARENTRIES_NUMBER_BLAHBLAH', 'How many entries should be displayed? (Default: 10)');
@define('PLUGIN_POPULARENTRIES_NUMBER_FROM', 'Skip front page entries');
@define('PLUGIN_POPULARENTRIES_NUMBER_FROM_DESC', 'Only recent entries that are not on the front page will be shown. (Default: latest ' .
$serendipity['fetchLimit'] . ' will be skipped)');
@define('PLUGIN_POPULARENTRIES_NUMBER_FROM_RADIO_ALL', 'Show all');
@define('PLUGIN_POPULARENTRIES_NUMBER_FROM_RADIO_POPULAR', 'Skip front page items');
break;
}
class serendipity_plugin_POPULARENTRIES extends serendipity_plugin {
var $title = PLUGIN_POPULARENTRIES_TITLE;
function introspect(&$propbag) {
$this->title = $this->get_config('title', $this->title);
$propbag->add('name', PLUGIN_POPULARENTRIES_TITLE);
$propbag->add('description', PLUGIN_POPULARENTRIES_BLAHBLAH);
$propbag->add('stackable', true);
$propbag->add('author', 'Kaustubh Srikanth');
$propbag->add('version', '1.0');
$propbag->add('configuration', array('title', 'number', 'number_from', 'category'));
}
function introspect_config_item($name, &$propbag) {
switch($name) {
case 'title':
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', TITLE_FOR_NUGGET);
$propbag->add('default', PLUGIN_POPULARENTRIES_TITLE);
break;
case 'number':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_POPULARENTRIES_NUMBER);
$propbag->add('description', PLUGIN_POPULARENTRIES_NUMBER_BLAHBLAH);
$propbag->add('default', 10);
break;
case 'number_from':
$propbag->add('type', 'radio');
$propbag->add('name', PLUGIN_POPULARENTRIES_NUMBER_FROM);
$propbag->add('description', PLUGIN_POPULARENTRIES_NUMBER_FROM_DESC);
$propbag->add('radio', array(
'value' => array('all', 'skip'),
'desc' => array(PLUGIN_POPULARENTRIES_NUMBER_FROM_RADIO_ALL, PLUGIN_POPULARENTRIES_NUMBER_FROM_RADIO_POPULAR)
));
$propbag->add('default', 'all');
break;
case 'category':
$cats = serendipity_fetchCategories($serendipity['authorid']);
if (!is_array($cats)) {
return false;
}
$catlist = serendipity_generateCategoryList($cats, array(0), 4);
$tmp_select_cats = explode('@@@', $catlist);
if (!is_array($tmp_select_cats)) {
return false;
}
$select_cats = array();
$select_cats['none'] = ALL_CATEGORIES;
foreach($tmp_select_cats as $cidx => $tmp_select_cat) {
$select_cat = explode('|||', $tmp_select_cat);
if (!empty($select_cat[0]) && !empty($select_cat[1])) {
$select_cats[$select_cat[0]] = $select_cat[1];
}
}
$propbag->add('type', 'select');
$propbag->add('select_values', $select_cats);
$propbag->add('name', CATEGORY);
$propbag->add('description', CATEGORIES_TO_FETCH);
$propbag->add('default', 'none');
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$number = $this->get_config('number');
$category = $this->get_config('category', 'none');
$title = $this->get_config('title', $this->title);
$number_from_sw = $this->get_config('number_from');
$sql_join = '';
$sql_where = '';
if ($category != 'none' && is_numeric($category)) {
$sql_join = 'LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'entrycat AS ec ON id = ec.entryid
LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'category AS c ON ec.categoryid = c.categoryid';
$sql_where = ' AND (c.category_left BETWEEN ' . implode(' AND ', serendipity_fetchCategoryRange($category)) . ')';
}
if (!$number || !is_numeric($number) || $number < 1) {
$number = 10;
}
$sql_number = $number;
switch($number_from_sw) {
case 'skip':
$sql_number = serendipity_db_limit_sql(serendipity_db_limit($serendipity['fetchLimit'], $sql_number));
break;
}
$entries_query = "SELECT id,
title,
comments
FROM {$serendipity['dbPrefix']}entries
$sql_join
WHERE isdraft = 'false' AND timestamp <= " . time() . "
$sql_where
ORDER BY comments DESC
LIMIT $sql_number";
$entries = serendipity_db_query($entries_query);
if (isset($entries) && is_array($entries)) {
foreach ($entries as $k => $entry) {
$entryLink = serendipity_archiveURL(
$entry['id'],
$entry['title'],
'serendipityHTTPPath'
);
echo '<a href="' . $entryLink . '" title="' . htmlspecialchars($entry['title']) . '">' . $entry['title'] . '</a><br />';
echo '<div class="serendipitySideBarDate">'. htmlspecialchars($entry['comments']) . ' comments</div>';
}
}
}
}
?>
|