Ejemplo n.º 1
0
 public function checkRules()
 {
     $DocID = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
     $rules = $this->getOptions("rules", array());
     $flag = empty($rules);
     if (!$flag && $DocID && $this->loadModClass("modResource")) {
         $DOC = new modResource($this->_modx);
         $data = $DOC->edit($DocID)->toArray();
         $flag = true;
         foreach ($rules as $item => $value) {
             switch ($item) {
                 case 'id':
                     if ($DOC->getID() != $value) {
                         $flag = false;
                     }
                     break;
                 default:
                     if (!isset($data[$item]) || $data[$item] != $value) {
                         $flag = false;
                     }
                     break;
             }
         }
     }
     return $flag;
 }
 /**
  * @param \modResource $originalParent
  */
 protected function handleOriginalParent($originalParent)
 {
     $originalGreatParent = $originalParent->Parent;
     if ($originalGreatParent && $originalGreatParent->class_key == 'CollectionContainer' && $originalParent->hasChildren() == 0) {
         $originalParent->set('show_in_tree', 0);
         $originalParent->save();
     }
 }
Ejemplo n.º 3
0
 public function process()
 {
     if (!$this->validate()) {
         return $this->failure();
     }
     $this->resource->fromArray($this->getProperties());
     if ($this->resource->save() === false) {
         return $this->failure($this->modx->lexicon('resource_err_save'));
     }
     return $this->success();
 }
Ejemplo n.º 4
0
 /**
  * @return array|string
  */
 public function process()
 {
     if (!($data = $this->handleFile())) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ns'));
     }
     $properties = $this->mediaSource->getProperties();
     $tmp = explode('.', $data['name']);
     $extension = strtolower(end($tmp));
     $image_extensions = $allowed_extensions = array();
     if (!empty($properties['imageExtensions']['value'])) {
         $image_extensions = array_map('trim', explode(',', strtolower($properties['imageExtensions']['value'])));
     }
     if (!empty($properties['allowedFileTypes']['value'])) {
         $allowed_extensions = array_map('trim', explode(',', strtolower($properties['allowedFileTypes']['value'])));
     }
     if (!empty($allowed_extensions) && !in_array($extension, $allowed_extensions)) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_ext'));
     } else {
         if (in_array($extension, $image_extensions)) {
             $type = 'image';
         } else {
             $type = $extension;
         }
     }
     $hash = sha1($data['stream']);
     if ($this->modx->getCount('msResourceFile', array('resource_id' => $this->resource->id, 'hash' => $hash, 'parent' => 0))) {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_exists'));
     }
     $filename = !empty($properties['imageNameType']) && $properties['imageNameType']['value'] == 'friendly' ? $this->resource->cleanAlias($data['name']) : $hash . '.' . $extension;
     $rank = isset($properties['imageUploadDir']) && empty($properties['imageUploadDir']['value']) ? 0 : $this->modx->getCount('msResourceFile', array('parent' => 0, 'resource_id' => $this->resource->id));
     /* @var msResourceFile $product_file */
     $product_file = $this->modx->newObject('msResourceFile', array('resource_id' => $this->resource->id, 'parent' => 0, 'name' => $data['name'], 'file' => $filename, 'path' => $this->resource->id . '/', 'source' => $this->mediaSource->get('id'), 'type' => $type, 'rank' => $rank, 'createdon' => date('Y-m-d H:i:s'), 'createdby' => $this->modx->user->id, 'active' => 1, 'hash' => $hash, 'properties' => $data['properties']));
     $this->mediaSource->createContainer($product_file->path, '/');
     $file = $this->mediaSource->createObject($product_file->get('path'), $product_file->get('file'), $data['stream']);
     if ($file) {
         $url = $this->mediaSource->getObjectUrl($product_file->get('path') . $product_file->get('file'));
         $product_file->set('url', $url);
         $product_file->save();
         if (empty($rank)) {
             $imagesTable = $this->modx->getTableName('msResourceFile');
             $sql = "UPDATE {$imagesTable} SET rank = rank + 1 WHERE resource_id ='" . $this->resource->id . "' AND id !='" . $product_file->get('id') . "'";
             $this->modx->exec($sql);
         }
         $generate = $product_file->generateThumbnails($this->mediaSource);
         if ($generate !== true) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not generate thumbnails for image with id = ' . $product_file->get('id') . '. ' . $generate);
             return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_thumb'));
         } else {
             return $this->success();
         }
     } else {
         return $this->failure($this->modx->lexicon('ms2gallery_err_gallery_save') . ': ' . print_r($this->mediaSource->getErrors(), 1));
     }
 }
Ejemplo n.º 5
0
 public function beforeSave()
 {
     /** @var modResource $parent */
     $parent = $this->modx->getObject('modResource', $this->object->parent);
     if ($parent && $parent->class_key == 'CollectionContainer') {
         $this->object->set('show_in_tree', 0);
     } else {
         $this->object->set('show_in_tree', 1);
     }
     return parent::beforeSave();
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
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));
     }
 }
 /**
  * @param \modResource $parent
  * @param \modResource $resource
  * @param \modResource $originalParent
  */
 protected function handleOriginalParent($parent, $resource, $originalParent)
 {
     if ($originalParent->class_key == 'CollectionContainer') {
         if ($parent->class_key != 'CollectionContainer') {
             $resource->set('show_in_tree', 1);
         }
     } else {
         /** @var \modResource $originalGreatParent */
         $originalGreatParent = $originalParent->Parent;
         if ($originalGreatParent && $originalGreatParent->class_key == 'CollectionContainer') {
             $resource->set('show_in_tree', 1);
         }
     }
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
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'];
 }
