Beispiel #1
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;
 }
 /**
  * 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;
 }
Beispiel #3
0
 public function setup()
 {
     $this->modx->lexicon->load('default', 'resource');
     if (empty($this->config['gpc']['rid'])) {
         return $this->modx->lexicon('resource_err_nf');
     }
     $this->resource = $this->modx->getObject('modResource', intval($this->config['gpc']['rid']));
     if (empty($this->resource)) {
         return $this->modx->lexicon('resource_err_nfs', array('id' => intval($this->config['gpc']['rid'])));
     }
     $this->template = $this->resource->getOne('Template');
     return true;
 }
Beispiel #4
0
 public function setup()
 {
     $this->modx->lexicon->load('default', 'resource');
     if (empty($this->config['gpc']['id'])) {
         return $this->modx->lexicon('resource_err_nf');
     }
     $this->resource = $this->modx->getObject('modResource', intval($this->config['gpc']['id']));
     if (empty($this->resource)) {
         return $this->modx->lexicon('resource_err_nfs', array('id' => intval($this->config['gpc']['id'])));
     }
     $this->resource->set('editedby', $this->modx->user->get('id'));
     $this->resource->set('editedon', strftime('%Y-%m-%d %H:%M:%S'));
     $this->template = $this->resource->getOne('Template');
     return true;
 }
Beispiel #5
0
 /**
  * Process this page, load the resource, and present its values
  * @return void
  */
 public function process()
 {
     $this->setPlaceholders($this->resource->toArray());
     $this->template = $this->resource->getOne('Template');
     if ($this->template) {
         $this->setPlaceholder('template', $this->template->get('templatename'));
     }
     $contentType = $this->resource->getOne('ContentType');
     if ($contentType) {
         $this->setPlaceholder('content_type', $contentType->get('name'));
     }
     $this->getContent();
     $this->getResourceFields();
     $this->getResourceSettings();
     if ($this->template) {
         $this->getTemplateVariables();
     }
 }
Beispiel #6
0
 /**
  * Sets the current resource to an internal variable, and also updates the working context.
  *
  * @param \modResource $resource
  */
 public function setResource(\modResource $resource)
 {
     $this->resource = $resource;
     $this->setWorkingContext($resource->get('context_key'));
     // Make sure the resource is also added to $modx->resource if there's nothing set there
     // This provides compatibility for dynamic media source paths using snippets relying on $modx->resource
     if (!$this->modx->resource) {
         $this->modx->resource =& $resource;
     }
     if ($this->getBooleanOption($this->namespace . '.parse_parent_path', null, true) && ($parent = $resource->getOne('Parent'))) {
         $this->setPathVariables(array('parent_alias' => $parent->get('alias')));
         $pids = $this->modx->getParentIds($resource->get('id'), (int) $this->getOption($this->namespace . '.parse_parent_path_height', null, 10), array('context' => $resource->get('context_key')));
         $pidx = count($pids) - 2;
         if ($pidx >= 0 && ($ultimateParent = $this->modx->getObject('modResource', $pids[$pidx]))) {
             $this->setPathVariables(array('ultimate_parent' => $ultimateParent->get('id'), 'ultimate_parent_alias' => $ultimateParent->get('alias'), 'ultimate_alias' => $ultimateParent->get('alias')));
         } else {
             $this->setPathVariables(array('ultimate_parent' => '', 'ultimate_parent_alias' => '', 'ultimate_alias' => ''));
         }
     } else {
         $this->setPathVariables(array('parent_alias' => '', 'ultimate_parent' => '', 'ultimate_parent_alias' => '', 'ultimate_alias' => ''));
     }
 }
 /**
  * Calculate a resource alias from the imported file
  *
  * @param modResource $resource A reference to the new modResource object
  * @param string $alias A suggested alias
  * @param integer $parent The parent ID of the Resource
  * @param string $context The context of the Resource
  * @return string The formatted alias
  */
 public function getResourceAlias(&$resource, $alias, $parent, $context = 'web')
 {
     // auto assign alias
     if ($alias == '' && $this->modx->getOption('automatic_alias')) {
         $alias = strtolower(trim($resource->cleanAlias($resource->get('pagetitle'))));
     } else {
         $alias = $resource->cleanAlias($alias);
     }
     $resourceContext = $this->modx->getObject('modContext', $context);
     $resourceContext->prepare(true);
     $isHtml = true;
     $extension = '';
     $containerSuffix = $this->modx->getOption('container_suffix', null, '');
     /** @var modContentType $contentType */
     if ($contentType = $resource->getOne('ContentType')) {
         $extension = $contentType->getExtension();
         $isHtml = strpos($contentType->get('mime_type'), 'html') !== false;
     }
     if ($resource->get('isfolder') && $isHtml && !empty($containerSuffix)) {
         $extension = $containerSuffix;
     }
     $aliasPath = '';
     if ($this->modx->getOption('use_alias_path')) {
         $pathParentId = intval($parent);
         $parentResources = array();
         $currResource = $this->modx->getObject('modResource', $pathParentId);
         while ($currResource) {
             $parentAlias = $currResource->get('alias');
             if (empty($parentAlias)) {
                 $parentAlias = "{$pathParentId}";
             }
             $parentResources[] = "{$parentAlias}";
             $pathParentId = $currResource->get('parent');
             $currResource = $currResource->getOne('Parent');
         }
         $aliasPath = !empty($parentResources) ? implode('/', array_reverse($parentResources)) : '';
     }
     $fullAlias = $aliasPath . $alias . $extension;
     $iterations = 3;
     $origAlias = $alias;
     while ($duplicateId = $this->modx->findResource($fullAlias) && $iterations > 0) {
         $iterations--;
         $this->log($this->modx->lexicon('import_duplicate_alias_found', array('id' => $duplicateId, 'alias' => $fullAlias)));
         $alias = $origAlias . '-' . substr(uniqid(''), -3);
         $fullAlias = $aliasPath . $alias . $extension;
     }
     return $alias;
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  * */
 public function &getOne($alias, $criteria = null, $cacheFlag = true)
 {
     if (in_array($alias, $this->dataRelated)) {
         if (!is_object($this->data)) {
             $this->loadData();
         }
         return $this->data->getOne($alias, $criteria, $cacheFlag);
     } else {
         return parent::getOne($alias, $criteria, $cacheFlag);
     }
 }