예제 #1
0
 private function moveFilesUnderCorrectResource(&$md, $field)
 {
     $matches = array();
     preg_match_all('~' . $this->uploadURL . '0/(?<file>[^ "\\)]+)~', $md, $matches);
     $path = $this->uploadPath . '0/';
     $correctPath = $this->uploadPath . $this->resource->id . '/';
     if (!is_dir($correctPath)) {
         mkdir($correctPath);
     }
     $files = $matches['file'];
     if (!empty($files)) {
         $files = array_map('trim', $files);
         $files = array_keys(array_flip($files));
         $files = array_filter($files);
         foreach ($files as $file) {
             rename($path . $file, $correctPath . $file);
         }
         $md = str_replace($this->uploadURL . '0/', $this->uploadURL . $this->resource->id . '/', $md);
         if (strpos($field, 'tv')) {
             $tvID = str_replace('tv', '', $field);
             $content = str_replace($this->uploadURL . '0/', $this->uploadURL . $this->resource->id . '/', $this->resource->getTVValue($tvID));
             $this->resource->setTVValue($tvID, $content);
         } else {
             if ($field == 'ta') {
                 $field = 'content';
             }
             $content = str_replace($this->uploadURL . '0/', $this->uploadURL . $this->resource->id . '/', $this->resource->get($field));
             $this->resource->set($field, $content);
             $this->resource->save();
         }
     }
 }
 /**
  * {@inheritDoc}
  * 
  * @return mixed
  */
 public function process()
 {
     /* get resource */
     $this->resource = $this->getResource();
     if (!is_object($this->resource) || !$this->resource instanceof modResource) {
         return $this->failure($this->resource);
     }
     /* get resource group */
     $resourceGroup = $this->modx->getObject('modResourceGroup', $this->getProperty('id'));
     if (empty($resourceGroup)) {
         return $this->failure($this->modx->lexicon('resource_group_err_nf'));
     }
     /* get access */
     $resourceGroupResource = $this->modx->getObject('modResourceGroupResource', array('document' => $this->resource->get('id'), 'document_group' => $resourceGroup->get('id')));
     if ($this->getProperty('access') == true && $resourceGroupResource != null) {
         return $this->failure($this->modx->lexicon('resource_group_resource_err_ae'));
     }
     if ($this->getProperty('access') == false && $resourceGroupResource == null) {
         return $this->failure($this->modx->lexicon('resource_group_resource_err_nf'));
     }
     if ($this->getProperty('access') == true) {
         $resourceGroupResource = $this->modx->newObject('modResourceGroupResource');
         $resourceGroupResource->set('document', $this->resource->get('id'));
         $resourceGroupResource->set('document_group', $resourceGroup->get('id'));
         $resourceGroupResource->save();
     } else {
         if ($resourceGroupResource instanceof modResourceGroupResource) {
             $resourceGroupResource->remove();
         }
     }
     return $this->success();
 }
예제 #3
0
    public static function getTemplateVarCollection(modResource &$resource) {
        $c = $resource->xpdo->newQuery('modTemplateVar');
        $c->query['distinct'] = 'DISTINCT';
        $c->select($resource->xpdo->getSelectColumns('modTemplateVar', 'modTemplateVar'));
        if ($resource->isNew()) {
            $c->select(array(
                "modTemplateVar.default_text AS value",
                "0 AS resourceId"
            ));
        } else {
            $c->select(array(
                "ISNULL(tvc.value,modTemplateVar.default_text) AS value",
                "{$resource->get('id')} AS resourceId"
            ));
        }
        $c->select($resource->xpdo->getSelectColumns('modTemplateVarTemplate', 'tvtpl', '', array('rank')));
        $c->innerJoin('modTemplateVarTemplate','tvtpl',array(
            'tvtpl.tmplvarid = modTemplateVar.id',
            'tvtpl.templateid' => $resource->get('template'),
        ));
        if (!$resource->isNew()) {
            $c->leftJoin('modTemplateVarResource','tvc',array(
                'tvc.tmplvarid = modTemplateVar.id',
                'tvc.contentid' => $resource->get('id'),
            ));
        }
        $c->sortby('tvtpl.rank,modTemplateVar.rank');

        return $resource->xpdo->getCollection('modTemplateVar', $c);
    }
