С версии: 3.0.0
Автор: Henry Ruhs
Пример #1
0
 /**
  * renderTemplate
  *
  * @since 3.0.0
  *
  * @return mixed
  */
 public static function renderTemplate()
 {
     $registry = Registry::getInstance();
     $request = Request::getInstance();
     $language = Language::getInstance();
     /* handle notification */
     if (!is_dir(self::$_configArray['directory']) && !mkdir(self::$_configArray['directory'])) {
         self::setNotification('error', $language->get('directory_not_found') . $language->get('colon') . ' ' . self::$_configArray['directory'] . $language->get('point'));
     }
     /* prevent as needed */
     if ($request->getPost() || $registry->get('noCache')) {
         return false;
     }
     /* cache as needed */
     $cache = new Cache();
     $cache->init(self::$_configArray['directory'], self::$_configArray['extension']);
     $fullRoute = $registry->get('fullRoute');
     /* load from cache */
     if ($cache->validate($fullRoute, self::$_configArray['lifetime'])) {
         $raw = $cache->retrieve($fullRoute);
         $content = preg_replace('/' . self::$_configArray['tokenPlaceholder'] . '/', $registry->get('token'), self::_uncompress($raw));
         return ['header' => function_exists('gzdeflate') ? 'content-encoding: deflate' : null, 'content' => self::_compress($content)];
     } else {
         $raw = Template\Tag::partial('templates/' . $registry->get('template') . '/index.phtml');
         $content = preg_replace('/' . $registry->get('token') . '/', self::$_configArray['tokenPlaceholder'], $raw);
         $cache->store($fullRoute, self::_compress($content));
         return ['content' => $raw];
     }
 }
