Exemplo n.º 1
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;
}
Exemplo n.º 2
0
    }
    if ($abort) {
        return false;
    }
}
checkAuthor('books', 'pages', $data->id);
if (!$abort) {
    $widgets = [];
    $reviewsWidget = "";
    //Validate widgets
    foreach ($data->widgets as $key => $widget) {
        //print_r($data->widgets);
        //echo "<br><br>";
        switch ($widget->type) {
            case "contentgroup":
                $widgets[] = processContentGroup($widget);
                break;
            case "header1":
                $widgets[] = processHeader1($widget);
                break;
            case "textBox":
                $widgets[] = processTextBox($widget);
                break;
            case "sidenote":
                $widgets[] = processSidenote($widget);
                break;
            case "imagewidget":
                $widgets[] = processImageWidget($widget);
                break;
            case "video":
                $widgets[] = processVideo($widget);