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