本文整理汇总了PHP中Core\Session\manager::write_close方法的典型用法代码示例。如果您正苦于以下问题:PHP manager::write_close方法的具体用法?PHP manager::write_close怎么用?PHP manager::write_close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core\Session\manager
的用法示例。
在下文中一共展示了manager::write_close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download_as_dataformat
/**
* Sends a formated data file to the browser
*
* @package core
* @subpackage dataformat
*
* @param string $filename The base filename without an extension
* @param string $dataformat A dataformat name
* @param array $columns An ordered map of column keys and labels
* @param Iterator $iterator An iterator over the records, usually a RecordSet
* @param function $callback An option function applied to each record before writing
* @param mixed $extra An optional value which is passed into the callback function
*/
function download_as_dataformat($filename, $dataformat, $columns, $iterator, $callback = null)
{
if (ob_get_length()) {
throw new coding_exception("Output can not be buffered before calling download_as_dataformat");
}
$classname = 'dataformat_' . $dataformat . '\\writer';
if (!class_exists($classname)) {
throw new coding_exception("Unable to locate dataformat/{$type}/classes/writer.php");
}
$format = new $classname();
// The data format export could take a while to generate...
set_time_limit(0);
// Close the session so that the users other tabs in the same session are not blocked.
\core\session\manager::write_close();
$format->set_filename($filename);
$format->send_http_headers();
$format->write_header($columns);
$c = 0;
foreach ($iterator as $row) {
if ($callback) {
$row = $callback($row);
}
if ($row === null) {
continue;
}
$format->write_record($row, $c++);
}
$format->write_footer($columns);
}
示例2: tool_dbtransfer_transfer_database
/**
* Initiate database transfer.
* @param moodle_database $sourcedb
* @param moodle_database $targetdb
* @param progress_trace $feedback
* @return void
*/
function tool_dbtransfer_transfer_database(moodle_database $sourcedb, moodle_database $targetdb, progress_trace $feedback = null)
{
core_php_time_limit::raise();
\core\session\manager::write_close();
// Release session.
$var = new database_mover($sourcedb, $targetdb, true, $feedback);
$var->export_database(null);
tool_dbtransfer_rebuild_target_log_actions($targetdb, $feedback);
}
示例3: test_write_close
public function test_write_close()
{
global $USER;
$this->resetAfterTest();
// Just make sure no errors and $USER->id is kept
$this->setAdminUser();
$userid = $USER->id;
\core\session\manager::write_close();
$this->assertSame($userid, $USER->id);
}
示例4: block_informationspot_pluginfile
/**
* Form for editing Information Spot block instances.
*
* @copyright 2014 Roberto Pinna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package block_informationspot
* @category files
* @param stdClass $course course object
* @param stdClass $birecord_or_cm block instance record
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool
*/
function block_informationspot_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
global $DB, $CFG, $USER;
if ($context->contextlevel != CONTEXT_BLOCK) {
send_file_not_found();
}
// If block is in course context, then check if user has capability to access course.
if ($context->get_course_context(false)) {
require_course_login($course);
} else {
if ($CFG->forcelogin) {
require_login();
} else {
// Get parent context and see if user have proper permission.
$parentcontext = $context->get_parent_context();
if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
// Check if category is visible and user can view this category.
$category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
if (!$category->visible) {
require_capability('moodle/category:viewhiddencategories', $parentcontext);
}
} else {
if ($parentcontext->contextlevel === CONTEXT_USER && $parentcontext->instanceid != $USER->id) {
// The block is in the context of a user, it is only visible to the user who it belongs to.
send_file_not_found();
}
}
// At this point there is no way to check SYSTEM context, so ignoring it.
}
}
if ($filearea != 'image') {
send_file_not_found();
}
$fs = get_file_storage();
$imageid = array_shift($args);
$filename = array_pop($args);
$filepath = $args ? '/' . implode('/', $args) . '/' : '/';
if (!($file = $fs->get_file($context->id, 'block_informationspot', $filearea, $imageid, $filepath, $filename)) or $file->is_directory()) {
send_file_not_found();
}
if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
if ($parentcontext->contextlevel == CONTEXT_USER) {
// force download on all personal pages including /my/
//because we do not have reliable way to find out from where this is used
$forcedownload = true;
}
} else {
// weird, there should be parent context, better force dowload then
$forcedownload = true;
}
// NOTE: it woudl be nice to have file revisions here, for now rely on standard file lifetime,
// do not lower it because the files are dispalyed very often.
\core\session\manager::write_close();
send_stored_file($file, null, 0, $forcedownload, $options);
}
示例5: tool_generator_pluginfile
/**
* Files support.
*
* Exits if the required permissions are not satisfied.
*
* @param stdClass $course course object
* @param stdClass $cm
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return void The file is sent along with it's headers
*/
function tool_generator_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
// Only for admins or CLI.
if (!defined('CLI_SCRIPT') && !is_siteadmin()) {
die;
}
if ($context->contextlevel != CONTEXT_SYSTEM) {
send_file_not_found();
}
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'tool_generator', $filearea, $args[0], '/', $args[1]);
// Send the file, always forcing download, we don't want options.
\core\session\manager::write_close();
send_stored_file($file, 0, 0, true);
}
示例6: block_slideshow_pluginfile
/**
* Slideshow block
*
* This is a simple block that allows a user to embed a slideshow just below the
* header of either the frontpage of a site or a coursepage. The slideshow is based
* on jquery cycle.
*
* @package block_slideshow
* @category blocks
* @copyright 2013 Paul Prenis
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function block_slideshow_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
global $DB, $CFG;
if ($context->contextlevel != CONTEXT_BLOCK) {
send_file_not_found();
}
// If block is in course context, then check if user has capability to access course.
if ($context->get_course_context(false)) {
require_course_login($course);
} else {
if ($CFG->forcelogin) {
require_login();
} else {
// Get parent context and see if user have proper permission.
$parentcontext = $context->get_parent_context();
if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
// Check if category is visible and user can view this category.
$category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
if (!$category->visible) {
require_capability('moodle/category:viewhiddencategories', $parentcontext);
}
}
// At this point there is no way to check SYSTEM or USER context, so ignoring it.
}
}
if ($filearea !== 'content') {
send_file_not_found();
}
$fs = get_file_storage();
$filename = array_pop($args);
$filepath = $args ? '/' . implode('/', $args) . '/' : '/';
if (!($file = $fs->get_file($context->id, 'block_slideshow', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
send_file_not_found();
}
if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
if ($parentcontext->contextlevel == CONTEXT_USER) {
// force download on all personal pages including /my/
//because we do not have reliable way to find out from where this is used
$forcedownload = true;
}
} else {
// weird, there should be parent context, better force dowload then
$forcedownload = true;
}
\core\session\manager::write_close();
send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
示例7: require_user_key_login
/**
* Require key login. Function terminates with error if key not found or incorrect.
*
* @uses NO_MOODLE_COOKIES
* @uses PARAM_ALPHANUM
* @param string $script unique script identifier
* @param int $instance optional instance id
* @return int Instance ID
*/
function require_user_key_login($script, $instance = null)
{
global $DB;
if (!NO_MOODLE_COOKIES) {
print_error('sessioncookiesdisable');
}
// Extra safety.
\core\session\manager::write_close();
$keyvalue = required_param('key', PARAM_ALPHANUM);
$key = validate_user_key($keyvalue, $script, $instance);
if (!($user = $DB->get_record('user', array('id' => $key->userid)))) {
print_error('invaliduserid');
}
// Emulate normal session.
enrol_check_plugins($user);
\core\session\manager::set_user($user);
// Note we are not using normal login.
if (!defined('USER_KEY_LOGIN')) {
define('USER_KEY_LOGIN', true);
}
// Return instance id - it might be empty.
return $key->instance;
}
示例8: file_pluginfile
/**
* This function delegates file serving to individual plugins
*
* @param string $relativepath
* @param bool $forcedownload
* @param null|string $preview the preview mode, defaults to serving the original file
* @todo MDL-31088 file serving improments
*/
function file_pluginfile($relativepath, $forcedownload, $preview = null)
{
global $DB, $CFG, $USER;
// relative path must start with '/'
if (!$relativepath) {
print_error('invalidargorconf');
} else {
if ($relativepath[0] != '/') {
print_error('pathdoesnotstartslash');
}
}
// extract relative path components
$args = explode('/', ltrim($relativepath, '/'));
if (count($args) < 3) {
// always at least context, component and filearea
print_error('invalidarguments');
}
$contextid = (int) array_shift($args);
$component = clean_param(array_shift($args), PARAM_COMPONENT);
$filearea = clean_param(array_shift($args), PARAM_AREA);
list($context, $course, $cm) = get_context_info_array($contextid);
$fs = get_file_storage();
// ========================================================================================================================
if ($component === 'blog') {
// Blog file serving
if ($context->contextlevel != CONTEXT_SYSTEM) {
send_file_not_found();
}
if ($filearea !== 'attachment' and $filearea !== 'post') {
send_file_not_found();
}
if (empty($CFG->enableblogs)) {
print_error('siteblogdisable', 'blog');
}
$entryid = (int) array_shift($args);
if (!($entry = $DB->get_record('post', array('module' => 'blog', 'id' => $entryid)))) {
send_file_not_found();
}
if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
require_login();
if (isguestuser()) {
print_error('noguest');
}
if ($CFG->bloglevel == BLOG_USER_LEVEL) {
if ($USER->id != $entry->userid) {
send_file_not_found();
}
}
}
if ($entry->publishstate === 'public') {
if ($CFG->forcelogin) {
require_login();
}
} else {
if ($entry->publishstate === 'site') {
require_login();
//ok
} else {
if ($entry->publishstate === 'draft') {
require_login();
if ($USER->id != $entry->userid) {
send_file_not_found();
}
}
}
}
$filename = array_pop($args);
$filepath = $args ? '/' . implode('/', $args) . '/' : '/';
if (!($file = $fs->get_file($context->id, $component, $filearea, $entryid, $filepath, $filename)) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 10 * 60, 0, true, array('preview' => $preview));
// download MUST be forced - security!
// ========================================================================================================================
} else {
if ($component === 'grade') {
if (($filearea === 'outcome' or $filearea === 'scale') and $context->contextlevel == CONTEXT_SYSTEM) {
// Global gradebook files
if ($CFG->forcelogin) {
require_login();
}
$fullpath = "/{$context->id}/{$component}/{$filearea}/" . implode('/', $args);
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
\core\session\manager::write_close();
// Unlock session during file serving.
send_stored_file($file, 60 * 60, 0, $forcedownload, array('preview' => $preview));
} else {
if ($filearea === 'feedback' and $context->contextlevel == CONTEXT_COURSE) {
//TODO: nobody implemented this yet in grade edit form!!
send_file_not_found();
//.........这里部分代码省略.........
示例9: require_user_key_login
/**
* Require key login. Function terminates with error if key not found or incorrect.
*
* @uses NO_MOODLE_COOKIES
* @uses PARAM_ALPHANUM
* @param string $script unique script identifier
* @param int $instance optional instance id
* @return int Instance ID
*/
function require_user_key_login($script, $instance = null)
{
global $DB;
if (!NO_MOODLE_COOKIES) {
print_error('sessioncookiesdisable');
}
// Extra safety.
\core\session\manager::write_close();
$keyvalue = required_param('key', PARAM_ALPHANUM);
if (!($key = $DB->get_record('user_private_key', array('script' => $script, 'value' => $keyvalue, 'instance' => $instance)))) {
print_error('invalidkey');
}
if (!empty($key->validuntil) and $key->validuntil < time()) {
print_error('expiredkey');
}
if ($key->iprestriction) {
$remoteaddr = getremoteaddr(null);
if (empty($remoteaddr) or !address_in_subnet($remoteaddr, $key->iprestriction)) {
print_error('ipmismatch');
}
}
if (!($user = $DB->get_record('user', array('id' => $key->userid)))) {
print_error('invaliduserid');
}
// Emulate normal session.
enrol_check_plugins($user);
\core\session\manager::set_user($user);
// Note we are not using normal login.
if (!defined('USER_KEY_LOGIN')) {
define('USER_KEY_LOGIN', true);
}
// Return instance id - it might be empty.
return $key->instance;
}
示例10: redirect
//.........这里部分代码省略.........
}
$debugdisableredirect = false;
do {
if (defined('DEBUGGING_PRINTED')) {
// Some debugging already printed, no need to look more.
$debugdisableredirect = true;
break;
}
if (core_useragent::is_msword()) {
// Clicking a URL from MS Word sends a request to the server without cookies. If that
// causes a redirect Word will open a browser pointing the new URL. If not, the URL that
// was clicked is opened. Because the request from Word is without cookies, it almost
// always results in a redirect to the login page, even if the user is logged in in their
// browser. This is not what we want, so prevent the redirect for requests from Word.
$debugdisableredirect = true;
break;
}
if (empty($CFG->debugdisplay) or empty($CFG->debug)) {
// No errors should be displayed.
break;
}
if (!function_exists('error_get_last') or !($lasterror = error_get_last())) {
break;
}
if (!($lasterror['type'] & $CFG->debug)) {
// Last error not interesting.
break;
}
// Watch out here, @hidden() errors are returned from error_get_last() too.
if (headers_sent()) {
// We already started printing something - that means errors likely printed.
$debugdisableredirect = true;
break;
}
if (ob_get_level() and ob_get_contents()) {
// There is something waiting to be printed, hopefully it is the errors,
// but it might be some error hidden by @ too - such as the timezone mess from setup.php.
$debugdisableredirect = true;
break;
}
} while (false);
// Technically, HTTP/1.1 requires Location: header to contain the absolute path.
// (In practice browsers accept relative paths - but still, might as well do it properly.)
// This code turns relative into absolute.
if (!preg_match('|^[a-z]+:|', $url)) {
// Get host name http://www.wherever.com.
$hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot);
if (preg_match('|^/|', $url)) {
// URLs beginning with / are relative to web server root so we just add them in.
$url = $hostpart . $url;
} else {
// URLs not beginning with / are relative to path of current script, so add that on.
$url = $hostpart . preg_replace('|\\?.*$|', '', me()) . '/../' . $url;
}
// Replace all ..s.
while (true) {
$newurl = preg_replace('|/(?!\\.\\.)[^/]*/\\.\\./|', '/', $url);
if ($newurl == $url) {
break;
}
$url = $newurl;
}
}
// Sanitise url - we can not rely on moodle_url or our URL cleaning
// because they do not support all valid external URLs.
$url = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $url);
$url = str_replace('"', '%22', $url);
$encodedurl = preg_replace("/\\&(?![a-zA-Z0-9#]{1,8};)/", "&", $url);
$encodedurl = preg_replace('/^.*href="([^"]*)".*$/', "\\1", clean_text('<a href="' . $encodedurl . '" />', FORMAT_HTML));
$url = str_replace('&', '&', $encodedurl);
if (!empty($message)) {
if ($delay === -1 || !is_numeric($delay)) {
$delay = 3;
}
$message = clean_text($message);
} else {
$message = get_string('pageshouldredirect');
$delay = 0;
}
// Make sure the session is closed properly, this prevents problems in IIS
// and also some potential PHP shutdown issues.
\core\session\manager::write_close();
if ($delay == 0 && !$debugdisableredirect && !headers_sent()) {
// 302 might not work for POST requests, 303 is ignored by obsolete clients.
@header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other');
@header('Location: ' . $url);
echo bootstrap_renderer::plain_redirect_message($encodedurl);
exit;
}
// Include a redirect message, even with a HTTP redirect, because that is recommended practice.
if ($PAGE) {
$CFG->docroot = false;
// To prevent the link to moodle docs from being displayed on redirect page.
echo $OUTPUT->redirect_message($encodedurl, $message, $delay, $debugdisableredirect);
exit;
} else {
echo bootstrap_renderer::early_redirect_message($encodedurl, $message, $delay);
exit;
}
}
示例11: shutdown_handler
/**
* @private - do NOT call directly.
*/
public static function shutdown_handler()
{
global $DB;
// Custom stuff first.
foreach (self::$callbacks as $data) {
list($callback, $params) = $data;
try {
if (!is_callable($callback)) {
error_log('Invalid custom shutdown function detected ' . var_export($callback, true));
continue;
}
if ($params === null) {
call_user_func($callback);
} else {
call_user_func_array($callback, $params);
}
} catch (Exception $e) {
error_log('Exception ignored in shutdown function ' . var_export($callback, true) . ':' . $e->getMessage());
}
}
// Handle DB transactions, session need to be written afterwards
// in order to maintain consistency in all session handlers.
if ($DB->is_transaction_started()) {
if (!defined('PHPUNIT_TEST') or !PHPUNIT_TEST) {
// This should not happen, it usually indicates wrong catching of exceptions,
// because all transactions should be finished manually or in default exception handler.
$backtrace = $DB->get_transaction_start_backtrace();
error_log('Potential coding error - active database transaction detected during request shutdown:' . "\n" . format_backtrace($backtrace, true));
}
$DB->force_transaction_rollback();
}
// Close sessions - do it here to make it consistent for all session handlers.
\core\session\manager::write_close();
// Other cleanup.
self::request_shutdown();
// Stop profiling.
if (function_exists('profiling_is_running')) {
if (profiling_is_running()) {
profiling_stop();
}
}
// NOTE: do not dispose $DB and MUC here, they might be used from legacy shutdown functions.
}
示例12: __construct
/**
* Constructor
*
* @param string $table An sql table
* @param string $dataformat type of dataformat for export
*/
public function __construct(&$table, $dataformat)
{
parent::__construct($table);
if (ob_get_length()) {
throw new coding_exception("Output can not be buffered before instantiating table_dataformat_export_format");
}
$classname = 'dataformat_' . $dataformat . '\\writer';
if (!class_exists($classname)) {
throw new coding_exception("Unable to locate dataformat/{$dataformat}/classes/writer.php");
}
$this->dataformat = new $classname();
// The dataformat export time to first byte could take a while to generate...
set_time_limit(0);
// Close the session so that the users other tabs in the same session are not blocked.
\core\session\manager::write_close();
}
示例13: send_file
/**
* Repository method to serve the referenced file.
*
* @inheritDocs
*/
public function send_file($storedfile, $lifetime = null, $filter = 0, $forcedownload = false, array $options = null)
{
$reference = $this->unpack_reference($storedfile->get_reference());
$maxcachesize = $this->max_cache_bytes();
if (empty($maxcachesize)) {
// Always cache the file, regardless of size.
$cachefile = true;
} else {
// Size available. Only cache if it is under maxcachesize.
$cachefile = $storedfile->get_filesize() < $maxcachesize;
}
if (!$cachefile) {
\core\session\manager::write_close();
header('Location: ' . $this->get_file_download_link($reference->url));
die;
}
try {
$this->import_external_file_contents($storedfile, $this->max_cache_bytes());
if (!is_array($options)) {
$options = array();
}
$options['sendcachedexternalfile'] = true;
\core\session\manager::write_close();
send_stored_file($storedfile, $lifetime, $filter, $forcedownload, $options);
} catch (moodle_exception $e) {
// Redirect to Dropbox, it will show the error.
// Note: We redirect to Dropbox shared link, not to the download link here!
\core\session\manager::write_close();
header('Location: ' . $reference->url);
die;
}
}
示例14: unlock_session
/**
* Unlock the session and allow the regrading process to run in the background.
*/
protected function unlock_session()
{
\core\session\manager::write_close();
ignore_user_abort(true);
}
示例15: send_file
public function send_file($filearea, $args, $forcedownload, array $options = array())
{
global $USER, $CFG;
require_capability('mod/assignment:view', $this->context);
$fullpath = "/{$this->context->id}/mod_assignment/{$filearea}/" . implode('/', $args);
$fs = get_file_storage();
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
if ($USER->id != $file->get_userid() && !has_capability('mod/assignment:grade', $this->context)) {
send_file_not_found();
}
\core\session\manager::write_close();
// Unlock session during file serving.
// Make the lifetime significantly shorter,
// it would be better to have file revision numbers.
$lifetime = $CFG->filelifetime;
if ($lifetime > 60 * 6) {
$lifetime = 60 * 6;
}
send_stored_file($file, $lifetime, 0, true, $options);
}