Exemple #1
0
function processVideo($data)
{
    global $abort, $errorArray;
    $data->type = 'video';
    //Check name
    if (isset($data->name)) {
        $data->name = strip_tags($data->name);
    } else {
        $data->name = 'Video';
    }
    //Check key
    if (isset($data->key)) {
        $re = "/^[a-z0-9]{10}\$/";
        //Alphanumeric, and 10 characters
        if (!preg_match($re, $data->key)) {
            $abort = true;
            $errorArray[] = "Invalid key for " . $data->name . " widget.";
        }
    }
    //Check title
    if (isset($data->title)) {
        $data->title = strip_tags($data->title);
    } else {
        $data->title = 'Sample title';
    }
    //Check description
    if (isset($data->desc)) {
        $data->desc = htmLawed($data->desc, array('safe' => 1, 'elements' => 'a', 'deny_attribute' => '* -href'));
        $data->desc = str_replace(" />", ">", $data->desc);
    } else {
        $data->desc = "";
    }
    //Check if valid YouTube url source
    if (!empty($data->url)) {
        $pattern = "/(?:https?:)?(?:\\/\\/)?(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/(?:embed\\/)?(?:watch\\?v=)?([a-zA-Z0-9_-]+)(?:\\?.+)?(?:&.+)?\$/";
        //Get YouTube video ID
        if (preg_match($pattern, $data->url)) {
            $data->url = preg_replace($pattern, "//www.youtube.com/embed/\$1?rel=0&showinfo=0", $data->url);
        } else {
            $abort = true;
            $errorArray[] = "YouTube video URL required for " . $data->name . " widget.";
        }
    } else {
        $data->url = "";
    }
    $data = checkAlignment($data);
    //From alignOptions.php
    //Check index is a number
    if (!empty($data->index)) {
        if (!filter_var($data->index, FILTER_VALIDATE_INT) || $data->index < 0) {
            unset($data->index);
        }
    } else {
        //Index is optional
    }
    //Remove any invalid keys
    $validKeys = (object) array('type' => '', 'name' => '', 'key' => '', 'title' => '', 'desc' => '', 'url' => '', 'align' => '', 'margin' => '', 'index' => '');
    $data = (object) array_intersect_key(get_object_vars($data), get_object_vars($validKeys));
    return $data;
}
Exemple #2
0
function processModel3d($data)
{
    global $abort, $errorArray;
    $data->type = 'model3d';
    //Check name
    if (isset($data->name)) {
        $data->name = strip_tags($data->name);
    } else {
        $data->name = '3D Model';
    }
    //Check key
    if (isset($data->key)) {
        $re = "/^[a-z0-9]{10}\$/";
        //Alphanumeric, and 10 characters
        if (!preg_match($re, $data->key)) {
            $abort = true;
            $errorArray[] = "Invalid key for " . $data->name . " widget.";
        }
    }
    //Check title
    if (isset($data->title)) {
        $data->title = strip_tags($data->title);
    } else {
        $data->title = '3D model title';
    }
    //Check description
    if (isset($data->desc)) {
        $data->desc = htmLawed($data->desc, array('safe' => 1, 'elements' => 'a', 'deny_attribute' => '* -href'));
        $data->desc = str_replace(" />", ">", $data->desc);
    } else {
        $data->desc = "";
    }
    //Check if valid Sketchfab url source
    if (!empty($data->url)) {
        $pattern = "/(?:https?:)?(?:\\/\\/)?(?:www\\.)?(?:sketchfab\\.com\\/models\\/)([a-z0-9]+)(?:.+)?/";
        //Get YouTube video ID
        if (preg_match($pattern, $data->url)) {
            $data->url = preg_replace($pattern, "https://sketchfab.com/models/\$1/embed", $data->url);
        } else {
            $abort = true;
            $errorArray[] = "Sketchfab URL required for " . $data->name . " widget.";
        }
    } else {
        $data->url = "";
    }
    $data = checkAlignment($data);
    //From alignOptions.php
    //Check index is a number
    if (!empty($data->index)) {
        if (!filter_var($data->index, FILTER_VALIDATE_INT) || $data->index < 0) {
            unset($data->index);
        }
    } else {
        //Index is optional
    }
    //Remove any invalid keys
    $validKeys = (object) array('type' => '', 'name' => '', 'key' => '', 'title' => '', 'desc' => '', 'url' => '', 'align' => '', 'margin' => '', 'index' => '');
    $data = (object) array_intersect_key(get_object_vars($data), get_object_vars($validKeys));
    return $data;
}
Exemple #3
0
function processImageWidget($data)
{
    global $abort, $errorArray;
    $data->type = 'imagewidget';
    //Check name
    if (isset($data->name)) {
        $data->name = strip_tags($data->name);
    } else {
        $data->name = 'Image';
    }
    //Check key
    if (isset($data->key)) {
        $re = "/^[a-z0-9]{10}\$/";
        //Alphanumeric, and 10 characters
        if (!preg_match($re, $data->key)) {
            $abort = true;
            $errorArray[] = "Invalid key for " . $data->name . " widget.";
        }
    }
    //Check title
    if (isset($data->title)) {
        $data->title = strip_tags($data->title);
    } else {
        $data->title = 'Sample title';
    }
    //Check description
    if (isset($data->desc)) {
        $data->desc = htmLawed($data->desc, array('safe' => 1, 'elements' => 'a', 'deny_attribute' => '* -href'));
        $data->desc = str_replace(" />", ">", $data->desc);
    } else {
        $data->desc = "";
    }
    //Check image source
    if (!empty($data->imgSrc)) {
        if (!file_exists(ROOT_PATH . ltrim($data->imgSrc, '/')) && !file_exists($data->imgSrc)) {
            $abort = true;
            $errorArray[] = $data->name . " image source not found.";
        }
    } else {
        $abort = true;
        $errorArray[] = "Image source required for " . $data->name . " widget.";
    }
    $data = checkAlignment($data);
    //From alignOptions.php
    //Check index is a number
    if (!empty($data->index)) {
        if (!filter_var($data->index, FILTER_VALIDATE_INT) || $data->index < 0) {
            unset($data->index);
        }
    } else {
        //Index is optional
    }
    //Remove any invalid keys
    $validKeys = (object) array('type' => '', 'name' => '', 'key' => '', 'title' => '', 'desc' => '', 'imgSrc' => '', 'align' => '', 'margin' => '', 'index' => '');
    $data = (object) array_intersect_key(get_object_vars($data), get_object_vars($validKeys));
    return $data;
}
function crossRepresentationProcess()
{
    global $Period_arr, $foldername, $locate, $string_info, $foldername;
    for ($i = 0; $i < sizeof($Period_arr); $i++) {
        $timeoffset = 0;
        $timescale = 1;
        $AdaptationSetAttr = $Period_arr[$i];
        if (!empty($AdaptationSetAttr['segmentAlignment'])) {
            //check is segment alignment supported within mpd
            $segmentAlignment = $AdaptationSetAttr['segmentAlignment'];
        } else {
            $segmentAlignment = "false";
        }
        if (!empty($AdaptationSetAttr['subsegmentAlignment'])) {
            //check sub-segment alignment
            $subsegmentAlignment = $AdaptationSetAttr['subsegmentAlignment'];
        } else {
            $subsegmentAlignment = "false";
        }
        if (!empty($AdaptationSetAttr['bitstreamSwitching'])) {
            // check if bit-stream switching is supported
            $bitstreamSwitching = $AdaptationSetAttr['bitstreamSwitching'];
        } else {
            $bitstreamSwitching = "false";
        }
        if (!($opfile = fopen($locate . "/Adapt" . $i . "_infofile.txt", 'w'))) {
            echo "Error opening cross-representation checks file" . "./temp/" . $foldername . "/Adapt" . $i . "_infofile.txt";
            return;
        }
        fprintf($opfile, "Cross representation checks for adaptation set with id \"%s\":\n", $AdaptationSetAttr['id']);
        if ($segmentAlignment == "true" || $subsegmentAlignment == "true" || $bitstreamSwitching == "true") {
            $leafInfo = array();
            for ($j = 0; $j < sizeof($AdaptationSetAttr['Representation']['bandwidth']); $j++) {
                $timescale = 1;
                //set timescale to default value
                $timeoffset = 0;
                // set offset to default value
                if (!empty($AdaptationSetAttr['SegmentTemplate']['timescale'])) {
                    // check if timescale exist in mpd in adaptationset level
                    $timescale = $AdaptationSetAttr['SegmentTemplate']['timescale'];
                }
                if (!empty($AdaptationSetAttr['SegmentTemplate']['presentationTimeOffset'])) {
                    // check if presentation time offset exist in adapatationset level
                    $timeoffset = $AdaptationSetAttr['SegmentTemplate']['presentationTimeOffset'];
                }
                if (!empty($AdaptationSetAttr['Representation']['SegmentTemplate'][$j]['timescale'])) {
                    //check time scale in presentation level
                    $timescale = $AdaptationSetAttr['Representation']['SegmentTemplate'][$j]['timescale'];
                }
                if (!empty($AdaptationSetAttr['Representation']['SegmentTemplate'][$j]['presentationTimeOffset'])) {
                    //check in segment template presentationtimeoffset in presentation level
                    $timeoffset = $AdaptationSetAttr['Representation']['SegmentTemplate'][$j]['presentationTimeOffset'];
                }
                if (!empty($AdaptationSetAttr['Representation']['presentationTimeOffset'][$j])) {
                    //check presentationtimeoffset in representationlevel
                    $timeoffset = $AdaptationSetAttr['Representation']['presentationTimeOffset'][$j];
                }
                $offsetmod = $timeoffset / $timescale;
                // calculate presentationtimeoffset relative to timescale (in seconds)
                $leafInfo[$j] = loadLeafInfoFile("/Adapt" . $i . "rep" . $j . "_infofile.txt", $offsetmod);
                // load values within infofile
                $leafInfo[$j]['id'] = $AdaptationSetAttr['Representation']['id'][$j];
                //get representation ID
            }
            for ($j = 0; $j < sizeof($AdaptationSetAttr['Representation']['bandwidth']) - 1; $j++) {
                for ($k = $j + 1; $k < sizeof($AdaptationSetAttr['Representation']['bandwidth']); $k++) {
                    checkAlignment($leafInfo[$j], $leafInfo[$k], $opfile, $segmentAlignment, $subsegmentAlignment, $bitstreamSwitching);
                    // check alignment
                }
            }
        }
        fprintf($opfile, "Checks completed.\n");
        fclose($opfile);
        $temp_string = str_replace(array('$Template$'), array("Adapt" . $i . "_infofile"), $string_info);
        // place infofile data within HTML string
        file_put_contents($locate . '/' . "Adapt" . $i . "_infofile.html", $temp_string);
        // convert HTML string to HTML file
    }
}
Exemple #5
0
function processSidenote($data)
{
    //Check type
    $data->type = 'sidenote';
    //Check name
    if (isset($data->name)) {
        $data->name = strip_tags($data->name);
    } else {
        $data->name = 'Sidenote';
    }
    //Check key
    if (isset($data->key)) {
        $re = "/^[a-z0-9]{10}\$/";
        //Alphanumeric, and 10 characters
        if (!preg_match($re, $data->key)) {
            $abort = true;
            $errorArray[] = "Invalid key for " . $data->name . " widget.";
        }
    }
    //Check title
    if (isset($data->title)) {
        $data->title = strip_tags($data->title);
    } else {
        $data->title = 'Sample title';
    }
    //Check text
    if (isset($data->text)) {
        $data->text = htmLawed($data->text, array('safe' => 1, 'elements' => '*', 'deny_attribute' => ''));
        $data->text = str_replace(" />", ">", $data->text);
    } else {
        $data->text = "";
    }
    //Check style
    if (!empty($data->style)) {
        $ds = $data->style;
        if ($ds !== 'red' && $ds !== 'blue' && $ds !== 'green' && $ds !== 'white') {
            $data->style = 'white';
            //Invalid style, reset to white.
        }
    } else {
        $data->style = "white";
    }
    //Check maxHeight is a number
    if (!empty($data->maxHeight)) {
        if (!filter_var($data->maxHeight, FILTER_VALIDATE_INT) || $data->maxHeight < 0) {
            unset($data->maxHeight);
        }
    } else {
        //maxHeight is optional
    }
    //Check index is a number
    if (!empty($data->index)) {
        if (!filter_var($data->index, FILTER_VALIDATE_INT) || $data->index < 0) {
            unset($data->index);
        }
    } else {
        //index is optional
    }
    $data = checkAlignment($data);
    //From alignOptions.php
    //Remove any invalid keys
    $validKeys = (object) array('type' => '', 'name' => '', 'key' => '', 'title' => '', 'text' => '', 'style' => '', 'maxHeight' => '', 'index' => '', 'align' => '', 'margin' => '');
    $data = (object) array_intersect_key(get_object_vars($data), get_object_vars($validKeys));
    return $data;
}
Exemple #6
0
function processContentGroup($data)
{
    //Check type
    /*		echo "Data:<br><br>";
    		print_r($data);
    		echo "<br><br>";*/
    $data->type = 'contentgroup';
    //Check contentType
    if (isset($data->contentType)) {
        switch ($data->contentType) {
            case "accordion":
                $defaultName = 'Accordion';
                $defaultSectionName = 'Accordion Section ';
                break;
            case "carousel":
                $defaultName = 'Carousel';
                $defaultSectionName = 'Carousel Slide ';
                break;
            case "sidenote":
                $defaultName = 'Sidenote';
                $defaultSectionName = 'none';
                break;
            default:
                $abort = true;
                $errorArray[] = "Invalid content type for " . $data->name . " widget.";
        }
    }
    //Check name
    if (isset($data->name)) {
        $data->name = strip_tags($data->name);
    } else {
        $data->name = $defaultName;
    }
    //Check key
    if (isset($data->key)) {
        $re = "/^[a-z0-9]{10}\$/";
        //Alphanumeric, and 10 characters
        if (!preg_match($re, $data->key)) {
            $abort = true;
            $errorArray[] = "Invalid key for " . $data->name . " widget.";
        }
    }
    //Check title
    if (isset($data->title)) {
        $data->title = strip_tags($data->title);
    } else {
        $data->title = 'Sample title';
    }
    //Validate sections
    $validSections = [];
    for ($i = 0; $i < count($data->sections); $i++) {
        //Validate name
        if (isset($data->sections[$i]->name)) {
            $sectionName = strip_tags($data->sections[$i]->name);
        } else {
            $sectionName = $defaultSectionName + ($i + 1);
        }
        //Validate widgets
        $sectionWidgets = [];
        for ($j = 0; $j < count($data->sections[$i]->widgets); $j++) {
            $widget = $data->sections[$i]->widgets[$j];
            if (isset($widget->type)) {
                switch ($widget->type) {
                    case "contentGroup":
                        $sectionWidgets[] = processContentGroup($widget);
                        break;
                    case "textBox":
                        $sectionWidgets[] = processTextBox($widget);
                        break;
                    case "imagewidget":
                        $sectionWidgets[] = processImageWidget($widget);
                        break;
                    case "video":
                        $sectionWidgets[] = processVideo($widget);
                        break;
                    case "model3d":
                        $sectionWidgets[] = processModel3d($widget);
                        break;
                    case "embeddocument":
                        $sectionWidgets[] = processEmbedDocument($widget);
                        break;
                    default:
                        break;
                }
            }
        }
        $validSections[] = (object) ['name' => $sectionName, 'widgets' => $sectionWidgets];
    }
    $data->sections = $validSections;
    //Check maxHeight is a number
    if (!empty($data->maxHeight)) {
        if (!filter_var($data->maxHeight, FILTER_VALIDATE_INT) || $data->maxHeight < 0) {
            unset($data->maxHeight);
        }
    } else {
        //maxHeight is optional
    }
    //Check index is a number
    if (!empty($data->index)) {
        if (!filter_var($data->index, FILTER_VALIDATE_INT) || $data->index < 0) {
            unset($data->index);
        }
    } else {
        //index is optional
    }
    $data = checkAlignment($data);
    //From alignOptions.php
    //Remove any invalid keys
    $validKeys = (object) array('type' => '', 'name' => '', 'contentType' => '', 'key' => '', 'title' => '', 'sections' => '', 'maxHeight' => '', 'index' => '', 'align' => '', 'margin' => '');
    $data = (object) array_intersect_key(get_object_vars($data), get_object_vars($validKeys));
    /*
    		print_r($data);
    		echo "<br><br>";*/
    return $data;
}