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 ()
 search ($needle)
 content_type ()

Static Public Member Functions

static get ($paramarray=array())
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 publish_scheduled_posts ($params)
static update_scheduled_posts_cronjob ()
static ascend ($post, $params=null)
static descend ($post, $params=null)
static search_to_get ($search_string)
static rewrite_match_type ($rule, $slug, $parameters)

Public Attributes

 $get_param_cache

Detailed Description

Habari Posts Class

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).

Definition at line 21 of file posts.php.


Member Function Documentation

Posts::__get ( name  ) 

function __get 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 The name of the property to return.

Definition at line 37 of file posts.php.

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

Returns an ascending post

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

Definition at line 1011 of file posts.php.

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

function by_slug select all post content by slug

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

Definition at line 857 of file posts.php.

static Posts::by_status ( status  )  [static]

function by_status select all posts of a given status

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

Definition at line 845 of file posts.php.

Posts::content_type (  ) 

Return the type of the content represented by this object

Returns:
string The name of the content representedt by this object

Implements IsContent.

Definition at line 1196 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 881 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 an author ID
mixed 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 894 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 A tag
mixed 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 910 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 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 868 of file posts.php.

Referenced by AtomHandler::get_collection().

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

Returns a descending post

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

Definition at line 1044 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
  • 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
  • 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:
array 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.

Turn the requested fields into a comma-separated SELECT field clause

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)

Build the final SQL statement

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 104 of file posts.php.

Referenced by Theme::act_display(), Charcoal::action_block_content_charcoal_menu(), K2::action_block_content_k2_menu(), CoreBlocks::action_block_content_monthly_archives(), CoreBlocks::action_block_content_recent_posts(), Mzingi::add_template_vars(), K2::add_template_vars(), 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_latest_entries(), AdminUsersHandler::form_user_success(), AtomHandler::get_collection(), AdminDashboardHandler::get_dashboard(), reassign(), rewrite_match_type(), and AdminUsersHandler::update_users().

static Posts::publish_scheduled_posts ( params  )  [static]

function publish_scheduled_posts

Callback function to publish scheduled posts

Definition at line 972 of file posts.php.

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

Reassigns the author of a specified set of posts

Parameters:
mixed a user ID or name
mixed 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 925 of file posts.php.

Referenced by AdminUsersHandler::form_user_success(), and AdminUsersHandler::update_users().

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

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

Returns:
Boolean Whether the requested post matches the content type of the rule.

Definition at line 1182 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 1076 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 1090 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 994 of file posts.php.

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


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