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