예제 #4
0
 public function Lists()
 {
     $out = '';
     $this->_modx->documentIdentifier = $this->_modx->getConfig('site_start');
     $this->_modx->config['site_url'] = MODX_MANAGER_URL;
     $method = $this->getParam('method', $_GET, '');
     $addWhere = array();
     switch ($method) {
         case 'doc':
             $docID = (int) $this->getParam('doc', $_GET, 0);
             $addWhere[] = '`page`=' . $docID;
             break;
         case 'active':
             $addWhere[] = '`active`=1';
             break;
         case 'deactive':
             $addWhere[] = '`active`=0';
             break;
     }
     /**
      * По какому полю вести сортировку
      */
     $key = $this->getParam('by', $_GET, 'page');
     $modSeo = Action::getClassTable();
     if (!$modSeo->issetField($key)) {
         $key = 'uri';
     }
     $data = array('orderBy' => '`' . $key . '` ' . $this->getParam('order', $_GET, 'ASC'), 'addWhereList' => implode(" AND ", $addWhere));
     /**
      * Хакаем URL пагинатора
      */
     parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL);
     $_SERVER['REQUEST_URI'] = $this->_modx->getManagerPath() . "?" . http_build_query(array_merge($URL, array('q' => null, 'action' => null)));
     if (!empty($data)) {
         $out = $this->_modx->runSnippet('DocLister', array_merge(array('controller' => 'onetable', 'table' => Action::TABLE(), 'tpl' => '@CODE: ' . $this->showBody('table/body'), 'ownerTPL' => '@CODE: ' . $this->showBody('table/wrap'), 'altItemClass' => 'gridAltItem', 'itemClass' => 'gridItem', 'display' => self::getParam('display', $this->_modx->event->params), 'id' => 'dl', 'pageInfoTpl' => '@CODE: ' . $this->showBody('table/pageInfo'), 'pageInfoEmptyTpl' => '@CODE: ' . $this->showBody('table/pageInfoEmpty'), 'debug' => 0, 'noneTPL' => '@CODE: Нет данных', 'noneWrapOuter' => 0, 'paginate' => 'pages', 'prepare' => function (array $data = array(), \DocumentParser $modx, \onetableDocLister $_DocLister) {
             if (!empty($data['page'])) {
                 include_once MODX_BASE_PATH . "assets/lib/MODxAPI/modResource.php";
                 $DOC = new \modResource($modx);
                 $DOC->edit($data['page']);
                 $data['doc_pagetitle'] = $DOC->getID() ? $DOC->get('pagetitle') : '';
                 $data['doc_parent'] = $DOC->getID() ? $DOC->get('parent') : '0';
                 $tpl = 'pageInfoTpl';
             } else {
                 $tpl = 'pageInfoEmptyTpl';
             }
             $data['pageInfo'] = $_DocLister->parseChunk($_DocLister->getCFGDef($tpl), $data);
             $data['saveGet'] = $data['save_get'] ? 'save' : 'exclamation';
             $data['fullRequest'] = $data['full_request'] ? 'page_white_copy' : 'page_white_magnify';
             $data['active'] = $data['active'] ? 'stop' : 'add';
             $data['class'] = isset($data['dl.iteration']) && $data['dl.iteration'] % 2 ? $_DocLister->getCFGDef('itemClass') : $_DocLister->getCFGDef('altItemClass');
             return $data;
         }, 'idType' => 'documents', 'ignoreEmpty' => 1), $data));
         $out .= $this->_modx->getPlaceholder('dl.pages');
     }
     return $out;
 }
 public function process()
 {
     /* @var modResourceGroupResource $resourceGroupResource */
     $resourceGroupResource = $this->modx->getObject('modResourceGroupResource', array('document_group' => $this->resourceGroup->get('id'), 'document' => $this->resource->get('id')));
     if (empty($resourceGroupResource)) {
         return $this->failure($this->modx->lexicon('resource_group_resource_err_nf'));
     }
     if ($resourceGroupResource->remove() == false) {
         return $this->failure($this->modx->lexicon('resource_group_resource_err_remove'));
     } else {
         $this->fireAfterRemove();
     }
     return $this->success('', $resourceGroupResource);
 }
예제 #6
0
 /**
  * Process this page, load the resource, and present its values
  * @return void
  */
 public function process()
 {
     $data = $this->processInput($this->config['gpc']);
     /* @var modProcessorResponse $response */
     $response = $this->modx->runProcessor('resource/update', $data);
     if (!$response->isError()) {
         $tempRes = $response->getObject();
         $this->resource = $this->modx->getObject('modResource', $tempRes['id']);
         $this->setPlaceholders(array('message' => $this->modx->lexicon('updated'), 'resid' => $this->resource->get('id'), 'ctx' => $this->resource->get('context_key')));
     } else {
         $error = $response->getAllErrors();
         $this->setPlaceholder('message', 'Something went wrong updating the Resource: ' . implode(', ', $error));
     }
 }
예제 #7
0
 public function process()
 {
     $action = $this->resource->get('deleted') ? 'undelete' : 'delete';
     $return = $this->hm->runProcessor(array('action' => 'resource/' . $action, 'id' => $this->resource->get('id')));
     if ($return['success'] == 1) {
         if ($action == 'undelete') {
             $message = 'Successfully undeleted resource ' . $this->resource->get('pagetitle') . '.';
         } else {
             $message = 'Successfully deleted resource ' . $this->resource->get('pagetitle') . '.';
         }
     } else {
         $message = 'Something went wrong. ' . $return['message'];
     }
     $this->setPlaceholder('message', $message);
 }
예제 #8
0
 public function getResourceGroups()
 {
     $parentGroups = array();
     if ($this->resource->get('id') == 0) {
         $parent = $this->modx->getObject('modResource', $this->resource->get('parent'));
         /** @var modResource $parent */
         if ($parent) {
             $parentResourceGroups = $parent->getMany('ResourceGroupResources');
             /** @var modResourceGroupResource $parentResourceGroup */
             foreach ($parentResourceGroups as $parentResourceGroup) {
                 $parentGroups[] = $parentResourceGroup->get('document_group');
             }
             $parentGroups = array_unique($parentGroups);
         }
     }
     $this->resourceArray['resourceGroups'] = array();
     $resourceGroups = $this->resource->getGroupsList(array('name' => 'ASC'), 0, 0);
     /** @var modResourceGroup $resourceGroup */
     foreach ($resourceGroups['collection'] as $resourceGroup) {
         $access = (bool) $resourceGroup->get('access');
         if (!empty($parent) && $this->resource->get('id') == 0) {
             $access = in_array($resourceGroup->get('id'), $parentGroups) ? true : false;
         }
         $resourceGroupArray = array($resourceGroup->get('id'), $resourceGroup->get('name'), $access);
         $this->resourceArray['resourceGroups'][] = $resourceGroupArray;
     }
     return $this->resourceArray['resourceGroups'];
 }
예제 #9
0
 /**
  * Empty site cache if specified to do so
  * @return void
  */
 public function clearCache()
 {
     $syncSite = $this->getProperty('syncsite', false);
     $clearCache = $this->getProperty('clearCache', false);
     if (!empty($syncSite) || !empty($clearCache)) {
         $this->modx->cacheManager->refresh(array('db' => array(), 'auto_publish' => array('contexts' => array($this->object->get('context_key'))), 'context_settings' => array('contexts' => array($this->object->get('context_key'))), 'resource' => array('contexts' => array($this->object->get('context_key')))));
     }
 }
