cvsimport fixups

This commit is contained in:
Jonathan Newman
2009-01-20 23:53:34 +00:00
parent 2a02fa4abe
commit 4d933beb8a
27 changed files with 82 additions and 517 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ if ($mnet_peer->id != $CFG->mnet_all_hosts_id) {
print_tabs(array($tabs), 'mnetthemes');
$themes = get_list_of_plugins("theme");
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
$sesskey = sesskey();
echo '<table style="margin-left:auto;margin-right:auto;" cellpadding="7" cellspacing="5">';
+5 -5
View File
@@ -36,11 +36,11 @@ class page_admin extends page_base {
return;
}
$adminroot =& admin_get_root(false, false); //settings not required - only pages
$adminroot = admin_get_root(false, false); //settings not required - only pages
// fetch the path parameter
$this->section = $section;
$current =& $adminroot->locate($section, true);
$current = $adminroot->locate($section, true);
$this->visiblepathtosection = array_reverse($current->visiblepath);
// all done
@@ -69,10 +69,10 @@ class page_admin extends page_base {
return $this->url;
}
$adminroot =& admin_get_root(false, false); //settings not required - only pages
$adminroot = admin_get_root(false, false); //settings not required - only pages
$root =& $adminroot->locate($this->section);
if (is_a($root, 'admin_externalpage')) {
$root = $adminroot->locate($this->section);
if ($root instanceof admin_externalpage) {
return $root->url;
} else {
return ($CFG->wwwroot . '/' . $CFG->admin . '/settings.php');
+2 -2
View File
@@ -7,7 +7,7 @@ require_once($CFG->libdir.'/adminlib.php');
$query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string
$adminroot =& admin_get_root(); // need all settings here
$adminroot = admin_get_root(); // need all settings here
$adminroot->search = $query; // So we can reference it in search boxes later in this invocation
$statusmsg = '';
$errormsg = '';
@@ -20,7 +20,7 @@ if ($data = data_submitted() and confirm_sesskey()) {
if (admin_write_settings($data)) {
$statusmsg = get_string('changessaved');
}
$adminroot =& admin_get_root(true); //reload tree
$adminroot = admin_get_root(true); //reload tree
if (!empty($adminroot->errors)) {
$errormsg = get_string('errorwithsettings', 'admin');
+3 -3
View File
@@ -12,10 +12,10 @@ $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
/// no guest autologin
require_login(0, false);
$adminroot =& admin_get_root(); // need all settings
$page =& $adminroot->locate($section);
$adminroot = admin_get_root(); // need all settings
$page = $adminroot->locate($section);
if (empty($page) or !is_a($page, 'admin_settingpage')) {
if (empty($page) or !($page instanceof admin_settingpage)) {
print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
die;
}
+2 -2
View File
@@ -11,13 +11,13 @@ $return = optional_param('return', '', PARAM_ALPHA);
/// no guest autologin
require_login(0, false);
$adminroot =& admin_get_root(); // need all settings
$adminroot = admin_get_root(); // need all settings
admin_externalpage_setup('upgradesettings'); // now hidden page
// now we'll deal with the case that the admin has submitted the form with new settings
if ($data = data_submitted() and confirm_sesskey()) {
$count = admin_write_settings($data);
$adminroot =& admin_get_root(true); //reload tree
$adminroot = admin_get_root(true); //reload tree
}
$newsettings = admin_output_new_settings_by_page($adminroot);
@@ -40,7 +40,7 @@ class block_admin_bookmarks extends block_base {
if (get_user_preferences('admin_bookmarks')) {
// this is expensive! Only require when bookmakrs exist..
require_once($CFG->libdir.'/adminlib.php');
$adminroot =& admin_get_root(false, false); // settings not required - only pages
$adminroot = admin_get_root(false, false); // settings not required - only pages
$bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
// hmm... just a liiitle (potentially) processor-intensive
@@ -51,9 +51,9 @@ class block_admin_bookmarks extends block_base {
foreach($bookmarks as $bookmark) {
$temp = $adminroot->locate($bookmark);
if (is_a($temp, 'admin_settingpage')) {
if ($temp instanceof admin_settingpage) {
$this->content->text .= '<li><a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $bookmark . '">' . $temp->visiblename . "</a></li>\n";
} else if (is_a($temp, 'admin_externalpage')) {
} else if ($temp instanceof admin_externalpage) {
$this->content->text .= '<li><a href="' . $temp->url . '">' . $temp->visiblename . "</a></li>\n";
}
}
+4 -4
View File
@@ -4,7 +4,7 @@ require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_login();
$adminroot =& admin_get_root(false, false); // settings not required - only pages
$adminroot = admin_get_root(false, false); // settings not required - only pages
if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey()) {
@@ -22,7 +22,7 @@ if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey(
$temp = $adminroot->locate($section);
if (is_a($temp, 'admin_settingpage') || is_a($temp, 'admin_externalpage')) {
if ($temp instanceof admin_settingpage || $temp instanceof admin_externalpage) {
$bookmarks[] = $section;
$bookmarks = implode(',', $bookmarks);
set_user_preference('admin_bookmarks', $bookmarks);
@@ -32,10 +32,10 @@ if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey(
die;
}
if (is_a($temp, 'admin_settingpage')) {
if ($temp instanceof admin_settingpage) {
redirect($CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $section);
} elseif (is_a($temp, 'admin_externalpage')) {
} elseif ($temp instanceof admin_externalpage) {
redirect($temp->url);
}
+3 -3
View File
@@ -5,7 +5,7 @@ require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_login();
$adminroot =& admin_get_root(false, false); // settings not required - only pages
$adminroot = admin_get_root(false, false); // settings not required - only pages
if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey()) {
@@ -26,9 +26,9 @@ if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey(
$temp = $adminroot->locate($section);
if (is_a($temp, 'admin_externalpage')) {
if ($temp instanceof admin_externalpage) {
redirect($temp->url, get_string('bookmarkdeleted','admin'));
} elseif (is_a($temp, 'admin_settingpage')) {
} elseif ($temp instanceof admin_settingpage) {
redirect($CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $section);
} else {
redirect($CFG->wwwroot);
+4 -4
View File
@@ -57,7 +57,7 @@ class block_admin_tree extends block_base {
function build_tree (&$content) {
global $CFG;
if (is_a($content, 'admin_settingpage')) {
if ($content instanceof admin_settingpage) {
// show hidden pages in tree if hidden page active
if ($content->check_access() and (($content->name == $this->section) or !$content->is_hidden())) {
$class = ($content->name == $this->section) ? 'link current' : 'link';
@@ -66,7 +66,7 @@ class block_admin_tree extends block_base {
}
$this->create_item($content->visiblename, $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section='.$content->name,$CFG->pixpath.'/i/item.gif', $class);
}
} else if (is_a($content, 'admin_externalpage')) {
} else if ($content instanceof admin_externalpage) {
// show hidden pages in tree if hidden page active
if ($content->check_access() and (($content->name == $this->section) or !$content->is_hidden())) {
$class = ($content->name == $this->section) ? 'link current' : 'link';
@@ -80,7 +80,7 @@ class block_admin_tree extends block_base {
}
$this->create_item($content->visiblename, $content->url, $CFG->pixpath.'/i/item.gif', $class);
}
} else if (is_a($content, 'admin_category')) {
} else if ($content instanceof admin_category) {
if ($content->check_access() and !$content->is_hidden()) {
// check if the category we're currently printing is a parent category for the current page; if it is, we
@@ -117,7 +117,7 @@ class block_admin_tree extends block_base {
}
require_once($CFG->libdir.'/adminlib.php');
$adminroot =& admin_get_root(false, false); // settings not required - only pages
$adminroot = admin_get_root(false, false); // settings not required - only pages
if ($current = $adminroot->locate($this->section, true)) {
$this->pathtosection = $current->path;
+1 -1
View File
@@ -469,7 +469,7 @@ class block_base {
} else {
$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
}
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey));
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => sesskey()));
if (empty($this->instance->pinned)) {
$movebuttons .= '<a class="icon roles" title="'. $this->str->assignroles .'" href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">' .
+2 -2
View File
@@ -111,7 +111,7 @@
// This instance is configured - show Add/Edit feeds link.
$script = $page->url_get_full(
array('instanceid' => $this->instance->id,
'sesskey' => $USER->sesskey,
'sesskey' => sesskey(),
'blockaction' => 'config',
'currentaction' => 'managefeeds',
'id' => $this->courseid,
@@ -123,7 +123,7 @@
if (has_capability('block/rss_client:manageanyfeeds', $context)) {
$script = $page->url_get_full(
array('instanceid' => $this->instance->id,
'sesskey' => $USER->sesskey,
'sesskey' => sesskey(),
'blockaction' => 'config',
'currentaction' => 'configblock',
'id' => $this->courseid,
+1 -1
View File
@@ -104,7 +104,7 @@ print_box_start();
|| has_capability('block/rss_client:createsharedfeeds', $context)) {
$addrsspage = $page->url_get_full(array('instanceid' => $this->instance->id,
'sesskey' => $USER->sesskey,
'sesskey' => sesskey(),
'blockaction' => 'config',
'currentaction' => 'managefeeds',
'id' => $id));
+2 -2
View File
@@ -13,12 +13,12 @@ if (empty($this->instance->pinned)) {
}
if (has_capability('moodle/site:manageblocks', $context)) {
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $id, 'section' => 'rss'));
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $id, 'section' => 'rss'));
$row[] = new tabobject('configblock', $script,
get_string('configblock', 'block_rss_client'));
}
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id, 'section' => 'rss'));
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id, 'section' => 'rss'));
$row[] = new tabobject('managefeeds', $script,
get_string('managefeeds', 'block_rss_client'));
+1 -1
View File
@@ -423,7 +423,7 @@
unset($options);
$options['id'] = $category->id;
$options['resort'] = 'name';
$options['sesskey'] = $USER->sesskey;
$options['sesskey'] = sesskey();
print_single_button('category.php', $options, get_string('resortcoursesbyname'), 'get');
}
+1 -1
View File
@@ -41,7 +41,7 @@
notice_yesno("$strdeletecoursecheck<br /><br />" . format_string($course->fullname) .
" (" . format_string($course->shortname) . ")",
"delete.php?id=$course->id&amp;delete=".md5($course->timemodified)."&amp;sesskey=$USER->sesskey",
"delete.php?id=$course->id&amp;delete=".md5($course->timemodified)."&amp;sesskey=".sesskey(),
"category.php?id=$course->category");
print_footer($course);
+3 -3
View File
@@ -87,7 +87,7 @@
if ( !(isset($required[$h]) or
isset($optionalDefaults[$h]) or
isset($optional[$h])) ) {
print_error('invalidfieldname', 'error', 'index.php?id='.$id.'&amp;sesskey='.$USER->sesskey, $h);
print_error('invalidfieldname', 'error', 'index.php?id='.$id.'&amp;sesskey='.sesskey(), $h);
}
if ( isset($required[$h]) ) {
$required[$h] = 2;
@@ -96,7 +96,7 @@
// check for required fields
foreach ($required as $key => $value) {
if ($value < 2) {
print_error('fieldrequired', 'error', 'uploaduser.php?id='.$id.'&amp;sesskey='.$USER->sesskey, $key);
print_error('fieldrequired', 'error', 'uploaduser.php?id='.$id.'&amp;sesskey='.sesskey(), $key);
}
}
$linenum = 2; // since header is line 1
@@ -121,7 +121,7 @@
foreach ($record as $name => $value) {
// check for required values
if (isset($required[$name]) and !$value) {
print_error('missingfield', 'error', 'uploaduser.php?sesskey='.$USER->sesskey, $name);
print_error('missingfield', 'error', 'uploaduser.php?sesskey='.sesskey(), $name);
}
else if ($name == "groupname") {
$newgroup->name = $value;
+23
View File
@@ -29,6 +29,12 @@ class grade_import_form extends moodleform {
function definition (){
$mform =& $this->_form;
if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
$features = $this->_customdata;
} else {
$features = array();
}
// course id needs to be passed for auth purposes
$mform->addElement('hidden', 'id', optional_param('id'));
$mform->setType('id', PARAM_INT);
@@ -41,6 +47,19 @@ class grade_import_form extends moodleform {
$encodings = $textlib->get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
if (!empty($features['includeseparator'])) {
$radio = array();
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
$radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
$mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
$mform->setDefault('separator', 'comma');
}
if (!empty($features['verbosescales'])) {
$options = array(1=>get_string('yes'), 0=>get_string('no'));
$mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
}
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
$mform->setType('previewrows', PARAM_INT);
@@ -106,6 +125,10 @@ class grade_import_mapping_form extends moodleform {
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'importcode');
$mform->setType('importcode', PARAM_FILE);
$mform->addElement('hidden', 'verbosescales', 1);
$mform->setType('separator', PARAM_ALPHA);
$mform->addElement('hidden', 'separator', 'comma');
$mform->setType('verbosescales', PARAM_INT);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
+4 -1
View File
@@ -1,4 +1,7 @@
<?php
$string['notenoughsaincategory'] = 'There is/are only $a->nosaquestions short answer questions in the category that you chose \'$a->catname\'. Choose a different category, make some more questions in this category or reduce the amount of questions you\'ve selected.';
$string['addingrandomsamatch'] = 'Adding a Random short-answer matching question';
$string['editingrandomsamatch'] = 'Editing a Random short-answer matching question';
$string['nosaincategory'] = 'There are no short answer questions in the category that you chose \'$a->catname\'. Choose a different category, make some questions in this category.';
$string['notenoughsaincategory'] = 'There is/are only $a->nosaquestions short answer questions in the category that you chose \'$a->catname\'. Choose a different category, make some more questions in this category or reduce the amount of questions you\'ve selected.';
$string['randomsamatch'] = 'Random short-answer matching';
?>
+5 -2
View File
@@ -1,6 +1,9 @@
<?php
$string['addingshortanswer'] = 'Adding a short answer question';
$string['addmoreanswerblanks'] = 'Blanks for {no} More Answers';
$string['answerno'] = 'Answer $a';
$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the score and feedback.';
$string['answermustbegiven'] = 'You must enter an answer if there is a grade or feedback.';
$string['answerno'] = 'Answer $a';
$string['editingshortanswer'] = 'Editing a Short answer question';
$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the score and feedback.';
$string['shortanswer'] = 'Short answer';
?>
+1 -1
View File
@@ -118,7 +118,7 @@
// echo '<div class="feedback_centered_button">';
echo '<div class="form-buttons">';
$export_button_link = 'analysis_to_excel.php';
$export_button_options = array('sesskey'=>$USER->sesskey, 'id'=>$id);
$export_button_options = array('sesskey'=>sesskey(), 'id'=>$id);
$export_button_label = get_string('export_to_excel', 'feedback');
print_single_button($export_button_link, $export_button_options, $export_button_label, 'post');
echo '</div>';
+2 -2
View File
@@ -72,7 +72,7 @@
//button "export to excel"
echo '<div class="mdl-align">';
$export_button_link = 'analysis_to_excel.php';
$export_button_options = array('sesskey'=>$USER->sesskey, 'id'=>$id, 'coursefilter'=>$coursefilter);
$export_button_options = array('sesskey'=>sesskey(), 'id'=>$id, 'coursefilter'=>$coursefilter);
$export_button_label = get_string('export_to_excel', 'feedback');
print_single_button($export_button_link, $export_button_options, $export_button_label, 'post');
echo '</div>';
@@ -128,7 +128,7 @@
echo get_string('search_course', 'feedback') . ': ';
echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> <input type="submit" value="'.get_string('search').'"/>';
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
echo '<input type="hidden" name="courseitemfiltertyp" value="'.$courseitemfiltertyp.'" />';
+2 -2
View File
@@ -336,7 +336,7 @@
// print_simple_box_start('center', '75%');
print_box_start('generalbox boxaligncenter boxwidthwide');
echo '<div class="mdl-align"><form name="frm" action="'.$ME.'" method="post" onsubmit=" ">';
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<table>';
switch ($feedback->anonymous) {
case FEEDBACK_ANONYMOUS_YES:
@@ -423,7 +423,7 @@
echo '<form name="frm" action="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'" method="post" onsubmit=" ">';
}
}
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="courseid" value="'. $courseid . '" />';
echo '<button type="submit">'.get_string('cancel').'</button>';
echo '</form>';
+1 -1
View File
@@ -26,6 +26,6 @@
}
}
notice_yesno(get_string("confirmdeletionofthispage","lesson"),
"lesson.php?action=delete&amp;id=$cm->id&amp;pageid=$pageid&amp;sesskey=".$USER->sesskey,
"lesson.php?action=delete&amp;id=$cm->id&amp;pageid=$pageid&amp;sesskey=".sesskey(),
"view.php?id=$cm->id");
?>
+5 -5
View File
@@ -18,9 +18,9 @@ class admin_setting_quiz_reviewoptions extends admin_setting {
QUIZ_REVIEW_SCORES => 'scores',
QUIZ_REVIEW_OVERALLFEEDBACK => 'overallfeedback');
function __construct($name, $visiblename, $description, $defaultsetting) {
public function __construct($name, $visiblename, $description, $defaultsetting) {
$this->plugin = 'quiz';
parent::admin_setting($name, $visiblename, $description, $defaultsetting);
parent::__construct($name, $visiblename, $description, $defaultsetting);
}
private function normalise_data($data) {
@@ -35,7 +35,7 @@ class admin_setting_quiz_reviewoptions extends admin_setting {
return $value;
}
function get_setting() {
public function get_setting() {
$value = $this->config_read($this->name);
$fix = $this->config_read('fix_' . $this->name);
if (is_null($value) or is_null($fix)) {
@@ -44,7 +44,7 @@ class admin_setting_quiz_reviewoptions extends admin_setting {
return array('value' => $value, 'fix' => $fix);
}
function write_setting($data) {
public function write_setting($data) {
if (!isset($data['value'])) {
$data['value'] = $this->normalise_data($data);
}
@@ -62,7 +62,7 @@ class admin_setting_quiz_reviewoptions extends admin_setting {
return '';
}
function output_html($data, $query='') {
public function output_html($data, $query='') {
if (!isset($data['value'])) {
$data['value'] = $this->normalise_data($data);
}
+1 -1
View File
@@ -63,7 +63,7 @@ class question_missingtype_qtype extends default_questiontype {
function display_question_editing_page(&$mform, $question, $wizardnow){
print_heading(get_string('warningmissingtype', 'quiz'));
print_heading(get_string('warningmissingtype', 'qtype_missingtype'));
$mform->display();
-358
View File
@@ -1,358 +0,0 @@
<?php
/**
* @author Dick Munroe ([email protected])
* @copyright copyright @ 2004, Dick Munroe, released under the GPL.
*
* The cURL class is a thin wrapper around the procedural interface
* to cURL provided by PHP. I use it mostly as a base class for
* web services whose low level interface is, literally, web pages.
*
* There are a few differences (value added, I guess) between the interface
* provided by this class and the procedural cURL interface. Most
* noticable are:
*
* 1. The curl::exec function (when returning data to the caller rather
* than simply outputing it) always parses the HTTP header and returns
* only the body portion of the reqeust. The header is available via
* the curl::getHeader method.
* 2. The status of the last curl::exec is always maintained. It is
* available via the curl::getStatus method. In addition to the information
* returned by curl_getinfo, that of curl_error and curl_errno is folded
* in as well.
*
* @example ./example.class.curl.php
*/
//
// Edit History:
//
// Dick Munroe [email protected] 30-Nov-2004
// Initial Version Created.
//
// Dick Munroe [email protected] 01-Dec-2004
// Forgot to check for cURL actually being in this instance of PHP.
//
class curl
{
/**
* The mapping to caseless header names.
*
* @access private
* @var array
*/
var $m_caseless ;
/**
* The handle for the current curl session.
*
* @access private
* @var resource
*/
var $m_handle ;
/**
* The parsed contents of the HTTP header if one happened in the
* message. All repeated elements appear as arrays.
*
* The headers are stored as an associative array, the key of which
* is the name of the header, e.g., Set-Cookie, and the values of which
* are the bodies of the header in the order in which they occurred.
*
* Some headers can be repeated in a single header, e.g., Set-Cookie and
* pragma, so each type of header has an array containing one or more
* headers of the same type.
*
* The names of the headers can, potentially, vary in spelling from
* server to server and client to client. No attempt to regulate this
* is made, i.e., the curl class does not force all headers to lower
* or upper class, but it DOES collect all headers of the same type
* under the spelling of the type of header used by the FIRST header
* of that type.
*
* For example, two headers:
*
* 1. Set-Cookie: ...
* 2. set-cookie: ...
*
* Would appear as $this->m_header['Set-Cookie'][0] and ...[1]
*
* @access private
* @var mixed
*/
var $m_header ;
/**
* Current setting of the curl options.
*
* @access private
* @var mixed
*/
var $m_options ;
/**
* Status information for the last executed http request. Includes the errno and error
* in addition to the information returned by curl_getinfo.
*
* The keys defined are those returned by curl_getinfo with two additional
* ones specified, 'error' which is the value of curl_error and 'errno' which
* is the value of curl_errno.
*
* @link http://www.php.net/curl_getinfo
* @link http://www.php.net/curl_errno
* @link http://www.php.net/curl_error
* @access private
* @var mixed
*/
var $m_status ;
/**
* curl class constructor
*
* Initializes the curl class for it's default behavior:
* o no HTTP headers.
* o return the transfer as a string.
* o URL to access.
* By default, the curl class will simply read the URL provided
* in the constructor.
*
* @link http://www.php.net/curl_init
* @param string $theURL [optional] the URL to be accessed by this instance of the class.
*/
function curl($theURL=null)
{
if (!function_exists('curl_init'))
{
trigger_error('PHP was not built with --with-curl, rebuild PHP to use the curl class.', E_USER_ERROR) ;
}
$this->m_handle = curl_init() ;
$this->m_caseless = null ;
$this->m_header = null ;
$this->m_options = null ;
$this->m_status = null ;
if (!empty($theURL))
{
$this->setopt(CURLOPT_URL, $theURL) ;
}
$this->setopt(CURLOPT_HEADER, false) ;
$this->setopt(CURLOPT_RETURNTRANSFER, true) ;
}
/**
* Free the resources associated with the curl session.
*
* @link http://www.php.net/curl_close
*/
function close()
{
curl_close($this->m_handle) ;
$this->m_handle = null ;
}
/**
* Execute the curl request and return the result.
*
* @link http://www.php.net/curl_exec
* @link http://www.php.net/curl_getinfo
* @link http://www.php.net/curl_errno
* @link http://www.php.net/curl_error
* @return string The contents of the page (or other interaction as defined by the
* settings of the various curl options).
*/
function exec()
{
$theReturnValue = curl_exec($this->m_handle) ;
$this->m_status = curl_getinfo($this->m_handle) ;
$this->m_status['errno'] = curl_errno($this->m_handle) ;
$this->m_status['error'] = curl_error($this->m_handle) ;
//
// Parse out the http header (if any).
//
$this->m_header = null ;
if ($this->getOption(CURLOPT_HEADER))
{
$theArray = preg_split("/(\r\n){2,2}/", $theReturnValue, 2) ;
$this->parseHeader($theArray[0]) ;
return $theArray[1] ;
}
return $theReturnValue ;
}
/**
* Returns the parsed http header.
*
* @param string $theHeader [optional] the name of the header to be returned.
* The name of the header is case insensitive. If
* the header name is omitted the parsed header is
* returned. If the requested header doesn't exist
* false is returned.
* @returns mixed
*/
function getHeader($theHeader=null)
{
if (empty($theHeader))
{
return $this->m_header ;
}
else
{
$theHeader = strtoupper($theHeader) ;
if (isset($this->m_caseless[$theHeader]))
{
return $this->m_header[$this->m_caseless[$theHeader]] ;
}
else
{
return false ;
}
}
}
/**
* Returns the current setting of the request option. If no
* option has been set, it return null.
*
* @param integer the requested CURLOPT.
* @returns mixed
*/
function getOption($theOption)
{
if (isset($this->m_options[$theOption]))
{
return $this->m_options[$theOption] ;
}
return null ;
}
/**
* Did the last curl exec operation have an error?
*
* @return mixed The error message associated with the error if an error
* occurred, false otherwise.
*/
function hasError()
{
if (isset($this->m_status['error']))
{
return (empty($this->m_status['error']) ? false : $this->m_status['error']) ;
}
else
{
return false ;
}
}
/**
* Parse an HTTP header.
*
* As a side effect it stores the parsed header in the
* m_header instance variable. The header is stored as
* an associative array and the case of the headers
* as provided by the server is preserved and all
* repeated headers (pragma, set-cookie, etc) are grouped
* with the first spelling for that header
* that is seen.
*
* All headers are stored as if they COULD be repeated, so
* the headers are really stored as an array of arrays.
*
* @param string $theHeader The HTTP data header.
*/
function parseHeader($theHeader)
{
$this->m_caseless = array() ;
$theArray = preg_split("/(\r\n)+/", $theHeader) ;
//
// Ditch the HTTP status line.
//
if (preg_match('/^HTTP/', $theArray[0]))
{
$theArray = array_slice($theArray, 1) ;
}
foreach ($theArray as $theHeaderString)
{
$theHeaderStringArray = preg_split("/\s*:\s*/", $theHeaderString, 2) ;
$theCaselessTag = strtoupper($theHeaderStringArray[0]) ;
if (!isset($this->m_caseless[$theCaselessTag]))
{
$this->m_caseless[$theCaselessTag] = $theHeaderStringArray[0] ;
}
$this->m_header[$this->m_caseless[$theCaselessTag]][] = $theHeaderStringArray[1] ;
}
}
/**
* Return the status information of the last curl request.
*
* @param string $theField [optional] the particular portion
* of the status information desired.
* If omitted the array of status
* information is returned. If a non-existant
* status field is requested, false is returned.
* @returns mixed
*/
function getStatus($theField=null)
{
if (empty($theField))
{
return $this->m_status ;
}
else
{
if (isset($this->m_status[$theField]))
{
return $this->m_status[$theField] ;
}
else
{
return false ;
}
}
}
/**
* Set a curl option.
*
* @link http://www.php.net/curl_setopt
* @param mixed $theOption One of the valid CURLOPT defines.
* @param mixed $theValue the value of the curl option.
*/
function setopt($theOption, $theValue)
{
curl_setopt($this->m_handle, $theOption, $theValue) ;
$this->m_options[$theOption] = $theValue ;
}
}
?>
@@ -1,106 +0,0 @@
<?php
/**
* Listener for HTTP_Request and HTTP_Response objects
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2002-2007, Richard Heyes
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* o The names of the authors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category HTTP
* @package HTTP_Request
* @author Alexey Borzov <[email protected]>
* @copyright 2002-2007 Richard Heyes
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id$
* @link http://pear.php.net/package/HTTP_Request/
*/
/**
* Listener for HTTP_Request and HTTP_Response objects
*
* This class implements the Observer part of a Subject-Observer
* design pattern.
*
* @category HTTP
* @package HTTP_Request
* @author Alexey Borzov <[email protected]>
* @version Release: 1.4.2
*/
class HTTP_Request_Listener
{
/**
* A listener's identifier
* @var string
*/
var $_id;
/**
* Constructor, sets the object's identifier
*
* @access public
*/
function HTTP_Request_Listener()
{
$this->_id = md5(uniqid('http_request_', 1));
}
/**
* Returns the listener's identifier
*
* @access public
* @return string
*/
function getId()
{
return $this->_id;
}
/**
* This method is called when Listener is notified of an event
*
* @access public
* @param object an object the listener is attached to
* @param string Event name
* @param mixed Additional data
* @abstract
*/
function update(&$subject, $event, $data = null)
{
echo "Notified of event: '$event'\n";
if (null !== $data) {
echo "Additional data: ";
var_dump($data);
}
}
}
?>