Public Member Functions | Static Public Member Functions | Public Attributes

Posts Class Reference

Inheritance diagram for Posts:
Collaboration diagram for Posts:

List of all members.

Public Member Functions

 __get ($name)
 count_all ()
 get_query ()
 search ($needle)
 content_type ()
 to_json ()

Static Public Member Functions

static get ($paramarray=array())
static merge_presets ($paramarray, $presets)
static empty_param ($param, $empty_values=array(0, 'any'))
static extract_param ($paramarray, $param)
static by_status ($status)
static by_slug ($slug= '')
static count_total ($status=false)
static count_by_author ($user_id, $status=false)
static count_by_tag ($tag, $status=false)
static reassign ($user, $posts)
static update_scheduled_posts_cronjob ()
static ascend ($post, $userparams=null)
static descend ($post, $userparams=null)
static search_to_get ($search_string)
static rewrite_match_type ($rule, $stub, $parameters)
static __static ()
static filter_posts_get_all_presets ($presets)

Public Attributes

 $get_param_cache

Detailed Description

Definition at line 28 of file posts.php.


Member Function Documentation

Posts::__get ( name  ) 

Returns properties of a Posts object. 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.

Parameters:
string $name The name of the property to return.
Returns:
array|bool|mixed The requested property value

Definition at line 44 of file posts.php.

static Posts::__static (  )  [static]

Register plugin hooks

Definition at line 1287 of file posts.php.

static Posts::ascend ( post,
userparams = null 
) [static]

Returns an ascending post

Parameters:
Post $post The Post from which to start
array $userparams The params by which to work out what is the next ascending post
Returns:
Post The ascending post

Definition at line 1025 of file posts.php.

static Posts::by_slug ( slug = ''  )  [static]

function by_slug select all post content by slug

Parameters:
string $slug a post slug
Returns:
array an array of post content

Definition at line 862 of file posts.php.

static Posts::by_status ( status  )  [static]

function by_status select all posts of a given status

Parameters:
int $status a status value
Returns:
array an array of Comment objects with the same status

Definition at line 850 of file posts.php.

Posts::content_type (  ) 

Return the type of the content represented by this object

Returns:
array The names of the possible content represented by this object

Implements IsContent.

Definition at line 1210 of file posts.php.

Posts::count_all (  ) 

return a count for the number of posts last queried

Returns:
int the number of posts of specified type ( published or draft )

Definition at line 886 of file posts.php.

static Posts::count_by_author ( user_id,
status = false 
) [static]

static count_by_author return a count of the number of posts by the specified author

Parameters:
int $user_id an author ID
mixed $status a status value to filter posts by; if false, then no filtering will be performed
Returns:
int the number of posts by the specified author

Definition at line 909 of file posts.php.

Referenced by User::count_posts().

static Posts::count_by_tag ( tag,
status = false 
) [static]

static count_by_tag return a count of the number of posts with the assigned tag

Parameters:
string $tag A tag
mixed $status a status value to filter posts by; if false, then no filtering will be performed
Returns:
int the number of posts with the specified tag

Definition at line 925 of file posts.php.

Referenced by CoreBlocks::action_block_content_tag_archives(), and Tag::rewrite_tag_exists().

static Posts::count_total ( status = false  )  [static]

static count_total return a count for the total number of posts

Parameters:
mixed $status a status value to filter posts by; if false, then no filtering will be performed
Returns:
int the number of posts of specified type ( published or draft )

Definition at line 873 of file posts.php.

static Posts::descend ( post,
userparams = null 
) [static]

Returns a descending post

Parameters:
Post $post The Post from which to start
array $userparams The params by which to work out what is the next descending post
Returns:
Post The descending post

Definition at line 1058 of file posts.php.

static Posts::empty_param ( param,
empty_values = array(0, 'any') 
) [static]

Determine whether a parameter supplied to Posts::get() is empty and should be ignored based on its value being comprised only of empty values

Parameters:
string|array $param The parameter values supplied to Posts::get()
array $empty_values An array defining what values are considered empty and ignorable
Returns:
bool True if the parameter values contain only empty values, false otherwise

Definition at line 810 of file posts.php.

Referenced by get().

static Posts::extract_param ( paramarray,
param 
) [static]

Extract parameters from a Posts::get()-style param array, even from within where's

Parameters:
array $paramarray An array of Posts::get()-style parameters
string $param The parameters to extract
Returns:
array|bool The parameters in the $paramarray that match $param or false

Definition at line 827 of file posts.php.

static Posts::filter_posts_get_all_presets ( presets  )  [static]

Provide some default presets

Parameters:
array $presets List of presets that other classes might provide
Returns:
array List of presets this class provides

Definition at line 1298 of file posts.php.

static Posts::get ( paramarray = array()  )  [static]

Returns a post or posts based on supplied parameters.

Todo:
THIS CLASS SHOULD CACHE QUERY RESULTS!
Parameters:
array $paramarray 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

Returns:
Posts|Post|string An array of Post objects, or a single post object, depending on request

Build the statement needed to filter by pubdate: If we've got the day, then get the date; If we've got the month, but no date, get the month; If we've only got the year, get the whole year.

Determine which fetch function to use: If it is specified, make sure it is valid (based on the $fns array defined at the beginning of this function); Else, use 'get_results' which will return a Posts array of Post objects.

If a count is requested: Replace the current fields to select with a COUNT(); Change the fetch function to 'get_value'; Remove the ORDER BY since it's useless. Remove the GROUP BY (tag search added it)

DEBUG: Uncomment the following line to display everything that happens in this function

Execute the SQL statement using the PDO extension

Return the results

Definition at line 116 of file posts.php.

Referenced by AjaxHandler::__static(), Theme::act_display(), MzingiHi::action_add_template_vars(), Charcoal::action_block_content_charcoal_menu(), CoreDashModules::action_block_content_latest_entries(), CoreBlocks::action_block_content_monthly_archives(), CoreBlocks::action_block_content_recent_posts(), Charcoal::add_template_vars(), AdminPostsHandler::ajax_update_posts(), ascend(), by_slug(), by_status(), count_all(), count_by_author(), count_by_tag(), count_total(), descend(), CoreDashModules::filter_dash_module_post_types_and_statuses(), AtomHandler::get_collection(), AdminDashboardHandler::get_dashboard(), get_query(), reassign(), and rewrite_match_type().

Posts::get_query (  ) 

return the query that generated this set of posts

Returns:
string The SQL and paramters used to generate this set of posts

Definition at line 896 of file posts.php.

static Posts::merge_presets ( paramarray,
presets 
) [static]

Accept a parameter array for Posts::get() with presets, and return an array with all defined parameters from those presets

Parameters:
array $paramarray An array of parameters to Posts::get that may contain presets
array $presets a list of presets, keyed by preset name, each an array of parameters that define the preset
Returns:
array The processed array, including all original presets and all newly added recursive presets and parameters

Definition at line 766 of file posts.php.

Referenced by get().

static Posts::reassign ( user,
posts 
) [static]

Reassigns the author of a specified set of posts

Parameters:
int|User|string $user a user ID or name
array|Posts $posts an array of post IDs, an array of Post objects, or an instance of Posts
Returns:
bool Whether the rename operation succeeded or not

Definition at line 940 of file posts.php.

static Posts::rewrite_match_type ( rule,
stub,
parameters 
) [static]

Check if the requested post is of the type specified, to see if a rewrite rule matches.

Parameters:
RewriteRule $rule The rewrite rule we're matching against
string $stub The URL stub request that triggered the rule
array $parameters The included parameters on this rule
Returns:
Boolean Whether the requested post matches the content type of the rule.

Definition at line 1196 of file posts.php.

Posts::search ( needle  ) 

Search this Posts object for the needle, returns its key if found

Parameters:
Post $needle Post object to find within this Posts object
Returns:
mixed Returns the index of the needle, on failure, null is returned

Definition at line 1090 of file posts.php.

static Posts::search_to_get ( search_string  )  [static]

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.

Parameters:
string $search_string The search string
Returns:
array An associative array which can be passed to Posts::get()

Definition at line 1104 of file posts.php.

Posts::to_json (  ) 

Serialize these posts as JSON

Returns:
string Posts as JSON

Definition at line 1334 of file posts.php.

static Posts::update_scheduled_posts_cronjob (  )  [static]

function update_scheduled_posts_cronjob

Creates or recreates the cronjob to publish scheduled posts. It is called whenever a post is updated or created

Definition at line 1008 of file posts.php.

Referenced by Post::delete(), Post::insert(), and Post::update().


The documentation for this class was generated from the following file: