示例#1
0
文件: page.php 项目: nlemoine/papi
/**
 * Get all page types based on a post type.
 *
 * @param  string $post_type
 *
 * @return array
 */
function papi_get_all_page_types($post_type = '')
{
    $page_types = papi_get_all_entry_types(['args' => $post_type, 'mode' => 'include', 'types' => ['attachment', 'page']]);
    if (is_array($page_types)) {
        usort($page_types, function ($a, $b) {
            return strcmp($a->name, $b->name);
        });
    }
    return papi_sort_order(array_reverse($page_types));
}
示例#2
0
/**
 * Get all content types that exists.
 *
 * @param  array $args {
 *   @type bool         $all
 *   @type mixed        $args
 *   @type array|string $id
 *   @type string       $mode
 *   @type array|string $types
 * }
 *
 * @return array
 */
function papi_get_all_content_types(array $args = [])
{
    $default_args = ['all' => true, 'args' => [], 'mode' => 'include', 'types' => []];
    $args = array_merge($default_args, $args);
    if (!is_array($args['types'])) {
        $args['types'] = [$args['types']];
    }
    if (!is_array($args['args'])) {
        $args['args'] = [$args['args']];
    }
    $args['args'] = array_filter($args['args']);
    if (!empty($args['types'])) {
        $args['all'] = false;
    }
    $content_types = [];
    $files = papi()->once(__FUNCTION__, function () {
        return papi_get_all_core_type_files();
    });
    foreach ($files as $file) {
        $content_type = papi_get_content_type($file);
        if (is_null($content_type)) {
            continue;
        }
        // Only content types can be loaded.
        // @codeCoverageIgnoreStart
        if ($content_type instanceof Papi_Content_Type === false) {
            continue;
        }
        // @codeCoverageIgnoreEnd
        if ($content_type->singleton()) {
            if (!empty($content_types)) {
                continue;
            }
        }
        $valid_type = in_array($content_type->type, $args['types']);
        $valid_type = $args['mode'] === 'include' ? $valid_type : !$valid_type;
        if ($args['all'] || $valid_type && call_user_func_array([$content_type, 'allowed'], $args['args'])) {
            $content_type->boot();
            $content_types[] = $content_type;
        }
        continue;
    }
    if (is_array($content_types)) {
        usort($content_types, function ($a, $b) {
            return strcmp($a->name, $b->name);
        });
    }
    return papi_sort_order(array_reverse($content_types));
}
示例#3
0
文件: tabs.php 项目: ekandreas/papi
/**
 * Setup tabs.
 *
 * @param  array $tabs
 *
 * @return array
 */
function papi_tabs_setup(array $tabs)
{
    $_tabs = [];
    foreach ($tabs as $tab) {
        if ($tab instanceof Papi_Core_Tab === false) {
            continue;
        }
        if (papi_current_user_is_allowed($tab->capabilities)) {
            $_tabs[] = $tab;
        }
    }
    $tabs = papi_sort_order($_tabs);
    // Generate unique names for all tabs.
    $len = count($tabs);
    for ($i = 0; $i < $len; $i++) {
        $tabs[$i]->id = papi_html_name($tabs[$i]->title) . '_' . $i;
    }
    return $tabs;
}
示例#4
0
文件: tabs.php 项目: KristoferN/papi
/**
 * Setup tabs.
 *
 * @param  array $tabs
 *
 * @return array
 */
function papi_setup_tabs(array $tabs)
{
    $_tabs = [];
    foreach ($tabs as $tab) {
        $tab = (object) $tab;
        if (!isset($tab->options)) {
            continue;
        }
        $tab->options = papi_get_tab_options($tab->options);
        if (papi_current_user_is_allowed($tab->options->capabilities)) {
            $_tabs[] = $tab;
        }
    }
    $tabs = papi_sort_order($_tabs);
    // Generate unique names for all tabs.
    $len = count($tabs);
    for ($i = 0; $i < $len; $i++) {
        $tabs[$i]->options->_name = papi_html_name($tabs[$i]->options->title) . '_' . $i;
    }
    return $tabs;
}
示例#5
0
文件: taxonomy.php 项目: wp-papi/papi
/**
 * Load the entry type id on a taxonomy.
 *
 * @param  string $entry_type_id
 * @param  string $type
 *
 * @return string
 */
