/** * 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; }
/** * Friendly URL alias checks * @return mixed|string */ public function checkFriendlyAlias() { $this->isSiteStart = $this->object->get('id') == $this->workingContext->getOption('site_start') || $this->object->get('id') == $this->modx->getOption('site_start'); $pageTitle = $this->getProperty('pagetitle', null); $alias = $this->getProperty('alias'); if ($this->workingContext->getOption('friendly_urls', false) && (!$this->getProperty('reloadOnly', false) || (!empty($pageTitle) || $this->isSiteStart))) { /* auto assign alias */ if (empty($alias) && ($this->isSiteStart || $this->workingContext->getOption('automatic_alias', false))) { if (empty($pageTitle)) { $alias = 'index'; } else { $alias = $this->object->cleanAlias($pageTitle); } } if (empty($alias)) { $this->addFieldError('alias', $this->modx->lexicon('field_required')); } /* check for duplicate alias */ $duplicateContext = $this->workingContext->getOption('global_duplicate_uri_check', false) ? '' : $this->getProperty('context_key'); $aliasPath = $this->object->getAliasPath($alias, $this->getProperties()); $duplicateId = $this->object->isDuplicateAlias($aliasPath, $duplicateContext); if (!empty($duplicateId)) { $err = $this->modx->lexicon('duplicate_uri_found', array('id' => $duplicateId, 'uri' => $aliasPath)); $this->addFieldError('uri', $err); $uriOverride = $this->getProperty('uri_override', null); if ($uriOverride == null || $uriOverride !== 1) { $this->addFieldError('alias', $err); } } $this->setProperty('alias', $alias); } return $alias; }
/** * 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; }
/** * 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); }
/** * 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; }
/** * 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); } } }
/** * Friendly URL alias checks * @return mixed|string */ public function checkFriendlyAlias() { // The user submitted alias & page title $alias = $this->getProperty('alias'); $pageTitle = $this->getProperty('pagetitle'); $autoGenerated = false; // If we don't have an alias passed, and automatic_alias is enabled, we generate one from the pagetitle. if (empty($alias) && $this->workingContext->getOption('automatic_alias', false)) { $alias = $this->object->cleanAlias($pageTitle); $autoGenerated = true; } $friendlyUrlsEnabled = $this->workingContext->getOption('friendly_urls', false) && (!$this->getProperty('reloadOnly', false) || !empty($pageTitle)); // Check for duplicates $duplicateContext = $this->workingContext->getOption('global_duplicate_uri_check', false) ? '' : $this->getProperty('context_key'); $aliasPath = $this->object->getAliasPath($alias, $this->getProperties()); $duplicateId = $this->object->isDuplicateAlias($aliasPath, $duplicateContext); // We have a duplicate! if ($duplicateId) { // If friendly urls is enabled, we throw an error about the alias if ($friendlyUrlsEnabled) { $err = $this->modx->lexicon('duplicate_uri_found', array('id' => $duplicateId, 'uri' => $aliasPath)); $this->addFieldError('uri', $err); if ($this->getProperty('uri_override', 0) !== 1) { $this->addFieldError('alias', $err); } } elseif ($autoGenerated) { $alias = ''; } } // If the alias is empty yet friendly urls is enabled, add an error to the alias field if (empty($alias) && $friendlyUrlsEnabled) { $this->addFieldError('alias', $this->modx->lexicon('field_required')); } // Set the new alias and return it, too. $this->setProperty('alias', $alias); return $alias; }
/** * 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; }
/** * 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') : ''); }