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