예제 #10
0
 public function getChanges(array $resourceArray)
 {
     $emptyDate = '0000-00-00 00:00:00';
     $resourceArray['pub_date'] = !empty($resourceArray['pub_date']) && $resourceArray['pub_date'] != $emptyDate ? $resourceArray['pub_date'] : $this->modx->lexicon('none');
     $resourceArray['unpub_date'] = !empty($resourceArray['unpub_date']) && $resourceArray['unpub_date'] != $emptyDate ? $resourceArray['unpub_date'] : $this->modx->lexicon('none');
     $resourceArray['status'] = $resourceArray['published'] ? $this->modx->lexicon('resource_published') : $this->modx->lexicon('resource_unpublished');
     $server_offset_time = intval($this->modx->getOption('server_offset_time', null, 0));
     $resourceArray['createdon_adjusted'] = strftime('%c', strtotime($this->resource->get('createdon')) + $server_offset_time);
     $resourceArray['createdon_by'] = $this->resource->get('creator');
     if (!empty($resourceArray['editedon']) && $resourceArray['editedon'] != $emptyDate) {
         $resourceArray['editedon_adjusted'] = strftime('%c', strtotime($this->resource->get('editedon')) + $server_offset_time);
         $resourceArray['editedon_by'] = $this->resource->get('editor');
     } else {
         $resourceArray['editedon_adjusted'] = $this->modx->lexicon('none');
         $resourceArray['editedon_by'] = $this->modx->lexicon('none');
     }
     if (!empty($resourceArray['publishedon']) && $resourceArray['publishedon'] != $emptyDate) {
         $resourceArray['publishedon_adjusted'] = strftime('%c', strtotime($this->resource->get('editedon')) + $server_offset_time);
         $resourceArray['publishedon_by'] = $this->resource->get('publisher');
     } else {
         $resourceArray['publishedon_adjusted'] = $this->modx->lexicon('none');
         $resourceArray['publishedon_by'] = $this->modx->lexicon('none');
     }
     return $resourceArray;
 }
예제 #11
0
 /**
  * Fire the TV Form Render event
  * @return mixed
  */
 public function fireOnTVFormRender()
 {
     $onResourceTVFormPrerender = $this->modx->invokeEvent('OnResourceTVFormPrerender', array('resource' => $this->resource->get('id')));
     if (is_array($onResourceTVFormPrerender)) {
         $onResourceTVFormPrerender = implode('', $onResourceTVFormPrerender);
     }
     $this->setPlaceholder('OnResourceTVFormPrerender', $onResourceTVFormPrerender);
     return $onResourceTVFormPrerender;
 }
예제 #12
0
 /**
  * Quick check to make sure it's not site_start, if so, publish if not published to prevent site error
  * 
  * @return boolean
  */
 public function checkIfSiteStart()
 {
     $saved = false;
     if ($this->object->get('id') == $this->workingContext->getOption('site_start') && !$this->object->get('published')) {
         $this->object->set('published', true);
         $saved = $this->object->save();
     }
     return $saved;
 }
예제 #13
0
 function get($k, $format = NULL, $formatTemplate = NULL)
 {
     switch ($k) {
         case 'url':
             return $this->makeUrl();
             break;
     }
     return parent::get($k, $format, $formatTemplate);
 }
예제 #14
0
 /**
  * Process this page, load the resource, and present its values
  * @return void
  */
 public function process()
 {
     $data = $this->processInput($this->config['gpc']);
     /* @var modProcessorResponse $response */
     $response = $this->modx->runProcessor('resource/create', $data);
     if (!$response->isError()) {
         $tempRes = $response->getObject();
         $this->resource = $this->modx->getObject('modResource', $tempRes['id']);
         /* Make sure the createdby column is set */
         $cb = $this->resource->get('createdby');
         if (empty($cb)) {
             $this->resource->set('createdby', $this->modx->user->get('id'));
             $this->resource->save();
         }
         $this->setPlaceholders(array('message' => 'Resource created.', 'resid' => $this->resource->get('id'), 'ctx' => $this->resource->get('context_key')));
     } else {
         $error = $response->getAllErrors();
         $this->setPlaceholder('message', 'Something went wrong creating the Resource: ' . implode(', ', $error));
     }
 }
