Source Code For most_popular.php

Turn Line Numbers Off
  1. <?php
  2. /*
  3. Plugin Name: Most Popular posts
  4. Version: 0.12
  5. Plugin URI: http://jfoucher.info
  6. Description: Displays a list of the most viewed plugins.
  7. Author: Jonathan Foucher
  8. Author URI: http://jfoucher.info/2004/10/04/teaser-style-wordpress-plugin/
  9. This plugin supports Automatic Update : http://wiki.wordpress.org/AutomaticUpdate
  10. Update: http://jfoucher.info/plugin-update.php?p=40
  11. Copyright (c) 2004
  12. Released under the GPL license
  13. http://www.gnu.org/licenses/gpl.txt
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21. */
  22. /************************************
  23. ** TO TAKE ADVANTAGE OF UPDATE **
  24. ** DETECTION, PLEASE CONSIDER **
  25.  ** MAKING THE FOLLOWING ADDITION **
  26.   ** TO YOUR WORDPRESS INSTALL **
  27.   ** **
  28.    *************************************
  29.     OPEN FOR EDITING : wp-admin/plugins.php
  30.     FIND
  31.             if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
  32.                     $version = $version1?;
  33.                 else
  34.                     $version ='';
  35.     ADD THE FOLLOWING CODE AFTERWARDS
  36.                 // BEGIN PLUGIN UPDATE ADD-ON
  37.     if ( preg_match("|Update:(.*)|i", $plugin_data, $update) )
  38.     {
  39.       $update = $update[1];
  40.       $update = trim($update);
  41.         if ($u = @file("$update")) {
  42.           $u = implode('',$u);
  43.           $u = trim($u);
  44.           $v = trim($version);
  45.           if($u != $v){
  46.             $updatelink = '<a href="';
  47.             $updatelink .= $plugin_uri[1];
  48.             $updatelink .= '">';
  49.             $updatelink .= '<em><strong>Update Available:</strong> (';
  50.             $updatelink .= $u;
  51.             $updatelink .= ')</em></a>';
  52.             $description[1] .= '<br />';
  53.             $description[1] .= $updatelink;
  54.                       }
  55.           else
  56.           {
  57.           $updatelink = '';
  58.           }
  59.         
  60.         }
  61.         else{
  62.           $updatelink = '';
  63.         }
  64.     }
  65.     else
  66.     {  $update ='';}
  67.     //END PLUGIN UPDATE ADD-ON
  68. */
  69. function popular($format='<li><a href="%u" title="%t">%t (%v views)</a></li>',$limit=5){
  70.     global $wpdb$tablestattraq$tableposts;
  71.     $url=$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
  72.     $permalinks=get_settings('permalink_structure');
  73.     if (ereg("%postname%",$permalinks)) {
  74.     $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";
  75.     $use_name=true;
  76.     }else{
  77.     $use_name=false;
  78.     $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";
  79. }    
  80.     $output $wpdb->get_results($sqlQuery);
  81.     foreach($output as $data){
  82.     
  83.         if($use_name){
  84.         eregi("name=([^&]*)",$data->url,$reg);
  85.         $art_title=$reg[1];
  86.         $article$wpdb->get_row("SELECT * FROM $tableposts WHERE post_name='$art_title'");
  87.         $art_id=$article->ID;
  88.         }else{
  89.         $art_id=$data->article_id;
  90.         $article$wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$art_id'");
  91.         }
  92.         
  93.         $the_url=get_permalink($art_id);
  94.         $the_title=$article->post_title;
  95.         $the_title apply_filters('the_title'$the_title);
  96.         
  97.         $the_count=$data->cnt;
  98.         $patterns = array("/%u/""/%t/""/%v/");
  99.         $replacements = array($the_url$the_title$the_count);
  100.         echo preg_replace($patterns$replacements$format);
  101.     }
  102.     return;
  103. }
  104. ?>