/**
  * Scans the template files of the active theme, and returns an
  * array of [Template Name => {file}.php]
  *
  * @since 0.2.0
  *
  * @return array
  */
 function get_post_templates()
 {
     $themes = get_themes();
     $theme = get_current_theme();
     $templates = $themes[$theme]['Template Files'];
     $post_templates = array();
     $base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
     foreach ((array) $templates as $template) {
         $template = WP_CONTENT_DIR . str_replace(WP_CONTENT_DIR, '', $template);
         $basename = str_replace($base, '', $template);
         /** Don't allow template files in subdirectories */
         if (false !== strpos($basename, '/')) {
             continue;
         }
         $template_data = implode('', file($template));
         $name = '';
         if (preg_match('|Single Post Template:(.*)$|mi', $template_data, $name)) {
             $name = _cleanup_header_comment($name[1]);
         }
         if (!empty($name)) {
             if (basename($template) != basename(__FILE__)) {
                 $post_templates[trim($name)] = $basename;
             }
         }
     }
     return $post_templates;
 }
Exemple #2
0
/**
 * Parse the plugin contents to retrieve plugin's metadata.
 *
 * The metadata of the plugin's data searches for the following in the plugin's
 * header. All plugin data must be on its own line. For plugin description, it
 * must not have any newlines or only parts of the description will be displayed
 * and the same goes for the plugin data. The below is formatted for printing.
 *
 * <code>
 * /*
 * Plugin Name: Name of Plugin
 * Plugin URI: Link to plugin information
 * Description: Plugin Description
 * Author: Plugin author's name
 * Author URI: Link to the author's web site
 * Version: Must be set in the plugin for WordPress 2.3+
 * Text Domain: Optional. Unique identifier, should be same as the one used in
 *		plugin_text_domain()
 * Domain Path: Optional. Only useful if the translations are located in a
 *		folder above the plugin's base path. For example, if .mo files are
 *		located in the locale folder then Domain Path will be "/locale/" and
 *		must have the first slash. Defaults to the base folder the plugin is
 *		located in.
 *  * / # Remove the space to close comment
 * </code>
 *
 * Plugin data returned array contains the following:
 *		'Name' - Name of the plugin, must be unique.
 *		'Title' - Title of the plugin and the link to the plugin's web site.
 *		'Description' - Description of what the plugin does and/or notes
 *		from the author.
 *		'Author' - The author's name
 *		'AuthorURI' - The authors web site address.
 *		'Version' - The plugin version number.
 *		'PluginURI' - Plugin web site address.
 *		'TextDomain' - Plugin's text domain for localization.
 *		'DomainPath' - Plugin's relative directory path to .mo files.
 *
 * Some users have issues with opening large files and manipulating the contents
 * for want is usually the first 1kiB or 2kiB. This function stops pulling in
 * the plugin contents when it has all of the required plugin data.
 *
 * The first 8kiB of the file will be pulled in and if the plugin data is not
 * within that first 8kiB, then the plugin author should correct their plugin
 * and move the plugin data headers to the top.
 *
 * The plugin file is assumed to have permissions to allow for scripts to read
 * the file. This is not checked however and the file is only opened for
 * reading.
 *
 * @link http://trac.wordpress.org/ticket/5651 Previous Optimizations.
 * @link http://trac.wordpress.org/ticket/7372 Further and better Optimizations.
 * @since 1.5.0
 *
 * @param string $plugin_file Path to the plugin file
 * @param bool $markup If the returned data should have HTML markup applied
 * @param bool $translate If the returned data should be translated
 * @return array See above for description.
 */
