Skip to content

Instantly share code, notes, and snippets.

@vito
Created July 22, 2008 03:49
Show Gist options
  • Save vito/634 to your computer and use it in GitHub Desktop.
Save vito/634 to your computer and use it in GitHub Desktop.
<?php
class Text extends Feathers implements Feather {
public function __construct() {
$this->setField(array("attr" => "title",
"type" => "text",
"label" => __("Title", "text"),
"optional" => true,
"bookmarklet" => "title"));
$this->setField(array("attr" => "body",
"type" => "text_block",
"label" => __("Body", "text"),
"preview" => true,
"bookmarklet" => "selection"));
$this->setFilter("body", "markup_post_text");
$this->setFilter("title", "markup_post_title");
}
public function submit() {
if (empty($_POST['body']))
error(__("Error"), __("Body can't be blank."));
fallback($_POST['slug'], sanitize($_POST['title']));
return Post::add(array("title" => $_POST['title'],
"body" => $_POST['body']),
$_POST['slug'],
Post::check_url($_POST['slug']));
}
public function update() {
if (empty($_POST['body']))
error(__("Error"), __("Body can't be blank."));
$post = new Post($_POST['id']);
$post->update(array("title" => $_POST['title'],
"body" => $_POST['body']));
}
public function title($post) {
return fallback($post->title, $post->title_from_excerpt(), true);
}
public function excerpt($post) {
return $post->body;
}
public function feed_content($post) {
return $post->body;
}
}
<?php
class Quote extends Feathers implements Feather {
public function __construct() {
$this->setField(array("attr" => "quote",
"type" => "text_block",
"rows" => 5,
"label" => __("Quote", "quote"),
"bookmarklet" => "selection"));
$this->setField(array("attr" => "source",
"type" => "text_block",
"rows" => 5,
"label" => __("Source", "quote"),
"optional" => true,
"preview" => true,
"bookmarklet" => "page_title"));
$this->setFilter("quote", "markup_post_text");
$this->setFilter("source", "markup_post_text");
}
public function submit() {
if (empty($_POST['quote']))
error(__("Error"), __("Quote can't be empty.", "quote"));
return Post::add(array("quote" => $_POST['quote'],
"source" => $_POST['source']),
$_POST['slug'],
Post::check_url($_POST['slug']));
}
public function update() {
if (empty($_POST['quote']))
error(__("Error"), __("Quote can't be empty."));
$post = new Post($_POST['id']);
$post->update(array("quote" => $_POST['quote'],
"source" => $_POST['source']));
}
public function title($post) {
return $post->title_from_excerpt();
}
public function excerpt($post) {
return $post->quote;
}
public function add_dash($text) {
return preg_replace("/(<p(\s+[^>]+)?>|^)/si", "\\1— ", $text, 1);
}
public function feed_content($post) {
$body = "<blockquote>\n\t";
$body.= $post->quote;
$body.= "\n</blockquote>\n";
$body.= $post->source;
return $body;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment