<commit_before><?php

/**
 * SHMD
 *
 * @package   SHMD
 * @copyright 2016 <NAME> (https://github.com/AlexHowansky)
 * @license   https://github.com/AlexHowansky/shmd/blob/master/LICENSE MIT License
 * @link      https://github.com/AlexHowansky/shmd
 */

namespace Shmd;

class Gallery
{

    const DESCRIPTION_FILE = 'description';

    const TITLE_FILE = 'title';

    /**
     * The app that spawned us.
     *
     * @var \Shmd\App
     */
    protected $app = null;

    /**
     * The gallery base directory.
     *
     * @var string
     */
    protected $dir = null;

    /**
     * The gallery name.
     *
     * @var string
     */
    protected $name = null;

    /**
     * Constructor.
     *
     * @param \Shmd\App $app  The app that spawned us.
     * @param string    $name The name of this gallery.
     */
    public function __construct(App $app = null, $name = null)
    {
        if ($app !== null) {
            $this->setApp($app);
        }
        if ($name !== null) {
            $this->setName($name);
        }
    }

    /**
     * Get the app that spawned us.
     *
     * @return \Shmd\App
     */
    public function getApp()
    {
        if ($this->app === null) {
            throw new \Exception('No App object has been set yet.');
        }
        return $this->app;
    }

    /**
     * Get the gallery description.
     *
     * @return string The gallery description.
     */
    public function getDescription()
    {
        return $this->getFileContents(self::DESCRIPTION_FILE);
    }

    /**
     * Get the gallery base directory.
     *
     * @return string The gallery base directory.
     */
    public function getDir()
    {
        return $this->dir;
    }

    /**
     * Get the contents of a file.
     *
     * @param string $name The name of the file to get.
     *
     * @return string The contents of the file.
     */
    protected function getFileContents($name)
    {
        $file = realpath($this->getDir() . '/' . $name);
        if (file_exists($file) === true) {
            return htmlspecialchars(trim(file_get_contents($file)));
        }
    }

    /**
     * Get the name of the gallery.
     *
     * @return string The name of the gallery.
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Get the photos in this gallery.
     *
     * @return array The photos in this gallery.
     */
    public function getPhotos()
    {
        $photos = [];
        foreach (new \DirectoryIterator($this->getDir()) as $item) {
            if ($item->isFile() === true && $item->isDot() === false && $item->getExtension() === 'jpg') {
                $photos[$item->getBasename('.jpg')] = $item->getCTime();
            }
        }
        asort($photos);
        return array_keys($photos);
    }

    /**
     * Get the path of this gallery relative to the document root.
     *
     * @return string The path of this gallery relative to the document root.
     */
    public function getRelativePath()
    {
        return $this->getApp()->getRelativePhotoDir() . '/' . $this->getName();
    }

    /**
     * Get the gallery title.
     *
     * @return string The gallery title.
     */
    public function getTitle()
    {
        return $this->getFileContents(self::TITLE_FILE) ?? $this->getName();
    }<commit_msg>Sort by filename.<commit_after><?php

/**
 * SHMD
 *
 * @package   SHMD
 * @copyright 2016 <NAME> (https://github.com/AlexHowansky)
 * @license   https://github.com/AlexHowansky/shmd/blob/master/LICENSE MIT License
 * @link      https://github.com/AlexHowansky/shmd
 */

namespace Shmd;

class Gallery
{

    const DESCRIPTION_FILE = 'description';

    const TITLE_FILE = 'title';

    /**
     * The app that spawned us.
     *
     * @var \Shmd\App
     */
    protected $app = null;

    /**
     * The gallery base directory.
     *
     * @var string
     */
    protected $dir = null;

    /**
     * The gallery name.
     *
     * @var string
     */
    protected $name = null;

    /**
     * Constructor.
     *
     * @param \Shmd\App $app  The app that spawned us.
     * @param string    $name The name of this gallery.
     */
    public function __construct(App $app = null, $name = null)
    {
        if ($app !== null) {
            $this->setApp($app);
        }
        if ($name !== null) {
            $this->setName($name);
        }
    }

    /**
     * Get the app that spawned us.
     *
     * @return \Shmd\App
     */
    public function getApp()
    {
        if ($this->app === null) {
            throw new \Exception('No App object has been set yet.');
        }
        return $this->app;
    }

    /**
     * Get the gallery description.
     *
     * @return string The gallery description.
     */
    public function getDescription()
    {
        return $this->getFileContents(self::DESCRIPTION_FILE);
    }

    /**
     * Get the gallery base directory.
     *
     * @return string The gallery base directory.
     */
    public function getDir()
    {
        return $this->dir;
    }

    /**
     * Get the contents of a file.
     *
     * @param string $name The name of the file to get.
     *
     * @return string The contents of the file.
     */
    protected function getFileContents($name)
    {
        $file = realpath($this->getDir() . '/' . $name);
        if (file_exists($file) === true) {
            return htmlspecialchars(trim(file_get_contents($file)));
        }
    }

    /**
     * Get the name of the gallery.
     *
     * @return string The name of the gallery.
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Get the photos in this gallery.
     *
     * @return array The photos in this gallery.
     */
    public function getPhotos()
    {
        $photos = [];
        foreach (new \DirectoryIterator($this->getDir()) as $item) {
            if ($item->isFile() === true && $item->isDot() === false && $item->getExtension() === 'jpg') {
                $photos[] = $item->getBasename('.jpg');
            }
        }
        asort($photos);
        return $photos;
    }

    /**
     * Get the path of this gallery relative to the document root.
     *
     * @return string The path of this gallery relative to the document root.
     */
    public function getRelativePath()
    {
        return $this->getApp()->getRelativePhotoDir() . '/' . $this->getName();
    }

    /**
     * Get the gallery title.
     *
     * @return string The gallery title.
     */
    public function getTitle()
    {
        return $this->getFileContents(self::TITLE_FILE) ?? $this->getName();
    }
{'fraction_non_alphanumeric': 0.1384083044982699, 'fraction_numerical': 0.001203550473897999, 'mean_word_length': 1.739184177997528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 42, 'https://': 6, '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': '58680', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1967, 'n_words': 538}