<commit_before><?php namespace Artesaos\SEOTools;

use Artesaos\SEOTools\Contracts\MetaTags as MetaTagsContract;
use Illuminate\Config\Repository as Config;

class SEOMeta implements MetaTagsContract
{
    /**
     * The meta title.
     *
     * @var string
     */
    protected $title;

    /**
     * The meta title session.
     *
     * @var string
     */
    protected $title_session;

    /**
     * The title tag seperator.
     *
     * @var array
     */
    protected $title_seperator;

    /**
     * The meta description.
     *
     * @var string
     */
    protected $description;

    /**
     * The meta keywords.
     *
     * @var array
     */
    protected $keywords = [];

    /**
     * extra metatags
     *
     * @var array
     */
    protected $metatags = [];

    /**
     * @var Config
     */
    protected $config;

    /**
     * The webmaster tags.
     *
     * @var array
     */
    protected $webmasterTags = [
        'google'   => "google-site-verification",
        'bing'     => "msvalidate.01",
        'alexa'    => "alexaVerifyID",
        'pintrest' => "p:domain_verify",
        'yandex'   => "yandex-verification"
    ];

    /**
     * @param array $config
     */
    public function __construct(array $config = array())
    {
        $this->config = new Config($config);
    }

    /**
     * Generates meta tags
     *
     * @return string
     */
    public function generate()
    {
        $this->loadWebMasterTags();

        $title       = $this->getTitle();
        $description = $this->getDescription();
        $keywords    = $this->getKeywords();
        $metatags    = $this->getMetatags();

        $html = [];

        if ($title):
            $html[] = "<title>$title</title>";
        endif;

        if ($description):
            $html[] = "<meta name=\"description\" content=\"{$description}\">";
        endif;

        if (!empty($keywords)):
            $keywords = implode(', ', $keywords);
            $html[]   = "<meta name=\"keywords\" content=\"{$keywords}\">";
        endif;

        foreach ($metatags as $key => $value):
            $name    = $value[0];
            $content = $value[1];

            // if $content is empty jump to nest
            if (empty($content)) continue;

            $html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\">";
        endforeach;

        return implode(PHP_EOL, $html);
    }

    /**
     * Sets the title
     *
     * @param string $title
     *
     * @return MetaTagsContract
     */
    public function setTitle($title)
    {
        // clean title
        $title = strip_tags($title);

        // store title session
        $this->title_session = $title;

        // store title
        $this->title = $this->parseTitle($title);

        return $this;
    }

    /**
     * Sets the separator for the title tag.
     *
     * @param string $separator
     *
     * @return MetaTagsContract
     */
    public function setTitleSeparator($separator)
    {
        $this->title_seperator = $separator;

        return $this;
    }

    /**
     * @param string $description
     *
     * @return MetaTagsContract
     */<commit_msg>#35 adding option to prevent the default title being appended<commit_after><?php namespace Artesaos\SEOTools;

use Artesaos\SEOTools\Contracts\MetaTags as MetaTagsContract;
use Illuminate\Config\Repository as Config;

class SEOMeta implements MetaTagsContract
{
    /**
     * The meta title.
     *
     * @var string
     */
    protected $title;

    /**
     * The meta title session.
     *
     * @var string
     */
    protected $title_session;

    /**
     * The title tag seperator.
     *
     * @var array
     */
    protected $title_seperator;

    /**
     * The meta description.
     *
     * @var string
     */
    protected $description;

    /**
     * The meta keywords.
     *
     * @var array
     */
    protected $keywords = [];

    /**
     * extra metatags
     *
     * @var array
     */
    protected $metatags = [];

    /**
     * @var Config
     */
    protected $config;

    /**
     * The webmaster tags.
     *
     * @var array
     */
    protected $webmasterTags = [
        'google'   => "google-site-verification",
        'bing'     => "msvalidate.01",
        'alexa'    => "alexaVerifyID",
        'pintrest' => "p:domain_verify",
        'yandex'   => "yandex-verification"
    ];

    /**
     * @param array $config
     */
    public function __construct(array $config = array())
    {
        $this->config = new Config($config);
    }

    /**
     * Generates meta tags
     *
     * @return string
     */
    public function generate()
    {
        $this->loadWebMasterTags();

        $title       = $this->getTitle();
        $description = $this->getDescription();
        $keywords    = $this->getKeywords();
        $metatags    = $this->getMetatags();

        $html = [];

        if ($title):
            $html[] = "<title>$title</title>";
        endif;

        if ($description):
            $html[] = "<meta name=\"description\" content=\"{$description}\">";
        endif;

        if (!empty($keywords)):
            $keywords = implode(', ', $keywords);
            $html[]   = "<meta name=\"keywords\" content=\"{$keywords}\">";
        endif;

        foreach ($metatags as $key => $value):
            $name    = $value[0];
            $content = $value[1];

            // if $content is empty jump to nest
            if (empty($content)) continue;

            $html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\">";
        endforeach;

        return implode(PHP_EOL, $html);
    }

    /**
     * Sets the title
     *
     * @param string $title
     *
     * @return MetaTagsContract
     */
    public function setTitle($title, $appendDefault = true)
    {
        // clean title
        $title = strip_tags($title);

        // store title session
        $this->title_session = $title;

        // store title
        if (true === $appendDefault) {
            $this->title = $this->parseTitle($title);
        } else {
            $this->title = $title;
        }

        return $this;
    }

    /**
     * Sets the separator for the title tag.
     *
     * @param string $separator
     *
     * @return MetaTagsContract
     */
    public function setTitleSeparator($separator)
    {
        $this->title_seperator = $separator;

        return $this;
    }

    /**
     * @param string $description
     *
     * @return MetaTagsContract
     */
{'fraction_non_alphanumeric': 0.147239263803681, 'fraction_numerical': 0.0015337423312883436, 'mean_word_length': 1.6659852820932135, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 46, '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': '739065', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1899, 'n_words': 431}