コード例 #1
0
ファイル: helper.php プロジェクト: Nyaan/meintagebuchonline
 public static function slug($string, $replacement = '-')
 {
     $slug = UTF8::trim(UTF8::strtolower($string));
     $map = array('/ä/' => 'ae', '/ö/' => 'oe', '/ü/' => 'ue', '/щ/' => 'sch', '/ш/' => 'sh', '/ч/' => 'ch', '/ц/' => 'c', '/ю/' => 'yu', '/я/' => 'ya', '/ж/' => 'zh', '/а/' => 'a', '/б/' => 'b', '/в/' => 'v', '/г|ґ/' => 'g', '/д/' => 'd', '/е/' => 'e', '/ё/' => 'yo', '/з/' => 'z', '/и|і/' => 'i', '/й/' => 'y', '/к/' => 'k', '/л/' => 'l', '/м/' => 'm', '/н/' => 'n', '/о/' => 'o', '/п/' => 'p', '/р/' => 'r', '/с/' => 's', '/т/' => 't', '/у/' => 'u', '/ф/' => 'f', '/х/' => 'h', '/ы/' => 'y', '/э/' => 'e', '/є/' => 'ye', '/ї/' => 'yi', '/º|°/' => 0, '/¹/' => 1, '/²/' => 2, '/³/' => 3, '/à|á|å|â|ã|ä|ą|ă|ā|ª/' => 'a', '/@/' => 'at', '/æ/' => 'ae', '/ḃ/' => 'b', '/č|ç|¢|ć|ċ|ĉ|©/' => 'c', '/ď|ḋ|đ/' => 'd', '/€/' => 'euro', '/è|é|ê|ě|ẽ|ë|ę|ē|ė|ĕ/' => 'e', '/ƒ|ḟ/' => 'f', '/ģ|ğ|ĝ|ġ/' => 'g', '/ĥ|ħ/' => 'h', '/Ì|Í|Î|Ï/' => 'I', '/ì|í|î|ï|ĩ|ī|į|ı/' => 'i', '/ĵ/' => 'j', '/ķ/' => 'k', '/ł|ľ|ĺ|ļ/' => 'l', '/Ł/' => 'L', '/ṁ/' => 'm', '/ñ|ń|ņ|ň/' => 'n', '/ò|ó|ô|ø|õ|ö|ō|ð|ơ|ő/' => 'o', '/œ/' => 'oe', '/ṗ/' => 'p', '/ř|ŗ|ŕ|®/' => 'r', '/š|ś|ṡ|ş|ș/' => 's', '/ť|ț|ŧ|ţ|ṫ/' => 't', '/þ/' => 'th', '/ß/' => 'ss', '/™/' => 'tm', '/ù|ú|ů|û|ü|ū|ũ|ű|ŭ|ư|ų|µ/' => 'u', '/ẃ|ẅ|ẁ|ŵ/' => 'w', '/×/' => 'x', '/ÿ|ý|ỳ|ŷ|¥/' => 'y', '/Ž|Ż|Ź/' => 'Z', '/ž|ż|ź/' => 'z', '/\\s+/' => $replacement);
     $slug = preg_replace(array_keys($map), array_values($map), $slug);
     return URL::title($slug, $replacement);
 }
コード例 #2
0
ファイル: user.php プロジェクト: anqh/core
 /**
  * Magic setter
  *
  * @param  string  $key
  * @param  mixed   $value
  */
 public function __set($key, $value)
 {
     switch ($key) {
         // Date of birth
         case 'dob':
             $value = Date::format(Date::DATE_SQL, $value);
             break;
             // Always lowercase e-mail
         // Always lowercase e-mail
         case 'email':
             $value = UTF8::strtolower($value);
             break;
             // Hash password
         // Hash password
         case 'password':
             $visitor = Visitor::instance();
             $value = $visitor->hash_password($value);
             break;
             // Set cleaned username when setting username
         // Set cleaned username when setting username
         case 'username':
             $this->username_clean = Text::clean($value);
             break;
     }
     parent::__set($key, $value);
 }
