예제 #1
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public function process()
 {
     if (!$this->resource->checkPolicy('delete')) {
         return $this->failure($this->modx->lexicon('resource_err_delete'));
     }
     $resources = array($this->resource);
     $ids = array($this->resource->id);
     $this->modx->invokeEvent('OnBeforeEmptyTrash', array('ids' => &$ids, 'resources' => &$resources));
     $this->handleChildren();
     /** @var modResourceGroupResource[] $resourceGroupResources */
     $resourceGroupResources = $this->resource->getMany('ResourceGroupResources');
     /** @var modTemplateVarResource[] $templateVarResources */
     $templateVarResources = $this->resource->getMany('TemplateVarResources');
     foreach ($resourceGroupResources as $resourceGroupResource) {
         $resourceGroupResource->remove();
     }
     foreach ($templateVarResources as $templateVarResource) {
         $templateVarResource->remove();
     }
     $this->modx->removeCollection('CollectionSelection', array('resource' => $this->resource->id));
     if ($this->resource->remove() == false) {
         return $this->failure($this->modx->lexicon('resource_err_delete'));
     }
     $this->modx->invokeEvent('OnEmptyTrash', array('num_deleted' => 1, 'resources' => &$resources, 'ids' => &$ids));
     $this->logManagerAction();
     $skipClearCache = $this->getProperty('skipClearCache', false);
     if ($skipClearCache == false) {
         $this->clearCache();
     }
     return $this->success();
 }
예제 #2
0
 /**
  * Custom logic code here for setting placeholders, etc
  * @param array $scriptProperties
  * @return mixed
  */
 public function process(array $scriptProperties = array())
 {
     $placeholders = array();
     $this->resource = $this->modx->getObject('modResource', $scriptProperties['id']);
     if ($this->resource == null) {
         return $this->failure(sprintf($this->modx->lexicon('resource_with_id_not_found'), $scriptProperties['id']));
     }
     if (!$this->resource->checkPolicy('view')) {
         return $this->failure($this->modx->lexicon('access_denied'));
     }
     $this->resource->getOne('CreatedBy');
     $this->resource->getOne('EditedBy');
     $this->resource->getOne('Template');
     $server_offset_time = intval($this->modx->getOption('server_offset_time', null, 0));
     $this->resource->set('createdon_adjusted', strftime('%c', $this->resource->get('createdon') + $server_offset_time));
     $this->resource->set('editedon_adjusted', strftime('%c', $this->resource->get('editedon') + $server_offset_time));
     $this->resource->_contextKey = $this->resource->get('context_key');
     $buffer = $this->modx->cacheManager->get($this->resource->getCacheKey(), array(xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_resource_key', null, 'resource'), xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_resource_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $this->modx->getOption('cache_resource_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))));
     if ($buffer) {
         $placeholders['buffer'] = htmlspecialchars($buffer['resource']['_content']);
     }
     /* assign resource to smarty */
     $placeholders['resource'] = $this->resource;
     /* make preview url */
     $this->getPreviewUrl();
     $placeholders['_ctx'] = $this->resource->get('context_key');
     return $placeholders;
 }
예제 #3
0
 /**
  * Ensure the user can add children to the parent
  * @return boolean
  */
 public function checkParentPermissions()
 {
     $canAddChildren = true;
     $this->parentResource = $this->oldResource->getOne('Parent');
     if ($this->parentResource && !$this->parentResource->checkPolicy('add_children')) {
         $canAddChildren = false;
     }
     return $canAddChildren;
 }
예제 #4
0
 public function getResource()
 {
     if (empty($this->scriptProperties['id'])) {
         return $this->failure($this->modx->lexicon('resource_err_nf'));
     }
     $this->resource = $this->modx->getObject($this->resourceClass, $this->scriptProperties['id']);
     if (empty($this->resource)) {
         return $this->failure($this->modx->lexicon('resource_err_nfs', array('id' => $this->scriptProperties['id'])));
     }
     if (!$this->resource->checkPolicy('save')) {
         $this->canSave = false;
     }
     return true;
 }
예제 #5
0
 public function initialize()
 {
     $id = $this->getProperty('id', false);
     if (empty($id)) {
         return $this->modx->lexicon('resource_err_ns');
     }
     $this->resource = $this->modx->getObject('modResource', $id);
     if (empty($this->resource)) {
         return $this->modx->lexicon('resource_err_nfs', array('id' => $id));
     }
     /* check permissions on the resource */
     if (!$this->resource->checkPolicy(array('save' => 1, 'unpublish' => 1))) {
         return $this->modx->lexicon('permission_denied');
     }
     return true;
 }
예제 #6
0
 /**
  * Add a lock to the resource we are saving
  * @return boolean
  */
 public function addLock()
 {
     $locked = $this->object->addLock();
     if ($locked !== true) {
         $stealLock = $this->getProperty('steal_lock', false);
         if (!empty($stealLock)) {
             if (!$this->modx->hasPermission('steal_locks') || !$this->object->checkPolicy('steal_lock')) {
                 return false;
             }
             if ($locked > 0 && $locked != $this->modx->user->get('id')) {
                 $this->object->removeLock($locked);
                 $locked = $this->object->addLock($this->modx->user->get('id'));
             }
         }
         if ($locked !== true) {
             $lockedBy = intval($locked);
             $this->lockedUser = $this->modx->getObject('modUser', $lockedBy);
             if ($this->lockedUser) {
                 $locked = false;
             } else {
                 $this->object->removeLock($lockedBy);
                 $locked = true;
             }
         }
     }
     return $locked;
 }
