本文整理汇总了PHP中filter_manager类的典型用法代码示例。如果您正苦于以下问题:PHP filter_manager类的具体用法?PHP filter_manager怎么用?PHP filter_manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了filter_manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset_all_data
/**
* Reset contents of all database tables to initial values, reset caches, etc.
*
* Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
*
* @static
* @param bool $detectchanges
* true - changes in global state and database are reported as errors
* false - no errors reported
* null - only critical problems are reported as errors
* @return void
*/
public static function reset_all_data($detectchanges = false)
{
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
// Stop any message redirection.
phpunit_util::stop_message_redirection();
// Stop any message redirection.
phpunit_util::stop_phpmailer_redirection();
// Stop any message redirection.
phpunit_util::stop_event_redirection();
// We used to call gc_collect_cycles here to ensure desctructors were called between tests.
// This accounted for 25% of the total time running phpunit - so we removed it.
// Show any unhandled debugging messages, the runbare() could already reset it.
self::display_debugging_messages();
self::reset_debugging();
// reset global $DB in case somebody mocked it
$DB = self::get_global_backup('DB');
if ($DB->is_transaction_started()) {
// we can not reset inside transaction
$DB->force_transaction_rollback();
}
$resetdb = self::reset_database();
$warnings = array();
if ($detectchanges === true) {
if ($resetdb) {
$warnings[] = 'Warning: unexpected database modification, resetting DB state';
}
$oldcfg = self::get_global_backup('CFG');
$oldsite = self::get_global_backup('SITE');
foreach ($CFG as $k => $v) {
if (!property_exists($oldcfg, $k)) {
$warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
} else {
if ($oldcfg->{$k} !== $CFG->{$k}) {
$warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
}
}
unset($oldcfg->{$k});
}
if ($oldcfg) {
foreach ($oldcfg as $k => $v) {
$warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
if (ini_get('max_execution_time') != 0) {
// This is special warning for all resets because we do not want any
// libraries to mess with timeouts unintentionally.
// Our PHPUnit integration is not supposed to change it either.
if ($detectchanges !== false) {
$warnings[] = 'Warning: max_execution_time was changed to ' . ini_get('max_execution_time');
}
set_time_limit(0);
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$_GET = array();
$_POST = array();
$_FILES = array();
$_REQUEST = array();
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
// Empty sessison and set fresh new not-logged-in user.
\core\session\manager::init_empty_session();
// reset all static caches
\core\event\manager::phpunit_reset();
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches(true);
reset_text_filters_cache(true);
events_get_handlers('reset');
core_text::reset_caches();
get_message_processors(false, true);
filter_manager::reset_caches();
// Reset internal users.
core_user::reset_internal_users();
//TODO MDL-25290: add more resets here and probably refactor them to new core function
//.........这里部分代码省略.........
示例2: test_filter
/**
* Tests that the filter applies the required changes.
*
* @return void
*/
public function test_filter()
{
$this->resetAfterTest(true);
$this->setAdminUser();
filter_manager::reset_caches();
filter_set_global_state('data', TEXTFILTER_ON);
$course1 = $this->getDataGenerator()->create_course();
$coursecontext1 = context_course::instance($course1->id);
$course2 = $this->getDataGenerator()->create_course();
$coursecontext2 = context_course::instance($course2->id);
$sitecontext = context_course::instance(SITEID);
$site = get_site();
$this->add_simple_database_instance($site, array('SiteEntry'));
$this->add_simple_database_instance($course1, array('CourseEntry'));
$html = '<p>I like CourseEntry and SiteEntry</p>';
// Testing at course level (both site and course).
$filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext1));
$this->assertRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
$this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
// Testing at site level (only site).
$filtered = format_text($html, FORMAT_HTML, array('context' => $sitecontext));
$this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
$this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
// Changing to another course to test the caches invalidation (only site).
$filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext2));
$this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered);
$this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered);
}
示例3: filter_text
/**
* Helper method to apply filters to some text and return the result.
* @param string $text the text to filter.
* @param array $skipfilters any filters not to apply, even if they are configured.
* @return string the filtered text.
*/
protected function filter_text($text, $skipfilters)
{
global $PAGE;
$filtermanager = filter_manager::instance();
$filtermanager->setup_page_for_filters($PAGE, $PAGE->context);
$filteroptions = array('originalformat' => FORMAT_HTML, 'noclean' => false);
return $filtermanager->filter_text($text, $PAGE->context, $filteroptions, $skipfilters);
}
示例4: filter_text
/**
* Given some text in HTML format, this function will pass it
* through any filters that have been configured for this context.
*
* @deprecated use the text formatting in a standard way instead,
* this was abused mostly for embedding of attachments
*
* @param string $text The text to be passed through format filters
* @param int $courseid The current course.
* @return string the filtered string.
*/
function filter_text($text, $courseid = NULL)
{
global $CFG, $COURSE;
if (!$courseid) {
$courseid = $COURSE->id;
}
if (!($context = context_course::instance($courseid, IGNORE_MISSING))) {
return $text;
}
return filter_manager::instance()->filter_text($text, $context);
}
示例5: filter_text
/**
* Given some text in HTML format, this function will pass it
* through any filters that have been configured for this context.
*
* @deprecated use the text formatting in a standard way instead,
* this was abused mostly for embedding of attachments
*
* @param string $text The text to be passed through format filters
* @param int $courseid The current course.
* @return string the filtered string.
*/
function filter_text($text, $courseid = NULL)
{
global $CFG, $COURSE;
if (!$courseid) {
$courseid = $COURSE->id;
}
if (!($context = get_context_instance(CONTEXT_COURSE, $courseid))) {
return $text;
}
return filter_manager::instance()->filter_text($text, $context);
}
示例6: test_filter_external_file
public function test_filter_external_file()
{
global $CFG;
$this->resetAfterTest(true);
$this->setAdminUser();
filter_manager::reset_caches();
filter_set_global_state('viewerjs', TEXTFILTER_ON);
$course1 = $this->getDataGenerator()->create_course();
$coursecontext1 = context_course::instance($course1->id);
$url = 'http://www.example.org/frog.ppt';
$html = '<a href= "' . $url . '">Link</a>';
$this->assertContains($url, format_text($html, FORMAT_HTML, array('context' => $coursecontext1)), 'did not transform external url');
$url = 'http://www.example.org/frog.pdf';
$html = '<a href= "' . $url . '">Link</a>';
$this->assertContains($url, format_text($html, FORMAT_HTML, array('context' => $coursecontext1)), 'did not transform external url even though it had a supported extension');
}
示例7: test_ampersands
/**
* Test ampersands.
*/
public function test_ampersands()
{
global $CFG;
$this->resetAfterTest(true);
// Enable glossary filter at top level.
filter_set_global_state('glossary', TEXTFILTER_ON);
$CFG->glossary_linkentries = 1;
// Create a test course.
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);
// Create a glossary.
$glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id, 'mainglossary' => 1));
// Create two entries with ampersands and one normal entry.
/** @var mod_glossary_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
$normal = $generator->create_content($glossary, array('concept' => 'normal'));
$amp1 = $generator->create_content($glossary, array('concept' => 'A&B'));
$amp2 = $generator->create_content($glossary, array('concept' => 'C&D'));
filter_manager::reset_caches();
\mod_glossary\local\concept_cache::reset_caches();
// Format text with all three entries in HTML.
$html = '<p>A&B C&D normal</p>';
$filtered = format_text($html, FORMAT_HTML, array('context' => $context));
// Find all the glossary links in the result.
$matches = array();
preg_match_all('~eid=([0-9]+).*?title="(.*?)"~', $filtered, $matches);
// There should be 3 glossary links.
$this->assertEquals(3, count($matches[1]));
$this->assertEquals($amp1->id, $matches[1][0]);
$this->assertEquals($amp2->id, $matches[1][1]);
$this->assertEquals($normal->id, $matches[1][2]);
// Check text and escaping of title attribute.
$this->assertEquals($glossary->name . ': A&B', $matches[2][0]);
$this->assertEquals($glossary->name . ': C&D', $matches[2][1]);
$this->assertEquals($glossary->name . ': normal', $matches[2][2]);
}
示例8: filter_text
/**
* Given some text in HTML format, this function will pass it
* through any filters that have been configured for this context.
*
* @param string $text The text to be passed through format filters
* @param int $courseid The current course.
* @return string the filtered string.
*/
function filter_text($text, $courseid = NULL)
{
global $CFG, $COURSE, $PAGE;
if (empty($courseid)) {
$courseid = $COURSE->id;
// (copied from format_text)
}
$context = $PAGE->context;
return filter_manager::instance()->filter_text($text, $context, $courseid);
}
示例9: get_performance_info
/**
* get_performance_info() pairs up with init_performance_info()
* loaded in setup.php. Returns an array with 'html' and 'txt'
* values ready for use, and each of the individual stats provided
* separately as well.
*
* @return array
*/
function get_performance_info() {
global $CFG, $PERF, $DB, $PAGE;
$info = array();
$info['html'] = ''; // Holds userfriendly HTML representation.
$info['txt'] = me() . ' '; // Holds log-friendly representation.
$info['realtime'] = microtime_diff($PERF->starttime, microtime());
$info['html'] .= '<span class="timeused">'.$info['realtime'].' secs</span> ';
$info['txt'] .= 'time: '.$info['realtime'].'s ';
if (function_exists('memory_get_usage')) {
$info['memory_total'] = memory_get_usage();
$info['memory_growth'] = memory_get_usage() - $PERF->startmemory;
$info['html'] .= '<span class="memoryused">RAM: '.display_size($info['memory_total']).'</span> ';
$info['txt'] .= 'memory_total: '.$info['memory_total'].'B (' . display_size($info['memory_total']).') memory_growth: '.
$info['memory_growth'].'B ('.display_size($info['memory_growth']).') ';
}
if (function_exists('memory_get_peak_usage')) {
$info['memory_peak'] = memory_get_peak_usage();
$info['html'] .= '<span class="memoryused">RAM peak: '.display_size($info['memory_peak']).'</span> ';
$info['txt'] .= 'memory_peak: '.$info['memory_peak'].'B (' . display_size($info['memory_peak']).') ';
}
$inc = get_included_files();
$info['includecount'] = count($inc);
$info['html'] .= '<span class="included">Included '.$info['includecount'].' files</span> ';
$info['txt'] .= 'includecount: '.$info['includecount'].' ';
if (!empty($CFG->early_install_lang) or empty($PAGE)) {
// We can not track more performance before installation or before PAGE init, sorry.
return $info;
}
$filtermanager = filter_manager::instance();
if (method_exists($filtermanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $filtermanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<span class='$key'>$nicenames[$key]: $value </span> ";
$info['txt'] .= "$key: $value ";
}
}
$stringmanager = get_string_manager();
if (method_exists($stringmanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $stringmanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<span class='$key'>$nicenames[$key]: $value </span> ";
$info['txt'] .= "$key: $value ";
}
}
if (!empty($PERF->logwrites)) {
$info['logwrites'] = $PERF->logwrites;
$info['html'] .= '<span class="logwrites">Log DB writes '.$info['logwrites'].'</span> ';
$info['txt'] .= 'logwrites: '.$info['logwrites'].' ';
}
$info['dbqueries'] = $DB->perf_get_reads().'/'.($DB->perf_get_writes() - $PERF->logwrites);
$info['html'] .= '<span class="dbqueries">DB reads/writes: '.$info['dbqueries'].'</span> ';
$info['txt'] .= 'db reads/writes: '.$info['dbqueries'].' ';
$info['dbtime'] = round($DB->perf_get_queries_time(), 5);
$info['html'] .= '<span class="dbtime">DB queries time: '.$info['dbtime'].' secs</span> ';
$info['txt'] .= 'db queries time: ' . $info['dbtime'] . 's ';
if (function_exists('posix_times')) {
$ptimes = posix_times();
if (is_array($ptimes)) {
foreach ($ptimes as $key => $val) {
$info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key];
}
$info['html'] .= "<span class=\"posixtimes\">ticks: $info[ticks] user: $info[utime] sys: $info[stime] cuser: $info[cutime] csys: $info[cstime]</span> ";
$info['txt'] .= "ticks: $info[ticks] user: $info[utime] sys: $info[stime] cuser: $info[cutime] csys: $info[cstime] ";
}
}
// Grab the load average for the last minute.
// /proc will only work under some linux configurations
// while uptime is there under MacOSX/Darwin and other unices.
if (is_readable('/proc/loadavg') && $loadavg = @file('/proc/loadavg')) {
list($serverload) = explode(' ', $loadavg[0]);
unset($loadavg);
} else if ( function_exists('is_executable') && is_executable('/usr/bin/uptime') && $loadavg = `/usr/bin/uptime` ) {
if (preg_match('/load averages?: (\d+[\.,:]\d+)/', $loadavg, $matches)) {
$serverload = $matches[1];
} else {
trigger_error('Could not parse uptime output!');
//.........这里部分代码省略.........
示例10: get_performance_info
/**
* get_performance_info() pairs up with init_performance_info()
* loaded in setup.php. Returns an array with 'html' and 'txt'
* values ready for use, and each of the individual stats provided
* separately as well.
*
* @global object
* @global object
* @global object
* @return array
*/
function get_performance_info()
{
global $CFG, $PERF, $DB, $PAGE;
$info = array();
$info['html'] = '';
// holds userfriendly HTML representation
$info['txt'] = me() . ' ';
// holds log-friendly representation
$info['realtime'] = microtime_diff($PERF->starttime, microtime());
$info['html'] .= '<span class="timeused">' . $info['realtime'] . ' secs</span> ';
$info['txt'] .= 'time: ' . $info['realtime'] . 's ';
if (function_exists('memory_get_usage')) {
$info['memory_total'] = memory_get_usage();
$info['memory_growth'] = memory_get_usage() - $PERF->startmemory;
$info['html'] .= '<span class="memoryused">RAM: ' . display_size($info['memory_total']) . '</span> ';
$info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') ';
}
if (function_exists('memory_get_peak_usage')) {
$info['memory_peak'] = memory_get_peak_usage();
$info['html'] .= '<span class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</span> ';
$info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') ';
}
$inc = get_included_files();
//error_log(print_r($inc,1));
$info['includecount'] = count($inc);
$info['html'] .= '<span class="included">Included ' . $info['includecount'] . ' files</span> ';
$info['txt'] .= 'includecount: ' . $info['includecount'] . ' ';
$filtermanager = filter_manager::instance();
if (method_exists($filtermanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $filtermanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> ";
$info['txt'] .= "{$key}: {$value} ";
}
}
$stringmanager = get_string_manager();
if (method_exists($stringmanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $stringmanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> ";
$info['txt'] .= "{$key}: {$value} ";
}
}
$jsmodules = $PAGE->requires->get_loaded_modules();
if ($jsmodules) {
$yuicount = 0;
$othercount = 0;
$details = '';
foreach ($jsmodules as $module => $backtraces) {
if (strpos($module, 'yui') === 0) {
$yuicount += 1;
} else {
$othercount += 1;
}
$details .= "<div class='yui-module'><p>{$module}</p>";
foreach ($backtraces as $backtrace) {
$details .= "<div class='backtrace'>{$backtrace}</div>";
}
$details .= '</div>';
}
$info['html'] .= "<span class='includedyuimodules'>Included YUI modules: {$yuicount}</span> ";
$info['txt'] .= "includedyuimodules: {$yuicount} ";
$info['html'] .= "<span class='includedjsmodules'>Other JavaScript modules: {$othercount}</span> ";
$info['txt'] .= "includedjsmodules: {$othercount} ";
// Slightly odd to output the details in a display: none div. The point
// Is that it takes a lot of space, and if you care you can reveal it
// using firebug.
$info['html'] .= '<div id="yui-module-debug" class="notifytiny">' . $details . '</div>';
}
if (!empty($PERF->logwrites)) {
$info['logwrites'] = $PERF->logwrites;
$info['html'] .= '<span class="logwrites">Log DB writes ' . $info['logwrites'] . '</span> ';
$info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' ';
}
$info['dbqueries'] = $DB->perf_get_reads() . '/' . ($DB->perf_get_writes() - $PERF->logwrites);
$info['html'] .= '<span class="dbqueries">DB reads/writes: ' . $info['dbqueries'] . '</span> ';
$info['txt'] .= 'db reads/writes: ' . $info['dbqueries'] . ' ';
if (!empty($PERF->profiling) && $PERF->profiling) {
require_once $CFG->dirroot . '/lib/profilerlib.php';
$info['html'] .= '<span class="profilinginfo">' . Profiler::get_profiling(array('-R')) . '</span>';
}
if (function_exists('posix_times')) {
$ptimes = posix_times();
if (is_array($ptimes)) {
foreach ($ptimes as $key => $val) {
$info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key];
}
//.........这里部分代码省略.........
示例11: test_external_format_string
public function test_external_format_string()
{
$this->resetAfterTest();
$settings = external_settings::get_instance();
$currentraw = $settings->get_raw();
$currentfilter = $settings->get_filter();
// Enable multilang filter to on content and heading.
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', 1);
$filtermanager = filter_manager::instance();
$filtermanager->reset_caches();
$settings->set_raw(true);
$settings->set_filter(true);
$context = context_system::instance();
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' . '<script>hi</script> <h3>there</h3>!';
$correct = $test;
$this->assertSame($correct, external_format_string($test, $context->id));
$settings->set_raw(false);
$settings->set_filter(false);
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' . '<script>hi</script> <h3>there</h3>?';
$correct = 'ENFR hi there?';
$this->assertSame($correct, external_format_string($test, $context->id));
$settings->set_filter(true);
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' . '<script>hi</script> <h3>there</h3>@';
$correct = 'EN hi there@';
$this->assertSame($correct, external_format_string($test, $context->id));
// Filters can be opted out.
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' . '<script>hi</script> <h3>there</h3>%';
$correct = 'ENFR hi there%';
$this->assertSame($correct, external_format_string($test, $context->id, false, ['filter' => false]));
$settings->set_raw($currentraw);
$settings->set_filter($currentfilter);
}
示例12: test_resort_courses
/**
* Test a categories ability to resort courses.
*/
public function test_resort_courses()
{
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$category = $generator->create_category();
$course1 = $generator->create_course(array('category' => $category->id, 'idnumber' => '006-01', 'shortname' => 'Biome Study', 'fullname' => '<span lang="ar" class="multilang">' . 'دراسة منطقة إحيائية' . '</span><span lang="en" class="multilang">Biome Study</span>', 'timecreated' => '1000000001'));
$course2 = $generator->create_course(array('category' => $category->id, 'idnumber' => '007-02', 'shortname' => 'Chemistry Revision', 'fullname' => 'Chemistry Revision', 'timecreated' => '1000000002'));
$course3 = $generator->create_course(array('category' => $category->id, 'idnumber' => '007-03', 'shortname' => 'Swiss Rolls and Sunflowers', 'fullname' => 'Aarkvarks guide to Swiss Rolls and Sunflowers', 'timecreated' => '1000000003'));
$course4 = $generator->create_course(array('category' => $category->id, 'idnumber' => '006-04', 'shortname' => 'Scratch', 'fullname' => '<a href="test.php">Basic Scratch</a>', 'timecreated' => '1000000004'));
$c1 = (int) $course1->id;
$c2 = (int) $course2->id;
$c3 = (int) $course3->id;
$c4 = (int) $course4->id;
$coursecat = coursecat::get($category->id);
$this->assertTrue($coursecat->resort_courses('idnumber'));
$this->assertSame(array($c1, $c4, $c2, $c3), array_keys($coursecat->get_courses()));
$this->assertTrue($coursecat->resort_courses('shortname'));
$this->assertSame(array($c1, $c2, $c4, $c3), array_keys($coursecat->get_courses()));
$this->assertTrue($coursecat->resort_courses('timecreated'));
$this->assertSame(array($c1, $c2, $c3, $c4), array_keys($coursecat->get_courses()));
try {
// Enable the multilang filter and set it to apply to headings and content.
filter_manager::reset_caches();
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
$expected = array($c3, $c4, $c1, $c2);
} catch (coding_exception $ex) {
$expected = array($c3, $c4, $c2, $c1);
}
$this->assertTrue($coursecat->resort_courses('fullname'));
$this->assertSame($expected, array_keys($coursecat->get_courses()));
}
示例13: get_performance_info
/**
* get_performance_info() pairs up with init_performance_info()
* loaded in setup.php. Returns an array with 'html' and 'txt'
* values ready for use, and each of the individual stats provided
* separately as well.
*
* @return array
*/
function get_performance_info()
{
global $CFG, $PERF, $DB, $PAGE;
$info = array();
$info['html'] = '';
// Holds userfriendly HTML representation.
$info['txt'] = me() . ' ';
// Holds log-friendly representation.
$info['realtime'] = microtime_diff($PERF->starttime, microtime());
$info['html'] .= '<span class="timeused">' . $info['realtime'] . ' secs</span> ';
$info['txt'] .= 'time: ' . $info['realtime'] . 's ';
if (function_exists('memory_get_usage')) {
$info['memory_total'] = memory_get_usage();
$info['memory_growth'] = memory_get_usage() - $PERF->startmemory;
$info['html'] .= '<span class="memoryused">RAM: ' . display_size($info['memory_total']) . '</span> ';
$info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') ';
}
if (function_exists('memory_get_peak_usage')) {
$info['memory_peak'] = memory_get_peak_usage();
$info['html'] .= '<span class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</span> ';
$info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') ';
}
$inc = get_included_files();
$info['includecount'] = count($inc);
$info['html'] .= '<span class="included">Included ' . $info['includecount'] . ' files</span> ';
$info['txt'] .= 'includecount: ' . $info['includecount'] . ' ';
if (!empty($CFG->early_install_lang) or empty($PAGE)) {
// We can not track more performance before installation or before PAGE init, sorry.
return $info;
}
$filtermanager = filter_manager::instance();
if (method_exists($filtermanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $filtermanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> ";
$info['txt'] .= "{$key}: {$value} ";
}
}
$stringmanager = get_string_manager();
if (method_exists($stringmanager, 'get_performance_summary')) {
list($filterinfo, $nicenames) = $stringmanager->get_performance_summary();
$info = array_merge($filterinfo, $info);
foreach ($filterinfo as $key => $value) {
$info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> ";
$info['txt'] .= "{$key}: {$value} ";
}
}
$jsmodules = $PAGE->requires->get_loaded_modules();
if ($jsmodules) {
$yuicount = 0;
$othercount = 0;
$details = '';
foreach ($jsmodules as $module => $backtraces) {
if (strpos($module, 'yui') === 0) {
$yuicount += 1;
} else {
$othercount += 1;
}
if (!empty($CFG->yuimoduledebug)) {
// Hidden feature for developers working on YUI module infrastructure.
$details .= "<div class='yui-module'><p>{$module}</p>";
foreach ($backtraces as $backtrace) {
$details .= "<div class='backtrace'>{$backtrace}</div>";
}
$details .= '</div>';
}
}
$info['html'] .= "<span class='includedyuimodules'>Included YUI modules: {$yuicount}</span> ";
$info['txt'] .= "includedyuimodules: {$yuicount} ";
$info['html'] .= "<span class='includedjsmodules'>Other JavaScript modules: {$othercount}</span> ";
$info['txt'] .= "includedjsmodules: {$othercount} ";
if ($details) {
$info['html'] .= '<div id="yui-module-debug" class="notifytiny">' . $details . '</div>';
}
}
if (!empty($PERF->logwrites)) {
$info['logwrites'] = $PERF->logwrites;
$info['html'] .= '<span class="logwrites">Log DB writes ' . $info['logwrites'] . '</span> ';
$info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' ';
}
$info['dbqueries'] = $DB->perf_get_reads() . '/' . ($DB->perf_get_writes() - $PERF->logwrites);
$info['html'] .= '<span class="dbqueries">DB reads/writes: ' . $info['dbqueries'] . '</span> ';
$info['txt'] .= 'db reads/writes: ' . $info['dbqueries'] . ' ';
if (function_exists('posix_times')) {
$ptimes = posix_times();
if (is_array($ptimes)) {
foreach ($ptimes as $key => $val) {
$info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key];
}
$info['html'] .= "<span class=\"posixtimes\">ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']}</span> ";
$info['txt'] .= "ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']} ";
//.........这里部分代码省略.........
示例14: format_string
/**
* Given a simple string, this function returns the string
* processed by enabled string filters if $CFG->filterall is enabled
*
* This function should be used to print short strings (non html) that
* need filter processing e.g. activity titles, post subjects,
* glossary concepts.
*
* @global object
* @global object
* @global object
* @staticvar bool $strcache
* @param string $string The string to be filtered.
* @param boolean $striplinks To strip any link in the result text.
Moodle 1.8 default changed from false to true! MDL-8713
* @param array $options options array/object or courseid
* @return string
*/
function format_string($string, $striplinks = true, $options = NULL)
{
global $CFG, $COURSE, $PAGE;
//We'll use a in-memory cache here to speed up repeated strings
static $strcache = false;
if (empty($CFG->version) or $CFG->version < 2010072800 or during_initial_install()) {
// do not filter anything during installation or before upgrade completes
return $string = strip_tags($string);
}
if ($strcache === false or count($strcache) > 2000) {
// this number might need some tuning to limit memory usage in cron
$strcache = array();
}
if (is_numeric($options)) {
// legacy courseid usage
$options = array('context' => get_context_instance(CONTEXT_COURSE, $options));
} else {
$options = (array) $options;
// detach object, we can not modify it
}
if (empty($options['context'])) {
// fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-(
$options['context'] = $PAGE->context;
} else {
if (is_numeric($options['context'])) {
$options['context'] = get_context_instance_by_id($options['context']);
}
}
if (!$options['context']) {
// we did not find any context? weird
return $string = strip_tags($string);
}
//Calculate md5
$md5 = md5($string . '<+>' . $striplinks . '<+>' . $options['context']->id . '<+>' . current_language());
//Fetch from cache if possible
if (isset($strcache[$md5])) {
return $strcache[$md5];
}
// First replace all ampersands not followed by html entity code
// Regular expression moved to its own method for easier unit testing
$string = replace_ampersands_not_followed_by_entity($string);
if (!empty($CFG->filterall)) {
$string = filter_manager::instance()->filter_string($string, $options['context']);
}
// If the site requires it, strip ALL tags from this string
if (!empty($CFG->formatstringstriptags)) {
$string = strip_tags($string);
} else {
// Otherwise strip just links if that is required (default)
if ($striplinks) {
//strip links in string
$string = strip_links($string);
}
$string = clean_text($string);
}
//Store to cache
$strcache[$md5] = $string;
return $string;
}
示例15: initialise_theme_and_output
/**
* Method for use by Moodle core to set up the theme. Do not
* use this in your own code.
*
* Make sure the right theme for this page is loaded. Tell our
* blocks_manager about the theme block regions, and then, if
* we are $PAGE, set up the global $OUTPUT.
*
* @return void
*/
public function initialise_theme_and_output()
{
global $OUTPUT, $PAGE, $SITE, $CFG;
if (!empty($this->_wherethemewasinitialised)) {
return;
}
if (!during_initial_install()) {
// Detect PAGE->context mess.
$this->magic_get_context();
}
if (!$this->_course && !during_initial_install()) {
$this->set_course($SITE);
}
if (is_null($this->_theme)) {
$themename = $this->resolve_theme();
$this->_theme = theme_config::load($themename);
}
$this->_theme->setup_blocks($this->pagelayout, $this->blocks);
if ($this->_theme->enable_dock && !empty($CFG->allowblockstodock)) {
$this->requires->strings_for_js(array('addtodock', 'undockitem', 'dockblock', 'undockblock', 'undockall', 'hidedockpanel', 'hidepanel'), 'block');
$this->requires->string_for_js('thisdirectionvertical', 'langconfig');
$this->requires->yui_module('moodle-core-dock-loader', 'M.core.dock.loader.initLoader');
}
if ($this === $PAGE) {
$target = null;
if ($this->pagelayout === 'maintenance') {
// If the page is using the maintenance layout then we're going to force target to maintenance.
// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
// page layout.
$target = RENDERER_TARGET_MAINTENANCE;
}
$OUTPUT = $this->get_renderer('core', null, $target);
}
if (!during_initial_install()) {
$filtermanager = filter_manager::instance();
$filtermanager->setup_page_for_globally_available_filters($this);
}
$this->_wherethemewasinitialised = debug_backtrace();
}