Chyrp

Post

The Post model.

See Also

Model

Summary
Post The Post model.
Variables
$url_attrs The translation array of the post URL setting to regular expressions.  Passed through the route_code filter.
Functions
__construct Model::grab
find Model::search
add Adds a post to the database with the passed XML, sanitized URL, and unique URL.  The rest is read from $_POST.
update Updates a post with the given XML.  The rest is read from $_POST.
delete <Model::destroy>
deletable Checks if the User can delete the post.
editable Checks if the User can edit the post.
any_editable Checks if the Visitor can edit any posts.
any_deletable Checks if the Visitor can delete any posts.
exists Checks if a post exists.
check_url Checks if a given clean URL is already being used as another post’s URL.
url Returns a post’s URL.
user Returns a post’s user.  Example: $post->user()->login
title_from_excerpt Generates an acceptable Title from the post’s excerpt.
title Returns the given post’s title, provided by its Feather.
excerpt Returns the given post’s excerpt, provided by its Feather.
feed_content Returns the given post’s Feed content, provided by its Feather.
next The next post (the post made after this one).
prev The next post (the post made after this one).
theme_exists Checks if the current post’s feather theme file exists.
parse Parses the passed XML and loads the tags and values into Post.
edit_link Outputs an edit link for the post, if the <User.can> edit_post.
delete_link Outputs a delete link for the post, if the <User.can> delete_post.
trackback_url Returns the posts trackback URL.
arr2xml Recursively adds an array (or object I guess) to a SimpleXML object.
xml2arr Recursively converts a SimpleXML object (and children) to an array.
send_pingbacks Sends any callbacks in $value.  Used by array_walk_recursive in Post.add.
from_url Attempts to grab a post from its clean URL.
statuses Returns a SQL query “chunk” for the “status” column permissions of the current user.
enabled_feathers Returns a SQL query “chunk” for the “feather” column so that it matches enabled feathers.

Variables

$url_attrs

static $url_attrs

The translation array of the post URL setting to regular expressions.  Passed through the route_code filter.

Functions

__construct

public function __construct( $post_id  =  null,
$options  =  array() )

See Also

Model::grab

find

static function find( $options  =  array(),
$options_for_object  =  array(),
$debug  =  false )

See Also

Model::search

add

static function add( $values,   
$clean  =  "",
$url  =  "",
$feather  =  null,
$user  =  null,
$pinned  =  null,
$status  =  null,
$created_at  =  null,
$updated_at  =  null,
$trackbacks  =  "",
$pingbacks  =  true,
$options  =  null )

Adds a post to the database with the passed XML, sanitized URL, and unique URL.  The rest is read from $_POST.

Trackbacks are automatically sent based on the contents of $_POST[‘trackbacks’].  Most of the $_POST variables will fall back gracefully if they don’t exist, e.g. if they’re posting from the Bookmarklet.

Calls the add_post trigger with the inserted post and extra options.

Parameters

$values The data to insert.
$clean The sanitized URL (or empty to default to “(feather).(new post’s id)”).
$url The unique URL (or empty to default to “(feather).(new post’s id)”).
$feather The feather to post as.
$user User to set as the post’s author.
$pinned Pin the post?
$status Post status
$slug A new URL for the post.
$created_at New created_at timestamp for the post.
$updated_at New updated_at timestamp for the post, or false to not updated it.
$trackbacks URLs separated by “ “ to send trackbacks to.
$options Options for the post.

Returns

self An object containing the new post.

See Also

update

update

public function update( $values,   
$user  =  null,
$pinned  =  null,
$status  =  null,
$slug  =  null,
$created_at  =  null,
$updated_at  =  null,
$options  =  null )

Updates a post with the given XML.  The rest is read from $_POST.

Most of the $_POST variables will fall back gracefully if they don’t exist, e.g. if they’re posting from the Bookmarklet.

Parameters

$values An array of data to set for the post.
$user User to set as the post’s author.
$pinned Pin the post?
$status Post status
$slug A new URL for the post.
$created_at New created_at timestamp for the post.
$updated_at New updated_at timestamp for the post, or false to not updated it.
$options Options for the post.

See Also

add

delete

static function delete( $id )

See Also

<Model::destroy>

deletable

public function deletable( $user  =  null )

Checks if the User can delete the post.

editable

public function editable( $user  =  null )

Checks if the User can edit the post.

any_editable

static function any_editable()

Checks if the Visitor can edit any posts.

any_deletable

static function any_deletable()

Checks if the Visitor can delete any posts.

exists

static function exists( $post_id )

Checks if a post exists.

Parameters

$post_id The post ID to check

Returns

true if a post with that ID is in the database.

check_url

static function check_url( $clean )

Checks if a given clean URL is already being used as another post’s URL.

Parameters

$clean The clean URL to check.

Returns

$url The unique version of the passed clean URL.  If it’s not used, it’s the same as $clean.  If it is, a number is appended.

url

public function url()

Returns a post’s URL.

user

public function user()

Returns a post’s user.  Example: $post->user()->login

title_from_excerpt

public function title_from_excerpt()

Generates an acceptable Title from the post’s excerpt.

Returns

The post’s excerpt. iltered -> first line -> ftags stripped -> truncated to 75 characters -> normalized.

title

public function title()

Returns the given post’s title, provided by its Feather.

excerpt

public function excerpt()

Returns the given post’s excerpt, provided by its Feather.

feed_content

public function feed_content()

Returns the given post’s Feed content, provided by its Feather.

next

public function next()

Returns

The next post (the post made after this one).

prev

public function prev()

Returns

The next post (the post made after this one).

theme_exists

public function theme_exists()

Checks if the current post’s feather theme file exists.

parse

private function parse()

Parses the passed XML and loads the tags and values into Post.

edit_link

public function edit_link( $text  =  null,
$before  =  null,
$after  =  null )

Outputs an edit link for the post, if the <User.can> edit_post.

Parameters

$text The text to show for the link.
$before If the link can be shown, show this before it.
$after If the link can be shown, show this after it.

delete_link

public function delete_link( $text  =  null,
$before  =  null,
$after  =  null )

Outputs a delete link for the post, if the <User.can> delete_post.

Parameters

$text The text to show for the link.
$before If the link can be shown, show this before it.
$after If the link can be shown, show this after it.

trackback_url

public function trackback_url()

Returns the posts trackback URL.

arr2xml

static function arr2xml( & $object,
$data )

Recursively adds an array (or object I guess) to a SimpleXML object.

Parameters

$object The SimpleXML object to add to.
$data The data to add to the SimpleXML object.

xml2arr

static function xml2arr( $parse )

Recursively converts a SimpleXML object (and children) to an array.

Parameters

$parse The SimpleXML object to convert into an array.

send_pingbacks

static function send_pingbacks( $value,
$key,
$post )

Sends any callbacks in $value.  Used by array_walk_recursive in Post.add.

from_url

static function from_url( $attrs  =  null,
$options  =  array() )

Attempts to grab a post from its clean URL.

statuses

static function statuses( $start  =  array() )

Returns a SQL query “chunk” for the “status” column permissions of the current user.

Parameters

$start An array of additional statuses to allow; “registered_only” and “private” are added deterministically.

enabled_feathers

Returns a SQL query “chunk” for the “feather” column so that it matches enabled feathers.