Пример #1
0
function GetDepFilesXML($manifestroot, $fname, &$filenames, &$dcx, $folder)
{
    $nlist = $dcx->nodeList("//img/@src | //attachments/attachment/@href  | //link/@href | //script/@src");
    $css_obj_array = array();
    foreach ($nlist as $nl) {
        $item = $nl->nodeValue;
        $path_parts = pathinfo($item);
        $fname = $path_parts['basename'];
        $ext = array_key_exists('extension', $path_parts) ? $path_parts['extension'] : '';
        if (!is_url($nl->nodeValue)) {
            //$file =   $folder.$nl->nodeValue; // DEPENDERA SI SE QUIERE Q SEA RELATIVO O ABSOLUTO
            $file = $nl->nodeValue;
            toNativePath($file);
            $filenames[] = $file;
        }
    }
    $dcx->registerNS('qti', 'http://www.imsglobal.org/xsd/imscc/ims_qtiasiv1p2.xsd');
    $dcx->resetXpath();
    $nlist = $dcx->nodeList("//qti:mattext | //text");
    $dcx2 = new XMLGenericDocument();
    foreach ($nlist as $nl) {
        if ($dcx2->loadString($nl->nodeValue)) {
            GetDepFilesHTML($manifestroot, $fname, $filenames, $dcx2, $folder);
        }
    }
}
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     foreach ($this->ccnamespaces as $key => $value) {
         $this->registerNS($key, $value);
     }
 }
Пример #3
0
function GetDepFiles($manifestroot, $fname, $folder, &$filenames)
{
    static $types = array('xhtml' => true, 'html' => true, 'htm' => true);
    $extension = strtolower(trim(pathinfo($fname, PATHINFO_EXTENSION)));
    $filenames = array();
    if (isset($types[$extension])) {
        $dcx = new XMLGenericDocument();
        $filename = $manifestroot . $folder . $fname;
        if (!file_exists($filename)) {
            $filename = $manifestroot . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $fname;
        }
        if (file_exists($filename)) {
            $res = $dcx->loadHTMLFile($filename);
            if ($res) {
                GetDepFilesHTML($manifestroot, $fname, $filenames, $dcx, $folder);
            }
        }
    }
}
Пример #4
0
 public function __construct($ccver = cc_version::v1, $activemanifest = null, $parentmanifest = null, $parentparentmanifest = null)
 {
     if (is_int($ccver)) {
         $this->ccversion = $ccver;
         $classname = "cc_version{$ccver}";
         $this->ccobj = new $classname();
         parent::__construct('UTF-8', true);
     } else {
         if (is_object($ccver) && get_class($ccver) == 'cc_manifest') {
             $this->doc = $ccver->doc;
             $this->rootmanifest = $ccver->rootmanifest;
             $this->activemanifest = $activemanifest;
             $this->parentmanifest = $parentmanifest;
             $this->parentparentmanifest = $parentparentmanifest;
             $this->ccversion = $ccver->ccversion;
             $this->ccobj = $ccver;
             $this->register_namespaces_for_xpath();
         }
     }
 }
Пример #5
0
 /**
  *
  * ctor
  * @param  cc_i_item $item
  * @param  cc_i_manifest $manifest
  * @param  string $rootpath
  * @param  string $path
  * @throws InvalidArgumentException
  */
 public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path)
 {
     $rpath = realpath($rootpath);
     if (empty($rpath)) {
         throw new InvalidArgumentException('Invalid path!');
     }
     $rpath2 = realpath($path);
     if (empty($rpath)) {
         throw new InvalidArgumentException('Invalid path!');
     }
     $doc = new XMLGenericDocument();
     if (!$doc->load($path . DIRECTORY_SEPARATOR . $this->defaultfile)) {
         throw new RuntimeException('File does not exist!');
     }
     $this->doc = $doc;
     $this->item = $item;
     $this->manifest = $manifest;
     $this->rootpath = $rpath;
     $this->path = $rpath2;
 }
Пример #6
0
 public function __destruct()
 {
     parent::__destruct();
 }