Пример #2
0
 /**
  * render the view
  *
  * @since 3.0.0
  *
  * @param integer $moduleId identifier of the module
  *
  * @return string
  */
 public function render($moduleId = null)
 {
     $output = Hook::trigger('adminModuleFormStart');
     $module = Db::forTablePrefix('modules')->whereIdIs($moduleId)->findOne();
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h2', ['class' => 'rs-admin-title-content']);
     $titleElement->text($module->name);
     $linkElement = new Html\Element();
     $linkElement->init('a');
     $itemElement = new Html\Element();
     $itemElement->init('li');
     $listElement = new Html\Element();
     $listElement->init('ul', ['class' => 'rs-admin-js-list-tab rs-admin-list-tab']);
     $formElement = new AdminForm($this->_registry, $this->_language);
     $formElement->init(['form' => ['action' => $this->_registry->get('parameterRoute') . ($module->id ? 'admin/process/modules/' . $module->id : 'admin/process/modules'), 'class' => 'rs-admin-js-tab rs-admin-js-validate-form rs-admin-component-tab rs-admin-form-default rs-admin-fn-clearfix'], 'link' => ['cancel' => ['href' => $this->_registry->get('modulesEdit') && $this->_registry->get('modulesUninstall') ? $this->_registry->get('parameterRoute') . 'admin/view/modules' : $this->_registry->get('parameterRoute') . 'admin'], 'uninstall' => ['href' => $module->alias ? $this->_registry->get('parameterRoute') . 'admin/uninstall/modules/' . $module->alias . '/' . $this->_registry->get('token') : null]]]);
     /* docs directory */
     $docsDirectory = new Directory();
     $docsDirectory->init('modules/' . $module->alias . '/docs');
     $docsDirectoryArray = $docsDirectory->getArray();
     /* collect item output */
     $tabCounter = 1;
     $tabRoute = $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute');
     $outputItem = $itemElement->copy()->addClass('rs-admin-js-item-active rs-admin-item-active')->html($linkElement->copy()->attr('href', $tabRoute . '#tab-' . $tabCounter++)->text($this->_language->get('module')));
     /* process directory */
     foreach ($docsDirectoryArray as $value) {
         $outputItem .= $itemElement->copy()->html($linkElement->copy()->attr('href', $tabRoute . '#tab-' . $tabCounter++)->text(pathinfo($value, PATHINFO_FILENAME)));
     }
     /* collect item output */
     $outputItem .= $itemElement->copy()->html($linkElement->copy()->attr('href', $tabRoute . '#tab-' . $tabCounter++)->text($this->_language->get('customize')));
     $listElement->append($outputItem);
     /* create the form */
     $tabCounter = 1;
     $formElement->append($listElement)->append('<div class="rs-admin-js-box-tab rs-admin-box-tab rs-admin-box-tab">')->append('<fieldset id="tab-' . $tabCounter++ . '" class="rs-admin-js-set-tab rs-admin-js-set-active rs-admin-set-tab rs-admin-set-active"><ul><li>')->label($this->_language->get('name'), ['for' => 'name'])->text(['autofocus' => 'autofocus', 'id' => 'name', 'name' => 'name', 'required' => 'required', 'value' => $module->name])->append('</li><li>')->label($this->_language->get('description'), ['for' => 'description'])->textarea(['class' => 'rs-admin-js-auto-resize rs-admin-field-textarea rs-admin-field-small', 'id' => 'description', 'name' => 'description', 'rows' => 1, 'value' => $module->description])->append('</li></ul></fieldset>');
     /* second tab */
     if ($docsDirectoryArray) {
         /* process directory */
         foreach ($docsDirectoryArray as $value) {
             $formElement->append('<fieldset id="tab-' . $tabCounter++ . '" class="rs-admin-js-set-tab rs-admin-set-tab">')->append(Template\Tag::partial('modules/' . $module->alias . '/docs/' . $value))->append('</fieldset>');
         }
     }
     /* last tab */
     $formElement->append('<fieldset id="tab-' . $tabCounter++ . '" class="rs-admin-js-set-tab rs-admin-set-tab"><ul><li>')->label($this->_language->get('status'), ['for' => 'status'])->select(Helper\Option::getToggleArray(), ['id' => 'status', 'name' => 'status', 'value' => intval($module->status)])->append('</li>');
     if ($this->_registry->get('groupsEdit')) {
         $formElement->append('<li>')->label($this->_language->get('access'), ['for' => 'access'])->select(Helper\Option::getAccessArray('groups'), ['id' => 'access', 'name' => 'access[]', 'multiple' => 'multiple', 'size' => count(Helper\Option::getAccessArray('groups')), 'value' => $module->access])->append('</li>');
     }
     $formElement->append('</ul></fieldset></div>')->token()->cancel();
     if ($this->_registry->get('modulesUninstall')) {
         $formElement->uninstall();
     }
     if ($this->_registry->get('modulesEdit')) {
         $formElement->save();
     }
     /* collect output */
     $output .= $titleElement . $formElement;
     $output .= Hook::trigger('adminModuleFormEnd');
     return $output;
 }
Пример #3
0
 /**
  * testExtraRaw
  *
  * @since 3.0.0
  */
 public function testExtraRaw()
 {
     /* actual */
     $actual = Template\Tag::extraRaw();
     /* compare */
     $this->assertInstanceOf('Redaxscript\\Db', $actual);
 }
Пример #4
0
 /**
  * render
  *
  * @since 3.0.0
  *
  * @param string $alias
  * @param string $path
  *
  * @return string
  */
 public static function render($alias = null, $path = null)
 {
     $titleElement = new Html\Element();
     $titleElement->init('h2', ['class' => 'rs-title-preview', 'id' => $alias]);
     $linkElement = new Html\Element();
     $linkElement->init('a', ['href' => Registry::get('secondParameter') === $alias ? Registry::get('parameterRoute') . 'preview#' . $alias : Registry::get('parameterRoute') . 'preview/' . $alias])->text(Registry::get('secondParameter') === $alias ? Language::get('back') : $alias);
     /* collect output */
     $output = $titleElement->html($linkElement);
     $output .= Template\Tag::partial($path);
     return $output;
 }