function papi_load_taxonomy_type_id($entry_type_id = '', $type = 'term')
{
    if ($type !== 'term') {
        return $entry_type_id;
    }
    $key = papi_get_page_type_key();
    $term_id = papi_get_term_id();
    $taxonomy = papi_get_taxonomy($term_id);
    // Try to load the entry type id from only taxonomy type filter.
    if (empty($entry_type_id)) {
        $entry_type_id = papi_filter_settings_only_taxonomy_type($taxonomy);
    }
    // If we have a term id we can load the entry type id from the term.
    if (empty($entry_type_id) && $term_id > 0 && papi_supports_term_meta()) {
        $meta_value = get_term_meta($term_id, $key, true);
        $entry_type_id = empty($meta_value) ? '' : $meta_value;
    }
    // Try to load the entry type from all taxonomy types and check
    // if only one exists of that post type.
    //
    // The same as only taxonomy type filter but without the filter.
    if (empty($entry_type_id)) {
        $key = sprintf('entry_type_id.taxonomy.%s', $taxonomy);
        if (papi()->exists($key)) {
            return papi()->make($key);
        }
        $entries = papi_get_all_entry_types(['args' => $taxonomy, 'mode' => 'include', 'types' => ['taxonomy']]);
        if (is_array($entries)) {
            usort($entries, function ($a, $b) {
                return strcmp($a->name, $b->name);
            });
        }
        $entries = papi_sort_order(array_reverse($entries));
        if (count($entries) === 1) {
            $entry_type_id = $entries[0]->get_id();
            papi()->bind($key, $entry_type_id);
        }
    }
    return $entry_type_id;
}
示例#6
0
文件: page.php 项目: KristoferN/papi
/**
 * Get all page types that exists.
 *
 * @param  bool   $all
 * @param  string $post_type
 * @param  bool   $fake_post_types
 *
 * @return array
 */
function papi_get_all_page_types($all = false, $post_type = null, $fake_post_types = false)
{
    if (empty($post_type)) {
        $post_type = papi_get_post_type();
    }
    $cache_key = papi_cache_key(sprintf('%s_%s', $all, $post_type), $fake_post_types);
    $page_types = wp_cache_get($cache_key);
    $load_once = papi_filter_core_load_one_type_on();
    if (empty($page_types)) {
        $files = papi_get_all_page_type_files();
        foreach ($files as $file) {
            $page_type = papi_get_page_type($file);
            if (is_null($page_type)) {
                continue;
            }
            if ($page_type instanceof Papi_Page_Type === false) {
                continue;
            }
            if (papi()->exists('core.page_type.' . $page_type->post_type[0])) {
                if (!empty($page_types)) {
                    continue;
                }
            } else {
                if (in_array($page_type->post_type[0], $load_once)) {
                    papi()->singleton('core.page_type.' . $page_type->post_type[0], $page_type->get_id());
                }
            }
            if ($fake_post_types) {
                if (isset($page_type->post_type[0]) && !post_type_exists($page_type->post_type[0])) {
                    // Boot page type.
                    $page_type->boot();
                    // Add it to the page types array.
                    $page_types[] = $page_type;
                }
                continue;
            } else {
                if ($page_type instanceof Papi_Option_Type) {
                    continue;
                }
            }
            // Add the page type if the post types is allowed.
            if (!is_null($page_type) && papi_current_user_is_allowed($page_type->capabilities) && ($all || in_array($post_type, $page_type->post_type))) {
                // Boot page type.
                $page_type->boot();
                // Add it to the page types array.
                $page_types[] = $page_type;
            }
        }
        if (is_array($page_types)) {
            usort($page_types, function ($a, $b) {
                return strcmp($a->name, $b->name);
            });
            wp_cache_set($cache_key, $page_types);
        }
    }
    if (!is_array($page_types)) {
        return [];
    }
    return papi_sort_order(array_reverse($page_types));
}
示例#7
0
文件: property.php 项目: wp-papi/papi
/**
 * Populate properties array.
 *
 * @param  array|object $properties
 *
 * @return array
 */
