Plugin Directory

Changeset 370330


Ignore:
Timestamp:
04/07/2011 06:56:03 PM (14 years ago)
Author:
blueinstyle
Message:
 
Location:
top-contributors/tags/1.4.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • top-contributors/tags/1.4.1/functions.inc.php

    r369146 r370330  
    11<?php
     2/**
     3 * Refresh comment cache function, regenerates the comment list output html
     4 * This function is called every time the plugin settings are saved,
     5 * and each time a comment is posted, edited or deleted from WP Admin area.
     6 */
    27function jmetc_refresh_comment_cache() {
    38    global $wpdb;
    49   
     10    /**
     11     * Get Top contributor 'commenter' options, and Star Icon options
     12     */
    513    $jmetcop['icon'] = get_option('jmetc_icon');
    614    $jmetc_options = get_option('jmetc_commenters');
    715   
    8     /* 
    9         set star icon name and count lists as arrays
    10         need these redefined for users that was using version 1.4
     16    /**
     17     * Set Star Icon name and count lists as arrays
     18     * Need to redefine these as arrays for users that are upgrading from version 1.4
    1119    */
    1220    $jmetc_options['toplist']['name'] = array();
    1321    $jmetc_options['toplist']['post_count'] = array();
    14            
     22
     23    /**
     24     * Start the html template code cache
     25     * $jmevar['cache'] is variable used to store final html output.
     26     */
    1527    $jmevar['cache'] = '<div class="top-contributors">'."\n";
    1628   
    17     /* if include/exclude categories, do advanced query */
     29   
     30    /**
     31     * If include/exclude categories is enabled in options, do a category sql query.
     32     * Need to do a separate sql query that checks category tables.
     33     */
    1834    if($jmetc_options['show_category'] == 1) {
    1935       
    20         /* create category list id */
     36        /**
     37         * Create comma'd category id list to do query search with
     38         */
    2139        $jmevar['catarray'] = implode(",",$jmetc_options['category_list']);
    2240       
    23         /* create category inc/exc sql */
     41        /**
     42         * Create the category id include/exclude sql depending on which option is selected
     43         */
    2444        if($jmetc_options['cat_inc_exc'] == 0)
    2545            $jmevar['catsql'] = "AND t.term_id IN ($jmevar[catarray])";
     
    2848       
    2949       
    30         /* additional query changes */
     50        /**
     51         * Do additional query modifications, author exclude, time interval and group by options.
     52         */
    3153        $jmevar['authorsql'] = jme_get_author_exclude(3,$jmetc_options['exclude_author']);
    3254        $jmevar['timeInterval'] = jme_get_time_interval(3,$jmetc_options);     
    3355        $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'c.comment_author_email' : 'c.comment_author';
    3456       
    35         /* create sql query */
     57        /**
     58         * Create the sql query
     59         */
    3660        $query = "SELECT   
    3761                        COUNT(c.comment_ID) AS `comment_count`,
     
    5478                ";
    5579    } else {
    56         /* else if no include/exclude categories, do basic query */
    57    
     80        /**
     81         * (else) If there is no category includes/excludes, do standard query
     82         */
     83         
     84               
     85        /**
     86         * Do additional query modifications, author exclude, time interval and group by options
     87         * for normal query without category check.
     88         */
    5889        $jmevar['authorsql'] = jme_get_author_exclude(2,$jmetc_options['exclude_author']);
    5990        $jmevar['timeInterval'] = jme_get_time_interval(2,$jmetc_options);
    6091        $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'comment_author_email' : 'comment_author';
    6192       
     93        /**
     94         * Create the sql query
     95         */
    6296        $query = "  SELECT  COUNT(comment_ID) AS `comment_count`,
    6397                        comment_author,
     
    75109    }
    76110               
    77     /* execute query */
     111    /**
     112     * Now excute the sql query
     113     */
    78114    $gettc = $wpdb->get_results( $query );
    79115
    80     /* if valid results */
     116    /**
     117     * If we get results, we can create the html output of results
     118     */
    81119    if($gettc) {
    82120           
    83             // If format is List Style
    84             if($jmetc_options['format'] == 1) {
    85                 $jmevar['count'] = 0;
    86                
    87                 if($jmetc_options['widget_columns'] > 1) {
    88                     $jmevar['rows'] = true;
    89                     $jmevar['cache'] .= '<table cellspacing="0"><tr>';
     121        /**
     122         * If its a list style format:
     123         */
     124        if($jmetc_options['format'] == 1) {
     125            $jmevar['count'] = 0;
     126           
     127            /**
     128             * If list columns is greater than 1, we need to put the list into a table for column formatting
     129             * Define 'columns' as true (meaning more than 1 column), and start the 'cache' output with a table.
     130             */
     131            if($jmetc_options['widget_columns'] > 1) {
     132                $jmevar['columns'] = true;
     133                $jmevar['cache'] .= '<table cellspacing="0"><tr>';
     134            }
     135           
     136            /**
     137             * Create the foreach loop to output html code
     138             */
     139            foreach($gettc as $tc) {
     140               
     141                /**
     142                 * If columns are true, add td tag for table, then start the div list.
     143                 */
     144                if($jmevar['columns']) $jmevar['cache'] .= '<td>';
     145                $jmevar['cache'] .= '<div class="list">';
     146           
     147                /**
     148                 * Generate and get output of username based on if keywordluv option
     149                 * is enabled, and if user has url or not (also check the rel link option).
     150                 */
     151                $jmevar['username'] = jmetc_do_keywordluv($tc->comment_author,
     152                                                                        $tc->comment_author_url,
     153                                                                        $jmetc_options['keywordluv'],
     154                                                                        $jmetc_options['rel_links']);
     155           
     156                /**
     157                 * If show avatar option is checked, add get_avatar function to cache.
     158                 */
     159                if($jmetc_options['show_avatar'] == 1) {
     160                    $jmevar['cache'] .= get_avatar($tc->comment_author_email, $jmetc_options['avatar_size']);
    90161                }
    91                
    92                 foreach($gettc as $tc) {
    93                     if($jmevar['rows']) $jmevar['cache'] .= '<td>';
    94                     $jmevar['cache'] .= '<div class="list">';
    95                
    96                     $jmevar['username'] = jmetc_do_keywordluv($tc->comment_author,$tc->comment_author_url,$jmetc_options['keywordluv'],$jmetc_options['rel_links']);
    97                
    98                     if($jmetc_options['show_avatar'] == 1) {
    99                         $jmevar['cache'] .= get_avatar($tc->comment_author_email, $jmetc_options['avatar_size']);
     162           
     163                /**
     164                 * Now put the username, defined above, in the cache.
     165                 * If show comment count enabled, included that in cache as well.
     166                 */             
     167                $jmevar['cache'] .= '<div class="tc-user">' . $jmevar['username'] . '</div>';
     168                    if($jmetc_options['show_count'] == 1) {
     169                        $jmevar['cache'] .= '<div class="tc-count">';
     170                        $jmevar['cache'] .= ($tc->comment_count == 1) ? sprintf(__("%s comment", 'jmetc'), $tc->comment_count) :
     171                            sprintf(__("%s comments", 'jmetc'), number_format($tc->comment_count));
     172                        $jmevar['cache'] .= '</div>';
    100173                    }
    101                
    102                     $jmevar['cache'] .= '<div class="tc-user">' . $jmevar['username'] . '</div>';
    103                         if($jmetc_options['show_count'] == 1) {
    104                             $jmevar['cache'] .= '<div class="tc-count">';
    105                             $jmevar['cache'] .= ($tc->comment_count == 1) ? sprintf(__("%s comment", 'jmetc'), $tc->comment_count) :
    106                                 sprintf(__("%s comments", 'jmetc'), number_format($tc->comment_count));
    107                             $jmevar['cache'] .= '</div>';
    108                         }
    109                     $jmevar['cache'] .= '<div style="clear:both;"></div></div>'."\n";
    110                     $jmevar['count']++;
    111                    
    112                     if($jmevar['rows']) {
    113                         $jmevar['cache'] .= '</td>';
    114                         if($jmevar['count'] % $jmetc_options['widget_columns'] == 0) $jmevar['cache'] .= '</tr><tr>';
     174                   
     175                /**
     176                 * Closing div tags for this output.
     177                 */
     178                $jmevar['cache'] .= '<div style="clear:both;"></div></div>'."\n";
     179                $jmevar['count']++;
     180               
     181                /**
     182                 * If 'columns' true, close the td tag, and also check if loop 'count' has reached
     183                 * the column count, and if so, end the row with </tr>, and open new <tr>
     184                 */                 
     185                if($jmevar['columns']) {
     186                    $jmevar['cache'] .= '</td>';
     187                    if($jmevar['count'] % $jmetc_options['widget_columns'] == 0) $jmevar['cache'] .= '</tr><tr>';
     188                }
     189            }
     190           
     191            /**
     192             * After looping through all users, if columns true, close the table
     193             */
     194            if($jmevar['columns']) $jmevar['cache'] .= "</tr></table>\n";
     195        }
     196        /** end of List Style output cache. */
     197       
     198        /**
     199         * If gallery format is selected
     200         */
     201        if($jmetc_options['format'] == 2) {
     202           
     203            /**
     204             * Start the gallery list loop
     205             */
     206            foreach($gettc as $tc) {
     207                /**
     208                 * Avatar is required for Gallery List, so get_avatar into variable
     209                 */
     210                $jmevar['gravatar'] = get_avatar($tc->comment_author_email, $jmetc_options['avatar_size']);
     211               
     212                /**
     213                 * Start gallery list html cache output
     214                 */
     215                $jmevar['cache'] .= '<div class="gallery">'."\n";
     216               
     217               
     218                /**
     219                 * Generate the user Tooltip data, including username, and post count
     220                 */
     221                $jmevar['tt'] = 'title="<div class=\'tc-user\'>' . $tc->comment_author . '</div>';
     222                    if($jmetc_options['show_count'] == 1) {
     223                        $jmevar['tt'] .= '<div class=\'tc-count\'>';
     224                        $jmevar['tt'] .= ($tc->comment_count == 1) ? sprintf(__("%s comment", 'jmetc'), $tc->comment_count) :
     225                            sprintf(__("%s comments", 'jmetc'), number_format($tc->comment_count));
     226                        $jmevar['tt'] .= '</div>';
    115227                    }
    116                 }
    117                 if($jmevar['rows']) $jmevar['cache'] .= "</tr></table>\n";
    118             }
    119            
    120             // If format is Gallery Style
    121             if($jmetc_options['format'] == 2) {
    122                
    123                 foreach($gettc as $tc) {
    124 
    125                     /* generate user avatar */
    126                     $gavatar = get_avatar($tc->comment_author_email, $jmetc_options['avatar_size']);
    127                    
    128                     $jmevar['cache'] .= '<div class="gallery">'."\n";
    129                    
    130                     /* generate tooltip info */
    131                     $jmevar['tt'] = 'title="<div class=\'tc-user\'>' . $tc->comment_author . '</div>';
    132                         if($jmetc_options['show_count'] == 1) {
    133                             $jmevar['tt'] .= '<div class=\'tc-count\'>';
    134                             $jmevar['tt'] .= ($tc->comment_count == 1) ? sprintf(__("%s comment", 'jmetc'), $tc->comment_count) :
    135                                 sprintf(__("%s comments", 'jmetc'), number_format($tc->comment_count));
    136                             $jmevar['tt'] .= '</div>';
    137                         }
    138                     $jmevar['tt'] .= '" ';
    139                     /* end tooltip info */ 
    140                                
    141                     /* add tooltip info to avatar */
    142                     $jmevar['cache'] .= str_replace('<img','<img '.$jmevar['tt'],$gavatar);
    143                    
    144                     $jmevar['cache'] .= "</div>\n";
    145                 }
    146                 $jmevar['cache'] .= '<div style="clear:both;"></div>';
    147             }
    148                
    149             /*
    150                 Create array of top users to add Star Icon next to in comments
    151                 This part only applied if threshold is set to 0, this puts top 10 users in the array
    152                 If threshold is not 0, a new query is created below
    153             */         
    154             if (($jmetcop['icon']['show_icon'] == 1) && ($jmetcop['icon']['comment_limit'] == '0')) {
    155                 foreach($gettc as $tc) {
    156                     $jmetc_options['toplist']['name'][] = $tc->comment_author;
    157                 }
    158             }
    159            
    160         /* if no results from query, no commeters */
     228                $jmevar['tt'] .= '" ';
     229                /** End tooltip info */
     230                           
     231                /**
     232                 * Now add the tooltip info to the Avatar image and put into cache
     233                 */
     234                $jmevar['cache'] .= str_replace('<img','<img '.$jmevar['tt'],$jmevar['gravatar']);
     235               
     236                /**
     237                 * Close the html tags
     238                 */
     239                $jmevar['cache'] .= "</div>\n";
     240            }
     241            /** Clear the Avatar image float */
     242            $jmevar['cache'] .= '<div style="clear:both;"></div>';
     243        }
     244        /** End of Gallery List loop and output cache */
     245           
     246        /**
     247         * Create array of top users to add Star Icon next to in comments
     248         * This part only applied if Top Commenter Icon option is enabled
     249         * and the comment threshold is set to 0. This puts top X users in the array
     250         * based on the results of 'top commenters' from query above.
     251        */         
     252        if (($jmetcop['icon']['show_icon'] == 1) && ($jmetcop['icon']['comment_limit'] == '0')) {
     253            foreach($gettc as $tc) {
     254                $jmetc_options['toplist']['name'][] = $tc->comment_author;
     255            }
     256        }
     257           
     258    /**
     259     * Now end of foreach loop of users
     260     * (else) If no results, output No commenters found
     261     */
     262    } else {
     263        $jmevar['cache'] .= __('No commenters found.', 'jmetc');
     264    }
     265    $jmevar['cache'] .= "</div>\n";
     266    /** End of Top Commenter output cache */
     267
     268    /**
     269        If comment threshold is not 0, we need to create a new query to get
     270        the list of users that meet or exceed the threshold.
     271        First check to make sure Top contributor Icon is enabled, and
     272        threshold limit is not set to '0'.
     273    */
     274    if($jmetcop['icon']['show_icon'] == 1 && $jmetcop['icon']['comment_limit'] != '0') {
     275       
     276        /**
     277            Find the minimum comment count needed for a star.
     278            If threshold is comma list, get the minmium comment count needed
     279            to be in the username array.
     280        */
     281        if(strpos($jmetcop['icon']['comment_limit'],",")) {
     282            $slist = explode(",",$jmetcop['icon']['comment_limit']);
     283            $starLimit = $slist[0];
    161284        } else {
    162             $jmevar['cache'] .= __('No commenters found.', 'jmetc');
    163         }
    164         $jmevar['cache'] .= "</div>\n";
    165 
    166         /*
    167             Create array of top users to add Star Icon, if threshold is not 0
    168            
     285            $starLimit = $jmetcop['icon']['comment_limit'];
     286        }
     287       
     288        /**
     289            If include/exclude categories exist, do a category query
    169290        */
    170         if($jmetcop['icon']['show_icon'] == 1 && $jmetcop['icon']['comment_limit'] != '0') {
    171             /*
    172                 Find the minimum comment count needed for star.
    173                 If threshold is array, get first value, else threshold is the minimum limit.
     291        if($jmetc_options['show_category'] == 1) {
     292   
     293            /**
     294                Create comma'd category id list to do query search with
    174295            */
    175             if(strpos($jmetcop['icon']['comment_limit'],",")) {
    176                 $slist = explode(",",$jmetcop['icon']['comment_limit']);
    177                 $starLimit = $slist[0];
    178             } else {
    179                 $starLimit = $jmetcop['icon']['comment_limit'];
    180             }
    181            
    182             /* if include/exclude categories, do advanced query */
    183             if($jmetc_options['show_category'] == 1) {
    184        
    185                 /* create category list id */
    186                 $jmevar['catarray'] = implode(",",$jmetc_options['category_list']);
    187        
    188                 /* create category inc/exc sql */
    189                 if($jmetc_options['cat_inc_exc'] == 0)
    190                     $jmevar['catsql'] = "AND t.term_id IN ($jmevar[catarray])";
    191                 else
    192                     $jmevar['catsql'] = "AND t.term_id NOT IN ($jmevar[catarray]) AND t.taxonomy = 'category'";
    193        
    194        
    195                 /* additional query changes */
    196                 $jmevar['authorsql'] = jme_get_author_exclude(3,$jmetc_options['exclude_author']);
    197                 $jmevar['timeInterval'] = jme_get_time_interval(3,$jmetc_options);     
    198                 $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'c.comment_author_email' : 'c.comment_author';
    199        
    200                 /* create sql query */
    201                 $query = "SELECT   
    202                                 COUNT(c.comment_ID) AS `comment_count`,
    203                                 c.comment_author
    204                             FROM $wpdb->comments c
    205                             LEFT JOIN $wpdb->term_relationships r
    206                             ON c.comment_post_ID = r.object_id
    207                             LEFT JOIN $wpdb->term_taxonomy t
    208                             ON r.term_taxonomy_id = t.term_taxonomy_id
    209                             WHERE c.comment_approved = 1
    210                             AND c.comment_type = ''
    211                             $jmevar[catsql]
    212                             $jmevar[authorsql]
    213                             $jmevar[timeInterval]
    214                             GROUP BY $jmevar[groupby]
    215                             HAVING `comment_count` >= '" .$starLimit . "'
     296            $jmevar['catarray'] = implode(",",$jmetc_options['category_list']);
     297   
     298            /**
     299                Create the category id include/exclude sql depending on which option is selected
     300            */
     301            if($jmetc_options['cat_inc_exc'] == 0)
     302                $jmevar['catsql'] = "AND t.term_id IN ($jmevar[catarray])";
     303            else
     304                $jmevar['catsql'] = "AND t.term_id NOT IN ($jmevar[catarray]) AND t.taxonomy = 'category'";
     305       
     306            /**
     307                Do additional query modifications, author exclude, time interval and group by options.
     308            */
     309            $jmevar['authorsql'] = jme_get_author_exclude(3,$jmetc_options['exclude_author']);
     310            $jmevar['timeInterval'] = jme_get_time_interval(3,$jmetc_options);     
     311            $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'c.comment_author_email' : 'c.comment_author';
     312   
     313            /**
     314                Create the sql query
     315            */
     316            $query = "SELECT   
     317                            COUNT(c.comment_ID) AS `comment_count`,
     318                            c.comment_author
     319                        FROM $wpdb->comments c
     320                        LEFT JOIN $wpdb->term_relationships r
     321                        ON c.comment_post_ID = r.object_id
     322                        LEFT JOIN $wpdb->term_taxonomy t
     323                        ON r.term_taxonomy_id = t.term_taxonomy_id
     324                        WHERE c.comment_approved = 1
     325                        AND c.comment_type = ''
     326                        $jmevar[catsql]
     327                        $jmevar[authorsql]
     328                        $jmevar[timeInterval]
     329                        GROUP BY $jmevar[groupby]
     330                        HAVING `comment_count` >= '" .$starLimit . "'
     331                    ";
     332        } else {               
     333            /**
     334                (else) If there is no category includes/excludes, do standard query
     335            */
     336       
     337            /**
     338                Do additional query modifications, author exclude, time interval and group by options.
     339            */     
     340            $jmevar['authorsql'] = jme_get_author_exclude(2,$jmetc_options['exclude_author']);
     341            $jmevar['timeInterval'] = jme_get_time_interval(2,$jmetc_options);
     342            $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'comment_author_email' : 'comment_author';
     343
     344            /**
     345                Create the sql query
     346            */
     347            $query = "  SELECT 
     348                            COUNT(comment_ID) AS `comment_count`,
     349                            comment_author
     350                        FROM $wpdb->comments
     351                        WHERE comment_approved = 1
     352                        AND comment_type = ''
     353                        $jmevar[authorsql]
     354                        $jmevar[timeInterval]
     355                        GROUP BY $jmevar[groupby]
     356                        HAVING `comment_count` >= '" . $starLimit . "'
    216357                        ";
    217358
    218             } else {
    219                 /* else if no category includes/excludes, do standard query */
    220                
    221                 $jmevar['authorsql'] = jme_get_author_exclude(2,$jmetc_options['exclude_author']);
    222                 $jmevar['timeInterval'] = jme_get_time_interval(2,$jmetc_options);
    223                 $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'comment_author_email' : 'comment_author';
    224 
    225        
    226                 $query = "  SELECT 
    227                                 COUNT(comment_ID) AS `comment_count`,
    228                                 comment_author
    229                             FROM $wpdb->comments
    230                             WHERE comment_approved = 1
    231                             AND comment_type = ''
    232                             $jmevar[authorsql]
    233                             $jmevar[timeInterval]
    234                             GROUP BY $jmevar[groupby]
    235                             HAVING `comment_count` >= '" . $starLimit . "'
    236                     ";
    237 
    238             }
    239            
    240             /* get result for top contributor star icons */
    241             $gettc = $wpdb->get_results( $query );
    242        
    243             if($gettc) {           
    244                 foreach($gettc as $tc) {               
    245                     $jmetc_options['toplist']['name'][] = $tc->comment_author;
    246                     $jmetc_options['toplist']['post_count'][$tc->comment_author] = $tc->comment_count;
    247                 }
    248             }
    249         }
    250 
    251         $jmetc_options['cache'] = $jmevar['cache'];
    252 
    253         update_option('jmetc_commenters', $jmetc_options);
    254 }
    255 
    256 // If listing Top Post Authors //
     359        }
     360           
     361        /**
     362            Get the sql result for list of usernames who qualify for a star
     363        */
     364        $gettc = $wpdb->get_results( $query );
     365       
     366        /**
     367         * If results, put the result into username and comment count arrays
     368         * for users who qualify for a star.
     369         */         
     370        if($gettc) {           
     371            foreach($gettc as $tc) {               
     372                $jmetc_options['toplist']['name'][] = $tc->comment_author;
     373                $jmetc_options['toplist']['post_count'][$tc->comment_author] = $tc->comment_count;
     374            }
     375        }
     376    }
     377
     378    /**
     379     * Put resulting cache into wp options table and update.
     380     */
     381    $jmetc_options['cache'] = $jmevar['cache'];
     382    update_option('jmetc_commenters', $jmetc_options);
     383       
     384/**
     385 * End of Top Commenter Cache function
     386 */
     387}
     388
     389
     390/**
     391 * Refresh author cache function, regenerates the author list output html
     392 * This function is called every time the plugin settings are saved,
     393 * and each time a new post is made, edited or deleted from WP Admin area.
     394 */
    257395function jmetc_refresh_author_cache() {
    258     global $wpdb, $jmetcop;
    259    
     396    global $wpdb;
     397   
     398    /**
     399     * Get author settings options
     400     */
    260401    $jmetc_options = get_option('jmetc_authors');
    261402
     403    /**
     404     * Start html output cache
     405     */
    262406    $jmevar['cache'] = '<div class="top-contributors">'."\n";
    263407
     408    /**
     409     * Get the author exclude list and time interval sql lines
     410     */
    264411    $jmevar['authorsql'] = jme_get_author_exclude(1,$jmetc_options['exclude_author']);
    265412    $jmevar['timeInterval'] = jme_get_time_interval(1,$jmetc_options);
    266    
    267     /* if include/exclude categories, category query */
     413
     414    /**
     415     * If top authors list has include/exclude categories, do a
     416     * category sql query
     417     */
    268418    if($jmetc_options['show_category'] == 1) {
    269419       
    270         /* create category list id */
     420        /**
     421         * Create comma'd category id list to do query search with
     422         */
    271423        $jmevar['catarray'] = implode(",",$jmetc_options['category_list']);
    272424       
    273         /* create category inc/exc sql */
     425        /**
     426         * Create the category id include/exclude sql depending on which option is selected
     427         */
    274428        if($jmetc_options['cat_inc_exc'] == 0)
    275429            $jmevar['catsql'] = "AND t.term_id IN ($jmevar[catarray])";
     
    277431            $jmevar['catsql'] = "AND t.term_id NOT IN ($jmevar[catarray]) AND t.taxonomy = 'category'";
    278432       
     433        /**
     434         * Create the sql query
     435         */
    279436        $query = "  SELECT
    280437                        COUNT(DISTINCT(a.ID)) AS `post_count`,
     
    301458
    302459    } else {
    303         /* if no category include/exclude do normal query */
     460        /**
     461         * (else) If there is no category includes/excludes, do standard query
     462         */
    304463       
    305464        $query = "  SELECT 
     
    320479                    LIMIT $jmetc_options[limit]
    321480                ";
    322     }           
    323        
    324         $gettc = $wpdb->get_results( $query );
    325 
    326         if($gettc) {
    327        
    328             if($jmetc_options['format'] == 1) {
    329                 $jmevar['count'] = 0;
    330                
    331                 if($jmetc_options['widget_columns'] > 1) {
    332                     $jmevar['rows'] = true;
    333                     $jmevar['cache'] .= '<table cellspacing="0"><tr>';
     481    }
     482   
     483    /**
     484     * Execute the sql query
     485     */
     486    $gettc = $wpdb->get_results( $query );
     487
     488    /**
     489     * If resuls are found
     490     */
     491    if($gettc) {
     492       
     493        /**
     494         * If author list is List Format setting
     495         */
     496        if($jmetc_options['format'] == 1) {
     497            $jmevar['count'] = 0;
     498               
     499       
     500            /**
     501             * If widget columns is greater than 1, define columns as true,
     502             * and wrap the results in a table with each result in td tag.
     503             */
     504            if($jmetc_options['widget_columns'] > 1) {
     505                $jmevar['columns'] = true;
     506                $jmevar['cache'] .= '<table cellspacing="0"><tr>';
     507            }
     508               
     509            /**
     510             * Start the result loop
     511             */
     512            foreach($gettc as $tc) {
     513               
     514                /**
     515                 * If columns true, wrap each result in td tag, then start standard formatting
     516                 */
     517                if($jmevar['columns']) $jmevar['cache'] .= '<td>';
     518               
     519                $jmevar['cache'] .= '<div class="list">';
     520               
     521               
     522                /**
     523                 * If linking to Author page is true, generate link for the username
     524                 * by getting 'author posts url' from author ID
     525                 * Else, do standard linking with keywordluv check, and rel links.
     526                 */
     527                if($jmetc_options['author_page'])
     528                        $jmevar['username'] = '<a href="' . get_author_posts_url($tc->ID) . '">' . $tc->display_name . '</a>';
     529                else
     530                        $jmevar['username'] = jmetc_do_keywordluv($tc->display_name,$tc->user_url,$jmetc_options['keywordluv'],$jmetc_options['rel_links']);
     531                   
     532   
     533                /**
     534                 * Check if Show avatar option is enabled
     535                 */
     536                if($jmetc_options['show_avatar'] == 1) {
     537                   
     538                    /**
     539                     * Now check if linking to author page is enabled, to create a href link for the avatar image
     540                     */
     541                    if($jmetc_options['author_page'])
     542                        $jmevar['cache'] .= '<a ' . jmetc_rel_link($jmetc_options['rel_links']) . 'href="' . get_author_posts_url($tc->ID) . '">';
     543               
     544                   
     545                    /** Put avatar result into cache */
     546                    $jmevar['cache'] .= get_avatar($tc->user_email, $jmetc_options['avatar_size']);
     547
     548                    /**
     549                     * Then put closing </a> tag if author link enabled
     550                     */
     551                    if($jmetc_options['author_page']) $jmevar['cache'] .= '</a>';
    334552                }
    335553               
    336                 foreach($gettc as $tc) {
    337                     if($jmevar['rows']) $jmevar['cache'] .= '<td>';
    338                     $jmevar['cache'] .= '<div class="list">';
    339                
    340                     if($jmetc_options['author_page']) {
    341                         $jmevar['username'] = '<a href="' . get_author_posts_url($tc->ID) . '">' . $tc->display_name . '</a>';
    342                     } else {
    343                         $jmevar['username'] = jmetc_do_keywordluv($tc->display_name,$tc->user_url,$jmetc_options['keywordluv'],$jmetc_options['rel_links']);
    344                     }
    345                    
    346                     /*  if link to Author Page */
    347                     if($jmetc_options['author_page']) $jmevar['cache'] .= '<a ' . jmetc_rel_link($jmetc_options['rel_links']) . 'href="' . get_author_posts_url($tc->ID) . '">';
    348                    
    349                     /* generate user Avatar */
    350                     if($jmetc_options['show_avatar'] == 1)
    351                         $jmevar['cache'] .= get_avatar($tc->user_email, $jmetc_options['avatar_size']);
    352 
    353                     /* end link to Author page */
    354                     if($jmetc_options['author_page']) $jmevar['cache'] .= '</a>';
    355                
    356                
    357                     $jmevar['cache'] .= '<div class="tc-user">' . $jmevar['username'] . '</div>';
    358                         if($jmetc_options['show_count'] == 1) {
    359                             $jmevar['cache'] .= '<div class="tc-count">';
    360                             $jmevar['cache'] .= ($tc->post_count == 1) ? sprintf(__("%s post", 'jmetc'), $tc->post_count) :
    361                                 sprintf(__("%s posts", 'jmetc'), number_format($tc->post_count));
    362                             $jmevar['cache'] .= '</div>';
    363                         }
    364                     $jmevar['cache'] .= '<div style="clear:both;"></div></div>'."\n";
    365                     $jmevar['count']++;
    366                    
    367                     if($jmevar['rows']) {
    368                         $jmevar['cache'] .= '</td>';
    369                         if($jmevar['count'] % $jmetc_options['widget_columns'] == 0) $jmevar['cache'] .= '</tr><tr>';
    370                     }
    371                     if($jmevar['rows']) $jmevar['cache'] .= "</tr></table>\n";
     554                /**
     555                 * Now format the username and comment count for each result,
     556                 * use $jmevar[username] result that was created above.
     557                 */
     558                $jmevar['cache'] .= '<div class="tc-user">' . $jmevar['username'] . '</div>';
     559               
     560                /**
     561                 * If show comment count is true, add count to cache
     562                 */
     563                if($jmetc_options['show_count'] == 1) {
     564                    $jmevar['cache'] .= '<div class="tc-count">';
     565                    $jmevar['cache'] .= ($tc->post_count == 1) ? sprintf(__("%s post", 'jmetc'), $tc->post_count) :
     566                        sprintf(__("%s posts", 'jmetc'), number_format($tc->post_count));
     567                    $jmevar['cache'] .= '</div>';
    372568                }
    373             }
    374        
    375             if($jmetc_options['format'] == 2) {
    376                
    377                 foreach($gettc as $tc) {
    378                    
    379                     /* if linking to Author Page */
    380                     if($jmetc_options['author_page']) $jmevar['cache'] .= '<a href="'.get_author_posts_url($tc->ID).'">';
     569                   
     570                /**
     571                 * Close username and comment count tags, and clear the image float left
     572                 * for each result
     573                 */
     574                $jmevar['cache'] .= '<div style="clear:both;"></div></div>'."\n";
     575                $jmevar['count']++;
     576                   
     577                /**
     578                 * If columns is true, then need to finish the wrap in the table
     579                 */
     580                if($jmevar['columns']) {
     581                    $jmevar['cache'] .= '</td>';
     582                    if($jmevar['count'] % $jmetc_options['widget_columns'] == 0) $jmevar['cache'] .= '</tr><tr>';
     583                }
     584            }
     585               
     586            /**
     587             * And finally close the table after the foreach loop
     588             */
     589            if($jmevar['columns']) $jmevar['cache'] .= "</tr></table>\n";
     590        }
     591        /** End of html output of List Style format */
     592       
     593       
     594       
     595        /**
     596         * If the format style is Gallery Style generate output html cache
     597         */
     598        if($jmetc_options['format'] == 2) {
     599               
     600            /**
     601             * Start foreach loop of each result
     602             */
     603            foreach($gettc as $tc) {
     604                   
     605                /**
     606                 * If linking to Author Page enabled, get the author page url from author ID
     607                 */
     608                if($jmetc_options['author_page']) $jmevar['cache'] .= '<a href="'.get_author_posts_url($tc->ID).'">';
    381609                       
    382                     /* generate user avatar */
    383                     $gavatar = get_avatar($tc->user_email, $jmetc_options['avatar_size']);
    384                    
    385                     $jmevar['cache'] .= '<div class="gallery">'."\n";
    386                    
    387                     /* create tooltip info */
    388                     $jmevar['tt'] = 'title="<div class=\'tc-user\'>' . $tc->display_name . '</div>';
    389                     if($jmetc_options['show_count'] == 1) {
    390                         $jmevar['tt'] .= '<div class=\'tc-count\'>';
    391                         $jmevar['tt'] .= ($tc->post_count == 1) ? sprintf(__("%s post", 'jmetc'), $tc->post_count) :
     610                /**
     611                 * Generate user avatar, this is required for Gallery Style
     612                 */
     613                $jmetc['gravatar'] = get_avatar($tc->user_email, $jmetc_options['avatar_size']);
     614                   
     615                $jmevar['cache'] .= '<div class="gallery">'."\n";
     616                   
     617                /**
     618                 * Create the avatar tooltip information, such as username, post count
     619                 */
     620                $jmevar['tt'] = 'title="<div class=\'tc-user\'>' . $tc->display_name . '</div>';
     621               
     622                /**
     623                 * If show post count true, add it after the username
     624                 */
     625                if($jmetc_options['show_count'] == 1) {
     626                    $jmevar['tt'] .= '<div class=\'tc-count\'>';
     627                    $jmevar['tt'] .= ($tc->post_count == 1) ? sprintf(__("%s post", 'jmetc'), $tc->post_count) :
    392628                            sprintf(__("%s posts", 'jmetc'), number_format($tc->post_count));
    393                         $jmevar['tt'] .= '</div>';
    394                     }
    395                     $jmevar['tt'] .= '" ';
    396                     /* end tooltip info */
    397                                
    398                     $jmevar['cache'] .= str_replace('<img','<img '.$jmevar['tt'],$gavatar);
    399                    
    400                     /* close link to Author page */
    401                     if($jmetc_options['author_page']) $jmevar['cache'] .= '</a>';
    402                    
    403 
    404                     $jmevar['cache'] .= "</div>\n";
     629                    $jmevar['tt'] .= '</div>';
    405630                }
    406                 $jmevar['cache'] .= '<div style="clear:both;"></div>';
    407             }
    408         } else {
    409             $jmevar['cache'] .= __('No authors found.', 'jmetc');
    410         }
    411        
    412         $jmevar['cache'] .= "</div>\n";
    413    
    414         $jmetc_options['cache'] = $jmevar['cache'];
    415 
    416         update_option('jmetc_authors', $jmetc_options);
    417 }
    418 
     631                $jmevar['tt'] .= '" ';
     632                /** End of tooltip output */
     633                   
     634                /**
     635                 * Add the tooltip info to the avatar image
     636                 */         
     637                $jmevar['cache'] .= str_replace('<img','<img '.$jmevar['tt'],$jmetc['gravatar']);
     638                   
     639                /**
     640                 * If author page link enabled, close link to Author page after avatar image
     641                 */
     642                if($jmetc_options['author_page']) $jmevar['cache'] .= '</a>';
     643               
     644                /**
     645                 * Closing html tags for each user output
     646                 */
     647                $jmevar['cache'] .= "</div>\n";
     648            }
     649            $jmevar['cache'] .= '<div style="clear:both;"></div>';
     650        }
     651    } else {
     652       
     653        /**
     654         * (else) if no results from query, output no authors found.
     655         */
     656        $jmevar['cache'] .= __('No authors found.', 'jmetc');
     657    }
     658       
     659    $jmevar['cache'] .= "</div>\n";
     660   
     661    /**
     662     * Store cached html output into WP option table, and update option table
     663     */
     664    $jmetc_options['cache'] = $jmevar['cache'];
     665    update_option('jmetc_authors', $jmetc_options);
     666}
     667/** End of Author result cache */
     668
     669
     670/**
     671 * Function to generate the username exclude list for sql query
     672 */
    419673function jme_get_author_exclude($type,$the_authors) {
     674   
     675    /** Define Author SQL as empty string */
    420676    $author_sql = '';
     677   
     678    /**
     679     * If exclude author list field is not empty,
     680     * put the author emails into comma list for sql query.
     681     */
    421682    if(trim($the_authors) != '') {
    422683        $authorlist = array();
     
    429690        $al = implode("','",$authorlist);       
    430691        if($al != '') {
     692           
     693            /**
     694             * Depending on $type of query, create the sql line
     695             * to be appended to sql query
     696             */
    431697            if($type == 1) {
    432698                $author_sql = "AND LOWER(b.user_email) NOT IN('" . $al . "')";
     
    438704        }
    439705    }
     706    /** Return the sql query */
    440707    return $author_sql;
    441708}
     709
     710/**
     711 * This just gets the blog's categories to display in the Admin settings options
     712 * for including and excluding categories
     713 */
    442714function jme_get_category_list_id() {
    443715    global $wpdb;
     
    453725}
    454726
     727/**
     728 * This creates the sql line for time interval to get
     729 * results from
     730 */
    455731function jme_get_time_interval($type,$options) {
    456732    $timeInterval = '';
     
    532808}
    533809
     810/**
     811 * Register and enqueue javascripts needed for Gallery Style tooltips and CSS style for
     812 * both List and Gallery style formatting
     813 */
    534814function jme_top_contributors_init() {
    535815    global $jmetcop;
     
    545825    }
    546826}
     827
     828/**
     829 * jQuery function required for Gallery List tooltip to work
     830 */
    547831function jme_top_contributors_tooltip() {
    548832    global $jmetcop;
     
    552836}
    553837
     838/**
     839 * This is the function that adds the Stars to each username in the comment list
     840 * This takes the array of user names created in the Comment List Cache function above
     841 * and if the username of the comment is in the array, add the neccessary amount of stars
     842 */
    554843function jme_tc_icon($user) {
    555844    global $jmetcop;
     
    561850            $starList = explode(",",$jmetcop['icon']['comment_limit']);
    562851
    563             /*
     852            /**
    564853                Loop through each threshold limit and check if user post count is above
    565854                that threshold limit, and add a star if it does
     
    576865}
    577866
    578 function jmetc_settings_link($links, $file) {
    579     static $this_plugin;
    580  
    581     if( !$this_plugin ) $this_plugin = plugin_basename(__FILE__);
    582  
    583     if( $file == $this_plugin ){
    584         $settings_link = '<a href="options-general.php?page='.dirname(plugin_basename(__FILE__)).'.php">' . __('Settings') . '</a>';
    585         $links = array_merge( array($settings_link), $links); // before other links
    586     }
    587     return $links;
    588 }
    589 
     867/**
     868 * Rel Link function
     869 */
    590870function jmetc_rel_link($rel) {
    591871    switch($rel) {
     
    596876    return $jmevar['rel'];
    597877}
     878
     879/**
     880 * Just check username for KeywordLuv, and rel links
     881 */
    598882function jmetc_do_keywordluv($name,$url,$kwl,$rel) {
    599883    if(strpos($name,'@') && $url != '' && $kwl == 1) {
  • top-contributors/tags/1.4.1/top-contributors.php

    r369153 r370330  
    1717**/
    1818
     19/**
     20 * Define plugin path, and load language directory for text localization
     21 */
    1922define('JMETC_PLUGINPATH', WP_CONTENT_URL . '/plugins/'. plugin_basename(dirname(__FILE__)) . '/');
    2023load_plugin_textdomain( 'jmetc', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    2124
    22 // default values
     25
     26/**
     27 * Default values for plugin options
     28 */
    2329$tcDefault['options'] = array( 
    2430                        'limit' => 10,
     
    5056                    );
    5157
    52 /* check and set options for plugin */
    53 
     58
     59/**
     60 * Check and set options for plugin
     61 */
    5462if(get_option('jmetc_commenters')) {
    5563    $jmetcop['comment'] = get_option('jmetc_commenters');
Note: See TracChangeset for help on using the changeset viewer.