本文整理汇总了PHP中s函数的典型用法代码示例。如果您正苦于以下问题:PHP s函数的具体用法?PHP s怎么用?PHP s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter_text_image
function filter_text_image($imagefile, $tex = "", $height = "", $width = "", $align = "middle", $alt = '')
{
global $CFG, $OUTPUT;
if ($alt === '') {
$alt = s($tex);
}
// Work out any necessary inline style.
$rules = array();
if ($align !== 'middle') {
$rules[] = 'vertical-align:' . $align . ';';
}
if ($height) {
$rules[] = 'height:' . $height . 'px;';
}
if ($width) {
$rules[] = 'width:' . $width . 'px;';
}
if (!empty($rules)) {
$style = ' style="' . implode('', $rules) . '" ';
} else {
$style = '';
}
// Prepare the title attribute.
if ($tex) {
$tex = str_replace('&', '&', $tex);
$tex = str_replace('<', '<', $tex);
$tex = str_replace('>', '>', $tex);
$tex = str_replace('"', '"', $tex);
$tex = str_replace("\\'", ''', $tex);
// Note that we retain the title tag as TeX format rather than using
// the alt text, even if supplied. The alt text is intended for blind
// users (to provide a text equivalent to the equation) while the title
// is there as a convenience for sighted users who want to see the TeX
// code.
$title = "title=\"{$tex}\"";
}
// Build the output.
$output = "";
if ($imagefile) {
$anchorcontents = "<img class=\"texrender\" {$title} alt=\"{$alt}\" src=\"";
if ($CFG->slasharguments) {
// Use this method if possible for better caching
$anchorcontents .= "{$CFG->wwwroot}/filter/tex/pix.php/{$imagefile}";
} else {
$anchorcontents .= "{$CFG->wwwroot}/filter/tex/pix.php?file={$imagefile}";
}
$anchorcontents .= "\" {$style}/>";
$link = $action = null;
if (!file_exists("{$CFG->dataroot}/filter/tex/{$imagefile}") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
$link = '/filter/tex/texdebug.php';
} else {
$link = '/filter/tex/displaytex.php?' . urlencode($tex);
$action = new popup_action('click', $link, 'popup', array('height' => 300, 'width' => 240));
}
$output .= $OUTPUT->action_link($link, $anchorcontents, $action, array('title' => 'TeX'));
} else {
$output .= "Error: must pass URL or course";
}
return $output;
}
示例2: getMessage
/**
* @return string
*/
public function getMessage()
{
if ($this->message !== null) {
return $this->message;
}
return s('Must not be greater than "%s".', $this->max);
}
示例3: display_add_field
function display_add_field($recordid = 0)
{
global $CFG, $DB;
if ($recordid) {
$content = trim($DB->get_field('data_content', 'content', array('fieldid' => $this->field->id, 'recordid' => $recordid)));
} else {
$content = '';
}
$str = '<div title="' . s($this->field->description) . '">';
$str .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>';
$i = 0;
foreach (explode("\n", $this->field->param1) as $radio) {
$radio = trim($radio);
if ($radio === '') {
continue;
// skip empty lines
}
$str .= '<input type="radio" id="field_' . $this->field->id . '_' . $i . '" name="field_' . $this->field->id . '" ';
$str .= 'value="' . s($radio) . '" ';
if ($content == $radio) {
// Selected by user.
$str .= 'checked />';
} else {
$str .= '/>';
}
$str .= '<label for="field_' . $this->field->id . '_' . $i . '">' . $radio . '</label><br />';
$i++;
}
$str .= '</fieldset>';
$str .= '</div>';
return $str;
}
示例4: export_for_template
/**
* Function to export the renderer data in a format that is suitable for a
* mustache template. This means:
* 1. No complex types - only stdClass, array, int, string, float, bool
* 2. Any additional info that is required for the template is pre-calculated (e.g. capability checks).
*
* This trait can be used as-is for simple form elements - or imported with a different name
* so it can be extended with additional context variables before being returned.
*
* @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return stdClass|array
*/
public function export_for_template(renderer_base $output)
{
$context = [];
// Not all elements have all of these attributes - but they are common enough to be valid for a few.
$standardattributes = ['id', 'name', 'label', 'multiple', 'checked', 'error', 'size', 'value'];
$standardproperties = ['helpbutton', 'hiddenLabel'];
// Standard attributes.
foreach ($standardattributes as $attrname) {
$value = $this->getAttribute($attrname);
$context[$attrname] = $value;
}
// Standard class properties.
foreach ($standardproperties as $propname) {
$classpropname = '_' . $propname;
$context[strtolower($propname)] = isset($this->{$classpropname}) ? $this->{$classpropname} : false;
}
$extraclasses = $this->getAttribute('class');
// Special wierd named property.
$context['frozen'] = !empty($this->_flagFrozen);
$context['hardfrozen'] = !empty($this->_flagFrozen) && empty($this->_persistantFreeze);
// Other attributes.
$otherattributes = [];
foreach ($this->getAttributes() as $attr => $value) {
if (!in_array($attr, $standardattributes) && $attr != 'class' && !is_object($value)) {
$otherattributes[] = $attr . '="' . s($value) . '"';
}
}
$context['extraclasses'] = $extraclasses;
$context['type'] = $this->getType();
$context['attributes'] = implode(' ', $otherattributes);
return $context;
}
示例5: restore_data
public static function restore_data($data, $restore)
{
$linknamestatus = $linkurlstatus = false;
foreach ($data as $datum) {
switch ($datum->name) {
case 'linkname':
// We just want to know that it is there
$linknamestatus = true;
break;
case 'linkurl':
$content = $datum->value;
$result = restore_decode_content_links_worker($content, $restore);
if ($result != $content) {
$datum->value = addslashes($result);
if (debugging() and !defined('RESTORE_SILENTLY')) {
echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
}
$linkurlstatus = update_record('pagemenu_link_data', $datum);
} else {
$linkurlstatus = true;
}
break;
default:
debugging('Deleting unknown data type: ' . $datum->name);
// Not recognized
delete_records('pagemenu_link_data', 'id', $datum->id);
break;
}
}
return $linkurlstatus and $linknamestatus;
}
示例6: display_search_field
function display_search_field($value = '')
{
global $CFG, $DB;
if (is_array($value)) {
$content = $value['checked'];
$allrequired = $value['allrequired'] ? true : false;
} else {
$content = array();
$allrequired = false;
}
$str = '';
$found = false;
foreach (explode("\n", $this->field->param1) as $checkbox) {
$checkbox = trim($checkbox);
if (in_array($checkbox, $content)) {
$str .= html_writer::checkbox('f_' . $this->field->id . '[]', s($checkbox), true, $checkbox);
} else {
$str .= html_writer::checkbox('f_' . $this->field->id . '[]', s($checkbox), false, $checkbox);
}
$found = true;
}
if (!$found) {
return '';
}
$str .= html_writer::checkbox('f_' . $this->field->id . '_allreq', null, $allrequired, get_string('selectedrequired', 'data'));
return $str;
}
示例7: htmllize_tree
/**
* Internal function - creates htmls structure suitable for YUI tree.
*/
protected function htmllize_tree($tree, $dir) {
global $CFG;
$yuiconfig = array();
$yuiconfig['type'] = 'html';
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
if ($CFG->enableplagiarism) {
require_once($CFG->libdir.'/plagiarismlib.php');
$plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
} else {
$plagiarsmlinks = '';
}
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
}
$result .= '</ul>';
return $result;
}
示例8: getHtml
/**
* Display the exception html
*/
public function getHtml()
{
if (req()->isAjax() || PHP_SAPI == "cli") {
echo $this->getMessage() . "\n\n" . $this->getTraceAsString();
return;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Error</title>
</head>
<body>
<h1>Well, something is going wrong!</h1>
<h3 style="color:red;"><?php
echo nl2br(s($this->getMessage()));
?>
</h3>
<pre><?php
echo $this->getTraceAsString();
?>
</pre>
</body>
</html>
<?php
}
示例9: __async_delete
/** Delete file controller */
public function __async_delete()
{
s()->async(true);
/** @var \samsonphp\fs\FileService $fsModule */
$fsModule = m('fs');
/** @var \samsoncms\input\Field $field */
$this->createField(new dbQuery(), $_GET['e'], $_GET['f'], $_GET['i']);
// Build uploaded file path
$file = $this->field->value();
// Delete thumbnails
if (class_exists('\\samson\\scale\\ScaleController', false) && $this->isImage($fsModule->extension($file))) {
/** @var string $path Path to file */
$path = '';
// Get file path
preg_match('/.*\\//', $file, $path);
$path = $path[0];
// Get image src
$src = substr($file, strlen($path));
/** @var \samson\scale\ScaleController $scale */
$scale = m('scale');
foreach (array_keys($scale->thumnails_sizes) as $folder) {
// Form image path for scale module
$imageScalePath = $path . $folder . '/' . $src;
if ($fsModule->exists($imageScalePath)) {
$fsModule->delete($imageScalePath);
}
}
}
$fsModule->delete($file);
// Save empty field value
$this->field->save('');
return array('status' => true);
}
示例10: display
function display()
{
$search = trim(optional_param('search', '', PARAM_TEXT));
$alpha = optional_param('alpha', '', PARAM_ALPHA);
// TODO: with a little more work, we could keep the previously selected sort here
$params = $_GET;
unset($params['page']);
// We want to go back to the first page
unset($params['search']);
// And clear the search
$target = $this->page->get_new_page($params);
echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>";
echo "<form action=\"" . $target->get_url() . "\" method=\"post\">";
echo "<fieldset class=\"invisiblefieldset\">";
echo "<input type=\"text\" name=\"search\" value=\"" . s($search, true) . "\" size=\"20\" />";
echo '<input type="submit" value="' . get_string('search') . '" />';
//remove the "bare" parameter to prevent from loading only part of the page
$moodleurl = new moodle_url($target->get_url());
$moodleurl->remove_params('mode');
if ($search) {
echo "<input type=\"button\" onclick=\"document.location='" . $moodleurl->out() . "';\" " . "value=\"Show all items\" />";
}
echo "</fieldset></form>";
echo "</td></tr></table>";
}
示例11: display_search_field
function display_search_field($value = '')
{
global $CFG;
if (is_array($value)) {
$content = $value['checked'];
$allrequired = $value['allrequired'] ? 'checked = "checked"' : '';
} else {
$content = array();
$allrequired = '';
}
static $c = 0;
$str = '';
$found = false;
foreach (explode("\n", $this->field->param1) as $checkbox) {
$checkbox = trim($checkbox);
$str .= '<input type="checkbox" value="' . s($checkbox) . '"';
if (in_array(addslashes($checkbox), $content)) {
// Selected by user.
$str .= ' checked = "checked"';
}
$str .= 'name="f_' . $this->field->id . '[]">' . $checkbox . '<br />';
$found = true;
}
if (!$found) {
// oh, nothing to search for
return '';
}
$str .= ' <input name="f_' . $this->field->id . '_allreq" id="f_' . $this->field->id . '_allreq' . $c . '" type="checkbox" ' . $allrequired . '/>';
$str .= '<label for="f_' . $this->field->id . '_allreq' . $c . '">' . get_string('selectedrequired', 'data') . '</label>';
$c++;
return $str;
}
示例12: routing
/**
* routing
*
* @since 1.2.1
* @deprecated 2.0.0
*
* @package Redaxscript
* @category Center
* @author Henry Ruhs
*/
function routing()
{
/* check token */
if ($_POST && $_POST['token'] != TOKEN) {
notification(l('error_occurred'), l('token_incorrect'), l('home'), ROOT);
return;
}
/* call default post */
$post_list = array('comment', 'login', 'password_reset', 'registration', 'reminder', 'search');
foreach ($post_list as $value) {
if ($_POST[$value . '_post'] && function_exists($value . '_post')) {
call_user_func($value . '_post');
return;
}
}
/* general routing */
switch (FIRST_PARAMETER) {
case 'admin':
if (LOGGED_IN == TOKEN) {
admin_routing();
} else {
notification(l('error_occurred'), l('access_no'), l('login'), 'login');
}
return;
case 'login':
login_form();
return;
case 'logout':
if (LOGGED_IN == TOKEN) {
logout();
} else {
notification(l('error_occurred'), l('access_no'), l('login'), 'login');
}
return;
case 'password_reset':
if (s('reminder') == 1 && FIRST_SUB_PARAMETER && THIRD_PARAMETER) {
password_reset_form();
} else {
notification(l('error_occurred'), l('access_no'), l('home'), ROOT);
}
return;
case 'registration':
if (s('registration')) {
registration_form();
} else {
notification(l('error_occurred'), l('access_no'), l('home'), ROOT);
}
return;
case 'reminder':
if (s('reminder') == 1) {
reminder_form();
} else {
notification(l('error_occurred'), l('access_no'), l('home'), ROOT);
}
return;
default:
contents();
return;
}
}
示例13: setResolver
/**
* @param $callable
*
* @throws InvalidResolverException
*/
public function setResolver($callable)
{
if (!is_callable($callable)) {
throw new InvalidResolverException(s('Routing resolver must be a callable, received "%s".', get_type($callable)));
}
$this->resolver = $callable;
}
示例14: test
/**
* execute tests
*/
public function test($action, $context)
{
$action = us($action);
// create token generator object
$generator = $context->createObject('simple', 'token_generator');
switch ($action) {
case "simple_default":
// create token generator object
$token = $generator->generateToken();
$this->assertEquals(strlen($token), 40);
$this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false);
echo "default token: {$token}";
break;
case "simple_sha1":
$config = new Charcoal_Config($this->getSandbox()->getEnvironment());
$config->set(s('algorithm'), 'sha1');
$generator->configure($config);
$token = $generator->generateToken();
$this->assertEquals(strlen($token), 40);
$this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false);
echo "sha1 token: {$token}";
break;
case "simple_md5":
$config = new Charcoal_Config($this->getSandbox()->getEnvironment());
$config->set(s('algorithm'), 'md5');
$generator->configure($config);
$token = $generator->generateToken();
$this->assertEquals(strlen($token), 32);
$this->assertEquals(preg_match("/[^0-9a-zA-Z]+/", $token), false);
echo "md5 token: {$token}";
break;
}
}
示例15: print_student_answer
function print_student_answer($userid, $return=false){
global $CFG, $USER, $OUTPUT;
$fs = get_file_storage();
$browser = get_file_browser();
$output = '';
if ($submission = $this->get_submission($userid)) {
if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
$found = true;
$mimetype = $file->get_mimetype();
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a><br />';
$output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
$output .='<br/>';
}
}
}
$output = '<div class="files">'.$output.'</div>';
return $output;
}