Ejemplo n.º 1
0
 /**
  * Check to see if the current page is webcomic-related.
  * 
  * We have to do this as early as possible to ensure that the
  * correct template can be set if the collection is using a custom
  * theme. Unfortunately, this means checking even before any
  * conditional tags are available.
  * 
  * @uses Webcomic::$config
  * @uses Webcomic::$integrate
  * @uses Webcomic::$collection
  * @hook setup_theme
  */
 public function setup_theme()
 {
     global $wp_rewrite;
     $match = $permalinks = array();
     if ($wp_rewrite->using_permalinks()) {
         $tokens = array('%year%' => '(?P<year>\\d{4})', '%monthnum%' => '(?P<monthnum>0[1-9]|1[012])', '%day%' => '(?P<day>0[1-9]|[12][0-9]|3[01])', '%hour%' => '(?P<hour>0[0-9]|1[0-9]|2[0-3])', '%minute%' => '(?P<minute>0[1-9]|[1-5][0-9])', '%second%' => '(?P<second>0[1-9]|[1-5][0-9])', '%post_id%' => '(?P<post_id>\\d+)', '%author%' => '(?P<author>[\\w-]+)');
         foreach (self::$config['collections'] as $k => $v) {
             $tokens["%{$k}_storyline%"] = "(?P<{$k}_storyline>([\\w-]+/?)+)";
             $permalinks["{$k}_archive"] = $v['slugs']['archive'];
             $permalinks["{$k}_webcomic"] = str_replace(array_keys($tokens), $tokens, $v['slugs']['webcomic']);
             $permalinks["{$k}_storyline"] = $v['slugs']['storyline'];
             $permalinks["{$k}_character"] = $v['slugs']['character'];
         }
     }
     if ((preg_match('/webcomic\\d+(_(storyline|character))?/', implode(' ', array_keys($_GET)), $match) or isset($_GET['post_type']) and isset(self::$config['collections'][$_GET['post_type']]) and $match[0] = $_GET['post_type'] or $wp_rewrite->using_permalinks() and preg_match('{/(' . implode('|', $permalinks) . ')/}', $_SERVER['REQUEST_URI'], $match) or $id = url_to_postid($_SERVER['REQUEST_URI']) and $match[0] = get_post_meta($id, 'webcomic_collection', true) and isset(self::$config['collections'][$match[0]])) and $match) {
         if (2 < count($match) and $permalinks) {
             foreach ($permalinks as $k => $v) {
                 if (false !== strpos($k, '_webcomic') and preg_match('{' . $v . '}', $match[1])) {
                     self::$collection = str_replace('_webcomic', '', $k);
                     break;
                 }
             }
         } else {
             $match[0] = preg_replace('/_(storyline|character)$/', '', $match[0]);
             self::$collection = empty(self::$config['collections'][$match[0]]) ? preg_replace('/_(archive|webcomic|storyline|character)$/', '', array_search($match[1], $permalinks)) : $match[0];
         }
     }
     $active_theme = new WP_Theme(get_stylesheet_directory(), '');
     self::$integrate = !$active_theme->get('Webcomic');
 }