本文整理汇总了PHP中modResource::checkPolicy方法的典型用法代码示例。如果您正苦于以下问题:PHP modResource::checkPolicy方法的具体用法?PHP modResource::checkPolicy怎么用?PHP modResource::checkPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modResource
的用法示例。
在下文中一共展示了modResource::checkPolicy方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@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: process
/**
* 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: checkParentPermissions
/**
* 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: getResource
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: initialize
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: addLock
/**
* 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: initialize
/**
* 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: setParentToContainer
/**
* 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: setParentToContainer
/**
* 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: setPermissions
/**
* 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: setPermissions
/**
* 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: initialize
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: getResource
/**
* 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: getResource
/**
* 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;
}