Пример #1
0
 /**
  * loadModul
  *
  * - constructs classname
  * - constructs absolute filename
  * - hands both to requireFile, returns true if successfull
  *
  * The classname for modules is prefixed 'module_' . $modname
  * The filename is 'clansuite/modules/'. $modname .'.module.php'
  *
  * String Variants to consider:
  * 1) admin
  * 2) module_admin
  * 3) module_admin_menueditor
  *
  * @param  string  $modulename The name of the module, which should be loaded.
  * @return boolean
  */
 public static function loadModul($modulename)
 {
     $modulename = mb_strtolower($modulename);
     // apply classname prefix to the modulename
     $modulename = \Koch\Functions::ensurePrefixedWith($modulename, 'clansuite_module_');
     // build classname from modulename
     $classname = \Koch\Functions::toUnderscoredUpperCamelCase($modulename);
     /**
      * now we have a common string like 'clansuite_module_admin_menu' or 'clansuite_module_news'
      * which we split at underscore, via explode, resulting in an array
      * like: Array ( [0] => clansuite [1] => module [2] => admin [3] => menu )
      * or  : Array ( [0] => clansuite [1] => module [2] => news )
      */
     $moduleinfos = explode('_', $modulename);
     unset($modulename);
     $filename = ROOT_MOD;
     // if there is a part [3], we have to require a submodule filename
     if ($moduleinfos['3'] !== null) {
         // and if part [3] is "admin", we have to require a admin submodule filename
         if ($moduleinfos['3'] == 'admin') {
             // admin submodule filename, like news.admin.php
             $filename .= $moduleinfos['2'] . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR . $moduleinfos['2'] . '.admin.php';
         } else {
             // normal submodule filename, like menueditor.module.php
             $filename .= $moduleinfos['3'] . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR . $moduleinfos['3'] . '.module.php';
         }
     } else {
         // module filename
         $filename .= $moduleinfos['2'] . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR . $moduleinfos['2'] . '.module.php';
     }
     return class_exists($classname);
     #if(false === class_exists($classname))
     #{
     //    return \Koch\Autoload\Loader::requireFile($filename, $classname);
     #}
 }
Пример #2
0
 /**
  *  ==========================================
  *          Load Configuration
  *  ==========================================
  *
  * 1. Load clansuite.config.php
  * 2. Load specific staging configuration (overloading clansuite.config.php)
  * 3. Maintenance check
  * 4. Alter php.ini settings
  */
 private static function initialize_Config()
 {
     // 1. load the main clansuite configuration file
     $clansuite_cfg_cached = false;
     if (APC === true and apc_exists('clansuite.config')) {
         self::$config = apc_fetch('clansuite.config');
         $clansuite_cfg_cached = true;
     }
     if ($clansuite_cfg_cached === false) {
         self::$config = \Koch\Config\Adapter\Ini::readConfig(ROOT . 'configuration/clansuite.php');
         if (APC === true) {
             apc_add('application.ini', self::$config);
         }
     }
     unset($clansuite_cfg_cached);
     // 2. Maintenance check
     if (isset(self::$config['maintenance']['maintenance']) and true === (bool) self::$config['maintenance']['maintenance']) {
         $token = false;
         // incoming maintenance token via GET
         if ($_GET['mnt'] !== null) {
             $tokenstring = $_GET['mnt'];
             $token = Clansuite_Securitytoken::ckeckToken($tokenstring);
         }
         // if token is false (or not valid) show maintenance
         if (false === $token) {
             Clansuite_Maintenance::show(self::$config);
         } else {
             self::$config['maintenance']['maintenance'] = 0;
             \Koch\Config\Ini::writeConfig(ROOT . 'configuration/clansuite.config.php', self::$config);
             // redirect to remove the token from url
             header('Location: ' . SERVER_URL);
         }
     }
     // 3. load staging configuration (overloading clansuite.config.php)
     if (true === (bool) self::$config['config']['staging']) {
         self::$config = \Koch\Config\Staging::overloadWithStagingConfig(self::$config);
     }
     /**
      * Deny service, if the system load is too high.
      */
     if (defined('DEBUG') and DEBUG == false) {
         $max_load = isset(self::$config['load']['max']) ? (double) self::$config['load']['max'] : 80;
         if (\Koch\Functions::get_server_load() > $max_load) {
             $retry = (int) mt_rand(45, 90);
             header('Retry-After: ' . $retry);
             header('HTTP/1.1 503 Too busy, try again later');
             die('HTTP/1.1 503 Server too busy. Please try again later.');
         }
     }
     /**
      *  ================================================
      *          4. Alter php.ini settings
      *  ================================================
      */
     set_time_limit(0);
     ini_set('short_open_tag', 'off');
     ini_set('arg_separator.input', '&');
     ini_set('arg_separator.output', '&');
     ini_set('default_charset', 'utf-8');
     self::setMemoryLimit('32');
     if (false === gc_enabled()) {
         gc_enable();
     }
 }
