/**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = papi_cast_string_value($this->get_value());
     $options_html = [];
     // Override selected setting with
     // database value if not empty.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     $classes = 'papi-fullwidth';
     if ($settings->select2) {
         $classes .= ' papi-component-select2';
     }
     if (!empty($settings->placeholder)) {
         $options_html[] = papi_html_tag('option', ['value' => '', $settings->placeholder]);
     }
     // Create option html tags for all items.
     foreach ($this->get_items() as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         if (papi_is_empty($key)) {
             continue;
         }
         $options_html[] = papi_html_tag('option', ['selected' => $value === $settings->selected ? 'selected' : null, 'value' => $value, papi_convert_to_string($key)]);
     }
     papi_render_html_tag('select', ['class' => $classes, 'data-allow-clear' => true, 'data-placeholder' => $settings->placeholder, 'data-width' => '100%', 'id' => $this->html_id(), 'name' => $this->html_name(), $options_html]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = $this->get_value();
     $settings_json = ['i18n' => ['previousMonth' => __('Previous Month', 'papi'), 'nextMonth' => __('Next Month', 'papi'), 'midnight' => __('Midnight', 'papi'), 'months' => [__('January', 'papi'), __('February', 'papi'), __('March', 'papi'), __('April', 'papi'), __('May', 'papi'), __('June', 'papi'), __('July', 'papi'), __('August', 'papi'), __('September', 'papi'), __('October', 'papi'), __('November', 'papi'), __('December', 'papi')], 'noon' => __('Noon', 'papi'), 'weekdays' => [__('Sunday', 'papi'), __('Monday', 'papi'), __('Tuesday', 'papi'), __('Wednesday', 'papi'), __('Thursday', 'papi'), __('Friday', 'papi'), __('Saturday', 'papi')], 'weekdaysShort' => [__('Sun', 'papi'), __('Mon', 'papi'), __('Tue', 'papi'), __('Wed', 'papi'), __('Thu', 'papi'), __('Fri', 'papi'), __('Sat', 'papi')]]];
     // Remove i18n setting if it exists.
     if (isset($settings->i18n)) {
         unset($settings->i18n);
     }
     // Remove default time format if show time is false.
     if (isset($settings->show_time) && !$settings->show_time && isset($settings->format)) {
         $settings->format = trim(str_replace('hh:mm:ss', '', $settings->format));
     }
     // Convert all sneak case key to camel case.
     foreach ((array) $settings as $key => $val) {
         if (!is_string($key)) {
             continue;
         }
         if ($key = papi_camel_case($key)) {
             $settings_json[$key] = $val;
         }
     }
     // Papi has `use24Hours` as key and Pikaday has `use24hour`.
     // This code will fix it.
     if (isset($settings_json['use24Hours'])) {
         $settings_json['use24hour'] = $settings_json['use24Hours'];
         unset($settings_json['use24Hours']);
     }
     papi_render_html_tag('input', ['class' => 'papi-property-datetime', 'data-settings' => (object) $settings_json, 'id' => $this->html_id(), 'name' => $this->html_name(), 'type' => 'text', 'value' => $value]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $options = $this->get_options();
     papi_render_html_tag('div', ['class' => 'papi-property-divider', 'data-papi-rule' => $this->html_name(), sprintf('<h3><span>%s</span></h3>', $options->title)]);
     if (!papi_is_empty($options->description)) {
         echo sprintf('<p>%s</p>', $options->description);
     }
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     papi_render_html_tag('input', ['class' => $settings->mediauploader ? 'papi-url-media-input' : null, 'id' => $this->html_id(), 'name' => $this->html_name(), 'type' => 'url', 'value' => $this->get_value()]);
     if ($settings->mediauploader) {
         echo '&nbsp;';
         papi_render_html_tag('input', ['class' => 'button papi-url-media-button', 'data-papi-action' => 'mediauploader', 'id' => $this->html_id(), 'name' => $this->html_name() . '_button', 'type' => 'button', 'value' => __('Select file', 'papi')]);
     }
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $options = $this->get_options();
     $text = '';
     $options->description = $options->slug;
     if (!papi_is_empty($options->description)) {
         $text = sprintf('<p>%s</p>', $options->description);
     }
     papi_render_html_tag('div', ['class' => 'papi-property-divider', 'data-papi-rule' => esc_attr($this->html_name()), sprintf('<h3><span>%s</span></h3>%s', esc_html($options->title), $text)]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $html = papi_maybe_get_callable_value($settings->html);
     if ($settings->save) {
         $value = $this->get_value();
         if (!empty($value) && is_string($value)) {
             $html = $value;
         }
         papi_render_html_tag('input', ['name' => esc_attr($this->html_name()), 'type' => 'hidden', 'value' => $html]);
     }
     papi_render_html_tag('div', ['data-papi-rule' => esc_attr($this->html_name()), 'class' => 'property-html', $html]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = $this->get_value();
     // If range type is used change the default values if empty.
     if ($settings->type === 'range') {
         $settings->max = papi_is_empty($settings->max) ? 100 : $settings->max;
         $settings->min = papi_is_empty($settings->min) ? 0 : $settings->min;
         $settings->step = papi_is_empty($settings->step) ? 1 : $settings->step;
     }
     if ($settings->min !== 0 && $value < $settings->min) {
         $value = $settings->min;
     }
     papi_render_html_tag('input', ['id' => $this->html_id(), 'max' => $settings->max, 'min' => $settings->min, 'name' => $this->html_name(), 'step' => $settings->step, 'type' => $settings->type, 'value' => $value]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = papi_cast_string_value($this->get_value());
     // Override selected setting with
     // database value if not null.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     foreach ($settings->items as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         papi_render_html_tag('label', ['class' => 'light', 'for' => $this->html_id($key), papi_render_html_tag('input', ['id' => $this->html_id($key), 'name' => $this->html_name(), 'type' => 'radio', 'checked' => $value === $settings->selected ? 'checked' : null, 'value' => $value]), papi_convert_to_string($key)]);
         papi_render_html_tag('br');
     }
 }
    /**
     * Add form fields to edit tags page.
     */
    public function add_form_fields()
    {
        $html_name = esc_attr(papi_get_page_type_key());
        $taxonomy = papi_get_qs('taxonomy');
        $taxonomy_object = get_taxonomy($taxonomy);
        // Get only the taxonomy types that has the taxonomy.
        $taxonomy_types = array_filter($this->taxonomy_types, function ($taxonomy_type) use($taxonomy) {
            return in_array($taxonomy, $taxonomy_type->taxonomy, true) && $taxonomy_type->display($taxonomy);
        });
        $taxonomy_types = array_values($taxonomy_types);
        // Do not display empty select if no taxonomy types.
        if (empty($taxonomy_types)) {
            return;
        }
        // Prepare taxonomy types with standard taxonomy type.
        $taxonomy_types = $this->prepare_taxonomy_types($taxonomy_types);
        // Render a dropdown if more than one taxonomy types
        // exists on the taxonomy.
        if (count($taxonomy_types) > 1) {
            ?>
			<div class="form-field">
				<label for="<?php 
            echo esc_attr($html_name);
            ?>
">
					<?php 
            echo esc_html(sprintf(__('%s type', 'papi'), $taxonomy_object->labels->singular_name));
            ?>
				</label>
				<select name="<?php 
            echo esc_attr($html_name);
            ?>
" id="<?php 
            echo esc_attr($html_name);
            ?>
" data-papi-page-type-key="true">
					<?php 
            foreach ($taxonomy_types as $taxonomy_type) {
                papi_render_html_tag('option', ['data-redirect' => $taxonomy_type->redirect_after_create, 'value' => esc_attr($taxonomy_type->get_id()), esc_html($taxonomy_type->name)]);
            }
            ?>
				</select>
			</div>
			<?php 
        } else {
            papi_render_html_tag('input', ['data-redirect' => $taxonomy_types[0]->redirect_after_create, 'data-papi-page-type-key' => true, 'name' => esc_attr($html_name), 'type' => 'hidden', 'value' => esc_attr($taxonomy_types[0]->get_id())]);
        }
    }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = papi_cast_string_value($this->get_value());
     // Override selected setting with
     // database value if not null.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     echo '<div class="papi-property-radio">';
     foreach ($settings->items as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         papi_render_html_tag('p', [papi_html_tag('label', ['class' => 'light', 'for' => esc_attr($this->html_id($key)), papi_html_tag('input', ['id' => esc_attr($this->html_id($key)), 'name' => esc_attr($this->html_name()), 'type' => 'radio', 'checked' => $value === $settings->selected, 'value' => $value]), esc_html(papi_convert_to_string($key))])]);
     }
     echo '</div>';
 }
    /**
     * Render property html.
     */
    public function html()
    {
        $layout = $this->get_setting('layout');
        $labels = $this->get_labels();
        $post_types = $this->get_post_types();
        $render_label = count($post_types) > 1;
        $advanced = $render_label && $layout === 'advanced';
        $single = $render_label && $layout !== 'advanced';
        $classes = count($post_types) > 1 ? '' : 'papi-fullwidth';
        $settings = $this->get_settings();
        $value = $this->get_value();
        $value = is_object($value) ? $value->ID : 0;
        $selected_label = array_shift($labels);
        $selected_post_type = get_post_type($value) ?: '';
        $posts = $this->get_posts($selected_post_type);
        if ($settings->select2) {
            $classes .= ' papi-component-select2';
        }
        ?>

		<div class="papi-property-post <?php 
        echo $advanced ? 'advanced' : '';
        ?>
">
			<?php 
        if ($advanced) {
            ?>
				<table class="papi-table">
					<tr>
						<td>
							<label for="<?php 
            echo esc_attr($this->html_id());
            ?>
_post_type">
								<?php 
            echo esc_html($settings->labels['select_post_type']);
            ?>
							</label>
						</td>
						<td>
							<select
								id="<?php 
            echo esc_attr($this->html_id());
            ?>
_post_type"
								class="<?php 
            echo esc_attr($classes);
            ?>
 papi-property-post-left"
								data-select-item="<?php 
            echo esc_attr($settings->labels['select_item']);
            ?>
"
								data-post-query='<?php 
            echo esc_attr(papi_maybe_json_encode($settings->query));
            ?>
'
								data-width="100%"
								>
								<?php 
            foreach ($labels as $post_type => $label) {
                papi_render_html_tag('option', ['value' => $post_type, 'selected' => $post_type === $selected_post_type, $label]);
                if ($selected) {
                    $selected_label = $label;
                }
            }
            ?>
							</select>
						</td>
					</tr>
					<tr>
					<td>
						<label for="<?php 
            echo esc_attr($this->html_id());
            ?>
_posts">
							<?php 
            echo esc_html(sprintf($settings->labels['select_item'], $selected_label));
            ?>
						</label>
					</td>
					<td>
			<?php 
        }
        ?>

			<select
				class="<?php 
        echo esc_attr($classes);
        ?>
  papi-property-post-right"
				id="<?php 
        echo esc_attr($this->html_id());
        ?>
_posts"
				name="<?php 
        echo esc_attr($this->html_name());
        ?>
"
				data-allow-clear="<?php 
        echo empty($settings->placeholder) ? 'false' : 'true';
        ?>
"
				data-placeholder="<?php 
        echo esc_attr($settings->placeholder);
        ?>
"
				data-width="100%"
				>

				<?php 
        if (!empty($settings->placeholder)) {
            ?>
					<option value=""></option>
				<?php 
        }
        ?>

				<?php 
        foreach ($posts as $label => $items) {
            ?>

					<?php 
            if ($single) {
                ?>
						<optgroup label="<?php 
                echo esc_attr($label);
                ?>
">
					<?php 
            }
            ?>

					<?php 
            foreach ($items as $post) {
                if (papi_is_empty($post->post_title)) {
                    continue;
                }
                papi_render_html_tag('option', ['data-edit-url' => get_edit_post_link($value), 'selected' => $value === $post->ID, 'value' => $post->ID, $post->post_title]);
            }
            ?>

					<?php 
            if ($single) {
                ?>
						</optgroup>
					<?php 
            }
            ?>

				<?php 
        }
        ?>
			</select>

			<?php 
        if ($advanced) {
            ?>
					</td>
				</tr>
			</table>
			<?php 
        }
        ?>

		</div>
		<?php 
    }
