This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Model_PagePermissionResponse extends PermissionResponse {
    
    // legacy support
    public function canWrite() { return $this->validate('edit_page_contents'); }
    public function canReadVersions() { return $this->validate('view_page_versions');}
    public function canRead() { return $this->validate('view_page');}
    public function canAddSubContent() { return $this->validate('add_subpage');}
    public function canAddSubpages() { return $this->validate('add_subpage');}
    public function canDeleteCollection() { return $this->canDeletePage(); }
    public function canApproveCollection() { return $this->validate('approve_page_versions');}
    public function canAdminPage() { return $this->validate('edit_page_permissions');}
    public function canAdmin() { return $this->validate('edit_page_permissions');}
    public function canAddExternalLink() {
        $pk = $this->category->getPermissionKeyByHandle('add_subpage');
        $pk->setPermissionObject($this->object);
        return $pk->canAddExternalLink();
    }
    public function canAddSubCollection($ct) {
        $pk = $this->category->getPermissionKeyByHandle('add_subpage');
        $pk->setPermissionObject($this->object);
        return $pk->validate($ct);
    }

    public function canViewPageInSitemap() {
        if (PERMISSIONS_MODEL != 'simple') {
            $pk = $this->category->getPermissionKeyByHandle('view_page_in_sitemap');
            $pk->setPermissionObject($this->object);
            return $pk->validate();
        }
        return $this->canViewPage();
    }
    
    public function canEditPageProperties($obj = false) {
        if ($this->object->isExternalLink()) {
            return $this->canDeletePage();
        }

        $pk = $this->category->getPermissionKeyByHandle('edit_page_properties');
        $pk->setPermissionObject($this->object);
        return $pk->validate($obj);
    }
    
    public function canDeletePage() {
        if ($this->object->isExternalLink()) {
            // then whether the person can delete/write to this page ACTUALLY dependent on whether the PARENT collection
            // is writable
            $cParentCollection = Page::getByID($this->object->getCollectionParentID(), "RECENT");
            $cp2 = new Permissions($cParentCollection);
            return $cp2->canAddExternalLink();
        }
        return $this->validate('delete_page');
    }
    
    // end legacy
    
    // convenience function
    public function canViewToolbar() {
        $u = new User();
        if (!$u->isRegistered()) {
            return false;
        }
        if ($u->isSuperUser()) {
            return true;
        }

        $dh = Loader::helper('concrete/dashboard');
        if ($dh->canRead() ||
        $this->canViewPageVersions() ||
        $this->canPreviewPageAsUser() ||
        $this->canEditPageSpeedSettings() ||
        $this->canEditPageProperties() ||
        $this->canEditPageContents() || 
        $this->canAddSubpage() ||
        $this->canDeletePage() ||
        $this->canApprovePageVersions() ||
        $this->canEditPagePermissions() ||
        $this->canMoveOrCopyPage()) {
            return true;
        } else { 
            return false;
        }
    }
    
    public function testForErrors() { 
        if ($this->object->isMasterCollection()) {
            $canEditMaster = TaskPermission::getByHandle('access_page_defaults')->can();
            if (!($canEditMaster && $_SESSION['mcEditID'] == $this->object->getCollectionID())) {
                return COLLECTION_FORBIDDEN;
            }
        } else {
            if ((!$this->canViewPage()) && (!$this->object->getCollectionPointerExternalLink() != '')) {
                return COLLECTION_FORBIDDEN;
            }
        }
    }


    public function getAllTimedAssignmentsForPage() {
        $db = Loader::db();
        $assignments = array();
        $r = $db->Execute('select peID, pkID, pdID from PagePermissionAssignments ppa inner join PermissionAccessList pal on ppa.paID = pal.paID where pdID > 0 and cID = ?', array($this->object->getCollectionID()));
        while ($row = $r->FetchRow()) { 
            $pk = PagePermissionKey::getByID($row['pkID']);
            $pae = PermissionAccessEntity::getByID($row['peID']);
            $pd = PermissionDuration::getByID($row['pdID']);
            $ppc = new PageContentPermissionTimedAssignment();
            $ppc->setDurationObject($pd);
            $ppc->setAccessEntityObject($pae);
            $ppc->setPermissionKeyObject($pk);
            $assignments[] = $ppc;
        }
        $r = $db->Execute('select arHandle from Areas where cID = ? and arOverrideCollectionPermissions = 1', array($this->object->getCollectionID()));
        while ($row = $r->FetchRow()) {
            $r2 = $db->Execute('select peID, pdID, pkID from AreaPermissionAssignments apa inner join PermissionAccessList pal on apa.paID = pal.paID where pdID > 0 and cID = ? and arHandle = ?', array($this->object->getCollectionID(), $row['arHandle']));
            while ($row2 = $r2->FetchRow()) { 
                $pk = AreaPermissionKey::getByID($row2['pkID']);
                $pae = PermissionAccessEntity::getByID($row2['peID']);
                $area = Area::get($this->getPermissionObject(), $row['arHandle']);
                $pk->setPermissionObject($area);
                $pd = PermissionDuration::getByID($row2['pdID']);
                $ppc = new PageContentPermissionTimedAssignment();
                $ppc->setDurationObject($pd);
                $ppc->setAccessEntityObject($pae);
                $ppc->setPermissionKeyObject($pk);
                $assignments[] = $ppc;
            }
        }
        $r = $db->Execute('select peID, cvb.cvID, cvb.bID, pdID, pkID from BlockPermissionAssignments bpa
        inner join PermissionAccessList pal on bpa.paID = pal.paID inner join CollectionVersionBlocks cvb on cvb.cID = bpa.cID and cvb.cvID = bpa.cvID and cvb.bID = bpa.bID
        where pdID > 0 and cvb.cID = ? and cvb.cvID = ? and cvb.cbOverrideAreaPermissions = 1', array($this->object->getCollectionID(), $this->object->getVersionID()));
        while ($row = $r->FetchRow()) { 
            $pk = BlockPermissionKey::getByID($row['pkID']);
            $pae = PermissionAccessEntity::getByID($row['peID']);
            $arHandle = $db->GetOne('select arHandle from CollectionVersionBlocks where bID = ? and cvID = ? and cID = ?', array(
                $row['bID'], $row['cvID'], $this->object->getCollectionID()
            ));
            $b = Block::getByID($row['bID'], $this->object, $arHandle);
            $pk->setPermissionObject($b);
            $pd = PermissionDuration::getByID($row['pdID']);
            $ppc = new PageContentPermissionTimedAssignment();
            $ppc->setDurationObject($pd);
            $ppc->setAccessEntityObject($pae);
            $ppc->setPermissionKeyObject($pk);
            $assignments[] = $ppc;
        }
        return $assignments;
    }
    
}