/** * Loads a class and instantiate an object. * @param string $class class name * @param null $params * @param bool $instantiate * @param bool $force_new_object * @return object|bool */ public static function &factory($class, $params = null, $instantiate = true, $force_new_object = false) { $class = strtolower($class); $path = str_replace('_', '/', $class); // If we would like to instantiate a new object, // we do not need to check the class existance. if ($force_new_object) { // Does the class exist? If so, we're done... if (isset(self::$_objects[$class])) { return self::$_objects[$class]; } } $p = explode('/', $path); $filename = end($p); $path = implode('/', array_slice($p, 0, -1)) . '/'; // Try to find a file $file = Exido::findFile($path, $filename, true); if (is_file($file)) { include_once $file; $name = $class; if ($force_new_object) { Helper::load('guid'); $name = $name . '_' . guidGet(); } if ($instantiate == false) { self::$_objects[$name] = true; return self::$_objects[$name]; } self::$_objects[$name] = new $class($params); return self::$_objects[$name]; } return false; }
/** * Returns all the files and directories in a resource path. * @param bool $path * @param bool $recursive * @return array */ function fileList($path = false, $recursive = false) { $files = array(); if ($path === false) { $paths = array_reverse(Exido::getIncludePaths()); foreach ($paths as $path) { // Recursively get and merge all files $files = array_merge($files, fileList($path, $recursive)); } } else { $path = exido_fix_path($path); if (is_readable($path)) { $items = (array) glob($path . '*'); if (!empty($items)) { foreach ($items as $index => $item) { $files[] = $item = exido_fix_path($item); // Handle recursion if (is_dir($item) and $recursive == true) { // Filename should only be the basename $item = pathinfo($item, PATHINFO_BASENAME); // Append sub-directory search $files = array_merge($files, fileList($path . $item, true)); } } } } } return $files; }
/** * Gets the site uri. * @param $uri * @return string */ function uriSite($uri) { if (Exido::config('global.core.use_friendly_url')) { return HOME . exido_fix_path($uri); } return HOME . Exido::config('global.core.index_file') . '/' . exido_fix_path($uri); }
/** * Loads a global view. Design theme. * @return View_Layout */ public function load() { $this->_file = Exido::findFile($this->_layout_path, $this->_layout_name); if ($this->_file == null) { $this->_file = sprintf(__('[View file %s is not found]'), $this->_layout_path . $this->_layout_name . '.php'); } return $this; }
/** * Loads an action view. Controller method. * @param string $controller * @param string $method * @return View_Action */ public function load($controller, $method) { $this->_file = Exido::findFile('template/default/action/' . $controller . '/', $method); if ($this->_file == null) { $this->_file = sprintf(__('[View file %s is not found]'), 'template/default/action/' . $controller . '/' . $method . '.php'); } return $this; }
/** * Merges configurations from all the loaded files. * @param string $group * @param array $config * @return Config_Reader */ public function load($group, array $config = NULL) { if ($files = Exido::findFile($this->_directory, $group)) { // Set config array $config = array(); foreach ($files as $file) { // Merge each config array to the global array $config = arrayMerge($config, require $file); } } return parent::load($group, $config); }
/** * Loads a custom view. Returns FALSE if the view has already been loaded. * @param string $file * @return View_Custom */ public function load($file) { if (isset($this->_files[$file])) { return $this; } // Find a view file $this->_files[$file] = Exido::findFile('template/default', $file); if ($this->_files[$file] == null) { $this->_files[$file] = sprintf(__('[View file %s is not found]'), 'template/default/' . $file . '.php'); } return $this; }
/** * Merges language lines from all the loaded files. * @return array */ public function load() { static $i18n = array(); if ($files = Exido::findFile($this->_directory, $this->_idiom)) { // Set config array foreach ($files as $file) { // Merge each config array to the global array $i18n = array_merge($i18n, require $file); } } return $i18n; }
/** * Constructor. * @param null $params */ public function __construct($params = null) { if (!is_array($params)) { $params = array(); } $params['degs'] = range(1, 360); if (!isset($params['mimes'])) { // Get mimes from config file if ($mimes = Exido::config('mime.image')) { $params['mimes'] = $mimes; } } $this->setup($params); }
/** * Loads a vendor. * @param string $vendor * @return bool */ public static function load($vendor) { $_vendors = func_get_args(); foreach ($_vendors as $file) { // Does the file exist? If so, we're done... if (!isset(self::$_vendors[$file])) { $path = Exido::findFile('vendors/' . str_replace('_', '/', $file), '_init', true); if ($path) { include_once $path; self::$_vendors[$file] = $path; } } } return true; }
/** * Loads a helper. * @param string $helper * @return bool */ public static function load($helper) { $_helpers = func_get_args(); foreach ($_helpers as $file) { // Does the class exist? If so, we're done... if (!isset(self::$_helpers[$file])) { $path = Exido::findFile('helper/', $file, true); if ($path) { include_once $path; self::$_helpers[$file] = $path; } } } return true; }
/** * Load paths of additional components. * @return void */ public static function initialize() { if ($paths = self::getPaths() and !empty($paths)) { Exido::setIncludePaths($paths); } // Load components configurations foreach (Exido::config('component') as $name_space => $path) { // Get component configuration $config = Exido::config($name_space); // Set name $config['ui_name'] = isset($config['ui_name']) ? $config['ui_name'] : $name_space; // Assign component configuration self::$_components[$name_space] = $config ? (array) $config : self::$default_config; // Set component paths self::$_components[$name_space]['paths'] = array(1 => COMPATH . $path . '/', 2 => COMPATH . $path . '/' . strtolower(EXIDO_ENVIRONMENT_NAME) . '/'); } }
/** * Constructor. * @throws Exception_Exido */ public function __construct() { $this->input = Input::instance(); // Set the "now" time. can either be gmt or server time, based on the // config prefs. we use this to set the "last activity" time $this->now = $this->_getTime(); $config = Exido::config('session'); // Set all the session preferences via the config file foreach (array('cookie_name', 'life_time', 'use_database', 'use_phpsession', 'db_table_name', 'db_files_path', 'cookie_path', 'cookie_domain', 'time_reference') as $key) { $this->{$key} = $config[$key]; } // We dont make anything else if we use the PHP sessions if ($this->use_phpsession) { @session_start(); return; } if (empty($this->cookie_domain)) { $this->cookie_domain = HOST; } if (empty($this->db_table_name)) { $this->db_table_name = 'session'; } if (empty($this->db_files_path)) { $this->db_files_path = APPPATH . 'data/cache'; } $this->db_files_path = rtrim($this->db_files_path, '/') . '/' . $this->sess_dir_name . '/'; // Try to create session directory if (!is_dir($this->db_files_path)) { if (!@mkdir($this->db_files_path, DIR_WRITE_MODE, true)) { throw new Exception_Exido("Couldn't create session directory"); } } // Load a database instance if ($this->use_database) { $this->use_database = Registry::factory('Session_Db'); $this->use_database->setDbTableName($this->db_table_name); } // Run the session routine. If a session doesn't exist we'll // create a new one. If it does, we'll update it. if (!$this->_read()) { $this->_create(); } else { $this->_update(); } }
/** * Get sa singleton instance. * @param string $name * @param null $config * @return mixed * @throws Exception_Exido */ public static function &instance($name = 'default', $config = null) { if (!isset(self::$instances[$name])) { // Get the DB settings if ($config == null) { $config = @Exido::config('database')->{$name}; } if (!isset($config['type'])) { throw new Exception_Exido("DB instance %s doesn't supported by the system", array($name)); } // Merge a default configuration with user's configuration self::$_config = array_merge(self::$_config, $config); if (is_file(SYSPATH . 'database/driver/' . self::$_config['type'] . '/adapter.php')) { // Initialize a driver include_once 'database/driver/' . self::$_config['type'] . '/adapter.php'; $driver = 'Database_Driver_' . ucfirst(self::$_config['type']) . '_Adapter'; self::$instances[$name] = new $driver(self::$_config); } else { throw new Exception_Exido("Driver :driver doesn't exist", array('database/driver/' . self::$_config['type'] . '/adapter.php')); } } return self::$instances[$name]; }
/** * Clear expired cache files * @return array */ public function clearCache() { $removed = array(); // Get cache files of the VIEW object $view_cache_dir = Exido::config('view.cache_folder'); // Get the cache life time $view_cache_lifetime = Exido::config('view.cache_lifetime'); // Get files list $files = fileList(rtrim($view_cache_dir, '/') . '/e-view', false); // Check each file foreach ($files as $file) { // Get information of the file if ($stat = stat($file)) { // Check if the difference between the current server time and the cache life time // is less then time of last access if (time() - $view_cache_lifetime > $stat['atime']) { @unlink($file); $removed[] = $file; } } } return true; }
* * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade ExidoEngine to newer * versions in the future. If you wish to customize ExidoEngine for your * needs please refer to http://www.exidoengine.com for more information. * * @license http://www.exidoengine.com/license/gpl-3.0.html (GNU General Public License v3) * @author ExidoTeam * @copyright Copyright (c) 2009 - 2013, ExidoEngine Solutions * @link http://www.exidoengine.com/ * @since Version 1.0 * @filesource *******************************************************************************/ // List actions menu $view->action_menu = array('/user/action/create' => __('Create user')); // Include menu code $view->getView('layout/inc.list-action-menu-panel'); $helper->heading(__('Users')); if ($view->item_list) { print tableOpen('-i-table -i-table-striped'); print tableHead(array(__('ID'), __('User name'), __('Email'), __('Owner'), __('Group'), __('Role'), __('Joined at'), __('Status'), __('Actions'))); foreach ($view->item_list as $item) { $item->is_enabled = htmlStatus($item->is_enabled); $item->created_at = dateConvertSQL2Human($item->created_at, Exido::config('global.date.format_long')); $item->actions = '<a href="user/action/edit/' . $item->user_id . '">' . __('Edit') . '</a> '; $item->actions .= '<a class="remove" href="user/action/remove/' . $item->user_id . '">' . __('Remove') . '</a>'; print tableTR(arrayExtract((array) $item, array('user_id', 'user_name', 'user_email', 'owner_name', 'group_name', 'role_name', 'created_at', 'is_enabled', 'actions'))); } print tableClose(); }
* DISCLAIMER * * Do not edit or add to this file if you wish to upgrade ExidoEngine to newer * versions in the future. If you wish to customize ExidoEngine for your * needs please refer to http://www.exidoengine.com for more information. * * @license http://www.exidoengine.com/license/gpl-3.0.html (GNU General Public License v3) * @author ExidoTeam * @copyright Copyright (c) 2009 - 2013, ExidoEngine Solutions * @link http://www.exidoengine.com/ * @since Version 1.0 * @filesource *******************************************************************************/ // List actions menu $view->action_menu = array('/page/action/create' => __('Create a new page')); // Include menu code $view->getView('layout/inc.list-action-menu-panel'); $helper->heading(__('Static pages')); if ($view->item_list) { print tableOpen('-i-table -i-table-striped'); print tableHead(array('', __('ID'), __('Page title'), __('Owner'), __('Group'), __('Added at'), __('Status'), __('Actions'))); foreach ($view->item_list as $item) { print '<tr>' . '<td>' . formCheckbox('item[]', $item->entity_id, false, 'class="item-list-checkbox"') . '</td>' . '<td>' . $item->entity_id . '</td>' . '<td>' . eavFetchValue('title', $item->attributes) . '</td>' . '<td>' . eavFetchValue('owner_name', $item->attributes) . '</td>' . '<td>' . eavFetchValue('group_name', $item->attributes) . '</td>' . '<td>' . dateConvertSQL2Human(eavFetchValue('created_at', $item->attributes), Exido::config('global.date.format_long')) . '</td>' . '<td>' . eavFetchValue('is_enabled', $item->attributes, 'htmlStatus') . '</td>' . '<td>'; $helper->a('page/action/edit/' . $item->entity_id, __('Edit')); $helper->a('page/action/remove/' . $item->entity_id, __('Remove'), 'remove'); print '</td></tr>'; } print tableClose(); } else { $helper->notifier(__('No pages created')); }
/** * Gets the language line. The function called __() just for simplicity. * @param string $line * @return string */ function __($line) { //file_put_contents(APPPATH.'data/lang.txt', "'".$line."' => '',".EXIDO_EOL, FILE_APPEND); return Exido::i18n($line); }
/** * Send password to email * @param string $to * @param string $username * @param string $password * @return void * @throws Exception_Exido */ private function _emailPassword($to, $username, $password) { $this->view->password = $password; $this->view->username = $username; $email = Registry::factory('Mail_Php'); $email->to($to); $email->from(Exido::config('global.mail.name'), Exido::config('global.mail.from')); $email->subject(__('Your credentials')); $email->body($this->view->getView('mail/notification/password', true)); return $email->send(); }
/** * Inline exception handler, displays the error message, source of the * exception, and the stack trace of the error. * @param object $e * return void */ public static function handlerException($e) { try { // Get the exception information $type = get_class($e); $code = $e->getCode(); $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); if (!in_array($code, self::$codes)) { $code = 500; } // Get the exception backtrace $trace = $e->getTrace(); // Run logger self::log($e); // If Exido running in a command line environment // or using an XML request. // We just print a json encoded string. if (Exido::$is_cli or Exido::$is_xml) { // Just display the text of the exception exit(json_encode(array('status' => false, 'code' => $code, 'text' => $message))); } if (!headers_sent()) { // Make sure the proper http header is sent header('Content-Type: text/html; charset=' . __('__charset'), true, $code); } // If we're in production so we should return the correct error page. if (IN_PRODUCTION == true) { if ($e instanceof Exception_Database) { exit($message); } else { $view = View::instance(); $view->code = $code; $view->message = $message; $view->file = Debug::path($file); $view->line = $line; $html = Registry::factory('View_Exception')->setLayout('exception/template', 'error' . $code)->load()->parse($view, new View_Helper()); // Display the contents and exit exit($html); } } else { if ($e instanceof Exception_Database) { $message = $e->errstr . ' [ ' . $e->errquery . ' ]'; } // Return the page with more information about error in the development mode. include_once Exido::findFile('exception/template', 'development'); exit(1); } } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo self::text($e), EXIDO_EOL; // Run logger Exido::$log->write(); // Exit with an error status exit(1); } }
/** * Constructor. Gets the cache configuration */ public function __construct() { $this->_cache_config = Exido::config('view'); }
/** * Execute cron tasks * @return bool */ public final function index() { Helper::load('date'); // Get config $cron = Exido::config('cron'); if (!$cron->cron_enabled) { print __('System cron disabled.'); return false; } if (!is_array($cron->cron_allowed_ip)) { $cron->cron_allowed_ip = array($cron->cron_allowed_ip); } // Get the client IP $ip_block = $this->input->ip(true); Helper::load('ip'); foreach ($cron->cron_allowed_ip as $ip) { if ($range = ipRangeParser($ip)) { if (!ipCheckRange($ip_block, $range[0], $range[1])) { if ($range[0] == $range[1]) { print sprintf(__("Your IP %s doesn't match in allowed IP %s"), $this->input->ip(), $ip); } else { print sprintf(__("Your IP %s doesn't match in allowed range %s"), $this->input->ip(), $ip); } return false; } } else { print sprintf(__("Incorrect IP range %s"), $ip); return false; } } $local = dateGetLocal('%M %H %e %m %u'); $srv_time = explode(' ', $local); array_unshift($srv_time, $local); if (is_array($cron->cron_job_list)) { foreach ($cron->cron_job_list as $job_name => $job_data) { if (isset(self::$_has_run[$job_name])) { continue; } $this->_log[$job_name] = ''; // Check job time if (!preg_match('/^([0-9\\*]{1,2})\\s([0-9\\*]{1,2})\\s([0-9\\*]{1,2})\\s([0-9\\*]{1})\\s([0-9\\*]{1})$/', $job_data['starting_at'], $job_time)) { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = sprintf(__('Incorrect starting time for job %s'), $job_name); continue; } // Check day of week if (is_numeric($job_time[5]) and $srv_time[5] != $job_time[5]) { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = __("Is omitted due the week day doesn't match the scheduled day"); continue; } // Check month if (is_numeric($job_time[4]) and $srv_time[4] != $job_time[4]) { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = __("Is omitted due the month doesn't match the scheduled month"); continue; } // Check day of month if (is_numeric($job_time[3]) and $srv_time[3] != $job_time[3]) { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = __("Is omitted due the day of month doesn't match the scheduled day"); continue; } // Check hour if (is_numeric($job_time[2]) and $srv_time[2] != $job_time[2]) { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = __("Is omitted due the hour doesn't match the scheduled hour"); continue; } // Check minute if (is_numeric($job_time[1]) and $srv_time[1] != $job_time[1]) { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = __("Is omitted due the minute doesn't match the scheduled minute"); continue; } // Here we go // Mark job as running self::$_has_run[$job_name] = $job_name; // Check the callback functions if (isset($job_data['callback']) and is_array($job_data['callback']) and !empty($job_data['callback'])) { foreach ($job_data['callback'] as $callback) { // Try to explode by ":" // If it is, so we're using a method from an object if ($func = explode(':', $callback) and count($func) > 1) { // Call method $this->_log[$job_name][$callback]['status'] = true; $this->_log[$job_name][$callback]['result'] = $this->model($func[0])->{$func}[1](); } else { // Instead we're using a function // Call function if (function_exists($callback)) { $this->_log[$job_name][$callback]['status'] = true; $this->_log[$job_name][$callback]['result'] = $callback(); } else { $this->_log[$job_name][$callback]['status'] = true; $this->_log[$job_name][$callback]['result'] = sprintf(__('Call to undefined cron function %s()'), $callback); } } } } else { $this->_log[$job_name]['status'] = false; $this->_log[$job_name]['result'] = __('Nothing to do'); } unset(self::$_has_run[$job_name]); } } // TODO: Make the log showing pre($this->_log); }
// Load framework base functions include_once 'base.php'; // Set the PHP error reporting level. // @see http://php.net/error_reporting error_reporting(E_ALL & ~E_DEPRECATED); // Check if an installation folder is exists //if(file_exists(APPPATH.'install/index.php')) { //include_once APPPATH.'install/index.php'; //} // Set error handlers set_error_handler(array('Exception_Exido', 'handlerError')); set_exception_handler(array('Exception_Exido', 'handlerException')); // Initialize framework Exido::initialize(); // Load basic include paths Exido::setIncludePaths(); // You can attach a log writer by uncomment next line //Exido::$log->attach(new Log_File(APPPATH.'data/cache/log')); // Load additional components Component::load(); // Initialize loaded components Component::initialize(); // Include internalization languages //Exido::$i18n->attach(new I18n_File('en_US')); Exido::$i18n->attach(new I18n_File('ru_RU')); // Set application time zone. Depends on language loaded. // It's UTC default. // @see http://php.net/timezones date_default_timezone_set(__('__time_zone')); // Set application locale. Depends on language loaded. // It's en_US.UTF-8 by default.
/** * Generates a routed URI from given URI. * @param array $segments * @return array */ private static function _getRouted(array $segments) { $ent = Exido::config('global.core.uri_entities'); if (self::$_routes === null) { // Load routes self::$_routes = Exido::config('route'); } // Join additional routes if (!empty(self::$_additional_routes)) { foreach (self::$_additional_routes as $key => $value) { self::$_routes->set($key, $value); } } $segments_string = implode('/', $segments); // Is there a literal match? If so we're done if (isset(self::$_routes[$segments_string])) { return explode('/', self::$_routes[$segments_string]); } $routed_uri = array(); // Loop through the routes and see if anything matches foreach (self::$_routes as $key => $val) { if ($key === 'default_controller') { continue; } $key = strtr($key, $ent); if (preg_match('#^' . $key . '$#', $segments_string)) { // Do we have a back-reference? if (strpos($val, '$') !== false and strpos($key, '(') !== false) { $val = preg_replace('#^' . $key . '$#', $val, $segments_string); } // Change a route $routed_uri = explode('/', $val); break; } else { // Get the original route $routed_uri = $segments; } } return $routed_uri; }
/** * Output handler. Calls during ob_clean, ob_flush, and their variants. * @param string $output * @return string */ public static function outputBuffer($output) { // Set and return the final output return self::$output = $output; }
/** * Fetches a user IP. * @param bool $return_array * @return string */ public function ip($return_array = false) { if ($this->ip_address !== false) { return $this->ip_address; } $proxy = Exido::config('proxy'); $proxy = implode(',', $proxy->asArray()); if (!empty($proxy) && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) { $proxies = preg_split('/[\\s,]/', $proxy, -1, PREG_SPLIT_NO_EMPTY); $proxies = is_array($proxies) ? $proxies : array($proxies); $this->ip_address = in_array($this->server('REMOTE_ADDR'), $proxies) ? $this->server('HTTP_X_FORWARDED_FOR') : $this->server('REMOTE_ADDR'); } elseif ($this->server('REMOTE_ADDR') and $this->server('HTTP_CLIENT_IP')) { $this->ip_address = $this->server('HTTP_CLIENT_IP'); } elseif ($this->server('REMOTE_ADDR')) { $this->ip_address = $this->server('REMOTE_ADDR'); } elseif ($this->server('HTTP_CLIENT_IP')) { $this->ip_address = $this->server('HTTP_CLIENT_IP'); } elseif ($this->server('HTTP_X_FORWARDED_FOR')) { $this->ip_address = $this->server('HTTP_X_FORWARDED_FOR'); } if ($this->ip_address === false) { return $this->ip_address = '0.0.0.0'; } if (strstr($this->ip_address, ',')) { $x = explode(',', $this->ip_address); $this->ip_address = trim(end($x)); } if (!$this->validateIP($this->ip_address)) { $this->ip_address = '0.0.0.0'; } if ($return_array) { return explode('.', $this->ip_address); } return $this->ip_address; }