Пример #1
0
 /**
  * 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()
    {
        $post_id = papi_get_post_id();
        $slug = $this->html_name();
        $settings = $this->get_settings();
        $settings_json = [];
        $sort_option = $this->get_sort_option($post_id);
        $sort_options = static::get_sort_options();
        $values = papi_get_only_objects($this->get_value());
        $items = $this->get_items($settings);
        if (papi_is_empty($settings->items)) {
            $values = array_map([$this, 'convert_post_to_item'], $values);
        } else {
            foreach (array_keys($sort_options) as $key) {
                if (strpos($key, 'Post') === 0) {
                    unset($sort_options[$key]);
                }
            }
        }
        // Remove existing values if `only once` is active.
        if ($this->get_setting('only_once')) {
            $items = array_udiff($items, $values, function ($a, $b) {
                // Backwards compatibility with both `post_title` and `title`.
                return strcmp(strtolower(isset($a->post_title) ? $a->post_title : $a->title), strtolower(isset($b->post_title) ? $b->post_title : $b->title));
            });
        }
        // Convert all sneak case key to camel case.
        foreach ((array) $settings as $key => $val) {
            if (!is_string($key) || !in_array($key, ['only_once', 'limit'], true)) {
                continue;
            }
            if ($key = papi_camel_case($key)) {
                $settings_json[$key] = $val;
            }
        }
        ?>
		<div class="papi-property-relationship" data-settings='<?php 
        echo esc_attr(papi_maybe_json_encode($settings_json));
        ?>
'>
			<input type="hidden" name="<?php 
        echo esc_attr($slug);
        ?>
[]" data-papi-rule="<?php 
        echo esc_attr($slug);
        ?>
" />
			<div class="relationship-inner">
				<div class="relationship-top-left">
					<label for="<?php 
        echo esc_attr($this->html_id('search'));
        ?>
"><?php 
        esc_html_e('Search', 'papi');
        ?>
</label>
					<input id="<?php 
        echo esc_attr($this->html_id('search'));
        ?>
" type="search" />
				</div>
				<div class="relationship-top-right">
					<?php 
        if ($settings->show_sort_by) {
            ?>
						<label for="<?php 
            echo esc_attr($this->html_id('sort_option'));
            ?>
"><?php 
            esc_html_e('Sort by', 'papi');
            ?>
</label>
						<select id="<?php 
            echo esc_attr($this->html_id('sort_option'));
            ?>
" name="<?php 
            echo esc_attr($this->html_id('sort_option'));
            ?>
">
							<?php 
            foreach (array_keys($sort_options) as $key) {
                ?>
								<option value="<?php 
                echo esc_attr($key);
                ?>
" <?php 
                echo $key === $sort_option ? 'selected="selected"' : '';
                ?>
><?php 
                echo esc_html($key);
                ?>
</option>
							<?php 
            }
            ?>
						</select>
					<?php 
        }
        ?>
				</div>
				<div class="papi-clear"></div>
			</div>
			<div class="relationship-inner">
				<div class="relationship-left">
					<ul>
						<?php 
        foreach ($items as $item) {
            if (!empty($item->title)) {
                ?>
								<li>
									<input type="hidden" data-name="<?php 
                echo esc_attr($slug);
                ?>
[]" value="<?php 
                echo esc_attr($item->id);
                ?>
"/>
									<a href="#" title="<?php 
                echo esc_attr($item->title);
                ?>
"><?php 
                echo esc_html($item->title);
                ?>
</a>
									<span class="icon plus"></span>
								</li>
							<?php 
            }
        }
        ?>
					</ul>
				</div>
				<div class="relationship-right">
					<ul>
						<?php 
        foreach ($values as $item) {
            ?>
							<li>
								<input type="hidden" name="<?php 
            echo esc_attr($slug);
            ?>
[]"
								       value="<?php 
            echo esc_attr($item->id);
            ?>
"/>
								<a href="#"><?php 
            echo esc_attr($item->title);
            ?>
</a>
								<span class="icon minus"></span>
							</li>
						<?php 
        }
        ?>
					</ul>
				</div>
				<div class="papi-clear"></div>
			</div>
		</div>
	<?php 
    }
    /**
     * Render property html.
     */
    public function html()
    {
        $post_id = papi_get_post_id();
        $slug = $this->html_name();
        $settings = $this->get_settings();
        $settings_json = [];
        $sort_option = $this->get_sort_option($post_id);
        $sort_options = static::get_sort_options();
        $values = papi_get_only_objects($this->get_value());
        $items = $this->get_items($settings);
        if (papi_is_empty($settings->items)) {
            $values = array_map([$this, 'convert_post_to_item'], $values);
        } else {
            foreach ($sort_options as $key => $sort) {
                if (strpos($key, 'Post') === 0) {
                    unset($sort_options[$key]);
                }
            }
        }
        // Convert all sneak case key to camel case.
        foreach ((array) $settings as $key => $val) {
            if (!is_string($key) || !in_array($key, ['only_once', 'limit'])) {
                continue;
            }
            $settings_json[papi_camel_case($key)] = $val;
        }
        ?>
		<div class="papi-property-relationship" data-settings='<?php 
        echo json_encode($settings_json);
        ?>
'>
			<input type="hidden" name="<?php 
        echo $slug;
        ?>
[]" data-papi-rule="<?php 
        echo $slug;
        ?>
" />
			<div class="relationship-inner">
				<div class="relationship-top-left">
					<label for="<?php 
        echo $this->html_id('search');
        ?>
"><?php 
        _e('Search', 'papi');
        ?>
</label>
					<input id="<?php 
        echo $this->html_id('search');
        ?>
" type="search" />
				</div>
				<div class="relationship-top-right">
					<?php 
        if ($settings->show_sort_by) {
            ?>
						<label for="<?php 
            echo $this->html_id('sort_option');
            ?>
"><?php 
            _e('Sort by', 'papi');
            ?>
</label>
						<select id="<?php 
            echo $this->html_id('sort_option');
            ?>
" name="<?php 
            echo $this->html_id('sort_option');
            ?>
">
							<?php 
            foreach ($sort_options as $key => $v) {
                ?>
								<option value="<?php 
                echo $key;
                ?>
" <?php 
                echo $key === $sort_option ? 'selected="selected"' : '';
                ?>
><?php 
                echo $key;
                ?>
</option>
							<?php 
            }
            ?>
						</select>
					<?php 
        }
        ?>
				</div>
				<div class="papi-clear"></div>
			</div>
			<div class="relationship-inner">
				<div class="relationship-left">
					<ul>
						<?php 
        foreach ($items as $item) {
            if (!empty($item->title)) {
                ?>
								<li>
									<input type="hidden"
										   data-name="<?php 
                echo $slug;
                ?>
[]"
									       value="<?php 
                echo $item->id;
                ?>
"/>
									<a href="#"><?php 
                echo $item->title;
                ?>
</a>
									<span class="icon plus"></span>
								</li>
							<?php 
            }
        }
        ?>
					</ul>
				</div>
				<div class="relationship-right">
					<ul>
						<?php 
        foreach ($values as $item) {
            ?>
							<li>
								<input type="hidden" name="<?php 
            echo $slug;
            ?>
[]"
								       value="<?php 
            echo $item->id;
            ?>
"/>
								<a href="#"><?php 
            echo $item->title;
            ?>
</a>
								<span class="icon minus"></span>
							</li>
						<?php 
        }
        ?>
					</ul>
				</div>
				<div class="papi-clear"></div>
			</div>
		</div>
	<?php 
    }