/** * Sanitizes plugin data, optionally adds markup, optionally translates. * * @since 0.0.1 * @access private * @see get_plugin_data() */ function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) { // Sanitize the plugin filename to a HQ_PLUGIN_DIR relative path $plugin_file = plugin_basename($plugin_file); // Translate fields if ($translate) { if ($textdomain = $plugin_data['TextDomain']) { if ($plugin_data['DomainPath']) { load_plugin_textdomain($textdomain, false, dirname($plugin_file) . $plugin_data['DomainPath']); } else { load_plugin_textdomain($textdomain, false, dirname($plugin_file)); } } elseif (in_array(basename($plugin_file), array('hello.php', 'akismet.php'))) { $textdomain = 'default'; } if ($textdomain) { foreach (array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field) { $plugin_data[$field] = translate($plugin_data[$field], $textdomain); } } } // Sanitize fields $allowed_tags = $allowed_tags_in_links = array('abbr' => array('title' => true), 'acronym' => array('title' => true), 'code' => true, 'em' => true, 'strong' => true); $allowed_tags['a'] = array('href' => true, 'title' => true); // Name is marked up inside <a> tags. Don't allow these. // Author is too, but some plugins have used <a> here (omitting Author URI). $plugin_data['Name'] = hq_kses($plugin_data['Name'], $allowed_tags_in_links); $plugin_data['Author'] = hq_kses($plugin_data['Author'], $allowed_tags); $plugin_data['Description'] = hq_kses($plugin_data['Description'], $allowed_tags); $plugin_data['Version'] = hq_kses($plugin_data['Version'], $allowed_tags); $plugin_data['PluginURI'] = esc_url($plugin_data['PluginURI']); $plugin_data['AuthorURI'] = esc_url($plugin_data['AuthorURI']); $plugin_data['Title'] = $plugin_data['Name']; $plugin_data['AuthorName'] = $plugin_data['Author']; // Apply markup if ($markup) { if ($plugin_data['PluginURI'] && $plugin_data['Name']) { $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; } if ($plugin_data['AuthorURI'] && $plugin_data['Author']) { $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; } $plugin_data['Description'] = hqtexturize($plugin_data['Description']); if ($plugin_data['Author']) { $plugin_data['Description'] .= ' <cite>' . sprintf(__('By %s.'), $plugin_data['Author']) . '</cite>'; } } return $plugin_data; }
/** * Builds the Caption shortcode output. * * Allows a plugin to replace the content that would otherwise be returned. The * filter is 'img_caption_shortcode' and passes an empty string, the attr * parameter and the content parameter values. * * The supported attributes for the shortcode are 'id', 'align', 'width', and * 'caption'. * * @since 0.0.1 * * @param array $attr { * Attributes of the caption shortcode. * * @type string $id ID of the div element for the caption. * @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft', * 'aligncenter', alignright', 'alignnone'. * @type int $width The width of the caption, in pixels. * @type string $caption The caption text. * @type string $class Additional class name(s) added to the caption container. * } * @param string $content Shortcode content. * @return string HTML content to display the caption. */ function img_caption_shortcode($attr, $content = null) { // New-style shortcode with the caption inside the shortcode with the link and image tags. if (!isset($attr['caption'])) { if (preg_match('#((?:<a [^>]+>\\s*)?<img [^>]+>(?:\\s*</a>)?)(.*)#is', $content, $matches)) { $content = $matches[1]; $attr['caption'] = trim($matches[2]); } } elseif (strpos($attr['caption'], '<') !== false) { $attr['caption'] = hq_kses($attr['caption'], 'post'); } /** * Filter the default caption shortcode output. * * If the filtered output isn't empty, it will be used instead of generating * the default caption template. * * @since 0.0.1 * * @see img_caption_shortcode() * * @param string $output The caption output. Default empty. * @param array $attr Attributes of the caption shortcode. * @param string $content The image element, possibly wrapped in a hyperlink. */ $output = apply_filters('img_caption_shortcode', '', $attr, $content); if ($output != '') { return $output; } $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption'); $atts['width'] = (int) $atts['width']; if ($atts['width'] < 1 || empty($atts['caption'])) { return $content; } if (!empty($atts['id'])) { $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" '; } $class = trim('hq-caption ' . $atts['align'] . ' ' . $atts['class']); if (current_theme_supports('html5', 'caption')) { return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="hq-caption-text">' . $atts['caption'] . '</figcaption></figure>'; } $caption_width = 10 + $atts['width']; /** * Filter the width of an image's caption. * * By default, the caption is 10 pixels greater than the width of the image, * to prevent post content from running up against a floated image. * * @since 0.0.1 * * @see img_caption_shortcode() * * @param int $caption_width Width of the caption in pixels. To remove this inline style, * return zero. * @param array $atts Attributes of the caption shortcode. * @param string $content The image element, possibly wrapped in a hyperlink. */ $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content); $style = ''; if ($caption_width) { $style = 'style="width: ' . (int) $caption_width . 'px" '; } return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="hq-caption-text">' . $atts['caption'] . '</p></div>'; }
/** * Strips all of the HTML in the content. * * @since 0.0.1 * * @param string $data Content to strip all HTML from * @return string Filtered content without any HTML */ function hq_filter_nohtml_kses($data) { return addslashes(hq_kses(stripslashes($data), 'strip')); }