Esempio n. 1
0
    public static function render_section($section_passed = [], $key = 0, $ncol = 1, $args = [])
    {
        //check supports
        $support_columns = !isset($args['supports']) || empty($args['supports']) || in_array('columns', $args['supports']);
        $support_fields = !isset($args['supports']) || empty($args['supports']) || in_array('fields', $args['supports']);
        $preview_path = isset($args['preview_path']) && !empty($args['preview_path']) ? $args['preview_path'] : false;
        $id_section = empty($args['id']) ? '' : $args['id'];
        $id_meta_section = !empty($id_section) ? '_' . $id_section : '';
        $id_input = !empty($id_section) ? $id_section . '_' : '';
        if (empty($section_passed)) {
            $section = ['columns' => $ncol, 'title' => '', 'background' => '', 'content' => ['column_1' => '']];
        } else {
            $section = ['columns' => $section_passed['columns'], 'title' => $section_passed['title'], 'background' => $section_passed['background']];
            for ($i = 1; $i <= $section_passed['columns']; $i++) {
                $section['content']['column_' . $i] = $section_passed['content']['column_' . $i];
            }
            if (!empty($section_passed['fields'])) {
                $section['fields'] = $section_passed['fields'];
            }
            if (!empty($section_passed['section_type'])) {
                $section['section_type'] = $section_passed['section_type'];
            }
        }
        ?>
		<div class="box-section<?php 
        echo $section_passed['section_type'] ? ' section_' . $section_passed['section_type'] : '';
        ?>
" data-section-num=<?php 
        echo $key;
        ?>
>
			<input type="hidden" data-section-columns="<?php 
        echo $id_section;
        ?>
" name="<?php 
        echo $id_input;
        ?>
post_section_columns_<?php 
        echo $key;
        ?>
" value="<?php 
        echo $section['columns'];
        ?>
">
			<div class="header-section" >
				<div class="remove_background" data-remove-background="<?php 
        echo $id_section;
        ?>
">x</div>
				<div class="background" data-section-background="<?php 
        echo $id_section;
        ?>
" style="background-image:url(<?php 
        echo stripslashes($section['background']);
        ?>
);">
					<input type="hidden" name="<?php 
        echo $id_input;
        ?>
post_section_background_<?php 
        echo $key;
        ?>
" id="<?php 
        echo $id_input;
        ?>
post_section_background_<?php 
        echo $key;
        ?>
" value="<?php 
        echo $section['background'];
        ?>
" />
				</div>
				<div class="title">
					<input type="text" placeholder="Here the title" class="post_section_title" name="<?php 
        echo $id_input;
        ?>
post_section_title_<?php 
        echo $key;
        ?>
" id="<?php 
        echo $id_input;
        ?>
post_section_title_<?php 
        echo $key;
        ?>
" value="<?php 
        echo stripslashes($section['title']);
        ?>
" >
				</div>
				<div class="controls">
					<button class="button button-small" data-section-expand="<?php 
        echo $id_section;
        ?>
" ><span class="dashicons dashicons-welcome-write-blog"></span></button>
				</div>
				<div style="clear:both;"></div>
			</div>
			<div class="body-section">
				<?php 
        /**
         * check pre render field
         * classic or conditional fields?
         */
        if (isset($args['fields']) && !empty($args['fields'])) {
            if (isset($args['fields'][0]['type'])) {
                /**
                 * Classic list fields
                 */
                echo '<div class="wrap-fields">';
                foreach ($args['fields'] as $field) {
                    $value = isset($section['fields'][$field['id']]) && !empty($section['fields'][$field['id']]) ? $section['fields'][$field['id']] : '';
                    AeriaSection::render_field($field, $key, $value, $id_section);
                }
                echo '</div>';
            } elseif (count($args['fields'])) {
                /**
                 * Relation list fields
                 */
                if (count($args['fields']) === 1) {
                    $value_type = current(array_keys($args['fields']));
                } else {
                    $value_type = isset($section['section_type']) ? $section['section_type'] : '';
                    // get value from general section settings
                    AeriaSection::render_relation_fields($args['fields'], $key, $value_type, $preview_path, $id_section);
                }
                if (!empty($value_type)) {
                    echo '<div class="row-full"><h4>' . strtoupper($args['fields'][$value_type]['description']) . '</h4></div>';
                    echo '<div class="wrap-fields">';
                    foreach ($args['fields'][$value_type]['fields'] as $field) {
                        $value = isset($section['fields'][$field['id']]) && !empty($section['fields'][$field['id']]) ? $section['fields'][$field['id']] : '';
                        AeriaSection::render_field($field, $key, $value, $id_section);
                    }
                    echo '</div>';
                } else {
                    echo '<div class="row-full"><p>Nessuna tipologia di sezione attiva</p></div>';
                }
            }
        }
        if ($support_columns) {
            for ($i = 1; $i <= $section['columns']; $i++) {
                if ($section['columns'] > 1) {
                    echo '<h2>Column ' . $i . '</h2>';
                }
                wp_editor(stripslashes($section['content']['column_' . $i]), $id_meta_section . 'post_section_' . $key . '_' . $i);
            }
        }
        ?>
			</div>
		</div>
	<?php 
    }