Changeset 370330
- Timestamp:
- 04/07/2011 06:56:03 PM (14 years ago)
- 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 1 1 <?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 */ 2 7 function jmetc_refresh_comment_cache() { 3 8 global $wpdb; 4 9 10 /** 11 * Get Top contributor 'commenter' options, and Star Icon options 12 */ 5 13 $jmetcop['icon'] = get_option('jmetc_icon'); 6 14 $jmetc_options = get_option('jmetc_commenters'); 7 15 8 /* 9 set star icon name and count lists as arrays10 need these redefined for users that was usingversion 1.416 /** 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 11 19 */ 12 20 $jmetc_options['toplist']['name'] = array(); 13 21 $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 */ 15 27 $jmevar['cache'] = '<div class="top-contributors">'."\n"; 16 28 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 */ 18 34 if($jmetc_options['show_category'] == 1) { 19 35 20 /* create category list id */ 36 /** 37 * Create comma'd category id list to do query search with 38 */ 21 39 $jmevar['catarray'] = implode(",",$jmetc_options['category_list']); 22 40 23 /* create category inc/exc sql */ 41 /** 42 * Create the category id include/exclude sql depending on which option is selected 43 */ 24 44 if($jmetc_options['cat_inc_exc'] == 0) 25 45 $jmevar['catsql'] = "AND t.term_id IN ($jmevar[catarray])"; … … 28 48 29 49 30 /* additional query changes */ 50 /** 51 * Do additional query modifications, author exclude, time interval and group by options. 52 */ 31 53 $jmevar['authorsql'] = jme_get_author_exclude(3,$jmetc_options['exclude_author']); 32 54 $jmevar['timeInterval'] = jme_get_time_interval(3,$jmetc_options); 33 55 $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'c.comment_author_email' : 'c.comment_author'; 34 56 35 /* create sql query */ 57 /** 58 * Create the sql query 59 */ 36 60 $query = "SELECT 37 61 COUNT(c.comment_ID) AS `comment_count`, … … 54 78 "; 55 79 } 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 */ 58 89 $jmevar['authorsql'] = jme_get_author_exclude(2,$jmetc_options['exclude_author']); 59 90 $jmevar['timeInterval'] = jme_get_time_interval(2,$jmetc_options); 60 91 $jmevar['groupby'] = ($jmetc_options['count_by'] == 0) ? 'comment_author_email' : 'comment_author'; 61 92 93 /** 94 * Create the sql query 95 */ 62 96 $query = " SELECT COUNT(comment_ID) AS `comment_count`, 63 97 comment_author, … … 75 109 } 76 110 77 /* execute query */ 111 /** 112 * Now excute the sql query 113 */ 78 114 $gettc = $wpdb->get_results( $query ); 79 115 80 /* if valid results */ 116 /** 117 * If we get results, we can create the html output of results 118 */ 81 119 if($gettc) { 82 120 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']); 90 161 } 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>'; 100 173 } 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>'; 115 227 } 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]; 161 284 } 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 169 290 */ 170 if($jmetc op['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 174 295 */ 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 . "' 216 357 "; 217 358 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 */ 257 395 function jmetc_refresh_author_cache() { 258 global $wpdb, $jmetcop; 259 396 global $wpdb; 397 398 /** 399 * Get author settings options 400 */ 260 401 $jmetc_options = get_option('jmetc_authors'); 261 402 403 /** 404 * Start html output cache 405 */ 262 406 $jmevar['cache'] = '<div class="top-contributors">'."\n"; 263 407 408 /** 409 * Get the author exclude list and time interval sql lines 410 */ 264 411 $jmevar['authorsql'] = jme_get_author_exclude(1,$jmetc_options['exclude_author']); 265 412 $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 */ 268 418 if($jmetc_options['show_category'] == 1) { 269 419 270 /* create category list id */ 420 /** 421 * Create comma'd category id list to do query search with 422 */ 271 423 $jmevar['catarray'] = implode(",",$jmetc_options['category_list']); 272 424 273 /* create category inc/exc sql */ 425 /** 426 * Create the category id include/exclude sql depending on which option is selected 427 */ 274 428 if($jmetc_options['cat_inc_exc'] == 0) 275 429 $jmevar['catsql'] = "AND t.term_id IN ($jmevar[catarray])"; … … 277 431 $jmevar['catsql'] = "AND t.term_id NOT IN ($jmevar[catarray]) AND t.taxonomy = 'category'"; 278 432 433 /** 434 * Create the sql query 435 */ 279 436 $query = " SELECT 280 437 COUNT(DISTINCT(a.ID)) AS `post_count`, … … 301 458 302 459 } else { 303 /* if no category include/exclude do normal query */ 460 /** 461 * (else) If there is no category includes/excludes, do standard query 462 */ 304 463 305 464 $query = " SELECT … … 320 479 LIMIT $jmetc_options[limit] 321 480 "; 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>'; 334 552 } 335 553 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>'; 372 568 } 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).'">'; 381 609 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) : 392 628 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>'; 405 630 } 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 */ 419 673 function jme_get_author_exclude($type,$the_authors) { 674 675 /** Define Author SQL as empty string */ 420 676 $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 */ 421 682 if(trim($the_authors) != '') { 422 683 $authorlist = array(); … … 429 690 $al = implode("','",$authorlist); 430 691 if($al != '') { 692 693 /** 694 * Depending on $type of query, create the sql line 695 * to be appended to sql query 696 */ 431 697 if($type == 1) { 432 698 $author_sql = "AND LOWER(b.user_email) NOT IN('" . $al . "')"; … … 438 704 } 439 705 } 706 /** Return the sql query */ 440 707 return $author_sql; 441 708 } 709 710 /** 711 * This just gets the blog's categories to display in the Admin settings options 712 * for including and excluding categories 713 */ 442 714 function jme_get_category_list_id() { 443 715 global $wpdb; … … 453 725 } 454 726 727 /** 728 * This creates the sql line for time interval to get 729 * results from 730 */ 455 731 function jme_get_time_interval($type,$options) { 456 732 $timeInterval = ''; … … 532 808 } 533 809 810 /** 811 * Register and enqueue javascripts needed for Gallery Style tooltips and CSS style for 812 * both List and Gallery style formatting 813 */ 534 814 function jme_top_contributors_init() { 535 815 global $jmetcop; … … 545 825 } 546 826 } 827 828 /** 829 * jQuery function required for Gallery List tooltip to work 830 */ 547 831 function jme_top_contributors_tooltip() { 548 832 global $jmetcop; … … 552 836 } 553 837 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 */ 554 843 function jme_tc_icon($user) { 555 844 global $jmetcop; … … 561 850 $starList = explode(",",$jmetcop['icon']['comment_limit']); 562 851 563 /* 852 /** 564 853 Loop through each threshold limit and check if user post count is above 565 854 that threshold limit, and add a star if it does … … 576 865 } 577 866 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 */ 590 870 function jmetc_rel_link($rel) { 591 871 switch($rel) { … … 596 876 return $jmevar['rel']; 597 877 } 878 879 /** 880 * Just check username for KeywordLuv, and rel links 881 */ 598 882 function jmetc_do_keywordluv($name,$url,$kwl,$rel) { 599 883 if(strpos($name,'@') && $url != '' && $kwl == 1) { -
top-contributors/tags/1.4.1/top-contributors.php
r369153 r370330 17 17 **/ 18 18 19 /** 20 * Define plugin path, and load language directory for text localization 21 */ 19 22 define('JMETC_PLUGINPATH', WP_CONTENT_URL . '/plugins/'. plugin_basename(dirname(__FILE__)) . '/'); 20 23 load_plugin_textdomain( 'jmetc', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 21 24 22 // default values 25 26 /** 27 * Default values for plugin options 28 */ 23 29 $tcDefault['options'] = array( 24 30 'limit' => 10, … … 50 56 ); 51 57 52 /* check and set options for plugin */ 53 58 59 /** 60 * Check and set options for plugin 61 */ 54 62 if(get_option('jmetc_commenters')) { 55 63 $jmetcop['comment'] = get_option('jmetc_commenters');
Note: See TracChangeset
for help on using the changeset viewer.