1 | <?php
|
---|
2 | function xpress_user_access_level(){
|
---|
3 | global $current_user;
|
---|
4 |
|
---|
5 | $level = @$current_user->user_level;
|
---|
6 | $role = @$current_user->roles[0];
|
---|
7 | switch ($role){
|
---|
8 | case 'administrator':
|
---|
9 | $role_level = 10;
|
---|
10 | break;
|
---|
11 | case 'editor':
|
---|
12 | $role_level = 7;
|
---|
13 | break;
|
---|
14 | case 'author':
|
---|
15 | $role_level = 2;
|
---|
16 | break;
|
---|
17 | case 'contributor':
|
---|
18 | $role_level = 1;
|
---|
19 | break;
|
---|
20 | default:
|
---|
21 | $role_level = 0;
|
---|
22 | }
|
---|
23 |
|
---|
24 | if ($level > $role_level){
|
---|
25 | return $level;
|
---|
26 | } else {
|
---|
27 | return $role_level;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | function xpress_is_contributor()
|
---|
34 | {
|
---|
35 | global $current_user;
|
---|
36 | get_currentuserinfo();
|
---|
37 | if (xpress_user_access_level() > 3)
|
---|
38 | return true;
|
---|
39 | else
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 |
|
---|
43 | function xpress_is_multiblog() {
|
---|
44 | global $xoops_config;
|
---|
45 |
|
---|
46 | if (function_exists('is_multisite') && is_multisite()) return true;
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 |
|
---|
50 | function xpress_is_multiblog_root() {
|
---|
51 | global $blog_id;
|
---|
52 | if ( xpress_is_multiblog() && $blog_id == 1){
|
---|
53 | return true;
|
---|
54 | } else {
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | function xpress_is_wp_version($operator='==',$comp_version){
|
---|
60 | global $xoops_config;
|
---|
61 | return version_compare($xoops_config->wp_version, $comp_version, $operator);
|
---|
62 | }
|
---|
63 |
|
---|
64 | function xpress_is_theme_sidebar_disp(){
|
---|
65 | global $xpress_config;
|
---|
66 | if (is_wordpress_style()) return true;
|
---|
67 | return $xpress_config->is_theme_sidebar_disp;
|
---|
68 | }
|
---|
69 |
|
---|
70 | function xpress_is_author_view_count(){
|
---|
71 | global $xpress_config;
|
---|
72 | return $xpress_config->is_author_view_count;
|
---|
73 | }
|
---|
74 |
|
---|
75 | function xpress_is_multi_user(){
|
---|
76 | global $xpress_config;
|
---|
77 | return $xpress_config->is_multi_user;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | function xpress_the_title($args = '')
|
---|
82 | {
|
---|
83 | $defaults = array(
|
---|
84 | 'echo' => 1
|
---|
85 | );
|
---|
86 | $r = wp_parse_args( $args, $defaults );
|
---|
87 |
|
---|
88 | extract( $r );
|
---|
89 |
|
---|
90 | $output = '<div class ="xpress-post-header">' . "\n";
|
---|
91 |
|
---|
92 | if (function_exists('hotDates')) {
|
---|
93 | ob_start();
|
---|
94 | hotDates();
|
---|
95 | $output .= ob_get_contents();
|
---|
96 | ob_end_clean();
|
---|
97 | }
|
---|
98 | $output .= '<div class ="xpress-post-title">' . "\n";
|
---|
99 | $output .= '<h2><a href="';
|
---|
100 | ob_start();
|
---|
101 | the_permalink();
|
---|
102 | $output .= ob_get_contents();
|
---|
103 | ob_end_clean();
|
---|
104 |
|
---|
105 | if(function_exists('the_title_attribute')){
|
---|
106 | $title = the_title_attribute('echo=0');
|
---|
107 | } else {
|
---|
108 | ob_start();
|
---|
109 | the_title();
|
---|
110 | $title = ob_get_contents();
|
---|
111 | ob_end_clean();
|
---|
112 | }
|
---|
113 |
|
---|
114 | $output .= '" rel="bookmark" title="';
|
---|
115 | $output .= sprintf(__('Permanent Link to %s', 'xpress'), $title);
|
---|
116 | $output .= '">';
|
---|
117 | $output .= $title;
|
---|
118 | $output .= '</a></h2>' . "\n";
|
---|
119 | $output .= '</div>' . "\n";
|
---|
120 | $output .= '</div>' . "\n";
|
---|
121 |
|
---|
122 | if ($echo)
|
---|
123 | echo $output;
|
---|
124 | else
|
---|
125 | return $output;
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | function xpress_selected_author($args ='' ) {
|
---|
130 | $defaults = array(
|
---|
131 | 'echo' => 1
|
---|
132 | );
|
---|
133 | $r = wp_parse_args( $args, $defaults );
|
---|
134 |
|
---|
135 | extract( $r );
|
---|
136 |
|
---|
137 | $output = '';
|
---|
138 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
139 | if (!empty($_COOKIE[$author_cookie])){
|
---|
140 | $uid = intval($_COOKIE[$author_cookie]);
|
---|
141 | $user_info = get_userdata($uid);
|
---|
142 | $output = $user_info->display_name;
|
---|
143 | }
|
---|
144 | if ($echo)
|
---|
145 | echo $output;
|
---|
146 | else
|
---|
147 | return $output;
|
---|
148 |
|
---|
149 | }
|
---|
150 | function xpress_selected_author_id($args ='' ) {
|
---|
151 | $defaults = array(
|
---|
152 | 'echo' => 1
|
---|
153 | );
|
---|
154 | $r = wp_parse_args( $args, $defaults );
|
---|
155 |
|
---|
156 | extract( $r );
|
---|
157 | $output = '';
|
---|
158 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
159 | if (!empty($_COOKIE[$author_cookie])){
|
---|
160 | $output = intval($_COOKIE[$author_cookie]);
|
---|
161 | } else {
|
---|
162 | $output = '';
|
---|
163 | }
|
---|
164 | if ($echo)
|
---|
165 | echo $output;
|
---|
166 | else
|
---|
167 | return $output;
|
---|
168 | }
|
---|
169 |
|
---|
170 | function xpress_now_user_level($args ='' ) {
|
---|
171 | global $current_user;
|
---|
172 | $defaults = array(
|
---|
173 | 'echo' => 1
|
---|
174 | );
|
---|
175 | $r = wp_parse_args( $args, $defaults );
|
---|
176 |
|
---|
177 | extract( $r );
|
---|
178 |
|
---|
179 | $output = xpress_user_access_level();
|
---|
180 | if ($echo)
|
---|
181 | echo $output;
|
---|
182 | else
|
---|
183 | return $output;
|
---|
184 | }
|
---|
185 |
|
---|
186 | function xpress_credit($args ='')
|
---|
187 | {
|
---|
188 | global $wp_version , $xoops_config;
|
---|
189 | if ($xoops_config->is_wpmu) {
|
---|
190 | global $wpmu_version;
|
---|
191 | }
|
---|
192 |
|
---|
193 | $defaults = array(
|
---|
194 | 'echo' => 1,
|
---|
195 | 'no_link' => 0
|
---|
196 | );
|
---|
197 | $r = wp_parse_args( $args, $defaults );
|
---|
198 |
|
---|
199 | extract( $r );
|
---|
200 |
|
---|
201 | $xpress_version = $xoops_config->module_version;
|
---|
202 | $xpress_codename = $xoops_config->module_codename;
|
---|
203 | if ($no_link){
|
---|
204 | if ($xoops_config->is_wpmu) {
|
---|
205 | $output = 'XPressMU Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
|
---|
206 | $output .= '(included WordPress MU ' . $wpmu_version. ')';
|
---|
207 | } else {
|
---|
208 | $output = 'XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
|
---|
209 | if (strstr($wp_version,'ME')){
|
---|
210 | $output .= '(included WordPress ' . $wp_version . ')';
|
---|
211 | } else {
|
---|
212 | $output .= '(included WordPress ' . $wp_version . ')';
|
---|
213 | }
|
---|
214 | }
|
---|
215 | } else {
|
---|
216 | if ($xoops_config->is_wpmu) {
|
---|
217 | $output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressMU Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
|
---|
218 | $output .= '(included <a href="http://mu.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress MU ' . $wpmu_version . '</a>)';
|
---|
219 | } else {
|
---|
220 | $output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
|
---|
221 | if (strstr($wp_version,'ME')){
|
---|
222 | $output .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
223 | } else {
|
---|
224 | $output .= '(included <a href="http://wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 | if ($echo)
|
---|
229 | echo $output;
|
---|
230 | else
|
---|
231 | return $output;
|
---|
232 | }
|
---|
233 |
|
---|
234 | function xpress_convert_time($args ='')
|
---|
235 | {
|
---|
236 | $defaults = array(
|
---|
237 | 'echo' => 1,
|
---|
238 | 'format' => '(%.3f sec.)'
|
---|
239 | );
|
---|
240 | $r = wp_parse_args( $args, $defaults );
|
---|
241 |
|
---|
242 | extract( $r );
|
---|
243 |
|
---|
244 | $output = sprintf($format,timer_stop(0));
|
---|
245 | if ($echo)
|
---|
246 | echo $output;
|
---|
247 | else
|
---|
248 | return $output;
|
---|
249 | }
|
---|
250 |
|
---|
251 | function xpress_left_arrow_post_link($args ='')
|
---|
252 | {
|
---|
253 | global $xpress_config;
|
---|
254 | $defaults = array(
|
---|
255 | 'echo' => 1
|
---|
256 | );
|
---|
257 | $r = wp_parse_args( $args, $defaults );
|
---|
258 |
|
---|
259 | extract( $r );
|
---|
260 |
|
---|
261 | $ret = '';
|
---|
262 |
|
---|
263 | if($xpress_config->is_left_postnavi_old){
|
---|
264 | $link_title = $xpress_config->old_post_link_text;
|
---|
265 | ob_start();
|
---|
266 | if ($xpress_config->is_postnavi_title_disp)
|
---|
267 | previous_post_link('« %link');
|
---|
268 | else
|
---|
269 | previous_post_link('« %link',$link_title);
|
---|
270 | $ret = ob_get_contents();
|
---|
271 | ob_end_clean();
|
---|
272 | ob_start();
|
---|
273 | previous_post_link('%link',$link_title);
|
---|
274 | $GLOBALS['left_arrow_post_link'] = ob_get_contents();
|
---|
275 | ob_end_clean();
|
---|
276 |
|
---|
277 | } else {
|
---|
278 | $link_title = $xpress_config->newer_post_link_text;
|
---|
279 | ob_start();
|
---|
280 | if ($xpress_config->is_postnavi_title_disp)
|
---|
281 | next_post_link('« %link');
|
---|
282 | else
|
---|
283 | next_post_link('« %link',$link_title);
|
---|
284 | $ret = ob_get_contents();
|
---|
285 | ob_end_clean();
|
---|
286 | ob_start();
|
---|
287 | next_post_link('%link',$link_title);
|
---|
288 | $GLOBALS['left_arrow_post_link'] = ob_get_contents();
|
---|
289 | ob_end_clean();
|
---|
290 |
|
---|
291 | }
|
---|
292 |
|
---|
293 | if ($xpress_config->is_postnavi_title_disp){
|
---|
294 | $on_mouse_show = $link_title;
|
---|
295 | } else {
|
---|
296 | if($xpress_config->is_left_postnavi_old){
|
---|
297 | ob_start();
|
---|
298 | previous_post_link('%link');
|
---|
299 | $on_mouse_show = ob_get_contents();
|
---|
300 | ob_end_clean();
|
---|
301 | } else {
|
---|
302 | ob_start();
|
---|
303 | next_post_link('%link');
|
---|
304 | $on_mouse_show = ob_get_contents();
|
---|
305 | ob_end_clean();
|
---|
306 | }
|
---|
307 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
308 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
309 | $on_mouse_show = $body_matches[1];
|
---|
310 | }
|
---|
311 | $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
312 |
|
---|
313 | if ($echo)
|
---|
314 | echo $output;
|
---|
315 | else
|
---|
316 | return $output;
|
---|
317 | }
|
---|
318 |
|
---|
319 | function xpress_right_arrow_post_link($args ='')
|
---|
320 | {
|
---|
321 | global $xpress_config;
|
---|
322 | $defaults = array(
|
---|
323 | 'echo' => 1
|
---|
324 | );
|
---|
325 | $r = wp_parse_args( $args, $defaults );
|
---|
326 |
|
---|
327 | extract( $r );
|
---|
328 |
|
---|
329 | $ret = '';
|
---|
330 |
|
---|
331 | if($xpress_config->is_left_postnavi_old){
|
---|
332 | $link_title = $xpress_config->newer_post_link_text;
|
---|
333 | ob_start();
|
---|
334 | if ($xpress_config->is_postnavi_title_disp)
|
---|
335 | next_post_link('%link »');
|
---|
336 | else
|
---|
337 | next_post_link('%link »',$link_title);
|
---|
338 | $ret = ob_get_contents();
|
---|
339 | ob_end_clean();
|
---|
340 | ob_start();
|
---|
341 | next_post_link('%link',$link_title);
|
---|
342 | $GLOBALS['right_arrow_post_link'] = ob_get_contents();
|
---|
343 | ob_end_clean();
|
---|
344 |
|
---|
345 | } else {
|
---|
346 | $link_title = $xpress_config->old_post_link_text;
|
---|
347 | ob_start();
|
---|
348 | if ($xpress_config->is_postnavi_title_disp)
|
---|
349 | previous_post_link('%link »');
|
---|
350 | else
|
---|
351 | previous_post_link('%link »',$link_title);
|
---|
352 | $ret = ob_get_contents();
|
---|
353 | ob_end_clean();
|
---|
354 | ob_start();
|
---|
355 | previous_post_link('%link',$link_title);
|
---|
356 | $GLOBALS['right_arrow_post_link'] = ob_get_contents();
|
---|
357 | ob_end_clean();
|
---|
358 |
|
---|
359 | }
|
---|
360 |
|
---|
361 | if ($xpress_config->is_postnavi_title_disp){
|
---|
362 | $on_mouse_show = $link_title;
|
---|
363 | } else {
|
---|
364 | if($xpress_config->is_left_postnavi_old){
|
---|
365 | ob_start();
|
---|
366 | next_post_link('%link');
|
---|
367 | $on_mouse_show = ob_get_contents();
|
---|
368 | ob_end_clean();
|
---|
369 | } else {
|
---|
370 | ob_start();
|
---|
371 | previous_post_link('%link');
|
---|
372 | $on_mouse_show = ob_get_contents();
|
---|
373 | ob_end_clean();
|
---|
374 | }
|
---|
375 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
376 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
377 | $on_mouse_show = $body_matches[1];
|
---|
378 | }
|
---|
379 | $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
380 |
|
---|
381 | if ($echo)
|
---|
382 | echo $output;
|
---|
383 | else
|
---|
384 | return $output;
|
---|
385 | }
|
---|
386 | // page link
|
---|
387 | function xpress_left_arrow_posts_link($args ='')
|
---|
388 | {
|
---|
389 | global $xpress_config;
|
---|
390 | $defaults = array(
|
---|
391 | 'echo' => 1
|
---|
392 | );
|
---|
393 | $r = wp_parse_args( $args, $defaults );
|
---|
394 |
|
---|
395 | extract( $r );
|
---|
396 |
|
---|
397 | $output = '';
|
---|
398 |
|
---|
399 | if($xpress_config->is_left_page_navi_old){
|
---|
400 | $link_title = $xpress_config->old_page_link_text;
|
---|
401 | ob_start();
|
---|
402 | next_posts_link("« $link_title");
|
---|
403 | $output = ob_get_contents();
|
---|
404 | ob_end_clean();
|
---|
405 | } else {
|
---|
406 | $link_title = $xpress_config->newer_page_link_text;
|
---|
407 | ob_start();
|
---|
408 | previous_posts_link("« $link_title");
|
---|
409 | $output = ob_get_contents();
|
---|
410 | ob_end_clean();
|
---|
411 | }
|
---|
412 |
|
---|
413 | if ($echo)
|
---|
414 | echo $output;
|
---|
415 | else
|
---|
416 | return $output;
|
---|
417 | }
|
---|
418 |
|
---|
419 | function xpress_right_arrow_posts_link($args ='')
|
---|
420 | {
|
---|
421 | global $xpress_config;
|
---|
422 | $defaults = array(
|
---|
423 | 'echo' => 1
|
---|
424 | );
|
---|
425 | $r = wp_parse_args( $args, $defaults );
|
---|
426 |
|
---|
427 | extract( $r );
|
---|
428 |
|
---|
429 | $output = '';
|
---|
430 |
|
---|
431 | if($xpress_config->is_left_page_navi_old){
|
---|
432 | $link_title = $xpress_config->newer_page_link_text;
|
---|
433 | ob_start();
|
---|
434 | previous_posts_link("$link_title »");
|
---|
435 | $output = ob_get_contents();
|
---|
436 | ob_end_clean();
|
---|
437 | } else {
|
---|
438 | $link_title = $xpress_config->old_page_link_text;
|
---|
439 | ob_start();
|
---|
440 | next_posts_link("$link_title »");
|
---|
441 | $output = ob_get_contents();
|
---|
442 | ob_end_clean();
|
---|
443 | }
|
---|
444 |
|
---|
445 | if ($echo)
|
---|
446 | echo $output;
|
---|
447 | else
|
---|
448 | return $output;
|
---|
449 | }
|
---|
450 |
|
---|
451 | function xpress_substr($str, $start, $length, $trimmarker = '...')
|
---|
452 | {
|
---|
453 | if (function_exists('mb_substr')){
|
---|
454 | $str2 = mb_substr( $str , $start , $length);
|
---|
455 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
|
---|
456 | } else {
|
---|
457 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
|
---|
458 | }
|
---|
459 | }
|
---|
460 |
|
---|
461 |
|
---|
462 | // views count
|
---|
463 | // Set and retrieves post views given a post ID or post object.
|
---|
464 | // Retrieves post views given a post ID or post object.
|
---|
465 | function xpress_post_views_count($args ='') {
|
---|
466 | global $xoops_db,$wpdb;
|
---|
467 | global $blog_id;
|
---|
468 | static $post_cache_views;
|
---|
469 |
|
---|
470 | $defaults = array(
|
---|
471 | 'post_id' => 0,
|
---|
472 | 'format'=> __('views :%d','xpressme'),
|
---|
473 | 'echo' => 1
|
---|
474 | );
|
---|
475 | $r = wp_parse_args( $args, $defaults );
|
---|
476 |
|
---|
477 | extract( $r );
|
---|
478 |
|
---|
479 | if ( empty($post_id) ) {
|
---|
480 | if ( isset($GLOBALS['post']) )
|
---|
481 | $post_id = $GLOBALS['post']->ID;
|
---|
482 | }
|
---|
483 |
|
---|
484 | $post_id = intval($post_id);
|
---|
485 | if($post_id==0) return null;
|
---|
486 | if(!isset($post_cache_views[$post_id])){
|
---|
487 | if (is_null($blog_id)){
|
---|
488 | $blog_where = '';
|
---|
489 | } else {
|
---|
490 | $blog_where = ' AND blog_id = '. $blog_id;
|
---|
491 | }
|
---|
492 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id " . $blog_where;
|
---|
493 | $post_views = $xoops_db->get_var($sql);
|
---|
494 | if (!$post_views) {
|
---|
495 | $post_cache_views[$post_id] = 0;
|
---|
496 | }else{
|
---|
497 | $post_cache_views[$post_id] = $post_views;
|
---|
498 | }
|
---|
499 | }
|
---|
500 | $v_count = intval($post_cache_views[$post_id]);
|
---|
501 |
|
---|
502 | if (empty($format)) $format = __('views :%d','xpressme');
|
---|
503 |
|
---|
504 | $output = sprintf($format,$v_count);
|
---|
505 |
|
---|
506 | if ($echo)
|
---|
507 | echo $output;
|
---|
508 | else
|
---|
509 | return $output;
|
---|
510 | }
|
---|
511 |
|
---|
512 | function set_post_views_count($content) {
|
---|
513 | if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
|
---|
514 | post_views_counting();
|
---|
515 | }
|
---|
516 | return $content;
|
---|
517 | }
|
---|
518 |
|
---|
519 | // Set post views given a post ID or post object.
|
---|
520 | function post_views_counting($post_id = 0) {
|
---|
521 | global $xoops_db,$wpdb;
|
---|
522 | global $table_prefix;
|
---|
523 | global $blog_id;
|
---|
524 | static $views;
|
---|
525 |
|
---|
526 | $post_id = intval($post_id);
|
---|
527 | if ( empty($post_id) && isset($GLOBALS['post']) ){
|
---|
528 | $post_id = $GLOBALS['post']->ID;
|
---|
529 | }
|
---|
530 |
|
---|
531 | $views_db = get_wp_prefix() . 'views';
|
---|
532 | if (is_null($blog_id)) $blog_id = 0;
|
---|
533 |
|
---|
534 | if($post_id==0 || !empty($views[$post_id])) return null;
|
---|
535 |
|
---|
536 | if(!xpress_is_author_view_count()){
|
---|
537 | $current_user_id = $GLOBALS['current_user']->ID;
|
---|
538 | $post_author_id = $GLOBALS['post']->post_author;
|
---|
539 | if ($current_user_id ==$post_author_id) return null;
|
---|
540 | }
|
---|
541 | if (is_null($blog_id)){
|
---|
542 | $blog_where = '';
|
---|
543 | } else {
|
---|
544 | $blog_where = ' AND blog_id = ' . $blog_id;
|
---|
545 | }
|
---|
546 | $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id" . $blog_where;
|
---|
547 | $post_views_found = $xoops_db->get_var($sql);
|
---|
548 | if($post_views_found){
|
---|
549 | $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id" . $blog_where;
|
---|
550 | }else{
|
---|
551 | if (is_null($blog_id)){
|
---|
552 | $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
|
---|
553 | } else {
|
---|
554 | $sql = "INSERT INTO " . $views_db . " (blog_id, post_id, post_views) VALUES ($blog_id, $post_id, 1)";
|
---|
555 | }
|
---|
556 | }
|
---|
557 | $xoops_db->query($sql);
|
---|
558 | return true;
|
---|
559 | }
|
---|
560 |
|
---|
561 | function get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text = '') {
|
---|
562 | global $post,$xpress_config;
|
---|
563 |
|
---|
564 | $blog_encoding = get_option('blog_charset');
|
---|
565 | $text = get_the_content('');
|
---|
566 | if (function_exists('strip_shortcodes')){ //@since WP2.5
|
---|
567 | $text = strip_shortcodes( $text );
|
---|
568 | }
|
---|
569 | $text = apply_filters('the_content', $text);
|
---|
570 | $text = str_replace(']]>', ']]>', $text);
|
---|
571 | $text = strip_tags($text);
|
---|
572 | $is_almost_ascii = ($xpress_config->ascii_judged_rate < round(@(mb_strlen($text, $blog_encoding) / strlen($text)) * 100)) ? true : false;
|
---|
573 | if($is_almost_ascii) {
|
---|
574 | $words = explode(' ', $text, $excerpt_length_word + 1);
|
---|
575 |
|
---|
576 | if(count($words) > $excerpt_length_word) {
|
---|
577 | array_pop($words);
|
---|
578 | array_push($words, ' ... ');
|
---|
579 | $text = implode(' ', $words);
|
---|
580 | if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
|
---|
581 |
|
---|
582 | }
|
---|
583 | }
|
---|
584 | elseif(mb_strlen($text, $blog_encoding) > $excerpt_length_character) {
|
---|
585 | $text = mb_substr($text, 0, $xpress_config->excerpt_length_character, $blog_encoding) . ' ... ';
|
---|
586 | if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
|
---|
587 | }
|
---|
588 |
|
---|
589 | return $text;
|
---|
590 | }
|
---|
591 |
|
---|
592 | function xpress_the_content($args ='')
|
---|
593 | {
|
---|
594 | global $post,$xpress_config;
|
---|
595 |
|
---|
596 | $defaults = array(
|
---|
597 | 'more_link_text'=> $xpress_config->more_link_text,
|
---|
598 | 'stripteaser' => 0,
|
---|
599 | 'more_file' => '',
|
---|
600 | 'configration_select' => 1,
|
---|
601 | 'do_excerpt' => 0,
|
---|
602 | 'excerpt_length_word' => $xpress_config->excerpt_length_word ,
|
---|
603 | 'excerpt_length_character' => $xpress_config->excerpt_length_character ,
|
---|
604 | 'excerpt_more_link_text' => $xpress_config->excerpt_more_link_text ,
|
---|
605 | 'echo' => 1
|
---|
606 | );
|
---|
607 | $r = wp_parse_args( $args, $defaults );
|
---|
608 |
|
---|
609 | extract( $r );
|
---|
610 |
|
---|
611 | if ($configration_select){
|
---|
612 | if ($xpress_config->is_content_excerpt)
|
---|
613 | $do_excerpt = 1;
|
---|
614 | else
|
---|
615 | $do_excerpt = 0;
|
---|
616 | }
|
---|
617 |
|
---|
618 | if ($do_excerpt){
|
---|
619 | $content = get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$excerpt_more_link_text);
|
---|
620 | } else {
|
---|
621 | $content = get_the_content($more_link_text,$stripteaser,$more_file);
|
---|
622 | $content = apply_filters('the_content', $content);
|
---|
623 | $content = str_replace(']]>', ']]>', $content);
|
---|
624 | }
|
---|
625 | if ($echo)
|
---|
626 | echo $content;
|
---|
627 | else
|
---|
628 | return $content;
|
---|
629 | }
|
---|
630 |
|
---|
631 | function xpress_post_new_link($args ='')
|
---|
632 | {
|
---|
633 | global $xoops_config;
|
---|
634 |
|
---|
635 | $defaults = array(
|
---|
636 | 'link_title'=> 'Post New',
|
---|
637 | 'echo' => 1
|
---|
638 | );
|
---|
639 | $r = wp_parse_args( $args, $defaults );
|
---|
640 |
|
---|
641 | extract( $r );
|
---|
642 |
|
---|
643 |
|
---|
644 | if (xpress_is_wp_version('>=','2.1')){
|
---|
645 | $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
|
---|
646 | } else {
|
---|
647 | $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post.php' . '">' . $link_title . '</a>';
|
---|
648 | }
|
---|
649 | if ($echo)
|
---|
650 | echo $output;
|
---|
651 | else
|
---|
652 | return $output;
|
---|
653 | }
|
---|
654 |
|
---|
655 | function xpress_conditional_title($args ='')
|
---|
656 | {
|
---|
657 | $defaults = array(
|
---|
658 | 'echo' => 1
|
---|
659 | );
|
---|
660 | $r = wp_parse_args( $args, $defaults );
|
---|
661 |
|
---|
662 | extract( $r );
|
---|
663 |
|
---|
664 | $selected_author = xpress_selected_author('echo=0');
|
---|
665 |
|
---|
666 | $output = __('Main', 'xpressme');
|
---|
667 | $output = '';
|
---|
668 | if (is_category())
|
---|
669 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpressme'), single_cat_title('', false));
|
---|
670 | if (function_exists( 'is_tag' )){
|
---|
671 | if (is_tag())
|
---|
672 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpressme'), single_tag_title('', false) );
|
---|
673 | }
|
---|
674 | if (is_day())
|
---|
675 | $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
|
---|
676 | if (is_month())
|
---|
677 | $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
|
---|
678 | if (is_year())
|
---|
679 | $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
|
---|
680 | if (is_author()){
|
---|
681 | if (empty($selected_author))
|
---|
682 | $output = sprintf(__('Archive for the ‘%s’ Author', 'xpressme'), get_author_name( get_query_var('author')));
|
---|
683 | }
|
---|
684 | if (is_search())
|
---|
685 | $output = sprintf(__('Search Results of word ‘%s’', 'xpressme'), get_search_query());
|
---|
686 |
|
---|
687 | if (!empty($selected_author)){
|
---|
688 | $selected_id = xpress_selected_author_id('echo=0');
|
---|
689 | // $output = get_avatar($selected_id,$size = '32') . sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
|
---|
690 | if (empty($output))
|
---|
691 | $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) ;
|
---|
692 | else
|
---|
693 | $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
|
---|
694 | }
|
---|
695 | if ($echo)
|
---|
696 | echo $output;
|
---|
697 | else
|
---|
698 | return $output;
|
---|
699 | }
|
---|
700 |
|
---|
701 | // The content of the trackback/pingback to the post is returned by the list.
|
---|
702 | function xpress_pings_list($args =''){
|
---|
703 | $defaults = array(
|
---|
704 | 'echo' => 1
|
---|
705 | );
|
---|
706 | $r = wp_parse_args( $args, $defaults );
|
---|
707 |
|
---|
708 | extract( $r );
|
---|
709 |
|
---|
710 | $trackbacks = xpress_get_pings();
|
---|
711 | if (! empty($trackbacks)) {
|
---|
712 | $output = '<ol id="xpress_pingslist"> ';
|
---|
713 |
|
---|
714 | foreach ($trackbacks as $trackback){
|
---|
715 | $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" ;
|
---|
716 |
|
---|
717 | $output .= '<li>';
|
---|
718 | $output .= $list ;
|
---|
719 | $output .= '</li>';
|
---|
720 |
|
---|
721 | }
|
---|
722 | $output .= '</ol>' ;
|
---|
723 | } else {
|
---|
724 | $output = '';
|
---|
725 | }
|
---|
726 |
|
---|
727 | if ($echo)
|
---|
728 | echo $output;
|
---|
729 | else
|
---|
730 | return $output;
|
---|
731 | }
|
---|
732 |
|
---|
733 | // The amount of the trackback/pingback to the post is returned.
|
---|
734 | function xpress_pings_number( $args ='' ) {
|
---|
735 | $defaults = array(
|
---|
736 | 'zero' => __('No Trackback/Pingback', 'xpressme'),
|
---|
737 | 'one' => __('One Trackback/Pingback', 'xpressme'),
|
---|
738 | 'more' => __('% TrackBack/Pingback', 'xpressme'),
|
---|
739 | 'deprecated' => '',
|
---|
740 | 'echo' => 1
|
---|
741 | );
|
---|
742 | $r = wp_parse_args( $args, $defaults );
|
---|
743 |
|
---|
744 | extract( $r );
|
---|
745 |
|
---|
746 | $pings = xpress_get_pings();
|
---|
747 | if (empty($pings)){
|
---|
748 | $number = 0;
|
---|
749 | }else {
|
---|
750 | $number = count($pings);
|
---|
751 | }
|
---|
752 | if ( $number > 1 )
|
---|
753 | $output = str_replace('%', number_format_i18n($number), $more);
|
---|
754 | elseif ( $number == 0 )
|
---|
755 | $output = $zero;
|
---|
756 | else // must be one
|
---|
757 | $output = $one;
|
---|
758 |
|
---|
759 | if ($echo)
|
---|
760 | echo $output;
|
---|
761 | else
|
---|
762 | return $output;
|
---|
763 | }
|
---|
764 |
|
---|
765 | // xpress_get_pings() is a subfunction used with xpress_pings_number() and xpress_pings_list().
|
---|
766 | function xpress_get_pings()
|
---|
767 | {
|
---|
768 | global $withcomments, $post, $wpdb, $id, $trackback, $user_login, $user_ID, $user_identity;
|
---|
769 |
|
---|
770 | if ( ! (is_single() || is_page() || $withcomments) )
|
---|
771 | return;
|
---|
772 |
|
---|
773 | /** @todo Use API instead of SELECTs. */
|
---|
774 | if ( $user_ID) {
|
---|
775 | $trackbacks = $wpdb->get_results(sprintf("SELECT * , UNIX_TIMESTAMP(comment_date) AS comment_timestamp ,UNIX_TIMESTAMP(comment_date_gmt) AS comment_timestamp_gmt 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));
|
---|
776 | } else if ( empty($trackback_author) ) {
|
---|
777 | $trackbacks = $wpdb->get_results(sprintf("SELECT * , UNIX_TIMESTAMP(comment_date) AS comment_timestamp ,UNIX_TIMESTAMP(comment_date_gmt) AS comment_timestamp_gmt 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));
|
---|
778 | } else {
|
---|
779 | $trackbacks = $wpdb->get_results(sprintf("SELECT * , UNIX_TIMESTAMP(comment_date) AS comment_timestamp ,UNIX_TIMESTAMP(comment_date_gmt) AS comment_timestamp_gmt 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));
|
---|
780 | }
|
---|
781 |
|
---|
782 | if ($trackbacks){
|
---|
783 | $ret = array();
|
---|
784 | foreach ($trackbacks as $trackback){
|
---|
785 |
|
---|
786 | $pattern = '<strong>(.*)<\/strong>(.*)';
|
---|
787 | if ( preg_match ( "/".$pattern."/i", $trackback->comment_content , $match ) ){
|
---|
788 | $title = $match[1];
|
---|
789 | $content = $match[2];
|
---|
790 | }
|
---|
791 | if (empty($title)) $title = $trackback->comment_author;
|
---|
792 |
|
---|
793 |
|
---|
794 | $row_data = array(
|
---|
795 | 'ID' => $trackback->comment_ID ,
|
---|
796 | 'post_ID' => $trackback->comment_post_ID ,
|
---|
797 | 'site_name' => $trackback->comment_author ,
|
---|
798 | 'site_url' => $trackback->comment_author_url ,
|
---|
799 | 'title' => $title ,
|
---|
800 | 'content' => $content ,
|
---|
801 | 'date' => $trackback->comment_timestamp ,
|
---|
802 | 'date_gmt' => $trackback->comment_timestamp_gmt ,
|
---|
803 | 'agent' => $trackback->comment_agent ,
|
---|
804 | 'type' => $trackback->comment_type ,
|
---|
805 | 'IP' => $trackback->comment_author_IP ,
|
---|
806 | );
|
---|
807 | array_push($ret,$row_data);
|
---|
808 | }
|
---|
809 | return $ret;
|
---|
810 | }
|
---|
811 | return false;
|
---|
812 | }
|
---|
813 |
|
---|
814 | function xpress_get_calendar($args = '') {
|
---|
815 | global $wpdb, $m, $monthnum, $year, $wp_locale, $posts , $xoops_config;
|
---|
816 |
|
---|
817 | $defaults = array(
|
---|
818 | sun_color => '#DB0000',
|
---|
819 | sat_color => '#004D99',
|
---|
820 | initial => true
|
---|
821 | );
|
---|
822 | $r = wp_parse_args( $args, $defaults );
|
---|
823 |
|
---|
824 | extract( $r );
|
---|
825 |
|
---|
826 | ob_start();
|
---|
827 | get_calendar(true);
|
---|
828 | $calendar = ob_get_contents();
|
---|
829 | ob_end_clean();
|
---|
830 | $calendar = preg_replace('/<th abbr=/', '<th align="center" abbr=', $calendar); //week name align center
|
---|
831 | $calendar = preg_replace('/<td>/', '<td align="center">', $calendar); //days align center
|
---|
832 | $calendar = preg_replace('/<td id="today">/', '<td id="today" align="center">', $calendar); //today align center
|
---|
833 | $calendar = preg_replace('/<span style="color:[^>]*>/', '', $calendar); //wp2011 color delete
|
---|
834 | $calendar = preg_replace('/<\/span>/', '', $calendar); //wp2011 color delete
|
---|
835 |
|
---|
836 | $week_begins = intval(get_option('start_of_week'));
|
---|
837 | $head_pattrn = '<thead>\s*<tr>\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*<\/tr>\s*<\/thead>';
|
---|
838 | if(preg_match('/'. $head_pattrn . '/s' ,$calendar,$head_match)){
|
---|
839 | $sun_index = 1 - $week_begins;
|
---|
840 | if ($sun_index < 1) $sun_index = $sun_index +7;
|
---|
841 | $sat_index = 7 - $week_begins;
|
---|
842 | if ($sat_index < 1) $sat_index = $sat_index +7;
|
---|
843 |
|
---|
844 | $sun_head = $head_match[$sun_index];
|
---|
845 | $sat_head = $head_match[$sat_index];
|
---|
846 |
|
---|
847 | $pattrn = '(<th[^>]*>)(.*)(<\/th>)';
|
---|
848 | if(preg_match('/'. $pattrn . '/' ,$sun_head,$sun_match)){
|
---|
849 | $sun_head_after = $sun_match[1] . '<span style="color: ' . $sun_color . '">' . $sun_match[2] . '</span>'. $sun_match[3];
|
---|
850 | $calendar = str_replace($sun_head,$sun_head_after,$calendar);
|
---|
851 | }
|
---|
852 | if(preg_match('/'. $pattrn . '/' ,$sat_head,$sat_match)){
|
---|
853 | $sat_head_after = $sat_match[1] . '<span style="color: ' . $sat_color . '">' . $sat_match[2] . '</span>'. $sat_match[3];
|
---|
854 | $calendar = str_replace($sat_head,$sat_head_after,$calendar);
|
---|
855 | }
|
---|
856 | }
|
---|
857 | return $calendar;
|
---|
858 | }
|
---|
859 | ?> |
---|