/**
  * Render AJAX request.
  */
 public function render_ajax_request()
 {
     papi_render_property($this);
 }
Esempio n. 2
0
/**
 * Render properties the right way.
 *
 * @param array $properties
 */
function papi_render_properties(array $properties)
{
    if (empty($properties)) {
        return;
    }
    // If it's a tab the tabs class will
    // handle the rendering of the properties.
    if ($properties[0] instanceof Papi_Core_Tab) {
        new Papi_Admin_Meta_Box_Tabs($properties);
    } else {
        ?>
		<table class="papi-table">
			<tbody>
			<?php 
        foreach ($properties as $property) {
            papi_render_property($property);
        }
        ?>
			</tbody>
		</table>
	<?php 
    }
}
    /**
     * Render properties.
     *
     * @param array $row
     * @param array|bool $value
     */
    protected function render_properties($row, $value)
    {
        $has_value = $value !== false;
        $render_layout = $this->get_setting('layout');
        $layout_slug = isset($row['slug']) ? $row['slug'] : false;
        $layout_slug = empty($layout_slug) && isset($value['_layout']) ? $value['_layout'] : $layout_slug;
        $layout_slug = empty($layout_slug) && isset($value[$this->layout_key]) ? $value[$this->layout_key] : $layout_slug;
        $row = isset($row['items']) ? $row['items'] : $row;
        // Render one hidden input for layout slug.
        $this->render_layout_input($layout_slug);
        ?>
			<td class="repeater-column flexible-column <?php 
        echo $render_layout === 'table' ? 'flexible-layout-table' : 'flexible-layout-row';
        ?>
">
				<div class="repeater-content-open">
					<table class="<?php 
        echo $render_layout === 'table' ? 'flexible-table' : 'papi-table';
        ?>
">
						<?php 
        if ($render_layout === 'table') {
            echo '<thead>';
            for ($i = 0, $l = count($row); $i < $l; $i++) {
                // Don't show the property if it's disabled.
                if ($row[$i]->disabled()) {
                    continue;
                }
                echo '<th class="' . ($row[$i]->display() ? '' : 'papi-hide') . '">';
                echo sprintf('<label for="%s">%s</label>', esc_attr($this->html_id($row[$i], $this->counter)), esc_html($row[$i]->title));
                echo '</th>';
            }
            echo '</thead>';
        }
        echo '<tbody>';
        if ($render_layout === 'table') {
            echo '<tr>';
        }
        for ($i = 0, $l = count($row); $i < $l; $i++) {
            // Don't show the property if it's disabled.
            if ($row[$i]->disabled()) {
                continue;
            }
            $render_property = clone $row[$i]->get_options();
            $value_slug = $row[$i]->get_slug(true);
            if ($has_value) {
                if (array_key_exists($value_slug, $value)) {
                    $render_property->value = $value[$value_slug];
                } else {
                    if (array_key_exists($row[$i]->get_slug(), $value)) {
                        $render_property->value = $row[$i]->default_value;
                    } else {
                        continue;
                    }
                }
            }
            $render_property->slug = $this->html_name($render_property, $this->counter);
            $render_property->raw = $render_layout === 'table';
            if ($render_layout === 'table') {
                echo '<td class="' . ($row[$i]->display() ? '' : 'papi-hide') . '">';
            }
            papi_render_property($render_property);
            if ($render_layout === 'table') {
                echo '</td>';
            }
        }
        if ($render_layout === 'table') {
            echo '</tr>';
        }
        echo '</tbody>';
        ?>
					</table>
				</div>
				<div class="repeater-content-closed">
					<?php 
        if ($layout = $this->get_layout($layout_slug)) {
            echo esc_html($layout['title']);
        }
        ?>
				</div>
			</td>
		<?php 
    }
    /**
     * Render properties.
     *
     * @param array $row
     * @param array|bool $value
     */
    protected function render_properties($row, $value)
    {
        $layout = $this->get_setting('layout');
        if ($layout === 'row') {
            ?>
		<td class="repeater-layout-row">
			<div class="repeater-content-open">
				<table class="papi-table">
					<tbody>
		<?php 
        }
        $has_value = $value !== false;
        foreach ($row as $property) {
            // Don't show the property if it's disabled.
            if ($property->disabled()) {
                continue;
            }
            $render_property = clone $property->get_options();
            $value_slug = $property->get_slug(true);
            if ($has_value) {
                if (array_key_exists($value_slug, $value)) {
                    $render_property->value = $value[$value_slug];
                } else {
                    if (array_key_exists($property->get_slug(), $value)) {
                        $render_property->value = $property->default_value;
                    } else {
                        continue;
                    }
                }
            }
            $render_property->slug = $this->html_name($property, $this->counter);
            $render_property->raw = $layout === 'table';
            if ($layout === 'table') {
                echo '<td class="repeater-column ' . ($property->display() ? '' : 'papi-hide') . '">';
                echo '<div class="repeater-content-open">';
                echo sprintf('<label for="%s" class="papi-visually-hidden">%s</label>', esc_attr($this->html_id($property, $this->counter)), esc_html($property->title));
            }
            papi_render_property($render_property);
            if ($layout === 'table') {
                echo '</div>';
                echo '</td>';
            }
        }
        if ($layout === 'row') {
            ?>
					</tbody>
				</table>
			</div>
		</td>
		<?php 
        }
    }