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