private static function is_theme_found()
 {
     if (!is_network_admin()) {
         return defined('PARENT_THEME_NAME') && PARENT_THEME_NAME == 'Genesis';
     }
     $themes = Util_Theme::get_themes();
     $theme_found = false;
     foreach ($themes as $theme) {
         if (strtolower($theme->Template) == 'genesis') {
             return true;
         }
     }
 }
 /**
  * Returns current theme
  *
  * @return string
  */
 function get_theme()
 {
     static $theme = null;
     if ($theme === null) {
         $theme = Util_Theme::get_theme_key(get_theme_root(), get_template(), get_stylesheet());
     }
     return $theme;
 }
 /**
  * Returns array of detected URLs for theme templates
  *
  * @param string  $theme_name
  * @return array
  */
 function get_theme_urls($theme_name)
 {
     $urls = array();
     $theme = Util_Theme::get($theme_name);
     if ($theme && isset($theme['Template Files'])) {
         $front_page_template = false;
         if (get_option('show_on_front') == 'page') {
             $front_page_id = get_option('page_on_front');
             if ($front_page_id) {
                 $front_page_template_file = get_post_meta($front_page_id, '_wp_page_template', true);
                 if ($front_page_template_file) {
                     $front_page_template = basename($front_page_template_file, '.php');
                 }
             }
         }
         $home_url = get_home_url();
         $template_files = (array) $theme['Template Files'];
         $mime_types = get_allowed_mime_types();
         $custom_mime_types = array();
         foreach ($mime_types as $mime_type) {
             list($type1, $type2) = explode('/', $mime_type);
             $custom_mime_types = array_merge($custom_mime_types, array($type1, $type2, $type1 . '_' . $type2));
         }
         foreach ($template_files as $template_file) {
             $link = false;
             $template = basename($template_file, '.php');
             /**
              * Check common templates
              */
             switch (true) {
                 /**
                  * Handle home.php or index.php or front-page.php
                  */
                 case !$front_page_template && $template == 'home':
                 case !$front_page_template && $template == 'index':
                 case !$front_page_template && $template == 'front-page':
                     /**
                      * Handle custom home page
                      */
                 /**
                  * Handle custom home page
                  */
                 case $template == $front_page_template:
                     $link = $home_url . '/';
                     break;
                     /**
                      * Handle 404.php
                      */
                 /**
                  * Handle 404.php
                  */
                 case $template == '404':
                     $permalink = get_option('permalink_structure');
                     if ($permalink) {
                         $link = sprintf('%s/%s/', $home_url, '404_test');
                     } else {
                         $link = sprintf('%s/?p=%d', $home_url, 999999999);
                     }
                     break;
                     /**
                      * Handle search.php
                      */
                 /**
                  * Handle search.php
                  */
                 case $template == 'search':
                     $link = sprintf('%s/?s=%s', $home_url, 'search_test');
                     break;
                     /**
                      * Handle date.php or archive.php
                      */
                 /**
                  * Handle date.php or archive.php
                  */
                 case $template == 'date':
                 case $template == 'archive':
                     $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $time = strtotime($posts[0]->post_date);
                         $link = get_day_link(date('Y', $time), date('m', $time), date('d', $time));
                     }
                     break;
                     /**
                      * Handle author.php
                      */
                 /**
                  * Handle author.php
                  */
                 case $template == 'author':
                     $author_id = false;
                     if (function_exists('get_users')) {
                         $users = get_users();
                         if (is_array($users) && count($users)) {
                             $user = current($users);
                             $author_id = $user->ID;
                         }
                     } else {
                         $author_ids = get_author_user_ids();
                         if (is_array($author_ids) && count($author_ids)) {
                             $author_id = $author_ids[0];
                         }
                     }
                     if ($author_id) {
                         $link = get_author_posts_url($author_id);
                     }
                     break;
                     /**
                      * Handle category.php
                      */
                 /**
                  * Handle category.php
                  */
                 case $template == 'category':
                     $category_ids = get_terms('category', array('orderby' => 'id', 'number' => 1, 'fields' => 'ids'));
                     if (is_array($category_ids) && count($category_ids)) {
                         $link = get_category_link($category_ids[0]);
                     }
                     break;
                     /**
                      * Handle tag.php
                      */
                 /**
                  * Handle tag.php
                  */
                 case $template == 'tag':
                     $term_ids = get_terms('post_tag', 'fields=ids');
                     if (is_array($term_ids) && count($term_ids)) {
                         $link = get_term_link($term_ids[0], 'post_tag');
                     }
                     break;
                     /**
                      * Handle taxonomy.php
                      */
                 /**
                  * Handle taxonomy.php
                  */
                 case $template == 'taxonomy':
                     $taxonomy = '';
                     if (isset($GLOBALS['wp_taxonomies']) && is_array($GLOBALS['wp_taxonomies'])) {
                         foreach ($GLOBALS['wp_taxonomies'] as $wp_taxonomy) {
                             if (!in_array($wp_taxonomy->name, array('category', 'post_tag', 'link_category'))) {
                                 $taxonomy = $wp_taxonomy->name;
                                 break;
                             }
                         }
                     }
                     if ($taxonomy) {
                         $terms = get_terms($taxonomy, array('number' => 1));
                         if (is_array($terms) && count($terms)) {
                             $link = get_term_link($terms[0], $taxonomy);
                         }
                     }
                     break;
                     /**
                      * Handle attachment.php
                      */
                 /**
                  * Handle attachment.php
                  */
                 case $template == 'attachment':
                     $attachments = get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($attachments) && count($attachments)) {
                         $link = get_attachment_link($attachments[0]->ID);
                     }
                     break;
                     /**
                      * Handle single.php
                      */
                 /**
                  * Handle single.php
                  */
                 case $template == 'single':
                     $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle page.php
                      */
                 /**
                  * Handle page.php
                  */
                 case $template == 'page':
                     $pages_ids = get_all_page_ids();
                     if (is_array($pages_ids) && count($pages_ids)) {
                         $link = get_page_link($pages_ids[0]);
                     }
                     break;
                     /**
                      * Handle comments-popup.php
                      */
                 /**
                  * Handle comments-popup.php
                  */
                 case $template == 'comments-popup':
                     $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = sprintf('%s/?comments_popup=%d', $home_url, $posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle paged.php
                      */
                 /**
                  * Handle paged.php
                  */
                 case $template == 'paged':
                     global $wp_rewrite;
                     if ($wp_rewrite->using_permalinks()) {
                         $link = sprintf('%s/page/%d/', $home_url, 1);
                     } else {
                         $link = sprintf('%s/?paged=%d', 1);
                     }
                     break;
                     /**
                      * Handle author-id.php or author-nicename.php
                      */
                 /**
                  * Handle author-id.php or author-nicename.php
                  */
                 case preg_match('~^author-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_author_posts_url($matches[1]);
                     } else {
                         $link = get_author_posts_url(null, $matches[1]);
                     }
                     break;
                     /**
                      * Handle category-id.php or category-slug.php
                      */
                 /**
                  * Handle category-id.php or category-slug.php
                  */
                 case preg_match('~^category-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_category_link($matches[1]);
                     } else {
                         $term = get_term_by('slug', $matches[1], 'category');
                         if (is_object($term)) {
                             $link = get_category_link($term->term_id);
                         }
                     }
                     break;
                     /**
                      * Handle tag-id.php or tag-slug.php
                      */
                 /**
                  * Handle tag-id.php or tag-slug.php
                  */
                 case preg_match('~^tag-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_tag_link($matches[1]);
                     } else {
                         $term = get_term_by('slug', $matches[1], 'post_tag');
                         if (is_object($term)) {
                             $link = get_tag_link($term->term_id);
                         }
                     }
                     break;
                     /**
                      * Handle taxonomy-taxonomy-term.php
                      */
                 /**
                  * Handle taxonomy-taxonomy-term.php
                  */
                 case preg_match('~^taxonomy-(.+)-(.+)$~', $template, $matches):
                     $link = get_term_link($matches[2], $matches[1]);
                     break;
                     /**
                      * Handle taxonomy-taxonomy.php
                      */
                 /**
                  * Handle taxonomy-taxonomy.php
                  */
                 case preg_match('~^taxonomy-(.+)$~', $template, $matches):
                     $terms = get_terms($matches[1], array('number' => 1));
                     if (is_array($terms) && count($terms)) {
                         $link = get_term_link($terms[0], $matches[1]);
                     }
                     break;
                     /**
                      * Handle MIME_type.php
                      */
                 /**
                  * Handle MIME_type.php
                  */
                 case in_array($template, $custom_mime_types):
                     $posts = get_posts(array('post_mime_type' => '%' . $template . '%', 'post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle single-posttype.php
                      */
                 /**
                  * Handle single-posttype.php
                  */
                 case preg_match('~^single-(.+)$~', $template, $matches):
                     $posts = get_posts(array('post_type' => $matches[1], 'numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle page-id.php or page-slug.php
                      */
                 /**
                  * Handle page-id.php or page-slug.php
                  */
                 case preg_match('~^page-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_permalink($matches[1]);
                     } else {
                         $posts = get_posts(array('pagename' => $matches[1], 'post_type' => 'page', 'numberposts' => 1));
                         if (is_array($posts) && count($posts)) {
                             $link = get_permalink($posts[0]->ID);
                         }
                     }
                     break;
                     /**
                      * Try to handle custom template
                      */
                 /**
                  * Try to handle custom template
                  */
                 default:
                     $posts = get_posts(array('pagename' => $template, 'post_type' => 'page', 'numberposts' => 1));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
             }
             if ($link && !is_wp_error($link)) {
                 $urls[$template] = $link;
             }
         }
     }
     return $urls;
 }
 /**
  * Returns array of theme groups
  *
  * @param string  $theme_name
  * @return array
  */
 public static function get_theme_files($theme_name)
 {
     $patterns = array('404', 'search', 'taxonomy(-.*)?', 'front-page', 'home', 'index', '(image|video|text|audio|application).*', 'attachment', 'single(-.*)?', 'page(-.*)?', 'category(-.*)?', 'tag(-.*)?', 'author(-.*)?', 'date', 'archive', 'comments-popup', 'paged');
     $templates = array();
     $theme = Util_Theme::get($theme_name);
     if ($theme && isset($theme['Template Files'])) {
         $template_files = (array) $theme['Template Files'];
         foreach ($template_files as $template_file) {
             /**
              * Check file name
              */
             $template = basename($template_file, '.php');
             foreach ($patterns as $pattern) {
                 $regexp = '~^' . $pattern . '$~';
                 if (preg_match($regexp, $template)) {
                     $templates[] = $template_file;
                     continue 2;
                 }
             }
             /**
              * Check get_header function call
              */
             $template_content = @file_get_contents($template_file);
             if ($template_content && preg_match('~\\s*get_header[0-9_]*\\s*\\(~', $template_content)) {
                 $templates[] = $template_file;
             }
         }
         sort($templates);
         reset($templates);
     }
     return $templates;
 }
 /**
  * Returns server info
  *
  * @return array
  */
 private function get_server_info()
 {
     global $wp_version, $wp_db_version, $wpdb;
     $wordpress_plugins = get_plugins();
     $wordpress_plugins_active = array();
     foreach ($wordpress_plugins as $wordpress_plugin_file => $wordpress_plugin) {
         if (is_plugin_active($wordpress_plugin_file)) {
             $wordpress_plugins_active[$wordpress_plugin_file] = $wordpress_plugin;
         }
     }
     $mysql_version = $wpdb->get_var('SELECT VERSION()');
     $mysql_variables_result = (array) $wpdb->get_results('SHOW VARIABLES', ARRAY_N);
     $mysql_variables = array();
     foreach ($mysql_variables_result as $mysql_variables_row) {
         $mysql_variables[$mysql_variables_row[0]] = $mysql_variables_row[1];
     }
     $server_info = array('w3tc' => array('version' => W3TC_VERSION, 'server' => !empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown', 'dir' => W3TC_DIR, 'cache_dir' => W3TC_CACHE_DIR, 'blog_id' => Util_Environment::blog_id(), 'home_domain_root_url' => Util_Environment::home_domain_root_url(), 'home_url_maybe_https' => Util_Environment::home_url_maybe_https(), 'site_path' => Util_Environment::site_path(), 'document_root' => Util_Environment::document_root(), 'site_root' => Util_Environment::site_root(), 'site_url_uri' => Util_Environment::site_url_uri(), 'home_url_host' => Util_Environment::home_url_host(), 'home_url_uri' => Util_Environment::home_url_uri(), 'network_home_url_uri' => Util_Environment::network_home_url_uri(), 'host_port' => Util_Environment::host_port(), 'host' => Util_Environment::host(), 'wp_config_path' => Util_Environment::wp_config_path()), 'wp' => array('version' => $wp_version, 'db_version' => $wp_db_version, 'abspath' => ABSPATH, 'home' => get_option('home'), 'siteurl' => get_option('siteurl'), 'email' => get_option('admin_email'), 'upload_info' => (array) Util_Http::upload_info(), 'theme' => Util_Theme::get_current_theme(), 'wp_cache' => defined('WP_CACHE') && WP_CACHE ? 'true' : 'false', 'plugins' => $wordpress_plugins_active), 'mysql' => array('version' => $mysql_version, 'variables' => $mysql_variables));
     return $server_info;
 }
 /**
  * Stylesheet filter
  *
  * @param unknown $stylesheet
  * @return string
  */
 function stylesheet_preview($stylesheet)
 {
     $theme_name = Util_Request::get_string('w3tc_theme');
     $theme = Util_Theme::get($theme_name);
     if ($theme) {
         return $theme['Stylesheet'];
     }
     return $stylesheet;
 }
 /**
  * Return array of themes
  *
  * @return array
  */
 function get_themes()
 {
     $themes = array();
     $wp_themes = Util_Theme::get_themes();
     foreach ($wp_themes as $wp_theme) {
         $theme_key = sprintf('%s/%s', $wp_theme['Template'], $wp_theme['Stylesheet']);
         $themes[$theme_key] = $wp_theme['Name'];
     }
     return $themes;
 }