Example #1
0
 public function executeFilter(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     /*
      * Deny service, if the system load is too high.
      */
     if (defined('DEBUG') and DEBUG === false) {
         $maxServerLoad = isset(self::$config['load']['max']) ? (double) self::$config['load']['max'] : 80;
         if (\Koch\Functions\Functions::getServerLoad() > $maxServerLoad) {
             $response->addHeader('Retry-After', mt_rand(45, 90));
             $response->setStatusCode('503');
             $response->addContent('HTTP/1.1 503 Server too busy. Please try again later.');
             $response->sendResponse();
         }
     }
     // ensure smarty "tpl_compile" folder exists
     if (false === is_dir(APPLICATION_CACHE_PATH . 'tpl_compile') and false === @mkdir(APPLICATION_CACHE_PATH . 'tpl_compile', 0755, true)) {
         throw new Exception('Smarty Template Directories not existant.', 9);
     }
     // ensure smarty "cache" folder exists
     if (false === is_dir(APPLICATION_CACHE_PATH . 'tpl_cache') and false === @mkdir(APPLICATION_CACHE_PATH . 'tpl_cache', 0755, true)) {
         throw new Exception('Smarty Template Directories not existant.', 9);
     }
     // ensure smarty folders are writable
     if (false === is_writable(APPLICATION_CACHE_PATH . 'tpl_compile') or false === is_writable(APPLICATION_CACHE_PATH . 'tpl_cache')) {
         // if not, try to set writeable permission on the folders
         if (false === chmod(APPLICATION_CACHE_PATH . 'tpl_compile', 0755) and false === chmod(APPLICATION_CACHE_PATH . 'tpl_cache', 0755)) {
             throw new Exception('Smarty Template Directories not writable.', 10);
         }
     }
 }
Example #2
0
 public function executeFilter(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     if (false === $rbacl->isAuthorized($actionname, $this->user->getUserId())) {
         // @todo errorpage, no permission to perform this action. access denied.
         $response->redirect();
     }
 }
Example #3
0
 public function executeFilter(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     /*
      * If the renderer is not smarty, then bypass the filter.
      */
     if ($request->getRoute()->getRenderEngine() !== 'smarty') {
         return;
     }
     /*
      * Get HttpResponse output buffer
      */
     $content = $response->getContent();
     /*
      * This matches the PRE_HEAD_CLOSE tag.
      * The X marks the position: X</head>
      */
     $matches = [];
     $regexp1 = '!@@@SMARTY:PRE_HEAD_CLOSE:BEGIN@@@(.*?)@@@SMARTY:PRE_HEAD_CLOSE:END@@@!is';
     preg_match_all($regexp1, $content, $matches);
     $content = preg_replace($regexp1, '', $content);
     $matches = array_keys(array_flip($matches[1]));
     foreach ($matches as $value) {
         $content = str_replace('</head>', $value . "\n" . '</head>', $content);
     }
     /*
      * This matches the POST_BODY_OPEN tag.
      * The X marks the position: <body>X
      */
     $matches = [];
     $regexp2 = '!@@@SMARTY:POST_BODY_OPEN:BEGIN@@@(.*?)@@@SMARTY:POST_BODY_OPEN:END@@@!is';
     preg_match_all($regexp2, $content, $matches);
     $content = preg_replace($regexp2, '', $content);
     $matches = array_keys(array_flip($matches[1]));
     foreach ($matches as $values) {
         $content = str_replace('<body>', '<body>' . "\n" . $value, $content);
     }
     /*
      * This matches the POST_BODY_OPEN tag.
      * The X marks the position: X</body>
      */
     $matches = [];
     $regexp3 = '!@@@SMARTY:PRE_BODY_CLOSE:BEGIN@@@(.*?)@@@SMARTY:PRE_BODY_CLOSE:END@@@!is';
     preg_match_all($regexp3, $content, $matches);
     $content = preg_replace($regexp3, '', $content);
     $matches = array_keys(array_flip($matches[1]));
     foreach ($matches as $values) {
         $content = str_replace('</body>', $value . "\n" . '</body>', $content);
     }
     /*
      * Replace the http response buffer
      */
     $response->setContent($content, true);
 }
Example #4
0
 public function executeFilter(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     /**
      * maintenance mode must be enabled in configuration
      */
     if ($this->config['maintenance']['maintenance'] == 1) {
         return;
     }
     /**
      * @todo b) create override of maintenance mode, in case it's an admin user?
      */
     // fetch renderer
     $smarty = Koch_Renderer_Factory::getRenderer('smarty', Clansuite_CMS::getInjector());
     // fetch maintenance template
     $html = $smarty->fetch(ROOT_THEMES . 'core/view/smarty/maintenance.tpl', true);
     // output
     $response->setContent($html);
     $response->flush();
     exit;
 }
Example #5
0
File: HtmlTidy.php Project: ksst/kf
 public function executeFilter(HttpRequestInterface $request, HttpResponseInterface $response)
 {
     // htmltidy must be enabled in configuration
     if ($this->config['htmltidy']['enabled'] === 1 and extension_loaded('tidy')) {
         // bypass
         return;
     }
     // get output from response
     $content = $response->getContent();
     // init tidy
     $tidy = new tidy();
     /*
     $tidyoptions = array(
        'indent-spaces'    => 4,
         'wrap'             => 120,
         'indent'           => auto,
         'tidy-mark'        => true,
         'show-body-only'   => true,
         'force-output'     => true,
         'output-xhtml'     => true,
         'clean'            => true,
         'hide-comments'    => false,
         'join-classes'     => false,
         'join-styles'      => false,
         'doctype'          => 'strict',
         'lower-literals'   => true,
         'quote-ampersand'  => true,
         'wrap'             => 0,
         'drop-font-tags'   => true,
         'drop-empty-paras' => true,
         'drop-proprietary-attributes' => true);
     */
     $tidyoptions = ['clean' => true, 'doctype' => 'transitional', 'output-xhtml' => true, 'drop-proprietary-attributes' => true, 'lower-literals' => true, 'show-body-only' => false, 'indent-spaces' => 4, 'wrap' => 130, 'indent' => 'auto'];
     // tidy the output
     $tidy->parseString($content, $tidyoptions, 'utf8');
     $tidy->cleanRepair();
     // @todo diagnose? errorreport?
     // set output to response
     $response->setContent(tidy_get_output($tidy), true);
 }