예제 #15
0
 /** {@inheritDoc} */
 public function prepareResourceNode(modResource $resource)
 {
     $qtipField = $this->getProperty('qtipField');
     $nodeField = $this->getProperty('nodeField');
     $hasChildren = (int) $resource->get('childrenCount') > 0 && $resource->get('hide_children_in_tree') == 0 ? true : false;
     // Assign an icon class based on the class_key
     $class = $iconCls = array();
     $classKey = strtolower($resource->get('class_key'));
     if (substr($classKey, 0, 3) == 'mod') {
         $classKey = substr($classKey, 3);
     }
     $classKeyIcon = $this->modx->getOption('mgr_tree_icon_' . $classKey, null, 'tree-resource');
     $iconCls[] = $classKeyIcon;
     $class[] = 'icon-' . strtolower(str_replace('mod', '', $resource->get('class_key')));
     if (!$resource->isfolder) {
         $class[] = 'x-tree-node-leaf icon-resource';
     }
     if (!$resource->get('published')) {
         $class[] = 'unpublished';
     }
     if ($resource->get('deleted')) {
         $class[] = 'deleted';
     }
     if ($resource->get('hidemenu')) {
         $class[] = 'hidemenu';
     }
     if ($hasChildren) {
         $class[] = 'haschildren';
         $iconCls[] = $this->modx->getOption('mgr_tree_icon_folder', null, 'tree-folder');
         $iconCls[] = 'parent-resource';
     }
     $qtip = '';
     if (!empty($qtipField)) {
         $qtip = '<b>' . strip_tags($resource->{$qtipField}) . '</b>';
     } else {
         if ($resource->longtitle != '') {
             $qtip = '<b>' . strip_tags($resource->longtitle) . '</b><br />';
         }
         if ($resource->description != '') {
             $qtip = '<i>' . strip_tags($resource->description) . '</i>';
         }
     }
     $idNote = $this->modx->hasPermission('tree_show_resource_ids') ? ' <span dir="ltr">(' . $resource->id . ')</span>' : '';
     $itemArray = array('text' => strip_tags($resource->{$nodeField}) . $idNote, 'id' => $resource->context_key . '_' . $resource->id, 'pk' => $resource->id, 'cls' => implode(' ', $class), 'iconCls' => implode(' ', $iconCls), 'type' => 'modResource', 'classKey' => $resource->class_key, 'ctx' => $resource->context_key, 'hide_children_in_tree' => $resource->hide_children_in_tree, 'qtip' => $qtip, 'checked' => !empty($resource->member) || $resource->id == $this->parent_id ? true : false, 'disabled' => $resource->id == $this->parent_id ? true : false);
     if (!$hasChildren) {
         $itemArray['hasChildren'] = false;
         $itemArray['children'] = array();
         $itemArray['expanded'] = true;
     } else {
         $itemArray['hasChildren'] = true;
     }
     if ($itemArray['classKey'] != 'msCategory') {
         unset($itemArray['checked']);
     }
     return $itemArray;
 }
 public function beforeSave()
 {
     /* format data */
     $resourceId = substr(strrchr($this->getProperty('resource', ''), '_'), 1);
     $resourceGroupId = substr(strrchr($this->getProperty('resourceGroup', ''), '_'), 1);
     if (empty($resourceId) || empty($resourceGroupId)) {
         return $this->modx->lexicon('invalid_data');
     }
     $this->resource = $this->modx->getObject('modResource', $resourceId);
     if (!$this->resource) {
         return $this->modx->lexicon('resource_err_nfs', array('id' => $resourceId));
     }
     $this->resourceGroup = $this->modx->getObject('modResourceGroup', $resourceGroupId);
     if (!$this->resourceGroup) {
         return $this->modx->lexicon('resource_group_err_nf');
     }
     if ($this->doesAlreadyExist(array('document' => $this->resource->get('id'), 'document_group' => $this->resourceGroup->get('id')))) {
         return $this->modx->lexicon($this->objectType . '_err_ae');
     }
     $this->object->set('document', $this->resource->get('id'));
     $this->object->set('document_group', $this->resourceGroup->get('id'));
     return parent::beforeSave();
 }
예제 #17
0
 /**
  * Check for locks on the Resource
  *
  * @return bool
  */
 public function checkForLocks()
 {
     $lockedBy = $this->resource->addLock($this->modx->user->get('id'));
     $this->canSave = $this->modx->hasPermission('save_document') ? 1 : 0;
     $this->locked = false;
     $this->lockedText = '';
     if (!empty($lockedBy) && $lockedBy !== true) {
         $this->canSave = false;
         $this->locked = true;
         $locker = $this->modx->getObject('modUser', $lockedBy);
         if ($locker) {
             $lockedBy = $locker->get('username');
         }
         $this->lockedText = $this->modx->lexicon('resource_locked_by', array('user' => $lockedBy, 'id' => $this->resource->get('id')));
     }
     return $this->locked;
 }
예제 #18
0
 /**
  * Used in MODX < 2.1 where the modResource::getTemplateVarCollection method is not yet available.
  * Collects modTemplateVar objects with their value for the current resource.
  *
  * @return array An array with TV objects.
  */
 private function _getTemplateVars()
 {
     $c = $this->modx->newQuery('modTemplateVar');
     $c->query['distinct'] = 'DISTINCT';
     $c->select($this->modx->getSelectColumns('modTemplateVar', 'modTemplateVar'));
     if ($this->resource->isNew()) {
         $c->select(array('modTemplateVar.default_text AS value', '0 AS resourceId'));
     } else {
         $c->select(array('IF(ISNULL(tvc.value),modTemplateVar.default_text,tvc.value) AS value', $this->resource->get('id') . ' AS resourceId'));
     }
     $c->innerJoin('modTemplateVarTemplate', 'tvtpl', array('tvtpl.tmplvarid = modTemplateVar.id', 'tvtpl.templateid' => $this->resource->get('template')));
     if (!$this->resource->isNew()) {
         $c->leftJoin('modTemplateVarResource', 'tvc', array('tvc.tmplvarid = modTemplateVar.id', 'tvc.contentid' => $this->resource->get('id')));
     }
     $c->sortby('tvtpl.rank,modTemplateVar.rank');
     return $this->modx->getCollection('modTemplateVar', $c);
 }
