mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge remote branch 'origin/master' into rubric
Conflicts: lib/db/upgrade.php
This commit is contained in:
commit
18dd4a69d0
@ -20,7 +20,6 @@
|
||||
*
|
||||
* This script is not intended for beginners!
|
||||
* Potential problems:
|
||||
* - environment check is not present yet
|
||||
* - su to apache account or sudo before execution
|
||||
* - not compatible with Windows platform
|
||||
*
|
||||
@ -91,7 +90,11 @@ if (file_exists($configfile)) {
|
||||
echo "\n\n";
|
||||
}
|
||||
|
||||
cli_error(get_string('clialreadyinstalled', 'install'));
|
||||
if ($DB->get_manager()->table_exists('config')) {
|
||||
cli_error(get_string('clialreadyinstalled', 'install'));
|
||||
} else {
|
||||
cli_error(get_string('clialreadyconfigured', 'install'));
|
||||
}
|
||||
}
|
||||
|
||||
$olddir = getcwd();
|
||||
@ -647,6 +650,27 @@ require($configfile);
|
||||
$CFG->lang = $installlang;
|
||||
$SESSION->lang = $CFG->lang;
|
||||
|
||||
require("$CFG->dirroot/version.php");
|
||||
|
||||
// Test environment first.
|
||||
require_once($CFG->libdir . '/environmentlib.php');
|
||||
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
|
||||
if (!$envstatus) {
|
||||
$errors = environment_get_errors($environment_results);
|
||||
cli_heading(get_string('environment', 'admin'));
|
||||
foreach ($errors as $error) {
|
||||
list($info, $report) = $error;
|
||||
echo "!! $info !!\n$report\n\n";
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Test plugin dependencies.
|
||||
require_once($CFG->libdir . '/pluginlib.php');
|
||||
if (!plugin_manager::instance()->all_plugins_ok($version)) {
|
||||
cli_error(get_string('pluginschecktodo', 'admin'));
|
||||
}
|
||||
|
||||
install_cli_database($options, $interactive);
|
||||
|
||||
echo get_string('cliinstallfinished', 'install')."\n";
|
||||
|
@ -144,6 +144,26 @@ if ($CFG->lang !== 'en') {
|
||||
$CFG->early_install_lang = false;
|
||||
get_string_manager(true);
|
||||
|
||||
require("$CFG->dirroot/version.php");
|
||||
|
||||
// Test environment first.
|
||||
require_once($CFG->libdir . '/environmentlib.php');
|
||||
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
|
||||
if (!$envstatus) {
|
||||
$errors = environment_get_errors($environment_results);
|
||||
cli_heading(get_string('environment', 'admin'));
|
||||
foreach ($errors as $error) {
|
||||
list($info, $report) = $error;
|
||||
echo "!! $info !!\n$report\n\n";
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Test plugin dependencies.
|
||||
require_once($CFG->libdir . '/pluginlib.php');
|
||||
if (!plugin_manager::instance()->all_plugins_ok($version)) {
|
||||
cli_error(get_string('pluginschecktodo', 'admin'));
|
||||
}
|
||||
|
||||
install_cli_database($options, true);
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
*
|
||||
* This script is not intended for beginners!
|
||||
* Potential problems:
|
||||
* - environment check is not present yet
|
||||
* - su to apache account or sudo before execution
|
||||
* - not compatible with Windows platform
|
||||
*
|
||||
@ -37,7 +36,7 @@ require_once($CFG->libdir.'/adminlib.php'); // various admin-only function
|
||||
require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
|
||||
require_once($CFG->libdir.'/clilib.php'); // cli only functions
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
|
||||
require_once($CFG->libdir.'/pluginlib.php');
|
||||
|
||||
// now get cli options
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
@ -93,8 +92,9 @@ if ($version < $CFG->version) {
|
||||
$oldversion = "$CFG->release ($CFG->version)";
|
||||
$newversion = "$release ($version)";
|
||||
|
||||
// test environment first
|
||||
if (!check_moodle_environment(normalize_version($release), $environment_results, false, ENV_SELECT_RELEASE)) {
|
||||
// Test environment first.
|
||||
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
|
||||
if (!$envstatus) {
|
||||
$errors = environment_get_errors($environment_results);
|
||||
cli_heading(get_string('environment', 'admin'));
|
||||
foreach ($errors as $error) {
|
||||
@ -104,6 +104,11 @@ if (!check_moodle_environment(normalize_version($release), $environment_results,
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Test plugin dependencies.
|
||||
if (!plugin_manager::instance()->all_plugins_ok($version)) {
|
||||
cli_error(get_string('pluginschecktodo', 'admin'));
|
||||
}
|
||||
|
||||
if ($interactive) {
|
||||
$a = new stdClass();
|
||||
$a->oldversion = $oldversion;
|
||||
|
@ -1,137 +1,109 @@
|
||||
<?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/>.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program 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 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program 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: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is the admin frontend to execute all the checks available
|
||||
// in the environment.xml file. It includes database, php and
|
||||
// php_extensions. Also, it's possible to update the xml file
|
||||
// from moodle.org be able to check more and more versions.
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
require_once($CFG->libdir.'/componentlib.class.php');
|
||||
|
||||
admin_externalpage_setup('environment');
|
||||
|
||||
/// Parameters
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$version = optional_param('version', '', PARAM_FILE); //
|
||||
/**
|
||||
* This file is the admin frontend to execute all the checks available
|
||||
* in the environment.xml file. It includes database, php and
|
||||
* php_extensions. Also, it's possible to update the xml file
|
||||
* from moodle.org be able to check more and more versions.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage admin
|
||||
* @copyright 2006 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
/// Get some strings
|
||||
$stradmin = get_string('administration');
|
||||
$stradminhelpenvironment = get_string("adminhelpenvironment");
|
||||
$strenvironment = get_string('environment', 'admin');
|
||||
$strerror = get_string('error');
|
||||
$strmoodleversion = get_string('moodleversion');
|
||||
$strupdate = get_string('updatecomponent', 'admin');
|
||||
$strupwards = get_string('upwards', 'admin');
|
||||
$strmisc = get_string('miscellaneous');
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
require_once($CFG->libdir.'/componentlib.class.php');
|
||||
|
||||
/// Print the header stuff
|
||||
echo $OUTPUT->header();
|
||||
// Parameters
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$version = optional_param('version', '', PARAM_FILE); //
|
||||
|
||||
/// Print the component download link
|
||||
echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&sesskey='.sesskey().'">'.$strupdate.'</a></div>';
|
||||
$extraurlparams = array();
|
||||
if ($version) {
|
||||
$extraurlparams['version'] = $version;
|
||||
}
|
||||
admin_externalpage_setup('environment', '', $extraurlparams);
|
||||
|
||||
echo $OUTPUT->heading($strenvironment);
|
||||
// Handle the 'updatecomponent' action
|
||||
if ($action == 'updatecomponent' && confirm_sesskey()) {
|
||||
// Create component installer and execute it
|
||||
if ($cd = new component_installer('http://download.moodle.org',
|
||||
'environment',
|
||||
'environment.zip')) {
|
||||
$status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
|
||||
switch ($status) {
|
||||
case COMPONENT_ERROR:
|
||||
if ($cd->get_error() == 'remotedownloaderror') {
|
||||
$a = new stdClass();
|
||||
$a->url = 'http://download.moodle.org/environment/environment.zip';
|
||||
$a->dest = $CFG->dataroot . '/';
|
||||
print_error($cd->get_error(), 'error', $PAGE->url, $a);
|
||||
die();
|
||||
|
||||
/// Handle the 'updatecomponent' action
|
||||
if ($action == 'updatecomponent' && confirm_sesskey()) {
|
||||
/// Create component installer and execute it
|
||||
if ($cd = new component_installer('http://download.moodle.org',
|
||||
'environment',
|
||||
'environment.zip')) {
|
||||
$status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
|
||||
switch ($status) {
|
||||
case COMPONENT_ERROR:
|
||||
if ($cd->get_error() == 'remotedownloaderror') {
|
||||
$a = new stdClass();
|
||||
$a->url = 'http://download.moodle.org/environment/environment.zip';
|
||||
$a->dest= $CFG->dataroot.'/';
|
||||
echo $OUTPUT->box(get_string($cd->get_error(), 'error', $a), 'errorbox');
|
||||
} else {
|
||||
echo $OUTPUT->box(get_string($cd->get_error(), 'error'), 'errorbox');
|
||||
}
|
||||
break;
|
||||
case COMPONENT_UPTODATE:
|
||||
echo $OUTPUT->box(get_string($cd->get_error(), 'error'));
|
||||
break;
|
||||
case COMPONENT_INSTALLED:
|
||||
echo $OUTPUT->box(get_string('componentinstalled', 'admin'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Start of main box
|
||||
echo $OUTPUT->box_start();
|
||||
|
||||
echo "<div style=\"text-align:center\">".$stradminhelpenvironment."</div><br />";
|
||||
|
||||
/// Get current Moodle version
|
||||
$current_version = $CFG->release;
|
||||
|
||||
/// Calculate list of versions
|
||||
$versions = array();
|
||||
if ($contents = load_environment_xml()) {
|
||||
if ($env_versions = get_list_of_environment_versions($contents)) {
|
||||
/// Set the current version at the beginning
|
||||
$env_version = normalize_version($current_version); //We need this later (for the upwards)
|
||||
$versions[$env_version] = $current_version;
|
||||
/// If no version has been previously selected, default to $current_version
|
||||
if (empty($version)) {
|
||||
$version = $env_version;
|
||||
}
|
||||
///Iterate over each version, adding bigger than current
|
||||
foreach ($env_versions as $env_version) {
|
||||
if (version_compare(normalize_version($current_version), $env_version, '<')) {
|
||||
$versions[$env_version] = $env_version;
|
||||
} else {
|
||||
print_error($cd->get_error(), 'error', $PAGE->url);
|
||||
die();
|
||||
}
|
||||
}
|
||||
/// Add 'upwards' to the last element
|
||||
$versions[$env_version] = $env_version.' '.$strupwards;
|
||||
} else {
|
||||
$versions = array('error' => $strerror);
|
||||
|
||||
case COMPONENT_UPTODATE:
|
||||
redirect($PAGE->url, get_string($cd->get_error(), 'error'));
|
||||
die;
|
||||
|
||||
case COMPONENT_INSTALLED:
|
||||
redirect($PAGE->url, get_string('componentinstalled', 'admin'));
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Print form and popup menu
|
||||
echo '<div style="text-align:center"> ';
|
||||
$select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
|
||||
$select->label = $strmoodleversion;
|
||||
echo $OUTPUT->render($select);
|
||||
echo '</div>';
|
||||
// Get current Moodle version
|
||||
$current_version = $CFG->release;
|
||||
|
||||
/// End of main box
|
||||
echo $OUTPUT->box_end();
|
||||
// Calculate list of versions
|
||||
$versions = array();
|
||||
if ($contents = load_environment_xml()) {
|
||||
if ($env_versions = get_list_of_environment_versions($contents)) {
|
||||
// Set the current version at the beginning
|
||||
$env_version = normalize_version($current_version); //We need this later (for the upwards)
|
||||
$versions[$env_version] = $current_version;
|
||||
// If no version has been previously selected, default to $current_version
|
||||
if (empty($version)) {
|
||||
$version = $env_version;
|
||||
}
|
||||
//Iterate over each version, adding bigger than current
|
||||
foreach ($env_versions as $env_version) {
|
||||
if (version_compare(normalize_version($current_version), $env_version, '<')) {
|
||||
$versions[$env_version] = $env_version;
|
||||
}
|
||||
}
|
||||
// Add 'upwards' to the last element
|
||||
$versions[$env_version] = $env_version.' '.get_string('upwards', 'admin');
|
||||
} else {
|
||||
$versions = array('error' => get_string('error'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Gather and show results
|
||||
$status = check_moodle_environment($version, $environment_results);
|
||||
|
||||
/// Print footer
|
||||
echo $OUTPUT->footer();
|
||||
// Get the results of the environment check.
|
||||
list($envstatus, $environment_results) = check_moodle_environment($version);
|
||||
|
||||
// Display the page.
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->environment_check_page($versions, $version, $envstatus, $environment_results);
|
||||
|
219
admin/index.php
219
admin/index.php
@ -26,7 +26,7 @@
|
||||
// Check that config.php exists, if not then call the install script
|
||||
if (!file_exists('../config.php')) {
|
||||
header('Location: ../install.php');
|
||||
die;
|
||||
die();
|
||||
}
|
||||
|
||||
// Check that PHP is of a sufficient version as soon as possible
|
||||
@ -35,7 +35,7 @@ if (version_compare(phpversion(), '5.3.2') < 0) {
|
||||
// do NOT localise - lang strings would not work here and we CAN NOT move it to later place
|
||||
echo "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).<br />";
|
||||
echo "Please upgrade your server software or install older Moodle version.";
|
||||
die;
|
||||
die();
|
||||
}
|
||||
|
||||
// make sure iconv is available and actually works
|
||||
@ -47,7 +47,7 @@ if (!function_exists('iconv')) {
|
||||
if (iconv('UTF-8', 'UTF-8//IGNORE', 'abc') !== 'abc') {
|
||||
// known to be broken in mid-2011 MAMP installations
|
||||
echo 'Broken iconv PHP extension detected, installation/upgrade can not continue.';
|
||||
die;
|
||||
die();
|
||||
}
|
||||
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
@ -103,6 +103,11 @@ if (!$version or !$release) {
|
||||
print_error('withoutversion', 'debug'); // without version, stop
|
||||
}
|
||||
|
||||
if (!isset($maturity)) {
|
||||
// Fallback for now. Should probably be removed in the future.
|
||||
$maturity = MATURITY_STABLE;
|
||||
}
|
||||
|
||||
// Turn off xmlstrictheaders during upgrade.
|
||||
$origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
|
||||
$CFG->xmlstrictheaders = false;
|
||||
@ -121,65 +126,43 @@ if (!core_tables_exist()) {
|
||||
|
||||
if (empty($agreelicense)) {
|
||||
$strlicense = get_string('license');
|
||||
|
||||
$PAGE->navbar->add($strlicense);
|
||||
$PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
|
||||
$PAGE->set_heading($strinstallation);
|
||||
$PAGE->set_cacheable(false);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
|
||||
echo $OUTPUT->heading(get_string('copyrightnotice'));
|
||||
$copyrightnotice = text_to_html(get_string('gpl3'));
|
||||
$copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
|
||||
echo $OUTPUT->box($copyrightnotice, 'copyrightnotice');
|
||||
echo '<br />';
|
||||
$continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
|
||||
echo $OUTPUT->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->install_licence_page();
|
||||
die();
|
||||
}
|
||||
if (empty($confirmrelease)) {
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
|
||||
$strcurrentrelease = get_string('currentrelease');
|
||||
|
||||
$PAGE->navbar->add($strcurrentrelease);
|
||||
$PAGE->set_title($strinstallation);
|
||||
$PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
|
||||
$PAGE->set_cacheable(false);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading("Moodle $release");
|
||||
|
||||
if (isset($maturity)) {
|
||||
// main version.php declares moodle code maturity
|
||||
if ($maturity < MATURITY_STABLE) {
|
||||
$maturitylevel = get_string('maturity'.$maturity, 'admin');
|
||||
echo $OUTPUT->box(
|
||||
$OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
|
||||
$OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))),
|
||||
'generalbox maturitywarning');
|
||||
}
|
||||
}
|
||||
|
||||
$releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
|
||||
$releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
|
||||
echo $OUTPUT->box($releasenoteslink, 'generalbox releasenoteslink');
|
||||
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
if (!check_moodle_environment(normalize_version($release), $environment_results, true, ENV_SELECT_RELEASE)) {
|
||||
print_upgrade_reload("index.php?agreelicense=1&lang=$CFG->lang");
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
|
||||
echo $OUTPUT->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release);
|
||||
die();
|
||||
}
|
||||
|
||||
//TODO: add a page with list of non-standard plugins here
|
||||
|
||||
$strdatabasesetup = get_string('databasesetup');
|
||||
upgrade_init_javascript();
|
||||
|
||||
$PAGE->navbar->add($strdatabasesetup);
|
||||
$PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
|
||||
$PAGE->set_heading($strinstallation);
|
||||
$PAGE->set_cacheable(false);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->header();
|
||||
|
||||
if (!$DB->setup_is_unicodedb()) {
|
||||
if (!$DB->change_db_encoding()) {
|
||||
@ -207,78 +190,45 @@ if ($version > $CFG->version) { // upgrade
|
||||
$PAGE->set_pagelayout('maintenance');
|
||||
$PAGE->set_popup_notification_allowed(false);
|
||||
|
||||
$a->oldversion = "$CFG->release ($CFG->version)";
|
||||
$a->newversion = "$release ($version)";
|
||||
$strdatabasechecking = get_string('databasechecking', '', $a);
|
||||
|
||||
if (empty($confirmupgrade)) {
|
||||
$a->oldversion = "$CFG->release ($CFG->version)";
|
||||
$a->newversion = "$release ($version)";
|
||||
$strdatabasechecking = get_string('databasechecking', '', $a);
|
||||
|
||||
$PAGE->set_title($stradministration);
|
||||
$PAGE->set_heading($strdatabasechecking);
|
||||
$PAGE->set_cacheable(false);
|
||||
echo $OUTPUT->header();
|
||||
if (isset($maturity)) {
|
||||
// main version.php declares moodle code maturity
|
||||
if ($maturity < MATURITY_STABLE) {
|
||||
$maturitylevel = get_string('maturity'.$maturity, 'admin');
|
||||
echo $OUTPUT->box(
|
||||
$OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
|
||||
$OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))),
|
||||
'generalbox maturitywarning');
|
||||
}
|
||||
}
|
||||
$continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
|
||||
$cancelurl = new moodle_url('index.php');
|
||||
echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueurl, $cancelurl);
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->upgrade_confirm_page($a->newversion, $maturity);
|
||||
die();
|
||||
|
||||
} else if (empty($confirmrelease)){
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE);
|
||||
$strcurrentrelease = get_string('currentrelease');
|
||||
|
||||
$PAGE->navbar->add($strcurrentrelease);
|
||||
$PAGE->set_title($strcurrentrelease);
|
||||
$PAGE->set_heading($strcurrentrelease);
|
||||
$PAGE->set_cacheable(false);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading("Moodle $release");
|
||||
$releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
|
||||
$releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
|
||||
echo $OUTPUT->box($releasenoteslink);
|
||||
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
|
||||
print_upgrade_reload('index.php?confirmupgrade=1');
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
|
||||
if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
|
||||
echo $OUTPUT->box_start('generalbox', 'notice');
|
||||
print_string('langpackwillbeupdated', 'admin');
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1');
|
||||
}
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->upgrade_environment_page($release, $envstatus, $environment_results);
|
||||
die();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
|
||||
} elseif (empty($confirmplugins)) {
|
||||
} else if (empty($confirmplugins)) {
|
||||
$strplugincheck = get_string('plugincheck');
|
||||
|
||||
$PAGE->navbar->add($strplugincheck);
|
||||
$PAGE->set_title($strplugincheck);
|
||||
$PAGE->set_heading($strplugincheck);
|
||||
$PAGE->set_cacheable(false);
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
$pluginman = plugin_manager::instance();
|
||||
|
||||
echo $output->header();
|
||||
echo $output->box_start('generalbox');
|
||||
echo $output->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
|
||||
echo $output->plugins_check($pluginman->get_plugins(), array('full' => $showallplugins));
|
||||
echo $output->box_end();
|
||||
print_upgrade_reload('index.php?confirmupgrade=1&confirmrelease=1');
|
||||
$button = new single_button(new moodle_url('index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get');
|
||||
$button->class = 'continuebutton';
|
||||
echo $output->render($button);
|
||||
echo $output->footer();
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $version, $showallplugins,
|
||||
new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)),
|
||||
new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)));
|
||||
die();
|
||||
|
||||
} else {
|
||||
@ -299,26 +249,19 @@ if (moodle_needs_upgrading()) {
|
||||
if (!$PAGE->headerprinted) {
|
||||
// means core upgrade or installation was not already done
|
||||
if (!$confirmplugins) {
|
||||
$strplugincheck = get_string('plugincheck');
|
||||
|
||||
$PAGE->set_pagelayout('maintenance');
|
||||
$PAGE->set_popup_notification_allowed(false);
|
||||
$strplugincheck = get_string('plugincheck');
|
||||
$PAGE->navbar->add($strplugincheck);
|
||||
$PAGE->set_title($strplugincheck);
|
||||
$PAGE->set_heading($strplugincheck);
|
||||
$PAGE->set_cacheable(false);
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
$pluginman = plugin_manager::instance();
|
||||
|
||||
echo $output->header();
|
||||
echo $output->box_start('generalbox');
|
||||
echo $output->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
|
||||
echo $output->plugins_check($pluginman->get_plugins(), array('full' => $showallplugins));
|
||||
echo $output->box_end();
|
||||
print_upgrade_reload('index.php');
|
||||
$button = new single_button(new moodle_url('index.php', array('confirmplugincheck'=>1)), get_string('upgradestart', 'admin'), 'get');
|
||||
$button->class = 'continuebutton';
|
||||
echo $output->render($button);
|
||||
echo $output->footer();
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $version, $showallplugins,
|
||||
new moodle_url('/admin/index.php'),
|
||||
new moodle_url('/admin/index.php', array('confirmplugincheck'=>1)));
|
||||
die();
|
||||
}
|
||||
}
|
||||
@ -413,58 +356,14 @@ if (any_new_admin_settings($adminroot)){
|
||||
// Everything should now be set up, and the user is an admin
|
||||
|
||||
// Print default admin page with notifications.
|
||||
admin_externalpage_setup('adminnotifications');
|
||||
echo $OUTPUT->header();
|
||||
$errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
|
||||
|
||||
// Unstable code warning
|
||||
if (isset($maturity)) {
|
||||
if ($maturity < MATURITY_STABLE) {
|
||||
$maturitylevel = get_string('maturity'.$maturity, 'admin');
|
||||
echo $OUTPUT->box(
|
||||
get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
|
||||
$OUTPUT->doc_link('admin/versions', get_string('morehelp')),
|
||||
'generalbox adminwarning maturityinfo');
|
||||
}
|
||||
}
|
||||
|
||||
if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
|
||||
echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
|
||||
} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
|
||||
echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror');
|
||||
|
||||
}
|
||||
|
||||
if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
|
||||
echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
|
||||
}
|
||||
|
||||
// If no recently cron run
|
||||
$lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
|
||||
if (time() - $lastcron > 3600 * 24) {
|
||||
$helpbutton = $OUTPUT->help_icon('cron', 'admin');
|
||||
echo $OUTPUT->box(get_string('cronwarning', 'admin').' '.$helpbutton, 'generalbox adminwarning');
|
||||
}
|
||||
|
||||
// diagnose DB, especially the sloppy MyISAM tables
|
||||
$diagnose = $DB->diagnose();
|
||||
if ($diagnose !== NULL) {
|
||||
echo $OUTPUT->box($diagnose, 'generalbox adminwarning');
|
||||
}
|
||||
|
||||
// Alert if we are currently in maintenance mode
|
||||
if (!empty($CFG->maintenance_enabled)) {
|
||||
echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
|
||||
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
|
||||
'<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
|
||||
'Copyright © 1999 onwards, Martin Dougiamas<br />'.
|
||||
'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
|
||||
'<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
|
||||
echo $OUTPUT->box($copyrighttext, 'copyright');
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
$cronoverdue = ($lastcron < time() - 3600 * 24);
|
||||
$dbproblems = $DB->diagnose();
|
||||
$maintenancemode = !empty($CFG->maintenance_enabled);
|
||||
|
||||
admin_externalpage_setup('adminnotifications');
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
|
||||
$cronoverdue, $dbproblems, $maintenancemode);
|
||||
|
@ -31,11 +31,4 @@ require_once($CFG->libdir . '/pluginlib.php');
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
admin_externalpage_setup('pluginsoverview');
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
$pluginman = plugin_manager::instance();
|
||||
|
||||
echo $output->header();
|
||||
echo $output->heading(get_string('pluginsoverview', 'core_admin'));
|
||||
echo $output->box_start('generalbox');
|
||||
echo $output->plugins_control_panel($pluginman->get_plugins());
|
||||
echo $output->box_end();
|
||||
echo $output->footer();
|
||||
echo $output->plugin_management_page(plugin_manager::instance());
|
||||
|
@ -32,6 +32,392 @@ require_once($CFG->libdir . '/pluginlib.php');
|
||||
*/
|
||||
class core_admin_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Display the 'Do you acknowledge the terms of the GPL' page. The first page
|
||||
* during install.
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function install_licence_page() {
|
||||
global $CFG;
|
||||
$output = '';
|
||||
|
||||
$copyrightnotice = text_to_html(get_string('gpl3'));
|
||||
$copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
|
||||
|
||||
$continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
|
||||
$output .= $this->heading(get_string('copyrightnotice'));
|
||||
$output .= $this->box($copyrightnotice, 'copyrightnotice');
|
||||
$output .= html_writer::empty_tag('br');
|
||||
$output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
|
||||
$output .= $this->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'environment check' page that is displayed during install.
|
||||
* @param int $maturity
|
||||
* @param boolean $envstatus final result of the check (true/false)
|
||||
* @param array $environment_results array of results gathered
|
||||
* @param string $release moodle release
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
|
||||
global $CFG;
|
||||
$output = '';
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->maturity_warning($maturity);
|
||||
$output .= $this->heading("Moodle $release");
|
||||
$output .= $this->release_notes_link();
|
||||
|
||||
$output .= $this->environment_check_table($envstatus, $environment_results);
|
||||
|
||||
if (!$envstatus) {
|
||||
$output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang)));
|
||||
} else {
|
||||
$output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
|
||||
$output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
|
||||
}
|
||||
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the 'You are about to upgrade Moodle' page. The first page
|
||||
* during upgrade.
|
||||
* @param string $strnewversion
|
||||
* @param int $maturity
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function upgrade_confirm_page($strnewversion, $maturity) {
|
||||
$output = '';
|
||||
|
||||
$continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
|
||||
$cancelurl = new moodle_url('index.php');
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->maturity_warning($maturity);
|
||||
$output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
|
||||
$output .= $this->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the environment page during the upgrade process.
|
||||
* @param string $release
|
||||
* @param boolean $envstatus final result of env check (true/false)
|
||||
* @param array $environment_results array of results gathered
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function upgrade_environment_page($release, $envstatus, $environment_results) {
|
||||
global $CFG;
|
||||
$output = '';
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading("Moodle $release");
|
||||
$output .= $this->release_notes_link();
|
||||
$output .= $this->environment_check_table($envstatus, $environment_results);
|
||||
|
||||
if (!$envstatus) {
|
||||
$output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
|
||||
|
||||
} else {
|
||||
$output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
|
||||
|
||||
if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
|
||||
$output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
|
||||
}
|
||||
|
||||
$output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
|
||||
}
|
||||
|
||||
$output .= $this->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the upgrade page that lists all the plugins that require attention.
|
||||
* @param plugin_manager $pluginman provides information about the plugins.
|
||||
* @param int $version the version of the Moodle code from version.php.
|
||||
* @param bool $showallplugins
|
||||
* @param moodle_url $reloadurl
|
||||
* @param moodle_url $continueurl
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function upgrade_plugin_check_page(plugin_manager $pluginman, $version, $showallplugins, $reloadurl, $continueurl) {
|
||||
$output = '';
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->box_start('generalbox');
|
||||
$output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
|
||||
$output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
|
||||
$output .= $this->box_end();
|
||||
$output .= $this->upgrade_reload($reloadurl);
|
||||
|
||||
if ($pluginman->all_plugins_ok($version)) {
|
||||
$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
|
||||
$button->class = 'continuebutton';
|
||||
$output .= $this->render($button);
|
||||
} else {
|
||||
$output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
|
||||
}
|
||||
|
||||
$output .= $this->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the admin notifications page.
|
||||
* @param int $maturity
|
||||
* @param bool $insecuredataroot warn dataroot is invalid
|
||||
* @param bool $errorsdisplayed warn invalid dispaly error setting
|
||||
* @param bool $cronoverdue warn cron not running
|
||||
* @param bool $dbproblems warn db has problems
|
||||
* @param bool $maintenancemode warn in maintenance mode
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
|
||||
$cronoverdue, $dbproblems, $maintenancemode) {
|
||||
$output = '';
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->maturity_info($maturity);
|
||||
$output .= $this->insecure_dataroot_warning($insecuredataroot);
|
||||
$output .= $this->display_errors_warning($errorsdisplayed);
|
||||
$output .= $this->cron_overdue_warning($errorsdisplayed);
|
||||
$output .= $this->db_problems($dbproblems);
|
||||
$output .= $this->maintenance_mode_warning($maintenancemode);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
|
||||
$output .= $this->moodle_copyright();
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$output .= $this->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the plugin management page (admin/plugins.php).
|
||||
* @param plugin_manager $pluginman
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function plugin_management_page(plugin_manager $pluginman) {
|
||||
$output = '';
|
||||
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
|
||||
$output .= $this->box_start('generalbox');
|
||||
$output .= $this->plugins_control_panel($pluginman);
|
||||
$output .= $this->box_end();
|
||||
$output .= $this->footer();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the plugin management page (admin/environment.php).
|
||||
* @param array $versions
|
||||
* @param string $version
|
||||
* @param boolean $envstatus final result of env check (true/false)
|
||||
* @param array $environment_results array of results gathered
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function environment_check_page($versions, $version, $envstatus, $environment_results) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
|
||||
// Print the component download link
|
||||
$output .= html_writer::tag('div', html_writer::link(
|
||||
new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
|
||||
get_string('updatecomponent', 'admin')),
|
||||
array('class' => 'reportlink'));
|
||||
|
||||
// Heading.
|
||||
$output .= $this->heading(get_string('environment', 'admin'));
|
||||
|
||||
// Box with info and a menu to choose the version.
|
||||
$output .= $this->box_start();
|
||||
$output .= html_writer::tag('div', get_string('adminhelpenvironment'));
|
||||
$select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
|
||||
$select->label = get_string('moodleversion');
|
||||
$output .= $this->render($select);
|
||||
$output .= $this->box_end();
|
||||
|
||||
// The results
|
||||
$output .= $this->environment_check_table($envstatus, $environment_results);
|
||||
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a warning message, of the type that appears on the admin notifications page.
|
||||
* @param string $message the message to display.
|
||||
* @param string $type type class
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function warning($message, $type = 'warning') {
|
||||
return $this->box($message, 'generalbox admin' . $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if dataroot is insecure.
|
||||
* @param bool $insecuredataroot
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function insecure_dataroot_warning($insecuredataroot) {
|
||||
global $CFG;
|
||||
|
||||
if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
|
||||
return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
|
||||
|
||||
} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
|
||||
return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
|
||||
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if dataroot is insecure.
|
||||
* @param bool $errorsdisplayed
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function display_errors_warning($errorsdisplayed) {
|
||||
if (!$errorsdisplayed) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->warning(get_string('displayerrorswarning', 'admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if cron has not been run recently.
|
||||
* @param bool $cronoverdue
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function cron_overdue_warning($cronoverdue) {
|
||||
if (!$cronoverdue) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->warning(get_string('cronwarning', 'admin') . ' ' .
|
||||
$this->help_icon('cron', 'admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if there are any problems with the DB set-up.
|
||||
* @param bool $dbproblems
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function db_problems($dbproblems) {
|
||||
if (!$dbproblems) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->warning($dbproblems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an appropriate message if the site in in maintenance mode.
|
||||
* @param bool $maintenancemode
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function maintenance_mode_warning($maintenancemode) {
|
||||
if (!$maintenancemode) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->warning(get_string('sitemaintenancewarning2', 'admin',
|
||||
new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a warning about installing development code if necesary.
|
||||
* @param int $maturity
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function maturity_warning($maturity) {
|
||||
if ($maturity == MATURITY_STABLE) {
|
||||
return ''; // No worries.
|
||||
}
|
||||
|
||||
$maturitylevel = get_string('maturity' . $maturity, 'admin');
|
||||
return $this->box(
|
||||
$this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
|
||||
$this->container($this->doc_link('admin/versions', get_string('morehelp'))),
|
||||
'generalbox maturitywarning');
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the copyright notice.
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function moodle_copyright() {
|
||||
global $CFG;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
|
||||
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
|
||||
'<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
|
||||
'Copyright © 1999 onwards, Martin Dougiamas<br />'.
|
||||
'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
|
||||
'<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return $this->box($copyrighttext, 'copyright');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a warning about installing development code if necesary.
|
||||
* @param int $maturity
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function maturity_info($maturity) {
|
||||
if ($maturity == MATURITY_STABLE) {
|
||||
return ''; // No worries.
|
||||
}
|
||||
|
||||
$maturitylevel = get_string('maturity' . $maturity, 'admin');
|
||||
return $this->box(
|
||||
get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
|
||||
$this->doc_link('admin/versions', get_string('morehelp')),
|
||||
'generalbox adminwarning maturityinfo');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a link to the release notes.
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
protected function release_notes_link() {
|
||||
$releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
|
||||
$releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
|
||||
return $this->box($releasenoteslink, 'generalbox releasenoteslink');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the reload link that appears on several upgrade/install pages.
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
function upgrade_reload($url) {
|
||||
return html_writer::empty_tag('br') .
|
||||
html_writer::tag('div',
|
||||
html_writer::link($url, $this->pix_icon('i/reload', '') .
|
||||
get_string('reload'), array('title' => get_string('reload'))),
|
||||
array('class' => 'continuebutton')) . html_writer::empty_tag('br');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all known plugins and information about their installation or upgrade
|
||||
*
|
||||
@ -39,11 +425,13 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
* options support:
|
||||
* (bool)full = false: whether to display up-to-date plugins, too
|
||||
*
|
||||
* @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
|
||||
* @param plugin_manager $pluginman provides information about the plugins.
|
||||
* @param int $version the version of the Moodle code from version.php.
|
||||
* @param array $options rendering options
|
||||
* @return string HTML code
|
||||
*/
|
||||
public function plugins_check(array $plugininfo, array $options = null) {
|
||||
public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
|
||||
$plugininfo = $pluginman->get_plugins();
|
||||
|
||||
if (empty($plugininfo)) {
|
||||
return '';
|
||||
@ -55,8 +443,6 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
);
|
||||
}
|
||||
|
||||
$pluginman = plugin_manager::instance();
|
||||
|
||||
$table = new html_table();
|
||||
$table->id = 'plugins-check';
|
||||
$table->head = array(
|
||||
@ -65,10 +451,11 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
get_string('source', 'core_plugin'),
|
||||
get_string('versiondb', 'core_plugin'),
|
||||
get_string('versiondisk', 'core_plugin'),
|
||||
get_string('requires', 'core_plugin'),
|
||||
get_string('status', 'core_plugin'),
|
||||
);
|
||||
$table->colclasses = array(
|
||||
'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'status',
|
||||
'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
|
||||
);
|
||||
$table->data = array();
|
||||
|
||||
@ -126,7 +513,13 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
|
||||
$status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
|
||||
|
||||
if ($isstandard and in_array($statuscode, array(plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE))) {
|
||||
$requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
|
||||
|
||||
$statusisboring = in_array($statuscode, array(
|
||||
plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
|
||||
$dependenciesok = $pluginman->are_dependencies_satisfied(
|
||||
$plugin->get_other_required_plugins());
|
||||
if ($isstandard and $statusisboring and $dependenciesok) {
|
||||
if (empty($options['full'])) {
|
||||
continue;
|
||||
}
|
||||
@ -134,7 +527,8 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
$numofhighlighted[$type]++;
|
||||
}
|
||||
|
||||
$row->cells = array($displayname, $rootdir, $source, $versiondb, $versiondisk, $status);
|
||||
$row->cells = array($displayname, $rootdir, $source,
|
||||
$versiondb, $versiondisk, $requires, $status);
|
||||
$plugintyperows[] = $row;
|
||||
}
|
||||
|
||||
@ -176,22 +570,76 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the information that needs to go in the 'Requires' column.
|
||||
* @param plugin_information $plugin the plugin we are rendering the row for.
|
||||
* @param plugin_manager $pluginman provides data on all the plugins.
|
||||
* @param string $version
|
||||
* @return string HTML code
|
||||
*/
|
||||
protected function required_column(plugin_information $plugin, plugin_manager $pluginman, $version) {
|
||||
$requires = array();
|
||||
|
||||
if (!empty($plugin->versionrequires)) {
|
||||
if ($plugin->versionrequires <= $version) {
|
||||
$class = 'requires-ok';
|
||||
} else {
|
||||
$class = 'requires-failed';
|
||||
}
|
||||
$requires[] = html_writer::tag('li',
|
||||
get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
|
||||
array('class' => $class));
|
||||
}
|
||||
|
||||
foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
|
||||
$ok = true;
|
||||
$otherplugin = $pluginman->get_plugin_info($component);
|
||||
|
||||
if (is_null($otherplugin)) {
|
||||
$ok = false;
|
||||
}
|
||||
if ($requiredversion != ANY_VERSION and $otherplugin->versiondb < $requiredversion) {
|
||||
$ok = false;
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
$class = 'requires-ok';
|
||||
} else {
|
||||
$class = 'requires-failed';
|
||||
}
|
||||
|
||||
if ($requiredversion != ANY_VERSION) {
|
||||
$str = 'otherpluginversion';
|
||||
} else {
|
||||
$str = 'otherplugin';
|
||||
}
|
||||
$requires[] = html_writer::tag('li',
|
||||
get_string($str, 'core_plugin',
|
||||
array('component' => $component, 'version' => $requiredversion)),
|
||||
array('class' => $class));
|
||||
}
|
||||
|
||||
if (!$requires) {
|
||||
return '';
|
||||
}
|
||||
return html_writer::tag('ul', implode("\n", $requires));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all known plugins and links to manage them
|
||||
*
|
||||
* This default implementation renders all plugins into one big table.
|
||||
*
|
||||
* @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
|
||||
* @param plugin_manager $pluginman provides information about the plugins.
|
||||
* @return string HTML code
|
||||
*/
|
||||
public function plugins_control_panel(array $plugininfo) {
|
||||
public function plugins_control_panel(plugin_manager $pluginman) {
|
||||
$plugininfo = $pluginman->get_plugins();
|
||||
|
||||
if (empty($plugininfo)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pluginman = plugin_manager::instance();
|
||||
|
||||
$table = new html_table();
|
||||
$table->id = 'plugins-control-panel';
|
||||
$table->head = array(
|
||||
@ -293,4 +741,183 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
|
||||
return html_writer::table($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will render one beautiful table with all the environmental
|
||||
* configuration and how it suits Moodle needs.
|
||||
*
|
||||
* @param boolean $result final result of the check (true/false)
|
||||
* @param array $environment_results array of results gathered
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function environment_check_table($result, $environment_results) {
|
||||
global $CFG;
|
||||
|
||||
// Table headers
|
||||
$servertable = new html_table();//table for server checks
|
||||
$servertable->head = array(
|
||||
get_string('name'),
|
||||
get_string('info'),
|
||||
get_string('report'),
|
||||
get_string('status'),
|
||||
);
|
||||
$servertable->align = array('center', 'center', 'left', 'center');
|
||||
$servertable->wrap = array('nowrap', '', '', 'nowrap');
|
||||
$servertable->size = array('10', 10, '100%', '10');
|
||||
$servertable->attributes['class'] = 'environmenttable generaltable';
|
||||
|
||||
$serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
|
||||
|
||||
$othertable = new html_table();//table for custom checks
|
||||
$othertable->head = array(
|
||||
get_string('info'),
|
||||
get_string('report'),
|
||||
get_string('status'),
|
||||
);
|
||||
$othertable->align = array('center', 'left', 'center');
|
||||
$othertable->wrap = array('', '', 'nowrap');
|
||||
$othertable->size = array(10, '100%', '10');
|
||||
$othertable->attributes['class'] = 'environmenttable generaltable';
|
||||
|
||||
$otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
|
||||
|
||||
// Iterate over each environment_result
|
||||
$continue = true;
|
||||
foreach ($environment_results as $environment_result) {
|
||||
$errorline = false;
|
||||
$warningline = false;
|
||||
$stringtouse = '';
|
||||
if ($continue) {
|
||||
$type = $environment_result->getPart();
|
||||
$info = $environment_result->getInfo();
|
||||
$status = $environment_result->getStatus();
|
||||
$error_code = $environment_result->getErrorCode();
|
||||
// Process Report field
|
||||
$rec = new stdClass();
|
||||
// Something has gone wrong at parsing time
|
||||
if ($error_code) {
|
||||
$stringtouse = 'environmentxmlerror';
|
||||
$rec->error_code = $error_code;
|
||||
$status = get_string('error');
|
||||
$errorline = true;
|
||||
$continue = false;
|
||||
}
|
||||
|
||||
if ($continue) {
|
||||
if ($rec->needed = $environment_result->getNeededVersion()) {
|
||||
// We are comparing versions
|
||||
$rec->current = $environment_result->getCurrentVersion();
|
||||
if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentrequireversion';
|
||||
} else {
|
||||
$stringtouse = 'environmentrecommendversion';
|
||||
}
|
||||
|
||||
} else if ($environment_result->getPart() == 'custom_check') {
|
||||
// We are checking installed & enabled things
|
||||
if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentrequirecustomcheck';
|
||||
} else {
|
||||
$stringtouse = 'environmentrecommendcustomcheck';
|
||||
}
|
||||
|
||||
} else if ($environment_result->getPart() == 'php_setting') {
|
||||
if ($status) {
|
||||
$stringtouse = 'environmentsettingok';
|
||||
} else if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentmustfixsetting';
|
||||
} else {
|
||||
$stringtouse = 'environmentshouldfixsetting';
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentrequireinstall';
|
||||
} else {
|
||||
$stringtouse = 'environmentrecommendinstall';
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the status value
|
||||
if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
|
||||
$status = get_string('bypassed');
|
||||
$warningline = true;
|
||||
} else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
|
||||
$status = get_string('restricted');
|
||||
$errorline = true;
|
||||
} else {
|
||||
if ($status) { //Handle ok result (ok)
|
||||
$status = get_string('ok');
|
||||
} else {
|
||||
if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
|
||||
$status = get_string('check');
|
||||
$warningline = true;
|
||||
} else { //Handle error result (error)
|
||||
$status = get_string('check');
|
||||
$errorline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build the text
|
||||
$linkparts = array();
|
||||
$linkparts[] = 'admin/environment';
|
||||
$linkparts[] = $type;
|
||||
if (!empty($info)){
|
||||
$linkparts[] = $info;
|
||||
}
|
||||
if (empty($CFG->docroot)) {
|
||||
$report = get_string($stringtouse, 'admin', $rec);
|
||||
} else {
|
||||
$report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
|
||||
}
|
||||
|
||||
// Format error or warning line
|
||||
if ($errorline || $warningline) {
|
||||
$messagetype = $errorline? 'error':'warn';
|
||||
} else {
|
||||
$messagetype = 'ok';
|
||||
}
|
||||
$status = '<span class="'.$messagetype.'">'.$status.'</span>';
|
||||
// Here we'll store all the feedback found
|
||||
$feedbacktext = '';
|
||||
// Append the feedback if there is some
|
||||
$feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
|
||||
//Append the bypass if there is some
|
||||
$feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
|
||||
//Append the restrict if there is some
|
||||
$feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
|
||||
|
||||
$report .= $feedbacktext;
|
||||
|
||||
// Add the row to the table
|
||||
if ($environment_result->getPart() == 'custom_check'){
|
||||
$otherdata[$messagetype][] = array ($info, $report, $status);
|
||||
} else {
|
||||
$serverdata[$messagetype][] = array ($type, $info, $report, $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//put errors first in
|
||||
$servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
|
||||
$othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
|
||||
|
||||
// Print table
|
||||
$output = '';
|
||||
$output .= $this->heading(get_string('serverchecks', 'admin'));
|
||||
$output .= html_writer::table($servertable);
|
||||
if (count($othertable->data)){
|
||||
$output .= $this->heading(get_string('customcheck', 'admin'));
|
||||
$output .= html_writer::table($othertable);
|
||||
}
|
||||
|
||||
// Finally, if any error has happened, print the summary box
|
||||
if (!$result) {
|
||||
$output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$params->displaysize = display_size($defaultuserquota);
|
||||
$temp->add(new admin_setting_configtext('userquota', get_string('userquota', 'admin'), get_string('configuserquota', 'admin', $params), $defaultuserquota));
|
||||
|
||||
$item = new admin_setting_configcheckbox('enablehtmlpurifier', get_string('enablehtmlpurifier', 'admin'), get_string('configenablehtmlpurifier', 'admin'), 1);
|
||||
$item->set_updatedcallback('reset_text_filters_cache');
|
||||
$temp->add($item);
|
||||
$temp->add(new admin_setting_configcheckbox('allowobjectembed', get_string('allowobjectembed', 'admin'), get_string('configallowobjectembed', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('enabletrusttext', get_string('enabletrusttext', 'admin'), get_string('configenabletrusttext', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configselect('maxeditingtime', get_string('maxeditingtime','admin'), get_string('configmaxeditingtime','admin'), 1800,
|
||||
|
@ -62,11 +62,10 @@ class block_online_users extends block_base {
|
||||
GROUP BY $userfields
|
||||
ORDER BY lastaccess DESC ";
|
||||
|
||||
$csql = "SELECT COUNT(u.id), u.id
|
||||
$csql = "SELECT COUNT(u.id)
|
||||
FROM {user} u $groupmembers
|
||||
WHERE u.lastaccess > $timefrom
|
||||
$groupselect
|
||||
GROUP BY u.id";
|
||||
$groupselect";
|
||||
|
||||
} else {
|
||||
// Course level - show only enrolled users for now
|
||||
@ -85,14 +84,13 @@ class block_online_users extends block_base {
|
||||
GROUP BY $userfields
|
||||
ORDER BY lastaccess DESC";
|
||||
|
||||
$csql = "SELECT u.id
|
||||
$csql = "SELECT COUNT(u.id)
|
||||
FROM {user_lastaccess} ul $groupmembers, {user} u
|
||||
JOIN ($esqljoin) euj ON euj.id = u.id
|
||||
WHERE ul.timeaccess > $timefrom
|
||||
AND u.id = ul.userid
|
||||
AND ul.courseid = :courseid
|
||||
$groupselect
|
||||
GROUP BY u.id";
|
||||
$groupselect";
|
||||
|
||||
$params['courseid'] = $this->page->course->id;
|
||||
}
|
||||
|
@ -16,17 +16,24 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package moodlecore
|
||||
* @package moodlecore
|
||||
* @subpackage backup-moodle2
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Specialised restore task for the quiz_results block
|
||||
* (using execute_after_tasks for recoding of target quiz)
|
||||
*
|
||||
* TODO: Finish phpdocs
|
||||
*
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class restore_quiz_results_block_task extends restore_block_task {
|
||||
|
||||
|
@ -1,5 +1,45 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Classes to enforce the various access rules that can apply to a quiz.
|
||||
*
|
||||
* @package block
|
||||
* @subpackage quiz_results
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Block quiz_results class definition.
|
||||
*
|
||||
* This block can be added to a course page or a quiz page to display of list of
|
||||
* the best/worst students/groups in a particular quiz.
|
||||
*
|
||||
* @package block
|
||||
* @subpackage quiz_results
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define('B_QUIZRESULTS_NAME_FORMAT_FULL', 1);
|
||||
define('B_QUIZRESULTS_NAME_FORMAT_ID', 2);
|
||||
define('B_QUIZRESULTS_NAME_FORMAT_ANON', 3);
|
||||
|
@ -16,13 +16,16 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Form for editing Quiz results block instances.
|
||||
* Defines the form for editing Quiz results block instances.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Form for editing Quiz results block instances.
|
||||
*
|
||||
|
@ -18,9 +18,10 @@
|
||||
/**
|
||||
* Strings for component 'block_quiz_results', language 'en', branch 'MOODLE_20_STABLE'
|
||||
*
|
||||
* @package block_quiz_results
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package block
|
||||
* @subpackage quiz_results
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['bestgrade'] = 'The highest grade:';
|
||||
|
@ -3,4 +3,4 @@
|
||||
.block_quiz_results table.grades {text-align: left;width: 100%;}
|
||||
.block_quiz_results table.grades .number,
|
||||
.block_quiz_results table.grades .grade {text-align: right;width: 10%;}
|
||||
.block_quiz_results table.grades caption {margin: 1em 0px 0px 0px;border-bottom-width: 1px;border-bottom-style: solid;font-weight: bold;}
|
||||
.block_quiz_results table.grades caption {margin: 1em 0px 0px 0px;border-bottom-width: 1px;border-bottom-style: solid;font-weight: bold;}
|
||||
|
@ -15,4 +15,19 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
$plugin->version = 2007101509;
|
||||
/**
|
||||
* Version information for the block_quiz_results plugin.
|
||||
*
|
||||
* @package block
|
||||
* @subpackage quiz_results
|
||||
* @copyright 2011 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$plugin->version = 2011100300;
|
||||
$plugin->requires = 2011091600;
|
||||
$plugin->component = 'block_quiz_results';
|
||||
|
@ -28,7 +28,10 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
|
||||
class moodle_course_external extends external_api {
|
||||
/**
|
||||
* Course functions
|
||||
*/
|
||||
class core_course_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
@ -363,4 +366,68 @@ class moodle_course_external extends external_api {
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated course functions
|
||||
* @deprecated since Moodle 2.2 please use core_course_external instead
|
||||
*/
|
||||
class moodle_course_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_course_external::get_courses_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_courses_parameters() {
|
||||
return core_course_external::get_courses_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get courses
|
||||
* @param array $options
|
||||
* @deprecated since Moodle 2.2 please use core_course_external::get_courses instead
|
||||
* @return array
|
||||
*/
|
||||
public static function get_courses($options) {
|
||||
return core_course_external::get_courses($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_course_external::get_courses_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_courses_returns() {
|
||||
return core_course_external::get_courses_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_course_external::create_courses_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function create_courses_parameters() {
|
||||
return core_course_external::create_courses_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create courses
|
||||
* @deprecated since Moodle 2.2 please use core_course_external::create_courses instead
|
||||
* @param array $courses
|
||||
* @return array courses (id and shortname only)
|
||||
*/
|
||||
public static function create_courses($courses) {
|
||||
return core_course_external::create_courses($courses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_course_external::create_courses_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function create_courses_returns() {
|
||||
return core_course_external::create_courses_returns();
|
||||
}
|
||||
|
||||
}
|
@ -2454,61 +2454,48 @@ function print_course($course, $highlightterms = '') {
|
||||
if (!empty($CFG->coursecontact)) {
|
||||
$managerroles = explode(',', $CFG->coursecontact);
|
||||
$namesarray = array();
|
||||
if (isset($course->managers)) {
|
||||
if (count($course->managers)) {
|
||||
$rusers = $course->managers;
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
$rusers = array();
|
||||
|
||||
/// Rename some of the role names if needed
|
||||
if (isset($context)) {
|
||||
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
||||
}
|
||||
|
||||
// keep a note of users displayed to eliminate duplicates
|
||||
$usersshown = array();
|
||||
foreach ($rusers as $ra) {
|
||||
|
||||
// if we've already displayed user don't again
|
||||
if (in_array($ra->user->id,$usersshown)) {
|
||||
continue;
|
||||
}
|
||||
$usersshown[] = $ra->user->id;
|
||||
|
||||
$fullname = fullname($ra->user, $canviewfullnames);
|
||||
|
||||
if (isset($aliasnames[$ra->roleid])) {
|
||||
$ra->rolename = $aliasnames[$ra->roleid]->name;
|
||||
}
|
||||
|
||||
$namesarray[] = format_string($ra->rolename).': '.
|
||||
html_writer::link(new moodle_url('/user/view.php', array('id'=>$ra->user->id, 'course'=>SITEID)), $fullname);
|
||||
}
|
||||
}
|
||||
if (!isset($course->managers)) {
|
||||
$rusers = get_role_users($managerroles, $context, true,
|
||||
'ra.id AS raid, u.id, u.username, u.firstname, u.lastname,
|
||||
r.name AS rolename, r.sortorder, r.id AS roleid',
|
||||
'r.sortorder ASC, u.lastname ASC');
|
||||
} else {
|
||||
$rusers = get_role_users($managerroles, $context,
|
||||
true, '', 'r.sortorder ASC, u.lastname ASC');
|
||||
if (is_array($rusers) && count($rusers)) {
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
// use the managers array if we have it for perf reasosn
|
||||
// populate the datastructure like output of get_role_users();
|
||||
foreach ($course->managers as $manager) {
|
||||
$u = new stdClass();
|
||||
$u = $manager->user;
|
||||
$u->roleid = $manager->roleid;
|
||||
$u->rolename = $manager->rolename;
|
||||
|
||||
/// Rename some of the role names if needed
|
||||
if (isset($context)) {
|
||||
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
||||
}
|
||||
|
||||
foreach ($rusers as $teacher) {
|
||||
$fullname = fullname($teacher, $canviewfullnames);
|
||||
|
||||
/// Apply role names
|
||||
if (isset($aliasnames[$teacher->roleid])) {
|
||||
$teacher->rolename = $aliasnames[$teacher->roleid]->name;
|
||||
}
|
||||
|
||||
$namesarray[] = format_string($teacher->rolename).': '.
|
||||
html_writer::link(new moodle_url('/user/view.php', array('id'=>$teacher->id, 'course'=>SITEID)), $fullname);
|
||||
}
|
||||
$rusers[] = $u;
|
||||
}
|
||||
}
|
||||
|
||||
/// Rename some of the role names if needed
|
||||
if (isset($context)) {
|
||||
$aliasnames = $DB->get_records('role_names', array('contextid'=>$context->id), '', 'roleid,contextid,name');
|
||||
}
|
||||
|
||||
$namesarray = array();
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
foreach ($rusers as $ra) {
|
||||
if (isset($namesarray[$ra->id])) {
|
||||
// only display a user once with the higest sortorder role
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($aliasnames[$ra->roleid])) {
|
||||
$ra->rolename = $aliasnames[$ra->roleid]->name;
|
||||
}
|
||||
|
||||
$fullname = fullname($ra, $canviewfullnames);
|
||||
$namesarray[$ra->id] = format_string($ra->rolename).': '.
|
||||
html_writer::link(new moodle_url('/user/view.php', array('id'=>$ra->id, 'course'=>SITEID)), $fullname);
|
||||
}
|
||||
|
||||
if (!empty($namesarray)) {
|
||||
echo html_writer::start_tag('ul', array('class'=>'teachers'));
|
||||
foreach ($namesarray as $name) {
|
||||
|
@ -170,11 +170,11 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
if ($e = $DB->get_record('user_enrolments', array('userid'=>$user->id, 'enrolid'=>$instance->id))) {
|
||||
// reenable enrolment when previously disable enrolment refreshed
|
||||
if ($e->status == ENROL_USER_SUSPENDED) {
|
||||
$DB->set_field('user_enrolments', 'status', ENROL_USER_ACTIVE, array('enrolid'=>$instance->id, 'userid'=>$user->id));
|
||||
$this->update_user_enrol($instance, $user->id, ENROL_USER_ACTIVE);
|
||||
}
|
||||
} else {
|
||||
$roleid = reset($roles);
|
||||
$this->enrol_user($instance, $user->id, $roleid);
|
||||
$this->enrol_user($instance, $user->id, $roleid, 0, 0, ENROL_USER_ACTIVE);
|
||||
}
|
||||
|
||||
if (!$context = get_context_instance(CONTEXT_COURSE, $instance->courseid)) {
|
||||
@ -231,7 +231,7 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
// disable
|
||||
if ($instance->ustatus != ENROL_USER_SUSPENDED) {
|
||||
$DB->set_field('user_enrolments', 'status', ENROL_USER_SUSPENDED, array('enrolid'=>$instance->id, 'userid'=>$user->id));
|
||||
$this->update_user_enrol($instance, $user->id, ENROL_USER_SUSPENDED);
|
||||
}
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
role_unassign_all(array('contextid'=>$context->id, 'userid'=>$user->id, 'component'=>'enrol_database', 'itemid'=>$instance->id));
|
||||
@ -455,7 +455,7 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
foreach ($requested_roles as $userid=>$userroles) {
|
||||
foreach ($userroles as $roleid) {
|
||||
if (empty($current_roles[$userid])) {
|
||||
$this->enrol_user($instance, $userid, $roleid);
|
||||
$this->enrol_user($instance, $userid, $roleid, 0, 0, ENROL_USER_ACTIVE);
|
||||
$current_roles[$userid][$roleid] = $roleid;
|
||||
$current_status[$userid] = ENROL_USER_ACTIVE;
|
||||
if ($verbose) {
|
||||
@ -488,7 +488,7 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
|
||||
// reenable enrolment when previously disable enrolment refreshed
|
||||
if ($current_status[$userid] == ENROL_USER_SUSPENDED) {
|
||||
$DB->set_field('user_enrolments', 'status', ENROL_USER_ACTIVE, array('enrolid'=>$instance->id, 'userid'=>$userid));
|
||||
$this->update_user_enrol($instance, $userid, ENROL_USER_ACTIVE);
|
||||
if ($verbose) {
|
||||
mtrace(" unsuspending: $userid ==> $course->shortname");
|
||||
}
|
||||
@ -520,7 +520,7 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
continue;
|
||||
}
|
||||
if ($status != ENROL_USER_SUSPENDED) {
|
||||
$DB->set_field('user_enrolments', 'status', ENROL_USER_SUSPENDED, array('enrolid'=>$instance->id, 'userid'=>$userid));
|
||||
$this->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
|
||||
if ($verbose) {
|
||||
mtrace(" suspending: $userid ==> $course->shortname");
|
||||
}
|
||||
|
@ -31,12 +31,415 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
|
||||
/**
|
||||
* Enrol functions
|
||||
*/
|
||||
class core_enrol_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_users_courses_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'userid' => new external_value(PARAM_INT, 'user id'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of courses user is enrolled in (only active enrolments are returned).
|
||||
*
|
||||
* Please note the current user must be able to access the course, otherwise the course is not included.
|
||||
*
|
||||
* @param int $userid
|
||||
* @return array of courses
|
||||
*/
|
||||
public static function get_users_courses($userid) {
|
||||
global $USER;
|
||||
|
||||
// Do basic automatic PARAM checks on incoming data, using params description
|
||||
// If any problems are found then exceptions are thrown with helpful error messages
|
||||
$params = self::validate_parameters(self::get_users_courses_parameters(), array('userid'=>$userid));
|
||||
|
||||
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
|
||||
$result = array();
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
try {
|
||||
self::validate_context($context);
|
||||
} catch (Exception $e) {
|
||||
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
|
||||
continue;
|
||||
}
|
||||
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
|
||||
// we need capability to view participants
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = array('id'=>$course->id, 'shortname'=>$course->shortname, 'fullname'=>$course->fullname, 'idnumber'=>$course->idnumber,'visible'=>$course->visible);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_users_courses_returns() {
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'id of course'),
|
||||
'shortname' => new external_value(PARAM_RAW, 'short name of course'),
|
||||
'fullname' => new external_value(PARAM_RAW, 'long name of course'),
|
||||
'idnumber' => new external_value(PARAM_RAW, 'id number of course'),
|
||||
'visible' => new external_value(PARAM_INT, '1 means visible, 0 means hidden course'),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_enrolled_users_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'courseid' => new external_value(PARAM_INT, 'course id'),
|
||||
'options' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'name' => new external_value(PARAM_ALPHANUMEXT, 'option name'),
|
||||
'value' => new external_value(PARAM_RAW, 'option value')
|
||||
)
|
||||
), 'method options'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course participants details
|
||||
* @param int $courseid course id
|
||||
* @param array $options options {
|
||||
* 'name' => option name
|
||||
* 'value' => option value
|
||||
* }
|
||||
* @return array An array of users
|
||||
*/
|
||||
public static function get_enrolled_users($courseid, $options) {
|
||||
global $CFG, $USER, $DB;
|
||||
require_once($CFG->dirroot . "/user/lib.php");
|
||||
|
||||
$params = self::validate_parameters(
|
||||
self::get_users_by_course_id_parameters(),
|
||||
array(
|
||||
'courseid'=>$courseid,
|
||||
'options'=>$options
|
||||
)
|
||||
);
|
||||
$withcapability = '';
|
||||
$groupid = 0;
|
||||
$onlyactive = false;
|
||||
foreach ($options as $option) {
|
||||
switch ($option['name']) {
|
||||
case 'withcapability':
|
||||
$withcapability = $option['value'];
|
||||
break;
|
||||
case 'groupid':
|
||||
$groupid = (int)$option['value'];
|
||||
break;
|
||||
case 'onlyactive':
|
||||
$onlyactive = !empty($option['value']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// to overwrite this parameter, you need role:review capability
|
||||
if ($withcapability) {
|
||||
require_capability('moodle/role:review', $coursecontext);
|
||||
}
|
||||
// need accessallgroups capability if you want to overwrite this option
|
||||
if (!empty($groupid) && groups_is_member($groupid)) {
|
||||
require_capability('moodle/site:accessallgroups', $context);
|
||||
}
|
||||
// to overwrite this option, you need course:enrolereview permission
|
||||
if ($onlyactive) {
|
||||
require_capability('moodle/course:enrolreview', $coursecontext);
|
||||
}
|
||||
|
||||
list($coursectxselect, $coursectxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
||||
$coursesql = "SELECT c.* $coursectxselect
|
||||
FROM {course} c $coursectxjoin
|
||||
WHERE c.id = $courseid";
|
||||
$course = $DB->get_record_sql($coursesql);
|
||||
context_instance_preload($course);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $params['courseid']);
|
||||
if ($courseid == SITEID) {
|
||||
$context = get_system_context();
|
||||
} else {
|
||||
$context = $coursecontext;
|
||||
}
|
||||
try {
|
||||
self::validate_context($context);
|
||||
} catch (Exception $e) {
|
||||
$exceptionparam = new stdClass();
|
||||
$exceptionparam->message = $e->getMessage();
|
||||
$exceptionparam->courseid = $params['courseid'];
|
||||
throw new moodle_exception(get_string('errorcoursecontextnotvalid' , 'webservice', $exceptionparam));
|
||||
}
|
||||
|
||||
list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
|
||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
|
||||
$records = $DB->get_records_sql($enrolledsql, $enrolledparams);
|
||||
$sqlparams['courseid'] = $courseid;
|
||||
$sql = "SELECT u.* $ctxselect
|
||||
FROM {user} u $ctxjoin
|
||||
WHERE u.id IN ($enrolledsql)
|
||||
ORDER BY u.id ASC";
|
||||
$enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams);
|
||||
$users = array();
|
||||
foreach ($enrolledusers as $user) {
|
||||
if (!empty($user->deleted)) {
|
||||
continue;
|
||||
}
|
||||
context_instance_preload($user);
|
||||
if ($userdetails = user_get_user_details($user, $course)) {
|
||||
$users[] = $userdetails;
|
||||
}
|
||||
}
|
||||
$enrolledusers->close();
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_enrolled_users_returns() {
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_NUMBER, 'ID of the user'),
|
||||
'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL),
|
||||
'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL),
|
||||
'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
|
||||
'fullname' => new external_value(PARAM_NOTAGS, 'The fullname of the user'),
|
||||
'email' => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL),
|
||||
'address' => new external_value(PARAM_MULTILANG, 'Postal address', VALUE_OPTIONAL),
|
||||
'phone1' => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL),
|
||||
'phone2' => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL),
|
||||
'icq' => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL),
|
||||
'skype' => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL),
|
||||
'yahoo' => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL),
|
||||
'aim' => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL),
|
||||
'msn' => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL),
|
||||
'department' => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL),
|
||||
'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL),
|
||||
'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL),
|
||||
'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL),
|
||||
'lastaccess' => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL),
|
||||
'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL),
|
||||
'descriptionformat' => new external_value(PARAM_INT, 'User profile description format', VALUE_OPTIONAL),
|
||||
'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
|
||||
'url' => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL),
|
||||
'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
|
||||
'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'),
|
||||
'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'),
|
||||
'customfields' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'),
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
|
||||
'name' => new external_value(PARAM_RAW, 'The name of the custom field'),
|
||||
'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'),
|
||||
)
|
||||
), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL),
|
||||
'groups' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'group id'),
|
||||
'name' => new external_value(PARAM_RAW, 'group name'),
|
||||
'description' => new external_value(PARAM_RAW, 'group description'),
|
||||
)
|
||||
), 'user groups', VALUE_OPTIONAL),
|
||||
'roles' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'roleid' => new external_value(PARAM_INT, 'role id'),
|
||||
'name' => new external_value(PARAM_RAW, 'role name'),
|
||||
'shortname' => new external_value(PARAM_ALPHANUMEXT, 'role shortname'),
|
||||
'sortorder' => new external_value(PARAM_INT, 'role sortorder')
|
||||
)
|
||||
), 'user roles', VALUE_OPTIONAL),
|
||||
'preferences' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'),
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
|
||||
)
|
||||
), 'User preferences', VALUE_OPTIONAL),
|
||||
'enrolledcourses' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'Id of the course'),
|
||||
'fullname' => new external_value(PARAM_RAW, 'Fullname of the course'),
|
||||
'shortname' => new external_value(PARAM_RAW, 'Shortname of the course')
|
||||
)
|
||||
), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Role functions
|
||||
*/
|
||||
class core_role_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function assign_roles_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'assignments' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
|
||||
'userid' => new external_value(PARAM_INT, 'The user that is going to be assigned'),
|
||||
'contextid' => new external_value(PARAM_INT, 'The context to assign the user role in'),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual role assignments to users
|
||||
*
|
||||
* @param array $assignment An array of manual role assignment
|
||||
* @return null
|
||||
*/
|
||||
public static function assign_roles($assignments) {
|
||||
global $DB;
|
||||
|
||||
// Do basic automatic PARAM checks on incoming data, using params description
|
||||
// If any problems are found then exceptions are thrown with helpful error messages
|
||||
$params = self::validate_parameters(self::assign_roles_parameters(), array('assignments'=>$assignments));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['assignments'] as $assignment) {
|
||||
// Ensure the current user is allowed to run this function in the enrolment context
|
||||
$context = get_context_instance_by_id($assignment['contextid']);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
// throw an exception if user is not able to assign the role in this context
|
||||
$roles = get_assignable_roles($context, ROLENAME_SHORT);
|
||||
|
||||
if (!key_exists($assignment['roleid'], $roles)) {
|
||||
throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
|
||||
}
|
||||
|
||||
role_assign($assignment['roleid'], $assignment['userid'], $assignment['contextid']);
|
||||
}
|
||||
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function assign_roles_returns() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function unassign_roles_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'unassignments' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
|
||||
'userid' => new external_value(PARAM_INT, 'The user that is going to be assigned'),
|
||||
'contextid' => new external_value(PARAM_INT, 'The context to unassign the user role from'),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign roles from users
|
||||
*
|
||||
* @param array $unassignment An array of unassignment
|
||||
* @return null
|
||||
*/
|
||||
public static function unassign_roles($unassignments) {
|
||||
global $DB;
|
||||
|
||||
// Do basic automatic PARAM checks on incoming data, using params description
|
||||
// If any problems are found then exceptions are thrown with helpful error messages
|
||||
$params = self::validate_parameters(self::unassign_roles_parameters(), array('unassignments'=>$unassignments));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['unassignments'] as $unassignment) {
|
||||
// Ensure the current user is allowed to run this function in the unassignment context
|
||||
$context = get_context_instance_by_id($unassignment['contextid']);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
// throw an exception if user is not able to unassign the role in this context
|
||||
$roles = get_assignable_roles($context, ROLENAME_SHORT);
|
||||
if (!key_exists($unassignment['roleid'], $roles)) {
|
||||
throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']);
|
||||
}
|
||||
|
||||
role_unassign($unassignment['roleid'], $unassignment['userid'], $unassignment['contextid']);
|
||||
}
|
||||
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return null
|
||||
*/
|
||||
public static function unassign_roles_returns() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated enroll and role functions
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external or core_role_external instead
|
||||
*/
|
||||
class moodle_enrol_external extends external_api {
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external::get_enrolled_users_parameters() instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_enrolled_users_parameters() {
|
||||
@ -52,7 +455,7 @@ class moodle_enrol_external extends external_api {
|
||||
|
||||
/**
|
||||
* Get list of course participants.
|
||||
*
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external::get_enrolled_users() instead
|
||||
* @param int $courseid
|
||||
* @param text $withcapability
|
||||
* @param int $groupid
|
||||
@ -143,6 +546,7 @@ class moodle_enrol_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external::get_enrolled_users_returns() instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_enrolled_users_returns() {
|
||||
@ -164,192 +568,89 @@ class moodle_enrol_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external::get_users_courses_parameters() instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_users_courses_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'userid' => new external_value(PARAM_INT, 'user id'),
|
||||
)
|
||||
);
|
||||
return core_enrol_external::get_users_courses_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of courses user is enrolled in (only active enrolments are returned).
|
||||
*
|
||||
* Please note the current user must be able to access the course, otherwise the course is not included.
|
||||
*
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external::get_users_courses() instead
|
||||
* @param int $userid
|
||||
* @return array of courses
|
||||
*/
|
||||
public static function get_users_courses($userid) {
|
||||
global $USER;
|
||||
|
||||
// Do basic automatic PARAM checks on incoming data, using params description
|
||||
// If any problems are found then exceptions are thrown with helpful error messages
|
||||
$params = self::validate_parameters(self::get_users_courses_parameters(), array('userid'=>$userid));
|
||||
|
||||
$courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible');
|
||||
$result = array();
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
try {
|
||||
self::validate_context($context);
|
||||
} catch (Exception $e) {
|
||||
// current user can not access this course, sorry we can not disclose who is enrolled in this course!
|
||||
continue;
|
||||
}
|
||||
if ($userid != $USER->id and !has_capability('moodle/course:viewparticipants', $context)) {
|
||||
// we need capability to view participants
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = array('id'=>$course->id, 'shortname'=>$course->shortname, 'fullname'=>$course->fullname, 'idnumber'=>$course->idnumber,'visible'=>$course->visible);
|
||||
}
|
||||
|
||||
return $result;
|
||||
return core_enrol_external::get_users_courses($userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_enrol_external::get_users_courses_returns() instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_users_courses_returns() {
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'id of course'),
|
||||
'shortname' => new external_value(PARAM_RAW, 'short name of course'),
|
||||
'fullname' => new external_value(PARAM_RAW, 'long name of course'),
|
||||
'idnumber' => new external_value(PARAM_RAW, 'id number of course'),
|
||||
'visible' => new external_value(PARAM_INT, '1 means visible, 0 means hidden course'),
|
||||
)
|
||||
)
|
||||
);
|
||||
return core_enrol_external::get_users_courses_returns();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_role_external::assign_roles_parameters() instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function role_assign_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'assignments' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
|
||||
'userid' => new external_value(PARAM_INT, 'The user that is going to be assigned'),
|
||||
'contextid' => new external_value(PARAM_INT, 'The context to assign the user role in'),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
return core_role_external::assign_roles_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual role assignments to users
|
||||
*
|
||||
* @deprecated since Moodle 2.2 please use core_role_external::assign_roles() instead
|
||||
* @param array $assignment An array of manual role assignment
|
||||
* @return null
|
||||
*/
|
||||
public static function role_assign($assignments) {
|
||||
global $DB;
|
||||
|
||||
// Do basic automatic PARAM checks on incoming data, using params description
|
||||
// If any problems are found then exceptions are thrown with helpful error messages
|
||||
$params = self::validate_parameters(self::role_assign_parameters(), array('assignments'=>$assignments));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['assignments'] as $assignment) {
|
||||
// Ensure the current user is allowed to run this function in the enrolment context
|
||||
$context = get_context_instance_by_id($assignment['contextid']);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
// throw an exception if user is not able to assign the role in this context
|
||||
$roles = get_assignable_roles($context, ROLENAME_SHORT);
|
||||
if (!key_exists($assignment['roleid'], $roles)) {
|
||||
throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
|
||||
}
|
||||
|
||||
role_assign($assignment['roleid'], $assignment['userid'], $assignment['contextid']);
|
||||
}
|
||||
|
||||
$transaction->allow_commit();
|
||||
return core_role_external::assign_roles($assignments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_role_external::assign_roles_returns() instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function role_assign_returns() {
|
||||
return null;
|
||||
return core_role_external::assign_roles_returns();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_role_external::unassign_roles_parameters() instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function role_unassign_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'unassignments' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
|
||||
'userid' => new external_value(PARAM_INT, 'The user that is going to be assigned'),
|
||||
'contextid' => new external_value(PARAM_INT, 'The context to unassign the user role from'),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
return core_role_external::unassign_roles_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign roles from users
|
||||
*
|
||||
* @deprecated since Moodle 2.2 please use core_role_external::unassign_roles() instead
|
||||
* @param array $unassignment An array of unassignment
|
||||
* @return null
|
||||
*/
|
||||
public static function role_unassign($unassignments) {
|
||||
global $DB;
|
||||
|
||||
// Do basic automatic PARAM checks on incoming data, using params description
|
||||
// If any problems are found then exceptions are thrown with helpful error messages
|
||||
$params = self::validate_parameters(self::role_unassign_parameters(), array('unassignments'=>$unassignments));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['unassignments'] as $unassignment) {
|
||||
// Ensure the current user is allowed to run this function in the unassignment context
|
||||
$context = get_context_instance_by_id($unassignment['contextid']);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
// throw an exception if user is not able to unassign the role in this context
|
||||
$roles = get_assignable_roles($context, ROLENAME_SHORT);
|
||||
if (!key_exists($unassignment['roleid'], $roles)) {
|
||||
throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']);
|
||||
}
|
||||
|
||||
role_unassign($unassignment['roleid'], $unassignment['userid'], $unassignment['contextid']);
|
||||
}
|
||||
|
||||
$transaction->allow_commit();
|
||||
return core_role_external::unassign_roles($unassignments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_role_external::unassign_roles_returns() instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function role_unassign_returns() {
|
||||
return null;
|
||||
return core_role_external::unassign_roles_returns();
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,17 @@ $functions = array(
|
||||
|
||||
// === enrol related functions ===
|
||||
'moodle_enrol_manual_enrol_users' => array(
|
||||
'classname' => 'moodle_enrol_manual_external',
|
||||
'methodname' => 'manual_enrol_users',
|
||||
'classname' => 'enrol_manual_external',
|
||||
'methodname' => 'enrol_users',
|
||||
'classpath' => 'enrol/manual/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as enrol_manual_enrol_users()',
|
||||
'capabilities'=> 'enrol/manual:enrol',
|
||||
'type' => 'write',
|
||||
),
|
||||
|
||||
'enrol_manual_enrol_users' => array(
|
||||
'classname' => 'enrol_manual_external',
|
||||
'methodname' => 'enrol_users',
|
||||
'classpath' => 'enrol/manual/externallib.php',
|
||||
'description' => 'Manual enrol users',
|
||||
'capabilities'=> 'enrol/manual:enrol',
|
||||
|
@ -29,13 +29,16 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
|
||||
class moodle_enrol_manual_external extends external_api {
|
||||
/**
|
||||
* Manual enrolment functions
|
||||
*/
|
||||
class enrol_manual_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function manual_enrol_users_parameters() {
|
||||
public static function enrol_users_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'enrolments' => new external_multiple_structure(
|
||||
@ -60,12 +63,12 @@ class moodle_enrol_manual_external extends external_api {
|
||||
* @param array $enrolments An array of user enrolment
|
||||
* @return null
|
||||
*/
|
||||
public static function manual_enrol_users($enrolments) {
|
||||
public static function enrol_users($enrolments) {
|
||||
global $DB, $CFG;
|
||||
|
||||
require_once($CFG->libdir . '/enrollib.php');
|
||||
|
||||
$params = self::validate_parameters(self::manual_enrol_users_parameters(),
|
||||
$params = self::validate_parameters(self::enrol_users_parameters(),
|
||||
array('enrolments' => $enrolments));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction(); //rollback all enrolment if an error occurs
|
||||
@ -134,10 +137,47 @@ class moodle_enrol_manual_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
* @return null
|
||||
*/
|
||||
public static function manual_enrol_users_returns() {
|
||||
public static function enrol_users_returns() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated manual enrolment functions
|
||||
* @deprecated since Moodle 2.2 please use enrol_manual_external instead
|
||||
*/
|
||||
class moodle_enrol_manual_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use enrol_manual_external::enrol_users_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function manual_enrol_users_parameters() {
|
||||
return enrol_manual_external::enrol_users_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enrolment of users
|
||||
* Function throw an exception at the first error encountered.
|
||||
* @deprecated since Moodle 2.2 please use enrol_manual_external::enrol_users instead
|
||||
* @param array $enrolments An array of user enrolment
|
||||
* @return null
|
||||
*/
|
||||
public static function manual_enrol_users($enrolments) {
|
||||
return enrol_manual_external::enrol_users($enrolments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use enrol_manual_external::enrol_users_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function manual_enrol_users_returns() {
|
||||
return enrol_manual_external::enrol_users_returns();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
|
||||
foreach ($user->enrolments as $enrolment) {
|
||||
$enrolment->courseid = $enrolment->enrolmentinstance->courseid;
|
||||
$enrolment->enrol = 'manual';
|
||||
events_trigger('user_unenrol_modified', $enrolment);
|
||||
events_trigger('user_enrol_modified', $enrolment);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -26,4 +26,4 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2010071201;
|
||||
$plugin->version = 2010071201.02;
|
||||
|
@ -56,6 +56,13 @@ $handlers = array (
|
||||
'internal' => 1,
|
||||
),
|
||||
|
||||
'user_enrol_modified' => array (
|
||||
'handlerfile' => '/enrol/meta/locallib.php',
|
||||
'handlerfunction' => array('enrol_meta_handler', 'user_enrol_modified'),
|
||||
'schedule' => 'instant',
|
||||
'internal' => 1,
|
||||
),
|
||||
|
||||
'course_deleted' => array (
|
||||
'handlerfile' => '/enrol/meta/locallib.php',
|
||||
'handlerfunction' => array('enrol_meta_handler', 'course_deleted'),
|
||||
|
@ -139,8 +139,20 @@ class enrol_meta_handler {
|
||||
|
||||
$plugin = enrol_get_plugin('meta');
|
||||
foreach ($enrols as $enrol) {
|
||||
if ($ue->status == ENROL_USER_ACTIVE) {
|
||||
$status = ENROL_USER_ACTIVE;
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $enrol->courseid);
|
||||
if (is_enrolled($context, $ue->userid)) {
|
||||
// user already has active enrolment, do not change it
|
||||
$status = ENROL_USER_ACTIVE;
|
||||
} else {
|
||||
$status = $ue->status;
|
||||
}
|
||||
|
||||
}
|
||||
// no problem if already enrolled
|
||||
$plugin->enrol_user($enrol, $ue->userid);
|
||||
$plugin->enrol_user($enrol, $ue->userid, $status);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -171,6 +183,33 @@ class enrol_meta_handler {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function user_enrol_modified($ue) {
|
||||
global $DB;
|
||||
|
||||
// update enrolment status if necessary
|
||||
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($ue->enrol === 'meta') {
|
||||
// prevent circular dependencies - we can not sync meta enrolments recursively
|
||||
return true;
|
||||
}
|
||||
|
||||
// does anything want to sync with this parent?
|
||||
if (!$enrols = $DB->get_records('enrol', array('customint1'=>$ue->courseid, 'enrol'=>'meta'), 'id ASC')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$plugin = enrol_get_plugin('meta');
|
||||
foreach ($enrols as $enrol) {
|
||||
$plugin->update_user_enrol($enrol, $ue->userid, $ue->status);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function course_deleted($course) {
|
||||
global $DB;
|
||||
|
||||
@ -207,6 +246,8 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
// unfortunately this may take a loooong time
|
||||
@set_time_limit(0); //if this fails during upgrade we can continue from cron, no big deal
|
||||
|
||||
$instances = array(); //cache
|
||||
|
||||
$meta = enrol_get_plugin('meta');
|
||||
|
||||
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
||||
@ -214,10 +255,8 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
// iterate through all not enrolled yet users
|
||||
if (enrol_is_enabled('meta')) {
|
||||
list($enabled, $params) = $DB->get_in_or_equal(explode(',', $CFG->enrol_plugins_enabled), SQL_PARAMS_NAMED, 'e');
|
||||
$onecourse = "";
|
||||
if ($courseid) {
|
||||
$params['courseid'] = $courseid;
|
||||
$onecourse = "AND e.courseid = :courseid";
|
||||
}
|
||||
$sql = "SELECT pue.userid, e.id AS enrolid
|
||||
FROM {user_enrolments} pue
|
||||
@ -229,7 +268,6 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
$params['courseid'] = $courseid;
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
$instances = array(); //cache
|
||||
foreach($rs as $ue) {
|
||||
if (!isset($instances[$ue->enrolid])) {
|
||||
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
|
||||
@ -237,7 +275,6 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
$meta->enrol_user($instances[$ue->enrolid], $ue->userid);
|
||||
}
|
||||
$rs->close();
|
||||
unset($instances);
|
||||
}
|
||||
|
||||
// unenrol as necessary - ignore enabled flag, we want to get rid of all
|
||||
@ -251,7 +288,6 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
WHERE pue.courseid IS NULL";
|
||||
//TODO: this may use a bit of SQL optimisation
|
||||
$rs = $DB->get_recordset_sql($sql, array('courseid'=>$courseid));
|
||||
$instances = array(); //cache
|
||||
foreach($rs as $ue) {
|
||||
if (!isset($instances[$ue->enrolid])) {
|
||||
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
|
||||
@ -259,7 +295,6 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
$meta->unenrol_user($instances[$ue->enrolid], $ue->userid);
|
||||
}
|
||||
$rs->close();
|
||||
unset($instances);
|
||||
|
||||
// now assign all necessary roles
|
||||
if (enrol_is_enabled('meta')) {
|
||||
@ -320,4 +355,65 @@ function enrol_meta_sync($courseid = NULL) {
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// sync enrolment status
|
||||
if (enrol_is_enabled('meta')) {
|
||||
$enabled = explode(',', $CFG->enrol_plugins_enabled);
|
||||
foreach($enabled as $k=>$v) {
|
||||
if ($v === 'meta') {
|
||||
unset($enabled[$k]);
|
||||
}
|
||||
}
|
||||
list($enabled, $params) = $DB->get_in_or_equal($enabled, SQL_PARAMS_NAMED, 'e');
|
||||
if ($courseid) {
|
||||
$params['courseid'] = $courseid;
|
||||
}
|
||||
//note: this will probably take a long time on mysql...
|
||||
$sql = "SELECT ue.userid, e.id AS enrolid
|
||||
FROM {user_enrolments} ue
|
||||
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'meta' AND e.status = :statusenabled $onecourse)
|
||||
LEFT JOIN (SELECT pue.id, pue.userid, pe.courseid
|
||||
FROM {user_enrolments} pue
|
||||
JOIN {enrol} pe ON (pe.enrol $enabled)
|
||||
WHERE pue.enrolid = pe.id AND pue.status = :activestatus2) xx ON (xx.userid = ue.userid AND xx.courseid = e.customint1)
|
||||
WHERE ue.status = :activestatus1 AND xx.id IS NULL";
|
||||
$params['statusenabled'] = ENROL_INSTANCE_ENABLED;
|
||||
$params['activestatus1'] = ENROL_USER_ACTIVE;
|
||||
$params['activestatus2'] = ENROL_USER_ACTIVE;
|
||||
$params['courseid'] = $courseid;
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $ue) {
|
||||
if (!isset($instances[$ue->enrolid])) {
|
||||
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
|
||||
}
|
||||
$meta->update_user_enrol($instances[$ue->enrolid], $ue->userid, ENROL_USER_SUSPENDED);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
list($enabled, $params) = $DB->get_in_or_equal(explode(',', $CFG->enrol_plugins_enabled), SQL_PARAMS_NAMED, 'e');
|
||||
if ($courseid) {
|
||||
$params['courseid'] = $courseid;
|
||||
}
|
||||
// enable if at least one enrolment active in linked course
|
||||
$sql = "SELECT DISTINCT ue.userid, e.id AS enrolid
|
||||
FROM {user_enrolments} ue
|
||||
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'meta' AND e.status = :statusenabled $onecourse)
|
||||
JOIN {enrol} pe ON (pe.courseid = e.customint1 AND pe.enrol $enabled)
|
||||
JOIN {user_enrolments} pue ON (pue.enrolid = pe.id AND pue.userid = ue.userid AND pue.status = :activestatus)
|
||||
WHERE ue.status = :suspendedstatus";
|
||||
$params['statusenabled'] = ENROL_INSTANCE_ENABLED;
|
||||
$params['suspendedstatus'] = ENROL_USER_SUSPENDED;
|
||||
$params['activestatus'] = ENROL_USER_ACTIVE;
|
||||
$params['courseid'] = $courseid;
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $ue) {
|
||||
if (!isset($instances[$ue->enrolid])) {
|
||||
$instances[$ue->enrolid] = $DB->get_record('enrol', array('id'=>$ue->enrolid));
|
||||
}
|
||||
$meta->update_user_enrol($instances[$ue->enrolid], $ue->userid, ENROL_USER_ACTIVE);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,5 +26,5 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2010073100;
|
||||
$plugin->version = 2010073101;
|
||||
$plugin->cron = 60;
|
@ -6,3 +6,4 @@ information provided here is intended especially for developers.
|
||||
required changes in code:
|
||||
* load_temp_role() is deprecated, use load_temp_course_role() instead, temp role not loaded
|
||||
* remove_temp_role() is deprecated, use remove_temp_course_roles() instead
|
||||
* 'user_unenrol_modified' event was renamed to 'user_enrol_modified'
|
||||
|
@ -27,7 +27,10 @@
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
class moodle_file_external extends external_api {
|
||||
/**
|
||||
* Files functions
|
||||
*/
|
||||
class core_files_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of get_files parameters
|
||||
@ -296,3 +299,77 @@ class moodle_file_external extends external_api {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated files functions
|
||||
* @deprecated since Moodle 2.2 please use core_files_external instead
|
||||
*/
|
||||
class moodle_file_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of get_files parameters
|
||||
* @deprecated since Moodle 2.2 please use core_files_external::get_files_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_files_parameters() {
|
||||
return core_files_external::get_files_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return moodle files listing
|
||||
* @deprecated since Moodle 2.2 please use core_files_external::get_files instead
|
||||
* @param int $contextid
|
||||
* @param int $component
|
||||
* @param int $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return array
|
||||
*/
|
||||
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
return core_files_external::get_files($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of get_files returns
|
||||
* @deprecated since Moodle 2.2 please use core_files_external::get_files_returns instead
|
||||
* @return external_multiple_structure
|
||||
*/
|
||||
public static function get_files_returns() {
|
||||
return core_files_external::get_files_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload parameters
|
||||
* @deprecated since Moodle 2.2 please use core_files_external::upload_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function upload_parameters() {
|
||||
return core_files_external::upload_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploading a file to moodle
|
||||
* @deprecated since Moodle 2.2 please use core_files_external::upload instead
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @param string $filecontent
|
||||
* @return array
|
||||
*/
|
||||
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
||||
return core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload returns
|
||||
* @deprecated since Moodle 2.2 please use core_files_external::upload_returns instead
|
||||
* @return external_multiple_structure
|
||||
*/
|
||||
public static function upload_returns() {
|
||||
return core_files_external::upload_returns();
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,10 @@
|
||||
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
|
||||
class moodle_group_external extends external_api {
|
||||
/**
|
||||
* Group functions
|
||||
*/
|
||||
class core_group_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
@ -305,7 +308,7 @@ class moodle_group_external extends external_api {
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_groupmembers_parameters() {
|
||||
public static function get_group_members_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'groupids' => new external_multiple_structure(new external_value(PARAM_INT, 'Group ID')),
|
||||
@ -318,10 +321,10 @@ class moodle_group_external extends external_api {
|
||||
* @param array $groupids array of group ids
|
||||
* @return array with group id keys containing arrays of user ids
|
||||
*/
|
||||
public static function get_groupmembers($groupids) {
|
||||
public static function get_group_members($groupids) {
|
||||
$members = array();
|
||||
|
||||
$params = self::validate_parameters(self::get_groupmembers_parameters(), array('groupids'=>$groupids));
|
||||
$params = self::validate_parameters(self::get_group_members_parameters(), array('groupids'=>$groupids));
|
||||
|
||||
foreach ($params['groupids'] as $groupid) {
|
||||
// validate params
|
||||
@ -351,7 +354,7 @@ class moodle_group_external extends external_api {
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_groupmembers_returns() {
|
||||
public static function get_group_members_returns() {
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
@ -367,7 +370,7 @@ class moodle_group_external extends external_api {
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function add_groupmembers_parameters() {
|
||||
public static function add_group_members_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'members'=> new external_multiple_structure(
|
||||
@ -387,11 +390,11 @@ class moodle_group_external extends external_api {
|
||||
* @param array $members of arrays with keys userid, groupid
|
||||
* @return void
|
||||
*/
|
||||
public static function add_groupmembers($members) {
|
||||
public static function add_group_members($members) {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->dirroot/group/lib.php");
|
||||
|
||||
$params = self::validate_parameters(self::add_groupmembers_parameters(), array('members'=>$members));
|
||||
$params = self::validate_parameters(self::add_group_members_parameters(), array('members'=>$members));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
foreach ($params['members'] as $member) {
|
||||
@ -429,9 +432,9 @@ class moodle_group_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
* @return null
|
||||
*/
|
||||
public static function add_groupmembers_returns() {
|
||||
public static function add_group_members_returns() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -440,7 +443,7 @@ class moodle_group_external extends external_api {
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function delete_groupmembers_parameters() {
|
||||
public static function delete_group_members_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'members'=> new external_multiple_structure(
|
||||
@ -460,11 +463,11 @@ class moodle_group_external extends external_api {
|
||||
* @param array $members of arrays with keys userid, groupid
|
||||
* @return void
|
||||
*/
|
||||
public static function delete_groupmembers($members) {
|
||||
public static function delete_group_members($members) {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->dirroot/group/lib.php");
|
||||
|
||||
$params = self::validate_parameters(self::delete_groupmembers_parameters(), array('members'=>$members));
|
||||
$params = self::validate_parameters(self::delete_group_members_parameters(), array('members'=>$members));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
@ -497,10 +500,217 @@ class moodle_group_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
* @return null
|
||||
*/
|
||||
public static function delete_groupmembers_returns() {
|
||||
public static function delete_group_members_returns() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated group functions
|
||||
* @deprecated since Moodle 2.2 please use core_group_external instead
|
||||
*/
|
||||
class moodle_group_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::create_groups_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function create_groups_parameters() {
|
||||
return core_group_external::create_groups_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create groups
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::create_groups instead
|
||||
* @param array $groups array of group description arrays (with keys groupname and courseid)
|
||||
* @return array of newly created groups
|
||||
*/
|
||||
public static function create_groups($groups) {
|
||||
return core_group_external::create_groups($groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::create_groups_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function create_groups_returns() {
|
||||
return core_group_external::create_groups_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_groups_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_groups_parameters() {
|
||||
return core_group_external::get_groups_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups definition specified by ids
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_groups instead
|
||||
* @param array $groupids arrays of group ids
|
||||
* @return array of group objects (id, courseid, name, enrolmentkey)
|
||||
*/
|
||||
public static function get_groups($groupids) {
|
||||
return core_group_external::get_groups($groupids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_groups_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_groups_returns() {
|
||||
return core_group_external::get_groups_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_course_groups_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_course_groups_parameters() {
|
||||
return core_group_external::get_course_groups_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all groups in the specified course
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_course_groups instead
|
||||
* @param int $courseid id of course
|
||||
* @return array of group objects (id, courseid, name, enrolmentkey)
|
||||
*/
|
||||
public static function get_course_groups($courseid) {
|
||||
return core_group_external::get_course_groups($courseid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_course_groups_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_course_groups_returns() {
|
||||
return core_group_external::get_course_groups_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::delete_group_members_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function delete_groups_parameters() {
|
||||
return core_group_external::delete_group_members_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete groups
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::delete_groups instead
|
||||
* @param array $groupids array of group ids
|
||||
* @return void
|
||||
*/
|
||||
public static function delete_groups($groupids) {
|
||||
return core_group_external::delete_groups($groupids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::delete_group_members_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function delete_groups_returns() {
|
||||
return core_group_external::delete_group_members_returns();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_group_members_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_groupmembers_parameters() {
|
||||
return core_group_external::get_group_members_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all members for a group
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_group_members instead
|
||||
* @param array $groupids array of group ids
|
||||
* @return array with group id keys containing arrays of user ids
|
||||
*/
|
||||
public static function get_groupmembers($groupids) {
|
||||
return core_group_external::get_group_members($groupids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::get_group_members_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_groupmembers_returns() {
|
||||
return core_group_external::get_group_members_returns();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::add_group_members_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function add_groupmembers_parameters() {
|
||||
return core_group_external::add_group_members_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add group members
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::add_group_members instead
|
||||
* @param array $members of arrays with keys userid, groupid
|
||||
* @return void
|
||||
*/
|
||||
public static function add_groupmembers($members) {
|
||||
return core_group_external::add_group_members($members);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::add_group_members_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function add_groupmembers_returns() {
|
||||
return core_group_external::add_group_members_returns();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::delete_group_members_parameters instead
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function delete_groupmembers_parameters() {
|
||||
return core_group_external::delete_group_members_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete group members
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::delete_group_members instead
|
||||
* @param array $members of arrays with keys userid, groupid
|
||||
* @return void
|
||||
*/
|
||||
public static function delete_groupmembers($members) {
|
||||
return core_group_external::delete_group_members($members);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @deprecated since Moodle 2.2 please use core_group_external::delete_group_members_returns instead
|
||||
* @return external_description
|
||||
*/
|
||||
public static function delete_groupmembers_returns() {
|
||||
return core_group_external::delete_group_members_returns();
|
||||
}
|
||||
|
||||
}
|
31
install/lang/wo/langconfig.php
Normal file
31
install/lang/wo/langconfig.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Automatically generated strings for Moodle 2.2dev installer
|
||||
*
|
||||
* Do not edit this file manually! It contains just a subset of strings
|
||||
* needed during the very first steps of installation. This file was
|
||||
* generated automatically by export-installer.php (which is part of AMOS
|
||||
* {@link http://docs.moodle.org/dev/Languages/AMOS}) using the
|
||||
* list of strings defined in /install/stringnames.txt.
|
||||
*
|
||||
* @package installer
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['thislanguage'] = 'Wolof';
|
@ -10,6 +10,7 @@ cannotsavezipfile,error
|
||||
cannotunzipfile,error
|
||||
chooselanguagehead,install
|
||||
chooselanguagesub,install
|
||||
clialreadyconfigured,install
|
||||
clialreadyinstalled,install
|
||||
clianswerno,admin
|
||||
cliansweryes,admin
|
||||
|
@ -191,7 +191,6 @@ $string['configenablecomments'] = 'Enable comments';
|
||||
$string['configenablecourserequests'] = 'This will allow any user to request a course be created.';
|
||||
$string['configenableglobalsearch'] = 'This setting enables global text searching in resources and activities, it is not compatible with PHP 4.';
|
||||
$string['configenablegroupmembersonly'] = 'If enabled, access to activities can be restricted to group members only. This may result in an increased server load. In addition, gradebook categories must be set up in a certain way to ensure that activities are hidden from non-group members.';
|
||||
$string['configenablehtmlpurifier'] = 'Use HTML Purifier instead of KSES for cleaning of untrusted text. HTML Purifier is actively developed and is believed to be more secure, but it is more resource intensive. Expect minor visual differences in the resulting html code. Please note that embed and object tags can not be enabled, MathML tags and old lang tags are not supported.';
|
||||
$string['configenablemobilewebservice'] = 'Enable mobile service for the official Moodle app or other app requesting it. For more information, read the {$a}';
|
||||
$string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site. To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.';
|
||||
$string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.';
|
||||
@ -473,7 +472,6 @@ $string['enableglobalsearch'] = 'Enable global search';
|
||||
$string['enablegravatar'] = 'Enable Gravatar';
|
||||
$string['enablegravatar_help'] = 'When enabled Moodle will attempt to fetch a user profile picture from Gravatar if the user has not uploaded an image.';
|
||||
$string['enablegroupmembersonly'] = 'Enable group members only';
|
||||
$string['enablehtmlpurifier'] = 'Enable HTML Purifier';
|
||||
$string['enablemobilewebservice'] = 'Enable mobile web service';
|
||||
$string['enablerecordcache'] = 'Enable record cache';
|
||||
$string['enablerssfeeds'] = 'Enable RSS feeds';
|
||||
@ -745,6 +743,7 @@ $string['pleaserefreshregistration'] = 'Your site has been registered with moodl
|
||||
$string['pleaseregister'] = 'Please register your site to remove this button';
|
||||
$string['plugin'] = 'Plugin';
|
||||
$string['plugins'] = 'Plugins';
|
||||
$string['pluginschecktodo'] = 'You must solve all the plugin requirements before proceeding to install this Moodle version!';
|
||||
$string['pluginsoverview'] = 'Plugins overview';
|
||||
$string['profilecategory'] = 'Category';
|
||||
$string['profilecategoryname'] = 'Category name (must be unique)';
|
||||
|
@ -42,7 +42,8 @@ $string['availablelangs'] = 'List of available languages';
|
||||
$string['caution'] = 'Caution';
|
||||
$string['cliadminpassword'] = 'New admin user password';
|
||||
$string['cliadminusername'] = 'Admin account username';
|
||||
$string['clialreadyinstalled'] = 'File config.php already exists, please use admin/cli/upgrade.php if you want to upgrade your site.';
|
||||
$string['clialreadyconfigured'] = 'File config.php already exists, please use admin/cli/install_database.php if you want to install this site.';
|
||||
$string['clialreadyinstalled'] = 'File config.php already exists, please use admin/cli/upgrade.php if you want to upgrade this site.';
|
||||
$string['cliinstallfinished'] = 'Installation completed successfully.';
|
||||
$string['cliinstallheader'] = 'Moodle {$a} command line installation program';
|
||||
$string['climustagreelicense'] = 'In non interactive mode you must agree to license by specifying --agree-license option';
|
||||
|
@ -1391,6 +1391,7 @@ $string['rssarticles'] = 'Number of RSS recent articles';
|
||||
$string['rsserror'] = 'Error reading RSS data';
|
||||
$string['rsserrorauth'] = 'Your RSS link does not contain a valid authentication token.';
|
||||
$string['rsserrorguest'] = 'This feed uses guest access to access the data, but guest does not have permission to read the data. Visit the original location that this feed comes from (URL) as a valid user and get a new RSS link from there.';
|
||||
$string['rsskeyshelp'] = 'To ensure security and privacy, RSS feed URLs contain a special token that identifies the user they are for. This prevents other users from accessing areas of Moodle they shouldn\'t have access to via RSS feeds.</p><p>This token is automatically created the first time you access an area of Moodle that produces an RSS feed. If you feel that your RSS feed token has been compromised in some way you can request a new one by clicking the Reset link here. Please note that your current RSS feed URLs will then become invalid.';
|
||||
$string['rsstype'] = 'RSS feed for this activity';
|
||||
$string['saveandnext'] = 'Save and show next';
|
||||
$string['savedat'] = 'Saved at:';
|
||||
|
@ -27,9 +27,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$string['availability'] = 'Availability';
|
||||
$string['displayname'] = 'Plugin name';
|
||||
$string['moodleversion'] = 'Moodle {$a}';
|
||||
$string['nonehighlighted'] = 'No plugins require your attention during this upgrade';
|
||||
$string['nonehighlightedinfo'] = 'Display the list of all installed plugins anyway';
|
||||
$string['noneinstalled'] = 'No plugins of this type are installed';
|
||||
$string['otherplugin'] = '{$a->component}';
|
||||
$string['otherpluginversion'] = '{$a->component} ({$a->version})';
|
||||
$string['showall'] = 'Reload and show all plugins';
|
||||
$string['pluginchecknotice'] = 'This page displays plugins that may require your attention during the upgrade. Highlighted items include new plugins that are about to be installed, updated plugins that are about to be upgraded and any missing plugins. Contributed plugins are also highlighted.
|
||||
It is recommended that you check whether there are more recent versions of contributed plugins available and update their source code before continuing with this Moodle upgrade.';
|
||||
@ -37,6 +40,7 @@ $string['plugindisable'] = 'Disable';
|
||||
$string['plugindisabled'] = 'Disabled';
|
||||
$string['pluginenable'] = 'Enable';
|
||||
$string['pluginenabled'] = 'Enabled';
|
||||
$string['requires'] = 'Requires';
|
||||
$string['rootdir'] = 'Directory';
|
||||
$string['settings'] = 'Settings';
|
||||
$string['somehighlighted'] = 'Number of plugins requiring attention during this upgrade: {$a}';
|
||||
|
@ -135,7 +135,7 @@ $string['errormovingquestions'] = 'Error while moving questions with ids {$a}.';
|
||||
$string['errorpostprocess'] = 'Error occurred during post-processing!';
|
||||
$string['errorpreprocess'] = 'Error occurred during pre-processing!';
|
||||
$string['errorprocess'] = 'Error occurred during processing!';
|
||||
$string['errorprocessingresponses'] = 'An error occurred while processing your responses.';
|
||||
$string['errorprocessingresponses'] = 'An error occurred while processing your responses ({$a}). Click continue to return to the page you were on and try again.';
|
||||
$string['errorsavingcomment'] = 'Error saving the comment for question {$a->name} in the database.';
|
||||
$string['errorupdatingattempt'] = 'Error updating attempt {$a->id} in the database.';
|
||||
$string['exportcategory'] = 'Export category';
|
||||
|
@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
$string['accessexception'] = 'Access control exception';
|
||||
$string['accessnotallowed'] = 'Access to web service not allowed';
|
||||
$string['actwebserviceshhdr'] = 'Active web service protocols';
|
||||
$string['accesstofunctionnotallowed'] = 'Access to the function {$a}() is not allowed. Please check if a service containing the function is enabled. In the service settings: if the service is restricted check that the user is listed. Still in the service settings check for IP restriction or if the service requires a capability.';
|
||||
$string['addaservice'] = 'Add service';
|
||||
@ -43,7 +42,7 @@ $string['apiexplorer'] = 'API explorer';
|
||||
$string['apiexplorernotavalaible'] = 'API explorer not available yet.';
|
||||
$string['arguments'] = 'Arguments';
|
||||
$string['authmethod'] = 'Authentication method';
|
||||
$string['cannotcreatemobiletoken'] = 'No permission to create web service token for mobile access.';
|
||||
$string['cannotcreatetoken'] = 'No permission to create web service token for the service {$a}.';
|
||||
$string['configwebserviceplugins'] = 'For security reasons, only protocols that are in use should be enabled.';
|
||||
$string['context'] = 'Context';
|
||||
$string['createservicedescription'] = 'A service is a set of web service functions. You will allow the user to access to a new service. On the <strong>Add service</strong> page check \'Enable\' and \'Authorised users\' options. Select \'No required capability\'.';
|
||||
@ -111,6 +110,7 @@ $string['managetokens'] = 'Manage tokens';
|
||||
$string['missingcaps'] = 'Missing capabilities';
|
||||
$string['missingcaps_help'] = 'List of required capabilities for the service which the selected user does not have. Missing capabilities must be added to the user\'s role in order to use the service.';
|
||||
$string['missingpassword'] = 'Missing password';
|
||||
$string['missingrequiredcapability'] = 'The capability {$a} is required.';
|
||||
$string['missingusername'] = 'Missing username';
|
||||
$string['missingversionfile'] = 'Coding error: version.php file is missing for the component {$a}';
|
||||
$string['mobilewsdisabled'] = 'Disabled';
|
||||
@ -130,6 +130,7 @@ $string['potusers'] = 'Not authorised users';
|
||||
$string['potusersmatching'] = 'Not authorised users matching';
|
||||
$string['print'] = 'Print all';
|
||||
$string['protocol'] = 'Protocol';
|
||||
$string['protocolnotallowed'] = 'You are not allowed to use the {$a} protocol (missing capability: webservice/{$a}:use)';
|
||||
$string['removefunction'] = 'Remove';
|
||||
$string['removefunctionconfirm'] = 'Do you really want to remove function "{$a->function}" from service "{$a->service}"?';
|
||||
$string['requireauthentication'] = 'This method requires authentication with xxx permission.';
|
||||
|
@ -986,6 +986,8 @@ function load_role_access_by_context($roleid, context $context, &$accessdata) {
|
||||
|
||||
/**
|
||||
* Returns empty accessdata structure.
|
||||
*
|
||||
* @private
|
||||
* @return array empt accessdata
|
||||
*/
|
||||
function get_empty_accessdata() {
|
||||
@ -1163,6 +1165,7 @@ function reload_all_capabilities() {
|
||||
* Adds a temp role to current USER->access array.
|
||||
*
|
||||
* Useful for the "temporary guest" access we grant to logged-in users.
|
||||
* @since 2.2
|
||||
*
|
||||
* @param context_course $coursecontext
|
||||
* @param int $roleid
|
||||
@ -1198,6 +1201,7 @@ function load_temp_course_role(context_course $coursecontext, $roleid) {
|
||||
|
||||
/**
|
||||
* Removes any extra guest roles from current USER->access array.
|
||||
* @since 2.2
|
||||
*
|
||||
* @param context_course $coursecontext
|
||||
* @return void
|
||||
@ -1533,7 +1537,6 @@ function get_roles_with_capability($capability, $permission = null, $context = n
|
||||
return $DB->get_records_sql($sql, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function makes a role-assignment (a role for a user in a particular context)
|
||||
*
|
||||
@ -2271,7 +2274,7 @@ function load_capability_def($component) {
|
||||
if (!empty(${$component.'_capabilities'})) {
|
||||
// BC capability array name
|
||||
// since 2.0 we prefer $capabilities instead - it is easier to use and matches db/* files
|
||||
debugging('componentname_capabilities array is deprecated, please use capabilities array only in access.php files');
|
||||
debugging('componentname_capabilities array is deprecated, please use $capabilities array only in access.php files');
|
||||
$capabilities = ${$component.'_capabilities'};
|
||||
}
|
||||
}
|
||||
@ -2500,12 +2503,6 @@ function capabilities_cleanup($component, $newcapdef = null) {
|
||||
return $removedcount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////
|
||||
// UI FUNCTIONS //
|
||||
//////////////////
|
||||
|
||||
/**
|
||||
* Returns an array of all the known types of risk
|
||||
* The array keys can be used, for example as CSS class names, or in calls to
|
||||
@ -3843,7 +3840,6 @@ function get_roles_on_exact_context(context $context) {
|
||||
FROM {role_assignments} ra, {role} r
|
||||
WHERE ra.roleid = r.id AND ra.contextid = ?",
|
||||
array($context->id));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4426,241 +4422,11 @@ function role_change_permission($roleid, $context, $capname, $permission) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Context maintenance and helper methods.
|
||||
*
|
||||
* This is "extends context" is a bloody hack that tires to work around the deficiencies
|
||||
* in the "protected" keyword in PHP, this helps us to hide all the internals of context
|
||||
* level implementation from the rest of code, the code completion returns what developers need.
|
||||
*
|
||||
* Thank you Tim Hunt for helping me with this nasty trick.
|
||||
*
|
||||
* @author Petr Skoda
|
||||
*/
|
||||
class context_helper extends context {
|
||||
|
||||
private static $alllevels = array(
|
||||
CONTEXT_SYSTEM => 'context_system',
|
||||
CONTEXT_USER => 'context_user',
|
||||
CONTEXT_COURSECAT => 'context_coursecat',
|
||||
CONTEXT_COURSE => 'context_course',
|
||||
CONTEXT_MODULE => 'context_module',
|
||||
CONTEXT_BLOCK => 'context_block',
|
||||
);
|
||||
|
||||
/**
|
||||
* Instance does not make sense here, only static use
|
||||
*/
|
||||
protected function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class name of the context level class
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel (CONTEXT_SYSTEM, etc.)
|
||||
* @return string class name of the context class
|
||||
*/
|
||||
public static function get_class_for_level($contextlevel) {
|
||||
if (isset(self::$alllevels[$contextlevel])) {
|
||||
return self::$alllevels[$contextlevel];
|
||||
} else {
|
||||
throw new coding_exception('Invalid context level specified');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all context levels
|
||||
*
|
||||
* @static
|
||||
* @return array int=>string (level=>level class name)
|
||||
*/
|
||||
public static function get_all_levels() {
|
||||
return self::$alllevels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove stale contexts that belonged to deleted instances.
|
||||
* Ideally all code should cleanup contexts properly, unfortunately accidents happen...
|
||||
*
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
public static function cleanup_instances() {
|
||||
global $DB;
|
||||
$sqls = array();
|
||||
foreach (self::$alllevels as $level=>$classname) {
|
||||
$sqls[] = $classname::get_cleanup_sql();
|
||||
}
|
||||
|
||||
$sql = implode(" UNION ", $sqls);
|
||||
|
||||
// it is probably better to use transactions, it might be faster too
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $record) {
|
||||
$context = context::create_instance_from_record($record);
|
||||
$context->delete();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all context instances at the given level and above.
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel null means all levels
|
||||
* @param bool $buildpaths
|
||||
* @return void
|
||||
*/
|
||||
public static function create_instances($contextlevel = null, $buildpaths = true) {
|
||||
foreach (self::$alllevels as $level=>$classname) {
|
||||
if ($contextlevel and $level > $contextlevel) {
|
||||
// skip potential sub-contexts
|
||||
continue;
|
||||
}
|
||||
$classname::create_level_instances();
|
||||
if ($buildpaths) {
|
||||
$classname::build_paths(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild paths and depths in all context levels.
|
||||
*
|
||||
* @static
|
||||
* @param bool $force false means add missing only
|
||||
* @return void
|
||||
*/
|
||||
public static function build_all_paths($force = false) {
|
||||
foreach (self::$alllevels as $classname) {
|
||||
$classname::build_paths($force);
|
||||
}
|
||||
|
||||
// reset static course cache - it might have incorrect cached data
|
||||
accesslib_clear_all_caches(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the cache to remove all data.
|
||||
* @static
|
||||
*/
|
||||
public static function reset_caches() {
|
||||
context::reset_caches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all fields necessary for context preloading from user $rec.
|
||||
*
|
||||
* This helps with performance when dealing with hundreds of contexts.
|
||||
*
|
||||
* @static
|
||||
* @param string $tablealias context table alias in the query
|
||||
* @return array (table.column=>alias, ...)
|
||||
*/
|
||||
public static function get_preload_record_columns($tablealias) {
|
||||
return array("$tablealias.id"=>"ctxid", "$tablealias.path"=>"ctxpath", "$tablealias.depth"=>"ctxdepth", "$tablealias.contextlevel"=>"ctxlevel", "$tablealias.instanceid"=>"ctxinstance");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all fields necessary for context preloading from user $rec.
|
||||
*
|
||||
* This helps with performance when dealing with hundreds of contexts.
|
||||
*
|
||||
* @static
|
||||
* @param string $tablealias context table alias in the query
|
||||
* @return string
|
||||
*/
|
||||
public static function get_preload_record_columns_sql($tablealias) {
|
||||
return "$tablealias.id AS ctxid, $tablealias.path AS ctxpath, $tablealias.depth AS ctxdepth, $tablealias.contextlevel AS ctxlevel, $tablealias.instanceid AS ctxinstance";
|
||||
}
|
||||
|
||||
/**
|
||||
* Preloads context information from db record and strips the cached info.
|
||||
*
|
||||
* The db request has to contain all columns from context_helper::get_preload_record_columns().
|
||||
*
|
||||
* @static
|
||||
* @param stdClass $rec
|
||||
* @return void (modifies $rec)
|
||||
*/
|
||||
public static function preload_from_record(stdClass $rec) {
|
||||
context::preload_from_record($rec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload all contexts instances from course.
|
||||
*
|
||||
* To be used if you expect multiple queries for course activities...
|
||||
*
|
||||
* @static
|
||||
* @param $courseid
|
||||
*/
|
||||
public static function preload_course($courseid) {
|
||||
// Users can call this multiple times without doing any harm
|
||||
if (isset(context::$cache_preloaded[$courseid])) {
|
||||
return;
|
||||
}
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$coursecontext->get_child_contexts();
|
||||
|
||||
context::$cache_preloaded[$courseid] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete context instance
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel
|
||||
* @param int $instanceid
|
||||
* @return void
|
||||
*/
|
||||
public static function delete_instance($contextlevel, $instanceid) {
|
||||
global $DB;
|
||||
|
||||
// double check the context still exists
|
||||
if ($record = $DB->get_record('context', array('contextlevel'=>$contextlevel, 'instanceid'=>$instanceid))) {
|
||||
$context = context::create_instance_from_record($record);
|
||||
$context->delete();
|
||||
} else {
|
||||
// we should try to purge the cache anyway
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of specified context level
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel
|
||||
* @return string name of the context level
|
||||
*/
|
||||
public static function get_level_name($contextlevel) {
|
||||
$classname = context_helper::get_class_for_level($contextlevel);
|
||||
return $classname::get_level_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* not used
|
||||
*/
|
||||
public function get_url() {
|
||||
}
|
||||
|
||||
/**
|
||||
* not used
|
||||
*/
|
||||
public function get_capabilities() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Basic moodle context abstraction class.
|
||||
*
|
||||
* @author Petr Skoda
|
||||
* @since 2.2
|
||||
*
|
||||
* @property-read int $id context id
|
||||
* @property-read int $contextlevel CONTEXT_SYSTEM, CONTEXT_COURSE, etc.
|
||||
@ -4696,6 +4462,7 @@ abstract class context extends stdClass {
|
||||
|
||||
/**
|
||||
* Resets the cache to remove all data.
|
||||
* @static
|
||||
*/
|
||||
protected static function reset_caches() {
|
||||
self::$cache_contextsbyid = array();
|
||||
@ -4893,6 +4660,7 @@ abstract class context extends stdClass {
|
||||
|
||||
/**
|
||||
* This function is also used to work around 'protected' keyword problems in context_helper.
|
||||
* @static
|
||||
* @param stdClass $record
|
||||
* @return context instance
|
||||
*/
|
||||
@ -5393,9 +5161,242 @@ abstract class context extends stdClass {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Context maintenance and helper methods.
|
||||
*
|
||||
* This is "extends context" is a bloody hack that tires to work around the deficiencies
|
||||
* in the "protected" keyword in PHP, this helps us to hide all the internals of context
|
||||
* level implementation from the rest of code, the code completion returns what developers need.
|
||||
*
|
||||
* Thank you Tim Hunt for helping me with this nasty trick.
|
||||
*
|
||||
* @author Petr Skoda
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_helper extends context {
|
||||
|
||||
private static $alllevels = array(
|
||||
CONTEXT_SYSTEM => 'context_system',
|
||||
CONTEXT_USER => 'context_user',
|
||||
CONTEXT_COURSECAT => 'context_coursecat',
|
||||
CONTEXT_COURSE => 'context_course',
|
||||
CONTEXT_MODULE => 'context_module',
|
||||
CONTEXT_BLOCK => 'context_block',
|
||||
);
|
||||
|
||||
/**
|
||||
* Instance does not make sense here, only static use
|
||||
*/
|
||||
protected function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class name of the context level class
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel (CONTEXT_SYSTEM, etc.)
|
||||
* @return string class name of the context class
|
||||
*/
|
||||
public static function get_class_for_level($contextlevel) {
|
||||
if (isset(self::$alllevels[$contextlevel])) {
|
||||
return self::$alllevels[$contextlevel];
|
||||
} else {
|
||||
throw new coding_exception('Invalid context level specified');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all context levels
|
||||
*
|
||||
* @static
|
||||
* @return array int=>string (level=>level class name)
|
||||
*/
|
||||
public static function get_all_levels() {
|
||||
return self::$alllevels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove stale contexts that belonged to deleted instances.
|
||||
* Ideally all code should cleanup contexts properly, unfortunately accidents happen...
|
||||
*
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
public static function cleanup_instances() {
|
||||
global $DB;
|
||||
$sqls = array();
|
||||
foreach (self::$alllevels as $level=>$classname) {
|
||||
$sqls[] = $classname::get_cleanup_sql();
|
||||
}
|
||||
|
||||
$sql = implode(" UNION ", $sqls);
|
||||
|
||||
// it is probably better to use transactions, it might be faster too
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $record) {
|
||||
$context = context::create_instance_from_record($record);
|
||||
$context->delete();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all context instances at the given level and above.
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel null means all levels
|
||||
* @param bool $buildpaths
|
||||
* @return void
|
||||
*/
|
||||
public static function create_instances($contextlevel = null, $buildpaths = true) {
|
||||
foreach (self::$alllevels as $level=>$classname) {
|
||||
if ($contextlevel and $level > $contextlevel) {
|
||||
// skip potential sub-contexts
|
||||
continue;
|
||||
}
|
||||
$classname::create_level_instances();
|
||||
if ($buildpaths) {
|
||||
$classname::build_paths(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild paths and depths in all context levels.
|
||||
*
|
||||
* @static
|
||||
* @param bool $force false means add missing only
|
||||
* @return void
|
||||
*/
|
||||
public static function build_all_paths($force = false) {
|
||||
foreach (self::$alllevels as $classname) {
|
||||
$classname::build_paths($force);
|
||||
}
|
||||
|
||||
// reset static course cache - it might have incorrect cached data
|
||||
accesslib_clear_all_caches(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the cache to remove all data.
|
||||
* @static
|
||||
*/
|
||||
public static function reset_caches() {
|
||||
context::reset_caches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all fields necessary for context preloading from user $rec.
|
||||
*
|
||||
* This helps with performance when dealing with hundreds of contexts.
|
||||
*
|
||||
* @static
|
||||
* @param string $tablealias context table alias in the query
|
||||
* @return array (table.column=>alias, ...)
|
||||
*/
|
||||
public static function get_preload_record_columns($tablealias) {
|
||||
return array("$tablealias.id"=>"ctxid", "$tablealias.path"=>"ctxpath", "$tablealias.depth"=>"ctxdepth", "$tablealias.contextlevel"=>"ctxlevel", "$tablealias.instanceid"=>"ctxinstance");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all fields necessary for context preloading from user $rec.
|
||||
*
|
||||
* This helps with performance when dealing with hundreds of contexts.
|
||||
*
|
||||
* @static
|
||||
* @param string $tablealias context table alias in the query
|
||||
* @return string
|
||||
*/
|
||||
public static function get_preload_record_columns_sql($tablealias) {
|
||||
return "$tablealias.id AS ctxid, $tablealias.path AS ctxpath, $tablealias.depth AS ctxdepth, $tablealias.contextlevel AS ctxlevel, $tablealias.instanceid AS ctxinstance";
|
||||
}
|
||||
|
||||
/**
|
||||
* Preloads context information from db record and strips the cached info.
|
||||
*
|
||||
* The db request has to contain all columns from context_helper::get_preload_record_columns().
|
||||
*
|
||||
* @static
|
||||
* @param stdClass $rec
|
||||
* @return void (modifies $rec)
|
||||
*/
|
||||
public static function preload_from_record(stdClass $rec) {
|
||||
context::preload_from_record($rec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload all contexts instances from course.
|
||||
*
|
||||
* To be used if you expect multiple queries for course activities...
|
||||
*
|
||||
* @static
|
||||
* @param $courseid
|
||||
*/
|
||||
public static function preload_course($courseid) {
|
||||
// Users can call this multiple times without doing any harm
|
||||
if (isset(context::$cache_preloaded[$courseid])) {
|
||||
return;
|
||||
}
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$coursecontext->get_child_contexts();
|
||||
|
||||
context::$cache_preloaded[$courseid] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete context instance
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel
|
||||
* @param int $instanceid
|
||||
* @return void
|
||||
*/
|
||||
public static function delete_instance($contextlevel, $instanceid) {
|
||||
global $DB;
|
||||
|
||||
// double check the context still exists
|
||||
if ($record = $DB->get_record('context', array('contextlevel'=>$contextlevel, 'instanceid'=>$instanceid))) {
|
||||
$context = context::create_instance_from_record($record);
|
||||
$context->delete();
|
||||
} else {
|
||||
// we should try to purge the cache anyway
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of specified context level
|
||||
*
|
||||
* @static
|
||||
* @param int $contextlevel
|
||||
* @return string name of the context level
|
||||
*/
|
||||
public static function get_level_name($contextlevel) {
|
||||
$classname = context_helper::get_class_for_level($contextlevel);
|
||||
return $classname::get_level_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* not used
|
||||
*/
|
||||
public function get_url() {
|
||||
}
|
||||
|
||||
/**
|
||||
* not used
|
||||
*/
|
||||
public function get_capabilities() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Basic context class
|
||||
* @author Petr Skoda (http://skodak.org)
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_system extends context {
|
||||
/**
|
||||
@ -5632,6 +5633,7 @@ class context_system extends context {
|
||||
/**
|
||||
* User context class
|
||||
* @author Petr Skoda (http://skodak.org)
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_user extends context {
|
||||
/**
|
||||
@ -5799,6 +5801,7 @@ class context_user extends context {
|
||||
/**
|
||||
* Course category context class
|
||||
* @author Petr Skoda (http://skodak.org)
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_coursecat extends context {
|
||||
/**
|
||||
@ -6018,6 +6021,7 @@ class context_coursecat extends context {
|
||||
/**
|
||||
* Course context class
|
||||
* @author Petr Skoda (http://skodak.org)
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_course extends context {
|
||||
/**
|
||||
@ -6232,6 +6236,7 @@ class context_course extends context {
|
||||
/**
|
||||
* Course module context class
|
||||
* @author Petr Skoda (http://skodak.org)
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_module extends context {
|
||||
/**
|
||||
@ -6471,6 +6476,7 @@ class context_module extends context {
|
||||
/**
|
||||
* Block context class
|
||||
* @author Petr Skoda (http://skodak.org)
|
||||
* @since 2.2
|
||||
*/
|
||||
class context_block extends context {
|
||||
/**
|
||||
@ -6681,12 +6687,20 @@ class context_block extends context {
|
||||
}
|
||||
|
||||
|
||||
// ============== DEPRECATED ========================
|
||||
// ============== DEPRECATED FUNCTIONS ==========================================
|
||||
// Old context related functions were deprecated in 2.0, it is recommended
|
||||
// to use context classes in new code. Old function can be used when
|
||||
// creating patches that are supposed to be backported to older stable branches.
|
||||
// These deprecated functions will not be removed in near future,
|
||||
// before removing devs will be warned with a debugging message first,
|
||||
// then we will add error message and only after that we can remove the functions
|
||||
// completely.
|
||||
|
||||
|
||||
/**
|
||||
* Use load_temp_course_role() instead.
|
||||
* @deprecated
|
||||
* Not available any more, use load_temp_course_role() instead.
|
||||
*
|
||||
* @deprecated since 2.2
|
||||
* @param stdClass $context
|
||||
* @param int $roleid
|
||||
* @param array $accessdata
|
||||
@ -6698,8 +6712,9 @@ function load_temp_role($context, $roleid, array $accessdata) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use remove_temp_course_roles() instead
|
||||
* @deprecated
|
||||
* Not available any more, use remove_temp_course_roles() instead.
|
||||
*
|
||||
* @deprecated since 2.2
|
||||
* @param object $context
|
||||
* @param array $accessdata
|
||||
* @return array access data
|
||||
@ -6712,7 +6727,7 @@ function remove_temp_roles($context, array $accessdata) {
|
||||
/**
|
||||
* Returns system context or null if can not be created yet.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use context_system::instance()
|
||||
* @param bool $cache use caching
|
||||
* @return context system context (null if context table not created yet)
|
||||
*/
|
||||
@ -6724,7 +6739,7 @@ function get_system_context($cache = true) {
|
||||
* Get the context instance as an object. This function will create the
|
||||
* context instance if it does not exist yet.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use context_course::instance() or other relevant class instead
|
||||
* @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
|
||||
* @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
|
||||
* for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
|
||||
@ -6753,7 +6768,7 @@ function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE
|
||||
/**
|
||||
* Get a context instance as an object, from a given context id.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use context::instance_by_id($id) instead
|
||||
* @param int $id context id
|
||||
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
|
||||
* MUST_EXIST means throw exception if no record or multiple records found
|
||||
@ -6768,7 +6783,7 @@ function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
|
||||
* and return the array in reverse order, i.e. parent first, then grand
|
||||
* parent, etc.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->get_parent_context_ids() instead
|
||||
* @param context $context
|
||||
* @param bool $includeself optional, defaults to false
|
||||
* @return array
|
||||
@ -6781,7 +6796,7 @@ function get_parent_contexts(context $context, $includeself = false) {
|
||||
* Return the id of the parent of this context, or false if there is no parent (only happens if this
|
||||
* is the site context.)
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->get_parent_context() instead
|
||||
* @param context $context
|
||||
* @return integer the id of the parent context.
|
||||
*/
|
||||
@ -6806,7 +6821,7 @@ function get_parent_contextid(context $context) {
|
||||
* If called on a user/course/module context it _will_ populate the cache with the appropriate
|
||||
* contexts ;-)
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->get_child_contexts() instead
|
||||
* @param context $context.
|
||||
* @return array Array of child records
|
||||
*/
|
||||
@ -6817,7 +6832,7 @@ function get_child_contexts(context $context) {
|
||||
/**
|
||||
* Precreates all contexts including all parents
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param int $contextlevel empty means all
|
||||
* @param bool $buildpaths update paths and depths
|
||||
* @return void
|
||||
@ -6829,7 +6844,7 @@ function create_contexts($contextlevel = null, $buildpaths = true) {
|
||||
/**
|
||||
* Remove stale context records
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use context_helper::cleanup_instances() instead
|
||||
* @return bool
|
||||
*/
|
||||
function cleanup_contexts() {
|
||||
@ -6840,7 +6855,7 @@ function cleanup_contexts() {
|
||||
/**
|
||||
* Populate context.path and context.depth where missing.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use context_helper::build_all_paths() instead
|
||||
* @param bool $force force a complete rebuild of the path and depth fields, defaults to false
|
||||
* @return void
|
||||
*/
|
||||
@ -6867,7 +6882,7 @@ function rebuild_contexts(array $fixcontexts) {
|
||||
* are no longer loaded here. The contexts for all the blocks on the current
|
||||
* page are now efficiently loaded by {@link block_manager::load_blocks()}.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param int $courseid Course ID
|
||||
* @return void
|
||||
*/
|
||||
@ -6895,7 +6910,7 @@ function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
|
||||
* Preloads context information from db record and strips the cached info.
|
||||
* The db request has to contain both the $join and $select from context_instance_preload_sql()
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param stdClass $rec
|
||||
* @return void (modifies $rec)
|
||||
*/
|
||||
@ -6906,9 +6921,7 @@ function context_instance_preload(stdClass $rec) {
|
||||
/**
|
||||
* Mark a context as dirty (with timestamp) so as to force reloading of the context.
|
||||
*
|
||||
* NOTE: use $context->mark_dirty() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->mark_dirty() instead
|
||||
* @param string $path context path
|
||||
*/
|
||||
function mark_context_dirty($path) {
|
||||
@ -6949,7 +6962,7 @@ function mark_context_dirty($path) {
|
||||
* DB efficient as possible. This op can have a
|
||||
* massive impact in the DB.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param context $context context obj
|
||||
* @param context $newparent new parent obj
|
||||
* @return void
|
||||
@ -6962,7 +6975,7 @@ function context_moved(context $context, context $newparent) {
|
||||
* Remove a context record and any dependent entries,
|
||||
* removes context from static context cache too
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->delete_content() instead
|
||||
* @param int $contextlevel
|
||||
* @param int $instanceid
|
||||
* @param bool $deleterecord false means keep record for now
|
||||
@ -6982,8 +6995,8 @@ function delete_context($contextlevel, $instanceid, $deleterecord = true) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated
|
||||
* Returns context level name
|
||||
* @deprecated since 2.2
|
||||
* @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
|
||||
* @return string the name for this type of context.
|
||||
*/
|
||||
@ -6994,7 +7007,7 @@ function get_contextlevel_name($contextlevel) {
|
||||
/**
|
||||
* Prints human readable context identifier.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param context $context the context.
|
||||
* @param boolean $withprefix whether to prefix the name of the context with the
|
||||
* type of context, e.g. User, Course, Forum, etc.
|
||||
@ -7011,7 +7024,7 @@ function print_context_name(context $context, $withprefix = true, $short = false
|
||||
* CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
|
||||
* user profile page.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param context $context the context.
|
||||
* @return moodle_url
|
||||
*/
|
||||
@ -7023,7 +7036,7 @@ function get_context_url(context $context) {
|
||||
* Is this context part of any course? if yes return course context,
|
||||
* if not return null or throw exception.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->get_course_context() instead
|
||||
* @param context $context
|
||||
* @return course_context context of the enclosing course, null if not found or exception
|
||||
*/
|
||||
@ -7034,7 +7047,7 @@ function get_course_context(context $context) {
|
||||
/**
|
||||
* Returns current course id or null if outside of course based on context parameter.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use $context->get_course_context instead
|
||||
* @param context $context
|
||||
* @return int|bool related course id or false
|
||||
*/
|
||||
@ -7050,7 +7063,7 @@ function get_courseid_from_context(context $context) {
|
||||
* Get an array of courses where cap requested is available
|
||||
* and user is enrolled, this can be relatively slow.
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, use enrol_get_users_courses() instead
|
||||
* @param int $userid A user id. By default (null) checks the permissions of the current user.
|
||||
* @param string $cap - name of the capability
|
||||
* @param array $accessdata_ignored
|
||||
@ -7085,7 +7098,7 @@ function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_
|
||||
* `contextlevel` int(10) NOT NULL,
|
||||
* `component` varchar(100) NOT NULL,
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param context $context
|
||||
* @return array
|
||||
*/
|
||||
@ -7100,7 +7113,7 @@ function fetch_context_capabilities(context $context) {
|
||||
* for the purpose of $select, you need to know that the context table has been
|
||||
* aliased to ctx, so for example, you can call get_sorted_contexts('ctx.depth = 3');
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param string $select the contents of the WHERE clause. Remember to do ctx.fieldname.
|
||||
* @param array $params any parameters required by $select.
|
||||
* @return array the requested context records.
|
||||
@ -7129,7 +7142,7 @@ function get_sorted_contexts($select, $params = array()) {
|
||||
/**
|
||||
* This is really slow!!! do not use above course context level
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2
|
||||
* @param int $roleid
|
||||
* @param context $context
|
||||
* @return array
|
||||
@ -7175,7 +7188,7 @@ function get_role_context_caps($roleid, context $context) {
|
||||
*
|
||||
* NOTE: use $DB->get_in_or_equal($context->get_parent_context_ids()...
|
||||
*
|
||||
* @deprecated
|
||||
* @deprecated since 2.2, $context->use get_parent_context_ids() instead
|
||||
* @param context $context
|
||||
* @return string
|
||||
*/
|
||||
|
196
lib/base32.php
196
lib/base32.php
@ -1,196 +0,0 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Base32 Library |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is dual-licensed. It is available under the terms |
|
||||
// | of the GNU GPL v2.0 and under the terms of the PHP license version |
|
||||
// | 2.02, available at through the world-wide-web at |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Minor fixes and additional functions by Allan Hansen. |
|
||||
// | Moodle porting work by Martin Langhoff |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | base32.php - based on race.php - RACE encode and decode strings. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Allan Hansen <All@nHansen.dk> |
|
||||
// | Arjan Wekking <a.wekking@synantics.nl> |
|
||||
// | Martin Langhoff <martin@catalyst.net.nz> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
/**
|
||||
* @package moodlecore
|
||||
* @copyright (c) 2001 The PHP Group
|
||||
* @license GNU GPL v2.0 http://www.php.net/license/2_02.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base32 encode a binary string
|
||||
*
|
||||
* @param $inString Binary string to base32 encode
|
||||
*
|
||||
* @return $outString Base32 encoded $inString
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
|
||||
function base32_encode ($inString)
|
||||
{
|
||||
$outString = "";
|
||||
$compBits = "";
|
||||
$BASE32_TABLE = array(
|
||||
'00000' => 0x61,
|
||||
'00001' => 0x62,
|
||||
'00010' => 0x63,
|
||||
'00011' => 0x64,
|
||||
'00100' => 0x65,
|
||||
'00101' => 0x66,
|
||||
'00110' => 0x67,
|
||||
'00111' => 0x68,
|
||||
'01000' => 0x69,
|
||||
'01001' => 0x6a,
|
||||
'01010' => 0x6b,
|
||||
'01011' => 0x6c,
|
||||
'01100' => 0x6d,
|
||||
'01101' => 0x6e,
|
||||
'01110' => 0x6f,
|
||||
'01111' => 0x70,
|
||||
'10000' => 0x71,
|
||||
'10001' => 0x72,
|
||||
'10010' => 0x73,
|
||||
'10011' => 0x74,
|
||||
'10100' => 0x75,
|
||||
'10101' => 0x76,
|
||||
'10110' => 0x77,
|
||||
'10111' => 0x78,
|
||||
'11000' => 0x79,
|
||||
'11001' => 0x7a,
|
||||
'11010' => 0x32,
|
||||
'11011' => 0x33,
|
||||
'11100' => 0x34,
|
||||
'11101' => 0x35,
|
||||
'11110' => 0x36,
|
||||
'11111' => 0x37,
|
||||
);
|
||||
|
||||
/* Turn the compressed string into a string that represents the bits as 0 and 1. */
|
||||
for ($i = 0; $i < strlen($inString); $i++) {
|
||||
$compBits .= str_pad(decbin(ord(substr($inString,$i,1))), 8, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/* Pad the value with enough 0's to make it a multiple of 5 */
|
||||
if((strlen($compBits) % 5) != 0) {
|
||||
$compBits = str_pad($compBits, strlen($compBits)+(5-(strlen($compBits)%5)), '0', STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
/* Create an array by chunking it every 5 chars */
|
||||
$fiveBitsArray = explode("\n",rtrim(chunk_split($compBits, 5, "\n")));
|
||||
|
||||
/* Look-up each chunk and add it to $outstring */
|
||||
foreach($fiveBitsArray as $fiveBitsString) {
|
||||
$outString .= chr($BASE32_TABLE[$fiveBitsString]);
|
||||
}
|
||||
|
||||
return $outString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Base32 decode to a binary string
|
||||
*
|
||||
* @param $inString String to base32 decode
|
||||
*
|
||||
* @return $outString Base32 decoded $inString
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
|
||||
function Base32_decode($inString) {
|
||||
/* declaration */
|
||||
$inputCheck = null;
|
||||
$deCompBits = null;
|
||||
|
||||
$BASE32_TABLE = array(
|
||||
0x61 => '00000',
|
||||
0x62 => '00001',
|
||||
0x63 => '00010',
|
||||
0x64 => '00011',
|
||||
0x65 => '00100',
|
||||
0x66 => '00101',
|
||||
0x67 => '00110',
|
||||
0x68 => '00111',
|
||||
0x69 => '01000',
|
||||
0x6a => '01001',
|
||||
0x6b => '01010',
|
||||
0x6c => '01011',
|
||||
0x6d => '01100',
|
||||
0x6e => '01101',
|
||||
0x6f => '01110',
|
||||
0x70 => '01111',
|
||||
0x71 => '10000',
|
||||
0x72 => '10001',
|
||||
0x73 => '10010',
|
||||
0x74 => '10011',
|
||||
0x75 => '10100',
|
||||
0x76 => '10101',
|
||||
0x77 => '10110',
|
||||
0x78 => '10111',
|
||||
0x79 => '11000',
|
||||
0x7a => '11001',
|
||||
0x32 => '11010',
|
||||
0x33 => '11011',
|
||||
0x34 => '11100',
|
||||
0x35 => '11101',
|
||||
0x36 => '11110',
|
||||
0x37 => '11111',
|
||||
);
|
||||
|
||||
/* Step 1 */
|
||||
$inputCheck = strlen($inString) % 8;
|
||||
if(($inputCheck == 1)||($inputCheck == 3)||($inputCheck == 6)) {
|
||||
trigger_error('input to Base32Decode was a bad mod length: '.$inputCheck);
|
||||
return false;
|
||||
//return $this->raiseError('input to Base32Decode was a bad mod length: '.$inputCheck, null,
|
||||
// PEAR_ERROR_DIE, null, null, 'Net_RACE_Error', false );
|
||||
}
|
||||
|
||||
/* $deCompBits is a string that represents the bits as 0 and 1.*/
|
||||
for ($i = 0; $i < strlen($inString); $i++) {
|
||||
$inChar = ord(substr($inString,$i,1));
|
||||
if(isset($BASE32_TABLE[$inChar])) {
|
||||
$deCompBits .= $BASE32_TABLE[$inChar];
|
||||
} else {
|
||||
trigger_error('input to Base32Decode had a bad character: '.$inChar);
|
||||
return false;
|
||||
//return $this->raiseError('input to Base32Decode had a bad character: '.$inChar, null,
|
||||
// PEAR_ERROR_DIE, null, null, 'Net_RACE_Error', false );
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 5 */
|
||||
$padding = strlen($deCompBits) % 8;
|
||||
$paddingContent = substr($deCompBits, (strlen($deCompBits) - $padding));
|
||||
if(substr_count($paddingContent, '1')>0) {
|
||||
trigger_error('found non-zero padding in Base32Decode');
|
||||
return false;
|
||||
//return $this->raiseError('found non-zero padding in Base32Decode', null,
|
||||
// PEAR_ERROR_DIE, null, null, 'Net_RACE_Error', false );
|
||||
}
|
||||
|
||||
/* Break the decompressed string into octets for returning */
|
||||
$deArr = array();
|
||||
for($i = 0; $i < (int)(strlen($deCompBits) / 8); $i++) {
|
||||
$deArr[$i] = chr(bindec(substr($deCompBits, $i*8, 8)));
|
||||
}
|
||||
|
||||
$outString = join('',$deArr);
|
||||
|
||||
return $outString;
|
||||
}
|
632
lib/cronlib.php
632
lib/cronlib.php
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -24,6 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Execute cron tasks
|
||||
*/
|
||||
function cron_run() {
|
||||
global $DB, $CFG, $OUTPUT;
|
||||
|
||||
@ -51,26 +53,195 @@ function cron_run() {
|
||||
set_time_limit(0);
|
||||
$starttime = microtime();
|
||||
|
||||
/// increase memory limit
|
||||
// Increase memory limit
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
|
||||
/// emulate normal session
|
||||
// Emulate normal session - we use admin accoutn by default
|
||||
cron_setup_user();
|
||||
|
||||
/// Start output log
|
||||
|
||||
// Start output log
|
||||
$timenow = time();
|
||||
|
||||
mtrace("Server Time: ".date('r',$timenow)."\n\n");
|
||||
|
||||
|
||||
/// Session gc
|
||||
// Run cleanup core cron jobs, but not every time since they aren't too important.
|
||||
// These don't have a timer to reduce load, so we'll use a random number
|
||||
// to randomly choose the percentage of times we should run these jobs.
|
||||
srand ((double) microtime() * 10000000);
|
||||
$random100 = rand(0,100);
|
||||
if ($random100 < 20) { // Approximately 20% of the time.
|
||||
mtrace("Running clean-up tasks...");
|
||||
|
||||
mtrace("Cleaning up stale sessions");
|
||||
// Delete users who haven't confirmed within required period
|
||||
if (!empty($CFG->deleteunconfirmed)) {
|
||||
$cuttime = $timenow - ($CFG->deleteunconfirmed * 3600);
|
||||
$rs = $DB->get_recordset_sql ("SELECT *
|
||||
FROM {user}
|
||||
WHERE confirmed = 0 AND firstaccess > 0
|
||||
AND firstaccess < ?", array($cuttime));
|
||||
foreach ($rs as $user) {
|
||||
delete_user($user); // we MUST delete user properly first
|
||||
$DB->delete_records('user', array('id'=>$user->id)); // this is a bloody hack, but it might work
|
||||
mtrace(" Deleted unconfirmed user for ".fullname($user, true)." ($user->id)");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
|
||||
// Delete users who haven't completed profile within required period
|
||||
if (!empty($CFG->deleteincompleteusers)) {
|
||||
$cuttime = $timenow - ($CFG->deleteincompleteusers * 3600);
|
||||
$rs = $DB->get_recordset_sql ("SELECT *
|
||||
FROM {user}
|
||||
WHERE confirmed = 1 AND lastaccess > 0
|
||||
AND lastaccess < ? AND deleted = 0
|
||||
AND (lastname = '' OR firstname = '' OR email = '')",
|
||||
array($cuttime));
|
||||
foreach ($rs as $user) {
|
||||
delete_user($user);
|
||||
mtrace(" Deleted not fully setup user $user->username ($user->id)");
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
|
||||
// Delete old logs to save space (this might need a timer to slow it down...)
|
||||
if (!empty($CFG->loglifetime)) { // value in days
|
||||
$loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
|
||||
$DB->delete_records_select("log", "time < ?", array($loglifetime));
|
||||
mtrace(" Deleted old log records");
|
||||
}
|
||||
|
||||
|
||||
// Delete old backup_controllers and logs
|
||||
if (!empty($CFG->loglifetime)) { // value in days
|
||||
$loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
|
||||
// Delete child records from backup_logs
|
||||
$DB->execute("DELETE FROM {backup_logs}
|
||||
WHERE EXISTS (
|
||||
SELECT 'x'
|
||||
FROM {backup_controllers} bc
|
||||
WHERE bc.backupid = {backup_logs}.backupid
|
||||
AND bc.timecreated < ?)", array($loglifetime));
|
||||
// Delete records from backup_controllers
|
||||
$DB->execute("DELETE FROM {backup_controllers}
|
||||
WHERE timecreated < ?", array($loglifetime));
|
||||
mtrace(" Deleted old backup records");
|
||||
}
|
||||
|
||||
|
||||
// Delete old cached texts
|
||||
if (!empty($CFG->cachetext)) { // Defined in config.php
|
||||
$cachelifetime = time() - $CFG->cachetext - 60; // Add an extra minute to allow for really heavy sites
|
||||
$DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
|
||||
mtrace(" Deleted old cache_text records");
|
||||
}
|
||||
|
||||
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
tag_cron();
|
||||
mtrace(' Executed tag cron');
|
||||
}
|
||||
|
||||
|
||||
// Context maintenance stuff
|
||||
context_helper::cleanup_instances();
|
||||
mtrace(' Cleaned up context instances');
|
||||
context_helper::build_all_paths(false);
|
||||
// If you suspect that the context paths are somehow corrupt
|
||||
// replace the line below with: context_helper::build_all_paths(true);
|
||||
mtrace(' Built context paths');
|
||||
|
||||
|
||||
// Remove expired cache flags
|
||||
gc_cache_flags();
|
||||
mtrace(' Cleaned cache flags');
|
||||
|
||||
|
||||
// Cleanup messaging
|
||||
if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
|
||||
$notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
|
||||
$DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime'=>$notificationdeletetime));
|
||||
mtrace(' Cleaned up read notifications');
|
||||
}
|
||||
|
||||
mtrace("...finished clean-up tasks");
|
||||
|
||||
} // End of occasional clean-up tasks
|
||||
|
||||
|
||||
// Send login failures notification - brute force protection in moodle is weak,
|
||||
// we should at least send notices early in each cron execution
|
||||
if (!empty($CFG->notifyloginfailures)) {
|
||||
notify_login_failures();
|
||||
mtrace(' Notified login failured');
|
||||
}
|
||||
|
||||
|
||||
// Make sure all context instances are properly created - they may be required in auth, enrol, etc.
|
||||
context_helper::create_instances();
|
||||
mtrace(' Created missing context instances');
|
||||
|
||||
|
||||
// Session gc
|
||||
session_gc();
|
||||
mtrace("Cleaned up stale user sessions");
|
||||
|
||||
/// Run all cron jobs for each module
|
||||
|
||||
// Run the auth cron, if any before enrolments
|
||||
// because it might add users that will be needed in enrol plugins
|
||||
$auths = get_enabled_auth_plugins();
|
||||
mtrace("Running auth crons if required...");
|
||||
foreach ($auths as $auth) {
|
||||
$authplugin = get_auth_plugin($auth);
|
||||
if (method_exists($authplugin, 'cron')) {
|
||||
mtrace("Running cron for auth/$auth...");
|
||||
$authplugin->cron();
|
||||
if (!empty($authplugin->log)) {
|
||||
mtrace($authplugin->log);
|
||||
}
|
||||
}
|
||||
unset($authplugin);
|
||||
}
|
||||
// Generate new password emails for users - ppl expect these generated asap
|
||||
if ($DB->count_records('user_preferences', array('name'=>'create_password', 'value'=>'1'))) {
|
||||
mtrace('Creating passwords for new users...');
|
||||
$newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.firstname,
|
||||
u.lastname, u.username,
|
||||
p.id as prefid
|
||||
FROM {user} u
|
||||
JOIN {user_preferences} p ON u.id=p.userid
|
||||
WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
|
||||
|
||||
foreach ($newusers as $newuser) {
|
||||
if (setnew_password_and_mail($newuser)) {
|
||||
unset_user_preference('create_password', $newuser);
|
||||
set_user_preference('auth_forcepasswordchange', 1, $newuser);
|
||||
} else {
|
||||
trigger_error("Could not create and mail new user password!");
|
||||
}
|
||||
}
|
||||
$newusers->close();
|
||||
}
|
||||
|
||||
|
||||
// It is very important to run enrol early
|
||||
// because other plugins depend on correct enrolment info.
|
||||
mtrace("Running enrol crons if required...");
|
||||
$enrols = enrol_get_plugins(true);
|
||||
foreach($enrols as $ename=>$enrol) {
|
||||
// do this for all plugins, disabled plugins might want to cleanup stuff such as roles
|
||||
if (!$enrol->is_cron_required()) {
|
||||
continue;
|
||||
}
|
||||
mtrace("Running cron for enrol_$ename...");
|
||||
$enrol->cron();
|
||||
$enrol->set_config('lastcron', time());
|
||||
}
|
||||
|
||||
|
||||
// Run all cron jobs for each module
|
||||
mtrace("Starting activity modules");
|
||||
get_mailer('buffer');
|
||||
if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
|
||||
@ -91,7 +262,7 @@ function cron_run() {
|
||||
mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
|
||||
mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
|
||||
}
|
||||
/// Reset possible changes by modules to time_limit. MDL-11597
|
||||
// Reset possible changes by modules to time_limit. MDL-11597
|
||||
@set_time_limit(0);
|
||||
mtrace("done.");
|
||||
}
|
||||
@ -101,9 +272,10 @@ function cron_run() {
|
||||
get_mailer('close');
|
||||
mtrace("Finished activity modules");
|
||||
|
||||
|
||||
mtrace("Starting blocks");
|
||||
if ($blocks = $DB->get_records_select("block", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
|
||||
// we will need the base class.
|
||||
// We will need the base class.
|
||||
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
|
||||
foreach ($blocks as $block) {
|
||||
$blockfile = $CFG->dirroot.'/blocks/'.$block->name.'/block_'.$block->name.'.php';
|
||||
@ -116,7 +288,7 @@ function cron_run() {
|
||||
if ($blockobj->cron()) {
|
||||
$DB->set_field('block', 'lastcron', $timenow, array('id'=>$block->id));
|
||||
}
|
||||
/// Reset possible changes by blocks to time_limit. MDL-11597
|
||||
// Reset possible changes by blocks to time_limit. MDL-11597
|
||||
@set_time_limit(0);
|
||||
mtrace('done.');
|
||||
}
|
||||
@ -126,6 +298,8 @@ function cron_run() {
|
||||
}
|
||||
mtrace('Finished blocks');
|
||||
|
||||
|
||||
//TODO: get rid of this bloody hardcoded quiz module stuff, this must be done from quiz_cron()!
|
||||
mtrace("Starting quiz reports");
|
||||
if ($reports = $DB->get_records_select('quiz_reports', "cron > 0 AND ((? - lastcron) > cron)", array($timenow))) {
|
||||
foreach ($reports as $report) {
|
||||
@ -145,6 +319,7 @@ function cron_run() {
|
||||
mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
|
||||
mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
|
||||
}
|
||||
@set_time_limit(0);
|
||||
mtrace("done.");
|
||||
}
|
||||
}
|
||||
@ -152,11 +327,13 @@ function cron_run() {
|
||||
}
|
||||
mtrace("Finished quiz reports");
|
||||
|
||||
|
||||
mtrace('Starting admin reports');
|
||||
cron_execute_plugin_type('report');
|
||||
mtrace('Finished admin reports');
|
||||
|
||||
mtrace('Starting main gradebook job ...');
|
||||
|
||||
mtrace('Starting main gradebook job...');
|
||||
grade_cron();
|
||||
mtrace('done.');
|
||||
|
||||
@ -183,189 +360,101 @@ function cron_run() {
|
||||
mtrace('done');
|
||||
}
|
||||
|
||||
|
||||
//now do plagiarism checks
|
||||
require_once($CFG->libdir.'/plagiarismlib.php');
|
||||
plagiarism_cron();
|
||||
|
||||
/// Run all core cron jobs, but not every time since they aren't too important.
|
||||
/// These don't have a timer to reduce load, so we'll use a random number
|
||||
/// to randomly choose the percentage of times we should run these jobs.
|
||||
|
||||
srand ((double) microtime() * 10000000);
|
||||
$random100 = rand(0,100);
|
||||
mtrace('Starting course reports');
|
||||
cron_execute_plugin_type('coursereport');
|
||||
mtrace('Finished course reports');
|
||||
|
||||
if ($random100 < 20) { // Approximately 20% of the time.
|
||||
mtrace("Running clean-up tasks...");
|
||||
|
||||
/// Delete users who haven't confirmed within required period
|
||||
// run gradebook import/export/report cron
|
||||
mtrace('Starting gradebook plugins');
|
||||
cron_execute_plugin_type('gradeimport');
|
||||
cron_execute_plugin_type('gradeexport');
|
||||
cron_execute_plugin_type('gradereport');
|
||||
mtrace('Finished gradebook plugins');
|
||||
|
||||
if (!empty($CFG->deleteunconfirmed)) {
|
||||
$cuttime = $timenow - ($CFG->deleteunconfirmed * 3600);
|
||||
$rs = $DB->get_recordset_sql ("SELECT id, firstname, lastname
|
||||
FROM {user}
|
||||
WHERE confirmed = 0 AND firstaccess > 0
|
||||
AND firstaccess < ?", array($cuttime));
|
||||
foreach ($rs as $user) {
|
||||
if ($DB->delete_records('user', array('id'=>$user->id))) {
|
||||
mtrace("Deleted unconfirmed user for ".fullname($user, true)." ($user->id)");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// Run external blog cron if needed
|
||||
if ($CFG->useexternalblogs) {
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
mtrace("Fetching external blog entries...", '');
|
||||
$sql = "timefetched < ? OR timefetched = 0";
|
||||
$externalblogs = $DB->get_records_select('blog_external', $sql, array(mktime() - $CFG->externalblogcrontime));
|
||||
|
||||
foreach ($externalblogs as $eb) {
|
||||
blog_sync_external_entries($eb);
|
||||
}
|
||||
flush();
|
||||
mtrace('done.');
|
||||
}
|
||||
// Run blog associations cleanup
|
||||
if ($CFG->useblogassociations) {
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
// delete entries whose contextids no longer exists
|
||||
mtrace("Deleting blog associations linked to non-existent contexts...", '');
|
||||
$DB->delete_records_select('blog_association', 'contextid NOT IN (SELECT id FROM {context})');
|
||||
mtrace('done.');
|
||||
}
|
||||
|
||||
|
||||
/// Delete users who haven't completed profile within required period
|
||||
|
||||
if (!empty($CFG->deleteincompleteusers)) {
|
||||
$cuttime = $timenow - ($CFG->deleteincompleteusers * 3600);
|
||||
$rs = $DB->get_recordset_sql ("SELECT *
|
||||
FROM {user}
|
||||
WHERE confirmed = 1 AND lastaccess > 0
|
||||
AND lastaccess < ? AND deleted = 0
|
||||
AND (lastname = '' OR firstname = '' OR email = '')",
|
||||
array($cuttime));
|
||||
foreach ($rs as $user) {
|
||||
if (delete_user($user)) {
|
||||
mtrace("Deleted not fully setup user $user->username ($user->id)");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
flush();
|
||||
//Run registration updated cron
|
||||
mtrace(get_string('siteupdatesstart', 'hub'));
|
||||
require_once($CFG->dirroot . '/admin/registration/lib.php');
|
||||
$registrationmanager = new registration_manager();
|
||||
$registrationmanager->cron();
|
||||
mtrace(get_string('siteupdatesend', 'hub'));
|
||||
|
||||
|
||||
/// Delete old logs to save space (this might need a timer to slow it down...)
|
||||
//cleanup old session linked tokens
|
||||
//deletes the session linked tokens that are over a day old.
|
||||
mtrace("Deleting session linked tokens more than one day old...", '');
|
||||
$DB->delete_records_select('external_tokens', 'lastaccess < :onedayago AND tokentype = :tokentype',
|
||||
array('onedayago' => time() - DAYSECS, 'tokentype' => EXTERNAL_TOKEN_EMBEDDED));
|
||||
mtrace('done.');
|
||||
|
||||
if (!empty($CFG->loglifetime)) { // value in days
|
||||
$loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
|
||||
if ($DB->delete_records_select("log", "time < ?", array($loglifetime))) {
|
||||
mtrace("Deleted old log records");
|
||||
|
||||
// all other plugins
|
||||
cron_execute_plugin_type('message', 'message plugins');
|
||||
cron_execute_plugin_type('filter', 'filters');
|
||||
cron_execute_plugin_type('editor', 'editors');
|
||||
cron_execute_plugin_type('format', 'course formats');
|
||||
cron_execute_plugin_type('profilefield', 'profile fields');
|
||||
cron_execute_plugin_type('webservice', 'webservices');
|
||||
// TODO: Repository lib.php files are messed up (include many other files, etc), so it is
|
||||
// currently not possible to implement repository plugin cron using this infrastructure
|
||||
// cron_execute_plugin_type('repository', 'repository plugins');
|
||||
cron_execute_plugin_type('qtype', 'question types');
|
||||
cron_execute_plugin_type('plagiarism', 'plagiarism plugins');
|
||||
cron_execute_plugin_type('theme', 'themes');
|
||||
cron_execute_plugin_type('tool', 'admin tools');
|
||||
|
||||
|
||||
// and finally run any local cronjobs, if any
|
||||
if ($locals = get_plugin_list('local')) {
|
||||
mtrace('Processing customized cron scripts ...', '');
|
||||
// new cron functions in lib.php first
|
||||
cron_execute_plugin_type('local');
|
||||
// legacy cron files are executed directly
|
||||
foreach ($locals as $local => $localdir) {
|
||||
if (file_exists("$localdir/cron.php")) {
|
||||
include("$localdir/cron.php");
|
||||
}
|
||||
}
|
||||
flush();
|
||||
|
||||
// Delete old backup_controllers and logs
|
||||
|
||||
if (!empty($CFG->loglifetime)) { // value in days
|
||||
$loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
|
||||
// Delete child records from backup_logs
|
||||
$DB->execute("DELETE FROM {backup_logs}
|
||||
WHERE EXISTS (
|
||||
SELECT 'x'
|
||||
FROM {backup_controllers} bc
|
||||
WHERE bc.backupid = {backup_logs}.backupid
|
||||
AND bc.timecreated < ?)", array($loglifetime));
|
||||
// Delete records from backup_controllers
|
||||
$DB->execute("DELETE FROM {backup_controllers}
|
||||
WHERE timecreated < ?", array($loglifetime));
|
||||
mtrace("Deleted old backup records");
|
||||
}
|
||||
flush();
|
||||
mtrace('done.');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Delete old cached texts
|
||||
|
||||
if (!empty($CFG->cachetext)) { // Defined in config.php
|
||||
$cachelifetime = time() - $CFG->cachetext - 60; // Add an extra minute to allow for really heavy sites
|
||||
if ($DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime))) {
|
||||
mtrace("Deleted old cache_text records");
|
||||
}
|
||||
}
|
||||
flush();
|
||||
|
||||
if (!empty($CFG->notifyloginfailures)) {
|
||||
notify_login_failures();
|
||||
mtrace('Notified login failured');
|
||||
}
|
||||
flush();
|
||||
|
||||
//
|
||||
// generate new password emails for users
|
||||
//
|
||||
mtrace('checking for create_password');
|
||||
if ($DB->count_records('user_preferences', array('name'=>'create_password', 'value'=>'1'))) {
|
||||
mtrace('creating passwords for new users');
|
||||
$newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.firstname,
|
||||
u.lastname, u.username,
|
||||
p.id as prefid
|
||||
FROM {user} u
|
||||
JOIN {user_preferences} p ON u.id=p.userid
|
||||
WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
|
||||
|
||||
foreach ($newusers as $newuser) {
|
||||
// email user
|
||||
if (setnew_password_and_mail($newuser)) {
|
||||
unset_user_preference('create_password', $newuser);
|
||||
set_user_preference('auth_forcepasswordchange', 1, $newuser);
|
||||
} else {
|
||||
trigger_error("Could not create and mail new user password!");
|
||||
}
|
||||
}
|
||||
$newusers->close();
|
||||
}
|
||||
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
tag_cron();
|
||||
mtrace ('Executed tag cron');
|
||||
}
|
||||
|
||||
// Accesslib stuff
|
||||
cleanup_contexts();
|
||||
mtrace ('Cleaned up contexts');
|
||||
gc_cache_flags();
|
||||
mtrace ('Cleaned cache flags');
|
||||
// If you suspect that the context paths are somehow corrupt
|
||||
// replace the line below with: build_context_path(true);
|
||||
build_context_path();
|
||||
mtrace ('Built context paths');
|
||||
|
||||
if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
|
||||
$notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
|
||||
$DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime'=>$notificationdeletetime));
|
||||
mtrace('Cleaned up read notifications');
|
||||
}
|
||||
|
||||
mtrace("Finished clean-up tasks...");
|
||||
|
||||
} // End of occasional clean-up tasks
|
||||
|
||||
// Run automated backups if required.
|
||||
// Run automated backups if required - these may take a long time to execute
|
||||
require_once($CFG->dirroot.'/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
|
||||
backup_cron_automated_helper::run_automated_backup();
|
||||
|
||||
/// Run the auth cron, if any
|
||||
/// before enrolments because it might add users that will be needed in enrol plugins
|
||||
$auths = get_enabled_auth_plugins();
|
||||
|
||||
mtrace("Running auth crons if required...");
|
||||
foreach ($auths as $auth) {
|
||||
$authplugin = get_auth_plugin($auth);
|
||||
if (method_exists($authplugin, 'cron')) {
|
||||
mtrace("Running cron for auth/$auth...");
|
||||
$authplugin->cron();
|
||||
if (!empty($authplugin->log)) {
|
||||
mtrace($authplugin->log);
|
||||
}
|
||||
}
|
||||
unset($authplugin);
|
||||
}
|
||||
|
||||
mtrace("Running enrol crons if required...");
|
||||
$enrols = enrol_get_plugins(true);
|
||||
foreach($enrols as $ename=>$enrol) {
|
||||
// do this for all plugins, disabled plugins might want to cleanup stuff such as roles
|
||||
if (!$enrol->is_cron_required()) {
|
||||
continue;
|
||||
}
|
||||
mtrace("Running cron for enrol_$ename...");
|
||||
$enrol->cron();
|
||||
$enrol->set_config('lastcron', time());
|
||||
}
|
||||
|
||||
// Run stats as at the end because they are known to take very long time on large sites
|
||||
if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
|
||||
require_once($CFG->dirroot.'/lib/statslib.php');
|
||||
// check we're not before our runtime
|
||||
@ -388,85 +477,10 @@ function cron_run() {
|
||||
}
|
||||
|
||||
|
||||
mtrace('Starting course reports');
|
||||
cron_execute_plugin_type('coursereport');
|
||||
mtrace('Finished course reports');
|
||||
|
||||
// run gradebook import/export/report cron
|
||||
mtrace('Starting gradebook plugins');
|
||||
cron_execute_plugin_type('gradeimport');
|
||||
cron_execute_plugin_type('gradeexport');
|
||||
cron_execute_plugin_type('gradereport');
|
||||
mtrace('Finished gradebook plugins');
|
||||
|
||||
// Run external blog cron if needed
|
||||
if ($CFG->useexternalblogs) {
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
mtrace("Fetching external blog entries...", '');
|
||||
$sql = "timefetched < ? OR timefetched = 0";
|
||||
$externalblogs = $DB->get_records_select('blog_external', $sql, array(mktime() - $CFG->externalblogcrontime));
|
||||
|
||||
foreach ($externalblogs as $eb) {
|
||||
blog_sync_external_entries($eb);
|
||||
}
|
||||
mtrace('done.');
|
||||
}
|
||||
|
||||
// Run blog associations cleanup
|
||||
if ($CFG->useblogassociations) {
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
// delete entries whose contextids no longer exists
|
||||
mtrace("Deleting blog associations linked to non-existent contexts...", '');
|
||||
$DB->delete_records_select('blog_association', 'contextid NOT IN (SELECT id FROM {context})');
|
||||
mtrace('done.');
|
||||
}
|
||||
|
||||
//Run registration updated cron
|
||||
mtrace(get_string('siteupdatesstart', 'hub'));
|
||||
require_once($CFG->dirroot . '/admin/registration/lib.php');
|
||||
$registrationmanager = new registration_manager();
|
||||
$registrationmanager->cron();
|
||||
mtrace(get_string('siteupdatesend', 'hub'));
|
||||
|
||||
// cleanup file trash
|
||||
// cleanup file trash - not very important
|
||||
$fs = get_file_storage();
|
||||
$fs->cron();
|
||||
|
||||
//cleanup old session linked tokens
|
||||
//deletes the session linked tokens that are over a day old.
|
||||
mtrace("Deleting session linked tokens more than one day old...", '');
|
||||
$DB->delete_records_select('external_tokens', 'lastaccess < :onedayago AND tokentype = :tokentype',
|
||||
array('onedayago' => time() - DAYSECS, 'tokentype' => EXTERNAL_TOKEN_EMBEDDED));
|
||||
mtrace('done.');
|
||||
|
||||
// all other plugins
|
||||
cron_execute_plugin_type('message', 'message plugins');
|
||||
cron_execute_plugin_type('filter', 'filters');
|
||||
cron_execute_plugin_type('editor', 'editors');
|
||||
cron_execute_plugin_type('format', 'course formats');
|
||||
cron_execute_plugin_type('profilefield', 'profile fields');
|
||||
cron_execute_plugin_type('webservice', 'webservices');
|
||||
// TODO: Repository lib.php files are messed up (include many other files, etc), so it is
|
||||
// currently not possible to implement repository plugin cron using this infrastructure
|
||||
// cron_execute_plugin_type('repository', 'repository plugins');
|
||||
cron_execute_plugin_type('qtype', 'question types');
|
||||
cron_execute_plugin_type('plagiarism', 'plagiarism plugins');
|
||||
cron_execute_plugin_type('theme', 'themes');
|
||||
cron_execute_plugin_type('tool', 'admin tools');
|
||||
|
||||
// and finally run any local cronjobs, if any
|
||||
if ($locals = get_plugin_list('local')) {
|
||||
mtrace('Processing customized cron scripts ...', '');
|
||||
// new cron functions in lib.php first
|
||||
cron_execute_plugin_type('local');
|
||||
// legacy cron files are executed directly
|
||||
foreach ($locals as $local => $localdir) {
|
||||
if (file_exists("$localdir/cron.php")) {
|
||||
include("$localdir/cron.php");
|
||||
}
|
||||
}
|
||||
mtrace('done.');
|
||||
}
|
||||
|
||||
mtrace("Cron script completed correctly");
|
||||
|
||||
@ -476,6 +490,7 @@ function cron_run() {
|
||||
|
||||
/**
|
||||
* Executes cron functions for a specific type of plugin.
|
||||
*
|
||||
* @param string $plugintype Plugin type (e.g. 'report')
|
||||
* @param string $description If specified, will display 'Starting (whatever)'
|
||||
* and 'Finished (whatever)' lines, otherwise does not display
|
||||
@ -530,6 +545,7 @@ function cron_execute_plugin_type($plugintype, $description = null) {
|
||||
round(microtime(true) - $pre_time, 2) . " seconds)");
|
||||
|
||||
set_config('lastcron', time(), $component);
|
||||
@set_time_limit(0);
|
||||
}
|
||||
|
||||
if ($description) {
|
||||
@ -541,6 +557,7 @@ function cron_execute_plugin_type($plugintype, $description = null) {
|
||||
* Used to add in old-style cron functions within plugins that have not been converted to the
|
||||
* new standard API. (The standard API is frankenstyle_name_cron() in lib.php; some types used
|
||||
* cron.php and some used a different name.)
|
||||
*
|
||||
* @param string $plugintype Plugin type e.g. 'report'
|
||||
* @param array $plugins Array from plugin name (e.g. 'report_frog') to function name (e.g.
|
||||
* 'report_frog_cron') for plugin cron functions that were already found using the new API
|
||||
@ -595,4 +612,119 @@ function cron_bc_hack_plugin_functions($plugintype, $plugins) {
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notify admin users or admin user of any failed logins (since last notification).
|
||||
*
|
||||
* Note that this function must be only executed from the cron script
|
||||
* It uses the cache_flags system to store temporary records, deleting them
|
||||
* by name before finishing
|
||||
*/
|
||||
function notify_login_failures() {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
$recip = get_users_from_config($CFG->notifyloginfailures, 'moodle/site:config');
|
||||
|
||||
if (empty($CFG->lastnotifyfailure)) {
|
||||
$CFG->lastnotifyfailure=0;
|
||||
}
|
||||
|
||||
// we need to deal with the threshold stuff first.
|
||||
if (empty($CFG->notifyloginthreshold)) {
|
||||
$CFG->notifyloginthreshold = 10; // default to something sensible.
|
||||
}
|
||||
|
||||
// Get all the IPs with more than notifyloginthreshold failures since lastnotifyfailure
|
||||
// and insert them into the cache_flags temp table
|
||||
$sql = "SELECT ip, COUNT(*)
|
||||
FROM {log}
|
||||
WHERE module = 'login' AND action = 'error'
|
||||
AND time > ?
|
||||
GROUP BY ip
|
||||
HAVING COUNT(*) >= ?";
|
||||
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $iprec) {
|
||||
if (!empty($iprec->ip)) {
|
||||
set_cache_flag('login_failure_by_ip', $iprec->ip, '1', 0);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
|
||||
// and insert them into the cache_flags temp table
|
||||
$sql = "SELECT info, count(*)
|
||||
FROM {log}
|
||||
WHERE module = 'login' AND action = 'error'
|
||||
AND time > ?
|
||||
GROUP BY info
|
||||
HAVING count(*) >= ?";
|
||||
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $inforec) {
|
||||
if (!empty($inforec->info)) {
|
||||
set_cache_flag('login_failure_by_info', $inforec->info, '1', 0);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// Now, select all the login error logged records belonging to the ips and infos
|
||||
// since lastnotifyfailure, that we have stored in the cache_flags table
|
||||
$sql = "SELECT l.*, u.firstname, u.lastname
|
||||
FROM {log} l
|
||||
JOIN {cache_flags} cf ON l.ip = cf.name
|
||||
LEFT JOIN {user} u ON l.userid = u.id
|
||||
WHERE l.module = 'login' AND l.action = 'error'
|
||||
AND l.time > ?
|
||||
AND cf.flagtype = 'login_failure_by_ip'
|
||||
UNION ALL
|
||||
SELECT l.*, u.firstname, u.lastname
|
||||
FROM {log} l
|
||||
JOIN {cache_flags} cf ON l.info = cf.name
|
||||
LEFT JOIN {user} u ON l.userid = u.id
|
||||
WHERE l.module = 'login' AND l.action = 'error'
|
||||
AND l.time > ?
|
||||
AND cf.flagtype = 'login_failure_by_info'
|
||||
ORDER BY time DESC";
|
||||
$params = array($CFG->lastnotifyfailure, $CFG->lastnotifyfailure);
|
||||
|
||||
// Init some variables
|
||||
$count = 0;
|
||||
$messages = '';
|
||||
// Iterate over the logs recordset
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $log) {
|
||||
$log->time = userdate($log->time);
|
||||
$messages .= get_string('notifyloginfailuresmessage','',$log)."\n";
|
||||
$count++;
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// If we haven't run in the last hour and
|
||||
// we have something useful to report and we
|
||||
// are actually supposed to be reporting to somebody
|
||||
if ((time() - HOURSECS) > $CFG->lastnotifyfailure && $count > 0 && is_array($recip) && count($recip) > 0) {
|
||||
$site = get_site();
|
||||
$subject = get_string('notifyloginfailuressubject', '', format_string($site->fullname));
|
||||
// Calculate the complete body of notification (start + messages + end)
|
||||
$body = get_string('notifyloginfailuresmessagestart', '', $CFG->wwwroot) .
|
||||
(($CFG->lastnotifyfailure != 0) ? '('.userdate($CFG->lastnotifyfailure).')' : '')."\n\n" .
|
||||
$messages .
|
||||
"\n\n".get_string('notifyloginfailuresmessageend','',$CFG->wwwroot)."\n\n";
|
||||
|
||||
// For each destination, send mail
|
||||
mtrace('Emailing admins about '. $count .' failed login attempts');
|
||||
foreach ($recip as $admin) {
|
||||
//emailing the admins directly rather than putting these through the messaging system
|
||||
email_to_user($admin,get_admin(), $subject, $body);
|
||||
}
|
||||
|
||||
// Update lastnotifyfailure with current time
|
||||
set_config('lastnotifyfailure', time());
|
||||
}
|
||||
|
||||
// Finally, delete all the temp records we have created in cache_flags
|
||||
$DB->delete_records_select('cache_flags', "flagtype IN ('login_failure_by_ip', 'login_failure_by_info')");
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
<attach event="ondocumentready" handler="parseStylesheets" />
|
||||
<script type="text/javascript">
|
||||
/**
|
||||
* Pseudos - V1.30.050121 - hover & active
|
||||
* ---------------------------------------------
|
||||
* Peterned - http://www.xs4all.nl/~peterned/
|
||||
* (c) 2005 - Peter Nederlof
|
||||
*
|
||||
* Credits - Arnoud Berendsen
|
||||
* - Martin Reurings
|
||||
* - Robert Hanson
|
||||
*
|
||||
* howto: body { behavior:url("csshover.htc"); }
|
||||
* ---------------------------------------------
|
||||
*/
|
||||
|
||||
var currentSheet, doc = window.document, activators = {
|
||||
onhover:{on:'onmouseover', off:'onmouseout'},
|
||||
onactive:{on:'onmousedown', off:'onmouseup'}
|
||||
}
|
||||
|
||||
function parseStylesheets() {
|
||||
var sheets = doc.styleSheets, l = sheets.length;
|
||||
for(var i=0; i<l; i++)
|
||||
parseStylesheet(sheets[i]);
|
||||
}
|
||||
function parseStylesheet(sheet) {
|
||||
if(sheet.imports) {
|
||||
try {
|
||||
var imports = sheet.imports, l = imports.length;
|
||||
for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
|
||||
} catch(securityException){}
|
||||
}
|
||||
|
||||
try {
|
||||
var rules = (currentSheet = sheet).rules, l = rules.length;
|
||||
for(var j=0; j<l; j++) parseCSSRule(rules[j]);
|
||||
} catch(securityException){}
|
||||
}
|
||||
|
||||
function parseCSSRule(rule) {
|
||||
var select = rule.selectorText, style = rule.style.cssText;
|
||||
if(!(/(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i).test(select) || !style) return;
|
||||
|
||||
var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
|
||||
var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
|
||||
var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
|
||||
var affected = select.replace(/:hover.*$/, '');
|
||||
var elements = getElementsBySelect(affected);
|
||||
|
||||
currentSheet.addRule(newSelect, style);
|
||||
for(var i=0; i<elements.length; i++)
|
||||
new HoverElement(elements[i], className, activators[pseudo]);
|
||||
}
|
||||
|
||||
function HoverElement(node, className, events) {
|
||||
if(!node.hovers) node.hovers = {};
|
||||
if(node.hovers[className]) return;
|
||||
node.hovers[className] = true;
|
||||
node.attachEvent(events.on,
|
||||
function() { node.className += ' ' + className; });
|
||||
node.attachEvent(events.off,
|
||||
function() { node.className =
|
||||
node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
|
||||
}
|
||||
|
||||
function getElementsBySelect(rule) {
|
||||
var parts, nodes = [doc];
|
||||
parts = rule.split(' ');
|
||||
for(var i=0; i<parts.length; i++) {
|
||||
nodes = getSelectedNodes(parts[i], nodes);
|
||||
} return nodes;
|
||||
}
|
||||
function getSelectedNodes(select, elements) {
|
||||
var result, node, nodes = [];
|
||||
var classname = (/\.([a-z0-9_-]+)/i).exec(select);
|
||||
var identify = (/\#([a-z0-9_-]+)/i).exec(select);
|
||||
var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
|
||||
for(var i=0; i<elements.length; i++) {
|
||||
result = tagName? elements[i].all.tags(tagName):elements[i].all;
|
||||
for(var j=0; j<result.length; j++) {
|
||||
node = result[j];
|
||||
if((identify && node.id != identify[1]) || (classname && !(new RegExp('\\b' +
|
||||
classname[1] + '\\b').exec(node.className)))) continue;
|
||||
nodes[nodes.length] = node;
|
||||
}
|
||||
} return nodes;
|
||||
}
|
||||
</script>
|
@ -717,7 +717,12 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
|
||||
$params = array();
|
||||
$i = 0;
|
||||
|
||||
$concat = $DB->sql_concat("COALESCE(c.summary, '". $DB->sql_empty() ."')", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
|
||||
// Thanks Oracle for your non-ansi concat and type limits in coalesce. MDL-29912
|
||||
if ($DB->get_dbfamily() == 'oracle') {
|
||||
$concat = $DB->sql_concat('c.summary', "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
|
||||
} else {
|
||||
$concat = $DB->sql_concat("COALESCE(c.summary, '". $DB->sql_empty() ."')", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
|
||||
}
|
||||
|
||||
foreach ($searchterms as $searchterm) {
|
||||
$i++;
|
||||
|
@ -73,7 +73,7 @@ course_content_removed - object course table record + context property
|
||||
course_deleted - object course table record + context property
|
||||
|
||||
user_enrolled - object record from user_enrolments table + courseid,enrol
|
||||
user_unenrol_modified - object record from user_enrolments table + courseid,enrol
|
||||
user_enrol_modified - object record from user_enrolments table + courseid,enrol
|
||||
user_unenrolled - object record from user_enrolments table + courseid,enrol,lastenrol
|
||||
|
||||
==== cohort related events ===
|
||||
|
@ -29,7 +29,16 @@ $functions = array(
|
||||
// === group related functions ===
|
||||
|
||||
'moodle_group_create_groups' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'create_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_create_groups(). ',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_create_groups' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'create_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Creates new groups.',
|
||||
@ -38,7 +47,16 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_group_get_groups' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'get_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_get_groups()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_get_groups' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'get_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Returns group details.',
|
||||
@ -47,7 +65,16 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_group_get_course_groups' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'get_course_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_get_course_groups()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_get_course_groups' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'get_course_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Returns all groups in specified course.',
|
||||
@ -56,7 +83,16 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_group_delete_groups' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'delete_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_delete_groups()',
|
||||
'type' => 'delete',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_delete_groups' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'delete_groups',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Deletes all specified groups.',
|
||||
@ -65,8 +101,17 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_group_get_groupmembers' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'methodname' => 'get_groupmembers',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'get_group_members',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_get_group_members()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_get_group_members' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'get_group_members',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Returns group members.',
|
||||
'type' => 'read',
|
||||
@ -74,8 +119,17 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_group_add_groupmembers' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'methodname' => 'add_groupmembers',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'add_group_members',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_add_group_members()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_add_group_members' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'add_group_members',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Adds group members.',
|
||||
'type' => 'write',
|
||||
@ -83,26 +137,51 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_group_delete_groupmembers' => array(
|
||||
'classname' => 'moodle_group_external',
|
||||
'methodname' => 'delete_groupmembers',
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'delete_group_members',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_group_delete_group_members()',
|
||||
'type' => 'delete',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
'core_group_delete_group_members' => array(
|
||||
'classname' => 'core_group_external',
|
||||
'methodname' => 'delete_group_members',
|
||||
'classpath' => 'group/externallib.php',
|
||||
'description' => 'Deletes group members.',
|
||||
'type' => 'delete',
|
||||
'capabilities'=> 'moodle/course:managegroups',
|
||||
),
|
||||
|
||||
|
||||
// === file related functions ===
|
||||
|
||||
'moodle_file_get_files' => array(
|
||||
'classname' => 'moodle_file_external',
|
||||
'classname' => 'core_files_external',
|
||||
'methodname' => 'get_files',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_files_get_files()',
|
||||
'type' => 'read',
|
||||
'classpath' => 'files/externallib.php',
|
||||
),
|
||||
|
||||
'core_files_get_files' => array(
|
||||
'classname' => 'core_files_external',
|
||||
'methodname' => 'get_files',
|
||||
'description' => 'browse moodle files',
|
||||
'type' => 'read',
|
||||
'classpath' => 'files/externallib.php',
|
||||
),
|
||||
|
||||
'moodle_file_upload' => array(
|
||||
'classname' => 'moodle_file_external',
|
||||
'classname' => 'core_files_external',
|
||||
'methodname' => 'upload',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_files_upload()',
|
||||
'type' => 'write',
|
||||
'classpath' => 'files/externallib.php',
|
||||
),
|
||||
|
||||
'core_files_upload' => array(
|
||||
'classname' => 'core_files_external',
|
||||
'methodname' => 'upload',
|
||||
'description' => 'upload a file to moodle',
|
||||
'type' => 'write',
|
||||
@ -112,7 +191,16 @@ $functions = array(
|
||||
// === user related functions ===
|
||||
|
||||
'moodle_user_create_users' => array(
|
||||
'classname' => 'moodle_user_external',
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'create_users',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_user_create_users()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/user:create',
|
||||
),
|
||||
|
||||
'core_user_create_users' => array(
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'create_users',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Create users.',
|
||||
@ -121,7 +209,16 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_user_get_users_by_id' => array(
|
||||
'classname' => 'moodle_user_external',
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'get_users_by_id',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_user_get_users_by_id()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update',
|
||||
),
|
||||
|
||||
'core_user_get_users_by_id' => array(
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'get_users_by_id',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Get users by id.',
|
||||
@ -130,25 +227,43 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_user_get_users_by_courseid' => array(
|
||||
'classname' => 'moodle_user_external',
|
||||
'methodname' => 'get_users_by_courseid',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Get enrolled users by course id.',
|
||||
'classname' => 'core_enrol_external',
|
||||
'methodname' => 'get_enrolled_users',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_enrol_get_enrolled_users()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update, moodle/site:accessallgroups',
|
||||
),
|
||||
|
||||
'moodle_user_get_course_participants_by_id' => array(
|
||||
'classname' => 'moodle_user_external',
|
||||
'methodname' => 'get_course_participants_by_id',
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'get_course_user_profiles',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Get course user profiles by id.',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_user_get_course_user_profiles()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update, moodle/site:accessallgroups',
|
||||
),
|
||||
|
||||
'core_user_get_course_user_profiles' => array(
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'get_course_user_profiles',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Get course user profiles (each of the profils matching a course id and a user id).',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update, moodle/site:accessallgroups',
|
||||
),
|
||||
|
||||
'moodle_user_delete_users' => array(
|
||||
'classname' => 'moodle_user_external',
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'delete_users',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_user_delete_users()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/user:delete',
|
||||
),
|
||||
|
||||
'core_user_delete_users' => array(
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'delete_users',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Delete users.',
|
||||
@ -157,7 +272,16 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_user_update_users' => array(
|
||||
'classname' => 'moodle_user_external',
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'update_users',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_user_update_users()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/user:update',
|
||||
),
|
||||
|
||||
'core_user_update_users' => array(
|
||||
'classname' => 'core_user_external',
|
||||
'methodname' => 'update_users',
|
||||
'classpath' => 'user/externallib.php',
|
||||
'description' => 'Update users.',
|
||||
@ -171,24 +295,53 @@ $functions = array(
|
||||
'classname' => 'moodle_enrol_external',
|
||||
'methodname' => 'get_enrolled_users',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Get list of course participants',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. Please use core_enrol_get_enrolled_users() (previously known as moodle_user_get_users_by_courseid).',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/site:viewparticipants, moodle/course:viewparticipants,
|
||||
moodle/role:review, moodle/site:accessallgroups, moodle/course:enrolreview',
|
||||
),
|
||||
|
||||
'core_enrol_get_enrolled_users' => array(
|
||||
'classname' => 'core_enrol_external',
|
||||
'methodname' => 'get_enrolled_users',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Get enrolled users by course id.',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update, moodle/site:accessallgroups',
|
||||
),
|
||||
|
||||
'moodle_enrol_get_users_courses' => array(
|
||||
'classname' => 'moodle_enrol_external',
|
||||
'classname' => 'core_enrol_external',
|
||||
'methodname' => 'get_users_courses',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Get list of courses user is enrolled in',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_enrol_get_users_courses()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:viewparticipants',
|
||||
),
|
||||
|
||||
'core_enrol_get_users_courses' => array(
|
||||
'classname' => 'core_enrol_external',
|
||||
'methodname' => 'get_users_courses',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Get the list of courses where a user is enrolled in',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:viewparticipants',
|
||||
),
|
||||
|
||||
// === Role related functions ===
|
||||
|
||||
'moodle_role_assign' => array(
|
||||
'classname' => 'moodle_enrol_external',
|
||||
'methodname' => 'role_assign',
|
||||
'classname' => 'core_role_external',
|
||||
'methodname' => 'assign_roles',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_role_assign_role()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/role:assign',
|
||||
),
|
||||
|
||||
'core_role_assign_roles' => array(
|
||||
'classname' => 'core_role_external',
|
||||
'methodname' => 'assign_roles',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Manual role assignments.',
|
||||
'type' => 'write',
|
||||
@ -196,8 +349,17 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_role_unassign' => array(
|
||||
'classname' => 'moodle_enrol_external',
|
||||
'methodname' => 'role_unassign',
|
||||
'classname' => 'core_role_external',
|
||||
'methodname' => 'unassign_roles',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_role_unassign_role()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/role:assign',
|
||||
),
|
||||
|
||||
'core_role_unassign_roles' => array(
|
||||
'classname' => 'core_role_external',
|
||||
'methodname' => 'unassign_roles',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Manual role unassignments.',
|
||||
'type' => 'write',
|
||||
@ -207,7 +369,16 @@ $functions = array(
|
||||
// === course related functions ===
|
||||
|
||||
'moodle_course_get_courses' => array(
|
||||
'classname' => 'moodle_course_external',
|
||||
'classname' => 'core_course_external',
|
||||
'methodname' => 'get_courses',
|
||||
'classpath' => 'course/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_course_get_courses()',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:view,moodle/course:update,moodle/course:viewhiddencourses',
|
||||
),
|
||||
|
||||
'core_course_get_courses' => array(
|
||||
'classname' => 'core_course_external',
|
||||
'methodname' => 'get_courses',
|
||||
'classpath' => 'course/externallib.php',
|
||||
'description' => 'Return course details',
|
||||
@ -216,7 +387,16 @@ $functions = array(
|
||||
),
|
||||
|
||||
'moodle_course_create_courses' => array(
|
||||
'classname' => 'moodle_course_external',
|
||||
'classname' => 'core_course_external',
|
||||
'methodname' => 'create_courses',
|
||||
'classpath' => 'course/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_course_create_courses()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/course:create,moodle/course:visibility',
|
||||
),
|
||||
|
||||
'core_course_create_courses' => array(
|
||||
'classname' => 'core_course_external',
|
||||
'methodname' => 'create_courses',
|
||||
'classpath' => 'course/externallib.php',
|
||||
'description' => 'Create new courses',
|
||||
@ -227,8 +407,17 @@ $functions = array(
|
||||
// === message related functions ===
|
||||
|
||||
'moodle_message_send_instantmessages' => array(
|
||||
'classname' => 'moodle_message_external',
|
||||
'methodname' => 'send_instantmessages',
|
||||
'classname' => 'core_message_external',
|
||||
'methodname' => 'send_instant_messages',
|
||||
'classpath' => 'message/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_message_send_instant_messages()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/site:sendmessage',
|
||||
),
|
||||
|
||||
'core_message_send_instant_messages' => array(
|
||||
'classname' => 'core_message_external',
|
||||
'methodname' => 'send_instant_messages',
|
||||
'classpath' => 'message/externallib.php',
|
||||
'description' => 'Send instant messages',
|
||||
'type' => 'write',
|
||||
@ -238,7 +427,16 @@ $functions = array(
|
||||
// === notes related functions ===
|
||||
|
||||
'moodle_notes_create_notes' => array(
|
||||
'classname' => 'moodle_notes_external',
|
||||
'classname' => 'core_notes_external',
|
||||
'methodname' => 'create_notes',
|
||||
'classpath' => 'notes/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_notes_create_notes()',
|
||||
'type' => 'write',
|
||||
'capabilities'=> 'moodle/notes:manage',
|
||||
),
|
||||
|
||||
'core_notes_create_notes' => array(
|
||||
'classname' => 'core_notes_external',
|
||||
'methodname' => 'create_notes',
|
||||
'classpath' => 'notes/externallib.php',
|
||||
'description' => 'Create notes',
|
||||
@ -249,8 +447,16 @@ $functions = array(
|
||||
// === webservice related functions ===
|
||||
|
||||
'moodle_webservice_get_siteinfo' => array(
|
||||
'classname' => 'moodle_webservice_external',
|
||||
'methodname' => 'get_siteinfo',
|
||||
'classname' => 'core_webservice_external',
|
||||
'methodname' => 'get_site_info',
|
||||
'classpath' => 'webservice/externallib.php',
|
||||
'description' => 'DEPRECATED: this deprecated function will be removed in a future version. This function has be renamed as core_webservice_get_site_info()',
|
||||
'type' => 'read',
|
||||
),
|
||||
|
||||
'core_webservice_get_site_info' => array(
|
||||
'classname' => 'core_webservice_external',
|
||||
'methodname' => 'get_site_info',
|
||||
'classpath' => 'webservice/externallib.php',
|
||||
'description' => 'Return some site info / user info / list web service functions',
|
||||
'type' => 'read',
|
||||
|
@ -3716,14 +3716,6 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||
upgrade_main_savepoint(true, 2010051801);
|
||||
}
|
||||
|
||||
if ($oldversion < 2010052100) {
|
||||
// Switch to html purifier as default cleaning engine - KSES is really very bad
|
||||
if (empty($CFG->enablehtmlpurifier)) {
|
||||
unset_config('enablehtmlpurifier');
|
||||
}
|
||||
upgrade_main_savepoint(true, 2010052100);
|
||||
}
|
||||
|
||||
if ($oldversion < 2010052200) {
|
||||
// Define field legacyfiles to be added to course - just in case we are upgrading from PR1
|
||||
$table = new xmldb_table('course');
|
||||
@ -6880,6 +6872,12 @@ FROM
|
||||
upgrade_main_savepoint(true, 2011101200.02);
|
||||
}
|
||||
|
||||
if ($oldversion < 2011101900.02) {
|
||||
// remove unused setting
|
||||
unset_config('enablehtmlpurifier');
|
||||
upgrade_main_savepoint(true, 2011101900.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3756,6 +3756,28 @@ class dml_test extends UnitTestCase {
|
||||
$records = $DB->get_records_sql($sql, null);
|
||||
$this->assertEqual($result, $records);
|
||||
|
||||
// another grouping by CASE expression just to ensure it works ok for multiple WHEN
|
||||
$sql = "SELECT CASE name
|
||||
WHEN 'xyz' THEN 'last'
|
||||
WHEN 'def' THEN 'mid'
|
||||
WHEN 'abc' THEN 'first'
|
||||
END AS casecol,
|
||||
COUNT(1) AS countrecs,
|
||||
MAX(name) AS maxname
|
||||
FROM {{$tablename}}
|
||||
GROUP BY CASE name
|
||||
WHEN 'xyz' THEN 'last'
|
||||
WHEN 'def' THEN 'mid'
|
||||
WHEN 'abc' THEN 'first'
|
||||
END
|
||||
ORDER BY casecol DESC";
|
||||
$result = array(
|
||||
'mid' => (object)array('casecol' => 'mid', 'countrecs' => 1, 'maxname' => 'def'),
|
||||
'last' => (object)array('casecol' => 'last', 'countrecs' => 1, 'maxname' => 'xyz'),
|
||||
'first'=> (object)array('casecol' => 'first', 'countrecs' => 2, 'maxname' => 'abc'));
|
||||
$records = $DB->get_records_sql($sql, null);
|
||||
$this->assertEqual($result, $records);
|
||||
|
||||
// test limits in queries with DISTINCT/ALL clauses and multiple whitespace. MDL-25268
|
||||
$sql = "SELECT DISTINCT course
|
||||
FROM {{$tablename}}
|
||||
|
@ -1103,6 +1103,7 @@ abstract class enrol_plugin {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
|
||||
|
||||
$inserted = false;
|
||||
$updated = false;
|
||||
if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
|
||||
//only update if timestart or timeend or status are different.
|
||||
if ($ue->timestart != $timestart or $ue->timeend != $timeend or (!is_null($status) and $ue->status != $status)) {
|
||||
@ -1114,6 +1115,8 @@ abstract class enrol_plugin {
|
||||
$ue->modifierid = $USER->id;
|
||||
$ue->timemodified = time();
|
||||
$DB->update_record('user_enrolments', $ue);
|
||||
|
||||
$updated = true;
|
||||
}
|
||||
} else {
|
||||
$ue = new stdClass();
|
||||
@ -1143,6 +1146,10 @@ abstract class enrol_plugin {
|
||||
$ue->courseid = $courseid;
|
||||
$ue->enrol = $name;
|
||||
events_trigger('user_enrolled', $ue);
|
||||
} else if ($updated) {
|
||||
$ue->courseid = $courseid;
|
||||
$ue->enrol = $name;
|
||||
events_trigger('user_enrol_modified', $ue);
|
||||
}
|
||||
|
||||
// reset primitive require_login() caching
|
||||
@ -1160,8 +1167,8 @@ abstract class enrol_plugin {
|
||||
/**
|
||||
* Store user_enrolments changes and trigger event.
|
||||
*
|
||||
* @param object $ue
|
||||
* @param int $user id
|
||||
* @param stdClass $instance
|
||||
* @param int $userid
|
||||
* @param int $status
|
||||
* @param int $timestart
|
||||
* @param int $timeend
|
||||
@ -1206,7 +1213,7 @@ abstract class enrol_plugin {
|
||||
// trigger event
|
||||
$ue->courseid = $instance->courseid;
|
||||
$ue->enrol = $instance->name;
|
||||
events_trigger('user_unenrol_modified', $ue);
|
||||
events_trigger('user_enrol_modified', $ue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,23 +80,19 @@ defined('MOODLE_INTERNAL') || die();
|
||||
define('ENV_SELECT_RELEASE', 2);
|
||||
|
||||
/**
|
||||
* This function will perform the whole check, returning
|
||||
* true or false as final result. Also, he full array of
|
||||
* environment_result will be returned in the parameter list.
|
||||
* The function looks for the best version to compare and
|
||||
* everything. This is the only function that should be called
|
||||
* ever from the rest of Moodle.
|
||||
* This function checks all the requirements defined in environment.xml.
|
||||
*
|
||||
* @staticvar bool $result
|
||||
* @staticvar array $env_results
|
||||
* @staticvar bool $cache_exists
|
||||
*
|
||||
* @param string $version version to check.
|
||||
* @param array $environment_results results array of results checked.
|
||||
* @param boolean $print_table true/false, whether to print the table or just return results array
|
||||
* @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. Default ENV_SELECT_NEWER (BC)
|
||||
* @return boolean true/false, depending of results
|
||||
* @return array with two elements. The first element true/false, depending on
|
||||
* on whether the check passed. The second element is an array of environment_results
|
||||
* objects that has detailed information about the checks and which ones passed.
|
||||
*/
|
||||
function check_moodle_environment($version, &$environment_results, $print_table=true, $env_select=ENV_SELECT_NEWER) {
|
||||
function check_moodle_environment($version, $env_select = ENV_SELECT_NEWER) {
|
||||
|
||||
$status = true;
|
||||
|
||||
@ -140,186 +136,7 @@ function check_moodle_environment($version, &$environment_results, $print_table=
|
||||
$cache_exists = true;
|
||||
} ///End of cache block
|
||||
|
||||
/// If we have decided to print all the information, just do it
|
||||
if ($print_table) {
|
||||
print_moodle_environment($result && $status, $environment_results);
|
||||
}
|
||||
return ($result && $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will print one beautiful table with all the environmental
|
||||
* configuration and how it suits Moodle needs.
|
||||
*
|
||||
* @global object
|
||||
* @param boolean $result final result of the check (true/false)
|
||||
* @param array $environment_results array of results gathered
|
||||
* @return void
|
||||
*/
|
||||
function print_moodle_environment($result, $environment_results) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
/// Get some strings
|
||||
$strname = get_string('name');
|
||||
$strinfo = get_string('info');
|
||||
$strreport = get_string('report');
|
||||
$strstatus = get_string('status');
|
||||
$strok = get_string('ok');
|
||||
$strerror = get_string('error');
|
||||
$strcheck = get_string('check');
|
||||
$strbypassed = get_string('bypassed');
|
||||
$strrestricted = get_string('restricted');
|
||||
$strenvironmenterrortodo = get_string('environmenterrortodo', 'admin');
|
||||
/// Table headers
|
||||
$servertable = new html_table();//table for server checks
|
||||
$servertable->head = array ($strname, $strinfo, $strreport, $strstatus);
|
||||
$servertable->align = array ('center', 'center', 'left', 'center');
|
||||
$servertable->wrap = array ('nowrap', '', '', 'nowrap');
|
||||
$servertable->size = array ('10', 10, '100%', '10');
|
||||
$servertable->attributes['class'] = 'environmenttable generaltable';
|
||||
|
||||
$serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
|
||||
|
||||
$othertable = new html_table();//table for custom checks
|
||||
$othertable->head = array ($strinfo, $strreport, $strstatus);
|
||||
$othertable->align = array ('center', 'left', 'center');
|
||||
$othertable->wrap = array ('', '', 'nowrap');
|
||||
$othertable->size = array (10, '100%', '10');
|
||||
$othertable->attributes['class'] = 'environmenttable generaltable';
|
||||
|
||||
$otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
|
||||
|
||||
/// Iterate over each environment_result
|
||||
$continue = true;
|
||||
foreach ($environment_results as $environment_result) {
|
||||
$errorline = false;
|
||||
$warningline = false;
|
||||
$stringtouse = '';
|
||||
if ($continue) {
|
||||
$type = $environment_result->getPart();
|
||||
$info = $environment_result->getInfo();
|
||||
$status = $environment_result->getStatus();
|
||||
$error_code = $environment_result->getErrorCode();
|
||||
/// Process Report field
|
||||
$rec = new stdClass();
|
||||
/// Something has gone wrong at parsing time
|
||||
if ($error_code) {
|
||||
$stringtouse = 'environmentxmlerror';
|
||||
$rec->error_code = $error_code;
|
||||
$status = $strerror;
|
||||
$errorline = true;
|
||||
$continue = false;
|
||||
}
|
||||
|
||||
if ($continue) {
|
||||
/// We are comparing versions
|
||||
if ($rec->needed = $environment_result->getNeededVersion()) {
|
||||
$rec->current = $environment_result->getCurrentVersion();
|
||||
if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentrequireversion';
|
||||
} else {
|
||||
$stringtouse = 'environmentrecommendversion';
|
||||
}
|
||||
/// We are checking installed & enabled things
|
||||
} else if ($environment_result->getPart() == 'custom_check') {
|
||||
if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentrequirecustomcheck';
|
||||
} else {
|
||||
$stringtouse = 'environmentrecommendcustomcheck';
|
||||
}
|
||||
} else if ($environment_result->getPart() == 'php_setting') {
|
||||
if ($status) {
|
||||
$stringtouse = 'environmentsettingok';
|
||||
} else if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentmustfixsetting';
|
||||
} else {
|
||||
$stringtouse = 'environmentshouldfixsetting';
|
||||
}
|
||||
} else {
|
||||
if ($environment_result->getLevel() == 'required') {
|
||||
$stringtouse = 'environmentrequireinstall';
|
||||
} else {
|
||||
$stringtouse = 'environmentrecommendinstall';
|
||||
}
|
||||
}
|
||||
/// Calculate the status value
|
||||
if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
|
||||
$status = $strbypassed;
|
||||
$warningline = true;
|
||||
} else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
|
||||
$status = $strrestricted;
|
||||
$errorline = true;
|
||||
} else {
|
||||
if ($status) { //Handle ok result (ok)
|
||||
$status = $strok;
|
||||
} else {
|
||||
if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
|
||||
$status = $strcheck;
|
||||
$warningline = true;
|
||||
} else { //Handle error result (error)
|
||||
$status = $strcheck;
|
||||
$errorline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the text
|
||||
$linkparts = array();
|
||||
$linkparts[] = 'admin/environment';
|
||||
$linkparts[] = $type;
|
||||
if (!empty($info)){
|
||||
$linkparts[] = $info;
|
||||
}
|
||||
if (empty($CFG->docroot)) {
|
||||
$report = get_string($stringtouse, 'admin', $rec);
|
||||
} else {
|
||||
$report = $OUTPUT->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
|
||||
}
|
||||
|
||||
|
||||
/// Format error or warning line
|
||||
if ($errorline || $warningline) {
|
||||
$messagetype = $errorline? 'error':'warn';
|
||||
} else {
|
||||
$messagetype = 'ok';
|
||||
}
|
||||
$status = '<span class="'.$messagetype.'">'.$status.'</span>';
|
||||
/// Here we'll store all the feedback found
|
||||
$feedbacktext = '';
|
||||
///Append the feedback if there is some
|
||||
$feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
|
||||
///Append the bypass if there is some
|
||||
$feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
|
||||
///Append the restrict if there is some
|
||||
$feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
|
||||
|
||||
$report .= $feedbacktext;
|
||||
/// Add the row to the table
|
||||
|
||||
if ($environment_result->getPart() == 'custom_check'){
|
||||
$otherdata[$messagetype][] = array ($info, $report, $status);
|
||||
} else {
|
||||
$serverdata[$messagetype][] = array ($type, $info, $report, $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
//put errors first in
|
||||
$servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
|
||||
$othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
|
||||
|
||||
/// Print table
|
||||
echo $OUTPUT->heading(get_string('serverchecks', 'admin'));
|
||||
echo html_writer::table($servertable);
|
||||
if (count($othertable->data)){
|
||||
echo $OUTPUT->heading(get_string('customcheck', 'admin'));
|
||||
echo html_writer::table($othertable);
|
||||
}
|
||||
|
||||
/// Finally, if any error has happened, print the summary box
|
||||
if (!$result) {
|
||||
echo $OUTPUT->box($strenvironmenterrortodo, 'environmentbox errorbox');
|
||||
}
|
||||
return array($result && $status, $environment_results);
|
||||
}
|
||||
|
||||
|
||||
|
@ -452,7 +452,7 @@ class stored_file {
|
||||
* @return string
|
||||
*/
|
||||
public function get_author() {
|
||||
return $this->file_record->license;
|
||||
return $this->file_record->author;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -404,7 +404,8 @@ function install_cli_database(array $options, $interactive) {
|
||||
}
|
||||
|
||||
// test environment first
|
||||
if (!check_moodle_environment(normalize_version($release), $environment_results, false, ENV_SELECT_RELEASE)) {
|
||||
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
|
||||
if (!$envstatus) {
|
||||
$errors = environment_get_errors($environment_results);
|
||||
cli_heading(get_string('environment', 'admin'));
|
||||
foreach ($errors as $error) {
|
||||
|
712
lib/kses.php
712
lib/kses.php
@ -1,712 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes
|
||||
* Copyright (C) 2002, 2003, 2005 Ulf Harnhammar
|
||||
*
|
||||
* This program is free software and open source 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* *** CONTACT INFORMATION ***
|
||||
*
|
||||
* E-mail: metaur at users dot sourceforge dot net
|
||||
* Web page: http://sourceforge.net/projects/kses
|
||||
* Paper mail: Ulf Harnhammar
|
||||
* Ymergatan 17 C
|
||||
* 753 25 Uppsala
|
||||
* SWEDEN
|
||||
*
|
||||
* [kses strips evil scripts!]
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright Ulf Harnhammar {@link http://sourceforge.net/projects/kses}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* This function makes sure that only the allowed HTML element names, attribute
|
||||
* names and attribute values plus only sane HTML entities will occur in
|
||||
* $string. You have to remove any slashes from PHP's magic quotes before you
|
||||
* call this function.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $allowed_html
|
||||
* @param array $allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses($string, $allowed_html, $allowed_protocols =
|
||||
array('http', 'https', 'ftp', 'news', 'nntp', 'telnet',
|
||||
'gopher', 'mailto'))
|
||||
###############################################################################
|
||||
# This function makes sure that only the allowed HTML element names, attribute
|
||||
# names and attribute values plus only sane HTML entities will occur in
|
||||
# $string. You have to remove any slashes from PHP's magic quotes before you
|
||||
# call this function.
|
||||
###############################################################################
|
||||
{
|
||||
$string = kses_no_null($string);
|
||||
$string = kses_js_entities($string);
|
||||
$string = kses_normalize_entities($string);
|
||||
$string = kses_hook($string);
|
||||
$allowed_html_fixed = kses_array_lc($allowed_html);
|
||||
return kses_split($string, $allowed_html_fixed, $allowed_protocols);
|
||||
} # function kses
|
||||
|
||||
|
||||
/**
|
||||
* You add any kses hooks here
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function kses_hook($string)
|
||||
###############################################################################
|
||||
# You add any kses hooks here.
|
||||
###############################################################################
|
||||
{
|
||||
return $string;
|
||||
} # function kses_hook
|
||||
|
||||
/**
|
||||
* This function returns kses' version number.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function kses_version()
|
||||
###############################################################################
|
||||
# This function returns kses' version number.
|
||||
###############################################################################
|
||||
{
|
||||
return '0.2.2';
|
||||
} # function kses_version
|
||||
|
||||
|
||||
/**
|
||||
* This function searches for HTML tags, no matter how malformed. It also
|
||||
* matches stray ">" characters.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $allowed_html
|
||||
* @param array $allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses_split($string, $allowed_html, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function searches for HTML tags, no matter how malformed. It also
|
||||
# matches stray ">" characters.
|
||||
###############################################################################
|
||||
{
|
||||
return preg_replace('%(<'. # EITHER: <
|
||||
'[^>]*'. # things that aren't >
|
||||
'(>|$)'. # > or end of string
|
||||
'|>)%e', # OR: just a >
|
||||
"kses_split2('\\1', \$allowed_html, ".
|
||||
'$allowed_protocols)',
|
||||
$string);
|
||||
} # function kses_split
|
||||
|
||||
/**
|
||||
* This function does a lot of work. It rejects some very malformed things
|
||||
* like <:::>. It returns an empty string, if the element isn't allowed (look
|
||||
* ma, no strip_tags()!). Otherwise it splits the tag into an element and an
|
||||
* attribute list.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $allowed_html
|
||||
* @param array $allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses_split2($string, $allowed_html, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function does a lot of work. It rejects some very malformed things
|
||||
# like <:::>. It returns an empty string, if the element isn't allowed (look
|
||||
# ma, no strip_tags()!). Otherwise it splits the tag into an element and an
|
||||
# attribute list.
|
||||
###############################################################################
|
||||
{
|
||||
$string = kses_stripslashes($string);
|
||||
|
||||
if (substr($string, 0, 1) != '<')
|
||||
return '>';
|
||||
# It matched a ">" character
|
||||
|
||||
if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
|
||||
return '';
|
||||
# It's seriously malformed
|
||||
|
||||
$slash = trim($matches[1]);
|
||||
$elem = $matches[2];
|
||||
$attrlist = $matches[3];
|
||||
|
||||
if (!@isset($allowed_html[strtolower($elem)]))
|
||||
return '';
|
||||
# They are using a not allowed HTML element
|
||||
|
||||
if ($slash != '')
|
||||
return "<$slash$elem>";
|
||||
# No attributes are allowed for closing elements
|
||||
|
||||
return kses_attr("$slash$elem", $attrlist, $allowed_html,
|
||||
$allowed_protocols);
|
||||
} # function kses_split2
|
||||
|
||||
/**
|
||||
* This function removes all attributes, if none are allowed for this element.
|
||||
* If some are allowed it calls kses_hair() to split them further, and then it
|
||||
* builds up new HTML code from the data that kses_hair() returns. It also
|
||||
* removes "<" and ">" characters, if there are any left. One more thing it
|
||||
* does is to check if the tag has a closing XHTML slash, and if it does,
|
||||
* it puts one in the returned code as well.
|
||||
*
|
||||
* @param string $element
|
||||
* @param string $attr
|
||||
* @param string $allowed_html
|
||||
* @param array $allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses_attr($element, $attr, $allowed_html, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function removes all attributes, if none are allowed for this element.
|
||||
# If some are allowed it calls kses_hair() to split them further, and then it
|
||||
# builds up new HTML code from the data that kses_hair() returns. It also
|
||||
# removes "<" and ">" characters, if there are any left. One more thing it
|
||||
# does is to check if the tag has a closing XHTML slash, and if it does,
|
||||
# it puts one in the returned code as well.
|
||||
###############################################################################
|
||||
{
|
||||
# Is there a closing XHTML slash at the end of the attributes?
|
||||
|
||||
$xhtml_slash = '';
|
||||
if (preg_match('%\s/\s*$%', $attr))
|
||||
$xhtml_slash = ' /';
|
||||
|
||||
# Are any attributes allowed at all for this element?
|
||||
|
||||
if (@count($allowed_html[strtolower($element)]) == 0)
|
||||
return "<$element$xhtml_slash>";
|
||||
|
||||
# Split it
|
||||
|
||||
$attrarr = kses_hair($attr, $allowed_protocols);
|
||||
|
||||
# Go through $attrarr, and save the allowed attributes for this element
|
||||
# in $attr2
|
||||
|
||||
$attr2 = '';
|
||||
|
||||
foreach ($attrarr as $arreach)
|
||||
{
|
||||
if (!@isset($allowed_html[strtolower($element)]
|
||||
[strtolower($arreach['name'])]))
|
||||
continue; # the attribute is not allowed
|
||||
|
||||
$current = $allowed_html[strtolower($element)]
|
||||
[strtolower($arreach['name'])];
|
||||
|
||||
if (!is_array($current))
|
||||
$attr2 .= ' '.$arreach['whole'];
|
||||
# there are no checks
|
||||
|
||||
else
|
||||
{
|
||||
# there are some checks
|
||||
$ok = true;
|
||||
foreach ($current as $currkey => $currval)
|
||||
if (!kses_check_attr_val($arreach['value'], $arreach['vless'],
|
||||
$currkey, $currval))
|
||||
{ $ok = false; break; }
|
||||
|
||||
if ($ok)
|
||||
$attr2 .= ' '.$arreach['whole']; # it passed them
|
||||
} # if !is_array($current)
|
||||
} # foreach
|
||||
|
||||
# Remove any "<" or ">" characters
|
||||
|
||||
$attr2 = preg_replace('/[<>]/', '', $attr2);
|
||||
|
||||
return "<$element$attr2$xhtml_slash>";
|
||||
} # function kses_attr
|
||||
|
||||
/**
|
||||
* This function does a lot of work. It parses an attribute list into an array
|
||||
* with attribute data, and tries to do the right thing even if it gets weird
|
||||
* input. It will add quotes around attribute values that don't have any quotes
|
||||
* or apostrophes around them, to make it easier to produce HTML code that will
|
||||
* conform to W3C's HTML specification. It will also remove bad URL protocols
|
||||
* from attribute values.
|
||||
*
|
||||
* @param string $attr
|
||||
* @param array $allowed_protocols
|
||||
* @return array
|
||||
*/
|
||||
function kses_hair($attr, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function does a lot of work. It parses an attribute list into an array
|
||||
# with attribute data, and tries to do the right thing even if it gets weird
|
||||
# input. It will add quotes around attribute values that don't have any quotes
|
||||
# or apostrophes around them, to make it easier to produce HTML code that will
|
||||
# conform to W3C's HTML specification. It will also remove bad URL protocols
|
||||
# from attribute values.
|
||||
###############################################################################
|
||||
{
|
||||
$attrarr = array();
|
||||
$mode = 0;
|
||||
$attrname = '';
|
||||
|
||||
# Loop through the whole attribute list
|
||||
|
||||
while (strlen($attr) != 0)
|
||||
{
|
||||
$working = 0; # Was the last operation successful?
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 0: # attribute name, href for instance
|
||||
|
||||
if (preg_match('/^([-a-zA-Z]+)/', $attr, $match))
|
||||
{
|
||||
$attrname = $match[1];
|
||||
$working = $mode = 1;
|
||||
$attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 1: # equals sign or valueless ("selected")
|
||||
|
||||
if (preg_match('/^\s*=\s*/', $attr)) # equals sign
|
||||
{
|
||||
$working = 1; $mode = 2;
|
||||
$attr = preg_replace('/^\s*=\s*/', '', $attr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s+/', $attr)) # valueless
|
||||
{
|
||||
$working = 1; $mode = 0;
|
||||
$attrarr[] = array
|
||||
('name' => $attrname,
|
||||
'value' => '',
|
||||
'whole' => $attrname,
|
||||
'vless' => 'y');
|
||||
$attr = preg_replace('/^\s+/', '', $attr);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2: # attribute value, a URL after href= for instance
|
||||
|
||||
if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match))
|
||||
# "value"
|
||||
{
|
||||
// MDL-2684 - kses stripping CSS styles that it thinks look like protocols
|
||||
if ($attrname == 'style') {
|
||||
$thisval = $match[1];
|
||||
} else {
|
||||
$thisval = kses_bad_protocol($match[1], $allowed_protocols);
|
||||
}
|
||||
|
||||
$attrarr[] = array
|
||||
('name' => $attrname,
|
||||
'value' => $thisval,
|
||||
'whole' => "$attrname=\"$thisval\"",
|
||||
'vless' => 'n');
|
||||
$working = 1; $mode = 0;
|
||||
$attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match))
|
||||
# 'value'
|
||||
{
|
||||
$thisval = kses_bad_protocol($match[1], $allowed_protocols);
|
||||
|
||||
$attrarr[] = array
|
||||
('name' => $attrname,
|
||||
'value' => $thisval,
|
||||
'whole' => "$attrname='$thisval'",
|
||||
'vless' => 'n');
|
||||
$working = 1; $mode = 0;
|
||||
$attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match))
|
||||
# value
|
||||
{
|
||||
$thisval = kses_bad_protocol($match[1], $allowed_protocols);
|
||||
|
||||
$attrarr[] = array
|
||||
('name' => $attrname,
|
||||
'value' => $thisval,
|
||||
'whole' => "$attrname=\"$thisval\"",
|
||||
'vless' => 'n');
|
||||
# We add quotes to conform to W3C's HTML spec.
|
||||
$working = 1; $mode = 0;
|
||||
$attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
|
||||
}
|
||||
|
||||
break;
|
||||
} # switch
|
||||
|
||||
if ($working == 0) # not well formed, remove and try again
|
||||
{
|
||||
$attr = kses_html_error($attr);
|
||||
$mode = 0;
|
||||
}
|
||||
} # while
|
||||
|
||||
if ($mode == 1)
|
||||
# special case, for when the attribute list ends with a valueless
|
||||
# attribute like "selected"
|
||||
$attrarr[] = array
|
||||
('name' => $attrname,
|
||||
'value' => '',
|
||||
'whole' => $attrname,
|
||||
'vless' => 'y');
|
||||
|
||||
return $attrarr;
|
||||
} # function kses_hair
|
||||
|
||||
/**
|
||||
* This function performs different checks for attribute values. The currently
|
||||
* implemented checks are "maxlen", "minlen", "maxval", "minval" and "valueless"
|
||||
* with even more checks to come soon.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $vless
|
||||
* @param string $checkname
|
||||
* @param string $checkvalue
|
||||
* @return bool
|
||||
*/
|
||||
function kses_check_attr_val($value, $vless, $checkname, $checkvalue)
|
||||
###############################################################################
|
||||
# This function performs different checks for attribute values. The currently
|
||||
# implemented checks are "maxlen", "minlen", "maxval", "minval" and "valueless"
|
||||
# with even more checks to come soon.
|
||||
###############################################################################
|
||||
{
|
||||
$ok = true;
|
||||
|
||||
switch (strtolower($checkname))
|
||||
{
|
||||
case 'maxlen':
|
||||
# The maxlen check makes sure that the attribute value has a length not
|
||||
# greater than the given value. This can be used to avoid Buffer Overflows
|
||||
# in WWW clients and various Internet servers.
|
||||
|
||||
if (strlen($value) > $checkvalue)
|
||||
$ok = false;
|
||||
break;
|
||||
|
||||
case 'minlen':
|
||||
# The minlen check makes sure that the attribute value has a length not
|
||||
# smaller than the given value.
|
||||
|
||||
if (strlen($value) < $checkvalue)
|
||||
$ok = false;
|
||||
break;
|
||||
|
||||
case 'maxval':
|
||||
# The maxval check does two things: it checks that the attribute value is
|
||||
# an integer from 0 and up, without an excessive amount of zeroes or
|
||||
# whitespace (to avoid Buffer Overflows). It also checks that the attribute
|
||||
# value is not greater than the given value.
|
||||
# This check can be used to avoid Denial of Service attacks.
|
||||
|
||||
if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
|
||||
$ok = false;
|
||||
if ($value > $checkvalue)
|
||||
$ok = false;
|
||||
break;
|
||||
|
||||
case 'minval':
|
||||
# The minval check checks that the attribute value is a positive integer,
|
||||
# and that it is not smaller than the given value.
|
||||
|
||||
if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value))
|
||||
$ok = false;
|
||||
if ($value < $checkvalue)
|
||||
$ok = false;
|
||||
break;
|
||||
|
||||
case 'valueless':
|
||||
# The valueless check checks if the attribute has a value
|
||||
# (like <a href="blah">) or not (<option selected>). If the given value
|
||||
# is a "y" or a "Y", the attribute must not have a value.
|
||||
# If the given value is an "n" or an "N", the attribute must have one.
|
||||
|
||||
if (strtolower($checkvalue) != $vless)
|
||||
$ok = false;
|
||||
break;
|
||||
} # switch
|
||||
|
||||
return $ok;
|
||||
} # function kses_check_attr_val
|
||||
|
||||
/**
|
||||
* This function removes all non-allowed protocols from the beginning of
|
||||
* $string. It ignores whitespace and the case of the letters, and it does
|
||||
* understand HTML entities. It does its work in a while loop, so it won't be
|
||||
* fooled by a string like "javascript:javascript:alert(57)".
|
||||
*
|
||||
* @param string $string
|
||||
* @param array $$allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses_bad_protocol($string, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function removes all non-allowed protocols from the beginning of
|
||||
# $string. It ignores whitespace and the case of the letters, and it does
|
||||
# understand HTML entities. It does its work in a while loop, so it won't be
|
||||
# fooled by a string like "javascript:javascript:alert(57)".
|
||||
###############################################################################
|
||||
{
|
||||
$string = kses_no_null($string);
|
||||
$string = preg_replace('/([^\xc3-\xcf])\xad+/', '\\1', $string); # deals with Opera "feature" -- moodle utf8 fix
|
||||
$string2 = $string.'a';
|
||||
|
||||
while ($string != $string2)
|
||||
{
|
||||
$string2 = $string;
|
||||
$string = kses_bad_protocol_once($string, $allowed_protocols);
|
||||
} # while
|
||||
|
||||
return $string;
|
||||
} # function kses_bad_protocol
|
||||
|
||||
/**
|
||||
* This function removes any NULL characters in $string.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function kses_no_null($string)
|
||||
###############################################################################
|
||||
# This function removes any NULL characters in $string.
|
||||
###############################################################################
|
||||
{
|
||||
$string = preg_replace('/\0+/', '', $string);
|
||||
$string = preg_replace('/(\\\\0)+/', '', $string);
|
||||
|
||||
return $string;
|
||||
} # function kses_no_null
|
||||
|
||||
|
||||
/**
|
||||
* This function changes the character sequence \" to just "
|
||||
* It leaves all other slashes alone. It's really weird, but the quoting from
|
||||
* preg_replace(//e) seems to require this.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function kses_stripslashes($string)
|
||||
###############################################################################
|
||||
# This function changes the character sequence \" to just "
|
||||
# It leaves all other slashes alone. It's really weird, but the quoting from
|
||||
# preg_replace(//e) seems to require this.
|
||||
###############################################################################
|
||||
{
|
||||
return preg_replace('%\\\\"%', '"', $string);
|
||||
} # function kses_stripslashes
|
||||
|
||||
|
||||
/**
|
||||
* This function goes through an array, and changes the keys to all lower case.
|
||||
*
|
||||
* @param array $inarray
|
||||
* @return array
|
||||
*/
|
||||
function kses_array_lc($inarray)
|
||||
###############################################################################
|
||||
# This function goes through an array, and changes the keys to all lower case.
|
||||
###############################################################################
|
||||
{
|
||||
$outarray = array();
|
||||
|
||||
foreach ($inarray as $inkey => $inval)
|
||||
{
|
||||
$outkey = strtolower($inkey);
|
||||
$outarray[$outkey] = array();
|
||||
|
||||
foreach ($inval as $inkey2 => $inval2)
|
||||
{
|
||||
$outkey2 = strtolower($inkey2);
|
||||
$outarray[$outkey][$outkey2] = $inval2;
|
||||
} # foreach $inval
|
||||
} # foreach $inarray
|
||||
|
||||
return $outarray;
|
||||
} # function kses_array_lc
|
||||
|
||||
/**
|
||||
* This function removes the HTML JavaScript entities found in early versions of
|
||||
* Netscape 4.
|
||||
*
|
||||
* @param string $string
|
||||
*/
|
||||
function kses_js_entities($string)
|
||||
###############################################################################
|
||||
# This function removes the HTML JavaScript entities found in early versions of
|
||||
# Netscape 4.
|
||||
###############################################################################
|
||||
{
|
||||
return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string);
|
||||
} # function kses_js_entities
|
||||
|
||||
/**
|
||||
* This function deals with parsing errors in kses_hair(). The general plan is
|
||||
* to remove everything to and including some whitespace, but it deals with
|
||||
* quotes and apostrophes as well.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function kses_html_error($string)
|
||||
###############################################################################
|
||||
# This function deals with parsing errors in kses_hair(). The general plan is
|
||||
# to remove everything to and including some whitespace, but it deals with
|
||||
# quotes and apostrophes as well.
|
||||
###############################################################################
|
||||
{
|
||||
return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string);
|
||||
} # function kses_html_error
|
||||
|
||||
/**
|
||||
* This function searches for URL protocols at the beginning of $string, while
|
||||
* handling whitespace and HTML entities.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses_bad_protocol_once($string, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function searches for URL protocols at the beginning of $string, while
|
||||
# handling whitespace and HTML entities.
|
||||
###############################################################################
|
||||
{
|
||||
$string2 = preg_split('/:|:|:/i', $string, 2);
|
||||
if(isset($string2[1]) && !preg_match('%/\?%',$string2[0]))
|
||||
{
|
||||
$string = kses_bad_protocol_once2($string2[0],$allowed_protocols).trim($string2[1]);
|
||||
}
|
||||
return $string;
|
||||
} # function kses_bad_protocol_once
|
||||
|
||||
/**
|
||||
* This function processes URL protocols, checks to see if they're in the white-
|
||||
* list or not, and returns different data depending on the answer.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $allowed_protocols
|
||||
* @return string
|
||||
*/
|
||||
function kses_bad_protocol_once2($string, $allowed_protocols)
|
||||
###############################################################################
|
||||
# This function processes URL protocols, checks to see if they're in the white-
|
||||
# list or not, and returns different data depending on the answer.
|
||||
###############################################################################
|
||||
{
|
||||
$string2 = kses_decode_entities($string);
|
||||
$string2 = preg_replace('/\s/', '', $string2);
|
||||
$string2 = kses_no_null($string2);
|
||||
$string2 = preg_replace('/\xad+/', '', $string2);
|
||||
# deals with Opera "feature"
|
||||
$string2 = strtolower($string2);
|
||||
|
||||
$allowed = false;
|
||||
foreach ($allowed_protocols as $one_protocol)
|
||||
if (strtolower($one_protocol) == $string2)
|
||||
{
|
||||
$allowed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($allowed)
|
||||
return "$string2:";
|
||||
else
|
||||
return '';
|
||||
} # function kses_bad_protocol_once2
|
||||
|
||||
/**
|
||||
* This function normalizes HTML entities. It will convert "AT&T" to the correct
|
||||
* "AT&T", ":" to ":", "&#XYZZY;" to "&#XYZZY;" and so on.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function kses_normalize_entities($string)
|
||||
###############################################################################
|
||||
# This function normalizes HTML entities. It will convert "AT&T" to the correct
|
||||
# "AT&T", ":" to ":", "&#XYZZY;" to "&#XYZZY;" and so on.
|
||||
###############################################################################
|
||||
{
|
||||
# Disarm all entities by converting & to &
|
||||
|
||||
$string = str_replace('&', '&', $string);
|
||||
|
||||
# Change back the allowed entities in our entity whitelist
|
||||
|
||||
$string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/',
|
||||
'&\\1;', $string);
|
||||
$string = preg_replace('/&#0*([0-9]{1,5});/e',
|
||||
'kses_normalize_entities2("\\1")', $string);
|
||||
$string = preg_replace('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/',
|
||||
'&#\\1\\2;', $string);
|
||||
|
||||
return $string;
|
||||
} # function kses_normalize_entities
|
||||
|
||||
/**
|
||||
* This function helps kses_normalize_entities() to only accept 16 bit values
|
||||
* and nothing more for &#number; entities.
|
||||
*
|
||||
* @param int $i
|
||||
* @return string
|
||||
*/
|
||||
function kses_normalize_entities2($i)
|
||||
###############################################################################
|
||||
# This function helps kses_normalize_entities() to only accept 16 bit values
|
||||
# and nothing more for &#number; entities.
|
||||
###############################################################################
|
||||
{
|
||||
return (($i > 65535) ? "&#$i;" : "&#$i;");
|
||||
} # function kses_normalize_entities2
|
||||
|
||||
/**
|
||||
* This function decodes numeric HTML entities (A and A). It doesn't
|
||||
* do anything with other entities like ä, but we don't need them in the
|
||||
* URL protocol whitelisting system anyway.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function kses_decode_entities($string)
|
||||
###############################################################################
|
||||
# This function decodes numeric HTML entities (A and A). It doesn't
|
||||
# do anything with other entities like ä, but we don't need them in the
|
||||
# URL protocol whitelisting system anyway.
|
||||
###############################################################################
|
||||
{
|
||||
$string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string);
|
||||
$string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))',
|
||||
$string);
|
||||
|
||||
return $string;
|
||||
} # function kses_decode_entities
|
||||
|
||||
?>
|
256
lib/md5.js
256
lib/md5.js
@ -1,256 +0,0 @@
|
||||
/*
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for more info.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configurable variables. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
*/
|
||||
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
|
||||
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
|
||||
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
|
||||
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
|
||||
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
|
||||
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function md5_vm_test()
|
||||
{
|
||||
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the MD5 of an array of little-endian words, and a bit length
|
||||
*/
|
||||
function core_md5(x, len)
|
||||
{
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << ((len) % 32);
|
||||
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
||||
|
||||
var a = 1732584193;
|
||||
var b = -271733879;
|
||||
var c = -1732584194;
|
||||
var d = 271733878;
|
||||
|
||||
for(var i = 0; i < x.length; i += 16)
|
||||
{
|
||||
var olda = a;
|
||||
var oldb = b;
|
||||
var oldc = c;
|
||||
var oldd = d;
|
||||
|
||||
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
|
||||
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
|
||||
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
|
||||
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
|
||||
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
|
||||
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
|
||||
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
|
||||
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
|
||||
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
|
||||
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
|
||||
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
|
||||
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
|
||||
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
|
||||
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
|
||||
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
|
||||
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
|
||||
|
||||
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
|
||||
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
|
||||
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
|
||||
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
|
||||
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
|
||||
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
|
||||
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
|
||||
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
|
||||
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
|
||||
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
|
||||
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
|
||||
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
|
||||
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
|
||||
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
|
||||
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
|
||||
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
|
||||
|
||||
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
|
||||
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
|
||||
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
|
||||
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
|
||||
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
|
||||
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
|
||||
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
|
||||
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
|
||||
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
|
||||
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
|
||||
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
|
||||
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
|
||||
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
|
||||
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
|
||||
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
|
||||
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
|
||||
|
||||
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
|
||||
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
|
||||
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
|
||||
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
|
||||
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
|
||||
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
|
||||
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
|
||||
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
|
||||
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
|
||||
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
|
||||
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
|
||||
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
|
||||
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
|
||||
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
|
||||
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
|
||||
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
}
|
||||
return Array(a, b, c, d);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions implement the four basic operations the algorithm uses.
|
||||
*/
|
||||
function md5_cmn(q, a, b, x, s, t)
|
||||
{
|
||||
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
|
||||
}
|
||||
function md5_ff(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
|
||||
}
|
||||
function md5_gg(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
|
||||
}
|
||||
function md5_hh(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
|
||||
}
|
||||
function md5_ii(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-MD5, of a key and some data
|
||||
*/
|
||||
function core_hmac_md5(key, data)
|
||||
{
|
||||
var bkey = str2binl(key);
|
||||
if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
|
||||
|
||||
var ipad = Array(16), opad = Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
{
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
|
||||
return core_md5(opad.concat(hash), 512 + 128);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y)
|
||||
{
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function bit_rol(num, cnt)
|
||||
{
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string to an array of little-endian words
|
||||
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
|
||||
*/
|
||||
function str2binl(str)
|
||||
{
|
||||
var bin = Array();
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < str.length * chrsz; i += chrsz)
|
||||
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a string
|
||||
*/
|
||||
function binl2str(bin)
|
||||
{
|
||||
var str = "";
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < bin.length * 32; i += chrsz)
|
||||
str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a hex string.
|
||||
*/
|
||||
function binl2hex(binarray)
|
||||
{
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i++)
|
||||
{
|
||||
str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
|
||||
hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a base-64 string
|
||||
*/
|
||||
function binl2b64(binarray)
|
||||
{
|
||||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i += 3)
|
||||
{
|
||||
var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)
|
||||
| (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
|
||||
| ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
|
||||
for(var j = 0; j < 4; j++)
|
||||
{
|
||||
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
|
||||
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
@ -126,7 +126,7 @@ function message_send($eventdata) {
|
||||
} else {
|
||||
//MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't
|
||||
//exist in the message_provider table (thus there is no default settings for them)
|
||||
$preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename);
|
||||
$preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename); //TODO: undefined $preferencename
|
||||
throw new coding_exception($preferrormsg,'blah');
|
||||
}
|
||||
|
||||
|
@ -8324,124 +8324,6 @@ function upgrade_set_timeout($max_execution_time=300) {
|
||||
|
||||
/// MISCELLANEOUS ////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Notify admin users or admin user of any failed logins (since last notification).
|
||||
*
|
||||
* Note that this function must be only executed from the cron script
|
||||
* It uses the cache_flags system to store temporary records, deleting them
|
||||
* by name before finishing
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses HOURSECS
|
||||
*/
|
||||
function notify_login_failures() {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
$recip = get_users_from_config($CFG->notifyloginfailures, 'moodle/site:config');
|
||||
|
||||
if (empty($CFG->lastnotifyfailure)) {
|
||||
$CFG->lastnotifyfailure=0;
|
||||
}
|
||||
|
||||
// we need to deal with the threshold stuff first.
|
||||
if (empty($CFG->notifyloginthreshold)) {
|
||||
$CFG->notifyloginthreshold = 10; // default to something sensible.
|
||||
}
|
||||
|
||||
/// Get all the IPs with more than notifyloginthreshold failures since lastnotifyfailure
|
||||
/// and insert them into the cache_flags temp table
|
||||
$sql = "SELECT ip, COUNT(*)
|
||||
FROM {log}
|
||||
WHERE module = 'login' AND action = 'error'
|
||||
AND time > ?
|
||||
GROUP BY ip
|
||||
HAVING COUNT(*) >= ?";
|
||||
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $iprec) {
|
||||
if (!empty($iprec->ip)) {
|
||||
set_cache_flag('login_failure_by_ip', $iprec->ip, '1', 0);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
|
||||
/// and insert them into the cache_flags temp table
|
||||
$sql = "SELECT info, count(*)
|
||||
FROM {log}
|
||||
WHERE module = 'login' AND action = 'error'
|
||||
AND time > ?
|
||||
GROUP BY info
|
||||
HAVING count(*) >= ?";
|
||||
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $inforec) {
|
||||
if (!empty($inforec->info)) {
|
||||
set_cache_flag('login_failure_by_info', $inforec->info, '1', 0);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// Now, select all the login error logged records belonging to the ips and infos
|
||||
/// since lastnotifyfailure, that we have stored in the cache_flags table
|
||||
$sql = "SELECT l.*, u.firstname, u.lastname
|
||||
FROM {log} l
|
||||
JOIN {cache_flags} cf ON l.ip = cf.name
|
||||
LEFT JOIN {user} u ON l.userid = u.id
|
||||
WHERE l.module = 'login' AND l.action = 'error'
|
||||
AND l.time > ?
|
||||
AND cf.flagtype = 'login_failure_by_ip'
|
||||
UNION ALL
|
||||
SELECT l.*, u.firstname, u.lastname
|
||||
FROM {log} l
|
||||
JOIN {cache_flags} cf ON l.info = cf.name
|
||||
LEFT JOIN {user} u ON l.userid = u.id
|
||||
WHERE l.module = 'login' AND l.action = 'error'
|
||||
AND l.time > ?
|
||||
AND cf.flagtype = 'login_failure_by_info'
|
||||
ORDER BY time DESC";
|
||||
$params = array($CFG->lastnotifyfailure, $CFG->lastnotifyfailure);
|
||||
|
||||
/// Init some variables
|
||||
$count = 0;
|
||||
$messages = '';
|
||||
/// Iterate over the logs recordset
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $log) {
|
||||
$log->time = userdate($log->time);
|
||||
$messages .= get_string('notifyloginfailuresmessage','',$log)."\n";
|
||||
$count++;
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// If we haven't run in the last hour and
|
||||
/// we have something useful to report and we
|
||||
/// are actually supposed to be reporting to somebody
|
||||
if ((time() - HOURSECS) > $CFG->lastnotifyfailure && $count > 0 && is_array($recip) && count($recip) > 0) {
|
||||
$site = get_site();
|
||||
$subject = get_string('notifyloginfailuressubject', '', format_string($site->fullname));
|
||||
/// Calculate the complete body of notification (start + messages + end)
|
||||
$body = get_string('notifyloginfailuresmessagestart', '', $CFG->wwwroot) .
|
||||
(($CFG->lastnotifyfailure != 0) ? '('.userdate($CFG->lastnotifyfailure).')' : '')."\n\n" .
|
||||
$messages .
|
||||
"\n\n".get_string('notifyloginfailuresmessageend','',$CFG->wwwroot)."\n\n";
|
||||
|
||||
/// For each destination, send mail
|
||||
mtrace('Emailing admins about '. $count .' failed login attempts');
|
||||
foreach ($recip as $admin) {
|
||||
//emailing the admins directly rather than putting these through the messaging system
|
||||
email_to_user($admin,get_admin(), $subject, $body);
|
||||
}
|
||||
|
||||
/// Update lastnotifyfailure with current time
|
||||
set_config('lastnotifyfailure', time());
|
||||
}
|
||||
|
||||
/// Finally, delete all the temp records we have created in cache_flags
|
||||
$DB->delete_records_select('cache_flags', "flagtype IN ('login_failure_by_ip', 'login_failure_by_info')");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the system locale
|
||||
*
|
||||
@ -9831,11 +9713,6 @@ function get_performance_info() {
|
||||
$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)) {
|
||||
|
74
lib/odbc.php
74
lib/odbc.php
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* odbc.php - This is the ODBC Socket Server class PHP client class
|
||||
* with sample usage at bottom.
|
||||
*
|
||||
* Released into the public domain for version 0.90 of ODBC Socket Server
|
||||
* {@link http://odbc.linuxbox.com/}
|
||||
*
|
||||
* @package moodlecore
|
||||
* @author Team FXML
|
||||
* @copyright Copyright (c) 1999 Team FXML
|
||||
* @license http://odbc.linuxbox.com/ public domain
|
||||
*/
|
||||
|
||||
/**
|
||||
* ODBC Socket Server class
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright Copyright (c) 1999 Team FXML
|
||||
* @license http://odbc.linuxbox.com/ public domain
|
||||
*/
|
||||
class ODBCSocketServer {
|
||||
|
||||
/**
|
||||
* Name of the host to connect to
|
||||
* @var string $sHostName
|
||||
*/
|
||||
var $sHostName;
|
||||
/**
|
||||
* Port to connect to
|
||||
* @var int $nPort
|
||||
*/
|
||||
var $nPort;
|
||||
/**
|
||||
* Connection string to use
|
||||
* @var string $sConnectionString
|
||||
*/
|
||||
var $sConnectionString;
|
||||
|
||||
//
|
||||
/**
|
||||
* Function to parse the SQL
|
||||
*
|
||||
* @param string $sSQL The SQL statement to parse
|
||||
* @return string
|
||||
*/
|
||||
function ExecSQL($sSQL) {
|
||||
|
||||
$fToOpen = fsockopen($this->sHostName, $this->nPort, &$errno, &$errstr, 30);
|
||||
if (!$fToOpen)
|
||||
{
|
||||
//contruct error string to return
|
||||
$sReturn = "<?xml version=\"1.0\"?>\r\n<result state=\"failure\">\r\n<error>$errstr</error>\r\n</result>\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
//construct XML to send
|
||||
//search and replace HTML chars in SQL first
|
||||
$sSQL = HTMLSpecialChars($sSQL);
|
||||
$sSend = "<?xml version=\"1.0\"?>\r\n<request>\r\n<connectionstring>$this->sConnectionString</connectionstring>\r\n<sql>$sSQL</sql>\r\n</request>\r\n";
|
||||
//write request
|
||||
fputs($fToOpen, $sSend);
|
||||
//now read response
|
||||
while (!feof($fToOpen))
|
||||
{
|
||||
$sReturn = $sReturn . fgets($fToOpen, 128);
|
||||
}
|
||||
fclose($fToOpen);
|
||||
}
|
||||
return $sReturn;
|
||||
}
|
||||
}//class
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -1,333 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Anchor Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.10 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
|
||||
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Anchor Plugin.');
|
||||
else {
|
||||
registerCommands('anchor,anchorx,anchory,noanchorwarn,anchoralign');
|
||||
|
||||
|
||||
|
||||
////////
|
||||
// DEFAULT CONFIGURATION
|
||||
// Settings you want everywhere are set here. All of this can also be
|
||||
// changed on your html page or through an overLIB call.
|
||||
////////
|
||||
if (typeof ol_anchor == 'undefined') var ol_anchor = '';
|
||||
if (typeof ol_anchorx == 'undefined') var ol_anchorx = 0;
|
||||
if (typeof ol_anchory == 'undefined') var ol_anchory = 0;
|
||||
if (typeof ol_noanchorwarn == 'undefined') var ol_noanchorwarn = 1;
|
||||
if (typeof ol_anchoralign == 'undefined') var ol_anchoralign = 'UL';
|
||||
|
||||
////////
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////
|
||||
// INIT
|
||||
////////
|
||||
// Runtime variables init. Don't change for config!
|
||||
var o3_anchor = "";
|
||||
var o3_anchorx = 0;
|
||||
var o3_anchory = 0;
|
||||
var o3_noanchorwarn = 1;
|
||||
var o3_anchoralign = 'UL';
|
||||
var mrkObj, rmrkPosition; //reference mark object, reference mark position, an array;
|
||||
|
||||
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
function setAnchorVariables() {
|
||||
o3_anchor = ol_anchor;
|
||||
o3_anchorx = ol_anchorx;
|
||||
o3_anchory = ol_anchory;
|
||||
o3_noanchorwarn = ol_noanchorwarn;
|
||||
o3_anchoralign = ol_anchoralign;
|
||||
mrkObj = null; // initialize this variable
|
||||
}
|
||||
|
||||
// Parses Reference Mark commands
|
||||
function parseAnchorExtras(pf,i,ar) {
|
||||
var v, k=i;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k] == ANCHOR) { eval(pf + "anchor = '" + escSglQuote(ar[++k]) + "'"); return k; }
|
||||
if (ar[k] == ANCHORX) { eval(pf + 'anchorx = ' + ar[++k]); return k; }
|
||||
if (ar[k] == ANCHORY) { eval(pf + 'anchory = ' + ar[++k]); return k; }
|
||||
if (ar[k] == NOANCHORWARN) { eval(pf + 'noanchorwarn = (' + pf + 'noanchorwarn==1) ? 0 : 1'); return k; }
|
||||
if (ar[k] == ANCHORALIGN) { k = opt_MULTIPLEARGS(++k, ar, (pf + 'anchoralign')); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
// FUNCTION WHICH CHECKS FOR THE EXISTENCE OF A REFERENCE MARKER
|
||||
///////
|
||||
function checkAnchorObject() {
|
||||
var w = o3_anchor;
|
||||
|
||||
if (w) {
|
||||
if (!(mrkObj = getAnchorObjectRef(w))) {
|
||||
if (o3_noanchorwarn) {
|
||||
alert('WARNING! Reference mark "' + w + '" not found.');
|
||||
return false;
|
||||
} else w = '';
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////
|
||||
// EXTERNAL SUPPORT FUNCTIONS TO HANDLE ANCHOR PROPERTIES
|
||||
///////
|
||||
|
||||
// Horizontal placement routine with anchors
|
||||
function anchorHorizontal(browserWidth, horizontalScrollAmount, widthFix) {
|
||||
var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
|
||||
if (!hasAnchor) return void(0);
|
||||
|
||||
// set o3_relx for follow scroll if defined
|
||||
if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_relx = rmrkPosition[0];
|
||||
|
||||
return rmrkPosition[0];
|
||||
}
|
||||
|
||||
// Vertical placement routine with anchors
|
||||
function anchorVertical(browserHeight,verticalScrollAmount) {
|
||||
var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
|
||||
if (!hasAnchor) return void(0);
|
||||
|
||||
// set o3_rely for follow scroll if defined
|
||||
if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_rely = rmrkPosition[1];
|
||||
|
||||
return rmrkPosition[1];
|
||||
}
|
||||
|
||||
// Stub function for the runHook routine
|
||||
function anchorPreface() {
|
||||
if (!mrkObj) return;
|
||||
rmrkPosition = getAnchorLocation(mrkObj);
|
||||
}
|
||||
|
||||
// Get Reference Mark object
|
||||
function getAnchorObjectRef(aObj) {
|
||||
return getRefById(aObj, o3_frame.document) || getRefByName(aObj, o3_frame.document)
|
||||
}
|
||||
|
||||
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
|
||||
function getAnchorLocation(objRef){
|
||||
var mkObj, of, offsets, mlyr
|
||||
|
||||
mkObj = mlyr = objRef
|
||||
offsets = [o3_anchorx, o3_anchory]
|
||||
|
||||
if (document.layers){
|
||||
if (typeof mlyr.length != 'undefined' && mlyr.length > 1) {
|
||||
mkObj = mlyr[0]
|
||||
offsets[0] += mlyr[0].x + mlyr[1].pageX
|
||||
offsets[1] += mlyr[0].y + mlyr[1].pageY
|
||||
} else {
|
||||
if(mlyr.toString().indexOf('Image') != -1 || mlyr.toString().indexOf('Anchor') != -1){
|
||||
offsets[0] += mlyr.x
|
||||
offsets[1] += mlyr.y
|
||||
} else {
|
||||
offsets[0] += mlyr.pageX
|
||||
offsets[1] += mlyr.pageY
|
||||
}
|
||||
}
|
||||
} else {
|
||||
offsets[0] += pageLocation(mlyr, 'Left')
|
||||
offsets[1] += pageLocation(mlyr, 'Top')
|
||||
}
|
||||
|
||||
of = getAnchorOffsets(mkObj)
|
||||
|
||||
if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
|
||||
olImgLeft = offsets[0];
|
||||
olImgTop = offsets[1];
|
||||
}
|
||||
|
||||
offsets[0] += of[0]
|
||||
offsets[1] += of[1]
|
||||
|
||||
if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
|
||||
olImgRight = offsets[0];
|
||||
olImgBottom = offsets[1];
|
||||
return;
|
||||
}
|
||||
|
||||
return offsets;
|
||||
}
|
||||
|
||||
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
|
||||
function getAnchorOffsets(mkObj){
|
||||
var fx = fy = 0, mp, puc, mkAry, sx = sy = 0, w = o3_anchoralign
|
||||
var mW = mH = pW = pH = 0
|
||||
var off = [0, 0]
|
||||
|
||||
mkAry = w.split(',');
|
||||
|
||||
if (mkAry.length < 3) {
|
||||
mp = mkAry[0].toUpperCase();
|
||||
puc = (mkAry.length == 1) ? mp : mkAry[1].toUpperCase();
|
||||
} else if (mkAry.length == 3) {
|
||||
if (!isNaN(mkAry[0])) {
|
||||
mp = mkAry.slice(0, 2);
|
||||
puc = mkAry[2].toUpperCase();
|
||||
} else {
|
||||
mp = mkAry[0].toUpperCase();
|
||||
puc = mkAry.slice(1);
|
||||
}
|
||||
} else {
|
||||
mp = mkAry.slice(0, 2);
|
||||
puc = mkAry.slice(2);
|
||||
}
|
||||
|
||||
var shdwPresent = typeof o3_shadow != 'undefined' && o3_shadow
|
||||
|
||||
if (shdwPresent) {
|
||||
sx = Math.abs(o3_shadowx);
|
||||
sy = Math.abs(o3_shadowy);
|
||||
}
|
||||
|
||||
pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
|
||||
pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
|
||||
|
||||
if (olOp && o3_wrap) {
|
||||
pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
|
||||
pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
|
||||
}
|
||||
|
||||
if (!olOp && mkObj.toString().indexOf('Image') != -1){
|
||||
mW = mkObj.width
|
||||
mH = mkObj.height
|
||||
} else if (!olOp && mkObj.toString().indexOf('Anchor') != -1) { // enforced only for NS4
|
||||
mp = 'UL'
|
||||
} else {
|
||||
mW = (olNs4) ? mkObj.clip.width : mkObj.offsetWidth
|
||||
mH = (olNs4) ? mkObj.clip.height : mkObj.offsetHeight
|
||||
}
|
||||
|
||||
if (!isNaN(mp) || typeof mp == 'object') {
|
||||
if (typeof mp == 'object') {
|
||||
fx = parseFloat(mp[0]);
|
||||
fy = parseFloat(mp[1]);
|
||||
} else
|
||||
fx = fy = parseFloat(mp);
|
||||
off = [Math.round(fx*mW), Math.round(fy*mH)];
|
||||
} else {
|
||||
if (mp == 'UR') off = [mW, 0]
|
||||
else if (mp == 'LL') off = [0, mH]
|
||||
else if (mp == 'LR') off = [mW, mH]
|
||||
}
|
||||
|
||||
if (typeof o3_dragimg != 'undefined' && o3_dragimg) return off;
|
||||
else {
|
||||
if (!isNaN(puc) || typeof puc == 'object' ) {
|
||||
if (typeof puc == 'object') {
|
||||
fx = parseFloat(puc[0]);
|
||||
fy = parseFloat(puc[1]);
|
||||
} else
|
||||
fx = fy = parseFloat(puc);
|
||||
off[0] -= Math.round(fx*(pW - sx));
|
||||
off[1] -= Math.round(fy*(pH - sy));
|
||||
} else {
|
||||
if (puc == 'UR') {
|
||||
off[0] -= (pW - sx);
|
||||
off[1] -= sy
|
||||
} else if (puc == 'LL') {
|
||||
off[0] -= sx;
|
||||
off[1] -= (pH - sy)
|
||||
} else if (puc == 'LR') {
|
||||
off[0] -= (pW-sx);
|
||||
off[1] -= (pH - sy)
|
||||
}
|
||||
}
|
||||
return off
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
|
||||
function pageLocation(o, t){
|
||||
var x = 0
|
||||
|
||||
while(o.offsetParent){
|
||||
x += o['offset' + t]
|
||||
o = o.offsetParent
|
||||
}
|
||||
x += o['offset' + t]
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
|
||||
function getRefById(l, d){
|
||||
var r = "", j
|
||||
|
||||
d = (d || document)
|
||||
if (d.all) return d.all[l]
|
||||
else if (d.getElementById) return d.getElementById(l)
|
||||
else if (d.layers && d.layers.length > 0) {
|
||||
if (d.layers[l]) return d.layers[l]
|
||||
|
||||
for (j=0; j < d.layers.length; j++) {
|
||||
r = getRefById(l, d.layers[j].document)
|
||||
if(r) return r
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
|
||||
function getRefByName(l, d) {
|
||||
var r = null, j
|
||||
|
||||
d = (d || document)
|
||||
|
||||
if (d.images[l]) return d.images[l]
|
||||
else if (d.anchors[l]) return d.anchors[l];
|
||||
else if (d.layers && d.layers.length > 0) {
|
||||
for (j=0; j < d.layers.length; j++) {
|
||||
r = getRefByName(l, d.layers[j].document)
|
||||
if (r && r.length > 0) return r
|
||||
else if (r) return [r, d.layers[j]]
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerRunTimeFunction(setAnchorVariables);
|
||||
registerCmdLineFunction(parseAnchorExtras);
|
||||
registerPostParseFunction(checkAnchorObject);
|
||||
registerHook("createPopup", anchorPreface, FAFTER);
|
||||
registerHook("horizontalPlacement", anchorHorizontal, FCHAIN);
|
||||
registerHook("verticalPlacement", anchorVertical, FCHAIN);
|
||||
if(olInfo.meets(4.10)) registerNoParameterCommands('noanchorwarn');
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Center Popup Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.10 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2003. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//
|
||||
//\/////
|
||||
//\mini
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Center Popup Plugin.');
|
||||
else {
|
||||
registerCommands('centerpopup,centeroffset');
|
||||
////////
|
||||
// DEFAULT CONFIGURATION
|
||||
// You don't have to change anything here if you don't want to. All of this can be
|
||||
// changed on your html page or through an overLIB call.
|
||||
////////
|
||||
// Default value for centerpopup is to not center the popup
|
||||
if (typeof ol_centerpopup == 'undefined') var ol_centerpopup = 0;
|
||||
if (typeof ol_centeroffset == 'undefined') var ol_centeroffset = '0';
|
||||
////////
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
////////
|
||||
// INIT
|
||||
////////
|
||||
// Runtime variables init. Don't change for config!
|
||||
var o3_centerpopup = 0;
|
||||
var o3_centeroffset = '0';
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
function setCenterPopupVariables() {
|
||||
o3_centerpopup = ol_centerpopup;
|
||||
o3_centeroffset = ol_centeroffset;
|
||||
}
|
||||
// Parses Shadow and Scroll commands
|
||||
function parseCenterPopupExtras(pf,i,ar) {
|
||||
var k = i,v;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k] == CENTERPOPUP) { eval(pf + 'centerpopup = (' + pf + 'centerpopup == 0) ? 1 : 0'); return k; }
|
||||
if (ar[k] == CENTEROFFSET) { k = opt_MULTIPLEARGS(++k,ar,(pf + 'centeroffset')); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
// Function which positions popup in Center of screen
|
||||
function centerPopupHorizontal(browserWidth, horizontalScrollAmount, widthFix) {
|
||||
if (!o3_centerpopup) return void(0);
|
||||
|
||||
var vdisp = o3_centeroffset.split(',');
|
||||
var placeX, iwidth = browserWidth, winoffset = horizontalScrollAmount;
|
||||
var pWd = parseInt(o3_width);
|
||||
|
||||
placeX = winoffset + Math.round((iwidth - widthFix - pWd)/2) + parseInt(vdisp[0]);
|
||||
if(typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_relx = placeX;
|
||||
|
||||
return placeX;
|
||||
}
|
||||
function centerPopupVertical(browserHeight,verticalScrollAmount) {
|
||||
if (!o3_centerpopup) return void(0);
|
||||
|
||||
var placeY, iheight = browserHeight, scrolloffset = verticalScrollAmount;
|
||||
var vdisp = o3_centeroffset.split(',');
|
||||
var pHeight = (o3_aboveheight ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight));
|
||||
|
||||
placeY = scrolloffset + Math.round((iheight - pHeight)/2) + (vdisp.length > 1 ? parseInt(vdisp[1]) : 0);
|
||||
if(typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_rely = placeY;
|
||||
|
||||
return placeY;
|
||||
}
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerRunTimeFunction(setCenterPopupVariables);
|
||||
registerCmdLineFunction(parseCenterPopupExtras);
|
||||
registerHook('horizontalPlacement',centerPopupHorizontal,FCHAIN);
|
||||
registerHook('verticalPlacement', centerPopupVertical, FCHAIN);
|
||||
if(olInfo.meets(4.10)) registerNoParameterCommands('centerpopup');
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Crossframe Support Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.05 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Cross Frame Support Plugin.');
|
||||
else {
|
||||
registerCommands('frame');
|
||||
|
||||
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
///////
|
||||
|
||||
// Parses FRAME command
|
||||
function parseFrameExtras(pf,i,ar) {
|
||||
var k = i,v;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k] == FRAME) { v = ar[++k]; if(pf == 'ol_') ol_frame = v; else opt_FRAME(v); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
////////
|
||||
// SUPPORT FUNCTIONS
|
||||
////////
|
||||
|
||||
// Defines which frame we should point to.
|
||||
function opt_FRAME(frm) {
|
||||
o3_frame = frm;
|
||||
over = createDivContainer('overDiv');
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get frame depth of nested frames
|
||||
function frmDepth(thisFrame,ofrm) {
|
||||
var retVal = '';
|
||||
|
||||
for (var i = 0; i<thisFrame.length; i++) {
|
||||
if (thisFrame[i].length > 0) {
|
||||
retVal = frmDepth(thisFrame[i],ofrm);
|
||||
if (retVal == '') continue;
|
||||
} else if (thisFrame[i] != ofrm) continue;
|
||||
retVal = '[' + i + ']' + retVal;
|
||||
break;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Gets frame reference value relative to top frame
|
||||
function getFrmRef(srcFrm,tgetFrm) {
|
||||
var rtnVal = ''
|
||||
|
||||
if (tgetFrm != srcFrm) {
|
||||
var tFrm = frmDepth(top.frames,tgetFrm)
|
||||
var sFrm = frmDepth(top.frames,srcFrm)
|
||||
if (sFrm.length == tFrm.length) {
|
||||
l = tFrm.lastIndexOf('[')
|
||||
|
||||
if (l) {
|
||||
while ( sFrm.substring(0,l) != tFrm.substring(0,l) )
|
||||
l = tFrm.lastIndexOf('[',l-1)
|
||||
tFrm = tFrm.substr(l)
|
||||
sFrm = sFrm.substr(l)
|
||||
}
|
||||
}
|
||||
|
||||
var cnt = 0, p = '',str = tFrm
|
||||
while ((k = str.lastIndexOf('[')) != -1) {
|
||||
cnt++
|
||||
str = str.substring(0,k)
|
||||
}
|
||||
|
||||
for (var i = 0; i<cnt; i++) p = p + 'parent.'
|
||||
rtnVal = p + 'frames' + sFrm + '.'
|
||||
}
|
||||
|
||||
return rtnVal
|
||||
}
|
||||
|
||||
function chkForFrmRef() {
|
||||
if(o3_frame != ol_frame) fnRef = getFrmRef(ol_frame,o3_frame)
|
||||
return true;
|
||||
}
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerCmdLineFunction(parseFrameExtras);
|
||||
registerPostParseFunction(chkForFrmRef);
|
||||
}
|
@ -1,182 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB CSS Style Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.05 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
|
||||
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the CSS Style Plugin.');
|
||||
else {
|
||||
registerCommands('cssstyle,padunit,heightunit,widthunit,textsizeunit,textdecoration,textstyle,textweight,captionsizeunit,captiondecoration,captionstyle,captionweight,closesizeunit,closedecoration,closestyle,closeweight');
|
||||
|
||||
|
||||
////////
|
||||
// DEFAULT CONFIGURATION
|
||||
// Settings you want everywhere are set here. All of this can also be
|
||||
// changed on your html page or through an overLIB call.
|
||||
////////
|
||||
if (typeof ol_padunit=='undefined') var ol_padunit="px";
|
||||
if (typeof ol_heightunit=='undefined') var ol_heightunit="px";
|
||||
if (typeof ol_widthunit=='undefined') var ol_widthunit="px";
|
||||
if (typeof ol_textsizeunit=='undefined') var ol_textsizeunit="px";
|
||||
if (typeof ol_textdecoration=='undefined') var ol_textdecoration="none";
|
||||
if (typeof ol_textstyle=='undefined') var ol_textstyle="normal";
|
||||
if (typeof ol_textweight=='undefined') var ol_textweight="normal";
|
||||
if (typeof ol_captionsizeunit=='undefined') var ol_captionsizeunit="px";
|
||||
if (typeof ol_captiondecoration=='undefined') var ol_captiondecoration="none";
|
||||
if (typeof ol_captionstyle=='undefined') var ol_captionstyle="normal";
|
||||
if (typeof ol_captionweight=='undefined') var ol_captionweight="bold";
|
||||
if (typeof ol_closesizeunit=='undefined') var ol_closesizeunit="px";
|
||||
if (typeof ol_closedecoration=='undefined') var ol_closedecoration="none";
|
||||
if (typeof ol_closestyle=='undefined') var ol_closestyle="normal";
|
||||
if (typeof ol_closeweight=='undefined') var ol_closeweight="normal";
|
||||
|
||||
////////
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
|
||||
|
||||
|
||||
////////
|
||||
// INIT
|
||||
////////
|
||||
// Runtime variables init. Don't change for config!
|
||||
var o3_padunit="px";
|
||||
var o3_heightunit="px";
|
||||
var o3_widthunit="px";
|
||||
var o3_textsizeunit="px";
|
||||
var o3_textdecoration="";
|
||||
var o3_textstyle="";
|
||||
var o3_textweight="";
|
||||
var o3_captionsizeunit="px";
|
||||
var o3_captiondecoration="";
|
||||
var o3_captionstyle="";
|
||||
var o3_captionweight="";
|
||||
var o3_closesizeunit="px";
|
||||
var o3_closedecoration="";
|
||||
var o3_closestyle="";
|
||||
var o3_closeweight="";
|
||||
|
||||
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
|
||||
// Function which sets runtime variables to their default values
|
||||
function setCSSStyleVariables() {
|
||||
o3_padunit=ol_padunit;
|
||||
o3_heightunit=ol_heightunit;
|
||||
o3_widthunit=ol_widthunit;
|
||||
o3_textsizeunit=ol_textsizeunit;
|
||||
o3_textdecoration=ol_textdecoration;
|
||||
o3_textstyle=ol_textstyle;
|
||||
o3_textweight=ol_textweight;
|
||||
o3_captionsizeunit=ol_captionsizeunit;
|
||||
o3_captiondecoration=ol_captiondecoration;
|
||||
o3_captionstyle=ol_captionstyle;
|
||||
o3_captionweight=ol_captionweight;
|
||||
o3_closesizeunit=ol_closesizeunit;
|
||||
o3_closedecoration=ol_closedecoration;
|
||||
o3_closestyle=ol_closestyle;
|
||||
o3_closeweight=ol_closeweight;
|
||||
}
|
||||
|
||||
// Parses CSS Style commands.
|
||||
function parseCSSStyleExtras(pf, i, ar) {
|
||||
var k = i;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k]==CSSSTYLE) { eval(pf+'css='+ar[k]); return k; }
|
||||
if (ar[k]==PADUNIT) { eval(pf+'padunit="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==HEIGHTUNIT) { eval(pf+'heightunit="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==WIDTHUNIT) { eval(pf+'widthunit="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==TEXTSIZEUNIT) { eval(pf+'textsizeunit="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==TEXTDECORATION) { eval(pf+'textdecoration="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==TEXTSTYLE) { eval(pf+'textstyle="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==TEXTWEIGHT) { eval(pf+'textweight="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CAPTIONSIZEUNIT) { eval(pf+'captionsizeunit="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CAPTIONDECORATION) { eval(pf+'captiondecoration="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CAPTIONSTYLE) { eval(pf+'captionstyle="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CAPTIONWEIGHT) { eval(pf+'captionweight="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CLOSESIZEUNIT) { eval(pf+'closesizeunit="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CLOSEDECORATION) { eval(pf+'closedecoration="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CLOSESTYLE) { eval(pf+'closestyle="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==CLOSEWEIGHT) { eval(pf+'closeweight="'+ar[++k]+'"'); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
////////
|
||||
// LAYER GENERATION FUNCTIONS
|
||||
////////
|
||||
|
||||
// Makes simple table without caption
|
||||
function ol_content_simple_cssstyle(text) {
|
||||
txt = '<table width="'+o3_width+ '" border="0" cellpadding="'+o3_border+'" cellspacing="0" style="background-color: '+o3_bgcolor+'; height: '+o3_height+o3_heightunit+';"><tr><td><table width="100%" border="0" cellpadding="' + o3_cellpad + '" cellspacing="0" style="color: '+o3_fgcolor+'; background-color: '+o3_fgcolor+'; height: '+o3_height+o3_heightunit+';"><tr><td valign="TOP"><font style="font-family: '+o3_textfont+'; color: '+o3_textcolor+'; font-size: '+o3_textsize+o3_textsizeunit+'; text-decoration: '+o3_textdecoration+'; font-weight: '+o3_textweight+'; font-style:'+o3_textstyle+'">'+text+'</font></td></tr></table></td></tr></table>';
|
||||
set_background("");
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
// Makes table with caption and optional close link
|
||||
function ol_content_caption_cssstyle(text, title, close) {
|
||||
var nameId;
|
||||
closing = "";
|
||||
closeevent = "onMouseOver";
|
||||
|
||||
if (o3_closeclick == 1) closeevent= (o3_closetitle ? "title='" + o3_closetitle +"'" : "") + " onClick";
|
||||
|
||||
if (o3_capicon!="") {
|
||||
nameId=' hspace=\"5\"'+' align=\"middle\" alt=\"\"';
|
||||
if (typeof o3_dragimg != 'undefined' && o3_dragimg) nameId = ' hspace=\"5\"'+' name=\"'+o3_dragimg+'\" id=\"'+o3_dragimg+'\" align=\"middle\" alt=\"Drag Enabled\" title=\"Drag Enabled\"';
|
||||
o3_capicon = '<img src=\"'+o3_capicon+'\"'+nameId+' />';
|
||||
}
|
||||
|
||||
if (close != "") {
|
||||
closing = '<td align="RIGHT"><a href="javascript:return '+fnRef+'cClick();" '+closeevent+'="return '+fnRef+'cClick();" style="color: '+o3_closecolor+'; font-family: '+o3_closefont+'; font-size: '+o3_closesize+o3_closesizeunit+'; text-decoration: '+o3_closedecoration+'; font-weight: '+o3_closeweight+'; font-style:'+o3_closestyle+';">'+close+'</a></td>';
|
||||
}
|
||||
|
||||
txt = '<table width="'+o3_width+ '" border="0" cellpadding="'+o3_border+'" cellspacing="0" style="background-color: '+o3_bgcolor+'; background-image: url('+o3_bgbackground+'); height: '+o3_height+o3_heightunit+';"><tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><font style="font-family: '+o3_captionfont+'; color: '+o3_capcolor+'; font-size: '+o3_captionsize+o3_captionsizeunit+'; font-weight: '+o3_captionweight+'; font-style: '+o3_captionstyle+'; text-decoration: '+o3_captiondecoration+';">'+o3_capicon+title+'</font></td>'+closing+'</tr></table><table width="100%" border="0" cellpadding="' + o3_cellpad + '" cellspacing="0" style="color: '+o3_fgcolor+'; background-color: '+o3_fgcolor+'; height: '+o3_height+o3_heightunit+';"><tr><td valign="TOP"><font style="font-family: '+o3_textfont+'; color: '+o3_textcolor+'; font-size: '+o3_textsize+o3_textsizeunit+'; text-decoration: '+o3_textdecoration+'; font-weight: '+o3_textweight+'; font-style:'+o3_textstyle+'">'+text+'</font></td></tr></table></td></tr></table>';
|
||||
set_background("");
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
// Sets the background picture, padding and lots more. :)
|
||||
function ol_content_background_cssstyle(text, picture, hasfullhtml) {
|
||||
if (hasfullhtml) {
|
||||
txt = text;
|
||||
} else {
|
||||
var pU, hU, wU;
|
||||
pU = (o3_padunit == '%' ? '%' : '');
|
||||
hU = (o3_heightunit == '%' ? '%' : '');
|
||||
wU = (o3_widthunit == '%' ? '%' : '');
|
||||
txt = '<table width="'+o3_width+wu+'" border="0" cellpadding="0" cellspacing="0" height="'+o3_height+hu+'"><tr><td colspan="3" height="'+o3_padyt+pu+'"></td></tr><tr><td width="'+o3_padxl+pu+'"></td><td valign="TOP" width="'+(o3_width-o3_padxl-o3_padxr)+pu+'"><font style="font-family: '+o3_textfont+'; color: '+o3_textcolor+'; font-size: '+o3_textsize+o3_textsizeunit+';">'+text+'</font></td><td width="'+o3_padxr+pu+'"></td></tr><tr><td colspan="3" height="'+o3_padyb+pu+'"></td></tr></table>';
|
||||
}
|
||||
|
||||
set_background(picture);
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerRunTimeFunction(setCSSStyleVariables);
|
||||
registerCmdLineFunction(parseCSSStyleExtras);
|
||||
registerHook("ol_content_simple", ol_content_simple_cssstyle, FALTERNATE, CSSSTYLE);
|
||||
registerHook("ol_content_caption", ol_content_caption_cssstyle, FALTERNATE, CSSSTYLE);
|
||||
registerHook("ol_content_background", ol_content_background_cssstyle, FALTERNATE, CSSSTYLE);
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Debug Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.05 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2003. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//
|
||||
//\/////
|
||||
//\mini
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Debug Plugin.');
|
||||
else {
|
||||
var olZindex;
|
||||
registerCommands('allowdebug');
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
// Parses Debug Parameters
|
||||
function parseDebugExtras(pf, i, ar) {
|
||||
var k = i, v;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k] == ALLOWDEBUG) { v = ar[k + 1]; if(typeof v == 'string') {v = ar[++k]; if (pf != 'ol_') setCanShowParm(v);} return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
// Debug main routine
|
||||
function showProperties() {
|
||||
var args = showProperties.arguments, sho, shoObj, vis, lvl = 0, istrt = 0, theDiv = 'showProps', txt = '';
|
||||
|
||||
if (args.length == 0) return;
|
||||
if (args.length % 2 && typeof args[0] == 'string') {
|
||||
istrt = 1;
|
||||
theDiv = args[0];
|
||||
}
|
||||
|
||||
sho = createDivContainer(theDiv);
|
||||
|
||||
if (olNs4) {
|
||||
shoObj = sho;
|
||||
txt += '<table cellpadding="1" cellspacing="0" border="0" bgcolor="#000000"><tr><td>';
|
||||
} else {
|
||||
with(sho.style) {
|
||||
backgroundColor = '#ffffcc';
|
||||
padding = '5px';
|
||||
border = '1px #000000 solid';
|
||||
}
|
||||
shoObj = sho.style;
|
||||
}
|
||||
|
||||
lvl = getLayerLevel(theDiv);
|
||||
|
||||
if(typeof sho.position == 'undefined') {
|
||||
sho.position = new Pagelocation(10 + lvl*20, 10, 1);
|
||||
if(typeof olZindex == 'undefined') olZindex = getDivZindex();
|
||||
shoObj.zIndex = olZindex + 1 + lvl;
|
||||
}
|
||||
|
||||
txt += '<table cellpadding="5" border="0" cellspacing="0"' + (olNs4 ? ' bgcolor="#ffffcc"' : '') + '>';
|
||||
txt += '<tr><td><strong><A HREF="javascript:moveToBack(\'' + theDiv + '\');" title="Move to back">' + theDiv + '</A></strong></td><td align="RIGHT"><strong><a href="javascript:closeLayer(\'' + theDiv + '\');" TITLE="Close Layer' + (!olNs4 ? '" style="background-color: #CCCCCC; border:2px #333369 outset; padding: 2px;' : '') + '">X</a></strong></td></tr>';
|
||||
txt += '<tr><td style="text-decoration: underline;"><strong>Item</strong></td><td style="text-decoration: underline;"><strong>Value</strong></td></tr>';
|
||||
for (var i = istrt; i<args.length-1; i++)
|
||||
txt += '<tr><td align="right"><strong>' + args[i] + ': </strong></td><td>' + args[++i] + '</td></tr>';
|
||||
txt += '</table>' + (olNs4 ? '</td></tr></table>' : '');
|
||||
|
||||
if (olNs4) {
|
||||
sho.document.open();
|
||||
sho.document.write(txt);
|
||||
sho.document.close();
|
||||
} else {
|
||||
if(olIe5&&isMac) sho.innerHTML = '';
|
||||
sho.innerHTML = txt;
|
||||
}
|
||||
|
||||
showAllVisibleLayers();
|
||||
}
|
||||
function getLayerLevel(lyr) {
|
||||
var i = 0;
|
||||
|
||||
if (typeof document.popups == 'undefined') {
|
||||
document.popups = new Array(lyr);
|
||||
} else {
|
||||
var l = document.popups;
|
||||
for (var i = 0; i<l.length; i++) if (lyr == l[i]) break;
|
||||
if(i == l.length) l[l.length++] = lyr;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
function getDivZindex(id) {
|
||||
var obj;
|
||||
|
||||
if(id == '' || id == null) id = 'overDiv';
|
||||
|
||||
obj = layerReference(id);
|
||||
obj = (olNs4 ? obj : obj.style);
|
||||
|
||||
return obj.zIndex;
|
||||
}
|
||||
function setCanShowParm(debugID) {
|
||||
var lyr, pLyr;
|
||||
|
||||
if(typeof debugID != 'string') return;
|
||||
|
||||
pLyr = debugID.split(',');
|
||||
for(var i = 0; i<pLyr.length; i++) {
|
||||
lyr = layerReference(pLyr[i]);
|
||||
if(lyr != null && typeof lyr.position != 'undefined') lyr.position.canShow = 1;
|
||||
}
|
||||
}
|
||||
function Pagelocation(x, y, canShow) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.canShow = (canShow == null) ? 0 : canShow;
|
||||
}
|
||||
function showAllVisibleLayers(){
|
||||
var lyr, lyrObj, l = document.popups;
|
||||
|
||||
for (var i = 0; i<l.length; i++) {
|
||||
lyr = layerReference(l[i]);
|
||||
lyrObj = (olNs4 ? lyr : lyr.style);
|
||||
if(lyr.position.canShow) {
|
||||
positionLayer(lyrObj, lyr.position.x, lyr.position.y);
|
||||
lyrObj.visibility = 'visible';
|
||||
}
|
||||
}
|
||||
}
|
||||
function positionLayer(Obj, x, y) { // Obj is obj.style for IE/NS6+ but obj for NS4
|
||||
Obj.left = x + (olIe4 ? eval(docRoot + '.scrollLeft') : window.pageXOffset) + (olNs4 ? 0 : 'px');
|
||||
Obj.top = y + (olIe4 ? eval(docRoot + '.scrollTop') : window.pageYOffset) + (olNs4 ? 0 : 'px');
|
||||
}
|
||||
function closeLayer(lyrID) {
|
||||
var lyr = layerReference(lyrID);
|
||||
|
||||
lyr.position.canShow = 0;
|
||||
lyr = (olNs4 ? lyr : lyr.style);
|
||||
lyr.visibility = 'hidden';
|
||||
}
|
||||
function moveToBack(layer) {
|
||||
var l = document.popups, lyr, obj, i, x = 10, y = 10, dx = 20, z = olZindex + 1;
|
||||
|
||||
if(l.length == 1) return;
|
||||
|
||||
lyr = layerReference(layer);
|
||||
lyr.position.x = x;
|
||||
lyr.position.y = y;
|
||||
obj = (olNs4 ? lyr : lyr.style);
|
||||
obj.zIndex = z;
|
||||
|
||||
for (i = 0; i<l.length; i++) {
|
||||
if (layer == l[i]) continue;
|
||||
lyr = layerReference(l[i]);
|
||||
if(lyr.position.canShow == 0) continue;
|
||||
obj = (olNs4 ? lyr : lyr.style);
|
||||
obj.zIndex += 1;
|
||||
lyr.position.x += dx;
|
||||
lyr.position.y = y;
|
||||
}
|
||||
|
||||
showAllVisibleLayers();
|
||||
}
|
||||
function rawTxt(txt) {
|
||||
if (typeof txt != 'string') return;
|
||||
return txt.replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");
|
||||
}
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerCmdLineFunction(parseDebugExtras);
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Exclusive Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.05 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Debug Plugin.');
|
||||
else {
|
||||
registerCommands('exclusive,exclusivestatus,exclusiveoverride');
|
||||
var olOverrideIsSet; // variable which tells if override is set
|
||||
|
||||
|
||||
////////
|
||||
// DEFAULT CONFIGURATION
|
||||
// Settings you want everywhere are set here. All of this can also be
|
||||
// changed on your html page or through an overLIB call.
|
||||
////////
|
||||
if (typeof ol_exclusive == 'undefined') var ol_exclusive = 0;
|
||||
if (typeof ol_exclusivestatus == 'undefined') var ol_exclusivestatus = 'Please close open popup first.';
|
||||
|
||||
////////
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
|
||||
|
||||
////////
|
||||
// INIT
|
||||
////////
|
||||
// Runtime variables init. Don't change for config!
|
||||
var o3_exclusive = 0;
|
||||
var o3_exclusivestatus = '';
|
||||
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
|
||||
// Set runtime variables
|
||||
function setExclusiveVariables() {
|
||||
o3_exclusive = ol_exclusive;
|
||||
o3_exclusivestatus = ol_exclusivestatus;
|
||||
}
|
||||
|
||||
// Parses Exclusive Parameters
|
||||
function parseExclusiveExtras(pf,i,ar) {
|
||||
var k = i,v;
|
||||
|
||||
olOverrideIsSet = false; // a global variable
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k] == EXCLUSIVEOVERRIDE) { if(pf != 'ol_') olOverrideIsSet = true; return k; }
|
||||
if (ar[k] == EXCLUSIVE) { eval(pf + 'exclusive = (' + pf + 'exclusive == 0) ? 1 : 0'); return k; }
|
||||
if (ar[k] == EXCLUSIVESTATUS) { eval(pf + "exclusivestatus = '" + escSglQuote(ar[++k]) + "'"); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
///////
|
||||
// HELPER FUNCTIONS
|
||||
///////
|
||||
// set status message and indicate whether popup is exclusive
|
||||
function isExclusive(args) {
|
||||
var rtnVal = false;
|
||||
|
||||
if(args != null) rtnVal = hasCommand(args, EXCLUSIVEOVERRIDE);
|
||||
|
||||
if(rtnVal) return false;
|
||||
else {
|
||||
self.status = (o3_exclusive) ? o3_exclusivestatus : '';
|
||||
return o3_exclusive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// checks overlib argument list to see if it has a COMMAND argument
|
||||
function hasCommand(args, COMMAND) {
|
||||
var rtnFlag = false;
|
||||
|
||||
for (var i=0; i<args.length; i++) {
|
||||
if (typeof args[i] == 'number' && args[i] == COMMAND) {
|
||||
rtnFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rtnFlag;
|
||||
}
|
||||
|
||||
// makes sure exclusive setting is off
|
||||
function clearExclusive() {
|
||||
o3_exclusive = 0;
|
||||
}
|
||||
|
||||
function setExclusive() {
|
||||
o3_exclusive = (o3_showingsticky && o3_exclusive);
|
||||
}
|
||||
|
||||
function chkForExclusive() {
|
||||
if (olOverrideIsSet) o3_exclusive = 0; // turn it off in case it's been set.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerRunTimeFunction(setExclusiveVariables);
|
||||
registerCmdLineFunction(parseExclusiveExtras);
|
||||
registerPostParseFunction(chkForExclusive);
|
||||
registerHook("createPopup",setExclusive,FBEFORE);
|
||||
registerHook("hideObject",clearExclusive,FAFTER);
|
||||
if (olInfo.meets(4.10)) registerNoParameterCommands('exclusive');
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Follow Scroll Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.10 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Follow Scroll Plugin.');
|
||||
else {
|
||||
registerCommands('followscroll,followscrollrefresh');
|
||||
|
||||
|
||||
////////
|
||||
// DEFAULT CONFIGURATION
|
||||
// You don't have to change anything here if you don't want to. All of this can be
|
||||
// changed on your html page or through an overLIB call.
|
||||
////////
|
||||
// Default value for scroll is not to scroll (0)
|
||||
if (typeof ol_followscroll=='undefined') var ol_followscroll=0;
|
||||
if (typeof ol_followscrollrefresh=='undefined') var ol_followscrollrefresh=100;
|
||||
|
||||
////////
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////
|
||||
// INIT
|
||||
////////
|
||||
// Runtime variables init. Don't change for config!
|
||||
var o3_followscroll=0;
|
||||
var o3_followscrollrefresh=100;
|
||||
|
||||
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
function setScrollVariables() {
|
||||
o3_followscroll=ol_followscroll;
|
||||
o3_followscrollrefresh=ol_followscrollrefresh;
|
||||
}
|
||||
|
||||
// Parses Shadow and Scroll commands
|
||||
function parseScrollExtras(pf,i,ar) {
|
||||
var k=i,v;
|
||||
if (k < ar.length) {
|
||||
if (ar[k]==FOLLOWSCROLL) { eval(pf +'followscroll=('+pf+'followscroll==0) ? 1 : 0'); return k; }
|
||||
if (ar[k]==FOLLOWSCROLLREFRESH) { eval(pf+'followscrollrefresh='+ar[++k]); return k; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to support scroll feature (overloads default)
|
||||
function scroll_placeLayer() {
|
||||
var placeX, placeY, widthFix = 0;
|
||||
|
||||
// HORIZONTAL PLACEMENT
|
||||
if (o3_frame.innerWidth) {
|
||||
widthFix=Math.ceil(1.2*(o3_frame.outerWidth - o3_frame.innerWidth));
|
||||
widthFix = (widthFix > 50) ? 20 : widthFix;
|
||||
iwidth=o3_frame.innerWidth;
|
||||
} else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientWidth=='number'")&&eval('o3_frame.'+docRoot+'.clientWidth'))
|
||||
iwidth=eval('o3_frame.'+docRoot+'.clientWidth');
|
||||
|
||||
// Horizontal scroll offset
|
||||
winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
|
||||
|
||||
placeX = runHook('horizontalPlacement',FCHAIN,iwidth,winoffset,widthFix);
|
||||
|
||||
// VERTICAL PLACEMENT
|
||||
if (o3_frame.innerHeight) iheight=o3_frame.innerHeight;
|
||||
else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientHeight=='number'")&&eval('o3_frame.'+docRoot+'.clientHeight'))
|
||||
iheight=eval('o3_frame.'+docRoot+'.clientHeight');
|
||||
|
||||
// Vertical scroll offset
|
||||
scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
|
||||
|
||||
placeY = runHook('verticalPlacement',FCHAIN,iheight,scrolloffset);
|
||||
|
||||
// Actually move the object.
|
||||
repositionTo(over,placeX,placeY);
|
||||
|
||||
if (o3_followscroll && o3_sticky && (o3_relx || o3_rely) && (typeof o3_draggable == 'undefined' || !o3_draggable)) {
|
||||
if (typeof over.scroller=='undefined' || over.scroller.canScroll) over.scroller = new Scroller(placeX-winoffset,placeY-scrolloffset,o3_followscrollrefresh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////
|
||||
// SUPPORT ROUTINES FOR SCROLL FEATURE
|
||||
///////
|
||||
|
||||
// Scroller constructor
|
||||
function Scroller(X,Y,refresh) {
|
||||
this.canScroll=0;
|
||||
this.refresh=refresh;
|
||||
this.x=X;
|
||||
this.y=Y;
|
||||
this.timer=setTimeout("repositionOver()",this.refresh);
|
||||
}
|
||||
|
||||
// Removes the timer to stop replacing the layer.
|
||||
function cancelScroll() {
|
||||
if (!o3_followscroll || typeof over.scroller == 'undefined') return;
|
||||
over.scroller.canScroll = 1;
|
||||
|
||||
if (over.scroller.timer) {
|
||||
clearTimeout(over.scroller.timer);
|
||||
over.scroller.timer=null;
|
||||
}
|
||||
}
|
||||
|
||||
// Find out how much we've scrolled.
|
||||
function getPageScrollY() {
|
||||
if (o3_frame.pageYOffset) return o3_frame.pageYOffset;
|
||||
if (eval(docRoot)) return eval('o3_frame.' + docRoot + '.scrollTop');
|
||||
return -1;
|
||||
}
|
||||
function getPageScrollX() {
|
||||
if (o3_frame.pageXOffset) return o3_frame.pageXOffset;
|
||||
if (eval(docRoot)) return eval('o3_frame.'+docRoot+'.scrollLeft');
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Find out where our layer is
|
||||
function getLayerTop(layer) {
|
||||
if (layer.pageY) return layer.pageY;
|
||||
if (layer.style.top) return parseInt(layer.style.top);
|
||||
return -1;
|
||||
}
|
||||
function getLayerLeft(layer) {
|
||||
if (layer.pageX) return layer.pageX;
|
||||
if (layer.style.left) return parseInt(layer.style.left);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Repositions the layer if needed
|
||||
function repositionOver() {
|
||||
var X, Y, pgLeft, pgTop;
|
||||
pgTop = getPageScrollY();
|
||||
pgLeft = getPageScrollX();
|
||||
X = getLayerLeft(over)-pgLeft;
|
||||
Y = getLayerTop(over)-pgTop;
|
||||
|
||||
if (X != over.scroller.x || Y != over.scroller.y) repositionTo(over, pgLeft+over.scroller.x, pgTop+over.scroller.y);
|
||||
over.scroller.timer = setTimeout("repositionOver()", over.scroller.refresh);
|
||||
}
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerRunTimeFunction(setScrollVariables);
|
||||
registerCmdLineFunction(parseScrollExtras);
|
||||
registerHook("hideObject",cancelScroll,FAFTER);
|
||||
registerHook("placeLayer",scroll_placeLayer,FREPLACE);
|
||||
if (olInfo.meets(4.10)) registerNoParameterCommands('followscroll');
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Hide Form Plugin
|
||||
//\
|
||||
//\ Uses an iframe shim to mask system controls for IE v5.5 or higher as suggested in
|
||||
//\ http://dotnetjunkies.com/weblog/jking/posts/488.aspx
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.05 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the HideForm Plugin.');
|
||||
else {
|
||||
|
||||
// Function which generates the popup with an IFRAME shim
|
||||
function generatePopUp(content) {
|
||||
if(!olIe4||olOp||!olIe55||(typeof o3_shadow != 'undefined' && o3_shadow)||(typeof o3_bubble != 'undefined' && o3_bubble)) return;
|
||||
|
||||
var wd,ht,txt, zIdx = 0;
|
||||
|
||||
wd = parseInt(o3_width);
|
||||
ht = over.offsetHeight;
|
||||
txt = backDropSource(wd,ht,zIdx++);
|
||||
txt += '<div style="position: absolute; top: 0; left: 0; width: '+ wd+'px; z-index: ' + zIdx + ';">' + content + '</div>';
|
||||
layerWrite(txt);
|
||||
}
|
||||
|
||||
// Code for the IFRAME which is used in other places
|
||||
function backDropSource(width, height, Z) {
|
||||
return '<iframe frameborder="0" scrolling="no" src="javascript:false;" width="' + width + '" height="' + height + '" style="z-index: ' + Z + '; filter: Beta(Style=0,Opacity=0);"></iframe>';
|
||||
}
|
||||
|
||||
// Hides SELECT boxes that will be under the popup
|
||||
// Checking Gecko version number to try to include other browsers based on the Gecko engine
|
||||
function hideSelectBox() {
|
||||
if(olNs4 || olOp || olIe55) return;
|
||||
var px, py, pw, ph, sx, sw, sy, sh, selEl, v;
|
||||
|
||||
if(olIe4) v = 0;
|
||||
else {
|
||||
v = navigator.userAgent.match(/Gecko\/(\d{8})/i);
|
||||
if(!v) return; // return if no string match
|
||||
v = parseInt(v[1]);
|
||||
}
|
||||
|
||||
if (v < 20030624) { // versions less than June 24, 2003 were earlier Netscape browsers
|
||||
px = parseInt(over.style.left);
|
||||
py = parseInt(over.style.top);
|
||||
pw = o3_width;
|
||||
ph = (o3_aboveheight ? parseInt(o3_aboveheight) : over.offsetHeight);
|
||||
selEl = (olIe4) ? o3_frame.document.all.tags("SELECT") : o3_frame.document.getElementsByTagName("SELECT");
|
||||
for (var i=0; i<selEl.length; i++) {
|
||||
if(!olIe4 && selEl[i].size < 2) continue; // Not IE and SELECT size is 1 or not specified
|
||||
sx = pageLocation(selEl[i],'Left');
|
||||
sy = pageLocation(selEl[i],'Top');
|
||||
sw = selEl[i].offsetWidth;
|
||||
sh = selEl[i].offsetHeight;
|
||||
if((px+pw) < sx || px > (sx+sw) || (py+ph) < sy || py > (sy+sh)) continue;
|
||||
selEl[i].isHidden = 1;
|
||||
selEl[i].style.visibility = 'hidden';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shows previously hidden SELECT Boxes
|
||||
function showSelectBox() {
|
||||
if(olNs4 || olOp || olIe55) return;
|
||||
var selEl, v;
|
||||
|
||||
if(olIe4) v = 0;
|
||||
else {
|
||||
v = navigator.userAgent.match(/Gecko\/(\d{8})/i);
|
||||
if(!v) return;
|
||||
v = parseInt(v[1]);
|
||||
}
|
||||
|
||||
if(v < 20030624) {
|
||||
selEl = (olIe4) ? o3_frame.document.all.tags("SELECT") : o3_frame.document.getElementsByTagName("SELECT");
|
||||
for (var i=0; i<selEl.length; i++) {
|
||||
if(typeof selEl[i].isHidden != 'undefined' && selEl[i].isHidden) {
|
||||
selEl[i].isHidden = 0;
|
||||
selEl[i].style.visibility = 'visible';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// function gets the total offset properties of an element
|
||||
// this same function occurs in overlib_mark.js.
|
||||
function pageLocation(o,t){
|
||||
var x = 0
|
||||
|
||||
while(o.offsetParent){
|
||||
x += o['offset'+t]
|
||||
o = o.offsetParent
|
||||
}
|
||||
|
||||
x += o['offset'+t]
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
// reset mouse move routine for NS7 but not NS7.1,Opera, or IE5.5+
|
||||
// It also bypasses Netscape 6 since the modifications mess up the display of popups
|
||||
// and don't work anyways.
|
||||
// Modify mouse move routine while loading so that hideSelectBox()
|
||||
// can be called from the correct location
|
||||
if (!(olNs4 || olOp || olIe55 || navigator.userAgent.indexOf('Netscape6') != -1)) {
|
||||
var MMStr = olMouseMove.toString();
|
||||
var strRe = /(if\s*\(o3_allowmove\s*==\s*1.*\)\s*)/;
|
||||
var f = MMStr.match(strRe);
|
||||
|
||||
if (f) {
|
||||
var ls = MMStr.search(strRe);
|
||||
ls += f[1].length;
|
||||
var le = MMStr.substring(ls).search(/[;|}]\n/);
|
||||
MMStr = MMStr.substring(0,ls) + ' { runHook("placeLayer",FREPLACE); if(olHideForm) hideSelectBox(); ' + MMStr.substring(ls + (le != -1 ? le+3 : 0));
|
||||
document.writeln('<script type="text/javascript">\n<!--\n' + MMStr + '\n//-->\n</' + 'script>');
|
||||
}
|
||||
|
||||
f = capExtent.onmousemove.toString().match(/function[ ]+(\w*)\(/);
|
||||
if (f&&f[1] != 'anonymous') capExtent.onmousemove = olMouseMove;
|
||||
}
|
||||
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerHook("createPopup",generatePopUp,FAFTER);
|
||||
registerHook("hideObject",showSelectBox,FAFTER);
|
||||
olHideForm=1;
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Set On/Off Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.10 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2003. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//
|
||||
//\/////
|
||||
//\mini
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Set On/Off Plugin.');
|
||||
else {
|
||||
registerCommands('seton, setoff');
|
||||
var olSetType;
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
// PLUGIN FUNCTIONS
|
||||
////////
|
||||
// Set runtime variables
|
||||
function setOnOffVariables() {
|
||||
olSetType = 0;
|
||||
}
|
||||
// Parses Set On/Off Parameters
|
||||
function parseOnOffExtras(pf, i, ar) {
|
||||
var k = i, v;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k] == SETON||ar[k] == SETOFF) { olSetType = 1; k = opt_MULTICOMMANDS(++k, ar); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
///////
|
||||
// HELPER FUNCTIONS
|
||||
///////
|
||||
// searches arg list for COMMAND;
|
||||
function hasCommand(istrt, args, COMMAND) {
|
||||
for (var i = istrt; i < args.length; i++) {
|
||||
if (typeof args[i] == 'number' && args[i] == COMMAND) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
// scans for toggle like commands to be forced ON/OFF
|
||||
function scanCommandSet(pf, args) {
|
||||
var k = -1, j, je;
|
||||
|
||||
if (olSetType) {
|
||||
// search for SETON command
|
||||
while ((k = hasCommand(++k, args, SETON)) < args.length && k > -1) {
|
||||
je = opt_MULTICOMMANDS(k + 1, args);
|
||||
for (j = k + 1; j < (k + je); j++) setNoParamCommand(1, pf, args[j]);
|
||||
k += (je - 1);
|
||||
}
|
||||
// search for SETOFF command
|
||||
k = -1;
|
||||
while ((k = hasCommand(++k, args, SETOFF)) < args.length && k > -1) {
|
||||
je = opt_MULTICOMMANDS(k + 1, args);
|
||||
for (j = k + 1; j < (k + je); j++) setNoParamCommand(0, pf, args[j]);
|
||||
k += (je - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
var olRe;
|
||||
// set command according to whichType (0 or 1)
|
||||
function setNoParamCommand(whichType, pf, COMMAND) {
|
||||
var v = pms[COMMAND - 1 - pmStart];
|
||||
|
||||
if(pmt && !olRe) olRe = eval('/' + pmt.split(',').join('|') + '/');
|
||||
if (pf != 'ol_' && /capturefirst/.test(v)) return; // no o3_capturefirst variable
|
||||
if (pf != 'ol_' && /wrap/.test(v) && eval(pf + 'wrap') && (whichType == 0)) {
|
||||
nbspCleanup(); // undo wrap effects since checked after all parsing
|
||||
o3_width = ol_width;
|
||||
}
|
||||
|
||||
if (olRe.test(v)) eval(pf + v + '=' + ((whichType && COMMAND == AUTOSTATUSCAP) ? whichType++ : whichType));
|
||||
}
|
||||
function opt_MULTICOMMANDS(i, ar) {
|
||||
var k = i;
|
||||
|
||||
while (k < ar.length && typeof ar[k] == 'number' && ar[k] > pmStart) {k++; if (ar[k - 1] == 'SETON'||ar[k - 1] == 'SETOFF') break;}
|
||||
k -= (k < ar.length ? 2 : 1);
|
||||
|
||||
return k;
|
||||
}
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
registerRunTimeFunction(setOnOffVariables);
|
||||
registerCmdLineFunction(parseOnOffExtras);
|
||||
registerPostParseFunction(scanCommandSet);
|
||||
}
|
@ -1,270 +0,0 @@
|
||||
//\/////
|
||||
//\ overLIB Shadow Plugin
|
||||
//\ This file requires overLIB 4.10 or later.
|
||||
//\
|
||||
//\ overLIB 4.05 - You may not remove or change this notice.
|
||||
//\ Copyright Erik Bosrup 1998-2003. All rights reserved.
|
||||
//\ Contributors are listed on the homepage.
|
||||
//\ See http://www.bosrup.com/web/overlib/ for details.
|
||||
// $Revision$ $Date$
|
||||
//\/////
|
||||
//\mini
|
||||
|
||||
////////
|
||||
// PRE-INIT
|
||||
// Ignore these lines, configuration is below.
|
||||
////////
|
||||
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Shadow Plugin.');
|
||||
else {
|
||||
registerCommands('shadow,shadowcolor,shadowimage,shadowopacity,shadowx,shadowy');
|
||||
|
||||
|
||||
////////
|
||||
// DEFAULT CONFIGURATION
|
||||
// You don't have to change anything here if you don't want to. All of this can be
|
||||
// changed on your html page or through an overLIB call.
|
||||
////////
|
||||
if (typeof ol_shadowadjust=='undefined') var ol_shadowadjust=2; // for Ns4.x only
|
||||
if (typeof ol_shadow=='undefined') var ol_shadow=0;
|
||||
if (typeof ol_shadowcolor=='undefined') var ol_shadowcolor='#CCCCCC';
|
||||
if (typeof ol_shadowimage=='undefined') var ol_shadowimage='';
|
||||
if (typeof ol_shadowopacity=='undefined') var ol_shadowopacity=0;
|
||||
if (typeof ol_shadowx=='undefined') var ol_shadowx=5;
|
||||
if (typeof ol_shadowy=='undefined') var ol_shadowy=5;
|
||||
|
||||
////////
|
||||
// END OF CONFIGURATION
|
||||
// Don't change anything below this line, all configuration is above.
|
||||
////////
|
||||
|
||||
|
||||
|
||||
|
||||
////////
|
||||
// INIT
|
||||
////////
|
||||
// Runtime variables init. Don't change for config!
|
||||
var o3_shadow=0;
|
||||
var o3_shadowcolor="#cccccc";
|
||||
var o3_shadowimage='';
|
||||
var o3_shadowopacity=0;
|
||||
var o3_shadowx=5;
|
||||
var o3_shadowy=5;
|
||||
var bkSet=0; // Needed for this effect in NS4
|
||||
|
||||
|
||||
|
||||
// Function which sets runtime variables to their default values
|
||||
function setShadowVariables() {
|
||||
o3_shadow=ol_shadow;
|
||||
o3_shadowcolor=ol_shadowcolor;
|
||||
o3_shadowimage=ol_shadowimage;
|
||||
o3_shadowopacity=ol_shadowopacity;
|
||||
o3_shadowx=ol_shadowx;
|
||||
o3_shadowy=ol_shadowy;
|
||||
}
|
||||
|
||||
|
||||
// Parses shadow commands
|
||||
function parseShadowExtras(pf,i,ar) {
|
||||
var k = i, v;
|
||||
|
||||
if (k < ar.length) {
|
||||
if (ar[k]==SHADOW) { eval(pf +'shadow=('+pf+'shadow==0) ? 1 : 0'); return k; }
|
||||
if (ar[k]==SHADOWCOLOR) { eval(pf+'shadowcolor="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==SHADOWOPACITY) {v=ar[++k]; eval(pf+'shadowopacity='+(olOp ? 0 : v)); return k; }
|
||||
if (ar[k]==SHADOWIMAGE) { eval(pf+'shadowimage="'+ar[++k]+'"'); return k; }
|
||||
if (ar[k]==SHADOWX) { eval(pf+'shadowx='+ar[++k]); return k; }
|
||||
if (ar[k]==SHADOWY) { eval(pf+'shadowy='+ar[++k]); return k; }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Function for MOUSEOUT/MOUSEOFF feature with shadow
|
||||
function shadow_cursorOff() {
|
||||
var left= parseInt(over.style.left);
|
||||
var top=parseInt(over.style.top);
|
||||
var right=left+(o3_shadow ? o3_width : over.offsetWidth);
|
||||
var bottom=top+(o3_shadow ? o3_aboveheight : over.offsetHeight);
|
||||
|
||||
if (o3_x < left || o3_x > right || o3_y < top || o3_y > bottom) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pre-hide processing to clean-up.
|
||||
function checkShadowPreHide() {
|
||||
if (o3_shadow && o3_shadowopacity) cleanUpShadowEffects();
|
||||
if (o3_shadow && (olIe4 && isMac) ) over.style.pixelWidth=over.style.pixelHeight = 0;
|
||||
}
|
||||
|
||||
|
||||
// Funciton that creates the actual shadow
|
||||
function generateShadow(content) {
|
||||
var wd, ht, X = 0, Y = 0, zIdx = 0, txt, dpObj, puObj, bS= '', aPos, posStr=new Array();
|
||||
|
||||
if (!o3_shadow || (o3_shadowx == 0 && o3_shadowy == 0)) return;
|
||||
|
||||
X = Math.abs(o3_shadowx);
|
||||
Y = Math.abs(o3_shadowy);
|
||||
wd = parseInt(o3_width);
|
||||
ht = (olNs4) ? over.clip.height : over.offsetHeight;
|
||||
|
||||
if (o3_shadowx == 0) {
|
||||
if (o3_shadowy < 0) {
|
||||
posStr[0]=' left:0; top: 0';
|
||||
posStr[1]=' left:0; top: '+Y+'px';
|
||||
} else if (o3_shadowy > 0) {
|
||||
posStr[0]=' left:0; top: '+Y+'px';
|
||||
posStr[1]=' left:0; top:0';
|
||||
}
|
||||
} else if (o3_shadowy == 0) {
|
||||
if (o3_shadowx < 0) {
|
||||
posStr[0]=' left:0; top: 0';
|
||||
posStr[1]=' left: '+X+'px';
|
||||
} else if (o3_shadowx > 0) {
|
||||
posStr[0]=' left: '+ X+'px; top: 0';
|
||||
posStr[1]=' left:0; top:0';
|
||||
}
|
||||
} else if (o3_shadowx > 0) {
|
||||
if (o3_shadowy > 0) {
|
||||
posStr[0]=' left:'+ X+'px; top:'+Y+'px';
|
||||
posStr[1]=' left:0; top:0';
|
||||
} else if (o3_shadowy < 0) {
|
||||
posStr[0]=' left:'+X+'px; top:0';
|
||||
posStr[1]=' left:0; top: '+Y+'px';
|
||||
}
|
||||
} else if (o3_shadowx < 0) {
|
||||
if (o3_shadowy > 0) {
|
||||
posStr[0]=' left:0; top:'+Y+'px';
|
||||
posStr[1]=' left:'+X+'px; top:0';
|
||||
} else if (o3_shadowy < 0) {
|
||||
posStr[0]=' left:0; top:0';
|
||||
posStr[1]=' left:'+X+'px; top:'+Y+'px';
|
||||
}
|
||||
}
|
||||
|
||||
txt = (olNs4) ? '<div id="backdrop"></div>' : ((olIe55&&olHideForm) ? backDropSource(wd+X,ht+Y,zIdx++) : '') + '<div id="backdrop" style="position: absolute;'+posStr[0]+'; width: '+wd+'px; height: '+ht+'px; z-index: ' + (zIdx++) + '; ';
|
||||
|
||||
if (o3_shadowimage) {
|
||||
bS='background-image: url('+o3_shadowimage+');';
|
||||
if (olNs4) bkSet=1;
|
||||
} else {
|
||||
bS='background-color: '+o3_shadowcolor +';';
|
||||
if (olNs4) bkSet=2;
|
||||
}
|
||||
|
||||
if (olNs4) {
|
||||
txt += '<div id="PUContent">'+content+'</div>';
|
||||
} else {
|
||||
txt += bS+'"></div><div id="PUContent" style="position: absolute;'+posStr[1]+'; width: '+ wd+'px; z-index: '+(zIdx++)+';">'+content+'</div>';
|
||||
}
|
||||
|
||||
layerWrite(txt);
|
||||
|
||||
if (olNs4 && bkSet) {
|
||||
dpObj = over.document.layers['backdrop'];
|
||||
if (typeof dpObj == 'undefined') return; // if shadow layer not found, then content layer won't be either
|
||||
|
||||
puObj = over.document.layers['PUContent'];
|
||||
wd = puObj.clip.width;
|
||||
ht = puObj.clip.height;
|
||||
aPos = posStr[0].split(';');
|
||||
|
||||
dpObj.clip.width = wd;
|
||||
dpObj.clip.height = ht;
|
||||
dpObj.left = parseInt(aPos[0].split(':')[1]);
|
||||
dpObj.top = parseInt(aPos[1].split(':')[1]);
|
||||
|
||||
dpObj.bgColor = (bkSet == 1) ? null : o3_shadowcolor;
|
||||
dpObj.background.src = (bkSet==2) ? null : o3_shadowimage;
|
||||
dpObj.zIndex = 0;
|
||||
|
||||
aPos = posStr[1].split(';');
|
||||
puObj.left = parseInt(aPos[0].split(':')[1]);
|
||||
puObj.top = parseInt(aPos[1].split(':')[1]);
|
||||
puObj.zIndex = 1;
|
||||
|
||||
} else {
|
||||
puObj = (olIe4 ? o3_frame.document.all['PUContent'] : o3_frame.document.getElementById('PUContent'));
|
||||
dpObj = (olIe4 ? o3_frame.document.all['backdrop'] : o3_frame.document.getElementById('backdrop'));
|
||||
ht = puObj.offsetHeight;
|
||||
dpObj.style.height = ht + 'px';
|
||||
|
||||
if (o3_shadowopacity) {
|
||||
var op = o3_shadowopacity;
|
||||
op = (op <= 100 ? op : 100);
|
||||
|
||||
setBrowserOpacity(op,dpObj);
|
||||
}
|
||||
}
|
||||
|
||||
// Set popup's new width and height values here so they are available in placeLayer()
|
||||
o3_width = wd+X;
|
||||
o3_aboveheight = ht+Y;
|
||||
}
|
||||
|
||||
|
||||
////////
|
||||
// SUPPORT FUNCTIONS
|
||||
////////
|
||||
|
||||
// Cleans up opacity settings if any.
|
||||
function cleanUpShadowEffects() {
|
||||
if (olNs4 || olOp) return;
|
||||
var dpObj=(olIe4 ? o3_frame.document.all['backdrop'] : o3_frame.document.getElementById('backdrop'));
|
||||
cleanUpBrowserOpacity(dpObj);
|
||||
}
|
||||
|
||||
// multi browser opacity support
|
||||
function setBrowserOpacity(op,lyr){
|
||||
if (olNs4||!op) return; // if Ns4.x or opacity not given return;
|
||||
lyr=(lyr) ? lyr : over;
|
||||
if (olIe4&&typeof lyr.filters != 'undefined') {
|
||||
lyr.style.filter='Alpha(Opacity='+op+')';
|
||||
lyr.filters.alpha.enabled=true;
|
||||
} else {
|
||||
var sOp=(typeof(lyr.style.MozOpacity)!='undefined') ? 'MozOpacity' : (typeof(lyr.style.KhtmlOpacity)!='undefined' ? 'KhtmlOpacity' : (typeof(lyr.style.opacity)!='undefined' ? 'opacity' : ''));
|
||||
if (sOp) eval('lyr.style.'+sOp+'=op/100');
|
||||
}
|
||||
}
|
||||
|
||||
// multi-browser Opacity cleanup
|
||||
function cleanUpBrowserOpacity(lyr) {
|
||||
if (olNs4) return;
|
||||
lyr=(lyr) ? lyr : over;
|
||||
if (olIe4&&(typeof lyr.filters != 'undefined'&&lyr.filters.alpha.enabled)) {
|
||||
lyr.style.filter='Alpha(Opacity=100)';
|
||||
lyr.filters.alpha.enabled=false;
|
||||
} else {
|
||||
var sOp=(typeof(lyr.style.MozOpacity)!='undefined') ? 'MozOpacity' : (typeof(lyr.style.KhtmlOpacity)!='undefined' ? 'KhtmlOpacity' : (typeof(lyr.style.opacity)!='undefined' ? 'opacity' : ''));
|
||||
if (sOp) eval('lyr.style.'+sOp+'=1.0');
|
||||
}
|
||||
}
|
||||
|
||||
// This routine is needed only for Ns4.x to allow use of popups with dropshadows and CSSCLASS at the same time on a page
|
||||
function shadowAdjust() {
|
||||
if (!olNs4) return;
|
||||
var fac = ol_shadowadjust;
|
||||
if (olNs4) {
|
||||
document.write('<style type="text/css">\n<!--\n');
|
||||
document.write('#backdrop, #PUContent {position: absolute; left: '+fac*o3_shadowx+'px; top: '+fac*o3_shadowy+'px; }\n');
|
||||
document.write('-->\n<' + '\/style>');
|
||||
}
|
||||
}
|
||||
|
||||
////////
|
||||
// PLUGIN REGISTRATIONS
|
||||
////////
|
||||
var before = (typeof rmrkPreface!='undefined' ? rmrkPreface : null);
|
||||
|
||||
registerRunTimeFunction(setShadowVariables);
|
||||
registerCmdLineFunction(parseShadowExtras);
|
||||
registerHook("cursorOff",shadow_cursorOff,FREPLACE);
|
||||
registerHook("hideObject",checkShadowPreHide,FBEFORE);
|
||||
registerHook("createPopup",generateShadow,FAFTER,before);
|
||||
if (olInfo.meets(4.10)) registerNoParameterCommands('shadow');
|
||||
|
||||
if (olNs4) shadowAdjust(); // write style rules for proper support of Ns4.x
|
||||
}
|
@ -1,290 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 5 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2004 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 3.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available through the world-wide-web at the following url: |
|
||||
// | http://www.php.net/license/3_0.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Andrei Zmievski <andrei@php.net> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Command-line options parsing class.
|
||||
*
|
||||
* @author Andrei Zmievski <andrei@php.net>
|
||||
*
|
||||
*/
|
||||
class Console_Getopt {
|
||||
/**
|
||||
* Parses the command-line options.
|
||||
*
|
||||
* The first parameter to this function should be the list of command-line
|
||||
* arguments without the leading reference to the running program.
|
||||
*
|
||||
* The second parameter is a string of allowed short options. Each of the
|
||||
* option letters can be followed by a colon ':' to specify that the option
|
||||
* requires an argument, or a double colon '::' to specify that the option
|
||||
* takes an optional argument.
|
||||
*
|
||||
* The third argument is an optional array of allowed long options. The
|
||||
* leading '--' should not be included in the option name. Options that
|
||||
* require an argument should be followed by '=', and options that take an
|
||||
* option argument should be followed by '=='.
|
||||
*
|
||||
* The return value is an array of two elements: the list of parsed
|
||||
* options and the list of non-option command-line arguments. Each entry in
|
||||
* the list of parsed options is a pair of elements - the first one
|
||||
* specifies the option, and the second one specifies the option argument,
|
||||
* if there was one.
|
||||
*
|
||||
* Long and short options can be mixed.
|
||||
*
|
||||
* Most of the semantics of this function are based on GNU getopt_long().
|
||||
*
|
||||
* @param array $args an array of command-line arguments
|
||||
* @param string $short_options specifies the list of allowed short options
|
||||
* @param array $long_options specifies the list of allowed long options
|
||||
*
|
||||
* @return array two-element array containing the list of parsed options and
|
||||
* the non-option arguments
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function getopt2($args, $short_options, $long_options = null)
|
||||
{
|
||||
return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function expects $args to start with the script name (POSIX-style).
|
||||
* Preserved for backwards compatibility.
|
||||
* @see getopt2()
|
||||
*/
|
||||
function getopt($args, $short_options, $long_options = null)
|
||||
{
|
||||
return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual implementation of the argument parsing code.
|
||||
*/
|
||||
function doGetopt($version, $args, $short_options, $long_options = null)
|
||||
{
|
||||
// in case you pass directly readPHPArgv() as the first arg
|
||||
if (PEAR::isError($args)) {
|
||||
return $args;
|
||||
}
|
||||
if (empty($args)) {
|
||||
return array(array(), array());
|
||||
}
|
||||
$opts = array();
|
||||
$non_opts = array();
|
||||
|
||||
settype($args, 'array');
|
||||
|
||||
if ($long_options) {
|
||||
sort($long_options);
|
||||
}
|
||||
|
||||
/*
|
||||
* Preserve backwards compatibility with callers that relied on
|
||||
* erroneous POSIX fix.
|
||||
*/
|
||||
if ($version < 2) {
|
||||
if (isset($args[0]{0}) && $args[0]{0} != '-') {
|
||||
array_shift($args);
|
||||
}
|
||||
}
|
||||
|
||||
reset($args);
|
||||
while (list($i, $arg) = each($args)) {
|
||||
|
||||
/* The special element '--' means explicit end of
|
||||
options. Treat the rest of the arguments as non-options
|
||||
and end the loop. */
|
||||
if ($arg == '--') {
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
|
||||
break;
|
||||
}
|
||||
|
||||
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i));
|
||||
break;
|
||||
} elseif (strlen($arg) > 1 && $arg{1} == '-') {
|
||||
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
} elseif ($arg == '-') {
|
||||
// - is stdin
|
||||
$non_opts = array_merge($non_opts, array_slice($args, $i));
|
||||
break;
|
||||
} else {
|
||||
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
|
||||
if (PEAR::isError($error))
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
|
||||
return array($opts, $non_opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _parseShortOption($arg, $short_options, &$opts, &$args)
|
||||
{
|
||||
for ($i = 0; $i < strlen($arg); $i++) {
|
||||
$opt = $arg{$i};
|
||||
$opt_arg = null;
|
||||
|
||||
/* Try to find the short option in the specifier string. */
|
||||
if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
|
||||
{
|
||||
return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
|
||||
}
|
||||
|
||||
if (strlen($spec) > 1 && $spec{1} == ':') {
|
||||
if (strlen($spec) > 2 && $spec{2} == ':') {
|
||||
if ($i + 1 < strlen($arg)) {
|
||||
/* Option takes an optional argument. Use the remainder of
|
||||
the arg string if there is anything left. */
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Option requires an argument. Use the remainder of the arg
|
||||
string if there is anything left. */
|
||||
if ($i + 1 < strlen($arg)) {
|
||||
$opts[] = array($opt, substr($arg, $i + 1));
|
||||
break;
|
||||
} else if (list(, $opt_arg) = each($args)) {
|
||||
/* Else use the next argument. */;
|
||||
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
} else {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$opts[] = array($opt, $opt_arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _isShortOpt($arg)
|
||||
{
|
||||
return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _isLongOpt($arg)
|
||||
{
|
||||
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
|
||||
preg_match('/[a-zA-Z]+$/', substr($arg, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
*/
|
||||
function _parseLongOption($arg, $long_options, &$opts, &$args)
|
||||
{
|
||||
@list($opt, $opt_arg) = explode('=', $arg, 2);
|
||||
$opt_len = strlen($opt);
|
||||
|
||||
for ($i = 0; $i < count($long_options); $i++) {
|
||||
$long_opt = $long_options[$i];
|
||||
$opt_start = substr($long_opt, 0, $opt_len);
|
||||
$long_opt_name = str_replace('=', '', $long_opt);
|
||||
|
||||
/* Option doesn't match. Go on to the next one. */
|
||||
if ($long_opt_name != $opt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$opt_rest = substr($long_opt, $opt_len);
|
||||
|
||||
/* Check that the options uniquely matches one of the allowed
|
||||
options. */
|
||||
if ($i + 1 < count($long_options)) {
|
||||
$next_option_rest = substr($long_options[$i + 1], $opt_len);
|
||||
} else {
|
||||
$next_option_rest = '';
|
||||
}
|
||||
if ($opt_rest != '' && $opt{0} != '=' &&
|
||||
$i + 1 < count($long_options) &&
|
||||
$opt == substr($long_options[$i+1], 0, $opt_len) &&
|
||||
$next_option_rest != '' &&
|
||||
$next_option_rest{0} != '=') {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
|
||||
}
|
||||
|
||||
if (substr($long_opt, -1) == '=') {
|
||||
if (substr($long_opt, -2) != '==') {
|
||||
/* Long option requires an argument.
|
||||
Take the next argument if one wasn't specified. */;
|
||||
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
|
||||
}
|
||||
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
|
||||
return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
|
||||
}
|
||||
}
|
||||
} else if ($opt_arg) {
|
||||
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
|
||||
}
|
||||
|
||||
$opts[] = array('--' . $opt, $opt_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely read the $argv PHP array across different PHP configurations.
|
||||
* Will take care on register_globals and register_argc_argv ini directives
|
||||
*
|
||||
* @access public
|
||||
* @return mixed the $argv PHP array or PEAR error if not registered
|
||||
*/
|
||||
function readPHPArgv()
|
||||
{
|
||||
global $argv;
|
||||
if (!is_array($argv)) {
|
||||
if (!@is_array($_SERVER['argv'])) {
|
||||
if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
|
||||
return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
|
||||
}
|
||||
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
|
||||
}
|
||||
return $_SERVER['argv'];
|
||||
}
|
||||
return $argv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,5 +0,0 @@
|
||||
This is licensed originally under the PHP license which is incompatible with the GPL. However, I got explicit permission from the author (Andrei Zmievski <andrei@gravitonic.com>) on 18/12/07 to dual license it:
|
||||
|
||||
"I am fine with my library to be distributed under the GPL by Moodle project (which basically means that it's dual-licensed, as far as I can tell)."
|
||||
|
||||
-- Penny
|
File diff suppressed because it is too large
Load Diff
@ -1,474 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to process command line phpcs scripts.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (is_file(dirname(__FILE__).'/../CodeSniffer.php') === true) {
|
||||
include_once dirname(__FILE__).'/../CodeSniffer.php';
|
||||
} else {
|
||||
include_once 'PHP/CodeSniffer.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to process command line phpcs scripts.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CLI
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Exits if the minimum requirements of PHP_CodSniffer are not met.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function checkRequirements()
|
||||
{
|
||||
// Check the PHP version.
|
||||
if (version_compare(PHP_VERSION, '5.1.2') === -1) {
|
||||
echo 'ERROR: PHP_CodeSniffer requires PHP version 5.1.2 or greater.'.PHP_EOL;
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (extension_loaded('tokenizer') === false) {
|
||||
echo 'ERROR: PHP_CodeSniffer requires the tokenizer extension to be enabled.'.PHP_EOL;
|
||||
exit(2);
|
||||
}
|
||||
|
||||
}//end checkRequirements()
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of default values for all possible command line arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaults()
|
||||
{
|
||||
// The default values for config settings.
|
||||
$defaults['files'] = array();
|
||||
$defaults['standard'] = null;
|
||||
$defaults['verbosity'] = 0;
|
||||
$defaults['local'] = false;
|
||||
$defaults['extensions'] = array();
|
||||
$defaults['ignored'] = array();
|
||||
$defaults['generator'] = '';
|
||||
|
||||
$defaults['report'] = PHP_CodeSniffer::getConfigData('report_format');
|
||||
if ($defaults['report'] === null) {
|
||||
$defaults['report'] = 'full';
|
||||
}
|
||||
|
||||
$showWarnings = PHP_CodeSniffer::getConfigData('show_warnings');
|
||||
if ($showWarnings === null) {
|
||||
$defaults['showWarnings'] = true;
|
||||
} else {
|
||||
$defaults['showWarnings'] = (bool) $showWarnings;
|
||||
}
|
||||
|
||||
$tabWidth = PHP_CodeSniffer::getConfigData('tab_width');
|
||||
if ($tabWidth === null) {
|
||||
$defaults['tabWidth'] = 0;
|
||||
} else {
|
||||
$defaults['tabWidth'] = (int) $tabWidth;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
|
||||
}//end getDefaults()
|
||||
|
||||
|
||||
/**
|
||||
* Process the command line arguments and returns the values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCommandLineValues()
|
||||
{
|
||||
$values = $this->getDefaults();
|
||||
|
||||
for ($i = 1; $i < $_SERVER['argc']; $i++) {
|
||||
$arg = $_SERVER['argv'][$i];
|
||||
if ($arg{0} === '-') {
|
||||
if ($arg{1} === '-') {
|
||||
$values = $this->processLongArgument(substr($arg, 2), $i, $values);
|
||||
} else {
|
||||
$switches = str_split($arg);
|
||||
foreach ($switches as $switch) {
|
||||
if ($switch === '-') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$values = $this->processShortArgument($switch, $values);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$values = $this->processUnknownArgument($arg, $i, $values);
|
||||
}
|
||||
}//end for
|
||||
|
||||
return $values;
|
||||
|
||||
}//end getCommandLineValues()
|
||||
|
||||
|
||||
/**
|
||||
* Processes a sort (-e) command line argument.
|
||||
*
|
||||
* @param string $arg The command line argument.
|
||||
* @param array $values An array of values determined from CLI args.
|
||||
*
|
||||
* @return array The updated CLI values.
|
||||
* @see getCommandLineValues()
|
||||
*/
|
||||
public function processShortArgument($arg, $values)
|
||||
{
|
||||
switch ($arg) {
|
||||
case 'h':
|
||||
case '?':
|
||||
$this->printUsage();
|
||||
exit(0);
|
||||
break;
|
||||
case 'i' :
|
||||
$this->printInstalledStandards();
|
||||
exit(0);
|
||||
break;
|
||||
case 'v' :
|
||||
$values['verbosity']++;
|
||||
break;
|
||||
case 'l' :
|
||||
$values['local'] = true;
|
||||
break;
|
||||
case 'n' :
|
||||
$values['showWarnings'] = false;
|
||||
break;
|
||||
case 'w' :
|
||||
$values['showWarnings'] = true;
|
||||
break;
|
||||
default:
|
||||
$values = $this->processUnknownArgument('-'.$arg, $values);
|
||||
}//end switch
|
||||
|
||||
return $values;
|
||||
|
||||
}//end processShortArgument()
|
||||
|
||||
|
||||
/**
|
||||
* Processes a long (--example) command line argument.
|
||||
*
|
||||
* @param string $arg The command line argument.
|
||||
* @param int $pos The position of the argument on the command line.
|
||||
* @param array $values An array of values determined from CLI args.
|
||||
*
|
||||
* @return array The updated CLI values.
|
||||
* @see getCommandLineValues()
|
||||
*/
|
||||
public function processLongArgument($arg, $pos, $values)
|
||||
{
|
||||
switch ($arg) {
|
||||
case 'help':
|
||||
$this->printUsage();
|
||||
exit(0);
|
||||
break;
|
||||
case 'version':
|
||||
echo 'PHP_CodeSniffer version 1.1.0 (stable) ';
|
||||
echo 'by Squiz Pty Ltd. (http://www.squiz.net)'.PHP_EOL;
|
||||
exit(0);
|
||||
break;
|
||||
case 'config-set':
|
||||
$key = $_SERVER['argv'][($pos + 1)];
|
||||
$value = $_SERVER['argv'][($pos + 2)];
|
||||
PHP_CodeSniffer::setConfigData($key, $value);
|
||||
exit(0);
|
||||
break;
|
||||
case 'config-delete':
|
||||
$key = $_SERVER['argv'][($pos + 1)];
|
||||
PHP_CodeSniffer::setConfigData($key, null);
|
||||
exit(0);
|
||||
break;
|
||||
case 'config-show':
|
||||
$data = PHP_CodeSniffer::getAllConfigData();
|
||||
print_r($data);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
if (substr($arg, 0, 7) === 'report=') {
|
||||
$values['report'] = substr($arg, 7);
|
||||
$validReports = array(
|
||||
'full',
|
||||
'xml',
|
||||
'checkstyle',
|
||||
'csv',
|
||||
'summary',
|
||||
);
|
||||
|
||||
if (in_array($values['report'], $validReports) === false) {
|
||||
echo 'ERROR: Report type "'.$report.'" not known.'.PHP_EOL;
|
||||
exit(2);
|
||||
}
|
||||
} else if (substr($arg, 0, 9) === 'standard=') {
|
||||
$values['standard'] = substr($arg, 9);
|
||||
} else if (substr($arg, 0, 11) === 'extensions=') {
|
||||
$values['extensions'] = explode(',', substr($arg, 11));
|
||||
} else if (substr($arg, 0, 7) === 'ignore=') {
|
||||
// Split the ignore string on commas, unless the comma is escaped
|
||||
// using 1 or 3 slashes (\, or \\\,).
|
||||
$values['ignored'] = preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
|
||||
} else if (substr($arg, 0, 10) === 'generator=') {
|
||||
$values['generator'] = substr($arg, 10);
|
||||
} else if (substr($arg, 0, 10) === 'tab-width=') {
|
||||
$values['tabWidth'] = (int) substr($arg, 10);
|
||||
} else {
|
||||
$values = $this->processUnknownArgument('--'.$arg, $values);
|
||||
}//end if
|
||||
|
||||
break;
|
||||
}//end switch
|
||||
|
||||
return $values;
|
||||
|
||||
}//end processLongArgument()
|
||||
|
||||
|
||||
/**
|
||||
* Processes an unknown command line argument.
|
||||
*
|
||||
* Assumes all unknown arguments are files and folders to check.
|
||||
*
|
||||
* @param string $arg The command line argument.
|
||||
* @param int $pos The position of the argument on the command line.
|
||||
* @param array $values An array of values determined from CLI args.
|
||||
*
|
||||
* @return array The updated CLI values.
|
||||
* @see getCommandLineValues()
|
||||
*/
|
||||
public function processUnknownArgument($arg, $pos, $values)
|
||||
{
|
||||
// We don't know about any additional switches; just files.
|
||||
if ($arg{0} === '-') {
|
||||
echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
|
||||
$this->printUsage();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$file = realpath($arg);
|
||||
if (file_exists($file) === false) {
|
||||
echo 'ERROR: The file "'.$arg.'" does not exist.'.PHP_EOL.PHP_EOL;
|
||||
$this->printUsage();
|
||||
exit(2);
|
||||
} else {
|
||||
$values['files'][] = $file;
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
||||
}//end processUnknownArgument()
|
||||
|
||||
|
||||
/**
|
||||
* Runs PHP_CodeSniffer over files are directories.
|
||||
*
|
||||
* @param array $values An array of values determined from CLI args.
|
||||
*
|
||||
* @return int The number of error and warning messages shown.
|
||||
* @see getCommandLineValues()
|
||||
*/
|
||||
public function process($values=array())
|
||||
{
|
||||
if (empty($values) === true) {
|
||||
$values = $this->getCommandLineValues();
|
||||
}
|
||||
|
||||
if ($values['generator'] !== '') {
|
||||
$phpcs = new PHP_CodeSniffer($values['verbosity']);
|
||||
$phpcs->generateDocs($values['standard'], $values['files'], $values['generator']);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (empty($values['files']) === true) {
|
||||
echo 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL;
|
||||
$this->printUsage();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$values['standard'] = $this->validateStandard($values['standard']);
|
||||
if (PHP_CodeSniffer::isInstalledStandard($values['standard']) === false) {
|
||||
// They didn't select a valid coding standard, so help them
|
||||
// out by letting them know which standards are installed.
|
||||
echo 'ERROR: the "'.$values['standard'].'" coding standard is not installed. ';
|
||||
$this->printInstalledStandards();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$phpcs = new PHP_CodeSniffer($values['verbosity'], $values['tabWidth']);
|
||||
|
||||
// Set file extensions if they were specified. Otherwise,
|
||||
// let PHP_CodeSniffer decide on the defaults.
|
||||
if (empty($values['extensions']) === false) {
|
||||
$phpcs->setAllowedFileExtensions($values['extensions']);
|
||||
}
|
||||
|
||||
// Set ignore patterns if they were specified.
|
||||
if (empty($values['ignored']) === false) {
|
||||
$phpcs->setIgnorePatterns($values['ignored']);
|
||||
}
|
||||
|
||||
$phpcs->process($values['files'], $values['standard'], array(), $values['local']);
|
||||
return $this->printErrorReport($phpcs, $values['report'], $values['showWarnings']);
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Prints the error report.
|
||||
*
|
||||
* @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object containing
|
||||
* the errors.
|
||||
* @param string $report The type of report to print.
|
||||
* @param bool $showWarnings TRUE if warnings should also be printed.
|
||||
*
|
||||
* @return int The number of error and warning messages shown.
|
||||
*/
|
||||
public function printErrorReport($phpcs, $report, $showWarnings)
|
||||
{
|
||||
switch ($report) {
|
||||
case 'xml':
|
||||
$numErrors = $phpcs->printXMLErrorReport($showWarnings);
|
||||
break;
|
||||
case 'checkstyle':
|
||||
$numErrors = $phpcs->printCheckstyleErrorReport($showWarnings);
|
||||
break;
|
||||
case 'csv':
|
||||
$numErrors = $phpcs->printCSVErrorReport($showWarnings);
|
||||
break;
|
||||
case 'summary':
|
||||
$numErrors = $phpcs->printErrorReportSummary($showWarnings);
|
||||
break;
|
||||
default:
|
||||
$numErrors = $phpcs->printErrorReport($showWarnings);
|
||||
break;
|
||||
}
|
||||
|
||||
return $numErrors;
|
||||
|
||||
}//end printErrorReport()
|
||||
|
||||
|
||||
/**
|
||||
* Convert the passed standard into a valid standard.
|
||||
*
|
||||
* Checks things like default values and case.
|
||||
*
|
||||
* @param string $standard The standard to validate.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validateStandard($standard)
|
||||
{
|
||||
if ($standard === null) {
|
||||
// They did not supply a standard to use.
|
||||
// Try to get the default from the config system.
|
||||
$standard = PHP_CodeSniffer::getConfigData('default_standard');
|
||||
if ($standard === null) {
|
||||
$standard = 'PEAR';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the standard name is valid. If not, check that the case
|
||||
// was not entered incorrectly.
|
||||
if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
|
||||
$installedStandards = PHP_CodeSniffer::getInstalledStandards();
|
||||
foreach ($installedStandards as $validStandard) {
|
||||
if (strtolower($standard) === strtolower($validStandard)) {
|
||||
$standard = $validStandard;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $standard;
|
||||
|
||||
}//end validateStandard()
|
||||
|
||||
|
||||
/**
|
||||
* Prints out the usage information for this script.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printUsage()
|
||||
{
|
||||
echo 'Usage: phpcs [-nwlvi] [--report=<report>] [--standard=<standard>]'.PHP_EOL;
|
||||
echo ' [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
|
||||
echo ' [--generator=<generator>] [--extensions=<extensions>]'.PHP_EOL;
|
||||
echo ' [--ignore=<patterns>] [--tab-width=<width>] <file> ...'.PHP_EOL;
|
||||
echo ' -n Do not print warnings'.PHP_EOL;
|
||||
echo ' -w Print both warnings and errors (on by default)'.PHP_EOL;
|
||||
echo ' -l Local directory only, no recursion'.PHP_EOL;
|
||||
echo ' -v[v][v] Print verbose output'.PHP_EOL;
|
||||
echo ' -i Show a list of installed coding standards'.PHP_EOL;
|
||||
echo ' --help Print this help message'.PHP_EOL;
|
||||
echo ' --version Print version information'.PHP_EOL;
|
||||
echo ' <file> One or more files and/or directories to check'.PHP_EOL;
|
||||
echo ' <extensions> A comma separated list of file extensions to check'.PHP_EOL;
|
||||
echo ' (only valid if checking a directory)'.PHP_EOL;
|
||||
echo ' <patterns> A comma separated list of patterns that are used'.PHP_EOL;
|
||||
echo ' to ignore directories and files'.PHP_EOL;
|
||||
echo ' <standard> The name of the coding standard to use'.PHP_EOL;
|
||||
echo ' <width> The number of spaces each tab represents'.PHP_EOL;
|
||||
echo ' <generator> The name of a doc generator to use'.PHP_EOL;
|
||||
echo ' (forces doc generation instead of checking)'.PHP_EOL;
|
||||
echo ' <report> Print either the "full", "xml", "checkstyle",'.PHP_EOL;
|
||||
echo ' "csv" or "summary" report'.PHP_EOL;
|
||||
echo ' (the "full" report is printed by default)'.PHP_EOL;
|
||||
|
||||
}//end printUsage()
|
||||
|
||||
|
||||
/**
|
||||
* Prints out a list of installed coding standards.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printInstalledStandards()
|
||||
{
|
||||
$installedStandards = PHP_CodeSniffer::getInstalledStandards();
|
||||
$numStandards = count($installedStandards);
|
||||
|
||||
if ($numStandards === 0) {
|
||||
echo 'No coding standards are installed.'.PHP_EOL;
|
||||
} else {
|
||||
$lastStandard = array_pop($installedStandards);
|
||||
if ($numStandards === 1) {
|
||||
echo 'The only coding standard installed is $lastStandard'.PHP_EOL;
|
||||
} else {
|
||||
$standardList = implode(', ', $installedStandards);
|
||||
$standardList .= ' and '.$lastStandard;
|
||||
echo 'The installed coding standards are '.$standardList.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
}//end printInstalledStandards()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,327 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to handle most of the parsing operations of a doc comment element.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (interface_exists('PHP_CodeSniffer_CommentParser_DocElement', true) === false) {
|
||||
$error = 'Interface PHP_CodeSniffer_CommentParser_DocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to handle most of the parsing operations of a doc comment element.
|
||||
*
|
||||
* Extending classes should implement the getSubElements method to return
|
||||
* a list of elements that the doc comment element contains, in the order that
|
||||
* they appear in the element. For example a function parameter element has a
|
||||
* type, a variable name and a comment. It should therefore implement the method
|
||||
* as follows:
|
||||
*
|
||||
* <code>
|
||||
* protected function getSubElements()
|
||||
* {
|
||||
* return array(
|
||||
* 'type',
|
||||
* 'variable',
|
||||
* 'comment',
|
||||
* );
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* The processSubElement will be called for each of the sub elements to allow
|
||||
* the extending class to process them. So for the parameter element we would
|
||||
* have:
|
||||
*
|
||||
* <code>
|
||||
* protected function processSubElement($name, $content, $whitespaceBefore)
|
||||
* {
|
||||
* if ($name === 'type') {
|
||||
* echo 'The name of the variable was '.$content;
|
||||
* }
|
||||
* // Process other tags.
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_CommentParser_AbstractDocElement implements PHP_CodeSniffer_CommentParser_DocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The element previous to this element.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
protected $previousElement = null;
|
||||
|
||||
/**
|
||||
* The element proceeding this element.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
protected $nextElement = null;
|
||||
|
||||
/**
|
||||
* The whitespace the occurs after this element and its sub elements.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $afterWhitespace = '';
|
||||
|
||||
/**
|
||||
* The tokens that comprise this element.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $tokens = array();
|
||||
|
||||
/**
|
||||
* The file this element is in.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $phpcsFile = null;
|
||||
|
||||
/**
|
||||
* The tag that this element represents (omiting the @ symbol).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Doc Element.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* that ocurred
|
||||
* before this.
|
||||
* @param array $tokens The tokens of
|
||||
* this element.
|
||||
* @param string $tag The doc
|
||||
* element tag
|
||||
* this element
|
||||
* represents.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*
|
||||
* @throws Exception If $previousElement in not a DocElement or if
|
||||
* getSubElements() does not return an array.
|
||||
*/
|
||||
public function __construct($previousElement, array $tokens, $tag, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
if ($previousElement !== null && ($previousElement instanceof PHP_CodeSniffer_CommentParser_DocElement) === false) {
|
||||
$error = '$previousElement must be an instance of DocElement';
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
$this->phpcsFile = $phpcsFile;
|
||||
|
||||
$this->previousElement = $previousElement;
|
||||
if ($previousElement !== null) {
|
||||
$this->previousElement->nextElement = $this;
|
||||
}
|
||||
|
||||
$this->tag = $tag;
|
||||
$this->tokens = $tokens;
|
||||
|
||||
$subElements = $this->getSubElements();
|
||||
|
||||
if (is_array($subElements) === false) {
|
||||
throw new Exception('getSubElements() must return an array');
|
||||
}
|
||||
|
||||
$whitespace = '';
|
||||
$currElem = 0;
|
||||
$lastElement = '';
|
||||
$lastElementWhitespace = null;
|
||||
$numSubElements = count($subElements);
|
||||
|
||||
foreach ($this->tokens as $token) {
|
||||
if (trim($token) === '') {
|
||||
$whitespace .= $token;
|
||||
} else {
|
||||
if ($currElem < ($numSubElements - 1)) {
|
||||
$element = $subElements[$currElem];
|
||||
$this->processSubElement($element, $token, $whitespace);
|
||||
$whitespace = '';
|
||||
$currElem++;
|
||||
} else {
|
||||
if ($lastElementWhitespace === null) {
|
||||
$lastElementWhitespace = $whitespace;
|
||||
}
|
||||
|
||||
$lastElement .= $whitespace.$token;
|
||||
$whitespace = '';
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$lastElement = ltrim($lastElement);
|
||||
$lastElementName = $subElements[($numSubElements - 1)];
|
||||
|
||||
// Process the last element in this tag.
|
||||
$this->processSubElement($lastElementName, $lastElement, $lastElementWhitespace);
|
||||
$this->afterWhitespace = $whitespace;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that exists before this.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
public function getPreviousElement()
|
||||
{
|
||||
return $this->previousElement;
|
||||
|
||||
}//end getPreviousElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that exists after this.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
public function getNextElement()
|
||||
{
|
||||
return $this->nextElement;
|
||||
|
||||
}//end getNextElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists before this element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceBefore()
|
||||
{
|
||||
if ($this->previousElement !== null) {
|
||||
return $this->previousElement->getWhitespaceAfter();
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}//end getWhitespaceBefore()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists after this element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceAfter()
|
||||
{
|
||||
return $this->afterWhitespace;
|
||||
|
||||
}//end getWhitespaceAfter()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the order that this element appears in the comment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
if ($this->previousElement === null) {
|
||||
return 1;
|
||||
} else {
|
||||
return ($this->previousElement->getOrder() + 1);
|
||||
}
|
||||
|
||||
}//end getOrder()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the tag that this element represents, ommiting the @ symbol.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
|
||||
}//end getTag()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the raw content of this element, ommiting the tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawContent()
|
||||
{
|
||||
return implode('', $this->tokens);
|
||||
|
||||
}//end getRawContent()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line in which this element first occured.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLine()
|
||||
{
|
||||
if ($this->previousElement === null) {
|
||||
// First element is on line one.
|
||||
return 1;
|
||||
} else {
|
||||
$previousContent = $this->previousElement->getRawContent();
|
||||
$previousLine = $this->previousElement->getLine();
|
||||
|
||||
return ($previousLine + substr_count($previousContent, $this->phpcsFile->eolChar));
|
||||
}
|
||||
|
||||
}//end getLine()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the sub element names that make up this element in the order they
|
||||
* appear in the element.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
abstract protected function getSubElements();
|
||||
|
||||
|
||||
/**
|
||||
* Called to process each sub element as sepcified in the return value
|
||||
* of getSubElements().
|
||||
*
|
||||
* @param string $name The name of the element to process.
|
||||
* @param string $content The content of the the element.
|
||||
* @param string $whitespaceBefore The whitespace found before this element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
abstract protected function processSubElement($name, $content, $whitespaceBefore);
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,586 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses doc comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_CommentElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_CommentElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ParserException', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ParserException not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses doc comments.
|
||||
*
|
||||
* This abstract parser handles the following tags:
|
||||
*
|
||||
* <ul>
|
||||
* <li>The short description and the long description</li>
|
||||
* <li>@see</li>
|
||||
* <li>@link</li>
|
||||
* <li>@deprecated</li>
|
||||
* <li>@since</li>
|
||||
* </ul>
|
||||
*
|
||||
* Extending classes should implement the getAllowedTags() method to return the
|
||||
* tags that they wish to process, ommiting the tags that this base class
|
||||
* processes. When one of these tags in encountered, the process<tag_name>
|
||||
* method is called on that class. For example, if a parser's getAllowedTags()
|
||||
* method returns \@param as one of its tags, the processParam method will be
|
||||
* called so that the parser can process such a tag.
|
||||
*
|
||||
* The method is passed the tokens that comprise this tag. The tokens array
|
||||
* includes the whitespace that exists between the tokens, as seperate tokens.
|
||||
* It's up to the method to create a element that implements the DocElement
|
||||
* interface, which should be returned. The AbstractDocElement class is a helper
|
||||
* class that can be used to handle most of the parsing of the tokens into their
|
||||
* individual sub elements. It requires that you construct it with the element
|
||||
* previous to the element currently being processed, which can be acquired
|
||||
* with the protected $previousElement class member of this class.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_CommentParser_AbstractParser
|
||||
{
|
||||
|
||||
/**
|
||||
* The comment element that appears in the doc comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_CommentElement
|
||||
*/
|
||||
protected $comment = null;
|
||||
|
||||
/**
|
||||
* The string content of the comment.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $commentString = '';
|
||||
|
||||
/**
|
||||
* The file that the comment exists in.
|
||||
*
|
||||
* @var PHP_CodeSniffer_File
|
||||
*/
|
||||
protected $phpcsFile = null;
|
||||
|
||||
/**
|
||||
* The word tokens that appear in the comment.
|
||||
*
|
||||
* Whitespace tokens also appear in this stack, but are separate tokens
|
||||
* from words.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
protected $words = array();
|
||||
|
||||
/**
|
||||
* The previous doc element that was processed.
|
||||
*
|
||||
* null if the current element being processed is the first element in the
|
||||
* doc comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_DocElement
|
||||
*/
|
||||
protected $previousElement = null;
|
||||
|
||||
/**
|
||||
* A list of see elements that appear in this doc comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected $sees = array();
|
||||
|
||||
/**
|
||||
* A list of see elements that appear in this doc comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected $deprecated = null;
|
||||
|
||||
/**
|
||||
* A list of see elements that appear in this doc comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected $links = array();
|
||||
|
||||
/**
|
||||
* A element to represent \@since tags.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected $since = null;
|
||||
|
||||
/**
|
||||
* True if the comment has been parsed.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_hasParsed = false;
|
||||
|
||||
/**
|
||||
* The tags that this class can process.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
private static $_tags = array(
|
||||
'see' => false,
|
||||
'link' => false,
|
||||
'deprecated' => true,
|
||||
'since' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* An array of unknown tags.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
public $unknown = array();
|
||||
|
||||
/**
|
||||
* The order of tags.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
public $orders = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Doc Comment Parser.
|
||||
*
|
||||
* @param string $comment The comment to parse.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
|
||||
*/
|
||||
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
$this->commentString = $comment;
|
||||
$this->phpcsFile = $phpcsFile;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Initiates the parsing of the doc comment.
|
||||
*
|
||||
* @return void
|
||||
* @throws PHP_CodeSniffer_CommentParser_ParserException If the parser finds a
|
||||
* problem with the
|
||||
* comment.
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
if ($this->_hasParsed === false) {
|
||||
$this->_parse($this->commentString);
|
||||
}
|
||||
|
||||
}//end parse()
|
||||
|
||||
|
||||
/**
|
||||
* Parse the comment.
|
||||
*
|
||||
* @param string $comment The doc comment to parse.
|
||||
*
|
||||
* @return void
|
||||
* @see _parseWords()
|
||||
*/
|
||||
private function _parse($comment)
|
||||
{
|
||||
// Firstly, remove the comment tags and any stars from the left side.
|
||||
$lines = explode($this->phpcsFile->eolChar, $comment);
|
||||
foreach ($lines as &$line) {
|
||||
$line = trim($line);
|
||||
|
||||
if ($line !== '') {
|
||||
if (substr($line, 0, 3) === '/**') {
|
||||
$line = substr($line, 3);
|
||||
} else if (substr($line, -2, 2) === '*/') {
|
||||
$line = substr($line, 0, -2);
|
||||
} else if ($line{0} === '*') {
|
||||
$line = substr($line, 1);
|
||||
}
|
||||
|
||||
// Add the words to the stack, preserving newlines. Other parsers
|
||||
// might be interested in the spaces between words, so tokenize
|
||||
// spaces as well as separate tokens.
|
||||
$flags = (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$words = preg_split('|(\s+)|', $line.$this->phpcsFile->eolChar, -1, $flags);
|
||||
$this->words = array_merge($this->words, $words);
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$this->_parseWords();
|
||||
|
||||
}//end _parse()
|
||||
|
||||
|
||||
/**
|
||||
* Parses each word within the doc comment.
|
||||
*
|
||||
* @return void
|
||||
* @see _parse()
|
||||
* @throws PHP_CodeSniffer_CommentParser_ParserException If more than the allowed
|
||||
* number of occurances of
|
||||
* a tag is found.
|
||||
*/
|
||||
private function _parseWords()
|
||||
{
|
||||
$allowedTags = (self::$_tags + $this->getAllowedTags());
|
||||
$allowedTagNames = array_keys($allowedTags);
|
||||
$foundTags = array();
|
||||
$prevTagPos = false;
|
||||
$wordWasEmpty = true;
|
||||
|
||||
foreach ($this->words as $wordPos => $word) {
|
||||
|
||||
if (trim($word) !== '') {
|
||||
$wordWasEmpty = false;
|
||||
}
|
||||
|
||||
if ($word{0} === '@') {
|
||||
|
||||
$tag = substr($word, 1);
|
||||
|
||||
// Filter out @ tags in the comment description.
|
||||
// A real comment tag should have whitespace and a newline before it.
|
||||
if (isset($this->words[($wordPos - 1)]) === false || trim($this->words[($wordPos - 1)]) !== '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($this->words[($wordPos - 2)]) === false || $this->words[($wordPos - 2)] !== $this->phpcsFile->eolChar) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$foundTags[] = $tag;
|
||||
|
||||
if ($prevTagPos !== false) {
|
||||
// There was a tag before this so let's process it.
|
||||
$prevTag = substr($this->words[$prevTagPos], 1);
|
||||
$this->parseTag($prevTag, $prevTagPos, ($wordPos - 1));
|
||||
} else {
|
||||
// There must have been a comment before this tag, so
|
||||
// let's process that.
|
||||
$this->parseTag('comment', 0, ($wordPos - 1));
|
||||
}
|
||||
|
||||
$prevTagPos = $wordPos;
|
||||
|
||||
if (in_array($tag, $allowedTagNames) === false) {
|
||||
// This is not a tag that we process, but let's check to
|
||||
// see if it is a tag we know about. If we don't know about it,
|
||||
// we add it to a list of unknown tags.
|
||||
$knownTags = array(
|
||||
'abstract',
|
||||
'access',
|
||||
'example',
|
||||
'filesource',
|
||||
'global',
|
||||
'ignore',
|
||||
'internal',
|
||||
'name',
|
||||
'static',
|
||||
'staticvar',
|
||||
'todo',
|
||||
'tutorial',
|
||||
'uses',
|
||||
'package_version@',
|
||||
);
|
||||
|
||||
if (in_array($tag, $knownTags) === false) {
|
||||
$this->unknown[] = array(
|
||||
'tag' => $tag,
|
||||
'line' => $this->getLine($wordPos),
|
||||
);
|
||||
}
|
||||
|
||||
}//end if
|
||||
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
// Only process this tag if there was something to process.
|
||||
if ($wordWasEmpty === false) {
|
||||
if ($prevTagPos === false) {
|
||||
// There must only be a comment in this doc comment.
|
||||
$this->parseTag('comment', 0, count($this->words));
|
||||
} else {
|
||||
// Process the last tag element.
|
||||
$prevTag = substr($this->words[$prevTagPos], 1);
|
||||
$this->parseTag($prevTag, $prevTagPos, count($this->words));
|
||||
}
|
||||
}
|
||||
|
||||
}//end _parseWords()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line that the token exists on in the doc comment.
|
||||
*
|
||||
* @param int $tokenPos The position in the words stack to find the line
|
||||
* number for.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getLine($tokenPos)
|
||||
{
|
||||
$newlines = 0;
|
||||
for ($i = 0; $i < $tokenPos; $i++) {
|
||||
$newlines += substr_count($this->phpcsFile->eolChar, $this->words[$i]);
|
||||
}
|
||||
|
||||
return $newlines;
|
||||
|
||||
}//end getLine()
|
||||
|
||||
|
||||
/**
|
||||
* Parses see tag element within the doc comment.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise this element.
|
||||
*
|
||||
* @return DocElement The element that represents this see comment.
|
||||
*/
|
||||
protected function parseSee($tokens)
|
||||
{
|
||||
$see = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'see', $this->phpcsFile);
|
||||
$this->sees[] = $see;
|
||||
return $see;
|
||||
|
||||
}//end parseSee()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the comment element that appears at the top of the doc comment.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise tihs element.
|
||||
*
|
||||
* @return DocElement The element that represents this comment element.
|
||||
*/
|
||||
protected function parseComment($tokens)
|
||||
{
|
||||
$this->comment = new PHP_CodeSniffer_CommentParser_CommentElement($this->previousElement, $tokens, $this->phpcsFile);
|
||||
return $this->comment;
|
||||
|
||||
}//end parseComment()
|
||||
|
||||
|
||||
/**
|
||||
* Parses \@deprecated tags.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise tihs element.
|
||||
*
|
||||
* @return DocElement The element that represents this deprecated tag.
|
||||
*/
|
||||
protected function parseDeprecated($tokens)
|
||||
{
|
||||
$this->deprecated = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'deprecated', $this->phpcsFile);
|
||||
return $this->deprecated;
|
||||
|
||||
}//end parseDeprecated()
|
||||
|
||||
|
||||
/**
|
||||
* Parses \@since tags.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise this element.
|
||||
*
|
||||
* @return SingleElement The element that represents this since tag.
|
||||
*/
|
||||
protected function parseSince($tokens)
|
||||
{
|
||||
$this->since = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'since', $this->phpcsFile);
|
||||
return $this->since;
|
||||
|
||||
}//end parseSince()
|
||||
|
||||
|
||||
/**
|
||||
* Parses \@link tags.
|
||||
*
|
||||
* @param array(string) $tokens The word tokens that comprise this element.
|
||||
*
|
||||
* @return SingleElement The element that represents this link tag.
|
||||
*/
|
||||
protected function parseLink($tokens)
|
||||
{
|
||||
$link = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'link', $this->phpcsFile);
|
||||
$this->links[] = $link;
|
||||
return $link;
|
||||
|
||||
}//end parseLink()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the see elements that appear in this doc comment.
|
||||
*
|
||||
* @return array(SingleElement)
|
||||
*/
|
||||
public function getSees()
|
||||
{
|
||||
return $this->sees;
|
||||
|
||||
}//end getSees()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment element that appears at the top of this doc comment.
|
||||
*
|
||||
* @return CommentElement
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->comment;
|
||||
|
||||
}//end getComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the link elements found in this comment.
|
||||
*
|
||||
* Returns an empty array if no links are found in the comment.
|
||||
*
|
||||
* @return array(SingleElement)
|
||||
*/
|
||||
public function getLinks()
|
||||
{
|
||||
return $this->links;
|
||||
|
||||
}//end getLinks()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the deprecated element found in this comment.
|
||||
*
|
||||
* Returns null if no element exists in the comment.
|
||||
*
|
||||
* @return SingleElement
|
||||
*/
|
||||
public function getDeprecated()
|
||||
{
|
||||
return $this->deprecated;
|
||||
|
||||
}//end getDeprecated()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the since element found in this comment.
|
||||
*
|
||||
* Returns null if no element exists in the comment.
|
||||
*
|
||||
* @return SingleElement
|
||||
*/
|
||||
public function getSince()
|
||||
{
|
||||
return $this->since;
|
||||
|
||||
}//end getSince()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the specified tag.
|
||||
*
|
||||
* @param string $tag The tag name to parse (omitting the @ sybmol from
|
||||
* the tag)
|
||||
* @param int $start The position in the word tokens where this element
|
||||
* started.
|
||||
* @param int $end The position in the word tokens where this element
|
||||
* ended.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception If the process method for the tag cannot be found.
|
||||
*/
|
||||
protected function parseTag($tag, $start, $end)
|
||||
{
|
||||
$tokens = array_slice($this->words, ($start + 1), ($end - $start));
|
||||
|
||||
$allowedTags = (self::$_tags + $this->getAllowedTags());
|
||||
$allowedTagNames = array_keys($allowedTags);
|
||||
if ($tag === 'comment' || in_array($tag, $allowedTagNames) === true) {
|
||||
$method = 'parse'.$tag;
|
||||
if (method_exists($this, $method) === false) {
|
||||
$error = 'Method '.$method.' must be implemented to process '.$tag.' tags';
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
$this->previousElement = $this->$method($tokens);
|
||||
} else {
|
||||
$this->previousElement = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, $tag, $this->phpcsFile);
|
||||
}
|
||||
|
||||
$this->orders[] = $tag;
|
||||
|
||||
if ($this->previousElement === null || ($this->previousElement instanceof PHP_CodeSniffer_CommentParser_DocElement) === false) {
|
||||
throw new Exception('Parse method must return a DocElement');
|
||||
}
|
||||
|
||||
}//end parseTag()
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of tags that this comment parser allows for it's comment.
|
||||
*
|
||||
* Each tag should indicate if only one entry of this tag can exist in the
|
||||
* comment by specifying true as the array value, or false if more than one
|
||||
* is allowed. Each tag should ommit the @ symbol. Only tags other than
|
||||
* the standard tags should be returned.
|
||||
*
|
||||
* @return array(string => boolean)
|
||||
*/
|
||||
protected abstract function getAllowedTags();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the tag orders (index => tagName).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTagOrders()
|
||||
{
|
||||
return $this->orders;
|
||||
|
||||
}//end getTagOrders()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the unknown tags.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUnknown()
|
||||
{
|
||||
return $this->unknown;
|
||||
|
||||
}//end getUnknown()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,300 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses Class doc comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses Class doc comments.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_ClassCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
|
||||
{
|
||||
|
||||
/**
|
||||
* The package element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_package = null;
|
||||
|
||||
/**
|
||||
* The subpackage element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_subpackage = null;
|
||||
|
||||
/**
|
||||
* The version element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_version = null;
|
||||
|
||||
/**
|
||||
* The category element of this class.
|
||||
*
|
||||
* @var SingleElement
|
||||
*/
|
||||
private $_category = null;
|
||||
|
||||
/**
|
||||
* The copyright elements of this class.
|
||||
*
|
||||
* @var array(SingleElement)
|
||||
*/
|
||||
private $_copyrights = array();
|
||||
|
||||
/**
|
||||
* The licence element of this class.
|
||||
*
|
||||
* @var PairElement
|
||||
*/
|
||||
private $_license = null;
|
||||
|
||||
/**
|
||||
* The author elements of this class.
|
||||
*
|
||||
* @var array(SingleElement)
|
||||
*/
|
||||
private $_authors = array();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the allowed tags withing a class comment.
|
||||
*
|
||||
* @return array(string => int)
|
||||
*/
|
||||
protected function getAllowedTags()
|
||||
{
|
||||
return array(
|
||||
'category' => false,
|
||||
'package' => true,
|
||||
'subpackage' => true,
|
||||
'author' => false,
|
||||
'copyright' => true,
|
||||
'license' => false,
|
||||
'version' => true,
|
||||
);
|
||||
|
||||
}//end getAllowedTags()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the license tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
protected function parseLicense($tokens)
|
||||
{
|
||||
$this->_license = new PHP_CodeSniffer_CommentParser_PairElement($this->previousElement, $tokens, 'license', $this->phpcsFile);
|
||||
return $this->_license;
|
||||
|
||||
}//end parseLicense()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the copyright tags of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseCopyright($tokens)
|
||||
{
|
||||
$copyright = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'copyright', $this->phpcsFile);
|
||||
$this->_copyrights[] = $copyright;
|
||||
return $copyright;
|
||||
|
||||
}//end parseCopyright()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the category tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseCategory($tokens)
|
||||
{
|
||||
$this->_category = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'category', $this->phpcsFile);
|
||||
return $this->_category;
|
||||
|
||||
}//end parseCategory()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the author tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
protected function parseAuthor($tokens)
|
||||
{
|
||||
$author = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'author', $this->phpcsFile);
|
||||
$this->_authors[] = $author;
|
||||
return $author;
|
||||
|
||||
}//end parseAuthor()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the version tag of this class comment.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseVersion($tokens)
|
||||
{
|
||||
$this->_version = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'version', $this->phpcsFile);
|
||||
return $this->_version;
|
||||
|
||||
}//end parseVersion()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the package tag found in this test.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this var.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parsePackage($tokens)
|
||||
{
|
||||
$this->_package = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'package', $this->phpcsFile);
|
||||
return $this->_package;
|
||||
|
||||
}//end parsePackage()
|
||||
|
||||
|
||||
/**
|
||||
* Parses the package tag found in this test.
|
||||
*
|
||||
* @param array $tokens The tokens that comprise this var.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseSubpackage($tokens)
|
||||
{
|
||||
$this->_subpackage = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'subpackage', $this->phpcsFile);
|
||||
return $this->_subpackage;
|
||||
|
||||
}//end parseSubpackage()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the authors of this class comment.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_SingleElement)
|
||||
*/
|
||||
public function getAuthors()
|
||||
{
|
||||
return $this->_authors;
|
||||
|
||||
}//end getAuthors()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the version of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->_version;
|
||||
|
||||
}//end getVersion()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the license of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
public function getLicense()
|
||||
{
|
||||
return $this->_license;
|
||||
|
||||
}//end getLicense()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the copyrights of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getCopyrights()
|
||||
{
|
||||
return $this->_copyrights;
|
||||
|
||||
}//end getCopyrights()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the category of this class comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->_category;
|
||||
|
||||
}//end getCategory()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the package that this class belongs to.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getPackage()
|
||||
{
|
||||
return $this->_package;
|
||||
|
||||
}//end getPackage()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the subpackage that this class belongs to.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
public function getSubpackage()
|
||||
{
|
||||
return $this->_subpackage;
|
||||
|
||||
}//end getSubpackage()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,240 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent Comments of a doc comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent Comments of a doc comment.
|
||||
*
|
||||
* Comments are in the following format.
|
||||
* <code>
|
||||
* /** <--this is the start of the comment.
|
||||
* * This is a short comment description
|
||||
* *
|
||||
* * This is a long comment description
|
||||
* * <-- this is the end of the comment
|
||||
* * @return something
|
||||
* {@/}
|
||||
* </code>
|
||||
*
|
||||
* Note that the sentence before two newlines is assumed
|
||||
* the short comment description.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_CommentElement extends PHP_CodeSniffer_CommentParser_SingleElement
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_CommentElement.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElemement $previousElement The element
|
||||
* that
|
||||
* appears
|
||||
* before this
|
||||
* element.
|
||||
* @param array $tokens The tokens
|
||||
* that make
|
||||
* up this
|
||||
* element.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file
|
||||
* that this
|
||||
* element is
|
||||
* in.
|
||||
*/
|
||||
public function __construct($previousElement, $tokens, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
parent::__construct($previousElement, $tokens, 'comment', $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the short comment description.
|
||||
*
|
||||
* @return string
|
||||
* @see getLongComment()
|
||||
*/
|
||||
public function getShortComment()
|
||||
{
|
||||
$pos = $this->_getShortCommentEndPos();
|
||||
if ($pos === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode('', array_slice($this->tokens, 0, ($pos + 1)));
|
||||
|
||||
}//end getShortComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the last token position of the short comment description.
|
||||
*
|
||||
* @return int The last token position of the short comment description
|
||||
* @see _getLongCommentStartPos()
|
||||
*/
|
||||
private function _getShortCommentEndPos()
|
||||
{
|
||||
$found = false;
|
||||
$whiteSpace = array(
|
||||
' ',
|
||||
"\t",
|
||||
);
|
||||
|
||||
foreach ($this->tokens as $pos => $token) {
|
||||
$token = str_replace($whiteSpace, '', $token);
|
||||
if ($token === $this->phpcsFile->eolChar) {
|
||||
if ($found === false) {
|
||||
// Include newlines before short description.
|
||||
continue;
|
||||
} else {
|
||||
if (isset($this->tokens[($pos + 1)]) === true) {
|
||||
if ($this->tokens[($pos + 1)] === $this->phpcsFile->eolChar) {
|
||||
return ($pos - 1);
|
||||
}
|
||||
} else {
|
||||
return $pos;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$found = true;
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
return (count($this->tokens) - 1);
|
||||
|
||||
}//end _getShortCommentEndPos()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the long comment description.
|
||||
*
|
||||
* @return string
|
||||
* @see getShortComment
|
||||
*/
|
||||
public function getLongComment()
|
||||
{
|
||||
$start = $this->_getLongCommentStartPos();
|
||||
if ($start === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode('', array_slice($this->tokens, $start));
|
||||
|
||||
}//end getLongComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the start position of the long comment description.
|
||||
*
|
||||
* Returns -1 if there is no long comment.
|
||||
*
|
||||
* @return int The start position of the long comment description.
|
||||
* @see _getShortCommentEndPos()
|
||||
*/
|
||||
private function _getLongCommentStartPos()
|
||||
{
|
||||
$pos = ($this->_getShortCommentEndPos() + 1);
|
||||
if ($pos === (count($this->tokens) - 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$count = count($this->tokens);
|
||||
for ($i = $pos; $i < $count; $i++) {
|
||||
$content = trim($this->tokens[$i]);
|
||||
if ($content !== '') {
|
||||
if ($content{0} === '@') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}//end _getLongCommentStartPos()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists between
|
||||
* the short and the long comment description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhiteSpaceBetween()
|
||||
{
|
||||
$endShort = ($this->_getShortCommentEndPos() + 1);
|
||||
$startLong = ($this->_getLongCommentStartPos() - 1);
|
||||
if ($startLong === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode('', array_slice($this->tokens, $endShort, ($startLong - $endShort)));
|
||||
|
||||
}//end getWhiteSpaceBetween()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of newlines that exist before the tags.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNewlineAfter()
|
||||
{
|
||||
$long = $this->getLongComment();
|
||||
if ($long !== '') {
|
||||
$long = rtrim($long, ' ');
|
||||
$long = strrev($long);
|
||||
$newlines = strspn($long, $this->phpcsFile->eolChar);
|
||||
} else {
|
||||
$endShort = ($this->_getShortCommentEndPos() + 1);
|
||||
$after = implode('', array_slice($this->tokens, $endShort));
|
||||
$after = trim($after, ' ');
|
||||
$newlines = strspn($after, $this->phpcsFile->eolChar);
|
||||
}
|
||||
|
||||
return ($newlines / strlen($this->phpcsFile->eolChar));
|
||||
|
||||
}//end getNewlineAfter()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if there is no comment.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return (trim($this->getContent()) === '');
|
||||
|
||||
}//end isEmpty()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A DocElement represents a logical element within a Doc Comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* A DocElement represents a logical element within a Doc Comment.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
interface PHP_CodeSniffer_CommentParser_DocElement
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the tag this element represents, omitting the @ symbol.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists before this element.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhitespaceAfter()
|
||||
*/
|
||||
public function getWhitespaceBefore();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace that exists after this element.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhitespaceBefore()
|
||||
*/
|
||||
public function getWhitespaceAfter();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the order that this element appears in the doc comment.
|
||||
*
|
||||
* The first element in the comment should have an order of 1.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that appears before this element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
* @see getNextElement()
|
||||
*/
|
||||
public function getPreviousElement();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element that appears after this element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_DocElement
|
||||
* @see getPreviousElement()
|
||||
*/
|
||||
public function getNextElement();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line that this element started on.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLine();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the raw content of this element, ommiting the tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawContent();
|
||||
|
||||
|
||||
}//end interface
|
||||
|
||||
?>
|
@ -1,196 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses function doc comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ParameterElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ParameterElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_PairElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_PairElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses function doc comments.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_FunctionCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
|
||||
{
|
||||
|
||||
/**
|
||||
* The parameter elements within this function comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_ParameterElement)
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* The return element in this function comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_PairElement.
|
||||
*/
|
||||
private $_return = null;
|
||||
|
||||
/**
|
||||
* The throws element list for this function comment.
|
||||
*
|
||||
* @var array(PHP_CodeSniffer_CommentParser_PairElement)
|
||||
*/
|
||||
private $_throws = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_FunctionCommentParser.
|
||||
*
|
||||
* @param string $comment The comment to parse.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
|
||||
*/
|
||||
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
parent::__construct($comment, $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Parses parameter elements.
|
||||
*
|
||||
* @param array(string) $tokens The tokens that conmpise this sub element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_ParameterElement
|
||||
*/
|
||||
protected function parseParam($tokens)
|
||||
{
|
||||
$param = new PHP_CodeSniffer_CommentParser_ParameterElement($this->previousElement, $tokens, $this->phpcsFile);
|
||||
$this->_params[] = $param;
|
||||
return $param;
|
||||
|
||||
}//end parseParam()
|
||||
|
||||
|
||||
/**
|
||||
* Parses return elements.
|
||||
*
|
||||
* @param array(string) $tokens The tokens that conmpise this sub element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
protected function parseReturn($tokens)
|
||||
{
|
||||
$return = new PHP_CodeSniffer_CommentParser_PairElement($this->previousElement, $tokens, 'return', $this->phpcsFile);
|
||||
$this->_return = $return;
|
||||
return $return;
|
||||
|
||||
}//end parseReturn()
|
||||
|
||||
|
||||
/**
|
||||
* Parses throws elements.
|
||||
*
|
||||
* @param array(string) $tokens The tokens that conmpise this sub element.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
protected function parseThrows($tokens)
|
||||
{
|
||||
$throws = new PHP_CodeSniffer_CommentParser_PairElement($this->previousElement, $tokens, 'throws', $this->phpcsFile);
|
||||
$this->_throws[] = $throws;
|
||||
return $throws;
|
||||
|
||||
}//end parseThrows()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the parameter elements that this function comment contains.
|
||||
*
|
||||
* Returns an empty array if no parameter elements are contained within
|
||||
* this function comment.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_ParameterElement)
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_params;
|
||||
|
||||
}//end getParams()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the return element in this fucntion comment.
|
||||
*
|
||||
* Returns null if no return element exists in the comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
public function getReturn()
|
||||
{
|
||||
return $this->_return;
|
||||
|
||||
}//end getReturn()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the throws elements in this fucntion comment.
|
||||
*
|
||||
* Returns empty array if no throws elements in the comment.
|
||||
*
|
||||
* @return array(PHP_CodeSniffer_CommentParser_PairElement)
|
||||
*/
|
||||
public function getThrows()
|
||||
{
|
||||
return $this->_throws;
|
||||
|
||||
}//end getThrows()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the allowed tags that can exist in a function comment.
|
||||
*
|
||||
* @return array(string => boolean)
|
||||
*/
|
||||
protected function getAllowedTags()
|
||||
{
|
||||
return array(
|
||||
'param' => false,
|
||||
'return' => true,
|
||||
'throws' => false,
|
||||
);
|
||||
|
||||
}//end getAllowedTags()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses class member comments.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses class member comments.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_MemberCommentParser extends PHP_CodeSniffer_CommentParser_ClassCommentParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Represents a \@var tag in a member comment.
|
||||
*
|
||||
* @var PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
private $_var = null;
|
||||
|
||||
|
||||
/**
|
||||
* Parses Var tags.
|
||||
*
|
||||
* @param array $tokens The tokens that represent this tag.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_SingleElement
|
||||
*/
|
||||
protected function parseVar($tokens)
|
||||
{
|
||||
$this->_var = new PHP_CodeSniffer_CommentParser_SingleElement($this->previousElement, $tokens, 'var', $this->phpcsFile);
|
||||
return $this->_var;
|
||||
|
||||
}//end parseVar()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the var tag found in the member comment.
|
||||
*
|
||||
* @return PHP_CodeSniffer_CommentParser_PairElement
|
||||
*/
|
||||
public function getVar()
|
||||
{
|
||||
return $this->_var;
|
||||
|
||||
}//end getVar()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the allowed tags for this parser.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllowedTags()
|
||||
{
|
||||
return array('var' => true);
|
||||
|
||||
}//end getAllowedTags()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,168 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent elements that have a value => comment format.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent elements that have a value => comment format.
|
||||
*
|
||||
* An example of a pair element tag is the \@throws as it has an exception type
|
||||
* and a comment on the circumstance of when the exception is thrown.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_PairElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The value of the tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_value = '';
|
||||
|
||||
/**
|
||||
* The comment of the tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_comment = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the value elem.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_valueWhitespace = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the comment elem.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_commentWhitespace = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_PairElement doc tag.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* before this
|
||||
* one.
|
||||
* @param array $tokens The tokens
|
||||
* that comprise
|
||||
* this element.
|
||||
* @param string $tag The tag that
|
||||
* this element
|
||||
* represents.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*/
|
||||
public function __construct($previousElement, $tokens, $tag, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element names that this tag is comprised of, in the order
|
||||
* that they appear in the tag.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
protected function getSubElements()
|
||||
{
|
||||
return array(
|
||||
'value',
|
||||
'comment',
|
||||
);
|
||||
|
||||
}//end getSubElements()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the sub element with the specified name.
|
||||
*
|
||||
* @param string $name The name of the sub element to process.
|
||||
* @param string $content The content of this sub element.
|
||||
* @param string $whitespaceBefore The whitespace that exists before the
|
||||
* sub element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
protected function processSubElement($name, $content, $whitespaceBefore)
|
||||
{
|
||||
$element = '_'.$name;
|
||||
$whitespace = $element.'Whitespace';
|
||||
$this->$element = $content;
|
||||
$this->$whitespace = $whitespaceBefore;
|
||||
|
||||
}//end processSubElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
|
||||
}//end getValue()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment associated with the value of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
|
||||
}//end getComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the witespace before the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceBeforeValue()
|
||||
{
|
||||
return $this->_valueWhitespace;
|
||||
|
||||
}//end getWhitespaceBeforeValue()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,326 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent param tags within a function comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent param tags within a function comment.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_ParameterElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The variable name of this parameter name, including the $ sign.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_varName = '';
|
||||
|
||||
/**
|
||||
* The comment of this parameter tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_comment = '';
|
||||
|
||||
/**
|
||||
* The variable type of this parameter tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_type = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the variable name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_varNameWhitespace = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the comment.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_commentWhitespace = null;
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the variable type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_typeWhitespace = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_CommentParser_ParameterElement.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* previous to
|
||||
* this one.
|
||||
* @param array $tokens The tokens
|
||||
* that make up
|
||||
* this element.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*/
|
||||
public function __construct($previousElement, $tokens, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
parent::__construct($previousElement, $tokens, 'param', $phpcsFile);
|
||||
|
||||
// Handle special variable type: array(x => y).
|
||||
$type = strtolower($this->_type);
|
||||
if ($this->_varName === '=>' && strpos($type, 'array(') !== false) {
|
||||
$rawContent = $this->getRawContent();
|
||||
$matches = array();
|
||||
if (preg_match('/^(\s+)(array\(.*\))(\s+)(\$\S*)(\s+)(.*)/i', $rawContent, $matches) !== 0) {
|
||||
// Process the sub elements correctly for this special case.
|
||||
if (count($matches) === 7) {
|
||||
$this->processSubElement('type', $matches[2], $matches[1]);
|
||||
$this->processSubElement('varName', $matches[4], $matches[3]);
|
||||
$this->processSubElement('comment', $matches[6], $matches[5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element names that this tag is comprised of, in the order
|
||||
* that they appear in the tag.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
protected function getSubElements()
|
||||
{
|
||||
return array(
|
||||
'type',
|
||||
'varName',
|
||||
'comment',
|
||||
);
|
||||
|
||||
}//end getSubElements()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the sub element with the specified name.
|
||||
*
|
||||
* @param string $name The name of the sub element to process.
|
||||
* @param string $content The content of this sub element.
|
||||
* @param string $beforeWhitespace The whitespace that exists before the
|
||||
* sub element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
protected function processSubElement($name, $content, $beforeWhitespace)
|
||||
{
|
||||
$element = '_'.$name;
|
||||
$whitespace = $element.'Whitespace';
|
||||
$this->$element = $content;
|
||||
$this->$whitespace = $beforeWhitespace;
|
||||
|
||||
}//end processSubElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the variable name that this parameter tag represents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVarName()
|
||||
{
|
||||
return $this->_varName;
|
||||
|
||||
}//end getVarName()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the variable type that this string represents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
|
||||
}//end getType()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the comment of this comment for this parameter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
|
||||
}//end getComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace before the variable type.
|
||||
*
|
||||
* @return stirng
|
||||
* @see getWhiteSpaceBeforeVarName()
|
||||
* @see getWhiteSpaceBeforeComment()
|
||||
*/
|
||||
public function getWhiteSpaceBeforeType()
|
||||
{
|
||||
return $this->_typeWhitespace;
|
||||
|
||||
}//end getWhiteSpaceBeforeType()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace before the variable name.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhiteSpaceBeforeComment()
|
||||
* @see getWhiteSpaceBeforeType()
|
||||
*/
|
||||
public function getWhiteSpaceBeforeVarName()
|
||||
{
|
||||
return $this->_varNameWhitespace;
|
||||
|
||||
}//end getWhiteSpaceBeforeVarName()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the whitespace before the comment.
|
||||
*
|
||||
* @return string
|
||||
* @see getWhiteSpaceBeforeVarName()
|
||||
* @see getWhiteSpaceBeforeType()
|
||||
*/
|
||||
public function getWhiteSpaceBeforeComment()
|
||||
{
|
||||
return $this->_commentWhitespace;
|
||||
|
||||
}//end getWhiteSpaceBeforeComment()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the postition of this parameter are it appears in the comment.
|
||||
*
|
||||
* This method differs from getOrder as it is only relative to method
|
||||
* parameters.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
if (($this->getPreviousElement() instanceof PHP_CodeSniffer_CommentParser_ParameterElement) === false) {
|
||||
return 1;
|
||||
} else {
|
||||
return ($this->getPreviousElement()->getPosition() + 1);
|
||||
}
|
||||
|
||||
}//end getPosition()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this parameter's variable aligns with the other's.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
|
||||
* to check
|
||||
* alignment with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function alignsVariableWith(PHP_CodeSniffer_CommentParser_ParameterElement $other)
|
||||
{
|
||||
// Format is:
|
||||
// @param type $variable Comment.
|
||||
// @param <-a-><---b---->
|
||||
// Compares the index before param variable.
|
||||
$otherVar = (strlen($other->_type) + strlen($other->_varNameWhitespace));
|
||||
$thisVar = (strlen($this->_type) + strlen($this->_varNameWhitespace));
|
||||
if ($otherVar !== $thisVar) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end alignsVariableWith()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this parameter's comment aligns with the other's.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
|
||||
* to check
|
||||
* alignment with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function alignsCommentWith(PHP_CodeSniffer_CommentParser_ParameterElement $other)
|
||||
{
|
||||
// Compares the index before param comment.
|
||||
$otherComment = (strlen($other->_varName) + strlen($other->_commentWhitespace));
|
||||
$thisComment = (strlen($this->_varName) + strlen($this->_commentWhitespace));
|
||||
if ($otherComment !== $thisComment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end alignsCommentWith()
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this parameter aligns with the other paramter.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
|
||||
* to check
|
||||
* alignment with.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function alignsWith(PHP_CodeSniffer_CommentParser_ParameterElement $other)
|
||||
{
|
||||
if ($this->alignsVariableWith($other) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->alignsCommentWith($other) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end alignsWith()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* An exception to be thrown when a DocCommentParser finds an anomilty in a
|
||||
* doc comment.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* An exception to be thrown when a DocCommentParser finds an anomilty in a
|
||||
* doc comment.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_ParserException extends Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* The line where the exception occured, in relation to the doc comment.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_line = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a DocCommentParserException.
|
||||
*
|
||||
* @param string $message The message of the exception.
|
||||
* @param int $line The position in comment where the error occured.
|
||||
* A position of 0 indicates that the error occured
|
||||
* at the opening line of the doc comment.
|
||||
*/
|
||||
public function __construct($message, $line)
|
||||
{
|
||||
parent::__construct($message);
|
||||
$this->_line = $line;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line number within the comment where the exception occured.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLineWithinComment()
|
||||
{
|
||||
return $this->_line;
|
||||
|
||||
}//end getLineWithinComment()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,161 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to represent single element doc tags.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to represent single element doc tags.
|
||||
*
|
||||
* A single element doc tag contains only one value after the tag itself. An
|
||||
* example would be the \@package tag.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_CommentParser_SingleElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
|
||||
{
|
||||
|
||||
/**
|
||||
* The content that exists after the tag.
|
||||
*
|
||||
* @var string
|
||||
* @see getContent()
|
||||
*/
|
||||
protected $content = '';
|
||||
|
||||
/**
|
||||
* The whitespace that exists before the content.
|
||||
*
|
||||
* @var string
|
||||
* @see getWhitespaceBeforeContent()
|
||||
*/
|
||||
protected $contentWhitespace = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a SingleElement doc tag.
|
||||
*
|
||||
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
|
||||
* before this
|
||||
* one.
|
||||
* @param array $tokens The tokens
|
||||
* that comprise
|
||||
* this element.
|
||||
* @param string $tag The tag that
|
||||
* this element
|
||||
* represents.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file that
|
||||
* this element
|
||||
* is in.
|
||||
*/
|
||||
public function __construct($previousElement, $tokens, $tag, PHP_CodeSniffer_File $phpcsFile)
|
||||
{
|
||||
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the element names that this tag is comprised of, in the order
|
||||
* that they appear in the tag.
|
||||
*
|
||||
* @return array(string)
|
||||
* @see processSubElement()
|
||||
*/
|
||||
protected function getSubElements()
|
||||
{
|
||||
return array('content');
|
||||
|
||||
}//end getSubElements()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the sub element with the specified name.
|
||||
*
|
||||
* @param string $name The name of the sub element to process.
|
||||
* @param string $content The content of this sub element.
|
||||
* @param string $whitespaceBefore The whitespace that exists before the
|
||||
* sub element.
|
||||
*
|
||||
* @return void
|
||||
* @see getSubElements()
|
||||
*/
|
||||
protected function processSubElement($name, $content, $whitespaceBefore)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->contentWhitespace = $whitespaceBefore;
|
||||
|
||||
}//end processSubElement()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
|
||||
}//end getContent()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the witespace before the content of this tag.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWhitespaceBeforeContent()
|
||||
{
|
||||
return $this->contentWhitespace;
|
||||
|
||||
}//end getWhitespaceBeforeContent()
|
||||
|
||||
|
||||
/**
|
||||
* Processes a content check for single doc element.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param int $commentStart The line number where
|
||||
* the error occurs.
|
||||
* @param string $docBlock Whether this is a file or
|
||||
* class comment doc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $commentStart, $docBlock)
|
||||
{
|
||||
if ($this->content === '') {
|
||||
$errorPos = ($commentStart + $this->getLine());
|
||||
$error = "Content missing for $this->tag tag in $docBlock comment";
|
||||
$phpcsFile->addError($error, $errorPos);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,191 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* The base class for all PHP_CodeSniffer documentation generators.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* The base class for all PHP_CodeSniffer documentation generators.
|
||||
*
|
||||
* Documentation generators are used to print documentation about code sniffs
|
||||
* in a standard.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_DocGenerators_Generator
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the coding standard we are generating docs for.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_standard = '';
|
||||
|
||||
/**
|
||||
* An array of sniffs that we are limiting the generated docs to.
|
||||
*
|
||||
* If this array is empty, docs are generated for all sniffs in the
|
||||
* supplied coding standard.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_sniffs = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_DocGenerators_Generator object.
|
||||
*
|
||||
* @param string $standard The name of the coding standard to generate
|
||||
* docs for.
|
||||
* @param array $sniffs An array of sniffs that we are limiting the
|
||||
* generated docs to.
|
||||
*
|
||||
* @see generate()
|
||||
*/
|
||||
public function __construct($standard, array $sniffs=array())
|
||||
{
|
||||
$this->_standard = $standard;
|
||||
$this->_sniffs = $sniffs;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the title of the sniff from the DOMNode supplied.
|
||||
*
|
||||
* @param DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle(DOMNode $doc)
|
||||
{
|
||||
return $doc->getAttribute('title');
|
||||
|
||||
}//end getTitle()
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the name of the standard we are generating docs for.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStandard()
|
||||
{
|
||||
return $this->_standard;
|
||||
|
||||
}//end getStandard()
|
||||
|
||||
|
||||
/**
|
||||
* Generates the documentation for a standard.
|
||||
*
|
||||
* It's probably wise for doc generators to override this method so they
|
||||
* have control over how the docs are produced. Otherwise, the processSniff
|
||||
* method should be overridden to output content for each sniff.
|
||||
*
|
||||
* @return void
|
||||
* @see processSniff()
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$standardFiles = $this->getStandardFiles();
|
||||
|
||||
foreach ($standardFiles as $standard) {
|
||||
$doc = new DOMDocument();
|
||||
$doc->load($standard);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$this->processSniff($documentation);
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of paths to XML standard files for all sniffs in a standard.
|
||||
*
|
||||
* Any sniffs that do not have an XML standard file are obviously not included
|
||||
* in the returned array. If documentation is only being generated for some
|
||||
* sniffs (ie. $this->_sniffs is not empty) then all others sniffs will
|
||||
* be filtered from the results as well.
|
||||
*
|
||||
* @return array(string)
|
||||
*/
|
||||
protected function getStandardFiles()
|
||||
{
|
||||
if (is_dir($this->_standard) === true) {
|
||||
// This is a custom standard.
|
||||
$standardDir = $this->_standard;
|
||||
$standard = basename($this->_standard);
|
||||
} else {
|
||||
$standardDir = realpath(dirname(__FILE__).'/../Standards/'.$this->_standard);
|
||||
$standard = $this->_standard;
|
||||
}
|
||||
|
||||
$sniffs = PHP_CodeSniffer::getSniffFiles($standardDir, $standard);
|
||||
|
||||
$standardFiles = array();
|
||||
foreach ($sniffs as $sniff) {
|
||||
if (empty($this->_sniffs) === false) {
|
||||
// We are limiting the docs to certain sniffs only, so filter
|
||||
// out any unwanted sniffs.
|
||||
$sniffName = substr($sniff, (strrpos($sniff, '/') + 1));
|
||||
$sniffName = substr($sniffName, 0, -9);
|
||||
if (in_array($sniffName, $this->_sniffs) === false) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$standardFile = str_replace(DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR, $sniff);
|
||||
$standardFile = str_replace('Sniff.php', 'Standard.xml', $standardFile);
|
||||
|
||||
if (is_file($standardFile) === true) {
|
||||
$standardFiles[] = $standardFile;
|
||||
}
|
||||
}
|
||||
|
||||
return $standardFiles;
|
||||
|
||||
}//end getStandardFiles()
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* Doc generators should override this function to produce output.
|
||||
*
|
||||
* @param DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
* @see generate()
|
||||
*/
|
||||
protected function processSniff(DOMNode $doc)
|
||||
{
|
||||
|
||||
}//end processSniff()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,291 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A doc generator that outputs documentation in one big HTML file.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
require_once 'PHP/CodeSniffer/DocGenerators/Generator.php';
|
||||
|
||||
/**
|
||||
* A doc generator that outputs documentation in one big HTML file.
|
||||
*
|
||||
* Output is in one large HTML file and is designed for you to style with
|
||||
* your own stylesheet. It contains a table of contents at the top with anchors
|
||||
* to each sniff.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_DocGenerators_HTML extends PHP_CodeSniffer_DocGenerators_Generator
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Generates the documentation for a standard.
|
||||
*
|
||||
* @return void
|
||||
* @see processSniff()
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
ob_start();
|
||||
$this->printHeader();
|
||||
|
||||
$standardFiles = $this->getStandardFiles();
|
||||
$this->printToc($standardFiles);
|
||||
|
||||
foreach ($standardFiles as $standard) {
|
||||
$doc = new DOMDocument();
|
||||
$doc->load($standard);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$this->processSniff($documentation);
|
||||
}
|
||||
|
||||
$this->printFooter();
|
||||
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
echo $content;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Print the header of the HTML page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printHeader()
|
||||
{
|
||||
$standard = $this->getStandard();
|
||||
echo '<html>'.PHP_EOL;
|
||||
echo ' <head>'.PHP_EOL;
|
||||
echo " <title>$standard Coding Standards</title>".PHP_EOL;
|
||||
echo ' <style>
|
||||
body {
|
||||
background-color: #FFFFFF;
|
||||
font-size: 14px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #666666;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
margin-top: 0px;
|
||||
background-color: #E6E7E8;
|
||||
padding: 20px;
|
||||
border: 1px solid #BBBBBB;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #00A5E3;
|
||||
font-size: 16px;
|
||||
font-weight: normal;
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.code-comparison {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.code-comparison td {
|
||||
border: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
.code-comparison-title, .code-comparison-code {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
color: #000000;
|
||||
vertical-align: top;
|
||||
padding: 4px;
|
||||
width: 50%;
|
||||
background-color: #F1F1F1;
|
||||
line-height: 15px;
|
||||
}
|
||||
|
||||
.code-comparison-code {
|
||||
font-family: Courier;
|
||||
background-color: #F9F9F9;
|
||||
}
|
||||
|
||||
.code-comparison-highlight {
|
||||
background-color: #DDF1F7;
|
||||
border: 1px solid #00A5E3;
|
||||
line-height: 15px;
|
||||
}
|
||||
|
||||
.tag-line {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
margin-top: 30px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.tag-line a {
|
||||
color: #000000;
|
||||
}
|
||||
</style>'.PHP_EOL;
|
||||
echo ' </head>'.PHP_EOL;
|
||||
echo ' <body>'.PHP_EOL;
|
||||
echo " <h1>$standard Coding Standards</h1>".PHP_EOL;
|
||||
|
||||
}//end printHeader()
|
||||
|
||||
|
||||
/**
|
||||
* Print the table of contents for the standard.
|
||||
*
|
||||
* The TOC is just an unordered list of bookmarks to sniffs on the page.
|
||||
*
|
||||
* @param array $standardFiles An array of paths to the XML standard files.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printToc($standardFiles)
|
||||
{
|
||||
echo ' <h2>Table of Contents</h2>'.PHP_EOL;
|
||||
echo ' <ul class="toc">'.PHP_EOL;
|
||||
|
||||
foreach ($standardFiles as $standard) {
|
||||
$doc = new DOMDocument();
|
||||
$doc->load($standard);
|
||||
$documentation = $doc->getElementsByTagName('documentation')->item(0);
|
||||
$title = $this->getTitle($documentation);
|
||||
echo ' <li><a href="#'.str_replace(' ', '-', $title)."\">$title</a></li>".PHP_EOL;
|
||||
}
|
||||
|
||||
echo ' </ul>'.PHP_EOL;
|
||||
|
||||
}//end printToc()
|
||||
|
||||
|
||||
/**
|
||||
* Print the footer of the HTML page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printFooter()
|
||||
{
|
||||
// Turn off strict errors so we don't get timezone warnings if people
|
||||
// don't have their timezone set.
|
||||
error_reporting(E_ALL);
|
||||
echo ' <div class="tag-line">';
|
||||
echo 'Documentation generated on '.date('r');
|
||||
echo ' by <a href="http://pear.php.net/package/PHP_CodeSniffer">PHP_CodeSniffer 1.1.0</a>';
|
||||
echo '</div>'.PHP_EOL;
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
echo ' </body>'.PHP_EOL;
|
||||
echo '</html>'.PHP_EOL;
|
||||
|
||||
}//end printFooter()
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* @param DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processSniff(DOMNode $doc)
|
||||
{
|
||||
$title = $this->getTitle($doc);
|
||||
echo ' <a name="'.str_replace(' ', '-', $title).'" />'.PHP_EOL;
|
||||
echo " <h2>$title</h2>".PHP_EOL;
|
||||
|
||||
foreach ($doc->childNodes as $node) {
|
||||
if ($node->nodeName === 'standard') {
|
||||
$this->printTextBlock($node);
|
||||
} else if ($node->nodeName === 'code_comparison') {
|
||||
$this->printCodeComparisonBlock($node);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSniff()
|
||||
|
||||
|
||||
/**
|
||||
* Print a text block found in a standard.
|
||||
*
|
||||
* @param DOMNode $node The DOMNode object for the text block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTextBlock($node)
|
||||
{
|
||||
$content = trim($node->nodeValue);
|
||||
$content = htmlspecialchars($content);
|
||||
|
||||
// Allow em tags only.
|
||||
$content = str_replace('<em>', '<em>', $content);
|
||||
$content = str_replace('</em>', '</em>', $content);
|
||||
|
||||
echo " <p class=\"text\">$content</p>".PHP_EOL;
|
||||
|
||||
}//end printTextBlock()
|
||||
|
||||
|
||||
/**
|
||||
* Print a code comparison block found in a standard.
|
||||
*
|
||||
* @param DOMNode $node The DOMNode object for the code comparison block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printCodeComparisonBlock($node)
|
||||
{
|
||||
$codeBlocks = $node->getElementsByTagName('code');
|
||||
|
||||
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
|
||||
$first = trim($codeBlocks->item(0)->nodeValue);
|
||||
$first = str_replace("\n", '</br>', $first);
|
||||
$first = str_replace(' ', ' ', $first);
|
||||
$first = str_replace('<em>', '<span class="code-comparison-highlight">', $first);
|
||||
$first = str_replace('</em>', '</span>', $first);
|
||||
|
||||
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
|
||||
$second = trim($codeBlocks->item(1)->nodeValue);
|
||||
$second = str_replace("\n", '</br>', $second);
|
||||
$second = str_replace(' ', ' ', $second);
|
||||
$second = str_replace('<em>', '<span class="code-comparison-highlight">', $second);
|
||||
$second = str_replace('</em>', '</span>', $second);
|
||||
|
||||
echo ' <table class="code-comparison">'.PHP_EOL;
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
echo " <td class=\"code-comparison-title\">$firstTitle</td>".PHP_EOL;
|
||||
echo " <td class=\"code-comparison-title\">$secondTitle</td>".PHP_EOL;
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
echo ' <tr>'.PHP_EOL;
|
||||
echo " <td class=\"code-comparison-code\">$first</td>".PHP_EOL;
|
||||
echo " <td class=\"code-comparison-code\">$second</td>".PHP_EOL;
|
||||
echo ' </tr>'.PHP_EOL;
|
||||
echo ' </table>'.PHP_EOL;
|
||||
|
||||
}//end printCodeComparisonBlock()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,266 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A doc generator that outputs text-based documentation.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
require_once 'PHP/CodeSniffer/DocGenerators/Generator.php';
|
||||
|
||||
/**
|
||||
* A doc generator that outputs text-based documentation.
|
||||
*
|
||||
* Output is designed to be displayed in a terminal and is wrapped to 100 characters.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_DocGenerators_Text extends PHP_CodeSniffer_DocGenerators_Generator
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Process the documentation for a single sniff.
|
||||
*
|
||||
* @param DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function processSniff(DOMNode $doc)
|
||||
{
|
||||
$this->printTitle($doc);
|
||||
|
||||
foreach ($doc->childNodes as $node) {
|
||||
if ($node->nodeName === 'standard') {
|
||||
$this->printTextBlock($node);
|
||||
} else if ($node->nodeName === 'code_comparison') {
|
||||
$this->printCodeComparisonBlock($node);
|
||||
}
|
||||
}
|
||||
|
||||
}//end processSniff()
|
||||
|
||||
|
||||
/**
|
||||
* Prints the title area for a single sniff.
|
||||
*
|
||||
* @param DOMNode $doc The DOMNode object for the sniff.
|
||||
* It represents the "documentation" tag in the XML
|
||||
* standard file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTitle(DOMNode $doc)
|
||||
{
|
||||
$title = $this->getTitle($doc);
|
||||
$standard = $this->getStandard();
|
||||
|
||||
echo PHP_EOL;
|
||||
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
|
||||
echo strtoupper(PHP_EOL."| $standard CODING STANDARD: $title |".PHP_EOL);
|
||||
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
|
||||
echo PHP_EOL.PHP_EOL;
|
||||
|
||||
}//end printTitle()
|
||||
|
||||
|
||||
/**
|
||||
* Print a text block found in a standard.
|
||||
*
|
||||
* @param DOMNode $node The DOMNode object for the text block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printTextBlock($node)
|
||||
{
|
||||
$text = trim($node->nodeValue);
|
||||
$text = str_replace('<em>', '*', $text);
|
||||
$text = str_replace('</em>', '*', $text);
|
||||
|
||||
$lines = array();
|
||||
$tempLine = '';
|
||||
$words = explode(' ', $text);
|
||||
|
||||
foreach ($words as $word) {
|
||||
if (strlen($tempLine.$word) >= 99) {
|
||||
if (strlen($tempLine.$word) === 99) {
|
||||
// Adding the extra space will push us to the edge
|
||||
// so we are done.
|
||||
$lines[] = $tempLine.$word;
|
||||
$tempLine = '';
|
||||
} else if (strlen($tempLine.$word) === 100) {
|
||||
// We are already at the edge, so we are done.
|
||||
$lines[] = $tempLine.$word;
|
||||
$tempLine = '';
|
||||
} else {
|
||||
$lines[] = rtrim($tempLine);
|
||||
$tempLine = $word.' ';
|
||||
}
|
||||
} else {
|
||||
$tempLine .= $word.' ';
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if ($tempLine !== '') {
|
||||
$lines[] = rtrim($tempLine);
|
||||
}
|
||||
|
||||
echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL;
|
||||
|
||||
}//end printTextBlock()
|
||||
|
||||
|
||||
/**
|
||||
* Print a code comparison block found in a standard.
|
||||
*
|
||||
* @param DOMNode $node The DOMNode object for the code comparison block.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function printCodeComparisonBlock($node)
|
||||
{
|
||||
$codeBlocks = $node->getElementsByTagName('code');
|
||||
$first = trim($codeBlocks->item(0)->nodeValue);
|
||||
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
|
||||
|
||||
$firstTitleLines = array();
|
||||
$tempTitle = '';
|
||||
$words = explode(' ', $firstTitle);
|
||||
|
||||
foreach ($words as $word) {
|
||||
if (strlen($tempTitle.$word) >= 45) {
|
||||
if (strlen($tempTitle.$word) === 45) {
|
||||
// Adding the extra space will push us to the edge
|
||||
// so we are done.
|
||||
$firstTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else if (strlen($tempTitle.$word) === 46) {
|
||||
// We are already at the edge, so we are done.
|
||||
$firstTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else {
|
||||
$firstTitleLines[] = $tempTitle;
|
||||
$tempTitle = $word;
|
||||
}
|
||||
} else {
|
||||
$tempTitle .= $word.' ';
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if ($tempTitle !== '') {
|
||||
$firstTitleLines[] = $tempTitle;
|
||||
}
|
||||
|
||||
$first = str_replace('<em>', '', $first);
|
||||
$first = str_replace('</em>', '', $first);
|
||||
$firstLines = explode("\n", $first);
|
||||
|
||||
$second = trim($codeBlocks->item(1)->nodeValue);
|
||||
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
|
||||
|
||||
$secondTitleLines = array();
|
||||
$tempTitle = '';
|
||||
$words = explode(' ', $secondTitle);
|
||||
|
||||
foreach ($words as $word) {
|
||||
if (strlen($tempTitle.$word) >= 45) {
|
||||
if (strlen($tempTitle.$word) === 45) {
|
||||
// Adding the extra space will push us to the edge
|
||||
// so we are done.
|
||||
$secondTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else if (strlen($tempTitle.$word) === 46) {
|
||||
// We are already at the edge, so we are done.
|
||||
$secondTitleLines[] = $tempTitle.$word;
|
||||
$tempTitle = '';
|
||||
} else {
|
||||
$secondTitleLines[] = $tempTitle;
|
||||
$tempTitle = $word;
|
||||
}
|
||||
} else {
|
||||
$tempTitle .= $word.' ';
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
if ($tempTitle !== '') {
|
||||
$secondTitleLines[] = $tempTitle;
|
||||
}
|
||||
|
||||
$second = str_replace('<em>', '', $second);
|
||||
$second = str_replace('</em>', '', $second);
|
||||
$secondLines = explode("\n", $second);
|
||||
|
||||
$maxCodeLines = max(count($firstLines), count($secondLines));
|
||||
$maxTitleLines = max(count($firstTitleLines), count($secondTitleLines));
|
||||
|
||||
echo str_repeat('-', 41);
|
||||
echo ' CODE COMPARISON ';
|
||||
echo str_repeat('-', 42).PHP_EOL;
|
||||
|
||||
for ($i = 0; $i < $maxTitleLines; $i++) {
|
||||
if (isset($firstTitleLines[$i]) === true) {
|
||||
$firstLineText = $firstTitleLines[$i];
|
||||
} else {
|
||||
$firstLineText = '';
|
||||
}
|
||||
|
||||
if (isset($secondTitleLines[$i]) === true) {
|
||||
$secondLineText = $secondTitleLines[$i];
|
||||
} else {
|
||||
$secondLineText = '';
|
||||
}
|
||||
|
||||
echo '| ';
|
||||
echo $firstLineText.str_repeat(' ', (46 - strlen($firstLineText)));
|
||||
echo ' | ';
|
||||
echo $secondLineText.str_repeat(' ', (47 - strlen($secondLineText)));
|
||||
echo ' |'.PHP_EOL;
|
||||
}//end for
|
||||
|
||||
echo str_repeat('-', 100).PHP_EOL;
|
||||
|
||||
for ($i = 0; $i < $maxCodeLines; $i++) {
|
||||
if (isset($firstLines[$i]) === true) {
|
||||
$firstLineText = $firstLines[$i];
|
||||
} else {
|
||||
$firstLineText = '';
|
||||
}
|
||||
|
||||
if (isset($secondLines[$i]) === true) {
|
||||
$secondLineText = $secondLines[$i];
|
||||
} else {
|
||||
$secondLineText = '';
|
||||
}
|
||||
|
||||
echo '| ';
|
||||
echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText)));
|
||||
echo '| ';
|
||||
echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText)));
|
||||
echo '|'.PHP_EOL;
|
||||
}//end for
|
||||
|
||||
echo str_repeat('-', 100).PHP_EOL.PHP_EOL;
|
||||
|
||||
}//end printCodeComparisonBlock()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* An exception thrown by PHP_CodeSniffer when it encounters an unrecoverable error.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
require_once 'PEAR/Exception.php';
|
||||
|
||||
/**
|
||||
* An exception thrown by PHP_CodeSniffer when it encounters an unrecoverable error.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_Exception extends PEAR_Exception
|
||||
{
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -1,116 +0,0 @@
|
||||
<?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/>.
|
||||
/**
|
||||
* Subclass of lib/pear/PHP/CodeSniffer/CLI.php
|
||||
*
|
||||
* Simple modifications to the CLI class to only use the Moodle Standard
|
||||
*
|
||||
* @package lib-pear-php-codesniffer
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once('PHP/MoodleCodeSniffer.php');
|
||||
require_once('PHP/CodeSniffer/CLI.php');
|
||||
|
||||
/**
|
||||
* A class to process command line runsniffer scripts. Modified for use within Moodle
|
||||
*
|
||||
* @category lib-pear-php-codesniffer
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_codesniffer_cli extends php_codesniffer_cli {
|
||||
/**
|
||||
* Modified to return Moodle only
|
||||
*
|
||||
* @param string $standard The standard to validate.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function validatestandard($standard) {
|
||||
return 'Moodle';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out the usage information for this script.
|
||||
*
|
||||
* Modified by removing the --standard option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printusage() {
|
||||
echo 'Usage: runsniffer [-nwlvi] [--report=<report>]'.PHP_EOL;
|
||||
echo ' [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
|
||||
echo ' [--generator=<generator>] [--extensions=<extensions>]'.PHP_EOL;
|
||||
echo ' [--ignore=<patterns>] [--tab-width=<width>] <file> ...'.PHP_EOL;
|
||||
echo ' -n Do not print warnings'.PHP_EOL;
|
||||
echo ' -w Print both warnings and errors (on by default)'.PHP_EOL;
|
||||
echo ' -l Local directory only, no recursion'.PHP_EOL;
|
||||
echo ' -v[v][v] Print verbose output'.PHP_EOL;
|
||||
echo ' -i Show a list of installed coding standards'.PHP_EOL;
|
||||
echo ' --help Print this help message'.PHP_EOL;
|
||||
echo ' --version Print version information'.PHP_EOL;
|
||||
echo ' <file> One or more files and/or directories to check'.PHP_EOL;
|
||||
echo ' <extensions> A comma separated list of file extensions to check'.PHP_EOL;
|
||||
echo ' (only valid if checking a directory)'.PHP_EOL;
|
||||
echo ' <patterns> A comma separated list of patterns that are used'.PHP_EOL;
|
||||
echo ' to ignore directories and files'.PHP_EOL;
|
||||
echo ' <width> The number of spaces each tab represents'.PHP_EOL;
|
||||
echo ' <generator> The name of a doc generator to use'.PHP_EOL;
|
||||
echo ' (forces doc generation instead of checking)'.PHP_EOL;
|
||||
echo ' <report> Print either the "full", "xml", "checkstyle",'.PHP_EOL;
|
||||
echo ' "csv" or "summary" report'.PHP_EOL;
|
||||
echo ' (the "full" report is printed by default)'.PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes an unknown command line argument.
|
||||
*
|
||||
* Overriding CLI method to allow for dynamic loading of path to requested file/directory
|
||||
*
|
||||
* @param string $arg The command line argument.
|
||||
* @param int $pos The position of the argument on the command line.
|
||||
* @param array $values An array of values determined from CLI args.
|
||||
*
|
||||
* @return array The updated CLI values.
|
||||
* @see getCommandLineValues()
|
||||
*/
|
||||
public function processunknownargument($arg, $pos, $values) {
|
||||
global $args, $argv, $argc;
|
||||
|
||||
// We don't know about any additional switches; just files.
|
||||
if ($arg{0} === '-') {
|
||||
echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
|
||||
$this->printUsage();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$file = $_SERVER['PWD'] . '/' . $arg;
|
||||
|
||||
if (file_exists($file) === false) {
|
||||
echo 'ERROR: The file "'.$arg.'" does not exist.'.PHP_EOL.PHP_EOL;
|
||||
$this->printUsage();
|
||||
exit(2);
|
||||
} else {
|
||||
$values['files'][] = $file;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Represents a PHP_CodeSniffer sniff for sniffing coding standards.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a PHP_CodeSniffer sniff for sniffing coding standards.
|
||||
*
|
||||
* A sniff registers what token types it wishes to listen for, then, when
|
||||
* PHP_CodeSniffer encounters that token, the sniff is invoked and passed
|
||||
* information about where the token was found in the stack, and the
|
||||
* PHP_CodeSniffer file in which the token was found.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
interface PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*
|
||||
* An example return value for a sniff that wants to listen for whitespace
|
||||
* and any comments would be:
|
||||
*
|
||||
* <code>
|
||||
* return array(
|
||||
* T_WHITESPACE,
|
||||
* T_DOC_COMMENT,
|
||||
* T_COMMENT,
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @return array(int)
|
||||
* @see Tokens.php
|
||||
*/
|
||||
public function register();
|
||||
|
||||
|
||||
/**
|
||||
* Called when one of the token types that this sniff is listening for
|
||||
* is found.
|
||||
*
|
||||
* The stackPtr variable indicates where in the stack the token was found.
|
||||
* A sniff can acquire information this token, along with all the other
|
||||
* tokens within the stack by first acquiring the token stack:
|
||||
*
|
||||
* <code>
|
||||
* $tokens = $phpcsFile->getTokens();
|
||||
* echo 'Encountered a '.$tokens[$stackPtr]['type'].' token';
|
||||
* echo 'token information: ';
|
||||
* print_r($tokens[$stackPtr]);
|
||||
* </code>
|
||||
*
|
||||
* If the sniff discovers an anomilty in the code, they can raise an error
|
||||
* by calling addError() on the PHP_CodeSniffer_File object, specifying an error
|
||||
* message and the position of the offending token:
|
||||
*
|
||||
* <code>
|
||||
* $phpcsFile->addError('Encountered an error', $stackPtr);
|
||||
* </code>
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
|
||||
* token was found.
|
||||
* @param int $stackPtr The position in the PHP_CodeSniffer
|
||||
* file's token stack where the token
|
||||
* was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
|
||||
|
||||
|
||||
}//end interface
|
||||
|
||||
?>
|
@ -1,779 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Processes pattern strings and checks that the code conforms to the pattern.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_Standards_IncorrectPatternException', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_Standards_IncorrectPatternException not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes pattern strings and checks that the code conforms to the pattern.
|
||||
*
|
||||
* This test essentially checks that code is correctly formatted with whitespace.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_Standards_AbstractPatternSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* The parsed patterns array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_parsedPatterns = array();
|
||||
|
||||
/**
|
||||
* Tokens that wish this sniff wishes to process outside of the patterns.
|
||||
*
|
||||
* @var array(int)
|
||||
* @see registerSupplementary()
|
||||
* @see processSupplementary()
|
||||
*/
|
||||
private $_supplementaryTokens = array();
|
||||
|
||||
/**
|
||||
* If true, comments will be ignored if they are found in the code.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_ignoreComments = false;
|
||||
|
||||
/**
|
||||
* Positions in the stack where errors have occured.
|
||||
*
|
||||
* @var array()
|
||||
*/
|
||||
private $_errorPos = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PHP_CodeSniffer_Standards_AbstractPatternSniff.
|
||||
*
|
||||
* @param boolean $ignoreComments If true, comments will be ignored.
|
||||
*/
|
||||
public function __construct($ignoreComments=false)
|
||||
{
|
||||
$this->_ignoreComments = $ignoreComments;
|
||||
$this->_supplementaryTokens = $this->registerSupplementary();
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens to listen to.
|
||||
*
|
||||
* Classes extending <i>AbstractPatternTest</i> should implement the
|
||||
* <i>getPatterns()</i> method to register the patterns they wish to test.
|
||||
*
|
||||
* @return array(int)
|
||||
* @see process()
|
||||
*/
|
||||
public final function register()
|
||||
{
|
||||
$listenTypes = array();
|
||||
$patterns = $this->getPatterns();
|
||||
|
||||
foreach ($patterns as $pattern) {
|
||||
|
||||
$parsedPattern = $this->_parse($pattern);
|
||||
|
||||
// Find a token position in the pattern that we can use for a listener
|
||||
// token.
|
||||
$pos = $this->_getListenerTokenPos($parsedPattern);
|
||||
$tokenType = $parsedPattern[$pos]['token'];
|
||||
$listenTypes[] = $tokenType;
|
||||
|
||||
$patternArray = array(
|
||||
'listen_pos' => $pos,
|
||||
'pattern' => $parsedPattern,
|
||||
'pattern_code' => $pattern,
|
||||
);
|
||||
|
||||
if (isset($this->_parsedPatterns[$tokenType]) === false) {
|
||||
$this->_parsedPatterns[$tokenType] = array();
|
||||
}
|
||||
|
||||
$this->_parsedPatterns[$tokenType][] = $patternArray;
|
||||
|
||||
}//end foreach
|
||||
|
||||
return array_unique(array_merge($listenTypes, $this->_supplementaryTokens));
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the token types that the specified pattern is checking for.
|
||||
*
|
||||
* Returned array is in the format:
|
||||
* <code>
|
||||
* array(
|
||||
* T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token
|
||||
* // should occur in the pattern.
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param array $pattern The parsed pattern to find the acquire the token
|
||||
* types from.
|
||||
*
|
||||
* @return array(int => int)
|
||||
*/
|
||||
private function _getPatternTokenTypes($pattern)
|
||||
{
|
||||
$tokenTypes = array();
|
||||
foreach ($pattern as $pos => $patternInfo) {
|
||||
if ($patternInfo['type'] === 'token') {
|
||||
if (isset($tokenTypes[$patternInfo['token']]) === false) {
|
||||
$tokenTypes[$patternInfo['token']] = $pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tokenTypes;
|
||||
|
||||
}//end _getPatternTokenTypes()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the position in the pattern that this test should register as
|
||||
* a listener for the pattern.
|
||||
*
|
||||
* @param array $pattern The pattern to acquire the listener for.
|
||||
*
|
||||
* @return int The postition in the pattern that this test should register
|
||||
* as the listener.
|
||||
* @throws PHP_CodeSniffer_Exception If we could not determine a token
|
||||
* to listen for.
|
||||
*/
|
||||
private function _getListenerTokenPos($pattern)
|
||||
{
|
||||
$tokenTypes = $this->_getPatternTokenTypes($pattern);
|
||||
$tokenCodes = array_keys($tokenTypes);
|
||||
$token = PHP_CodeSniffer_Tokens::getHighestWeightedToken($tokenCodes);
|
||||
|
||||
// If we could not get a token.
|
||||
if ($token === false) {
|
||||
$error = 'Could not determine a token to listen for';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
return $tokenTypes[$token];
|
||||
|
||||
}//end _getListenerTokenPos()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the test.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
|
||||
* token occured.
|
||||
* @param int $stackPtr The postion in the tokens stack
|
||||
* where the listening token type was
|
||||
* found.
|
||||
*
|
||||
* @return void
|
||||
* @see register()
|
||||
*/
|
||||
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if (in_array($tokens[$stackPtr]['code'], $this->_supplementaryTokens) === true) {
|
||||
$this->processSupplementary($phpcsFile, $stackPtr);
|
||||
}
|
||||
|
||||
$type = $tokens[$stackPtr]['code'];
|
||||
|
||||
// If the type is not set, then it must have been a token registered
|
||||
// with registerSupplementary().
|
||||
if (isset($this->_parsedPatterns[$type]) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$allErrors = array();
|
||||
|
||||
// Loop over each pattern that is listening to the current token type
|
||||
// that we are processing.
|
||||
foreach ($this->_parsedPatterns[$type] as $patternInfo) {
|
||||
|
||||
// If processPattern returns false, then the pattern that we are
|
||||
// checking the code with must not be design to check that code.
|
||||
$errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
|
||||
if ($errors === false) {
|
||||
// The pattern didn't match.
|
||||
continue;
|
||||
} else if (empty($errors) === true) {
|
||||
// The pattern matched, but there were no errors.
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($errors as $stackPtr => $error) {
|
||||
if (isset($this->_errorPos[$stackPtr]) === false) {
|
||||
$this->_errorPos[$stackPtr] = true;
|
||||
$allErrors[$stackPtr] = $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($allErrors as $stackPtr => $error) {
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the pattern and verifies the code at $stackPtr.
|
||||
*
|
||||
* @param array $patternInfo Information about the pattern used
|
||||
* for checking, which includes are
|
||||
* parsed token representation of the
|
||||
* pattern.
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
|
||||
* token occured.
|
||||
* @param int $stackPtr The postion in the tokens stack where
|
||||
* the listening token type was found.
|
||||
*
|
||||
* @return array(errors)
|
||||
*/
|
||||
protected function processPattern($patternInfo, PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$pattern = $patternInfo['pattern'];
|
||||
$patternCode = $patternInfo['pattern_code'];
|
||||
$errors = array();
|
||||
$found = '';
|
||||
|
||||
$ignoreTokens = array(T_WHITESPACE);
|
||||
|
||||
if ($this->_ignoreComments === true) {
|
||||
$ignoreTokens = array_merge($ignoreTokens, PHP_CodeSniffer_Tokens::$commentTokens);
|
||||
}
|
||||
|
||||
$origStackPtr = $stackPtr;
|
||||
$hasError = false;
|
||||
|
||||
if ($patternInfo['listen_pos'] > 0) {
|
||||
$stackPtr--;
|
||||
|
||||
for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
|
||||
|
||||
if ($pattern[$i]['type'] === 'token') {
|
||||
|
||||
if ($pattern[$i]['token'] === T_WHITESPACE) {
|
||||
|
||||
if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
|
||||
$found = $tokens[$stackPtr]['content'].$found;
|
||||
}
|
||||
|
||||
// Only check the size of the whitespace if this is not
|
||||
// not the first token. We don't care about the size of
|
||||
// leading whitespace, just that there is some.
|
||||
if ($i !== 0) {
|
||||
if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Check to see if this important token is the same as the
|
||||
// previous important token in the pattern. If it is not,
|
||||
// then the pattern cannot be for this piece of code.
|
||||
$prev = $phpcsFile->findPrevious($ignoreTokens, $stackPtr, null, true);
|
||||
if ($prev === false || $tokens[$prev]['code'] !== $pattern[$i]['token']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we skipped past some whitespace tokens, then add them
|
||||
// to the found string.
|
||||
if (($stackPtr - $prev) > 1) {
|
||||
for ($j = ($stackPtr - 1); $j > $prev; $j--) {
|
||||
$found = $tokens[$j]['content'].$found;
|
||||
}
|
||||
}
|
||||
|
||||
$found = $tokens[$prev]['content'].$found;
|
||||
|
||||
if (isset($pattern[($i - 1)]) === true && $pattern[($i - 1)]['type'] === 'skip') {
|
||||
$stackPtr = $prev;
|
||||
} else {
|
||||
$stackPtr = ($prev - 1);
|
||||
}
|
||||
|
||||
}//end if
|
||||
} else if ($pattern[$i]['type'] === 'skip') {
|
||||
// Skip to next piece of relevant code.
|
||||
if ($pattern[$i]['to'] === 'parenthesis_closer') {
|
||||
$to = 'parenthesis_opener';
|
||||
} else {
|
||||
$to = 'scope_opener';
|
||||
}
|
||||
|
||||
// Find the previous opener.
|
||||
$next = $phpcsFile->findPrevious($ignoreTokens, $stackPtr, null, true);
|
||||
if ($next === false || isset($tokens[$next][$to]) === false) {
|
||||
// If there was not opener, then we must be
|
||||
// using the wrong pattern.
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($to === 'parenthesis_opener') {
|
||||
$found = '{'.$found;
|
||||
} else {
|
||||
$found = '('.$found;
|
||||
}
|
||||
|
||||
$found = '...'.$found;
|
||||
|
||||
// Skip to the opening token.
|
||||
$stackPtr = ($tokens[$next][$to] - 1);
|
||||
} else if ($pattern[$i]['type'] === 'string') {
|
||||
$found = 'abc';
|
||||
} else if ($pattern[$i]['type'] === 'newline') {
|
||||
$found = 'EOL';
|
||||
}//end if
|
||||
}//end for
|
||||
}//end if
|
||||
|
||||
$stackPtr = $origStackPtr;
|
||||
$lastAddedStackPtr = null;
|
||||
$patternLen = count($pattern);
|
||||
|
||||
for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
|
||||
|
||||
if ($pattern[$i]['type'] === 'token') {
|
||||
|
||||
if ($pattern[$i]['token'] === T_WHITESPACE) {
|
||||
|
||||
if ($this->_ignoreComments === true) {
|
||||
// If we are ignoring comments, check to see if this current
|
||||
// token is a comment. If so skip it.
|
||||
if (in_array($tokens[$stackPtr]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the next token is a comment, the we need to skip the
|
||||
// current token as we should allow a space before a
|
||||
// comment for readability.
|
||||
if (in_array($tokens[($stackPtr + 1)]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$tokenContent = '';
|
||||
if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
|
||||
if (isset($pattern[($i + 1)]) === false) {
|
||||
// This is the last token in the pattern, so just compare
|
||||
// the next token of content.
|
||||
$tokenContent = $tokens[$stackPtr]['content'];
|
||||
} else {
|
||||
// Get all the whitespace to the next token.
|
||||
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr, null, true);
|
||||
$tokenContent = $phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr));
|
||||
$lastAddedStackPtr = $stackPtr;
|
||||
$stackPtr = $next;
|
||||
}
|
||||
|
||||
if ($stackPtr !== $lastAddedStackPtr) {
|
||||
$found .= $tokenContent;
|
||||
}
|
||||
} else {
|
||||
if ($stackPtr !== $lastAddedStackPtr) {
|
||||
$found .= $tokens[$stackPtr]['content'];
|
||||
$lastAddedStackPtr = $stackPtr;
|
||||
}
|
||||
}//end if
|
||||
|
||||
if (isset($pattern[($i + 1)]) === true && $pattern[($i + 1)]['type'] === 'skip') {
|
||||
// The next token is a skip token, so we just need to make
|
||||
// sure the whitespace we found has *at least* the
|
||||
// whitespace required.
|
||||
if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
|
||||
$hasError = true;
|
||||
}
|
||||
} else {
|
||||
if ($tokenContent !== $pattern[$i]['value']) {
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Check to see if this important token is the same as the
|
||||
// next important token in the pattern. If it is not, then
|
||||
// the pattern cannot be for this piece of code.
|
||||
$next = $phpcsFile->findNext($ignoreTokens, $stackPtr, null, true);
|
||||
if ($next === false || $tokens[$next]['code'] !== $pattern[$i]['token']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we skipped past some whitespace tokens, then add them
|
||||
// to the found string.
|
||||
if (($next - $stackPtr) > 0) {
|
||||
$hasComment = false;
|
||||
for ($j = $stackPtr; $j < $next; $j++) {
|
||||
$found .= $tokens[$j]['content'];
|
||||
if (in_array($tokens[$j]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
|
||||
$hasComment = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If we are not ignoring comments, this additional
|
||||
// whitespace or comment is not allowed. If we are
|
||||
// ignoring comments, there needs to be at least one
|
||||
// comment for this to be allowed.
|
||||
if ($this->_ignoreComments === false || ($this->_ignoreComments === true && $hasComment === false)) {
|
||||
$hasError = true;
|
||||
}
|
||||
|
||||
// Even when ignoring comments, we are not allowed to include
|
||||
// newlines without the pattern specifying them, so
|
||||
// everything should be on the same line.
|
||||
if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
|
||||
$hasError = true;
|
||||
}
|
||||
}//end if
|
||||
|
||||
if ($next !== $lastAddedStackPtr) {
|
||||
$found .= $tokens[$next]['content'];
|
||||
$lastAddedStackPtr = $next;
|
||||
}
|
||||
|
||||
if (isset($pattern[($i + 1)]) === true && $pattern[($i + 1)]['type'] === 'skip') {
|
||||
$stackPtr = $next;
|
||||
} else {
|
||||
$stackPtr = ($next + 1);
|
||||
}
|
||||
}//end if
|
||||
|
||||
} else if ($pattern[$i]['type'] === 'skip') {
|
||||
// Find the previous opener.
|
||||
$next = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$blockOpeners, $stackPtr, null);
|
||||
if ($next === false || isset($tokens[$next][$pattern[$i]['to']]) === false) {
|
||||
// If there was not opener, then we must
|
||||
// be using the wrong pattern.
|
||||
return false;
|
||||
}
|
||||
|
||||
$found .= '...';
|
||||
if ($pattern[$i]['to'] === 'parenthesis_closer') {
|
||||
$found .= ')';
|
||||
} else {
|
||||
$found .= '}';
|
||||
}
|
||||
|
||||
// Skip to the closing token.
|
||||
$stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
|
||||
} else if ($pattern[$i]['type'] === 'string') {
|
||||
if ($tokens[$stackPtr]['code'] !== T_STRING) {
|
||||
$hasError = true;
|
||||
}
|
||||
|
||||
if ($stackPtr !== $lastAddedStackPtr) {
|
||||
$found .= 'abc';
|
||||
$lastAddedStackPtr = $stackPtr;
|
||||
}
|
||||
|
||||
$stackPtr++;
|
||||
} else if ($pattern[$i]['type'] === 'newline') {
|
||||
// Find the next token that contains a newline character.
|
||||
$newline = 0;
|
||||
for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
|
||||
if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
|
||||
$newline = $j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($newline === 0) {
|
||||
// We didn't find a newline character in the rest of the file.
|
||||
$next = ($phpcsFile->numTokens - 1);
|
||||
$hasError = true;
|
||||
} else {
|
||||
if ($this->_ignoreComments === false) {
|
||||
// The newline character cannot be part of a comment.
|
||||
if (in_array($tokens[$newline]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($newline === $stackPtr) {
|
||||
$next = ($stackPtr + 1);
|
||||
} else {
|
||||
// Check that there were no significant tokens that we
|
||||
// skipped over to find our newline character.
|
||||
$next = $phpcsFile->findNext($ignoreTokens, $stackPtr, null, true);
|
||||
if ($next < $newline) {
|
||||
// We skipped a non-ignored token.
|
||||
$hasError = true;
|
||||
} else {
|
||||
$next = ($newline + 1);
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
|
||||
if ($stackPtr !== $lastAddedStackPtr) {
|
||||
$found .= $phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr));
|
||||
$diff = ($next - $stackPtr);
|
||||
$lastAddedStackPtr = ($next - 1);
|
||||
}
|
||||
|
||||
$stackPtr = $next;
|
||||
}//end if
|
||||
}//end for
|
||||
|
||||
if ($hasError === true) {
|
||||
$error = $this->prepareError($found, $patternCode);
|
||||
$errors[$origStackPtr] = $error;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
|
||||
}//end processPattern()
|
||||
|
||||
|
||||
/**
|
||||
* Prepares an error for the specified patternCode.
|
||||
*
|
||||
* @param string $found The actual found string in the code.
|
||||
* @param string $patternCode The expected pattern code.
|
||||
*
|
||||
* @return string The error message.
|
||||
*/
|
||||
protected function prepareError($found, $patternCode)
|
||||
{
|
||||
$found = str_replace("\r\n", '\n', $found);
|
||||
$found = str_replace("\n", '\n', $found);
|
||||
$found = str_replace("\r", '\n', $found);
|
||||
$found = str_replace('EOL', '\n', $found);
|
||||
$expected = str_replace('EOL', '\n', $patternCode);
|
||||
|
||||
$error = "Expected \"$expected\"; found \"$found\"";
|
||||
|
||||
return $error;
|
||||
|
||||
}//end prepareError()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the patterns that should be checked.
|
||||
*
|
||||
* @return array(string)
|
||||
*/
|
||||
protected abstract function getPatterns();
|
||||
|
||||
|
||||
/**
|
||||
* Registers any supplementary tokens that this test might wish to process.
|
||||
*
|
||||
* A sniff may wish to register supplementary tests when it wishes to group
|
||||
* an arbitary validation that cannot be performed using a pattern, with
|
||||
* other pattern tests.
|
||||
*
|
||||
* @return array(int)
|
||||
* @see processSupplementary()
|
||||
*/
|
||||
protected function registerSupplementary()
|
||||
{
|
||||
return array();
|
||||
|
||||
}//end registerSupplementary()
|
||||
|
||||
|
||||
/**
|
||||
* Processes any tokens registered with registerSupplementary().
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where to
|
||||
* process the skip.
|
||||
* @param int $stackPtr The position in the tokens stack to
|
||||
* process.
|
||||
*
|
||||
* @return void
|
||||
* @see registerSupplementary()
|
||||
*/
|
||||
protected function processSupplementary(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
return;
|
||||
|
||||
}//end processSupplementary()
|
||||
|
||||
|
||||
/**
|
||||
* Parses a pattern string into an array of pattern steps.
|
||||
*
|
||||
* @param string $pattern The pattern to parse.
|
||||
*
|
||||
* @return array The parsed pattern array.
|
||||
* @see _createSkipPattern()
|
||||
* @see _createTokenPattern()
|
||||
*/
|
||||
private function _parse($pattern)
|
||||
{
|
||||
$patterns = array();
|
||||
$length = strlen($pattern);
|
||||
$lastToken = 0;
|
||||
$firstToken = 0;
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
|
||||
$specialPattern = false;
|
||||
$isLastChar = ($i === ($length - 1));
|
||||
$oldFirstToken = $firstToken;
|
||||
|
||||
if (substr($pattern, $i, 3) === '...') {
|
||||
// It's a skip pattern. The skip pattern requires the
|
||||
// content of the token in the "from" position and the token
|
||||
// to skip to.
|
||||
$specialPattern = $this->_createSkipPattern($pattern, ($i - 1));
|
||||
$lastToken = ($i - $firstToken);
|
||||
$firstToken = ($i + 4);
|
||||
$i = ($i + 3);
|
||||
} else if (substr($pattern, $i, 3) === 'abc') {
|
||||
$specialPattern = array('type' => 'string');
|
||||
$lastToken = ($i - $firstToken);
|
||||
$firstToken = ($i + 3);
|
||||
$i = ($i + 2);
|
||||
} else if (substr($pattern, $i, 3) === 'EOL') {
|
||||
$specialPattern = array('type' => 'newline');
|
||||
$lastToken = ($i - $firstToken);
|
||||
$firstToken = ($i + 3);
|
||||
$i = ($i + 2);
|
||||
}
|
||||
|
||||
if ($specialPattern !== false || $isLastChar === true) {
|
||||
|
||||
// If we are at the end of the string, don't worry about a limit.
|
||||
if ($isLastChar === true) {
|
||||
// Get the string from the end of the last skip pattern, if any,
|
||||
// to the end of the pattern string.
|
||||
$str = substr($pattern, $oldFirstToken);
|
||||
} else {
|
||||
// Get the string from the end of the last special pattern,
|
||||
// if any, to the start of this special pattern.
|
||||
$str = substr($pattern, $oldFirstToken, $lastToken);
|
||||
}
|
||||
|
||||
$tokenPatterns = $this->_createTokenPattern($str);
|
||||
|
||||
// Make sure we don't skip the last token.
|
||||
if ($isLastChar === false && $i === ($length - 1)) {
|
||||
$i--;
|
||||
}
|
||||
|
||||
foreach ($tokenPatterns as $tokenPattern) {
|
||||
$patterns[] = $tokenPattern;
|
||||
}
|
||||
}//end if
|
||||
|
||||
// Add the skip pattern *after* we have processed
|
||||
// all the tokens from the end of the last skip pattern
|
||||
// to the start of this skip pattern.
|
||||
if ($specialPattern !== false) {
|
||||
$patterns[] = $specialPattern;
|
||||
}
|
||||
|
||||
}//end for
|
||||
|
||||
return $patterns;
|
||||
|
||||
}//end _parse()
|
||||
|
||||
|
||||
/**
|
||||
* Creates a skip pattern.
|
||||
*
|
||||
* @param string $pattern The pattern being parsed.
|
||||
* @param string $from The token content that the skip pattern starts from.
|
||||
*
|
||||
* @return array The pattern step.
|
||||
* @see _createTokenPattern()
|
||||
* @see _parse()
|
||||
*/
|
||||
private function _createSkipPattern($pattern, $from)
|
||||
{
|
||||
$skip = array('type' => 'skip');
|
||||
|
||||
for ($from; $from >= 0; $from--) {
|
||||
switch ($pattern[$from]) {
|
||||
case '(':
|
||||
$skip['to'] = 'parenthesis_closer';
|
||||
break;
|
||||
case '{':
|
||||
$skip['to'] = 'scope_closer';
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($skip['to']) === true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($skip['to']) === false) {
|
||||
$skip['to'] = 'unknown';
|
||||
}
|
||||
|
||||
return $skip;
|
||||
|
||||
}//end _createSkipPattern()
|
||||
|
||||
|
||||
/**
|
||||
* Creates a token pattern.
|
||||
*
|
||||
* @param string $str The tokens string that the pattern should match.
|
||||
*
|
||||
* @return array The pattern step.
|
||||
* @see _createSkipPattern()
|
||||
* @see _parse()
|
||||
*/
|
||||
private function _createTokenPattern($str)
|
||||
{
|
||||
// Don't add a space after the closing php tag as it will add a new
|
||||
// whitespace token.
|
||||
$tokens = token_get_all('<?php '.$str.'?>');
|
||||
|
||||
// Remove the <?php tag from the front and the end php tag from the back.
|
||||
$tokens = array_slice($tokens, 1, (count($tokens) - 2));
|
||||
|
||||
foreach ($tokens as &$token) {
|
||||
$token = PHP_CodeSniffer::standardiseToken($token);
|
||||
}
|
||||
|
||||
$patterns = array();
|
||||
foreach ($tokens as $patternInfo) {
|
||||
$patterns[] = array(
|
||||
'type' => 'token',
|
||||
'token' => $patternInfo['code'],
|
||||
'value' => $patternInfo['content'],
|
||||
);
|
||||
}
|
||||
|
||||
return $patterns;
|
||||
|
||||
}//end _createTokenPattern()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,213 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* An AbstractScopeTest allows for tests that extend from this class to
|
||||
* listen for tokens within a particluar scope.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* An AbstractScopeTest allows for tests that extend from this class to
|
||||
* listen for tokens within a particluar scope.
|
||||
*
|
||||
* Below is a test that listens to methods that exist only within classes:
|
||||
* <code>
|
||||
* class ClassScopeTest extends PHP_CodeSniffer_Standards_AbstractScopeSniff
|
||||
* {
|
||||
* public function __construct()
|
||||
* {
|
||||
* parent::__construct(array(T_CLASS), array(T_FUNCTION));
|
||||
* }
|
||||
*
|
||||
* protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $)
|
||||
* {
|
||||
* $className = $phpcsFile->getDeclarationName($currScope);
|
||||
* echo 'encountered a method within class '.$className;
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_Standards_AbstractScopeSniff implements PHP_CodeSniffer_Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* The token types that this test wishes to listen to within the scope.
|
||||
*
|
||||
* @var array()
|
||||
*/
|
||||
private $_tokens = array();
|
||||
|
||||
/**
|
||||
* The type of scope opener tokens that this test wishes to listen to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_scopeTokens = array();
|
||||
|
||||
/**
|
||||
* The position in the tokens array that opened the current scope.
|
||||
*
|
||||
* @var array()
|
||||
*/
|
||||
protected $currScope = null;
|
||||
|
||||
/**
|
||||
* True if this test should fire on tokens outside of the scope.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_listenOutside = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new AbstractScopeTest.
|
||||
*
|
||||
* @param array $scopeTokens The type of scope the test wishes to listen to.
|
||||
* @param array $tokens The tokens that the test wishes to listen to
|
||||
* within the scope.
|
||||
* @param boolean $listenOutside If true this test will also alert the
|
||||
* extending class when a token is found outside
|
||||
* the scope, by calling the
|
||||
* processTokenOutideScope method.
|
||||
*
|
||||
* @see PHP_CodeSniffer.getValidScopeTokeners()
|
||||
* @throws PHP_CodeSniffer_Test_Exception If the specified tokens array is empty.
|
||||
*/
|
||||
public function __construct(array $scopeTokens, array $tokens, $listenOutside=false)
|
||||
{
|
||||
if (empty($scopeTokens) === true) {
|
||||
$error = 'The scope tokens list cannot be empty';
|
||||
throw new PHP_CodeSniffer_Test_Exception($error);
|
||||
}
|
||||
|
||||
if (empty($tokens) === true) {
|
||||
$error = 'The tokens list cannot be empty';
|
||||
throw new PHP_CodeSniffer_Test_Exception($error);
|
||||
}
|
||||
|
||||
$invalidScopeTokens = array_intersect($scopeTokens, $tokens);
|
||||
if (empty($invalidScopeTokens) === false) {
|
||||
$invalid = implode(', ', $invalidScopeTokens);
|
||||
$error = "Scope tokens [$invalid] cant be in the tokens array";
|
||||
throw new PHP_CodeSniffer_Test_Exception($error);
|
||||
}
|
||||
|
||||
$this->_listenOutside = $listenOutside;
|
||||
$this->_scopeTokens = $scopeTokens;
|
||||
$this->_tokens = $tokens;
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* The method that is called to register the tokens this test wishes to
|
||||
* listen to.
|
||||
*
|
||||
* DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register
|
||||
* for the desired tokens and scope.
|
||||
*
|
||||
* @return array(int)
|
||||
* @see __constructor()
|
||||
*/
|
||||
public final function register()
|
||||
{
|
||||
if ($this->_listenOutside === false) {
|
||||
return $this->_scopeTokens;
|
||||
} else {
|
||||
return array_merge($this->_scopeTokens, $this->_tokens);
|
||||
}
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens that this test is listening for.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param int $stackPtr The position in the stack where this
|
||||
* token was found.
|
||||
*
|
||||
* @return void
|
||||
* @see processTokenWithinScope()
|
||||
*/
|
||||
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if (in_array($tokens[$stackPtr]['code'], $this->_scopeTokens) === true) {
|
||||
$this->currScope = $stackPtr;
|
||||
$phpcsFile->addTokenListener($this, $this->_tokens);
|
||||
} else if ($this->currScope !== null && isset($tokens[$this->currScope]['scope_closer']) === true && $stackPtr > $tokens[$this->currScope]['scope_closer']) {
|
||||
$this->currScope = null;
|
||||
if ($this->_listenOutside === true) {
|
||||
// This is a token outside the current scope, so notify the
|
||||
// extender as they wish to know about this.
|
||||
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
|
||||
} else {
|
||||
// Don't remove the listener if the extender wants to know about
|
||||
// tokens that live outside the current scope.
|
||||
$phpcsFile->removeTokenListener($this, $this->_tokens);
|
||||
}
|
||||
} else if ($this->currScope !== null) {
|
||||
$this->processTokenWithinScope($phpcsFile, $stackPtr, $this->currScope);
|
||||
} else {
|
||||
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Processes a token that is found within the scope that this test is
|
||||
* listening to.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param int $stackPtr The position in the stack where this
|
||||
* token was found.
|
||||
* @param int $currScope The position in the tokens array that
|
||||
* opened the scope that this test is
|
||||
* listening for.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected abstract function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope);
|
||||
|
||||
|
||||
/**
|
||||
* Processes a token that is found within the scope that this test is
|
||||
* listening to.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
|
||||
* @param int $stackPtr The position in the stack where this
|
||||
* token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
return;
|
||||
|
||||
}//end processTokenOutsideScope()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,217 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to find T_VARIABLE tokens.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
|
||||
$error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to find T_VARIABLE tokens.
|
||||
*
|
||||
* This class can distingush between normal T_VARIABLE tokens, and those tokens
|
||||
* that represent class members. If a class member is encountered, then then
|
||||
* processMemberVar method is called so the extending class can process it. If
|
||||
* the token is found to be a normal T_VARIABLE token, then processVariable is
|
||||
* called.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
abstract class PHP_CodeSniffer_Standards_AbstractVariableSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
|
||||
{
|
||||
|
||||
/**
|
||||
* The end token of the current function that we are in.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_endFunction = -1;
|
||||
|
||||
/**
|
||||
* true if a function is currently open.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_functionOpen = false;
|
||||
|
||||
/**
|
||||
* The current PHP_CodeSniffer file that we are processing.
|
||||
*
|
||||
* @var PHP_CodeSniffer_File
|
||||
*/
|
||||
protected $currentFile = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an AbstractVariableTest.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$listen = array(
|
||||
T_CLASS,
|
||||
T_INTERFACE,
|
||||
);
|
||||
|
||||
$scopes = array(
|
||||
T_FUNCTION,
|
||||
T_VARIABLE,
|
||||
T_DOUBLE_QUOTED_STRING,
|
||||
);
|
||||
|
||||
parent::__construct($listen, $scopes, true);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the token in the specified PHP_CodeSniffer_File.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
|
||||
* token was found.
|
||||
* @param int $stackPtr The position where the token was found.
|
||||
* @param array $currScope The current scope opener token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected final function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
|
||||
{
|
||||
if ($this->currentFile !== $phpcsFile) {
|
||||
$this->currentFile = $phpcsFile;
|
||||
$this->_functionOpen = false;
|
||||
$this->_endFunction = -1;
|
||||
}
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
if ($stackPtr > $this->_endFunction) {
|
||||
$this->_functionOpen = false;
|
||||
}
|
||||
|
||||
if ($tokens[$stackPtr]['code'] === T_FUNCTION && $this->_functionOpen === false) {
|
||||
|
||||
$this->_functionOpen = true;
|
||||
|
||||
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
|
||||
|
||||
// If the function is abstract, or is in an interface,
|
||||
// then set the end of the function to it's closing semicolon.
|
||||
if ($methodProps['is_abstract'] === true || $tokens[$currScope]['code'] === T_INTERFACE) {
|
||||
$this->_endFunction = $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr);
|
||||
} else {
|
||||
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
|
||||
$error = 'Possible parse error: non-abstract method defined as abstract';
|
||||
$phpcsFile->addWarning($error, $stackPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_endFunction = $tokens[$stackPtr]['scope_closer'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($this->_functionOpen === true) {
|
||||
if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
|
||||
$this->processVariable($phpcsFile, $stackPtr);
|
||||
} else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING) {
|
||||
// Check to see if this string has a variable in it.
|
||||
$pattern = '|[^\\\]\$[a-zA-Z0-9_]+|';
|
||||
if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
|
||||
$this->processVariableInString($phpcsFile, $stackPtr);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
// What if we assign a member variable to another?
|
||||
// ie. private $_count = $this->_otherCount + 1;.
|
||||
$this->processMemberVar($phpcsFile, $stackPtr);
|
||||
}
|
||||
|
||||
}//end processTokenWithinScope()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the token outside the scope in the file.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
|
||||
* token was found.
|
||||
* @param int $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected final function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
// These variables are not member vars.
|
||||
if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
|
||||
$this->processVariable($phpcsFile, $stackPtr);
|
||||
} else {
|
||||
$this->processVariableInString($phpcsFile, $stackPtr);
|
||||
}
|
||||
|
||||
}//end processTokenOutsideScope()
|
||||
|
||||
|
||||
/**
|
||||
* Called to process class member vars.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
|
||||
* token was found.
|
||||
* @param int $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
|
||||
|
||||
|
||||
/**
|
||||
* Called to process normal member vars.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
|
||||
* token was found.
|
||||
* @param int $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
|
||||
|
||||
|
||||
/**
|
||||
* Called to process variables found in duoble quoted strings.
|
||||
*
|
||||
* Note that there may be more than one variable in the string, which will
|
||||
* result only in one call for the string.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
|
||||
* token was found.
|
||||
* @param int $stackPtr The position where the double quoted
|
||||
* string was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Bass Coding Standard class.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Coding Standard class.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_Standards_CodingStandard
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of external sniffs to include with this standard.
|
||||
*
|
||||
* External locations can be single sniffs, a whole directory of sniffs, or
|
||||
* an entire coding standard. Locations start with the standard name. For
|
||||
* example:
|
||||
* PEAR => include all sniffs in this standard
|
||||
* PEAR/Sniffs/Files => include all sniffs in this dir
|
||||
* PEAR/Sniffs/Files/LineLengthSniff => include this single sniff
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIncludedSniffs()
|
||||
{
|
||||
return array();
|
||||
|
||||
}//end getIncludedSniffs()
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of external sniffs to exclude from this standard.
|
||||
*
|
||||
* External locations can be single sniffs, a whole directory of sniffs, or
|
||||
* an entire coding standard. Locations start with the standard name. For
|
||||
* example:
|
||||
* PEAR => exclude all sniffs in this standard
|
||||
* PEAR/Sniffs/Files => exclude all sniffs in this dir
|
||||
* PEAR/Sniffs/Files/LineLengthSniff => exclude this single sniff
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExcludedSniffs()
|
||||
{
|
||||
return array();
|
||||
|
||||
}//end getExcludedSniffs()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* An exception thrown if the pattern being processed is not supposed to be
|
||||
* validating the code in question.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* An exception thrown if the pattern being processed is not supposed to be
|
||||
* validating the code in question.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @author Marc McIntyre <mmcintyre@squiz.net>
|
||||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
||||
* @version Release: 1.1.0
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class PHP_CodeSniffer_Standards_IncorrectPatternException extends Exception
|
||||
{
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,54 +0,0 @@
|
||||
<?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/>.
|
||||
/**
|
||||
* Subclass of lib/pear/PHP/CodeSniffer/CLI.php
|
||||
*
|
||||
* Simple modifications to the CLI class to only use the Moodle Standard
|
||||
*
|
||||
* @package lib-pear-php-codesniffer-standards-moodle
|
||||
* @copyright 2008 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) {
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Moodle Coding Standard.
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class php_codesniffer_standards_moodle_moodlecodingstandard extends php_codesniffer_standards_codingstandard {
|
||||
/**
|
||||
* To include additional sniffs in this standard, add their paths to this method's return array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getincludedsniffs() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* To exclude included sniffs from this standard, add their paths to this method's return array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getexcludedsniffs() {
|
||||
return array('Moodle/Sniffs/CodeAnalysis');
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
<?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/>.
|
||||
/**
|
||||
* File containing the Class Declaration Test.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-classes
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Declaration Test.
|
||||
*
|
||||
* Checks the declaration of the class is correct.
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_sniffs_classes_classdeclarationsniff implements php_codesniffer_sniff {
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register() {
|
||||
return array(T_CLASS, T_INTERFACE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
|
||||
* @param int $stackptr The position of the current token in the
|
||||
* stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
|
||||
$tokens = $phpcsfile->gettokens();
|
||||
|
||||
if (isset($tokens[$stackptr]['scope_opener']) === false) {
|
||||
$error = 'possible parse error: ';
|
||||
$error .= $tokens[$stackptr]['content'];
|
||||
$error .= ' missing opening or closing brace';
|
||||
$phpcsfile->addwarning($error, $stackptr);
|
||||
return;
|
||||
}
|
||||
|
||||
$curlybrace = $tokens[$stackptr]['scope_opener'];
|
||||
$lastcontent = $phpcsfile->findprevious(T_WHITESPACE, ($curlybrace - 1), $stackptr, true);
|
||||
$classline = $tokens[$lastcontent]['line'];
|
||||
$braceline = $tokens[$curlybrace]['line'];
|
||||
|
||||
if ($braceline != $classline) {
|
||||
$error = 'Opening brace of a ';
|
||||
$error .= $tokens[$stackptr]['content'];
|
||||
$error .= ' must be on the same line as the definition';
|
||||
$phpcsfile->adderror($error, $curlybrace);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($tokens[($curlybrace - 1)]['code'] === T_WHITESPACE) {
|
||||
$prevcontent = $tokens[($curlybrace - 1)]['content'];
|
||||
|
||||
if ($prevcontent !== $phpcsfile->eolChar) {
|
||||
$blankspace = substr($prevcontent, strpos($prevcontent, $phpcsfile->eolChar));
|
||||
$spaces = strlen($blankspace);
|
||||
|
||||
if ($spaces !== 1) {
|
||||
$error = "Expected 1 space before opening brace; $spaces found";
|
||||
$phpcsfile->adderror($error, $curlybrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
<?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/>.
|
||||
/**
|
||||
* File containing the moodle_sniffs_codeanalysis_emptystatementsniff Class
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* This sniff class detected empty statement.
|
||||
*
|
||||
* This sniff implements the common algorithm for empty statement body detection.
|
||||
* A body is considered as empty if it is completely empty or it only contains
|
||||
* whitespace characters and|or comments.
|
||||
*
|
||||
* <code>
|
||||
* stmt {
|
||||
* // foo
|
||||
* }
|
||||
* stmt (conditions) {
|
||||
* // foo
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* Statements covered by this sniff are <b>catch</b>, <b>do</b>, <b>else</b>,
|
||||
* <b>elsif</b>, <b>for</b>, <b>foreach<b>, <b>if</b>, <b>switch</b>, <b>try</b>
|
||||
* and <b>while</b>.
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_sniffs_codeanalysis_emptystatementsniff implements php_codesniffer_sniff {
|
||||
|
||||
/**
|
||||
* List of block tokens that this sniff covers.
|
||||
*
|
||||
* The key of this hash identifies the required token while the boolean
|
||||
* value says mark an error or mark a warning.
|
||||
*
|
||||
* @type array<boolean>
|
||||
* @var array(integer=>boolean) $_tokens
|
||||
*/
|
||||
private $_tokens = array(
|
||||
T_CATCH => true,
|
||||
T_DO => false,
|
||||
T_ELSE => false,
|
||||
T_ELSEIF => false,
|
||||
T_FOR => false,
|
||||
T_FOREACH => false,
|
||||
T_IF => false,
|
||||
T_SWITCH => false,
|
||||
T_TRY => false,
|
||||
T_WHILE => false,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*
|
||||
* @return array(integer)
|
||||
*/
|
||||
public function register() {
|
||||
return array_keys($this->_tokens);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
|
||||
* @param int $stackptr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
|
||||
$tokens = $phpcsfile->gettokens();
|
||||
$token = $tokens[$stackptr];
|
||||
|
||||
// Skip for-statements without body.
|
||||
if (isset($token['scope_opener']) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$next = ++$token['scope_opener'];
|
||||
$end = --$token['scope_closer'];
|
||||
|
||||
$emptybody = true;
|
||||
|
||||
for (; $next <= $end; ++$next) {
|
||||
|
||||
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_tokens::$emptyTokens) === false) {
|
||||
$emptybody = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($emptybody === true) {
|
||||
// Get token identifier.
|
||||
$name = $phpcsfile->gettokensAsString($stackptr, 1);
|
||||
$error = sprintf('Empty %s statement detected', strtoupper($name));
|
||||
|
||||
if ($this->_tokens[$token['code']] === true) {
|
||||
$phpcsfile->adderror($error, $stackptr);
|
||||
|
||||
} else {
|
||||
$phpcsfile->addwarning($error, $stackptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
<?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 is part of the CodeAnalysis addon for PHP_CodeSniffer.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Detects for-loops that can be simplified to a while-loop.
|
||||
*
|
||||
* This rule is based on the PMD rule catalog. Detects for-loops that can be
|
||||
* simplified as a while-loop.
|
||||
*
|
||||
* <code>
|
||||
* class Foo
|
||||
* {
|
||||
* public function bar($x)
|
||||
* {
|
||||
* for (;true;) true; // No Init or Update part, may as well be: while (true)
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_sniffs_codeanalysis_forloopshouldbewhileloopsniff implements php_codesniffer_sniff {
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*
|
||||
* @return array(integer)
|
||||
*/
|
||||
public function register() {
|
||||
return array(T_FOR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
|
||||
* @param int $stackptr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
|
||||
$tokens = $phpcsfile->gettokens();
|
||||
$token = $tokens[$stackptr];
|
||||
|
||||
// Skip invalid statement.
|
||||
if (isset($token['parenthesis_opener']) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$next = ++$token['parenthesis_opener'];
|
||||
$end = --$token['parenthesis_closer'];
|
||||
|
||||
$parts = array(0, 0, 0);
|
||||
$index = 0;
|
||||
|
||||
for (; $next <= $end; ++$next) {
|
||||
$code = $tokens[$next]['code'];
|
||||
|
||||
if ($code === T_SEMICOLON) {
|
||||
++$index;
|
||||
|
||||
} else if (in_array($code, PHP_CodeSniffer_tokens::$emptyTokens) === false) {
|
||||
++$parts[$index];
|
||||
}
|
||||
}
|
||||
|
||||
if ($parts[0] === 0 && $parts[2] === 0 && $parts[1] > 0) {
|
||||
$error = 'This FOR loop can be simplified to a WHILE loop';
|
||||
$phpcsfile->addwarning($error, $stackptr);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
<?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 is part of the CodeAnalysis addon for PHP_CodeSniffer.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Detects for-loops that use a function call in the test expression.
|
||||
*
|
||||
* This rule is based on the PMD rule catalog. Detects for-loops that use a
|
||||
* function call in the test expression.
|
||||
*
|
||||
* <code>
|
||||
* class Foo
|
||||
* {
|
||||
* public function bar($x)
|
||||
* {
|
||||
* $a = array(1, 2, 3, 4);
|
||||
* for ($i = 0; $i < count($a); $i++) {
|
||||
* $a[$i] *= $i;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_sniffs_codeanalysis_forloopwithtestfunctioncallsniff implements php_codesniffer_sniff {
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*
|
||||
* @return array(integer)
|
||||
*/
|
||||
public function register() {
|
||||
return array(T_FOR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
|
||||
* @param int $stackptr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
|
||||
$tokens = $phpcsfile->gettokens();
|
||||
$token = $tokens[$stackptr];
|
||||
|
||||
// Skip invalid statement.
|
||||
if (isset($token['parenthesis_opener']) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$next = ++$token['parenthesis_opener'];
|
||||
$end = --$token['parenthesis_closer'];
|
||||
|
||||
$position = 0;
|
||||
|
||||
for (; $next <= $end; ++$next) {
|
||||
$code = $tokens[$next]['code'];
|
||||
|
||||
if ($code === T_SEMICOLON) {
|
||||
++$position;
|
||||
}
|
||||
|
||||
if ($position < 1) {
|
||||
continue;
|
||||
|
||||
} else if ($position > 1) {
|
||||
break;
|
||||
|
||||
} else if ($code !== T_VARIABLE && $code !== T_STRING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find next non empty token, if it is a open curly brace we have a
|
||||
// function call.
|
||||
$index = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($next + 1), null, true);
|
||||
|
||||
if ($tokens[$index]['code'] === T_OPEN_PARENTHESIS) {
|
||||
$error = 'Avoid function calls in a FOR loop test part';
|
||||
$phpcsfile->addwarning($error, $stackptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
<?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 is part of the CodeAnalysis addon for PHP_CodeSniffer.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Detects incrementer jumbling in for loops.
|
||||
*
|
||||
* This rule is based on the PMD rule catalog. The jumbling incrementer sniff
|
||||
* detects the usage of one and the same incrementer into an outer and an inner
|
||||
* loop. Even it is intended this is confusing code.
|
||||
*
|
||||
* <code>
|
||||
* class Foo
|
||||
* {
|
||||
* public function bar($x)
|
||||
* {
|
||||
* for ($i = 0; $i < 10; $i++)
|
||||
* {
|
||||
* for ($k = 0; $k < 20; $i++)
|
||||
* {
|
||||
* echo 'Hello';
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_sniffs_codeanalysis_jumbledincrementersniff implements php_codesniffer_sniff {
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*
|
||||
* @return array(integer)
|
||||
*/
|
||||
public function register() {
|
||||
return array(T_FOR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
|
||||
* @param int $stackptr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
|
||||
$tokens = $phpcsfile->gettokens();
|
||||
$token = $tokens[$stackptr];
|
||||
|
||||
// Skip for-loop without body.
|
||||
if (isset($token['scope_opener']) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find incrementors for outer loop.
|
||||
$outer = $this->findincrementers($tokens, $token);
|
||||
|
||||
// Skip if empty.
|
||||
if (count($outer) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find nested for loops.
|
||||
$start = ++$token['scope_opener'];
|
||||
$end = --$token['scope_closer'];
|
||||
|
||||
for (; $start <= $end; ++$start) {
|
||||
|
||||
if ($tokens[$start]['code'] !== T_FOR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$inner = $this->findincrementers($tokens, $tokens[$start]);
|
||||
$diff = array_intersect($outer, $inner);
|
||||
|
||||
if (count($diff) !== 0) {
|
||||
$error = sprintf('Loop incrementor (%s) jumbling with inner loop', join(', ', $diff));
|
||||
$phpcsfile->addwarning($error, $stackptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all used variables in the incrementer part of a for statement.
|
||||
*
|
||||
* @param array(integer=>array) $tokens Array with all code sniffer tokens.
|
||||
* @param array(string=>mixed) $token Current for loop token
|
||||
*
|
||||
* @return array(string) List of all found incrementer variables.
|
||||
*/
|
||||
protected function findincrementers(array $tokens, array $token) {
|
||||
// Skip invalid statement.
|
||||
if (isset($token['parenthesis_opener']) === false) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$start = ++$token['parenthesis_opener'];
|
||||
$end = --$token['parenthesis_closer'];
|
||||
|
||||
$incrementers = array();
|
||||
$semicolons = 0;
|
||||
|
||||
for ($next = $start; $next <= $end; ++$next) {
|
||||
$code = $tokens[$next]['code'];
|
||||
|
||||
if ($code === T_SEMICOLON) {
|
||||
++$semicolons;
|
||||
|
||||
} else if ($semicolons === 2 && $code === T_VARIABLE) {
|
||||
$incrementers[] = $tokens[$next]['content'];
|
||||
}
|
||||
}
|
||||
|
||||
return $incrementers;
|
||||
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
<?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 is part of the CodeAnalysis addon for PHP_CodeSniffer.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Detects unconditional if- and elseif-statements.
|
||||
*
|
||||
* This rule is based on the PMD rule catalog. The Unconditional If Statment
|
||||
* sniff detects statement conditions that are only set to one of the constant
|
||||
* values <b>true</b> or <b>false</b>
|
||||
*
|
||||
* <code>
|
||||
* class Foo
|
||||
* {
|
||||
* public function close()
|
||||
* {
|
||||
* if (true)
|
||||
* {
|
||||
* // ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_sniffs_codeanalysis_unconditionalifstatementsniff implements php_codesniffer_sniff {
|
||||
|
||||
|
||||
/**
|
||||
* Registers the tokens that this sniff wants to listen for.
|
||||
*
|
||||
* @return array(integer)
|
||||
*/
|
||||
public function register() {
|
||||
return array(T_IF, T_ELSEIF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
|
||||
* @param int $stackptr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
|
||||
$tokens = $phpcsfile->gettokens();
|
||||
$token = $tokens[$stackptr];
|
||||
|
||||
// Skip for-loop without body.
|
||||
if (isset($token['parenthesis_opener']) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$next = ++$token['parenthesis_opener'];
|
||||
$end = --$token['parenthesis_closer'];
|
||||
|
||||
$goodcondition = false;
|
||||
|
||||
for (; $next <= $end; ++$next) {
|
||||
$code = $tokens[$next]['code'];
|
||||
|
||||
if (in_array($code, PHP_CodeSniffer_tokens::$emptyTokens) === true) {
|
||||
continue;
|
||||
|
||||
} else if ($code !== T_TRUE && $code !== T_FALSE) {
|
||||
$goodcondition = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($goodcondition === false) {
|
||||
$error = 'Avoid IF statements that are always true or false';
|
||||
$phpcsfile->addwarning($error, $stackptr);
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user