2004-09-12 17:34:35 +00:00
|
|
|
<?php // $Id$
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2003-08-18 17:46:51 +00:00
|
|
|
if (!isset($CFG->resource_framesize)) {
|
|
|
|
set_config("resource_framesize", 130);
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2003-01-05 10:10:05 +00:00
|
|
|
|
2003-11-25 08:01:52 +00:00
|
|
|
if (!isset($CFG->resource_websearch)) {
|
|
|
|
set_config("resource_websearch", "http://google.com/");
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2003-11-25 08:01:52 +00:00
|
|
|
|
2003-11-26 11:47:51 +00:00
|
|
|
if (!isset($CFG->resource_defaulturl)) {
|
|
|
|
set_config("resource_defaulturl", "http://");
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2003-11-28 02:11:02 +00:00
|
|
|
|
|
|
|
if (!isset($CFG->resource_filterexternalpages)) {
|
|
|
|
set_config("resource_filterexternalpages", false);
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2003-11-26 11:47:51 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
if (!isset($CFG->resource_secretphrase)) {
|
|
|
|
set_config("resource_secretphrase", random_string(20));
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2004-07-25 14:32:05 +00:00
|
|
|
|
2003-12-09 04:00:33 +00:00
|
|
|
if (!isset($CFG->resource_popup)) {
|
|
|
|
set_config("resource_popup", "");
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2003-12-09 04:00:33 +00:00
|
|
|
|
2004-08-28 17:20:55 +00:00
|
|
|
if (!isset($CFG->resource_windowsettings)) {
|
|
|
|
set_config("resource_windowsettings", "0");
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2004-08-28 17:20:55 +00:00
|
|
|
|
|
|
|
if (!isset($CFG->resource_parametersettings)) {
|
|
|
|
set_config("resource_parametersettings", "0");
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2004-08-28 17:20:55 +00:00
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
$RESOURCE_WINDOW_OPTIONS = array('resizable', 'scrollbars', 'directories', 'location',
|
2005-01-18 09:46:01 +00:00
|
|
|
'menubar', 'toolbar', 'status', 'height', 'width');
|
2004-08-08 14:33:23 +00:00
|
|
|
|
2003-12-09 04:00:33 +00:00
|
|
|
foreach ($RESOURCE_WINDOW_OPTIONS as $popupoption) {
|
|
|
|
$popupoption = "resource_popup$popupoption";
|
|
|
|
if (!isset($CFG->$popupoption)) {
|
2005-01-18 09:46:01 +00:00
|
|
|
if ($popupoption == 'resource_popupheight') {
|
2003-12-09 04:00:33 +00:00
|
|
|
set_config($popupoption, 450);
|
2005-01-18 09:46:01 +00:00
|
|
|
} else if ($popupoption == 'resource_popupwidth') {
|
2003-12-09 04:00:33 +00:00
|
|
|
set_config($popupoption, 620);
|
|
|
|
} else {
|
2005-01-18 09:46:01 +00:00
|
|
|
set_config($popupoption, 'checked');
|
2003-12-09 04:00:33 +00:00
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2003-12-09 04:00:33 +00:00
|
|
|
}
|
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
/**
|
|
|
|
* resource_base is the base class for resource types
|
|
|
|
*
|
|
|
|
* This class provides all the functionality for a resource
|
|
|
|
*/
|
|
|
|
|
|
|
|
class resource_base {
|
|
|
|
|
|
|
|
var $cm;
|
|
|
|
var $course;
|
|
|
|
var $resource;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the base resource class
|
|
|
|
*
|
|
|
|
* Constructor for the base resource class.
|
|
|
|
* If cmid is set create the cm, course, resource objects.
|
2004-11-11 07:44:14 +00:00
|
|
|
* and do some checks to make sure people can be here, and so on.
|
2004-07-25 14:32:05 +00:00
|
|
|
*
|
|
|
|
* @param cmid integer, the current course module id - not set for new resources
|
|
|
|
*/
|
|
|
|
function resource_base($cmid=0) {
|
|
|
|
|
2004-11-11 07:44:14 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
if ($cmid) {
|
|
|
|
if (! $this->cm = get_record("course_modules", "id", $cmid)) {
|
|
|
|
error("Course Module ID was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->course = get_record("course", "id", $this->cm->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
require_course_login($this->course, true, $this->cm);
|
2004-11-11 07:44:14 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
if (! $this->resource = get_record("resource", "id", $this->cm->instance)) {
|
|
|
|
error("Resource ID was incorrect");
|
|
|
|
}
|
2004-11-11 07:44:14 +00:00
|
|
|
|
|
|
|
$this->strresource = get_string("modulename", "resource");
|
|
|
|
$this->strresources = get_string("modulenameplural", "resource");
|
|
|
|
|
|
|
|
if ($this->course->category) {
|
|
|
|
$this->navigation = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> -> ".
|
|
|
|
"<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$this->strresources</a> ->";
|
|
|
|
} else {
|
2005-02-16 10:40:48 +00:00
|
|
|
$this->navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$this->strresources</a> ->";
|
2004-11-11 07:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->cm->visible and !isteacher($this->course->id)) {
|
|
|
|
$pagetitle = strip_tags($this->course->shortname.': '.$this->strresource);
|
|
|
|
print_header($pagetitle, $this->course->fullname, "$this->navigation $this->strresource", "", "", true, '', navmenu($this->course, $this->cm));
|
|
|
|
notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
|
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
}
|
2004-07-25 14:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-11 07:44:14 +00:00
|
|
|
/**
|
|
|
|
* Display function does nothing in the base class
|
|
|
|
*/
|
2004-07-25 14:32:05 +00:00
|
|
|
function display() {
|
2004-11-11 07:44:14 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-28 06:56:59 +00:00
|
|
|
function setup(&$form) {
|
2004-07-25 14:32:05 +00:00
|
|
|
global $CFG, $usehtmleditor;
|
|
|
|
|
|
|
|
if (! empty($form->course)) {
|
|
|
|
if (! $this->course = get_record("course", "id", $form->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($form->name)) {
|
|
|
|
$form->name = "";
|
|
|
|
}
|
|
|
|
if (empty($form->type)) {
|
|
|
|
$form->type = "";
|
|
|
|
}
|
|
|
|
if (empty($form->summary)) {
|
|
|
|
$form->summary = "";
|
|
|
|
}
|
|
|
|
if (empty($form->reference)) {
|
|
|
|
$form->reference = "";
|
|
|
|
}
|
|
|
|
if (empty($form->alltext)) {
|
|
|
|
$form->alltext = "";
|
|
|
|
}
|
2004-07-28 06:56:59 +00:00
|
|
|
if (empty($form->options)) {
|
|
|
|
$form->options = "";
|
|
|
|
}
|
2004-07-25 14:32:05 +00:00
|
|
|
$nohtmleditorneeded = true;
|
|
|
|
|
2004-08-02 19:11:15 +00:00
|
|
|
print_heading_with_help(get_string("resourcetype$form->type", 'resource'), $form->type, 'resource/type');
|
2004-07-25 14:32:05 +00:00
|
|
|
|
|
|
|
include("$CFG->dirroot/mod/resource/type/common.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setup_end() {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
include("$CFG->dirroot/mod/resource/type/common_end.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function add_instance($resource) {
|
2005-02-16 10:40:48 +00:00
|
|
|
// Given an object containing all the necessary data,
|
|
|
|
// (defined by the form in mod.html) this function
|
|
|
|
// will create a new instance and return the id number
|
2003-07-12 05:19:18 +00:00
|
|
|
// of the new instance.
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2003-07-20 13:53:31 +00:00
|
|
|
global $RESOURCE_WINDOW_OPTIONS;
|
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
$resource->timemodified = time();
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
if (isset($resource->windowpopup)) {
|
2004-08-14 11:54:32 +00:00
|
|
|
if ($resource->windowpopup) {
|
|
|
|
$optionlist = array();
|
|
|
|
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
|
|
|
if (isset($resource->$option)) {
|
|
|
|
$optionlist[] = $option."=".$resource->$option;
|
|
|
|
}
|
2003-07-20 13:53:31 +00:00
|
|
|
}
|
2004-08-14 11:54:32 +00:00
|
|
|
$resource->popup = implode(',', $optionlist);
|
2004-07-25 14:32:05 +00:00
|
|
|
$resource->options = "";
|
2004-08-14 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
if (isset($resource->framepage)) {
|
|
|
|
$resource->options = "frame";
|
|
|
|
} else {
|
|
|
|
$resource->options = "";
|
|
|
|
}
|
|
|
|
$resource->popup = "";
|
2004-07-25 14:32:05 +00:00
|
|
|
}
|
2003-07-20 13:53:31 +00:00
|
|
|
}
|
|
|
|
|
2004-08-28 17:20:55 +00:00
|
|
|
if (isset($resource->parametersettingspref)) {
|
|
|
|
set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
|
|
|
|
}
|
|
|
|
if (isset($resource->windowsettingspref)) {
|
|
|
|
set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
|
|
|
|
}
|
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
return insert_record("resource", $resource);
|
|
|
|
}
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
function update_instance($resource) {
|
2005-02-16 10:40:48 +00:00
|
|
|
// Given an object containing all the necessary data,
|
|
|
|
// (defined by the form in mod.html) this function
|
2003-07-12 05:19:18 +00:00
|
|
|
// will update an existing instance with new data.
|
|
|
|
|
2003-07-20 13:53:31 +00:00
|
|
|
global $RESOURCE_WINDOW_OPTIONS;
|
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
$resource->id = $resource->instance;
|
|
|
|
$resource->timemodified = time();
|
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
if (isset($resource->windowpopup)) {
|
2004-08-14 11:54:32 +00:00
|
|
|
if ($resource->windowpopup) {
|
|
|
|
$optionlist = array();
|
|
|
|
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
|
|
|
if (isset($resource->$option)) {
|
|
|
|
$optionlist[] = $option."=".$resource->$option;
|
|
|
|
}
|
2003-07-20 13:53:31 +00:00
|
|
|
}
|
2004-08-14 11:54:32 +00:00
|
|
|
$resource->popup = implode(',', $optionlist);
|
2004-07-25 14:32:05 +00:00
|
|
|
$resource->options = "";
|
2004-08-14 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
if (isset($resource->framepage)) {
|
|
|
|
$resource->options = "frame";
|
|
|
|
} else {
|
|
|
|
$resource->options = "";
|
|
|
|
}
|
|
|
|
$resource->popup = "";
|
2004-07-25 14:32:05 +00:00
|
|
|
}
|
2003-07-20 13:53:31 +00:00
|
|
|
}
|
|
|
|
|
2004-08-28 17:20:55 +00:00
|
|
|
if (isset($resource->parametersettingspref)) {
|
|
|
|
set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
|
|
|
|
}
|
|
|
|
if (isset($resource->windowsettingspref)) {
|
|
|
|
set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
|
|
|
|
}
|
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
return update_record("resource", $resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
function delete_instance($id) {
|
2005-02-16 10:40:48 +00:00
|
|
|
// Given an ID of an instance of this module,
|
|
|
|
// this function will permanently delete the instance
|
|
|
|
// and any data that depends on it.
|
2003-07-12 05:19:18 +00:00
|
|
|
|
|
|
|
if (! $resource = get_record("resource", "id", "$id")) {
|
|
|
|
return false;
|
2002-10-17 14:03:59 +00:00
|
|
|
}
|
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
$result = true;
|
|
|
|
|
|
|
|
if (! delete_records("resource", "id", "$resource->id")) {
|
|
|
|
$result = false;
|
2002-10-17 14:03:59 +00:00
|
|
|
}
|
|
|
|
|
2003-07-12 05:19:18 +00:00
|
|
|
return $result;
|
2002-10-17 14:03:59 +00:00
|
|
|
}
|
2003-07-12 05:19:18 +00:00
|
|
|
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
|
|
|
|
} /// end of class definition
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function resource_add_instance($resource) {
|
|
|
|
global $CFG;
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2004-09-29 03:12:31 +00:00
|
|
|
$resource->type = clean_filename($resource->type); // Just to be safe
|
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
|
2004-07-28 06:56:59 +00:00
|
|
|
$resourceclass = "resource_$resource->type";
|
|
|
|
$res = new $resourceclass();
|
2004-07-25 14:32:05 +00:00
|
|
|
|
|
|
|
return $res->add_instance($resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resource_update_instance($resource) {
|
|
|
|
global $CFG;
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2004-09-29 03:12:31 +00:00
|
|
|
$resource->type = clean_filename($resource->type); // Just to be safe
|
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
|
2004-07-28 06:56:59 +00:00
|
|
|
$resourceclass = "resource_$resource->type";
|
|
|
|
$res = new $resourceclass();
|
2004-07-25 14:32:05 +00:00
|
|
|
|
|
|
|
return $res->update_instance($resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resource_delete_instance($id) {
|
|
|
|
global $CFG;
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
if (! $resource = get_record("resource", "id", "$id")) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-09-29 03:12:31 +00:00
|
|
|
|
|
|
|
$resource->type = clean_filename($resource->type); // Just to be safe
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
|
2004-07-28 06:56:59 +00:00
|
|
|
$resourceclass = "resource_$resource->type";
|
|
|
|
$res = new $resourceclass();
|
2004-07-25 14:32:05 +00:00
|
|
|
|
|
|
|
return $res->delete_instance($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-17 14:03:59 +00:00
|
|
|
function resource_user_outline($course, $user, $mod, $resource) {
|
2005-02-16 10:40:48 +00:00
|
|
|
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND action='view' AND info='$resource->id'", "time ASC")) {
|
2002-10-17 14:03:59 +00:00
|
|
|
|
|
|
|
$numviews = count($logs);
|
|
|
|
$lastlog = array_pop($logs);
|
|
|
|
|
|
|
|
$result->info = get_string("numviews", "", $numviews);
|
|
|
|
$result->time = $lastlog->time;
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resource_user_complete($course, $user, $mod, $resource) {
|
2005-02-01 03:46:20 +00:00
|
|
|
global $CFG;
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
2002-12-23 09:39:26 +00:00
|
|
|
AND action='view' AND info='$resource->id'", "time ASC")) {
|
2002-10-17 14:03:59 +00:00
|
|
|
$numviews = count($logs);
|
|
|
|
$lastlog = array_pop($logs);
|
|
|
|
|
|
|
|
$strmostrecently = get_string("mostrecently");
|
|
|
|
$strnumviews = get_string("numviews", "", $numviews);
|
|
|
|
|
|
|
|
echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
|
|
|
|
|
|
|
|
} else {
|
2002-10-17 14:28:12 +00:00
|
|
|
print_string("neverseen", "resource");
|
2002-10-17 14:03:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-07 22:01:47 +00:00
|
|
|
function resource_get_participants($resourceid) {
|
|
|
|
//Returns the users with data in one resource
|
|
|
|
//(NONE, byt must exists on EVERY mod !!)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-17 14:03:59 +00:00
|
|
|
|
2003-10-22 13:14:56 +00:00
|
|
|
function resource_get_coursemodule_info($coursemodule) {
|
2005-02-16 10:40:48 +00:00
|
|
|
/// Given a course_module object, this function returns any
|
2003-10-22 13:14:56 +00:00
|
|
|
/// "extra" information that may be needed when printing
|
|
|
|
/// this activity in a course listing.
|
|
|
|
///
|
|
|
|
/// See get_array_of_activities() in course/lib.php
|
|
|
|
///
|
|
|
|
|
2004-04-26 15:31:22 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$info = NULL;
|
|
|
|
|
2003-10-22 13:14:56 +00:00
|
|
|
if ($resource = get_record("resource", "id", $coursemodule->instance)) {
|
2004-07-26 16:21:56 +00:00
|
|
|
if (!empty($resource->popup)) {
|
2004-10-07 08:08:56 +00:00
|
|
|
$info->extra = urlencode("target=\"resource$resource->id\" onclick=\"return ".
|
2004-09-16 17:13:57 +00:00
|
|
|
"openpopup('/mod/resource/view.php?inpopup=true&id=".
|
2003-10-22 13:14:56 +00:00
|
|
|
$coursemodule->id.
|
2004-07-25 14:32:05 +00:00
|
|
|
"','resource$resource->id','$resource->popup');\"");
|
2003-10-22 13:14:56 +00:00
|
|
|
}
|
2004-04-26 15:31:22 +00:00
|
|
|
|
2005-03-07 11:32:03 +00:00
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
2004-04-26 15:31:22 +00:00
|
|
|
|
2004-07-26 16:21:56 +00:00
|
|
|
if ($resource->type == 'file') {
|
2005-02-16 10:40:48 +00:00
|
|
|
$icon = mimeinfo("icon", $resource->reference);
|
2004-04-26 15:31:22 +00:00
|
|
|
if ($icon != 'unknown.gif') {
|
2005-02-16 10:40:48 +00:00
|
|
|
$info->icon ="f/$icon";
|
2004-07-26 16:21:56 +00:00
|
|
|
} else {
|
2005-02-16 10:40:48 +00:00
|
|
|
$info->icon ="f/web.gif";
|
2004-04-26 15:31:22 +00:00
|
|
|
}
|
2004-07-25 14:32:05 +00:00
|
|
|
} else if ($resource->type == 'directory') {
|
2005-02-16 10:40:48 +00:00
|
|
|
$info->icon ="f/folder.gif";
|
2004-04-26 15:31:22 +00:00
|
|
|
}
|
2003-10-22 13:14:56 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 15:31:22 +00:00
|
|
|
return $info;
|
2003-10-22 13:14:56 +00:00
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-27 19:09:47 +00:00
|
|
|
function resource_fetch_remote_file ($cm, $url, $headers = "" ) {
|
2003-11-28 02:11:02 +00:00
|
|
|
/// Snoopy is an HTTP client in PHP
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once("$CFG->libdir/snoopy/Snoopy.class.inc");
|
|
|
|
|
2003-11-28 02:19:20 +00:00
|
|
|
$client = new Snoopy();
|
2005-02-16 10:40:48 +00:00
|
|
|
$ua = 'Moodle/'. $CFG->release . ' (+http://moodle.org';
|
2003-11-28 03:27:24 +00:00
|
|
|
if ( $CFG->resource_usecache ) {
|
|
|
|
$ua = $ua . ')';
|
|
|
|
} else {
|
|
|
|
$ua = $ua . '; No cache)';
|
|
|
|
}
|
|
|
|
$client->agent = $ua;
|
|
|
|
$client->read_timeout = 5;
|
|
|
|
$client->use_gzip = true;
|
2003-11-28 02:19:20 +00:00
|
|
|
if (is_array($headers) ) {
|
|
|
|
$client->rawheaders = $headers;
|
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-28 02:19:20 +00:00
|
|
|
@$client->fetch($url);
|
2003-11-28 03:27:24 +00:00
|
|
|
if ( $client->status >= 200 && $client->status < 300 ) {
|
|
|
|
$tags = array("A" => "href=",
|
|
|
|
"IMG" => "src=",
|
|
|
|
"LINK" => "href=",
|
|
|
|
"AREA" => "href=",
|
|
|
|
"FRAME" => "src=",
|
|
|
|
"IFRAME" => "src=",
|
|
|
|
"FORM" => "action=");
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-28 03:27:24 +00:00
|
|
|
foreach ($tags as $tag => $key) {
|
2004-09-16 17:13:57 +00:00
|
|
|
$prefix = "fetch.php?id=$cm->id&url=";
|
2003-11-28 03:27:24 +00:00
|
|
|
if ( $tag == "IMG" or $tag == "LINK" or $tag == "FORM") {
|
|
|
|
$prefix = "";
|
|
|
|
}
|
|
|
|
$client->results = resource_redirect_tags($client->results, $url, $tag, $key,$prefix);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( $client->status >= 400 && $client->status < 500) {
|
|
|
|
$client->results = get_string("fetchclienterror","resource"); // Client error
|
|
|
|
} elseif ( $client->status >= 500 && $client->status < 600) {
|
|
|
|
$client->results = get_string("fetchservererror","resource"); // Server error
|
|
|
|
} else {
|
|
|
|
$client->results = get_string("fetcherror","resource"); // Redirection? HEAD? Unknown error.
|
2003-11-27 19:04:36 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-28 02:19:20 +00:00
|
|
|
return $client;
|
2003-11-27 19:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function resource_redirect_tags($text, $url, $tagtoparse, $keytoparse,$prefix = "" ) {
|
2003-11-28 03:27:24 +00:00
|
|
|
$valid = 1;
|
2003-11-27 19:04:36 +00:00
|
|
|
if ( strpos($url,"?") == FALSE ) {
|
|
|
|
$valid = 1;
|
|
|
|
}
|
|
|
|
if ( $valid ) {
|
|
|
|
$lastpoint = strrpos($url,".");
|
|
|
|
$lastslash = strrpos($url,"/");
|
|
|
|
if ( $lastpoint > $lastslash ) {
|
|
|
|
$root = substr($url,0,$lastslash+1);
|
|
|
|
} else {
|
|
|
|
$root = $url;
|
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
if ( $root == "http://" or
|
2003-11-27 19:04:36 +00:00
|
|
|
$root == "https://") {
|
|
|
|
$root = $url;
|
|
|
|
}
|
|
|
|
if ( substr($root,strlen($root)-1) == '/' ) {
|
|
|
|
$root = substr($root,0,-1);
|
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-27 19:04:36 +00:00
|
|
|
$mainroot = $root;
|
|
|
|
$lastslash = strrpos($mainroot,"/");
|
|
|
|
while ( $lastslash > 9) {
|
|
|
|
$mainroot = substr($mainroot,0,$lastslash);
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-27 19:04:36 +00:00
|
|
|
$lastslash = strrpos($mainroot,"/");
|
|
|
|
}
|
2003-10-22 13:14:56 +00:00
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
$regex = "/<$tagtoparse (.+?)>/is";
|
|
|
|
$count = preg_match_all($regex, $text, $hrefs);
|
2003-11-27 19:04:36 +00:00
|
|
|
for ( $i = 0; $i < $count; $i++) {
|
|
|
|
$tag = $hrefs[1][$i];
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-27 19:04:36 +00:00
|
|
|
$poshref = strpos(strtolower($tag),strtolower($keytoparse));
|
|
|
|
$start = $poshref + strlen($keytoparse);
|
|
|
|
$left = substr($tag,0,$start);
|
|
|
|
if ( $tag[$start] == '"' ) {
|
|
|
|
$left .= '"';
|
|
|
|
$start++;
|
|
|
|
}
|
|
|
|
$posspace = strpos($tag," ", $start+1);
|
|
|
|
$right = "";
|
|
|
|
if ( $posspace != FALSE) {
|
|
|
|
$right = substr($tag, $posspace);
|
|
|
|
}
|
|
|
|
$end = strlen($tag)-1;
|
|
|
|
if ( $tag[$end] == '"' ) {
|
|
|
|
$right = '"' . $right;
|
|
|
|
}
|
|
|
|
$finalurl = substr($tag,$start,$end-$start+$diff);
|
|
|
|
// Here, we could have these possible values for $finalurl:
|
|
|
|
// file.ext Add current root dir
|
|
|
|
// http://(domain) don't care
|
|
|
|
// http://(domain)/ don't care
|
|
|
|
// http://(domain)/folder don't care
|
|
|
|
// http://(domain)/folder/ don't care
|
|
|
|
// http://(domain)/folder/file.ext don't care
|
|
|
|
// folder/ Add current root dir
|
|
|
|
// folder/file.ext Add current root dir
|
|
|
|
// /folder/ Add main root dir
|
|
|
|
// /folder/file.ext Add main root dir
|
|
|
|
|
|
|
|
// Special case: If finalurl contains a ?, it won't be parsed
|
2003-11-28 03:27:24 +00:00
|
|
|
$valid = 1;
|
2003-11-27 19:04:36 +00:00
|
|
|
|
|
|
|
if ( strpos($finalurl,"?") == FALSE ) {
|
|
|
|
$valid = 1;
|
|
|
|
}
|
|
|
|
if ( $valid ) {
|
|
|
|
if ( $finalurl[0] == "/" ) {
|
|
|
|
$finalurl = $mainroot . $finalurl;
|
2005-02-16 10:40:48 +00:00
|
|
|
} elseif ( strtolower(substr($finalurl,0,7)) != "http://" and
|
2003-11-27 19:04:36 +00:00
|
|
|
strtolower(substr($finalurl,0,8)) != "https://") {
|
|
|
|
if ( $finalurl[0] == "/") {
|
|
|
|
$finalurl = $mainroot . $finalurl;
|
|
|
|
} else {
|
|
|
|
$finalurl = "$root/$finalurl";
|
|
|
|
}
|
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-11-27 19:04:36 +00:00
|
|
|
$text = str_replace($tag,"$left$prefix$finalurl$right",$text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
2003-10-22 13:14:56 +00:00
|
|
|
|
2004-07-25 14:32:05 +00:00
|
|
|
function resource_is_url($path) {
|
2004-08-01 06:36:42 +00:00
|
|
|
if (strpos($path, '://')) { // eg http:// https:// ftp:// etc
|
2004-07-25 14:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-01 06:36:42 +00:00
|
|
|
if (strpos($path, '/') === 0) { // Starts with slash
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2004-07-25 14:32:05 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 19:11:15 +00:00
|
|
|
function resource_get_resource_types() {
|
|
|
|
/// Returns a menu of current resource types, in standard order
|
|
|
|
global $resource_standard_order;
|
|
|
|
|
|
|
|
$resources = array();
|
|
|
|
|
|
|
|
/// Standard resource types
|
2004-08-08 14:33:23 +00:00
|
|
|
$standardresources = array('text','html','file','directory');
|
2004-08-02 19:11:15 +00:00
|
|
|
foreach ($standardresources as $resourcetype) {
|
|
|
|
$resources[$resourcetype] = get_string("resourcetype$resourcetype", 'resource');
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Drop-in extra resource types
|
|
|
|
$resourcetypes = get_list_of_plugins('mod/resource/type');
|
|
|
|
foreach ($resourcetypes as $resourcetype) {
|
|
|
|
if (!in_array($resourcetype, $resources)) {
|
|
|
|
$resources[$resourcetype] = get_string("resourcetype$resourcetype", 'resource');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $resources;
|
|
|
|
}
|
2002-10-17 14:03:59 +00:00
|
|
|
?>
|