Ejemplo n.º 1
0
 /**
  * Returns array of detected URLs for theme templates
  *
  * @param string $theme_name
  * @return array
  */
 function get_theme_urls($theme_name)
 {
     $urls = array();
     $theme = w3tc_get_theme($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 = w3_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_all_category_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;
 }
Ejemplo n.º 2
0
        function _modify_view_screen($errors = array())
        {
            foreach ((array) $errors as $error) {
                ITUtility::show_error_message($error);
            }
            $view = array();
            if (isset($_POST['layout'])) {
                $view = array('layout' => $_POST['layout'], 'view' => $_POST['view'], 'category_id' => $_POST['category_id'], 'tag_id' => $_POST['tag_id'], 'author_id' => $_POST['author_id'], 'extension' => isset($_POST['extension']) ? $_POST['extension'] : '');
            } else {
                if (isset($_REQUEST['original_view']) && isset($this->_options['views'][$_REQUEST['original_view']])) {
                    $view = $this->_get_view_data($_REQUEST['original_view']);
                }
            }
            $layouts = array();
            $layouts[__('Rules', 'it-l10n-Builder-Paige')] = array('//INHERIT//' => __('Use this View\'s Active Layout', 'it-l10n-Builder-Paige'), '' => __('Use the site\'s Default Layout', 'it-l10n-Builder-Paige'));
            $layout_index_name = __('Layouts', 'it-l10n-Builder-Paige');
            uksort($this->_options['layouts'], array($this, '_orderedSort'));
            foreach ((array) $this->_options['layouts'] as $id => $layout) {
                $layouts[$layout_index_name][$id] = $layout['description'];
            }
            $available_views = apply_filters('builder_get_available_views', array());
            if (empty($_REQUEST['original_view']) && empty($_REQUEST['view'])) {
                $views = array('' => '');
            }
            foreach ((array) $available_views as $id => $view_data) {
                if (empty($this->_options['views'][$id]) || isset($_REQUEST['original_view']) && $_REQUEST['original_view'] === $id || in_array($id, array('is_category', 'is_tag', 'is_author'))) {
                    $views[$id] = $view_data['name'];
                }
            }
            asort($views);
            $exclude_categories = '';
            $exclude_tags = '';
            $exclude_authors = array();
            foreach ((array) $this->_options['views'] as $view_id => $view_data) {
                if (preg_match('/is_category__(\\d+)/', $view_id, $matches) && (empty($view['view_id']) || $view_id !== $view['view_id'])) {
                    if (!empty($exclude_categories)) {
                        $exclude_categories .= ',';
                    }
                    $exclude_categories .= $matches[1];
                } else {
                    if (preg_match('/is_tag__(\\d+)/', $view_id, $matches) && (empty($view['view_id']) || $view_id !== $view['view_id'])) {
                        if (!empty($exclude_tags)) {
                            $exclude_tags .= ',';
                        }
                        $exclude_tags .= $matches[1];
                    } else {
                        if (preg_match('/is_author__(\\d+)/', $view_id, $matches) && (empty($view['view_id']) || $view_id !== $view['view_id'])) {
                            $exclude_authors[] = $matches[1];
                        }
                    }
                }
            }
            $category_arguments = array('hide_empty' => 0, 'orderby' => 'name', 'hierarchical' => true, 'exclude' => $exclude_categories);
            if (isset($view['category_id']) && !is_null($view['category_id'])) {
                $category_arguments['selected'] = $view['category_id'];
            }
            $category_options = array();
            if (!isset($this->_options['views']['is_category']) || isset($view['view_id']) && 'is_category' === $view['view_id']) {
                $category_options['__optgroup_1'][] = __('All Categories', 'it-l10n-Builder-Paige');
            }
            $categories = get_categories($category_arguments);
            if (!empty($categories)) {
                foreach ((array) $categories as $category) {
                    $category_options['__optgroup_2'][$category->term_id] = $this->_get_full_term_name($category->term_id, $category->taxonomy);
                }
                natcasesort($category_options['__optgroup_2']);
            }
            if (empty($category_options)) {
                unset($views['is_category']);
            }
            $tag_arguments = array('hide_empty' => 0, 'orderby' => 'name', 'exclude' => $exclude_tags);
            $tag_options = array();
            if (!isset($this->_options['views']['is_tag']) || isset($view['view_id']) && 'is_tag' === $view['view_id']) {
                $tag_options['__optgroup_1'][] = __('All Tags', 'it-l10n-Builder-Paige');
            }
            $tags = get_tags($tag_arguments);
            if (!empty($tags)) {
                foreach ((array) $tags as $tag) {
                    $tag_options['__optgroup_2'][$tag->term_id] = $tag->name;
                }
                natcasesort($tag_options['__optgroup_2']);
            }
            if (empty($tag_options)) {
                unset($views['is_tag']);
            }
            $author_options = array();
            if (!isset($this->_options['views']['is_author']) || isset($view['view_id']) && 'is_author' === $view['view_id']) {
                $author_options['__optgroup_1'][] = __('All Authors', 'it-l10n-Builder-Paige');
            }
            $authors = function_exists('get_users') ? get_users(array('who' => 'authors')) : get_author_user_ids();
            if (!empty($authors)) {
                foreach ((array) $authors as $author) {
                    if (is_object($author) && isset($author->ID)) {
                        $author_id = $author->ID;
                    } else {
                        $author_id = $author;
                    }
                    if (!in_array($author_id, $exclude_authors)) {
                        $author = get_userdata($author_id);
                        $author_options['__optgroup_2'][$author_id] = "{$author->display_name} ({$author->user_login})";
                    }
                }
                natcasesort($author_options['__optgroup_2']);
            }
            if (empty($author_options)) {
                unset($views['is_author']);
            }
            if (builder_theme_supports('builder-extensions')) {
                $extension_options = array();
                $extension_options[__('Rules', 'it-l10n-Builder-Paige')] = array('' => __('Use the Active Extension', 'it-l10n-Builder-Paige'), '//DISABLE_EXTENSION//' => __('Disable the Active Extension', 'it-l10n-Builder-Paige'));
                $extension_options[__('Extensions', 'it-l10n-Builder-Paige')] = apply_filters('builder_get_extensions_with_names', array());
                $extensions_data = apply_filters('builder_get_extensions_data', array());
                foreach ($extensions_data as $extension => $extension_data) {
                    $description = $extension_data['description'];
                    if (!empty($description)) {
                        $description = "<p>{$description}</p>";
                    }
                    if ($extension_data['disable_theme_style']) {
                        $description .= __('<p><strong>Notice:</strong> This Extension replaces theme styling with its own.</p>', 'it-l10n-Builder-Paige');
                    }
                    $extension_descriptions[] = '"' . str_replace('"', '\\"', $extension) . '": "' . str_replace('"', '\\"', $description) . '"';
                }
            }
            $form = new ITForm($view);
            ?>
	<?php 
            $form->start_form();
            ?>
		<h1><?php 
            echo empty($_REQUEST['original_view']) ? __('Add View', 'it-l10n-Builder-Paige') : __('Modify View', 'it-l10n-Builder-Paige');
            ?>
</h1>
		
		<table class="valign-top">
			<tr><td><?php 
            _e('View', 'it-l10n-Builder-Paige');
            ?>
</td>
				<td>
					<?php 
            $form->add_drop_down('view', $views);
            ?>
					<div id="view-description"></div>
				</td>
			</tr>
			<tr id="tag-options" style="display:none;"><td><?php 
            _e('Tag', 'it-l10n-Builder-Paige');
            ?>
</td>
				<td>
					<?php 
            $form->add_drop_down('tag_id', $tag_options);
            ?>
				</td>
			</tr>
			<tr id="category-options" style="display:none;"><td><?php 
            _e('Category', 'it-l10n-Builder-Paige');
            ?>
</td>
				<td>
					<?php 
            $form->add_drop_down('category_id', $category_options);
            ?>
				</td>
			</tr>
			<tr id="author-options" style="display:none;"><td><?php 
            _e('Author', 'it-l10n-Builder-Paige');
            ?>
</td>
				<td>
					<?php 
            $form->add_drop_down('author_id', $author_options);
            ?>
				</td>
			</tr>
			<tr><td><?php 
            _e('Layout', 'it-l10n-Builder-Paige');
            ?>
</td>
				<td>
					<?php 
            $form->add_drop_down('layout', $layouts);
            ?>
					<?php 
            ITUtility::add_tooltip(__('The Active Layout is the Layout that would be used if this View did not exist.', 'it-l10n-Builder-Paige'));
            ?>
				</td>
			</tr>
			<?php 
            if (builder_theme_supports('builder-extensions')) {
                ?>
				<tr><td><?php 
                _e('Extension', 'it-l10n-Builder-Paige');
                ?>
</td>
					<td>
						<?php 
                $form->add_drop_down('extension', $extension_options);
                ?>
						<?php 
                ITUtility::add_tooltip(__('The Active Extension is the Extension that would be used if this View did not exist.', 'it-l10n-Builder-Paige'));
                ?>
						
						<div id="extension-details"></div>
					</td>
				</tr>
			<?php 
            }
            ?>
		</table>
		<?php 
            $form->add_hidden('render_clean', 'dialog');
            ?>
		<?php 
            if (isset($_REQUEST['original_view'])) {
                $form->add_hidden('original_view', $_REQUEST['original_view']);
            }
            ?>
		
		<p class="submit">
			<?php 
            $save_desc = empty($_REQUEST['original_view']) ? __('Add', 'it-l10n-Builder-Paige') : __('Update', 'it-l10n-Builder-Paige');
            ?>
			<?php 
            $form->add_submit('modify_view', array('value' => $save_desc, 'class' => 'button-primary save'));
            ?>
			<?php 
            $form->add_submit('cancel', array('value' => __('Cancel', 'it-l10n-Builder-Paige'), 'class' => 'button-secondary', 'onclick' => 'it_dialog_remove();'));
            ?>
		</p>
		
		<div id="view-descriptions" style="display:none;">
			<?php 
            foreach ((array) $available_views as $id => $view) {
                ?>
				<div id="view-<?php 
                echo $this->_parse_view_id($id);
                ?>
"><?php 
                echo $view['description'];
                ?>
</div>
			<?php 
            }
            ?>
		</div>
		
		<?php 
            $form->add_hidden('editor_tab', $_REQUEST['editor_tab']);
            ?>
	<?php 
            $form->end_form();
            ?>
	<script type="text/javascript">
		<?php 
            if (isset($extension_descriptions)) {
                ?>
			var builder_extension_details = {<?php 
                echo implode(",\n", $extension_descriptions);
                ?>
};
		<?php 
            }
            ?>
		
//		it_dialog_update_size();
		
		
		init_modify_view_screen();
	</script>
<?php 
        }