function get_plugin_data($plugin_file, $markup = true, $translate = true)
{
    // We don't need to write to the file, so just open for reading.
    $fp = fopen($plugin_file, 'r');
    // Pull only the first 8kiB of the file in.
    $plugin_data = fread($fp, 8192);
    // PHP will close file handle, but we are good citizens.
    fclose($fp);
    preg_match('|Plugin Name:(.*)$|mi', $plugin_data, $name);
    preg_match('|Plugin URI:(.*)$|mi', $plugin_data, $uri);
    preg_match('|Version:(.*)|i', $plugin_data, $version);
    preg_match('|Description:(.*)$|mi', $plugin_data, $description);
    preg_match('|Author:(.*)$|mi', $plugin_data, $author_name);
    preg_match('|Author URI:(.*)$|mi', $plugin_data, $author_uri);
    preg_match('|Text Domain:(.*)$|mi', $plugin_data, $text_domain);
    preg_match('|Domain Path:(.*)$|mi', $plugin_data, $domain_path);
    foreach (array('name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path') as $field) {
        if (!empty(${$field})) {
            ${$field} = _cleanup_header_comment(${$field}[1]);
        } else {
            ${$field} = '';
        }
    }
    $plugin_data = array('Name' => $name, 'Title' => $name, 'PluginURI' => $uri, 'Description' => $description, 'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version, 'TextDomain' => $text_domain, 'DomainPath' => $domain_path);
    if ($markup || $translate) {
        $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup, $translate);
    }
    return $plugin_data;
}
Exemple #3
0
/**
 * Function for getting an array of available custom templates with a specific header. Ideally,
 * this function would be used to grab custom singular post (any post type) templates.
 *
 * @since 0.7
 * @param array $args Arguments to check the templates against.
 * @return array $post_templates The array of templates.
 */
function hybrid_get_post_templates( $args = array() ) {

	$args = wp_parse_args( $args, array( 'label' => array( 'Post Template' ) ) );

	$themes = get_themes();
	$theme = get_current_theme();
	$templates = $themes[$theme]['Template Files'];
	$post_templates = array();

	if ( is_array( $templates ) ) {
		$base = array( trailingslashit( get_template_directory() ), trailingslashit( get_stylesheet_directory() ) );

		foreach ( $templates as $template ) {
			$basename = str_replace( $base, '', $template );

			$template_data = implode( '', file( $template ) );

			$name = '';
			foreach ( $args['label'] as $label ) {
				if ( preg_match( "|{$label}:(.*)$|mi", $template_data, $name ) ) {
					$name = _cleanup_header_comment( $name[1] );
					break;
				}
			}

			if ( !empty( $name ) )
				$post_templates[trim( $name )] = $basename;
		}
	}

	return $post_templates;
}
Exemple #4
0
 function get_file_data($file, $default_headers, $context = '')
 {
     // We don't need to write to the file, so just open for reading.
     $fp = fopen($file, 'r');
     // Pull only the first 8kiB of the file in.
     $file_data = fread($fp, 8192);
     // PHP will close file handle, but we are good citizens.
     fclose($fp);
     if ($context != '') {
         $extra_headers = apply_filters("extra_{$context}" . '_headers', array());
         $extra_headers = array_flip($extra_headers);
         foreach ($extra_headers as $key => $value) {
             $extra_headers[$key] = $key;
         }
         $all_headers = array_merge($extra_headers, $default_headers);
     } else {
         $all_headers = $default_headers;
     }
     foreach ($all_headers as $field => $regex) {
         preg_match('/' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, ${$field});
         if (!empty(${$field})) {
             ${$field} = _cleanup_header_comment(${$field}[1]);
         } else {
             ${$field} = '';
         }
     }
     $file_data = compact(array_keys($all_headers));
     return $file_data;
 }
Exemple #5
0
 function get_post_templates()
 {
     $themes = wp_get_themes();
     $theme = get_option('template');
     $templates = $themes[$theme]['Template Files'];
     $post_templates = array();
     if (is_array($templates)) {
         $base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
         foreach ($templates as $template) {
             $basename = str_replace($base, '', $template);
             if ($basename != 'functions.php') {
                 // don't allow template files in subdirectories
                 if (false !== strpos($basename, '/')) {
                     continue;
                 }
                 if ($basename == 'post_templates.php') {
                     continue;
                 }
                 $template_data = implode('', file($template));
                 $name = '';
                 if (preg_match('|Single Post Template:(.*)$|mi', $template_data, $name)) {
                     $name = _cleanup_header_comment($name[1]);
                 }
                 if (!empty($name)) {
                     $post_templates[trim($basename)] = $name;
                 }
             }
         }
     }
     return $post_templates;
 }
