<commit_before><?php

namespace NextBuzz\SEO\Features;

/**
 * Option page administration feature
 *
 * @author <NAME> <<EMAIL>>
 */
class PostSEOBox extends BaseFeature
{

    public function name()
    {
        return __("SEO Box", 'buzz-seo');
    }

    public function desc()
    {
        return __("Add an optimization SEO box for each post.", 'buzz-seo');
    }

    private $postMeta;

    public function init()
    {
        add_action('admin_init', array($this, 'initBack'));

        // Filter title
        add_filter('document_title_parts', array($this, 'filterTitleParts'), 15);

        add_action('wp_head', array($this, 'addMetaDescription'), 1);
        add_action('wp_head', array($this, 'addRobots'), 1);

        // Add canonical
        remove_action('wp_head', 'rel_canonical');
        add_action('wp_head', array($this, 'addCanonical'), 1);

        // Add facebook opengraph data
        add_action('wp_head', array($this, 'addOpenGraphTwitter'), 1);

        // Remove wordpress its do not cache this page option since we take care of this ourselves
        remove_action('wp_head', 'noindex', 1);
    }

    public function allowDisable()
    {
        return false;
    }

    /**
     * Initialize everything that is only needed in backend
     *
     * @return void
     */
    public function initBack()
    {
        // Load SEO box for all Single pages
        new \NextBuzz\SEO\PHPTAL\MetaBox('PostSEOBox', __('Search Engine Optimization (SEO)', 'buzz-seo'));
    }

    /**
     * Change the 'title' part of the title array
     *
     * @param array $title All parts of the title IE. title/page/tagline/site
     *
     * @return array
     */
    public function filterTitleParts($title)
    {
        $postMeta = $this->getPostMeta();

        if (!empty($postMeta['pageTitle'])) {
            $title['title'] = $postMeta['pageTitle'];
        }

        return $title;
    }

    private function getPostMeta()
    {
        if ($this->postMeta === null) {
            $this->postMeta = get_post_meta(get_the_ID(), '_metaboxPostSEOBox', true);
        }

        return $this->postMeta;
    }

    public function addMetaDescription()
    {
        if (is_singular()) {
            // Add singular description<commit_msg>Fix: an issue with document title sometimes showing a post title on an archive page.<commit_after><?php

namespace NextBuzz\SEO\Features;

/**
 * Option page administration feature
 *
 * @author <NAME> <<EMAIL>>
 */
class PostSEOBox extends BaseFeature
{

    public function name()
    {
        return __("SEO Box", 'buzz-seo');
    }

    public function desc()
    {
        return __("Add an optimization SEO box for each post.", 'buzz-seo');
    }

    private $postMeta;

    public function init()
    {
        add_action('admin_init', array($this, 'initBack'));

        // Filter title
        add_filter('document_title_parts', array($this, 'filterTitleParts'), 15);

        add_action('wp_head', array($this, 'addMetaDescription'), 1);
        add_action('wp_head', array($this, 'addRobots'), 1);

        // Add canonical
        remove_action('wp_head', 'rel_canonical');
        add_action('wp_head', array($this, 'addCanonical'), 1);

        // Add facebook opengraph data
        add_action('wp_head', array($this, 'addOpenGraphTwitter'), 1);

        // Remove wordpress its do not cache this page option since we take care of this ourselves
        remove_action('wp_head', 'noindex', 1);
    }

    public function allowDisable()
    {
        return false;
    }

    /**
     * Initialize everything that is only needed in backend
     *
     * @return void
     */
    public function initBack()
    {
        // Load SEO box for all Single pages
        new \NextBuzz\SEO\PHPTAL\MetaBox('PostSEOBox', __('Search Engine Optimization (SEO)', 'buzz-seo'));
    }

    /**
     * Change the 'title' part of the title array
     *
     * @param array $title All parts of the title IE. title/page/tagline/site
     *
     * @return array
     */
    public function filterTitleParts($title)
    {
        if (!is_singular()) {
            return $title;
        }
        
        $postMeta = $this->getPostMeta();

        if (!empty($postMeta['pageTitle'])) {
            $title['title'] = $postMeta['pageTitle'];
        }

        return $title;
    }

    private function getPostMeta()
    {
        if ($this->postMeta === null) {
            $this->postMeta = get_post_meta(get_the_ID(), '_metaboxPostSEOBox', true);
        }

        return $this->postMeta;
    }

    public function addMetaDescription()
    {
        if (is_singular()) {
            // Add singular description
{'fraction_non_alphanumeric': 0.12983957219251338, 'fraction_numerical': 0.002994652406417112, 'mean_word_length': 2.342387419585418, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4198367', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1345, 'n_words': 365}