示例#1
0
文件: page.php 项目: KristoferN/papi
/**
 * Check if the page type should be displayed or not.
 *
 * @param  string|object $page_type
 *
 * @return bool
 */
function papi_display_page_type($page_type)
{
    $post_type = papi_get_post_type();
    if (empty($post_type)) {
        return false;
    }
    if (is_string($page_type)) {
        $page_type = papi_get_page_type_by_id($page_type);
    }
    if (!is_object($page_type)) {
        return false;
    }
    if (!in_array($post_type, $page_type->post_type)) {
        return false;
    }
    $display = $page_type->display($post_type);
    if (!is_bool($display) || $display === false) {
        return false;
    }
    if (preg_match('/papi\\-standard\\-\\w+\\-type/', $page_type->get_id())) {
        return true;
    }
    $parent_page_type = papi_get_page_type_by_post_id(papi_get_parent_post_id());
    if (papi_is_page_type($parent_page_type)) {
        $child_types = $parent_page_type->get_child_types();
        if (!empty($child_types)) {
            return in_array($page_type, $parent_page_type->get_child_types());
        }
    }
    // Run show page type filter.
    return papi_filter_settings_show_page_type($post_type, $page_type);
}
 /**
  * List Papi types.
  *
  * ## Options
  *
  * [--<field>=<value>]
  * : Filter types based on type property.
  *
  * [--field=<field>]
  * : Prints the value of a single field for each type.
  *
  * [--fields=<fields>]
  * : Limit the output to specific type fields.
  *
  * [--format=<format>]
  * : Acceptec values: table, csv, json, count, ids. Default: table.
  *
  * ## AVAILABLE FIELDS
  *
  * These fields will be displayed by default for each type:
  *
  * * name
  * * id
  * * post_type
  * * template
  * * number_of_pages
  * * type
  *
  * Not all fields exists on a Papi type so some fields will have `n/a`
  * as value when no value can be displayed.
  *
  * ## EXAMPLES
  *
  *     wp papi type list
  *
  * @subcommand list
  */
 public function list_($_, $assoc_args)
 {
     // Get all page types.
     $types = papi_get_all_content_types();
     // Create type item with the fields that
     // will be displayed.
     $types = array_map(function ($type) {
         $is_page_type = papi_is_page_type($type);
         return ['id' => $type->get_id(), 'name' => $type->name, 'post_type' => $is_page_type ? implode(', ', $type->post_type) : 'n/a', 'template' => $is_page_type ? $type->template : 'n/a', 'type' => $type->get_type(), 'number_of_pages' => $is_page_type ? papi_get_number_of_pages($type->get_id()) : 'n/a'];
     }, $types);
     // Render types as a table.
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($types);
 }
示例#3
0
文件: page.php 项目: ekandreas/papi
/**
 * Get number of how many pages uses the given page type.
 * This will also work with only page type.
 *
 * @param  string|Papi_Core_Type $page_type
 *
 * @return int
 */
function papi_get_number_of_pages($page_type)
{
    global $wpdb;
    if (empty($page_type) || !is_string($page_type) && !is_object($page_type)) {
        return 0;
    }
    if (papi_is_page_type($page_type)) {
        $page_type = $page_type->get_id();
    }
    if (!is_string($page_type)) {
        return 0;
    }
    $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}postmeta WHERE `meta_key` = '%s' AND `meta_value` = '%s'";
    $sql = $wpdb->prepare($sql, papi_get_page_type_key(), $page_type);
    return intval($wpdb->get_var($sql));
}
 /**
  * Get child page types that lives under the current page type.
  *
  * @return array
  */
 public function get_child_types()
 {
     $child_types = [];
     foreach (papi_to_array($this->child_types) as $id) {
         $child_type = papi_get_page_type_by_id($id);
         if (papi_is_page_type($child_type)) {
             $child_types[] = $child_type;
         }
     }
     return $child_types;
 }
示例#5
0
?>
</strong>
			</th>
			<th>
				<strong><?php 
_e('Page Count', 'papi');
?>
</strong>
			</th>
		</tr>
		</thead>
		<tbody>
		<?php 
$page_types = papi_get_all_page_types(true);
foreach ($page_types as $key => $page_type) {
    if (!papi_is_page_type($page_type)) {
        continue;
    }
    ?>
			<tr>
				<td>
					<a href="<?php 
    echo sanitize_text_field($_SERVER['REQUEST_URI']);
    ?>
&view=management-page-type&page_type=<?php 
    echo esc_attr($page_type->get_id());
    ?>
">
						<?php 
    echo esc_html($page_type->name);
    ?>
示例#6
0
 /**
  * Import data to Papi.
  *
  * @param  mixed $options
  * @param  array $fields
  *
  * @return bool
  */
 public function import($options, array $fields = [])
 {
     $options = $this->get_import_options($options);
     $post_id = $options['post_id'];
     $page_type = $options['page_type'];
     if (isset($options['update_arrays'])) {
         $this->driver->set_options(['update_array' => $options['update_arrays']]);
     }
     if (empty($post_id) || empty($fields)) {
         return false;
     }
     if (empty($page_type)) {
         $page_type = papi_get_page_type_by_post_id($options['post_id']);
     }
     if (is_string($page_type)) {
         $page_type = papi_get_page_type_by_id($page_type);
     }
     if (!papi_is_page_type($page_type)) {
         return false;
     }
     $result = true;
     foreach ($fields as $slug => $value) {
         if (!is_string($slug) || papi_is_empty($value)) {
             continue;
         }
         $property = $page_type->get_property($slug);
         if (!papi_is_property($property)) {
             $result = false;
             continue;
         }
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'before', 'value' => [$value, $slug]]);
         $value = $this->get_value(['post_id' => $post_id, 'property' => $property, 'slug' => $slug, 'value' => $value]);
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'after', 'value' => [$value, $slug]]);
         $out = papi_update_property_meta_value(['post_id' => $post_id, 'slug' => $slug, 'value' => $value]);
         $result = $out ? $result : $out;
     }
     return $result;
 }
示例#7
0
?>
		</label>

		<input placeholder="<?php 
echo $post_type->labels->search_items;
?>
..." type="search" name="add-new-page-search"
		       id="add-new-page-search" class="papi-search">
	</h2>

	<div class="papi-box-list">
		<?php 
$parent_page_type = papi_get_page_type_by_id(papi_get_page_type_id());
$page_types = papi_get_all_page_types();
$show_standard = papi_filter_settings_show_standard_page_type($post_type_name);
if (papi_is_page_type($parent_page_type)) {
    $child_types = $parent_page_type->get_child_types();
    $page_types = empty($child_types) ? $page_types : $child_types;
    if (!$show_standard) {
        $show_standard = $parent_page_type->standard_type;
    }
}
if ($show_standard) {
    $id = sprintf('papi-standard-%s-type', $post_type_name);
    $page_type = new Papi_Page_Type($id);
    $page_type->id = $id;
    $page_type->name = papi_filter_settings_standard_page_name($post_type_name);
    $page_type->description = papi_filter_settings_standard_page_description($post_type_name);
    $page_type->thumbnail = papi_filter_settings_standard_page_thumbnail($post_type_name);
    $page_type->post_type = [$post_type_name];
    $page_types[] = $page_type;