function post_tpl_get_templates()
{
    $templates = wp_get_theme()->get_files('php', 1, true);
    $post_templates = array();
    foreach ((array) $templates as $file => $full_path) {
        if (!preg_match('|' . str_replace("_", " ", "Modello_di_pubblicazione:") . '(.*)$|mi', file_get_contents($full_path), $header)) {
            continue;
        }
        $post_templates[$file] = _cleanup_header_comment($header[1]);
    }
    return $post_templates;
}
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $file
 * @return unknown
 */
function get_file_description($file)
{
    global $wp_file_descriptions;
    if (isset($wp_file_descriptions[basename($file)])) {
        return $wp_file_descriptions[basename($file)];
    } elseif (file_exists($file) && is_file($file)) {
        $template_data = implode('', file($file));
        if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
            return _cleanup_header_comment($name[1]) . ' Page Template';
        }
    }
    return basename($file);
}
Exemple #8
0
 function get_post_templates()
 {
     $templates = wp_get_theme()->get_files('php', 1);
     $post_templates = array();
     $base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
     foreach ((array) $templates as $file => $full_path) {
         if (!preg_match('|Single Post Template:(.*)$|mi', file_get_contents($full_path), $header)) {
             continue;
         }
         $post_templates[$file] = _cleanup_header_comment($header[1]);
     }
     return $post_templates;
 }
Exemple #9
0
/**
 * Get the description for standard HiveQueen theme files and other various standard
 * HiveQueen files
 *
 * @since 0.0.1
 *
 * @global array $hq_file_descriptions
 * @param string $file Filesystem path or filename
 * @return string Description of file from $hq_file_descriptions or basename of $file if description doesn't exist
 */
