KXStudio Website https://kx.studio/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.8KB

  1. <?php
  2. class Link extends Feathers implements Feather {
  3. public function __init() {
  4. $this->setField(array("attr" => "source",
  5. "type" => "text",
  6. "label" => __("URL", "link"),
  7. "bookmarklet" => "url"));
  8. $this->setField(array("attr" => "name",
  9. "type" => "text",
  10. "label" => __("Name", "link"),
  11. "bookmarklet" => "title"));
  12. $this->setField(array("attr" => "description",
  13. "type" => "text_block",
  14. "label" => __("Description", "link"),
  15. "optional" => true,
  16. "preview" => true,
  17. "bookmarklet" => "selection"));
  18. $this->setFilter("name", array("markup_title", "markup_post_title"));
  19. $this->setFilter("description", array("markup_text", "markup_post_text"));
  20. $this->respondTo("feed_url", "set_feed_url");
  21. }
  22. public function submit() {
  23. if (empty($_POST['source']))
  24. error(__("Error"), __("URL can't be empty."));
  25. if (!@parse_url($_POST['source'], PHP_URL_SCHEME))
  26. $_POST['source'] = "http://".$_POST['source'];
  27. fallback($_POST['slug'], sanitize($_POST['name']));
  28. return Post::add(array("name" => $_POST['name'],
  29. "source" => $_POST['source'],
  30. "description" => $_POST['description']),
  31. $_POST['slug'],
  32. Post::check_url($_POST['slug']));
  33. }
  34. public function update($post) {
  35. if (empty($_POST['source']))
  36. error(__("Error"), __("URL can't be empty."));
  37. if (!@parse_url($_POST['source'], PHP_URL_SCHEME))
  38. $_POST['source'] = "http://".$_POST['source'];
  39. $post->update(array("name" => $_POST['name'],
  40. "source" => $_POST['source'],
  41. "description" => $_POST['description']));
  42. }
  43. public function title($post) {
  44. $return = $post->name;
  45. fallback($return, $post->title_from_excerpt());
  46. fallback($return, $post->source);
  47. return $return;
  48. }
  49. public function excerpt($post) {
  50. return $post->description;
  51. }
  52. public function feed_content($post) {
  53. return $post->description;
  54. }
  55. public function set_feed_url($url, $post) {
  56. if ($post->feather != "link") return;
  57. return $url = $post->source;
  58. }
  59. }