示例#1
0
文件: Lang.php 项目: fuelphp/legacy
 /**
  * Returns a (dot notated) language string
  *
  * @param string|array $line
  * @param array        $params
  * @param mixed        $default
  *
  * @return mixed
  */
 public static function get($line, array $params = array(), $default = null)
 {
     // create the list of keys to search
     if (!is_array($line)) {
         $line = array($line);
     }
     // look for a match
     foreach ($line as $key) {
         if (($found = static::getInstance()->get($key, '__FAIL__')) !== '__FAIL__') {
             break;
         }
     }
     // no match
     if ($found === '__FAIL__') {
         // do we have a default?
         if (func_num_args() == 4) {
             $found = $default;
         } else {
             // get the globally configured default
             $found = \Config::get('lang.default', '');
             $found = str_replace('{key}', array_shift($line), $found);
         }
     }
     // stuff in any parameters passed, and return the result
     return \Str::tr($found, $params);
 }
示例#2
0
 public function create_user($userdata)
 {
     $password = \Arr::get($userdata, 'password', null);
     $email = \Arr::get($userdata, 'email', null);
     if (is_null($password) || is_null($email)) {
         Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_BAD_CRIDENTIALS, $email);
         throw new LogInFailed(\Lang::get('ethanol.errors.loginInvalid'));
     }
     $user = Auth_Driver::get_core_user($email);
     $security = new Model_User_Security();
     //Generate a salt
     $security->salt = Hasher::instance()->hash(\Date::time(), Random::instance()->random());
     $security->password = Hasher::instance()->hash($password, $security->salt);
     if (\Config::get('ethanol.activate_emails', false)) {
         $keyLength = \Config::get('ethanol.activation_key_length');
         $security->activation_hash = Random::instance()->random($keyLength);
         $user->activated = 0;
         //Send email
         \Package::load('email');
         //Build an array of data that can be passed to the email template
         $emailData = array('email' => $user->email, 'activation_path' => \Str::tr(\Config::get('ethanol.activation_path'), array('key' => $security->activation_hash)));
         $email = \Email::forge()->from(\Config::get('ethanol.activation_email_from'))->to($user->email, $user->username)->subject(\Config::get('ethanol.activation_email_subject'))->html_body(\View::forge('ethanol/activation_email', $emailData))->send();
     } else {
         $user->activated = 1;
         $security->activation_hash = '';
     }
     $user->security = $security;
     $user->save();
     $user->clean_security();
     return $user;
 }
示例#3
0
 public static function get($line, array $params = array(), $default = null, $language = null)
 {
     $output = parent::get($line, $params, '__NOT__FOUND__', $language);
     if (!empty($output) && $output != '__NOT__FOUND__') {
         return $output;
     }
     if ($output == '__NOT__FOUND__') {
         $output = $default;
     }
     if (!static::$autosave || !\CMF::$lang_enabled) {
         return $output;
     }
     $language === null and $language = static::get_lang();
     $pos = strpos($line, '.');
     $group = 'common';
     $basename = $line;
     if ($pos === false) {
         if (empty($default)) {
             $default = $line;
         }
         $line = "{$group}.{$line}";
     } else {
         $basename = substr($line, $pos + 1);
         if (empty($default)) {
             $default = $basename;
         }
         $group = substr($line, 0, $pos);
     }
     // Try and load from the DB...
     if (!in_array($group . '_' . $language, static::$loaded)) {
         static::load("{$group}.db", $group, $language, true, true);
         static::$loaded[] = $group . '_' . $language;
     }
     // Don't continue if it's not the 'common' group
     if ($group != 'common') {
         return $output != null ? \Str::tr(\Fuel::value($output), $params) : $default;
     }
     $output = \Arr::get(static::$lines, "{$language}.{$line}");
     if ($output == null) {
         // First try and get from the fallback...
         $output = \Arr::get(static::$lines, static::$fallback[0] . ".{$line}");
         if (!in_array($group, static::$to_save)) {
             static::$to_save[] = $group;
         }
         //if (!empty($default) && $default != $line)
         static::set($line, $default);
         static::set($line, $default, null, static::$fallback[0]);
         if ($output == null) {
             $output = $default;
         }
     }
     return $output != null ? \Str::tr(\Fuel::value($output), $params) : $default;
 }