コード例 #3
0
ファイル: str_ireplace.php プロジェクト: nevermlnd/cv
/**
 * UTF8::str_ireplace
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2010 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_ireplace($search, $replace, $str, & $count = NULL)
{
	if (UTF8::is_ascii($search) AND UTF8::is_ascii($replace) AND UTF8::is_ascii($str))
		return str_ireplace($search, $replace, $str, $count);

	if (is_array($str))
	{
		foreach ($str as $key => $val)
		{
			$str[$key] = UTF8::str_ireplace($search, $replace, $val, $count);
		}
		return $str;
	}

	if (is_array($search))
	{
		$keys = array_keys($search);

		foreach ($keys as $k)
		{
			if (is_array($replace))
			{
				if (array_key_exists($k, $replace))
				{
					$str = UTF8::str_ireplace($search[$k], $replace[$k], $str, $count);
				}
				else
				{
					$str = UTF8::str_ireplace($search[$k], '', $str, $count);
				}
			}
			else
			{
				$str = UTF8::str_ireplace($search[$k], $replace, $str, $count);
			}
		}
		return $str;
	}

	$search = UTF8::strtolower($search);
	$str_lower = UTF8::strtolower($str);

	$total_matched_strlen = 0;
	$i = 0;

	while (preg_match('/(.*?)'.preg_quote($search, '/').'/s', $str_lower, $matches))
	{
		$matched_strlen = strlen($matches[0]);
		$str_lower = substr($str_lower, $matched_strlen);

		$offset = $total_matched_strlen + strlen($matches[1]) + ($i * (strlen($replace) - 1));
		$str = substr_replace($str, $replace, $offset, strlen($search));

		$total_matched_strlen += $matched_strlen;
		$i++;
	}

	$count += $i;
	return $str;
}
コード例 #4
0
ファイル: autocomplete.php プロジェクト: MenZil-Team/cms
 /**
  * Retrieve a JSON object containing autocomplete suggestions for existing users.
  */
 public function action_tag()
 {
     $string = $this->request->param('string', FALSE);
     $type = $this->request->param('type', 'blog');
     // The user enters a comma-separated list of tags. We only autocomplete the last tag.
     $tags_typed = Tags::explode($string);
     $tag_last = UTF8::strtolower(array_pop($tags_typed));
     $matches = array();
     if (!empty($tag_last)) {
         $query = DB::select('name')->from('tags')->where('name', 'LIKE', $tag_last . '%')->where('type', '=', $type);
         // Do not select already entered terms.
         if (!empty($tags_typed)) {
             $query->where('name', 'NOT IN', $tags_typed);
         }
         $result = $query->limit('10')->execute();
         $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : '';
         foreach ($result as $tag) {
             $n = $tag['name'];
             // Tag names containing commas or quotes must be wrapped in quotes.
             if (strpos($tag['name'], ',') !== FALSE or strpos($tag['name'], '"') !== FALSE) {
                 $n = '"' . str_replace('"', '""', $tag['name']) . '"';
             } else {
                 $matches[$prefix . $n] = Text::plain($tag['name']);
             }
         }
     }
     $this->response->body(JSON::encode($matches));
 }
コード例 #5
0
ファイル: Inflector.php プロジェクト: eok8177/shopCMS
 /**
  * Returns a string with all spaces converted to underscores (by default), accented
  * characters converted to non-accented characters, and non word characters removed.
  *
  * @static
  *
  * @param        $string      the string you want to slug
  * @param string $replacement will replace keys in map
  * @param bool $tolower все в нижний регистр
  *
  * @return mixed
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::slug
  */
 public static function slug($string, $replacement = '-', $tolower = false)
 {
     $string = $tolower ? UTF8::strtolower($string) : $string;
     $quoted_replacement = preg_quote($replacement, '/');
     $merge = ['/[^\\s\\p{Ll}\\p{Lm}\\p{Lo}\\p{Lt}\\p{Lu}\\p{Nd}]/mu' => ' ', '/\\s+/' => $replacement, sprintf('/^[%s]+|[%s]+$/', $quoted_replacement, $quoted_replacement) => ''];
     $map = self::$_transliteration + $merge;
     return preg_replace(array_keys($map), array_values($map), $string);
 }