예제 #19
0
파일: Alpacka.php 프로젝트: modmore/alpacka
 /**
  * Parses a path by replacing placeholders with dynamic values. This supports the following placeholders:
  * - [[+year]]
  * - [[+month]]
  * - [[+date]]
  * - [[+day]]
  * - [[+user]]
  * - [[+username]]
  * - [[++assets_url]]
  * - [[++site_url]]
  * - [[++base_url]]
  * - [[+<any resource field>]]
  * - [[+tv.<any template variable name>]]
  *
  * In $this->setResource, support is also added for the following through $this->setPathVariables:
  * - [[+parent_alias]]
  * - [[+ultimate_parent]]
  * - [[+ultimate_parent_alias]]
  *
  * @param $path
  * @return mixed
  */
 public function parsePathVariables($path)
 {
     $path = str_replace('[[+year]]', date('Y'), $path);
     $path = str_replace('[[+month]]', date('m'), $path);
     $path = str_replace('[[+date]]', date('d'), $path);
     $path = str_replace('[[+day]]', date('d'), $path);
     $path = str_replace('[[+user]]', $this->modx->getUser()->get('id'), $path);
     $path = str_replace('[[+username]]', $this->modx->getUser()->get('username'), $path);
     $path = str_replace('[[++assets_url]]', $this->getOption('assets_url', null, 'assets/'), $path);
     $path = str_replace('[[++site_url]]', $this->getOption('site_url', null, ''), $path);
     $path = str_replace('[[++base_url]]', $this->getOption('base_url', null, ''), $path);
     foreach ($this->pathVariables as $key => $value) {
         $path = str_replace('[[+' . $key . ']]', $value, $path);
     }
     if ($this->resource) {
         $path = str_replace('[[+resource]]', $this->resource->get('id'), $path);
         // Match all placeholders in the string so we can replace it with the proper values.
         if (preg_match_all('/\\[\\[\\+(.*?)\\]\\]/', $path, $matches) && !empty($matches[1])) {
             foreach ($matches[1] as $key) {
                 $ph = '[[+' . $key . ']]';
                 if (substr($key, 0, 3) == 'tv.') {
                     $tvName = substr($key, 3);
                     $tvValue = $this->resource->getTVValue($tvName);
                     $path = str_replace($ph, $tvValue, $path);
                 } elseif (array_key_exists($key, $this->resource->_fieldMeta)) {
                     $path = str_replace($ph, $this->resource->get($key), $path);
                 } else {
                     $this->modx->log(\modX::LOG_LEVEL_WARN, "Unknown placeholder '{$key}' in redactor path {$path}", '', __METHOD__, __FILE__, __LINE__);
                 }
             }
         }
     }
     /**
      * Prevent changing double slashes in a protocol (e.g. http://) to a single slash, while cleaning up other
      * duplicate slashes in the path.
      */
     $path = str_replace('://', '__:_/_/__', $path);
     $path = str_replace('//', '/', $path);
     $path = str_replace('__:_/_/__', '://', $path);
     return $path;
 }
예제 #20
0
 /**
  * @param string $k
  * @param null $v
  * @param string $vType
  *
  * @return bool
  */
 public function set($k, $v = null, $vType = '')
 {
     if (is_string($k) && $k == 'createdby' && empty($this->_oldAuthor)) {
         $this->_oldAuthor = parent::get('createdby');
     }
     return parent::set($k, $v, $vType);
 }
예제 #21
0
 /**
  * Clear the site cache
  * @return void
  */
 public function clearCache()
 {
     $this->modx->cacheManager->refresh(array('db' => array(), 'auto_publish' => array('contexts' => array($this->resource->get('context_key'))), 'context_settings' => array('contexts' => array($this->resource->get('context_key'))), 'resource' => array('contexts' => array($this->resource->get('context_key')))));
 }
예제 #22
0
 /**
  * Check for any Form Customization rules for this TV
  * @param string $value
  * @param modResource $resource
  * @return mixed
  */
 public function checkForFormCustomizationRules($value, &$resource)
 {
     if ($this->xpdo->request && $this->xpdo->user instanceof modUser) {
         if (empty($resource)) {
             $resource =& $this->xpdo->resource;
         }
         if ($this->xpdo->getOption('form_customization_use_all_groups', null, false)) {
             $userGroups = $this->xpdo->user->getUserGroups();
         } else {
             $primaryGroup = $this->xpdo->user->getPrimaryGroup();
             if ($primaryGroup) {
                 $userGroups = array($primaryGroup->get('id'));
             }
         }
         $c = $this->xpdo->newQuery('modActionDom');
         $c->innerJoin('modFormCustomizationSet', 'FCSet');
         $c->innerJoin('modFormCustomizationProfile', 'Profile', 'FCSet.profile = Profile.id');
         $c->leftJoin('modFormCustomizationProfileUserGroup', 'ProfileUserGroup', 'Profile.id = ProfileUserGroup.profile');
         $c->leftJoin('modFormCustomizationProfile', 'UGProfile', 'UGProfile.id = ProfileUserGroup.profile');
         $ruleFieldName = $this->xpdo->escape('rule');
         $c->where(array(array("(modActionDom.{$ruleFieldName} = 'tvDefault'\n                   OR modActionDom.{$ruleFieldName} = 'tvVisible'\n                   OR modActionDom.{$ruleFieldName} = 'tvTitle')"), "'tv{$this->get('id')}' IN ({$this->xpdo->escape('modActionDom')}.{$this->xpdo->escape('name')})", 'FCSet.active' => true, 'Profile.active' => true));
         if (!empty($userGroups)) {
             $c->where(array(array('ProfileUserGroup.usergroup:IN' => $userGroups, array('OR:ProfileUserGroup.usergroup:IS' => null, 'AND:UGProfile.active:=' => true)), 'OR:ProfileUserGroup.usergroup:=' => null), xPDOQuery::SQL_AND, null, 2);
         }
         if (!empty($this->xpdo->request) && !empty($this->xpdo->request->action)) {
             $c->where(array('modActionDom.action' => $this->xpdo->request->action));
         }
         $c->select($this->xpdo->getSelectColumns('modActionDom', 'modActionDom'));
         $c->select(array('FCSet.constraint_class', 'FCSet.constraint_field', 'FCSet.' . $this->xpdo->escape('constraint'), 'FCSet.template'));
         $c->sortby('FCSet.template', 'ASC');
         $c->sortby('modActionDom.rank', 'ASC');
         $domRules = $this->xpdo->getCollection('modActionDom', $c);
         /** @var modActionDom $rule */
         foreach ($domRules as $rule) {
             if (!empty($resource)) {
                 $template = $rule->get('template');
                 if (!empty($template) && $template != $resource->get('template')) {
                     continue;
                 }
                 $constraintClass = $rule->get('constraint_class');
                 if (!empty($constraintClass)) {
                     if (!$resource instanceof $constraintClass) {
                         continue;
                     }
                     $constraintField = $rule->get('constraint_field');
                     $constraint = $rule->get('constraint');
                     if ($resource->get($constraintField) != $constraint) {
                         continue;
                     }
                 }
             }
             switch ($rule->get('rule')) {
                 case 'tvVisible':
                     if ($rule->get('value') == 0) {
                         $this->set('type', 'hidden');
                     }
                     break;
                 case 'tvDefault':
                     $v = $rule->get('value');
                     if (empty($resourceId)) {
                         $value = $v;
                         $this->set('value', $v);
                     }
                     $this->set('default_text', $v);
                     break;
                 case 'tvTitle':
                     $v = $rule->get('value');
                     $this->set('caption', $v);
                     break;
             }
         }
         unset($domRules, $rule, $userGroups, $v, $c);
     }
     return $value;
 }
