Source Code For most_popular.php
Turn Line Numbers On
<?php
/*
Plugin Name: Most Popular posts
Version: 0.12
Plugin URI: http://jfoucher.info
Description: Displays a list of the most viewed plugins.
Author: Jonathan Foucher
Author URI: http://jfoucher.info/2004/10/04/teaser-style-wordpress-plugin/
This plugin supports Automatic Update : http://wiki.wordpress.org/AutomaticUpdate
Update: http://jfoucher.info/plugin-update.php?p=40
Copyright (c) 2004
Released under the GPL license
http://www.gnu.org/licenses/gpl.txt
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/************************************
** TO TAKE ADVANTAGE OF UPDATE **
** DETECTION, PLEASE CONSIDER **
** MAKING THE FOLLOWING ADDITION **
** TO YOUR WORDPRESS INSTALL **
** **
*************************************
OPEN FOR EDITING : wp-admin/plugins.php
FIND
if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
$version = $version1?;
else
$version ='';
ADD THE FOLLOWING CODE AFTERWARDS
// BEGIN PLUGIN UPDATE ADD-ON
if ( preg_match("|Update:(.*)|i", $plugin_data, $update) )
{
$update = $update[1];
$update = trim($update);
if ($u = @file("$update")) {
$u = implode('',$u);
$u = trim($u);
$v = trim($version);
if($u != $v){
$updatelink = '<a href="';
$updatelink .= $plugin_uri[1];
$updatelink .= '">';
$updatelink .= '<em><strong>Update Available:</strong> (';
$updatelink .= $u;
$updatelink .= ')</em></a>';
$description[1] .= '<br />';
$description[1] .= $updatelink;
}
else
{
$updatelink = '';
}
}
else{
$updatelink = '';
}
}
else
{ $update ='';}
//END PLUGIN UPDATE ADD-ON
*/
function popular($format='<li><a href="%u" title="%t">%t (%v views)</a></li>',$limit=5){
global $wpdb, $tablestattraq, $tableposts;
$url=$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
$permalinks=get_settings('permalink_structure');
if (ereg("%postname%",$permalinks)) {
$sqlQuery = "SELECT COUNT(*) AS cnt, article_id, url FROM $tablestattraq WHERE user_agent_type=0 AND article_id!='feed' AND url LIKE '%name=%' GROUP BY url ORDER BY cnt DESC LIMIT 0,$limit";
$use_name=true;
}else{
$use_name=false;
$sqlQuery = "SELECT COUNT(*) AS cnt, article_id, url FROM $tablestattraq WHERE user_agent_type=0 AND article_id!='feed' AND article_id!=0 GROUP BY article_id ORDER BY cnt DESC LIMIT 0,$limit";
}
$output = $wpdb->get_results($sqlQuery);
foreach($output as $data){
if($use_name){
eregi("name=([^&]*)",$data->url,$reg);
$art_title=$reg[1];
$article= $wpdb->get_row("SELECT * FROM $tableposts WHERE post_name='$art_title'");
$art_id=$article->ID;
}else{
$art_id=$data->article_id;
$article= $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$art_id'");
}
$the_url=get_permalink($art_id);
$the_title=$article->post_title;
$the_title = apply_filters('the_title', $the_title);
$the_count=$data->cnt;
$patterns = array("/%u/", "/%t/", "/%v/");
$replacements = array($the_url, $the_title, $the_count);
echo preg_replace($patterns, $replacements, $format);
}
return;
}
?>