コード例 #6
0
/**
 * UTF8::strcasecmp
 *
 * @package    JsonApiApplication
 * @author     JsonApiApplication Team
 * @copyright  (c) 2007-2012 JsonApiApplication Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strcasecmp($str1, $str2)
{
    if (UTF8::is_ascii($str1) and UTF8::is_ascii($str2)) {
        return strcasecmp($str1, $str2);
    }
    $str1 = UTF8::strtolower($str1);
    $str2 = UTF8::strtolower($str2);
    return strcmp($str1, $str2);
}
コード例 #7
0
 public static function title($title, $separator = '-', $ascii_only = FALSE)
 {
     if ($ascii_only === TRUE) {
         $title = UTF8::transliterate_to_ascii($title);
         $title = preg_replace('![^' . preg_quote($separator) . 'a-z0-9\\s]+!', '', strtolower($title));
     } else {
         $title = preg_replace('![^' . preg_quote($separator) . '\\pL\\pN\\s]+!u', '', UTF8::strtolower($title));
     }
     $title = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $title);
     return trim($title, $separator);
 }
コード例 #8
0
ファイル: indexer.php プロジェクト: ZerGabriel/cms-1
 protected function _prepare_data($title, $content = '')
 {
     if (is_array($content)) {
         $content = implode(' ', $content);
     }
     if (is_array($title)) {
         $title = implode(' ', $title);
     }
     $title = UTF8::strtolower($title);
     $content = UTF8::strtolower($content);
     $title = $this->_get_stemmed_text($title);
     $content = $this->_get_stemmed_text($content);
     return array($title, $content);
 }
コード例 #9
0
 function clean_file_name($file_name, $separator = '-', $lowercase = false, $language = NULL)
 {
     $extension = UTF8::strtolower(extension($file_name));
     if ($extension != '') {
         $file_name = substr($file_name, 0, -(strlen($extension) + 1));
     }
     $file_name = url_title($file_name, $separator, $lowercase, true, $language);
     if ($file_name == '') {
         $file_name = 'file';
     }
     if ($extension != '') {
         $file_name .= '.' . $extension;
     }
     return $file_name;
 }
コード例 #10
0
ファイル: stristr.php プロジェクト: gilyaev/framework-bench
/**
 * UTF8::stristr
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2011 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _stristr($str, $search)
{
    if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) {
        return stristr($str, $search);
    }
    if ($search == '') {
        return $str;
    }
    $str_lower = UTF8::strtolower($str);
    $search_lower = UTF8::strtolower($search);
    preg_match('/^(.*?)' . preg_quote($search_lower, '/') . '/s', $str_lower, $matches);
    if (isset($matches[1])) {
        return substr($str, strlen($matches[1]));
    }
    return FALSE;
}
コード例 #11
0
ファイル: mysql.php プロジェクト: ZerGabriel/cms-1
 /**
  * 
  * @param string $keyword
  * @return string
  */
 public function stem_query($keyword)
 {
     $result = '';
     $text = UTF8::strtolower($keyword);
     $text = trim($text);
     $text = strip_tags($text);
     $stop_words = Model_Search_Stopwords::get();
     // Parse original text and stem all words that are not tags
     $tkn = new Model_Search_Tokenizer();
     $tkn->set_text($text);
     $tkn->stopwords = $stop_words;
     $stemmer = new Model_Search_Stemmer($tkn);
     while ($cur = $tkn->next()) {
         $result .= $stemmer->stem($cur);
     }
     return $result;
 }
コード例 #12
0
ファイル: model.php プロジェクト: anqh/core
 /**
  * Extract model name from model.
  *
  *  Model::model_name('Model_User') => 'user'
  *  Model_User::model_name() => 'user'
  *
  * @static
  * @param   string|Model  $model
  * @return  string
  *
  * @throws  Kohana_Exception
  */
 public static function model_name($model = null)
 {
     if (is_null($model)) {
         // Get current model
         $model = get_called_class();
     } else {
         if (is_object($model)) {
             // Model is a model
             $model = get_class($model);
         } else {
             if (!is_string($model)) {
                 // Invalid
                 throw new Kohana_Exception(':model is not a proper model.', array(':model' => $model));
             }
         }
     }
     $model = UTF8::strtolower($model ? $model : get_called_class());
     return strpos($model, $prefix = 'model_') === 0 ? substr($model, strlen($prefix)) : $model;
 }
コード例 #13
0
ファイル: file.php プロジェクト: MenZil-Team/cms
 /**
  * Generate a unique filename to avoid conflicts
  *
  * @since   1.0.1
  *
  * @param   string   $name           Filename [Optional]
  * @param   integer  $length         Length of filename to return [Optional]
  * @param   boolean  $remove_spaces  Remove spaces from file name [Optional]
  * @param   string   $replacement    Replacement for spaces [Optional]
  *
  * @return  string
  *
  * @uses    Text::random
  * @uses    UTF8::strtolower
  */
 public static function getUnique($name = NULL, $length = 20, $remove_spaces = TRUE, $replacement = '_')
 {
     if (is_null($name)) {
         return UTF8::strtolower(uniqid() . Text::random('alnum', (int) $length));
     } else {
         // Find the file extension
         $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
         // Remove the extension from the filename
         $name = substr($name, 0, -(strlen($ext) + 1));
         $retval = uniqid() . ($remove_spaces ? preg_replace('/\\s+/u', $replacement, $name) : $name);
         $retval = is_null($length) ? $retval : substr($retval, 0, (int) $length);
         $retval = $retval . '.' . $ext;
         return $retval;
     }
 }
コード例 #14
0
ファイル: Gravatar.php プロジェクト: patilstar/HMVC-WITH-CI
 /**
  * Creates a hash value from a provided e-mail address.
  * @link https://en.gravatar.com/site/implement/hash/
  *
  * @param   string      $email      A registered email.
  * @return  string/null             The hash for accessing the avatar or profile data.
  */
 public function create_hash($email)
 {
     // Modified by Deepak Patil <*****@*****.**>, 09-JAN-2015.
     //return md5(strtolower(trim($email)));
     return md5(UTF8::strtolower(trim($email)));
     //
 }
