本文整理汇总了PHP中shorten_text函数的典型用法代码示例。如果您正苦于以下问题:PHP shorten_text函数的具体用法?PHP shorten_text怎么用?PHP shorten_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shorten_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readquestions
protected function readquestions($lines)
{
// For this class the method has been simplified as
// there can never be more than one question for a
// multianswer import
$questions = array();
$questiontext = array();
$questiontext['text'] = implode('', $lines);
$questiontext['format'] = 0;
$questiontext['itemid'] = '';
$question = qtype_multianswer_extract_question($questiontext);
$question->questiontext = $question->questiontext['text'];
$question->questiontextformat = 0;
$question->qtype = MULTIANSWER;
$question->generalfeedback = '';
$question->course = $this->course;
if (!empty($question)) {
$name = html_to_text(implode(' ', $lines));
$name = preg_replace('/{[^}]*}/', '', $name);
$name = trim($name);
if ($name) {
$question->name = shorten_text($name, 45);
} else {
// We need some name, so use the current time, since that will be
// reasonably unique.
$question->name = userdate(time());
}
$questions[] = $question;
}
return $questions;
}
示例2: get_other_values
protected function get_other_values(renderer_base $output)
{
$contextcache = array();
$competencies = array();
foreach ($this->related['competencies'] as $competency) {
if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
$contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
}
$context = $contextcache[$competency->get_competencyframeworkid()];
$compexporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $compexporter->export($output);
}
$urlshort = '';
$url = $this->persistent->get_url();
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\\.)?@', '', $murl->out(false));
$urlshort = shorten_text($shorturl, 30, true);
}
$files = array();
$storedfiles = $this->persistent->get_files();
if (!empty($storedfiles)) {
foreach ($storedfiles as $storedfile) {
$fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context']));
$files[] = $fileexporter->export($output);
}
}
$values = array('canmanage' => $this->persistent->can_manage(), 'competencycount' => count($competencies), 'competencies' => $competencies, 'filecount' => count($files), 'files' => $files, 'hasurlorfiles' => !empty($files) || !empty($url), 'urlshort' => $urlshort);
return $values;
}
示例3: get_discussion_options
/**
* Generate options array for hierselect form element
*
* Creates a list of discussions.
*
* @return array
*/
public function get_discussion_options()
{
$options = array(0 => get_string('all', 'hsuforum'));
$rs = hsuforum_get_discussions($this->_customdata->cm, 'd.name');
foreach ($rs as $discussion) {
$options[$discussion->discussion] = shorten_text(format_string($discussion->name));
}
$rs->close();
return $options;
}
示例4: render_result
/**
* Displaying search results.
*
* @param \core_search\document Containing a single search response to be displayed.a
* @return string HTML
*/
public function render_result(\core_search\document $doc)
{
$docdata = $doc->export_for_template($this);
// Limit text fields size.
$docdata['title'] = shorten_text($docdata['title'], static::SEARCH_RESULT_STRING_SIZE, true);
$docdata['content'] = $docdata['content'] ? shorten_text($docdata['content'], static::SEARCH_RESULT_TEXT_SIZE, true) : '';
$docdata['description1'] = $docdata['description1'] ? shorten_text($docdata['description1'], static::SEARCH_RESULT_TEXT_SIZE, true) : '';
$docdata['description2'] = $docdata['description2'] ? shorten_text($docdata['description2'], static::SEARCH_RESULT_TEXT_SIZE, true) : '';
return $this->output->render_from_template('core_search/result', $docdata);
}
示例5: 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;
}
示例6: get_other_values
protected function get_other_values(renderer_base $output)
{
$filename = $this->file->get_filename();
$filenameshort = $filename;
if (core_text::strlen($filename) > 25) {
$filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..');
$filenameshort .= substr($filename, -4);
}
$icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file);
$iconurl = $output->pix_url($icon, 'core');
$url = moodle_url::make_pluginfile_url($this->file->get_contextid(), $this->file->get_component(), $this->file->get_filearea(), $this->file->get_itemid(), $this->file->get_filepath(), $this->file->get_filename(), true);
return array('filenameshort' => $filenameshort, 'filesizeformatted' => display_size((int) $this->file->get_filesize()), 'icon' => $icon, 'iconurl' => $iconurl->out(false), 'url' => $url->out(false), 'timecreatedformatted' => userdate($this->file->get_timecreated()), 'timemodifiedformatted' => userdate($this->file->get_timemodified()));
}
示例7: edit_form_add
public function edit_form_add(&$mform)
{
global $COURSE, $CFG;
require_once $CFG->dirroot . '/course/lib.php';
get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesusesd);
$modinfo = unserialize((string) $COURSE->modinfo);
$modules = array();
foreach ($mods as $mod) {
$instancename = urldecode($modinfo[$mod->id]->name);
$instancename = format_string($instancename, true, $COURSE->id);
$modules[$mod->id] = shorten_text($mod->modfullname . ': ' . $instancename, 28);
}
natcasesort($modules);
// Add our choose option to the front
$options = array(0 => get_string('choose', 'pagemenu')) + $modules;
$mform->addElement('select', 'moduleid', get_string('addmodule', 'pagemenu'), $options);
$mform->setType('moduleid', PARAM_INT);
}
示例8: get_text_for_indexing_txt
/**
* @param object $resource
* @uses $CFG
*/
function get_text_for_indexing_txt(&$resource, $directfile = '')
{
global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
return;
}
// just try to get text empirically from ppt binary flow
if ($directfile == '') {
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
} else {
$text = implode('', file("{$CFG->dataroot}/{$directfile}"));
}
if (!empty($CFG->block_search_limit_index_body)) {
$text = shorten_text($text, $CFG->block_search_limit_index_body);
}
return $text;
}
示例9: get_other_values
protected function get_other_values(renderer_base $output)
{
$urlshort = '';
$url = $this->persistent->get_url();
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\\.)?@', '', $murl->out(false));
$urlshort = shorten_text($shorturl, 30, true);
}
$files = array();
$storedfiles = $this->persistent->get_files();
if (!empty($storedfiles)) {
foreach ($storedfiles as $storedfile) {
$fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context']));
$files[] = $fileexporter->export($output);
}
}
$userevidencecompetencies = array();
$frameworks = array();
$scales = array();
$usercompetencies = $this->persistent->get_user_competencies();
foreach ($usercompetencies as $usercompetency) {
$competency = $usercompetency->get_competency();
// Get the framework.
if (!isset($frameworks[$competency->get_competencyframeworkid()])) {
$frameworks[$competency->get_competencyframeworkid()] = $competency->get_framework();
}
$framework = $frameworks[$competency->get_competencyframeworkid()];
// Get the scale.
$scaleid = $competency->get_scaleid();
if ($scaleid === null) {
$scaleid = $framework->get_scaleid();
}
if (!isset($scales[$framework->get_scaleid()])) {
$scales[$framework->get_scaleid()] = $framework->get_scale();
}
$scale = $scales[$framework->get_scaleid()];
$related = array('competency' => $competency, 'usercompetency' => $usercompetency, 'scale' => $scale, 'context' => $framework->get_context());
$userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related);
$userevidencecompetencies[] = $userevidencecompetencysummaryexporter->export($output);
}
$values = array('canmanage' => $this->persistent->can_manage(), 'filecount' => count($files), 'files' => $files, 'userhasplan' => $this->persistent->user_has_plan(), 'hasurlorfiles' => !empty($files) || !empty($url), 'urlshort' => $urlshort, 'competencycount' => count($userevidencecompetencies), 'usercompetencies' => $userevidencecompetencies);
return $values;
}
示例10: get_text_for_indexing_xml
/**
* @param object $resource
* @uses $CFG
*/
function get_text_for_indexing_xml(&$resource, $directfile = '')
{
global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
return;
}
// just get text
if ($directfile == '') {
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
} else {
$text = implode('', file("{$CFG->dataroot}/{$directfile}"));
}
// filter out all xml tags
$text = preg_replace("/<[^>]*>/", ' ', $text);
if (!empty($CFG->block_search_limit_index_body)) {
$text = shorten_text($text, $CFG->block_search_limit_index_body);
}
return $text;
}
示例11: get_text_for_indexing_htm
/**
* @param object $resource
* @uses $CFG
*/
function get_text_for_indexing_htm(&$resource, $directfile = '')
{
global $CFG;
// SECURITY : do not allow non admin execute anything on system !!
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
return;
}
// just get text
if ($directfile == '') {
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
} else {
$text = implode('', file("{$CFG->dataroot}/{$directfile}"));
}
// extract keywords and other interesting meta information and put it back as real content for indexing
if (preg_match('/(.*)<meta ([^>]*)>(.*)/is', $text, $matches)) {
$prefix = $matches[1];
$meta_attributes = $matches[2];
$suffix = $matches[3];
if (preg_match('/name="(keywords|description)"/i', $meta_attributes)) {
preg_match('/content="([^"]+)"/i', $meta_attributes, $matches);
$text = $prefix . ' ' . $matches[1] . ' ' . $suffix;
}
}
// brutally filters all html tags
$text = preg_replace("/<[^>]*>/", '', $text);
$text = preg_replace("/<!--[^>]*-->/", '', $text);
$text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
$text = mb_convert_encoding($text, 'UTF-8', 'auto');
/*
* debug code for tracing input
echo "<hr/>";
$FILE = fopen("filetrace.log", 'w');
fwrite($FILE, $text);
fclose($FILE);
echo "<hr/>";
*/
if (!empty($CFG->block_search_limit_index_body)) {
$text = shorten_text($text, $CFG->block_search_limit_index_body);
}
return $text;
}
示例12: export_for_template
public function export_for_template(\renderer_base $output)
{
global $USER;
$context = clone $this->notification;
if ($context->useridto == $USER->id && $context->timeusertodeleted) {
$context->deleted = true;
} else {
$context->deleted = false;
}
$context->timecreatedpretty = get_string('ago', 'message', format_time(time() - $context->timecreated));
$context->text = message_format_message_text($context);
$context->read = $context->timeread ? true : false;
$context->shortenedsubject = shorten_text($context->subject, 125);
if (!empty($context->component) && substr($context->component, 0, 4) == 'mod_') {
$iconurl = $output->pix_url('icon', $context->component);
} else {
$iconurl = $output->pix_url('i/marker', 'core');
}
$context->iconurl = $iconurl->out();
return $context;
}
示例13: readquestions
public function readquestions($lines) {
question_bank::get_qtype('multianswer'); // Ensure the multianswer code is loaded.
// For this class the method has been simplified as
// there can never be more than one question for a
// multianswer import.
$questions = array();
$questiontext = array();
$questiontext['text'] = implode('', $lines);
$questiontext['format'] = FORMAT_MOODLE;
$questiontext['itemid'] = '';
$question = qtype_multianswer_extract_question($questiontext);
$question->questiontext = $question->questiontext['text'];
$question->questiontextformat = 0;
$question->qtype = 'multianswer';
$question->generalfeedback = '';
$question->generalfeedbackformat = FORMAT_MOODLE;
$question->length = 1;
$question->penalty = 0.3333333;
if (!empty($question)) {
$name = html_to_text(implode(' ', $lines));
$name = preg_replace('/{[^}]*}/', '', $name);
$name = trim($name);
if ($name) {
$question->name = shorten_text($name, 45);
} else {
// We need some name, so use the current time, since that will be
// reasonably unique.
$question->name = userdate(time());
}
$questions[] = $question;
}
return $questions;
}
示例14: edit_form_add
public function edit_form_add(&$mform)
{
global $COURSE, $CFG;
require_once $CFG->dirroot . '/course/lib.php';
$modinfo = get_fast_modinfo($COURSE);
$modules = array();
foreach ($modinfo->cms as $cm) {
$modules[$cm->modplural][$cm->id] = shorten_text(format_string($cm->name, true, $COURSE->id), 28);
}
// Fix the sorting
$options = array();
$modnames = array_keys($modules);
natcasesort($modnames);
foreach ($modnames as $modname) {
$mods = $modules[$modname];
natcasesort($mods);
$options[$modname] = $mods;
}
// Add our choose option to the front
$options = array('' => array(0 => get_string('choose', 'pagemenu'))) + $options;
$mform->addElement('selectgroups', 'moduleid', get_string('addmodule', 'pagemenu'), $options);
$mform->setType('moduleid', PARAM_INT);
}
示例15: comment_on_datasetitems
public function comment_on_datasetitems($qtypeobj, $questionid, $questiontext, $answers, $data, $number)
{
global $DB;
$comment = new stdClass();
$comment->stranswers = array();
$comment->outsidelimit = false;
$comment->answers = array();
// Find a default unit.
if (!empty($questionid) && ($unit = $DB->get_record('question_numerical_units', array('question' => $questionid, 'multiplier' => 1.0)))) {
$unit = $unit->unit;
} else {
$unit = '';
}
$answers = fullclone($answers);
$delimiter = ': ';
$virtualqtype = $qtypeobj->get_virtual_qtype();
foreach ($answers as $key => $answer) {
$error = qtype_calculated_find_formula_errors($answer->answer);
if ($error) {
$comment->stranswers[$key] = $error;
continue;
}
$formula = $this->substitute_variables($answer->answer, $data);
$formattedanswer = qtype_calculated_calculate_answer($answer->answer, $data, $answer->tolerance, $answer->tolerancetype, $answer->correctanswerlength, $answer->correctanswerformat, $unit);
if ($formula === '*') {
$answer->min = ' ';
$formattedanswer->answer = $answer->answer;
} else {
eval('$ansvalue = ' . $formula . ';');
$ans = new qtype_numerical_answer(0, $ansvalue, 0, '', 0, $answer->tolerance);
$ans->tolerancetype = $answer->tolerancetype;
list($answer->min, $answer->max) = $ans->get_tolerance_interval($answer);
}
if ($answer->min === '') {
// This should mean that something is wrong.
$comment->stranswers[$key] = " {$formattedanswer->answer}" . '<br/><br/>';
} else {
if ($formula === '*') {
$comment->stranswers[$key] = $formula . ' = ' . get_string('anyvalue', 'qtype_calculated') . '<br/><br/><br/>';
} else {
$formula = shorten_text($formula, 57, true);
$comment->stranswers[$key] = $formula . ' = ' . $formattedanswer->answer . '<br/>';
$correcttrue = new stdClass();
$correcttrue->correct = $formattedanswer->answer;
$correcttrue->true = '';
if ($formattedanswer->answer < $answer->min || $formattedanswer->answer > $answer->max) {
$comment->outsidelimit = true;
$comment->answers[$key] = $key;
$comment->stranswers[$key] .= get_string('trueansweroutsidelimits', 'qtype_calculated', $correcttrue);
} else {
$comment->stranswers[$key] .= get_string('trueanswerinsidelimits', 'qtype_calculated', $correcttrue);
}
$comment->stranswers[$key] .= '<br/>';
$comment->stranswers[$key] .= get_string('min', 'qtype_calculated') . $delimiter . $answer->min . ' --- ';
$comment->stranswers[$key] .= get_string('max', 'qtype_calculated') . $delimiter . $answer->max;
}
}
}
return fullclone($comment);
}