Since: 2.0.0
Author: Henry Ruhs
Author: Gary Aylward
示例#1
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;
 }
 /**
  * render
  *
  * @since 2.6.0
  *
  * @param string $directory
  * @param array $options
  *
  * @return string
  */
 public static function render($directory = null, $options = null)
 {
     $output = null;
     $outputItem = null;
     /* html elements */
     $imageElement = new Html\Element();
     $imageElement->init('img', array('class' => self::$_config['className']['image']));
     $linkElement = new Html\Element();
     $linkElement->init('a');
     $listElement = new Html\Element();
     $listElement->init('ul', array('class' => self::$_config['className']['list']));
     /* gallery directory */
     $galleryDirectory = new Directory();
     $galleryDirectory->init($directory, self::$_config['thumbDirectory']);
     $galleryDirectoryArray = $galleryDirectory->getArray();
     /* adjust order */
     if ($options['order'] === 'desc') {
         $galleryDirectoryArray = array_reverse($galleryDirectoryArray);
     }
     /* gallery data */
     $galleryCounter = 0;
     $galleryTotal = count($galleryDirectoryArray);
     $galleryId = uniqid('gallery-');
     /* remove thumbs */
     if ($options['command'] === 'remove' || !$galleryTotal) {
         $galleryDirectory->remove(self::$_config['thumbDirectory']);
     } else {
         /* process directory */
         foreach ($galleryDirectoryArray as $key => $value) {
             $imagePath = $directory . '/' . $value;
             $thumbPath = $directory . '/' . self::$_config['thumbDirectory'] . '/' . $value;
             /* create thumbs */
             if ($options['command'] === 'create' || !is_file($thumbPath)) {
                 self::_createThumb($value, $directory, $options);
             }
             /* image data */
             $imageData = self::_getImageData($imagePath);
             /* collect item output */
             $outputItem .= '<li>';
             $outputItem .= $linkElement->copy()->attr(array('href' => $imagePath, 'data-counter' => ++$galleryCounter, 'data-total' => $galleryTotal, 'data-id' => $galleryId, 'data-artist' => array_key_exists('artist', $imageData) ? $imageData['artist'] : null, 'data-date' => array_key_exists('date', $imageData) ? $imageData['date'] : null, 'data-description' => array_key_exists('description', $imageData) ? $imageData['description'] : null))->html($imageElement->copy()->attr(array('src' => $thumbPath, 'alt' => array_key_exists('description', $imageData) ? $imageData['description'] : null)));
             $outputItem .= '</li>';
         }
         $output = $listElement->attr('id', $galleryId)->html($outputItem);
     }
     return $output;
 }