コード例 #15
0
 /**
  * Humanize
  *
  * Takes multiple words separated by the separator and changes them to spaces
  *
  * @param       string      $str            Input string
  * @param       string      $separator      Input separator
  * @return      string
  */
 function humanize($str, $separator = '_')
 {
     return UTF8::ucwords(preg_replace('/[' . preg_quote($separator) . ']+/' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), ' ', UTF8::trim(UTF8::strtolower($str))));
 }
コード例 #16
0
ファイル: UTF8Test.php プロジェクト: azuya/Wi3
 /**
  * Tests UTF8::strtolower
  *
  * @test
  * @dataProvider provider_strtolower
  */
 public function test_strtolower($input, $expected)
 {
     $this->assertSame($expected, UTF8::strtolower($input));
     UTF8::$server_utf8 = !UTF8::$server_utf8;
     $this->assertSame($expected, UTF8::strtolower($input));
     UTF8::$server_utf8 = !UTF8::$server_utf8;
 }
コード例 #17
0
 /**
  * @return array
  */
 public function get_editable_types()
 {
     if ($this->is_superadmin()) {
         return array(self::TYPE_SUPERADMIN => UTF8::ucfirst(__(UTF8::strtolower(self::TYPE_SUPERADMIN))), self::TYPE_ADMIN => UTF8::ucfirst(__(UTF8::strtolower(self::TYPE_ADMIN))), self::TYPE_INTERNAL => UTF8::ucfirst(__(UTF8::strtolower(self::TYPE_INTERNAL))));
     }
     if ($this->is_only_admin()) {
         return array(self::TYPE_EXTERNAL => UTF8::ucfirst(__(UTF8::strtolower(self::TYPE_EXTERNAL))));
     }
     return array();
 }
コード例 #18
0
ファイル: multiupload.php プロジェクト: greor/kohana-photo
 public function action_upload()
 {
     $this->auto_render = FALSE;
     $request = $this->request->current();
     $post = $request->post();
     $album_id = (int) Arr::get($post, 'album');
     $to_head = Arr::get($post, 'to_head') === 'true';
     $album_orm = ORM::factory('photo_Album')->where('id', '=', $album_id)->find();
     if (!$album_orm->loaded() or !$this->acl->is_allowed($this->user, $album_orm, 'edit')) {
         throw new HTTP_Exception_404();
     }
     $response = array('jsonrpc' => '2.0', 'id' => 'id');
     /* $target_dir */
     $target_dir = str_replace('/', DIRECTORY_SEPARATOR, DOCROOT . Kohana::$config->load('_photo.multiupload_dir'));
     if (!is_dir($target_dir)) {
         Ku_Dir::make($target_dir, 0755);
     }
     if (is_dir($target_dir) && ($dir = opendir($target_dir))) {
         while (($file = readdir($dir)) !== false) {
             $tmp_file_path = $target_dir . DIRECTORY_SEPARATOR . $file;
             /* Remove temp file if it is older than the max age and is not the current file */
             if (preg_match('/\\.part$/', $file) and filemtime($tmp_file_path) < time() - $this->max_file_age and $tmp_file_path != "{$file_path}.part") {
                 @unlink($tmp_file_path);
             }
         }
         closedir($dir);
     } else {
         $response['error'] = array('code' => 100, 'message' => 'Failed to open temp directory.');
         $this->json_send($response);
         return;
     }
     /* $chunk, $chunks */
     $chunk = Arr::get($post, 'chunk', 0);
     $chunks = Arr::get($post, 'chunks', 0);
     /* $file_name */
     $file_name = Arr::get($post, 'name', '');
     $file_name = preg_replace('/[^\\w\\._]+/', '_', $file_name);
     $ext = UTF8::strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
     if (!preg_match('/^jpe?g$/s', $ext)) {
         $response['error'] = array('code' => 105, 'message' => 'Invalid file type.');
         $this->json_send($response);
         return;
     }
     if ($chunks < 2 and file_exists($target_dir . DIRECTORY_SEPARATOR . $file_name)) {
         $ext = strrpos($file_name, '.');
         $file_name_a = substr($file_name, 0, $ext);
         $file_name_b = substr($file_name, $ext);
         $count = 1;
         while (file_exists($target_dir . DIRECTORY_SEPARATOR . $file_name_a . '_' . $count . $file_name_b)) {
             $count++;
         }
         $file_name = $file_name_a . '_' . $count . $file_name_b;
     }
     /* $file_path */
     $file_path = $target_dir . DIRECTORY_SEPARATOR . $file_name;
     $_h = $request->headers('http-content-type');
     $content_type = empty($_h) ? '' : $_h;
     $_h = $request->headers('content-type');
     $content_type = empty($_h) ? $content_type : $_h;
     /* Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 */
     if (strpos($content_type, "multipart") !== false) {
         if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
             if ($out = fopen("{$file_path}.part", $chunk == 0 ? "wb" : "ab")) {
                 if ($in = fopen($_FILES['file']['tmp_name'], "rb")) {
                     while ($buff = fread($in, 4096)) {
                         fwrite($out, $buff);
                     }
                 } else {
                     $response['error'] = array('code' => 101, 'message' => 'Failed to open input stream.');
                     $this->json_send($response);
                     return;
                 }
                 fclose($in);
                 fclose($out);
                 @unlink($_FILES['file']['tmp_name']);
             } else {
                 $response['error'] = array('code' => 102, 'message' => 'Failed to open output stream.');
                 $this->json_send($response);
                 return;
             }
         } else {
             $response['error'] = array('code' => 103, 'message' => 'Failed to move uploaded file.');
             $this->json_send($response);
             return;
         }
     } else {
         if ($out = fopen("{$file_path}.part", $chunk == 0 ? "wb" : "ab")) {
             if ($in = fopen("php://input", "rb")) {
                 while ($buff = fread($in, 4096)) {
                     fwrite($out, $buff);
                 }
             } else {
                 $response['error'] = array('code' => 101, 'message' => 'Failed to open input stream.');
                 $this->json_send($response);
                 return;
             }
             fclose($in);
             fclose($out);
         } else {
             $response['error'] = array('code' => 102, 'message' => 'Failed to open output stream.');
             $this->json_send($response);
             return;
         }
     }
     /* Check if file has been uploaded */
     if (!$chunks or $chunk == $chunks - 1) {
         /* Strip the temp .part suffix off */
         rename("{$file_path}.part", $file_path);
         $save_result = $this->save_file($file_path, $album_orm, $to_head);
         if ($save_result !== TRUE) {
             $response['error'] = array('code' => 104, 'message' => $save_result);
             $this->json_send($response);
             return;
         }
     }
     /* Return JSON-RPC response */
     $response['result'] = NULL;
     $this->json_send($response);
 }
