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