API/overview

From Habari Project

Jump to: navigation, search

This page or image is a candidate for deletion. The given reason is: There should be a link to the doxygen-generated API somewhere, but most of this is out of date, already more complete somewhere else, or would be better elsewhere. It also uses a hierarchical name, which is icky in MediaWiki.

This notice should remain for a minimum of 1 week after it was placed on the page. If discussion is still ongoing, it should remain until a consensus is reached, after which the page will either be deleted or this notice removed.

If you disagree with its deletion, please discuss your reasons on this page or on its associated talk page, as applicable.

Remember to check if anything links here and the page history before deleting.


This document intends to provide a quick introduction to the Habari API which will assist developers in programmatically accessing the core codebase. It is current as of revision 2453. For a full listing of the API, please see the PHP documentation.

Habari is built around object-oriented concepts, meaning everything is built primarily around classes and methods. Additionally, classes have both private and public methods. Only public methods should be accessed from outside the class.

Contents

Singleton

Many classes in Habari employ a Singleton design pattern, whereby there is only 1 global instance of the class which can be accessed globally.

Posts

The most common API usage is to retrieve, modify, and create posts. These actions are built around the Post and Posts classes.

Retrieving a set of posts

A set of posts can be retrieved by calling Posts::get() anywhere in Habari. The first parameter is optional, and should contain an associative array of filters.

Posts::get(array('user_id' => 1, 'status' => Post::status('published'), 'tag' => 'foo'));

Parameters

These are a variety of parameters you can pass to filter the set of returned post(s). They are listed in no particular order.

  • where is a textual SQL query, which if used will override all other parameters
  • id is the ID of the post
  • nolimit is a boolean limit flag. By default, a maximum 5 posts will be returned for any query. If you set nolimit to true, unlimited posts will be returned.
  • status is the numerical status of the post. This can be retrieved by passing the textual status to Post::status() (ex. Post::status('published'))
  • content_type is the numerical content type of the post. This can be retrieved by passing the textual status to Post::type() (ex. Post::type('entry'))
  • slug is the unique slug for the post
  • user_id is the user ID of the post author
  • tag is either a string or array of the tags which the post(s) should have. This parameter is inclusive, in that if a post has any of the passed tags, it will be returned.
  • tag_slug is either a string or array of the tag slugs which the post(s) should have. This parameter is inclusive, in that if a post has any of the passed tag slugs, it will be returned.
  • all:tag is either a string or array of the tags which the post(s) should have. The post must have all of the passed tags to be returned.
  • not:tag is either a string or array of the tags which the post(s) should not have. This parameter is exclusive, in that if a post has any of the passed tags, it will not be returned.
  • criteria is a search query to be performed
  • all:info matches posts based upon their post info. The post must match all of the passed info to be returned.
  • any:info matches posts based upon their post info. The post may match any of the passed info to be returned.
  • not:all:info filters out posts based upon their post info. If a post has all of the passed info, it will not be returned.
  • not:any:info filters out posts based upon their post info. If a post has any of the passed info, it will not be returned.
Personal tools