本文整理汇总了PHP中core_text::strlen方法的典型用法代码示例。如果您正苦于以下问题:PHP core_text::strlen方法的具体用法?PHP core_text::strlen怎么用?PHP core_text::strlen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_text
的用法示例。
在下文中一共展示了core_text::strlen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: col_name
/**
* Determine output for the name column.
*
* @param stdClass $recording The recording row being worked on.
* @return string The output to display.
*/
public function col_name($recording)
{
if (\core_text::strlen($recording->name) > 60) {
return \core_text::substr($recording->name, 0, 55) . '…';
}
return $recording->name;
}
示例2: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
if (empty($data['shorten']) and core_text::strlen($data['search']) < core_text::strlen($data['replace'])) {
$errors['shorten'] = get_string('required');
}
return $errors;
}
示例3: block_course_overview_update_myorder
/**
* Sets user course sorting preference in course_overview block
*
* @param array $sortorder list of course ids
*/
function block_course_overview_update_myorder($sortorder)
{
$value = implode(',', $sortorder);
if (core_text::strlen($value) > 1333) {
// The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice).
$value = preg_replace('/,[\\d]*$/', '', core_text::substr($value, 0, 1334));
}
set_user_preference('course_overview_course_sortorder', $value);
}
示例4: get_trainingevent_name
/**
* @uses COURSECLASSROOM_MAX_NAME_LENGTH
* @param object $trainingevent
* @return string
*/
function get_trainingevent_name($trainingevent)
{
$name = strip_tags(format_string($trainingevent->name, true));
if (core_text::strlen($name) > COURSECLASSROOM_MAX_NAME_LENGTH) {
$name = core_text::substr($name, 0, COURSECLASSROOM_MAX_NAME_LENGTH) . "...";
}
if (empty($name)) {
// Arbitrary name.
$name = get_string('modulename', 'trainingevent');
}
return $name;
}
示例5: validate
/**
* Validates a value using a range comparison
*
* @param string $value Value to be checked
* @param mixed $options Int for length, array for range
* @access public
* @return boolean true if value is valid
*/
function validate($value, $options = null)
{
$length = core_text::strlen($value);
switch ($this->name) {
case 'minlength':
return $length >= $options;
case 'maxlength':
return $length <= $options;
default:
return $length >= $options[0] && $length <= $options[1];
}
}
示例6: get_label_name
/**
* @uses LABEL_MAX_NAME_LENGTH
* @param object $label
* @return string
*/
function get_label_name($label)
{
$name = strip_tags(format_string($label->intro, true));
if (core_text::strlen($name) > LABEL_MAX_NAME_LENGTH) {
$name = core_text::substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
}
if (empty($name)) {
// arbitrary name
$name = get_string('modulename', 'label');
}
return $name;
}
示例7: send_message
/**
* Processes the message and sends a notification via airnotifier
*
* @param stdClass $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
* @return true if ok, false if error
*/
public function send_message($eventdata)
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
if (!empty($CFG->noemailever)) {
// Hidden setting for development sites, set in config.php if needed.
debugging('$CFG->noemailever active, no airnotifier message sent.', DEBUG_MINIMAL);
return true;
}
// Skip any messaging suspended and deleted users.
if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
return true;
}
// Site id, to map with Moodle Mobile stored sites.
$siteid = md5($CFG->wwwroot . $eventdata->userto->username);
// Mandatory notification data that need to be sent in the payload. They have variable length.
// We need to take them in consideration to calculate the maximum message size.
$notificationdata = array("site" => $siteid, "type" => $eventdata->component . '_' . $eventdata->name, "device" => "xxxxxxxxxx", "notif" => "x", "userfrom" => !empty($eventdata->userfrom) ? fullname($eventdata->userfrom) : '');
// Calculate the size of the message knowing Apple payload must be lower than 256 bytes.
// Airnotifier using few bytes of the payload, we must limit our message to even less characters.
$maxmsgsize = 205 - core_text::strlen(json_encode($notificationdata));
$message = s($eventdata->smallmessage);
// If the message size is too big make it shorter.
if (core_text::strlen($message) >= $maxmsgsize) {
// Cut the message to the maximum possible size. -4 for the the ending 3 dots (...).
$message = core_text::substr($message, 0, $maxmsgsize - 4);
// We need to check when the message is "escaped" then the message is not too long.
$encodedmsgsize = core_text::strlen(json_encode($message));
if ($encodedmsgsize > $maxmsgsize) {
$totalescapedchar = $encodedmsgsize - core_text::strlen($message);
// Cut the message to the maximum possible size (taking the escaped character in account).
$message = core_text::substr($message, 0, $maxmsgsize - 4 - $totalescapedchar);
}
$message = $message . '...';
}
// We are sending to message to all devices.
$airnotifiermanager = new message_airnotifier_manager();
$devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $eventdata->userto->id);
foreach ($devicetokens as $devicetoken) {
if (!$devicetoken->enable) {
continue;
}
// Sending the message to the device.
$serverurl = $CFG->airnotifierurl . ':' . $CFG->airnotifierport . '/notification/';
$header = array('Accept: application/json', 'X-AN-APP-NAME: ' . $CFG->airnotifierappname, 'X-AN-APP-KEY: ' . $CFG->airnotifieraccesskey);
$curl = new curl();
$curl->setHeader($header);
$params = array('alert' => $message, 'date' => !empty($eventdata->timecreated) ? $eventdata->timecreated : time(), 'site' => $siteid, 'type' => $eventdata->component . '_' . $eventdata->name, 'userfrom' => !empty($eventdata->userfrom) ? fullname($eventdata->userfrom) : '', 'device' => $devicetoken->platform, 'notif' => !empty($eventdata->notification) ? '1' : '0', 'token' => $devicetoken->pushid);
$resp = $curl->post($serverurl, $params);
}
return true;
}
示例8: shorten_post_name
/**
* Prevent name from exceeding 255 chars.
*/
public static function shorten_post_name($name)
{
$strre = get_string('re', 'hsuforum');
if (\core_text::strlen($name) > 255) {
$shortened = shorten_text($name, 255);
if (trim(str_ireplace($strre, '', $shortened)) === '...' || \core_text::strlen($shortened) > 255) {
// Make a 2nd pass with the 'exact' param true, as shortening on word boundary failed or exceeded 255 chars.
$shortened = shorten_text($name, 255, true);
}
$name = $shortened;
}
return $name;
}
示例9: save_usage
public function save_usage($preferredbehaviour, $attempt, $qas, $quizlayout)
{
global $OUTPUT;
$missing = array();
$layout = explode(',', $attempt->layout);
$questionkeys = array_combine(array_values($layout), array_keys($layout));
$this->set_quba_preferred_behaviour($attempt->uniqueid, $preferredbehaviour);
$i = 0;
foreach (explode(',', $quizlayout) as $questionid) {
if ($questionid == 0) {
continue;
}
$i++;
if (!array_key_exists($questionid, $qas)) {
$missing[] = $questionid;
$layout[$questionkeys[$questionid]] = $questionid;
continue;
}
$qa = $qas[$questionid];
$qa->questionusageid = $attempt->uniqueid;
$qa->slot = $i;
if (core_text::strlen($qa->questionsummary) > question_bank::MAX_SUMMARY_LENGTH) {
// It seems some people write very long quesions! MDL-30760
$qa->questionsummary = core_text::substr($qa->questionsummary, 0, question_bank::MAX_SUMMARY_LENGTH - 3) . '...';
}
$this->insert_record('question_attempts', $qa);
$layout[$questionkeys[$questionid]] = $qa->slot;
foreach ($qa->steps as $step) {
$step->questionattemptid = $qa->id;
$this->insert_record('question_attempt_steps', $step);
foreach ($step->data as $name => $value) {
$datum = new stdClass();
$datum->attemptstepid = $step->id;
$datum->name = $name;
$datum->value = $value;
$this->insert_record('question_attempt_step_data', $datum, false);
}
}
}
$this->set_quiz_attempt_layout($attempt->uniqueid, implode(',', $layout));
if ($missing) {
$message = "Question sessions for questions " . implode(', ', $missing) . " were missing when upgrading question usage {$attempt->uniqueid}.";
echo $OUTPUT->notification($message);
}
}
示例10: rfc2445_fold
function rfc2445_fold($string)
{
if (core_text::strlen($string, 'utf-8') <= RFC2445_FOLDED_LINE_LENGTH) {
return $string;
}
$retval = '';
$i = 0;
$len_count = 0;
//multi-byte string, get the correct length
$section_len = core_text::strlen($string, 'utf-8');
while ($len_count < $section_len) {
//get the current portion of the line
$section = core_text::substr($string, $i * RFC2445_FOLDED_LINE_LENGTH, RFC2445_FOLDED_LINE_LENGTH, 'utf-8');
//increment the length we've processed by the length of the new portion
$len_count += core_text::strlen($section, 'utf-8');
/* Add the portion to the return value, terminating with CRLF.HTAB
As per RFC 2445, CRLF.HTAB will be replaced by the processor of the
data */
$retval .= $section . RFC2445_CRLF . substr(RFC2445_WSP, 0, 1);
$i++;
}
return $retval;
}
示例11: tag_print_user_box
/**
* Prints an individual user box
*
* @deprecated since 3.1
* @param user_object $user (contains the following fields: id, firstname, lastname and picture)
* @param bool $return if true return html string
* @return string|null a HTML string or null if this function does the output
*/
function tag_print_user_box($user, $return = false)
{
global $CFG, $OUTPUT;
debugging('Function tag_print_user_box() is deprecated without replacement. ' . 'See core_user_renderer for similar code.', DEBUG_DEVELOPER);
$usercontext = context_user::instance($user->id);
$profilelink = '';
if ($usercontext and has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id)) {
$profilelink = $CFG->wwwroot . '/user/view.php?id=' . $user->id;
}
$output = $OUTPUT->box_start('user-box', 'user' . $user->id);
$fullname = fullname($user);
$alt = '';
if (!empty($profilelink)) {
$output .= '<a href="' . $profilelink . '">';
$alt = $fullname;
}
$output .= $OUTPUT->user_picture($user, array('size' => 100));
$output .= '<br />';
if (!empty($profilelink)) {
$output .= '</a>';
}
//truncate name if it's too big
if (core_text::strlen($fullname) > 26) {
$fullname = core_text::substr($fullname, 0, 26) . '...';
}
$output .= '<strong>' . $fullname . '</strong>';
$output .= $OUTPUT->box_end();
if ($return) {
return $output;
} else {
echo $output;
}
}
示例12: blog_sync_external_entries
/**
* Given a record in the {blog_external} table, checks the blog's URL
* for new entries not yet copied into Moodle.
* Also attempts to identify and remove deleted blog entries
*
* @param object $externalblog
* @return boolean False if the Feed is invalid
*/
function blog_sync_external_entries($externalblog)
{
global $CFG, $DB;
require_once $CFG->libdir . '/simplepie/moodle_simplepie.php';
$rss = new moodle_simplepie();
$rssfile = $rss->registry->create('File', array($externalblog->url));
$filetest = $rss->registry->create('Locator', array($rssfile));
if (!$filetest->is_feed($rssfile)) {
$externalblog->failedlastsync = 1;
$DB->update_record('blog_external', $externalblog);
return false;
} else {
if (!empty($externalblog->failedlastsync)) {
$externalblog->failedlastsync = 0;
$DB->update_record('blog_external', $externalblog);
}
}
$rss->set_feed_url($externalblog->url);
$rss->init();
if (empty($rss->data)) {
return null;
}
//used to identify blog posts that have been deleted from the source feed
$oldesttimestamp = null;
$uniquehashes = array();
foreach ($rss->get_items() as $entry) {
// If filtertags are defined, use them to filter the entries by RSS category
if (!empty($externalblog->filtertags)) {
$containsfiltertag = false;
$categories = $entry->get_categories();
$filtertags = explode(',', $externalblog->filtertags);
$filtertags = array_map('trim', $filtertags);
$filtertags = array_map('strtolower', $filtertags);
foreach ($categories as $category) {
if (in_array(trim(strtolower($category->term)), $filtertags)) {
$containsfiltertag = true;
}
}
if (!$containsfiltertag) {
continue;
}
}
$uniquehashes[] = $entry->get_permalink();
$newentry = new stdClass();
$newentry->userid = $externalblog->userid;
$newentry->module = 'blog_external';
$newentry->content = $externalblog->id;
$newentry->uniquehash = $entry->get_permalink();
$newentry->publishstate = 'site';
$newentry->format = FORMAT_HTML;
// Clean subject of html, just in case
$newentry->subject = clean_param($entry->get_title(), PARAM_TEXT);
// Observe 128 max chars in DB
// TODO: +1 to raise this to 255
if (core_text::strlen($newentry->subject) > 128) {
$newentry->subject = core_text::substr($newentry->subject, 0, 125) . '...';
}
$newentry->summary = $entry->get_description();
//used to decide whether to insert or update
//uses enty permalink plus creation date if available
$existingpostconditions = array('uniquehash' => $entry->get_permalink());
//our DB doesnt allow null creation or modified timestamps so check the external blog supplied one
$entrydate = $entry->get_date('U');
if (!empty($entrydate)) {
$existingpostconditions['created'] = $entrydate;
}
//the post ID or false if post not found in DB
$postid = $DB->get_field('post', 'id', $existingpostconditions);
$timestamp = null;
if (empty($entrydate)) {
$timestamp = time();
} else {
$timestamp = $entrydate;
}
//only set created if its a new post so we retain the original creation timestamp if the post is edited
if ($postid === false) {
$newentry->created = $timestamp;
}
$newentry->lastmodified = $timestamp;
if (empty($oldesttimestamp) || $timestamp < $oldesttimestamp) {
//found an older post
$oldesttimestamp = $timestamp;
}
if (core_text::strlen($newentry->uniquehash) > 255) {
// The URL for this item is too long for the field. Rather than add
// the entry without the link we will skip straight over it.
// RSS spec says recommended length 500, we use 255.
debugging('External blog entry skipped because of oversized URL', DEBUG_DEVELOPER);
continue;
}
if ($postid === false) {
$id = $DB->insert_record('post', $newentry);
//.........这里部分代码省略.........
示例13: get_short_filename
/**
* Create a shorten filename
*
* @param string $str filename
* @param int $maxlength max file name length
* @return string short filename
*/
public function get_short_filename($str, $maxlength)
{
if (core_text::strlen($str) >= $maxlength) {
return trim(core_text::substr($str, 0, $maxlength)) . '...';
} else {
return $str;
}
}
示例14: legacy_add_to_log
/**
* Legacy add_to_log() code.
*
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int|\stdClass $user If log regards $user other than $USER
*/
public function legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user)
{
// Note that this function intentionally does not follow the normal Moodle DB access idioms.
// This is for a good reason: it is the most frequently used DB update function,
// so it has been optimised for speed.
global $DB, $CFG, $USER;
if (!$this->is_logging()) {
return;
}
if ($cm === '' || is_null($cm)) {
// Postgres won't translate empty string to its default.
$cm = 0;
}
if ($user) {
$userid = $user;
} else {
if (\core\session\manager::is_loggedinas()) {
// Don't log.
return;
}
$userid = empty($USER->id) ? '0' : $USER->id;
}
if (isset($CFG->logguests) and !$CFG->logguests) {
if (!$userid or isguestuser($userid)) {
return;
}
}
$remoteaddr = getremoteaddr();
$timenow = time();
if (!empty($url)) {
// Could break doing html_entity_decode on an empty var.
$url = html_entity_decode($url, ENT_QUOTES, 'UTF-8');
} else {
$url = '';
}
// Restrict length of log lines to the space actually available in the
// database so that it doesn't cause a DB error. Log a warning so that
// developers can avoid doing things which are likely to cause this on a
// routine basis.
if (\core_text::strlen($action) > 40) {
$action = \core_text::substr($action, 0, 37) . '...';
debugging('Warning: logged very long action', DEBUG_DEVELOPER);
}
if (!empty($info) && \core_text::strlen($info) > 255) {
$info = \core_text::substr($info, 0, 252) . '...';
debugging('Warning: logged very long info', DEBUG_DEVELOPER);
}
// If the 100 field size is changed, also need to alter print_log in course/lib.php.
if (!empty($url) && \core_text::strlen($url) > 100) {
$url = \core_text::substr($url, 0, 97) . '...';
debugging('Warning: logged very long URL', DEBUG_DEVELOPER);
}
if (defined('MDL_PERFDB')) {
global $PERF;
$PERF->logwrites++;
}
$log = array('time' => $timenow, 'userid' => $userid, 'course' => $courseid, 'ip' => $remoteaddr, 'module' => $module, 'cmid' => $cm, 'action' => $action, 'url' => $url, 'info' => $info);
try {
$DB->insert_record_raw('log', $log, false);
} catch (\dml_exception $e) {
debugging('Error: Could not insert a new entry to the Moodle log. ' . $e->errorcode, DEBUG_ALL);
// MDL-11893, alert $CFG->supportemail if insert into log failed.
if ($CFG->supportemail and empty($CFG->noemailever)) {
// Function email_to_user is not usable because email_to_user tries to write to the logs table,
// and this will get caught in an infinite loop, if disk is full.
$site = get_site();
$subject = 'Insert into log failed at your moodle site ' . $site->fullname;
$message = "Insert into log table failed at " . date('l dS \\of F Y h:i:s A') . ".\n It is possible that your disk is full.\n\n";
$message .= "The failed query parameters are:\n\n" . var_export($log, true);
$lasttime = get_config('admin', 'lastloginserterrormail');
if (empty($lasttime) || time() - $lasttime > 60 * 60 * 24) {
// Limit to 1 email per day.
// Using email directly rather than messaging as they may not be able to log in to access a message.
mail($CFG->supportemail, $subject, $message);
set_config('lastloginserterrormail', time(), 'admin');
}
}
}
}
示例15: update
/**
* Updates the record with either form data or raw data
*
* Please note that this function does not verify access control.
*
* This function calls coursecat::change_parent_raw if field 'parent' is updated.
* It also calls coursecat::hide_raw or coursecat::show_raw if 'visible' is updated.
* Visibility is changed first and then parent is changed. This means that
* if parent category is hidden, the current category will become hidden
* too and it may overwrite whatever was set in field 'visible'.
*
* Note that fields 'path' and 'depth' can not be updated manually
* Also coursecat::update() can not directly update the field 'sortoder'
*
* @param array|stdClass $data
* @param array $editoroptions if specified, the data is considered to be
* form data and file_postupdate_standard_editor() is being called to
* process images in description.
* @throws moodle_exception
*/
public function update($data, $editoroptions = null)
{
global $DB, $CFG;
if (!$this->id) {
// There is no actual DB record associated with root category.
return;
}
$data = (object) $data;
$newcategory = new stdClass();
$newcategory->id = $this->id;
// Copy all description* fields regardless of whether this is form data or direct field update.
foreach ($data as $key => $value) {
if (preg_match("/^description/", $key)) {
$newcategory->{$key} = $value;
}
}
if (isset($data->name) && empty($data->name)) {
throw new moodle_exception('categorynamerequired');
}
if (!empty($data->name) && $data->name !== $this->name) {
if (core_text::strlen($data->name) > 255) {
throw new moodle_exception('categorytoolong');
}
$newcategory->name = $data->name;
}
if (isset($data->idnumber) && $data->idnumber != $this->idnumber) {
if (core_text::strlen($data->idnumber) > 100) {
throw new moodle_exception('idnumbertoolong');
}
if ($DB->record_exists('course_categories', array('idnumber' => $data->idnumber))) {
throw new moodle_exception('categoryidnumbertaken');
}
$newcategory->idnumber = $data->idnumber;
}
if (isset($data->theme) && !empty($CFG->allowcategorythemes)) {
$newcategory->theme = $data->theme;
}
$changes = false;
if (isset($data->visible)) {
if ($data->visible) {
$changes = $this->show_raw();
} else {
$changes = $this->hide_raw(0);
}
}
if (isset($data->parent) && $data->parent != $this->parent) {
if ($changes) {
cache_helper::purge_by_event('changesincoursecat');
}
$parentcat = self::get($data->parent, MUST_EXIST, true);
$this->change_parent_raw($parentcat);
fix_course_sortorder();
}
$newcategory->timemodified = time();
$categorycontext = $this->get_context();
if ($editoroptions) {
$newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'coursecat', 'description', 0);
}
$DB->update_record('course_categories', $newcategory);
$event = \core\event\course_category_updated::create(array('objectid' => $newcategory->id, 'context' => $categorycontext));
$event->trigger();
fix_course_sortorder();
// Purge cache even if fix_course_sortorder() did not do it.
cache_helper::purge_by_event('changesincoursecat');
// Update all fields in the current object.
$this->restore();
}