Skip to content

Anatomy of a Feather

Daniel Pimley edited this page Mar 18, 2017 · 37 revisions

Feathers enable Chyrp Lite to render different types of content in blog posts. Feathers are simply a class that extends the Feathers class and implements the Feather interface, to ensure that all feathers provide the correct structure.

Feather Functions

__init(), __install(), and __uninstall() are optional, but the rest are required.

__init()

This function is called after all of the modules and feathers are instantiated. It exists because calling other triggers in your feather's __construct() function would be problematic because not every extension is ready to react.

__install()

This function is called when the Feather is enabled.

__uninstall($confirm)

This function is called when the feather is disabled. There is one possible argument, and that's if your feather has a confirm metadata item; the argument will be a boolean of whether or not the user confirmed the dialogue.

##### submit() This is the function called when submitting a post.

update($post)

This is the function called when updating a post.

##### title($post) This function should return the most logical title for the post. If there is no obvious title field that you can return, use $post->title_from_excerpt().

excerpt($post)

This returns the source for the excerpt. You do not need to do any truncation, it's handled automatically by wherever it was called from.

feed_content($post)

This returns the content for a feed entry.

Feather Construct Functions

There are a few functions that the Feathers class provides to feathers, mainly to be used in the __construct() or __init() function.

$this->setField()

This sets a field for your feather, for use on Write/Edit pages.

function __init() {
        $this->setField(array(# The name of the post attribute.
                              "attr" => "body",
                              # One of text, text_block, file, checkbox, select.
                              "type" => "text_block",
                              # The label for the field on the Write/Edit page.
                              "label" => __("Body", "my_feather"),
                              # If set, this will appear alongside the label.
                              "note" => __("I am a note!", "my_feather"),
                              # Can the field be blank?
                              "optional" => true,
                              # Can the field be previewed?
                              "preview" => true,
                              # For file fields: allow multiple files?
                              "multiple" => false,
                              # For select fields: an array of options.
                              "options" => array(array("name" => $name,
                                                       "value" => $value,
                                                       "selected" => true))));
}
$this->setFilter()

This function is used for applying a filter to a given attribute. Filters will be stacked and executed in the order that they are specified, therefore it is usually preferable to specify specialised filters before general-purpose ones.

function __init() {
    $this->setFilter("body", array("markup_post_text", "markup_text"));
}
$this->customFilter()

Much like setFilter(), but the second argument is a public function your feather provides. Custom filters will be executed before any filters added with setFilter().

function __init() {
    $this->customFilter("body", "my_filter_function", (int) $priority);
}
$this->respondTo()

Calling this sets your feather up to respond to a Trigger like a Module would.

function __init() {
    $this->respondTo("feed_item", "my_filter_function", (int) $priority);
}
Clone this wiki locally