Since: 2.2.0
Author: Henry Ruhs
Inheritance: extends Singleton
Exemplo n.º 1
0
 /**
  * render
  *
  * @since 2.6.0
  *
  * @param string $directory
  * @param array $optionArray
  *
  * @return string
  */
 public static function render($directory = null, $optionArray = [])
 {
     $output = null;
     $outputItem = null;
     /* html elements */
     $listElement = new Html\Element();
     $listElement->init('ul', ['class' => self::$_configArray['className']['list']]);
     /* handle option */
     if ($optionArray['hash']) {
         $optionArray['hash'] = '#' . $optionArray['hash'];
     }
     /* handle query */
     $directoryQuery = Request::getQuery('directory');
     $directoryQueryArray = explode('/', $directoryQuery);
     /* parent directory */
     if ($directoryQueryArray[0] === $directory && $directory !== $directoryQuery) {
         $pathFilter = new Filter\Path();
         $rootDirectory = $directory;
         $directory = $pathFilter->sanitize($directoryQuery);
         $parentDirectory = $pathFilter->sanitize(dirname($directory));
         $outputItem .= self::_renderParent($rootDirectory, $parentDirectory, $optionArray);
     }
     /* has directory */
     if (is_dir($directory)) {
         $outputItem .= self::_renderItem($directory, $optionArray);
         /* collect list output */
         if ($outputItem) {
             $output = $listElement->html($outputItem);
         }
     } else {
         self::setNotification('error', Language::get('directory_not_found') . Language::get('colon') . ' ' . $directory . Language::get('point'));
     }
     return $output;
 }
Exemplo n.º 2
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];
     }
 }
Exemplo n.º 3
0
 /**
  * setUp
  *
  * @since 3.0.0
  */
 public function setUp()
 {
     $this->_registry = Registry::getInstance();
     $this->_request = Request::getInstance();
     $this->_config = Config::getInstance();
     $this->_configArray = $this->_config->get();
 }
Exemplo n.º 4
0
 /**
  * setUp
  *
  * @since 3.0.0
  */
 public function setUp()
 {
     $this->_registry = Registry::getInstance();
     $this->_language = Language::getInstance();
     $this->_request = Request::getInstance();
     $this->_config = Config::getInstance();
     $this->_configArray = $this->_config->get();
     $this->_config->set('dbPrefix', 'controller_');
 }
Exemplo n.º 5
0
 /**
  * upload
  *
  * @since 3.0.0
  */
 protected static function _upload()
 {
     $filesArray = current(Request::getFiles());
     /* upload file */
     if (is_uploaded_file($filesArray['tmp_name'])) {
         if (move_uploaded_file($filesArray['tmp_name'], self::$_configArray['uploadDirectory'] . '/' . $filesArray['name'])) {
             return json_encode(['location' => self::$_configArray['uploadDirectory'] . '/' . $filesArray['name']]);
         }
     }
     header('http/1.0 404 not found');
 }
 /**
  * log
  *
  * @since 2.2.0
  *
  * @return array
  */
 protected static function _log()
 {
     $root = Registry::get('root');
     $fullRoute = Registry::get('fullRoute');
     $recentView = Request::getSession($root . '/recent_view');
     /* handle recent view */
     if ($fullRoute && current($recentView) !== $fullRoute) {
         if (!is_array($recentView)) {
             $recentView = array();
         }
         array_unshift($recentView, $fullRoute);
         Request::setSession($root . '/recent_view', $recentView);
     }
     $output = $recentView;
     return $output;
 }
