XPressME Integration Kit

Trac

source: trunk/wp-content/plugins/xpressme/include/custom_functions.php @ 155

Last change on this file since 155 was 155, checked in by toemon, 15 years ago

#14 マルチユーザーモードの実装

File size: 14.9 KB
Line 
1<?php
2function xpress_selected_author($show=true ) {
3        $output = '';
4        $author_cookie = get_xpress_dir_name() . "_select_author" ;
5        if (!empty($_COOKIE[$author_cookie])){
6                $uid = intval($_COOKIE[$author_cookie]);
7                $user_info = get_userdata($uid);
8                $output = $user_info->display_name;
9        }
10        if (empty($show))
11                return $output;
12        else
13                echo $output;
14               
15}
16       
17function xpress_list_pings($trackback, $args, $depth) {
18       $GLOBALS['comment'] = $trackback;
19        echo '<li id="comment-<?php comment_ID(); ?>">';
20        comment_author_link();
21}
22       
23function xpress_credit($show = false)
24{
25        global $wp_version , $xoops_config;
26       
27        $xpress_version = $xoops_config->module_version;
28        $xpress_codename = $xoops_config->module_codename;
29        $ret = '<a href="http://www.toemon.com"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
30        if (strstr($wp_version,'ME')){
31                $ret .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
32        } else {
33                $ret .= '(included <a href="http://ja.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
34        }
35
36        if (empty($show))
37                return $ret;
38        else
39                echo $ret;
40}
41
42function xpress_convert_time($show = false)
43{
44        $ret =  timer_stop(0) .'sec. ';
45        if (empty($show))
46                return $ret;
47        else
48                echo $ret;
49}
50
51function xpress_is_theme_sidebar_disp(){
52        global $xpress_config;
53        if (is_wordpress_style()) return true;
54        return $xpress_config->is_theme_sidebar_disp;
55}       
56
57function xpress_left_arrow_post_link($show = false)
58{
59        global $xpress_config;
60        $ret = '';
61               
62        if($xpress_config->is_left_postnavi_old){
63                $link_title = $xpress_config->old_post_link_text;
64                ob_start();
65                if ($xpress_config->is_postnavi_title_disp)
66                        previous_post_link('&laquo; %link');
67                else
68                        previous_post_link('&laquo; %link',$link_title);
69                $ret = ob_get_contents();
70                ob_end_clean();
71        } else {
72                $link_title = $xpress_config->newer_post_link_text;
73                ob_start();
74                if ($xpress_config->is_postnavi_title_disp)
75                        next_post_link('&laquo; %link');
76                else
77                        next_post_link('&laquo; %link',$link_title);
78                $ret = ob_get_contents();
79                ob_end_clean();
80        }
81       
82        if ($xpress_config->is_postnavi_title_disp){
83                $on_mouse_show = $link_title;
84        } else  {
85                if($xpress_config->is_left_postnavi_old){
86                        ob_start();
87                                previous_post_link('%link');
88                                $on_mouse_show = ob_get_contents();
89                        ob_end_clean();
90                } else {
91                        ob_start();
92                                next_post_link('%link');
93                                $on_mouse_show = ob_get_contents();
94                        ob_end_clean();
95                }
96                $pattern = "<a[^>]*?>(.*)<\/a>";
97                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
98                $on_mouse_show = $body_matches[1];
99        }
100        $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
101
102        if (empty($show))
103                return $ret;
104        else
105                echo $ret;
106}
107
108function xpress_right_arrow_post_link($show = false)
109{
110        global $xpress_config;
111        $ret = '';             
112       
113        if($xpress_config->is_left_postnavi_old){
114                $link_title = $xpress_config->newer_post_link_text;
115                ob_start();
116                if ($xpress_config->is_postnavi_title_disp)
117                        next_post_link('%link &raquo;');
118                else
119                        next_post_link('%link &raquo;',$link_title);
120                $ret = ob_get_contents();
121                ob_end_clean();
122        } else {
123                $link_title = $xpress_config->old_post_link_text;
124                ob_start();
125                if ($xpress_config->is_postnavi_title_disp)
126                        previous_post_link('%link &raquo;');
127                else
128                        previous_post_link('%link &raquo;',$link_title);
129                $ret = ob_get_contents();
130                ob_end_clean();
131        }
132       
133        if ($xpress_config->is_postnavi_title_disp){
134                $on_mouse_show = $link_title;
135        } else  {
136                if($xpress_config->is_left_postnavi_old){
137                        ob_start();
138                                next_post_link('%link');
139                                $on_mouse_show = ob_get_contents();
140                        ob_end_clean();
141                } else {
142                        ob_start();
143                                previous_post_link('%link');
144                                $on_mouse_show = ob_get_contents();
145                        ob_end_clean();
146                }
147                $pattern = "<a[^>]*?>(.*)<\/a>";
148                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
149                $on_mouse_show = $body_matches[1];
150        }
151        $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
152
153        if (empty($show))
154                return $ret;
155        else
156                echo $ret;     
157}
158// page link
159function xpress_left_arrow_posts_link($show = false)
160{
161        global $xpress_config;
162        $ret = '';
163               
164        if($xpress_config->is_left_page_navi_old){
165                $link_title = $xpress_config->old_page_link_text;
166                ob_start();
167                next_posts_link("&laquo; $link_title");
168                $ret = ob_get_contents();
169                ob_end_clean();
170        } else {
171                $link_title = $xpress_config->newer_page_link_text;
172                ob_start();
173                previous_posts_link("&laquo; $link_title");
174                $ret = ob_get_contents();
175                ob_end_clean();
176        }
177
178        if (empty($show))
179                return $ret;
180        else
181                echo $ret;
182}
183
184function xpress_right_arrow_posts_link($show = false)
185{
186        global $xpress_config;
187        $ret = '';             
188       
189        if($xpress_config->is_left_page_navi_old){
190                $link_title = $xpress_config->newer_page_link_text;
191                ob_start();
192                previous_posts_link("$link_title &raquo;");
193                $ret = ob_get_contents();
194                ob_end_clean();
195        } else {
196                $link_title = $xpress_config->old_page_link_text;
197                ob_start();
198                next_posts_link("$link_title &raquo;");
199                $ret = ob_get_contents();
200                ob_end_clean();
201        }
202
203        if (empty($show))
204                return $ret;
205        else
206                echo $ret;     
207}
208
209
210function xpress_is_author_view_count(){
211        global $xpress_config;
212        return $xpress_config->is_author_view_count;
213}
214
215function xpress_is_multi_user(){
216        global $xpress_config;
217        return $xpress_config->is_multi_user;
218}
219
220
221function xpress_substr($str, $start, $length, $trimmarker = '...')
222{
223    if (function_exists('mb_substr')){
224        $str2 = mb_substr( $str , $start , $length);
225        return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
226    } else {
227        return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
228    }
229}
230
231
232// views count
233// Set and retrieves post views given a post ID or post object.
234// Retrieves post views given a post ID or post object.
235function xpress_post_views_count($post_id=0,$format= '',$show = true) {
236        global $xoops_db,$wpdb;
237
238        static $post_cache_views;
239
240        if ( empty($post_id) ) {
241                if ( isset($GLOBALS['post']) )
242                        $post_id = $GLOBALS['post']->ID;
243        }
244
245        $post_id = intval($post_id);
246        if($post_id==0) return null;
247        if(!isset($post_cache_views[$post_id])){
248        $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
249        $post_views = $xoops_db->get_var($sql);
250        if (!$post_views) {
251                $post_cache_views[$post_id] = 0;
252        }else{
253                $post_cache_views[$post_id] = $post_views;
254        }
255        }
256        $v_count = intval($post_cache_views[$post_id]);
257       
258        if (empty($format)) $format = __('views :%d','xpressme');
259       
260        $ret = sprintf($format,$v_count);
261
262        if ($show) echo $ret; else return $ret;
263}
264
265function set_post_views_count(&$content) {
266        if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
267                post_views_counting();
268        }
269        return $content;
270}
271
272// Set post views given a post ID or post object.
273function post_views_counting($post_id = 0) {
274        global $xoops_db,$wpdb;
275        global $table_prefix;
276        static $views;
277       
278        $post_id = intval($post_id);
279        if ( empty($post_id) && isset($GLOBALS['post']) ){
280                $post_id = $GLOBALS['post']->ID;
281        }
282
283
284        $views_db = get_wp_prefix() . 'views';
285
286        if($post_id==0 || !empty($views[$post_id])) return null;
287       
288        if(!xpress_is_author_view_count()){
289                $current_user_id = $GLOBALS['current_user']->ID;
290                $post_author_id = $GLOBALS['post']->post_author;
291                if ($current_user_id ==$post_author_id) return null;
292        }
293
294    $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
295        $post_views_found = $xoops_db->get_var($sql);
296        if($post_views_found){
297        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
298    }else{
299        $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
300    }
301    $xoops_db->query($sql);
302        return true;
303}
304
305function get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text = '') {
306        global $post,$xpress_config;
307       
308        $blog_encoding = get_option('blog_charset');
309        $text = get_the_content('');
310        $text = strip_shortcodes( $text );
311        $text = apply_filters('the_content', $text);
312        $text = str_replace(']]>', ']]&gt;', $text);
313        $text = strip_tags($text);
314        $is_almost_ascii = ($xpress_config->ascii_judged_rate < round(@(mb_strlen($text, $blog_encoding) / strlen($text)) * 100)) ? true : false;
315        if($is_almost_ascii) {
316                $words = explode(' ', $text, $excerpt_length_word + 1);
317
318                if(count($words) > $excerpt_length_word) {
319                        array_pop($words);
320                        array_push($words, ' ... ');
321                        $text = implode(' ', $words);
322                        if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
323
324                }
325        }
326        elseif(mb_strlen($text, $blog_encoding) > $excerpt_length_character) {
327                $text = mb_substr($text, 0, $xpress_config->excerpt_length_character, $blog_encoding) . ' ... ';
328                if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
329        }
330
331        return $text;
332}
333
334function xpress_the_content($more_link_text = null, $stripteaser = 0, $more_file = '',$show = true)
335{
336        global $post,$xpress_config;
337       
338       
339        if ($xpress_config->is_content_excerpt){
340                $excerpt_length_word = $xpress_config->excerpt_length_word;
341                $excerpt_length_character = $xpress_config->excerpt_length_character;
342                $more_link_text = $xpress_config->more_link_text;
343                $content = get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text);
344        } else {
345                $content = get_the_content($more_link_text,$stripteaser,$more_file);
346                $content = apply_filters('the_content', $content);
347                $content = str_replace(']]>', ']]&gt;', $content);
348        }       
349        if(empty($show)) return $content;
350        echo $content;
351}
352
353function is_xpress_contributor()
354{
355        global $current_user;
356        get_currentuserinfo();
357        if ($current_user->user_level > 3)
358                return true;
359        else
360                return false;
361}
362
363function xpress_post_new_link($link_title,$display = true)
364{
365        $output = '<a href="'. get_xpress_url() . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
366        if ($display)
367                echo $output;
368        else
369                return $output;
370}
371
372function xpress_conditional_title($display = true)
373{
374        $selected_author = xpress_selected_author(false);
375       
376        $output = __('Main', 'xpressme');
377        if (is_category())
378                $output = sprintf(__('Archive for the &#8216;%s&#8217; Category', 'xpressme'), single_cat_title('', false));
379        if (is_tag())
380                $output = sprintf(__('Posts Tagged &#8216;%s&#8217;', 'xpressme'), single_tag_title('', false) );
381        if (is_day())
382                $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
383        if (is_month())
384                $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
385        if (is_year())
386                $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
387        if (is_author()){
388                if (empty($selected_author))
389                        $output = sprintf(__('Archive for the &#8216;%s&#8217; Author', 'xpressme'), get_author_name( get_query_var('author')));
390        }
391        if (is_search())
392                $output = sprintf(__('Search Results of word &#8216;%s&#8217;', 'xpressme'), get_search_query());
393       
394        if (!empty($selected_author))
395        $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
396               
397        if ($display)
398                echo $output;
399        else
400                return $output;
401}
402
403function xpress_pings_list($show = false){
404       
405        $trackbacks = xpress_get_pings();
406        if (! empty($trackbacks)) {
407                $output = '<ol id="xpress_pingslist"> ';
408
409                foreach ($trackbacks as $trackback){
410                        $list = date(get_settings('date_format'),$trackback['date']) . ' <a target="_blank" href="' . $trackback['site_url'] . '" rel="external nofollow">' . sprintf(__('From %1$s on site %2$s','xpressme'),$trackback['title'],$trackback['site_name']) . "</a>\n" ;
411
412                        $output .=  '<li>';
413                        $output .=  $list ;
414                        $output .=  '</li>';
415
416                }
417                $output .= '</ol>' ;
418        } else {
419                $output = '';
420        }
421       
422        if ($show) echo $output; else return $output;
423}
424
425function xpress_pings_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
426        $pings = xpress_get_pings();
427        if (empty($pings)){
428                $number = 0;
429        }else {
430                $number = count($pings);
431        }
432        if ( $number > 1 )
433                $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% TrackBack/Pingback', 'xpressme') : $more);
434        elseif ( $number == 0 )
435                $output = ( false === $zero ) ? __('No Trackback/Pingback', 'xpressme') : $zero;
436        else // must be one
437                $output = ( false === $one ) ? __('One Trackback/Pingback', 'xpressme') : $one;
438
439        echo $output;
440}
441
442
443function xpress_get_pings()
444{
445        global $withcomments, $post, $wpdb, $id, $trackback, $user_login, $user_ID, $user_identity;
446
447        if ( ! (is_single() || is_page() || $withcomments) )
448                return;
449
450        /** @todo Use API instead of SELECTs. */
451        if ( $user_ID) {
452                $trackbacks = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ORDER BY comment_date", $post->ID, $user_ID));
453        } else if ( empty($trackback_author) ) {
454                $trackbacks = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ORDER BY comment_date", $post->ID));
455        } else {
456                $trackbacks = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ORDER BY comment_date", $post->ID, $trackback_author, $trackback_author_email));
457        }
458
459        if ($trackbacks){
460                $ret = array();
461                foreach ($trackbacks as $trackback){
462
463                        $pattern = '<strong>(.*)<\/strong>(.*)';
464                        if ( preg_match ( "/".$pattern."/i", $trackback->comment_content , $match ) ){
465                                $title = $match[1];
466                                $content = $match[2];
467                        }
468                        if (empty($title)) $title = $trackback->comment_author;
469
470
471                        $row_data = array(
472                                'ID'            => $trackback->comment_ID ,
473                                'post_ID'       => $trackback->comment_post_ID ,
474                                'site_name' => $trackback->comment_author ,
475                                'site_url' => $trackback->comment_author_url ,
476                                'title' => $title ,
477                                'content' => $content ,
478                                'date'          => $trackback->comment_date ,
479                                'date_gmt'              => $trackback->comment_date_gmt ,
480                                'agent'         => $trackback->comment_agent ,
481                                'type'          => $trackback->comment_type ,
482                                'IP'            => $trackback->comment_author_IP ,
483                        );
484                        array_push($ret,$row_data);
485                }
486                return $ret;
487        }
488                        return false;
489}
490?>
Note: See TracBrowser for help on using the repository browser.