コード例 #19
0
ファイル: property.php プロジェクト: greor/satin-spb
 /**
  * Search owner_id by condition (only for 'simple', 'file' and 'enum' types).
  * Don't search by 'text' properties
  *
  * Condition support format:
  * 		'field_name' => 'value_1'
  * 				 - equal 'field_name' = 'value_1'
  * 		'field_name' => array('operator', 'value_1')
  * 				 - equal 'field_name' 'operator' 'value_1'
  * 		'field_name' => array('operator', array('value_1'))
  * 				 - equal 'field_name' 'operator' ('value_1')
  *
  * Example:
  * 		$where = array(
  *			'field_1' => 'value_1',
  *			'OR',
  *			'field_2' => array('IN', array('value_2', 'value_3')),
  *		);
  *
  * Generated in:
  *		'field_1' = 'value_1'
  *		OR
  *		'field_2' IN ('value_2', 'value_3')
  *
  *
  * @param string $owner
  * @param array $where
  * @param bool $bulder will return as builder
  * @return array
  */
 public function search($where = array(), $bulder = FALSE)
 {
     $table_name = $this->_orm_helper->orm()->table_name();
     $table_enum_name = $this->_orm_helper->orm()->enum->table_name();
     $builder = DB::select('owner_id')->from($table_name)->where('owner', '=', $this->_owner)->where('delete_bit', '=', 0);
     if (!empty($where)) {
         $builder->where_open();
         $method = NULL;
         foreach ($where as $_name => $_condition) {
             if (is_int($_name)) {
                 // logic operator
                 $_condition = UTF8::strtolower($_condition);
                 switch ($_condition) {
                     case 'or':
                         $method = 'or_where';
                         break;
                     case 'and':
                         $method = 'and_where';
                         break;
                 }
             } else {
                 // condition
                 if ($method === NULL) {
                     $method = 'and_where';
                 }
                 $_op = $_val = '';
                 if (is_array($_condition)) {
                     $_op = $_condition[0];
                     $_val = $_condition[1];
                 } else {
                     $_op = '=';
                     $_val = $_condition;
                 }
                 $_type = $this->get_type($_name);
                 switch ($_type['type']) {
                     case 'simple':
                     case 'file':
                         $builder->{$method . '_open'}()->where('name', '=', $_name)->where('value', $_op, $_val)->{$method . '_close'}();
                         break;
                     case 'enum':
                         $_val = $this->_enum_get_id($_type['set'], $_val);
                         if (!empty($_val)) {
                             $_sub = DB::select('property_id')->from($table_enum_name)->where('value_id', 'IN', $_val);
                             $builder->{$method . '_open'}()->where('name', '=', $_name)->where('id', 'IN', $_sub)->{$method . '_close'}();
                         }
                         break;
                 }
                 $method = NULL;
             }
         }
         $builder->where_close();
     }
     if ($bulder) {
         return $builder;
     } else {
         return $builder->execute()->as_array(NULL, 'id');
     }
 }
