/** * Set a value in the modules moduleInfo.php. * * @param mixed config Key * @param mixed config value */ public static function setConfigValue($key, $value) { $file = self::getModulePath() . 'moduleInfo.php'; self::$cfg->{$key} = $value; // Check if the module path is set yet if (self::getModulePath() == null) { Logger::logWarning('Could not write module config. ModulePath is not set', get_class($this)); return false; } if (file_exists($file) && is_writable($file)) { $config = var_export($this->cfg, true); file_put_contents($file, "<?php return {$config} ;"); } }
/** * Loads the available themes */ public static function loadThemes() { if ($handle = opendir(THEMES_DIR)) { while (false !== ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..') { $name = explode('.', $entry)[0]; self::$CSS_THEMES[ucfirst($name)] = $entry; } } asort(self::$CSS_THEMES); closedir($handle); } else { Logger::logWarning('Cannot open themes directory'); } }
/** * Checks if the Model/View/Controller exists for a classname, then loads the MVC classes definitions from its files * * @param string $classname * Name of the class to check * @return boolean true if the files exist, false otherwise */ private static function checkMVC($classname) { /* Check each file */ $commonPath = MODULES_DIR . $classname . DIRECTORY_SEPARATOR . $classname; $controller_file = $commonPath . 'Controller.php'; if (!file_exists($controller_file)) { Logger::logWarning('File ' . $controller_file . ' not found'); return false; } $view_file = $commonPath . 'View.php'; if (!file_exists($view_file)) { Logger::logWarning('File ' . $view_file . ' not found'); return false; } $model_file = $commonPath . 'Model.php'; if (!file_exists($model_file)) { Logger::logWarning('File ' . $model_file . ' not found'); return false; } /* Load the classes */ require_once $controller_file; require_once $model_file; require_once $view_file; return true; }
/** * Display Output * * Processes and sends finalized output data to the browser along * with any server headers and profile data. It also stops benchmark * timers so the page rendering speed and memory usage can be shown. * * Note: All "view" data is automatically put into $this->final_output * by controller class. * * @uses Output::$final_output * @param string $output Output data override * @return void */ public function _display($output = '') { $router = Factory::getInstance()->router; // Grab the super object if we can. if ($router->getCallable() === null) { $use_cache = true; } else { $use_cache = false; } // -------------------------------------------------------------------- // Set the output data if ($output === '') { $output =& $this->final_output; } // -------------------------------------------------------------------- // Do we need to write a cache file? Only if the controller does not have its // own _output() method and we are not dealing with a cache file, which we // can determine by the existence of the $CI object above if ($this->cache_expiration > 0 && $use_cache === false) { $this->_write_cache($output); } // -------------------------------------------------------------------- if ($this->parse_exec_vars === TRUE) { $memory = round(memory_get_usage() / 1024 / 1024, 2) . 'MB'; $output = str_replace(array('{memory_usage}'), array($memory), $output); } // -------------------------------------------------------------------- // Is compression requested? if ($use_cache === false && $this->_compress_output === TRUE && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) { ob_start('ob_gzhandler'); } // -------------------------------------------------------------------- // Are there any server headers to send? if (count($this->headers) > 0) { foreach ($this->headers as $header) { @header($header[0], $header[1]); } } // -------------------------------------------------------------------- if ($use_cache === true) { if ($this->_compress_output === TRUE) { if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) { header('Content-Encoding: gzip'); header('Content-Length: ' . strlen($output)); } else { // User agent doesn't support gzip compression, // so we'll have to decompress our cache $output = gzinflate(substr($output, 10, -8)); } } echo $output; Logger::log('Final output sent to browser'); return; } // -------------------------------------------------------------------- // Do we need to generate profile data? // If so, load the Profile class and run it. if ($this->enable_profiler === TRUE) { Logger::logWarning("Profiler not yet implemented"); return; $CI->load->library('profiler'); if (!empty($this->_profiler_sections)) { $CI->profiler->set_sections($this->_profiler_sections); } // If the output data contains closing </body> and </html> tags // we will remove them and add them back after we insert the profile data $output = preg_replace('|</body>.*?</html>|is', '', $output, -1, $count) . $CI->profiler->run(); if ($count > 0) { $output .= '</body></html>'; } } echo $output; Logger::log('Output sent to browser'); }