Changeset 983110
- Timestamp:
- 09/06/2014 04:29:12 PM (12 years ago)
- Location:
- wp-author-ranking
- Files:
-
- 11 added
- 4 edited
-
tags/1.0.1 (added)
-
tags/1.0.1/Readme.txt (added)
-
tags/1.0.1/index.php (added)
-
tags/1.0.1/lang (added)
-
tags/1.0.1/lang/wpAuthorRanking-fr.mo (added)
-
tags/1.0.1/lang/wpAuthorRanking-fr.po (added)
-
tags/1.0.1/lang/wpAuthorRanking-ja.mo (added)
-
tags/1.0.1/lang/wpAuthorRanking-ja.po (added)
-
tags/1.0.1/readme.md (added)
-
tags/1.0.1/screenshot-1.png (added)
-
tags/1.0.1/setting.php (added)
-
trunk/Readme.txt (modified) (6 diffs)
-
trunk/index.php (modified) (4 diffs)
-
trunk/readme.md (modified) (2 diffs)
-
trunk/setting.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-author-ranking/trunk/Readme.txt
r980803 r983110 4 4 Requires at least: 3.4 5 5 Tested up to: 3.9 6 Stable tag: 1.0 6 Stable tag: 1.0.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 18 18 3. Open the setting menu, it is possible to set the execution condition. 19 19 20 = = Get the ranking data. ==20 = Get the ranking data. = 21 21 22 22 The function "get_wpAuthorRanking()" return the ranking data stored in an array. … … 34 34 ?>` 35 35 36 = = Informations the ranking data has. ==36 = Informations the ranking data has. = 37 37 38 38 * ID … … 56 56 * d (day) 57 57 * cpt (custom post type) 58 * exclude (exclude users) 59 * sort 58 60 59 61 This example gets columnist (post type 'column') ranking in September 2014. 60 62 61 63 `<?php 62 $rankingData = get_wpAuthorRanking(array('y'=>2014, 'm'=>9, 'cpt'=>'column')); 64 $rankingData = get_wpAuthorRanking(array( 65 'y'=>2014, 66 'm'=>9, 67 'cpt'=>'column')); 68 69 for ($i=0; $i < count($rankingData); $i++) { 70 echo '<li>'; 71 echo '<p>No'.$rankingData[$i]['rank'].'</p>'; 72 echo '<p><strong>'.$rankingData[$i]['display_name'].'</strong></p>'; 73 echo '<p>'.$rankingData[$i]['count'].'pv<p>'; 74 echo '</li>'; 75 } 76 ?>` 77 78 Gets totally worst ranking, exclude ID.3 and ID.4 user. 79 80 `<?php 81 $rankingData = get_wpAuthorRanking(array( 82 'sort'=>'ASC', 83 'exclude'=>array(3,4))); 63 84 for ($i=0; $i < count($rankingData); $i++) { 64 85 echo '<li>'; … … 71 92 72 93 73 = = Count pv manually ==94 = Count pv manually = 74 95 75 96 In default setting, page views are counted at single post page. You also have the function "count_wpAuthorRanking()" to count authors page views manually. 76 97 This example counts id-3 user on 'column' post type. 77 98 78 ` 79 <?php 99 `<?php 80 100 count_wpAuthorRanking(array('user'=>3,'cpt'=>'column')); 81 101 ?>` … … 87 107 88 108 == Changelog == 89 90 = 1.0 = 109 110 = 1.0.1 = 111 * Add filtering option that excludes users. 112 * Add request option to request worst ranking. 113 114 = 1.0.0 = 91 115 * 2014-09-01 First release -
wp-author-ranking/trunk/index.php
r980849 r983110 13 13 14 14 class wpAuthorRanking { 15 16 15 private $already; 17 16 private $tableName; … … 21 20 $this->tableName = $wpdb->prefix.'author_ranking'; 22 21 $this->already=false; 23 24 22 add_action('init', array( $this, 'pageHead')); 25 23 add_action('wp_head', array( $this, 'autoSingleCount')); … … 38 36 'm' => $countDate[1], 39 37 'd' => $countDate[2]); 40 41 $dbQuery_where = '';42 // $optDef['user'] = '"aaa"';43 38 foreach ( $optDef as $key => $value ){ 44 39 $opt[$key] = isset($opt[$key])? $opt[$key] : $value; 45 $dbQuery_where .= ($key=='user'? '':' AND ').$key."='".$opt[$key]."'";46 40 } 47 48 41 if( $opt['user'] != 0 ){ 49 if( $wpdb->get_row("SELECT count FROM {$this->tableName} WHERE {$dbQuery_where}") ) { 50 $dbQuery = $wpdb->prepare("UPDATE {$this->tableName} SET count = count + 1 WHERE user = %s AND cpt = %s AND y = %s AND m = %s AND d = %s;", $opt['user'], $opt['cpt'], $opt['y'], $opt['m'], $opt['d']); 42 if( $wpdb->get_row( $wpdb->prepare("SELECT count FROM {$this->tableName} WHERE user = %d AND cpt = %s AND y = %d AND m = %d AND d = %d;", $opt['user'], $opt['cpt'], $opt['y'], $opt['m'], $opt['d']) ) ) { 43 $dbQuery = $wpdb->prepare("UPDATE {$this->tableName} SET count = count + 1 44 WHERE user = %d AND cpt = %s AND y = %d AND m = %d AND d = %d;", 45 $opt['user'], $opt['cpt'], $opt['y'], $opt['m'], $opt['d']); 51 46 $wpdb->query($dbQuery); 52 47 } else { … … 60 55 public function getRank( $opt = array() ) { 61 56 global $wpdb; 62 $dbQuery = "SELECT ID, user_login, user_nicename, user_email, user_url, user_registered, user_activation_key, display_name, SUM(count) AS count FROM {$this->tableName} JOIN {$wpdb->users} ON {$this->tableName}.user = {$wpdb->users}.ID "; 63 $dbQuery_where = ''; 64 $dbQuery_exclude = ''; 65 $dbQuery_sort = 'DESC'; 66 67 foreach ( $opt as $key => $value ) { 68 if( in_array($key, array('y','m','d','cpt') ) ) { 69 $dbQuery_where .= ($dbQuery_where==''? '':'AND ').$key."='".$value."' "; 70 } elseif($key == 'sort' && $value == 'ASC') { 71 $dbQuery_sort = 'ASC'; 72 } elseif( $key == 'exclude' && is_array($value) ) { 73 foreach ( $value as $excludeUser ) { 74 $dbQuery_exclude .= ($dbQuery_exclude==''? 'NOT ' : 'AND NOT ')."user='".$excludeUser."' "; 57 $optDef = Array( 'cpt' => '', 'y' => '', 'm' => '', 'd' => '', 'exclude' => false, 'sort' => 'DESC' ); 58 $opt['cpt']='post'; 59 $where = ''; 60 $exclude = ''; 61 $sort = ''; 62 foreach ( $optDef as $key => $value ){ 63 $value = ( isset($opt[$key]) ? $opt[$key] : $value ); 64 if( $key == 'sort' ){ 65 $sort = 'ORDER BY count '.( $value=='DESC' ? 'DESC ' : 'ASC ' ); 66 } elseif( $key == 'exclude' ) { 67 if(is_array($value)) { 68 foreach ($value as $userId) { 69 $exclude .= ( $exclude=='' ? 'AND user NOT IN (' : ',').$wpdb->prepare( '%d ' ,$userId); 70 } 71 $exclude .= ($exclude==''? '':')'); 72 } 73 } else { 74 if($value!=''){ 75 $where .= ($where==''? '' : 'AND '); 76 $where .= $wpdb->prepare( $key.'='.($key=='cpt'?'%s ':'%d ') ,(isset($opt[$key])? $opt[$key] : $value)); 75 77 } 76 78 } 77 79 } 78 80 79 $dbQuery.= ($dbQuery_where!='' || $dbQuery_exclude!=''? 'WHERE ':'').$dbQuery_where; 80 $dbQuery.= ($dbQuery_where!='' && $dbQuery_exclude!=''? 'AND ':'').$dbQuery_exclude.'GROUP BY user ORDER BY count '.$dbQuery_sort.';'; 81 $dbQuery = "SELECT ID, user_login, user_nicename, user_email, user_url, user_registered, user_activation_key, display_name, SUM(count) AS count FROM {$this->tableName} JOIN {$wpdb->users} ON {$this->tableName}.user = {$wpdb->users}.ID ". ($where=='' && $exclude=='' ? ' ':'WHERE ') . $where . $exclude .'GROUP BY user '. $sort .';'; 81 82 $sqlResult = $wpdb->get_results($dbQuery); 82 83 $sqlResult_len = count($sqlResult); 84 83 85 $result = Array(); 84 86 $rankerRank = 1; 85 $beforeRankerCount = -1; 86 87 for( $i=0; $i<$sqlResult_len; $i++ ) { 87 $curRank = -1; 88 for( $i = 0; $i < $sqlResult_len; $i++ ) { 88 89 $rankerData = (array)$sqlResult[$i]; 89 if( $rankerData['count'] != $ beforeRankerCount){90 if( $rankerData['count'] != $curRank ){ 90 91 $rankerRank = $i+1; 91 $ beforeRankerCount= $rankerData['count'];92 $curRank = $rankerData['count']; 92 93 } 93 94 $rankerData += array('rank' => $rankerRank); 94 array_push( $result,$rankerData);95 array_push( $result , $rankerData ); 95 96 } 96 return $result;97 return ( count($result) > 0 ? $result : false); 97 98 } 98 99 99 100 public function init() { 100 101 global $wpdb; 101 if( $wpdb->get_var('SHOW TABLES LIKE "'.$this->tableName.'";')!=$this->tableName){102 if( $wpdb->get_var('SHOW TABLES LIKE "'.$this->tableName.'";') != $this->tableName ){ 102 103 $dbQuery = "CREATE TABLE {$this->tableName} ( user int, cpt VARCHAR(20), y int, m int, d int, count int);"; 103 104 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 104 105 dbDelta($dbQuery); 105 106 } 106 update_option( 'wpAuthorRanking_countSingle', true);107 update_option( 'wpAuthorRanking_countUU', true);107 update_option( 'wpAuthorRanking_countSingle' , true ); 108 update_option( 'wpAuthorRanking_countUU' , true ); 108 109 } 109 110 -
wp-author-ranking/trunk/readme.md
r979802 r983110 55 55 * d (day) 56 56 * cpt (custom post type) 57 * exclude (exclude users) 58 * sort 57 59 58 60 This example gets columnist (post type 'column') ranking in September 2014. … … 60 62 ``` 61 63 <?php 62 $rankingData = get_wpAuthorRanking(array('y'=>2014, 'm'=>9, 'cpt'=>'column')); 64 $rankingData = get_wpAuthorRanking(array( 65 'y'=>2014, 66 'm'=>9, 67 'cpt'=>'column')); 68 for ($i=0; $i < count($rankingData); $i++) { 69 echo '<li>'; 70 echo '<p>No'.$rankingData[$i]['rank'].'</p>'; 71 echo '<p><strong>'.$rankingData[$i]['display_name'].'</strong></p>'; 72 echo '<p>'.$rankingData[$i]['count'].'pv<p>'; 73 echo '</li>'; 74 } 75 ?> 76 ``` 77 78 Gets totally worst ranking, exclude ID.3 and ID.4 user. 79 80 ``` 81 <?php 82 $rankingData = get_wpAuthorRanking(array( 83 'sort'=>'ASC', 84 'exclude'=>array(3,4))); 63 85 for ($i=0; $i < count($rankingData); $i++) { 64 86 echo '<li>'; -
wp-author-ranking/trunk/setting.php
r979802 r983110 1 1 <?php 2 $currentDate = preg_split('/[- ]/', date_i18n('Y-n- d'));2 $currentDate = preg_split('/[- ]/', date_i18n('Y-n-j')); 3 3 $tiaraColor = ['#e8c289','#bec6cc','#d8b2ae']; 4 4 load_plugin_textdomain('wpAuthorRanking',false,'wp-author-ranking/lang/'); … … 23 23 24 24 <?php 25 for ($i=0; $i < 4; $i++) { 25 for ($i=0; $i < 4; $i++) { 26 26 $rankingGraphTitle = array('Daily','Monthly','Yearly','Total'); 27 ?> 28 <h3 style='margin: 25px 10px 8px;'><?php _e($rankingGraphTitle[$i], 'wpAuthorRanking'); ?></h3> 29 30 <?php 27 31 $theQuery=array(); 28 32 if ($i<=2) { $theQuery['y'] = $currentDate[0]; } … … 31 35 $rankingData = get_wpAuthorRanking($theQuery); 32 36 $theMaxCount = 0; 37 if($rankingData){ 33 38 foreach($rankingData as $key) { 34 39 $theMaxCount = $theMaxCount<$key['count']? $key['count']:$theMaxCount; 35 40 } 36 41 ?> 37 <h3 style='margin: 25px 10px 8px;'><?php _e($rankingGraphTitle[$i], 'wpAuthorRanking'); ?></h3>38 42 <table cellspacing='10' style='width:100%; max-width:600px;'> 39 43 <?php for ($j=0; $j < count($rankingData); $j++) { ?> … … 50 54 <?php } ?> 51 55 </table> 56 <?php }else{ ?> 57 <p>no data</p> 58 <?php } ?> 52 59 <hr> 53 60 <?php } ?>
Note: See TracChangeset
for help on using the changeset viewer.