コード例 #20
0
 /**
  * Timespan
  *
  * Returns a span of seconds in this format:
  *    10 days 14 hours 36 minutes 47 seconds
  *
  * @param       int     a number of seconds
  * @param       int     Unix timestamp
  * @param       int     a number of display units
  * @return      string
  */
 function timespan($seconds = 1, $time = '', $units = 7)
 {
     $CI =& get_instance();
     $CI->lang->load('date');
     is_numeric($seconds) or $seconds = 1;
     is_numeric($time) or $time = time();
     is_numeric($units) or $units = 7;
     $seconds = $time <= $seconds ? 1 : $time - $seconds;
     $str = array();
     $years = floor($seconds / 31557600);
     if ($years > 0) {
         $str[] = $years . ' ' . $CI->lang->line($years > 1 ? 'date_years' : 'date_year');
     }
     $seconds -= $years * 31557600;
     $months = floor($seconds / 2629743);
     if (count($str) < $units && ($years > 0 or $months > 0)) {
         if ($months > 0) {
             $str[] = $months . ' ' . $CI->lang->line($months > 1 ? 'date_months' : 'date_month');
         }
         $seconds -= $months * 2629743;
     }
     $weeks = floor($seconds / 604800);
     if (count($str) < $units && ($years > 0 or $months > 0 or $weeks > 0)) {
         if ($weeks > 0) {
             $str[] = $weeks . ' ' . $CI->lang->line($weeks > 1 ? 'date_weeks' : 'date_week');
         }
         $seconds -= $weeks * 604800;
     }
     $days = floor($seconds / 86400);
     if (count($str) < $units && ($months > 0 or $weeks > 0 or $days > 0)) {
         if ($days > 0) {
             $str[] = $days . ' ' . $CI->lang->line($days > 1 ? 'date_days' : 'date_day');
         }
         $seconds -= $days * 86400;
     }
     $hours = floor($seconds / 3600);
     if (count($str) < $units && ($days > 0 or $hours > 0)) {
         if ($hours > 0) {
             $str[] = $hours . ' ' . $CI->lang->line($hours > 1 ? 'date_hours' : 'date_hour');
         }
         $seconds -= $hours * 3600;
     }
     $minutes = floor($seconds / 60);
     if (count($str) < $units && ($days > 0 or $hours > 0 or $minutes > 0)) {
         if ($minutes > 0) {
             $str[] = $minutes . ' ' . $CI->lang->line($minutes > 1 ? 'date_minutes' : 'date_minute');
         }
         $seconds -= $minutes * 60;
     }
     if (count($str) === 0) {
         $str[] = $seconds . ' ' . $CI->lang->line($seconds > 1 ? 'date_seconds' : 'date_second');
     }
     // Modified by Ivan Tcholakov, 06-FEB-2016.
     //return implode(', ', $str);
     $result = implode(', ', $str);
     switch ($CI->lang->current()) {
         case 'english':
         case 'bulgarian':
             $result = IS_UTF8_CHARSET ? UTF8::strtolower($result) : strtolower($result);
             break;
     }
     return $result;
     //
 }
コード例 #21
0
 public function display_allowed_sizes()
 {
     $result = array();
     if (!empty($this->max_size)) {
         $this->load->helper('number');
         $label = $this->lang->line('ui_max_file_size');
         $result[] = $label . ': ' . byte_format(1024 * $this->max_size, 0);
     }
     if (!empty($this->max_width)) {
         $label = $this->lang->line('ui_max_width');
         if ($this->lang->current() == 'bulgarian' && count($result) > 0) {
             $label = UTF8::strtolower($label);
         }
         $result[] = $label . ': ' . $this->max_width . ' px';
     }
     if (!empty($this->max_height)) {
         $label = $this->lang->line('ui_max_height');
         if ($this->lang->current() == 'bulgarian' && count($result) > 0) {
             $label = UTF8::strtolower($label);
         }
         $result[] = $label . ': ' . $this->max_height . ' px';
     }
     $result = implode('; ', $result);
     return $result;
 }
コード例 #22
0
/**
 * UTF8::stripos
 *
 * @copyright  (c) 2015 Ivan Tcholakov
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _stripos($str, $search, $offset = 0)
{
    return UTF8::strpos(UTF8::strtolower($str), UTF8::strtolower($search), $offset);
}
コード例 #23
0
ファイル: UTF8Test.php プロジェクト: reznikds/Reznik
 /**
  * Tests UTF8::strtolower
  *
  * @test
  * @dataProvider provider_strtolower
  */
 public function test_strtolower($input, $expected)
 {
     $this->assertSame($expected, UTF8::strtolower($input));
 }
