• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP MultiByte类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中MultiByte的典型用法代码示例。如果您正苦于以下问题:PHP MultiByte类的具体用法?PHP MultiByte怎么用?PHP MultiByte使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MultiByte类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:habari-extras,项目名称:passwdlogins,代码行数:25,代码来源:passwdlogins.plugin.php


示例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 );
	}
开发者ID:rick-c,项目名称:TagsAutocomplete,代码行数:32,代码来源:tagautocomplete.plugin.php


示例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)));
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:8,代码来源:test_multibyte.php


示例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;
     }
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:19,代码来源:inputfilter.php


示例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) : '');
     }
 }
开发者ID:wwxgitcat,项目名称:habari,代码行数:21,代码来源:adminhandler.php


示例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( '&quot;', '"', $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();
	}
开发者ID:rynodivino,项目名称:system,代码行数:48,代码来源:terms.php


示例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;
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:61,代码来源:comments.php


示例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;
开发者ID:wwxgitcat,项目名称:habari,代码行数:67,代码来源:eventlog.php


示例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);
 }
开发者ID:psaintlaurent,项目名称:Habari,代码行数:74,代码来源:userhandler.php


示例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) . '&hellip;' . MultiByte::substr($str, -$len);
     } else {
         // no, the ellipse goes at the end
         $len = $len - 3;
         return MultiByte::substr($str, 0, $len) . '&hellip;';
     }
 }
开发者ID:habari,项目名称:system,代码行数:29,代码来源:utils.php


示例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;
     }
 }
开发者ID:ringmaster,项目名称:system,代码行数:28,代码来源:remoterequest.php


示例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();
     }
 }
开发者ID:anupom,项目名称:my-blog,代码行数:98,代码来源:pingback.plugin.php


示例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);
 }
开发者ID:habari,项目名称:system,代码行数:101,代码来源:theme.php


示例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');
 }
开发者ID:habari,项目名称:tests,代码行数:6,代码来源:test_multibyte.php


示例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;
     }
 }
开发者ID:habari-extras,项目名称:exportsnapshot,代码行数:14,代码来源:exportsnapshot.plugin.php


示例16: get_form

 /**
  * Returns a form for editing this post
  * @param string $context The context the form is being created in, most often 'admin'
  * @return FormUI A form appropriate for creating and updating this post.
  */
 public function get_form($context)
 {
     $form = new FormUI('create-content');
     $form->class[] = 'create';
     $newpost = 0 === $this->id;
     // If the post has already been saved, add a link to its permalink
     if (!$newpost) {
         $post_links = $form->append('wrapper', 'post_links');
         $permalink = $this->status != Post::status('published') ? $this->permalink . '?preview=1' : $this->permalink;
         $post_links->append('static', 'post_permalink', '<a href="' . $permalink . '" class="viewpost" >' . ($this->status != Post::status('published') ? _t('Preview Post') : _t('View Post')) . '</a>');
         $post_links->class = 'container';
     }
     // Store this post instance into a hidden field for later use when saving data
     $form->append('hidden', 'post', $this, _t('Title'), 'admincontrol_text');
     // Create the Title field
     $form->append('text', 'title', 'null:null', _t('Title'), 'admincontrol_text');
     $form->title->class[] = 'important';
     $form->title->class[] = 'check-change';
     $form->title->tabindex = 1;
     $form->title->value = $this->title_internal;
     // Create the silos
     if (count(Plugins::get_by_interface('MediaSilo'))) {
         $form->append('silos', 'silos');
         $form->silos->silos = Media::dir();
     }
     // Create the Content field
     $form->append('textarea', 'content', 'null:null', _t('Content'), 'admincontrol_textarea');
     $form->content->class[] = 'resizable';
     $form->content->class[] = 'check-change';
     $form->content->tabindex = 2;
     $form->content->value = $this->content_internal;
     $form->content->raw = true;
     // Create the tags field
     $form->append('text', 'tags', 'null:null', _t('Tags, separated by, commas'), 'admincontrol_text');
     $form->tags->class = 'check-change';
     $form->tags->tabindex = 3;
     $tags = (array) $this->get_tags();
     array_walk($tags, function (&$element, $key) {
         $element->term_display = MultiByte::strpos($element->term_display, ',') === false ? $element->term_display : $element->tag_text_searchable;
     });
     $form->tags->value = implode(', ', $tags);
     // Create the splitter
     $publish_controls = $form->append('tabs', 'publish_controls');
     // Create the publishing controls
     // pass "false" to list_post_statuses() so that we don't include internal post statuses
     $statuses = Post::list_post_statuses($this);
     unset($statuses[array_search('any', $statuses)]);
     $statuses = Plugins::filter('admin_publish_list_post_statuses', $statuses);
     $settings = $publish_controls->append('fieldset', 'settings', _t('Settings'));
     $settings->append('select', 'status', 'null:null', _t('Content State'), array_flip($statuses), 'tabcontrol_select');
     $settings->status->value = $this->status;
     // hide the minor edit checkbox if the post is new
     if ($newpost) {
         $settings->append('hidden', 'minor_edit', 'null:null');
         $settings->minor_edit->value = false;
     } else {
         $settings->append('checkbox', 'minor_edit', 'null:null', _t('Minor Edit'), 'tabcontrol_checkbox');
         $settings->minor_edit->value = true;
         $form->append('hidden', 'modified', 'null:null')->value = $this->modified;
     }
     $settings->append('checkbox', 'comments_enabled', 'null:null', _t('Comments Allowed'), 'tabcontrol_checkbox');
     $settings->comments_enabled->value = $this->info->comments_disabled ? false : true;
     $settings->append('text', 'pubdate', 'null:null', _t('Publication Time'), 'tabcontrol_text');
     $settings->pubdate->value = $this->pubdate->format('Y-m-d H:i:s');
     $settings->pubdate->helptext = _t('YYYY-MM-DD HH:MM:SS');
     $settings->append('hidden', 'updated', 'null:null');
     $settings->updated->value = $this->updated->int;
     $settings->append('text', 'newslug', 'null:null', _t('Content Address'), 'tabcontrol_text');
     $settings->newslug->id = 'newslug';
     $settings->newslug->value = $this->slug;
     // Create the button area
     $buttons = $form->append('fieldset', 'buttons');
     $buttons->template = 'admincontrol_buttons';
     $buttons->class[] = 'container';
     $buttons->class[] = 'buttons';
     $buttons->class[] = 'publish';
     // Create the Save button
     $require_any = array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($this->content_type) => 'create');
     if ($newpost && User::identify()->can_any($require_any) || !$newpost && ACL::access_check($this->get_access(), 'edit')) {
         $buttons->append('submit', 'save', _t('Save'), 'admincontrol_submit');
         $buttons->save->tabindex = 4;
     }
     // Add required hidden controls
     $form->append('hidden', 'content_type', 'null:null');
     $form->content_type->id = 'content_type';
     $form->content_type->value = $this->content_type;
     $form->append('hidden', 'post_id', 'null:null');
     $form->post_id->id = 'id';
     $form->post_id->value = $this->id;
     $form->append('hidden', 'slug', 'null:null');
     $form->slug->value = $this->slug;
     $form->slug->id = 'originalslug';
     $form->on_success(array($this, 'form_publish_success'));
     // Let plugins alter this form
     Plugins::act('form_publish', $form, $this, $context);
