/** * Allows for custom templates * * @return array */ public function getTemplateList() { $list = array(); $templateListSnippet = $this->context->getOption('tiny.template_list_snippet', '', $this->properties); if (!empty($templateListSnippet)) { $templateList = $this->modx->runSnippet($templateListSnippet); } else { $templateList = $this->context->getOption('tiny.template_list', '', $this->properties); } if (empty($templateList)) { return $list; } $templateList = explode(',', $templateList); foreach ($templateList as $template) { if (empty($template)) { continue; } $templateParams = explode(':', $template); if (count($templateParams) < 2) { continue; } $t = array($templateParams[0], $templateParams[1]); if (!empty($templateParams[2])) { array_push($t, $templateParams[2]); } $list[] = $t; } return $list; }
/** * Clear the cache if specified * @return boolean */ public function clearCache() { $clear = $this->getProperty('syncsite', false) || $this->getProperty('clearCache', false); if ($clear) { $this->modx->cacheManager->refresh(array('db' => array(), 'auto_publish' => array('contexts' => array($this->workingContext->get('key'))), 'context_settings' => array('contexts' => array($this->workingContext->get('key'))), 'resource' => array('contexts' => array($this->workingContext->get('key'))))); } return $clear; }
/** * @return mixed */ public function onRender() { $this->onContextFormRender = $this->modx->invokeEvent('OnContextFormRender', array('key' => $this->context->get('key'), 'context' => &$this->context, 'mode' => modSystemEvent::MODE_UPD)); if (is_array($this->onContextFormRender)) { $this->onContextFormRender = implode('', $this->onContextFormRender); } $this->onContextFormRender = str_replace(array('"', "\n", "\r"), array('\\"', '', ''), $this->onContextFormRender); return $this->onContextFormRender; }
/** * Grabs a setting value by its key, looking at the current working context (see setWorkingContext) first. * * @param $key * @param null $options * @param null $default * @param bool $skipEmpty * @return mixed */ public function getOption($key, $options = null, $default = null, $skipEmpty = false) { if ($this->wctx) { $value = $this->wctx->getOption($key, $default, $options); if ($skipEmpty && $value == '') { return $default; } else { return $value; } } return $this->modx->getOption($key, $options, $default, $skipEmpty); }
/** * 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)) { $contexts = array($this->object->get('context_key')); if (!empty($this->oldContext)) { $contexts[] = $this->oldContext->get('key'); } $this->modx->cacheManager->refresh(array('db' => array(), 'auto_publish' => array('contexts' => $contexts), 'context_settings' => array('contexts' => $contexts), 'resource' => array('contexts' => $contexts))); } }
/** * Get base URL of file manager * * @return string The base URL */ public function getBaseUrl() { $baseUrl = $this->context->getOption('filemanager_url', $this->context->getOption('rb_base_url', MODX_BASE_URL, $this->config), $this->config); /* expand placeholders */ $baseUrl = str_replace(array('{base_url}', '{core_url}', '{assets_url}'), array($this->context->getOption('base_url', MODX_BASE_PATH, $this->config), $this->context->getOption('core_url', MODX_CORE_PATH, $this->config), $this->context->getOption('assets_url', MODX_ASSETS_PATH, $this->config)), $baseUrl); return !empty($baseUrl) ? $this->postfixSlash($baseUrl) : $baseUrl; }
/** * Cleanup the processor and return the resulting object * * @return array */ public function cleanup() { $this->object->removeLock(); $this->clearCache(); $returnArray = $this->object->get(array_diff(array_keys($this->object->_fields), array('content', 'ta', 'introtext', 'description', 'link_attributes', 'pagetitle', 'longtitle', 'menutitle'))); foreach ($returnArray as $k => $v) { if (strpos($k, 'tv') === 0) { unset($returnArray[$k]); } } $returnArray['class_key'] = $this->object->get('class_key'); $this->workingContext->prepare(true); $returnArray['preview_url'] = $this->modx->makeUrl($this->object->get('id'), '', '', 'full'); return $this->success('', $returnArray); }
/** * Initialize a RichText Editor, if set * * @return void */ public function loadRichTextEditor() { /* register JS scripts */ $rte = isset($this->scriptProperties['which_editor']) ? $this->scriptProperties['which_editor'] : $this->context->getOption('which_editor', '', $this->modx->_userConfig); $this->setPlaceholder('which_editor', $rte); /* Set which RTE if not core */ if ($this->context->getOption('use_editor', false, $this->modx->_userConfig) && !empty($rte)) { /* invoke OnRichTextEditorRegister event */ $textEditors = $this->modx->invokeEvent('OnRichTextEditorRegister'); $this->setPlaceholder('text_editors', $textEditors); $this->rteFields = array('ta'); $this->setPlaceholder('replace_richtexteditor', $this->rteFields); /* invoke OnRichTextEditorInit event */ $resourceId = $this->resource->get('id'); $onRichTextEditorInit = $this->modx->invokeEvent('OnRichTextEditorInit', array('editor' => $rte, 'elements' => $this->rteFields, 'id' => $resourceId, 'resource' => &$this->resource, 'mode' => !empty($resourceId) ? modSystemEvent::MODE_UPD : modSystemEvent::MODE_NEW)); if (is_array($onRichTextEditorInit)) { $onRichTextEditorInit = implode('', $onRichTextEditorInit); $this->setPlaceholder('onRichTextEditorInit', $onRichTextEditorInit); } } }
/** * {@inheritDoc} * @return mixed */ public function afterSave() { $this->setLexiconEntries($this->object->toArray()); $this->modx->reloadConfig(); $key = $this->getProperty('key'); $value = $this->getProperty('value'); $refreshURIs = false; if ($key === 'friendly_urls' && $value == '1') { $refreshURIs = true; } if ($key === 'use_alias_path') { $refreshURIs = true; } if ($key === 'container_suffix') { $refreshURIs = true; } if ($refreshURIs) { $this->context->config[$key] = $value; $this->modx->call('modResource', 'refreshURIs', array(&$this->modx, 0, array('contexts' => $this->context->get('key')))); } return true; }
/** * Prepare a Context for being shown in the tree * * @param modContext $context * @return array */ public function prepareContextNode(modContext $context) { $class = array('tree-pseudoroot-node'); $createRoot = $this->modx->hasPermission('new_document_in_root'); $class[] = !empty($this->permissions['edit_context']) ? $this->permissions['edit_context'] : ''; $class[] = !empty($this->permissions['new_context']) ? $this->permissions['new_context'] : ''; $class[] = !empty($this->permissions['delete_context']) ? $this->permissions['delete_context'] : ''; $class[] = !empty($this->permissions['new_context_document']) && $createRoot ? $this->permissions['new_context_document'] : ''; $class[] = !empty($this->permissions['new_context_symlink']) && $createRoot ? $this->permissions['new_context_symlink'] : ''; $class[] = !empty($this->permissions['new_context_weblink']) && $createRoot ? $this->permissions['new_context_weblink'] : ''; $class[] = !empty($this->permissions['new_context_static_resource']) && $createRoot ? $this->permissions['new_context_static_resource'] : ''; $class[] = !empty($this->permissions['resource_quick_create']) && $createRoot ? $this->permissions['resource_quick_create'] : ''; $context->prepare(); return array('text' => $context->get('name') != '' ? $context->get('name') : $context->get('key'), 'id' => $context->get('key') . '_0', 'pk' => $context->get('key'), 'ctx' => $context->get('key'), 'settings' => array('default_template' => $context->getOption('default_template'), 'richtext_default' => $context->getOption('richtext_default'), 'hidemenu_default' => $context->getOption('hidemenu_default'), 'search_default' => $context->getOption('search_default'), 'cache_default' => $context->getOption('cache_default'), 'publish_default' => $context->getOption('publish_default'), 'default_content_type' => $context->getOption('default_content_type')), 'leaf' => false, 'cls' => implode(' ', $class), 'iconCls' => $this->modx->getOption('mgr_tree_icon_context', null, 'tree-context'), 'qtip' => $context->get('description') != '' ? strip_tags($context->get('description')) : '', 'type' => 'modContext', 'pseudoroot' => true); }
/** * Prepare the source path for phpThumb * * @param string $src * @return string */ public function prepareSrcForThumb($src) { /* dont strip stuff for absolute URLs */ if (substr($src, 0, 4) != 'http') { if (strpos($src, '/') !== 0) { $properties = $this->getPropertyList(); $src = !empty($properties['basePath']) ? $properties['basePath'] . $src : $src; if (!empty($properties['basePathRelative'])) { $src = $this->ctx->getOption('base_path', null, MODX_BASE_PATH) . $src; } } /* strip out double slashes */ $src = str_replace(array('///', '//'), '/', $src); /* check for file existence if local url */ if (strpos($src, '/') !== 0 && empty($src)) { if (file_exists('/' . $src)) { $src = '/' . $src; } else { return ''; } } } return $src; }
/** {@inheritDoc} */ public function prepareContextNode(modContext $context) { $context->prepare(); return array('text' => $context->get('key'), 'id' => $context->get('key') . '_0', 'pk' => $context->get('key'), 'ctx' => $context->get('key'), 'leaf' => false, 'cls' => 'icon-context', 'iconCls' => $this->modx->getOption('mgr_tree_icon_context', null, 'tree-context'), 'qtip' => $context->get('description') != '' ? strip_tags($context->get('description')) : '', 'type' => 'modContext'); }
/** * Prepare a Context for being shown in the tree * * @param modContext $context * @return array */ public function prepareContextNode(modContext $context) { $class = array(); $class[] = 'icon-context'; $class[] = !empty($this->permissions['edit_context']) ? $this->permissions['edit_context'] : ''; $class[] = !empty($this->permissions['new_context']) ? $this->permissions['new_context'] : ''; $class[] = !empty($this->permissions['delete_context']) ? $this->permissions['delete_context'] : ''; $class[] = !empty($this->permissions['new_context_document']) ? $this->permissions['new_context_document'] : ''; $class[] = !empty($this->permissions['new_context_symlink']) ? $this->permissions['new_context_symlink'] : ''; $class[] = !empty($this->permissions['new_context_weblink']) ? $this->permissions['new_context_weblink'] : ''; $class[] = !empty($this->permissions['new_context_static_resource']) ? $this->permissions['new_context_static_resource'] : ''; $class[] = !empty($this->permissions['resource_quick_create']) ? $this->permissions['resource_quick_create'] : ''; $context->prepare(); return array('text' => $context->get('key'), 'id' => $context->get('key') . '_0', 'pk' => $context->get('key'), 'ctx' => $context->get('key'), 'settings' => array('default_template' => $context->getOption('default_template'), 'richtext_default' => $context->getOption('richtext_default'), 'hidemenu_default' => $context->getOption('hidemenu_default'), 'search_default' => $context->getOption('search_default'), 'cache_default' => $context->getOption('cache_default'), 'publish_default' => $context->getOption('publish_default'), 'default_content_type' => $context->getOption('default_content_type')), 'leaf' => false, 'cls' => implode(' ', $class), 'qtip' => $context->get('description') != '' ? strip_tags($context->get('description')) : '', 'type' => 'modContext', 'page' => !$this->getProperty('noHref') ? '?a=' . $this->actions['context/update'] . '&key=' . $context->get('key') : ''); }
/** * Log the manager action of updating this Context * @return void */ public function logManagerAction() { $this->modx->logManagerAction('context_update', 'modContext', $this->context->get('id')); }
/** * @param modContext $context * * @return array */ protected function _prepareContextRow(modContext $context) { $row = $context->toArray('', false, true); $row['type'] = 'context'; if (empty($row['name'])) { $row['name'] = $row['key']; } return $row; }
/** * Clear the context settings cache * @return void */ public function clearCache() { $this->modx->cacheManager->refresh(array('db' => array(), 'context_settings' => array('contexts' => array($this->context->get('key'))), 'resource' => array('contexts' => array($this->context->get('key'))))); }