function papi_populate_properties($properties)
{
    if (!is_array($properties) && !is_object($properties) || empty($properties)) {
        return [];
    }
    if (is_object($properties)) {
        return [$properties];
    }
    // Convert all non property objects to property objects.
    $properties = array_map(function ($property) {
        if (is_array($property)) {
            return papi_property($property);
        }
        return $property;
    }, $properties);
    if (!isset($properties[0])) {
        $properties = [papi_property($properties)];
    }
    // If the first property is a core tab, just return
    // the properties array and skip the last check.
    if (empty($properties) || $properties[0] instanceof Papi_Core_Tab) {
        return papi_sort_order($properties);
    }
    return papi_sort_order(array_filter(array_reverse($properties), 'papi_is_property'));
}
示例#8
0
/**
 * Populate properties array.
 *
 * @param  array|object $properties
 *
 * @return array
 */
function papi_populate_properties($properties)
{
    if (!is_array($properties) && !is_object($properties) || empty($properties)) {
        return [];
    }
    if (is_object($properties)) {
        return [$properties];
    }
    $results = [];
    // Get the box property (when you only put a array in the box method) if it exists.
    $properties = papi_get_box_property($properties);
    // Convert all non property objects to property objects.
    $properties = array_map(function ($property) {
        if (!is_object($property) && is_array($property) && !isset($property['tab'])) {
            return papi_get_property_options($property);
        }
        return $property;
    }, $properties);
    // Fix so the properties array will have the right order.
    $properties = array_reverse($properties);
    foreach ($properties as $property) {
        if (isset($property->tab) && $property->tab) {
            $results[] = $property;
            continue;
        }
        $results[] = $property;
    }
    if (empty($results) || isset($results[0]->tab) && $results[0]->tab) {
        return $results;
    }
    return papi_sort_order($results);
}
示例#9
0
 /**
  * Get boxes from the page type.
  *
  * @return array
  */
 public function get_boxes()
 {
     if (empty($this->boxes) && $this->load_boxes === false) {
         if (!method_exists($this, 'register')) {
             return [];
         }
         $this->load_boxes = true;
         $this->call_parent_register();
         $this->register();
     }
     // Merge boxes, e.g a parent box with a child box.
     $this->boxes = $this->merge_boxes($this->boxes);
     /**
      * Modify boxes array.
      *
      * @param array  $boxes
      * @param string $id
      */
     $this->boxes = apply_filters('papi/get_boxes', $this->boxes, $this->get_id());
     $this->boxes = is_array($this->boxes) ? $this->boxes : [];
     // Go through all boxes and only add boxes
     // that is a array and remove boxes that isn't
     // a instance of core box class.
     foreach ($this->boxes as $index => $box) {
         if (is_array($box)) {
             if (is_string($index)) {
                 $box['title'] = $index;
             }
             $this->box($box);
             unset($this->boxes[$index]);
             continue;
         }
         if ($box instanceof Papi_Core_Box === false) {
             unset($this->boxes[$index]);
             continue;
         }
     }
     return papi_sort_order(array_reverse($this->boxes));
 }
示例#10
0
    }
}
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_type_name($post_type_name);
    $page_type->description = papi_filter_settings_standard_page_type_description($post_type_name);
    $page_type->thumbnail = papi_filter_settings_standard_page_type_thumbnail($post_type_name);
    $page_type->post_type = [$post_type_name];
    $page_types[] = $page_type;
}
usort($page_types, function ($a, $b) {
    return strcmp($a->name, $b->name);
});
$page_types = papi_sort_order(array_reverse($page_types));
$use_thumbnail = false;
foreach ($page_types as $key => $page_type) {
    if (!empty($page_type->get_thumbnail())) {
        $use_thumbnail = true;
    }
}
foreach ($page_types as $key => $page_type) {
    if (!papi_display_page_type($page_type)) {
        continue;
    }
    papi_include_template('admin/views/partials/add-new-item.php', ['title' => $page_type->name, 'description' => $page_type->description, 'thumbnail' => $page_type->get_thumbnail(), 'url' => papi_get_page_new_url($page_type->get_id(), true, null), 'use_thumbnail' => $use_thumbnail]);
}
?>
	</div>
</div>
示例#11
0
 /**
  * This function will setup all meta boxes.
  */
 public function setup()
 {
     if (!method_exists($this, 'register')) {
         return;
     }
     // 1. Run the register method.
     $this->register();
     // 2. Remove post type support
     $this->remove_post_type_support();
     // 3. Load all boxes.
     $this->boxes = papi_sort_order(array_reverse($this->boxes));
     foreach ($this->boxes as $box) {
         new Papi_Admin_Meta_Box($box[0], $box[1]);
     }
 }
