/concreteOLD/models/page.php
https://bitbucket.org/selfeky/xclusivescardwebsite · PHP · 2554 lines · 1738 code · 376 blank · 440 comment · 323 complexity · b56bdeceef3bcb9c62522eb2f617a424 MD5 · raw file
Large files are truncated click here to view the full file
- <?php
- defined('C5_EXECUTE') or die("Access Denied.");
- /**
- *
- * 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 {
- protected $blocksAliasedFromMasterCollection = null;
-
- /**
- * @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 = Cache::get('page_id_from_path', $path);
- if ($cID == false) {
- $db = Loader::db();
- $cID = $db->GetOne("select cID from PagePaths where cPath = ?", array($path));
- Cache::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, $versionOrig = 'RECENT', $class = 'Page') {
- if ($versionOrig) {
- $version = CollectionVersion::getNumericalVersionID($cID, $versionOrig);
- }
- $ca = new Cache();
- $c = ($version > 0) ? $ca->get(strtolower($class), $cID . ':' . $version) : '';
- 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
- if ($version > 0) {
- $ca->set(strtolower($class), $cID . ':' . $version, $c);
- }
- return $c;
- }
-
- /**
- * @access private
- */
- protected function populatePage($cInfo, $where, $cvID) {
- $db = Loader::db();
-
- $q0 = "select Pages.cID, Pages.pkgID, Pages.cPointerID, Pages.cPointerExternalLink, Pages.cIsActive, Pages.cIsSystemPage, Pages.cPointerExternalLinkNewWindow, Pages.cFilename, Collections.cDateAdded, Pages.cDisplayOrder, Collections.cDateModified, cInheritPermissionsFromCID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cPendingAction, cPendingActionUID, cPendingActionTargetCID, cPendingActionDatetime, cCheckedOutUID, cIsTemplate, uID, cPath, Pages.ctID, ctHandle, ctIcon, ptID, cParentID, cChildren, ctName, cCacheFullPageContent, cCacheFullPageContentOverrideLifetime, cCacheFullPageContentLifetimeCustom from Pages inner join Collections on Pages.cID = Collections.cID left join PageTypes on (PageTypes.ctID = Pages.ctID) 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'];
- $cPathOverride = $row['cPath'];
- $cPointerID = $row['cPointerID'];
- $cDisplayOrderOverride = $row['cDisplayOrder'];
- $r = $db->query($q1, $v);
- $row = $r->fetchRow();
- }
-
- if ($r) {
- if ($row) {
- foreach ($row as $key => $value) {
- $this->{$key} = $value;
- }
- if (isset($cParentIDOverride)) {
- $this->cPointerID = $cPointerID;
- $this->cPointerOriginalID = $cPointerOriginalID;
- $this->cPath = $cPathOverride;
- $this->cParentID = $cParentIDOverride;
- }
- $this->isMasterCollection = $row['cIsTemplate'];
- } else {
- if ($cInfo == 1) {
- $this->cID = '1';
- $this->loadError(COLLECTION_INIT);
- } else {
- // there was no record of this particular collection in the database
- $this->loadError(COLLECTION_NOT_FOUND);
- }
- }
- $r->free();
- } else {
- $this->loadError(COLLECTION_NOT_FOUND);
- }
-
- if ($cvID != false) {
- // we don't do this on the front page
- $this->loadVersionObject($cvID);
- }
-
- unset($r);
-
- }
- /**
- * Returns 1 if the page is in edit mode
- * @return bool
- */
- public function isEditMode() {
- $v = View::getInstance();
- return ($this->isCheckedOutByMe() && ($v->editingEnabled()));
- }
-
- /**
- * Get the package ID for a page (page thats added by a package) (returns 0 if its not in a package)
- * @return int
- */
- public function getPackageID() {return $this->pkgID;}
-
- /**
- * Get the package handle for a page (page thats added by a package)
- * @return string
- */
- public function getPackageHandle() {
- return PackageList::getHandle($this->pkgID);
- }
-
- /**
- * Returns 1 if the page is in arrange mode
- * @return bool
- */
- public function isArrangeMode() {return ($this->isCheckedOutByMe() && ($_REQUEST['btask'] == 'arrange'));}
-
- /**
- * Forces the page to be checked in if its checked out
- */
- public function forceCheckIn() {
- // This function forces checkin to take place
- $db = Loader::db();
- $q = "update Pages set cIsCheckedOut = 0, cCheckedOutUID = null, cCheckedOutDatetime = null, cCheckedOutDatetimeLastEdit = null where cID = '{$this->cID}'";
- $r = $db->query($q);
- }
- /**
- * Checks if the page is a dashboard page, returns true if it is
- * @return bool
- */
- public function isAdminArea() {
- if ($this->isGeneratedCollection()) {
- $pos = strpos($this->getCollectionFilename(), "/" . DIRNAME_DASHBOARD);
- return ($pos > -1);
- }
- return false;
- }
-
- /**
- * Takes an array of area/block values and makes that the arrangement for this page's version
- * Format is like: $area[10][0] = 2, $area[10][1] = 8, $area[15][0] = 27, with the area ID being the
- * key and the block IDs being 1-n values inside it
- * @param array $areas
- */
- public function processArrangement($areas) {
- // this function is called via ajax, so it's a bit wonky, but the format is generally
- // a{areaID} = array(b1, b2, b3) (where b1, etc... are blocks with ids appended.)
- $db = Loader::db();
-
- $db->Execute('delete from CollectionVersionBlockStyles where cID = ? and cvID = ?', array($this->getCollectionID(), $this->getVersionID()));
-
- foreach($areas as $arID => $blocks) {
- if (intval($arID) > 0) {
- // this is a serialized area;
- $arHandle = $db->getOne("select arHandle from Areas where arID = ?", array($arID));
- $startDO = 0;
-
- foreach($blocks as $bIdentifier) {
- $bID = 0;
- $csrID = 0;
-
- $bd2 = explode('-', $bIdentifier);
- $bID = $bd2[0];
- $csrID = $bd2[1];
- if (intval($bID) > 0) {
- $v = array($startDO, $arHandle, $bID, $this->getCollectionID(), $this->getVersionID());
- try {
- $db->query("update CollectionVersionBlocks set cbDisplayOrder = ?, arHandle = ? where bID = ? and cID = ? and (cvID = ? or cbIncludeAll = 1)", $v);
- if ($csrID > 0) {
- $db->query("insert into CollectionVersionBlockStyles (csrID, arHandle, bID, cID, cvID) values (?, ?, ?, ?, ?)", array(
- $csrID, $arHandle, $bID, $this->getCollectionID(), $this->getVersionID()
- ));
- }
- // update the style for any of these blocks
-
- } catch(Exception $e) {}
-
- $startDO++;
- }
- }
- }
- }
- Cache::delete('collection_blocks', $this->getCollectionID() . ':' . $this->getVersionID());
- }
- /**
- * checks if the page is checked out, if it is return true
- * @return bool
- */
- function isCheckedOut() {
- // function to inform us as to whether the current collection is checked out
- $db = Loader::db();
- if (isset($this->isCheckedOutCache)) {
- return $this->isCheckedOutCache;
- }
-
- $dh = Loader::helper('date');
-
- $q = "select cIsCheckedOut, UNIX_TIMESTAMP('" . $dh->getSystemDateTime() . "') - UNIX_TIMESTAMP(cCheckedOutDatetimeLastEdit) as timeout from Pages where cID = '{$this->cID}'";
- $r = $db->query($q);
- if ($r) {
- $row = $r->fetchRow();
- if ($row['cIsCheckedOut'] == 0) {
- return false;
- } else {
- if ($row['timeout'] > CHECKOUT_TIMEOUT) {
- $this->forceCheckIn();
- $this->isCheckedOutCache = false;
- return false;
- } else {
- $this->isCheckedOutCache = true;
- return true;
- }
- }
- }
- }
- /**
- * Gets the user that is editing the current page.
- * $return string $name
- */
- public function getCollectionCheckedOutUserName() {
- $db = Loader::db();
- $query = "select cCheckedOutUID from Pages where cID = ?";
- $vals=array($this->cID);
- $checkedOutId = $db->getOne($query, $vals);
- if(is_object(UserInfo::getByID($checkedOutId))){
- $ui = UserInfo::getByID($checkedOutId);
- $name=$ui->getUserName();
- }else{
- $name= t('Unknown User');
- }
- return $name;
- }
-
- /**
- * Checks if the page is checked out by the current user
- * @return bool
- */
- function isCheckedOutByMe() {
- $u = new User();
- return ($this->getCollectionCheckedOutUserID() > 0 && $this->getCollectionCheckedOutUserID() == $u->getUserID());
- }
- /**
- * Checks if the page is a single page
- * @return bool
- */
- function isGeneratedCollection() {
- // generated collections are collections without types, that have special cFilename attributes
- return $this->cFilename != null && $this->ctID == 0;
- }
- /**
- * Assign permissions to a page based on an array
- * <code>
- * $pxml->guests['canRead'] = 1;
- * $pxml->registered['canWrite'] = 1;
- * $pxml->group[0]['canWrite'] = 1;
- * $pxml->group[0]['canRead'] = 1;
- * </code>
- * @param array $permissionsArray
- */
- function assignPermissionSet($permissionsArray) {
- $db = Loader::db();
- // first, we make sure to set this collection's permission inheritance to override
- if ($this->getCollectionInheritance() != 'OVERRIDE') {
- // now, if we were inheriting permissions from elsewhere, we'll grab those, copy them to this node, before we
- // assign/add new permission
- $v = array($this->getPermissionsCollectionID());
- $q = "select cID, uID, gID, cgPermissions, cgStartDate, cgEndDate from PagePermissions where cID = ?";
- $r = $db->query($q, $v);
- while($row = $r->fetchRow()) {
- $v = array($this->cID, $row['uID'], $row['gID'], $row['cgPermissions'], $row['cgStartDate'], $row['cgEndDate']);
- $q = "insert into PagePermissions (cID, uID, gID, cgPermissions, cgStartDate, cgEndDate) values (?, ?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
- $v = array($this->getPermissionsCollectionID());
- $q = "select cID, uID, gID, ctID from PagePermissionPageTypes where cID = ?";
- $r = $db->query($q, $v);
- while($row = $r->fetchRow()) {
- $v = array($this->cID, $row['uID'], $row['gID'], $row['ctID']);
- $q = "insert into PagePermissionPageTypes (cID, uID, gID, ctID) values (?, ?, ?, ?)";
- $db->query($q, $v);
- }
- // ack - we need to copy area permissions from that page as well
- // wait, i'm not sure if we need to do this anymore.
-
- $v = array($this->getPermissionsCollectionID());
- $q = "select cID, arHandle, gID, uID, agPermissions from AreaGroups where cID = ?";
- $r = $db->query($q, $v);
- while($row = $r->fetchRow()) {
- $v = array($this->cID, $row['arHandle'], $row['gID'], $row['uID'], $row['agPermissions']);
- $q = "insert into AreaGroups (cID, arHandle, gID, uID, agPermissions) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
- $v = array($this->getPermissionsCollectionID());
- $q = "select cID, arHandle, gID, uID, btID from AreaGroupBlockTypes where cID = ?";
- $r = $db->query($q, $v);
- while($row = $r->fetchRow()) {
- $v = array($this->cID, $row['arHandle'], $row['gID'], $row['uID'], $row['btID']);
- $q = "insert into AreaGroupBlockTypes (cID, arHandle, gID, uID, btID) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
-
- }
- // now that we're done copying, we set the collection to override
- $q = "update Pages set cInheritPermissionsFromCID = {$this->cID}, cInheritPermissionsFrom = 'OVERRIDE' where cID = {$this->cID}";
- $r = $db->query($q);
-
- $this->cInheritPermissionsFromCID = $this->cID;
- $this->cInheritPermissionsFrom = 'OVERRIDE';
-
- // permissions format is read from XML into an array by simplexml
- // this gets us something like this
- // $pxml->guests['canRead'] = 1;
- // $pxml->registered['canWrite'] = 1;
- // $pxml->group[0]['canWrite'] = 1;
- // $pxml->group[0]['canRead'] = 1;
-
- $px = $permissionsArray;
-
- // this is too verbose but i don't know of a good place to stash a reusable function :-(
-
- // not sure if we want to ALWAYS remove permissions for everything then stack the new ones
- // or not, so for now i'm commenting out the selective removal and removing everything
- // THIS IS DUMB: If you want to turn off permissions for a group don't auto-delete them just make sure
- // your permissions XML set's them to not be able to read
-
- //$db->query("delete from PagePermissions where cID = '{$this->cID}'");
-
- if (isset($px->guests)) {
- $permissions = Permissions::buildPermissionsFromArray($px->guests);
- $q = "delete from PagePermissions where cID = '{$this->cID}' and gID = " . GUEST_GROUP_ID;
- $r = $db->query($q);
- if ($permissions != '') {
- $v = array($this->cID, GUEST_GROUP_ID, $permissions, $px->guests['cgStartDate'], $px->guests['cgEndDate']);
- $q = "insert into PagePermissions (cID, gID, cgPermissions, cgStartDate, cgEndDate) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
-
- }
- if (isset($px->registered)) {
- $permissions = Permissions::buildPermissionsFromArray($px->registered);
- $q = "delete from PagePermissions where cID = '{$this->cID}' and gID = " . REGISTERED_GROUP_ID;
- $r = $db->query($q);
- if ($permissions != '') {
- $v = array($this->cID, REGISTERED_GROUP_ID, $permissions, $px->registered['cgStartDate'], $px->registered['cgEndDate']);
- $q = "insert into PagePermissions (cID, gID, cgPermissions, cgStartDate, cgEndDate) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
- }
- if (isset($px->administrators)) {
- $permissions = Permissions::buildPermissionsFromArray($px->administrators);
- $q = "delete from PagePermissions where cID = '{$this->cID}' and gID = " . ADMIN_GROUP_ID;
- $r = $db->query($q);
- if ($permissions != '') {
- $v = array($this->cID, ADMIN_GROUP_ID, $permissions, $px->administrators['cgStartDate'], $px->administrators['cgEndDate']);
- $q = "insert into PagePermissions (cID, gID, cgPermissions, cgStartDate, cgEndDate) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
- }
- if (isset($px->group)) {
- foreach($px->group as $g) {
-
- $permissions = Permissions::buildPermissionsFromArray($g);
- $gID = $g['gID'];
- if (isset($g['gName'])) {
- $gID = $db->getOne("select gID from Groups where gName = ?", array($g['gName']));
- }
-
- $q = "delete from PagePermissions where cID = '{$this->cID}' and gID = " . $gID;
- $r = $db->query($q);
- if ($permissions != '') {
- $v = array($this->cID, $gID, $permissions, $g['cgStartDate'], $g['cgEndDate']);
- $q = "insert into PagePermissions (cID, gID, cgPermissions, cgStartDate, cgEndDate) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
-
- }
- }
-
- if (isset($px->user)) {
- foreach($px->user as $_u) {
-
- $permissions = Permissions::buildPermissionsFromArray($_u);
- $uID = $_u['uID'];
- if (isset($_u['uName'])) {
- $uID = $db->getOne("select uID from Users where uName = ?", array($_u['uName']));
- }
-
- $q = "delete from PagePermissions where cID = '{$this->cID}' and uID = " . $uID;
- $r = $db->query($q);
- if ($permissions != '') {
- $v = array($this->cID, $uID, $permissions, $_u['cgStartDate'], $_u['cgEndDate']);
- $q = "insert into PagePermissions (cID, uID, cgPermissions, cgStartDate, cgEndDate) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
-
- }
- }
-
- $this->refreshCache();
- }
- /**
- * Make an alias to a page
- * @param Collection $c
- * @return int $newCID
- */
- function addCollectionAlias($c) {
- $db = Loader::db();
- // the passed collection is the parent collection
- $cParentID = $c->getCollectionID();
- $u = new User();
- $uID = $u->getUserID();
- $ctID = 0;
-
- $dh = Loader::helper('date');
-
- $cDate = $dh->getSystemDateTime();
- $cDatePublic = $dh->getSystemDateTime();
- $handle = $this->getCollectionHandle();
- $_cParentID = $c->getCollectionID();
- $q = "select PagePaths.cPath from PagePaths where cID = '{$_cParentID}'";
- if ($_cParentID > 1) {
- $q .= " and ppIsCanonical = 1";
- }
- $cPath = $db->getOne($q);
-
- $data['handle'] = $this->getCollectionHandle();
- $data['name'] = $this->getCollectionName();
-
- $cobj = parent::add($data);
- $newCID = $cobj->getCollectionID();
-
- $v = array($newCID, $ctID, $cParentID, $uID, $this->getCollectionID());
- $q = "insert into Pages (cID, ctID, cParentID, uID, cPointerID) values (?, ?, ?, ?, ?)";
- $r = $db->prepare($q);
-
- $res = $db->execute($r, $v);
- $newCID = $db->Insert_ID();
- Loader::model('page_statistics');
- PageStatistics::incrementParents($newCID);
-
- $q2 = "insert into PagePaths (cID, cPath) values (?, ?)";
- $v2 = array($newCID, $cPath . '/' . $handle);
- $db->query($q2, $v2);
-
- $c->refreshCache();
- return $newCID;
- }
- /**
- * Update the name, link, and to open in a new window for an external link
- * @param string $cName
- * @param string $cLink
- * @param bool $newWindow
- */
- function updateCollectionAliasExternal($cName, $cLink, $newWindow = 0) {
- if ($this->cPointerExternalLink != '') {
- $db = Loader::db();
- $this->markModified();
- if ($newWindow) {
- $newWindow = 1;
- } else {
- $newWindow = 0;
- }
- $db->query("update CollectionVersions set cvName = ? where cID = ?", array($cName, $this->cID));
- $db->query("update Pages set cPointerExternalLink = ?, cPointerExternalLinkNewWindow = ? where cID = ?", array($cLink, $newWindow, $this->cID));
- $this->refreshCache();
- }
- }
- /**
- * Add a new external link
- * @param string $cName
- * @param string $cLink
- * @param bool $newWindow
- * @return int $newCID
- */
- function addCollectionAliasExternal($cName, $cLink, $newWindow = 0) {
- $db = Loader::db();
- $dh = Loader::helper('date');
- $dt = Loader::helper('text');
- $u = new User();
- $cParentID = $this->getCollectionID();
- $uID = $u->getUserID();
- $ctID = 0;
-
- $cDate = $dh->getSystemDateTime();
- $cDatePublic = $dh->getSystemDateTime();
- $handle = $this->getCollectionHandle();
-
- // make the handle out of the title
- $handle = $dt->sanitizeFileSystem($cLink);
- $data['handle'] = $handle;
- $data['name'] = $cName;
-
- $cobj = parent::add($data);
- $newCID = $cobj->getCollectionID();
-
- if ($newWindow) {
- $newWindow = 1;
- } else {
- $newWindow = 0;
- }
-
- $v = array($newCID, $ctID, $cParentID, $uID, $cLink, $newWindow);
- $q = "insert into Pages (cID, ctID, cParentID, uID, cPointerExternalLink, cPointerExternalLinkNewWindow) values (?, ?, ?, ?, ?, ?)";
- $r = $db->prepare($q);
-
- $res = $db->execute($r, $v);
- $newCID = $db->Insert_ID();
- Loader::model('page_statistics');
- PageStatistics::incrementParents($newCID);
- return $newCID;
- }
- /**
- * Check if a page is a single page that is in the core (/concrete directory)
- * @return bool
- */
- public function isSystemPage() {
- return $this->cIsSystemPage;
- }
- /**
- * Gets the icon for a page (also fires the on_page_get_icon event)
- * @return string $icon Path to the icon
- */
- public function getCollectionIcon() {
- // returns a fully qualified image link for this page's icon, either based on its collection type or if icon.png appears in its view directory
- $icon = '';
-
- $icon = Events::fire('on_page_get_icon', $this);
-
- if ($icon) {
- return $icon;
- }
-
- if ($this->isGeneratedCollection()) {
- if ($this->getPackageID() > 0) {
- if (is_dir(DIR_PACKAGES . '/' . $this->getPackageHandle())) {
- $dirp = DIR_PACKAGES;
- $url = BASE_URL . DIR_REL;
- } else {
- $dirp = DIR_PACKAGES_CORE;
- $url = ASSETS_URL;
- }
- $file = $dirp . '/' . $this->getPackageHandle() . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON;
- if (file_exists($file)) {
- $icon = $url . '/' . DIRNAME_PACKAGES . '/' . $this->getPackageHandle() . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON;
- }
- } else if (file_exists(DIR_FILES_CONTENT . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON)) {
- $icon = BASE_URL . DIR_REL . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON;
- } else if (file_exists(DIR_FILES_CONTENT_REQUIRED . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON)) {
- $icon = ASSETS_URL . '/' . DIRNAME_PAGES . $this->getCollectionPath() . '/' . FILENAME_PAGE_ICON;
- }
-
- } else {
- }
- return $icon;
- }
- /**
- * Remove an external link/alias
- * @return int $cIDRedir cID for the original page if the page was an alias
- */
- function removeThisAlias() {
- $cIDRedir = $this->getCollectionPointerID();
- $cPointerExternalLink = $this->getCollectionPointerExternalLink();
-
- parent::refreshCache();
- if ($cPointerExternalLink != '') {
- $this->delete();
- } else if ($cIDRedir > 0) {
- $db = Loader::db();
- Loader::model('page_statistics');
- PageStatistics::decrementParents($this->getCollectionPointerOriginalID());
- $args = array($this->getCollectionPointerOriginalID());
- $q = "delete from Pages where cID = ?";
- $r = $db->query($q, $args);
- $q = "delete from Collections where cID = ?";
- $r = $db->query($q, $args);
- $q = "delete from CollectionVersions where cID = ?";
- $r = $db->query($q, $args);
-
- $q = "delete from PagePaths where cID = ?";
- $r = $db->query($q, $args);
- Cache::delete('page', $this->getCollectionPointerOriginalID() );
- Cache::delete('page_path', $this->getCollectionPointerOriginalID() );
- Cache::delete('request_path_page', $this->getCollectionPointerOriginalID() );
- return $cIDRedir;
- }
- }
-
- public function export($pageNode) {
- $p = $pageNode->addChild('page');
- $p->addAttribute('name', Loader::helper('text')->entities($this->getCollectionName()));
- $p->addAttribute('path', $this->getCollectionPath());
- $p->addAttribute('filename', $this->getCollectionFilename());
- $p->addAttribute('pagetype', $this->getCollectionTypeHandle());
- $p->addAttribute('description', Loader::helper('text')->entities($this->getCollectionDescription()));
- $p->addAttribute('package', $this->getPackageHandle());
- if ($this->getCollectionParentID() == 0 && $this->isSystemPage()) {
- $p->addAttribute('root', 'true');
- }
- $attribs = $this->getSetCollectionAttributes();
- if (count($attribs) > 0) {
- $attributes = $p->addChild('attributes');
- foreach($attribs as $ak) {
- $av = $this->getAttributeValueObject($ak);
- $cnt = $ak->getController();
- $cnt->setAttributeValue($av);
- $akx = $attributes->addChild('attributekey');
- $akx->addAttribute('handle', $ak->getAttributeKeyHandle());
- $cnt->exportValue($akx);
- }
- }
- $db = Loader::db();
- $r = $db->Execute('select arHandle from Areas where cID = ? and arIsGlobal = 0', array($this->getCollectionID()));
- while ($row = $r->FetchRow()) {
- $ax = Area::get($this, $row['arHandle']);
- $ax->export($p, $this);
- }
- }
- /**
- * Returns the uID for a page that is checked out
- * @return int
- */
- function getCollectionCheckedOutUserID() {
- return $this->cCheckedOutUID;
- }
- /**
- * Gets the allowed sub pages for a page
- */
- function getAllowedSubCollections() {
- return $this->allowedSubCollections;
- }
- /**
- * Returns the path for the current page
- * @return string
- */
- function getCollectionPath() {
- return $this->cPath;
- }
-
- /**
- * Returns the path for a page from its cID
- * @param int cID
- * @return string $path
- */
- public static function getCollectionPathFromID($cID) {
- $db = Loader::db();
- $path = $db->GetOne("select cPath from PagePaths inner join CollectionVersions on (PagePaths.cID = CollectionVersions.cID and CollectionVersions.cvIsApproved = 1) where PagePaths.cID = ?", array($cID));
- $path .= '/';
- return $path;
- }
- /**
- * Returns the uID for a page ownder
- * @return int
- */
- function getCollectionUserID() {
- return $this->uID;
- }
- /**
- * Returns the page's handle
- * @return string
- */
- function getCollectionHandle() {
- return $this->vObj->cvHandle;
- }
- /**
- * Returns the page's name
- * @return string
- */
- function getCollectionTypeName() {
- return $this->ctName;
- }
- /**
- * Returns the Collection Type ID
- * @return int
- */
- function getCollectionTypeID() {
- return $this->ctID;
- }
- /**
- * Returns the Collection Type handle
- * @return string
- */
- function getCollectionTypeHandle() {
- return $this->ctHandle;
- }
- /**
- * Returns theme id for the collection
- * @return int
- */
- function getCollectionThemeID() {
- if ($this->ptID < 1 && $this->cID != HOME_CID) {
- $c = Page::getByID(HOME_CID);
- return $c->getCollectionThemeID();
- } else {
- return $this->ptID;
- }
- }
-
- /**
- * Check if a block is an alias from a page default
- * @param array $b
- * @return bool
- */
- function isBlockAliasedFromMasterCollection(&$b) {
- //Retrieve info for all of this page's blocks at once (and "cache" it)
- // so we don't have to query the database separately for every block on the page.
- if (is_null($this->blocksAliasedFromMasterCollection)) {
- $db = Loader::db();
- $q = 'SELECT bID FROM CollectionVersionBlocks WHERE cID = ? AND isOriginal = 0 AND cvID = ? AND bID IN (SELECT bID FROM CollectionVersionBlocks AS cvb2 WHERE cvb2.cid = ?)';
- $v = array($this->getCollectionID(), $this->getVersionObject()->getVersionID(), $this->getMasterCollectionID());
- $r = $db->execute($q, $v);
- $this->blocksAliasedFromMasterCollection = $db->GetCol($q, $v);
- }
-
- return ($b->isAlias() && in_array($b->getBlockID(), $this->blocksAliasedFromMasterCollection));
- }
- /**
- * Returns Collection's theme object
- * @return PageTheme
- */
- function getCollectionThemeObject() {
- if ($this->ptID < 1) {
- return PageTheme::getSiteTheme();
- } else {
- $pl = PageTheme::getByID($this->ptID);
- return $pl;
- }
- }
- /**
- * Returns the page's name
- * @return string
- */
- function getCollectionName() {
- if (isset($this->vObj)) {
- return $this->vObj->cvName;
- }
- return $this->cvName;
- }
- /**
- * Returns the collection ID for the aliased page (returns 0 unless used on an actual alias)
- * @return int
- */
- function getCollectionPointerID() {
- return $this->cPointerID;
- }
- /**
- * Returns link for the aliased page
- * @return string
- */
- function getCollectionPointerExternalLink() {
- return $this->cPointerExternalLink;
- }
- /**
- * Returns if the alias opens in a new window
- * @return bool
- */
- function openCollectionPointerExternalLinkInNewWindow() {
- return $this->cPointerExternalLinkNewWindow;
- }
- /**
- * Checks to see if the page is an alias
- * @return bool
- */
- function isAlias() {
- return $this->cPointerID > 0 || $this->cPointerExternalLink != null;
- }
- /**
- * Checks if a page is an external link
- * @return bool
- */
- function isExternalLink() {
- return ($this->cPointerExternalLink != null);
- }
- /**
- * Get the original cID of a page
- * @return int
- */
- function getCollectionPointerOriginalID() {
- return $this->cPointerOriginalID;
- }
- /**
- * Get the file name of a page (single pages)
- * @return string
- */
- function getCollectionFilename() {
- return $this->cFilename;
- }
-
- /**
- * Gets the date a the current version was made public,
- * if user is specified, returns in the current user's timezone
- * @param string $dateFormat
- * @param string $type (system || user)
- * @return string date formated like: 2009-01-01 00:00:00
- */
- function getCollectionDatePublic($dateFormat = null, $type='system') {
- if(!$dateFormat) {
- $dateFormat = 'Y-m-d H:i:s';
- }
- if(ENABLE_USER_TIMEZONES && $type == 'user') {
- $dh = Loader::helper('date');
- return $dh->getLocalDateTime($this->vObj->cvDatePublic, $dateFormat);
- } else {
- return date($dateFormat, strtotime($this->vObj->cvDatePublic));
- }
- }
- /**
- * Get the description of a page
- * @return string
- */
- function getCollectionDescription() {
- return $this->vObj->cvDescription;
- }
- /**
- * Gets the cID of the page's parent
- * @return int
- */
- function getCollectionParentID() {
- return $this->cParentID;
- }
- /**
- * Get the Parent cID from a page by using a cID
- * @param int $cID
- * @return int
- */
- function getCollectionParentIDFromChildID($cID) {
- $db = Loader::db();
- $q = "select cParentID from Pages where cID = ?";
- $cParentID = $db->GetOne($q, array($cID));
- return $cParentID;
- }
- /**
- * Returns an array of this cParentID and aliased parentIDs
- * @return array $cID
- */
- function getCollectionParentIDs(){
- $cIDs=array($this->cParentID);
- $db = Loader::db();
- $aliasedParents=$db->getAll('SELECT cParentID FROM Pages WHERE cPointerID='.intval($this->cID).' ');
- foreach($aliasedParents as $aliasedParent)
- $cIDs[]=$aliasedParent['cParentID'];
- return $cIDs;
- }
- /**
- * Checks if a page is a page default
- * @return bool
- */
- function isMasterCollection() {
- return $this->isMasterCollection;
- }
- /**
- * Gets the pending action for a page
- * @return string
- */
- function getPendingAction() {
- return $this->cPendingAction;
- }
- /**
- * Gets the uID of the user that intiated the pending action
- * @return int
- */
- function getPendingActionUserID() {
- return $this->cPendingActionUID;
- }
- /**
- * Gets the pending action date,
- * if user is specified, returns in the current user's timezone
- * @param string $type (system || user)
- * @return string date formated like: 2009-01-01 00:00:00
- */
- function getPendingActionDateTime($type = 'system') {
- if(ENABLE_USER_TIMEZONES && $type == 'user') {
- $dh = Loader::helper('date');
- return $dh->getLocalDateTime($this->cPendingActionDatetime);
- } else {
- return $this->cPendingActionDatetime;
- }
- }
- /**
- * Gets the cID of the target page (like for deleting)
- * @return int
- */
- function getPendingActionTargetCollectionID() {
- return $this->cPendingActionTargetCID;
- }
-
- /**
- * Checks if the pending action is move
- * @return bool
- */
- function isPendingMove() {
- return ($this->cPendingAction == 'MOVE');
- }
- /**
- * Checks if the pending action is copy
- * @return bool
- */
- function isPendingCopy() {
- return ($this->cPendingAction == 'COPY');
- }
- /**
- * Checks if the pending action is delete
- * @return bool
- */
- function isPendingDelete() {
- return ($this->cPendingAction == 'DELETE');
- }
- /**
- * Gets the template permissions
- * @return string
- */
- function overrideTemplatePermissions() {
- return $this->cOverrideTemplatePermissions;
- }
- /**
- * Gets the position of the page in the sitemap
- * @return int
- */
- function getCollectionDisplayOrder() {
- return $this->cDisplayOrder;
- }
- /**
- * Set the theme for a page using the page object
- * @param PageTheme $pl
- */
- public function setTheme($pl) {
- $db = Loader::db();
- $db->query('update Pages set ptID = ? where cID = ?', array($pl->getThemeID(), $this->cID));
- parent::refreshCache();
- }
- /**
- * Set the permissions of sub-collections added beneath this permissions to inherit from the template
- */
- function setPermissionsInheritanceToTemplate() {
- $db = Loader::db();
- if ($this->cID) {
- $db->query("update Pages set cOverrideTemplatePermissions = 0 where cID = {$this->cID}");
- }
- }
- /**
- * Set the permissions of sub-collections added beneath this permissions to inherit from the parent
- */
- function setPermissionsInheritanceToOverride() {
- $db = Loader::db();
- if ($this->cID) {
- $db->query("update Pages set cOverrideTemplatePermissions = 1 where cID = {$this->cID}");
- }
- }
- function getPermissionsCollectionID() {
- return $this->cInheritPermissionsFromCID;
- }
- function getCollectionInheritance() {
- return $this->cInheritPermissionsFrom;
- }
- function getParentPermissionsCollectionID() {
- $db = Loader::db();
- $v = array($this->cParentID);
- $q = "select cInheritPermissionsFromCID from Pages where cID = ?";
- $ppID = $db->getOne($q, $v);
- return $ppID;
- }
- function getPermissionsCollectionObject() {
- return Page::getByID($this->cInheritPermissionsFromCID, "RECENT");
- }
-
- function getMasterCollectionID() {
- $db = Loader::db();
- $q = "select cID from Pages where Pages.ctID = '{$this->ctID}' and cIsTemplate = 1";
- $cID = $db->getOne($q);
- if ($cID) {
- return $cID;
- }
- }
- function getOriginalCollectionID() {
- // this is a bit weird...basically, when editing a master collection, we store the
- // master collection ID in session, along with the collection ID we were looking at before
- // moving to the master collection. This allows us to get back to that original collection
- return $_SESSION['ocID'];
- }
- function getNumChildren() {
- return $this->cChildren;
- }
-
- function getNumChildrenDirect() {
- // direct children only
- $db = Loader::db();
- $v = array($this->cID);
- $num = $db->getOne('select count(cID) as total from Pages where cParentID = ?', $v);
- if ($num) {
- return $num;
- }
- return 0;
- }
-
- /**
- * Returns the first child of the current page, or null if there is no child
- * @param string $sortColumn
- * @return Page
- */
- public function getFirstChild($sortColumn = 'cDisplayOrder asc') {
- $db = Loader::db();
- $cID = $db->GetOne("select Pages.cID from Pages inner join CollectionVersions on Pages.cID = CollectionVersions.cID where cvIsApproved = 1 and cParentID = ? order by {$sortColumn}", array($this->cID));
- if ($cID > 1) {
- return Page::getByID($cID, "ACTIVE");
- }
- return false;
- }
- function getCollectionChildrenArray( $oneLevelOnly=0 ) {
- $this->childrenCIDArray = array();
- $this->_getNumChildren($this->cID,$oneLevelOnly);
- return $this->childrenCIDArray;
- }
- function _getNumChildren($cID,$oneLevelOnly=0, $sortColumn = 'cDisplayOrder asc') {
- $db = Loader::db();
- $q = "select cID from Pages left join Packages on Pages.pkgID = Packages.pkgID where cParentID = {$cID} and cIsTemplate = 0 and (Packages.pkgHandle <> 'core' or pkgHandle is null or Pages.ctID > 0) order by {$sortColumn}";
- $r = $db->query($q);
- if ($r) {
- while ($row = $r->fetchRow()) {
- if ($row['cID'] > 0) {
- $this->childrenCIDArray[] = $row['cID'];
- if( !$oneLevelOnly ) $this->_getNumChildren($row['cID']);
- }
- }
- }
- }
- function canMoveCopyTo($cobj) {
- // ensures that we're not moving or copying to a collection inside our part of the tree
- $children = $this->getCollectionChildrenArray();
- $children[] = $this->getCollectionID();
- return (!in_array($cobj->getCollectionID(), $children));
- }
- function update($data) {
- $db = Loader::db();
- $vo = $this->getVersionObject();
- $cvID = $vo->getVersionID();
- $this->markModified();
- parent::refreshCache();
-
- $cName = $this->getCollectionName();
- $cDescription = $this->getCollectionDescription();
- $cDatePublic = $this->getCollectionDatePublic();
- $ctID = $this->getCollectionTypeID();
- $uID = $this->getCollectionUserID();
- $pkgID = $this->getPackageID();
- $cFilename = $this->getCollectionFilename();
-
- $rescanTemplatePermissions = false;
-
- $cCacheFullPageContent = $this->cCacheFullPageContent;
- $cCacheFullPageContentLifetimeCustom = $this->cCacheFullPageContentLifetimeCustom;
- $cCacheFullPageContentOverrideLifetime = $this->cCacheFullPageContentOverrideLifetime;
-
- if (isset($data['cName'])) {
- $cName = $data['cName'];
- }
- if (isset($data['cCacheFullPageContent'])) {
- $cCacheFullPageContent = $data['cCacheFullPageContent'];
- }
- if (isset($data['cCacheFullPageContentLifetimeCustom'])) {
- $cCacheFullPageContentLifetimeCustom = $data['cCacheFullPageContentLifetimeCustom'];
- }
- if (isset($data['cCacheFullPageContentOverrideLifetime'])) {
- $cCacheFullPageContentOverrideLifetime = $data['cCacheFullPageContentOverrideLifetime'];
- }
- if (isset($data['cDescription'])) {
- $cDescription = $data['cDescription'];
- }
- if (isset($data['cDatePublic'])) {
- $cDatePublic = $data['cDatePublic'];
- }
- if (isset($data['uID'])) {
- $uID = $data['uID'];
- }
- if (isset($data['ctID'])) {
- $ctID = $data['ctID'];
- // we grab the package that this ct belongs to
- $pkgID = $db->GetOne("select pkgID from PageTypes where ctID = ?", array($data['ctID']));
- $rescanTemplatePermissions = true;
- }
- $txt = Loader::helper('text');
- if (!isset($data['cHandle']) && ($this->getCollectionHandle() != '')) {
- $cHandle = $this->getCollectionHandle();
- } else if (!$data['cHandle']) {
- // make the handle out of the title
- $cHandle = $txt->sanitizeFileSystem($cName);
- } else {
- $cHandle = $txt->sanitizeFileSystem($data['cHandle']);
- }
-
- $cName = $txt->sanitize($cName);
-
- // Update the non-canonical page paths
- if (isset($data['ppURL']))
- $this->rescanPagePaths($data['ppURL']);
- if ($this->isGeneratedCollection()) {
- if (isset($data['cFilename'])) {
- $cFilename = $data['cFilename'];
- }
- // we only update a subset
- $v = array($cName, $cHandle, $cDescription, $cDatePublic, $cvID, $this->cID);
- $q = "update CollectionVersions set cvName = ?, cvHandle = ?, cvDescription = ?, cvDatePublic = ? where cvID = ? and cID = ?";
- $r = $db->prepare($q);
- $res = $db->execute($r, $v);
- } else {
- $v = array($cName, $cHandle, $cDescription, $cDatePublic, $cvID, $this->cID);
- $q = "update CollectionVersions set cvName = ?, cvHandle = ?, cvDescription = ?, cvDatePublic = ? where cvID = ? and cID = ?";
- $r = $db->prepare($q);
- $res = $db->execute($r, $v);
- }
- $db->query("update Pages set uID = ?, ctID = ?, pkgID = ?, cFilename = ?, cCacheFullPageContent = ?, cCacheFullPageContentLifetimeCustom = ?, cCacheFullPageContentOverrideLifetime = ? where cID = ?", array($uID, $ctID, $pkgID, $cFilename, $cCacheFullPageContent, $cCacheFullPageContentLifetimeCustom, $cCacheFullPageContentOverrideLifetime, $this->cID));
- if ($rescanTemplatePermissions) {
- if ($this->cInheritPermissionsFrom == 'TEMPLATE') {
- // we make sure to update the cInheritPermissionsFromCID value
- $ct = CollectionType::getByID($ctID);
- $masterC = $ct->getMasterTemplate();
- $db->Execute('update Pages set cInheritPermissionsFromCID = ? where cID = ?', array($masterC->getCollectionID(), $this->getCollectioniD()));
- }
- }
- // run any internal event we have for page update
- // i don't think we need to do this because approve reindexes
- //$this->reindex();
- parent::refreshCache();
- $ret = Events::fire('on_page_update', $this);
- }
-
- public function uniquifyPagePath($origPath) {
- $db = Loader::db();
- $proceed = false;
- $suffix = 0;
- while ($proceed != true) {
- $newPath = ($suffix == 0) ? $origPath : $origPath . $suffix;
- $v = array($newPath, $this->cID);
- $q = "select cID from PagePaths where cPath = ? and cID <> ?";
- $r = $db->query($q, $v);
- if ($r->numRows() == 0) {
- $proceed = true;
- } else {
- $suffix++;
- }
- }
- return $newPath;
- }
- public function rescanPagePaths($newPaths) {
- $db = Loader::db();
- $txt = Loader::helper('text');
- // First, get the list of page paths from the DB.
- $ppaths = $this->getPagePaths();
- // Second, reset all of their cPath values to null.
- $paths = array();
- foreach ($ppaths as $ppath) {
- if (!$ppath['ppIsCanonical']) {
- $paths[$ppath['ppID']] = null;
- }
- }
- // Third, fill in the cPath values from the user updated data.
- foreach ($newPaths as $key=>$val) {
- if (!empty($val)) {
- // Auto-prepend a slash if one is missing.
- $val = trim($val, '/');
- $val = $txt->sanitizeFileSystem($val, true);
- if ($val{0} != '/') {
- $val = '/' . $val;
- }
- $paths[$key] = $val;
- }
- }
-
- // Fourth, delete, update, or insert page paths as necessary.
- foreach ($paths as $key=>$val) {
- if (empty($val)) {
- $v = array($this->cID, $key);
- $q = "delete from PagePaths where cID = ? and ppID = ?";
- } else if (is_numeric($key)) {
- $val = $this->uniquifyPagePath($val);
- $v = array($val, $this->cID, $key);
- $q = "update PagePaths set cPath = ?, ppIsCanonical = 0 where cID = ? and ppID = ?";
- } else {
- $val = $this->uniquifyPagePath($val);
- $v = array($this->cID, $val);
- $q = "insert into PagePaths (cID, cPath, ppIsCanonical) values (?, ?, 0)";
- }
- $r = $db->query($q, $v);
- }
- }
- function acquireAreaPermissions($permissionsCollectionID) {
- $v = array($this->cID);
- $db = Loader::db();
- $q = "delete from AreaGroups where cID = ?";
- $db->query($q, $v);
- $q = "delete from AreaGroupBlockTypes where cID = ?";
- $db->query($q, $v);
- // ack - we need to copy area permissions from that page as well
- $v = array($permissionsCollectionID);
- $q = "select cID, arHandle, gID, uID, agPermissions from AreaGroups where cID = ?";
- $r = $db->query($q, $v);
- while($row = $r->fetchRow()) {
- $v = array($this->cID, $row['arHandle'], $row['gID'], $row['uID'], $row['agPermissions']);
- $q = "insert into AreaGroups (cID, arHandle, gID, uID, agPermissions) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
- $v = array($permissionsCollectionID);
- $q = "select cID, arHandle, gID, uID, btID from AreaGroupBlockTypes where cID = ?";
- $r = $db->query($q, $v);
- while($row = $r->fetchRow()) {
- $v = array($this->cID, $row['arHandle'], $row['gID'], $row['uID'], $row['btID']);
- $q = "insert into AreaGroupBlockTypes (cID, arHandle, gID, uID, btID) values (?, ?, ?, ?, ?)";
- $db->query($q, $v);
- }
- }
- function updatePermissions($args = null) {
- $db = Loader::db();
- if (!is_array($args)) {
- $args = $_POST; // legacy support
- }
-
- if ($args['cInheritPermissionsFrom'] == 'OVERRIDE') {
- // we're hitting manual override, which means we need to do permissions updates
- if ($this->getPermissionsCollectionID() != $this->cID) {
- // that means we're selecting override from some collection that _wasn't_ set to override
- // we have to grab the existing area permissions for that collection, then, clear out any
- // area permissions we might have (for some reason) and add them to this collection
- $this->acquireAreaPermissions($this->getPermissionsCollectionID());
- }
- $v = array('OVERRIDE', $this->cID, $this->cID);
- $q = "update Pages set cInheritPermissionsFrom = ?, cInheritPermissionsFromCID = ? where cID = ?";
- $r = $db->query($q, $v);
- $this->updateGroups($args);
- } else {
- // we're not overriding permissions so we don't do those updates
- if ($args['cInheritPermissionsFrom'] == 'PARENT') {
- $cpID = $this->getParentPermissionsCollectionID();
- $this->updatePermissionsCollectionID($this->cID, $cpID);
- } else if ($args['cInheritPermissionsFrom'] == 'TEMPLATE') {
- $cpID = $this->getMasterCollectionID();
- $this->updatePermissionsCollectionID($this->cID, $cpID);
- } else {
- $cpID = $this->getCollectionID();
- }
- $v = array($args['cInheritPermissionsFrom'], $cpID, $this->cID);
- $q = "update Pages set cInheritPermissionsFrom = ?, cInheritPermissionsFromCID = ? where cID = ?";
- $r = $db->query($q, $v);
- $this->cInheritPermissionsFrom = $args['cInheritPermissionsFrom'];
- $this->cInheritPermissionsFromCID = $cpID;
- // we do this because we may be going from a manual override to inheritance, and we don't
- // want any orphaned groups
- $this->clearGroups();
- }
- $cOverrideTemplatePermissions = ($args['cOverrideTemplatePermissions'] == 1) ? 1 : 0;
- $v = array($cOverrideTemplatePermissions, $this->cID);
- $q = "update Pages set cOverrideTemplatePermissions = ? where cID = ?";
- $this->cOverrideTemplatePermissions = $cOverrideTemplatePermissions;
-
- $arHandles = $db->GetCol('select arHandle from Areas where cID = ?', $this->getCollectionID());
- foreach($arHandles as $arHandle) {
- $a = Area::getOrCreate($this, $arHandle);
- $a->rescanAreaPermissionsChain();
- }
- $blocks = $this->getBlocks();
- foreach($blocks as $b) {
- $b->refreshCache();
- }
-
- $db->query($q, $v);
- parent::refreshCache();
- }
-
- public function __destruct() {
- parent::__destruct();
- }
- function updatePermissionsCollectionID($cParentIDString, $npID) {
- // now we iterate through
- $db = Loader::db();
- $pcID = $this->getPermissionsCollectionID();
- $q = "select cID from Pages where cParentID in ({$cParentIDString}) and cInheritPermissionsFromCID = {$pcID}";
- $r = $db->query($q);
- $cList = array();
- while ($row = $r->fetchRow()) {
- $cList[] = $row['cID'];
- }
- if (count($cList) > 0) {
- $cParentIDString = implode(',', $cList);
- $q2 = "update Pages set cInheritPermissionsFromCID = {$npID} where cID in ({$cParentIDString})";
- $r2 = $db->query($q2);
- $this->updatePermissionsCollectionID($cParentIDString, $npID);
- }
- }
- function updateGroupsSubCollection($cParentIDString) {
- // now we iterate through
- $db = Loader::db();
- $pcID = $this->getPermissionsCollectionID();
- $q = "select cID from Pages where cParentID in ({$cParentIDString}) and cInheritPermissionsFrom = 'PARENT'";
- $r = $db->query($q);
- $cList = array();
- while ($row = $r->fetchRow()) {
- $cList[] = $row['cID'];
- }
- if (count($cList) > 0) {
- $cParentIDString = implode(',', $cList);
- $q2 = "update Pages set cInheritPermissionsFromCID = {$this->cID} where cID in ({$cParentIDString})";
- $r2 = $db->query($q2);
- $this->updateGroupsSubCollection($cParentIDString);
- }
- }
- function move($nc, $retainOldPagePath = false) {
- $db = Loader::db();
- $newCParentID = $nc->getCollectionID();
- $dh = Loader::helper('date');
- Loader::model('page_statistics');
- $cID = ($this->getCollectionPointerOriginalID() > 0) ? $this->getCollectionPointerOriginalID() : $this->cID;
- PageStatistics::decrementParents($cID);
- parent::refreshCache();
-
- $cDateModified = $dh->getSystemDateTime();
- if ($this->getPermissionsCollectionID() != $this->getCollectionID() && $this->getPermissionsCollectionID() != $this->getMasterCollectionID()) {
- // implicitly, we're set to inherit the permissions of wherever we are in the site.
- // as such, we'll change to inherit whatever permissions our new parent has
- $npID = $nc->getPermissionsCollectionID();
- if ($npID != $this->getPermissionsCollectionID()) {
- //we have to update the existing collection with the info for the new
- //as well as all collections beneath it that are set to inherit from this parent
- // first we do this one
- $q = "update Pages set cInheritPermissionsFromCID = {$npID} where cID = {$this->cID}";
- $r = $db->query($q);
- $this->updatePermissionsCollectionID($this->getCollectionID(), $npID);
- }
- }
-
- $db->query("update Collections set cDateModified = ? where cID = ?", array($cDateModified, $cID));
- $v = array($newCParentID, $cID);
- $q = "update Pages set cParentID = ? where cID = ?";
- $r = $db->prepare($q);
- $res = $db->execute($r, $v);
- PageStatistics::incrementParents($cID);
- if (!$this->isActive()) {
- $this->activate();
- }
- $this->rescanSystemPageStatus();
- // run any event we have for page move. Arguments are
- // 1. current page being moved
- // 2. former parent
- // 3. new parent
-
- $oldParent = Page::getByID($this->getCollectionParentID(), 'RECENT');
- $newParent = Page::getByID($newCParentID, 'RECENT');
-
- $oldParent->refreshCache();
- $newParent->refreshCache();
- $ret = Events::fire('on_page_move', $this, $oldParent, $newParent);
- // now that we've moved the collection, we rescan its path
- $this->rescanCollectionPath($retainOldPagePath);
- }
- function duplicateAll($nc, $preserveUserID = false) {
- $db = Loader::db();
- $nc2 = $this->duplicate($nc);
- Page::_duplicateAll($this, $nc2, $preserveUserID);
- return $nc2;
- }
- /**
- * @access private
- **/
- function _duplicateAll($cParent, $cNewParent, $preserveUserID = false) {
- $db = Loader::db();
- $cID = $cParent->getCollectionID();
- $q = "select cID from Pages where cParentID = '{$cID}' order by cDisplayOrder asc";
- $r = $db->query($q);
- if ($r) {
- while ($row = $r->fetchRow()) {
- $tc = Page::getByID($row['cID']);
- $nc = $tc->duplicate($cNewParent, $preserveUserID);
- $tc->_duplicateAll($tc, $nc, $preserveUserID);
- }
- }
- }
- function duplicate($nc, $preserveUserID = false) {
- $db = Loader::db();
- // the passed collection is the parent collection
- $cParentID = $nc->getCollectionID();
- $u = new User();
- $uID = $u->getUserID();
- if ($preserveUserID) {
- $uID = $this->getCollectionUserID();
- }
- $dh = Loader::helper('date');
- $cDate = $dh->getSystemDateTime();
-
- $cobj = parent::getByID($this->cID);
- // create new name
-
- $newCollectionName = $this->getCollectionName();
- $index = 1;
- $nameCount = 1;
-
- while ($nameCount > 0) {
- // if we have a node at the new level with the same name, we keep incrementing til we don't
- $nameCount = $db->GetOne('select count(Pages.cID) from CollectionVersions inner join Pages on (CollectionVersions.cID = Pages.cID and CollectionVersions.cvIsApproved = 1) where Pages.cParentID = ? and CollectionVersions.cvName = ?',
- array($cParentID, $newCollectionName)
- );
- if ($nameCount > 0) {
- $index++;
- $newCollectionName = $this->getCollectionName() . ' ' . $index;
- }
- }
-
- $newC = $cobj->duplicate();
- $newCID = $newC->getCollectionID();
-
- $v = array($newCID, $this->getCollectionTypeID(), $cParentID, $uID, $this->overrideTemplatePermissions(), $this->getPermissionsCollectionID(), $this->getCollectionInheritance(), $this->cFilename, $this->cPointerID, $this->cPointerExternalLink, $this->cPointerExternalLinkNewWindow, $this->ptID, $this->cDisplayOrder);
- $q = "insert into Pages (cID, ctID, cParentID, uID, cOverrideTemplatePermissions, cInheritPermissionsFromCID, cInheritPermissionsFrom, cFilename, cPointerID, cPointerExternalLink, cPointerExternalLinkNewWindow, ptID, cDisplayOrder) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- $res = $db->query($q, $v);
-
- Loader::model('page_statistics');
- PageStatistics::incrementParents($newCID);
-
- // now with any specific permissions - but only if this collection is set to override
- if ($this->getCollectionInheritance() == 'OVERRIDE') {
- $q = "select cID, gID, uID, cgPermissions, cgStartDate, cgEndDate…