コード例 #24
0
ファイル: Route.php プロジェクト: bikramjeetbajwa/trackddb
 /**
  * Tests if the route matches a given Request. A successful match will return
  * all of the routed parameters as an array. A failed match will return
  * boolean FALSE.
  *
  *     // Params: controller = users, action = edit, id = 10
  *     $params = $route->matches(Request::factory('users/edit/10'));
  *
  * This method should almost always be used within an if/else block:
  *
  *     if ($params = $route->matches($request))
  *     {
  *         // Parse the parameters
  *     }
  *
  * @param   Request $request  Request object to match
  * @return  array             on success
  * @return  FALSE             on failure
  * @uses    Lang::$i18n_routes
  * @uses    Route::matches
  * @uses    Route::remap
  * @uses    Request::$lang
  * @uses    Lang::$default
  * @uses    HTTP_Exception_404
  */
 public function matches(Request $request)
 {
     if (!Lang::$i18n_routes) {
         // i18n routes are off
         return parent::matches($request);
     }
     // Set params
     $params = parent::matches($request);
     if ($params !== FALSE) {
         foreach ($params as $label => &$param) {
             if (isset($this->_translate['<' . $label . '>']) or isset($this->_translate[$param])) {
                 // If param might be translated see if it needs to be
                 // converted back to application (source) language
                 $source_param = Route::remap(UTF8::strtolower($param));
                 if (Request::$lang !== Lang::$default and isset($this->_translate['<' . $label . '>']) and $source_param === $param and strtolower($param) !== $this->_defaults[$label]) {
                     // To avoid duplicate content throw 404
                     throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => $request->uri()));
                 }
                 // Set translated param
                 $param = UTF8::ucfirst($source_param);
             }
         }
         // Return URI converted back to application (source) language
         return $params;
     } else {
         // No match
         return FALSE;
     }
 }
コード例 #25
0
 function url_title($str, $separator = '-', $lowercase = FALSE, $transliterate_to_ascii = TRUE, $language = NULL)
 {
     $language = (string) $language;
     if ($language == '') {
         $language = config_item('language');
     }
     $str = strip_tags($str);
     if ($transliterate_to_ascii) {
         $str = Transliterate::to_ascii($str, $language);
     }
     if ($separator === 'dash') {
         $separator = '-';
     } elseif ($separator === 'underscore') {
         $separator = '_';
     }
     $q_separator = preg_quote($separator);
     if (PCRE_UTF8_INSTALLED) {
         $trans = array('&.+?;' => '', '[^\\p{L}0-9 _-]' => '', '\\s+' => $separator, '(' . $q_separator . ')+' => $separator);
         foreach ($trans as $key => $val) {
             $str = preg_replace('#' . $key . '#u', $val, $str);
         }
     } else {
         $trans = array('&.+?;' => '', '[^a-z0-9 _-]' => '', '\\s+' => $separator, '(' . $q_separator . ')+' => $separator);
         foreach ($trans as $key => $val) {
             $str = preg_replace('#' . $key . '#i', $val, $str);
         }
     }
     if ($lowercase) {
         $str = UTF8::strtolower($str);
     }
     return trim(trim($str, $separator));
 }
コード例 #26
0
ファイル: Gravatar.php プロジェクト: aslijiasheng/ciFramework
 /**
  * Creates a hash value from a provided e-mail address.
  * @link https://en.gravatar.com/site/implement/hash/
  *
  * @param   string      $email      A registered email.
  * @return  string/null             The hash for accessing the avatar or profile data.
  */
 public function create_hash($email)
 {
     // Modified by Ivan Tcholakov, 09-JAN-2015.
     //return md5(strtolower(trim($email)));
     return md5(UTF8::strtolower(trim($email)));
     //
 }
コード例 #27
0
ファイル: url.php プロジェクト: hbarroso/Goworkat
 /**
  * Convert a phrase to a URL-safe title.
  *
  *     echo URL::title('My Blog Post'); // "my-blog-post"
  *
  * @param   string   $title       Phrase to convert
  * @param   string   $separator   Word separator (any single character)
  * @param   boolean  $ascii_only  Transliterate to ASCII?
  * @return  string
  * @uses    UTF8::transliterate_to_ascii
  */
 public static function title($title, $separator = '-', $ascii_only = FALSE)
 {
     if ($ascii_only === TRUE) {
         // Transliterate non-ASCII characters
         $title = UTF8::transliterate_to_ascii($title);
         // Remove all characters that are not the separator, a-z, 0-9, or whitespace
         $title = preg_replace('![^' . preg_quote($separator) . 'a-z0-9\\s]+!', $separator, strtolower($title));
     } else {
         // Remove all characters that are not the separator, letters, numbers, or whitespace
         $title = preg_replace('![^' . preg_quote($separator) . '\\pL\\pN\\s]+!u', '', UTF8::strtolower($title));
     }
     // Replace all separator characters and whitespace by a single separator
     $title = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $title);
     // Trim separators from the beginning and end
     return trim($title, $separator);
 }
