XPressME Integration Kit

Trac

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

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

コメントからトラックバック、ピンバックを省く、#85
デフォルトテーマ、コメント部分の調整 #80

File size: 11.0 KB
Line 
1<?php
2       
3function xpress_list_pings($comment, $args, $depth) {
4       $GLOBALS['comment'] = $comment;
5        echo '<li id="comment-<?php comment_ID(); ?>">';
6        comment_author_link();
7}
8       
9function xpress_credit($show = false)
10{
11        global $wp_version , $xoops_config;
12       
13        $xpress_version = $xoops_config->module_version;
14        $xpress_codename = $xoops_config->module_codename;
15        $ret = '<a href="http://www.toemon.com"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
16        if (strstr($wp_version,'ME')){
17                $ret .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
18        } else {
19                $ret .= '(included <a href="http://ja.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
20        }
21
22        if (empty($show))
23                return $ret;
24        else
25                echo $ret;
26}
27
28function xpress_convert_time($show = false)
29{
30        $ret =  timer_stop(0) .'sec. ';
31        if (empty($show))
32                return $ret;
33        else
34                echo $ret;
35}
36
37function xpress_is_theme_sidebar_disp(){
38        global $xpress_config;
39        if (is_wordpress_style()) return true;
40        return $xpress_config->is_theme_sidebar_disp;
41}       
42
43function xpress_left_arrow_post_link($show = false)
44{
45        global $xpress_config;
46        $ret = '';
47               
48        if($xpress_config->is_left_postnavi_old){
49                $link_title = $xpress_config->old_post_link_text;
50                ob_start();
51                if ($xpress_config->is_postnavi_title_disp)
52                        previous_post_link('&laquo; %link');
53                else
54                        previous_post_link('&laquo; %link',$link_title);
55                $ret = ob_get_contents();
56                ob_end_clean();
57        } else {
58                $link_title = $xpress_config->newer_post_link_text;
59                ob_start();
60                if ($xpress_config->is_postnavi_title_disp)
61                        next_post_link('&laquo; %link');
62                else
63                        next_post_link('&laquo; %link',$link_title);
64                $ret = ob_get_contents();
65                ob_end_clean();
66        }
67       
68        if ($xpress_config->is_postnavi_title_disp){
69                $on_mouse_show = $link_title;
70        } else  {
71                if($xpress_config->is_left_postnavi_old){
72                        ob_start();
73                                previous_post_link('%link');
74                                $on_mouse_show = ob_get_contents();
75                        ob_end_clean();
76                } else {
77                        ob_start();
78                                next_post_link('%link');
79                                $on_mouse_show = ob_get_contents();
80                        ob_end_clean();
81                }
82                $pattern = "<a[^>]*?>(.*)<\/a>";
83                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
84                $on_mouse_show = $body_matches[1];
85        }
86        $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
87
88        if (empty($show))
89                return $ret;
90        else
91                echo $ret;
92}
93
94function xpress_right_arrow_post_link($show = false)
95{
96        global $xpress_config;
97        $ret = '';             
98       
99        if($xpress_config->is_left_postnavi_old){
100                $link_title = $xpress_config->newer_post_link_text;
101                ob_start();
102                if ($xpress_config->is_postnavi_title_disp)
103                        next_post_link('%link &raquo;');
104                else
105                        next_post_link('%link &raquo;',$link_title);
106                $ret = ob_get_contents();
107                ob_end_clean();
108        } else {
109                $link_title = $xpress_config->old_post_link_text;
110                ob_start();
111                if ($xpress_config->is_postnavi_title_disp)
112                        previous_post_link('%link &raquo;');
113                else
114                        previous_post_link('%link &raquo;',$link_title);
115                $ret = ob_get_contents();
116                ob_end_clean();
117        }
118       
119        if ($xpress_config->is_postnavi_title_disp){
120                $on_mouse_show = $link_title;
121        } else  {
122                if($xpress_config->is_left_postnavi_old){
123                        ob_start();
124                                next_post_link('%link');
125                                $on_mouse_show = ob_get_contents();
126                        ob_end_clean();
127                } else {
128                        ob_start();
129                                previous_post_link('%link');
130                                $on_mouse_show = ob_get_contents();
131                        ob_end_clean();
132                }
133                $pattern = "<a[^>]*?>(.*)<\/a>";
134                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
135                $on_mouse_show = $body_matches[1];
136        }
137        $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
138
139        if (empty($show))
140                return $ret;
141        else
142                echo $ret;     
143}
144// page link
145function xpress_left_arrow_posts_link($show = false)
146{
147        global $xpress_config;
148        $ret = '';
149               
150        if($xpress_config->is_left_page_navi_old){
151                $link_title = $xpress_config->old_page_link_text;
152                ob_start();
153                next_posts_link("&laquo; $link_title");
154                $ret = ob_get_contents();
155                ob_end_clean();
156        } else {
157                $link_title = $xpress_config->newer_page_link_text;
158                ob_start();
159                previous_posts_link("&laquo; $link_title");
160                $ret = ob_get_contents();
161                ob_end_clean();
162        }
163
164        if (empty($show))
165                return $ret;
166        else
167                echo $ret;
168}
169
170function xpress_right_arrow_posts_link($show = false)
171{
172        global $xpress_config;
173        $ret = '';             
174       
175        if($xpress_config->is_left_page_navi_old){
176                $link_title = $xpress_config->newer_page_link_text;
177                ob_start();
178                previous_posts_link("$link_title &raquo;");
179                $ret = ob_get_contents();
180                ob_end_clean();
181        } else {
182                $link_title = $xpress_config->old_page_link_text;
183                ob_start();
184                next_posts_link("$link_title &raquo;");
185                $ret = ob_get_contents();
186                ob_end_clean();
187        }
188
189        if (empty($show))
190                return $ret;
191        else
192                echo $ret;     
193}
194
195
196function xpress_is_author_view_count(){
197        global $xpress_config;
198        return $xpress_config->is_author_view_count;
199}
200
201function xpress_substr($str, $start, $length, $trimmarker = '...')
202{
203    if (function_exists('mb_substr')){
204        $str2 = mb_substr( $str , $start , $length);
205        return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
206    } else {
207        return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
208    }
209}
210
211
212// views count
213// Set and retrieves post views given a post ID or post object.
214// Retrieves post views given a post ID or post object.
215function xpress_post_views_count($post_id=0,$format= '',$show = true) {
216        global $xoops_db,$wpdb;
217
218        static $post_cache_views;
219
220        if ( empty($post_id) ) {
221                if ( isset($GLOBALS['post']) )
222                        $post_id = $GLOBALS['post']->ID;
223        }
224
225        $post_id = intval($post_id);
226        if($post_id==0) return null;
227        if(!isset($post_cache_views[$post_id])){
228        $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
229        $post_views = $xoops_db->get_var($sql);
230        if (!$post_views) {
231                $post_cache_views[$post_id] = 0;
232        }else{
233                $post_cache_views[$post_id] = $post_views;
234        }
235        }
236        $v_count = intval($post_cache_views[$post_id]);
237       
238        if (empty($format)) $format = __('views :%d','xpressme');
239       
240        $ret = sprintf($format,$v_count);
241
242        if ($show) echo $ret; else return $ret;
243}
244
245function set_post_views_count(&$content) {
246        if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
247                post_views_counting();
248        }
249        return $content;
250}
251
252// Set post views given a post ID or post object.
253function post_views_counting($post_id = 0) {
254        global $xoops_db,$wpdb;
255        global $table_prefix;
256        static $views;
257       
258        $post_id = intval($post_id);
259        if ( empty($post_id) && isset($GLOBALS['post']) ){
260                $post_id = $GLOBALS['post']->ID;
261        }
262
263
264        $views_db = get_wp_prefix() . 'views';
265
266        if($post_id==0 || !empty($views[$post_id])) return null;
267       
268        if(!xpress_is_author_view_count()){
269                $current_user_id = $GLOBALS['current_user']->ID;
270                $post_author_id = $GLOBALS['post']->post_author;
271                if ($current_user_id ==$post_author_id) return null;
272        }
273
274    $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
275        $post_views_found = $xoops_db->get_var($sql);
276        if($post_views_found){
277        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
278    }else{
279        $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
280    }
281    $xoops_db->query($sql);
282        return true;
283}
284
285function get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text = '') {
286        global $post,$xpress_config;
287       
288        $blog_encoding = get_option('blog_charset');
289        $text = get_the_content('');
290        $text = strip_shortcodes( $text );
291        $text = apply_filters('the_content', $text);
292        $text = str_replace(']]>', ']]&gt;', $text);
293        $text = strip_tags($text);
294        $is_almost_ascii = ($xpress_config->ascii_judged_rate < round(@(mb_strlen($text, $blog_encoding) / strlen($text)) * 100)) ? true : false;
295        if($is_almost_ascii) {
296                $words = explode(' ', $text, $excerpt_length_word + 1);
297
298                if(count($words) > $excerpt_length_word) {
299                        array_pop($words);
300                        array_push($words, ' ... ');
301                        $text = implode(' ', $words);
302                        if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
303
304                }
305        }
306        elseif(mb_strlen($text, $blog_encoding) > $excerpt_length_character) {
307                $text = mb_substr($text, 0, $xpress_config->excerpt_length_character, $blog_encoding) . ' ... ';
308                if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
309        }
310
311        return $text;
312}
313
314function xpress_the_content($more_link_text = null, $stripteaser = 0, $more_file = '',$show = true)
315{
316        global $post,$xpress_config;
317       
318       
319        if ($xpress_config->is_content_excerpt){
320                $excerpt_length_word = $xpress_config->excerpt_length_word;
321                $excerpt_length_character = $xpress_config->excerpt_length_character;
322                $more_link_text = $xpress_config->more_link_text;
323                $content = get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text);
324        } else {
325                $content = get_the_content($more_link_text,$stripteaser,$more_file);
326                $content = apply_filters('the_content', $content);
327                $content = str_replace(']]>', ']]&gt;', $content);
328        }       
329        if(empty($show)) return $content;
330        echo $content;
331}
332
333function is_xpress_contributor()
334{
335        global $current_user;
336        get_currentuserinfo();
337        if ($current_user->user_level > 3)
338                return true;
339        else
340                return false;
341}
342
343function xpress_post_new_link($link_title,$display = true)
344{
345        $output = '<a href="'. get_xpress_url() . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
346        if ($display)
347                echo $output;
348        else
349                return $output;
350}
351
352function xpress_conditional_title($display = true)
353{
354        $output = __('Main', 'xpressme');
355        if (is_category())
356                $output = sprintf(__('Archive for the &#8216;%s&#8217; Category', 'xpressme'), single_cat_title('', false));
357        if (is_tag())
358                $output = sprintf(__('Posts Tagged &#8216;%s&#8217;', 'xpressme'), single_tag_title('', false) );
359        if (is_day())
360                $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
361        if (is_month())
362                $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
363        if (is_year())
364                $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
365        if (is_author())
366                $output = sprintf(__('Archive for the &#8216;%s&#8217; Author', 'xpressme'), get_author_name( get_query_var('author')));
367        if (is_search())
368                $output = sprintf(__('Search Results of word &#8216;%s&#8217;', 'xpressme'), get_search_query());
369               
370        if ($display)
371                echo $output;
372        else
373                return $output;
374}
375
376?>
Note: See TracBrowser for help on using the repository browser.