[ Index ]
 

Code source de WordPress 2.1.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/wp-includes/ -> general-template.php (source)

   1  <?php
   2  
   3  /* Note: these tags go anywhere in the template */
   4  
   5  function get_header() {
   6      do_action( 'get_header' );
   7      if ( file_exists( TEMPLATEPATH . '/header.php') )
   8          load_template( TEMPLATEPATH . '/header.php');
   9      else
  10          load_template( ABSPATH . 'wp-content/themes/default/header.php');
  11  }
  12  
  13  
  14  function get_footer() {
  15      do_action( 'get_footer' );
  16      if ( file_exists( TEMPLATEPATH . '/footer.php') )
  17          load_template( TEMPLATEPATH . '/footer.php');
  18      else
  19          load_template( ABSPATH . 'wp-content/themes/default/footer.php');
  20  }
  21  
  22  
  23  function get_sidebar() {
  24      if ( file_exists( TEMPLATEPATH . '/sidebar.php') )
  25          load_template( TEMPLATEPATH . '/sidebar.php');
  26      else
  27          load_template( ABSPATH . 'wp-content/themes/default/sidebar.php');
  28  }
  29  
  30  
  31  function wp_loginout() {
  32      if ( ! is_user_logged_in() )
  33          $link = '<a href="' . get_option('siteurl') . '/wp-login.php">' . __('Login') . '</a>';
  34      else
  35          $link = '<a href="' . get_option('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
  36  
  37      echo apply_filters('loginout', $link);
  38  }
  39  
  40  
  41  function wp_register( $before = '<li>', $after = '</li>' ) {
  42  
  43      if ( ! is_user_logged_in() ) {
  44          if ( get_option('users_can_register') )
  45              $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after;
  46          else
  47              $link = '';
  48      } else {
  49          $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
  50      }
  51  
  52      echo apply_filters('register', $link);
  53  }
  54  
  55  
  56  function wp_meta() {
  57      do_action('wp_meta');
  58  }
  59  
  60  
  61  function bloginfo($show='') {
  62      $info = get_bloginfo($show);
  63      if (!strstr($show, 'url') && //don't filter URLs
  64          !strstr($show, 'directory') &&
  65          !strstr($show, 'home')) {
  66          $info = apply_filters('bloginfo', $info, $show);
  67          $info = convert_chars($info);
  68      } else {
  69          $info = apply_filters('bloginfo_url', $info, $show);
  70      }
  71  
  72      echo $info;
  73  }
  74  
  75  
  76  function get_bloginfo($show='') {
  77  
  78      switch($show) {
  79          case 'url' :
  80          case 'home' :
  81          case 'siteurl' :
  82              $output = get_option('home');
  83              break;
  84          case 'wpurl' :
  85              $output = get_option('siteurl');
  86              break;
  87          case 'description':
  88              $output = get_option('blogdescription');
  89              break;
  90          case 'rdf_url':
  91              $output = get_feed_link('rdf');
  92              break;
  93          case 'rss_url':
  94              $output = get_feed_link('rss');
  95              break;
  96          case 'rss2_url':
  97              $output = get_feed_link('rss2');
  98              break;
  99          case 'atom_url':
 100              $output = get_feed_link('atom');
 101              break;
 102          case 'comments_rss2_url':
 103              $output = get_feed_link('comments_rss2');
 104              break;
 105          case 'pingback_url':
 106              $output = get_option('siteurl') .'/xmlrpc.php';
 107              break;
 108          case 'stylesheet_url':
 109              $output = get_stylesheet_uri();
 110              break;
 111          case 'stylesheet_directory':
 112              $output = get_stylesheet_directory_uri();
 113              break;
 114          case 'template_directory':
 115          case 'template_url':
 116              $output = get_template_directory_uri();
 117              break;
 118          case 'admin_email':
 119              $output = get_option('admin_email');
 120              break;
 121          case 'charset':
 122              $output = get_option('blog_charset');
 123              if ('' == $output) $output = 'UTF-8';
 124              break;
 125          case 'html_type' :
 126              $output = get_option('html_type');
 127              break;
 128          case 'version':
 129              global $wp_version;
 130              $output = $wp_version;
 131              break;
 132          case 'language':
 133              $output = get_locale();
 134              $output = str_replace('_', '-', $output);
 135              break;
 136          case 'text_direction':
 137              global $wp_locale;
 138              $output = $wp_locale->text_direction;
 139              break;
 140          case 'name':
 141          default:
 142              $output = get_option('blogname');
 143              break;
 144      }
 145      return $output;
 146  }
 147  
 148  
 149  function wp_title($sep = '&raquo;', $display = true) {
 150      global $wpdb;
 151      global $m, $year, $monthnum, $day, $category_name, $wp_locale, $posts;
 152  
 153      $cat = get_query_var('cat');
 154      $p = get_query_var('p');
 155      $name = get_query_var('name');
 156      $category_name = get_query_var('category_name');
 157      $author = get_query_var('author');
 158      $author_name = get_query_var('author_name');
 159      $title = '';
 160  
 161      // If there's a category
 162      if ( !empty($cat) ) {
 163              // category exclusion
 164              if ( !stristr($cat,'-') )
 165                  $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
 166      }
 167      if ( !empty($category_name) ) {
 168          if ( stristr($category_name,'/') ) {
 169                  $category_name = explode('/',$category_name);
 170                  if ( $category_name[count($category_name)-1] )
 171                      $category_name = $category_name[count($category_name)-1]; // no trailing slash
 172                  else
 173                      $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
 174          }
 175          $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
 176          $title = apply_filters('single_cat_title', $title);
 177      }
 178  
 179      // If there's an author
 180      if ( !empty($author) ) {
 181          $title = get_userdata($author);
 182          $title = $title->display_name;
 183      }
 184      if ( !empty($author_name) ) {
 185          // We do a direct query here because we don't cache by nicename.
 186          $title = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE user_nicename = '$author_name'");
 187      }
 188  
 189      // If there's a month
 190      if ( !empty($m) ) {
 191          $my_year = substr($m, 0, 4);
 192          $my_month = $wp_locale->get_month($m);
 193          $title = "$my_year $sep $my_month";
 194      }
 195  
 196      if ( !empty($year) ) {
 197          $title = $year;
 198          if ( !empty($monthnum) )
 199              $title .= " $sep ".$wp_locale->get_month($monthnum);
 200          if ( !empty($day) )
 201              $title .= " $sep ".zeroise($day, 2);
 202      }
 203  
 204      // If there is a post
 205      if ( is_single() || is_page() ) {
 206          $title = strip_tags($posts[0]->post_title);
 207          $title = apply_filters('single_post_title', $title);
 208      }
 209  
 210      $prefix = '';
 211      if ( !empty($title) )
 212          $prefix = " $sep ";
 213  
 214      $title = $prefix . $title;
 215      $title = apply_filters('wp_title', $title, $sep);
 216  
 217      // Send it out
 218      if ( $display )
 219          echo $title;
 220      else
 221          return $title;
 222  }
 223  
 224  
 225  function single_post_title($prefix = '', $display = true) {
 226      global $wpdb;
 227      $p = get_query_var('p');
 228      $name = get_query_var('name');
 229  
 230      if ( intval($p) || '' != $name ) {
 231          if ( !$p )
 232              $p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'");
 233          $post = & get_post($p);
 234          $title = $post->post_title;
 235          $title = apply_filters('single_post_title', $title);
 236          if ( $display )
 237              echo $prefix.strip_tags($title);
 238          else
 239              return strip_tags($title);
 240      }
 241  }
 242  
 243  
 244  function single_cat_title($prefix = '', $display = true ) {
 245      $cat = intval( get_query_var('cat') );
 246      if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
 247          $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
 248          if ( !empty($my_cat_name) ) {
 249              if ( $display )
 250                  echo $prefix.strip_tags($my_cat_name);
 251              else
 252                  return strip_tags($my_cat_name);
 253          }
 254      }
 255  }
 256  
 257  
 258  function single_month_title($prefix = '', $display = true ) {
 259      global $m, $monthnum, $wp_locale, $year;
 260      if ( !empty($monthnum) && !empty($year) ) {
 261          $my_year = $year;
 262          $my_month = $wp_locale->get_month($monthnum);
 263      } elseif ( !empty($m) ) {
 264          $my_year = substr($m, 0, 4);
 265          $my_month = $wp_locale->get_month(substr($m, 4, 2));
 266      }
 267  
 268      if ( empty($my_month) )
 269          return false;
 270  
 271      $result = $prefix . $my_month . $prefix . $my_year;
 272  
 273      if ( !$display )
 274          return $result;
 275      echo $result;
 276  }
 277  
 278  
 279  /* link navigation hack by Orien http://icecode.com/ */
 280  function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
 281      $text = wptexturize($text);
 282      $title_text = attribute_escape($text);
 283  
 284      if ('link' == $format)
 285          return "\t<link rel='archives' title='$title_text' href='$url' />\n";
 286      elseif ('option' == $format)
 287          return "\t<option value='$url'>$before $text $after</option>\n";
 288      elseif ('html' == $format)
 289          return "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
 290      else // custom
 291          return "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
 292  }
 293  
 294  
 295  function wp_get_archives($args = '') {
 296      global $wp_locale, $wpdb;
 297  
 298      if ( is_array($args) )
 299          $r = &$args;
 300      else
 301          parse_str($args, $r);
 302  
 303      $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false);
 304      $r = array_merge($defaults, $r);
 305      extract($r);
 306  
 307      if ( '' == $type )
 308          $type = 'monthly';
 309  
 310      if ( '' != $limit ) {
 311          $limit = (int) $limit;
 312          $limit = ' LIMIT '.$limit;
 313      }
 314  
 315      // this is what will separate dates on weekly archive links
 316      $archive_week_separator = '&#8211;';
 317  
 318      // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
 319      $archive_date_format_over_ride = 0;
 320  
 321      // options for daily archive (only if you over-ride the general date format)
 322      $archive_day_date_format = 'Y/m/d';
 323  
 324      // options for weekly archive (only if you over-ride the general date format)
 325      $archive_week_start_date_format = 'Y/m/d';
 326      $archive_week_end_date_format    = 'Y/m/d';
 327  
 328      if ( !$archive_date_format_over_ride ) {
 329          $archive_day_date_format = get_option('date_format');
 330          $archive_week_start_date_format = get_option('date_format');
 331          $archive_week_end_date_format = get_option('date_format');
 332      }
 333  
 334      $add_hours = intval(get_option('gmt_offset'));
 335      $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours));
 336  
 337      if ( 'monthly' == $type ) {
 338          $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
 339          if ( $arcresults ) {
 340              $afterafter = $after;
 341              foreach ( $arcresults as $arcresult ) {
 342                  $url    = get_month_link($arcresult->year,    $arcresult->month);
 343                  $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
 344                  if ( $show_post_count ) 
 345                      $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
 346                  echo get_archives_link($url, $text, $format, $before, $after);
 347              }
 348          }
 349      } elseif ('yearly' == $type) {
 350           $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts WHERE post_type ='post' AND post_status = 'publish' GROUP BY YEAR(post_date) ORDER BY post_date DESC" . $limit);
 351          if ($arcresults) {
 352              $afterafter = $after;
 353              foreach ($arcresults as $arcresult) {
 354                  $url = get_year_link($arcresult->year);
 355                  $text = sprintf('%d', $arcresult->year);
 356                  if ($show_post_count)
 357                      $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
 358                  echo get_archives_link($url, $text, $format, $before, $after);
 359              }
 360          }              
 361      } elseif ( 'daily' == $type ) {
 362          $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC" . $limit);
 363          if ( $arcresults ) {
 364              $afterafter = $after;
 365              foreach ( $arcresults as $arcresult ) {
 366                  $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
 367                  $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
 368                  $text = mysql2date($archive_day_date_format, $date);
 369                  if ($show_post_count)
 370                      $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
 371                  echo get_archives_link($url, $text, $format, $before, $after);
 372              }
 373          }
 374      } elseif ( 'weekly' == $type ) {
 375          $start_of_week = get_option('start_of_week');
 376          $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC" . $limit);
 377          $arc_w_last = '';
 378          $afterafter = $after;
 379          if ( $arcresults ) {
 380                  foreach ( $arcresults as $arcresult ) {
 381                      if ( $arcresult->week != $arc_w_last ) {
 382                          $arc_year = $arcresult->yr;
 383                          $arc_w_last = $arcresult->week;
 384                          $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
 385                          $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
 386                          $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
 387                          $url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&amp;', '=', $arcresult->week);
 388                          $text = $arc_week_start . $archive_week_separator . $arc_week_end;
 389                          if ($show_post_count)
 390                              $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
 391                          echo get_archives_link($url, $text, $format, $before, $after);
 392                      }
 393                  }
 394          }
 395      } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
 396          ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC ";
 397          $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY $orderby $limit");
 398          if ( $arcresults ) {
 399              foreach ( $arcresults as $arcresult ) {
 400                  if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
 401                      $url  = get_permalink($arcresult);
 402                      $arc_title = $arcresult->post_title;
 403                      if ( $arc_title )
 404                          $text = strip_tags($arc_title);
 405                      else
 406                          $text = $arcresult->ID;
 407                      echo get_archives_link($url, $text, $format, $before, $after);
 408                  }
 409              }
 410          }
 411      }
 412  }
 413  
 414  
 415  // Used in get_calendar
 416  function calendar_week_mod($num) {
 417      $base = 7;
 418      return ($num - $base*floor($num/$base));
 419  }
 420  
 421  
 422  function get_calendar($initial = true) {
 423      global $wpdb, $m, $monthnum, $year, $timedifference, $wp_locale, $posts;
 424  
 425      $key = md5( $m . $monthnum . $year );
 426      if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
 427          if ( isset( $cache[ $key ] ) ) {
 428              echo $cache[ $key ];
 429              return;
 430          }
 431      }
 432  
 433      ob_start();
 434      // Quick check. If we have no posts at all, abort!
 435      if ( !$posts ) {
 436          $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
 437          if ( !$gotsome )
 438              return;
 439      }
 440  
 441      if ( isset($_GET['w']) )
 442          $w = ''.intval($_GET['w']);
 443  
 444      // week_begins = 0 stands for Sunday
 445      $week_begins = intval(get_option('start_of_week'));
 446      $add_hours = intval(get_option('gmt_offset'));
 447      $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours));
 448  
 449      // Let's figure out when we are
 450      if ( !empty($monthnum) && !empty($year) ) {
 451          $thismonth = ''.zeroise(intval($monthnum), 2);
 452          $thisyear = ''.intval($year);
 453      } elseif ( !empty($w) ) {
 454          // We need to get the month from MySQL
 455          $thisyear = ''.intval(substr($m, 0, 4));
 456          $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
 457          $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('$thisyear}0101', INTERVAL $d DAY) ), '%m')");
 458      } elseif ( !empty($m) ) {
 459          $calendar = substr($m, 0, 6);
 460          $thisyear = ''.intval(substr($m, 0, 4));
 461          if ( strlen($m) < 6 )
 462                  $thismonth = '01';
 463          else
 464                  $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
 465      } else {
 466          $thisyear = gmdate('Y', current_time('timestamp'));
 467          $thismonth = gmdate('m', current_time('timestamp'));
 468      }
 469  
 470      $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
 471  
 472      // Get the next and previous month and year with at least one post
 473      $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
 474          FROM $wpdb->posts
 475          WHERE post_date < '$thisyear-$thismonth-01'
 476          AND post_type = 'post' AND post_status = 'publish'
 477              ORDER BY post_date DESC
 478              LIMIT 1");
 479      $next = $wpdb->get_row("SELECT    DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
 480          FROM $wpdb->posts
 481          WHERE post_date >    '$thisyear-$thismonth-01'
 482          AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
 483          AND post_type = 'post' AND post_status = 'publish'
 484              ORDER    BY post_date ASC
 485              LIMIT 1");
 486  
 487      echo '<table id="wp-calendar">
 488      <caption>' . $wp_locale->get_month($thismonth) . ' ' . date('Y', $unixmonth) . '</caption>
 489      <thead>
 490      <tr>';
 491  
 492      $myweek = array();
 493  
 494      for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
 495          $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
 496      }
 497  
 498      foreach ( $myweek as $wd ) {
 499          $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
 500          echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
 501      }
 502  
 503      echo '
 504      </tr>
 505      </thead>
 506  
 507      <tfoot>
 508      <tr>';
 509  
 510      if ( $previous ) {
 511          echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
 512          get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
 513              date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
 514      } else {
 515          echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
 516      }
 517  
 518      echo "\n\t\t".'<td class="pad">&nbsp;</td>';
 519  
 520      if ( $next ) {
 521          echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
 522          get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month),
 523              date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
 524      } else {
 525          echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
 526      }
 527  
 528      echo '
 529      </tr>
 530      </tfoot>
 531  
 532      <tbody>
 533      <tr>';
 534  
 535      // Get days with posts
 536      $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
 537          FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
 538          AND YEAR(post_date) = '$thisyear'
 539          AND post_type = 'post' AND post_status = 'publish'
 540          AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
 541      if ( $dayswithposts ) {
 542          foreach ( $dayswithposts as $daywith ) {
 543              $daywithpost[] = $daywith[0];
 544          }
 545      } else {
 546          $daywithpost = array();
 547      }
 548  
 549  
 550  
 551      if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') )
 552          $ak_title_separator = "\n";
 553      else
 554          $ak_title_separator = ', ';
 555  
 556      $ak_titles_for_day = array();
 557      $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
 558          ."FROM $wpdb->posts "
 559          ."WHERE YEAR(post_date) = '$thisyear' "
 560          ."AND MONTH(post_date) = '$thismonth' "
 561          ."AND post_date < '".current_time('mysql')."' "
 562          ."AND post_type = 'post' AND post_status = 'publish'"
 563      );
 564      if ( $ak_post_titles ) {
 565          foreach ( $ak_post_titles as $ak_post_title ) {
 566                  if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
 567                      $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
 568                  if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
 569                      $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
 570                  else
 571                      $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
 572          }
 573      }
 574  
 575  
 576      // See how much we should pad in the beginning
 577      $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
 578      if ( 0 != $pad )
 579          echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
 580  
 581      $daysinmonth = intval(date('t', $unixmonth));
 582      for ( $day = 1; $day <= $daysinmonth; ++$day ) {
 583          if ( isset($newrow) && $newrow )
 584              echo "\n\t</tr>\n\t<tr>\n\t\t";
 585          $newrow = false;
 586  
 587          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)) )
 588              echo '<td id="today">';
 589          else
 590              echo '<td>';
 591  
 592          if ( in_array($day, $daywithpost) ) // any posts today?
 593                  echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
 594          else
 595              echo $day;
 596          echo '</td>';
 597  
 598          if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
 599              $newrow = true;
 600      }
 601  
 602      $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
 603      if ( $pad != 0 && $pad != 7 )
 604          echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
 605  
 606      echo "\n\t</tr>\n\t</tbody>\n\t</table>";
 607  
 608      $output = ob_get_contents();
 609      ob_end_clean();
 610      echo $output;
 611      $cache[ $key ] = $output;
 612      wp_cache_set( 'get_calendar', $cache, 'calendar' );
 613  }
 614  
 615  function delete_get_calendar_cache() {
 616      wp_cache_delete( 'get_calendar', 'calendar' );
 617  }
 618  add_action( 'save_post', 'delete_get_calendar_cache' );
 619  add_action( 'delete_post', 'delete_get_calendar_cache' );
 620  add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
 621  add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
 622  add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
 623  
 624  
 625  function allowed_tags() {
 626      global $allowedtags;
 627      $allowed = '';
 628      foreach ( $allowedtags as $tag => $attributes ) {
 629          $allowed .= '<'.$tag;
 630          if ( 0 < count($attributes) ) {
 631              foreach ( $attributes as $attribute => $limits ) {
 632                  $allowed .= ' '.$attribute.'=""';
 633              }
 634          }
 635          $allowed .= '> ';
 636      }
 637      return htmlentities($allowed);
 638  }
 639  
 640  
 641  /***** Date/Time tags *****/
 642  
 643  
 644  function the_date_xml() {
 645      global $post;
 646      echo mysql2date('Y-m-d', $post->post_date);
 647      //echo ""+$post->post_date;
 648  }
 649  
 650  
 651  function the_date($d='', $before='', $after='', $echo = true) {
 652      global $id, $post, $day, $previousday, $newday;
 653      $the_date = '';
 654      if ( $day != $previousday ) {
 655          $the_date .= $before;
 656          if ( $d=='' )
 657              $the_date .= mysql2date(get_option('date_format'), $post->post_date);
 658          else
 659              $the_date .= mysql2date($d, $post->post_date);
 660          $the_date .= $after;
 661          $previousday = $day;
 662      }
 663      $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
 664      if ( $echo )
 665          echo $the_date;
 666      else
 667          return $the_date;
 668  }
 669  
 670  
 671  function the_modified_date($d = '') {
 672      echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
 673  }
 674  
 675  
 676  function get_the_modified_date($d = '') {
 677      if ( '' == $d )
 678          $the_time = get_post_modified_time(get_option('date_format'));
 679      else
 680          $the_time = get_post_modified_time($d);
 681      return apply_filters('get_the_modified_date', $the_time, $d);
 682  }
 683  
 684  
 685  function the_time( $d = '' ) {
 686      echo apply_filters('the_time', get_the_time( $d ), $d);
 687  }
 688  
 689  
 690  function get_the_time( $d = '' ) {
 691      if ( '' == $d )
 692          $the_time = get_post_time(get_option('time_format'));
 693      else
 694          $the_time = get_post_time($d);
 695      return apply_filters('get_the_time', $the_time, $d);
 696  }
 697  
 698  
 699  function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp
 700      global $post;
 701      if ( $gmt )
 702          $time = $post->post_date_gmt;
 703      else
 704          $time = $post->post_date;
 705  
 706      $time = mysql2date($d, $time);
 707      return apply_filters('get_the_time', $time, $d, $gmt);
 708  }
 709  
 710  
 711  function the_modified_time($d = '') {
 712      echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
 713  }
 714  
 715  
 716  function get_the_modified_time($d = '') {
 717      if ( '' == $d )
 718          $the_time = get_post_modified_time(get_option('time_format'));
 719      else
 720          $the_time = get_post_modified_time($d);
 721      return apply_filters('get_the_modified_time', $the_time, $d);
 722  }
 723  
 724  
 725  function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp
 726      global $post;
 727  
 728      if ( $gmt )
 729          $time = $post->post_modified_gmt;
 730      else
 731          $time = $post->post_modified;
 732      $time = mysql2date($d, $time);
 733  
 734      return apply_filters('get_the_modified_time', $time, $d, $gmt);
 735  }
 736  
 737  
 738  function the_weekday() {
 739      global $wp_locale, $id, $post;
 740      $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date));
 741      $the_weekday = apply_filters('the_weekday', $the_weekday);
 742      echo $the_weekday;
 743  }
 744  
 745  
 746  function the_weekday_date($before='',$after='') {
 747      global $wp_locale, $id, $post, $day, $previousweekday;
 748      $the_weekday_date = '';
 749      if ( $day != $previousweekday ) {
 750          $the_weekday_date .= $before;
 751          $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date));
 752          $the_weekday_date .= $after;
 753          $previousweekday = $day;
 754      }
 755      $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
 756      echo $the_weekday_date;
 757  }
 758  
 759  function wp_head() {
 760      do_action('wp_head');
 761  }
 762  
 763  function wp_footer() {
 764      do_action('wp_footer');
 765  }
 766  
 767  function rsd_link() {
 768      echo '    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
 769  }
 770  
 771  function noindex() {
 772      // If the blog is not public, tell robots to go away.
 773      if ( '0' == get_option('blog_public') )
 774          echo "<meta name='robots' content='noindex,nofollow' />\n";
 775  }
 776  
 777  function rich_edit_exists() {
 778      global $wp_rich_edit_exists;
 779      if ( !isset($wp_rich_edit_exists) )
 780          $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
 781      return $wp_rich_edit_exists;
 782  }
 783  
 784  function user_can_richedit() {
 785      global $wp_rich_edit, $pagenow;
 786  
 787      if ( !isset($wp_rich_edit) )
 788          $wp_rich_edit = ( 'true' == get_user_option('rich_editing') && !preg_match('!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) && 'comment.php' != $pagenow && rich_edit_exists() ) ? true : false;
 789  
 790      return apply_filters('user_can_richedit', $wp_rich_edit);
 791  }
 792  
 793  function the_editor($content, $id = 'content', $prev_id = 'title') {
 794      $rows = get_option('default_post_edit_rows');
 795      if (($rows < 3) || ($rows > 100))
 796          $rows = 12;
 797  
 798      $rows = "rows='$rows'";
 799  
 800      if ( user_can_richedit() ) :
 801          add_filter('the_editor_content', 'wp_richedit_pre');
 802  
 803          //    The following line moves the border so that the active button "attaches" to the toolbar. Only IE needs it.
 804      ?>
 805      <style type="text/css">
 806          #postdivrich table, #postdivrich #quicktags {border-top: none;}
 807          #quicktags {border-bottom: none; padding-bottom: 2px; margin-bottom: -1px;}
 808          #edButtons {border-bottom: 1px solid #ccc;}
 809      </style>
 810      <div id='edButtons' style='display:none;'>
 811          <div class='zerosize'><input accesskey='e' type='button' onclick='switchEditors("<?php echo $id; ?>")' /></div>
 812          <input id='edButtonPreview' class='edButtonFore' type='button' value='<?php _e('Visual'); ?>' />
 813          <input id='edButtonHTML' class='edButtonBack' type='button' value='<?php _e('Code'); ?>' onclick='switchEditors("<?php echo $id; ?>")' />
 814      </div>
 815      <script type="text/javascript">
 816      // <![CDATA[
 817          if ( typeof tinyMCE != "undefined" && tinyMCE.configs.length > 0 )
 818              document.getElementById('edButtons').style.display = 'block';
 819      // ]]>
 820      </script>
 821  
 822      <?php endif; ?>
 823      <div id="quicktags">
 824      <?php wp_print_scripts( 'quicktags' ); ?>
 825      <script type="text/javascript">edToolbar()</script>
 826      </div>
 827      <script type="text/javascript">
 828      // <![CDATA[
 829          if ( typeof tinyMCE != "undefined" && tinyMCE.configs.length > 0 )
 830              document.getElementById("quicktags").style.display="none";
 831  
 832  		function edInsertContent(myField, myValue) {
 833              //IE support
 834              if (document.selection) {
 835                  myField.focus();
 836                  sel = document.selection.createRange();
 837                  sel.text = myValue;
 838                  myField.focus();
 839              }
 840              //MOZILLA/NETSCAPE support
 841              else if (myField.selectionStart || myField.selectionStart == "0") {
 842                  var startPos = myField.selectionStart;
 843                  var endPos = myField.selectionEnd;
 844                  myField.value = myField.value.substring(0, startPos)
 845                                + myValue 
 846                                + myField.value.substring(endPos, myField.value.length);
 847                  myField.focus();
 848                  myField.selectionStart = startPos + myValue.length;
 849                  myField.selectionEnd = startPos + myValue.length;
 850              } else {
 851                  myField.value += myValue;
 852                  myField.focus();
 853              }
 854          }
 855      // ]]>
 856      </script>
 857      <?php
 858  
 859      $the_editor = apply_filters('the_editor', "<div><textarea class='mceEditor' $rows cols='40' name='$id' tabindex='2' id='$id'>%s</textarea></div>\n");
 860      $the_editor_content = apply_filters('the_editor_content', $content);
 861  
 862      printf($the_editor, $the_editor_content);
 863  
 864      ?>
 865      <script type="text/javascript">
 866      //<!--
 867      edCanvas = document.getElementById('<?php echo $id; ?>');
 868      <?php if ( $prev_id && user_can_richedit() ) : ?>
 869      // This code is meant to allow tabbing from Title to Post (TinyMCE).
 870      if ( tinyMCE.isMSIE )
 871          document.getElementById('<?php echo $prev_id; ?>').onkeydown = function (e)
 872              {
 873                  e = e ? e : window.event;
 874                  if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
 875                      var i = tinyMCE.getInstanceById('<?php echo $id; ?>');
 876                      if(typeof i ==  'undefined')
 877                          return true;
 878                      tinyMCE.execCommand("mceStartTyping");
 879                      this.blur();
 880                      i.contentWindow.focus();
 881                      e.returnValue = false;
 882                      return false;
 883                  }
 884              }
 885      else
 886          document.getElementById('<?php echo $prev_id; ?>').onkeypress = function (e)
 887              {
 888                  e = e ? e : window.event;
 889                  if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
 890                      var i = tinyMCE.getInstanceById('<?php echo $id; ?>');
 891                      if(typeof i ==  'undefined')
 892                          return true;
 893                      tinyMCE.execCommand("mceStartTyping");
 894                      this.blur();
 895                      i.contentWindow.focus();
 896                      e.returnValue = false;
 897                      return false;
 898                  }
 899              }
 900      <?php endif; ?>
 901      //-->
 902      </script>
 903      <?php
 904  }
 905  
 906  function the_search_query() {
 907      global $s;
 908      echo attribute_escape(stripslashes($s));
 909  }
 910  
 911  function language_attributes() {
 912      $output = '';
 913      if ( $dir = get_bloginfo('text_direction') )
 914          $output = "dir=\"$dir\"";
 915      if ( $lang = get_bloginfo('language') ) {
 916          if ( $dir ) $output .= ' ';
 917          if ( get_option('html_type') == 'text/html' )
 918              $output .= "lang=\"$lang\"";
 919          else $output .= "xml:lang=\"$lang\"";
 920      }
 921  
 922      echo $output;
 923  }
 924  
 925  function paginate_links( $arg = '' ) {
 926      if ( is_array($arg) )
 927          $a = &$arg;
 928      else
 929          parse_str($arg, $a);
 930  
 931      // Defaults
 932      $base = '%_%'; // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
 933      $format = '?page=%#%'; // ?page=%#% : %#% is replaced by the page number
 934      $total = 1;
 935      $current = 0;
 936      $show_all = false;
 937      $prev_next = true;
 938      $prev_text = __('&laquo; Previous');
 939      $next_text = __('Next &raquo;');
 940      $end_size = 1; // How many numbers on either end including the end
 941      $mid_size = 2; // How many numbers to either side of current not including current
 942      $type = 'plain';
 943      $add_args = false; // array of query args to aadd
 944  
 945      extract($a);
 946  
 947      // Who knows what else people pass in $args
 948      $total    = (int) $total;
 949      if ( $total < 2 )
 950          return;
 951      $current  = (int) $current;
 952      $end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default.
 953      $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
 954      $add_args = is_array($add_args) ? $add_args : false;
 955      $r = '';
 956      $page_links = array();
 957      $n = 0;
 958      $dots = false;
 959  
 960      if ( $prev_next && $current && 1 < $current ) :
 961          $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
 962          $link = str_replace('%#%', $current - 1, $link);
 963          if ( $add_args )
 964              $link = add_query_arg( $add_args, $link );
 965          $page_links[] = "<a class='prev page-numbers' href='" . attribute_escape($link) . "'>$prev_text</a>";
 966      endif;
 967      for ( $n = 1; $n <= $total; $n++ ) :
 968          if ( $n == $current ) :
 969              $page_links[] = "<span class='page-numbers current'>$n</span>";
 970              $dots = true;
 971          else :
 972              if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
 973                  $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
 974                  $link = str_replace('%#%', $n, $link);
 975                  if ( $add_args )
 976                      $link = add_query_arg( $add_args, $link );
 977                  $page_links[] = "<a class='page-numbers' href='" . attribute_escape($link) . "'>$n</a>";
 978                  $dots = true;
 979              elseif ( $dots && !$show_all ) :
 980                  $page_links[] = "<span class='page-numbers dots'>...</span>";
 981                  $dots = false;
 982              endif;
 983          endif;
 984      endfor;
 985      if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
 986          $link = str_replace('%_%', $format, $base);
 987          $link = str_replace('%#%', $current + 1, $link);
 988          if ( $add_args )
 989              $link = add_query_arg( $add_args, $link );
 990          $page_links[] = "<a class='next page-numbers' href='" . attribute_escape($link) . "'>$next_text</a>";
 991      endif;
 992      switch ( $type ) :
 993          case 'array' :
 994              return $page_links;
 995              break;
 996          case 'list' :
 997              $r .= "<ul class='page-numbers'>\n\t<li>";
 998              $r .= join("</li>\n\t<li>", $page_links);
 999              $r .= "</li>\n</ul>\n";
1000              break;
1001          default :
1002              $r = join("\n", $page_links);
1003              break;
1004      endswitch;
1005      return $r;
1006  }
1007  ?>


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7