コード例 #28
0
ファイル: path.php プロジェクト: ultimateprogramer/cms
 /**
  * Clean up a string segment to be used in an URL alias
  *
  * Performs the following possible alterations:
  * - Remove all HTML tags
  * - Replace or remove punctuation with the separator character
  * - Remove back-slashes
  * - Replace non-ascii and non-numeric characters with the separator
  * - Remove common words
  * - Replace whitespace with the separator character
  * - Trim duplicate, leading, and trailing separators
  * - Convert to lower-case
  * - Shorten to a desired length and logical position based on word boundaries
  *
  * @param   string  $string  A string to clean
  * @return  string  The cleaned string
  */
 public static function clean($string)
 {
     $separator = '-';
     // Empty strings do not need any proccessing.
     if ($string === '' || $string === NULL) {
         return '';
     }
     // Remove all HTML tags from the string.
     $string = strip_tags($string);
     //Replace all characters that are not the separator, letters, numbers, or whitespace
     $string = preg_replace('![^' . preg_quote($separator) . '\\pL\\pN\\/\\s]+!u', $separator, $string);
     // Replace all separator characters and whitespace by a single separator
     $string = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $string);
     //convert to lower case.
     $string = UTF8::strtolower($string);
     // Trim separators from the beginning and end
     return trim($string, $separator);
 }
コード例 #29
0
ファイル: user.php プロジェクト: anqh/anqh
 /**
  * Action: settings
  */
 public function action_settings()
 {
     $this->history = false;
     $user = $this->_get_user();
     Permission::required($user, Model_User::PERMISSION_UPDATE);
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Login information
         if ($user->username !== Arr::get($_POST, 'username') || $user->email !== UTF8::strtolower(Arr::get($_POST, 'email')) || Arr::get($_POST, 'password')) {
             $visitor = Visitor::instance();
             $old_password = Arr::get($_POST, 'current_password');
             $new_password = Arr::get($_POST, 'password');
             $validation = Validation::factory(array('current_password' => $old_password));
             $validation->rule('current_password', 'not_empty');
             if (!$visitor->check_password($old_password) && Visitor::generate_password($user->password_kohana) !== $old_password) {
                 $validation->rule('current_password', 'equals', array(':validation', __('current password')));
             } else {
                 if ($new_password) {
                     // Change password only if correct old one given
                     $user->password_kohana = $new_password;
                 }
             }
             $user->username = Arr::get($_POST, 'username');
             $user->email = Arr::get($_POST, 'email');
         }
         $user->set_fields(Arr::intersect($_POST, Model_User::$editable_fields));
         // Settings
         $name_visiblity = Arr::get($_POST, 'name_visibility');
         if (in_array($name_visiblity, array(Model_User::NAME_HIDDEN, Model_User::NAME_VISIBLE))) {
             $user->setting('user.name', $name_visiblity);
         }
         $dob_visiblity = Arr::get($_POST, 'dob_visibility');
         if (in_array($dob_visiblity, array(Model_User::DOB_DATEONLY, Model_User::DOB_HIDDEN, Model_User::DOB_VISIBLE))) {
             $user->setting('user.dob', $dob_visiblity);
         }
         // Clear default image id if Facebook image is set
         if (Arr::get($_POST, 'picture')) {
             $user->default_image_id = null;
         }
         $user->modified = time();
         try {
             $user->save(isset($validation) ? $validation : null);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->view = self::_set_page($user);
     $this->view->add(View_Page::COLUMN_TOP, $this->section_settings($user, $errors));
 }
コード例 #30
0
ファイル: widgets.php プロジェクト: ultimateprogramer/cms
 protected function is_visible($widget)
 {
     static $current_route;
     $widget->visible = TRUE;
     if (is_null($current_route)) {
         $current_route = Request::current()->uri();
         $current_route = UTF8::strtolower($current_route);
     }
     // role based widget access
     if (!User::belongsto($widget->roles)) {
         $widget->visible = FALSE;
     }
     if ($widget->pages) {
         $pages = UTF8::strtolower($widget->pages);
         $page_match = Path::match_path($current_route, $pages);
         $widget->visible = !($widget->visibility xor $page_match);
     }
     return $widget;
 }