PHP Класс Habari\Posts

class Posts This class provides two key features. 1: Posts contains static method get() that returns the requested posts based on the passed criteria. Depending on the type of request, different types are returned. See the function for details 2: An instance of Posts functions as an array (by extending ArrayObject) and is returned by Posts::get() as the results of a query. This allows the result of Posts::get() to be iterated (for example, in a foreach construct) and to have properties that can be accessed that describe the results (for example, $posts->onepost).
Наследование: extends ArrayObject, implements IsContent
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$get_param_cache

Открытые методы

Метод Описание
__get ( string $name ) : array | boolean | mixed Returns properties of a Posts object.
__static ( ) Register plugin hooks
ascend ( Post $post, array $userparams = null ) : Post Returns an ascending post
by_slug ( string $slug = '' ) : array function by_slug select all post content by slug
by_status ( integer $status ) : array function by_status select all posts of a given status
content_type ( ) : array Return the type of the content represented by this object
count_all ( ) : integer return a count for the number of posts last queried
count_by_author ( integer $user_id, mixed $status = false ) : integer static count_by_author return a count of the number of posts by the specified author
count_by_tag ( string $tag, mixed $status = false ) : integer static count_by_tag return a count of the number of posts with the assigned tag
count_total ( mixed $status = false ) : integer static count_total return a count for the total number of posts
delete ( ) function delete Delete all Posts in a Posts object
descend ( Post $post, array $userparams = null ) : Post Returns a descending post
empty_param ( string | array $param, array $empty_values = [0, 'any'] ) : boolean Determine whether a parameter supplied to Posts::get() is empty and should be ignored based on its value being comprised only of empty values
extract_param ( array $paramarray, string $param ) : array | boolean Extract parameters from a Posts::get()-style param array, even from within where's
filter_posts_get_all_presets ( array $presets ) : array Provide some default presets
get ( array $paramarray = [] ) : Posts | Post | string Returns a post or posts based on supplied parameters.
get_query ( ) : string return the query that generated this set of posts
merge_presets ( array $paramarray, array $presets ) : array Accept a parameter array for Posts::get() with presets, and return an array with all defined parameters from those presets
publish_scheduled_posts ( ) Callback function to publish scheduled posts, executed on cron
reassign ( integer | User | string $user, array | Posts $posts ) : boolean Reassigns the author of a specified set of posts
rewrite_match_type ( RewriteRule $rule, string $stub, array $parameters ) : boolean Check if the requested post is of the type specified, to see if a rewrite rule matches.
search ( Post $needle ) : mixed Search this Posts object for the needle, returns its key if found
search_id ( Post $needle ) : mixed Search this Posts object for the needle, returns its key if found. Only compare the post IDs
search_to_get ( string $search_string ) : array Parses a search string for status, type, author, and tag keywords. Returns an associative array which can be passed to Posts::get(). If multiple authors, statuses, tags, or types are specified, we assume an implicit OR such that (e.g.) any author that matches would be returned.
to_json ( ) : string Serialize these posts as JSON
update_scheduled_posts_cronjob ( ) function update_scheduled_posts_cronjob

Приватные методы

Метод Описание
vocabulary_params ( array $params ) : array Accepts a set of term query qualifiers and converts it into a multi-dimensional array of vocabulary (ie: tags), matching method (any, all, not), matching field (id, term, term_display), and list of terms

Описание методов

__get() публичный Метод

This is the function that returns information about the set of posts that was requested. This function should offer property names that are identical to properties of instances of the URL class. A call to Posts::get() without parameters should return mostly the same property values as the global $url object for the request. The difference would occur when the data returned doesn't necessarily match the request, such as when several posts are requested, but only one is available to return.
public __get ( string $name ) : array | boolean | mixed
$name string The name of the property to return.
Результат array | boolean | mixed The requested property value

__static() публичный статический Метод

Register plugin hooks
public static __static ( )

ascend() публичный статический Метод

Returns an ascending post
public static ascend ( Post $post, array $userparams = null ) : Post
$post Post The Post from which to start
$userparams array The params by which to work out what is the next ascending post
Результат Post The ascending post

by_slug() публичный статический Метод

function by_slug select all post content by slug
public static by_slug ( string $slug = '' ) : array
$slug string a post slug
Результат array an array of post content

by_status() публичный статический Метод

function by_status select all posts of a given status
public static by_status ( integer $status ) : array
$status integer a status value
Результат array an array of Comment objects with the same status

content_type() публичный Метод

Return the type of the content represented by this object
public content_type ( ) : array
Результат array The names of the possible content represented by this object

count_all() публичный Метод

return a count for the number of posts last queried
public count_all ( ) : integer
Результат integer the number of posts of specified type ( published or draft )

count_by_author() публичный статический Метод

static count_by_author return a count of the number of posts by the specified author
public static count_by_author ( integer $user_id, mixed $status = false ) : integer
$user_id integer an author ID
$status mixed a status value to filter posts by; if false, then no filtering will be performed
Результат integer the number of posts by the specified author

count_by_tag() публичный статический Метод

static count_by_tag return a count of the number of posts with the assigned tag
public static count_by_tag ( string $tag, mixed $status = false ) : integer
$tag string A tag
$status mixed a status value to filter posts by; if false, then no filtering will be performed
Результат integer the number of posts with the specified tag

count_total() публичный статический Метод

static count_total return a count for the total number of posts
public static count_total ( mixed $status = false ) : integer
$status mixed a status value to filter posts by; if false, then no filtering will be performed
Результат integer the number of posts of specified type ( published or draft )

delete() публичный Метод

function delete Delete all Posts in a Posts object
public delete ( )

descend() публичный статический Метод

Returns a descending post
public static descend ( Post $post, array $userparams = null ) : Post
$post Post The Post from which to start
$userparams array The params by which to work out what is the next descending post
Результат Post The descending post

empty_param() публичный статический Метод

Determine whether a parameter supplied to Posts::get() is empty and should be ignored based on its value being comprised only of empty values
public static empty_param ( string | array $param, array $empty_values = [0, 'any'] ) : boolean
$param string | array The parameter values supplied to Posts::get()
$empty_values array An array defining what values are considered empty and ignorable
Результат boolean True if the parameter values contain only empty values, false otherwise

extract_param() публичный статический Метод

Extract parameters from a Posts::get()-style param array, even from within where's
public static extract_param ( array $paramarray, string $param ) : array | boolean
$paramarray array An array of Posts::get()-style parameters
$param string The parameters to extract
Результат array | boolean The parameters in the $paramarray that match $param or false

filter_posts_get_all_presets() публичный статический Метод

Provide some default presets
public static filter_posts_get_all_presets ( array $presets ) : array
$presets array List of presets that other classes might provide
Результат array List of presets this class provides

get() публичный статический Метод

