Пример #1
0
/**
 * 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);
}
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 /**
  * 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) . '/');
     }
 }
Пример #4
0
 /**
  * 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();
     }
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  * 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];
 }
Пример #7
0
 /**
  * Initializes the core.
  * @return bool
  */
 public static function initialize()
 {
     if (self::$_init) {
         // Do not allow to execution twice
         return false;
     }
     self::$_init = true;
     // Determine if we are running in a Windows environment
     self::$is_win = DIRECTORY_SEPARATOR === '\\';
     // Load the logger
     self::$log = Log::instance();
     // Load the default configuration files
     self::$config = Config::instance()->attach(new Config_File());
     // Load the i18n class
     self::$i18n = I18n::instance();
     // Enable debug log
     if (self::$log_debug) {
         self::$log->attach(new Log_File(APPPATH . 'data/log/debug'), array('EXIDO_DEBUG_LOG'));
         self::$log->add('EXIDO_DEBUG_LOG', 'Initialize framework');
     }
     // Enable error log
     if (self::$log_error) {
         self::$log->attach(new Log_File(APPPATH . 'data/log/error'), array('EXIDO_ERROR_LOG'));
     }
     // Determine if we are running in a command line environment
     self::$is_cli = PHP_SAPI === 'cli';
     // Check if we have an Ajax request
     self::$is_xml = Input::instance()->isXmlRequest();
     // Load helpers
     Helper::load('lang', 'uri');
     // Check if we can use gZIP compression
     self::$use_gzip = strstr(Input::instance()->server('HTTP_ACCEPT_ENCODING'), "gzip") !== false and extension_loaded("zlib");
     // Start output buffering
     ob_start(array(__CLASS__, 'outputBuffer'));
     // Save buffering level
     self::$_buffer_level = ob_get_level();
     Event::add('system.routing', array('Router', 'getUri'));
     Event::add('system.routing', array('Router', 'initialize'));
     Event::add('system.execute', array(__CLASS__, 'instance'));
     Event::add('system.shutdown', array(__CLASS__, 'shutdown'));
     return true;
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 *
 * 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();
}
Пример #10
0
 /**
  * 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;
 }
Пример #11
0
 /**
  * Constructor. Gets the cache configuration
  */
 public function __construct()
 {
     $this->_cache_config = Exido::config('view');
 }
Пример #12
0
 /**
  * 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();
 }
Пример #13
0
 * 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'));
}
Пример #14
0
 /**
  * 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;
 }