<commit_before><?php
namespace Concrete\Core\Page;
use Concrete\Core\Page\Type\Type;
use Loader;
use CacheLocal;
use Collection;
use Request;
use \Concrete\Core\Page\Statistics as PageStatistics;
use PageCache;
use PageTemplate;
use \Events;
use Core;
use Config;
use PageController;
use User;
use Block;
use UserInfo;
use PageType;
use PageTheme;
use \Concrete\Core\Permission\Key\PageKey as PagePermissionKey;
use PermissionAccess;
use \Concrete\Core\Package\PackageList;
use \Concrete\Core\Permission\Access\Entity\GroupEntity as GroupPermissionAccessEntity;
use \Concrete\Core\Permission\Access\Entity\GroupCombinationEntity as GroupCombinationPermissionAccessEntity;
use \Concrete\Core\Permission\Access\Entity\UserEntity as UserPermissionAccessEntity;
use \Concrete\Core\StyleCustomizer\CustomCssRecord;
use Area;
use Queue;
use Log;
use Environment;
/**
*
* The page object in Concrete encapsulates all the functionality used by a typical page and their contents
* including blocks, page metadata, page permissions.
* @package Pages
*
*/
class Page extends Collection implements \Concrete\Core\Permission\ObjectInterface {

    protected $controller;
    protected $blocksAliasedFromMasterCollection = null;
    protected $cIsSystemPage = false;
    /**
     * @param string $path /path/to/page
     * @param string $version ACTIVE or RECENT
     * @return Page
     */
    public static function getByPath($path, $version = 'RECENT') {
        $path = rtrim($path, '/'); // if the path ends in a / remove it.

        $cID = CacheLocal::getEntry('page_id_from_path', $path);
        if ($cID == false) {
            $db = Loader::db();
            $cID = $db->GetOne("select cID from PagePaths where cPath = ?", array($path));
            CacheLocal::set("page_id_from_path", $path, $cID);
        }
        return Page::getByID($cID, $version);
    }

    /**
     * @param int $cID Collection ID of a page
     * @param string $versionOrig ACTIVE or RECENT
     * @param string $class
     * @return Page
     */
    public static function getByID($cID, $version = 'RECENT', $class = 'Page') {

        $c = CacheLocal::getEntry('page', $cID . ':' . $version . ':' . $class);
        if ($c instanceof $class) {
            return $c;
        }

        $where = "where Pages.cID = ?";
        $c = new $class;
        $c->populatePage($cID, $where, $version);

        // must use cID instead of c->getCollectionID() because cID may be the pointer to another page
        CacheLocal::set('page', $cID . ':' . $version . ':' . $class, $c);

        return $c;
    }

    public function __construct() {
        $this->loadError(COLLECTION_INIT); // init collection until we populate.
    }

