Plugin Directory

Changeset 983110


Ignore:
Timestamp:
09/06/2014 04:29:12 PM (12 years ago)
Author:
minojiro
Message:

tagging version 1.0.1

Location:
wp-author-ranking
Files:
11 added
4 edited

Legend:

Unmodified
Added
Removed
  • wp-author-ranking/trunk/Readme.txt

    r980803 r983110  
    44Requires at least: 3.4
    55Tested up to: 3.9
    6 Stable tag: 1.0
     6Stable tag: 1.0.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    18183. Open the setting menu, it is possible to set the execution condition.
    1919
    20 == Get the ranking data. ==
     20= Get the ranking data. =
    2121
    2222The function "get_wpAuthorRanking()" return the ranking data stored in an array.
     
    3434?>`
    3535
    36 == Informations the ranking data has. ==
     36= Informations the ranking data has. =
    3737
    3838* ID
     
    5656* d (day)
    5757* cpt (custom post type)
     58* exclude (exclude users)
     59* sort
    5860
    5961This example gets columnist (post type 'column') ranking in September 2014.
    6062
    6163`<?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
     69for ($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
     78Gets 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)));
    6384for ($i=0; $i < count($rankingData); $i++) {
    6485    echo '<li>';
     
    7192
    7293
    73 == Count pv manually ==
     94= Count pv manually =
    7495
    7596In default setting, page views are counted at single post page. You also have the function "count_wpAuthorRanking()" to count authors page views manually.
    7697This example counts id-3 user on 'column' post type.
    7798
    78 `
    79 <?php
     99`<?php
    80100count_wpAuthorRanking(array('user'=>3,'cpt'=>'column'));
    81101?>`
     
    87107 
    88108== 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 =
    91115* 2014-09-01  First release
  • wp-author-ranking/trunk/index.php

    r980849 r983110  
    1313
    1414class wpAuthorRanking {
    15 
    1615    private $already;
    1716    private $tableName;
     
    2120        $this->tableName = $wpdb->prefix.'author_ranking';
    2221        $this->already=false;
    23 
    2422        add_action('init', array( $this, 'pageHead'));
    2523        add_action('wp_head', array( $this, 'autoSingleCount'));
     
    3836                'm'    => $countDate[1],
    3937                'd'    => $countDate[2]);
    40 
    41             $dbQuery_where = '';
    42             // $optDef['user'] = '"aaa"';
    4338            foreach ( $optDef as $key => $value ){
    4439                $opt[$key] = isset($opt[$key])? $opt[$key] : $value;
    45                 $dbQuery_where .= ($key=='user'? '':' AND ').$key."='".$opt[$key]."'";
    4640            }
    47 
    4841            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']);
    5146                    $wpdb->query($dbQuery);
    5247                } else {
     
    6055    public function getRank( $opt = array() ) {
    6156        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));
    7577                }
    7678            }
    7779        }
    7880
    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 .';';
    8182        $sqlResult = $wpdb->get_results($dbQuery);
    8283        $sqlResult_len = count($sqlResult);
     84
    8385        $result = Array();
    8486        $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++ ) {
    8889            $rankerData = (array)$sqlResult[$i];
    89             if( $rankerData['count'] != $beforeRankerCount ){
     90            if( $rankerData['count'] != $curRank ){
    9091                $rankerRank = $i+1;
    91                 $beforeRankerCount = $rankerData['count'];
     92                $curRank = $rankerData['count'];
    9293            }
    9394            $rankerData += array('rank' => $rankerRank);
    94             array_push($result,$rankerData);
     95            array_push( $result , $rankerData );
    9596        }
    96         return $result;
     97        return ( count($result) > 0 ? $result : false);
    9798    }
    9899
    99100    public function init() {
    100101        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 ){
    102103            $dbQuery = "CREATE TABLE {$this->tableName} ( user int, cpt VARCHAR(20), y int, m int, d int, count int);";
    103104            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    104105            dbDelta($dbQuery);
    105106        }
    106         update_option('wpAuthorRanking_countSingle', true);
    107         update_option('wpAuthorRanking_countUU', true);
     107        update_option( 'wpAuthorRanking_countSingle' , true );
     108        update_option( 'wpAuthorRanking_countUU' , true );
    108109    }
    109110
  • wp-author-ranking/trunk/readme.md

    r979802 r983110  
    5555* d (day)
    5656* cpt (custom post type)
     57* exclude (exclude users)
     58* sort
    5759
    5860This example gets columnist (post type 'column') ranking in September 2014.
     
    6062```
    6163<?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'));
     68for ($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
     78Gets 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)));
    6385for ($i=0; $i < count($rankingData); $i++) {
    6486    echo '<li>';
  • wp-author-ranking/trunk/setting.php

    r979802 r983110  
    11<?php
    2     $currentDate = preg_split('/[- ]/', date_i18n('Y-n-d'));
     2    $currentDate = preg_split('/[- ]/', date_i18n('Y-n-j'));
    33    $tiaraColor = ['#e8c289','#bec6cc','#d8b2ae'];
    44    load_plugin_textdomain('wpAuthorRanking',false,'wp-author-ranking/lang/');
     
    2323
    2424<?php
    25     for ($i=0; $i < 4; $i++) { 
     25    for ($i=0; $i < 4; $i++) {
    2626        $rankingGraphTitle = array('Daily','Monthly','Yearly','Total');
     27?>
     28    <h3 style='margin: 25px 10px 8px;'><?php _e($rankingGraphTitle[$i], 'wpAuthorRanking'); ?></h3>
     29
     30<?php
    2731        $theQuery=array();
    2832        if ($i<=2) {    $theQuery['y'] = $currentDate[0];   }
     
    3135        $rankingData = get_wpAuthorRanking($theQuery);
    3236        $theMaxCount = 0;
     37        if($rankingData){
    3338        foreach($rankingData as $key) {
    3439            $theMaxCount = $theMaxCount<$key['count']? $key['count']:$theMaxCount;
    3540        }
    3641?>
    37 <h3 style='margin: 25px 10px 8px;'><?php _e($rankingGraphTitle[$i], 'wpAuthorRanking'); ?></h3>
    3842<table cellspacing='10' style='width:100%; max-width:600px;'>
    3943<?php for ($j=0; $j < count($rankingData); $j++) { ?>
     
    5054<?php } ?>
    5155</table>
     56<?php }else{ ?>
     57<p>no data</p>
     58<?php } ?>
    5259<hr>
    5360<?php } ?>
Note: See TracChangeset for help on using the changeset viewer.