public static function embedAssets($originalXml)
    {
        $basedir = dirname($originalXml) . DIRECTORY_SEPARATOR;

        $xmlDocument = new XmlDocument();
        $xmlDocument->load($originalXml, true);

        //get images and object to base64 their src/data
        $images = $xmlDocument->getDocumentComponent()->getComponentsByClassName('img');
        $objects = $xmlDocument->getDocumentComponent()->getComponentsByClassName('object');

        /** @var $image \qtism\data\content\xhtml\Img */
        foreach ($images as $image) {
            $source = $image->getSrc();
            static::validateSource($basedir, $source);
            $image->setSrc(self::secureEncode($basedir, $source));
        }

        /** @var $object \qtism\data\content\xhtml\Object */
        foreach ($objects as $object) {
            $data = $object->getData();
            static::validateSource($basedir, $data);
            $object->setData(self::secureEncode($basedir, $data));
        }

        // save the document to a tempfile
        $newXml = tempnam(sys_get_temp_dir(), 'sharedStimulus_') . '.xml';
        $xmlDocument->save($newXml);
        return $newXml;
    }
public static function embedAssets($originalXml)
    {
        $basedir = dirname($originalXml) . DIRECTORY_SEPARATOR;

        $xmlDocument = new XmlDocument();
        $xmlDocument->load($originalXml, true);

        //get images and object to base64 their src/data
        $images = $xmlDocument->getDocumentComponent()->getComponentsByClassName('img');
        $objects = $xmlDocument->getDocumentComponent()->getComponentsByClassName('object');

        /** @var $image \qtism\data\content\xhtml\Img */
        foreach ($images as $image) {
            $source = $image->getSrc();
            static::validateSource($basedir, $source);
            $image->setSrc(self::secureEncode($basedir, $source));
        }

        /** @var $object \qtism\data\content\xhtml\Object */
        foreach ($objects as $object) {
            $data = $object->getData();
            static::validateSource($basedir, $data);
            $object->setData(self::secureEncode($basedir, $data));
        }

        // save the document to a tempfile
        $newXml = tempnam(sys_get_temp_dir(), 'sharedStimulus_') . '.xml';
        $xmlDocument->save($newXml);
        return $newXml;
    }
public static function embedAssets ( $ originalXml ) { $ basedir = dirname ( $ originalXml ) . DIRECTORY_SEPARATOR ; $ xmlDocument = new XmlDocument ( ) ; $ xmlDocument -> load ( $ originalXml , true ) ; //get images and object to base64 their src/data $ images = $ xmlDocument -> getDocumentComponent ( ) -> getComponentsByClassName ( 'img' ) ; $ objects = $ xmlDocument -> getDocumentComponent ( ) -> getComponentsByClassName ( 'object' ) ; /** @var $image \qtism\data\content\xhtml\Img */ foreach ( $ images as $ image ) { $ source = $ image -> getSrc ( ) ; static :: validateSource ( $ basedir , $ source ) ; $ image -> setSrc ( self :: secureEncode ( $ basedir , $ source ) ) ; } /** @var $object \qtism\data\content\xhtml\Object */ foreach ( $ objects as $ object ) { $ data = $ object -> getData ( ) ; static :: validateSource ( $ basedir , $ data ) ; $ object -> setData ( self :: secureEncode ( $ basedir , $ data ) ) ; } // save the document to a tempfile $ newXml = tempnam ( sys_get_temp_dir ( ) , 'sharedStimulus_' ) . '.xml' ; $ xmlDocument -> save ( $ newXml ) ; return $ newXml ; }
Embed external resources into the XML

@param $originalXml

@return string
@throws InvalidSourcePathException
@throws \common_exception_Error
@throws \qtism\data\storage\xml\XmlStorageException
@throws \tao_models_classes_FileNotFoundException
Embed external resources into the XML