Пример #7
0
 public static function embedded_mapping($packageroot, $contextid = null)
 {
     $main_file = $packageroot . DIRECTORY_SEPARATOR . 'files.xml';
     $mfile = new XMLGenericDocument();
     if (!$mfile->load($main_file)) {
         return false;
     }
     $query = "/files/file[filename!='.']";
     if (!empty($contextid)) {
         $query .= "[contextid='{$contextid}']";
     }
     $files = $mfile->nodeList($query);
     $depfiles = array();
     foreach ($files as $node) {
         $mainfile = intval($mfile->nodeValue('sortorder', $node));
         $filename = $mfile->nodeValue('filename', $node);
         $filepath = $mfile->nodeValue('filepath', $node);
         $source = $mfile->nodeValue('source', $node);
         $author = $mfile->nodeValue('author', $node);
         $license = $mfile->nodeValue('license', $node);
         $hashedname = $mfile->nodeValue('contenthash', $node);
         $hashpart = substr($hashedname, 0, 2);
         $location = 'files' . DIRECTORY_SEPARATOR . $hashpart . DIRECTORY_SEPARATOR . $hashedname;
         $type = $mfile->nodeValue('mimetype', $node);
         $depfiles[$filepath . $filename] = array($location, $mainfile == 1, strtolower(str_replace(' ', '_', $filename)), $type, $source, $author, $license, strtolower(str_replace(' ', '_', $filepath)));
     }
     return $depfiles;
 }
Пример #8
0
 /**
  *
  * Process the activites and create item structure
  * @param cc_i_item $item
  * @param array $sequence
  * @param string $packageroot - directory path
  * @throws DOMException
  */
 protected static function process_sequence(cc_i_item &$item, cc_i_manifest &$manifest, array $sequence, $packageroot, $outdir)
 {
     $moodle_backup = $packageroot . DIRECTORY_SEPARATOR . 'moodle_backup.xml';
     $doc = new XMLGenericDocument();
     if (!$doc->load($moodle_backup)) {
         return;
     }
     $activities = $doc->nodeList('/moodle_backup/information/contents/activities/activity');
     if (!empty($activities)) {
         $dpp = new XMLGenericDocument();
         foreach ($activities as $activity) {
             $moduleid = $doc->nodeValue('moduleid', $activity);
             if (in_array($moduleid, $sequence)) {
                 //detect activity type
                 $directory = $doc->nodeValue('directory', $activity);
                 $path = $packageroot . DIRECTORY_SEPARATOR . $directory;
                 $module_file = $path . DIRECTORY_SEPARATOR . 'module.xml';
                 if ($dpp->load($module_file)) {
                     $activity_type = $dpp->nodeValue('/module/modulename');
                     $activity_indentation = $dpp->nodeValue('/module/indent');
                     $aitem = self::item_indenter($item, $activity_indentation);
                     $caller = "cc_converter_{$activity_type}";
                     if (class_exists($caller)) {
                         $obj = new $caller($aitem, $manifest, $packageroot, $path);
                         if (!$obj->convert($outdir)) {
                             throw new RuntimeException("failed to convert {$activity_type}");
                         }
                     }
                 }
             }
         }
     }
 }
Пример #9
0
 public function on_generate_feedbacks()
 {
     $general_question_feedback = $this->questions->nodeValue('generalfeedback', $this->question_node);
     if (empty($general_question_feedback)) {
         return;
     }
     $name = 'general_fb';
     //Add question general feedback - the one that should be always displayed
     $result = cc_helpers::process_linked_files($general_question_feedback, $this->manifest, $this->rootpath, $this->contextid, $this->outdir);
     cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $name);
     pkg_resource_dependencies::instance()->add($result[1]);
     $this->general_feedback = $name;
 }
Пример #10
0
 /**
  *
  * Is the element visible in the course?
  * @throws RuntimeException
  * @return bool
  */
 protected function is_visible()
 {
     $tdoc = new XMLGenericDocument();
     if (!$tdoc->load($this->path . DIRECTORY_SEPARATOR . 'module.xml')) {
         throw new RuntimeException('File does not exist!');
     }
     $visible = (int) $tdoc->nodeValue('/module/visible');
     return $visible > 0;
 }