<commit_before><?php
namespace DL\Gallery\ViewHelpers;

/***************************************************************
 *  Copyright (C) 2015 <NAME>
 *
 *  This script is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published
 *  by the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\QueryInterface;
use TYPO3\Media\Domain\Model\Image;
use TYPO3\Media\Domain\Model\Tag;
use TYPO3\TYPO3CR\Domain\Model\Node;

class GalleryViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper
{

    /**
     * @Flow\Inject
     * @var \TYPO3\Media\Domain\Repository\TagRepository
     */
    protected $tagRepository;

    /**
     * @Flow\Inject
     * @var \TYPO3\Media\Domain\Repository\ImageRepository
     */
    protected $imageRepository;

    /**
     * @var array
     */
    protected $settings;

    /**
     * @param array $settings
     * @return void
     */
    public function injectSettings(array $settings)
    {
        $this->settings = $settings;
    }


    /**
     * @param Node $galleryNode
     * @return string
     * @throws \TYPO3\Fluid\Core\ViewHelper\Exception\InvalidVariableException
     */
    public function render(Node $galleryNode)
    {

        $this->templateVariableContainer->add('themeSettings', $this->getSettingsForCurrentTheme());

        $images = array_merge(
            $this->selectImagesByTag($galleryNode), 
            $this->getSelectedImages($galleryNode)
        );

        if (count($images) === 0) {
            return 'No images are assigned to the selected tag. Please go to the media management and assign images to this tag.';
        }

        $result = '';

        foreach ($images as $image) {
            /** @var Image $image */
            $this->templateVariableContainer->add('image', $image);
            $this->templateVariableContainer->add('imageMeta', $this->buildImageMetaDataArray($image));

            $result .= $this->renderChildren();

            $this->templateVariableContainer->remove('image');
            $this->templateVariableContainer->remove('imageMeta');
        }

        $this->templateVariableContainer->remove('themeSettings');

        return $result;
    }


    /**
     * @param Node $galleryNode
     * @return array<commit_msg>BUGFIX: Ignore non image assets<commit_after><?php
namespace DL\Gallery\ViewHelpers;

/***************************************************************
 *  Copyright (C) 2015 <NAME>
 *
 *  This script is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published
 *  by the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\QueryInterface;
use TYPO3\Media\Domain\Model\Image;
use TYPO3\Media\Domain\Model\Tag;
use TYPO3\TYPO3CR\Domain\Model\Node;

class GalleryViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper
{

    /**
     * @Flow\Inject
     * @var \TYPO3\Media\Domain\Repository\TagRepository
     */
    protected $tagRepository;

    /**
     * @Flow\Inject
     * @var \TYPO3\Media\Domain\Repository\ImageRepository
     */
    protected $imageRepository;

    /**
     * @var array
     */
    protected $settings;

    /**
     * @param array $settings
     * @return void
     */
    public function injectSettings(array $settings)
    {
        $this->settings = $settings;
    }


    /**
     * @param Node $galleryNode
     * @return string
     * @throws \TYPO3\Fluid\Core\ViewHelper\Exception\InvalidVariableException
     */
    public function render(Node $galleryNode)
    {

        $this->templateVariableContainer->add('themeSettings', $this->getSettingsForCurrentTheme());

        $images = array_merge(
            $this->selectImagesByTag($galleryNode), 
            $this->getSelectedImages($galleryNode)
        );

        if (count($images) === 0) {
            return 'No images are assigned to the selected tag. Please go to the media management and assign images to this tag.';
        }

        $result = '';

        foreach ($images as $image) {
            if ($image instanceof Image) {
                /** @var Image $image */
                $this->templateVariableContainer->add('image', $image);
                $this->templateVariableContainer->add('imageMeta', $this->buildImageMetaDataArray($image));

                $result .= $this->renderChildren();

                $this->templateVariableContainer->remove('image');
                $this->templateVariableContainer->remove('imageMeta');
            }
        }

        $this->templateVariableContainer->remove('themeSettings');

        return $result;
    }


    /**
     * @param Node $galleryNode
     * @return array
{'fraction_non_alphanumeric': 0.14622875061891402, 'fraction_numerical': 0.005281399570886285, 'mean_word_length': 2.8089252042740416, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3516240', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1586, 'n_words': 457}