示例#3
0
 /**
  * centerStart
  *
  * @since 2.2.0
  */
 public static function centerStart()
 {
     if (Registry::get('firstParameter') === 'preview') {
         $partialsPath = 'modules/preview/partials/';
         $partialsDirectory = new Directory($partialsPath);
         $partialsDirectoryArray = $partialsDirectory->get();
         /* collect partial output */
         $output = '<div class="preview clearfix">' . PHP_EOL;
         /* include as needed */
         if (Registry::get('secondParameter')) {
             $output .= self::_render(Registry::get('secondParameter'), $partialsPath . Registry::get('secondParameter') . '.phtml');
         } else {
             foreach ($partialsDirectoryArray as $partial) {
                 $output .= self::_render(str_replace('.phtml', '', $partial), $partialsPath . $partial);
             }
         }
         $output .= '</div>' . PHP_EOL;
         echo $output;
     }
 }
 /**
  * centerStart
  *
  * @since 2.2.0
  */
 public static function centerStart()
 {
     if (Registry::get('firstParameter') === 'preview') {
         $partialsPath = 'modules/Preview/partials';
         $partialExtension = '.phtml';
         $partialsDirectory = new Directory();
         $partialsDirectory->init($partialsPath);
         $partialsDirectoryArray = $partialsDirectory->getArray();
         $secondParameter = Registry::get('secondParameter');
         /* collect partial output */
         $output = '<div class="preview clearfix">';
         /* include as needed */
         if ($secondParameter) {
             $output .= self::render($secondParameter, $partialsPath . '/' . $secondParameter . $partialExtension);
         } else {
             foreach ($partialsDirectoryArray as $partial) {
                 $alias = str_replace($partialExtension, '', $partial);
                 $output .= self::render($alias, $partialsPath . '/' . $partial);
             }
         }
         $output .= '</div>';
         echo $output;
     }
 }
 /**
  * testRemove
  *
  * @since 2.1.0
  *
  * @param array $path
  * @param array $expect
  *
  * @dataProvider providerRemove
  */
 public function testRemove($path = array(), $expect = array())
 {
     /* setup */
     $directory = new Directory();
     $directory->init(Stream::url($path[1]));
     $directory->remove($path[0]);
     /* actual */
     $actual = scandir(Stream::url($path[2]));
     /* compare */
     $this->assertEquals($expect, $actual);
 }
 /**
  * render
  *
  * @since 2.6.0
  *
  * @param string $directory
  * @param array $options
  *
  * @return string
  */
 public static function render($directory = null, $options = null)
 {
     $output = null;
     $outputDirectory = null;
     $outputFile = null;
     /* hash option */
     if ($options['hash']) {
         $hashString = '#' . $options['hash'];
     }
     /* handle query */
     $directoryQuery = Request::getQuery('d');
     if ($directoryQuery && $directory !== $directoryQuery) {
         $pathFilter = new Filter\Path();
         $directory = $pathFilter->sanitize($directoryQuery);
         $parentDirectory = $pathFilter->sanitize(dirname($directory));
     }
     /* has directory */
     if (is_dir($directory)) {
         /* html elements */
         $linkElement = new Html\Element();
         $linkElement->init('a', array('class' => self::$_config['className']['link']));
         $textSizeElement = new Html\Element();
         $textSizeElement->init('span', array('class' => self::$_config['className']['textSize']));
         $textDateElement = new Html\Element();
         $textDateElement->init('span', array('class' => self::$_config['className']['textDate']));
         $listElement = new Html\Element();
         $listElement->init('ul', array('class' => self::$_config['className']['list']));
         /* list directory object */
         $listDirectory = new Directory();
         $listDirectory->init($directory);
         $listDirectoryArray = $listDirectory->getArray();
         /* date format */
         $dateFormat = Db::getSettings('date');
         /* parent directory */
         if (is_dir($parentDirectory)) {
             $outputDirectory .= '<li>';
             $outputDirectory .= $linkElement->copy()->attr(array('href' => Registry::get('rewriteRoute') . Registry::get('fullRoute') . '&d=' . $parentDirectory . $hashString, 'title' => Language::get('directory_parent', '_directory_lister')))->addClass(self::$_config['className']['types']['directoryParent'])->text(Language::get('directory_parent', '_directory_lister'));
             $outputDirectory .= '</li>';
         }
         /* process directory */
         foreach ($listDirectoryArray as $key => $value) {
             $path = $directory . '/' . $value;
             $fileExtension = pathinfo($path, PATHINFO_EXTENSION);
             $text = $value;
             /* replace option */
             if ($options['replace']) {
                 foreach ($options['replace'] as $replaceKey => $replaceValue) {
                     if ($replaceKey === self::$_config['replaceKey']['extension']) {
                         $replaceKey = $fileExtension;
                     }
                     $text = str_replace($replaceKey, $replaceValue, $text);
                 }
             }
             /* handle directory */
             if (is_dir($path)) {
                 $outputDirectory .= '<li>';
                 $outputDirectory .= $linkElement->copy()->attr(array('href' => Registry::get('rewriteRoute') . Registry::get('fullRoute') . '&d=' . $path . $hashString, 'title' => Language::get('directory', '_directory_lister')))->addClass(self::$_config['className']['types']['directory'])->text($text);
                 $outputDirectory .= $textSizeElement->copy();
                 $outputDirectory .= $textDateElement->copy()->text(date($dateFormat, filectime($path)));
                 $outputDirectory .= '</li>';
             } else {
                 if (is_file($path)) {
                     if (array_key_exists($fileExtension, self::$_config['extension'])) {
                         $fileType = self::$_config['extension'][$fileExtension];
                         $outputFile .= '<li>';
                         $outputFile .= $linkElement->copy()->attr(array('href' => $path, 'target' => '_blank', 'title' => Language::get('file', '_directory_lister')))->addClass(self::$_config['className']['types'][$fileType])->text($text);
                         $outputFile .= $textSizeElement->copy()->attr('data-unit', self::$_config['size']['unit'])->html(ceil(filesize($path) / self::$_config['size']['divider']));
                         $outputFile .= $textDateElement->copy()->html(date($dateFormat, filectime($path)));
                         $outputFile .= '</li>';
                     }
                 }
             }
         }
         /* collect list output */
         if ($outputDirectory || $outputFile) {
             $output = $listElement->html($outputDirectory . $outputFile);
         }
     }
     return $output;
 }
