コード例 #1
0
ファイル: amt-utils.php プロジェクト: ashenkar/sanga
function amt_get_title_for_metadata($options, $post)
{
    // Non persistent object cache
    $amtcache_key = amt_get_amtcache_key('amt_cache_get_title_for_metadata', $post);
    $metadata_title_value = wp_cache_get($amtcache_key, $group = 'add-meta-tags');
    if ($metadata_title_value !== false) {
        return $metadata_title_value;
    }
    // Variables
    // #entity_title#, #page#, #page_total#, #site_name#, #site_tagline#
    $default_metadata_title_templates = array('front_page_default' => '#site_name#', 'front_page_default_paged' => '#site_name# | Page #page#', 'front_page_static' => '#site_name#', 'front_page_static_paged' => '#site_name# | Page #page#', 'blog_index_static' => '#entity_title#', 'blog_index_static_paged' => '#entity_title# | Page #page#', 'archive_taxonomy_category' => '#Entity_title# Archive', 'archive_taxonomy_category_paged' => '#Entity_title# Archive | Page #page#', 'archive_taxonomy_post_tag' => '#Entity_title# Archive', 'archive_taxonomy_post_tag_paged' => '#Entity_title# Archive | Page #page#', 'archive_taxonomy_CUSTOMSLUG' => '#entity_title# Archive', 'archive_taxonomy_CUSTOMSLUG_paged' => '#entity_title# Archive | Page #page#', 'archive_author' => '#entity_title# profile', 'archive_author_paged' => 'Content published by #entity_title# | Page #page#', 'archive_posttype_POSTTYPESLUG' => '#entity_title# Archive', 'archive_posttype_POSTTYPESLUG_paged' => '#entity_title# Archive | Page #page#', 'content_attachment' => '#entity_title#', 'content_page' => '#entity_title#', 'content_page_paged' => '#entity_title# | Page #page#', 'content_post' => '#entity_title#', 'content_post_paged' => '#entity_title# | Page #page#', 'content_POSTTYPESLUG' => '#entity_title#', 'content_POSTTYPESLUG_paged' => '#entity_title# | Page #page#');
    $metadata_title_templates = apply_filters('amt_titles_metadata_title_templates', $default_metadata_title_templates, $post);
    $force_custom_title = false;
    if (is_array($options) && array_key_exists('enforce_custom_title_in_metadata', $options) && $options['enforce_custom_title_in_metadata'] == '1') {
        $force_custom_title = true;
    }
    $metadata_title_value = amt_internal_get_title($options, $post, $metadata_title_templates, $force_custom_title_if_set = $force_custom_title, $caller_is_metadata_generator = true);
    // Non persistent object cache
    // Cache even empty
    wp_cache_add($amtcache_key, $metadata_title_value, $group = 'add-meta-tags');
    return $metadata_title_value;
}
コード例 #2
0
ファイル: add-meta-tags.php プロジェクト: ashenkar/sanga
function amt_get_metadata_review($options, $add_as_view = false)
{
    // Collect metadata
    //
    // Metadata from head section
    //
    $metadata_block_head = null;
    // Non persistent object cache
    $amtcache_key = amt_get_amtcache_key('amt_metadata_block_head');
    $metadata_block_head = wp_cache_get($amtcache_key, $group = 'add-meta-tags');
    if ($metadata_block_head === false) {
        $metadata_block_head = amt_add_metadata_head();
        // Cache even empty
        wp_cache_add($amtcache_key, $metadata_block_head, $group = 'add-meta-tags');
    }
    //
    // Metadata from footer
    //
    $metadata_block_footer = null;
    // Non persistent object cache
    $amtcache_key = amt_get_amtcache_key('amt_metadata_block_footer');
    $metadata_block_footer = wp_cache_get($amtcache_key, $group = 'add-meta-tags');
    if ($metadata_block_footer === false) {
        $metadata_block_footer = amt_add_metadata_footer();
        // Cache even empty
        wp_cache_add($amtcache_key, $metadata_block_footer, $group = 'add-meta-tags');
    }
    //
    // Metadata from content filter (Schema.org Microdata)
    //
    $metadata_block_content_filter = null;
    if ($options["schemaorg_force_jsonld"] == "0") {
        // What happens here:
        // The Metadata Review mode content filter should have a bigger priority that the Schema.org
        // Microdata filter. There the metadata has been stored in non persistent cache.
        // Here we retrieve it. See the notes there for more info.
        $metadata_block_content_filter = wp_cache_get('amt_cache_metadata_block_content_filter', $group = 'add-meta-tags');
    }
    // Build texts
    if ($add_as_view) {
        // $BR = '<br />';
        $BR = PHP_EOL;
        $enclosure_start = '<div id="amt-metadata-review">' . '<pre id="amt-metadata-review-pre">' . $BR;
        $enclosure_end = '</pre>' . '</div>' . $BR . $BR;
    } else {
        $BR = PHP_EOL;
        $enclosure_start = '<pre id="amt-metadata-review-pre">' . $BR;
        $enclosure_end = '</pre>' . $BR . $BR;
    }
    if ($options['review_mode_omit_notices'] == '0') {
        $text_title = '<span class="amt-ht-title">Add-Meta-Tags &mdash; Metadata Review Mode</span>' . $BR . $BR;
    } else {
        $text_title = '';
    }
    if ($options['review_mode_omit_notices'] == '0') {
        $text_intro = '<span class="amt-ht-notice"><span class="amt-ht-important">NOTE</span>: This menu has been added because <span class="amt-ht-important">Metadata Review Mode</span> has been enabled in';
        $text_intro .= $BR . 'the Add-Meta-Tags settings. Only logged in administrators can see this menu.</span>';
    } else {
        $text_intro = '';
    }
    if ($options['review_mode_omit_notices'] == '0') {
        //$text_head_intro = $BR . $BR . '<span class="amt-ht-notice">The following metadata has been added to the head section.</span>' . $BR . $BR;
        $text_head_intro = $BR . $BR . 'Metadata at the head section' . $BR;
        $text_head_intro .= '============================' . $BR . $BR;
    } else {
        $text_head_intro = '';
    }
    if ($options['review_mode_omit_notices'] == '0') {
        //$text_footer_intro = $BR . $BR . '<span class="amt-ht-notice">The following metadata has been embedded in the body of the page.</span>' . $BR . $BR;
        $text_footer_intro = $BR . $BR . 'Metadata within the body area' . $BR;
        $text_footer_intro .= '=============================' . $BR . $BR;
    } else {
        $text_footer_intro = $BR . $BR;
    }
    if ($options['review_mode_omit_notices'] == '0') {
        //$text_content_filter_intro = $BR . $BR . '<span class="amt-ht-notice">The following metadata has been embedded in the body of the page.</span>' . $BR;
        $text_content_filter_intro = $BR . $BR . 'Metadata within the body area' . $BR;
        $text_content_filter_intro .= '=============================' . $BR;
    } else {
        $text_content_filter_intro = $BR;
    }
    //
    // Build view
    //
    $data = $enclosure_start . $text_title;
    $data .= apply_filters('amt_metadata_review_text_before', $text_intro, $metadata_block_head, $metadata_block_footer, $metadata_block_content_filter);
    //
    // Metadata Overview
    //
    if ($options["review_mode_metadata_report"] == '1') {
        $metadata_overview_default_text = '';
        $data .= amt_metadata_analysis($metadata_overview_default_text, $metadata_block_head, $metadata_block_footer, $metadata_block_content_filter);
    }
    //
    // Metadata from head section
    //
    // Add for review
    if (!empty($metadata_block_head)) {
        // Pretty print JSON+LD
        if (array_key_exists('json+ld_data', $metadata_block_head)) {
            $jsonld_data_arr = json_decode($metadata_block_head['json+ld_data']);
            $metadata_block_head['json+ld_data'] = json_encode($jsonld_data_arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
        }
        $data .= apply_filters('amt_metadata_review_head', $text_head_intro, $metadata_block_head);
        $data .= amt_metatag_highlighter(implode($BR, $metadata_block_head));
    }
    //
    // Metadata from footer
    //
    // Add for review
    if (!empty($metadata_block_footer)) {
        $data .= apply_filters('amt_metadata_review_footer', $text_footer_intro, $metadata_block_footer);
        $data .= amt_metatag_highlighter(implode($BR, $metadata_block_footer));
    }
    //
    // Metadata from content filter (Schema.org Microdata)
    //
    if ($options["schemaorg_force_jsonld"] == "0") {
        if ($metadata_block_content_filter !== false) {
            // Add for review
            $data .= apply_filters('amt_metadata_review_content_filter', $text_content_filter_intro, $metadata_block_content_filter);
            $data .= amt_metatag_highlighter(implode($BR, $metadata_block_content_filter));
        }
    }
    $data .= apply_filters('amt_metadata_review_text_after', '', $metadata_block_head, $metadata_block_footer, $metadata_block_content_filter);
    // End
    $data .= $BR . $BR . $enclosure_end;
    return $data;
}