Пример #3
0
 /**
  * Render Engine Configuration
  * Configures the Smarty Object
  */
 public function configureEngine()
 {
     /**
      * Directories
      */
     $this->renderer->compile_dir = ROOT_CACHE . 'tpl_compile' . DIRECTORY_SEPARATOR;
     $this->renderer->config_dir = ROOT_LIBRARIES . 'smarty' . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR;
     $this->renderer->cache_dir = ROOT_CACHE . 'tpl_cache' . DIRECTORY_SEPARATOR;
     /**
      * Debugging
      */
     $this->renderer->debugging = DEBUG ? true : false;
     // set smarty debugging, when debug on
     if ($this->renderer->debugging === true) {
         $this->renderer->debug_tpl = ROOT_THEMES_CORE . 'view/smarty/debug.tpl';
         // set debugging template for smarty
         #$this->renderer->debug_tpl  = ROOT_LIBRARIES . 'smarty/debug.tpl';   // set debugging template for smarty
         $this->renderer->clearCompiledTemplate();
         // clear compiled tpls in case of debug
         $this->renderer->clearAllCache();
         // clear cache
     }
     $this->renderer->auto_literal = true;
     // auto delimiter of javascript/css (The literal tag of Smarty v2.x)
     /**
      * SMARTY FILTERS
      */
     $autoload_filters = array();
     if ($this->renderer->debugging === true) {
         $autoload_filters = array('pre' => array('inserttplnames'));
     }
     $this->renderer->autoload_filters = $autoload_filters;
     #array(       // indicates which filters will be auto-loaded
     #'pre'    => array('inserttplnames'),
     #'post'   => array(),
     #'output' => array('trimwhitespaces')
     #);
     /**
      * COMPILER OPTIONS
      */
     // defines the compiler class for Smarty ... ONLY FOR ADVANCED USERS
     // $this->renderer->compiler_class   = "Smarty_Compiler";
     // set individual compile_id instead of assign compile_ids to function-calls (useful with prefilter for different languages)
     // $this->renderer->compile_id       = 0;
     /**
      * recompile/rewrite templates only in debug mode
      * @see http://www.smarty.net/manual/de/variable.compile.check.php
      */
     if ($this->renderer->debugging === true) {
         // if a template was changed it would be recompiled, if set to false nothing will be compiled (changes take no effect)
         $this->renderer->compile_check = true;
         // if true compiles each template everytime, overwrites $compile_check
         $this->renderer->force_compile = true;
     } else {
         $this->renderer->compile_check = false;
         $this->renderer->force_compile = false;
     }
     /**
      * CACHING OPTIONS (set these options if caching is enabled)
      */
     #\Koch\Debug\Debug::printr($this->config['smarty']);
     if ($this->renderer->debugging === true) {
         $this->renderer->caching = 0;
         $this->renderer->cache_lifetime = 0;
         // refresh templates on every load
         // $this->renderer->cache_handler_func   = "";      // Specify your own cache_handler function
         $this->renderer->cache_modified_check = 0;
         // set to 1 to activate
     } else {
         // $this->renderer->setCaching(true);
         $this->renderer->caching = (bool) $this->config['smarty']['cache'];
         // -1 ... dont expire, 0 ... refresh everytime
         $this->renderer->cache_lifetime = isset($this->config['smarty']['cache_lifetime']) ? $this->config['smarty']['cache_lifetime'] : 0;
         // $this->renderer->cache_handler_func   = "";      // Specify your own cache_handler function
         $this->renderer->cache_modified_check = 1;
         // set to 1 to activate
     }
     /**
      * DEFAULT TEMPLATE HANDLER FUNCTION
      */
     // $this->renderer->default_template_handler_func = "";
     /**
      *  ENGINE SETTINGS
      */
     // $this->renderer->left_delimiter           = "{";    // default : {
     // $this->renderer->right_delimiter          = "}";    // default : }
     #$this->renderer->show_info_header           = false;  // if true : Smarty Version and Compiler Date are displayed as comment in template files
     #$this->renderer->show_info_include          = false;  // if true : adds an HTML comment at start and end of template files
     // $this->renderer->request_vars_order       = "";     // order in which the request variables were set, same as 'variables_order' in php.ini
     #$this->renderer->use_sub_dirs               = true;   // set to false if creating subdirs is not allowed, but subdirs are more efficiant
     /**
      * Smarty Template Directories
      *
      * This sets multiple template dirs, with the following detection order:
      * The user-choosen Theme, before Module, before Core/Default/Admin-Theme.
      *
      * 1) "/themes/[frontend|backend]/theme_of_user_session/"
      * 2) "/themes/[frontend|backend]/theme_of_user_session/modulename/"
      * 3) "/modules/"
      * 4) "/modules/modulename/view/"
      * 5) "/themes/core/view/"
      * 6) "/themes/"
      */
     $tpl_array = array(Mapper::getThemeTemplatePaths(), Mapper::getModuleTemplatePaths(), ROOT_THEMES_CORE . 'view' . DIRECTORY_SEPARATOR . 'smarty', ROOT_THEMES);
     // flatten that thing
     $this->renderer->template_dir = \Koch\Functions::array_flatten($tpl_array);
     #\Koch\Debug\Debug::printR($this->renderer->template_dir);
     /**
      * Smarty Plugins
      *
      * Configure Smarty Viewhelper Directories
      * 1) original smarty plugins               => libraries\smarty\plugins\
      * 2) core                                  => core\view\helper\smarty
      * 3) clansuite application smarty plugins  => application\core\viewhelper\smarty\
      * 4) clansuite module smarty plugins       => application\modules\module_name\viewhelper\smarty\
      */
     $this->renderer->setPluginsDir(array(ROOT_LIBRARIES . 'smarty/plugins', KOCH . 'view/helper/smarty', ROOT_FRAMEWORK . 'view/helper/smarty', ROOT_MOD . TargetRoute::getModuleName() . '/viewhelper/smarty'));
     #\Koch\Debug\Debug::printR($this->renderer->plugins_dir);
     // $this->renderer->registerPlugin('modifier', 'timemarker',  array('benchmark', 'timemarker'));
     #$this->renderer->registerFilter(Smarty::FILTER_VARIABLE, 'htmlspecialchars');
     // Auto-Escape all variables
     #$this->renderer->default_modifiers = array('escape:"html":"UTF-8"');
     // compile time setting, tpls need recompiling
     $this->renderer->merge_compiled_includes = true;
 }