示例#12
0
文件: entry.php 项目: nlemoine/papi
/**
 * Get all entry types that exists.
 *
 * @param  array $args {
 *   @type bool         $all
 *   @type mixed        $args
 *   @type bool         $cache
 *   @type array|string $id
 *   @type string       $mode
 *   @type array|string $types
 * }
 *
 * @return array
 */
function papi_get_all_entry_types(array $args = [])
{
    $default_args = ['all' => true, 'args' => [], 'cache' => true, 'mode' => 'include', 'types' => []];
    $args = array_merge($default_args, $args);
    if (!is_array($args['types'])) {
        $args['types'] = [$args['types']];
    }
    if (!is_array($args['args'])) {
        $args['args'] = [$args['args']];
    }
    $args['args'] = array_filter($args['args']);
    if (!empty($args['types'])) {
        $args['all'] = false;
    }
    $cache_key = papi_cache_key(__FUNCTION__, md5(serialize($args)));
    if (!$args['cache']) {
        papi()->remove('papi_get_all_core_type_files');
        papi()->remove($cache_key);
    }
    if (papi()->exists($cache_key)) {
        return papi()->make($cache_key);
    }
    $singletons = [];
    $entry_types = [];
    $files = papi_get_all_core_type_files();
    foreach ($files as $file) {
        $entry_type = papi_get_entry_type($file);
        if (is_null($entry_type)) {
            continue;
        }
        // Only entry types can be loaded.
        // @codeCoverageIgnoreStart
        if ($entry_type instanceof Papi_Entry_Type === false) {
            continue;
        }
        // @codeCoverageIgnoreEnd
        if ($entry_type->singleton()) {
            if (isset($singletons[$entry_type->type])) {
                continue;
            } else {
                $singletons[$entry_type->type] = true;
            }
        }
        $id = $entry_type->get_id();
        $valid_type = in_array($entry_type->type, $args['types'], true);
        $valid_type = $args['mode'] === 'include' ? $valid_type : !$valid_type;
        if ($args['all'] || $valid_type && call_user_func_array([$entry_type, 'allowed'], $args['args'])) {
            $entry_type->boot();
            $entry_types[$id] = $entry_type;
        }
    }
    $entry_types = array_values($entry_types);
    if (is_array($entry_types)) {
        usort($entry_types, function ($a, $b) {
            return strcmp($a->name, $b->name);
        });
    }
    $entry_types = papi_sort_order(array_reverse($entry_types));
    if (!papi()->exists($cache_key)) {
        papi()->singleton($cache_key, $entry_types);
    }
    return $entry_types;
}
 /**
  * Prepare taxonomy types, add standard taxonomy if it should be added.
  *
  * @param  array $taxonomy_types
  *
  * @return array
  */
 protected function prepare_taxonomy_types(array $taxonomy_types)
 {
     $taxonomy = papi_get_qs('taxonomy');
     if (papi_filter_settings_show_standard_taxonomy_type($taxonomy)) {
         $id = sprintf('papi-standard-%s-type', $taxonomy);
         $taxonomy_type = new Papi_Taxonomy_Type($id);
         $taxonomy_type->id = $id;
         $taxonomy_type->name = papi_filter_settings_standard_taxonomy_type_name($taxonomy);
         $taxonomy_type->taxonomy = [$taxonomy];
         $taxonomy_types[] = $taxonomy_type;
     }
     usort($taxonomy_types, function ($a, $b) {
         return strcmp($a->name, $b->name);
     });
     return papi_sort_order(array_reverse($taxonomy_types));
 }
示例#14
0
 /**
  * Get boxes from the page type.
  *
  * @return array
  */
 public function get_boxes()
 {
     if (empty($this->boxes) && $this->load_boxes === false) {
         if (!method_exists($this, 'register')) {
             return [];
         }
         $this->load_boxes = true;
         $this->call_parent_register();
         $this->register();
     }
     $this->boxes = $this->merge_boxes($this->boxes);
     $this->boxes = papi_sort_order(array_reverse($this->boxes));
     return $this->boxes;
 }