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.

107 lines
4.0KB

  1. <?php
  2. /**
  3. * Class: Feathers
  4. * Contains various functions, acts as the backbone for all feathers.
  5. */
  6. class Feathers {
  7. # Array: $instances
  8. # Holds all Module instantiations.
  9. static $instances = array();
  10. # Array: $custom_filters
  11. # Manages named Trigger filters for Feather fields.
  12. static $filters = array();
  13. # Array: $custom_filters
  14. # Manages custom Feather-provided Trigger filters.
  15. static $custom_filters = array();
  16. /**
  17. * Function: setFilter
  18. * Applies a filter to a specified field of the Feather.
  19. *
  20. * Parameters:
  21. * $field - Attribute of the post to filter.
  22. * $name - Name of the filter to use.
  23. *
  24. * See Also:
  25. * <Trigger.filter>
  26. */
  27. protected function setFilter($field, $name) {
  28. self::$filters[get_class($this)][] = array("field" => $field, "name" => $name);
  29. }
  30. /**
  31. * Function: customFilter
  32. * Allows a Feather to apply its own filter to a specified field.
  33. *
  34. * Parameters:
  35. * $field - Attribute of the post to filter.
  36. * $name - Name of the class function to use as the filter.
  37. * $priority - Priority of the filter.
  38. *
  39. * See Also:
  40. * <Trigger.filter>
  41. */
  42. protected function customFilter($field, $name, $priority = 10) {
  43. self::$custom_filters[get_class($this)][] = array("field" => $field, "name" => $name);
  44. }
  45. /**
  46. * Function: respondTo
  47. * Allows a Feather to respond to a Trigger as a Module would.
  48. *
  49. * Parameters:
  50. * $name - Name of the trigger to respond to.
  51. * $function - Name of the class function to respond with.
  52. * $priority - Priority of the response.
  53. *
  54. * See Also:
  55. * <Trigger>
  56. */
  57. protected function respondTo($name, $function = null, $priority = 10) {
  58. fallback($function, $name);
  59. Trigger::current()->priorities[$name][] = array("priority" => $priority, "function" => array($this, $function));
  60. }
  61. /**
  62. * Function: setField
  63. * Sets the feather's fields for creating/editing posts with that feather.
  64. *
  65. * Parameters:
  66. * $options - An array of key => val options for the field.
  67. *
  68. * Options:
  69. * attr - The technical name for the field. Think $post->attr.
  70. * type - The field type. (text, file, text_block, or select)
  71. * label - The label for the field.
  72. * preview - Is this field previewable?
  73. * optional - Is this field optional?
  74. * bookmarklet - What to fill this field by in the bookmarklet.
  75. * url or page_url - The URL of the page they're viewing when they open the bookmarklet.
  76. * title or page_title - The title of the page they're viewing when they open the bookmarklet.
  77. * selection - Their selection on the page they're viewing when they open the bookmarklet.
  78. * extra - Stuff to output after the input field. Can be anything.
  79. * note - A minor note to display next to the label text.
  80. */
  81. protected function setField($options) {
  82. fallback($options["classes"], array());
  83. if (isset($options["class"]))
  84. $options["classes"][] = $options["class"];
  85. if (isset($options["preview"]) and $options["preview"])
  86. $options["classes"][] = "preview_me";
  87. $this->fields[$options["attr"]] = $options;
  88. }
  89. /**
  90. * Function: bookmarkletSelected
  91. * The Feather that this function is called from will be selected when they open the Bookmarklet.
  92. */
  93. protected function bookmarkletSelected() {
  94. AdminController::current()->selected_bookmarklet = $this->safename;
  95. }
  96. }