<commit_before><?php

/**
 * kitFramework::Basic
 *
 * @author Team phpManufaktur <<EMAIL>>
 * @link https://kit2.phpmanufaktur.de
 * @copyright 2013 <NAME> <<EMAIL>>
 * @license MIT License (MIT) http://www.opensource.org/licenses/MIT
 */

namespace phpManufaktur\Basic\Data\CMS\WebsiteBaker;

use Silex\Application;

class Page
{
    protected $app = null;
    protected static $pages_directory = null;
    protected static $page_extension = null;

    /**
     * Constructor
     *
     * @param Application $app
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
        self::$page_extension = $this->getPageExtension();
        self::$pages_directory = $this->getPageDirectory();
    }

    /**
     * Get the page extension with leading dot, by default '.php'
     *
     * @throws \Exception
     * @return string page extension
     */
    public function getPageExtension()
    {
        try {
          $SQL = "SELECT `value` FROM `".CMS_TABLE_PREFIX."settings` WHERE `name`='page_extension'";
          return $this->app['db']->fetchColumn($SQL);
        } catch (\Doctrine\DBAL\DBALException $e) {
            throw new \Exception($e);
        }
    }

    /**
     * Get the page directory with leading slash, by default '/pages' or '/page'
     *
     * @throws \Exception
     * @return string page directory
     */
    public function getPageDirectory()
    {
        try {
            $SQL = "SELECT `value` FROM `".CMS_TABLE_PREFIX."settings` WHERE `name`='pages_directory'";
            return $this->app['db']->fetchColumn($SQL);
        } catch (\Doctrine\DBAL\DBALException $e) {
            throw new \Exception($e);
        }
    }

    /**
     * Get the TOPICS directory if this addon is installed
     *
     * @return string|boolean
     */
    public function getTopicsDirectory()
    {
        if ($this->app['filesystem']->exists(CMS_PATH . '/modules/topics/module_settings.php')) {
            ob_start();
                require_once(CMS_PATH.'/config.php');
                global $topics_directory;
                include_once CMS_PATH . '/modules/topics/module_settings.php';
            ob_end_clean();
            return $topics_directory;
        }
        return false;
    }

    /**
     * Get the URL of the given page ID. If arguments 'topic_id' or 'post_id'
     * the function will return the URL for the given TOPICS or NEWS article
     *
     * @param integer $page_id
     * @param null|array $arguments
     * @throws \Exception
     * @return string URL of the page
     */
    public function getURL($page_id, $arguments=null)
    {
        try {
            if (isset($arguments['topic_id']) && !is_null($arguments['topic_id'])) {
                // indicate a TOPICS page
                if (false === ($topics_directory = $this->getTopicsDirectory())) {
                    throw new \Exception('A TOPIC_ID was submitted, but the TOPICS addon is not installed at the parent CMS!');
                }
                // indicate a TOPICS page
                $SQL = "SELECT `link` FROM `".CMS_TABLE_PREFIX."mod_topics` WHERE `topic_id`='".$arguments['topic_id']."'";
                $topic_link = $this->app['db']->fetchColumn($SQL);
                return CMS_URL . $topics_directory . $topic_link . $this->getPageExtension();
            }
<commit_msg>changed handling to get the TOPICS directory - no longer try to include the `module_settings.php`<commit_after><?php

/**
 * kitFramework::Basic
 *
 * @author Team phpManufaktur <<EMAIL>>
 * @link https://kit2.phpmanufaktur.de
 * @copyright 2013 <NAME> <<EMAIL>>
 * @license MIT License (MIT) http://www.opensource.org/licenses/MIT
 */

namespace phpManufaktur\Basic\Data\CMS\WebsiteBaker;

use Silex\Application;

class Page
{
    protected $app = null;
    protected static $pages_directory = null;
    protected static $page_extension = null;

    /**
     * Constructor
     *
     * @param Application $app
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
        self::$page_extension = $this->getPageExtension();
        self::$pages_directory = $this->getPageDirectory();
    }

    /**
     * Get the page extension with leading dot, by default '.php'
     *
     * @throws \Exception
     * @return string page extension
     */
    public function getPageExtension()
    {
        try {
          $SQL = "SELECT `value` FROM `".CMS_TABLE_PREFIX."settings` WHERE `name`='page_extension'";
          return $this->app['db']->fetchColumn($SQL);
        } catch (\Doctrine\DBAL\DBALException $e) {
            throw new \Exception($e);
        }
    }

    /**
     * Get the page directory with leading slash, by default '/pages' or '/page'
     *
     * @throws \Exception
     * @return string page directory
     */
    public function getPageDirectory()
    {
        try {
            $SQL = "SELECT `value` FROM `".CMS_TABLE_PREFIX."settings` WHERE `name`='pages_directory'";
            return $this->app['db']->fetchColumn($SQL);
        } catch (\Doctrine\DBAL\DBALException $e) {
            throw new \Exception($e);
        }
    }

    /**
     * Get the TOPICS directory if this addon is installed
     *
     * @return string|boolean
     */
    public function getTopicsDirectory()
    {
        if ($this->app['filesystem']->exists(CMS_PATH . '/modules/topics/module_settings.php')) {
            if (!$this->app['filesystem']->exists(FRAMEWORK_PATH.'/config/cms/module/topics.json')) {
                $config = array(
                    'topics' => array(
                        'directory' => '/topics/'
                    )
                );
                $this->app['filesystem']->mkdir(FRAMEWORK_PATH.'/config/cms/module');
                if (!file_put_contents(FRAMEWORK_PATH.'/config/cms/module/topics.json', $this->app['utils']->JSONFormat($config))) {
                    // can't create the config file
                    $error = error_get_last();
                    throw new \Exception($error);
                }
            }
            $topics = $this->app['utils']->readJSON(FRAMEWORK_PATH.'/config/cms/module/topics.json');
            return $this->getPageDirectory().$topics['topics']['directory'];
        }
        return false;
    }

    /**
     * Get the URL of the given page ID. If arguments 'topic_id' or 'post_id'
     * the function will return the URL for the given TOPICS or NEWS article
     *
     * @param integer $page_id
     * @param null|array $arguments
     * @throws \Exception
     * @return string URL of the page
     */
    public function getURL($page_id, $arguments=null)
    {
        try {
            if (isset($arguments['topic_id']) && !is_null($arguments['topic_id'])) {
                // indicate a TOPICS page
                if (false === ($topics_directory = $this->getTopicsDirectory())) {
                    throw new \Exception('A TOPIC_ID was submitted, but the TOPICS addon is not installed at the parent CMS!');
                }
                // indicate a TOPICS page
                $SQL = "SELECT `link` FROM `".CMS_TABLE_PREFIX."mod_topics` WHERE `topic_id`='".$arguments['topic_id']."'";
                $topic_link = $this->app['db']->fetchColumn($SQL);
                return CMS_URL . $topics_directory . $topic_link . $this->getPageExtension();
            }

{'fraction_non_alphanumeric': 0.13465454051852857, 'fraction_numerical': 0.0013574046423238768, 'mean_word_length': 2.136653895274585, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 50, 'https://': 2, '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': '7033239', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2082, 'n_words': 509}