本文整理汇总了PHP中elgg_substr函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_substr函数的具体用法?PHP elgg_substr怎么用?PHP elgg_substr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_substr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: app2_blog_save
function app2_blog_save($title, $text, $excerpt, $tags, $access, $container_guid)
{
$user = elgg_get_logged_in_user_entity();
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
$obj = new ElggObject();
$obj->subtype = "blog";
$obj->owner_guid = $user->guid;
$obj->container_guid = $container_guid;
$obj->access_id = strip_tags($access);
$obj->method = "api";
$obj->description = strip_tags($text);
$obj->title = elgg_substr(strip_tags($title), 0, 140);
$obj->status = 'published';
$obj->comments_on = 'On';
$obj->excerpt = strip_tags($excerpt);
$obj->tags = strip_tags($tags);
$guid = $obj->save();
elgg_create_river_item('river/object/blog/create', 'create', $user->guid, $obj->guid);
if ($guid) {
return true;
} else {
return false;
}
}
示例2: tgswire_save_post
/**
* Create a new wire post, the TGS way
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @param int $container_guid Container guid (for group wire posts)
* @return guid or false if failure
*/
function tgswire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site", $container_guid = NULL)
{
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
// Check if we're removing the limit
if (elgg_get_plugin_setting('limit_wire_chars', 'wire-extender') == 'yes') {
// only 200 characters allowed
$text = elgg_substr($text, 0, 200);
}
// If supplied with a container_guid, use it
if ($container_guid) {
$post->container_guid = $container_guid;
}
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid);
// let other plugins know we are setting a user status
$params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire');
elgg_trigger_plugin_hook('status', 'user', $params);
}
return $guid;
}
示例3: elgg_get_excerpt
/**
* Returns an excerpt.
* Will return up to n chars stopping at the nearest space.
* If no spaces are found (like in Japanese) will crop off at the
* n char mark. Adds ... if any text was chopped.
*
* @param string $text The full text to excerpt
* @param int $num_chars Return a string up to $num_chars long
*
* @return string
* @since 1.7.2
*/
function elgg_get_excerpt($text, $num_chars = 250)
{
$text = trim(elgg_strip_tags($text));
$string_length = elgg_strlen($text);
if ($string_length <= $num_chars) {
return $text;
}
// handle cases
$excerpt = elgg_substr($text, 0, $num_chars);
$space = elgg_strrpos($excerpt, ' ', 0);
// don't crop if can't find a space.
if ($space === false) {
$space = $num_chars;
}
$excerpt = trim(elgg_substr($excerpt, 0, $space));
if ($string_length != elgg_strlen($excerpt)) {
$excerpt .= '...';
}
return $excerpt;
}
示例4: hypefaker_add_wire
function hypefaker_add_wire($owner, $parent = null)
{
$locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
$faker = Factory::create($locale);
$wire = new ElggObject();
$wire->subtype = 'thewire';
$wire->owner_guid = $owner->guid;
$tags = $faker->words(5);
$text = $faker->text(80);
foreach ($tags as $tag) {
$text .= " #{$tag}";
}
if ($parent) {
$wire->reply = true;
$username = $parent->getOwnerEntity()->username;
$text = "@{$username} {$text}";
}
$limit = elgg_get_plugin_setting('limit', 'thewire');
if ($limit > 0) {
$text = elgg_substr($text, 0, $limit);
}
$wire->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$wire->tags = $tags;
$wire->method = 'faker';
$wire->access_id = ACCESS_PUBLIC;
$wire->__faker = true;
if ($wire->save()) {
if ($parent) {
$wire->addRelationship($parent->guid, 'parent');
$wire->wire_thread = $parent->wire_thread;
} else {
$wire->wire_thread = $wire->guid;
}
elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $wire->owner_guid, 'object_guid' => $wire->guid));
$params = array('entity' => $wire, 'user' => $owner, 'message' => $wire->description, 'url' => $wire->getURL(), 'origin' => 'thewire');
elgg_trigger_plugin_hook('status', 'user', $params);
return $wire;
}
return false;
}
示例5: blog_save
/**
* Web service for making a blog post
*
* @param string $username username of author
* @param string $title the title of blog
* @param string $excerpt the excerpt of blog
* @param string $text the content of blog
* @param string $tags tags for blog
* @param string $access Access level of blog
*
* @return bool
*/
function blog_save($username, $title, $text, $excerpt = "", $tags = "blog", $access = ACCESS_PUBLIC)
{
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
$obj = new ElggObject();
$obj->subtype = "blog";
$obj->owner_guid = $user->guid;
$obj->access_id = strip_tags($access);
$obj->method = "api";
$obj->description = strip_tags($text);
$obj->title = elgg_substr(strip_tags($title), 0, 140);
$obj->status = 'published';
$obj->comments_on = 'On';
$obj->excerpt = strip_tags($excerpt);
$obj->tags = strip_tags($tags);
$guid = $obj->save();
add_to_river('river/object/blog/create', 'create', $user->guid, $obj->guid);
$return['success'] = true;
$return['message'] = elgg_echo('blog:message:saved');
return $return;
}
示例6: search_get_highlighted_relevant_substrings
/**
* Return a string with highlighted matched queries and relevant context
* Determins context based upon occurance and distance of words with each other.
*
* @param string $haystack
* @param string $query
* @param int $min_match_context = 30
* @param int $max_length = 300
* @return string
*/
function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300)
{
global $CONFIG;
$haystack = strip_tags($haystack);
$haystack_length = elgg_strlen($haystack);
$haystack_lc = elgg_strtolower($haystack);
$words = search_remove_ignored_words($query, 'array');
// if haystack < $max_length return the entire haystack w/formatting immediately
if ($haystack_length <= $max_length) {
$return = search_highlight_words($words, $haystack);
return $return;
}
// get the starting positions and lengths for all matching words
$starts = array();
$lengths = array();
foreach ($words as $word) {
$word = elgg_strtolower($word);
$count = elgg_substr_count($haystack_lc, $word);
$word_len = elgg_strlen($word);
// find the start positions for the words
if ($count > 1) {
$offset = 0;
while (FALSE !== ($pos = elgg_strpos($haystack_lc, $word, $offset))) {
$start = $pos - $min_match_context > 0 ? $pos - $min_match_context : 0;
$starts[] = $start;
$stop = $pos + $word_len + $min_match_context;
$lengths[] = $stop - $start;
$offset += $pos + $word_len;
}
} else {
$pos = elgg_strpos($haystack_lc, $word);
$start = $pos - $min_match_context > 0 ? $pos - $min_match_context : 0;
$starts[] = $start;
$stop = $pos + $word_len + $min_match_context;
$lengths[] = $stop - $start;
}
}
$offsets = search_consolidate_substrings($starts, $lengths);
// figure out if we can adjust the offsets and lengths
// in order to return more context
$total_length = array_sum($offsets);
$add_length = 0;
if ($total_length < $max_length) {
$add_length = floor(($max_length - $total_length) / count($offsets) / 2);
$starts = array();
$lengths = array();
foreach ($offsets as $offset => $length) {
$start = $offset - $add_length > 0 ? $offset - $add_length : 0;
$length = $length + $add_length;
$starts[] = $start;
$lengths[] = $length;
}
$offsets = search_consolidate_substrings($starts, $lengths);
}
// sort by order of string size descending (which is roughly
// the proximity of matched terms) so we can keep the
// substrings with terms closest together and discard
// the others as needed to fit within $max_length.
arsort($offsets);
$return_strs = array();
$total_length = 0;
foreach ($offsets as $start => $length) {
$string = trim(elgg_substr($haystack, $start, $length));
// continue past if adding this substring exceeds max length
if ($total_length + $length > $max_length) {
continue;
}
$total_length += $length;
$return_strs[$start] = $string;
}
// put the strings in order of occurence
ksort($return_strs);
// add ...s where needed
$return = implode('...', $return_strs);
if (!array_key_exists(0, $return_strs)) {
$return = "...{$return}";
}
// add to end of string if last substring doesn't hit the end.
$starts = array_keys($return_strs);
$last_pos = $starts[count($starts) - 1];
if ($last_pos + elgg_strlen($return_strs[$last_pos]) < $haystack_length) {
$return .= '...';
}
$return = search_highlight_words($words, $return);
return $return;
}
示例7: thewire_save_post
/**
* Create a new wire post.
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @return guid or false if failure
*/
function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
// Character limit is now from config
$limit = elgg_get_plugin_setting('limit', 'thewire');
if ($limit > 0) {
$text = elgg_substr($text, 0, $limit);
}
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->owner_guid, 'object_guid' => $post->guid));
// let other plugins know we are setting a user status
$params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire');
elgg_trigger_plugin_hook('status', 'user', $params);
}
return $guid;
}
示例8: thewire_save_post
/**
* Create a new wire post.
*
* @param string $text The post text
* @param int $userid The user's guid
* @param int $access_id Public/private etc
* @param int $parent_guid Parent post guid (if any)
* @param string $method The method (default: 'site')
* @return guid or false if failure
*/
function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
$post = new ElggObject();
$post->subtype = "thewire";
$post->owner_guid = $userid;
$post->access_id = $access_id;
// only 200 characters allowed
$text = elgg_substr($text, 0, 200);
// no html tags allowed so we escape
$post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$post->method = $method;
//method: site, email, api, ...
$tags = thewire_get_hashtags($text);
if ($tags) {
$post->tags = $tags;
}
// must do this before saving so notifications pick up that this is a reply
if ($parent_guid) {
$post->reply = true;
}
$guid = $post->save();
// set thread guid
if ($parent_guid) {
$post->addRelationship($parent_guid, 'parent');
// name conversation threads by guid of first post (works even if first post deleted)
$parent_post = get_entity($parent_guid);
$post->wire_thread = $parent_post->wire_thread;
} else {
// first post in this thread
$post->wire_thread = $guid;
}
if ($guid) {
add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid);
}
return $guid;
}
示例9: tokenizeAttributes
/**
* Tokenize the ECML tag attributes
*
* @param string $string Attribute string
* @param bool $success
* @return array
*/
protected function tokenizeAttributes($string, &$success = null)
{
$success = true;
$string = trim($string);
if (empty($string)) {
return array();
}
$attributes = array();
$pos = 0;
$char = elgg_substr($string, $pos, 1);
// working var for assembling name and values
$operand = $name = '';
while ($char !== false && $char !== '') {
switch ($char) {
// handle quoted names/values
case '"':
case "'":
$quote = $char;
$next_char = elgg_substr($string, ++$pos, 1);
while ($next_char != $quote) {
// note: mb_substr returns "" instead of false...
if ($next_char === false || $next_char === '') {
// no matching quote. bail.
$success = false;
return array();
} elseif ($next_char === '\\') {
// allow escaping quotes
$after_escape = elgg_substr($string, $pos + 1, 1);
if ($after_escape === $quote) {
$operand .= $quote;
$pos += 2;
// skip escape and quote
$next_char = elgg_substr($string, $pos, 1);
continue;
}
}
$operand .= $next_char;
$next_char = elgg_substr($string, ++$pos, 1);
}
break;
case self::ATTR_SEPARATOR:
$this->setAttribute($operand, $name, $attributes);
break;
case self::ATTR_OPERATOR:
// save name, switch to value
$name = $operand;
$operand = '';
break;
default:
$operand .= $char;
break;
}
$char = elgg_substr($string, ++$pos, 1);
}
// need to get the last attr
$this->setAttribute($operand, $name, $attributes);
return $attributes;
}
示例10: string_to_tag_array
$file->description = $desc;
$file->access_id = $access_id;
$file->container_guid = $container_guid;
$file->tags = string_to_tag_array($tags);
// we have a file upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
$prefix = "file/";
// if previous file, delete it
if ($new_file == false) {
$filename = $file->getFilenameOnFilestore();
if (file_exists($filename)) {
unlink($filename);
}
// use same filename on the disk - ensures thumbnails are overwritten
$filestorename = $file->getFilename();
$filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
} else {
$filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
}
$file->setFilename($prefix . $filestorename);
/*$indexOfExt = strrpos($_FILES['upload']['name'], ".") + 1;
$ext = substr($_FILES['upload']['name'],$indexOfExt);
error_log($ext);*/
$ext = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
if ($ext == "ppt") {
$mime_type = 'application/vnd.ms-powerpoint';
} else {
$mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type'], $_FILES['upload']['name']);
}
// hack for Microsoft zipped formats
$info = pathinfo($_FILES['upload']['name']);
示例11: strip_tags
<?php
/**
* Elgg plugin project creation action
*/
// Get variables
$title = strip_tags(get_input("title"));
$description = plugins_strip_tags(get_input("description"));
$tags = get_input("tags");
$summary = strip_tags(elgg_substr(get_input('summary'), 0, 250));
$homepage = strip_tags(get_input('homepage'));
$donate = strip_tags(get_input('donate'));
$repo = strip_tags(get_input('repo'));
$license = get_input('license');
$plugincat = get_input('plugincat', 'uncategorized');
$project_access_id = get_input("project_access_id", ACCESS_PUBLIC);
$plugin_type = get_input('plugin_type');
if ($plugin_type != 'theme' && $plugin_type != 'languagepack') {
$plugin_type = 'plugin';
}
$release_notes = plugins_strip_tags(get_input('release_notes'));
$elgg_version = get_input('elgg_version', 'Not specified');
$comments = get_input('comments', 'yes');
$version = strip_tags(get_input('version', 'Not specified'));
$recommended = get_input('recommended', FALSE);
$release_access_id = get_input('release_access_id', ACCESS_PUBLIC);
$user = get_loggedin_user();
// validate data
if (!$title) {
register_error(elgg_echo('plugins:error:notitle'));
forward(REFERER);
示例12: blog_save_post
/**
* Web service for making a blog post
*
* @param string $title the title of blog
* @param $body
* @param $comment_status
* @param string $access Access level of blog
*
* @param $status
* @param $username
* @param string $tags tags for blog
* @param string $excerpt the excerpt of blog
* @return bool
* @throws InvalidParameterException
* @internal param $description
* @internal param $container_guid
* @internal param string $text the content of blog
* @internal param string $username username of author
*/
function blog_save_post($title, $body, $comment_status, $access, $status, $username, $tags, $excerpt)
{
if (!$username) {
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
}
if ($access == 'ACCESS_FRIENDS') {
$access_id = -2;
} elseif ($access == 'ACCESS_PRIVATE') {
$access_id = 0;
} elseif ($access == 'ACCESS_LOGGED_IN') {
$access_id = 1;
} elseif ($access == 'ACCESS_PUBLIC') {
$access_id = 2;
} else {
$access_id = -2;
}
$blog = new ElggBlog();
$blog->subtype = "blog";
$blog->owner_guid = $user->guid;
$blog->container_guid = $user->guid;
$blog->access_id = $access_id;
$blog->description = $body;
$blog->title = elgg_substr(strip_tags($title), 0, 140);
$blog->status = $status;
$blog->comments_on = $comment_status;
$blog->excerpt = strip_tags($excerpt);
$blog->tags = string_to_tag_array($tags);
$guid = $blog->save();
$newStatus = $blog->status;
if ($guid > 0 && $newStatus == 'published') {
elgg_create_river_item(array('view' => 'river/object/blog/create', 'action_type' => 'create', 'subject_guid' => $blog->owner_guid, 'object_guid' => $blog->getGUID()));
elgg_trigger_event('publish', 'object', $blog);
if ($guid) {
$blog->time_created = time();
$blog->save();
}
$return['guid'] = $guid;
$return['message'] = $newStatus;
} else {
$return['guid'] = $guid;
$return['message'] = $status;
}
return $return;
}
示例13: create_file
function create_file($container_guid, $title, $desc, $access_id, $guid, $tags, $new_file)
{
// register_error("Creating file: " . $container_guid . ", vars: " . print_r(array($title, $desc, $access_id, $guid, $tags, $new_file), true));
if ($new_file) {
// must have a file if a new file upload
if (empty($_FILES['upload']['name'])) {
// cache information in session
$_SESSION['uploadtitle'] = $title;
$_SESSION['uploaddesc'] = $desc;
$_SESSION['uploadtags'] = $tags;
$_SESSION['uploadaccessid'] = $access_id;
register_error(elgg_echo('file:nofile') . "no file new");
forward($_SERVER['HTTP_REFERER']);
}
$file = new FilePluginFile();
$file->subtype = "file";
// if no title on new upload, grab filename
if (empty($title)) {
$title = $_FILES['upload']['name'];
}
} else {
// load original file object
$file = get_entity($guid);
if (!$file) {
register_error(elgg_echo('file:cannotload') . 'can"t load existing');
forward($_SERVER['HTTP_REFERER']);
}
// user must be able to edit file
if (!$file->canEdit()) {
register_error(elgg_echo('file:noaccess') . 'no access to existing');
forward($_SERVER['HTTP_REFERER']);
}
}
$file->title = $title;
$file->description = $desc;
$file->access_id = $access_id;
$file->container_guid = $container_guid;
$tags = explode(",", $tags);
$file->tags = $tags;
// we have a file upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
$prefix = "file/";
// if previous file, delete it
if ($new_file == false) {
$filename = $file->getFilenameOnFilestore();
if (file_exists($filename)) {
unlink($filename);
}
// use same filename on the disk - ensures thumbnails are overwritten
$filestorename = $file->getFilename();
$filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
} else {
$filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
}
$file->setFilename($prefix . $filestorename);
$file->setMimeType($_FILES['upload']['type']);
$file->originalfilename = $_FILES['upload']['name'];
$file->simpletype = get_general_file_type($_FILES['upload']['type']);
$file->open("write");
$file->write(get_uploaded_file('upload'));
$file->close();
$guid = $file->save();
// if image, we need to create thumbnails (this should be moved into a function)
if ($guid && $file->simpletype == "image") {
$thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
if ($thumbnail) {
$thumb = new ElggFile();
$thumb->setMimeType($_FILES['upload']['type']);
$thumb->setFilename($prefix . "thumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
$file->thumbnail = $prefix . "thumb" . $filestorename;
unset($thumbnail);
}
$thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
if ($thumbsmall) {
$thumb->setFilename($prefix . "smallthumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumbsmall);
$thumb->close();
$file->smallthumb = $prefix . "smallthumb" . $filestorename;
unset($thumbsmall);
}
$thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
if ($thumblarge) {
$thumb->setFilename($prefix . "largethumb" . $filestorename);
$thumb->open("write");
$thumb->write($thumblarge);
$thumb->close();
$file->largethumb = $prefix . "largethumb" . $filestorename;
unset($thumblarge);
}
}
} else {
// not saving a file but still need to save the entity to push attributes to database
$file->save();
}
return array($file, $guid);
}
示例14: elgg_http_url_is_identical
/**
* Test if two URLs are functionally identical.
*
* @tip If $ignore_params is used, neither the name nor its value will be considered when comparing.
*
* @tip The order of GET params doesn't matter.
*
* @param string $url1 First URL
* @param string $url2 Second URL
* @param array $ignore_params GET params to ignore in the comparison
*
* @return bool
* @since 1.8.0
*/
function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset', 'limit'))
{
global $CONFIG;
// if the server portion is missing but it starts with / then add the url in.
// @todo use elgg_normalize_url()
if (elgg_substr($url1, 0, 1) == '/') {
$url1 = elgg_get_site_url() . ltrim($url1, '/');
}
if (elgg_substr($url1, 0, 1) == '/') {
$url2 = elgg_get_site_url() . ltrim($url2, '/');
}
// @todo - should probably do something with relative URLs
if ($url1 == $url2) {
return TRUE;
}
$url1_info = parse_url($url1);
$url2_info = parse_url($url2);
if (isset($url1_info['path'])) {
$url1_info['path'] = trim($url1_info['path'], '/');
}
if (isset($url2_info['path'])) {
$url2_info['path'] = trim($url2_info['path'], '/');
}
// compare basic bits
$parts = array('scheme', 'host', 'path');
foreach ($parts as $part) {
if (isset($url1_info[$part]) && isset($url2_info[$part]) && $url1_info[$part] != $url2_info[$part]) {
return FALSE;
} elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
return FALSE;
} elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
return FALSE;
}
}
// quick compare of get params
if (isset($url1_info['query']) && isset($url2_info['query']) && $url1_info['query'] == $url2_info['query']) {
return TRUE;
}
// compare get params that might be out of order
$url1_params = array();
$url2_params = array();
if (isset($url1_info['query'])) {
if ($url1_info['query'] = html_entity_decode($url1_info['query'])) {
$url1_params = elgg_parse_str($url1_info['query']);
}
}
if (isset($url2_info['query'])) {
if ($url2_info['query'] = html_entity_decode($url2_info['query'])) {
$url2_params = elgg_parse_str($url2_info['query']);
}
}
// drop ignored params
foreach ($ignore_params as $param) {
if (isset($url1_params[$param])) {
unset($url1_params[$param]);
}
if (isset($url2_params[$param])) {
unset($url2_params[$param]);
}
}
// array_diff_assoc only returns the items in arr1 that aren't in arrN
// but not the items that ARE in arrN but NOT in arr1
// if arr1 is an empty array, this function will return 0 no matter what.
// since we only care if they're different and not how different,
// add the results together to get a non-zero (ie, different) result
$diff_count = count(array_diff_assoc($url1_params, $url2_params));
$diff_count += count(array_diff_assoc($url2_params, $url1_params));
if ($diff_count > 0) {
return FALSE;
}
return TRUE;
}
示例15: thewire_save_post
/**
* Create a new wire post.
*
* @param string $post The post
* @param int $access_id Public/private etc
* @param int $parent Parent post (if any)
* @param string $method The method (default: 'site')
* @return bool
*/
function thewire_save_post($post, $access_id, $parent = 0, $method = "site")
{
global $SESSION;
// Initialise a new ElggObject
$thewire = new ElggObject();
// Tell the system it's a thewire post
$thewire->subtype = "thewire";
// Set its owner to the current user
$thewire->owner_guid = get_loggedin_userid();
// For now, set its access to public (we'll add an access dropdown shortly)
$thewire->access_id = $access_id;
// Set its description appropriately
$thewire->description = elgg_substr(strip_tags($post), 0, 160);
/*if (is_callable('mb_substr'))
$thewire->description = mb_substr(strip_tags($post), 0, 160);
else
$thewire->description = substr(strip_tags($post), 0, 160);*/
// add some metadata
$thewire->method = $method;
//method, e.g. via site, sms etc
$thewire->parent = $parent;
//used if the note is a reply
//save
$save = $thewire->save();
if ($save) {
add_to_river('river/object/thewire/create', 'create', $SESSION['user']->guid, $thewire->guid);
}
return $save;
}