XPressME Integration Kit

Trac

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

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

XOOPS mainfile.phpのdefine文を事前に読み取りwp-config.phpのDB接続関係を生成することにより、XOOPSシステムを必要なときだけ呼び出す仕組みを作る。
およびイベント通知関係の修正(まだゲストのアクセス権限がないと駄目)

File size: 6.9 KB
Line 
1<?php
2       
3function xpress_credit($show = false)
4{
5        global $xoopsModule,$wp_version;
6       
7        $ret = '<a href="http://www.toemon.com"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xoopsModule->getInfo('version'),$xoopsModule->getInfo('codename')) .'</a>';
8        if (strstr($wp_version,'ME')){
9                $ret .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
10        } else {
11                $ret .= '(included <a href="http://ja.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
12        }
13
14        if (empty($show))
15                return $ret;
16        else
17                echo $ret;
18}
19
20function xpress_convert_time($show = false)
21{
22        $ret =  timer_stop(0) .'sec. ';
23        if (empty($show))
24                return $ret;
25        else
26                echo $ret;
27}
28
29function xpress_is_theme_sidebar_disp(){
30        global $XPressME;
31        return $XPressME->is_theme_sidebar_disp;
32}       
33
34function xpress_left_arrow_post_link($show = false)
35{
36        global $XPressME;
37        $ret = '';
38               
39        if($XPressME->is_left_postnavi_old){
40                $link_title = $XPressME->old_post_link_text;
41                ob_start();
42                if ($XPressME->is_postnavi_title_disp)
43                        previous_post_link('&laquo; %link');
44                else
45                        previous_post_link('&laquo; %link',$link_title);
46                $ret = ob_get_contents();
47                ob_end_clean();
48        } else {
49                $link_title = $XPressME->newer_post_link_text;
50                ob_start();
51                if ($XPressME->is_postnavi_title_disp)
52                        next_post_link('&laquo; %link');
53                else
54                        next_post_link('&laquo; %link',$link_title);
55                $ret = ob_get_contents();
56                ob_end_clean();
57        }
58       
59        if ($XPressME->is_postnavi_title_disp){
60                $on_mouse_show = $link_title;
61        } else  {
62                if($XPressME->is_left_postnavi_old){
63                        ob_start();
64                                previous_post_link('%link');
65                                $on_mouse_show = ob_get_contents();
66                        ob_end_clean();
67                } else {
68                        ob_start();
69                                next_post_link('%link');
70                                $on_mouse_show = ob_get_contents();
71                        ob_end_clean();
72                }
73                $pattern = "<a[^>]*?>(.*)<\/a>";
74                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
75                $on_mouse_show = $body_matches[1];
76        }
77        $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
78
79        if (empty($show))
80                return $ret;
81        else
82                echo $ret;
83}
84
85function xpress_right_arrow_post_link($show = false)
86{
87        global $XPressME;
88        $ret = '';             
89       
90        if($XPressME->is_left_postnavi_old){
91                $link_title = $XPressME->newer_post_link_text;
92                ob_start();
93                if ($XPressME->is_postnavi_title_disp)
94                        next_post_link('%link &raquo;');
95                else
96                        next_post_link('%link &raquo;',$link_title);
97                $ret = ob_get_contents();
98                ob_end_clean();
99        } else {
100                $link_title = $XPressME->old_post_link_text;
101                ob_start();
102                if ($XPressME->is_postnavi_title_disp)
103                        previous_post_link('%link &raquo;');
104                else
105                        previous_post_link('%link &raquo;',$link_title);
106                $ret = ob_get_contents();
107                ob_end_clean();
108        }
109       
110        if ($XPressME->is_postnavi_title_disp){
111                $on_mouse_show = $link_title;
112        } else  {
113                if($XPressME->is_left_postnavi_old){
114                        ob_start();
115                                next_post_link('%link');
116                                $on_mouse_show = ob_get_contents();
117                        ob_end_clean();
118                } else {
119                        ob_start();
120                                previous_post_link('%link');
121                                $on_mouse_show = ob_get_contents();
122                        ob_end_clean();
123                }
124                $pattern = "<a[^>]*?>(.*)<\/a>";
125                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
126                $on_mouse_show = $body_matches[1];
127        }
128        $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
129
130        if (empty($show))
131                return $ret;
132        else
133                echo $ret;     
134}
135
136function xpress_is_author_view_count(){
137        global $XPressME;
138        return $XPressME->is_author_view_count;
139}
140
141function xpress_substr($str, $start, $length, $trimmarker = '...')
142{
143    if (function_exists('mb_substr')){
144        $str2 = mb_substr( $str , $start , $length);
145        return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
146    } else {
147        return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
148    }
149}
150
151
152// views count
153// Set and retrieves post views given a post ID or post object.
154// Retrieves post views given a post ID or post object.
155function xpress_post_views_count($post_id=0,$format= '',$show = true) {
156        global $xoops_db,$wpdb;
157
158        static $post_cache_views;
159
160        if ( empty($post_id) ) {
161                if ( isset($GLOBALS['post']) )
162                        $post_id = $GLOBALS['post']->ID;
163        }
164
165        $post_id = intval($post_id);
166        if($post_id==0) return null;
167        if(!isset($post_cache_views[$post_id])){
168        $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
169        $post_views = $xoops_db->get_var($sql);
170        if (!$post_views) {
171                $post_cache_views[$post_id] = 0;
172        }else{
173                $post_cache_views[$post_id] = $post_views;
174        }
175        }
176        $v_count = intval($post_cache_views[$post_id]);
177       
178        if (empty($format)) $format = __('views :%d','xpressme');
179       
180        $ret = sprintf($format,$v_count);
181
182        if ($show) echo $ret; else return $ret;
183}
184
185function set_post_views_count(&$content) {
186        if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
187                post_views_counting();
188        }
189        return $content;
190}
191
192// Set post views given a post ID or post object.
193function post_views_counting($post_id = 0) {
194        global $table_prefix;
195        static $views;
196       
197        $post_id = intval($post_id);
198        if ( empty($post_id) && isset($GLOBALS['post']) ){
199                $post_id = $GLOBALS['post']->ID;
200        }
201
202
203        $views_db = $table_prefix . "views";
204
205        if($post_id==0 || !empty($views[$post_id])) return null;
206       
207        if(!xpress_is_author_view_count()){
208                $current_user_id = $GLOBALS['current_user']->ID;
209                $post_author_id = $GLOBALS['post']->post_author;
210                if ($current_user_id ==$post_author_id) return null;
211        }
212
213    $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
214    $exist = false;
215    if ($result = $GLOBALS["xoopsDB"]->query($sql)) {
216        while($row = $GLOBALS["xoopsDB"]->fetchArray($result)){
217                $exist = true;
218                break;
219        }
220        }
221        if($exist){
222        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
223    }else{
224        $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
225    }
226    if ($result = $GLOBALS["xoopsDB"]->queryF($sql)) {
227        $views[$post_id] = 1;
228    }
229   
230        return true;
231}
232
233function xpress_the_content($more_link_text = '',$excerpt_size = 0,$show = true)
234{
235        $content = get_the_content();   
236        if($excerpt_size > 0) {
237
238                $content = apply_filters('the_excerpt_rss', $content);
239                $content = strip_tags($content);
240
241                if (mb_strlen($content) > $excerpt_size){
242                        $content = mb_substr($content, 0, $excerpt_size);
243                        $content .= '... ';
244                        if (!empty($more_link_text)) $content .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
245                }
246        }
247        if(empty($show)) return $content;
248        echo $content;
249}
250
251?>
Note: See TracBrowser for help on using the repository browser.