/** * Loads URI and Input objects into the controller. * Check if the requested environment the system does supports. */ function __construct($instance) { $this->db = Registry::factory('Database_Query_Builder'); $this->_data_types = $this->_getDataTypes(); $this->eav_instance = $this->_checkInstance($instance); $this->_aData = Model_Registry::instance(true); }
/** * Loader. * @param string $model * @param null $params * @return bool|object */ public function load($model, $params = null) { // Does the model exist? If so, we're done... if (isset($this->_models[$model])) { return $this->_models[$model]; } // Load model class $this->_models[$model] = Registry::factory($model, $params); // Get object return $this->get($model); }
/** * Executes a query. * @param bool $print_last * @return mixed */ public function exec($print_last = false) { if ($print_last) { $this->_printSql(); } // Execute an SQL $result = $this->db->exec($this->_query()); if (!$result) { return Registry::factory('Database_Mapper_Result_Dummy'); } // Clear last SQL //$this->_clear(); return $result; }
/** * Dashboard page * @return void */ public function email() { $this->disableViews(); $mail = Registry::factory('Mail_Php'); $mail->to('*****@*****.**', 'Александр'); $mail->from('*****@*****.**', 'Exidoengine'); $mail->reply('*****@*****.**', 'Admin'); $mail->subject('Тема'); $mail->body('Текст письма'); if ($mail->send()) { print '1'; } else { print '0'; } }
/** * Loads URI and Input objects into the controller. * Check if the requested environment supports by the system. * @throws Exception_Exido */ public function __construct() { // Check environment if (!in_array(EXIDO_ENVIRONMENT_NAME, $this->_envs)) { throw new Exception_Exido('The requested environment %s does not supported by the system', array(EXIDO_ENVIRONMENT_NAME)); } // URI should always be available $this->uri = Uri::instance(); // Input should always be available $this->input = Input::instance(); // Init a model loader object $this->_model = Registry::factory('Model'); // Input should always be available $this->view = View::instance(); // Session object $this->session = Registry::factory('Session'); // Init layout view object $this->_viewLayout = Registry::factory('View_Layout'); // Init action view object $this->_viewAction = Registry::factory('View_Action'); // Get active components $this->_components = $this->model('Model_Component')->getActiveComponents(); // Get session data $_user_key = $this->_getCurrentUser(); // If current user is unknown so we should start guest session if (empty($_user_key)) { // Guest session id $_user_key = '5627a272bf2563cee5877539bd906e7cc3eb33afcefe2b570a08906f9a34ae48'; } if ($r = $this->model('Model_User')->getUserByUniqueKey($_user_key)) { $this->_system_user = array('user_id' => $r->getUser_id(), 'user_name' => $r->getUser_name(), 'password' => $r->getPassword(), 'user_email' => $r->getUser_email(), 'owner_id' => $r->getOwner_id(), 'owner_name' => $r->getOwner_name(), 'group_id' => $r->getGroup_id(), 'group_name' => $r->getGroup_name(), 'role_name' => $r->getRole_key(), 'permissions' => array('owner' => $r->getPermissions_owner(), 'group' => $r->getPermissions_group(), 'other' => $r->getPermissions_other()), 'is_enabled' => $r->getIs_enabled(), 'is_dropped' => $r->getIs_dropped(), 'is_system' => $r->getIs_system()); // User constants define('@SU.GROUP_ID', $r->getGroup_id()); define('@SU.GROUP_NAME', $r->getGroup_name()); define('@SU.USER_ID', $r->getUser_id()); define('@SU.USER_NAME', $r->getUser_name()); $this->_system_user_access = $this->model('Model_User')->getUserAccess($r->getUser_id(), EXIDO_ENVIRONMENT_NAME); $this->session->set('system_user', $_user_key); } }
/** * Prevents inheritance of the method. */ public final function __construct() { $this->input = Input::instance(); $this->_model = Registry::factory('Model'); }
/** * Generates a pagination selector. * @return string */ public function get() { if (empty($this->total_rows) or empty($this->per_page)) { return ''; } // Count pages $num_pages = $this->_countPages(); // Return empty if we have one page. if ($num_pages == 1) { return ''; } // Get the current page number if (!is_numeric($this->cur_page) or $this->cur_page < 1) { $this->cur_page = 1; } if (!is_numeric($this->num_links)) { $this->num_links = 2; } if ($this->num_links < 1) { return ''; } // If the current page number is bigger than total count of a pages // so we will need to show the last page if ($this->cur_page > $num_pages) { $this->cur_page = $num_pages; } $view = View::instance(); // Get start and end page numbers $view->start = $this->cur_page - $this->num_links > 0 ? $this->cur_page - ($this->num_links - 1) : 1; $view->end = $this->cur_page + $this->num_links < $num_pages ? $this->cur_page + $this->num_links : $num_pages; $view->cur_page = $this->cur_page; $view->base_url = $this->base_url; $view->url_attach = $this->base_url_attach; // Define variables... $view->first_page = $view->prev_page = $view->next_page = $view->last_page = ''; // Generate link to a first page if ($this->cur_page > $this->num_links + 1) { $view->first_page = $this->base_url . '1' . $this->base_url_attach; } // Generate link to a previous page if ($this->cur_page != 1) { $i = $this->cur_page - 1; if ($i <= 0) { $i = '1'; } $view->prev_page = $this->base_url . $i . $this->base_url_attach; } // Generate link to a next page if ($this->cur_page < $num_pages) { $view->next_page = $this->base_url . ($this->cur_page + 1) . $this->base_url_attach; } // Generate link to a last page if ($this->cur_page + $this->num_links < $num_pages) { $view->last_page = $this->base_url . $num_pages . $this->base_url_attach; } // Load a pagination view return Registry::factory('View_Custom')->load('pagination')->parse('pagination', $view, new View_Helper()); }
/** * 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(); } }
/** * Handles view variables that do not exist. * @param string $var * @return bool|object|void */ public function __get($var) { print sprintf(__('[Undefined property $view->%s]'), $var); return Registry::factory('View_Dummy'); }
/** * Checks if the entered captcha string consists with the session captcha string. * @param string $str * @return bool */ public function captcha($str) { // Get secret word from session $s = Registry::factory('Session'); $str2 = $s->get('captcha'); if (empty($str) or empty($str2)) { return false; } return $str == $str2 ? true : false; }
/** * 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); } }
/** * Get user. Return FALSE if the user is not found. * @param string $key * @return mixed */ public function getUserByUniqueKey($key) { if ($r = $this->db->select('user', '*')->where(array('unique_session_id' => $key))->limit(1)->exec()->row()) { return $this->_user = Registry::factory('Model_Auth_User', $r); } return false; }
/** * Loads URI and Input objects into the controller. * Check if the requested environment supports by the system. */ function __construct() { $this->_aData = Model_Registry::instance(true); $this->db = Registry::factory('Database_Query_Builder', null, true, true); }
/** * 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(); }
/** * Gets the value of given key. * @param string $key * @param bool $xss_clean_enabled * @return array|string */ public function cookie($key = '', $xss_clean_enabled = true) { if (!isset($_COOKIE) or empty($_COOKIE)) { return false; } if (empty($key)) { return $xss_clean_enabled ? Registry::factory('security')->cleanXSS($_COOKIE) : $_COOKIE; } if (!isset($_COOKIE[$key])) { return false; } // Sanitize variable return $xss_clean_enabled ? Registry::factory('security')->cleanXSS($_COOKIE[$key]) : $_COOKIE[$key]; }