예제 #23
0
 /**
  * Log the manager action
  *
  * @return void
  */
 public function logManagerAction()
 {
     $this->modx->logManagerAction('remove_resource', $this->resource->get('class_key'), $this->resource->get('id'));
 }
예제 #24
0
 /**
  * Prepare a Resource for being shown in the tree
  *
  * @param modResource $resource
  * @return array
  */
 public function prepareResourceNode(modResource $resource)
 {
     $qtipField = $this->getProperty('qtipField');
     $nodeField = $this->getProperty('nodeField');
     $nodeFieldFallback = $this->getProperty('nodeFieldFallback');
     $noHref = $this->getProperty('noHref', false);
     $hasChildren = $resource->get('childrenCount') > 0 && !$resource->get('hide_children_in_tree');
     $class = array();
     if (!$resource->isfolder) {
         $class[] = 'x-tree-node-leaf';
     }
     if (!$resource->get('published')) {
         $class[] = 'unpublished';
     }
     if ($resource->get('deleted')) {
         $class[] = 'deleted';
     }
     if ($resource->get('hidemenu')) {
         $class[] = 'hidemenu';
     }
     if (!empty($this->permissions['save_document'])) {
         $class[] = $this->permissions['save_document'];
     }
     if (!empty($this->permissions['view_document'])) {
         $class[] = $this->permissions['view_document'];
     }
     if (!empty($this->permissions['edit_document'])) {
         $class[] = $this->permissions['edit_document'];
     }
     if (!empty($this->permissions['resource_duplicate'])) {
         if ($resource->parent != $this->defaultRootId || $this->modx->hasPermission('new_document_in_root')) {
             $class[] = $this->permissions['resource_duplicate'];
         }
     }
     if ($resource->allowChildrenResources) {
         if (!empty($this->permissions['new_document'])) {
             $class[] = $this->permissions['new_document'];
         }
         if (!empty($this->permissions['new_symlink'])) {
             $class[] = $this->permissions['new_symlink'];
         }
         if (!empty($this->permissions['new_weblink'])) {
             $class[] = $this->permissions['new_weblink'];
         }
         if (!empty($this->permissions['new_static_resource'])) {
             $class[] = $this->permissions['new_static_resource'];
         }
         if (!empty($this->permissions['resource_quick_create'])) {
             $class[] = $this->permissions['resource_quick_create'];
         }
     }
     if (!empty($this->permissions['resource_quick_update'])) {
         $class[] = $this->permissions['resource_quick_update'];
     }
     if (!empty($this->permissions['delete_document'])) {
         $class[] = $this->permissions['delete_document'];
     }
     if (!empty($this->permissions['undelete_document'])) {
         $class[] = $this->permissions['undelete_document'];
     }
     if (!empty($this->permissions['publish_document'])) {
         $class[] = $this->permissions['publish_document'];
     }
     if (!empty($this->permissions['unpublish_document'])) {
         $class[] = $this->permissions['unpublish_document'];
     }
     $active = false;
     if ($this->getProperty('currentResource') == $resource->id && $this->getProperty('currentAction') == 'resource/update') {
         $active = true;
     }
     $qtip = '';
     if (!empty($qtipField) && !empty($resource->{$qtipField})) {
         $qtip = '<b>' . strip_tags($resource->{$qtipField}) . '</b>';
     } else {
         if ($resource->longtitle != '') {
             $qtip = '<b>' . strip_tags($resource->longtitle) . '</b><br />';
         }
         if ($resource->description != '') {
             $qtip = '<i>' . strip_tags($resource->description) . '</i>';
         }
     }
     // Check for an icon class on the resource template
     $tplIcon = $resource->Template ? $resource->Template->icon : '';
     // Assign an icon class based on the class_key
     $classKey = strtolower($resource->get('class_key'));
     if (substr($classKey, 0, 3) == 'mod') {
         $classKey = substr($classKey, 3);
     }
     $classKeyIcon = $this->modx->getOption('mgr_tree_icon_' . $classKey, null, 'tree-resource', true);
     if (!empty($tplIcon)) {
         $iconCls[] = $tplIcon;
     } else {
         $iconCls[] = $classKeyIcon;
     }
     switch ($classKey) {
         case 'weblink':
             $iconCls[] = $this->modx->getOption('mgr_tree_icon_weblink', null, 'tree-weblink');
             break;
         case 'symlink':
             $iconCls[] = $this->modx->getOption('mgr_tree_icon_symlink', null, 'tree-symlink');
             break;
         case 'staticresource':
             $iconCls[] = $this->modx->getOption('mgr_tree_icon_staticresource', null, 'tree-static-resource');
             break;
     }
     // Icons specific with the context and resource ID for super specific tweaks
     $iconCls[] = 'icon-' . $resource->get('context_key') . '-' . $resource->get('id');
     $iconCls[] = 'icon-parent-' . $resource->get('context_key') . '-' . $resource->get('parent');
     // Modifiers to indicate resource _state_
     if ($hasChildren || $resource->isfolder) {
         if (empty($tplIcon) && $classKeyIcon == 'tree-resource') {
             $iconCls[] = $this->modx->getOption('mgr_tree_icon_folder', null, 'tree-folder');
         }
         $iconCls[] = 'parent-resource';
     }
     // Add icon class - and additional description to the tooltip - if the resource is locked.
     $locked = $resource->getLock();
     if ($locked && $locked != $this->modx->user->get('id')) {
         $iconCls[] = 'locked-resource';
         /** @var modUser $lockedBy */
         $lockedBy = $this->modx->getObject('modUser', $locked);
         if ($lockedBy) {
             $qtip .= ' - ' . $this->modx->lexicon('locked_by', array('username' => $lockedBy->get('username')));
         }
     }
     // Add the ID to the item text if the user has the permission
     $idNote = $this->modx->hasPermission('tree_show_resource_ids') ? ' <span dir="ltr">(' . $resource->id . ')</span>' : '';
     // Used in the preview_url, if sessions are disabled on the resource context we add an extra url param
     $sessionEnabled = '';
     if ($ctxSetting = $this->modx->getObject('modContextSetting', array('context_key' => $resource->get('context_key'), 'key' => 'session_enabled'))) {
         $sessionEnabled = $ctxSetting->get('value') == 0 ? array('preview' => 'true') : '';
     }
     $text = strip_tags($resource->get($nodeField));
     if (empty($text)) {
         $text = $resource->get($nodeFieldFallback);
         $text = strip_tags($text);
     }
     $itemArray = array('text' => $text . $idNote, 'id' => $resource->context_key . '_' . $resource->id, 'pk' => $resource->id, 'cls' => implode(' ', $class), 'iconCls' => implode(' ', $iconCls), 'type' => 'modResource', 'selected' => $active, 'classKey' => $resource->class_key, 'ctx' => $resource->context_key, 'hide_children_in_tree' => $resource->hide_children_in_tree, 'qtip' => $qtip, 'preview_url' => !$resource->get('deleted') ? $this->modx->makeUrl($resource->get('id'), $resource->get('context_key'), $sessionEnabled, 'full', array('xhtml_urls' => false)) : '', 'page' => empty($noHref) ? '?a=' . (!empty($this->permissions['edit_document']) ? 'resource/update' : 'resource/data') . '&id=' . $resource->id : '', 'allowDrop' => true);
     if (!$hasChildren) {
         $itemArray['hasChildren'] = false;
         $itemArray['children'] = array();
         $itemArray['expanded'] = true;
     } else {
         $itemArray['hasChildren'] = true;
     }
     $itemArray = $resource->prepareTreeNode($itemArray);
     return $itemArray;
 }