Пример #4
0
 /**
  * Level 1 - The form.
  *
  * $form_array_section is an array of the following structure:
  *
  * @todo $form_array_section description
  *
  * Level 2 - The formelements
  *
  * $form_array_element is an array of the following structure:
  *
  * Obligatory Elements to describe the Formelement
  * These array keys have to exist!
  *
  *   [id]            => resultsPerPage_show
  *   [name]          => resultsPerPage_show
  *   [label]         => Results per Page for Action Show
  *   [description]   => This defines the Number of Newsitems to show per Page in Newsmodule
  *   [formfieldtype] => text
  *
  * Optional Elements to describe the Formelement
  *
  *   [value] => 3
  *   [class] => cssClass
  *
  * @param $form_array the form array
  *
  * @return bool|null true/false
  */
 public static function validateFormArrayStructure($form_array)
 {
     $obligatory_form_array_elements = ['id', 'name', 'label', 'description', 'formfieldtype', 'value'];
     $optional_form_array_elements = ['class', 'decorator'];
     // loop over all elements of the form description array
     foreach ($form_array as $form_array_section => $form_array_elements) {
         #\Koch\Debug\Debug::firebug($form_array_elements);
         #\Koch\Debug\Debug::firebug($form_array_section);
         foreach ($form_array_elements as $form_array_element_number => $form_array_element) {
             #\Koch\Debug\Debug::firebug(array_keys($form_array_element));
             #\Koch\Debug\Debug::firebug($obligatory_form_array_elements);
             // this does the validation. it ensures that required keys are present
             $report_differences_or_true = Functions::array_compare($obligatory_form_array_elements, array_keys($form_array_element));
             // errorcheck for valid formfield elements
             if (is_array($report_differences_or_true) === false) {
                 // form description arrays are identical
                 return true;
             } else {
                 // form description arrays are not identical
                 throw new \Koch\Exception\Exception('Form Array Structure not valid. The first array shows the obligatory form array elements.
                      The second array shows your form definition. Please add the missing array keys with values.' . var_dump($report_differences_or_true));
             }
         }
     }
 }