本文整理汇总了PHP中MultiByte类的典型用法代码示例。如果您正苦于以下问题:PHP MultiByte类的具体用法?PHP MultiByte怎么用?PHP MultiByte使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MultiByte类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_htpasswd
public function parse_htpasswd($passwdfile)
{
$lines = file($passwdfile);
$users = array();
$i = 0;
foreach ($lines as $line) {
// if there is no :, assume this is a username with a newline
if (MultiByte::strpos($line, ':') === false) {
// append the next line to it
$line = $line . $lines[$i + 1];
// unset the next line
unset($lines[$i + 1]);
}
list($username, $password) = explode(':', $line);
// trim the username and password
$username = trim($username);
$password = trim($password);
if ($username == '' || $password == '') {
continue;
}
$users[$username] = $password;
$i++;
}
return $users;
}
示例2: action_ajax_auto_tags
/**
* Respond to Javascript callbacks
* The name of this method is action_ajax_ followed by what you passed to the context parameter above.
*/
public function action_ajax_auto_tags( $handler )
{
$selected = array();
if( isset( $handler->handler_vars['selected'] ) ) {
$selected = Utils::single_array( $handler->handler_vars['selected'] );
}
if( isset( $handler->handler_vars['term'] ) && MultiByte::strlen( $handler->handler_vars['term'] ) ) {
$search = $handler->handler_vars['term'] . '%';
$tags = new Terms( DB::get_results( "SELECT * FROM {terms} WHERE vocabulary_id = :vid and LOWER(term_display) LIKE LOWER(:crit) ORDER BY term_display ASC", array( 'vid' => Tags::vocabulary()->id, 'crit' => $search ), 'Term' ) );
}
else {
$tags = Tags::vocabulary()->get_tree( 'term_display ASC' );
}
$resp = array();
foreach ( $tags as $tag ) {
$resp[] = MultiByte::strpos( $tag->term_display, ',' ) === false ? $tag->term_display : $tag->tag_text_searchable;
}
if( count( $selected ) ) {
$resp = array_diff($resp, $selected );
}
// Send the response
// $ar = new AjaxResponse();
// $ar->data = $resp;
// $ar->out();
echo json_encode( $resp );
}
示例3: test_strtolower
function test_strtolower()
{
$this->assert_equal(MultiByte::strtolower(self::$test_str), mb_strtolower(mb_convert_encoding(self::$test_str, 'UTF-8', mb_detect_encoding(self::$test_str)), 'UTF-8'));
printf("Test string: %s <br>", self::$test_str);
printf("MultiByte strtolower: %s <br>", MultiByte::strtolower(self::$test_str));
printf("mbstring strtolower without detecting encoding: %s <br>", mb_strtolower(self::$test_str));
printf("mstring strtolower with detecting encoding: %s <br><br>", mb_strtolower(self::$test_str, mb_detect_encoding(self::$test_str)));
}
示例4: filter
/**
* Perform all filtering, return new string.
* @param string $str Input string.
* @return string Filtered output string.
*/
public static function filter($str)
{
if (!MultiByte::valid_data($str)) {
return '';
} else {
do {
$_str = $str;
$str = self::strip_nulls($str);
$str = self::strip_illegal_entities($str);
$str = self::filter_html_elements($str);
} while ($str != $_str);
return $str;
}
}
示例5: setup_admin_theme
/**
* Create the admin theme instance
*
* @param string $page The admin page requested
* @param string $type The content type included in the request
*/
public function setup_admin_theme($page, $type = '')
{
if (!isset($this->theme)) {
$theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', true));
$this->theme = Themes::create('_admin', 'RawPHPEngine', $theme_dir);
// Add some default template variables
$this->set_admin_template_vars($this->theme);
$this->theme->admin_type = $type;
$this->theme->admin_page = $page;
$this->theme->admin_page_url = $page == 'dashboard' ? URL::get('admin', 'page=') : URL::get('admin', 'page=' . $page);
$this->theme->page = $page;
$this->theme->admin_title = MultiByte::ucwords($page) . ($type != '' ? ' ' . MultiByte::ucwords($type) : '');
$this->theme->admin_title = isset($this->theme->mainmenu[$this->theme->admin_page]['text']) ? $this->theme->mainmenu[$this->theme->admin_page]['text'] : MultiByte::ucwords($page) . ($type != '' ? ' ' . MultiByte::ucwords($type) : '');
}
}
示例6: parse
/**
* Turns a comma-separated string or array of terms into an array of Term objects
* @param mixed $terms A comma-separated string or array of string terms
* @param string $term_class The class of the Term object type to create from each string
* @param Vocabulary $vocabulary An instance of the Vocabulary that might hold the terms.
* Use existing term object data if found in the specified vocabulary.
* @return Terms An instance of Terms contianing the specified Term objects
**/
public static function parse( $terms, $term_class = 'Term', $vocabulary = null )
{
if ( is_string( $terms ) ) {
if ( '' === $terms ) {
return new Terms();
}
$terms = trim( MultiByte::str_replace( '"', '"', $terms ) );
// dirrty ;)
$rez = array( '\\"'=>':__unlikely_quote__:', '\\\''=>':__unlikely_apos__:' );
$zer = array( ':__unlikely_quote__:'=>'"', ':__unlikely_apos__:'=>"'" );
// escape
$tagstr = str_replace( array_keys( $rez ), $rez, $terms );
// match-o-matic
preg_match_all( '/((("|((?<= )|^)\')\\S([^\\3]*?)\\3((?=[\\W])|$))|[^,])+/u', $tagstr, $matches );
// cleanup
$terms = array_map( 'trim', $matches[0] );
$terms = preg_replace( array_fill( 0, count( $terms ), '/^(["\'])(((?!").)+)(\\1)$/' ), '$2', $terms );
// unescape
$terms = str_replace( array_keys( $zer ), $zer, $terms );
// hooray
}
if ( is_array( $terms ) ) {
if ( $vocabulary instanceof Vocabulary ) {
foreach ( $terms as $k => $term ) {
if ( $saved_term = $vocabulary->get_term( $term, $term_class ) ) {
$terms[$k] = $saved_term;
}
else {
$terms[$k] = new $term_class( $term );
}
}
//Utils::debug($terms);
}
else {
array_walk( $terms, create_function( '&$tag', '$tag = new ' . $term_class . '($tag);' ) );
}
return new Terms( $terms );
}
return new Terms();
}
示例7: search_to_get
/**
* Parses a search string for status, type, author, and tag keywords. Returns
* an associative array which can be passed to Comments::get(). If multiple
* authors, statuses, or types are specified, we assume an implicit OR
* such that (e.g.) any author that matches would be returned.
*
* @param string $search_string The search string
* @return array An associative array which can be passed to Comments::get()
*/
public static function search_to_get($search_string)
{
$keywords = array('author' => 1, 'status' => 1, 'type' => 1);
// Comments::list_comment_statuses and list_comment_types return associative arrays with key/values
// in the opposite order of the equivalent functions in Posts. Maybe we should change this?
// In any case, we need to flip them for our purposes
$statuses = array_flip(Comment::list_comment_statuses());
$types = array_flip(Comment::list_comment_types());
$arguments = array('name' => array(), 'status' => array(), 'type' => array());
$criteria = '';
$tokens = explode(' ', $search_string);
foreach ($tokens as $token) {
// check for a keyword:value pair
if (preg_match('/^\\w+:\\S+$/u', $token)) {
list($keyword, $value) = explode(':', $token);
$keyword = strtolower($keyword);
$value = MultiByte::strtolower($value);
switch ($keyword) {
case 'author':
$arguments['name'][] = $value;
break;
case 'status':
if (isset($statuses[$value])) {
$arguments['status'][] = (int) $statuses[$value];
}
break;
case 'type':
if (isset($types[$value])) {
$arguments['type'][] = (int) $types[$value];
}
break;
}
} else {
$criteria .= $token . ' ';
}
}
// flatten keys that have single-element or no-element arrays
foreach ($arguments as $key => $arg) {
switch (count($arg)) {
case 0:
unset($arguments[$key]);
break;
case 1:
$arguments[$key] = $arg[0];
break;
}
}
if ($criteria != '') {
$arguments['criteria'] = $criteria;
}
return $arguments;
}
示例8: get
//.........这里部分代码省略.........
}
} else {
$where[] = 'type_id = ?';
$params[] = $paramset['type_id'];
}
}
if (isset($paramset['module'])) {
if (!is_array($paramset['module'])) {
$paramset['module'] = array($paramset['module']);
}
$where[] = 'type_id IN ( SELECT DISTINCT id FROM {log_types} WHERE module IN ( ' . implode(', ', array_fill(0, count($paramset['module']), '?')) . ' ) )';
$params = array_merge($params, $paramset['module']);
}
if (isset($paramset['type'])) {
if (!is_array($paramset['type'])) {
$paramset['type'] = array($paramset['type']);
}
$where[] = 'type_id IN ( SELECT DISTINCT id FROM {log_types} WHERE type IN ( ' . implode(', ', array_fill(0, count($paramset['type']), '?')) . ' ) )';
$params = array_merge($params, $paramset['type']);
}
if (isset($paramset['ip'])) {
$where[] = 'ip = ?';
$params[] = $paramset['ip'];
}
/* do searching */
if (isset($paramset['criteria'])) {
preg_match_all('/(?<=")(\\w[^"]*)(?=")|([:\\w]+)/u', $paramset['criteria'], $matches);
foreach ($matches[0] as $word) {
if (preg_match('%^id:(\\d+)$%i', $word, $special_crit)) {
$where[] .= '(id = ?)';
$params[] = $special_crit[1];
} else {
$where[] .= "( LOWER( message ) LIKE ? )";
$params[] = '%' . MultiByte::strtolower($word) . '%';
}
}
}
/**
* Build the pubdate
* If we've got the day, then get the date.
* If we've got the month, but no date, get the month.
* If we've only got the year, get the whole year.
*
* @todo Ensure that we've actually got all the needed parts when we query on them
*/
if (isset($paramset['day'])) {
$where[] = 'timestamp BETWEEN ? AND ?';
$start_date = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], $paramset['day']);
$start_date = HabariDateTime::date_create($start_date);
$params[] = $start_date->sql;
$params[] = $start_date->modify('+1 day')->sql;
//$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, $paramset['month'], $paramset['day'], $paramset['year'] ) );
//$params[] = date( 'Y-m-d H:i:s', mktime( 23, 59, 59, $paramset['month'], $paramset['day'], $paramset['year'] ) );
} elseif (isset($paramset['month'])) {
$where[] = 'timestamp BETWEEN ? AND ?';
$start_date = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1);
$start_date = HabariDateTime::date_create($start_date);
$params[] = $start_date->sql;
$params[] = $start_date->modify('+1 month')->sql;
//$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, $paramset['month'], 1, $paramset['year'] ) );
//$params[] = date( 'Y-m-d H:i:s', mktime( 23, 59, 59, $paramset['month'] + 1, 0, $paramset['year'] ) );
} elseif (isset($paramset['year'])) {
$where[] = 'timestamp BETWEEN ? AND ?';
$start_date = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1);
$start_date = HabariDateTime::date_create($start_date);
$params[] = $start_date->sql;
示例9: act_login
/**
* Either just display the login form; or check a user's credentials, and
* create a session for them; or handle a password reset request.
*/
public function act_login()
{
// If we're a reset password request, do that.
if (isset($_POST['submit_button']) && $_POST['submit_button'] === _t('Reset password')) {
Utils::check_request_method(array('POST'));
$name = $this->handler_vars['habari_username'];
if ($name !== NULL) {
if (!is_numeric($name) && ($user = User::get($name))) {
$hash = Utils::random_password();
$user->info->password_reset = md5($hash);
$user->info->commit();
$message = _t('Please visit %1$s to reset your password.', array(URL::get('user', array('page' => 'password_reset', 'id' => $user->id, 'hash' => $hash))));
Utils::mail($user->email, _t('[%1$s] Password reset request for %2$s', array(Options::get('title'), $user->displayname)), $message);
}
// Moving this inside the check for user existence would allow attackers to test usernames, so don't
Session::notice(_t('A password reset request has been sent to the user.'));
}
} else {
Utils::check_request_method(array('GET', 'HEAD', 'POST'));
$name = $_POST['habari_username'];
$pass = $_POST['habari_password'];
if (NULL != $name || NULL != $pass) {
$user = User::authenticate($name, $pass);
if ($user instanceof User && FALSE != $user) {
/* Successfully authenticated. */
// Timestamp last login date and time.
$user->info->authenticate_time = date('Y-m-d H:i:s');
$user->update();
// Remove left over expired session error message.
if (Session::has_errors('expired_session')) {
Session::remove_error('expired_session');
}
$login_session = Session::get_set('login');
if (!empty($login_session)) {
/* Now that we know we're dealing with the same user, transfer the form data so he does not lose his request */
if (!empty($login_session['post_data'])) {
Session::add_to_set('last_form_data', $last_form_data['post'], 'post');
}
if (!empty($login_session['get_data'])) {
Session::add_to_set('last_form_data', $last_form_data['get'], 'get');
}
/* Redirect to the correct admin page */
$dest = explode('/', MultiByte::substr($login_session['original'], MultiByte::strpos($login_session['original'], 'admin/')));
if ('' == $dest[0]) {
$login_dest = Site::get_url('admin');
} else {
// Replace '?' with '&' in $dest[1] before call URL::get()
// Therefore calling URL::get() with a query string
$dest[1] = str_replace('?', '&', $dest[1]);
$login_dest = URL::get('admin', 'page=' . $dest[1]);
}
} else {
$login_session = null;
$login_dest = Site::get_url('admin');
}
// filter the destination
$login_dest = Plugins::filter('login_redirect_dest', $login_dest, $user, $login_session);
// finally, redirect to the destination
Utils::redirect($login_dest);
return TRUE;
}
/* Authentication failed. */
// Remove submitted password, see, we're secure!
$_POST['habari_password'] = '';
$this->handler_vars['error'] = _t('Bad credentials');
}
}
// Display the login form.
$this->login_form($name);
}
示例10: truncate
/**
* Trims longer phrases to shorter ones with elipsis in the middle
* @param string $str The string to truncate
* @param integer $len The length of the returned string
* @param bool $middle Whether to place the ellipsis in the middle (true) or at the end (false)
* @return string The truncated string
*/
public static function truncate($str, $len = 10, $middle = true)
{
// make sure $len is a positive integer
if (!is_numeric($len) || 0 > $len) {
return $str;
}
// if the string is less than the length specified, bail out
if (MultiByte::strlen($str) <= $len) {
return $str;
}
// okay. Shuold we place the ellipse in the middle?
if ($middle) {
// yes, so compute the size of each half of the string
$len = round(($len - 3) / 2);
// and place an ellipse in between the pieces
return MultiByte::substr($str, 0, $len) . '…' . MultiByte::substr($str, -$len);
} else {
// no, the ellipse goes at the end
$len = $len - 3;
return MultiByte::substr($str, 0, $len) . '…';
}
}
示例11: get_contents
/**
* Static helper function to quickly fetch an URL, with semantics similar to
* PHP's file_get_contents. Does not support
*
* Returns the content on success or false if an error occurred.
*
* @param string $url The URL to fetch
* @param bool $use_include_path whether to search the PHP include path first (unsupported)
* @param resource $context a stream context to use (unsupported)
* @param int $offset how many bytes to skip from the beginning of the result
* @param int $maxlen how many bytes to return
* @return string description
*/
public static function get_contents($url, $use_include_path = false, $context = null, $offset = 0, $maxlen = -1)
{
try {
$rr = new RemoteRequest($url);
if ($rr->execute() === true) {
return $maxlen != -1 ? MultiByte::substr($rr->get_response_body(), $offset, $maxlen) : MultiByte::substr($rr->get_response_body(), $offset);
} else {
return false;
}
} catch (Exception $e) {
// catch any exceptions to try and emulate file_get_contents() as closely as possible.
// if you want more control over the errors, instantiate RemoteRequest manually
return false;
}
}
示例12: xmlrpc_pingback__ping
/**
* Receive a Pingback via XMLRPC
* @param array $params An array of XMLRPC parameters from the remote call
* @return string The success state of the pingback
*/
public function xmlrpc_pingback__ping($params)
{
try {
list($source_uri, $target_uri) = $params;
// This should really be done by an Habari core function
$target_parse = InputFilter::parse_url($target_uri);
$target_stub = $target_parse['path'];
$base_url = Site::get_path('base', TRUE);
if ('/' != $base_url) {
$target_stub = str_replace($base_url, '', $target_stub);
}
$target_stub = trim($target_stub, '/');
if (strpos($target_stub, '?') !== FALSE) {
list($target_stub, $query_string) = explode('?', $target_stub);
}
// Can this be used as a target?
$target_slug = URL::parse($target_stub)->named_arg_values['slug'];
if ($target_slug === FALSE) {
throw new XMLRPCException(33);
}
// Does the target exist?
$target_post = Post::get(array('slug' => $target_slug));
if ($target_post === FALSE) {
throw new XMLRPCException(32);
}
// Is comment allowed?
if ($target_post->info->comments_disabled) {
throw new XMLRPCException(33);
}
// Is this Pingback already registered?
if (Comments::get(array('post_id' => $target_post->id, 'url' => $source_uri, 'type' => Comment::PINGBACK))->count() > 0) {
throw new XMLRPCException(48);
}
// Retrieve source contents
$rr = new RemoteRequest($source_uri);
$rr->execute();
if (!$rr->executed()) {
throw new XMLRPCException(16);
}
$source_contents = $rr->get_response_body();
// encoding is converted into internal encoding.
// @todo check BOM at beginning of file before checking for a charset attribute
$habari_encoding = MultiByte::hab_encoding();
if (preg_match("/<meta[^>]+charset=([A-Za-z0-9\\-\\_]+)/i", $source_contents, $matches) !== FALSE && strtolower($habari_encoding) != strtolower($matches[1])) {
$ret = MultiByte::convert_encoding($source_contents, $habari_encoding, $matches[1]);
if ($ret !== FALSE) {
$source_contents = $ret;
}
}
// Find the page's title
preg_match('/<title>(.*)<\\/title>/is', $source_contents, $matches);
$source_title = $matches[1];
// Find the reciprocal links and their context
preg_match('/<body[^>]*>(.+)<\\/body>/is', $source_contents, $matches);
$source_contents_filtered = preg_replace('/\\s{2,}/is', ' ', strip_tags($matches[1], '<a>'));
if (!preg_match('%.{0,100}?<a[^>]*?href\\s*=\\s*("|\'|)' . $target_uri . '\\1[^>]*?' . '>(.+?)</a>.{0,100}%s', $source_contents_filtered, $source_excerpt)) {
throw new XMLRPCException(17);
}
/** Sanitize Data */
$source_excerpt = '...' . InputFilter::filter($source_excerpt[0]) . '...';
$source_title = InputFilter::filter($source_title);
$source_uri = InputFilter::filter($source_uri);
/* Sanitize the URL */
if (!empty($source_uri)) {
$parsed = InputFilter::parse_url($source_uri);
if ($parsed['is_relative']) {
// guess if they meant to use an absolute link
$parsed = InputFilter::parse_url('http://' . $source_uri);
if (!$parsed['is_error']) {
$source_uri = InputFilter::glue_url($parsed);
} else {
// disallow relative URLs
$source_uri = '';
}
}
if ($parsed['is_pseudo'] || $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') {
// allow only http(s) URLs
$source_uri = '';
} else {
// reconstruct the URL from the error-tolerant parsing
// http:moeffju.net/blog/ -> http://moeffju.net/blog/
$source_uri = InputFilter::glue_url($parsed);
}
}
// Add a new pingback comment
$pingback = new Comment(array('post_id' => $target_post->id, 'name' => $source_title, 'email' => '', 'url' => $source_uri, 'ip' => sprintf("%u", ip2long($_SERVER['REMOTE_ADDR'])), 'content' => $source_excerpt, 'status' => Comment::STATUS_UNAPPROVED, 'date' => HabariDateTime::date_create(), 'type' => Comment::PINGBACK));
$pingback->insert();
// Respond to the Pingback
return 'The pingback has been registered';
} catch (XMLRPCException $e) {
$e->output_fault_xml();
}
}
示例13: act_display
//.........这里部分代码省略.........
$where_filters['vocabulary'] = array();
if (array_key_exists('tag', $where_filters)) {
$tags = Tags::parse_url_tags($where_filters['tag']);
$not_tag = $tags['exclude_tag'];
$all_tag = $tags['include_tag'];
if (count($not_tag) > 0) {
$where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':not:term' => $not_tag));
}
if (count($all_tag) > 0) {
$where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':all:term' => $all_tag));
}
$where_filters['tag_slug'] = Utils::slugify($where_filters['tag']);
unset($where_filters['tag']);
}
if (!isset($_GET['preview'])) {
$where_filters['status'] = Post::status('published');
}
if (!isset($posts)) {
$user_filters = Plugins::filter('template_user_filters', $user_filters);
// Work around the tags parameters to Posts::get() being subsumed by the vocabulary parameter
if (isset($user_filters['not:tag'])) {
$user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':not:term' => $user_filters['not:tag']);
unset($user_filters['not:tag']);
}
if (isset($user_filters['tag'])) {
$user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':term_display' => $user_filters['tag']);
unset($user_filters['tag']);
}
$where_filters = $where_filters->merge($user_filters);
$where_filters = Plugins::filter('template_where_filters', $where_filters);
$posts = Posts::get($where_filters);
}
$this->assign('posts', $posts);
if ($posts !== false && count($posts) > 0) {
if (count($posts) == 1) {
$post = $posts instanceof Post ? $posts : reset($posts);
Stack::add('body_class', Post::type_name($post->content_type) . '-' . $post->id);
Stack::add('body_class', 'single');
} else {
$post = reset($posts);
Stack::add('body_class', 'multiple');
}
$this->assign('post', $post);
$type = Post::type_name($post->content_type);
} elseif ($posts === false || isset($where_filters['page']) && $where_filters['page'] > 1 && count($posts) == 0) {
if ($this->template_exists('404')) {
$fallback = array('404');
// Replace template variables with the 404 rewrite rule
$this->request->{URL::get_matched_rule()->name} = false;
$this->request->{URL::set_404()->name} = true;
$this->matched_rule = URL::get_matched_rule();
// 404 status header sent in act_display_404, but we're past
// that, so send it now.
header('HTTP/1.1 404 Not Found', true, 404);
} else {
$this->display('header');
echo '<h2>';
_e("Whoops! 404. The page you were trying to access is not really there. Please try again.");
echo '</h2>';
header('HTTP/1.1 404 Not Found', true, 404);
$this->display('footer');
die;
}
}
$extract = $where_filters->filter_keys('page', 'type', 'id', 'slug', 'posttag', 'year', 'month', 'day', 'tag', 'tag_slug');
foreach ($extract as $key => $value) {
${$key} = $value;
}
$this->assign('page', isset($page) ? $page : 1);
if (!isset($fallback)) {
// Default fallbacks based on the number of posts
$fallback = array('{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}');
if (count($posts) > 1) {
$fallback[] = '{$type}.multiple';
$fallback[] = 'multiple';
} else {
$fallback[] = '{$type}.single';
$fallback[] = 'single';
}
}
$searches = array('{$id}', '{$slug}', '{$year}', '{$month}', '{$day}', '{$type}', '{$tag}');
$replacements = array(isset($post) && $post instanceof Post ? $post->id : '-', isset($post) && $post instanceof Post ? $post->slug : '-', isset($year) ? $year : '-', isset($month) ? $month : '-', isset($day) ? $day : '-', isset($type) ? $type : '-', isset($tag_slug) ? $tag_slug : '-');
$fallback[] = 'home';
$fallback = Plugins::filter('template_fallback', $fallback, $posts, isset($post) ? $post : null);
$fallback = array_values(array_unique(MultiByte::str_replace($searches, $replacements, $fallback)));
for ($z = 0; $z < count($fallback); $z++) {
if (MultiByte::strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) {
$replacements = array();
if ($alltags = $post->tags) {
foreach ($alltags as $current_tag) {
$replacements[] = MultiByte::str_replace('{$posttag}', $current_tag->term, $fallback[$z]);
}
array_splice($fallback, $z, 1, $replacements);
} else {
break;
}
}
}
return $this->display_fallback($fallback);
}
示例14: test_detect_encoding
public function test_detect_encoding()
{
$this->assert_equal(MultiByte::detect_encoding('foo'), 'ASCII');
$str = MultiByte::convert_encoding($this->test_strings['jis'], 'JIS');
$this->assert_equal(MultiByte::detect_encoding($str), 'JIS');
}
示例15: save
private static function save($xml, $type)
{
$timestamp = HabariDateTime::date_create('now');
$result = Cache::set('exportsnapshot__' . $timestamp->int, $xml, 0, true);
// 0s expiration, but keep it forever
if ($result) {
$snapshots = Options::get('exportsnapshot__snapshots', array());
$snapshots[$timestamp->int] = array('size' => MultiByte::strlen($xml), 'type' => $type, 'ts' => $timestamp->int);
Options::set('exportsnapshot__snapshots', $snapshots);
return true;
} else {
return false;
}
}