    /**
     * @access private
     */
    protected function populatePage($cInfo, $where, $cvID) {
        $db = Loader::db();

        $this->loadError(false);

        $q0 = "select Pages.cID, Pages.pkgID, Pages.cPointerID, Pages.cPointerExternalLink, Pages.cIsActive, Pages.cIsSystemPage, Pages.cPointerExternalLinkNewWindow, Pages.cFilename, Pages.ptID, Collections.cDateAdded, Pages.cDisplayOrder, Collections.cDateModified, cInheritPermissionsFromCID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cCheckedOutUID, cIsTemplate, uID, cPath, cParentID, cChildren, cCacheFullPageContent, cCacheFullPageContentOverrideLifetime, cCacheFullPageContentLifetimeCustom from Pages inner join Collections on Pages.cID = Collections.cID left join PagePaths on (Pages.cID = PagePaths.cID and PagePaths.ppIsCanonical = 1) ";
        //$q2 = "select cParentID, cPointerID, cPath, Pages.cID from Pages left join PagePaths on (Pages.cID = PagePaths.cID and PagePaths.ppIsCanonical = 1) ";

        $v = array($cInfo);
        $r = $db->query($q0 . $where, $v);
        $row = $r->fetchRow();
        if ($row['cPointerID'] > 0) {
            $q1 = $q0 . "where Pages.cID = ?";
            $cPointerOriginalID = $row['cID'];
            $v = array($row['cPointerID']);
            $cParentIDOverride = $row['cParentID'];<commit_msg>use ioc for page instantiation<commit_after><?php
namespace Concrete\Core\Page;
use Concrete\Core\Page\Type\Type;
use Loader;
use CacheLocal;
use Collection;
use Request;
use \Concrete\Core\Page\Statistics as PageStatistics;
use PageCache;
use PageTemplate;
use \Events;
use Core;
use Config;
use PageController;
use User;
use Block;
use UserInfo;
use PageType;
use PageTheme;
use \Concrete\Core\Permission\Key\PageKey as PagePermissionKey;
use PermissionAccess;
use \Concrete\Core\Package\PackageList;
use \Concrete\Core\Permission\Access\Entity\GroupEntity as GroupPermissionAccessEntity;
use \Concrete\Core\Permission\Access\Entity\GroupCombinationEntity as GroupCombinationPermissionAccessEntity;
use \Concrete\Core\Permission\Access\Entity\UserEntity as UserPermissionAccessEntity;
use \Concrete\Core\StyleCustomizer\CustomCssRecord;
use Area;
use Queue;
use Log;
use Environment;
/**
*
* The page object in Concrete encapsulates all the functionality used by a typical page and their contents
* including blocks, page metadata, page permissions.
* @package Pages
*
*/
class Page extends Collection implements \Concrete\Core\Permission\ObjectInterface {

    protected $controller;
    protected $blocksAliasedFromMasterCollection = null;
    protected $cIsSystemPage = false;
    /**
     * @param string $path /path/to/page
     * @param string $version ACTIVE or RECENT
     * @return Page
     */
    public static function getByPath($path, $version = 'RECENT') {
        $path = rtrim($path, '/'); // if the path ends in a / remove it.

        $cID = CacheLocal::getEntry('page_id_from_path', $path);
        if ($cID == false) {
            $db = Loader::db();
            $cID = $db->GetOne("select cID from PagePaths where cPath = ?", array($path));
            CacheLocal::set("page_id_from_path", $path, $cID);
        }
        return Page::getByID($cID, $version);
    }

    /**
     * @param int $cID Collection ID of a page
     * @param string $versionOrig ACTIVE or RECENT
     * @param string $class
     * @return Page
     */
    public static function getByID($cID, $version = 'RECENT', $class = 'Page') {

        $c = CacheLocal::getEntry('page', $cID . ':' . $version . ':' . $class);
        if ($c instanceof $class) {
            return $c;
        }

        $where = "where Pages.cID = ?";
        $c = Core::make('\Concrete\Core\Page\Page');
        $c->populatePage($cID, $where, $version);

        // must use cID instead of c->getCollectionID() because cID may be the pointer to another page
        CacheLocal::set('page', $cID . ':' . $version . ':' . $class, $c);

        return $c;
    }

    public function __construct() {
        $this->loadError(COLLECTION_INIT); // init collection until we populate.
    }

    /**
     * @access private
     */
    protected function populatePage($cInfo, $where, $cvID) {
        $db = Loader::db();

        $this->loadError(false);

        $q0 = "select Pages.cID, Pages.pkgID, Pages.cPointerID, Pages.cPointerExternalLink, Pages.cIsActive, Pages.cIsSystemPage, Pages.cPointerExternalLinkNewWindow, Pages.cFilename, Pages.ptID, Collections.cDateAdded, Pages.cDisplayOrder, Collections.cDateModified, cInheritPermissionsFromCID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cCheckedOutUID, cIsTemplate, uID, cPath, cParentID, cChildren, cCacheFullPageContent, cCacheFullPageContentOverrideLifetime, cCacheFullPageContentLifetimeCustom from Pages inner join Collections on Pages.cID = Collections.cID left join PagePaths on (Pages.cID = PagePaths.cID and PagePaths.ppIsCanonical = 1) ";
        //$q2 = "select cParentID, cPointerID, cPath, Pages.cID from Pages left join PagePaths on (Pages.cID = PagePaths.cID and PagePaths.ppIsCanonical = 1) ";

        $v = array($cInfo);
        $r = $db->query($q0 . $where, $v);
        $row = $r->fetchRow();
        if ($row['cPointerID'] > 0) {
            $q1 = $q0 . "where Pages.cID = ?";
            $cPointerOriginalID = $row['cID'];
            $v = array($row['cPointerID']);
            $cParentIDOverride = $row['cParentID'];
{'fraction_non_alphanumeric': 0.12449105490438002, 'fraction_numerical': 0.001974090067859346, 'mean_word_length': 3.36275565123789, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '5605351', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2444, 'n_words': 656}