[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/resource/type/file/ -> resource.class.php (source)

   1  <?php // $Id: resource.class.php,v 1.71.2.14 2008/09/26 05:49:06 tjhunt Exp $
   2  
   3  /**
   4  * Extend the base resource class for file resources
   5  */
   6  class resource_file extends resource_base {
   7  
   8      function resource_file($cmid=0) {
   9          parent::resource_base($cmid);
  10      }
  11  
  12      var $parameters;
  13      var $maxparameters = 5;
  14  
  15  
  16      /**
  17      * Sets the parameters property of the extended class
  18      *
  19      * @param    USER  global object
  20      * @param    CFG   global object
  21      */
  22      function set_parameters() {
  23          global $USER, $CFG;
  24  
  25          $site = get_site();
  26  
  27          $littlecfg = new object;       // to avoid some notices later
  28          $littlecfg->wwwroot = $CFG->wwwroot;
  29  
  30  
  31          $this->parameters = array(
  32                  'label2'          => array('langstr' => "",
  33                                             'value'   =>'/optgroup'),
  34                  'label3'          => array('langstr' => get_string('course'),
  35                                             'value'   => 'optgroup'),
  36  
  37                  'courseid'        => array('langstr' => 'id',
  38                                             'value'   => $this->course->id),
  39                  'coursefullname'  => array('langstr' => get_string('fullname'),
  40                                             'value'   => $this->course->fullname),
  41                  'courseshortname' => array('langstr' => get_string('shortname'),
  42                                             'value'   => $this->course->shortname),
  43                  'courseidnumber'  => array('langstr' => get_string('idnumbercourse'),
  44                                             'value'   => $this->course->idnumber),
  45                  'coursesummary'   => array('langstr' => get_string('summary'),
  46                                             'value'   => $this->course->summary),
  47                  'courseformat'    => array('langstr' => get_string('format'),
  48                                             'value'   => $this->course->format),
  49                  'courseteacher'   => array('langstr' => get_string('wordforteacher'),
  50                                             'value'   => $this->course->teacher),
  51                  'courseteachers'  => array('langstr' => get_string('wordforteachers'),
  52                                             'value'   => $this->course->teachers),
  53                  'coursestudent'   => array('langstr' => get_string('wordforstudent'),
  54                                             'value'   => $this->course->student),
  55                  'coursestudents'  => array('langstr' => get_string('wordforstudents'),
  56                                             'value'   => $this->course->students),
  57  
  58                  'label4'          => array('langstr' => "",
  59                                             'value'   =>'/optgroup'),
  60                  'label5'          => array('langstr' => get_string('miscellaneous'),
  61                                             'value'   => 'optgroup'),
  62  
  63                  'lang'            => array('langstr' => get_string('preferredlanguage'),
  64                                             'value'   => current_language()),
  65                  'sitename'        => array('langstr' => get_string('fullsitename'),
  66                                             'value'   => format_string($site->fullname)),
  67                  'serverurl'       => array('langstr' => get_string('serverurl', 'resource', $littlecfg),
  68                                             'value'   => $littlecfg->wwwroot),
  69                  'currenttime'     => array('langstr' => get_string('time'),
  70                                             'value'   => time()),
  71                  'encryptedcode'   => array('langstr' => get_string('encryptedcode'),
  72                                             'value'   => $this->set_encrypted_parameter()),
  73  
  74                  'label6'          => array('langstr' => "",
  75                                             'value'   =>'/optgroup')
  76          );
  77  
  78          if (!empty($USER->id)) {
  79  
  80              $userparameters = array(
  81  
  82                  'label1'          => array('langstr' => get_string('user'),
  83                                             'value'   => 'optgroup'),
  84  
  85                  'userid'          => array('langstr' => 'id',
  86                                             'value'   => $USER->id),
  87                  'userusername'    => array('langstr' => get_string('username'),
  88                                             'value'   => $USER->username),
  89                  'useridnumber'    => array('langstr' => get_string('idnumber'),
  90                                             'value'   => $USER->idnumber),
  91                  'userfirstname'   => array('langstr' => get_string('firstname'),
  92                                             'value'   => $USER->firstname),
  93                  'userlastname'    => array('langstr' => get_string('lastname'),
  94                                             'value'   => $USER->lastname),
  95                  'userfullname'    => array('langstr' => get_string('fullname'),
  96                                             'value'   => fullname($USER)),
  97                  'useremail'       => array('langstr' => get_string('email'),
  98                                             'value'   => $USER->email),
  99                  'usericq'         => array('langstr' => get_string('icqnumber'),
 100                                             'value'   => $USER->icq),
 101                  'userphone1'      => array('langstr' => get_string('phone').' 1',
 102                                             'value'   => $USER->phone1),
 103                  'userphone2'      => array('langstr' => get_string('phone2').' 2',
 104                                             'value'   => $USER->phone2),
 105                  'userinstitution' => array('langstr' => get_string('institution'),
 106                                             'value'   => $USER->institution),
 107                  'userdepartment'  => array('langstr' => get_string('department'),
 108                                             'value'   => $USER->department),
 109                  'useraddress'     => array('langstr' => get_string('address'),
 110                                             'value'   => $USER->address),
 111                  'usercity'        => array('langstr' => get_string('city'),
 112                                             'value'   => $USER->city),
 113                  'usertimezone'    => array('langstr' => get_string('timezone'),
 114                                             'value'   => get_user_timezone_offset()),
 115                  'userurl'         => array('langstr' => get_string('webpage'),
 116                                             'value'   => $USER->url)
 117               );
 118  
 119               $this->parameters = $userparameters + $this->parameters;
 120          }
 121      }
 122  
 123      function add_instance($resource) {
 124          $this->_postprocess($resource);
 125          return parent::add_instance($resource);
 126      }
 127  
 128  
 129      function update_instance($resource) {
 130          $this->_postprocess($resource);
 131          return parent::update_instance($resource);
 132      }
 133  
 134      function _postprocess(&$resource) {
 135          global $RESOURCE_WINDOW_OPTIONS;
 136          $alloptions = $RESOURCE_WINDOW_OPTIONS;
 137  
 138          if (!empty($resource->forcedownload)) {
 139              $resource->popup = '';
 140              $resource->options = 'forcedownload';
 141  
 142          } else if ($resource->windowpopup) {
 143              $optionlist = array();
 144              foreach ($alloptions as $option) {
 145                  $optionlist[] = $option."=".$resource->$option;
 146                  unset($resource->$option);
 147              }
 148              $resource->popup = implode(',', $optionlist);
 149              unset($resource->windowpopup);
 150              $resource->options = '';
 151  
 152          } else {
 153              if (empty($resource->framepage)) {
 154                  $resource->options = '';
 155              } else {
 156                  $resource->options = 'frame';
 157              }
 158              unset($resource->framepage);
 159              $resource->popup = '';
 160          }
 161  
 162          $optionlist = array();
 163          for ($i = 0; $i < $this->maxparameters; $i++) {
 164              $parametername = "parameter$i";
 165              $parsename = "parse$i";
 166              if (!empty($resource->$parsename) and $resource->$parametername != "-") {
 167                  $optionlist[] = $resource->$parametername."=".$resource->$parsename;
 168              }
 169              unset($resource->$parsename);
 170              unset($resource->$parametername);
 171          }
 172  
 173          $resource->alltext = implode(',', $optionlist);
 174      }
 175  
 176  
 177      /**
 178      * Display the file resource
 179      *
 180      * Displays a file resource embedded, in a frame, or in a popup.
 181      * Output depends on type of file resource.
 182      *
 183      * @param    CFG     global object
 184      */
 185      function display() {
 186          global $CFG, $THEME, $USER;
 187  
 188      /// Set up generic stuff first, including checking for access
 189          parent::display();
 190  
 191      /// Set up some shorthand variables
 192          $cm = $this->cm;
 193          $course = $this->course;
 194          $resource = $this->resource;
 195  
 196  
 197          $this->set_parameters(); // set the parameters array
 198  
 199      ///////////////////////////////////////////////
 200  
 201          /// Possible display modes are:
 202          /// File displayed embedded in a normal page
 203          /// File displayed in a popup window
 204          /// File displayed embedded in a popup window
 205          /// File not displayed at all, but downloaded
 206  
 207  
 208          /// First, find out what sort of file we are dealing with.
 209          require_once($CFG->libdir.'/filelib.php');
 210  
 211          $querystring = '';
 212          $resourcetype = '';
 213          $embedded = false;
 214          $mimetype = mimeinfo("type", $resource->reference);
 215          $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
 216  
 217          $formatoptions = new object();
 218          $formatoptions->noclean = true;
 219  
 220          if ($resource->options != "forcedownload") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
 221              if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) {  // It's an image
 222                  $resourcetype = "image";
 223                  $embedded = true;
 224  
 225              } else if ($mimetype == "audio/mp3") {    // It's an MP3 audio file
 226                  $resourcetype = "mp3";
 227                  $embedded = true;
 228  
 229              } else if ($mimetype == "video/x-flv") {    // It's a Flash video file
 230                  $resourcetype = "flv";
 231                  $embedded = true;
 232  
 233              } else if (substr($mimetype, 0, 10) == "video/x-ms") {   // It's a Media Player file
 234                  $resourcetype = "mediaplayer";
 235                  $embedded = true;
 236  
 237              } else if ($mimetype == "video/quicktime") {   // It's a Quicktime file
 238                  $resourcetype = "quicktime";
 239                  $embedded = true;
 240  
 241              } else if ($mimetype == "application/x-shockwave-flash") {   // It's a Flash file
 242                  $resourcetype = "flash";
 243                  $embedded = true;
 244  
 245              } else if ($mimetype == "video/mpeg") {   // It's a Mpeg file
 246                  $resourcetype = "mpeg";
 247                  $embedded = true;
 248  
 249              } else if ($mimetype == "text/html") {    // It's a web page
 250                  $resourcetype = "html";
 251  
 252              } else if ($mimetype == "application/zip") {    // It's a zip archive
 253                  $resourcetype = "zip";
 254                  $embedded = true;
 255  
 256              } else if ($mimetype == 'application/pdf' || $mimetype == 'application/x-pdf') {
 257                  $resourcetype = "pdf";
 258                  $embedded = true;
 259              } else if ($mimetype == "audio/x-pn-realaudio") {   // It's a realmedia file
 260                  $resourcetype = "rm";
 261                  $embedded = true;
 262              } 
 263          }
 264  
 265          $isteamspeak = (stripos($resource->reference, 'teamspeak://') === 0);
 266  
 267      /// Form the parse string
 268          $querys = array();
 269          if (!empty($resource->alltext)) {
 270              $parray = explode(',', $resource->alltext);
 271              foreach ($parray as $fieldstring) {
 272                  list($moodleparam, $urlname) = explode('=', $fieldstring);
 273                  $value = urlencode($this->parameters[$moodleparam]['value']);
 274                  $querys[urlencode($urlname)] = $value;
 275                  $querysbits[] = urlencode($urlname) . '=' . $value;
 276              }
 277              if ($isteamspeak) {
 278                  $querystring = implode('?', $querysbits);
 279              } else {
 280                  $querystring = implode('&amp;', $querysbits);
 281              }
 282          }
 283  
 284  
 285          /// Set up some variables
 286  
 287          $inpopup = optional_param('inpopup', 0, PARAM_BOOL);
 288  
 289          if (resource_is_url($resource->reference)) {
 290              $fullurl = $resource->reference;
 291              if (!empty($querystring)) {
 292                  $urlpieces = parse_url($resource->reference);
 293                  if (empty($urlpieces['query']) or $isteamspeak) {
 294                      $fullurl .= '?'.$querystring;
 295                  } else {
 296                      $fullurl .= '&amp;'.$querystring;
 297                  }
 298              }
 299  
 300          } else if ($CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) {  // Localpath
 301              $localpath = get_user_preferences('resource_localpath', 'D:');
 302              $relativeurl = str_replace(RESOURCE_LOCALPATH, $localpath, $resource->reference);
 303  
 304              if ($querystring) {
 305                  $relativeurl .= '?'.$querystring;
 306              }
 307  
 308              $relativeurl = str_replace('\\', '/', $relativeurl);
 309              $relativeurl = str_replace(' ', '%20', $relativeurl);
 310              $fullurl = 'file:///'.htmlentities($relativeurl);
 311              $localpath = true;
 312  
 313          } else {   // Normal uploaded file
 314              $forcedownloadsep = '?';
 315              if ($resource->options == 'forcedownload') {
 316                  $querys['forcedownload'] = '1';
 317              }
 318              $fullurl = get_file_url($course->id.'/'.$resource->reference, $querys);
 319          }
 320  
 321          /// Print a notice and redirect if we are trying to access a file on a local file system
 322          /// and the config setting has been disabled
 323          if (!$CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) {
 324              if ($inpopup) {
 325                  print_header($pagetitle, $course->fullname);
 326              } else {
 327                  $navigation = build_navigation($this->navlinks, $cm);
 328                  print_header($pagetitle, $course->fullname, $navigation,
 329                          "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm));
 330              }
 331              notify(get_string('notallowedlocalfileaccess', 'resource', ''));
 332              if ($inpopup) {
 333                  close_window_button();
 334              }
 335              print_footer('none');
 336              die;
 337          }
 338  
 339  
 340          /// Check whether this is supposed to be a popup, but was called directly
 341          if ($resource->popup and !$inpopup) {    /// Make a page and a pop-up window
 342              $navigation = build_navigation($this->navlinks, $cm);
 343              print_header($pagetitle, $course->fullname, $navigation,
 344                      "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm));
 345  
 346              echo "\n<script type=\"text/javascript\">";
 347              echo "\n<!--\n";
 348              echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
 349              echo "\n-->\n";
 350              echo '</script>';
 351  
 352              if (trim(strip_tags($resource->summary))) {
 353                  print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center");
 354              }
 355  
 356              $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" "
 357                    . "onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', "
 358                    . "'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
 359  
 360              echo '<div class="popupnotice">';
 361              print_string('popupresource', 'resource');
 362              echo '<br />';
 363              print_string('popupresourcelink', 'resource', $link);
 364              echo '</div>';
 365              print_footer($course);
 366              exit;
 367          }
 368  
 369  
 370          /// Now check whether we need to display a frameset
 371  
 372          $frameset = optional_param('frameset', '', PARAM_ALPHA);
 373          if (empty($frameset) and !$embedded and !$inpopup and ($resource->options == "frame") and empty($USER->screenreader)) {
 374              @header('Content-Type: text/html; charset=utf-8');
 375              echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
 376              echo "<html dir=\"ltr\">\n";
 377              echo '<head>';
 378              echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
 379              echo "<title>" . format_string($course->shortname) . ": ".strip_tags(format_string($resource->name,true))."</title></head>\n";
 380              echo "<frameset rows=\"$CFG->resource_framesize,*\">";
 381              echo "<frame src=\"view.php?id={$cm->id}&amp;type={$resource->type}&amp;frameset=top\" title=\""
 382                   . get_string('modulename','resource')."\"/>";
 383              if (!empty($localpath)) {  // Show it like this so we interpose some HTML
 384                  echo "<frame src=\"view.php?id={$cm->id}&amp;type={$resource->type}&amp;inpopup=true\" title=\"".
 385                          get_string('modulename','resource')."\"/>";
 386              } else {
 387                  echo "<frame src=\"$fullurl\" title=\"".get_string('modulename','resource')."\"/>";
 388              }
 389              echo "</frameset>";
 390              echo "</html>";
 391              exit;
 392          }
 393  
 394  
 395          /// We can only get here once per resource, so add an entry to the log
 396  
 397          add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
 398  
 399  
 400          /// If we are in a frameset, just print the top of it
 401  
 402          if (!empty( $frameset ) and ($frameset == "top") ) {
 403              $navigation = build_navigation($this->navlinks, $cm);
 404              print_header($pagetitle, $course->fullname, $navigation,
 405                      "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
 406  
 407              $options = new object();
 408              $options->para = false;
 409              echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $options).'</div>';
 410              if (!empty($localpath)) {  // Show some help
 411                  echo '<div align="right" class="helplink">';
 412                  link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
 413                          get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
 414                  echo '</div>';
 415              }
 416              print_footer('empty');
 417              exit;
 418          }
 419  
 420  
 421          /// Display the actual resource
 422          if ($embedded) {       // Display resource embedded in page
 423              $strdirectlink = get_string("directlink", "resource");
 424  
 425              if ($inpopup) {
 426                  print_header($pagetitle);
 427              } else {
 428                  $navigation = build_navigation($this->navlinks, $cm);
 429                  print_header_simple($pagetitle, '', $navigation, "", "", true,
 430                      update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self"));
 431  
 432              }
 433  
 434              if ($resourcetype == "image") {
 435                  echo '<div class="resourcecontent resourceimg">';
 436                  echo "<img title=\"".strip_tags(format_string($resource->name,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />";
 437                  echo '</div>';
 438  
 439              } else if ($resourcetype == "mp3") {
 440                  if (!empty($THEME->resource_mp3player_colors)) {
 441                      $c = $THEME->resource_mp3player_colors;   // You can set this up in your theme/xxx/config.php
 442                  } else {
 443                      $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
 444                           'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
 445                           'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes';
 446                  }
 447                  $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
 448                  $c = htmlentities($c);
 449                  $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache
 450                  $cleanurl = addslashes_js($fullurl);
 451  
 452  
 453                  // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins
 454  
 455                  echo '<div class="resourcecontent resourcemp3">';
 456  
 457                  echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'.
 458                       '<script type="text/javascript">'."\n".
 459                       '//<![CDATA['."\n".
 460                         'var FO = { movie:"'.$CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n".
 461                           'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n".
 462                         'UFO.create(FO, "'.$id.'");'."\n".
 463                       '//]]>'."\n".
 464                       '</script>'."\n";
 465  
 466                  echo '<noscript>';
 467  
 468                  echo "<object type=\"audio/mpeg\" data=\"$fullurl\" width=\"600\" height=\"70\">";
 469                  echo "<param name=\"src\" value=\"$fullurl\" />";
 470                  echo '<param name="quality" value="high" />';
 471                  echo '<param name="autoplay" value="true" />';
 472                  echo '<param name="autostart" value="true" />';
 473                  echo '</object>';
 474                  echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
 475  
 476                  echo '</noscript>';
 477                  echo '</div>';
 478  
 479              } else if ($resourcetype == "flv") {
 480                  $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache
 481                  $cleanurl = addslashes_js($fullurl);
 482  
 483  
 484                  // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins
 485  
 486                  echo '<div class="resourcecontent resourceflv">';
 487  
 488                  echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'.
 489                       '<script type="text/javascript">'."\n".
 490                       '//<![CDATA['."\n".
 491                         'var FO = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n".
 492                           'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", quality: "high" };'."\n".
 493                         'UFO.create(FO, "'.$id.'");'."\n".
 494                       '//]]>'."\n".
 495                       '</script>'."\n";
 496  
 497                  echo '<noscript>';
 498  
 499                  echo "<object type=\"video/x-flv\" data=\"$fullurl\" width=\"600\" height=\"400\">";
 500                  echo "<param name=\"src\" value=\"$fullurl\" />";
 501                  echo '<param name="quality" value="high" />';
 502                  echo '<param name="autoplay" value="true" />';
 503                  echo '<param name="autostart" value="true" />';
 504                  echo '</object>';
 505                  echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
 506  
 507                  echo '</noscript>';
 508                  echo '</div>';
 509  
 510              } else if ($resourcetype == "mediaplayer") {
 511                  echo '<div class="resourcecontent resourcewmv">';
 512                  echo '<object type="video/x-ms-wmv" data="' . $fullurl . '">';
 513                  echo '<param name="controller" value="true" />';
 514                  echo '<param name="autostart" value="true" />';
 515                  echo "<param name=\"src\" value=\"$fullurl\" />";
 516                  echo '<param name="scale" value="noScale" />';
 517                  echo "<a href=\"$fullurl\">$fullurl</a>";
 518                  echo '</object>';
 519                  echo '</div>';
 520  
 521              } else if ($resourcetype == "mpeg") {
 522                  echo '<div class="resourcecontent resourcempeg">';
 523                  echo '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
 524                                codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsm p2inf.cab#Version=5,1,52,701"
 525                                type="application/x-oleobject">';
 526                  echo "<param name=\"fileName\" value=\"$fullurl\" />";
 527                  echo '<param name="autoStart" value="true" />';
 528                  echo '<param name="animationatStart" value="true" />';
 529                  echo '<param name="transparentatStart" value="true" />';
 530                  echo '<param name="showControls" value="true" />';
 531                  echo '<param name="Volume" value="-450" />';
 532                  echo '<!--[if !IE]>-->';
 533                  echo '<object type="video/mpeg" data="' . $fullurl . '">';
 534                  echo '<param name="controller" value="true" />';
 535                  echo '<param name="autostart" value="true" />';
 536                  echo "<param name=\"src\" value=\"$fullurl\" />";
 537                  echo "<a href=\"$fullurl\">$fullurl</a>";
 538                  echo '<!--<![endif]-->';
 539                  echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
 540                  echo '<!--[if !IE]>-->';
 541                  echo '</object>';
 542                  echo '<!--<![endif]-->';
 543                  echo '</object>';
 544                  echo '</div>';
 545              } else if ($resourcetype == "rm") {
 546  
 547                  echo '<div class="resourcecontent resourcerm">'; 
 548                  echo '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="320" height="240">';
 549                  echo '<param name="src" value="' . $fullurl . '" />';
 550                  echo '<param name="controls" value="All" />';
 551                  echo '<!--[if !IE]>-->';
 552                  echo '<object type="audio/x-pn-realaudio-plugin" data="' . $fullurl . '" width="320" height="240">';
 553                  echo '<param name="controls" value="All" />';
 554                  echo '<a href="' . $fullurl . '">' . $fullurl .'</a>';
 555                  echo '</object>';
 556                  echo '<!--<![endif]-->';
 557                  echo '</object>';
 558                  echo '</div>'; 
 559  
 560              } else if ($resourcetype == "quicktime") {
 561                  echo '<div class="resourcecontent resourceqt">';
 562  
 563                  echo '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
 564                  echo '        codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
 565                  echo "<param name=\"src\" value=\"$fullurl\" />";
 566                  echo '<param name="autoplay" value="true" />';
 567                  echo '<param name="loop" value="true" />';
 568                  echo '<param name="controller" value="true" />';
 569                  echo '<param name="scale" value="aspect" />';
 570  
 571                  echo '<!--[if !IE]>-->';
 572                  echo "<object type=\"video/quicktime\" data=\"$fullurl\">";
 573                  echo '<param name="controller" value="true" />';
 574                  echo '<param name="autoplay" value="true" />';
 575                  echo '<param name="loop" value="true" />';
 576                  echo '<param name="scale" value="aspect" />';
 577                  echo '<!--<![endif]-->';
 578                  echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
 579                  echo '<!--[if !IE]>-->';
 580                  echo '</object>';
 581                  echo '<!--<![endif]-->';
 582                  echo '</object>';
 583                  echo '</div>';
 584              }  else if ($resourcetype == "flash") {
 585                  echo '<div class="resourcecontent resourceswf">';
 586                  echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
 587                  echo "<param name=\"movie\" value=\"$fullurl\" />";
 588                  echo '<param name="autoplay" value="true" />';
 589                  echo '<param name="loop" value="true" />';
 590                  echo '<param name="controller" value="true" />';
 591                  echo '<param name="scale" value="aspect" />';
 592                  echo '<!--[if !IE]>-->';
 593                  echo "<object type=\"application/x-shockwave-flash\" data=\"$fullurl\">";
 594                  echo '<param name="controller" value="true" />';
 595                  echo '<param name="autoplay" value="true" />';
 596                  echo '<param name="loop" value="true" />';
 597                  echo '<param name="scale" value="aspect" />';
 598                  echo '<!--<![endif]-->';
 599                  echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
 600                  echo '<!--[if !IE]>-->';
 601                  echo '</object>';
 602                  echo '<!--<![endif]-->';
 603                  echo '</object>';
 604                  echo '</div>';
 605  
 606              } elseif ($resourcetype == 'zip') {
 607                  echo '<div class="resourcepdf">';
 608                  echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name) . '</a>';
 609                  echo '</div>';
 610  
 611              } elseif ($resourcetype == 'pdf') {
 612                  echo '<div class="resourcepdf">';
 613                  echo '<object data="' . $fullurl . '" type="application/pdf">';
 614                  echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name) . '</a>';
 615                  echo '</object>';
 616                  echo '</div>';
 617              }
 618  
 619              if (trim($resource->summary)) {
 620                  print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
 621              }
 622  
 623              if ($inpopup) {
 624                  echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$strdirectlink</a>)</div>";
 625                  echo "</div>"; // MDL-12098
 626                  print_footer($course); // MDL-12098
 627              } else {
 628                  print_spacer(20,20);
 629                  print_footer($course);
 630              }
 631  
 632          } else {              // Display the resource on it's own
 633              if (!empty($localpath)) {   // Show a link to help work around browser security
 634                  echo '<div align="right" class="helplink">';
 635                  link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
 636                          get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
 637                  echo '</div>';
 638                  echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$fullurl</a>)</div>";
 639              }
 640              redirect($fullurl);
 641          }
 642  
 643      }
 644  
 645  
 646      //backwards compatible with existing resources
 647      function set_encrypted_parameter() {
 648          global $CFG;
 649  
 650          if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource/type/file/externserverfile.php")) {
 651              include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php";
 652              if (function_exists(extern_server_file)) {
 653                  return extern_server_file($this->resource->reference);
 654              }
 655          }
 656          return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase);
 657      }
 658  
 659      function setup_preprocessing(&$defaults){
 660  
 661          if (isset($defaults['options']) and $defaults['options'] === 'forcedownload') {
 662              $defaults['forcedownload'] = 1;
 663  
 664          } else if (!isset($defaults['popup'])) {
 665              // use form defaults
 666  
 667          } else if (!empty($defaults['popup'])) {
 668              $defaults['windowpopup'] = 1;
 669              if (array_key_exists('popup', $defaults)) {
 670                  $rawoptions = explode(',', $defaults['popup']);
 671                  foreach ($rawoptions as $rawoption) {
 672                      $option = explode('=', trim($rawoption));
 673                      $defaults[$option[0]] = $option[1];
 674                  }
 675              }
 676          } else {
 677              $defaults['windowpopup'] = 0;
 678              if (array_key_exists('options', $defaults)) {
 679                  $defaults['framepage'] = ($defaults['options']=='frame');
 680              }
 681          }
 682          /// load up any stored parameters
 683          if (!empty($defaults['alltext'])) {
 684              $parray = explode(',', $defaults['alltext']);
 685              $i=0;
 686              foreach ($parray as $rawpar) {
 687                  list($param, $varname) = explode('=', $rawpar);
 688                  $defaults["parse$i"] = $varname;
 689                  $defaults["parameter$i"] = $param;
 690                  $i++;
 691              }
 692          }
 693      }
 694  
 695      /**
 696       * TODO document
 697       */
 698      function setup_elements(&$mform) {
 699          global $CFG, $RESOURCE_WINDOW_OPTIONS;
 700  
 701          $this->set_parameters(); // set the parameter array for the form
 702  
 703          $mform->addElement('choosecoursefile', 'reference', get_string('location'));
 704          $mform->setDefault('reference', $CFG->resource_defaulturl);
 705          $mform->addRule('name', null, 'required', null, 'client');
 706  
 707          if (!empty($CFG->resource_websearch)) {
 708              $searchbutton = $mform->addElement('button', 'searchbutton', get_string('searchweb', 'resource').'...');
 709              $buttonattributes = array('title'=>get_string('searchweb', 'resource'), 'onclick'=>"return window.open('"
 710                                . "$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,"
 711                                . "scrollbars,resizable,width=800,height=600');");
 712              $searchbutton->updateAttributes($buttonattributes);
 713          }
 714  
 715          if (!empty($CFG->resource_allowlocalfiles)) {
 716              $lfbutton = $mform->addElement('button', 'localfilesbutton', get_string('localfilechoose', 'resource').'...');
 717              $options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400';
 718              $url = '/mod/resource/type/file/localfile.php?choose=id_reference_value';
 719              $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return openpopup('$url', '"
 720                                . $lfbutton->getName()."', '$options', 0);");
 721              $lfbutton->updateAttributes($buttonattributes);
 722          }
 723  
 724          $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
 725  
 726          $mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource'));
 727          $mform->setHelpButton('forcedownload', array('forcedownload', get_string('forcedownload', 'resource'), 'resource'));
 728          $mform->disabledIf('forcedownload', 'windowpopup', 'eq', 1);
 729  
 730          $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
 731          $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
 732          $mform->setDefault('windowpopup', !empty($CFG->resource_popup));
 733          $mform->disabledIf('windowpopup', 'forcedownload', 'checked');
 734  
 735          $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource'));
 736  
 737          $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource'));
 738          $mform->setDefault('framepage', 0);
 739          $mform->disabledIf('framepage', 'windowpopup', 'eq', 1);
 740          $mform->disabledIf('framepage', 'forcedownload', 'checked');
 741          $mform->setAdvanced('framepage');
 742  
 743          foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
 744              if ($option == 'height' or $option == 'width') {
 745                  $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
 746                  $mform->setDefault($option, $CFG->{'resource_popup'.$option});
 747                  $mform->disabledIf($option, 'windowpopup', 'eq', 0);
 748              } else {
 749                  $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
 750                  $mform->setDefault($option, $CFG->{'resource_popup'.$option});
 751                  $mform->disabledIf($option, 'windowpopup', 'eq', 0);
 752              }
 753              $mform->setAdvanced($option);
 754          }
 755  
 756          $mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
 757  
 758          $options = array();
 759          $options['-'] = get_string('chooseparameter', 'resource').'...';
 760          $optgroup = '';
 761          foreach ($this->parameters as $pname=>$param) {
 762              if ($param['value']=='/optgroup') {
 763                  $optgroup = '';
 764                  continue;
 765              }
 766              if ($param['value']=='optgroup') {
 767                  $optgroup = $param['langstr'];
 768                  continue;
 769              }
 770              $options[$pname] = $optgroup.' - '.$param['langstr'];
 771          }
 772  
 773          for ($i = 0; $i < $this->maxparameters; $i++) {
 774              $parametername = "parameter$i";
 775              $parsename = "parse$i";
 776              $group = array();
 777              $group[] =& $mform->createElement('text', $parsename, '', array('size'=>'12'));//TODO: accessiblity
 778              $group[] =& $mform->createElement('select', $parametername, '', $options);//TODO: accessiblity
 779              $mform->addGroup($group, 'pargroup'.$i, get_string('variablename', 'resource').'='.get_string('parameter', 'resource'), ' ', false);
 780              $mform->setAdvanced('pargroup'.$i);
 781  
 782              $mform->setDefault($parametername, '-');
 783          }
 784      }
 785  
 786  }
 787  
 788  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7