本文整理汇总了PHP中elgg_strlen函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_strlen函数的具体用法?PHP elgg_strlen怎么用?PHP elgg_strlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_strlen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _elgg_set_user_name
/**
* Set a user's display name
*
* @return bool
* @since 1.8.0
* @access private
*/
function _elgg_set_user_name()
{
$name = strip_tags(get_input('name'));
$user_guid = get_input('guid');
if ($user_guid) {
$user = get_user($user_guid);
} else {
$user = elgg_get_logged_in_user_entity();
}
if (elgg_strlen($name) > 50) {
register_error(elgg_echo('user:name:fail'));
return false;
}
if ($user && $user->canEdit() && $name) {
if ($name != $user->name) {
$user->name = $name;
if ($user->save()) {
system_message(elgg_echo('user:name:success'));
return true;
} else {
register_error(elgg_echo('user:name:fail'));
}
} else {
// no change
return null;
}
} else {
register_error(elgg_echo('user:name:fail'));
}
return false;
}
示例2: user_save_profile
/**
* Web service to update profile information
*
* @param string $username username to update profile information
*
* @return bool
*/
function user_save_profile($username, $profile)
{
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
$owner = get_entity($user->guid);
$profile_fields = elgg_get_config('profile_fields');
foreach ($profile_fields as $shortname => $valuetype) {
$value = $profile[$shortname];
$value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
if ($valuetype != 'longtext' && elgg_strlen($value) > 250) {
$error = elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$shortname}")));
return $error;
}
if ($valuetype == 'tags') {
$value = string_to_tag_array($value);
}
$input[$shortname] = $value;
}
$name = strip_tags($profile['name']);
if ($name) {
if (elgg_strlen($name) > 50) {
return elgg_echo('user:name:fail');
} elseif ($owner->name != $name) {
$owner->name = $name;
return $owner->save();
if (!$owner->save()) {
return elgg_echo('user:name:fail');
}
}
}
if (sizeof($input) > 0) {
foreach ($input as $shortname => $value) {
$options = array('guid' => $owner->guid, 'metadata_name' => $shortname);
elgg_delete_metadata($options);
if (isset($accesslevel[$shortname])) {
$access_id = (int) $accesslevel[$shortname];
} else {
// this should never be executed since the access level should always be set
$access_id = ACCESS_DEFAULT;
}
if (is_array($value)) {
$i = 0;
foreach ($value as $interval) {
$i++;
$multiple = $i > 1 ? TRUE : FALSE;
create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
}
} else {
create_metadata($owner->guid, $shortname, $value, 'text', $owner->guid, $access_id);
}
}
}
return "Success";
}
示例3: put
/**
* {@inheritdoc}
*/
public function put(ParameterBag $params)
{
$owner = get_entity($params->guid);
if (!$owner->canEdit()) {
throw new GraphException("You are not allowed to modify this user's profile", HttpResponse::HTTP_FORBIDDEN);
}
$profile_fields = (array) elgg_get_config('profile_fields');
$access_id = $params->access_id !== null ? $params->access_id : get_default_access($owner);
$input = array();
foreach ($profile_fields as $field => $valuetype) {
// Making sure the consumer has sent these fields with the request
if (isset($params->{$field}) && $this->request->get($field) !== null) {
$value = $params->{$field};
$value = _elgg_html_decode($value);
if (!is_array($value) && $valuetype != 'longtext' && elgg_strlen($value) > 250) {
throw new GraphException(elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$field}")), HttpResponse::HTTP_BAD_REQUEST));
}
if ($value && $valuetype == 'url' && !preg_match('~^https?\\://~i', $value)) {
$value = "http://{$value}";
}
if ($valuetype == 'tags') {
$value = string_to_tag_array($value);
}
if ($valuetype == 'email' && !empty($value) && !is_email_address($value)) {
throw new GraphException(elgg_echo('profile:invalid_email', array(elgg_echo("profile:{$field}"))), HttpResponse::HTTP_BAD_REQUEST);
}
$input[$field] = $value;
}
}
// go through custom fields
if (sizeof($input) > 0) {
foreach ($input as $shortname => $value) {
$options = array('guid' => $owner->guid, 'metadata_name' => $shortname, 'limit' => false);
elgg_delete_metadata($options);
if (!is_null($value) && $value !== '') {
// only create metadata for non empty values (0 is allowed) to prevent metadata records
// with empty string values #4858
if (is_array($value)) {
$i = 0;
foreach ($value as $interval) {
$i++;
$multiple = $i > 1 ? TRUE : FALSE;
create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
}
} else {
create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id);
}
}
}
$owner->save();
// Notify of profile update
elgg_trigger_event('profileupdate', $owner->type, $owner);
}
return $this->get($params);
}
示例4: 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;
}
示例5: set
/**
* Add or update a config setting.
*
* Plugin authors should use elgg_set_config().
*
* If the config name already exists, it will be updated to the new value.
*
* @warning Names should be selected so as not to collide with the names for the
* datalist (application configuration)
*
* @note Internal: These settings are stored in the dbprefix_config table and read
* during system boot into $CONFIG.
*
* @note Internal: The value is serialized so we maintain type information.
*
* @param string $name The name of the configuration value
* @param mixed $value Its value
* @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
*
* @return bool
*/
function set($name, $value, $site_guid = 0)
{
$name = trim($name);
// cannot store anything longer than 255 characters in db, so catch before we set
if (elgg_strlen($name) > 255) {
_elgg_services()->logger->error("The name length for configuration variables cannot be greater than 255");
return false;
}
$site_guid = (int) $site_guid;
if ($site_guid == 0) {
$site_guid = (int) $this->CONFIG->site_guid;
}
if ($site_guid == $this->CONFIG->site_guid) {
$this->CONFIG->{$name} = $value;
}
$escaped_name = sanitize_string($name);
$escaped_value = sanitize_string(serialize($value));
$result = _elgg_services()->db->insertData("INSERT INTO {$this->CONFIG->dbprefix}config\n\t\t\tSET name = '{$escaped_name}', value = '{$escaped_value}', site_guid = {$site_guid}\n\t\t\tON DUPLICATE KEY UPDATE value = '{$escaped_value}'");
return $result !== false;
}
示例6: file_tools_generate_thumbs
function file_tools_generate_thumbs($file)
{
$formats = array("thumbnail" => 60, "smallthumb" => 153, "largethumb" => 600);
$file->icontime = time();
$filestorename = $file->getFilename();
$filestorename = elgg_substr($filestorename, elgg_strlen("file/"));
foreach ($formats as $name => $size) {
$thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), $size, $size, true);
if ($thumbnail) {
$filename = "file/{$name}" . $filestorename;
$thumb = new ElggFile();
$thumb->setFilename($filename);
$thumb->open("write");
$thumb->write($thumbnail);
$thumb->close();
$file->{$name} = $filename;
unset($thumbnail);
}
}
}
示例7: getFieldSearchWhereClause
/**
* Returns a where clause for a search query.
*
* @see search_get_where_sql
*
* @param str $table Prefix for table to search on
* @param array $fields Fields to match against
* @param array $params Original search params
* @param bool $use_fulltext Use fulltext search
* @return str
*/
public static function getFieldSearchWhereClause($table, $fields, $params, $use_fulltext = TRUE)
{
if (is_callable('search_get_where_sql')) {
return search_get_where_sql($table, $fields, $params, $use_fulltext);
}
$query = $params['query'];
// add the table prefix to the fields
foreach ($fields as $i => $field) {
if ($table) {
$fields[$i] = "{$table}.{$field}";
}
}
$where = '';
$search_info = elgg_get_config('search_info');
// if query is shorter than the min for fts words
// it's likely a single acronym or similar
// switch to literal mode
if (elgg_strlen($query) < $search_info['min_chars']) {
$likes = array();
$query = sanitise_string($query);
foreach ($fields as $field) {
$likes[] = "{$field} LIKE '%{$query}%'";
}
$likes_str = implode(' OR ', $likes);
$where = "({$likes_str})";
} else {
// if we're not using full text, rewrite the query for bool mode.
// exploiting a feature(ish) of bool mode where +-word is the same as -word
if (!$use_fulltext) {
$query = '+' . str_replace(' ', ' +', $query);
}
// if using advanced, boolean operators, or paired "s, switch into boolean mode
$booleans_used = preg_match("/([\\-\\+~])([\\w]+)/i", $query);
$advanced_search = isset($params['advanced_search']) && $params['advanced_search'];
$quotes_used = elgg_substr_count($query, '"') >= 2;
$options = '';
if (!$use_fulltext || $booleans_used || $advanced_search || $quotes_used) {
$options = 'IN BOOLEAN MODE';
}
$query = sanitise_string($query);
$fields_str = implode(',', $fields);
$where = "(MATCH ({$fields_str}) AGAINST ('{$query}' {$options}))";
}
return $where;
}
示例8: set_config
/**
* Add or update a config setting.
*
* If the config name already exists, it will be updated to the new value.
*
* @internal
* These settings are stored in the dbprefix_config table and read during system
* boot into $CONFIG.
*
* @param string $name The name of the configuration value
* @param string $value Its value
* @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
*
* @return bool
* @todo The config table doens't have numeric primary keys so insert_data returns 0.
* @todo Use "INSERT ... ON DUPLICATE KEY UPDATE" instead of trying to delete then add.
* @see unset_config()
* @see get_config()
* @access private
*/
function set_config($name, $value, $site_guid = 0)
{
global $CONFIG;
$name = trim($name);
// cannot store anything longer than 255 characters in db, so catch before we set
if (elgg_strlen($name) > 255) {
elgg_log("The name length for configuration variables cannot be greater than 255", "ERROR");
return false;
}
// Unset existing
unset_config($name, $site_guid);
$site_guid = (int) $site_guid;
if ($site_guid == 0) {
$site_guid = (int) $CONFIG->site_id;
}
$CONFIG->{$name} = $value;
$value = sanitise_string(serialize($value));
$query = "insert into {$CONFIG->dbprefix}config" . " set name = '{$name}', value = '{$value}', site_guid = {$site_guid}";
$result = insert_data($query);
return $result !== false;
}
示例9: 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']);
示例10: unlink
$video->tags = $tags;
// Save the entity to push attributes to database
// and to get access to guid if adding a new video
$video->save();
// we have a video upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
$prefix = "video/{$video->getGUID()}/";
// if previous video, delete it
if ($new_video == false) {
$videoname = $video->getFilenameOnFilestore();
if (file_exists($videoname)) {
unlink($videoname);
}
// use same videoname on the disk - ensures thumbnails are overwritten
$videostorename = $video->getFilename();
$videostorename = elgg_substr($videostorename, elgg_strlen($prefix));
} else {
$videostorename = elgg_strtolower($_FILES['upload']['name']);
}
$video->setFilename($prefix . $videostorename);
$mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
$video->setMimeType($mime_type);
$video->originalvideoname = $_FILES['upload']['name'];
$video->simpletype = 'video';
// Open the video to guarantee the directory exists
$video->open("write");
$video->close();
move_uploaded_file($_FILES['upload']['tmp_name'], $video->getFilenameOnFilestore());
// Change the directory mode
chmod($video->getFileDirectory(), 0775);
$guid = $video->save();
示例11: elgg_substr
if ($col == 3) {
echo "</tr>";
$col = 0;
}
}
if ($col < 3) {
echo "</tr>";
}
echo "</table>";
}
?>
</div>
</div>
<?php
$substr = elgg_substr($chararray, elgg_strlen($chararray) - 1, 1);
if ($letter == $substr) {
break;
}
//$letter++;
$letpos++;
$letter = elgg_substr($chararray, $letpos, 1);
}
?>
</div>
<?php
if ($formtarget) {
if (isset($vars['formcontents'])) {
echo $vars['formcontents'];
}
示例12: elgg_extract
<?php
/**
* Output view for elgg_get_excerpt
*
* @uses $vars['text'] The text to get the excerpt for
* @uses $vars['num_chars'] The max number of characters of the excerpt
* @uses $vars['suffix'] The suffix to be added if text is cut
*/
$text = elgg_extract('text', $vars);
$text = trim(elgg_strip_tags($text));
$suffix = elgg_extract('suffix', $vars, '...');
$string_length = elgg_strlen($text);
$num_chars = (int) elgg_extract('num_chars', $vars, 250);
if ($string_length <= $num_chars) {
echo $text;
return;
}
// 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 .= $suffix;
}
echo $excerpt;
示例13: set
/**
* Set the value for a datalist element.
*
* Plugin authors should use elgg_save_config() and pass null for the site GUID.
*
* @warning Names should be selected so as not to collide with the names for the
* site config.
*
* @warning Values set here are not available in $CONFIG until next page load.
*
* @param string $name The name of the datalist
* @param string $value The new value
*
* @return bool
* @access private
*/
function set($name, $value)
{
$name = trim($name);
// cannot store anything longer than 255 characters in db, so catch before we set
if (elgg_strlen($name) > 255) {
$this->logger->error("The name length for configuration variables cannot be greater than 255");
return false;
}
$escaped_name = $this->db->sanitizeString($name);
$escaped_value = $this->db->sanitizeString($value);
$success = $this->db->insertData("INSERT INTO {$this->table}" . " SET name = '{$escaped_name}', value = '{$escaped_value}'" . " ON DUPLICATE KEY UPDATE value = '{$escaped_value}'");
$this->cache->put($name, $value);
return $success !== false;
}
示例14: hj_framework_process_file_upload
/**
* Process uploaded files
*
* @param mixed $files Uploaded files
* @param mixed $entity If an entity is set and it doesn't belong to one of the file subtypes, uploaded files will be converted into hjFile objects and attached to the entity
* @return void
*/
function hj_framework_process_file_upload($name, $entity = null)
{
// Normalize the $_FILES array
if (is_array($_FILES[$name]['name'])) {
$files = hj_framework_prepare_files_global($_FILES);
$files = $files[$name];
} else {
$files = $_FILES[$name];
$files = array($files);
}
if (elgg_instanceof($entity)) {
if (!$entity instanceof hjFile) {
$is_attachment = true;
}
$subtype = $entity->getSubtype();
}
foreach ($files as $file) {
if (!is_array($file) || $file['error']) {
continue;
}
if ($is_attachment) {
$filehandler = new hjFile();
} else {
$filehandler = new hjFile($entity->guid);
}
$prefix = 'hjfile/';
if ($entity instanceof hjFile) {
$filename = $filehandler->getFilenameOnFilestore();
if (file_exists($filename)) {
unlink($filename);
}
$filestorename = $filehandler->getFilename();
$filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
} else {
$filestorename = elgg_strtolower(time() . $file['name']);
}
$filehandler->setFilename($prefix . $filestorename);
$filehandler->title = $file['name'];
$mime_type = ElggFile::detectMimeType($file['tmp_name'], $file['type']);
// hack for Microsoft zipped formats
$info = pathinfo($file['name']);
$office_formats = array('docx', 'xlsx', 'pptx');
if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
switch ($info['extension']) {
case 'docx':
$mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
case 'xlsx':
$mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
break;
case 'pptx':
$mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
break;
}
}
// check for bad ppt detection
if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
$mime_type = "application/vnd.ms-powerpoint";
}
$filehandler->setMimeType($mime_type);
$filehandler->originalfilename = $file['name'];
$filehandler->simpletype = hj_framework_get_simple_type($mime_type);
$filehandler->filesize = $file['size'];
$filehandler->open("write");
$filehandler->close();
move_uploaded_file($file['tmp_name'], $filehandler->getFilenameOnFilestore());
if ($filehandler->save()) {
if ($is_attachment && elgg_instanceof($entity)) {
make_attachment($entity->guid, $filehandler->getGUID());
}
// Generate icons for images
if ($filehandler->simpletype == "image") {
if (!elgg_instanceof($entity) || $is_attachment) {
// no entity provided or this is an attachment generating icons for self
hj_framework_generate_entity_icons($filehandler, $filehandler);
} else {
if (elgg_instanceof($entity)) {
hj_framework_generate_entity_icons($entity, $filehandler);
}
}
// the settings tell us not to keep the original image file, so downsizing to master
if (!HYPEFRAMEWORK_FILES_KEEP_ORIGINALS) {
$icon_sizes = hj_framework_get_thumb_sizes($subtype);
$values = $icon_sizes['master'];
$master = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']);
$filehandler->open('write');
$filehandler->write($master);
$filehandler->close();
}
}
$return[$file['name']] = $filehandler->getGUID();
} else {
$return[$file['name']] = false;
//.........这里部分代码省略.........
示例15: search_get_highlighted_relevant_substrings
/**
* Return a string with highlighted matched queries and relevant context
* Determines 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
* @param bool $tag_match Search is for tags. Don't ignore words.
* @return string
*/
function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300, $tag_match = false)
{
$haystack = strip_tags($haystack);
$haystack_length = elgg_strlen($haystack);
$haystack_lc = elgg_strtolower($haystack);
if (!$tag_match) {
$words = search_remove_ignored_words($query, 'array');
} else {
$words = 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);
$haystack_len = elgg_strlen($haystack_lc);
// 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;
if ($offset >= $haystack_len) {
break;
}
}
} 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 && $offsets) {
$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 .= '...';
//.........这里部分代码省略.........