]> git.mxchange.org Git - friendica.git/blobdiff - doc/Addons.md
Merge pull request #5234 from fabrixxm/fix/api
[friendica.git] / doc / Addons.md
index dadf76abd7dc677ea05566c8f641214b0745991f..22b34fa62b9301f5b57737f936f5cecb6077dbb3 100644 (file)
@@ -25,22 +25,24 @@ Addons should contain a comment block with the four following parameters:
      * Author: John Q. Public <john@myfriendicasite.com>
      */
 
+Please also add a README or README.md file to the addon directory.
+It will be displayed in the admin panel and should include some further information in addition to the header information.
+
+PHP addon hooks
+---
+
 Register your addon hooks during installation.
 
     Addon::registerHook($hookname, $file, $function);
 
-$hookname is a string and corresponds to a known Friendica hook.
+$hookname is a string and corresponds to a known Friendica PHP hook.
 
 $file is a pathname relative to the top-level Friendica directory.
-This *should* be 'addon/addon_name/addon_name.php' in most cases.
+This *should* be 'addon/*addon_name*/*addon_name*.php' in most cases.
 
 $function is a string and is the name of the function which will be executed when the hook is called.
 
-Please also add a README or README.md file to the addon directory.
-It will be displayed in the admin panel and should include some further information in addition to the header information.
-
-Arguments
----
+#### Arguments
 Your hook callback functions will be called with at least one and possibly two arguments
 
     function myhook_function(App $a, &$b) {
@@ -50,7 +52,7 @@ Your hook callback functions will be called with at least one and possibly two a
 
 If you wish to make changes to the calling data, you must declare them as reference variables (with '&') during function declaration.
 
-#### $a
+##### $a
 $a is the Friendica 'App' class.
 It contains a wealth of information about the current state of Friendica:
 
@@ -61,11 +63,50 @@ It contains a wealth of information about the current state of Friendica:
 
 It is recommeded you call this '$a' to match its usage elsewhere.
 
-#### $b
+##### $b
 $b can be called anything you like.
 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.
 Remember to declare it with '&' if you wish to alter it.
 
+JavaScript addon hooks
+---
+
+#### PHP part
+Make sure your JavaScript addon file (addon/*addon_name*/*addon_name*.js) is listed in the document response. 
+
+In your addon install function, add:
+
+    Addon::registerHook('template_vars', 'addon/<addon_name>/<addon_name>.php', '<addon_name>_template_vars');
+    
+In your addon uninstall function, add:
+
+    Addon::unregisterHook('template_vars', 'addon/<addon_name>/<addon_name>.php', '<addon_name>_template_vars');
+
+Then, add your addon name to the *addon_hooks* template variable array:
+
+     function <addon_name>_template_vars($a, &$arr)
+       {
+         if (!array_key_exists('addon_hooks',$arr['vars']))
+         {
+            $arr['vars']['addon_hooks'] = array();
+         }
+       $arr['vars']['addon_hooks'][] = "<addon_name>";
+       }
+
+#### JavaScript part
+Register your addon hooks in file 'addon/*addon_name*/*addon_name*.js'.
+
+    Addon_registerHook(type,hookfnstr);
+
+*type* is the name of the hook and corresponds to a known Friendica JavaScript hook.
+*hookfnstr* is the name of your JavaScript function to execute.
+
+No arguments are provided to your JavaScript callback function. Example:
+
+    function myhook_function() {
+  
+    }
+
 Modules
 ---
 
@@ -106,7 +147,7 @@ In your code, like in the function addon_name_content(), load the template file
 
 See also the wiki page [Quick Template Guide](https://github.com/friendica/friendica/wiki/Quick-Template-Guide).
 
-Current hooks
+Current PHP hooks
 -------------
 
 ### 'authenticate'
@@ -126,8 +167,8 @@ $b contains the $a->user array.
 'display_item' is called when formatting a post for display.
 $b is an array:
 
-       'item' => The item (array) details pulled from the database
-       'output' => the (string) HTML representation of this item prior to adding it to the page
+    'item' => The item (array) details pulled from the database
+    'output' => the (string) HTML representation of this item prior to adding it to the page
 
 ### 'post_local'
 * called when a status post or comment is entered on the local system
@@ -167,8 +208,8 @@ $b is an array:
 'profile_edit' is called prior to output of profile edit page.
 $b is an array containing:
 
-       'profile' => profile (array) record from the database
-       'entry' => the (string) HTML of the generated entry
+    'profile' => profile (array) record from the database
+    'entry' => the (string) HTML of the generated entry
 
 ### 'profile_advanced'
 * called when the HTML is generated for the 'Advanced profile', corresponding to the 'Profile' tab within a person's profile page
@@ -179,7 +220,7 @@ $b is an array containing:
 'directory_item' is called from the Directory page when formatting an item for display.
 $b is an array:
 
-       'contact' => contact (array) record for the person from the database
+    'contact' => contact (array) record for the person from the database
     'entry' => the (string) HTML of the generated entry
 
 ### 'profile_sidebar_enter'
@@ -190,15 +231,15 @@ $b is an array:
 'profile_sidebar is called when generating the sidebar "short" profile for a page.
 $b is an array:
 
-       'profile' => profile (array) record for the person from the database
-       'entry' => the (string) HTML of the generated entry
+    'profile' => profile (array) record for the person from the database
+    'entry' => the (string) HTML of the generated entry
 
 ### 'contact_block_end'
 is called when formatting the block of contacts/friends on a profile sidebar has completed.
 $b is an array:
 
-       'contacts' => array of contacts
-       'output' => the (string) generated HTML of the contact block
+    'contacts' => array of contacts
+    'output' => the (string) generated HTML of the contact block
 
 ### 'bbcode'
 * called during conversion of bbcode to html
@@ -216,8 +257,8 @@ $b is an array:
 'personal_xrd' is called prior to output of personal XRD file.
 $b is an array:
 
-       'user' => the user record for the person
-       'xml' => the complete XML to be output
+    'user' => the user record for the person
+    'xml' => the complete XML to be output
 
 ### 'home_content'
 * called prior to output home page content, shown to unlogged users
@@ -227,8 +268,8 @@ $b is an array:
 is called when editing contact details on an individual from the Contacts page.
 $b is an array:
 
-       'contact' => contact record (array) of target contact
-       'output' => the (string) generated HTML of the contact edit page
+    'contact' => contact record (array) of target contact
+    'output' => the (string) generated HTML of the contact edit page
 
 ### 'contact_edit_post'
 * called when posting the contact edit page.
@@ -246,9 +287,9 @@ $b is an array:
 'avatar_lookup' is called when looking up the avatar.
 $b is an array:
 
-       'size' => the size of the avatar that will be looked up
-       'email' => email to look up the avatar for
-       'url' => the (string) generated URL of the avatar
+    'size' => the size of the avatar that will be looked up
+    'email' => email to look up the avatar for
+    'url' => the (string) generated URL of the avatar
 
 ### 'emailer_send_prepare'
 'emailer_send_prepare' called from Emailer::send() before building the mime message.
@@ -284,192 +325,347 @@ $b is an array with:
     'template' => filename of template
     'vars' => array of vars passed to template
 
-### ''acl_lookup_end'
+### 'acl_lookup_end'
 is called after the other queries have passed.
 The registered function can add, change or remove the acl_lookup() variables.
 
     'results' => array of the acl_lookup() vars
 
+### 'prepare_body_init'
+Called at the start of prepare_body
+Hook data:
+    'item' => item array (input/output)
+
+### 'prepare_body_content_filter'
+Called before the HTML conversion in prepare_body. If the item matches a content filter rule set by an addon, it should
+just add the reason to the filter_reasons element of the hook data.
+Hook data:
+    'item' => item array (input)
+    'filter_reasons' => reasons array (input/output)
+
+### 'prepare_body'
+Called after the HTML conversion in prepare_body.
+Hook data:
+    'item' => item array (input)
+    'html' => converted item body (input/output)
+    'is_preview' => post preview flag (input)
+    'filter_reasons' => reasons array (input)
+
+### 'prepare_body_final'
+Called at the end of prepare_body.
+Hook data:
+    'item' => item array (input)
+    'html' => converted item body (input/output)
+
+Current JavaScript hooks
+-------------
+
+### 'postprocess_liveupdate'
+Called at the end of the live update process (XmlHttpRequest)
 
 Complete list of hook callbacks
 ---
 
-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.
+Here is a complete list of all hook callbacks with file locations (as of 01-Apr-2018). Please see the source for details of any hooks not documented above.
+
+### index.php
+
+    Addon::callHooks('init_1');
+    Addon::callHooks('app_menu', $arr);
+    Addon::callHooks('page_content_top', $a->page['content']);
+    Addon::callHooks($a->module.'_mod_init', $placeholder);
+    Addon::callHooks($a->module.'_mod_init', $placeholder);
+    Addon::callHooks($a->module.'_mod_post', $_POST);
+    Addon::callHooks($a->module.'_mod_afterpost', $placeholder);
+    Addon::callHooks($a->module.'_mod_content', $arr);
+    Addon::callHooks($a->module.'_mod_aftercontent', $arr);
+    Addon::callHooks('page_end', $a->page['content']);
+    
+### include/api.php
+
+    Addon::callHooks('logged_in', $a->user);
+    Addon::callHooks('authenticate', $addon_auth);
+    Addon::callHooks('logged_in', $a->user);
+
+### include/enotify.php
+    
+    Addon::callHooks('enotify', $h);
+    Addon::callHooks('enotify_store', $datarray);
+    Addon::callHooks('enotify_mail', $datarray);
+    Addon::callHooks('check_item_notification', $notification_data);
+    
+### include/conversation.php
+
+    Addon::callHooks('conversation_start', $cb);
+    Addon::callHooks('render_location', $locate);
+    Addon::callHooks('display_item', $arr);
+    Addon::callHooks('display_item', $arr);
+    Addon::callHooks('item_photo_menu', $args);
+    Addon::callHooks('jot_tool', $jotplugins);
+
+### include/security.php
+
+    Addon::callHooks('logged_in', $a->user);
+
+### include/text.php
+
+    Addon::callHooks('contact_block_end', $arr);
+    Addon::callHooks('poke_verbs', $arr);
+    Addon::callHooks('prepare_body_init', $item);
+    Addon::callHooks('prepare_body_content_filter', $hook_data);
+    Addon::callHooks('prepare_body', $hook_data);
+    Addon::callHooks('prepare_body_final', $hook_data);
+
+### include/items.php
+
+    Addon::callHooks('page_info_data', $data);
+
+### mod/directory.php
+
+    Addon::callHooks('directory_item', $arr);
+
+### mod/xrd.php
+
+    Addon::callHooks('personal_xrd', $arr);
+
+### mod/ping.php
+
+    Addon::callHooks('network_ping', $arr);
+
+### mod/parse_url.php
+
+    Addon::callHooks("parse_link", $arr);
+
+### mod/manage.php
+
+    Addon::callHooks('home_init', $ret);
 
-boot.php:      Addon::callHooks('login_hook',$o);
+### mod/acl.php
 
-boot.php:      Addon::callHooks('profile_sidebar_enter', $profile);
+    Addon::callHooks('acl_lookup_end', $results);
 
-boot.php:      Addon::callHooks('profile_sidebar', $arr);
+### mod/network.php
 
-boot.php:      Addon::callHooks("proc_run", $arr);
+    Addon::callHooks('network_content_init', $arr);
+    Addon::callHooks('network_tabs', $arr);
 
-include/contact_selectors.php: Addon::callHooks('network_to_name', $nets);
+### mod/friendica.php
 
-include/api.php:                               Addon::callHooks('logged_in', $a->user);
+    Addon::callHooks('about_hook', $o);
+    
+### mod/subthread.php
 
-include/api.php:               Addon::callHooks('logged_in', $a->user);
+    Addon::callHooks('post_local_end', $arr);
 
-include/queue.php:             Addon::callHooks('queue_predeliver', $a, $r);
+### mod/profiles.php
 
-include/queue.php:                             Addon::callHooks('queue_deliver', $a, $params);
+    Addon::callHooks('profile_post', $_POST);
+    Addon::callHooks('profile_edit', $arr);
 
-include/text.php:      Addon::callHooks('contact_block_end', $arr);
+### mod/settings.php
 
-include/text.php:      Addon::callHooks('smilie', $s);
+    Addon::callHooks('addon_settings_post', $_POST);
+    Addon::callHooks('connector_settings_post', $_POST);
+    Addon::callHooks('display_settings_post', $_POST);
+    Addon::callHooks('settings_post', $_POST);
+    Addon::callHooks('addon_settings', $settings_addons);
+    Addon::callHooks('connector_settings', $settings_connectors);
+    Addon::callHooks('display_settings', $o);
+    Addon::callHooks('settings_form', $o);
 
-include/text.php:      Addon::callHooks('prepare_body_init', $item);
+### mod/photos.php
 
-include/text.php:      Addon::callHooks('prepare_body', $prep_arr);
+    Addon::callHooks('photo_post_init', $_POST);
+    Addon::callHooks('photo_post_file', $ret);
+    Addon::callHooks('photo_post_end', $foo);
+    Addon::callHooks('photo_post_end', $foo);
+    Addon::callHooks('photo_post_end', $foo);
+    Addon::callHooks('photo_post_end', $foo);
+    Addon::callHooks('photo_post_end', intval($item_id));
+    Addon::callHooks('photo_upload_form', $ret);
 
-include/text.php:      Addon::callHooks('prepare_body_final', $prep_arr);
+### mod/profile.php
 
-include/nav.php:       Addon::callHooks('page_header', $a->page['nav']);
+    Addon::callHooks('profile_advanced', $o);
 
-include/auth.php:              Addon::callHooks('authenticate', $addon_auth);
+### mod/home.php
 
-include/bbcode.php:    Addon::callHooks('bbcode',$Text);
+    Addon::callHooks('home_init', $ret);
+    Addon::callHooks("home_content", $content);
 
-include/oauth.php:             Addon::callHooks('logged_in', $a->user);
+### mod/poke.php
 
-include/acl_selectors.php:     Addon::callHooks($a->module . '_pre_' . $selname, $arr);
+    Addon::callHooks('post_local_end', $arr);
 
-include/acl_selectors.php:     Addon::callHooks($a->module . '_post_' . $selname, $o);
+### mod/contacts.php
 
-include/acl_selectors.php:     Addon::callHooks('contact_select_options', $x);
+    Addon::callHooks('contact_edit_post', $_POST);
+    Addon::callHooks('contact_edit', $arr);
 
-include/acl_selectors.php:     Addon::callHooks($a->module . '_pre_' . $selname, $arr);
+### mod/tagger.php
 
-include/acl_selectors.php:     Addon::callHooks($a->module . '_post_' . $selname, $o);
+    Addon::callHooks('post_local_end', $arr);
 
-include/acl_selectors.php:     Addon::callHooks($a->module . '_pre_' . $selname, $arr);
+### mod/lockview.php
 
-include/acl_selectors.php:     Addon::callHooks($a->module . '_post_' . $selname, $o);
+    Addon::callHooks('lockview_content', $item);
 
-include/acl_selectors.php      Addon::callHooks('acl_lookup_end', $results);
+### mod/uexport.php
 
-include/notifier.php:          Addon::callHooks('notifier_normal',$target_item);
+    Addon::callHooks('uexport_options', $options);
 
-include/notifier.php:  Addon::callHooks('notifier_end',$target_item);
+### mod/register.php
 
-include/items.php:     Addon::callHooks('atom_feed', $atom);
+    Addon::callHooks('register_post', $arr);
+    Addon::callHooks('register_form', $arr);
 
-include/items.php:             Addon::callHooks('atom_feed_end', $atom);
+### mod/item.php
 
-include/items.php:     Addon::callHooks('atom_feed_end', $atom);
+    Addon::callHooks('post_local_start', $_REQUEST);
+    Addon::callHooks('post_local', $datarray);
+    Addon::callHooks('post_local_end', $datarray);
 
-include/items.php:     Addon::callHooks('parse_atom', $arr);
+### mod/editpost.php    
 
-include/items.php:     Addon::callHooks('post_remote',$arr);
+    Addon::callHooks('jot_tool', $jotplugins);
 
-include/items.php:     Addon::callHooks('atom_author', $o);
+### src/Network/FKOAuth1.php
 
-include/items.php:     Addon::callHooks('atom_entry', $o);
+    Addon::callHooks('logged_in', $a->user);
 
-include/bb2diaspora.php:       Addon::callHooks('bb2diaspora',$Text);
+### src/Render/FriendicaSmartyEngine.php
 
-include/cronhooks.php: Addon::callHooks('cron', $d);
+    Addon::callHooks("template_vars", $arr);
 
-include/security.php:          Addon::callHooks('logged_in', $a->user);
+### src/Model/Item.php
 
-include/html2bbcode.php:       Addon::callHooks('html2bbcode', $text);
+    Addon::callHooks('post_local', $item);
+    Addon::callHooks('post_remote', $item);
+    Addon::callHooks('post_local_end', $posted_item);
+    Addon::callHooks('post_remote_end', $posted_item);
+    Addon::callHooks('tagged', $arr);
+    Addon::callHooks('post_local_end', $new_item);
 
-include/Contact.php:   Addon::callHooks('remove_user',$r[0]);
+### src/Model/Contact.php
 
-include/Contact.php:   Addon::callHooks('contact_photo_menu', $args);
+    Addon::callHooks('contact_photo_menu', $args);
+    Addon::callHooks('follow', $arr);
 
-include/conversation.php:      Addon::callHooks('conversation_start',$cb);
+### src/Model/Profile.php
 
-include/conversation.php:                              Addon::callHooks('render_location',$locate);
+    Addon::callHooks('profile_sidebar_enter', $profile);
+    Addon::callHooks('profile_sidebar', $arr);
+    Addon::callHooks('profile_tabs', $arr);
+    Addon::callHooks('zrl_init', $arr);
 
-include/conversation.php:                              Addon::callHooks('display_item', $arr);
+### src/Model/Event.php
 
-include/conversation.php:                              Addon::callHooks('render_location',$locate);
+    Addon::callHooks('event_updated', $event['id']);
+    Addon::callHooks("event_created", $event['id']);
 
-include/conversation.php:                              Addon::callHooks('display_item', $arr);
+### src/Model/User.php
 
-include/conversation.php:      Addon::callHooks('item_photo_menu', $args);
+    Addon::callHooks('register_account', $uid);
+    Addon::callHooks('remove_user', $user);
 
-include/conversation.php:      Addon::callHooks('jot_tool', $jotplugins);
+### src/Content/Text/BBCode.php
 
-include/conversation.php:      Addon::callHooks('jot_networks', $jotnets);
+    Addon::callHooks('bbcode', $text);
+    Addon::callHooks('bb2diaspora', $text);
 
-index.php:     Addon::callHooks('init_1');
+### src/Content/Text/HTML.php
 
-index.php:Addon::callHooks('app_menu', $arr);
+    Addon::callHooks('html2bbcode', $message);
 
-index.php:Addon::callHooks('page_end', $a->page['content']);
+### src/Content/Smilies.php
 
-mod/photos.php:        Addon::callHooks('photo_post_init', $_POST);
+    Addon::callHooks('smilie', $params);
 
-mod/photos.php:        Addon::callHooks('photo_post_file',$ret);
+### src/Content/Feature.php
 
-mod/photos.php:                Addon::callHooks('photo_post_end',$foo);
+    Addon::callHooks('isEnabled', $arr);
+    Addon::callHooks('get', $arr);
 
-mod/photos.php:                Addon::callHooks('photo_post_end',$foo);
+### src/Content/ContactSelector.php
 
-mod/photos.php:                Addon::callHooks('photo_post_end',$foo);
+    Addon::callHooks('network_to_name', $nets);
+    Addon::callHooks('gender_selector', $select);
+    Addon::callHooks('sexpref_selector', $select);
+    Addon::callHooks('marital_selector', $select);
 
-mod/photos.php:        Addon::callHooks('photo_post_end',intval($item_id));
+### src/Content/OEmbed.php    
 
-mod/photos.php:                Addon::callHooks('photo_upload_form',$ret);
+    Addon::callHooks('oembed_fetch_url', $embedurl, $j);
 
-mod/friendica.php:     Addon::callHooks('about_hook', $o);
+### src/Content/Nav.php    
 
-mod/editpost.php:      Addon::callHooks('jot_tool', $jotplugins);
+    Addon::callHooks('page_header', $a->page['nav']);
+    Addon::callHooks('nav_info', $nav);
 
-mod/editpost.php:      Addon::callHooks('jot_networks', $jotnets);
+### src/Worker/Directory.php
 
-mod/parse_url.php:     Addon::callHooks('parse_link', $arr);
+    Addon::callHooks('globaldir_update', $arr);
 
-mod/home.php:  Addon::callHooks('home_init',$ret);
+### src/Worker/Notifier.php
 
-mod/home.php:  Addon::callHooks("home_content",$o);
+    Addon::callHooks('notifier_end', $target_item);
 
-mod/contacts.php:      Addon::callHooks('contact_edit_post', $_POST);
+### src/Worker/Queue.php    
 
-mod/contacts.php:              Addon::callHooks('contact_edit', $arr);
+    Addon::callHooks('queue_predeliver', $r);
+    Addon::callHooks('queue_deliver', $params);
 
-mod/settings.php:              Addon::callHooks('addon_settings_post', $_POST);
+### src/Module/Login.php
 
-mod/settings.php:              Addon::callHooks('connector_settings_post', $_POST);
+    Addon::callHooks('authenticate', $addon_auth);
+    Addon::callHooks('login_hook', $o);
 
-mod/settings.php:      Addon::callHooks('settings_post', $_POST);
+### src/Module/Logout.php    
 
-mod/settings.php:              Addon::callHooks('addon_settings', $settings_addons);
+    Addon::callHooks("logging_out");
 
-mod/settings.php:              Addon::callHooks('connector_settings', $settings_connectors);
+### src/Object/Post.php
 
-mod/settings.php:      Addon::callHooks('settings_form',$o);
+    Addon::callHooks('render_location', $locate);
+    Addon::callHooks('display_item', $arr);
 
-mod/register.php:      Addon::callHooks('register_account', $newuid);
+### src/Core/ACL.php
 
-mod/like.php:  Addon::callHooks('post_local_end', $arr);
+    Addon::callHooks('contact_select_options', $x);
+    Addon::callHooks($a->module.'_pre_'.$selname, $arr);
+    Addon::callHooks($a->module.'_post_'.$selname, $o);
+    Addon::callHooks($a->module.'_pre_'.$selname, $arr);
+    Addon::callHooks($a->module.'_post_'.$selname, $o);
+    Addon::callHooks('jot_networks', $jotnets);
 
-mod/xrd.php:   Addon::callHooks('personal_xrd', $arr);
+### src/Core/Worker.php
 
-mod/item.php:  Addon::callHooks('post_local_start', $_REQUEST);
+    Addon::callHooks("proc_run", $arr);
 
-mod/item.php:  Addon::callHooks('post_local',$datarray);
+### src/Util/Emailer.php
 
-mod/item.php:  Addon::callHooks('post_local_end', $datarray);
+    Addon::callHooks('emailer_send_prepare', $params);
+    Addon::callHooks("emailer_send", $hookdata);
 
-mod/profile.php:                       Addon::callHooks('profile_advanced',$o);
+### src/Util/Map.php
 
-mod/profiles.php:      Addon::callHooks('profile_post', $_POST);
+    Addon::callHooks('generate_map', $arr);
+    Addon::callHooks('generate_named_map', $arr);
+    Addon::callHooks('Map::getCoordinates', $arr);
 
-mod/profiles.php:              Addon::callHooks('profile_edit', $arr);
+### src/Util/Network.php
 
-mod/tagger.php:        Addon::callHooks('post_local_end', $arr);
+    Addon::callHooks('avatar_lookup', $avatar);
 
-mod/cb.php:    Addon::callHooks('cb_init');
+### src/Util/ParseUrl.php
 
-mod/cb.php:    Addon::callHooks('cb_post', $_POST);
+    Addon::callHooks("getsiteinfo", $siteinfo);
 
-mod/cb.php:    Addon::callHooks('cb_afterpost');
+### src/Protocol/DFRN.php
 
-mod/cb.php:    Addon::callHooks('cb_content', $o);
+    Addon::callHooks('atom_feed_end', $atom);
+    Addon::callHooks('atom_feed_end', $atom);
 
-mod/directory.php:                     Addon::callHooks('directory_item', $arr);
+### view/js/main.js
 
-src/Model/Item.php Addon::callHooks('tagged', $arr);
+    callAddonHooks("postprocess_liveupdate");
\ No newline at end of file