<commit_before><?php

namespace Craft;

class SitemapService extends BaseApplicationComponent
{
    /**
     * Array of Sitemap_UrlModel instances.
     *
     * @var array
     */
    protected $urls = array();

    /**
     * {@inheritdoc} CApplicationComponent::init()
     */
    public function init()
    {
        Craft::import('plugins.sitemap.library.*');

        parent::init();
    }

    /**
     * Returns all sections that have URLs.
     *
     * @return array An array of Section instances
     */
    public function getSectionsWithUrls()
    {
        return array_filter(craft()->sections->allSections, function ($section) {
            return $section->isHomepage() || $section->urlFormat;
        });
    }

    /**
     * Return the sitemap as a string.
     *
     * @return string
     */
    public function getSitemap()
    {
        $settings = $this->pluginSettings;

        // Loop through and add the sections checked in the plugin settings
        foreach ($this->sectionsWithUrls as $section) {
            if (!empty($settings['sections'][$section->id])) {
                $changefreq = $settings['sections'][$section->id]['changefreq'];
                $priority = $settings['sections'][$section->id]['priority'];
                $this->addSection($section, $changefreq, $priority);
            }
        }

        // Hook: renderSitemap
        craft()->plugins->call('renderSitemap');

        // Use DOMDocument to generate XML
        $document = new \DOMDocument('1.0', 'utf-8');

        // Format XML output when devMode is active for easier debugging
        if (craft()->config->get('devMode')) {
            $document->formatOutput = true;
        }

        // Append a urlset node
        $urlset = $document->createElement('urlset');
        $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
        $urlset->setAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
        $document->appendChild($urlset);

        // Loop through and append Sitemap_UrlModel elements
        foreach ($this->urls as $url) {
            $urlElement = $url->getDomElement($document);
            $urlset->appendChild($urlElement);
        }

        return $document->saveXML();
    }

    /**
     * Adds a URL to the sitemap.
     */
    public function addUrl(Sitemap_UrlModel $url)
    {
        if ($url->validate()) {
            $this->urls[$url->loc] = $url;
        }
    }

    /**
     * Adds an element to the sitemap.
     *
     * @param BaseElementModel $element
     * @param string           $changefreq
     * @param string           $priority
     */
    public function addElement(BaseElementModel $element, $changefreq = null, $priority = null)
    {
        $url = new Sitemap_UrlModel($element->url, $element->dateUpdated, $changefreq, $priority);

        $locales = craft()->elements->getEnabledLocalesForElement($element->id);
        foreach ($locales as $locale) {
            $alternateUrl = new Sitemap_AlternateUrlModel();
            $alternateUrl->hreflang = $locale;
            $alternateUrl->href = craft()->sitemap->getElementUrlForLocale($element, $locale);

            $url->addAlternateUrl($alternateUrl);
        }

        $this->addUrl($url);
    }

    /**
     * Adds all entries related to the section to the sitemap.
     *
     * @param SectionModel $section
     * @param string       $changefreq
     * @param string       $priority
     */
    public function addSection(SectionModel $section, $changefreq = null, $priority = null)
    {
        $criteria = craft()->elements->getCriteria(ElementType::Entry);
        $criteria->section = $section;
        foreach ($criteria->find() as $element) {
            $this->addElement($element, $changefreq, $priority);
        }
    }

    /**
     * Adds all entries related to the category to the sitemap.
     *
     * @param CategoryModel $category
     * @param string        $changefreq
     * @param string        $priority
     */
    public function addCategory(CategoryModel $category, $changefreq = null, $priority = null)
    {
        $criteria = craft()->elements->getCriteria(ElementType::Entry);
        $criteria->category = $category;

        $entries = $criteria->find();
        foreach ($entries as $entry) {
            $this->addElement($entry, $changefreq, $priority);
        }
    }

