Add mvconfig tag
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -34,6 +34,28 @@ class GlModelHooks {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MWHook: Called when the parser initializes for the first time
|
||||
*
|
||||
* @param Parser $parser: Parser object being initialized
|
||||
*/
|
||||
static function onParserFirstCallInit( $parser ) {
|
||||
$parser->setHook('mvconfig', array( __CLASS__, 'renderConfigTag'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the config json in a <pre> tag
|
||||
*
|
||||
* @param $input The text inside the custom tag
|
||||
* @param array $args Any attributes given in the tag
|
||||
* @param Parser $parser The parser object
|
||||
* @param PPFrame $frame The parent frame calling the parser
|
||||
* @return string HTML string of output
|
||||
*/
|
||||
static function renderConfigTag( $input, array $args, $parser, $frame ) {
|
||||
return '<pre mvconfig>' . $input . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* MWHook: Load the js and css modules if model-viewer element is found in the html output
|
||||
*
|
||||
@@ -110,7 +132,7 @@ class GlModelHooks {
|
||||
public static function onUploadFormBeforeProcessing( $uploadFormObj ) {
|
||||
$uploadFormObj->mComment .= <<<CONF
|
||||
|
||||
<pre>
|
||||
<mvconfig>
|
||||
{
|
||||
"viewerConfig": {
|
||||
"default": {
|
||||
@@ -120,7 +142,7 @@ class GlModelHooks {
|
||||
"annotations": {},
|
||||
"annotationSets": {}
|
||||
}
|
||||
</pre>
|
||||
</mvconfig>
|
||||
CONF;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -47,9 +47,10 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
||||
*/
|
||||
public function toHtml($options = []) {
|
||||
$descriptText = $this->file->getDescriptionText();
|
||||
preg_match('/<pre mvconfig.*?>([\S\s]*?)<\/pre>/',$descriptText,$modelDescript);
|
||||
$metadata = json_decode($modelDescript[1], true);
|
||||
|
||||
if ($this->thumb) {
|
||||
preg_match('/<pre>([\S\s]*?)<\/pre>/',$descriptText,$modelDescript);
|
||||
$metadata = json_decode($modelDescript[1], true);
|
||||
$poster = $metadata['viewerConfig'][$this->view]['poster'] ?? false;
|
||||
|
||||
if ($poster) {
|
||||
@@ -78,7 +79,7 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
||||
$this->parameters['preview'] = $options['preview'];
|
||||
}
|
||||
|
||||
return self::buildViewer($descriptText,$this->url,$this->parameters);
|
||||
return self::buildViewer($metadata,$this->url,$this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,15 +89,13 @@ class GlModelTransformOutput extends MediaTransformOutput {
|
||||
* and produces the html string for the model-viewer and all relevant child
|
||||
* elements.
|
||||
*
|
||||
* @param string $inText The metadata text which must include a json formatted string inside a pre tag
|
||||
* @param string $metadata The metadata object parsed from the text
|
||||
* @param string $srcUrl The full url pointing to the model file
|
||||
* @param array $frameParams The additional user defined parameters for the viewer such as hotspot and view classes
|
||||
* @return string Html string of the complete model-viewer element inside a div container
|
||||
*/
|
||||
private function buildViewer($inText, $srcUrl, $viewParams) {
|
||||
private function buildViewer($metadata, $srcUrl, $viewParams) {
|
||||
//Gather basic data
|
||||
preg_match('/<pre>([\S\s]*?)<\/pre>/',$inText,$modelDescript);
|
||||
$metadata = json_decode($modelDescript[1], true);
|
||||
$hsSet = (isset($metadata['annotationSets']) && isset($metadata['annotationSets'][$this->hsset])) ? $this->hsset : 'default';
|
||||
$view = (isset($metadata['viewerConfig']) && isset($metadata['viewerConfig'][$this->view])) ? $this->view : 'default';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user