Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
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.

457 lines
15 KiB

6 years ago
10 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. Friendica Addon/Plugin development
  2. ==========================
  3. Please see the sample addon 'randplace' for a working example of using some of these features.
  4. The facebook addon provides an example of integrating both "addon" and "module" functionality.
  5. Addons work by intercepting event hooks - which must be registered.
  6. Modules work by intercepting specific page requests (by URL path).
  7. Plugin names cannot contain spaces or other punctuation and are used as filenames and function names.
  8. You may supply a "friendly" name within the comment block.
  9. Each addon must contain both an install and an uninstall function based on the addon/plugin name.
  10. For instance "plugin1name_install()".
  11. These two functions take no arguments and are usually responsible for registering (and unregistering) event hooks that your plugin will require.
  12. The install and uninstall functions will also be called (i.e. re-installed) if the plugin changes after installation.
  13. Therefore your uninstall should not destroy data and install should consider that data may already exist.
  14. Future extensions may provide for "setup" amd "remove".
  15. Plugins should contain a comment block with the four following parameters:
  16. /*
  17. * Name: My Great Plugin
  18. * Description: This is what my plugin does. It's really cool
  19. * Version: 1.0
  20. * Author: John Q. Public <>
  21. */
  22. Register your plugin hooks during installation.
  23. register_hook($hookname, $file, $function);
  24. $hookname is a string and corresponds to a known Friendica hook.
  25. $file is a pathname relative to the top-level Friendica directory.
  26. This *should* be 'addon/plugin_name/plugin_name.php' in most cases.
  27. $function is a string and is the name of the function which will be executed when the hook is called.
  28. Arguments
  29. ---
  30. Your hook callback functions will be called with at least one and possibly two arguments
  31. function myhook_function(&$a, &$b) {
  32. }
  33. If you wish to make changes to the calling data, you must declare them as reference variables (with '&') during function declaration.
  34. ###$a
  35. $a is the Friendica 'App' class.
  36. It contains a wealth of information about the current state of Friendica:
  37. * which module has been called,
  38. * configuration information,
  39. * the page contents at the point the hook was invoked,
  40. * profile and user information, etc.
  41. It is recommeded you call this '$a' to match its usage elsewhere.
  42. ###$b
  43. $b can be called anything you like.
  44. This is information specific to the hook currently being processed, and generally contains information that is being immediately processed or acted on that you can use, display, or alter.
  45. Remember to declare it with '&' if you wish to alter it.
  46. Modules
  47. --------
  48. Plugins/addons may also act as "modules" and intercept all page requests for a given URL path.
  49. In order for a plugin to act as a module it needs to define a function "plugin_name_module()" which takes no arguments and needs not do anything.
  50. If this function exists, you will now receive all page requests for "" - with any number of URL components as additional arguments.
  51. These are parsed into an array $a->argv, with a corresponding $a->argc indicating the number of URL components.
  52. So would look for a module named "plugin" and pass its module functions the $a App structure (which is available to many components).
  53. This will include:
  54. $a->argc = 3
  55. $a->argv = array(0 => 'plugin', 1 => 'arg1', 2 => 'arg2');
  56. Your module functions will often contain the function plugin_name_content(&$a), which defines and returns the page body content.
  57. They may also contain plugin_name_post(&$a) which is called before the _content function and typically handles the results of POST forms.
  58. You may also have plugin_name_init(&$a) which is called very early on and often does module initialisation.
  59. Templates
  60. ----------
  61. If your plugin needs some template, you can use the Friendica template system.
  62. Friendica uses [smarty3]( as a template engine.
  63. Put your tpl files in the *templates/* subfolder of your plugin.
  64. In your code, like in the function plugin_name_content(), load the template file and execute it passing needed values:
  65. # load template file. first argument is the template name,
  66. # second is the plugin path relative to friendica top folder
  67. $tpl = get_markup_template('mytemplate.tpl', 'addon/plugin_name/');
  68. # apply template. first argument is the loaded template,
  69. # second an array of 'name'=>'values' to pass to template
  70. $output = replace_macros($tpl,array(
  71. 'title' => 'My beautiful plugin',
  72. ));
  73. See also the wiki page [Quick Template Guide](
  74. Current hooks
  75. -------------
  76. ###'authenticate'
  77. 'authenticate' is called when a user attempts to login.
  78. $b is an array containing:
  79. 'username' => the supplied username
  80. 'password' => the supplied password
  81. 'authenticated' => set this to non-zero to authenticate the user.
  82. 'user_record' => successful authentication must also return a valid user record from the database
  83. ###'logged_in'
  84. 'logged_in' is called after a user has successfully logged in.
  85. $b contains the $a->user array.
  86. ###'display_item'
  87. 'display_item' is called when formatting a post for display.
  88. $b is an array:
  89. 'item' => The item (array) details pulled from the database
  90. 'output' => the (string) HTML representation of this item prior to adding it to the page
  91. ###'post_local'
  92. * called when a status post or comment is entered on the local system
  93. * $b is the item array of the information to be stored in the database
  94. * Please note: body contents are bbcode - not HTML
  95. ###'post_local_end'
  96. * called when a local status post or comment has been stored on the local system
  97. * $b is the item array of the information which has just been stored in the database
  98. * Please note: body contents are bbcode - not HTML
  99. ###'post_remote'
  100. * called when receiving a post from another source. This may also be used to post local activity or system generated messages.
  101. * $b is the item array of information to be stored in the database and the item body is bbcode.
  102. ###'settings_form'
  103. * called when generating the HTML for the user Settings page
  104. * $b is the (string) HTML of the settings page before the final '</form>' tag.
  105. ###'settings_post'
  106. * called when the Settings pages are submitted
  107. * $b is the $_POST array
  108. ###'plugin_settings'
  109. * called when generating the HTML for the addon settings page
  110. * $b is the (string) HTML of the addon settings page before the final '</form>' tag.
  111. ###'plugin_settings_post'
  112. * called when the Addon Settings pages are submitted
  113. * $b is the $_POST array
  114. ###'profile_post'
  115. * called when posting a profile page
  116. * $b is the $_POST array
  117. ###'profile_edit'
  118. 'profile_edit' is called prior to output of profile edit page.
  119. $b is an array containing:
  120. 'profile' => profile (array) record from the database
  121. 'entry' => the (string) HTML of the generated entry
  122. ###'profile_advanced'
  123. * called when the HTML is generated for the 'Advanced profile', corresponding to the 'Profile' tab within a person's profile page
  124. * $b is the (string) HTML representation of the generated profile
  125. * The profile array details are in $a->profile.
  126. ###'directory_item'
  127. 'directory_item' is called from the Directory page when formatting an item for display.
  128. $b is an array:
  129. 'contact' => contact (array) record for the person from the database
  130. 'entry' => the (string) HTML of the generated entry
  131. ###'profile_sidebar_enter'
  132. * called prior to generating the sidebar "short" profile for a page
  133. * $b is the person's profile array
  134. ###'profile_sidebar'
  135. 'profile_sidebar is called when generating the sidebar "short" profile for a page.
  136. $b is an array:
  137. 'profile' => profile (array) record for the person from the database
  138. 'entry' => the (string) HTML of the generated entry
  139. ###'contact_block_end'
  140. is called when formatting the block of contacts/friends on a profile sidebar has completed.
  141. $b is an array:
  142. 'contacts' => array of contacts
  143. 'output' => the (string) generated HTML of the contact block
  144. ###'bbcode'
  145. * called during conversion of bbcode to html
  146. * $b is a string converted text
  147. ###'html2bbcode'
  148. * called during conversion of html to bbcode (e.g. remote message posting)
  149. * $b is a string converted text
  150. ###'page_header'
  151. * called after building the page navigation section
  152. * $b is a string HTML of nav region
  153. ###'personal_xrd'
  154. 'personal_xrd' is called prior to output of personal XRD file.
  155. $b is an array:
  156. 'user' => the user record for the person
  157. 'xml' => the complete XML to be output
  158. ###'home_content'
  159. * called prior to output home page content, shown to unlogged users
  160. * $b is (string) HTML of section region
  161. ###'contact_edit'
  162. is called when editing contact details on an individual from the Contacts page.
  163. $b is an array:
  164. 'contact' => contact record (array) of target contact
  165. 'output' => the (string) generated HTML of the contact edit page
  166. ###'contact_edit_post'
  167. * called when posting the contact edit page.
  168. * $b is the $_POST array
  169. ###'init_1'
  170. * called just after DB has been opened and before session start
  171. * $b is not used or passed
  172. ###'page_end'
  173. * called after HTML content functions have completed
  174. * $b is (string) HTML of content div
  175. ###'avatar_lookup'
  176. 'avatar_lookup' is called when looking up the avatar.
  177. $b is an array:
  178. 'size' => the size of the avatar that will be looked up
  179. 'email' => email to look up the avatar for
  180. 'url' => the (string) generated URL of the avatar
  181. ###'emailer_send_prepare'
  182. 'emailer_send_prepare' called from Emailer::send() before building the mime message.
  183. $b is an array, params to Emailer::send()
  184. 'fromName' => name of the sender
  185. 'fromEmail' => email fo the sender
  186. 'replyTo' => replyTo address to direct responses
  187. 'toEmail' => destination email address
  188. 'messageSubject' => subject of the message
  189. 'htmlVersion' => html version of the message
  190. 'textVersion' => text only version of the message
  191. 'additionalMailHeader' => additions to the smtp mail header
  192. ###'emailer_send'
  193. is called before calling PHP's mail().
  194. $b is an array, params to mail()
  195. 'to'
  196. 'subject'
  197. 'body'
  198. 'headers'
  199. ###'nav_info'
  200. is called after the navigational menu is build in include/nav.php.
  201. $b is an array containing $nav from nav.php.
  202. Complete list of hook callbacks
  203. ---
  204. Here is a complete list of all hook callbacks with file locations (as of 14-Feb-2012). Please see the source for details of any hooks not documented above.
  205. boot.php: call_hooks('login_hook',$o);
  206. boot.php: call_hooks('profile_sidebar_enter', $profile);
  207. boot.php: call_hooks('profile_sidebar', $arr);
  208. boot.php: call_hooks("proc_run", $arr);
  209. include/contact_selectors.php: call_hooks('network_to_name', $nets);
  210. include/api.php: call_hooks('logged_in', $a->user);
  211. include/api.php: call_hooks('logged_in', $a->user);
  212. include/queue.php: call_hooks('queue_predeliver', $a, $r);
  213. include/queue.php: call_hooks('queue_deliver', $a, $params);
  214. include/text.php: call_hooks('contact_block_end', $arr);
  215. include/text.php: call_hooks('smilie', $s);
  216. include/text.php: call_hooks('prepare_body_init', $item);
  217. include/text.php: call_hooks('prepare_body', $prep_arr);
  218. include/text.php: call_hooks('prepare_body_final', $prep_arr);
  219. include/nav.php: call_hooks('page_header', $a->page['nav']);
  220. include/auth.php: call_hooks('authenticate', $addon_auth);
  221. include/bbcode.php: call_hooks('bbcode',$Text);
  222. include/oauth.php: call_hooks('logged_in', $a->user);
  223. include/acl_selectors.php: call_hooks($a->module . '_pre_' . $selname, $arr);
  224. include/acl_selectors.php: call_hooks($a->module . '_post_' . $selname, $o);
  225. include/acl_selectors.php: call_hooks('contact_select_options', $x);
  226. include/acl_selectors.php: call_hooks($a->module . '_pre_' . $selname, $arr);
  227. include/acl_selectors.php: call_hooks($a->module . '_post_' . $selname, $o);
  228. include/acl_selectors.php: call_hooks($a->module . '_pre_' . $selname, $arr);
  229. include/acl_selectors.php: call_hooks($a->module . '_post_' . $selname, $o);
  230. include/notifier.php: call_hooks('notifier_normal',$target_item);
  231. include/notifier.php: call_hooks('notifier_end',$target_item);
  232. include/items.php: call_hooks('atom_feed', $atom);
  233. include/items.php: call_hooks('atom_feed_end', $atom);
  234. include/items.php: call_hooks('atom_feed_end', $atom);
  235. include/items.php: call_hooks('parse_atom', $arr);
  236. include/items.php: call_hooks('post_remote',$arr);
  237. include/items.php: call_hooks('atom_author', $o);
  238. include/items.php: call_hooks('atom_entry', $o);
  239. include/bb2diaspora.php: call_hooks('bb2diaspora',$Text);
  240. include/cronhooks.php: call_hooks('cron', $d);
  241. include/security.php: call_hooks('logged_in', $a->user);
  242. include/html2bbcode.php: call_hooks('html2bbcode', $text);
  243. include/Contact.php: call_hooks('remove_user',$r[0]);
  244. include/Contact.php: call_hooks('contact_photo_menu', $args);
  245. include/conversation.php: call_hooks('conversation_start',$cb);
  246. include/conversation.php: call_hooks('render_location',$locate);
  247. include/conversation.php: call_hooks('display_item', $arr);
  248. include/conversation.php: call_hooks('render_location',$locate);
  249. include/conversation.php: call_hooks('display_item', $arr);
  250. include/conversation.php: call_hooks('item_photo_menu', $args);
  251. include/conversation.php: call_hooks('jot_tool', $jotplugins);
  252. include/conversation.php: call_hooks('jot_networks', $jotnets);
  253. include/plugin.php:if(! function_exists('call_hooks')) {
  254. include/plugin.php:function call_hooks($name, &$data = null) {
  255. index.php: call_hooks('init_1');
  256. index.php:call_hooks('app_menu', $arr);
  257. index.php:call_hooks('page_end', $a->page['content']);
  258. mod/photos.php: call_hooks('photo_post_init', $_POST);
  259. mod/photos.php: call_hooks('photo_post_file',$ret);
  260. mod/photos.php: call_hooks('photo_post_end',$foo);
  261. mod/photos.php: call_hooks('photo_post_end',$foo);
  262. mod/photos.php: call_hooks('photo_post_end',$foo);
  263. mod/photos.php: call_hooks('photo_post_end',intval($item_id));
  264. mod/photos.php: call_hooks('photo_upload_form',$ret);
  265. mod/friendica.php: call_hooks('about_hook', $o);
  266. mod/editpost.php: call_hooks('jot_tool', $jotplugins);
  267. mod/editpost.php: call_hooks('jot_networks', $jotnets);
  268. mod/parse_url.php: call_hooks('parse_link', $arr);
  269. mod/home.php: call_hooks('home_init',$ret);
  270. mod/home.php: call_hooks("home_content",$o);
  271. mod/contacts.php: call_hooks('contact_edit_post', $_POST);
  272. mod/contacts.php: call_hooks('contact_edit', $arr);
  273. mod/settings.php: call_hooks('plugin_settings_post', $_POST);
  274. mod/settings.php: call_hooks('connector_settings_post', $_POST);
  275. mod/settings.php: call_hooks('settings_post', $_POST);
  276. mod/settings.php: call_hooks('plugin_settings', $settings_addons);
  277. mod/settings.php: call_hooks('connector_settings', $settings_connectors);
  278. mod/settings.php: call_hooks('settings_form',$o);
  279. mod/register.php: call_hooks('register_account', $newuid);
  280. mod/like.php: call_hooks('post_local_end', $arr);
  281. mod/xrd.php: call_hooks('personal_xrd', $arr);
  282. mod/item.php: call_hooks('post_local_start', $_REQUEST);
  283. mod/item.php: call_hooks('post_local',$datarray);
  284. mod/item.php: call_hooks('post_local_end', $datarray);
  285. mod/profile.php: call_hooks('profile_advanced',$o);
  286. mod/profiles.php: call_hooks('profile_post', $_POST);
  287. mod/profiles.php: call_hooks('profile_edit', $arr);
  288. mod/tagger.php: call_hooks('post_local_end', $arr);
  289. mod/cb.php: call_hooks('cb_init');
  290. mod/cb.php: call_hooks('cb_post', $_POST);
  291. mod/cb.php: call_hooks('cb_afterpost');
  292. mod/cb.php: call_hooks('cb_content', $o);
  293. mod/directory.php: call_hooks('directory_item', $arr);