���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/locallib.php.tar
���ѧ٧ѧ�
home3/cpr76684/public_html/Aem/admin/tool/customlang/locallib.php 0000644 00000050142 15152036246 0020507 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Definition of classes used by language customization admin tool * * @package tool * @subpackage customlang * @copyright 2010 David Mudrak <david@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Provides various utilities to be used by the plugin * * All the public methods here are static ones, this class can not be instantiated */ class tool_customlang_utils { /** * Rough number of strings that are being processed during a full checkout. * This is used to estimate the progress of the checkout. */ const ROUGH_NUMBER_OF_STRINGS = 32000; /** @var array cache of {@link self::list_components()} results */ private static $components = null; /** * This class can not be instantiated */ private function __construct() { } /** * Returns a list of all components installed on the server * * @return array (string)legacyname => (string)frankenstylename */ public static function list_components() { if (self::$components === null) { $list['moodle'] = 'core'; $coresubsystems = core_component::get_core_subsystems(); ksort($coresubsystems); // Should be but just in case. foreach ($coresubsystems as $name => $location) { $list[$name] = 'core_' . $name; } $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { $pluginlist = core_component::get_plugin_list($type); foreach ($pluginlist as $name => $ununsed) { if ($type == 'mod') { // Plugin names are now automatically validated. $list[$name] = $type . '_' . $name; } else { $list[$type . '_' . $name] = $type . '_' . $name; } } } self::$components = $list; } return self::$components; } /** * Updates the translator database with the strings from files * * This should be executed each time before going to the translation page * * @param string $lang language code to checkout * @param progress_bar $progressbar optionally, the given progress bar can be updated */ public static function checkout($lang, progress_bar $progressbar = null) { global $DB, $CFG; require_once("{$CFG->libdir}/adminlib.php"); // For behat executions we are going to load only a few components in the // language customisation structures. Using the whole "en" langpack is // too much slow (leads to Selenium 30s timeouts, especially on slow // environments) and we don't really need the whole thing for tests. So, // apart from escaping from the timeouts, we are also saving some good minutes // in tests. See MDL-70014 and linked issues for more info. $behatneeded = ['core', 'core_langconfig', 'tool_customlang']; // make sure that all components are registered $current = $DB->get_records('tool_customlang_components', null, 'name', 'name,version,id'); foreach (self::list_components() as $component) { // Filter out unwanted components when running behat. if (defined('BEHAT_SITE_RUNNING') && !in_array($component, $behatneeded)) { continue; } if (empty($current[$component])) { $record = new stdclass(); $record->name = $component; if (!$version = get_component_version($component)) { $record->version = null; } else { $record->version = $version; } $DB->insert_record('tool_customlang_components', $record); } else if ($version = get_component_version($component)) { if (is_null($current[$component]->version) or ($version > $current[$component]->version)) { $DB->set_field('tool_customlang_components', 'version', $version, array('id' => $current[$component]->id)); } } } unset($current); // initialize the progress counter - stores the number of processed strings $done = 0; $strinprogress = get_string('checkoutinprogress', 'tool_customlang'); // reload components and fetch their strings $stringman = get_string_manager(); $components = $DB->get_records('tool_customlang_components'); foreach ($components as $component) { $sql = "SELECT stringid, id, lang, componentid, original, master, local, timemodified, timecustomized, outdated, modified FROM {tool_customlang} s WHERE lang = ? AND componentid = ? ORDER BY stringid"; $current = $DB->get_records_sql($sql, array($lang, $component->id)); $english = $stringman->load_component_strings($component->name, 'en', true, true); if ($lang == 'en') { $master =& $english; } else { $master = $stringman->load_component_strings($component->name, $lang, true, true); } $local = $stringman->load_component_strings($component->name, $lang, true, false); foreach ($english as $stringid => $stringoriginal) { $stringmaster = isset($master[$stringid]) ? $master[$stringid] : null; $stringlocal = isset($local[$stringid]) ? $local[$stringid] : null; $now = time(); if (!is_null($progressbar)) { $done++; $donepercent = floor(min($done, self::ROUGH_NUMBER_OF_STRINGS) / self::ROUGH_NUMBER_OF_STRINGS * 100); $progressbar->update_full($donepercent, $strinprogress); } if (isset($current[$stringid])) { $needsupdate = false; $currentoriginal = $current[$stringid]->original; $currentmaster = $current[$stringid]->master; $currentlocal = $current[$stringid]->local; if ($currentoriginal !== $stringoriginal or $currentmaster !== $stringmaster) { $needsupdate = true; $current[$stringid]->original = $stringoriginal; $current[$stringid]->master = $stringmaster; $current[$stringid]->timemodified = $now; $current[$stringid]->outdated = 1; } if ($stringmaster !== $stringlocal) { $needsupdate = true; $current[$stringid]->local = $stringlocal; $current[$stringid]->timecustomized = $now; } else if (isset($currentlocal) && $stringlocal !== $currentlocal) { // If local string has been removed, we need to remove also the old local value from DB. $needsupdate = true; $current[$stringid]->local = null; $current[$stringid]->timecustomized = $now; } if ($needsupdate) { $DB->update_record('tool_customlang', $current[$stringid]); continue; } } else { $record = new stdclass(); $record->lang = $lang; $record->componentid = $component->id; $record->stringid = $stringid; $record->original = $stringoriginal; $record->master = $stringmaster; $record->timemodified = $now; $record->outdated = 0; if ($stringmaster !== $stringlocal) { $record->local = $stringlocal; $record->timecustomized = $now; } else { $record->local = null; $record->timecustomized = null; } $DB->insert_record('tool_customlang', $record); } } } if (!is_null($progressbar)) { $progressbar->update_full(100, get_string('checkoutdone', 'tool_customlang')); } } /** * Exports the translator database into disk files * * @param mixed $lang language code */ public static function checkin($lang) { global $DB, $USER, $CFG; require_once($CFG->libdir.'/filelib.php'); if ($lang !== clean_param($lang, PARAM_LANG)) { return false; } list($insql, $inparams) = $DB->get_in_or_equal(self::list_components()); // Get all customized strings from updated valid components. $sql = "SELECT s.*, c.name AS component FROM {tool_customlang} s JOIN {tool_customlang_components} c ON s.componentid = c.id WHERE s.lang = ? AND (s.local IS NOT NULL OR s.modified = 1) AND c.name $insql ORDER BY componentid, stringid"; array_unshift($inparams, $lang); $strings = $DB->get_records_sql($sql, $inparams); $files = array(); foreach ($strings as $string) { if (!is_null($string->local)) { $files[$string->component][$string->stringid] = $string->local; } } fulldelete(self::get_localpack_location($lang)); foreach ($files as $component => $strings) { self::dump_strings($lang, $component, $strings); } $DB->set_field_select('tool_customlang', 'modified', 0, 'lang = ?', array($lang)); $sm = get_string_manager(); $sm->reset_caches(); } /** * Returns full path to the directory where local packs are dumped into * * @param string $lang language code * @return string full path */ public static function get_localpack_location($lang) { global $CFG; return $CFG->langlocalroot.'/'.$lang.'_local'; } /** * Writes strings into a local language pack file * * @param string $component the name of the component * @param array $strings * @return void */ protected static function dump_strings($lang, $component, $strings) { global $CFG; if ($lang !== clean_param($lang, PARAM_LANG)) { throw new moodle_exception('Unable to dump local strings for non-installed language pack .'.s($lang)); } if ($component !== clean_param($component, PARAM_COMPONENT)) { throw new coding_exception('Incorrect component name'); } if (!$filename = self::get_component_filename($component)) { throw new moodle_exception('Unable to find the filename for the component '.s($component)); } if ($filename !== clean_param($filename, PARAM_FILE)) { throw new coding_exception('Incorrect file name '.s($filename)); } list($package, $subpackage) = core_component::normalize_component($component); $packageinfo = " * @package $package"; if (!is_null($subpackage)) { $packageinfo .= "\n * @subpackage $subpackage"; } $filepath = self::get_localpack_location($lang); $filepath = $filepath.'/'.$filename; if (!is_dir(dirname($filepath))) { check_dir_exists(dirname($filepath)); } if (!$f = fopen($filepath, 'w')) { throw new moodle_exception('Unable to write '.s($filepath)); } fwrite($f, <<<EOF <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Local language pack from $CFG->wwwroot * $packageinfo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); EOF ); foreach ($strings as $stringid => $text) { if ($stringid !== clean_param($stringid, PARAM_STRINGID)) { debugging('Invalid string identifier '.s($stringid)); continue; } fwrite($f, '$string[\'' . $stringid . '\'] = '); fwrite($f, var_export($text, true)); fwrite($f, ";\n"); } fclose($f); @chmod($filepath, $CFG->filepermissions); } /** * Returns the name of the file where the component's local strings should be exported into * * @param string $component normalized name of the component, eg 'core' or 'mod_workshop' * @return string|boolean filename eg 'moodle.php' or 'workshop.php', false if not found */ protected static function get_component_filename($component) { $return = false; foreach (self::list_components() as $legacy => $normalized) { if ($component === $normalized) { $return = $legacy.'.php'; break; } } return $return; } /** * Returns the number of modified strings checked out in the translator * * @param string $lang language code * @return int */ public static function get_count_of_modified($lang) { global $DB; return $DB->count_records('tool_customlang', array('lang'=>$lang, 'modified'=>1)); } /** * Saves filter data into a persistant storage such as user session * * @see self::load_filter() * @param stdclass $data filter values * @param stdclass $persistant storage object */ public static function save_filter(stdclass $data, stdclass $persistant) { if (!isset($persistant->tool_customlang_filter)) { $persistant->tool_customlang_filter = array(); } foreach ($data as $key => $value) { if ($key !== 'submit') { $persistant->tool_customlang_filter[$key] = serialize($value); } } } /** * Loads the previously saved filter settings from a persistent storage * * @see self::save_filter() * @param stdclass $persistant storage object * @return stdclass filter data */ public static function load_filter(stdclass $persistant) { $data = new stdclass(); if (isset($persistant->tool_customlang_filter)) { foreach ($persistant->tool_customlang_filter as $key => $value) { $data->{$key} = unserialize($value); } } return $data; } } /** * Represents the action menu of the tool */ class tool_customlang_menu implements renderable { /** @var menu items */ protected $items = array(); public function __construct(array $items = array()) { global $CFG; foreach ($items as $itemkey => $item) { $this->add_item($itemkey, $item['title'], $item['url'], empty($item['method']) ? 'post' : $item['method']); } } /** * Returns the menu items * * @return array (string)key => (object)[->(string)title ->(moodle_url)url ->(string)method] */ public function get_items() { return $this->items; } /** * Adds item into the menu * * @param string $key item identifier * @param string $title localized action title * @param moodle_url $url action handler * @param string $method form method */ public function add_item($key, $title, moodle_url $url, $method) { if (isset($this->items[$key])) { throw new coding_exception('Menu item already exists'); } if (empty($title) or empty($key)) { throw new coding_exception('Empty title or item key not allowed'); } $item = new stdclass(); $item->title = $title; $item->url = $url; $item->method = $method; $this->items[$key] = $item; } } /** * Represents the translation tool */ class tool_customlang_translator implements renderable { /** @const int number of rows per page */ const PERPAGE = 100; /** @var int total number of the rows int the table */ public $numofrows = 0; /** @var moodle_url */ public $handler; /** @var string language code */ public $lang; /** @var int page to display, starting with page 0 */ public $currentpage = 0; /** @var array of stdclass strings to display */ public $strings = array(); /** @var stdclass */ protected $filter; public function __construct(moodle_url $handler, $lang, $filter, $currentpage = 0) { global $DB; $this->handler = $handler; $this->lang = $lang; $this->filter = $filter; $this->currentpage = $currentpage; if (empty($filter) or empty($filter->component)) { // nothing to do $this->currentpage = 1; return; } list($insql, $inparams) = $DB->get_in_or_equal($filter->component, SQL_PARAMS_NAMED); $csql = "SELECT COUNT(*)"; $fsql = "SELECT s.*, c.name AS component"; $sql = " FROM {tool_customlang_components} c JOIN {tool_customlang} s ON s.componentid = c.id WHERE s.lang = :lang AND c.name $insql"; $params = array_merge(array('lang' => $lang), $inparams); if (!empty($filter->customized)) { $sql .= " AND s.local IS NOT NULL"; } if (!empty($filter->modified)) { $sql .= " AND s.modified = 1"; } if (!empty($filter->stringid)) { $sql .= " AND s.stringid = :stringid"; $params['stringid'] = $filter->stringid; } if (!empty($filter->substring)) { $sql .= " AND (".$DB->sql_like('s.original', ':substringoriginal', false)." OR ".$DB->sql_like('s.master', ':substringmaster', false)." OR ".$DB->sql_like('s.local', ':substringlocal', false).")"; $params['substringoriginal'] = '%'.$filter->substring.'%'; $params['substringmaster'] = '%'.$filter->substring.'%'; $params['substringlocal'] = '%'.$filter->substring.'%'; } if (!empty($filter->helps)) { $sql .= " AND ".$DB->sql_like('s.stringid', ':help', false); //ILIKE $params['help'] = '%\_help'; } else { $sql .= " AND ".$DB->sql_like('s.stringid', ':link', false, true, true); //NOT ILIKE $params['link'] = '%\_link'; } $osql = " ORDER BY c.name, s.stringid"; $this->numofrows = $DB->count_records_sql($csql.$sql, $params); $this->strings = $DB->get_records_sql($fsql.$sql.$osql, $params, ($this->currentpage) * self::PERPAGE, self::PERPAGE); } } home3/cpr76684/public_html/Aem/admin/tool/dbtransfer/locallib.php 0000644 00000016166 15152263153 0020474 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Export db content to file. * * @package tool_dbtransfer * @copyright 2008 Petr Skoda {@link http://skodak.org/} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; /* TODO: - exporting to server file >2GB fails in 32bit operating systems - needs warning - we may run out of disk space exporting to server file - we must verify the file is not truncated; read from the end of file? - when sending file >4GB - FAT32 limit, Apache limit, browser limit - needs warning - there must be some form of progress bar during export, transfer - new tracking class could be passed around - command line operation - could work around some 2G/4G limits in PHP; useful for cron full backups - by default allow exporting into empty database only (no tables with the same prefix yet) - all dangerous operation (like deleting of all data) should be confirmed by key found in special file in dataroot (user would need file access to dataroot which might prevent various "accidents") - implement "Export/import running" notification in lib/setup.php (similar to new upgrade flag in config table) - gzip compression when storing xml file - the xml is very verbose and full of repeated tags (zip is not suitable here at all) this could help us keep the files below 2G (expected ratio is > 10:1) */ require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/dtllib.php'); /** * Initiate database export. * @param string $description * @param moodle_database $mdb * @return does not return, calls die() */ function tool_dbtransfer_export_xml_database($description, $mdb) { core_php_time_limit::raise(); \core\session\manager::write_close(); // Release session. header('Content-Type: application/xhtml+xml; charset=utf-8'); header('Content-Disposition: attachment; filename=database.xml'); header('Expires: 0'); header('Cache-Control: must-revalidate,post-check=0,pre-check=0'); header('Pragma: public'); while(@ob_flush()); $var = new file_xml_database_exporter('php://output', $mdb); $var->export_database($description); // No more output. die; } /** * 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); } /** * Very hacky function for rebuilding of log actions in target database. * @param moodle_database $target * @param progress_trace $feedback * @return void * @throws Exception on conversion error */ function tool_dbtransfer_rebuild_target_log_actions(moodle_database $target, progress_trace $feedback = null) { global $DB, $CFG; require_once("$CFG->libdir/upgradelib.php"); $feedback->output(get_string('convertinglogdisplay', 'tool_dbtransfer')); $olddb = $DB; $DB = $target; try { $DB->delete_records('log_display', array('component'=>'moodle')); log_update_descriptions('moodle'); $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { $plugs = core_component::get_plugin_list($type); foreach ($plugs as $plug => $fullplug) { $component = $type.'_'.$plug; $DB->delete_records('log_display', array('component'=>$component)); log_update_descriptions($component); } } } catch (Exception $e) { $DB = $olddb; throw $e; } $DB = $olddb; $feedback->output(get_string('done', 'core_dbtransfer', null), 1); } /** * Returns list of fully working database drivers present in system. * @return array */ function tool_dbtransfer_get_drivers() { global $CFG; $files = new RegexIterator(new DirectoryIterator("$CFG->libdir/dml"), '|^.*_moodle_database\.php$|'); $drivers = array(); foreach ($files as $file) { $matches = null; preg_match('|^([a-z0-9]+)_([a-z]+)_moodle_database\.php$|', $file->getFilename(), $matches); if (!$matches) { continue; } $dbtype = $matches[1]; $dblibrary = $matches[2]; if ($dbtype === 'sqlite3') { // The sqlite3 driver is not fully working yet and should not be returned. continue; } $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, false); if ($targetdb->driver_installed() !== true) { continue; } $driver = $dbtype.'/'.$dblibrary; $drivers[$driver] = $targetdb->get_name(); }; return $drivers; } /** * Create CLI maintenance file to prevent all access. */ function tool_dbtransfer_create_maintenance_file() { global $CFG; core_shutdown_manager::register_function('tool_dbtransfer_maintenance_callback'); $options = new stdClass(); $options->trusted = false; $options->noclean = false; $options->smiley = false; $options->filter = false; $options->para = true; $options->newlines = false; $message = format_text(get_string('climigrationnotice', 'tool_dbtransfer'), FORMAT_MARKDOWN, $options); $message = bootstrap_renderer::early_error_content($message, '', '', array()); $html = <<<OET <!DOCTYPE html> <html> <header><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><header/> <body>$message</body> </html> OET; file_put_contents("$CFG->dataroot/climaintenance.html", $html); @chmod("$CFG->dataroot/climaintenance.html", $CFG->filepermissions); } /** * This callback is responsible for unsetting maintenance mode * if the migration is interrupted. */ function tool_dbtransfer_maintenance_callback() { global $CFG; if (empty($CFG->tool_dbransfer_migration_running)) { // Migration was finished properly - keep the maintenance file in place. return; } if (file_exists("$CFG->dataroot/climaintenance.html")) { // Failed migration, revert to normal site operation. unlink("$CFG->dataroot/climaintenance.html"); error_log('tool_dbtransfer: Interrupted database migration detected, switching off CLI maintenance mode.'); } } home3/cpr76684/public_html/Aem/report/log/locallib.php 0000644 00000057706 15152276407 0016404 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * This file contains functions used by the log reports * * This files lists the functions that are used during the log report generation. * * @package report_log * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; if (!defined('REPORT_LOG_MAX_DISPLAY')) { define('REPORT_LOG_MAX_DISPLAY', 150); // days } require_once(__DIR__.'/lib.php'); /** * This function is used to generate and display the log activity graph * * @global stdClass $CFG * @param stdClass $course course instance * @param int|stdClass $user id/object of the user whose logs are needed * @param string $typeormode type of logs graph needed (usercourse.png/userday.png) or the mode (today, all). * @param int $date timestamp in GMT (seconds since epoch) * @param string $logreader Log reader. * @return void */ function report_log_print_graph($course, $user, $typeormode, $date=0, $logreader='') { global $CFG, $OUTPUT; if (!is_object($user)) { $user = core_user::get_user($user); } $logmanager = get_log_manager(); $readers = $logmanager->get_readers(); if (empty($logreader)) { $reader = reset($readers); } else { $reader = $readers[$logreader]; } // If reader is not a sql_internal_table_reader and not legacy store then don't show graph. if (!($reader instanceof \core\log\sql_internal_table_reader) && !($reader instanceof logstore_legacy\log\store)) { return array(); } $coursecontext = context_course::instance($course->id); $a = new stdClass(); $a->coursename = format_string($course->shortname, true, array('context' => $coursecontext)); $a->username = fullname($user, true); if ($typeormode == 'today' || $typeormode == 'userday.png') { $logs = report_log_usertoday_data($course, $user, $date, $logreader); $title = get_string("hitsoncoursetoday", "", $a); } else if ($typeormode == 'all' || $typeormode == 'usercourse.png') { $logs = report_log_userall_data($course, $user, $logreader); $title = get_string("hitsoncourse", "", $a); } if (!empty($CFG->preferlinegraphs)) { $chart = new \core\chart_line(); } else { $chart = new \core\chart_bar(); } $series = new \core\chart_series(get_string("hits"), $logs['series']); $chart->add_series($series); $chart->set_title($title); $chart->set_labels($logs['labels']); $yaxis = $chart->get_yaxis(0, true); $yaxis->set_label(get_string("hits")); $yaxis->set_stepsize(max(1, round(max($logs['series']) / 10))); echo $OUTPUT->render($chart); } /** * Select all log records for a given course and user * * @param int $userid The id of the user as found in the 'user' table. * @param int $courseid The id of the course as found in the 'course' table. * @param string $coursestart unix timestamp representing course start date and time. * @param string $logreader log reader to use. * @return array */ function report_log_usercourse($userid, $courseid, $coursestart, $logreader = '') { global $DB; $logmanager = get_log_manager(); $readers = $logmanager->get_readers(); if (empty($logreader)) { $reader = reset($readers); } else { $reader = $readers[$logreader]; } // If reader is not a sql_internal_table_reader and not legacy store then return. if (!($reader instanceof \core\log\sql_internal_table_reader) && !($reader instanceof logstore_legacy\log\store)) { return array(); } $coursestart = (int)$coursestart; // Note: unfortunately pg complains if you use name parameter or column alias in GROUP BY. if ($reader instanceof logstore_legacy\log\store) { $logtable = 'log'; $timefield = 'time'; $coursefield = 'course'; // Anonymous actions are never logged in legacy log. $nonanonymous = ''; } else { $logtable = $reader->get_internal_log_table_name(); $timefield = 'timecreated'; $coursefield = 'courseid'; $nonanonymous = 'AND anonymous = 0'; } $params = array(); $courseselect = ''; if ($courseid) { $courseselect = "AND $coursefield = :courseid"; $params['courseid'] = $courseid; } $params['userid'] = $userid; return $DB->get_records_sql("SELECT FLOOR(($timefield - $coursestart)/" . DAYSECS . ") AS day, COUNT(*) AS num FROM {" . $logtable . "} WHERE userid = :userid AND $timefield > $coursestart $courseselect $nonanonymous GROUP BY FLOOR(($timefield - $coursestart)/" . DAYSECS .")", $params); } /** * Select all log records for a given course, user, and day * * @param int $userid The id of the user as found in the 'user' table. * @param int $courseid The id of the course as found in the 'course' table. * @param string $daystart unix timestamp of the start of the day for which the logs needs to be retrived * @param string $logreader log reader to use. * @return array */ function report_log_userday($userid, $courseid, $daystart, $logreader = '') { global $DB; $logmanager = get_log_manager(); $readers = $logmanager->get_readers(); if (empty($logreader)) { $reader = reset($readers); } else { $reader = $readers[$logreader]; } // If reader is not a sql_internal_table_reader and not legacy store then return. if (!($reader instanceof \core\log\sql_internal_table_reader) && !($reader instanceof logstore_legacy\log\store)) { return array(); } $daystart = (int)$daystart; // Note: unfortunately pg complains if you use name parameter or column alias in GROUP BY. if ($reader instanceof logstore_legacy\log\store) { $logtable = 'log'; $timefield = 'time'; $coursefield = 'course'; // Anonymous actions are never logged in legacy log. $nonanonymous = ''; } else { $logtable = $reader->get_internal_log_table_name(); $timefield = 'timecreated'; $coursefield = 'courseid'; $nonanonymous = 'AND anonymous = 0'; } $params = array('userid' => $userid); $courseselect = ''; if ($courseid) { $courseselect = "AND $coursefield = :courseid"; $params['courseid'] = $courseid; } return $DB->get_records_sql("SELECT FLOOR(($timefield - $daystart)/" . HOURSECS . ") AS hour, COUNT(*) AS num FROM {" . $logtable . "} WHERE userid = :userid AND $timefield > $daystart $courseselect $nonanonymous GROUP BY FLOOR(($timefield - $daystart)/" . HOURSECS . ") ", $params); } /** * This function is used to generate and display Mnet selector form * * @global stdClass $USER * @global stdClass $CFG * @global stdClass $SITE * @global moodle_database $DB * @global core_renderer $OUTPUT * @global stdClass $SESSION * @uses CONTEXT_SYSTEM * @uses COURSE_MAX_COURSES_PER_DROPDOWN * @uses CONTEXT_COURSE * @uses SEPARATEGROUPS * @param int $hostid host id * @param stdClass $course course instance * @param int $selecteduser id of the selected user * @param string $selecteddate Date selected * @param string $modname course_module->id * @param string $modid number or 'site_errors' * @param string $modaction an action as recorded in the logs * @param int $selectedgroup Group to display * @param int $showcourses whether to show courses if we're over our limit. * @param int $showusers whether to show users if we're over our limit. * @param string $logformat Format of the logs (downloadascsv, showashtml, downloadasods, downloadasexcel) * @return void */ function report_log_print_mnet_selector_form($hostid, $course, $selecteduser=0, $selecteddate='today', $modname="", $modid=0, $modaction='', $selectedgroup=-1, $showcourses=0, $showusers=0, $logformat='showashtml') { global $USER, $CFG, $SITE, $DB, $OUTPUT, $SESSION; require_once $CFG->dirroot.'/mnet/peer.php'; $mnet_peer = new mnet_peer(); $mnet_peer->set_id($hostid); $sql = "SELECT DISTINCT course, hostid, coursename FROM {mnet_log}"; $courses = $DB->get_records_sql($sql); $remotecoursecount = count($courses); // first check to see if we can override showcourses and showusers $numcourses = $remotecoursecount + $DB->count_records('course'); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } $sitecontext = context_system::instance(); // Context for remote data is always SITE // Groups for remote data are always OFF if ($hostid == $CFG->mnet_localhost_id) { $context = context_course::instance($course->id); /// Setup for group handling. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = -1; $showgroups = false; } else if ($course->groupmode) { $showgroups = true; } else { $selectedgroup = 0; $showgroups = false; } if ($selectedgroup === -1) { if (isset($SESSION->currentgroup[$course->id])) { $selectedgroup = $SESSION->currentgroup[$course->id]; } else { $selectedgroup = groups_get_all_groups($course->id, $USER->id); if (is_array($selectedgroup)) { $selectedgroup = array_shift(array_keys($selectedgroup)); $SESSION->currentgroup[$course->id] = $selectedgroup; } else { $selectedgroup = 0; } } } } else { $context = $sitecontext; } // Get all the possible users $users = array(); // Define limitfrom and limitnum for queries below // If $showusers is enabled... don't apply limitfrom and limitnum $limitfrom = empty($showusers) ? 0 : ''; $limitnum = empty($showusers) ? COURSE_MAX_USERS_PER_DROPDOWN + 1 : ''; // If looking at a different host, we're interested in all our site users if ($hostid == $CFG->mnet_localhost_id && $course->id != SITEID) { $userfieldsapi = \core_user\fields::for_name(); $courseusers = get_enrolled_users($context, '', $selectedgroup, 'u.id, ' . $userfieldsapi->get_sql('u', false, '', '', false)->selects, null, $limitfrom, $limitnum); } else { // this may be a lot of users :-( $userfieldsapi = \core_user\fields::for_name(); $courseusers = $DB->get_records('user', array('deleted' => 0), 'lastaccess DESC', 'id, ' . $userfieldsapi->get_sql('', false, '', '', false)->selects, $limitfrom, $limitnum); } if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { $showusers = 1; } if ($showusers) { if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } $users[$CFG->siteguest] = get_string('guestuser'); } // Get all the hosts that have log records $sql = "select distinct h.id, h.name from {mnet_host} h, {mnet_log} l where h.id = l.hostid order by h.name"; if ($hosts = $DB->get_records_sql($sql)) { foreach($hosts as $host) { $hostarray[$host->id] = $host->name; } } $hostarray[$CFG->mnet_localhost_id] = $SITE->fullname; asort($hostarray); $dropdown = array(); foreach($hostarray as $hostid => $name) { $courses = array(); $sites = array(); if ($CFG->mnet_localhost_id == $hostid) { if (has_capability('report/log:view', $sitecontext) && $showcourses) { if ($ccc = $DB->get_records("course", null, "fullname","id,shortname,fullname,category")) { foreach ($ccc as $cc) { if ($cc->id == SITEID) { $sites["$hostid/$cc->id"] = format_string($cc->fullname).' ('.get_string('site').')'; } else { $courses["$hostid/$cc->id"] = format_string(get_course_display_name_for_list($cc)); } } } } } else { if (has_capability('report/log:view', $sitecontext) && $showcourses) { $sql = "SELECT DISTINCT course, coursename FROM {mnet_log} where hostid = ?"; if ($ccc = $DB->get_records_sql($sql, array($hostid))) { foreach ($ccc as $cc) { if (1 == $cc->course) { // TODO: this might be wrong - site course may have another id $sites["$hostid/$cc->course"] = $cc->coursename.' ('.get_string('site').')'; } else { $courses["$hostid/$cc->course"] = $cc->coursename; } } } } } asort($courses); $dropdown[] = array($name=>($sites + $courses)); } $activities = array(); $selectedactivity = ""; $modinfo = get_fast_modinfo($course); if (!empty($modinfo->cms)) { $section = 0; $thissection = array(); foreach ($modinfo->cms as $cm) { // Exclude activities that aren't visible or have no view link (e.g. label). Account for folder being displayed inline. if (!$cm->uservisible || (!$cm->has_view() && strcmp($cm->modname, 'folder') !== 0)) { continue; } if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) { $activities[] = $thissection; $thissection = array(); } $section = $cm->sectionnum; $modname = strip_tags($cm->get_formatted_name()); if (core_text::strlen($modname) > 55) { $modname = core_text::substr($modname, 0, 50)."..."; } if (!$cm->visible) { $modname = "(".$modname.")"; } $key = get_section_name($course, $cm->sectionnum); if (!isset($thissection[$key])) { $thissection[$key] = array(); } $thissection[$key][$cm->id] = $modname; if ($cm->id == $modid) { $selectedactivity = "$cm->id"; } } if (!empty($thissection)) { $activities[] = $thissection; } } if (has_capability('report/log:view', $sitecontext) && !$course->category) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; } } $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); asort($users); // Prepare the list of action options. $actions = array( 'view' => get_string('view'), 'add' => get_string('add'), 'update' => get_string('update'), 'delete' => get_string('delete'), '-view' => get_string('allchanges') ); // Get all the possible dates // Note that we are keeping track of real (GMT) time and user time // User time is only used in displays - all calcs and passing is GMT $timenow = time(); // GMT // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = $today = usergetmidnight($timenow); // Put today up the top of the list $dates = array( "0" => get_string('alldays'), "$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); if (!$course->startdate or ($course->startdate > $timenow)) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); $numdates++; } if ($selecteddate === "today") { $selecteddate = $today; } echo "<form class=\"logselectform\" action=\"$CFG->wwwroot/report/log/index.php\" method=\"get\">\n"; echo "<div>\n";//invisible fieldset here breaks wrapping echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n"; echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n"; if (has_capability('report/log:view', $sitecontext) && $showcourses) { $cid = empty($course->id)? '1' : $course->id; echo html_writer::label(get_string('selectacoursesite'), 'menuhost_course', false, array('class' => 'accesshide')); echo html_writer::select($dropdown, "host_course", $hostid.'/'.$cid); } else { $courses = array(); $courses[$course->id] = get_course_display_name_for_list($course) . ((empty($course->category)) ? ' ('.get_string('site').') ' : ''); echo html_writer::label(get_string('selectacourse'), 'menuid', false, array('class' => 'accesshide')); echo html_writer::select($courses,"id",$course->id, false); if (has_capability('report/log:view', $sitecontext)) { $a = new stdClass(); $a->url = "$CFG->wwwroot/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; print_string('logtoomanycourses','moodle',$a); } } if ($showgroups) { if ($cgroups = groups_get_all_groups($course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } else { $groups = array(); } echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide')); echo html_writer::select($groups, "group", $selectedgroup, get_string("allgroups")); } if ($showusers) { echo html_writer::label(get_string('participantslist'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $selecteduser, get_string("allparticipants")); } else { $users = array(); if (!empty($selecteduser)) { $user = $DB->get_record('user', array('id'=>$selecteduser)); $users[$selecteduser] = fullname($user); } else { $users[0] = get_string('allparticipants'); } echo html_writer::label(get_string('participantslist'), 'menuuser', false, array('class' => 'accesshide')); echo html_writer::select($users, "user", $selecteduser, false); $a = new stdClass(); $a->url = "$CFG->wwwroot/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showusers=1&showcourses=$showcourses"; print_string('logtoomanyusers','moodle',$a); } echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide')); echo html_writer::select($dates, "date", $selecteddate, false); echo html_writer::label(get_string('showreports'), 'menumodid', false, array('class' => 'accesshide')); echo html_writer::select($activities, "modid", $selectedactivity, get_string("allactivities")); echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide')); echo html_writer::select($actions, 'modaction', $modaction, get_string("allactions")); $logformats = array('showashtml' => get_string('displayonpage'), 'downloadascsv' => get_string('downloadtext'), 'downloadasods' => get_string('downloadods'), 'downloadasexcel' => get_string('downloadexcel')); echo html_writer::label(get_string('logsformat', 'report_log'), 'menulogformat', false, array('class' => 'accesshide')); echo html_writer::select($logformats, 'logformat', $logformat, false); echo '<input type="submit" value="'.get_string('gettheselogs').'" />'; echo '</div>'; echo '</form>'; } /** * Fetch logs since the start of the courses and structure in series and labels to be sent to Chart API. * * @param stdClass $course the course object * @param stdClass $user user object * @param string $logreader the log reader where the logs are. * @return array structured array to be sent to chart API, split in two indexes (series and labels). */ function report_log_userall_data($course, $user, $logreader) { global $CFG; $site = get_site(); $timenow = time(); $logs = []; if ($course->id == $site->id) { $courseselect = 0; } else { $courseselect = $course->id; } $maxseconds = REPORT_LOG_MAX_DISPLAY * 3600 * 24; // Seconds. if ($timenow - $course->startdate > $maxseconds) { $course->startdate = $timenow - $maxseconds; } if (!empty($CFG->loglifetime)) { $maxseconds = $CFG->loglifetime * 3600 * 24; // Seconds. if ($timenow - $course->startdate > $maxseconds) { $course->startdate = $timenow - $maxseconds; } } $timestart = $coursestart = usergetmidnight($course->startdate); $i = 0; $logs['series'][$i] = 0; $logs['labels'][$i] = 0; while ($timestart < $timenow) { $timefinish = $timestart + 86400; $logs['labels'][$i] = userdate($timestart, "%a %d %b"); $logs['series'][$i] = 0; $i++; $timestart = $timefinish; } $rawlogs = report_log_usercourse($user->id, $courseselect, $coursestart, $logreader); foreach ($rawlogs as $rawlog) { if (isset($logs['labels'][$rawlog->day])) { $logs['series'][$rawlog->day] = $rawlog->num; } } return $logs; } /** * Fetch logs of the current day and structure in series and labels to be sent to Chart API. * * @param stdClass $course the course object * @param stdClass $user user object * @param int $date A time of a day (in GMT). * @param string $logreader the log reader where the logs are. * @return array $logs structured array to be sent to chart API, split in two indexes (series and labels). */ function report_log_usertoday_data($course, $user, $date, $logreader) { $site = get_site(); $logs = []; if ($course->id == $site->id) { $courseselect = 0; } else { $courseselect = $course->id; } if ($date) { $daystart = usergetmidnight($date); } else { $daystart = usergetmidnight(time()); } for ($i = 0; $i <= 23; $i++) { $hour = $daystart + $i * 3600; $logs['series'][$i] = 0; $logs['labels'][$i] = userdate($hour, "%H:00"); } $rawlogs = report_log_userday($user->id, $courseselect, $daystart, $logreader); foreach ($rawlogs as $rawlog) { if (isset($logs['labels'][$rawlog->hour])) { $logs['series'][$rawlog->hour] = $rawlog->num; } } return $logs; } home3/cpr76684/public_html/Aem/mod/imscp/locallib.php 0000644 00000034662 15152537353 0016176 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Private imscp module utility functions * * @package mod_imscp * @copyright 2009 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); require_once("$CFG->dirroot/mod/imscp/lib.php"); require_once("$CFG->libdir/filelib.php"); require_once("$CFG->libdir/resourcelib.php"); /** * Print IMSCP content to page. * * @param stdClass $imscp module instance. * @param stdClass $cm course module. * @param stdClass $course record. */ function imscp_print_content($imscp, $cm, $course) { global $PAGE, $CFG; $items = unserialize($imscp->structure); $first = reset($items); $context = context_module::instance($cm->id); $urlbase = "$CFG->wwwroot/pluginfile.php"; $path = '/'.$context->id.'/mod_imscp/content/'.$imscp->revision.'/'.$first['href']; $firsturl = file_encode_url($urlbase, $path, false); echo '<div id="imscp_layout">'; echo '<div id="imscp_toc">'; echo '<div id="imscp_tree"><ul>'; foreach ($items as $item) { echo imscp_htmllize_item($item, $imscp, $cm); } echo '</ul></div>'; echo '<div id="imscp_nav" style="display:none">'; echo '<button id="nav_skipprev"><<</button><button id="nav_prev"><</button><button id="nav_up">^</button>'; echo '<button id="nav_next">></button><button id="nav_skipnext">>></button>'; echo '</div>'; echo '</div>'; echo '</div>'; $PAGE->requires->js_init_call('M.mod_imscp.init'); return; } /** * Internal function - creates htmls structure suitable for YUI tree. */ function imscp_htmllize_item($item, $imscp, $cm) { global $CFG; if ($item['href']) { if (preg_match('|^https?://|', $item['href'])) { $url = $item['href']; } else { $context = context_module::instance($cm->id); $urlbase = "$CFG->wwwroot/pluginfile.php"; $path = '/'.$context->id.'/mod_imscp/content/'.$imscp->revision.'/'.$item['href']; $url = file_encode_url($urlbase, $path, false); } $result = "<li><a href=\"$url\">".$item['title'].'</a>'; } else { $result = '<li>'.$item['title']; } if ($item['subitems']) { $result .= '<ul>'; foreach ($item['subitems'] as $subitem) { $result .= imscp_htmllize_item($subitem, $imscp, $cm); } $result .= '</ul>'; } $result .= '</li>'; return $result; } /** * Parse an IMS content package's manifest file to determine its structure * @param object $imscp * @param object $context * @return array */ function imscp_parse_structure($imscp, $context) { $fs = get_file_storage(); if (!$manifestfile = $fs->get_file($context->id, 'mod_imscp', 'content', $imscp->revision, '/', 'imsmanifest.xml')) { return null; } return imscp_parse_manifestfile($manifestfile->get_content(), $imscp, $context); } /** * Parse the contents of a IMS package's manifest file. * @param string $manifestfilecontents the contents of the manifest file * @return array */ function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) { $doc = new DOMDocument(); $oldentities = imscp_libxml_disable_entity_loader(true); if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) { return null; } imscp_libxml_disable_entity_loader($oldentities); // We put this fake URL as base in order to detect path changes caused by xml:base attributes. $doc->documentURI = 'http://grrr/'; $xmlorganizations = $doc->getElementsByTagName('organizations'); if (empty($xmlorganizations->length)) { return null; } $default = null; if ($xmlorganizations->item(0)->attributes->getNamedItem('default')) { $default = $xmlorganizations->item(0)->attributes->getNamedItem('default')->nodeValue; } $xmlorganization = $doc->getElementsByTagName('organization'); if (empty($xmlorganization->length)) { return null; } $organization = null; foreach ($xmlorganization as $org) { if (is_null($organization)) { // Use first if default nor found. $organization = $org; } if (!$org->attributes->getNamedItem('identifier')) { continue; } if ($default === $org->attributes->getNamedItem('identifier')->nodeValue) { // Found default - use it. $organization = $org; break; } } // Load all resources. $resources = array(); $xmlresources = $doc->getElementsByTagName('resource'); foreach ($xmlresources as $res) { if (!$identifier = $res->attributes->getNamedItem('identifier')) { continue; } $identifier = $identifier->nodeValue; if ($xmlbase = $res->baseURI) { // Undo the fake URL, we are interested in relative links only. $xmlbase = str_replace('http://grrr/', '/', $xmlbase); $xmlbase = rtrim($xmlbase, '/').'/'; } else { $xmlbase = ''; } if (!$href = $res->attributes->getNamedItem('href')) { // If href not found look for <file href="help.htm"/>. $fileresources = $res->getElementsByTagName('file'); foreach ($fileresources as $file) { $href = $file->getAttribute('href'); } if (pathinfo($href, PATHINFO_EXTENSION) == 'xml') { $href = imscp_recursive_href($href, $imscp, $context); } if (empty($href)) { continue; } } else { $href = $href->nodeValue; } if (strpos($href, 'http://') !== 0) { $href = $xmlbase.$href; } // Item href cleanup - Some packages are poorly done and use \ in urls. $href = ltrim(strtr($href, "\\", '/'), '/'); $resources[$identifier] = $href; } $items = array(); foreach ($organization->childNodes as $child) { if ($child->nodeName === 'item') { if (!$item = imscp_recursive_item($child, 0, $resources)) { continue; } $items[] = $item; } } return $items; } function imscp_recursive_href($manifestfilename, $imscp, $context) { $fs = get_file_storage(); $dirname = dirname($manifestfilename); $filename = basename($manifestfilename); if ($dirname !== '/') { $dirname = "/$dirname/"; } if (!$manifestfile = $fs->get_file($context->id, 'mod_imscp', 'content', $imscp->revision, $dirname, $filename)) { return null; } $doc = new DOMDocument(); $oldentities = imscp_libxml_disable_entity_loader(true); if (!$doc->loadXML($manifestfile->get_content(), LIBXML_NONET)) { return null; } imscp_libxml_disable_entity_loader($oldentities); $xmlresources = $doc->getElementsByTagName('resource'); foreach ($xmlresources as $res) { if (!$href = $res->attributes->getNamedItem('href')) { $fileresources = $res->getElementsByTagName('file'); foreach ($fileresources as $file) { $href = $file->getAttribute('href'); if (pathinfo($href, PATHINFO_EXTENSION) == 'xml') { $href = imscp_recursive_href($href, $imscp, $context); } if (pathinfo($href, PATHINFO_EXTENSION) == 'htm' || pathinfo($href, PATHINFO_EXTENSION) == 'html') { return $href; } } } } return $manifestfilename; } function imscp_recursive_item($xmlitem, $level, $resources) { $identifierref = ''; if ($identifierref = $xmlitem->attributes->getNamedItem('identifierref')) { $identifierref = $identifierref->nodeValue; } $title = '?'; $subitems = array(); foreach ($xmlitem->childNodes as $child) { if ($child->nodeName === 'title') { $title = $child->textContent; } else if ($child->nodeName === 'item') { if ($subitem = imscp_recursive_item($child, $level + 1, $resources)) { $subitems[] = $subitem; } } } return array('href' => isset($resources[$identifierref]) ? $resources[$identifierref] : '', 'title' => $title, 'level' => $level, 'subitems' => $subitems, ); } /** * Wrapper for function libxml_disable_entity_loader() deprecated in PHP 8 * * Method was deprecated in PHP 8 and it shows deprecation message. However it is still * required in the previous versions on PHP. While Moodle supports both PHP 7 and 8 we need to keep it. * @see https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation * * @param bool $value * @return bool */ function imscp_libxml_disable_entity_loader(bool $value): bool { if (PHP_VERSION_ID < 80000) { return (bool)libxml_disable_entity_loader($value); } return true; } /** * File browsing support class * * @copyright 2009 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class imscp_file_info extends file_info { protected $course; protected $cm; protected $areas; protected $filearea; public function __construct($browser, $course, $cm, $context, $areas, $filearea) { parent::__construct($browser, $context); $this->course = $course; $this->cm = $cm; $this->areas = $areas; $this->filearea = $filearea; } /** * Returns list of standard virtual file/directory identification. * The difference from stored_file parameters is that null values * are allowed in all fields * @return array with keys contextid, filearea, itemid, filepath and filename */ public function get_params() { return array('contextid' => $this->context->id, 'component' => 'mod_imscp', 'filearea' => $this->filearea, 'itemid' => null, 'filepath' => null, 'filename' => null); } /** * Returns localised visible name. * @return string */ public function get_visible_name() { return $this->areas[$this->filearea]; } /** * Can I add new files or directories? * @return bool */ public function is_writable() { return false; } /** * Is directory? * @return bool */ public function is_directory() { return true; } /** * Returns list of children. * @return array of file_info instances */ public function get_children() { return $this->get_filtered_children('*', false, true); } /** * Help function to return files matching extensions or their count * * @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') * @param bool|int $countonly if false returns the children, if an int returns just the * count of children but stops counting when $countonly number of children is reached * @param bool $returnemptyfolders if true returns items that don't have matching files inside * @return array|int array of file_info instances or the count */ private function get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false) { global $DB; $params = array('contextid' => $this->context->id, 'component' => 'mod_imscp', 'filearea' => $this->filearea); $sql = 'SELECT DISTINCT itemid FROM {files} WHERE contextid = :contextid AND component = :component AND filearea = :filearea'; if (!$returnemptyfolders) { $sql .= ' AND filename <> :emptyfilename'; $params['emptyfilename'] = '.'; } list($sql2, $params2) = $this->build_search_files_sql($extensions); $sql .= ' '.$sql2; $params = array_merge($params, $params2); if ($countonly !== false) { $sql .= ' ORDER BY itemid'; } $rs = $DB->get_recordset_sql($sql, $params); $children = array(); foreach ($rs as $record) { if ($child = $this->browser->get_file_info($this->context, 'mod_imscp', $this->filearea, $record->itemid)) { $children[] = $child; if ($countonly !== false && count($children) >= $countonly) { break; } } } $rs->close(); if ($countonly !== false) { return count($children); } return $children; } /** * Returns list of children which are either files matching the specified extensions * or folders that contain at least one such file. * * @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') * @return array of file_info instances */ public function get_non_empty_children($extensions = '*') { return $this->get_filtered_children($extensions, false); } /** * Returns the number of children which are either files matching the specified extensions * or folders containing at least one such file. * * @param string|array $extensions, for example '*' or array('.gif','.jpg') * @param int $limit stop counting after at least $limit non-empty children are found * @return int */ public function count_non_empty_children($extensions = '*', $limit = 1) { return $this->get_filtered_children($extensions, $limit); } /** * Returns parent file_info instance * @return file_info or null for root */ public function get_parent() { return $this->browser->get_file_info($this->context); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