예제 #7
0
 /**
  * Get the Resource and check for proper permissions
  *
  * {@inheritDoc}
  * @return boolean|string
  */
 public function initialize()
 {
     $id = $this->getProperty('id', false);
     if (empty($id)) {
         return $this->modx->lexicon('resource_err_ns');
     }
     $this->resource = $this->modx->getObject('modResource', $id);
     if (empty($this->resource)) {
         return $this->modx->lexicon('resource_err_nfs', array('id' => $id));
     }
     /* validate resource can be deleted */
     if (!$this->resource->checkPolicy(array('save' => true, 'delete' => true))) {
         return $this->modx->lexicon('permission_denied');
     }
     $this->deletedTime = time();
     return true;
 }
예제 #8
0
 /**
  * Update parent to be a container if user has save permission
  *
  * @return boolean
  */
 public function setParentToContainer()
 {
     $saved = false;
     if ($this->parentResource && $this->parentResource instanceof modResource && $this->parentResource->checkPolicy('save')) {
         $this->parentResource->set('isfolder', true);
         $saved = $this->parentResource->save();
     }
     return $saved;
 }
예제 #9
0
 /**
  * Update parent to be a container if user has save permission
  *
  * @return boolean
  */
 public function setParentToContainer()
 {
     $saved = false;
     $autoIsFolder = $this->modx->getOption('auto_isfolder', null, true);
     if ($autoIsFolder && $this->parentResource && $this->parentResource instanceof modResource && $this->parentResource->checkPolicy('save')) {
         $this->parentResource->set('isfolder', true);
         $saved = $this->parentResource->save();
     }
     return $saved;
 }
예제 #10
0
 /**
  * Setup permissions for this page
  * @return void
  */
 public function setPermissions()
 {
     if ($this->canSave) {
         $this->canSave = $this->resource->checkPolicy('save');
     }
     $this->canEdit = $this->modx->hasPermission('edit_document');
     $this->canCreate = $this->modx->hasPermission('new_document');
     $this->canPublish = $this->modx->hasPermission('publish_document');
     $this->canDelete = $this->modx->hasPermission('delete_document');
     $this->canDuplicate = $this->resource->checkPolicy('save');
 }
예제 #11
0
 /**
  * Setup permissions for this page
  * @return void
  */
 public function setPermissions()
 {
     if ($this->canSave) {
         $this->canSave = $this->resource->checkPolicy('save');
     }
     $this->canEdit = $this->modx->hasPermission('edit_document');
     $this->canCreate = $this->modx->hasPermission('new_document');
     $this->canPublish = $this->modx->hasPermission('publish_document');
     $this->canDelete = $this->modx->hasPermission('delete_document') && $this->resource->checkPolicy(array('save' => true, 'delete' => true));
     $this->canDuplicate = $this->modx->hasPermission('resource_duplicate') && $this->resource->checkPolicy('save');
     $this->canCreateRoot = $this->modx->hasPermission('new_document_in_root');
 }
예제 #12
0
 public function initialize()
 {
     $id = $this->getProperty('id', false);
     if (empty($id)) {
         return $this->modx->lexicon('resource_err_ns');
     }
     $c = $this->modx->newQuery('modResource');
     $c->select(array($this->modx->getSelectColumns('modResource', 'modResource'), 'template_name' => 'Template.templatename', 'creator' => 'CreatedBy.username', 'editor' => 'EditedBy.username', 'publisher' => 'PublishedBy.username'));
     $c->leftJoin('modTemplate', 'Template');
     $c->leftJoin('modUser', 'CreatedBy');
     $c->leftJoin('modUser', 'EditedBy');
     $c->leftJoin('modUser', 'PublishedBy');
     $c->where(array('modResource.id' => $id));
     $this->resource = $this->modx->getObject('modResource', $c);
     if (empty($this->resource)) {
         return $this->modx->lexicon('resource_err_nfs', array('id' => $id));
     }
     if (!$this->resource->checkPolicy('view')) {
         return $this->modx->lexicon('permission_denied');
     }
     return true;
 }
예제 #13
0
 /**
  * Get the Resource associated
  * 
  * @return modResource|string
  */
 public function getResource()
 {
     $resource_id = $this->getProperty('resource');
     if (empty($resource_id)) {
         return $this->modx->lexicon('resource_err_ns');
     }
     $this->resource = $this->modx->getObject('modResource', $resource_id);
     if (empty($resourcegroup)) {
         return $this->modx->lexicon('resource_err_nf');
     }
     /* check access */
     if (!$this->resource->checkPolicy('save')) {
         return $this->modx->lexicon('permission_denied');
     }
     return $this->resource;
 }
예제 #14
0
 /**
  * Get the Resource associated
  * 
  * @return modResource|string
  */
 public function getResource()
 {
     $resourceId = $this->getProperty('resource', 0);
     if (empty($resourceId)) {
         $this->resource = $this->modx->newObject('modResource');
         $this->resource->set('id', 0);
     } else {
         $this->resource = $this->modx->getObject('modResource', $resourceId);
         if (empty($this->resource)) {
             return $this->modx->lexicon('resource_err_nfs', array('id' => $resourceId));
         }
         /* check access */
         if (!$this->resource->checkPolicy('view')) {
             return $this->modx->lexicon('permission_denied');
         }
     }
     return $this->resource;
 }