Exemple #12
0
    echo esc_html(implode(', ', $post_types));
    ?>
				</td>
				<td>
					<?php 
    if (empty($page_type->template)) {
        _e('Page Type has no template file', 'papi');
    } else {
        if (!current_user_can('edit_themes') || defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
            echo esc_html($page_type->template);
        } else {
            $theme_dir = get_template_directory();
            $theme_name = basename($theme_dir);
            $url = admin_url('theme-editor.php?file=' . $page_type->template . '&theme=' . $theme_name);
            if (file_exists($theme_dir . '/' . $page_type->template)) {
                papi_render_html_tag('a', ['href' => esc_attr($url), esc_html($page_type->template)]);
            } else {
                _e('Template file does not exist', 'papi');
            }
        }
    }
    ?>
				</td>
				<td>
					<?php 
    echo esc_html(papi_get_number_of_pages($page_type->get_id()));
    ?>
				</td>
			</tr>
		<?php 
}
    /**
     * Render repeater html.
     *
     * @param stdClass $options
     */
    protected function render_repeater($options)
    {
        ?>
		<div class="papi-property-repeater papi-property-repeater-top" data-limit="<?php 
        echo esc_attr($this->get_setting('limit'));
        ?>
">
			<table class="papi-table">
				<?php 
        $this->render_repeater_head();
        ?>

				<tbody class="repeater-tbody">
					<?php 
        $this->render_repeater_rows();
        ?>
				</tbody>
			</table>

			<div class="bottom">
				<?php 
        papi_render_html_tag('button', ['class' => 'button button-primary', 'data-papi-json' => sprintf('%s_repeater_json', $options->slug), 'type' => 'button', esc_html($this->get_setting('add_new_label'))]);
        ?>
			</div>

			<?php 
        /* Default repeater value */
        ?>

			<input type="hidden" data-papi-rule="<?php 
        echo esc_attr($options->slug);
        ?>
" name="<?php 
        echo esc_attr($options->slug);
        ?>
[]" />
		</div>
		<?php 
    }
    /**
     * Render property html.
     */
    public function html()
    {
        $css_classes = '';
        $labels = $this->get_labels();
        $settings = $this->get_settings();
        $slug = $this->html_name();
        $value = papi_to_array($this->get_value());
        // Keep only valid objects.
        $value = array_filter($value, function ($item) {
            return is_object($item) && isset($item->id) && !empty($item->id);
        });
        $show_button = empty($value);
        if ($settings->multiple) {
            $css_classes .= ' multiple ';
            $slug .= '[]';
            $show_button = true;
        }
        ?>

		<div class="papi-property-file <?php 
        echo esc_attr($css_classes);
        ?>
" data-file-type="<?php 
        echo esc_attr($this->file_type);
        ?>
">
			<p class="papi-file-select <?php 
        echo $show_button ? '' : 'papi-hide';
        ?>
">
				<?php 
        if (!$settings->multiple) {
            echo esc_html($labels['no_file']) . '&nbsp;';
        }
        papi_render_html_tag('input', ['name' => esc_attr($slug), 'type' => 'hidden', 'value' => '']);
        papi_render_html_tag('button', ['data-slug' => esc_attr($slug), 'class' => 'button', 'type' => 'button', esc_html($labels['add'])]);
        ?>
			</p>
			<div class="attachments">
				<?php 
        if (is_array($value)) {
            foreach ($value as $file) {
                $url = wp_get_attachment_thumb_url($file->id);
                if (empty($url)) {
                    $url = wp_mime_type_icon($file->id);
                }
                ?>
						<div class="attachment">
							<a class="check" href="#">&times;</a>
							<div class="attachment-preview">
								<div class="thumbnail">
									<div class="centered">
										<?php 
                papi_render_html_tag('img', ['alt' => esc_attr($file->alt), 'src' => esc_attr($url)]);
                papi_render_html_tag('input', ['name' => esc_attr($slug), 'type' => 'hidden', 'value' => esc_attr($file->id)]);
                ?>
									</div>
									<?php 
                if ($this->file_type === 'file') {
                    ?>
										<div class="filename">
											<div><?php 
                    echo esc_html(basename($file->file));
                    ?>
</div>
										</div>
									<?php 
                }
                ?>
								</div>
							</div>
						</div>
					<?php 
            }
        }
        ?>
			</div>
			<div class="clear"></div>
		</div>
	<?php 
    }
    /**
     * Render repeater html.
     *
     * @param object $options
     */
    protected function render_repeater($options)
    {
        $layouts = $this->get_settings_layouts();
        ?>
		<div class="papi-property-flexible papi-property-repeater-top" data-limit="<?php 
        echo esc_attr($this->get_setting('limit'));
        ?>
">
			<table class="papi-table">
				<tbody class="repeater-tbody flexible-tbody">
					<?php 
        $this->render_repeater_row();
        ?>
				</tbody>
			</table>

			<div class="bottom">
				<div class="flexible-layouts-btn-wrap">
					<div class="flexible-layouts papi-hide">
						<div class="flexible-layouts-arrow"></div>
						<ul>
							<?php 
        foreach ($layouts as $layout) {
            papi_render_html_tag('li', [papi_html_tag('a', ['data-layout' => esc_html($layout['slug']), 'data-papi-json' => sprintf('%s_repeater_json', $options->slug), 'href' => '#', 'role' => 'button', 'tabindex' => 0, esc_html($layout['title'])])]);
        }
        ?>
						</ul>
					</div>

					<?php 
        papi_render_html_tag('button', ['class' => 'button button-primary', 'type' => 'button', esc_html($this->get_setting('add_new_label'))]);
        ?>
				</div>
			</div>

			<?php 
        /* Default repeater value */
        ?>

			<input type="hidden" data-papi-rule="<?php 
        echo esc_attr($options->slug);
        ?>
" name="<?php 
        echo esc_attr($this->get_slug());
        ?>
[]" />
		</div>
		<?php 
    }
 /**
  * Render property html.
  */
 public function html()
 {
     papi_render_html_tag('textarea', ['class' => 'papi-property-text', 'id' => esc_attr($this->html_id()), 'name' => esc_attr($this->html_name()), $this->get_value()]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     $value = $this->get_value();
     papi_render_html_tag('div', ['class' => 'papi-property-color-picker', papi_html_tag('input', ['data-palettes' => $settings->palettes, 'id' => $this->html_id(), 'name' => $this->html_name(), 'type' => $settings->show_input === true ? 'text' : 'hidden', 'value' => $value])]);
 }
Exemple #18
0
 /**
  * Output Papi page type hidden field.
  *
  * This will only output on a post type page.
  */
 public function edit_form_after_title()
 {
     wp_nonce_field('papi_save_data', 'papi_meta_nonce');
     if ($value = esc_attr(papi_get_entry_type_id())) {
         papi_render_html_tag('input', ['data-papi-page-type-key' => true, 'name' => esc_attr(papi_get_page_type_key()), 'type' => 'hidden', 'value' => $value]);
     }
 }
    /**
     * Render property html.
     */
    public function html()
    {
        $settings = $this->get_settings();
        $value = $this->get_value();
        if (is_object($value)) {
            $value = $value->term_id;
        } else {
            $value = 0;
        }
        $classes = 'papi-fullwidth';
        if ($settings->select2) {
            $classes = ' papi-component-select2';
        }
        ?>
		<div class="papi-property-term">
		<?php 
        if (empty($settings->taxonomy)) {
            ?>
			<p><?php 
            _e('No taxonomy defined for term property', 'papi');
            ?>
</p>
		<?php 
        } elseif (!term_exists($settings->taxonomy)) {
            ?>
			<p><?php 
            echo esc_html(sprintf(__('The taxonomy "%s" does not exists', 'papi'), $settings->taxonomy));
            ?>
</p>
		<?php 
        } else {
            $terms = $this->get_terms($settings);
            ?>
			<select
				id="<?php 
            echo $this->html_id();
            ?>
"
				name="<?php 
            echo $this->html_name();
            ?>
"
				class="<?php 
            echo $classes;
            ?>
"
				data-allow-clear="true"
				data-placeholder="<?php 
            echo isset($settings->placeholder) ? $settings->placeholder : '';
            ?>
"
				data-width="100%">

				<?php 
            if (isset($settings->placeholder)) {
                ?>
					<option value=""></option>
				<?php 
            }
            ?>

				<?php 
            foreach ($terms as $term_id => $term_name) {
                ?>
					<?php 
                papi_render_html_tag('option', ['value' => $term_id, 'selected' => $value === $term_id ? 'selected' : null, $term_name]);
                ?>
				<?php 
            }
            ?>

			</select>
		<?php 
        }
        ?>
		</div>
		<?php 
    }
    /**
     * Render property html.
     */
    public function html()
    {
        $settings = $this->get_settings();
        $value = $this->get_value();
        if (is_object($value)) {
            $value = $value->ID;
        } else {
            $value = 0;
        }
        $posts = $this->get_posts($settings);
        $render_label = count($posts) > 1;
        $classes = 'papi-fullwidth';
        if ($settings->select2) {
            $classes = ' papi-component-select2';
        }
        ?>

		<div class="papi-property-post">
			<select
				id="<?php 
        echo $this->html_id();
        ?>
"
				name="<?php 
        echo $this->html_name();
        ?>
"
				class="<?php 
        echo $classes;
        ?>
"
				data-allow-clear="true"
				data-placeholder="<?php 
        echo $settings->placeholder;
        ?>
"
				data-width="100%">

				<?php 
        if (!empty($settings->placeholder)) {
            ?>
					<option value=""></option>
				<?php 
        }
        ?>

				<?php 
        foreach ($posts as $label => $items) {
            ?>

					<?php 
            if ($render_label && is_string($label)) {
                ?>
						<optgroup label="<?php 
                echo $label;
                ?>
">
					<?php 
            }
            ?>

					<?php 
            foreach ($items as $post) {
                if (papi_is_empty($post->post_title)) {
                    continue;
                }
                papi_render_html_tag('option', ['value' => $post->ID, 'selected' => $value === $post->ID ? 'selected' : null, $post->post_title]);
            }
            ?>

					<?php 
            if ($render_label) {
                ?>
						</optgroup>
					<?php 
            }
            ?>

				<?php 
        }
        ?>

			</select>
		</div>
		<?php 
    }
 /**
  * Render property html.
  */
 public function html()
 {
     papi_render_html_tag('input', ['id' => $this->html_id(), 'name' => $this->html_name(), 'type' => $this->input_type, 'value' => $this->get_value()]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $value = $this->get_value();
     papi_render_html_tag('input', ['type' => 'hidden', 'name' => esc_attr($this->html_name()), 'value' => false]);
     papi_render_html_tag('input', ['checked' => !empty($value), 'id' => esc_attr($this->html_id()), 'name' => esc_attr($this->html_name()), 'type' => 'checkbox']);
 }
 /**
  * Render Conditional rules as script tag with JSON.
  */
 protected function render_rules_json()
 {
     $rules = $this->get_rules();
     if (empty($rules)) {
         return;
     }
     $rules = $this->conditional->prepare_rules($rules, $this);
     papi_render_html_tag('script', ['data-papi-rule-source-slug' => $this->html_name(), 'data-papi-rules' => 'true', 'type' => 'application/json', json_encode($rules)]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     papi_render_html_tag('input', ['id' => esc_attr($this->html_id()), 'name' => esc_attr($this->html_name()), 'type' => esc_attr($this->input_type), 'value' => $this->get_value(), 'placeholder' => esc_attr($this->get_setting('placeholder'))]);
 }
    /**
     * Render metabox.
     */
    public function metabox()
    {
        $post_type = papi_get_post_type();
        $page_type = papi_get_entry_type_by_id(papi_get_page_type_id());
        $page_type_key = papi_get_page_type_key('switch');
        $page_types = papi_get_all_page_types($post_type);
        // Don't do anything without any page types.
        if (empty($page_type) || empty($page_types)) {
            return;
        }
        ?>

		<div class="misc-pub-section misc-pub-section-last papi-page-type-switcher">
			<label for="<?php 
        echo esc_attr($page_type_key);
        ?>
"><?php 
        esc_html_e('Page Type:', 'papi');
        ?>
</label>
			<span><?php 
        echo esc_html($page_type->name);
        ?>
</span>

			<?php 
        if (papi_current_user_is_allowed($page_type->capabilities) && $page_type->switcher) {
            ?>
				<a href="#" id="papi-page-type-switcher-edit" class="hide-if-no-js"><?php 
            esc_html_e('Edit', 'papi');
            ?>
</a>
				<div>
					<select name="<?php 
            echo esc_attr($page_type_key);
            ?>
" id="<?php 
            echo esc_attr($page_type_key);
            ?>
">
					<?php 
            foreach ($page_types as $pt) {
                if (!papi_current_user_is_allowed($pt->capabilities)) {
                    continue;
                }
                papi_render_html_tag('option', ['selected' => $page_type->match_id($pt->get_id()), 'value' => esc_attr($pt->get_id()), esc_html($pt->name)]);
            }
            ?>
					</select>
					<a href="#" id="papi-page-type-switcher-save" class="hide-if-no-js button"><?php 
            esc_html_e('OK', 'papi');
            ?>
</a>
					<a href="#" id="papi-page-type-switcher-cancel" class="hide-if-no-js"><?php 
            esc_html_e('Cancel', 'papi');
            ?>
</a>
				</div>
			<?php 
        }
        ?>
		</div>
		<?php 
    }
    /**
     * Render property html.
     */
    public function html()
    {
        $settings = $this->get_settings();
        $layout = $settings->layout;
        $labels = $this->get_labels();
        $taxonomies = $this->get_taxonomies();
        $render_label = count($taxonomies) > 1;
        $advanced = $render_label && $layout === 'advanced';
        $single = $render_label && $layout !== 'advanced';
        $classes = count($taxonomies) > 1 ? '' : 'papi-fullwidth';
        $value = $this->get_value();
        $value = is_object($value) ? $value->term_id : 0;
        $selected_label = reset($labels);
        $selected_term = $this->get_term($value) ?: '';
        $selected_term = is_wp_error($selected_term) || empty($selected_term) ? '' : $selected_term;
        $selected_taxonomy = empty($selected_term) ? reset($taxonomies) : $selected_term->taxonomy;
        if ($settings->select2) {
            $classes = ' papi-component-select2';
        }
        ?>

		<div class="papi-property-term <?php 
        echo $advanced ? 'advanced' : '';
        ?>
">
			<?php 
        if ($advanced) {
            ?>
				<table class="papi-table">
					<tr>
						<td>
							<label for="<?php 
            echo esc_attr($this->html_id());
            ?>
_taxonomy">
								<?php 
            echo esc_html($settings->labels['select_taxonomy']);
            ?>
							</label>
						</td>
						<td>
							<select
								id="<?php 
            echo esc_attr($this->html_id());
            ?>
_taxonomy"
								class="<?php 
            echo esc_attr($classes);
            ?>
 papi-property-term-left"
								data-select-item="<?php 
            echo esc_attr($settings->labels['select_item']);
            ?>
"
								data-term-query='<?php 
            echo esc_attr(papi_maybe_json_encode($settings->query));
            ?>
'
								data-width="100%"
								>
								<?php 
            foreach ($labels as $taxonomy => $label) {
                papi_render_html_tag('option', ['value' => $taxonomy, 'selected' => $taxonomy === $selected_taxonomy, $label]);
                if ($selected) {
                    $selected_label = $label;
                }
            }
            ?>
							</select>
						</td>
					</tr>
					<tr>
						<td>
							<label for="<?php 
            echo esc_attr($this->html_id());
            ?>
_terms">
								<?php 
            echo esc_html(sprintf($settings->labels['select_item'], $selected_label));
            ?>
							</label>
						</td>
					<td>
			<?php 
        }
        ?>

			<select
				class="<?php 
        echo esc_attr($classes);
        ?>
  papi-property-term-right"
				id="<?php 
        echo esc_attr($this->html_id());
        ?>
_terms"
				name="<?php 
        echo esc_attr($this->html_name());
        ?>
"
				class="<?php 
        echo esc_attr($classes);
        ?>
"
				data-allow-clear="<?php 
        echo empty($settings->placeholder) ? 'false' : 'true';
        ?>
"
				data-placeholder="<?php 
        echo esc_attr(isset($settings->placeholder) ? $settings->placeholder : '');
        ?>
"
				data-width="100%">

				<?php 
        if (!empty($settings->placeholder)) {
            ?>
					<option value=""></option>
				<?php 
        }
        ?>

				<?php 
        foreach ($taxonomies as $taxonomy) {
            ?>
					<?php 
            if ($advanced && $taxonomy !== $selected_taxonomy) {
                continue;
            }
            $terms = $this->get_terms($taxonomy);
            if (empty($terms)) {
                continue;
            }
            ?>

					<?php 
            if ($single) {
                ?>
						<optgroup label="<?php 
                echo esc_attr($labels[$taxonomy]);
                ?>
">
					<?php 
            }
            ?>

					<?php 
            foreach ($terms as $term_id => $term_name) {
                if (papi_is_empty($term_name)) {
                    continue;
                }
                papi_render_html_tag('option', ['value' => $term_id, 'selected' => $value === $term_id, esc_html($term_name)]);
            }
            ?>

					<?php 
            if ($single) {
                ?>
						</optgroup>
					<?php 
            }
            ?>

				<?php 
        }
        ?>
			</select>

			<?php 
        if ($advanced) {
            ?>
					</td>
				</tr>
			</table>
			<?php 
        }
        ?>

		</div>
		<?php 
    }
 /**
  * Render property html.
  */
 public function html()
 {
     // Setup variables needed.
     $settings = $this->get_settings();
     $value = $this->get_value();
     $options_html = [];
     // Properties that extends dropdown property
     // maybe don't have this setting.
     if (!isset($settings->multiple)) {
         $settings->multiple = false;
     }
     // Override selected setting with
     // database value if not empty.
     if (!papi_is_empty($value)) {
         $settings->selected = $value;
     }
     $classes = 'papi-fullwidth';
     if ($settings->select2) {
         $classes .= ' papi-component-select2';
     }
     // Add placeholder if any.
     if (!empty($settings->placeholder)) {
         $options_html[] = papi_html_tag('option', ['value' => '', $settings->placeholder]);
     }
     // Create option html tags for all items.
     foreach ($this->get_items() as $key => $value) {
         $key = is_numeric($key) ? $value : $key;
         if (papi_is_empty($key)) {
             continue;
         }
         // When a multiple we need to check with
         // `in_array` since the value is a array.
         if ($settings->multiple) {
             $selected = in_array($value, $settings->selected, true);
         } else {
             $selected = $value === $settings->selected;
         }
         $options_html[] = papi_html_tag('option', ['data-edit-url' => get_edit_post_link($value), 'selected' => $selected ? 'selected' : null, 'value' => $value, esc_html(papi_convert_to_string($key))]);
     }
     // When selectize is empty this will be used.
     papi_render_html_tag('input', ['name' => $this->html_name() . ($settings->multiple ? '[]' : ''), 'type' => 'hidden']);
     papi_render_html_tag('select', ['class' => $classes, 'data-allow-clear' => !empty($settings->placeholder), 'data-placeholder' => $settings->placeholder, 'data-width' => '100%', 'id' => $this->html_id() . ($settings->multiple ? '[]' : ''), 'multiple' => $settings->multiple ? 'multiple' : null, 'name' => $this->html_name() . ($settings->multiple ? '[]' : ''), $options_html]);
 }
 /**
  * Render property html.
  */
 public function html()
 {
     $settings = $this->get_settings();
     papi_render_html_tag('div', ['data-papi-rule' => $this->html_name(), 'class' => 'property-html', papi_maybe_get_callable_value($settings->html)]);
 }