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