예제 #25
0
 public function getCollectionsTemplate()
 {
     /** @var CollectionTemplate $template */
     $template = $this->modx->collections->getCollectionsView($this->resource);
     $c = $this->modx->newQuery('CollectionTemplateColumn');
     $c->sortby('position', 'ASC');
     $c->where(array('template' => $template->id));
     /** @var CollectionTemplateColumn[] $columns */
     $columns = $this->modx->getIterator('CollectionTemplateColumn', $c);
     $derivates = array();
     if ($template->resource_type_selection) {
         $response = $this->modx->runProcessor('mgr/extra/getderivates', array('skip' => 'modXMLRPCResource', 'class' => 'modResource'), array('processors_path' => $this->modx->collections->getOption('processorsPath')));
         $response = $this->modx->fromJSON($response->response);
         if ($response != '') {
             if ($template->allowed_resource_types == '') {
                 foreach ($response['results'] as $type) {
                     $derivates[] = $type;
                 }
             } else {
                 $allowedTypes = $this->modx->collections->explodeAndClean($template->allowed_resource_types);
                 foreach ($allowedTypes as $type) {
                     if (isset($response['results'][$type])) {
                         $derivates[] = $response['results'][$type];
                     }
                 }
             }
         }
     }
     $parent = !empty($template->parent) ? $template->parent : '';
     if (substr($parent, 0, 8) == '@SNIPPET') {
         $snippet = trim(substr($parent, 8));
         $properties = array('resource' => &$this->resource);
         $parent = $this->modx->runSnippet($snippet, $properties);
     }
     $parent_context = $this->resource->get('context_key');
     if (!empty($parent)) {
         //we have a custom parent - try to get the context_key
         if ($p_resource = $this->modx->getObject('modResource', $parent)) {
             $parent_context = $p_resource->get('context_key');
         }
     } else {
         $parent = $this->resource->get('id');
     }
     $templateOptions = array('fields' => array('actions', 'action_edit', 'preview_url', 'menu_actions', 'icons'), 'columns' => array(), 'sort' => array('field' => $template->sort_field . ':' . $template->sort_type, 'dir' => $template->sort_dir), 'pageSize' => $template->page_size, 'bulkActions' => $template->bulk_actions, 'allowDD' => $template->allow_dd, 'resource_type_selection' => $template->resource_type_selection, 'children' => array('template' => $template->child_template, 'resource_type' => $template->child_resource_type), 'tab_label' => $template->tab_label, 'button_label' => $template->button_label, 'link_label' => $template->link_label, 'content_place' => $template->content_place, 'context_menu' => $this->modx->collections->explodeAndClean($template->context_menu, ',', 1), 'resourceDerivatives' => $derivates, 'selection_create_sort' => $template->selection_create_sort, 'parent' => $parent, 'parent_context' => $parent_context, 'permanent_sort' => array('before' => $template->permanent_sort_before, 'after' => $template->permanent_sort_after));
     foreach ($columns as $column) {
         $templateOptions['fields'][] = $column->name;
         $header = $this->modx->lexicon($column->label);
         if ($header == null) {
             $header = $column->label;
         }
         $columnDef = array('header' => $header, 'dataIndex' => $column->name, 'hidden' => $column->hidden, 'sortable' => $column->sortable, 'width' => $column->width);
         if ($column->editor != '') {
             $editorObj = $this->modx->fromJSON($column->editor);
             if ($editorObj == null) {
                 $editorObj = array('xtype' => $column->editor, 'renderer' => false);
             }
             $columnDef['editor'] = $editorObj;
         }
         if ($column->renderer != '') {
             $columnDef['renderer'] = $column->renderer;
         }
         $templateOptions['columns'][] = $columnDef;
     }
     return $this->modx->toJSON($templateOptions);
 }
