From: martinlanghoff Date: Fri, 10 Mar 2006 01:05:52 +0000 (+0000) Subject: mod/resource: dos2unix on the Hive code X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=10741fb26e5295dd93e4883992df91e50f9cf927;p=moodle.git mod/resource: dos2unix on the Hive code Some Windows newlines got in there somehow. Cleanup. --- diff --git a/mod/resource/type/repository/repository.html b/mod/resource/type/repository/repository.html index 286706f29f..fdddfdb53b 100644 --- a/mod/resource/type/repository/repository.html +++ b/mod/resource/type/repository/repository.html @@ -1,210 +1,210 @@ - - - - - - - - - : - - - reference\" alt=\"reference\" />
"; - ?> - - - - - - - - - - - -
- - - : - - - - - - - - -
- - - - - - - - - - - - - - -
- - - onclick="lockoptions('form', 'windowpopup[0]', frameitem); - return lockoptions('form', 'windowpopup[1]', popupitems);" /> - "> -
- - options == "frame") ? "checked=\"checked\"" : "" ?> alt="" /> - -
-
- - onclick="lockoptions('form', 'windowpopup[0]', frameitem); - return lockoptions('form', 'windowpopup[1]', popupitems);" /> - -
- $value) { - if ($name == "height" or $name == "width") { - continue; - } - echo ""; - echo "$name." alt=\"$name\" />"; - $stringname = "str$name"; - echo $$stringname."
"; - } - ?> - - - -
- - - -
- "; - echo "lockoptions('form','windowpopup[1]', popupitems);"; - echo ""; - } else { - echo ""; - } - ?> -
-
- -
- - - - - : - - - - - - - - -
- - - - - - - - -maxparameters; $i++) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; -} - -?> - - -
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
- -
- - - - - - - - + + + + + + + + + : + + + reference\" alt=\"reference\" />
"; + ?> + + + + + + + + + + + +
+ + + : + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + onclick="lockoptions('form', 'windowpopup[0]', frameitem); + return lockoptions('form', 'windowpopup[1]', popupitems);" /> + "> +
+ + options == "frame") ? "checked=\"checked\"" : "" ?> alt="" /> + +
+
+ + onclick="lockoptions('form', 'windowpopup[0]', frameitem); + return lockoptions('form', 'windowpopup[1]', popupitems);" /> + +
+ $value) { + if ($name == "height" or $name == "width") { + continue; + } + echo ""; + echo "$name." alt=\"$name\" />"; + $stringname = "str$name"; + echo $$stringname."
"; + } + ?> + + + +
+ + + +
+ "; + echo "lockoptions('form','windowpopup[1]', popupitems);"; + echo ""; + } else { + echo ""; + } + ?> +
+
+ +
+ + + + + : + + + + + + + + +
+ + + + + + + + +maxparameters; $i++) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; +} + +?> + + +
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
+ +
+ + + + + + + + diff --git a/mod/resource/type/repository/resource.class.php b/mod/resource/type/repository/resource.class.php index d290c35332..26cf0587bd 100644 --- a/mod/resource/type/repository/resource.class.php +++ b/mod/resource/type/repository/resource.class.php @@ -1,612 +1,612 @@ -course->lang)) { - $CFG->courselang = $this->course->lang; - } - - if (empty($USER->id)) { // No need to set up parameters - $this->parameters = array(); - return; - } - - $site = get_site(); - - $this->parameters = array( - - 'label1' => array('langstr' => get_string('user'), - 'value' => 'optgroup'), - - 'userid' => array('langstr' => 'id', - 'value' => $USER->id), - 'userusername' => array('langstr' => get_string('username'), - 'value' => $USER->username), - 'userpassword' => array('langstr' => get_string('password'), - 'value' => $USER->password), - 'useridnumber' => array('langstr' => get_string('idnumber'), - 'value' => $USER->idnumber), - 'userfirstname' => array('langstr' => get_string('firstname'), - 'value' => $USER->firstname), - 'userlastname' => array('langstr' => get_string('lastname'), - 'value' => $USER->lastname), - 'userfullname' => array('langstr' => get_string('fullname'), - 'value' => fullname($USER)), - 'useremail' => array('langstr' => get_string('email'), - 'value' => $USER->email), - 'usericq' => array('langstr' => get_string('icqnumber'), - 'value' => $USER->icq), - 'userphone1' => array('langstr' => get_string('phone').' 1', - 'value' => $USER->phone1), - 'userphone2' => array('langstr' => get_string('phone').' 2', - 'value' => $USER->phone2), - 'userinstitution' => array('langstr' => get_string('institution'), - 'value' => $USER->institution), - 'userdepartment' => array('langstr' => get_string('department'), - 'value' => $USER->department), - 'useraddress' => array('langstr' => get_string('address'), - 'value' => $USER->address), - 'usercity' => array('langstr' => get_string('city'), - 'value' => $USER->city), - 'usertimezone' => array('langstr' => get_string('timezone'), - 'value' => get_user_timezone_offset()), - 'userurl' => array('langstr' => get_string('webpage'), - 'value' => $USER->url), - - 'label2' => array('langstr' => "", - 'value' =>'/optgroup'), - 'label3' => array('langstr' => get_string('course'), - 'value' => 'optgroup'), - - 'courseid' => array('langstr' => 'id', - 'value' => $this->course->id), - 'coursefullname' => array('langstr' => get_string('fullname'), - 'value' => $this->course->fullname), - 'courseshortname' => array('langstr' => get_string('shortname'), - 'value' => $this->course->shortname), - 'courseidnumber' => array('langstr' => get_string('idnumber'), - 'value' => $this->course->idnumber), - 'coursesummary' => array('langstr' => get_string('summary'), - 'value' => $this->course->summary), - 'courseformat' => array('langstr' => get_string('format'), - 'value' => $this->course->format), - 'courseteacher' => array('langstr' => get_string('wordforteacher'), - 'value' => $this->course->teacher), - 'courseteachers' => array('langstr' => get_string('wordforteachers'), - 'value' => $this->course->teachers), - 'coursestudent' => array('langstr' => get_string('wordforstudent'), - 'value' => $this->course->student), - 'coursestudents' => array('langstr' => get_string('wordforstudents'), - 'value' => $this->course->students), - - 'label4' => array('langstr' => "", - 'value' =>'/optgroup'), - 'label5' => array('langstr' => get_string('miscellaneous'), - 'value' => 'optgroup'), - - 'lang' => array('langstr' => get_string('preferredlanguage'), - 'value' => current_language()), - 'sitename' => array('langstr' => get_string('fullsitename'), - 'value' => $site->fullname), - 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $CFG), - 'value' => $CFG->wwwroot), - 'currenttime' => array('langstr' => get_string('time'), - 'value' => time()), - 'encryptedcode' => array('langstr' => get_string('encryptedcode'), - 'value' => $this->set_encrypted_parameter()), - - 'label6' => array('langstr' => "", - 'value' =>'/optgroup') - ); - -} - - -/** -* Add new instance of repository resource -* -* Create alltext field before calling base class function. -* -* @param resource object -*/ -function add_instance($resource) { - $optionlist = array(); - - for ($i = 0; $i < $this->maxparameters; $i++) { - $parametername = "parameter$i"; - $parsename = "parse$i"; - if (!empty($resource->$parsename) and $resource->$parametername != "-") { - $optionlist[] = $resource->$parametername."=".$resource->$parsename; - } - } - - $resource->alltext = implode(',', $optionlist); - - return parent::add_instance($resource); -} - - -/** -* Update instance of repository resource -* -* Create alltext field before calling base class function. -* -* @param resource object -*/ -function update_instance($resource) { - $optionlist = array(); - - for ($i = 0; $i < $this->maxparameters; $i++) { - $parametername = "parameter$i"; - $parsename = "parse$i"; - if (!empty($resource->$parsename) and $resource->$parametername != "-") { - $optionlist[] = $resource->$parametername."=".$resource->$parsename; - } - } - - $resource->alltext = implode(',', $optionlist); - - return parent::update_instance($resource); -} - - -/** -* Display the repository resource -* -* Displays a repository resource embedded, in a frame, or in a popup. -* Output depends on type of file resource. -* -* @param CFG global object -*/ -function display() { - global $CFG, $THEME, $SESSION; - -/// Set up generic stuff first, including checking for access - parent::display(); - -/// Set up some shorthand variables - $cm = $this->cm; - $course = $this->course; - $resource = $this->resource; - - - $this->set_parameters(); // set the parameters array - -/////////////////////////////////////////////// - - /// Possible display modes are: - /// File displayed in a frame in a normal window - /// File displayed embedded in a normal page - /// File displayed in a popup window - /// File displayed emebedded in a popup window - - - /// First, find out what sort of file we are dealing with. - require_once($CFG->libdir.'/filelib.php'); - - $querystring = ''; - $resourcetype = ''; - $embedded = false; - $mimetype = mimeinfo("type", $resource->reference); - $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name)); - - if ($resource->options != "frame") { - if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image - $resourcetype = "image"; - $embedded = true; - - } else if ($mimetype == "audio/mp3") { // It's an MP3 audio file - $resourcetype = "mp3"; - $embedded = true; - - } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file - $resourcetype = "mediaplayer"; - $embedded = true; - - } else if ($mimetype == "video/quicktime") { // It's a Quicktime file - $resourcetype = "quicktime"; - $embedded = true; - - } else if ($mimetype == "text/html") { // It's a web page - $resourcetype = "html"; - } - } - - - -/// Form the parse string - if (!empty($resource->alltext)) { - $querys = array(); - $parray = explode(',', $resource->alltext); - foreach ($parray as $fieldstring) { - $field = explode('=', $fieldstring); - $querys[] = urlencode($field[1]).'='.urlencode($this->parameters[$field[0]]['value']); - } - $querystring = implode('&', $querys); - } - - - /// Set up some variables - - $inpopup = !empty($_GET["inpopup"]); - - $fullurl = $resource->reference. '&HIVE_SESSION='.$SESSION->HIVE_SESSION; - if (!empty($querystring)) { - $urlpieces = parse_url($resource->reference); - if (empty($urlpieces['query'])) { - $fullurl .= '?'.$querystring; - } else { - $fullurl .= '&'.$querystring; - } - } - - /// MW check that the HIVE_SESSION is there - if (empty($SESSION->HIVE_SESSION)) { - if ($inpopup) { - print_header($pagetitle, $course->fullname); - } else { - print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); - } - notify('You do not have access to HarvestRoad Hive. This resource is unavailable.'); - if ($inpopup) { - close_window_button(); - } - print_footer('none'); - die; - } - /// MW END - - - /// Print a notice and redirect if we are trying to access a file on a local file system - /// and the config setting has been disabled - if (!$CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { - if ($inpopup) { - print_header($pagetitle, $course->fullname); - } else { - print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); - } - notify(get_string('notallowedlocalfileaccess', 'resource', '')); - if ($inpopup) { - close_window_button(); - } - print_footer('none'); - die; - } - - - /// Check whether this is supposed to be a popup, but was called directly - - if ($resource->popup and !$inpopup) { /// Make a page and a pop-up window - - print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); - - - echo "\n'; - - if (trim(strip_tags($resource->summary))) { - $formatoptions->noclean = true; - print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center"); - } - - $link = "wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true).""; - - echo "

 

"; - echo '

'; - print_string('popupresource', 'resource'); - echo '
'; - print_string('popupresourcelink', 'resource', $link); - echo "

"; - - print_footer($course); - exit; - } - - - /// Now check whether we need to display a frameset - - if (empty($_GET['frameset']) and !$embedded and !$inpopup and $resource->options == "frame") { - echo "\n"; - echo "\n"; - echo ''; - echo ''; - echo "{$course->shortname}: ".strip_tags(format_string($resource->name,true))."\n"; - echo "resource_framesize,*\">"; - echo "id}&type={$resource->type}&frameset=top\" />"; - if (!empty($localpath)) { // Show it like this so we interpose some HTML - echo "id}&type={$resource->type}&inpopup=true\" />"; - } else { - echo ""; - } - echo ""; - echo ""; - exit; - } - - - /// We can only get here once per resource, so add an entry to the log - - add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); - - - /// If we are in a frameset, just print the top of it - - if (!empty($_GET['frameset']) and $_GET['frameset'] == "top") { - print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); - - $options->para = false; - echo '
'.format_text($resource->summary, FORMAT_HTML, $options).'
'; - if (!empty($localpath)) { // Show some help - echo ''; - } - echo ''; - exit; - } - - - /// Display the actual resource - - if ($embedded) { // Display resource embedded in page - $strdirectlink = get_string("directlink", "resource"); - - if ($inpopup) { - print_header($pagetitle); - } else { - print_header($pagetitle, $course->fullname, "$this->navigation framename\" href=\"$fullurl\"> ".format_string($resource->name,true)."", "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self")); - - } - - if ($resourcetype == "image") { - echo "

"; - echo "name,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />"; - echo "

"; - - } else if ($resourcetype == "mp3") { - if (!empty($THEME->resource_mp3player_colors)) { - $c = $THEME->resource_mp3player_colors; // You can set this up in your theme/xxx/config.php - } else { - $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'. - 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'. - 'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes'; - } - $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource'); - $c = htmlentities($c); - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - - - } else if ($resourcetype == "mediaplayer") { - echo "

"; - echo ''; - echo ""; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo "\n'; - echo ''; - echo ''; - echo "

"; - - } else if ($resourcetype == "quicktime") { - - echo "

"; - echo ''; - echo ""; - echo ''; - echo ''; - echo ''; - echo ''; - echo "\n'; - echo ''; - echo ''; - echo "

"; - } - - if (trim($resource->summary)) { - $formatoptions->noclean = true; - print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); - } - - if ($inpopup) { - echo "

($strdirectlink)

"; - } else { - print_spacer(20,20); - print_footer($course); - } - - } else { // Display the resource on it's own - if (!empty($localpath)) { // Show a link to help work around browser security - echo ''; - echo "

($fullurl)

"; - } - redirect($fullurl); - } - -} - - - -/** -* Setup a new repository resource -* -* Display a form to create a new or edit an existing repository resource -* -* @param form object -* @param CFG global object -* @param usehtmleditor global integer -* @param RESOURCE_WINDOW_OPTIONS global array -*/ -function setup($form) { - global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS; - - parent::setup($form); - - $this->set_parameters(); // set the parameter array for the form - - - $strfilename = get_string("location"); - $strnote = get_string("note", "resource"); - $strchooseafile = get_string("chooseafile", "resource"); - $strnewwindow = get_string("newwindow", "resource"); - $strnewwindowopen = get_string("newwindowopen", "resource"); - $strsearch = get_string("searchweb", "resource"); - - foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { - $stringname = "str$optionname"; - $$stringname = get_string("new$optionname", "resource"); - $window->$optionname = ""; - $jsoption[] = "\"$optionname\""; - } - - $frameoption = "\"framepage\""; - $popupoptions = implode(",", $jsoption); - $jsoption[] = $frameoption; - $alloptions = implode(",", $jsoption); - - - - if ($form->instance) { // Re-editing - if (!$form->popup) { - $windowtype = "page"; // No popup text => in page - foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { - $defaultvalue = "resource_popup$optionname"; - $window->$optionname = $CFG->$defaultvalue; - } - } else { - $windowtype = "popup"; - $rawoptions = explode(',', $form->popup); - foreach ($rawoptions as $rawoption) { - $option = explode('=', trim($rawoption)); - $optionname = $option[0]; - $optionvalue = $option[1]; - if ($optionname == 'height' or $optionname == 'width') { - $window->$optionname = $optionvalue; - } else if ($optionvalue) { - $window->$optionname = 'checked="checked"'; - } - } - } - } else { - foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { - $defaultvalue = "resource_popup$optionname"; - - if ($optionname == 'height' or $optionname == 'width') { - $window->$optionname = $CFG->$defaultvalue; - } else if ($CFG->$defaultvalue) { - $window->$optionname = 'checked="checked"'; - } - } - - $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; - if (empty($form->options)) { - $form->options = 'frame'; - $form->reference = $CFG->resource_defaulturl; - } - } - if (empty($form->reference)) { - $form->reference = $CFG->resource_defaulturl; - } - - -/// set the 5 parameter defaults - $alltextfield = array(); - for ($i = 0; $i < $this->maxparameters; $i++) { - $alltextfield[] = array('parameter' => '', - 'parse' => ''); - } - /// load up any stored parameters - if (!empty($form->alltext)) { - $parray = explode(',', $form->alltext); - foreach ($parray as $key => $fieldstring) { - $field = explode('=', $fieldstring); - $alltextfield[$key]['parameter'] = $field[0]; - $alltextfield[$key]['parse'] = $field[1]; - } - } - - - include("$CFG->dirroot/mod/resource/type/repository/repository.html"); - - parent::setup_end(); -} - -//backwards compatible with existing resources -function set_encrypted_parameter() { - global $CFG; - - if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource//type/file/externserverfile.php")) { - include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php"; - if (function_exists(extern_server_file)) { - return extern_server_file($this->resource->reference); - } - } - return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase); -} - -} - -?> +course->lang)) { + $CFG->courselang = $this->course->lang; + } + + if (empty($USER->id)) { // No need to set up parameters + $this->parameters = array(); + return; + } + + $site = get_site(); + + $this->parameters = array( + + 'label1' => array('langstr' => get_string('user'), + 'value' => 'optgroup'), + + 'userid' => array('langstr' => 'id', + 'value' => $USER->id), + 'userusername' => array('langstr' => get_string('username'), + 'value' => $USER->username), + 'userpassword' => array('langstr' => get_string('password'), + 'value' => $USER->password), + 'useridnumber' => array('langstr' => get_string('idnumber'), + 'value' => $USER->idnumber), + 'userfirstname' => array('langstr' => get_string('firstname'), + 'value' => $USER->firstname), + 'userlastname' => array('langstr' => get_string('lastname'), + 'value' => $USER->lastname), + 'userfullname' => array('langstr' => get_string('fullname'), + 'value' => fullname($USER)), + 'useremail' => array('langstr' => get_string('email'), + 'value' => $USER->email), + 'usericq' => array('langstr' => get_string('icqnumber'), + 'value' => $USER->icq), + 'userphone1' => array('langstr' => get_string('phone').' 1', + 'value' => $USER->phone1), + 'userphone2' => array('langstr' => get_string('phone').' 2', + 'value' => $USER->phone2), + 'userinstitution' => array('langstr' => get_string('institution'), + 'value' => $USER->institution), + 'userdepartment' => array('langstr' => get_string('department'), + 'value' => $USER->department), + 'useraddress' => array('langstr' => get_string('address'), + 'value' => $USER->address), + 'usercity' => array('langstr' => get_string('city'), + 'value' => $USER->city), + 'usertimezone' => array('langstr' => get_string('timezone'), + 'value' => get_user_timezone_offset()), + 'userurl' => array('langstr' => get_string('webpage'), + 'value' => $USER->url), + + 'label2' => array('langstr' => "", + 'value' =>'/optgroup'), + 'label3' => array('langstr' => get_string('course'), + 'value' => 'optgroup'), + + 'courseid' => array('langstr' => 'id', + 'value' => $this->course->id), + 'coursefullname' => array('langstr' => get_string('fullname'), + 'value' => $this->course->fullname), + 'courseshortname' => array('langstr' => get_string('shortname'), + 'value' => $this->course->shortname), + 'courseidnumber' => array('langstr' => get_string('idnumber'), + 'value' => $this->course->idnumber), + 'coursesummary' => array('langstr' => get_string('summary'), + 'value' => $this->course->summary), + 'courseformat' => array('langstr' => get_string('format'), + 'value' => $this->course->format), + 'courseteacher' => array('langstr' => get_string('wordforteacher'), + 'value' => $this->course->teacher), + 'courseteachers' => array('langstr' => get_string('wordforteachers'), + 'value' => $this->course->teachers), + 'coursestudent' => array('langstr' => get_string('wordforstudent'), + 'value' => $this->course->student), + 'coursestudents' => array('langstr' => get_string('wordforstudents'), + 'value' => $this->course->students), + + 'label4' => array('langstr' => "", + 'value' =>'/optgroup'), + 'label5' => array('langstr' => get_string('miscellaneous'), + 'value' => 'optgroup'), + + 'lang' => array('langstr' => get_string('preferredlanguage'), + 'value' => current_language()), + 'sitename' => array('langstr' => get_string('fullsitename'), + 'value' => $site->fullname), + 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $CFG), + 'value' => $CFG->wwwroot), + 'currenttime' => array('langstr' => get_string('time'), + 'value' => time()), + 'encryptedcode' => array('langstr' => get_string('encryptedcode'), + 'value' => $this->set_encrypted_parameter()), + + 'label6' => array('langstr' => "", + 'value' =>'/optgroup') + ); + +} + + +/** +* Add new instance of repository resource +* +* Create alltext field before calling base class function. +* +* @param resource object +*/ +function add_instance($resource) { + $optionlist = array(); + + for ($i = 0; $i < $this->maxparameters; $i++) { + $parametername = "parameter$i"; + $parsename = "parse$i"; + if (!empty($resource->$parsename) and $resource->$parametername != "-") { + $optionlist[] = $resource->$parametername."=".$resource->$parsename; + } + } + + $resource->alltext = implode(',', $optionlist); + + return parent::add_instance($resource); +} + + +/** +* Update instance of repository resource +* +* Create alltext field before calling base class function. +* +* @param resource object +*/ +function update_instance($resource) { + $optionlist = array(); + + for ($i = 0; $i < $this->maxparameters; $i++) { + $parametername = "parameter$i"; + $parsename = "parse$i"; + if (!empty($resource->$parsename) and $resource->$parametername != "-") { + $optionlist[] = $resource->$parametername."=".$resource->$parsename; + } + } + + $resource->alltext = implode(',', $optionlist); + + return parent::update_instance($resource); +} + + +/** +* Display the repository resource +* +* Displays a repository resource embedded, in a frame, or in a popup. +* Output depends on type of file resource. +* +* @param CFG global object +*/ +function display() { + global $CFG, $THEME, $SESSION; + +/// Set up generic stuff first, including checking for access + parent::display(); + +/// Set up some shorthand variables + $cm = $this->cm; + $course = $this->course; + $resource = $this->resource; + + + $this->set_parameters(); // set the parameters array + +/////////////////////////////////////////////// + + /// Possible display modes are: + /// File displayed in a frame in a normal window + /// File displayed embedded in a normal page + /// File displayed in a popup window + /// File displayed emebedded in a popup window + + + /// First, find out what sort of file we are dealing with. + require_once($CFG->libdir.'/filelib.php'); + + $querystring = ''; + $resourcetype = ''; + $embedded = false; + $mimetype = mimeinfo("type", $resource->reference); + $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name)); + + if ($resource->options != "frame") { + if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image + $resourcetype = "image"; + $embedded = true; + + } else if ($mimetype == "audio/mp3") { // It's an MP3 audio file + $resourcetype = "mp3"; + $embedded = true; + + } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file + $resourcetype = "mediaplayer"; + $embedded = true; + + } else if ($mimetype == "video/quicktime") { // It's a Quicktime file + $resourcetype = "quicktime"; + $embedded = true; + + } else if ($mimetype == "text/html") { // It's a web page + $resourcetype = "html"; + } + } + + + +/// Form the parse string + if (!empty($resource->alltext)) { + $querys = array(); + $parray = explode(',', $resource->alltext); + foreach ($parray as $fieldstring) { + $field = explode('=', $fieldstring); + $querys[] = urlencode($field[1]).'='.urlencode($this->parameters[$field[0]]['value']); + } + $querystring = implode('&', $querys); + } + + + /// Set up some variables + + $inpopup = !empty($_GET["inpopup"]); + + $fullurl = $resource->reference. '&HIVE_SESSION='.$SESSION->HIVE_SESSION; + if (!empty($querystring)) { + $urlpieces = parse_url($resource->reference); + if (empty($urlpieces['query'])) { + $fullurl .= '?'.$querystring; + } else { + $fullurl .= '&'.$querystring; + } + } + + /// MW check that the HIVE_SESSION is there + if (empty($SESSION->HIVE_SESSION)) { + if ($inpopup) { + print_header($pagetitle, $course->fullname); + } else { + print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); + } + notify('You do not have access to HarvestRoad Hive. This resource is unavailable.'); + if ($inpopup) { + close_window_button(); + } + print_footer('none'); + die; + } + /// MW END + + + /// Print a notice and redirect if we are trying to access a file on a local file system + /// and the config setting has been disabled + if (!$CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { + if ($inpopup) { + print_header($pagetitle, $course->fullname); + } else { + print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); + } + notify(get_string('notallowedlocalfileaccess', 'resource', '')); + if ($inpopup) { + close_window_button(); + } + print_footer('none'); + die; + } + + + /// Check whether this is supposed to be a popup, but was called directly + + if ($resource->popup and !$inpopup) { /// Make a page and a pop-up window + + print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); + + + echo "\n'; + + if (trim(strip_tags($resource->summary))) { + $formatoptions->noclean = true; + print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center"); + } + + $link = "wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true).""; + + echo "

 

"; + echo '

'; + print_string('popupresource', 'resource'); + echo '
'; + print_string('popupresourcelink', 'resource', $link); + echo "

"; + + print_footer($course); + exit; + } + + + /// Now check whether we need to display a frameset + + if (empty($_GET['frameset']) and !$embedded and !$inpopup and $resource->options == "frame") { + echo "\n"; + echo "\n"; + echo ''; + echo ''; + echo "{$course->shortname}: ".strip_tags(format_string($resource->name,true))."\n"; + echo "resource_framesize,*\">"; + echo "id}&type={$resource->type}&frameset=top\" />"; + if (!empty($localpath)) { // Show it like this so we interpose some HTML + echo "id}&type={$resource->type}&inpopup=true\" />"; + } else { + echo ""; + } + echo ""; + echo ""; + exit; + } + + + /// We can only get here once per resource, so add an entry to the log + + add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); + + + /// If we are in a frameset, just print the top of it + + if (!empty($_GET['frameset']) and $_GET['frameset'] == "top") { + print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); + + $options->para = false; + echo '
'.format_text($resource->summary, FORMAT_HTML, $options).'
'; + if (!empty($localpath)) { // Show some help + echo ''; + } + echo ''; + exit; + } + + + /// Display the actual resource + + if ($embedded) { // Display resource embedded in page + $strdirectlink = get_string("directlink", "resource"); + + if ($inpopup) { + print_header($pagetitle); + } else { + print_header($pagetitle, $course->fullname, "$this->navigation framename\" href=\"$fullurl\"> ".format_string($resource->name,true)."", "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self")); + + } + + if ($resourcetype == "image") { + echo "

"; + echo "name,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />"; + echo "

"; + + } else if ($resourcetype == "mp3") { + if (!empty($THEME->resource_mp3player_colors)) { + $c = $THEME->resource_mp3player_colors; // You can set this up in your theme/xxx/config.php + } else { + $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'. + 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'. + 'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes'; + } + $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource'); + $c = htmlentities($c); + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + + + } else if ($resourcetype == "mediaplayer") { + echo "

"; + echo ''; + echo ""; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo "\n'; + echo ''; + echo ''; + echo "

"; + + } else if ($resourcetype == "quicktime") { + + echo "

"; + echo ''; + echo ""; + echo ''; + echo ''; + echo ''; + echo ''; + echo "\n'; + echo ''; + echo ''; + echo "

"; + } + + if (trim($resource->summary)) { + $formatoptions->noclean = true; + print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); + } + + if ($inpopup) { + echo "

($strdirectlink)

"; + } else { + print_spacer(20,20); + print_footer($course); + } + + } else { // Display the resource on it's own + if (!empty($localpath)) { // Show a link to help work around browser security + echo ''; + echo "

($fullurl)

"; + } + redirect($fullurl); + } + +} + + + +/** +* Setup a new repository resource +* +* Display a form to create a new or edit an existing repository resource +* +* @param form object +* @param CFG global object +* @param usehtmleditor global integer +* @param RESOURCE_WINDOW_OPTIONS global array +*/ +function setup($form) { + global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS; + + parent::setup($form); + + $this->set_parameters(); // set the parameter array for the form + + + $strfilename = get_string("location"); + $strnote = get_string("note", "resource"); + $strchooseafile = get_string("chooseafile", "resource"); + $strnewwindow = get_string("newwindow", "resource"); + $strnewwindowopen = get_string("newwindowopen", "resource"); + $strsearch = get_string("searchweb", "resource"); + + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $stringname = "str$optionname"; + $$stringname = get_string("new$optionname", "resource"); + $window->$optionname = ""; + $jsoption[] = "\"$optionname\""; + } + + $frameoption = "\"framepage\""; + $popupoptions = implode(",", $jsoption); + $jsoption[] = $frameoption; + $alloptions = implode(",", $jsoption); + + + + if ($form->instance) { // Re-editing + if (!$form->popup) { + $windowtype = "page"; // No popup text => in page + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "resource_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + } else { + $windowtype = "popup"; + $rawoptions = explode(',', $form->popup); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == 'height' or $optionname == 'width') { + $window->$optionname = $optionvalue; + } else if ($optionvalue) { + $window->$optionname = 'checked="checked"'; + } + } + } + } else { + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "resource_popup$optionname"; + + if ($optionname == 'height' or $optionname == 'width') { + $window->$optionname = $CFG->$defaultvalue; + } else if ($CFG->$defaultvalue) { + $window->$optionname = 'checked="checked"'; + } + } + + $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; + if (empty($form->options)) { + $form->options = 'frame'; + $form->reference = $CFG->resource_defaulturl; + } + } + if (empty($form->reference)) { + $form->reference = $CFG->resource_defaulturl; + } + + +/// set the 5 parameter defaults + $alltextfield = array(); + for ($i = 0; $i < $this->maxparameters; $i++) { + $alltextfield[] = array('parameter' => '', + 'parse' => ''); + } + /// load up any stored parameters + if (!empty($form->alltext)) { + $parray = explode(',', $form->alltext); + foreach ($parray as $key => $fieldstring) { + $field = explode('=', $fieldstring); + $alltextfield[$key]['parameter'] = $field[0]; + $alltextfield[$key]['parse'] = $field[1]; + } + } + + + include("$CFG->dirroot/mod/resource/type/repository/repository.html"); + + parent::setup_end(); +} + +//backwards compatible with existing resources +function set_encrypted_parameter() { + global $CFG; + + if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource//type/file/externserverfile.php")) { + include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php"; + if (function_exists(extern_server_file)) { + return extern_server_file($this->resource->reference); + } + } + return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase); +} + +} + +?>