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