Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  /**
  18   * @package   moodlecore
  19   * @subpackage backup-imscc
  20   * @copyright 2011 Darko Miletic (dmiletic@moodlerooms.com)
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
  25  
  26  class cc11_basiclti extends entities11 {
  27  
  28      public function generate_node () {
  29  
  30          cc2moodle::log_action('Creating BasicLTI mods');
  31  
  32          $response = '';
  33  
  34          if (!empty(cc2moodle::$instances['instances'][MOODLE_TYPE_BASICLTI])) {
  35              foreach (cc2moodle::$instances['instances'][MOODLE_TYPE_BASICLTI] as $instance) {
  36                  $response .= $this->create_node_course_modules_mod_basiclti($instance);
  37              }
  38          }
  39  
  40          return $response;
  41      }
  42  
  43      private function create_node_course_modules_mod_basiclti ($instance) {
  44  
  45          $sheet_mod_basiclti = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_BASICLTI);
  46  
  47          $topic_data = $this->get_basiclti_data($instance);
  48  
  49          $result = '';
  50          if (!empty($topic_data)) {
  51  
  52              $find_tags = array('[#mod_instance#]'        ,
  53                                 '[#mod_basiclti_name#]'   ,
  54                                 '[#mod_basiclti_intro#]'  ,
  55                                 '[#mod_basiclti_timec#]'  ,
  56                                 '[#mod_basiclti_timem#]'  ,
  57                                 '[#mod_basiclti_toolurl#]',
  58                                 '[#mod_basiclti_orgid#]'  ,
  59                                 '[#mod_basiclti_orgurl#]' ,
  60                                 '[#mod_basiclti_orgdesc#]'
  61                                 );
  62  
  63              $replace_values = array($instance['instance'],
  64                                      $topic_data['title'],
  65                                      $topic_data['description'],
  66                                      time(),time(),
  67                                      $topic_data['launchurl'],
  68                                      $topic_data['orgid'],
  69                                      $topic_data['orgurl'],
  70                                      $topic_data['orgdesc']
  71                                      );
  72  
  73              $result = str_replace($find_tags, $replace_values, $sheet_mod_basiclti);
  74  
  75          }
  76  
  77          return $result;
  78      }
  79  
  80      protected function getValue($node, $default = '') {
  81          $result = $default;
  82          if (is_object($node) && ($node->length > 0) && !empty($node->item(0)->nodeValue)) {
  83              $result = htmlspecialchars(trim($node->item(0)->nodeValue), ENT_COMPAT, 'UTF-8', false);
  84          }
  85          return $result;
  86      }
  87  
  88      public function get_basiclti_data($instance) {
  89  
  90          $topic_data = array();
  91  
  92          $basiclti_file = $this->get_external_xml($instance['resource_indentifier']);
  93  
  94          if (!empty($basiclti_file)) {
  95              $basiclti_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $basiclti_file;
  96              $basiclti_file_dir = dirname($basiclti_file_path);
  97              $basiclti = $this->load_xml_resource($basiclti_file_path);
  98              if (!empty($basiclti)) {
  99                  $xpath = cc2moodle::newx_path($basiclti, cc112moodle::$basicltins);
 100                  $topic_title = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:title'),'Untitled');
 101                  $blti_description = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:description'));
 102                  $launch_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:launch_url'));
 103                  $tool_raw = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:code'),null);
 104                  $tool_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:url'),null);
 105                  $tool_desc = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:description'),null);
 106                  $topic_data['title'      ] = $topic_title;
 107                  $topic_data['description'] = $blti_description;
 108                  $topic_data['launchurl'  ] = $launch_url;
 109                  $topic_data['orgid'      ] = $tool_raw;
 110                  $topic_data['orgurl'     ] = $tool_url;
 111                  $topic_data['orgdesc'    ] = $tool_desc;
 112              }
 113          }
 114  
 115          return $topic_data;
 116      }
 117  
 118  }
 119