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