//.........这里部分代码省略.........
开发者ID:wwxgitcat,项目名称:habari,代码行数:101,代码来源:post.php


示例17: get_dir

	/**
	 * get_dir returns a complete filesystem path to the requested item
	 *	'config_file' returns the complete path to the config.php file, including the filename
	 *	'config' returns the path of the directory containing config.php
	 *	'user' returns the path of the user directory
	 *	'theme' returns the path of the site's active theme
	 * @param string the name of the path item to return
	 * @param bool whether to include a trailing slash.  Default: No
	 * @return string Path
	 */
	public static function get_dir( $name, $trail = false )
	{
		$path = '';

		switch ( strtolower( $name ) ) {
			case 'config_file':
				$path = Site::get_dir( 'config' ) . '/config.php';
				break;
			case 'config':
				if ( self::$config_path ) {
					return self::$config_path;
				}

				self::$config_path = HABARI_PATH;

				$config_dirs = preg_replace( '/^' . preg_quote( HABARI_PATH, '/' ) . '\/user\/sites\/(.*)\/config.php/', '$1', Utils::glob( HABARI_PATH . '/user/sites/*/config.php' ) );

				if ( empty( $config_dirs ) ) {
					return self::$config_path;
				}

				$server = InputFilter::parse_url( Site::get_url( 'habari' ) );
				$server = ( isset( $server['port'] ) ) ? $server['port'] . '.' . $server['host'] . '.' : $server['host'] . '.';

				$request = explode( '/', trim( $_SERVER['REQUEST_URI'], '/' ) );
				$match = trim( $server, '.' );
				$x = count( $request );
				do {
					if ( in_array( $match, $config_dirs ) ) {
						self::$config_dir = $match;
						self::$config_path = HABARI_PATH . '/user/sites/' . self::$config_dir;
						self::$config_type = ( $x > 0 ) ? Site::CONFIG_SUBDOMAIN : Site::CONFIG_SUBDIR;
						break;
					}

					$match = MultiByte::substr( $match, MultiByte::strpos( $match, '.' ) + 1 );
					$x--;
				} while ( MultiByte::strpos( $match, '.' ) !== false );

				$path = self::$config_path;
				break;
			case 'user':
				if ( Site::get_dir( 'config' ) == HABARI_PATH ) {
					$path = HABARI_PATH . '/user';
				}
				else {
					$path = Site::get_dir( 'config' );
				}
				break;
			case 'theme':
				$theme = Themes::get_theme_dir();
				if ( file_exists( Site::get_dir( 'config' ) . '/themes/' . $theme ) ) {
					$path = Site::get_dir( 'user' ) . '/themes/' . $theme;
				}
				elseif ( file_exists( HABARI_PATH . '/user/themes/' . $theme ) ) {
					$path = HABARI_PATH . '/user/themes/' . $theme;
				}
				elseif ( file_exists( HABARI_PATH . '/3rdparty/themes/' . $theme ) ) {
					$url = Site::get_url( 'habari' ) . '/3rdparty/themes/' . $theme;
				}
				else {
					$path = HABARI_PATH . '/system/themes/' . $theme;
				}
				break;
			case 'admin_theme':
				$path = HABARI_PATH . '/system/admin';
				break;
			case 'vendor':
				$path = HABARI_PATH . '/system/vendor';
				break;
		}
		$path .= Utils::trail( $trail );
		$path = Plugins::filter( 'site_dir_' . $name, $path );
		return $path;
	}
开发者ID:nerdfiles,项目名称:habari_boilerplate,代码行数:85,代码来源:site.php


示例18: get


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP MultiPostThumbnails类代码示例发布时间:2022-05-23
下一篇:
PHP Msg类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap