function doc_link($path='', $text='', $iconpath='') {
global $CFG, $OUTPUT;
- // debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->action_icon().');
+ // debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
if (empty($CFG->docroot)) {
return '';
}
/** Close the current browser window. */
-function close_window() {
- window.close();
+function close_window(e) {
+ YAHOO.util.Event.preventDefault(e);
+ self.close();
}
/**
* @var string $style value to use for the style attribute of this HTML tag.
*/
public $style = '';
- /**
- * @var mixed $label The label for that component. String or html_label object
- */
- public $label;
/**
* @var array class names to add to this HTML element.
*/
return $this->actions;
}
+ /**
+ * Shortcut for adding a JS confirm dialog when the component is clicked.
+ * The message must be a yes/no question.
+ * @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur.
+ * @return void
+ */
+ public function add_confirm_action($message) {
+ $this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message)));
+ }
+}
+
+class labelled_html_component extends moodle_html_component {
+ /**
+ * @var mixed $label The label for that component. String or html_label object
+ */
+ public $label;
+
/**
* Adds a descriptive label to the component.
*
$this->label->text = $text;
}
}
-
- /**
- * Shortcut for adding a JS confirm dialog when the component is clicked.
- * The message must be a yes/no question.
- * @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur.
- * @return void
- */
- public function add_confirm_action($message) {
- $this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message)));
- }
}
/// Components representing HTML elements
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class html_select extends moodle_html_component {
+class html_select extends labelled_html_component {
/**
* The html_select object parses an array of options into component objects
* @see nested attribute
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class html_select_option extends moodle_html_component {
+class html_select_option extends labelled_html_component {
/**
* @var string $value The value of this option (will be sent with form)
*/
* @param string $alt
* @return html_select_option A component ready for $OUTPUT->checkbox()
*/
- public function make_checkbox($value, $checked, $label='', $alt='') {
+ public function make_checkbox($value, $checked, $label, $alt='') {
$checkbox = new html_select_option();
$checkbox->value = $value;
$checkbox->selected = $checked;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class html_field extends moodle_html_component {
+class html_field extends labelled_html_component {
/**
* @var string $name The name attribute of the field
*/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class html_table extends moodle_html_component {
+class html_table extends labelled_html_component {
/**
* @var array of headings. The n-th array item is used as a heading of the n-th column.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class html_button extends moodle_html_component {
+class html_button extends labelled_html_component {
/**
* @var string $text
*/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class html_image extends moodle_html_component {
+class html_image extends labelled_html_component {
/**
* @var string $alt A descriptive text
*/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class moodle_help_icon extends moodle_html_component {
+class moodle_help_icon extends labelled_html_component {
/**
* @var html_link $link A html_link object that will hold the URL info
*/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
-class moodle_action_icon extends moodle_html_component {
+class moodle_action_icon extends labelled_html_component {
/**
* @var string $linktext Optional text to display next to the icon
*/
public function prepare() {
$this->image->add_class('action-icon');
+ if (!empty($this->actions)) {
+ foreach ($this->actions as $action) {
+ $this->link->add_action($action);
+ }
+ unset($this->actions);
+ }
+
parent::prepare();
if (empty($this->image->src)) {
require_once($CFG->libdir.'/outputcomponents.php');
require_once($CFG->libdir.'/outputactions.php');
require_once($CFG->libdir.'/outputfactories.php');
-require_once($CFG->libdir.'/outputpixfinders.php');
require_once($CFG->libdir.'/outputrenderers.php');
/**
}
}
+/**
+ * An icon finder is responsible for working out the correct URL for an icon.
+ *
+ * A icon finder must also have a constructor that takes a theme object.
+ * (See {@link standard_icon_finder::__construct} for an example.)
+ *
+ * Note that we are planning to change the Moodle icon naming convention before
+ * the Moodle 2.0 release. Therefore, this API will probably change.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+interface icon_finder {
+ /**
+ * Return the URL for an icon identified as in pre-Moodle 2.0 code.
+ *
+ * Suppose you have old code like $url = "$CFG->pixpath/i/course.gif";
+ * then old_icon_url('i/course'); will return the equivalent URL that is correct now.
+ *
+ * @param string $iconname the name of the icon.
+ * @return string the URL for that icon.
+ */
+ public function old_icon_url($iconname);
+
+ /**
+ * Return the URL for an icon identified as in pre-Moodle 2.0 code.
+ *
+ * Suppose you have old code like $url = "$CFG->modpixpath/$mod/icon.gif";
+ * then mod_icon_url('icon', $mod); will return the equivalent URL that is correct now.
+ *
+ * @param string $iconname the name of the icon.
+ * @param string $module the module the icon belongs to.
+ * @return string the URL for that icon.
+ */
+ public function mod_icon_url($iconname, $module);
+}
+
+/**
+ * This icon finder implements the old scheme that was used when themes that had
+ * $THEME->custompix = false.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class pix_icon_finder implements icon_finder {
+ /**
+ * Constructor
+ * @param theme_config $theme the theme we are finding icons for (which is irrelevant).
+ */
+ public function __construct($theme) {
+ }
+
+ /**
+ * Implement interface method.
+ * @param string $iconname the name of the icon.
+ * @return string the URL for that icon.
+ */
+ public function old_icon_url($iconname) {
+ global $CFG;
+ if (file_exists($CFG->dirroot . '/pix/' . $iconname . '.png')) {
+ return $CFG->httpswwwroot . '/pix/' . $iconname . '.png';
+ } else {
+ return $CFG->httpswwwroot . '/pix/' . $iconname . '.gif';
+ }
+ }
+
+ /**
+ * Implement interface method.
+ * @param string $iconname the name of the icon.
+ * @param string $module the module the icon belongs to.
+ * @return string the URL for that icon.
+ */
+ public function mod_icon_url($iconname, $module) {
+ global $CFG;
+ if (file_exists($CFG->dirroot . '/mod/' . $module . '/' . $iconname . '.png')) {
+ return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.png';
+ } else {
+ return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.gif';
+ }
+ }
+}
+
+
+/**
+ * This icon finder implements the old scheme that was used for themes that had
+ * $THEME->custompix = true.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class theme_icon_finder implements icon_finder {
+ protected $themename;
+ /**
+ * Constructor
+ * @param theme_config $theme the theme we are finding icons for.
+ */
+ public function __construct($theme) {
+ $this->themename = $theme->name;
+ }
+
+ /**
+ * Implement interface method.
+ * @param string $iconname the name of the icon.
+ * @return string the URL for that icon.
+ */
+ public function old_icon_url($iconname) {
+ global $CFG;
+ if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/' . $iconname . '.png')) {
+ return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.png';
+ } else {
+ return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.gif';
+ }
+ }
+
+ /**
+ * Implement interface method.
+ * @param string $iconname the name of the icon.
+ * @param string $module the module the icon belongs to.
+ * @return string the URL for that icon.
+ */
+ public function mod_icon_url($iconname, $module) {
+ global $CFG;
+ if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png')) {
+ return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png';
+ } else {
+ return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.gif';
+ }
+ }
+}
+
+
+/**
+ * This icon finder implements the algorithm in pix/smartpix.php.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class smartpix_icon_finder extends pix_icon_finder {
+ protected $places = array();
+
+ /**
+ * Constructor
+ * @param theme_config $theme the theme we are finding icons for.
+ */
+ public function __construct($theme) {
+ global $CFG;
+ $this->places[$CFG->themedir . '/' . $theme->name . '/pix/'] =
+ $CFG->httpsthemewww . '/' . $theme->name . '/pix/';
+ if (!empty($theme->parent)) {
+ $this->places[$CFG->themedir . '/' . $theme->parent . '/pix/'] =
+ $CFG->httpsthemewww . '/' . $theme->parent . '/pix/';
+ }
+ }
+
+ /**
+ * Implement interface method.
+ * @param string $iconname the name of the icon.
+ * @return string the URL for that icon.
+ */
+ public function old_icon_url($iconname) {
+ foreach ($this->places as $dirroot => $urlroot) {
+ if (file_exists($dirroot . $iconname . '.png')) {
+ return $dirroot . $iconname . '.png';
+ } else if (file_exists($dirroot . $iconname . '.gif')) {
+ return $dirroot . $iconname . '.gif';
+ }
+ }
+ return parent::old_icon_url($iconname);
+ }
+
+ /**
+ * Implement interface method.
+ * @param string $iconname the name of the icon.
+ * @param string $module the module the icon belongs to.
+ * @return string the URL for that icon.
+ */
+ public function mod_icon_url($iconname, $module) {
+ foreach ($this->places as $dirroot => $urlroot) {
+ if (file_exists($dirroot . 'mod/' . $iconname . '.png')) {
+ return $dirroot . 'mod/' . $iconname . '.png';
+ } else if (file_exists($dirroot . 'mod/' . $iconname . '.gif')) {
+ return $dirroot . 'mod/' . $iconname . '.gif';
+ }
+ }
+ return parent::old_icon_url($iconname, $module);
+ }
+}
+
/**
* Output CSS while replacing constants/variables. See MDL-6798 for details
+++ /dev/null
-<?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/>.
-
-/**
- * Interface and classes for icon finders.
- *
- * Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
- * for an overview.
- *
- * @package moodlecore
- * @copyright 2009 Tim Hunt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-/**
- * An icon finder is responsible for working out the correct URL for an icon.
- *
- * A icon finder must also have a constructor that takes a theme object.
- * (See {@link standard_icon_finder::__construct} for an example.)
- *
- * Note that we are planning to change the Moodle icon naming convention before
- * the Moodle 2.0 release. Therefore, this API will probably change.
- *
- * @copyright 2009 Tim Hunt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
- */
-interface icon_finder {
- /**
- * Return the URL for an icon identified as in pre-Moodle 2.0 code.
- *
- * Suppose you have old code like $url = "$CFG->pixpath/i/course.gif";
- * then old_icon_url('i/course'); will return the equivalent URL that is correct now.
- *
- * @param string $iconname the name of the icon.
- * @return string the URL for that icon.
- */
- public function old_icon_url($iconname);
-
- /**
- * Return the URL for an icon identified as in pre-Moodle 2.0 code.
- *
- * Suppose you have old code like $url = "$CFG->modpixpath/$mod/icon.gif";
- * then mod_icon_url('icon', $mod); will return the equivalent URL that is correct now.
- *
- * @param string $iconname the name of the icon.
- * @param string $module the module the icon belongs to.
- * @return string the URL for that icon.
- */
- public function mod_icon_url($iconname, $module);
-}
-
-/**
- * This icon finder implements the old scheme that was used when themes that had
- * $THEME->custompix = false.
- *
- * @copyright 2009 Tim Hunt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
- */
-class pix_icon_finder implements icon_finder {
- /**
- * Constructor
- * @param theme_config $theme the theme we are finding icons for (which is irrelevant).
- */
- public function __construct($theme) {
- }
-
- /**
- * Implement interface method.
- * @param string $iconname the name of the icon.
- * @return string the URL for that icon.
- */
- public function old_icon_url($iconname) {
- global $CFG;
- if (file_exists($CFG->dirroot . '/pix/' . $iconname . '.png')) {
- return $CFG->httpswwwroot . '/pix/' . $iconname . '.png';
- } else {
- return $CFG->httpswwwroot . '/pix/' . $iconname . '.gif';
- }
- }
-
- /**
- * Implement interface method.
- * @param string $iconname the name of the icon.
- * @param string $module the module the icon belongs to.
- * @return string the URL for that icon.
- */
- public function mod_icon_url($iconname, $module) {
- global $CFG;
- if (file_exists($CFG->dirroot . '/mod/' . $module . '/' . $iconname . '.png')) {
- return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.png';
- } else {
- return $CFG->httpswwwroot . '/mod/' . $module . '/' . $iconname . '.gif';
- }
- }
-}
-
-
-/**
- * This icon finder implements the old scheme that was used for themes that had
- * $THEME->custompix = true.
- *
- * @copyright 2009 Tim Hunt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
- */
-class theme_icon_finder implements icon_finder {
- protected $themename;
- /**
- * Constructor
- * @param theme_config $theme the theme we are finding icons for.
- */
- public function __construct($theme) {
- $this->themename = $theme->name;
- }
-
- /**
- * Implement interface method.
- * @param string $iconname the name of the icon.
- * @return string the URL for that icon.
- */
- public function old_icon_url($iconname) {
- global $CFG;
- if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/' . $iconname . '.png')) {
- return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.png';
- } else {
- return $CFG->httpsthemewww . '/' . $this->themename . '/pix/' . $iconname . '.gif';
- }
- }
-
- /**
- * Implement interface method.
- * @param string $iconname the name of the icon.
- * @param string $module the module the icon belongs to.
- * @return string the URL for that icon.
- */
- public function mod_icon_url($iconname, $module) {
- global $CFG;
- if (file_exists($CFG->themedir . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png')) {
- return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.png';
- } else {
- return $CFG->httpsthemewww . '/' . $this->themename . '/pix/mod/' . $module . '/' . $iconname . '.gif';
- }
- }
-}
-
-
-/**
- * This icon finder implements the algorithm in pix/smartpix.php.
- *
- * @copyright 2009 Tim Hunt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.0
- */
-class smartpix_icon_finder extends pix_icon_finder {
- protected $places = array();
-
- /**
- * Constructor
- * @param theme_config $theme the theme we are finding icons for.
- */
- public function __construct($theme) {
- global $CFG;
- $this->places[$CFG->themedir . '/' . $theme->name . '/pix/'] =
- $CFG->httpsthemewww . '/' . $theme->name . '/pix/';
- if (!empty($theme->parent)) {
- $this->places[$CFG->themedir . '/' . $theme->parent . '/pix/'] =
- $CFG->httpsthemewww . '/' . $theme->parent . '/pix/';
- }
- }
-
- /**
- * Implement interface method.
- * @param string $iconname the name of the icon.
- * @return string the URL for that icon.
- */
- public function old_icon_url($iconname) {
- foreach ($this->places as $dirroot => $urlroot) {
- if (file_exists($dirroot . $iconname . '.png')) {
- return $dirroot . $iconname . '.png';
- } else if (file_exists($dirroot . $iconname . '.gif')) {
- return $dirroot . $iconname . '.gif';
- }
- }
- return parent::old_icon_url($iconname);
- }
-
- /**
- * Implement interface method.
- * @param string $iconname the name of the icon.
- * @param string $module the module the icon belongs to.
- * @return string the URL for that icon.
- */
- public function mod_icon_url($iconname, $module) {
- foreach ($this->places as $dirroot => $urlroot) {
- if (file_exists($dirroot . 'mod/' . $iconname . '.png')) {
- return $dirroot . 'mod/' . $iconname . '.png';
- } else if (file_exists($dirroot . 'mod/' . $iconname . '.gif')) {
- return $dirroot . 'mod/' . $iconname . '.gif';
- }
- }
- return parent::old_icon_url($iconname, $module);
- }
-}
-
-
// Removing the button so it doesn't get output again
unset($form->button);
- return $this->form($form, $buttonoutput);
+ return $this->output_tag('div', array('class' => 'singlebutton'), $this->form($form, $buttonoutput));
}
/**
'class' => $form->get_classes_string());
$divoutput = $this->output_tag('div', array(), $hiddenoutput . $contents . $buttonoutput);
- $formoutput = $this->output_tag('form', $formattributes, $divoutput);
- $output = $this->output_tag('div', array('class' => 'singlebutton'), $formoutput);
+ $output = $this->output_tag('form', $formattributes, $divoutput);
return $output;
}
* @param string $text The lang string for the button's label (already output from get_string())
* @return string|void if $return is true, void otherwise
*/
- public function close_window_button($text) {
+ public function close_window_button($text='') {
if (empty($text)) {
$text = get_string('closewindow');
}
$closeform = new html_form();
$closeform->url = '#';
+ $closeform->method = 'get';
$closeform->button->text = $text;
$closeform->button->add_action('click', 'close_window');
$closeform->button->prepare();
if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out(true), $matches)) {
return $matches[1] . "/$output";
+ } else if ($output == '') {
+ return $PAGE->url->out(false, array(), false) . '#';
} else {
throw new coding_exception('Your page uses bizarre relative URLs which Moodle cannot handle. Please use absolute URLs.');
}