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 | function xpress_is_contributor()
|
---|
32 | {
|
---|
33 | global $current_user;
|
---|
34 | get_currentuserinfo();
|
---|
35 | if (xpress_user_access_level() > 3)
|
---|
36 | return true;
|
---|
37 | else
|
---|
38 | return false;
|
---|
39 | }
|
---|
40 |
|
---|
41 | function xpress_is_multiblog() {
|
---|
42 | if (function_exists('is_multisite') && is_multisite()) return true;
|
---|
43 | return false;
|
---|
44 | }
|
---|
45 |
|
---|
46 | function xpress_is_multiblog_root() {
|
---|
47 | global $blog_id;
|
---|
48 | if ( xpress_is_multiblog() && $blog_id == BLOG_ID_CURRENT_SITE){
|
---|
49 | return true;
|
---|
50 | } else {
|
---|
51 | return false;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | function xpress_is_wp_version($operator='==',$comp_version){
|
---|
56 | global $modInfo;
|
---|
57 | return version_compare($modInfo->get_wp_version(), $comp_version, $operator);
|
---|
58 | }
|
---|
59 |
|
---|
60 | function xpress_is_theme_sidebar_disp(){
|
---|
61 | global $xpress_config;
|
---|
62 | if (is_wordpress_style()) return true;
|
---|
63 | return $xpress_config->is_theme_sidebar_disp;
|
---|
64 | }
|
---|
65 |
|
---|
66 | function xpress_is_author_view_count(){
|
---|
67 | global $xpress_config;
|
---|
68 | return $xpress_config->is_author_view_count;
|
---|
69 | }
|
---|
70 |
|
---|
71 | function xpress_is_multi_user(){
|
---|
72 | global $xpress_config;
|
---|
73 | return $xpress_config->is_multi_user;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | function xpress_the_title($args = '')
|
---|
78 | {
|
---|
79 | $defaults = array(
|
---|
80 | 'echo' => 1
|
---|
81 | );
|
---|
82 | $r = wp_parse_args( $args, $defaults );
|
---|
83 |
|
---|
84 | extract( $r );
|
---|
85 |
|
---|
86 | $output = '<div class ="xpress-post-header">' . "\n";
|
---|
87 |
|
---|
88 | if (function_exists('hotDates')) {
|
---|
89 | ob_start();
|
---|
90 | hotDates();
|
---|
91 | $output .= ob_get_contents();
|
---|
92 | ob_end_clean();
|
---|
93 | }
|
---|
94 | $output .= '<div class ="xpress-post-title">' . "\n";
|
---|
95 | $output .= '<h2><a href="';
|
---|
96 | ob_start();
|
---|
97 | the_permalink();
|
---|
98 | $output .= ob_get_contents();
|
---|
99 | ob_end_clean();
|
---|
100 |
|
---|
101 | if(function_exists('the_title_attribute')){
|
---|
102 | $title = the_title_attribute('echo=0');
|
---|
103 | } else {
|
---|
104 | ob_start();
|
---|
105 | the_title();
|
---|
106 | $title = ob_get_contents();
|
---|
107 | ob_end_clean();
|
---|
108 | }
|
---|
109 |
|
---|
110 | $output .= '" rel="bookmark" title="';
|
---|
111 | $output .= sprintf(__('Permanent Link to %s', 'xpress'), $title);
|
---|
112 | $output .= '">';
|
---|
113 | $output .= $title;
|
---|
114 | $output .= '</a></h2>' . "\n";
|
---|
115 | $output .= '</div>' . "\n";
|
---|
116 | $output .= '</div>' . "\n";
|
---|
117 |
|
---|
118 | if ($echo)
|
---|
119 | echo $output;
|
---|
120 | else
|
---|
121 | return $output;
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | function xpress_selected_author($args ='' ) {
|
---|
126 | $defaults = array(
|
---|
127 | 'echo' => 1
|
---|
128 | );
|
---|
129 | $r = wp_parse_args( $args, $defaults );
|
---|
130 |
|
---|
131 | extract( $r );
|
---|
132 |
|
---|
133 | $output = '';
|
---|
134 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
135 | if (!empty($_COOKIE[$author_cookie])){
|
---|
136 | $uid = intval($_COOKIE[$author_cookie]);
|
---|
137 | $user_info = get_userdata($uid);
|
---|
138 | $output = $user_info->display_name;
|
---|
139 | }
|
---|
140 | if ($echo)
|
---|
141 | echo $output;
|
---|
142 | else
|
---|
143 | return $output;
|
---|
144 |
|
---|
145 | }
|
---|
146 | function xpress_selected_author_id($args ='' ) {
|
---|
147 | $defaults = array(
|
---|
148 | 'echo' => 1
|
---|
149 | );
|
---|
150 | $r = wp_parse_args( $args, $defaults );
|
---|
151 |
|
---|
152 | extract( $r );
|
---|
153 | $output = '';
|
---|
154 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
155 | if (!empty($_COOKIE[$author_cookie])){
|
---|
156 | $output = intval($_COOKIE[$author_cookie]);
|
---|
157 | } else {
|
---|
158 | $output = '';
|
---|
159 | }
|
---|
160 | if ($echo)
|
---|
161 | echo $output;
|
---|
162 | else
|
---|
163 | return $output;
|
---|
164 | }
|
---|
165 |
|
---|
166 | function xpress_now_user_level($args ='' ) {
|
---|
167 | global $current_user;
|
---|
168 | $defaults = array(
|
---|
169 | 'echo' => 1
|
---|
170 | );
|
---|
171 | $r = wp_parse_args( $args, $defaults );
|
---|
172 |
|
---|
173 | extract( $r );
|
---|
174 |
|
---|
175 | $output = xpress_user_access_level();
|
---|
176 | if ($echo)
|
---|
177 | echo $output;
|
---|
178 | else
|
---|
179 | return $output;
|
---|
180 | }
|
---|
181 |
|
---|
182 | function xpress_credit($args ='')
|
---|
183 | {
|
---|
184 | global $wp_version , $modInfo;
|
---|
185 |
|
---|
186 | $defaults = array(
|
---|
187 | 'echo' => 1,
|
---|
188 | 'no_link' => 0
|
---|
189 | );
|
---|
190 | $r = wp_parse_args( $args, $defaults );
|
---|
191 |
|
---|
192 | extract( $r );
|
---|
193 |
|
---|
194 | $xpress_version = $modInfo->get_module_version();
|
---|
195 | $xpress_codename = $modInfo->get_module_codename();
|
---|
196 | if ($no_link){
|
---|
197 | $output = 'XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
|
---|
198 | if (strstr($wp_version,'ME')){
|
---|
199 | $output .= '(included WordPress ' . $wp_version . ')';
|
---|
200 | } else {
|
---|
201 | $output .= '(included WordPress ' . $wp_version . ')';
|
---|
202 | }
|
---|
203 | } else {
|
---|
204 | $output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
|
---|
205 | if (strstr($wp_version,'ME')){
|
---|
206 | $output .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
207 | } else {
|
---|
208 | $output .= '(included <a href="http://wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
209 | }
|
---|
210 | }
|
---|
211 | if ($echo)
|
---|
212 | echo $output;
|
---|
213 | else
|
---|
214 | return $output;
|
---|
215 | }
|
---|
216 |
|
---|
217 | function xpress_convert_time($args ='')
|
---|
218 | {
|
---|
219 | $defaults = array(
|
---|
220 | 'echo' => 1,
|
---|
221 | 'format' => '(%.3f sec.)'
|
---|
222 | );
|
---|
223 | $r = wp_parse_args( $args, $defaults );
|
---|
224 |
|
---|
225 | extract( $r );
|
---|
226 |
|
---|
227 | $output = sprintf($format,timer_stop(0));
|
---|
228 | if ($echo)
|
---|
229 | echo $output;
|
---|
230 | else
|
---|
231 | return $output;
|
---|
232 | }
|
---|
233 |
|
---|
234 | function xpress_left_arrow_post_link($args ='')
|
---|
235 | {
|
---|
236 | global $xpress_config;
|
---|
237 | $defaults = array(
|
---|
238 | 'echo' => 1
|
---|
239 | );
|
---|
240 | $r = wp_parse_args( $args, $defaults );
|
---|
241 |
|
---|
242 | extract( $r );
|
---|
243 |
|
---|
244 | $ret = '';
|
---|
245 |
|
---|
246 | $link_str = '« %link';
|
---|
247 |
|
---|
248 | if($xpress_config->is_left_postnavi_old){
|
---|
249 | $link_title = $xpress_config->old_post_link_text;
|
---|
250 | ob_start();
|
---|
251 | if ($xpress_config->is_postnavi_title_disp)
|
---|
252 | previous_post_link($link_str);
|
---|
253 | else
|
---|
254 | previous_post_link($link_str,$link_title);
|
---|
255 | $ret = ob_get_contents();
|
---|
256 | ob_end_clean();
|
---|
257 | ob_start();
|
---|
258 | previous_post_link('%link',$link_title);
|
---|
259 | $GLOBALS['left_arrow_post_link'] = ob_get_contents();
|
---|
260 | ob_end_clean();
|
---|
261 |
|
---|
262 | } else {
|
---|
263 | $link_title = $xpress_config->newer_post_link_text;
|
---|
264 | ob_start();
|
---|
265 | if ($xpress_config->is_postnavi_title_disp)
|
---|
266 | next_post_link($link_str);
|
---|
267 | else
|
---|
268 | next_post_link($link_str,$link_title);
|
---|
269 | $ret = ob_get_contents();
|
---|
270 | ob_end_clean();
|
---|
271 | ob_start();
|
---|
272 | next_post_link('%link',$link_title);
|
---|
273 | $GLOBALS['left_arrow_post_link'] = ob_get_contents();
|
---|
274 | ob_end_clean();
|
---|
275 |
|
---|
276 | }
|
---|
277 |
|
---|
278 | if ($xpress_config->is_postnavi_title_disp){
|
---|
279 | $on_mouse_show = $link_title;
|
---|
280 | } else {
|
---|
281 | if($xpress_config->is_left_postnavi_old){
|
---|
282 | ob_start();
|
---|
283 | previous_post_link('%link');
|
---|
284 | $on_mouse_show = ob_get_contents();
|
---|
285 | ob_end_clean();
|
---|
286 | } else {
|
---|
287 | ob_start();
|
---|
288 | next_post_link('%link');
|
---|
289 | $on_mouse_show = ob_get_contents();
|
---|
290 | ob_end_clean();
|
---|
291 | }
|
---|
292 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
293 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
294 | $on_mouse_show = $body_matches[1];
|
---|
295 | }
|
---|
296 | $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
297 |
|
---|
298 | if (icon_exists($xpress_config->post_left_arrow_image_link)){
|
---|
299 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->post_left_arrow_image_link\" alt=\"\" style=\"vertical-align:middle\"/>",$GLOBALS['left_arrow_post_link']);
|
---|
300 | $img_link = str_replace('rel=','title="'.$on_mouse_show.'" rel=',$img_link);
|
---|
301 | $output = str_replace('«',$img_link , $output);
|
---|
302 | }
|
---|
303 |
|
---|
304 | if ($echo)
|
---|
305 | echo $output;
|
---|
306 | else
|
---|
307 | return $output;
|
---|
308 | }
|
---|
309 |
|
---|
310 | function xpress_right_arrow_post_link($args ='')
|
---|
311 | {
|
---|
312 | global $xpress_config;
|
---|
313 | $defaults = array(
|
---|
314 | 'echo' => 1
|
---|
315 | );
|
---|
316 | $r = wp_parse_args( $args, $defaults );
|
---|
317 |
|
---|
318 | extract( $r );
|
---|
319 |
|
---|
320 | $ret = '';
|
---|
321 |
|
---|
322 | $link_str = '%link »';
|
---|
323 |
|
---|
324 | if($xpress_config->is_left_postnavi_old){
|
---|
325 | $link_title = $xpress_config->newer_post_link_text;
|
---|
326 | ob_start();
|
---|
327 | if ($xpress_config->is_postnavi_title_disp)
|
---|
328 | next_post_link($link_str);
|
---|
329 | else
|
---|
330 | next_post_link($link_str,$link_title);
|
---|
331 | $ret = ob_get_contents();
|
---|
332 | ob_end_clean();
|
---|
333 | ob_start();
|
---|
334 | next_post_link('%link',$link_title);
|
---|
335 | $GLOBALS['right_arrow_post_link'] = ob_get_contents();
|
---|
336 | ob_end_clean();
|
---|
337 |
|
---|
338 | } else {
|
---|
339 | $link_title = $xpress_config->old_post_link_text;
|
---|
340 | ob_start();
|
---|
341 | if ($xpress_config->is_postnavi_title_disp)
|
---|
342 | previous_post_link($link_str);
|
---|
343 | else
|
---|
344 | previous_post_link($link_str,$link_title);
|
---|
345 | $ret = ob_get_contents();
|
---|
346 | ob_end_clean();
|
---|
347 | ob_start();
|
---|
348 | previous_post_link('%link',$link_title);
|
---|
349 | $GLOBALS['right_arrow_post_link'] = ob_get_contents();
|
---|
350 | ob_end_clean();
|
---|
351 |
|
---|
352 | }
|
---|
353 |
|
---|
354 | if ($xpress_config->is_postnavi_title_disp){
|
---|
355 | $on_mouse_show = $link_title;
|
---|
356 | } else {
|
---|
357 | if($xpress_config->is_left_postnavi_old){
|
---|
358 | ob_start();
|
---|
359 | next_post_link('%link');
|
---|
360 | $on_mouse_show = ob_get_contents();
|
---|
361 | ob_end_clean();
|
---|
362 | } else {
|
---|
363 | ob_start();
|
---|
364 | previous_post_link('%link');
|
---|
365 | $on_mouse_show = ob_get_contents();
|
---|
366 | ob_end_clean();
|
---|
367 | }
|
---|
368 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
369 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
370 | $on_mouse_show = $body_matches[1];
|
---|
371 | }
|
---|
372 | $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
373 |
|
---|
374 | if (icon_exists($xpress_config->post_right_arrow_image_link)){
|
---|
375 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->post_right_arrow_image_link\" alt=\"\" style=\"vertical-align:middle\"/>",$GLOBALS['right_arrow_post_link']);
|
---|
376 | $img_link = str_replace('rel=','title="'.$on_mouse_show.'" rel=',$img_link);
|
---|
377 | $output = str_replace('»',$img_link , $output);
|
---|
378 | }
|
---|
379 |
|
---|
380 | if ($echo)
|
---|
381 | echo $output;
|
---|
382 | else
|
---|
383 | return $output;
|
---|
384 | }
|
---|
385 | // page link
|
---|
386 | function xpress_left_arrow_posts_link($args ='')
|
---|
387 | {
|
---|
388 | global $xpress_config;
|
---|
389 | $defaults = array(
|
---|
390 | 'echo' => 1
|
---|
391 | );
|
---|
392 | $r = wp_parse_args( $args, $defaults );
|
---|
393 |
|
---|
394 | extract( $r );
|
---|
395 |
|
---|
396 | $output = '';
|
---|
397 |
|
---|
398 | if($xpress_config->is_left_page_navi_old){
|
---|
399 | $link_title = $xpress_config->old_page_link_text;
|
---|
400 | ob_start();
|
---|
401 | next_posts_link("« $link_title");
|
---|
402 | $output = ob_get_contents();
|
---|
403 | ob_end_clean();
|
---|
404 | } else {
|
---|
405 | $link_title = $xpress_config->newer_page_link_text;
|
---|
406 | ob_start();
|
---|
407 | previous_posts_link("« $link_title");
|
---|
408 | $output = ob_get_contents();
|
---|
409 | ob_end_clean();
|
---|
410 | }
|
---|
411 |
|
---|
412 | if (icon_exists($xpress_config->page_left_arrow_image_link)){
|
---|
413 | $output = $img_link . str_replace('«','' , $output);
|
---|
414 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->page_left_arrow_image_link\" alt=\"\" style=\"vertical-align:middle\"/>",$output);
|
---|
415 | $output = $img_link . $output;
|
---|
416 | }
|
---|
417 |
|
---|
418 | if ($echo)
|
---|
419 | echo $output;
|
---|
420 | else
|
---|
421 | return $output;
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | function xpress_right_arrow_posts_link($args ='')
|
---|
426 | {
|
---|
427 | global $xpress_config;
|
---|
428 | $defaults = array(
|
---|
429 | 'echo' => 1
|
---|
430 | );
|
---|
431 | $r = wp_parse_args( $args, $defaults );
|
---|
432 |
|
---|
433 | extract( $r );
|
---|
434 |
|
---|
435 | $output = '';
|
---|
436 |
|
---|
437 | if($xpress_config->is_left_page_navi_old){
|
---|
438 | $link_title = $xpress_config->newer_page_link_text;
|
---|
439 | ob_start();
|
---|
440 | previous_posts_link("$link_title »");
|
---|
441 | $output = ob_get_contents();
|
---|
442 | ob_end_clean();
|
---|
443 | } else {
|
---|
444 | $link_title = $xpress_config->old_page_link_text;
|
---|
445 | ob_start();
|
---|
446 | next_posts_link("$link_title »");
|
---|
447 | $output = ob_get_contents();
|
---|
448 | ob_end_clean();
|
---|
449 | }
|
---|
450 |
|
---|
451 | if (icon_exists($xpress_config->page_right_arrow_image_link)){
|
---|
452 | $output = $img_link . str_replace('»','' , $output);
|
---|
453 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->page_right_arrow_image_link\" alt=\"\" style=\"vertical-align:middle\"/>",$output);
|
---|
454 | $output = $output . $img_link;
|
---|
455 | }
|
---|
456 | if ($echo)
|
---|
457 | echo $output;
|
---|
458 | else
|
---|
459 | return $output;
|
---|
460 | }
|
---|
461 |
|
---|
462 | function xpress_substr($str, $start, $length, $trimmarker = '...')
|
---|
463 | {
|
---|
464 | if (function_exists('mb_substr') && function_exists('mb_strlen')){
|
---|
465 | $str2 = mb_substr( $str , $start , $length);
|
---|
466 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
|
---|
467 | } else {
|
---|
468 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
|
---|
469 | }
|
---|
470 | }
|
---|
471 |
|
---|
472 |
|
---|
473 | // views count
|
---|
474 | // Set and retrieves post views given a post ID or post object.
|
---|
475 | // Retrieves post views given a post ID or post object.
|
---|
476 | function xpress_post_views_count($args ='') {
|
---|
477 | global $xoops_db,$wpdb;
|
---|
478 | global $blog_id;
|
---|
479 | static $post_cache_views;
|
---|
480 |
|
---|
481 | $defaults = array(
|
---|
482 | 'post_id' => 0,
|
---|
483 | 'format'=> __('views :%d','xpressme'),
|
---|
484 | 'echo' => 1
|
---|
485 | );
|
---|
486 | $r = wp_parse_args( $args, $defaults );
|
---|
487 |
|
---|
488 | extract( $r );
|
---|
489 |
|
---|
490 | if ( empty($post_id) ) {
|
---|
491 | if ( isset($GLOBALS['post']) )
|
---|
492 | $post_id = $GLOBALS['post']->ID;
|
---|
493 | }
|
---|
494 | if ( empty($blogid) ) {
|
---|
495 | $blogid = $blog_id;
|
---|
496 | }
|
---|
497 |
|
---|
498 | $post_id = intval($post_id);
|
---|
499 | if($post_id==0) return null;
|
---|
500 | if(!isset($post_cache_views[$post_id])){
|
---|
501 | if (is_null($blogid)){
|
---|
502 | $blog_where = '';
|
---|
503 | } else {
|
---|
504 | $blog_where = ' AND blog_id = '. $blogid;
|
---|
505 | }
|
---|
506 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id " . $blog_where;
|
---|
507 | $post_views = $xoops_db->get_var($sql);
|
---|
508 | if (!$post_views) {
|
---|
509 | $post_cache_views[$post_id] = 0;
|
---|
510 | }else{
|
---|
511 | $post_cache_views[$post_id] = $post_views;
|
---|
512 | }
|
---|
513 | }
|
---|
514 | $v_count = intval($post_cache_views[$post_id]);
|
---|
515 |
|
---|
516 | if (empty($format)) $format = __('views :%d','xpressme');
|
---|
517 |
|
---|
518 | $output = sprintf($format,$v_count);
|
---|
519 |
|
---|
520 | if ($echo)
|
---|
521 | echo $output;
|
---|
522 | else
|
---|
523 | return $output;
|
---|
524 | }
|
---|
525 |
|
---|
526 | function set_post_views_count($content) {
|
---|
527 | if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
|
---|
528 | post_views_counting();
|
---|
529 | }
|
---|
530 | return $content;
|
---|
531 | }
|
---|
532 |
|
---|
533 | // Set post views given a post ID or post object.
|
---|
534 | function post_views_counting($post_id = 0) {
|
---|
535 | global $xoops_db,$wpdb;
|
---|
536 | global $table_prefix;
|
---|
537 | global $blog_id;
|
---|
538 | static $views;
|
---|
539 |
|
---|
540 | $post_id = intval($post_id);
|
---|
541 | if ( empty($post_id) && isset($GLOBALS['post']) ){
|
---|
542 | $post_id = $GLOBALS['post']->ID;
|
---|
543 | }
|
---|
544 |
|
---|
545 | $views_db = get_wp_prefix() . 'views';
|
---|
546 | if (is_null($blog_id)) $blog_id = 0;
|
---|
547 |
|
---|
548 | if($post_id==0 || !empty($views[$post_id])) return null;
|
---|
549 |
|
---|
550 | if(!xpress_is_author_view_count()){
|
---|
551 | $current_user_id = $GLOBALS['current_user']->ID;
|
---|
552 | $post_author_id = $GLOBALS['post']->post_author;
|
---|
553 | if ($current_user_id ==$post_author_id) return null;
|
---|
554 | }
|
---|
555 | if (is_null($blog_id)){
|
---|
556 | $blog_where = '';
|
---|
557 | } else {
|
---|
558 | $blog_where = ' AND blog_id = ' . $blog_id;
|
---|
559 | }
|
---|
560 | $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id" . $blog_where;
|
---|
561 | $post_views_found = $xoops_db->get_var($sql);
|
---|
562 | if($post_views_found){
|
---|
563 | $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id" . $blog_where;
|
---|
564 | }else{
|
---|
565 | if (is_null($blog_id)){
|
---|
566 | $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
|
---|
567 | } else {
|
---|
568 | $sql = "INSERT INTO " . $views_db . " (blog_id, post_id, post_views) VALUES ($blog_id, $post_id, 1)";
|
---|
569 | }
|
---|
570 | }
|
---|
571 | $xoops_db->query($sql);
|
---|
572 | return true;
|
---|
573 | }
|
---|
574 |
|
---|
575 | function get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text = '') {
|
---|
576 | global $post,$xpress_config;
|
---|
577 |
|
---|
578 | $blog_encoding = get_option('blog_charset');
|
---|
579 | $text = get_the_content('');
|
---|
580 | if (function_exists('strip_shortcodes')){ //@since WP2.5
|
---|
581 | $text = strip_shortcodes( $text );
|
---|
582 | }
|
---|
583 | $text = apply_filters('the_content', $text);
|
---|
584 | $text = str_replace(']]>', ']]>', $text);
|
---|
585 | $text = strip_tags($text);
|
---|
586 | if (function_exists('mb_strlen') && function_exists('mb_substr')){
|
---|
587 | $is_almost_ascii = ($xpress_config->ascii_judged_rate < round(@(mb_strlen($text, $blog_encoding) / strlen($text)) * 100)) ? true : false;
|
---|
588 | } else {
|
---|
589 | $is_almost_ascii = true;
|
---|
590 | }
|
---|
591 | if($is_almost_ascii) {
|
---|
592 | $words = explode(' ', $text, $excerpt_length_word + 1);
|
---|
593 |
|
---|
594 | if(count($words) > $excerpt_length_word) {
|
---|
595 | array_pop($words);
|
---|
596 | array_push($words, ' ... ');
|
---|
597 | $text = implode(' ', $words);
|
---|
598 | if (!empty($more_link_text)) $text .= '<div class="xpress-more-link"><a href="'. get_permalink() . "\">".$more_link_text .'</a></div>';
|
---|
599 |
|
---|
600 | }
|
---|
601 | }
|
---|
602 | elseif(mb_strlen($text, $blog_encoding) > $excerpt_length_character) {
|
---|
603 | $text = mb_substr($text, 0, $xpress_config->excerpt_length_character, $blog_encoding) . ' ... ';
|
---|
604 | if (!empty($more_link_text)) $text .= '<div class="xpress-more-link"><a href="'. get_permalink() . "\">".$more_link_text .'</a></div>';
|
---|
605 | }
|
---|
606 |
|
---|
607 | return $text;
|
---|
608 | }
|
---|
609 |
|
---|
610 | function xpress_the_content($args ='')
|
---|
611 | {
|
---|
612 | global $post,$xpress_config;
|
---|
613 |
|
---|
614 | $defaults = array(
|
---|
615 | 'more_link_text'=> $xpress_config->more_link_text,
|
---|
616 | 'stripteaser' => 0,
|
---|
617 | 'more_file' => '',
|
---|
618 | 'configration_select' => 1,
|
---|
619 | 'do_excerpt' => 0,
|
---|
620 | 'excerpt_length_word' => $xpress_config->excerpt_length_word ,
|
---|
621 | 'excerpt_length_character' => $xpress_config->excerpt_length_character ,
|
---|
622 | 'excerpt_more_link_text' => $xpress_config->excerpt_more_link_text ,
|
---|
623 | 'echo' => 1
|
---|
624 | );
|
---|
625 | $r = wp_parse_args( $args, $defaults );
|
---|
626 |
|
---|
627 | extract( $r );
|
---|
628 |
|
---|
629 | if ($configration_select){
|
---|
630 | if ($xpress_config->is_content_excerpt)
|
---|
631 | $do_excerpt = 1;
|
---|
632 | else
|
---|
633 | $do_excerpt = 0;
|
---|
634 | }
|
---|
635 |
|
---|
636 | if ($do_excerpt){
|
---|
637 | $content = get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$excerpt_more_link_text);
|
---|
638 | } else {
|
---|
639 | $content = get_the_content($more_link_text,$stripteaser,$more_file);
|
---|
640 | $content = apply_filters('the_content', $content);
|
---|
641 | $content = str_replace(']]>', ']]>', $content);
|
---|
642 | }
|
---|
643 | if ($echo)
|
---|
644 | echo $content;
|
---|
645 | else
|
---|
646 | return $content;
|
---|
647 | }
|
---|
648 |
|
---|
649 | function xpress_post_new_link($args ='')
|
---|
650 | {
|
---|
651 | global $modInfo;
|
---|
652 |
|
---|
653 | $defaults = array(
|
---|
654 | 'link_title'=> 'Post New',
|
---|
655 | 'echo' => 1
|
---|
656 | );
|
---|
657 | $r = wp_parse_args( $args, $defaults );
|
---|
658 |
|
---|
659 | extract( $r );
|
---|
660 |
|
---|
661 |
|
---|
662 | if (xpress_is_wp_version('>=','2.1')){
|
---|
663 | $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
|
---|
664 | } else {
|
---|
665 | $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post.php' . '">' . $link_title . '</a>';
|
---|
666 | }
|
---|
667 | if ($echo)
|
---|
668 | echo $output;
|
---|
669 | else
|
---|
670 | return $output;
|
---|
671 | }
|
---|
672 |
|
---|
673 | function xpress_conditional_title($args ='')
|
---|
674 | {
|
---|
675 | $defaults = array(
|
---|
676 | 'echo' => 1
|
---|
677 | );
|
---|
678 | $r = wp_parse_args( $args, $defaults );
|
---|
679 |
|
---|
680 | extract( $r );
|
---|
681 |
|
---|
682 | $selected_author = xpress_selected_author('echo=0');
|
---|
683 |
|
---|
684 | $output = __('Main', 'xpressme');
|
---|
685 | $output = '';
|
---|
686 | if (is_category())
|
---|
687 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpressme'), single_cat_title('', false));
|
---|
688 | if (function_exists( 'is_tag' )){
|
---|
689 | if (is_tag())
|
---|
690 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpressme'), single_tag_title('', false) );
|
---|
691 | }
|
---|
692 | if (is_day())
|
---|
693 | $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
|
---|
694 | if (is_month())
|
---|
695 | $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
|
---|
696 | if (is_year())
|
---|
697 | $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
|
---|
698 | if (is_author()){
|
---|
699 | if (empty($selected_author))
|
---|
700 | $output = sprintf(__('Archive for the ‘%s’ Author', 'xpressme'), get_author_name( get_query_var('author')));
|
---|
701 | }
|
---|
702 | if (is_search())
|
---|
703 | $output = sprintf(__('Search Results of word ‘%s’', 'xpressme'), get_search_query());
|
---|
704 |
|
---|
705 | if (!empty($selected_author)){
|
---|
706 | $selected_id = xpress_selected_author_id('echo=0');
|
---|
707 | // $output = get_avatar($selected_id,$size = '32') . sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
|
---|
708 | if (empty($output))
|
---|
709 | $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) ;
|
---|
710 | else
|
---|
711 | $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
|
---|
712 | }
|
---|
713 | if ($echo)
|
---|
714 | echo $output;
|
---|
715 | else
|
---|
716 | return $output;
|
---|
717 | }
|
---|
718 |
|
---|
719 | // The content of the trackback/pingback to the post is returned by the list.
|
---|
720 | function xpress_pings_list($args =''){
|
---|
721 | $defaults = array(
|
---|
722 | 'echo' => 1
|
---|
723 | );
|
---|
724 | $r = wp_parse_args( $args, $defaults );
|
---|
725 |
|
---|
726 | extract( $r );
|
---|
727 |
|
---|
728 | $trackbacks = xpress_get_pings();
|
---|
729 | if (! empty($trackbacks)) {
|
---|
730 | $output = '<ol id="xpress_pingslist"> ';
|
---|
731 |
|
---|
732 | foreach ($trackbacks as $trackback){
|
---|
733 | $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" ;
|
---|
734 |
|
---|
735 | $output .= '<li>';
|
---|
736 | $output .= $list ;
|
---|
737 | $output .= '</li>';
|
---|
738 |
|
---|
739 | }
|
---|
740 | $output .= '</ol>' ;
|
---|
741 | } else {
|
---|
742 | $output = '';
|
---|
743 | }
|
---|
744 |
|
---|
745 | if ($echo)
|
---|
746 | echo $output;
|
---|
747 | else
|
---|
748 | return $output;
|
---|
749 | }
|
---|
750 |
|
---|
751 | // The amount of the trackback/pingback to the post is returned.
|
---|
752 | function xpress_pings_number( $args ='' ) {
|
---|
753 | $defaults = array(
|
---|
754 | 'zero' => __('No Trackback/Pingback', 'xpressme'),
|
---|
755 | 'one' => __('One Trackback/Pingback', 'xpressme'),
|
---|
756 | 'more' => __('% TrackBack/Pingback', 'xpressme'),
|
---|
757 | 'deprecated' => '',
|
---|
758 | 'echo' => 1
|
---|
759 | );
|
---|
760 | $r = wp_parse_args( $args, $defaults );
|
---|
761 |
|
---|
762 | extract( $r );
|
---|
763 |
|
---|
764 | $pings = xpress_get_pings();
|
---|
765 | if (empty($pings)){
|
---|
766 | $number = 0;
|
---|
767 | }else {
|
---|
768 | $number = count($pings);
|
---|
769 | }
|
---|
770 | if ( $number > 1 )
|
---|
771 | $output = str_replace('%', number_format_i18n($number), $more);
|
---|
772 | elseif ( $number == 0 )
|
---|
773 | $output = $zero;
|
---|
774 | else // must be one
|
---|
775 | $output = $one;
|
---|
776 |
|
---|
777 | if ($echo)
|
---|
778 | echo $output;
|
---|
779 | else
|
---|
780 | return $output;
|
---|
781 | }
|
---|
782 |
|
---|
783 | // xpress_get_pings() is a subfunction used with xpress_pings_number() and xpress_pings_list().
|
---|
784 | function xpress_get_pings()
|
---|
785 | {
|
---|
786 | global $withcomments, $post, $wpdb, $id, $trackback, $user_login, $user_ID, $user_identity;
|
---|
787 |
|
---|
788 | if ( ! (is_single() || is_page() || $withcomments) )
|
---|
789 | return;
|
---|
790 |
|
---|
791 | /** @todo Use API instead of SELECTs. */
|
---|
792 | if ( $user_ID) {
|
---|
793 | $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));
|
---|
794 | } else if ( empty($trackback_author) ) {
|
---|
795 | $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));
|
---|
796 | } else {
|
---|
797 | $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));
|
---|
798 | }
|
---|
799 |
|
---|
800 | if ($trackbacks){
|
---|
801 | $ret = array();
|
---|
802 | foreach ($trackbacks as $trackback){
|
---|
803 |
|
---|
804 | $pattern = '<strong>(.*)<\/strong>(.*)';
|
---|
805 | if ( preg_match ( "/".$pattern."/i", $trackback->comment_content , $match ) ){
|
---|
806 | $title = $match[1];
|
---|
807 | $content = $match[2];
|
---|
808 | }
|
---|
809 | if (empty($title)) $title = $trackback->comment_author;
|
---|
810 |
|
---|
811 |
|
---|
812 | $row_data = array(
|
---|
813 | 'ID' => $trackback->comment_ID ,
|
---|
814 | 'post_ID' => $trackback->comment_post_ID ,
|
---|
815 | 'site_name' => $trackback->comment_author ,
|
---|
816 | 'site_url' => $trackback->comment_author_url ,
|
---|
817 | 'title' => $title ,
|
---|
818 | 'content' => $content ,
|
---|
819 | 'date' => $trackback->comment_timestamp ,
|
---|
820 | 'date_gmt' => $trackback->comment_timestamp_gmt ,
|
---|
821 | 'agent' => $trackback->comment_agent ,
|
---|
822 | 'type' => $trackback->comment_type ,
|
---|
823 | 'IP' => $trackback->comment_author_IP ,
|
---|
824 | );
|
---|
825 | array_push($ret,$row_data);
|
---|
826 | }
|
---|
827 | return $ret;
|
---|
828 | }
|
---|
829 | return false;
|
---|
830 | }
|
---|
831 |
|
---|
832 | function xpress_get_calendar($args = '') {
|
---|
833 | global $wpdb, $m, $monthnum, $year, $wp_locale, $posts , $modInfo;
|
---|
834 |
|
---|
835 | $defaults = array(
|
---|
836 | sun_color => '#DB0000',
|
---|
837 | sat_color => '#004D99',
|
---|
838 | initial => true
|
---|
839 | );
|
---|
840 | $r = wp_parse_args( $args, $defaults );
|
---|
841 |
|
---|
842 | extract( $r );
|
---|
843 |
|
---|
844 | ob_start();
|
---|
845 | get_calendar(true);
|
---|
846 | $calendar = ob_get_contents();
|
---|
847 | ob_end_clean();
|
---|
848 | $calendar = preg_replace('/<th abbr=/', '<th align="center" abbr=', $calendar); //week name align center
|
---|
849 | $calendar = preg_replace('/<td>/', '<td align="center">', $calendar); //days align center
|
---|
850 | $calendar = preg_replace('/<td id="today">/', '<td id="today" align="center">', $calendar); //today align center
|
---|
851 | $calendar = preg_replace('/<span style="color:[^>]*>/', '', $calendar); //wp2011 color delete
|
---|
852 | $calendar = preg_replace('/<\/span>/', '', $calendar); //wp2011 color delete
|
---|
853 |
|
---|
854 | $week_begins = intval(get_option('start_of_week'));
|
---|
855 | $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>';
|
---|
856 | if(preg_match('/'. $head_pattrn . '/s' ,$calendar,$head_match)){
|
---|
857 | $sun_index = 1 - $week_begins;
|
---|
858 | if ($sun_index < 1) $sun_index = $sun_index +7;
|
---|
859 | $sat_index = 7 - $week_begins;
|
---|
860 | if ($sat_index < 1) $sat_index = $sat_index +7;
|
---|
861 |
|
---|
862 | $sun_head = $head_match[$sun_index];
|
---|
863 | $sat_head = $head_match[$sat_index];
|
---|
864 |
|
---|
865 | $pattrn = '(<th[^>]*>)(.*)(<\/th>)';
|
---|
866 | if(preg_match('/'. $pattrn . '/' ,$sun_head,$sun_match)){
|
---|
867 | $sun_head_after = $sun_match[1] . '<span style="color: ' . $sun_color . '">' . $sun_match[2] . '</span>'. $sun_match[3];
|
---|
868 | $calendar = str_replace($sun_head,$sun_head_after,$calendar);
|
---|
869 | }
|
---|
870 | if(preg_match('/'. $pattrn . '/' ,$sat_head,$sat_match)){
|
---|
871 | $sat_head_after = $sat_match[1] . '<span style="color: ' . $sat_color . '">' . $sat_match[2] . '</span>'. $sat_match[3];
|
---|
872 | $calendar = str_replace($sat_head,$sat_head_after,$calendar);
|
---|
873 | }
|
---|
874 | }
|
---|
875 | return $calendar;
|
---|
876 | }
|
---|
877 |
|
---|
878 | function xpress_grobal_recent_posts($num = 10,$post_list='')
|
---|
879 | {
|
---|
880 | global $wpdb, $wp_rewrite , $switched , $blog_id;
|
---|
881 | if (empty($date_format)) $date_format = get_settings('date_format');
|
---|
882 | if (empty($time_format)) $time_format = get_settings('time_format');
|
---|
883 |
|
---|
884 | $first_blogid = $blog_id;
|
---|
885 | $num = (int)$num;
|
---|
886 | // $wp_query->in_the_loop = true; //for use the_tags() in multi lopp
|
---|
887 | $data_array = array();
|
---|
888 | if (xpress_is_multiblog()){
|
---|
889 | $blogs = get_blog_list(0,'all');
|
---|
890 | foreach ($blogs AS $blog) {
|
---|
891 | switch_to_blog($blog['blog_id']);
|
---|
892 | $wp_rewrite->init(); // http://core.trac.wordpress.org/ticket/12040 is solved, it is unnecessary.
|
---|
893 |
|
---|
894 | if (empty($num)){
|
---|
895 | query_posts("post_status=publish");
|
---|
896 | } else {
|
---|
897 | query_posts("showposts=$num&post_status=publish");
|
---|
898 | }
|
---|
899 | if (have_posts()){
|
---|
900 | while(have_posts()){
|
---|
901 | $data = new stdClass();
|
---|
902 |
|
---|
903 | the_post();
|
---|
904 | ob_start();
|
---|
905 | the_ID();
|
---|
906 | $data->post_id = ob_get_contents();
|
---|
907 | ob_end_clean();
|
---|
908 |
|
---|
909 | $data->brog_id = $blog['blog_id'];
|
---|
910 | $data->blog_name = get_bloginfo('name');
|
---|
911 | $data->blog_url = get_bloginfo('url');
|
---|
912 | $data->blog_link = '<a href="' . $data->blog_url . '">' . $data->blog_name . '</a>' ;
|
---|
913 |
|
---|
914 |
|
---|
915 | ob_start();
|
---|
916 | the_title();
|
---|
917 | $data->title = ob_get_contents();
|
---|
918 | ob_end_clean();
|
---|
919 | $data->post_permalink = get_blog_permalink($data->brog_id, $data->post_id);
|
---|
920 | $data->title_link = '<a href="' . $data->post_permalink . '">' . $data->title . '</a>' ;
|
---|
921 |
|
---|
922 | ob_start();
|
---|
923 | the_author_posts_link();
|
---|
924 | $data->post_author = ob_get_contents();
|
---|
925 | ob_end_clean();
|
---|
926 |
|
---|
927 | ob_start();
|
---|
928 | the_category(' • ');
|
---|
929 | $data->post_category = ob_get_contents();
|
---|
930 | ob_end_clean();
|
---|
931 |
|
---|
932 | if (function_exists('the_tags')){
|
---|
933 | ob_start();
|
---|
934 | the_tags(__('Tags:', 'xpress') . ' ',' • ','');
|
---|
935 | $data->post_tags = ob_get_contents();
|
---|
936 | ob_end_clean();
|
---|
937 | } else {
|
---|
938 | $data->tags = '';
|
---|
939 | }
|
---|
940 |
|
---|
941 | $data->the_content = xpress_the_content('echo=0');
|
---|
942 |
|
---|
943 | ob_start();
|
---|
944 | the_content();
|
---|
945 | $data->the_full_content = ob_get_contents();
|
---|
946 | ob_end_clean();
|
---|
947 |
|
---|
948 | ob_start();
|
---|
949 | the_modified_date($date_format);
|
---|
950 | $data->post_modified_date = ob_get_contents();
|
---|
951 | ob_end_clean();
|
---|
952 |
|
---|
953 | ob_start();
|
---|
954 | the_modified_date($time_format);
|
---|
955 | $data->post_modified_time = ob_get_contents();
|
---|
956 | ob_end_clean();
|
---|
957 | $data->post_modified_date_time = $data->post_modified_date . ' ' . $data->post_modified_time;
|
---|
958 |
|
---|
959 | ob_start();
|
---|
960 | the_time('U');
|
---|
961 | $data->post_unix_time = ob_get_contents();
|
---|
962 | ob_end_clean();
|
---|
963 |
|
---|
964 | ob_start();
|
---|
965 | the_time($date_format);
|
---|
966 | $data->post_date = ob_get_contents();
|
---|
967 | ob_end_clean();
|
---|
968 |
|
---|
969 | ob_start();
|
---|
970 | the_time($time_format);
|
---|
971 | $data->post_time = ob_get_contents();
|
---|
972 | ob_end_clean();
|
---|
973 |
|
---|
974 | $data->post_date_time = $data->post_date . ' ' . $data->post_time;
|
---|
975 |
|
---|
976 | ob_start();
|
---|
977 | comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
|
---|
978 | $data->comments_link = ob_get_contents();
|
---|
979 | ob_end_clean();
|
---|
980 |
|
---|
981 | $data->post_views = xpress_post_views_count('post_id=' . $data->post_id . '&blogid=' . $data->brog_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
|
---|
982 |
|
---|
983 | $data_array[] = $data;
|
---|
984 | } // end whilwe
|
---|
985 | } // end if
|
---|
986 | restore_current_blog();
|
---|
987 | // $wp_rewrite->init();
|
---|
988 | } // end foreach
|
---|
989 | // switch_to_blog($first_blogid);
|
---|
990 | $wp_rewrite->init(); // http://core.trac.wordpress.org/ticket/12040 is solved, it is unnecessary.
|
---|
991 |
|
---|
992 | restore_current_blog();
|
---|
993 | usort($data_array, "the_time_cmp");
|
---|
994 | }
|
---|
995 |
|
---|
996 | if (!empty($num)){
|
---|
997 | $data_array = array_slice($data_array,0,$num);
|
---|
998 | }
|
---|
999 | return $data_array;
|
---|
1000 | }
|
---|
1001 | function the_time_cmp($a, $b)
|
---|
1002 | {
|
---|
1003 | return - strcasecmp($a->post_unix_time, $b->post_unix_time);
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | function xpress_get_blog_option($option_name,$b_id = 1)
|
---|
1007 | {
|
---|
1008 | global $wpdb;
|
---|
1009 | $db_prefix = get_wp_prefix();
|
---|
1010 |
|
---|
1011 | if (empty($b_id)) $b_id =1;
|
---|
1012 | $blog_prefix = '';
|
---|
1013 | if ($b_id >1) $blog_prefix = $b_id . '_';
|
---|
1014 | $options_tb = $db_prefix . $blog_prefix .'options';
|
---|
1015 |
|
---|
1016 | $sql = "SELECT option_value FROM $options_tb WHERE option_name = $option_name";
|
---|
1017 | $ret_val = $wpdb->get_var($sql);
|
---|
1018 | return $ret_val;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | function xpress_create_new_blog_link($args ='' ) {
|
---|
1022 | global $modInfo;
|
---|
1023 |
|
---|
1024 | global $current_user;
|
---|
1025 | $defaults = array(
|
---|
1026 | 'echo' => 1
|
---|
1027 | );
|
---|
1028 | $r = wp_parse_args( $args, $defaults );
|
---|
1029 |
|
---|
1030 | extract( $r );
|
---|
1031 | $result = xpress_create_new_blog();
|
---|
1032 | if (!empty($result)){
|
---|
1033 | $output = $result['link'];
|
---|
1034 | } else {
|
---|
1035 | $output = '';
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | if ($echo)
|
---|
1039 | echo $output;
|
---|
1040 | else
|
---|
1041 | return $output;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | function xpress_create_new_blog() {
|
---|
1045 | global $modInfo;
|
---|
1046 | global $current_user;
|
---|
1047 | $ret = array();
|
---|
1048 |
|
---|
1049 | if (xpress_is_multiblog() && is_user_logged_in()){
|
---|
1050 | $primary_blog_id = @$current_user->primary_blog;
|
---|
1051 | if (!empty($primary_blog_id)) return $ret;
|
---|
1052 | $active_signup = get_site_option( 'registration' );
|
---|
1053 | if ( !$active_signup ) $active_signup = 'none';
|
---|
1054 | switch ($active_signup){
|
---|
1055 | case 'all':
|
---|
1056 | case 'blog':
|
---|
1057 | $ret['url'] = $modInfo->get_module_url() . '/wp-signup.php';
|
---|
1058 | $ret['menu_url'] = 'wp-signup.php';
|
---|
1059 | $ret['title'] = __('Create New Blog','xpressme');
|
---|
1060 | $ret['link'] = '<a href="' . $ret['url'] . '">' . $ret['title'] . '</a>';
|
---|
1061 | break;
|
---|
1062 | case 'user':
|
---|
1063 | case 'none':
|
---|
1064 | default:
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 | return $ret;
|
---|
1068 | }
|
---|
1069 | function xpress_primary_blog_link() {
|
---|
1070 | global $modInfo;
|
---|
1071 | global $current_user;
|
---|
1072 | global $blog_id;
|
---|
1073 | $ret = array();
|
---|
1074 |
|
---|
1075 | if (xpress_is_multiblog() && is_user_logged_in()){
|
---|
1076 | $blog_list = get_blog_list();
|
---|
1077 | $root_path = get_blog_status(1,'path');
|
---|
1078 | $primary_blog_id = @$current_user->primary_blog;
|
---|
1079 | if(empty($primary_blog_id)) return $ret;
|
---|
1080 | $primary_path = get_blog_status($primary_blog_id,'path');
|
---|
1081 | $script = str_replace($root_path, "", $primary_path);
|
---|
1082 | if ($primary_blog_id !== $blog_id){
|
---|
1083 | $ret['url'] = get_blogaddress_by_id($primary_blog_id);
|
---|
1084 | $ret['menu_url'] = $script;
|
---|
1085 | $ret['title'] = __('Your Primary Blog','xpressme');
|
---|
1086 | $ret['link'] = '<a href="' . $ret['url'] . '">' . $ret['title'] . '</a>';
|
---|
1087 | }
|
---|
1088 | }
|
---|
1089 | return $ret;
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | ?> |
---|