示例#4
0
 public function join($alias_from, $rel_name, $alias_to_nr, $conditions = array())
 {
     $alias_to = 't' . $alias_to_nr;
     $model = array('model' => $this->model_to, 'connection' => call_user_func(array($this->model_to, 'connection')), 'table' => array(call_user_func(array($this->model_to, 'table')), $alias_to), 'primary_key' => call_user_func(array($this->model_to, 'primary_key')), 'join_type' => \Arr::get($conditions, 'join_type') ?: \Arr::get($this->conditions, 'join_type', 'left'), 'join_on' => array(), 'columns' => $this->select($alias_to), 'rel_name' => strpos($rel_name, '.') ? substr($rel_name, strrpos($rel_name, '.') + 1) : $rel_name, 'relation' => $this, 'where' => \Arr::get($conditions, 'where', array()), 'order_by' => \Arr::get($conditions, 'order_by') ?: \Arr::get($this->conditions, 'order_by', array()));
     var_dump($model);
     exit;
     reset($this->key_to);
     foreach ($this->key_from as $key) {
         $key_to = current($this->key_to);
         $alias = array();
         if ($key instanceof \Fuel\Core\Database_Query_Builder_Select) {
             $key = $key->compile();
             $key = \Str::tr($key, array('alias_to' => $alias_to, 'alias_from' => $alias_from, $rel_name => $alias_to));
             $key = \DB::expr('(' . $key . ')');
             $alias[0] = $key;
         } else {
             $alias[0] = $alias_from . '.' . $key;
         }
         $alias[1] = '=';
         if ($key_to instanceof \Fuel\Core\Database_Query_Builder_Select) {
             $key_to = current($this->key_to);
             $key_to = $key_to->compile();
             $key_to = \Str::tr($key_to, array('alias_to' => $alias_to, 'alias_from' => $alias_from, $rel_name => $alias_to));
             $key_to = \DB::expr('(' . $key_to . ')');
             $alias[2] = $key_to;
         } else {
             $alias[2] = $alias_to . '.' . $key_to;
         }
         $model['join_on'][] = $alias;
         next($this->key_to);
     }
     foreach (array(\Arr::get($this->conditions, 'where', array()), \Arr::get($conditions, 'join_on', array())) as $c) {
         foreach ($c as $key => $condition) {
             !is_array($condition) and $condition = array($key, '=', $condition);
             if (!$condition[0] instanceof \Fuel\Core\Database_Expression and strpos($condition[0], '.') === false) {
                 $condition[0] = $alias_to . '.' . $condition[0];
             }
             is_string($condition[2]) and $condition[2] = \Db::quote($condition[2], $model['connection']);
             $model['join_on'][] = $condition;
         }
     }
     return array($rel_name => $model);
 }
示例#5
0
 /**
  * Fetch a line from the language
  *
  * @param   string  key for the line
  * @param   array   array of params to str_replace
  * @return  bool|string  either the line or false when not found
  * @depricated  Remove in v1.2
  */
 public static function line($line, array $params = array())
 {
     logger(\Fuel::L_WARNING, 'This method is deprecated. Please use Lang::get() instead.', __METHOD__);
     return \Str::tr(\Arr::get(static::$lines, $line, false), $params);
 }
示例#6
0
文件: lang.php 项目: wushian/MDD
 /**
  * Returns a (dot notated) language string
  *
  * @param   string       $line      key for the line
  * @param   array        $params    array of params to str_replace
  * @param   mixed        $default   default value to return
  * @param   string|null  $language  name of the language to get, null for the configurated language
  * @return  mixed                   either the line or default when not found
  */
 public static function get($line, array $params = array(), $default = null, $language = null)
 {
     if ($language === null) {
         $languages = static::$fallback;
         array_unshift($languages, $language ?: \Config::get('language'));
         $language = reset($languages);
     }
     return isset(static::$lines[$language]) ? \Str::tr(\Fuel::value(\Arr::get(static::$lines[$language], $line, $default)), $params) : $default;
 }
示例#7
0
 /**
  * Returns a (dot notated) language string
  *
  * @param   string       $line      key for the line
  * @param   array        $params    array of params to str_replace
  * @param   mixed        $default   default value to return
  * @param   string|null  $language  name of the language to get, null for the configurated language
  * @return  mixed                   either the line or default when not found
  */
 public static function get($line, array $params = array(), $default = null, $language = null)
 {
     $language === null and $language = static::get_lang();
     return isset(static::$lines[$language]) ? \Str::tr(\Fuel::value(\Arr::get(static::$lines[$language], $line, $default)), $params) : $default;
 }
示例#8
0
 /**
  * Compile the SQL query and return it. Replaces any parameters with their
  * given values.
  *
  * @param   mixed $db Database instance or instance name
  *
  * @return  string
  */
 public function compile($db = null)
 {
     if ($this->_connection !== null and $db === null) {
         $db = $this->_connection;
     }
     if (!$db instanceof \Database_Connection) {
         // Get the database instance
         $db = $this->_connection ?: \Database_Connection::instance($db);
     }
     // Import the SQL locally
     $sql = $this->_sql;
     if (!empty($this->_parameters)) {
         // Quote all of the values
         $values = array_map(array($db, 'quote'), $this->_parameters);
         // Replace the values in the SQL
         $sql = \Str::tr($sql, $values);
     }
     return trim($sql);
 }
示例#9
0
 /**
  * Returns a (dot notated) language string
  *
  * @param   string  key for the line
  * @param   array   array of params to str_replace
  * @param   mixed   default value to return
  * @return  mixed   either the line or default when not found
  */
 public static function get($line, array $params = array(), $default = null)
 {
     return \Str::tr(\Fuel::value(\Arr::get(static::$lines, $line, $default)), $params);
 }