    /**
     * Adds all entries related to the group to the sitemap.
     *
     * @param CategoryGroupModel $categoryGroup
     * @param string             $changefreq
     * @param string             $priority
     */
    public function addCategoryGroup(CategoryGroupModel $categoryGroup, $changefreq = null, $priority = null)
    {
        $criteria = craft()->elements->getCriteria(ElementType::Category);
        $criteria->group = $categoryGroup;

        $categories = $criteria->find();
        foreach ($categories as $category) {<commit_msg>Removed addCategory group<commit_after><?php

namespace Craft;

class SitemapService extends BaseApplicationComponent
{
    /**
     * Array of Sitemap_UrlModel instances.
     *
     * @var array
     */
    protected $urls = array();

    /**
     * {@inheritdoc} CApplicationComponent::init()
     */
    public function init()
    {
        Craft::import('plugins.sitemap.library.*');

        parent::init();
    }

    /**
     * Returns all sections that have URLs.
     *
     * @return array An array of Section instances
     */
    public function getSectionsWithUrls()
    {
        return array_filter(craft()->sections->allSections, function ($section) {
            return $section->isHomepage() || $section->urlFormat;
        });
    }

    /**
     * Return the sitemap as a string.
     *
     * @return string
     */
    public function getSitemap()
    {
        $settings = $this->pluginSettings;

        // Loop through and add the sections checked in the plugin settings
        foreach ($this->sectionsWithUrls as $section) {
            if (!empty($settings['sections'][$section->id])) {
                $changefreq = $settings['sections'][$section->id]['changefreq'];
                $priority = $settings['sections'][$section->id]['priority'];
                $this->addSection($section, $changefreq, $priority);
            }
        }

        // Hook: renderSitemap
        craft()->plugins->call('renderSitemap');

        // Use DOMDocument to generate XML
        $document = new \DOMDocument('1.0', 'utf-8');

        // Format XML output when devMode is active for easier debugging
        if (craft()->config->get('devMode')) {
            $document->formatOutput = true;
        }

        // Append a urlset node
        $urlset = $document->createElement('urlset');
        $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
        $urlset->setAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
        $document->appendChild($urlset);

        // Loop through and append Sitemap_UrlModel elements
        foreach ($this->urls as $url) {
            $urlElement = $url->getDomElement($document);
            $urlset->appendChild($urlElement);
        }

        return $document->saveXML();
    }

    /**
     * Adds a URL to the sitemap.
     */
    public function addUrl(Sitemap_UrlModel $url)
    {
        if ($url->validate()) {
            $this->urls[$url->loc] = $url;
        }
    }

    /**
     * Adds an element to the sitemap.
     *
     * @param BaseElementModel $element
     * @param string           $changefreq
     * @param string           $priority
     */
    public function addElement(BaseElementModel $element, $changefreq = null, $priority = null)
    {
        $url = new Sitemap_UrlModel($element->url, $element->dateUpdated, $changefreq, $priority);

        $locales = craft()->elements->getEnabledLocalesForElement($element->id);
        foreach ($locales as $locale) {
            $alternateUrl = new Sitemap_AlternateUrlModel();
            $alternateUrl->hreflang = $locale;
            $alternateUrl->href = craft()->sitemap->getElementUrlForLocale($element, $locale);

            $url->addAlternateUrl($alternateUrl);
        }

        $this->addUrl($url);
    }

    /**
     * Adds all entries related to the section to the sitemap.
     *
     * @param SectionModel $section
     * @param string       $changefreq
     * @param string       $priority
     */
    public function addSection(SectionModel $section, $changefreq = null, $priority = null)
    {
        $criteria = craft()->elements->getCriteria(ElementType::Entry);
        $criteria->section = $section;
        foreach ($criteria->find() as $element) {
            $this->addElement($element, $changefreq, $priority);
        }
    }

    /**
     * Adds all entries related to the group to the sitemap.
     *
     * @param CategoryGroupModel $categoryGroup
     * @param string             $changefreq
     * @param string             $priority
     */
    public function addCategoryGroup(CategoryGroupModel $categoryGroup, $changefreq = null, $priority = null)
    {
        $criteria = craft()->elements->getCriteria(ElementType::Category);
        $criteria->group = $categoryGroup;

        $categories = $criteria->find();
        foreach ($categories as $category) {
{'fraction_non_alphanumeric': 0.13499838518678006, 'fraction_numerical': 0.002153084293250081, 'mean_word_length': 2.2448480614739785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, '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': '911875', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2533, 'n_words': 580}