[ Index ]
 

Code source de WordPress 2.1.2

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

title

Body

[fermer]

/wp-includes/ -> theme.php (source)

   1  <?php
   2  /*
   3   * Theme/template/stylesheet functions.
   4   */
   5  
   6  function get_stylesheet() {
   7      return apply_filters('stylesheet', get_option('stylesheet'));
   8  }
   9  
  10  function get_stylesheet_directory() {
  11      $stylesheet = get_stylesheet();
  12      $stylesheet_dir = get_theme_root() . "/$stylesheet";
  13      return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
  14  }
  15  
  16  function get_stylesheet_directory_uri() {
  17      $stylesheet = get_stylesheet();
  18      $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
  19      return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
  20  }
  21  
  22  function get_stylesheet_uri() {
  23      $stylesheet_dir_uri = get_stylesheet_directory_uri();
  24      $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
  25      return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
  26  }
  27  
  28  function get_locale_stylesheet_uri() {
  29      global $wp_locale;
  30      $stylesheet_dir_uri = get_stylesheet_directory_uri();
  31      $dir = get_stylesheet_directory();
  32      $locale = get_locale();
  33      if ( file_exists("$dir/$locale.css") )
  34          $stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
  35      elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )
  36          $stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
  37      else
  38          $stylesheet_uri = '';
  39      return apply_filters('locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
  40  }
  41  
  42  function get_template() {
  43      return apply_filters('template', get_option('template'));
  44  }
  45  
  46  function get_template_directory() {
  47      $template = get_template();
  48      $template_dir = get_theme_root() . "/$template";
  49      return apply_filters('template_directory', $template_dir, $template);
  50  }
  51  
  52  function get_template_directory_uri() {
  53      $template = get_template();
  54      $template_dir_uri = get_theme_root_uri() . "/$template";
  55      return apply_filters('template_directory_uri', $template_dir_uri, $template);
  56  }
  57  
  58  function get_theme_data( $theme_file ) {
  59      $theme_data = implode( '', file( $theme_file ) );
  60      $theme_data = str_replace ( '\r', '\n', $theme_data ); 
  61      preg_match( '|Theme Name:(.*)|i', $theme_data, $theme_name );
  62      preg_match( '|Theme URI:(.*)|i', $theme_data, $theme_uri );
  63      preg_match( '|Description:(.*)|i', $theme_data, $description );
  64      preg_match( '|Author:(.*)|i', $theme_data, $author_name );
  65      preg_match( '|Author URI:(.*)|i', $theme_data, $author_uri );
  66      preg_match( '|Template:(.*)|i', $theme_data, $template );
  67      if ( preg_match( '|Version:(.*)|i', $theme_data, $version ) )
  68          $version = trim( $version[1] );
  69      else
  70          $version ='';
  71      if ( preg_match('|Status:(.*)|i', $theme_data, $status) )
  72          $status = trim($status[1]);
  73      else
  74          $status = 'publish';
  75  
  76      $description = wptexturize( trim( $description[1] ) );
  77  
  78      $name = $theme_name[1];
  79      $name = trim( $name );
  80      $theme = $name;
  81  
  82      if ( '' == $author_uri[1] ) {
  83          $author = trim( $author_name[1] );
  84      } else {
  85          $author = '<a href="' . trim( $author_uri[1] ) . '" title="' . __('Visit author homepage') . '">' . trim( $author_name[1] ) . '</a>';
  86      }
  87  
  88      return array( 'Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status );
  89  }
  90  
  91  function get_themes() {
  92      global $wp_themes, $wp_broken_themes;
  93  
  94      if ( isset($wp_themes) )
  95          return $wp_themes;
  96  
  97      $themes = array();
  98      $wp_broken_themes = array();
  99      $theme_root = get_theme_root();
 100      $theme_loc = str_replace(ABSPATH, '', $theme_root);
 101  
 102      // Files in wp-content/themes directory and one subdir down
 103      $themes_dir = @ dir($theme_root);
 104      if ( !$themes_dir )
 105          return false;
 106  
 107      while ( ($theme_dir = $themes_dir->read()) !== false ) {
 108          if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
 109              if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
 110                  continue;
 111              $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
 112              $found_stylesheet = false;
 113              while ( ($theme_file = $stylish_dir->read()) !== false ) {
 114                  if ( $theme_file == 'style.css' ) {
 115                      $theme_files[] = $theme_dir . '/' . $theme_file;
 116                      $found_stylesheet = true;
 117                      break;
 118                  }
 119              }
 120              if ( !$found_stylesheet ) { // look for themes in that dir
 121                  $subdir = "$theme_root/$theme_dir";
 122                  $subdir_name = $theme_dir;
 123                  $theme_subdir = @dir( $subdir );
 124                  while ( ($theme_dir = $theme_subdir->read()) !== false ) {
 125                      if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
 126                          if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
 127                              continue;
 128                          $stylish_dir = @ dir($subdir . '/' . $theme_dir);
 129                          $found_stylesheet = false;
 130                          while ( ($theme_file = $stylish_dir->read()) !== false ) {
 131                              if ( $theme_file == 'style.css' ) {
 132                                  $theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
 133                                  $found_stylesheet = true;
 134                                  break;
 135                              }
 136                          }
 137                      }
 138                  }
 139                  $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
 140              }
 141          }
 142      }
 143  
 144      if ( !$themes_dir || !$theme_files )
 145          return $themes;
 146  
 147      sort($theme_files);
 148  
 149      foreach ( (array) $theme_files as $theme_file ) {
 150          if ( !is_readable("$theme_root/$theme_file") ) {
 151              $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
 152              continue;
 153          }
 154  
 155          $theme_data = get_theme_data("$theme_root/$theme_file");
 156  
 157          $name        = $theme_data['Name'];
 158          $title       = $theme_data['Title'];
 159          $description = wptexturize($theme_data['Description']);
 160          $version     = $theme_data['Version'];
 161          $author      = $theme_data['Author'];
 162          $template    = $theme_data['Template'];
 163          $stylesheet  = dirname($theme_file);
 164  
 165          foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) {
 166              if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
 167                  $screenshot = "screenshot.$ext";
 168                  break;
 169              }
 170          }
 171  
 172          if ( empty($name) ) {
 173              $name = dirname($theme_file);
 174              $title = $name;
 175          }
 176  
 177          if ( empty($template) ) {
 178              if ( file_exists(dirname("$theme_root/$theme_file/index.php")) )
 179                  $template = dirname($theme_file);
 180              else
 181                  continue;
 182          }
 183  
 184          $template = trim($template);
 185  
 186          if ( !file_exists("$theme_root/$template/index.php") ) {
 187              $parent_dir = dirname(dirname($theme_file));
 188              if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) {
 189                  $template = "$parent_dir/$template";     
 190              } else {
 191                  $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
 192                  continue;
 193              }
 194          }
 195  
 196          $stylesheet_files = array();
 197          $stylesheet_dir = @ dir("$theme_root/$stylesheet");
 198          if ( $stylesheet_dir ) {
 199              while ( ($file = $stylesheet_dir->read()) !== false ) {
 200                  if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
 201                      $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
 202              }
 203          }
 204  
 205          $template_files = array();
 206          $template_dir = @ dir("$theme_root/$template");
 207          if ( $template_dir ) {
 208              while(($file = $template_dir->read()) !== false) {
 209                  if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
 210                      $template_files[] = "$theme_loc/$template/$file";
 211              }
 212          }
 213  
 214          $template_dir = dirname($template_files[0]);
 215          $stylesheet_dir = dirname($stylesheet_files[0]);
 216  
 217          if ( empty($template_dir) )
 218              $template_dir = '/';
 219          if ( empty($stylesheet_dir) )
 220              $stylesheet_dir = '/';
 221  
 222          // Check for theme name collision.  This occurs if a theme is copied to
 223          // a new theme directory and the theme header is not updated.  Whichever
 224          // theme is first keeps the name.  Subsequent themes get a suffix applied.
 225          // The Default and Classic themes always trump their pretenders.
 226          if ( isset($themes[$name]) ) {
 227              if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
 228                       ('default' == $stylesheet || 'classic' == $stylesheet) ) {
 229                  // If another theme has claimed to be one of our default themes, move
 230                  // them aside.
 231                  $suffix = $themes[$name]['Stylesheet'];
 232                  $new_name = "$name/$suffix";
 233                  $themes[$new_name] = $themes[$name];
 234                  $themes[$new_name]['Name'] = $new_name;
 235              } else {
 236                  $name = "$name/$stylesheet";
 237              }
 238          }
 239  
 240          $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot);
 241      }
 242  
 243      // Resolve theme dependencies.
 244      $theme_names = array_keys($themes);
 245  
 246      foreach ( (array) $theme_names as $theme_name ) {
 247          $themes[$theme_name]['Parent Theme'] = '';
 248          if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
 249              foreach ( (array) $theme_names as $parent_theme_name ) {
 250                  if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
 251                      $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
 252                      break;
 253                  }
 254              }
 255          }
 256      }
 257  
 258      $wp_themes = $themes;
 259  
 260      return $themes;
 261  }
 262  
 263  function get_theme($theme) {
 264      $themes = get_themes();
 265  
 266      if ( array_key_exists($theme, $themes) )
 267          return $themes[$theme];
 268  
 269      return NULL;
 270  }
 271  
 272  function get_current_theme() {
 273      $themes = get_themes();
 274      $theme_names = array_keys($themes);
 275      $current_template = get_option('template');
 276      $current_stylesheet = get_option('stylesheet');
 277      $current_theme = 'WordPress Default';
 278  
 279      if ( $themes ) {
 280          foreach ( (array) $theme_names as $theme_name ) {
 281              if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
 282                      $themes[$theme_name]['Template'] == $current_template ) {
 283                  $current_theme = $themes[$theme_name]['Name'];
 284                  break;
 285              }
 286          }
 287      }
 288  
 289      return $current_theme;
 290  }
 291  
 292  function get_theme_root() {
 293      return apply_filters('theme_root', ABSPATH . "wp-content/themes");
 294  }
 295  
 296  function get_theme_root_uri() {
 297      return apply_filters('theme_root_uri', get_option('siteurl') . "/wp-content/themes", get_option('siteurl'));
 298  }
 299  
 300  function get_query_template($type) {
 301      $template = '';
 302      if ( file_exists(TEMPLATEPATH . "/{$type}.php") )
 303          $template = TEMPLATEPATH . "/{$type}.php";
 304  
 305      return apply_filters("{$type}_template", $template);
 306  }
 307  
 308  function get_404_template() {
 309      return get_query_template('404');
 310  }
 311  
 312  function get_archive_template() {
 313      return get_query_template('archive');
 314  }
 315  
 316  function get_author_template() {
 317      return get_query_template('author');
 318  }
 319  
 320  function get_category_template() {
 321      $template = '';
 322      if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') )
 323          $template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php';
 324      elseif ( file_exists(TEMPLATEPATH . "/category.php") )
 325          $template = TEMPLATEPATH . "/category.php";
 326  
 327      return apply_filters('category_template', $template);
 328  }
 329  
 330  function get_date_template() {
 331      return get_query_template('date');
 332  }
 333  
 334  function get_home_template() {
 335      $template = '';
 336  
 337      if ( file_exists(TEMPLATEPATH . "/home.php") )
 338          $template = TEMPLATEPATH . "/home.php";
 339      elseif ( file_exists(TEMPLATEPATH . "/index.php") )
 340          $template = TEMPLATEPATH . "/index.php";
 341  
 342      return apply_filters('home_template', $template);
 343  }
 344  
 345  function get_page_template() {
 346      global $wp_query;
 347  
 348      $id = $wp_query->post->ID;
 349      $template = get_post_meta($id, '_wp_page_template', true);
 350  
 351      if ( 'default' == $template )
 352          $template = '';
 353  
 354      if ( !empty($template) && file_exists(TEMPLATEPATH . "/$template") )
 355          $template = TEMPLATEPATH . "/$template";
 356      elseif ( file_exists(TEMPLATEPATH . "/page.php") )
 357          $template = TEMPLATEPATH . "/page.php";
 358      else
 359          $template = '';
 360  
 361      return apply_filters('page_template', $template);
 362  }
 363  
 364  function get_paged_template() {
 365      return get_query_template('paged');
 366  }
 367  
 368  function get_search_template() {
 369      return get_query_template('search');
 370  }
 371  
 372  function get_single_template() {
 373      return get_query_template('single');
 374  }
 375  
 376  function get_attachment_template() {
 377      global $posts;
 378      $type = explode('/', $posts[0]->post_mime_type);
 379      if ( $template = get_query_template($type[0]) )
 380          return $template;
 381      elseif ( $template = get_query_template($type[1]) )
 382          return $template;
 383      elseif ( $template = get_query_template("$type[0]_$type[1]") )
 384          return $template;
 385      else
 386          return get_query_template('attachment');
 387  }
 388  
 389  function get_comments_popup_template() {
 390      if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
 391          $template = TEMPLATEPATH . '/comments-popup.php';
 392      else
 393          $template = get_theme_root() . '/default/comments-popup.php';
 394  
 395      return apply_filters('comments_popup_template', $template);
 396  }
 397  
 398  function load_template($_template_file) {
 399      global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
 400          $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment;
 401  
 402      if ( is_array($wp_query->query_vars) )
 403          extract($wp_query->query_vars, EXTR_SKIP);
 404  
 405      require_once($_template_file);
 406  }
 407  
 408  function locale_stylesheet() {
 409      $stylesheet = get_locale_stylesheet_uri();
 410      if ( empty($stylesheet) )
 411          return;
 412      echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
 413  }
 414  
 415  function validate_current_theme() {
 416      // Don't validate during an install/upgrade.
 417      if ( defined('WP_INSTALLING') )
 418          return true;
 419  
 420      if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) {
 421          update_option('template', 'default');
 422          update_option('stylesheet', 'default');
 423          do_action('switch_theme', 'Default');
 424          return false;
 425      }
 426  
 427      if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) {
 428          update_option('template', 'default');
 429          update_option('stylesheet', 'default');
 430          do_action('switch_theme', 'Default');
 431          return false;
 432      }
 433  
 434      return true;
 435  }
 436  
 437  function get_theme_mod($name, $default = false) {
 438      $theme = get_current_theme();
 439  
 440      $mods = get_option("mods_$theme");
 441  
 442      if ( isset($mods[$name]) )
 443          return $mods[$name];
 444  
 445      return sprintf($default, get_template_directory_uri());
 446  }
 447  
 448  function set_theme_mod($name, $value) {
 449      $theme = get_current_theme();
 450  
 451      $mods = get_option("mods_$theme");
 452  
 453      $mods[$name] = $value;
 454  
 455      update_option("mods_$theme", $mods);
 456      wp_cache_delete("mods_$theme", 'options');
 457  }
 458  
 459  function remove_theme_mod( $name ) {
 460      $theme = get_current_theme();
 461  
 462      $mods = get_option("mods_$theme");
 463  
 464      if ( !isset($mods[$name]) )
 465          return;
 466  
 467      unset($mods[$name]);
 468  
 469      if ( empty($mods) )
 470          return remove_theme_mods();
 471  
 472      update_option("mods_$theme", $mods);
 473      wp_cache_delete("mods_$theme", 'options');
 474  }
 475  
 476  function remove_theme_mods() {
 477      $theme = get_current_theme();
 478  
 479      delete_option("mods_$theme");
 480  }
 481  
 482  function get_header_textcolor() {
 483      return get_theme_mod('header_textcolor', HEADER_TEXTCOLOR);
 484  }
 485  
 486  function header_textcolor() {
 487      echo get_header_textcolor();    
 488  }
 489  
 490  function get_header_image() {
 491      return get_theme_mod('header_image', HEADER_IMAGE);
 492  }
 493  
 494  function header_image() {
 495      echo get_header_image();    
 496  }
 497  
 498  function add_custom_image_header($header_callback, $admin_header_callback) {
 499      if ( ! empty($header_callback) )
 500          add_action('wp_head', $header_callback);
 501  
 502      if ( ! is_admin() )
 503          return;
 504      require_once (ABSPATH . 'wp-admin/custom-header.php');
 505      $GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback);
 506      add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
 507  }
 508  
 509  ?>


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