function get_file_description($file)
{
    global $hq_file_descriptions;
    if (isset($hq_file_descriptions[basename($file)])) {
        return $hq_file_descriptions[basename($file)];
    } elseif (file_exists($file) && is_file($file)) {
        $template_data = implode('', file($file));
        if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}
Exemple #10
0
/**
 * Get the description for standard WordPress theme files and other various standard
 * WordPress files
 *
 * @since 1.5.0
 *
 * @global array $wp_file_descriptions
 * @param string $file Filesystem path or filename
 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist.
 *                Appends 'Page Template' to basename of $file if the file is a page template
 */
function get_file_description($file)
{
    global $wp_file_descriptions, $allowed_files;
    $relative_pathinfo = pathinfo($file);
    $file_path = $allowed_files[$file];
    if (isset($wp_file_descriptions[basename($file)]) && '.' === $relative_pathinfo['dirname']) {
        return $wp_file_descriptions[basename($file)];
    } elseif (file_exists($file_path) && is_file($file_path)) {
        $template_data = implode('', file($file_path));
        if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
            return sprintf(__('%s Page Template'), _cleanup_header_comment($name[1]));
        }
    }
    return trim(basename($file));
}
 function get_header($page)
 {
     $default_headers = array('Name' => 'Template Name');
     $fp = fopen(APPPATH . 'views/templates/' . $page, 'r');
     $file_data = fread($fp, 512);
     fclose($fp);
     $file_data = str_replace("\r", "\n", $file_data);
     foreach ($default_headers as $field => $regex) {
         if (preg_match('/^[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
             $all_headers[$field] = _cleanup_header_comment($match[1]);
         } else {
             $all_headers[$field] = '';
         }
         return $all_headers;
     }
 }
 /**
  * Retrieve metadata from a file. Based on WP Core's get_file_data function
  *
  * @since 0.8
  * @param string $file Path to the file
  * @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name')
  */
 public function get_file_version($file)
 {
     // We don't need to write to the file, so just open for reading.
     $fp = fopen($file, 'r');
     // Pull only the first 8kiB of the file in.
     $file_data = fread($fp, 8192);
     // PHP will close file handle, but we are good citizens.
     fclose($fp);
     // Make sure we catch CR-only line endings.
     $file_data = str_replace("\r", "\n", $file_data);
     $version = '';
     if (preg_match('/^[ \\t\\/*#@]*' . preg_quote('@version', '/') . '(.*)$/mi', $file_data, $match) && $match[1]) {
         $version = _cleanup_header_comment($match[1]);
     }
     return $version;
 }
 public static function getScriptDataFromContents($sContent, $sType = 'plugin', $aDefaultHeaderKeys = array())
 {
     $sContent = str_replace("\r", "\n", $sContent);
     $_aHeaders = $aDefaultHeaderKeys;
     if ($sType) {
         $_aExtraHeaders = apply_filters("extra_{$sType}_headers", array());
         if (!empty($_aExtraHeaders)) {
             $_aExtraHeaders = array_combine($_aExtraHeaders, $_aExtraHeaders);
             $_aHeaders = array_merge($_aExtraHeaders, (array) $aDefaultHeaderKeys);
         }
     }
     foreach ($_aHeaders as $_sHeaderKey => $_sRegex) {
         $_bFound = preg_match('/^[ \\t\\/*#@]*' . preg_quote($_sRegex, '/') . ':(.*)$/mi', $sContent, $_aMatch);
         $_aHeaders[$_sHeaderKey] = $_bFound && $_aMatch[1] ? _cleanup_header_comment($_aMatch[1]) : '';
     }
     return $_aHeaders;
 }
/**
 * Gets all the custom templates stored inside the current skin directory
 * @param type $post 
 * @return ? templates
 * @since 1.0
 */
function cuttz_get_templates($post)
{
    $page_templates = '';
    // wp_cache_get( 'page_templates' );
    $page_templates = array();
    $files = glob(SKIN_DIR . '/*.php');
    foreach ($files as $file => $full_path) {
        if (!preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) {
            continue;
        }
        $page_templates[basename($full_path)] = _cleanup_header_comment($header[1]);
    }
    if (wp_get_theme()->parent()) {
        $page_templates = wp_get_theme()->parent()->get_page_templates($post) + $page_templates;
    }
    return apply_filters('cuttz_page_templates', $page_templates, $post);
}
Exemple #15
0
function geko_check_update($transient)
{
    if (empty($transient->checked)) {
        return $transient;
    }
    $theme_data = wp_get_theme(wp_get_theme()->template);
    $theme_slug = $theme_data->get_template();
    //Delete '-master' from the end of slug
    $theme_uri_slug = preg_replace('/-master$/', '', $theme_slug);
    $remote_version = '0.0.0';
    $style_css = wp_remote_get("https://raw.githubusercontent.com/erm2587/" . $theme_uri_slug . "/master/style.css")['body'];
    if (preg_match('/^[ \\t\\/*#@]*' . preg_quote('Version', '/') . ':(.*)$/mi', $style_css, $match) && $match[1]) {
        $remote_version = _cleanup_header_comment($match[1]);
    }
    if (version_compare($theme_data->version, $remote_version, '<')) {
        $transient->response[$theme_slug] = array('theme' => $theme_slug, 'new_version' => $remote_version, 'url' => 'https://github.com/erm2587/' . $theme_uri_slug, 'package' => 'https://github.com/erm2587/' . $theme_uri_slug . '/archive/master.zip');
    }
    return $transient;
}
 function get_template_files($type = '')
 {
     $page_templates = array();
     $files = $this->get_files('php', 1);
     foreach ($files as $file => $full_path) {
         if (!preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) {
             continue;
         }
         if ('' != $type) {
             if (!preg_match('|Template Type:(.*)$|mi', file_get_contents($full_path), $header2)) {
                 continue;
             }
             if ($type != _cleanup_header_comment($header2[1])) {
                 continue;
             }
         }
         $page_templates[$file] = _cleanup_header_comment($header[1]);
     }
     return $page_templates;
 }
Exemple #17
0
  protected function get_names($dir, &$names, &$dupes) {
    
    $handle = opendir($dir);

    // and scan through the items inside
    while (FALSE !== ($item = readdir($handle))) {
      
      $full_path = $dir.WOOF_DIR_SEP.$item;
      
      $pi = pathinfo($item);
      
      $file_name = $pi["basename"];
      
	  if (isset($pi["extension"])) {

		  $ext = strtolower($pi["extension"]);
      
	      if ($ext == "php") {
        
	        // find the template name
	        if ( preg_match( '|Template Name:(.*)$|mi', file_get_contents($full_path), $matches ) ) {
          
	          $tn = _cleanup_header_comment($matches[1]);
          
	          if (isset($names[$tn]) && $names[$tn] != $file_name) { 
	            // second condition ensures child theme overrides are ignored
	            $dupes[$tn] = $file_name; 
	          } else {
	            $names[$tn] = $file_name;
	          }
        
	        }
        
	      }

	  }	
	
      
    }
    
  }
 function get_plugin_headers()
 {
     static $all_headers = array();
     if (!empty($all_headers)) {
         return $all_headers;
     }
     $response = wp_remote_get('https://raw.githubusercontent.com/siteorigin/siteorigin-installer/' . self::UPDATES_BRANCH . '/siteorigin-installer.php');
     if (is_wp_error($response) || empty($response['body'])) {
         return false;
     }
     $file_data = $response['body'];
     $all_headers = array('Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI');
     foreach ($all_headers as $field => $regex) {
         if (preg_match('/^[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
             $all_headers[$field] = _cleanup_header_comment($match[1]);
         } else {
             $all_headers[$field] = '';
         }
     }
     return $all_headers;
 }
Exemple #19
0
/**
 * Retrieve metadata from a file.
 *
 * Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
 * Each piece of metadata must be on its own line. Fields can not span multiple
 * lines, the value will get cut at the end of the first line.
 *
 * If the file data is not within that first 8kiB, then the author should correct
 * their plugin file and move the data headers to the top.
 *
 * @link https://codex.wordpress.org/File_Header
 *
 * @since 2.9.0
 *
 * @param string $file            Path to the file.
 * @param array  $default_headers List of headers, in the format array('HeaderKey' => 'Header Name').
 * @param string $context         Optional. If specified adds filter hook "extra_{$context}_headers".
 *                                Default empty.
 * @return array Array of file headers in `HeaderKey => Header Value` format.
 */
function get_file_data($file, $default_headers, $context = '')
{
    // We don't need to write to the file, so just open for reading.
    $fp = fopen($file, 'r');
    // Pull only the first 8kiB of the file in.
    $file_data = fread($fp, 8192);
    // PHP will close file handle, but we are good citizens.
    fclose($fp);
    // Make sure we catch CR-only line endings.
    $file_data = str_replace("\r", "\n", $file_data);
    /**
     * Filter extra file headers by context.
     *
     * The dynamic portion of the hook name, `$context`, refers to
     * the context where extra headers might be loaded.
     *
     * @since 2.9.0
     *
     * @param array $extra_context_headers Empty array by default.
     */
    if ($context && ($extra_headers = apply_filters("extra_{$context}_headers", array()))) {
        $extra_headers = array_combine($extra_headers, $extra_headers);
        // keys equal values
        $all_headers = array_merge($extra_headers, (array) $default_headers);
    } else {
        $all_headers = $default_headers;
    }
    foreach ($all_headers as $field => $regex) {
        if (preg_match('/^[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
            $all_headers[$field] = _cleanup_header_comment($match[1]);
        } else {
            $all_headers[$field] = '';
        }
    }
    return $all_headers;
}
 /**
  * Return the current theme templates.
  * Template will return untranslated.
  * Uses the same approach as in class-wp-theme.php to get templates.
  *
  * @since 2.0.29
  */
 function get_theme_templates()
 {
     $theme = wp_get_theme();
     $page_templates = array();
     $files = (array) $theme->get_files('php', 1);
     foreach ($files as $file => $full_path) {
         if (!preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) {
             continue;
         }
         $page_templates[$file] = _cleanup_header_comment($header[1]);
     }
     return $page_templates;
 }
Exemple #21
0
 /**
  * Take remote file contents as string and parse headers.
  *
  * @param $contents
  * @param $type
  *
  * @return array
  */
 protected function get_file_headers($contents, $type)
 {
     $default_plugin_headers = array('Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path', 'Network' => 'Network');
     $default_theme_headers = array('Name' => 'Theme Name', 'ThemeURI' => 'Theme URI', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Version' => 'Version', 'Template' => 'Template', 'Status' => 'Status', 'Tags' => 'Tags', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path');
     if (false !== strpos($type, 'plugin')) {
         $all_headers = $default_plugin_headers;
     }
     if (false !== strpos($type, 'theme')) {
         $all_headers = $default_theme_headers;
     }
     /*
      * Make sure we catch CR-only line endings.
      */
     $file_data = str_replace("\r", "\n", $contents);
     /*
      * Merge extra headers and default headers.
      */
     $all_headers = array_merge(self::$extra_headers, (array) $all_headers);
     $all_headers = array_unique($all_headers);
     foreach ($all_headers as $field => $regex) {
         if (preg_match('/^[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
             $all_headers[$field] = _cleanup_header_comment($match[1]);
         } else {
             $all_headers[$field] = '';
         }
     }
     return $all_headers;
 }
 function scan($folder, $external = false)
 {
     global $icl_extra_packages;
     $packages = array();
     $dh = opendir($folder);
     $packages_type = basename($folder);
     if ($dh) {
         while ($f = readdir($dh)) {
             if (0 === strpos($f, '.')) {
                 continue;
             }
             $package_main_file = $folder . '/' . $f . '/load.php';
             if (file_exists($package_main_file)) {
                 $fp = fopen($package_main_file, 'r');
                 // Pull only the first 8kiB of the file in.
                 $package_info = fread($fp, 8192);
                 fclose($fp);
                 preg_match('|Package Name:(.*)$|mi', $package_info, $name);
                 preg_match('|Package URI:(.*)$|mi', $package_info, $uri);
                 preg_match('|\\n[\\s]*Version:(.*)|i', $package_info, $version);
                 if ($packages_type == 'themes' || $external) {
                     preg_match('|Theme:(.*)|i', $package_info, $theme);
                     preg_match('|Theme version:(.*)|i', $package_info, $theme_version);
                 }
                 if ($packages_type == 'plugins' || $external) {
                     preg_match('|Plugin:(.*)|i', $package_info, $plugin);
                     preg_match('|Plugin version:(.*)|i', $package_info, $plugin_version);
                 }
                 preg_match('|Description:(.*)$|mi', $package_info, $description);
                 preg_match('|Author:(.*)$|mi', $package_info, $author_name);
                 preg_match('|Author URI:(.*)$|mi', $package_info, $author_uri);
                 foreach (array('name', 'uri', 'version', 'theme', 'theme_version', 'plugin', 'plugin_version', 'description', 'author_name', 'author_uri') as $field) {
                     if (!empty(${$field})) {
                         ${$field} = _cleanup_header_comment(${$field}[1]);
                     } else {
                         ${$field} = '';
                     }
                 }
                 if ($name && $version) {
                     $package_data = array('Name' => $name, 'URI' => $uri, 'Description' => $description, 'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version);
                     if ($packages_type == 'themes' || $external) {
                         $package_data['Theme'] = $theme;
                         $package_data['ThemeVersion'] = $theme_version;
                         $package_data['id'] = $theme;
                     }
                     if ($packages_type == 'plugins' || $external) {
                         $package_data['Plugin'] = $plugin;
                         $package_data['PluginVersion'] = $plugin_version;
                         $package_data['id'] = str_replace(array('/', '.php'), array('-', ''), $plugin);
                     }
                     // add the package only if the theme is active
                     if ($external && $package_data['Plugin'] && !in_array($package_data['Plugin'], get_option('active_plugins'))) {
                         continue;
                     }
                     if ($external && $package_data['Theme']) {
                         if ($package_data['Theme'] != basename(get_template_directory()) && $package_data['Theme'] != basename(get_stylesheet_directory())) {
                             continue;
                         }
                     }
                     if ($packages_type == 'themes') {
                         if ($package_data['Theme'] != basename(get_template_directory()) && $package_data['Theme'] != basename(get_stylesheet_directory())) {
                             continue;
                         }
                     } elseif ($packages_type == 'plugins') {
                         $plugins = get_option('active_plugins');
                         if (function_exists('get_site_option')) {
                             $plugins = array_merge($plugins, array_keys(get_site_option('active_sitewide_plugins', array())));
                         }
                         if (!in_array($package_data['Plugin'], $plugins)) {
                             continue;
                         }
                     }
                     $package_data['path'] = $folder . '/' . $f;
                     $packages[$f] = $package_data;
                 }
             }
         }
         closedir($dh);
     } else {
         throw new Exception(sprintf('Can\'t open folder %s', $folder));
     }
     return $packages;
 }
Exemple #23
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @return unknown
 */
function get_page_templates()
{
    $themes = get_themes();
    $theme = get_current_theme();
    $templates = $themes[$theme]['Template Files'];
    $page_templates = array();
    if (is_array($templates)) {
        foreach ($templates as $template) {
            $template_data = implode('', file(WP_CONTENT_DIR . $template));
            $name = '';
            if (preg_match('|Template Name:(.*)$|mi', $template_data, $name)) {
                $name = _cleanup_header_comment($name[1]);
            }
            if (!empty($name)) {
                $page_templates[trim($name)] = basename($template);
            }
        }
    }
    return $page_templates;
}
 public static function get_template_version($file)
 {
     $filesystem = Redux_Filesystem::get_instance();
     // Avoid notices if file does not exist
     if (!file_exists($file)) {
         return '';
     }
     //
     //// We don't need to write to the file, so just open for reading.
     //$fp = fopen( $file, 'r' );
     //
     //// Pull only the first 8kiB of the file in.
     //$file_data = fread( $fp, 8192 );
     //
     //// PHP will close file handle, but we are good citizens.
     //fclose( $fp );
     //
     // Make sure we catch CR-only line endings.
     $data = get_file_data($file, array('version'), 'plugin');
     if (!empty($data[0])) {
         return $data[0];
     } else {
         $file_data = $filesystem->execute('get_contents', $file);
         $file_data = str_replace("\r", "\n", $file_data);
         $version = '';
         if (preg_match('/^[ \\t\\/*#@]*' . preg_quote('@version', '/') . '(.*)$/mi', $file_data, $match) && $match[1]) {
             $version = _cleanup_header_comment($match[1]);
         }
         return $version;
     }
 }
Exemple #25
0
 /**
  * Returns the theme's page templates.
  *
  * @since 3.4.0
  * @access public
  *
  * @param WP_Post|null $post Optional. The post being edited, provided for context.
  * @return array Array of page templates, keyed by filename, with the value of the translated header name.
  */
 public function get_page_templates($post = null)
 {
     // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
     if ($this->errors() && $this->errors()->get_error_codes() !== array('theme_parent_invalid')) {
         return array();
     }
     $page_templates = $this->cache_get('page_templates');
     if (!is_array($page_templates)) {
         $page_templates = array();
         $files = (array) $this->get_files('php', 1);
         foreach ($files as $file => $full_path) {
             if (!preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) {
                 continue;
             }
             $page_templates[$file] = _cleanup_header_comment($header[1]);
         }
         $this->cache_add('page_templates', $page_templates);
     }
     if ($this->load_textdomain()) {
         foreach ($page_templates as &$page_template) {
             $page_template = $this->translate_header('Template Name', $page_template);
         }
     }
     if ($this->parent()) {
         $page_templates += $this->parent()->get_page_templates($post);
     }
     /**
      * Filter list of page templates for a theme.
      *
      * @since 3.9.0
      * @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
      *
      * @param array        $page_templates Array of page templates. Keys are filenames,
      *                                     values are translated names.
      * @param WP_Theme     $this           The theme object.
      * @param WP_Post|null $post           The post being edited, provided for context, or null.
      */
     return (array) apply_filters('theme_page_templates', $page_templates, $this, $post);
 }
 /**
  * Returns the theme's doc templates.
  *
  * @since 3.4.0
  * @access public
  *
  * @param WP_Post|null $post Optional. The post being edited, provided for context.
  * @return array Array of page templates, keyed by filename, with the value of the translated header name.
  */
 public static function get_doc_templates($type = null)
 {
     $doc_templates = false;
     if (!is_array($doc_templates)) {
         $doc_templates = array();
         $files = (array) self::get_sa_files($type);
         foreach ($files as $file => $full_path) {
             if (!preg_match('|SA Template Name:(.*)$|mi', file_get_contents($full_path), $header)) {
                 continue;
             }
             $doc_templates[$file] = _cleanup_header_comment($header[1]);
         }
         // add cache
     }
     $return = apply_filters('theme_doc_templates', $doc_templates, $type);
     return array_intersect_assoc($return, $doc_templates);
 }
Exemple #27
0
 /**
  * Parse a plugin or theme file to fetch its header values.
  *
  * Based on WordPress' `get_file_data()` function.
  * 
  * @param  string $content     The file content.
  * @param  array  $all_headers The headers to return.
  * @return array               The header values.
  */
 public static function get_content_data($content, array $all_headers)
 {
     // Pull only the first 8kiB of the file in.
     if (function_exists('mb_substr')) {
         $file_data = mb_substr($content, 0, 8192);
     } else {
         $file_data = substr($content, 0, 8192);
     }
     // Make sure we catch CR-only line endings.
     $file_data = str_replace("\r", "\n", $file_data);
     foreach ($all_headers as $field => $regex) {
         if (preg_match('/^[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
             $all_headers[$field] = _cleanup_header_comment($match[1]);
         } else {
             $all_headers[$field] = '';
         }
     }
     return $all_headers;
 }
 /**
  * Parse plugin metadata from the header comment.
  * This is basically a simplified version of the get_file_data() function from /wp-includes/functions.php.
  *
  * @param $content
  * @return array
  */
 protected function getFileHeader($content)
 {
     $headers = array('Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path', 'Network' => 'Network', 'Tested WP' => 'Tested WP', 'Requires WP' => 'Requires WP', 'Tested up to' => 'Tested up to', 'Requires at least' => 'Requires at least');
     $content = str_replace("\r", "\n", $content);
     //Normalize line endings.
     $results = array();
     foreach ($headers as $field => $name) {
         $success = preg_match('/^[ \\t\\/*#@]*' . preg_quote($name, '/') . ':(.*)$/mi', $content, $matches);
         if ($success === 1 && $matches[1]) {
             $results[$field] = _cleanup_header_comment($matches[1]);
         } else {
             $results[$field] = '';
         }
     }
     return $results;
 }
Exemple #29
0
 /**
  * Returns the theme's page templates.
  *
  * @since 3.4.0
  * @access public
  *
  * @return array Array of page templates, keyed by filename, with the value of the translated header name.
  */
 public function get_page_templates()
 {
     // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
     if ($this->errors() && $this->errors()->get_error_codes() !== array('theme_parent_invalid')) {
         return array();
     }
     $page_templates = $this->cache_get('page_templates');
     if (!is_array($page_templates)) {
         $page_templates = array();
         $files = (array) $this->get_files('php', 1);
         foreach ($files as $file => $full_path) {
             if (!preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) {
                 continue;
             }
             $page_templates[$file] = _cleanup_header_comment($header[1]);
         }
         $this->cache_add('page_templates', $page_templates);
     }
     if ($this->load_textdomain()) {
         foreach ($page_templates as &$page_template) {
             $page_template = $this->translate_header('Template Name', $page_template);
         }
     }
     if ($this->parent()) {
         $page_templates += $this->parent()->get_page_templates();
     }
     return $page_templates;
 }
 function read_styles($dir)
 {
     $themes = array();
     if ($handle = opendir($dir)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != ".." && $file != ".svn" && $file != 'admin.css') {
                 $theme_data = implode('', file($dir . '/' . $file));
                 $name = '';
                 if (preg_match('|Theme Name:(.*)$|mi', $theme_data, $matches)) {
                     $name = _cleanup_header_comment($matches[1]);
                 } else {
                     $name = basename($file);
                 }
                 $themes[$file] = $name;
             }
         }
         closedir($handle);
     }
     return $themes;
 }