예제 #26
0
 /**
  * Return the pagetitle
  *
  * @return string
  */
 public function getPageTitle()
 {
     return $this->resource->get('pagetitle');
 }
예제 #27
0
    /**
     * @param modManagerController $controller
     * @param modResource $resource
     */
    public function loadManagerFiles(modManagerController $controller, modResource $resource)
    {
        $modx23 = (int) $this->systemVersion();
        $cssUrl = $this->config['cssUrl'] . 'mgr/';
        $jsUrl = $this->config['jsUrl'] . 'mgr/';
        $properties = $resource->getProperties('ms2gallery');
        if (empty($properties['media_source'])) {
            if (!($source_id = $resource->getTVValue('ms2Gallery'))) {
                /** @var modContextSetting $setting */
                $setting = $this->modx->getObject('modContextSetting', array('key' => 'ms2gallery_source_default', 'context_key' => $resource->get('context_key')));
                $source_id = !empty($setting) ? $setting->get('value') : $this->modx->getOption('ms2gallery_source_default');
            }
            $resource->setProperties(array('media_source' => $source_id), 'ms2gallery');
            $resource->save();
        } else {
            $source_id = $properties['media_source'];
        }
        if (empty($source_id)) {
            $source_id = $this->modx->getOption('ms2gallery_source_default');
        }
        $resource->set('media_source', $source_id);
        $controller->addLexiconTopic('ms2gallery:default');
        $controller->addJavascript($jsUrl . 'ms2gallery.js');
        $controller->addLastJavascript($jsUrl . 'misc/ms2.combo.js');
        $controller->addLastJavascript($jsUrl . 'misc/ms2.utils.js');
        $controller->addLastJavascript($jsUrl . 'misc/plupload/plupload.full.js');
        $controller->addLastJavascript($jsUrl . 'misc/ext.ddview.js');
        $controller->addLastJavascript($jsUrl . 'gallery.view.js');
        $controller->addLastJavascript($jsUrl . 'gallery.window.js');
        $controller->addLastJavascript($jsUrl . 'gallery.toolbar.js');
        $controller->addLastJavascript($jsUrl . 'gallery.panel.js');
        $controller->addCss($cssUrl . 'main.css');
        if (!$modx23) {
            $controller->addCss($cssUrl . 'font-awesome.min.css');
        }
        $source_config = array();
        /** @var modMediaSource $source */
        if ($source = $this->modx->getObject('modMediaSource', $source_id)) {
            $tmp = $source->getProperties();
            foreach ($tmp as $v) {
                $source_config[$v['name']] = $v['value'];
            }
        }
        $controller->addHtml('
		<script type="text/javascript">
			MODx.modx23 = ' . $modx23 . ';
			ms2Gallery.config = ' . $this->modx->toJSON($this->config) . ';
			ms2Gallery.config.media_source = ' . $this->modx->toJSON($source_config) . ';
		</script>');
        if ($this->modx->getOption('ms2gallery_new_tab_mode', null, true)) {
            $controller->addLastJavascript($jsUrl . 'tab.js');
        } else {
            $insert = '
				tabs.add({
					xtype: "ms2gallery-page",
					id: "ms2gallery-page",
					title: _("ms2gallery"),
					record: {
						id: ' . $resource->get('id') . ',
						source: ' . $source_id . ',
					}
				});
			';
            if ($this->modx->getCount('modPlugin', array('name' => 'AjaxManager', 'disabled' => false))) {
                $controller->addHtml('
				<script type="text/javascript">
					Ext.onReady(function() {
						window.setTimeout(function() {
							var tabs = Ext.getCmp("modx-resource-tabs");
							if (tabs) {
								' . $insert . '
							}
						}, 10);
					});
				</script>');
            } else {
                $controller->addHtml('
				<script type="text/javascript">
					Ext.ComponentMgr.onAvailable("modx-resource-tabs", function() {
						var tabs = this;
						tabs.on("beforerender", function() {
							' . $insert . '
						});
					});
				</script>');
            }
        }
    }
 /**
  * Updates the Context of all Children recursively to that of the parent.
  *
  * @static
  * @param modX &$modx A reference to an initialized modX instance.
  * @param modResource $parent The parent modResource instance.
  * @param array $options An array of options.
  * @return int The number of children updated.
  */
 public static function updateContextOfChildren(modX &$modx, $parent, array $options = array())
 {
     $count = 0;
     /** @var modResource $child */
     foreach ($parent->getIterator('Children') as $child) {
         $child->set('context_key', $parent->get('context_key'));
         if ($child->save()) {
             $count++;
         } else {
             $modx->log(modX::LOG_LEVEL_ERROR, "Could not change Context of child resource {$child->get('id')}", '', __METHOD__, __FILE__, __LINE__);
         }
     }
     return $count;
 }
 public function get($key)
 {
     global $modx;
     $orig = parent::get($key);
     $translated = array('pagetitle', 'longtitle', 'description', 'introtext', 'menutitle', 'content');
     if (in_array($key, $translated)) {
         $value = $this->lookForTranslations($key);
         if (!$value) {
             $value = parent::get($key);
         }
     } else {
         $value = parent::get($key);
     }
     return $value;
 }
 /**
  * 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;
 }