本文整理汇总了PHP中_cleanup_header_comment函数的典型用法代码示例。如果您正苦于以下问题:PHP _cleanup_header_comment函数的具体用法?PHP _cleanup_header_comment怎么用?PHP _cleanup_header_comment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_cleanup_header_comment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_post_templates
/**
* 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;
}
示例2: get_plugin_data
/**
* 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;
}
示例3: hybrid_get_post_templates
/**
* 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;
}
示例4: get_file_data
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;
}
示例5: get_post_templates
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;
}
示例6: post_tpl_get_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;
}
示例7: get_file_description
/**
* {@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);
}
示例8: get_post_templates
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;
}
示例9: get_file_description
/**
* 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));
}
示例10: get_file_description
/**
* 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));
}
示例11: get_header
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;
}
}
示例12: get_file_version
/**
* 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;
}
示例13: getScriptDataFromContents
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;
}
示例14: cuttz_get_templates
/**
* 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);
}
示例15: geko_check_update
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;
}