leilukin-tumbleblog/feathers/quote/quote.php

108 lines
3.5 KiB
PHP
Raw Permalink Normal View History

2024-06-20 14:10:42 +00:00
<?php
class Quote extends Feathers implements Feather {
public function __init() {
$this->setField(
array(
"attr" => "quote",
"type" => "text_block",
"label" => __("Quote", "quote"),
"preview" => true
)
);
$this->setField(
array(
"attr" => "source",
"type" => "text_block",
"label" => __("Source", "quote"),
"optional" => true,
"preview" => true
)
);
$this->setFilter(
"quote",
array("markup_post_text", "markup_text")
);
$this->setFilter(
"source",
array("markup_post_text", "markup_text")
);
}
public function submit(): Post {
if (empty($_POST['quote']))
error(
__("Error"),
__("Quote can't be empty.", "quote"),
code:422
);
fallback($_POST['source'], "");
fallback($_POST['slug'], $_POST['quote']);
fallback($_POST['status'], "public");
fallback($_POST['created_at'], datetime());
fallback($_POST['option'], array());
return Post::add(
values:array(
"quote" => $_POST['quote'],
"source" => $_POST['source']
),
2024-09-05 17:51:48 +00:00
clean:sanitize($_POST['slug'], true, SLUG_STRICT, 128),
2024-06-20 14:10:42 +00:00
feather:"quote",
pinned:!empty($_POST['pinned']),
status:$_POST['status'],
created_at:datetime($_POST['created_at']),
pingbacks:true,
options:$_POST['option']
);
}
public function update($post): Post|false {
if (empty($_POST['quote']))
error(
__("Error"),
__("Quote can't be empty.", "quote"),
code:422
);
fallback($_POST['source'], "");
2024-09-05 17:51:48 +00:00
fallback($_POST['slug'], "");
2024-06-20 14:10:42 +00:00
fallback($_POST['status'], $post->status);
fallback($_POST['created_at'], $post->created_at);
fallback($_POST['option'], array());
return $post->update(
values:array(
"quote" => $_POST['quote'],
"source" => $_POST['source']
),
pinned:!empty($_POST['pinned']),
status:$_POST['status'],
2024-09-05 17:51:48 +00:00
clean:sanitize($_POST['slug'], true, SLUG_STRICT, 128),
2024-06-20 14:10:42 +00:00
created_at:datetime($_POST['created_at']),
options:$_POST['option']
);
}
public function title($post): string {
return $post->title_from_excerpt();
}
public function excerpt($post): string {
return $post->quote;
}
public function feed_content($post): string {
$content = '<blockquote>'.
$post->quote.
'</blockquote>';
if (!empty($post->source))
$content.= '<figcaption><cite>'.
$post->source.
'</cite></figcaption>';
return '<figure>'.$content.'</figure>';
}
}