Exemplo n.º 7
0
 /**
  * detect the required asset
  *
  * @since 2.0.0
  *
  * @param array $setup array of detector setup
  * @param string $type type of the asset
  * @param string $path path to the required file
  */
 protected function _detect($setup = array(), $type = null, $path = null)
 {
     foreach ($setup as $key => $value) {
         if (isset($value)) {
             $file = str_replace('{value}', $value, $path);
             /* if file exists */
             if (file_exists($file)) {
                 $this->_output = $value;
                 /* store query to session */
                 if ($key === 'query') {
                     $root = $this->_registry->get('root');
                     Request::setSession($root . '/' . $type, $value);
                 }
                 break;
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * login
  *
  * @since 2.2.0
  */
 protected static function _login()
 {
     $root = Registry::get('root');
     $token = Registry::get('token');
     /* session values */
     Request::setSession($root . '/logged_in', $token);
     Request::setSession($root . '/my_name', 'Anonymous');
     Request::setSession($root . '/my_user', 'demo');
     Request::setSession($root . '/my_email', '*****@*****.**');
     Request::setSession($root . '/categories_new', 1);
     Request::setSession($root . '/categories_edit', 1);
     Request::setSession($root . '/articles_new', 1);
     Request::setSession($root . '/articles_edit', 1);
     Request::setSession($root . '/comments_new', 1);
     Request::setSession($root . '/comments_edit', 1);
     Request::setSession($root . '/settings_edit', 1);
     Request::setSession($root . '/filter', 1);
     /* notification */
     notification(l('welcome'), l('logged_in'), l('continue'), 'admin');
 }
Exemplo n.º 9
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     /* process post */
     $postArray = ['author' => $specialFilter->sanitize(Request::getPost('author')), 'email' => $emailFilter->sanitize(Request::getPost('email')), 'url' => $urlFilter->sanitize(Request::getPost('url')), 'text' => nl2br($htmlFilter->sanitize(Request::getPost('text'))), 'task' => Request::getPost('task'), 'solution' => Request::getPost('solution')];
     /* handle error */
     $messageArray = self::_validate($postArray);
     if ($messageArray) {
         return self::_error(['message' => $messageArray]);
     }
     /* handle success */
     $mailArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text']];
     /* mail */
     if (self::_mail($mailArray)) {
         return self::_success();
     }
     return self::_error(['message' => Language::get('something_wrong')]);
 }
Exemplo n.º 10
0
 /**
  * process
  *
  * @since 2.6.0
  */
 public static function _process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     $emailValidator = new Validator\Email();
     $urlValidator = new Validator\Url();
     $captchaValidator = new Validator\Captcha();
     /* process post */
     $postData = array('author' => $specialFilter->sanitize(Request::getPost('author')), 'email' => $emailFilter->sanitize(Request::getPost('email')), 'url' => $urlFilter->sanitize(Request::getPost('url')), 'text' => nl2br($htmlFilter->sanitize(Request::getPost('text'))), 'task' => Request::getPost('task'), 'solution' => Request::getPost('solution'));
     /* validate post */
     if (!$postData['author']) {
         $errorData['author'] = Language::get('author_empty');
     }
     if (!$postData['email']) {
         $errorData['email'] = Language::get('email_empty');
     } else {
         if ($emailValidator->validate($postData['email']) === Validator\ValidatorInterface::FAILED) {
             $errorData['email'] = Language::get('email_incorrect');
         }
     }
     if ($errorData['url'] && $urlValidator->validate($postData['url']) === Validator\ValidatorInterface::FAILED) {
         $errorData['url'] = Language::get('url_incorrect');
     }
     if (!$postData['text']) {
         $errorData['text'] = Language::get('message_empty');
     }
     if ($captchaValidator->validate($postData['task'], $postData['solution']) === Validator\ValidatorInterface::FAILED) {
         $errorData['captcha'] = Language::get('captcha_incorrect');
     }
     /* handle error */
     if ($errorData) {
         notification(Language::get('error_occurred'), $errorData, Language::get('home'), Registry::get('root'));
     } else {
         notification(Language::get('operation_completed'), Language::get('message_sent', '_contact'), Language::get('home'), Registry::get('root'));
         self::_send($postData);
     }
 }
Exemplo n.º 11
0
 /**
  * login
  *
  * @since 2.4.0
  */
 protected static function _login()
 {
     $root = Registry::get('root');
     $token = Registry::get('token');
     $tableArray = array('categories', 'articles', 'extras', 'comments', 'groups', 'users');
     /* session values */
     Request::setSession($root . '/logged_in', $token);
     Request::setSession($root . '/my_name', 'Demo');
     Request::setSession($root . '/my_user', 'demo');
     Request::setSession($root . '/my_email', 'demo@localhost');
     foreach ($tableArray as $value) {
         Request::setSession($root . '/' . $value . '_new', 1);
         Request::setSession($root . '/' . $value . '_edit', 1);
         Request::setSession($root . '/' . $value . '_delete', 1);
     }
     Request::setSession($root . '/modules_install', 0);
     Request::setSession($root . '/modules_edit', 0);
     Request::setSession($root . '/modules_uninstall', 0);
     Request::setSession($root . '/settings_edit', 1);
     Request::setSession($root . '/filter', 1);
     /* notification */
     notification(Language::get('welcome'), Language::get('logged_in'), Language::get('continue'), 'admin');
 }
Exemplo n.º 12
0
 /**
  * render
  *
  * @since 2.3.0
  *
  * @param string $table
  *
  * @return string
  */
 public static function render($table = 'articles')
 {
     $output = '';
     /* fetch result */
     $result = Db::forTablePrefix($table)->where('status', 1)->where('access', 0)->where('language', Request::getQuery('l') ? Registry::get('language') : '')->orderGlobal('rank')->limitGlobal()->findArray();
     /* process result */
     if ($result) {
         $route = Registry::get('root') . '/' . Registry::get('rewriteRoute') . Registry::get('fullRoute');
         if (Request::getQuery('l')) {
             $route .= Registry::get('languageRoute') . Registry::get('language');
         }
         $title = Db::getSettings('title');
         $description = Db::getSettings('description');
         $author = Db::getSettings('author');
         $copyright = Db::getSettings('copyright');
         /* collect output */
         $output = '<?xml version="1.0" encoding="' . Db::getSettings('charset') . '"?>';
         $output .= '<feed xmlns="http://www.w3.org/2005/Atom">';
         $output .= '<id>' . $route . '</id>';
         $output .= '<link type="application/atom+xml" href="' . $route . '" rel="self" />';
         $output .= '<updated>' . date('c', strtotime(Registry::get('now'))) . '</updated>';
         /* title */
         if ($title) {
             $output .= '<title>' . $title . '</title>';
         }
         /* description */
         if ($description) {
             $output .= '<subtitle>' . $description . '</subtitle>';
         }
         /* author */
         if ($author) {
             $output .= '<author><name>' . $author . '</name></author>';
         }
         /* copyright */
         if ($copyright) {
             $output .= '<rights>' . $copyright . '</rights>';
         }
         /* generator */
         $output .= '<generator>' . Language::get('name', '_package') . ' ' . Language::get('version', '_package') . '</generator>';
         /* collect body output */
         foreach ($result as $value) {
             $route = Registry::get('root') . '/' . Registry::get('rewriteRoute');
             $route .= $value['category'] < 1 ? $value['alias'] : build_route($table, $value['id']);
             /* collect entry output */
             $output .= '<entry>';
             $output .= '<id>' . $route . '</id>';
             $output .= '<link href="' . $route . '" />';
             $output .= '<updated>' . date('c', strtotime($value['date'])) . '</updated>';
             /* title */
             $output .= '<title>' . ($table === 'comments' ? $value['author'] : $value['title']) . '</title>';
             /* description */
             if ($value['description']) {
                 $output .= '<summary>' . $value['description'] . '</summary>';
             }
             /* text */
             $output .= '<content>' . strip_tags($value['text']) . '</content>';
             /* author */
             if ($value['author']) {
                 $output .= '<author><name>' . $value['author'] . '</name></author>';
             }
             $output .= '</entry>';
         }
         $output .= '</feed>';
     }
     return $output;
 }
Exemplo n.º 13
0
 /**
  * console line
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function consoleLine()
 {
     $console = new Console\Console(Registry::getInstance(), Request::getInstance(), Config::getInstance());
     $output = $console->init('template');
     if (is_string($output)) {
         return htmlentities($output);
     }
 }
Exemplo n.º 14
0
 /**
  * setUp
  *
  * @since 2.6.0
  */
 public function setUp()
 {
     $this->_registry = Registry::getInstance();
     $this->_language = Language::getInstance();
     $this->_request = Request::getInstance();
 }
Exemplo n.º 15
0
 /**
  * setUp
  *
  * @since 2.4.0
  */
 public function setUp()
 {
     $this->_request = Request::getInstance();
 }
 /**
  * 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;
 }
Exemplo n.º 17
0
 /**
  * init the class
  *
  * @since 2.1.0
  */
 public function init()
 {
     $this->_detect(array('query' => Request::getQuery('l'), 'session' => Request::getSession($this->_registry->get('root') . '/language'), 'contents' => $this->_registry->get('lastTable') ? Db::forPrefixTable($this->_registry->get('lastTable'))->where('id', $this->_registry->get('lastId'))->findOne()->language : null, 'settings' => Db::getSettings('language'), 'browser' => substr(Request::getServer('HTTP_ACCEPT_LANGUAGE'), 0, 2), 'fallback' => 'en'), 'language', 'languages/{value}.json');
 }
 /**
  * setUp
  *
  * @since 2.4.0
  */
 protected function setUp()
 {
     $this->_request = Request::getInstance();
     $this->_request->init();
 }
Exemplo n.º 19
0
 /**
  * init the class
  *
  * @since 2.1.0
  */
 public function init()
 {
     $this->_detect(array('query' => Request::getQuery('t'), 'session' => Request::getSession($this->_registry->get('root') . '/template'), 'contents' => $this->_registry->get('lastTable') ? Db::forPrefixTable($this->_registry->get('lastTable'))->where('id', $this->_registry->get('lastId'))->findOne()->template : null, 'settings' => Db::getSettings('template'), 'fallback' => 'default'), 'template', 'templates/{value}/index.phtml');
 }
Exemplo n.º 20
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public static function process()
 {
     $auth = new Auth(Request::getInstance());
     $tableArray = ['categories', 'articles', 'extras', 'comments', 'groups', 'users'];
     /* set user */
     $auth->setUser('name', 'Demo');
     $auth->setUser('user', 'demo');
     $auth->setUser('email', 'demo@localhost');
     /* set permission */
     foreach ($tableArray as $value) {
         $auth->setPermission($value, [1, 2, 3]);
     }
     $auth->setPermission('settings', [1]);
     /* save user and permission */
     $auth->save();
     /* handle success */
     if ($auth->getStatus()) {
         return self::_success();
     }
     return self::_error();
 }
 /**
  * setUp
  *
  * @since 2.4.0
  */
 protected function setUp()
 {
     $this->_request = Request::getInstance();
     $this->_request->init();
     $this->_request->set('server', array('HTTP_HOST' => 'localhost', 'HTTPS' => 'off', 'SCRIPT_NAME' => '/tests/includes/Server/ServerTest.php'));
 }
Exemplo n.º 22
0
 /**
  * testCookie
  *
  * @since 2.2.0
  */
 public function testCookie()
 {
     /* setup */
     Request::setCookie('testKey', 'testValue');
     /* result */
     $result = Request::getCookie('testKey');
     /* compare */
     $this->assertEquals('testValue', $result);
 }
Exemplo n.º 23
0
 /**
  * setUp
  *
  * @since 2.4.0
  */
 public function setUp()
 {
     $this->_request = Request::getInstance();
     $this->_request->set('server', ['HTTP_HOST' => 'localhost', 'HTTPS' => 'off', 'SCRIPT_NAME' => '/tests/includes/Server/ServerTest.php']);
 }
Exemplo n.º 24
0
 /**
  * setUp
  *
  * @since 2.1.0
  */
 protected function setUp()
 {
     $this->_registry = Registry::getInstance();
     $this->_request = Request::getInstance();
 }
Exemplo n.º 25
0
 /**
  * testDetectorTemplate
  *
  * @since 2.2.0
  */
 public function testDetectorQuery()
 {
     /* setup */
     Request::setQuery('l', 'en');
     Request::setQuery('t', 'default');
     $this->_registry->init();
     $detectorLanguage = new Detector\Language($this->_registry);
     $detectorTemplate = new Detector\Template($this->_registry);
     /* result */
     $resultLanguage = $detectorLanguage->getOutput();
     $resultTemplate = $detectorTemplate->getOutput();
     /* compare */
     $this->assertEquals('en', $resultLanguage);
     $this->assertEquals('default', $resultTemplate);
 }