XPressME Integration Kit

Trac

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

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

最近の記事内容ブロック 実装
概要処理の部分と、閲覧数の部分は未完です。

File size: 8.1 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        $config = new XPressME_Class();
31        return $config->is_theme_sidebar_disp;
32}       
33
34function xpress_left_arrow_post_link($show = false)
35{
36        $config = new XPressME_Class();
37        $ret = '';
38               
39        if($config->is_left_postnavi_old){
40                $link_title = $config->old_post_link_text;
41                ob_start();
42                if ($config->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 = $config->newer_post_link_text;
50                ob_start();
51                if ($config->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 ($config->is_postnavi_title_disp){
60                $on_mouse_show = $link_title;
61        } else  {
62                if($config->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        $config = new XPressME_Class();
88        $ret = '';             
89       
90        if($config->is_left_postnavi_old){
91                $link_title = $config->newer_post_link_text;
92                ob_start();
93                if ($config->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 = $config->old_post_link_text;
101                ob_start();
102                if ($config->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 ($config->is_postnavi_title_disp){
111                $on_mouse_show = $link_title;
112        } else  {
113                if($config->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        $config = new XPressME_Class();
138        return $config->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// xoops db
151function get_xpress_dir_path()
152{
153        return ABSPATH;
154}
155
156function get_xpress_dir_name()
157{
158        return basename(ABSPATH);
159}
160
161function get_wp_prefix_only()
162{
163        $dir_name = get_xpress_dir_name();
164        $prefix = $dir_name;
165        if ($prefix == 'wordpress') $prefix = 'wp';
166       
167        $prefix = $prefix . '_';
168        return $prefix;
169}
170
171function get_xoops_prefix()
172{
173        global $wpdb;
174       
175        $prefix = $wpdb->prefix;
176        $ret = str_replace(get_wp_prefix_only(),'',$prefix);
177        return $ret;
178}
179
180function get_xpress_modid()
181{
182        global $xoops_db;
183       
184        $modulename = get_xpress_dir_name();   
185        $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
186        $mid = $xoops_db->get_var($sql);
187        return $mid;   
188}
189
190function block_cache_refresh()
191{
192        global $xoops_db;
193        $mid = get_xpress_modid();
194        $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
195        $blocks = $xoops_db->get_results($sql);
196        $mydirname = get_xpress_dir_name();
197        require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
198
199
200        foreach($blocks as $block){
201                $func_file = $block->func_file;
202                $call_theme_function_name = str_replace(".php", "", $func_file);
203                $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
204                $cache_title = str_replace(".php", "", $func_file);
205                $blockID = $block->bid;
206                $options = explode("|", $block->options);
207                                       
208                $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
209                require_once $block_theme_file;
210                $block_render = $call_theme_function_name($options);            //The block name and the called function name should be assumed to be the same name.                   
211                $xml['block'] = $block_render;
212                xpress_block_cache_write($mydirname,$cache_title. $blockID, $xml);
213        }
214}
215
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 $xoops_db;
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 " . get_xoops_prefix() . "views" . " WHERE post_id=$post_id";
233        $post_views = $xoops_db->get_var($sql);
234        if (!$post_views) {
235                $post_cache_views[$post_id] = 0;
236        }else{
237                $post_cache_views[$post_id] = $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
298?>
Note: See TracBrowser for help on using the repository browser.