Returns a post or posts based on supplied parameters.
public static get ( array $paramarray = [] ) : Posts | Post | string
$paramarray array An associative array of parameters, or a querystring. The following keys are supported: - id => a post id or array of post ids - not:id => a post id or array of post ids to exclude - slug => a post slug or array of post slugs - not:slug => a post slug or array of post slugs to exclude - user_id => an author id or array of author ids - content_type => a post content type or array post content types - not:content_type => a post content type or array post content types to exclude - status => a post status, an array of post statuses, or 'any' for all statuses - year => a year of post publication - month => a month of post publication, ignored if year is not specified - day => a day of post publication, ignored if month and year are not specified - before => a timestamp to compare post publication dates - after => a timestamp to compare post publication dates - month_cts => return the number of posts published in each month - criteria => a literal search string to match post content or title - title => an exact case-insensitive match to a post title - title_search => a search string that acts only on the post title - has:info => a post info key or array of post info keys, which should be present - all:info => a post info key and value pair or array of post info key and value pairs, which should all be present and match - not:all:info => a post info key and value pair or array of post info key and value pairs, to exclude if all are present and match - any:info => a post info key and value pair or array of post info key and value pairs, any of which can match - not:any:info => a post info key and value pair or array of post info key and value pairs, to exclude if any are present and match - vocabulary => an array describing parameters related to vocabularies attached to posts. This can be one of two forms: - object-based, in which an array of Term objects are passed - any => posts associated with any of the terms are returned - all => posts associated with all of the terms are returned - not => posts associated with none of the terms are returned - property-based, in which an array of vocabulary names and associated fields are passed - vocabulary_name:term => a vocabulary name and term slug pair or array of vocabulary name and term slug pairs, any of which can be associated with the posts - vocabulary_name:term_display => a vocabulary name and term display pair or array of vocabulary name and term display pairs, any of which can be associated with the posts - vocabulary_name:not:term => a vocabulary name and term slug pair or array of vocabulary name and term slug pairs, none of which can be associated with the posts - vocabulary_name:not:term_display => a vocabulary name and term display pair or array of vocabulary name and term display pairs, none of which can be associated with the posts - vocabulary_name:all:term => a vocabulary name and term slug pair or array of vocabulary name and term slug pairs, all of which must be associated with the posts - vocabulary_name:all:term_display => a vocabulary name and term display pair or array of vocabulary name and term display pairs, all of which must be associated with the posts - on_query_built => a closure that accepts a Query as a parameter, allowing a plugin to alter the Query for this request directly - limit => the maximum number of posts to return, implicitly set for many queries - nolimit => do not implicitly set limit - offset => amount by which to offset returned posts, used in conjunction with limit - page => the 'page' of posts to return when paging, sets the appropriate offset - count => return the number of posts that would be returned by this request - orderby => how to order the returned posts - groupby => columns by which to group the returned posts, for aggregate functions - having => for selecting posts based on an aggregate function - where => manipulate the generated WHERE clause. Currently broken, see https://trac.habariproject.org/habari/ticket/1383 - add_select => an array of clauses to be added to the generated SELECT clause. - fetch_fn => the function used to fetch data, one of 'get_results', 'get_row', 'get_value', 'get_query' Further description of parameters, including usage examples, can be found at http://wiki.habariproject.org/en/Dev:Retrieving_Posts
Результат Posts | Post | string An array of Post objects, or a single post object, depending on request

get_query() публичный Метод

return the query that generated this set of posts
public get_query ( ) : string
Результат string The SQL and paramters used to generate this set of posts

merge_presets() публичный статический Метод

Accept a parameter array for Posts::get() with presets, and return an array with all defined parameters from those presets
public static merge_presets ( array $paramarray, array $presets ) : array
$paramarray array An array of parameters to Posts::get that may contain presets
$presets array a list of presets, keyed by preset name, each an array of parameters that define the preset
Результат array The processed array, including all original presets and all newly added recursive presets and parameters

publish_scheduled_posts() публичный статический Метод

Callback function to publish scheduled posts, executed on cron
public static publish_scheduled_posts ( )

reassign() публичный статический Метод

Reassigns the author of a specified set of posts
public static reassign ( integer | User | string $user, array | Posts $posts ) : boolean
$user integer | User | string a user ID or name
$posts array | Posts an array of post IDs, an array of Post objects, or an instance of Posts
Результат boolean Whether the rename operation succeeded or not

rewrite_match_type() публичный статический Метод

Check if the requested post is of the type specified, to see if a rewrite rule matches.
public static rewrite_match_type ( RewriteRule $rule, string $stub, array $parameters ) : boolean
$rule RewriteRule The rewrite rule we're matching against
$stub string The URL stub request that triggered the rule
$parameters array The included parameters on this rule
Результат boolean Whether the requested post matches the content type of the rule.

search_id() публичный Метод

Search this Posts object for the needle, returns its key if found. Only compare the post IDs
public search_id ( Post $needle ) : mixed
$needle Post Post object to find within this Posts object
Результат mixed Returns the index of the needle, on failure, null is returned

search_to_get() публичный статический Метод

Parses a search string for status, type, author, and tag keywords. Returns an associative array which can be passed to Posts::get(). If multiple authors, statuses, tags, or types are specified, we assume an implicit OR such that (e.g.) any author that matches would be returned.
public static search_to_get ( string $search_string ) : array
$search_string string The search string
Результат array An associative array which can be passed to Posts::get()

to_json() публичный Метод

Serialize these posts as JSON
public to_json ( ) : string
Результат string Posts as JSON

update_scheduled_posts_cronjob() публичный статический Метод

Creates or recreates the cronjob to publish scheduled posts. It is called whenever a post is updated or created
public static update_scheduled_posts_cronjob ( )

Описание свойств

$get_param_cache публичное свойство

public $get_param_cache