XPressME Integration Kit

Trac

Changeset 51


Ignore:
Timestamp:
Dec 27, 2008, 5:31:55 PM (15 years ago)
Author:
toemon
Message:

閲覧数カウント機能の実装 #18
xpress_post_views_count($post_id=0,$format= ,$show = true)関数で閲覧数表示
wp-content/themes/xpress_default/index.php上で仮に使用しています。
投稿者自身の閲覧をカウントするかしないかは、xpressmeプラグインの設定画面で指定します。

Location:
trunk/wp-content
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/plugins/xpressme/include/custom_functions.php

    r49 r51  
    8080                return $ret; 
    8181        else 
    82                 echo $ret;       
     82                echo $ret; 
    8383} 
    8484 
     
    133133                echo $ret;       
    134134} 
     135 
     136function xpress_is_author_view_count(){ 
     137        $config = new XPressME_Class(); 
     138        return $config->is_author_view_count; 
     139} 
     140 
    135141function xpress_substr($str, $start, $length, $trimmarker = '...') 
    136142{ 
     
    208214} 
    209215 
     216// views count 
     217// Set and retrieves post views given a post ID or post object.  
     218// Retrieves post views given a post ID or post object.  
     219function xpress_post_views_count($post_id=0,$format= '',$show = true) { 
     220        global $table_prefix; 
     221 
     222        static $post_cache_views; 
     223 
     224        if ( empty($post_id) ) { 
     225                if ( isset($GLOBALS['post']) ) 
     226                        $post_id = $GLOBALS['post']->ID; 
     227        } 
     228 
     229        $post_id = intval($post_id); 
     230        if($post_id==0) return null; 
     231        if(!isset($post_cache_views[$post_id])){ 
     232        $sql = "SELECT post_views FROM " . $table_prefix . "views" . " WHERE post_id=$post_id"; 
     233        if (!$result = $GLOBALS["xoopsDB"]->query($sql)) { 
     234                $post_cache_views[$post_id] = 0; 
     235        }else{ 
     236                $row = $GLOBALS["xoopsDB"]->fetchArray($result); 
     237                $post_cache_views[$post_id] = $row["post_views"]; 
     238        } 
     239        } 
     240        $v_count = intval($post_cache_views[$post_id]); 
     241         
     242        if (empty($format)) $format = __('views :%d','xpressme'); 
     243         
     244        $ret = sprintf($format,$v_count); 
     245 
     246        if ($show) echo $ret; else return $ret; 
     247} 
     248 
     249function set_post_views_count(&$content) { 
     250        if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){ 
     251                post_views_counting(); 
     252        } 
     253        return $content; 
     254} 
     255 
     256// Set post views given a post ID or post object.  
     257function post_views_counting($post_id = 0) { 
     258        global $table_prefix; 
     259        static $views; 
     260         
     261        $post_id = intval($post_id); 
     262        if ( empty($post_id) && isset($GLOBALS['post']) ){ 
     263                $post_id = $GLOBALS['post']->ID; 
     264        } 
     265 
     266 
     267        $views_db = $table_prefix . "views"; 
     268 
     269        if($post_id==0 || !empty($views[$post_id])) return null; 
     270         
     271        if(!xpress_is_author_view_count()){ 
     272                $current_user_id = $GLOBALS['current_user']->ID; 
     273                $post_author_id = $GLOBALS['post']->post_author; 
     274                if ($current_user_id ==$post_author_id) return null; 
     275        } 
     276 
     277    $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id"; 
     278    $exist = false; 
     279    if ($result = $GLOBALS["xoopsDB"]->query($sql)) { 
     280        while($row = $GLOBALS["xoopsDB"]->fetchArray($result)){ 
     281                $exist = true; 
     282                break; 
     283        } 
     284        } 
     285        if($exist){ 
     286        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id"; 
     287    }else{ 
     288        $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)"; 
     289    } 
     290    if ($result = $GLOBALS["xoopsDB"]->queryF($sql)) { 
     291        $views[$post_id] = 1; 
     292    } 
     293     
     294        return true; 
     295} 
     296 
     297 
    210298?> 
  • trunk/wp-content/plugins/xpressme/language/xpressme-ja.po

    r32 r51  
    33"Project-Id-Version: fckeditor for xpress\n" 
    44"POT-Creation-Date: \n" 
    5 "PO-Revision-Date: 2008-12-17 09:50+0900\n" 
     5"PO-Revision-Date: 2008-12-27 17:37+0900\n" 
    66"Last-Translator: toemon <toychee@toemon.com>\n" 
    77"Language-Team: \n" 
     
    1212"X-Poedit-Country: JAPAN\n" 
    1313"X-Poedit-KeywordsList: _e;__\n" 
    14 "X-Poedit-Basepath: C:\\xampp\\htdocs\\cube\\modules\\xpress2\\wp-content\\plugins\\xpressme\n" 
     14"X-Poedit-Basepath: C:\\xampp\\htdocs\\cube\\modules\\xpress2x\\wp-content\\plugins\\xpressme\n" 
    1515"X-Poedit-SearchPath-0: .\n" 
    1616 
    17 #: xpressme_class.php:25 
     17#: xpressme_class.php:26 
    1818msgid "XPressME Settings" 
    1919msgstr "XPressME設定" 
    2020 
    21 #: xpressme_class.php:42 
    22 #: xpressme_class.php:81 
     21#: xpressme_class.php:43 
     22#: xpressme_class.php:89 
    2323msgid "to Old Post" 
    2424msgstr "前の投稿へ" 
    2525 
    26 #: xpressme_class.php:43 
    27 #: xpressme_class.php:83 
     26#: xpressme_class.php:44 
     27#: xpressme_class.php:91 
    2828msgid "to Newer Post" 
    2929msgstr "次の投稿へ" 
    3030 
    31 #: xpressme_class.php:88 
    32 #: xpressme_class.php:148 
    33 #: xpressme_class.php:153 
     31#: xpressme_class.php:97 
     32#: xpressme_class.php:157 
     33#: xpressme_class.php:162 
     34#: xpressme_class.php:183 
    3435msgid "YES" 
    3536msgstr "はい" 
    3637 
    37 #: xpressme_class.php:89 
    38 #: xpressme_class.php:149 
    39 #: xpressme_class.php:154 
     38#: xpressme_class.php:98 
     39#: xpressme_class.php:158 
     40#: xpressme_class.php:163 
     41#: xpressme_class.php:184 
    4042msgid "NO" 
    4143msgstr "いいえ" 
    4244 
    43 #: xpressme_class.php:138 
     45#: xpressme_class.php:147 
    4446msgid "XPressME Configuration Page" 
    4547msgstr "XPressMEの設定ページ" 
    4648 
    47 #: xpressme_class.php:142 
     49#: xpressme_class.php:151 
    4850msgid "Media Upload Base Path" 
    4951msgstr "メディアアップロードのベースパス設定" 
    5052 
    51 #: xpressme_class.php:143 
     53#: xpressme_class.php:152 
    5254msgid "Use XOOPS UPLOAD PATH" 
    5355msgstr "XOOPSのアップロードパスを使用する。" 
    5456 
    55 #: xpressme_class.php:144 
     57#: xpressme_class.php:153 
    5658msgid "USE WordPress BASE_PATH" 
    5759msgstr "WordPressのベースパスを使用する。" 
    5860 
    59 #: xpressme_class.php:147 
     61#: xpressme_class.php:156 
    6062msgid "Thema Sidebar Display" 
    6163msgstr "テーマ表示時にサイドバー表示する。" 
    6264 
    63 #: xpressme_class.php:152 
     65#: xpressme_class.php:161 
    6466msgid "The change tracking of the post is preserved" 
    6567msgstr "投稿の変更履歴を有効にする。" 
    6668 
    67 #: xpressme_class.php:157 
     69#: xpressme_class.php:166 
    6870msgid "Select Display name of PostNavi Link" 
    6971msgstr "投稿記事リンクナビのタイトル設定" 
    7072 
    71 #: xpressme_class.php:158 
     73#: xpressme_class.php:167 
    7274msgid "Title of post" 
    7375msgstr "投稿記事のタイトルを表示" 
    7476 
    75 #: xpressme_class.php:159 
     77#: xpressme_class.php:168 
    7678msgid "Next and Previous" 
    7779msgstr "[次の投稿へ]、[前の投稿]へを表示" 
    7880 
    79 #: xpressme_class.php:162 
     81#: xpressme_class.php:171 
    8082msgid "Adjustment of Navi link display position" 
    8183msgstr "投稿記事ナビリンクの表示位置設定" 
    8284 
    83 #: xpressme_class.php:163 
     85#: xpressme_class.php:172 
    8486msgid "'Old Post Link' is displayed in the left, and 'Newer Post Link' is displayed in the right" 
    8587msgstr "古い記事へのリンクを左に、より新しい記事へのリンクを右に表示" 
    8688 
    87 #: xpressme_class.php:164 
     89#: xpressme_class.php:173 
    8890msgid "'Newer Post Link' is displayed in the left, and 'Old Post Link' is displayed in the right" 
    8991msgstr "より新しい記事へのリンクを左に、古い記事へのリンクを右に表示" 
    9092 
    91 #: xpressme_class.php:167 
     93#: xpressme_class.php:176 
    9294msgid "Display Title of Old Post Link" 
    9395msgstr "古い記事へのリンクタイトルを設定" 
    9496 
    95 #: xpressme_class.php:170 
     97#: xpressme_class.php:179 
    9698msgid "Display Title of Newer Post Link" 
    9799msgstr "より新しい記事へのリンクタイトルを設定" 
    98100 
    99 #: xpressme_class.php:178 
     101#: xpressme_class.php:182 
     102msgid "Is the posts author views counted?" 
     103msgstr "投稿者自身の閲覧をカウントしますか?" 
     104 
     105#: xpressme_class.php:190 
    100106msgid "Update Config" 
    101107msgstr "更新" 
    102108 
    103 #: xpressme_class.php:179 
     109#: xpressme_class.php:191 
    104110msgid "Preset Config" 
    105111msgstr "プリセット" 
    106112 
     113#: include/custom_functions.php:242 
     114#, php-format 
     115msgid "views :%d" 
     116msgstr "閲覧数 :%d" 
     117 
  • trunk/wp-content/plugins/xpressme/xpressme.php

    r46 r51  
    3535add_action("wp_set_comment_status" , "block_cache_refresh"); 
    3636 
     37add_action("the_content",       "set_post_views_count"); 
     38 
     39 
    3740//require_once('../include/custom_functions.php'); 
    3841?> 
  • trunk/wp-content/plugins/xpressme/xpressme_class.php

    r32 r51  
    1212        var $old_post_link_text; 
    1313        var $newer_post_link_text; 
     14        var $is_author_view_count; 
    1415 
    1516        //constructor 
     
    4243                $this->old_post_link_text = __('to Old Post'); 
    4344                $this->newer_post_link_text = __('to Newer Post'); 
     45                $this->is_author_view_count = false; 
    4446        } 
    4547         
     
    6769                        'is_left_postnavi_old' => $this->is_left_postnavi_old , 
    6870                        'old_post_link_text' => $this->old_post_link_text , 
    69                         'newer_post_link_text' => $this->newer_post_link_text  
     71                        'newer_post_link_text' => $this->newer_post_link_text, 
     72                        'is_author_view_count' => $this->is_author_view_count 
    7073                ); 
    7174                if ($mode == 'add_new') { 
     
    8790                $this->newer_post_link_text = stripslashes($_POST['ch_newer_post_link_text']); 
    8891                if(empty($this->newer_post_link_text)) $this->newer_post_link_text = __('to Newer Post'); 
     92                $this->is_author_view_count = stripslashes(trim($_POST['ch_is_author_view_count'])); 
    8993                 
    9094        } 
     
    174178                echo                            $this->text_option('newer_post_link_text', 
    175179                                                                                                __('Display Title of Newer Post Link','xpressme') 
    176                                                                                                 ); 
    177                  
    178                          
     180                                                                                                );               
     181                echo                            $this->yes_no_radio_option('is_author_view_count', 
     182                                                                                                __('Is the posts author views counted?','xpressme'), 
     183                                                                                                __('YES','xpressme'), 
     184                                                                                                __('NO','xpressme')              
     185                                                                                                );                               
    179186//              $this->is_use_xoops_upload_path_html(); 
    180187                echo                    "</table>\n"; 
  • trunk/wp-content/themes/xpress_default/index.php

    r32 r51  
    33       <div id="xpress_wrap"> 
    44            
    5         <?php if(xpress_is_theme_sidebar_disp()) : ?> 
     5        <?php if(is_sidbar_disp()) : ?> 
    66            
    77                <div id="xpress_content" class="narrowcolumn"> 
     
    3030 
    3131                                <div class="entry"> 
    32                                         <?php the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?> 
     32                                        <?php wp_the_content(); ?> 
    3333                                </div> 
    3434 
    3535                                <p class="postmetadata"><!-- Post author start --><?php/* _e('Posted:', 'kubrick'); echo '&nbsp;'; the_author_posts_link(); echo '<br />' ; */?><!-- Post author end --><?php if(function_exists('the_tags')) : ?><?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', '<br />'); ?><?php endif; ?><?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?>  <?php comments_popup_link(__('No Comments &#187;', 'kubrick'), __('1 Comment &#187;', 'kubrick'), __('% Comments &#187;', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?></p> 
    36                         </div> 
     36                                <?php sprintf('Views: %d',xpress_post_views_count(the_ID()); ?> 
     37                                </div> 
    3738 
    3839                <?php endwhile; ?> 
Note: See TracChangeset for help on using the changeset viewer.