Ejemplo n.º 11
0
function modresource_populate_children(\Teleport\Action\Extract &$extract, modResource &$object, $criteria, $graph, $graphCriteria, $vehicle, &$vehicleCount)
{
    unset($criteria['parent']);
    $children = $object->getMany('Children', null, false);
    if ($children) {
        foreach ($children as &$child) {
            /** @var modResource $child */
            if ($graph !== null) {
                $child->getGraph($graph, $graphCriteria);
            }
            if ($extract->package->put($child, $vehicle['attributes'])) {
                $vehicleCount++;
            }
            modresource_populate_children($extract, $child, $criteria, $graph, $graphCriteria, $vehicle, $vehicleCount);
        }
    }
}
Ejemplo n.º 12
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')))));
     }
 }
Ejemplo n.º 13
0
 /**
  * {@inheritDoc}
  * @return array
  */
 public static function loadCollection(xPDO &$xpdo, $className, $criteria = null, $cacheFlag = true)
 {
     if (!is_object($criteria)) {
         $criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
     }
     $xpdo->addDerivativeCriteria($className, $criteria);
     return parent::loadCollection($xpdo, $className, $criteria, $cacheFlag);
 }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
0
 function get($k, $format = NULL, $formatTemplate = NULL)
 {
     switch ($k) {
         case 'url':
             return $this->makeUrl();
             break;
     }
     return parent::get($k, $format, $formatTemplate);
 }
Ejemplo n.º 17
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;
 }
Ejemplo n.º 18
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;
 }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
0
 /**
  * Override the parent function to get our special properties.
  * @param string $namespace
  * @return array
  */
 public function getProperties($namespace = 'core')
 {
     $properties = parent::getProperties($namespace);
     //$this->xpdo->log(1, print_r($properties,true));
     if (!empty($properties)) {
         return $properties;
     }
     // Properties defaults
     $properties = array('product_type' => 'regular', 'product_template' => $this->xpdo->getOption('moxycart.default_product_template', '', $this->xpdo->getOption('default_template')), 'sort_order' => 'name', 'qty_alert' => 0, 'track_inventory' => 0, 'specs' => array(), 'variations' => array(), 'taxonomies' => array());
     return $properties;
 }
Ejemplo n.º 21
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);
    }
Ejemplo n.º 22
0
 public function getContent(array $options = array())
 {
     $content = '<div class="postBody">' . parent::getContent($options) . '</div>';
     $conversation = $this->class_key . '-' . $this->id;
     $properties = $this->getProperties('modxtalks');
     $properties = array_merge(array('conversation' => $conversation), $properties);
     $out = '';
     foreach ($properties as $key => $property) {
         $out .= "&{$key}=`{$property}`";
     }
     $content .= '[[$chankModxTalksStreak]][[!modxTalks?' . $out . ']]';
     return $content;
 }
    /**
     * @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('modupdater');
        $controller->addLexiconTopic('modupdater:default');
        $controller->addJavascript($jsUrl . 'modupdater.js');
        $controller->addLastJavascript($jsUrl . 'misc/utils.js');
        $controller->addCss($cssUrl . 'main.css');
        if (!$modx23) {
            $controller->addCss($cssUrl . 'font-awesome.min.css');
        }
        $controller->addHtml('
		<script type="text/javascript">
			MODx.modx23 = ' . $modx23 . ';
			modUpdater.config = ' . $this->modx->toJSON($this->config) . ';
			modUpdater.config.resID = ' . $resource->id . ';
            modUpdater.config.connector_url = "' . $this->config['connectorUrl'] . '";
		</script>', true);
        $controller->addLastJavascript($jsUrl . 'widgets/items.windows.js');
    }
Ejemplo n.º 24
0
 private function saveMarkdown()
 {
     $resourceArray = $this->resource->toArray();
     $mode = $this->sp['mode'];
     $deleteUnused = (int) $this->md->getOption('upload.delete_unused', null, 1);
     $underResource = (int) $this->md->getOption('upload.under_resource', null, 1);
     if ($mode == \modSystemEvent::MODE_UPD) {
         if ($deleteUnused && $underResource) {
             $this->uploadedFiles();
         }
     }
     foreach ($resourceArray as $field => $value) {
         if (!strpos($field, '_markdown')) {
             continue;
         }
         $fieldName = str_replace('_markdown', '', $field);
         $markdown = $this->modx->fromJSON($this->resource->getProperty('markdown', 'markdowneditor', '[]'));
         if ($mode == \modSystemEvent::MODE_NEW) {
             if ($underResource) {
                 $this->moveFilesUnderCorrectResource($value, $fieldName);
             }
         }
         if ($mode == \modSystemEvent::MODE_UPD) {
             if ($deleteUnused && $underResource) {
                 $this->unsetUnusedFiles($value);
             }
         }
         $markdown[$fieldName] = $value;
         $this->resource->setProperty('markdown', $this->modx->toJSON($markdown), 'markdowneditor');
         $this->resource->save();
         $this->resource->{$field} = '';
     }
     if ($mode == \modSystemEvent::MODE_UPD) {
         if ($deleteUnused && $underResource) {
             $this->deleteUnusedFiles();
         }
     }
 }
 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();
 }
 function process()
 {
     $this->_content = '';
     $this->_output = '';
     $this->xpdo->getParser();
     /** @var modTemplate $baseElement */
     if ($baseElement = $this->getOne('Template') and $baseElement->process()) {
         $this->_content = $baseElement->_output;
         $this->_processed = true;
     } else {
         return parent::process();
     }
     return $this->_content;
 }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
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;
 }
Ejemplo n.º 29
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;
 }
Ejemplo n.º 30
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);
 }