示例#7
0
 /**
  * testClear
  *
  * @since 3.0.0
  */
 public function testClear()
 {
     /* setup */
     $directory = new Directory();
     $directory->init(Stream::url('root'));
     $directory->clear();
     /* expect and actual */
     $expectArray = ['.', '..'];
     $actualArray = scandir(Stream::url('root'));
     /* compare */
     $this->assertEquals($expectArray, $actualArray);
 }
 /**
  * renderItem
  *
  * @param string $directory
  * @param array $optionArray
  *
  * @return string
  */
 protected static function _renderItem($directory = null, $optionArray = [])
 {
     $outputItem = null;
     /* html elements */
     $linkElement = new Html\Element();
     $linkElement->init('a', ['class' => self::$_configArray['className']['link']]);
     $textSizeElement = new Html\Element();
     $textSizeElement->init('span', ['class' => self::$_configArray['className']['textSize']]);
     $textDateElement = new Html\Element();
     $textDateElement->init('span', ['class' => self::$_configArray['className']['textDate']]);
     /* lister directory */
     $listerDirectory = new Directory();
     $listerDirectory->init($directory);
     $listerDirectoryArray = $listerDirectory->getArray();
     /* process directory */
     foreach ($listerDirectoryArray as $value) {
         $path = $directory . '/' . $value;
         $fileExtension = pathinfo($path, PATHINFO_EXTENSION);
         $text = self::_replace($value, $fileExtension, $optionArray['replace']);
         $textDate = date(Db::getSetting('date'), filectime($path));
         $isDir = is_dir($path);
         $isFile = is_file($path) && array_key_exists($fileExtension, self::$_configArray['extension']);
         /* handle directory */
         if ($isDir || $isFile) {
             $outputItem .= '<li>';
         }
         if ($isDir) {
             $outputItem .= $linkElement->copy()->attr(['href' => Registry::get('parameterRoute') . Registry::get('fullRoute') . '&directory=' . $path . $optionArray['hash'], 'title' => Language::get('directory', '_directory_lister')])->addClass(self::$_configArray['className']['types']['directory'])->text($text);
             $outputItem .= $textSizeElement->copy();
         } else {
             if ($isFile) {
                 $fileType = self::$_configArray['extension'][$fileExtension];
                 $textSize = ceil(filesize($path) / self::$_configArray['size']['divider']);
                 $outputItem .= $linkElement->copy()->attr(['href' => Registry::get('root') . '/' . $path, 'target' => '_blank', 'title' => Language::get('file', '_directory_lister')])->addClass(self::$_configArray['className']['types'][$fileType])->text($text);
                 $outputItem .= $textSizeElement->copy()->attr('data-unit', self::$_configArray['size']['unit'])->text($textSize);
             }
         }
         if ($isDir || $isFile) {
             $outputItem .= $textDateElement->copy()->text($textDate);
             $outputItem .= '</li>';
         }
     }
     return $outputItem;
 }
示例#9
0
 /**
  * get the template array
  *
  * @since 3.0.0
  *
  * @return array
  */
 public static function getTemplateArray()
 {
     $templateDirectory = new Directory();
     $templateDirectory->init('templates', ['admin', 'console', 'install']);
     $templateDirectoryArray = $templateDirectory->getArray();
     /* process directory */
     $templateArray[Language::get('select')] = 'select';
     foreach ($templateDirectoryArray as $value) {
         $templateArray[$value] = $value;
     }
     return $templateArray;
 }
示例#10
0
 /**
  * tearDownAfterClass
  *
  * @since 3.0.0
  */
 public static function tearDownAfterClass()
 {
     $rootDirectory = new Directory();
     $rootDirectory->init('.');
     $rootDirectory->remove('.restore');
 }
示例#11
0
 /**
  * createThumb
  *
  * @since 3.0.0
  *
  * @param string $directory
  * @param array $optionArray
  *
  * @return string
  */
 protected static function _createThumb($directory = null, $optionArray = [])
 {
     /* gallery directory */
     $galleryDirectory = new Directory();
     $galleryDirectory->init($directory, [self::$_configArray['thumbDirectory']]);
     $galleryDirectory->create(self::$_configArray['thumbDirectory']);
     $galleryDirectoryArray = $galleryDirectory->getArray();
     /* process directory */
     if (chmod($directory . '/' . self::$_configArray['thumbDirectory'], 0777)) {
         foreach ($galleryDirectoryArray as $value) {
             $imagePath = $directory . '/' . $value;
             $imageExtension = strtolower(pathinfo($value, PATHINFO_EXTENSION));
             $thumbPath = $directory . '/' . self::$_configArray['thumbDirectory'] . '/' . $value;
             /* switch extension */
             switch ($imageExtension) {
                 case 'gif':
                     $image = imagecreatefromgif($imagePath);
                     break;
                 case 'jpg':
                     $image = imagecreatefromjpeg($imagePath);
                     break;
                 case 'png':
                     $image = imagecreatefrompng($imagePath);
                     break;
                 default:
                     $image = null;
             }
             /* source and dist */
             $sourceArray = self::_calcSource($imagePath);
             $distArray = self::_calcDist($sourceArray, $optionArray);
             /* create thumb files */
             $thumb = imagecreatetruecolor($distArray['width'], $distArray['height']);
             imagecopyresampled($thumb, $image, 0, 0, 0, 0, $distArray['width'], $distArray['height'], $sourceArray['width'], $sourceArray['height']);
             imagejpeg($thumb, $thumbPath, $distArray['quality']);
             /* destroy image */
             imagedestroy($thumb);
             imagedestroy($image);
         }
     } else {
         self::setNotification('error', Language::get('directory_permission_grant') . Language::get('colon') . ' ' . $directory . '/' . self::$_configArray['thumbDirectory'] . Language::get('point'));
     }
 }