1
1
Fork 0

Improved documentation formatting (of Plugins.md)

This commit is contained in:
Andrej Stieben 2016-02-04 19:37:06 +01:00
parent 4d0778bfe1
commit acefb84681
2 changed files with 92 additions and 84 deletions

View file

@ -1,5 +1,7 @@
Friendica Addon/Plugin development Friendica Addon/Plugin development
========================== ==============
* [Home](help)
Please see the sample addon 'randplace' for a working example of using some of these features. Please see the sample addon 'randplace' for a working example of using some of these features.
Addons work by intercepting event hooks - which must be registered. Addons work by intercepting event hooks - which must be registered.
@ -18,7 +20,7 @@ Plugins should contain a comment block with the four following parameters:
/* /*
* Name: My Great Plugin * Name: My Great Plugin
* Description: This is what my plugin does. It's really cool * Description: This is what my plugin does. It's really cool.
* Version: 1.0 * Version: 1.0
* Author: John Q. Public <john@myfriendicasite.com> * Author: John Q. Public <john@myfriendicasite.com>
*/ */
@ -45,7 +47,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. 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. $a is the Friendica 'App' class.
It contains a wealth of information about the current state of Friendica: It contains a wealth of information about the current state of Friendica:
@ -56,13 +58,13 @@ It contains a wealth of information about the current state of Friendica:
It is recommeded you call this '$a' to match its usage elsewhere. It is recommeded you call this '$a' to match its usage elsewhere.
###$b #### $b
$b can be called anything you like. $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. 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. Remember to declare it with '&' if you wish to alter it.
Modules Modules
-------- ---
Plugins/addons may also act as "modules" and intercept all page requests for a given URL path. Plugins/addons may also act as "modules" and intercept all page requests for a given URL path.
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. 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.
@ -80,7 +82,7 @@ They may also contain plugin_name_post(&$a) which is called before the _content
You may also have plugin_name_init(&$a) which is called very early on and often does module initialisation. You may also have plugin_name_init(&$a) which is called very early on and often does module initialisation.
Templates Templates
---------- ---
If your plugin needs some template, you can use the Friendica template system. If your plugin needs some template, you can use the Friendica template system.
Friendica uses [smarty3](http://www.smarty.net/) as a template engine. Friendica uses [smarty3](http://www.smarty.net/) as a template engine.
@ -104,7 +106,7 @@ See also the wiki page [Quick Template Guide](https://github.com/friendica/frien
Current hooks Current hooks
------------- -------------
###'authenticate' ### 'authenticate'
'authenticate' is called when a user attempts to login. 'authenticate' is called when a user attempts to login.
$b is an array containing: $b is an array containing:
@ -113,131 +115,131 @@ $b is an array containing:
'authenticated' => set this to non-zero to authenticate the user. 'authenticated' => set this to non-zero to authenticate the user.
'user_record' => successful authentication must also return a valid user record from the database 'user_record' => successful authentication must also return a valid user record from the database
###'logged_in' ### 'logged_in'
'logged_in' is called after a user has successfully logged in. 'logged_in' is called after a user has successfully logged in.
$b contains the $a->user array. $b contains the $a->user array.
###'display_item' ### 'display_item'
'display_item' is called when formatting a post for display. 'display_item' is called when formatting a post for display.
$b is an array: $b is an array:
'item' => The item (array) details pulled from the database 'item' => The item (array) details pulled from the database
'output' => the (string) HTML representation of this item prior to adding it to the page 'output' => the (string) HTML representation of this item prior to adding it to the page
###'post_local' ### 'post_local'
* called when a status post or comment is entered on the local system * called when a status post or comment is entered on the local system
* $b is the item array of the information to be stored in the database * $b is the item array of the information to be stored in the database
* Please note: body contents are bbcode - not HTML * Please note: body contents are bbcode - not HTML
###'post_local_end' ### 'post_local_end'
* called when a local status post or comment has been stored on the local system * called when a local status post or comment has been stored on the local system
* $b is the item array of the information which has just been stored in the database * $b is the item array of the information which has just been stored in the database
* Please note: body contents are bbcode - not HTML * Please note: body contents are bbcode - not HTML
###'post_remote' ### 'post_remote'
* called when receiving a post from another source. This may also be used to post local activity or system generated messages. * called when receiving a post from another source. This may also be used to post local activity or system generated messages.
* $b is the item array of information to be stored in the database and the item body is bbcode. * $b is the item array of information to be stored in the database and the item body is bbcode.
###'settings_form' ### 'settings_form'
* called when generating the HTML for the user Settings page * called when generating the HTML for the user Settings page
* $b is the (string) HTML of the settings page before the final '</form>' tag. * $b is the (string) HTML of the settings page before the final '</form>' tag.
###'settings_post' ### 'settings_post'
* called when the Settings pages are submitted * called when the Settings pages are submitted
* $b is the $_POST array * $b is the $_POST array
###'plugin_settings' ### 'plugin_settings'
* called when generating the HTML for the addon settings page * called when generating the HTML for the addon settings page
* $b is the (string) HTML of the addon settings page before the final '</form>' tag. * $b is the (string) HTML of the addon settings page before the final '</form>' tag.
###'plugin_settings_post' ### 'plugin_settings_post'
* called when the Addon Settings pages are submitted * called when the Addon Settings pages are submitted
* $b is the $_POST array * $b is the $_POST array
###'profile_post' ### 'profile_post'
* called when posting a profile page * called when posting a profile page
* $b is the $_POST array * $b is the $_POST array
###'profile_edit' ### 'profile_edit'
'profile_edit' is called prior to output of profile edit page. 'profile_edit' is called prior to output of profile edit page.
$b is an array containing: $b is an array containing:
'profile' => profile (array) record from the database 'profile' => profile (array) record from the database
'entry' => the (string) HTML of the generated entry 'entry' => the (string) HTML of the generated entry
###'profile_advanced' ### 'profile_advanced'
* called when the HTML is generated for the 'Advanced profile', corresponding to the 'Profile' tab within a person's profile page * called when the HTML is generated for the 'Advanced profile', corresponding to the 'Profile' tab within a person's profile page
* $b is the (string) HTML representation of the generated profile * $b is the (string) HTML representation of the generated profile
* The profile array details are in $a->profile. * The profile array details are in $a->profile.
###'directory_item' ### 'directory_item'
'directory_item' is called from the Directory page when formatting an item for display. 'directory_item' is called from the Directory page when formatting an item for display.
$b is an array: $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 'entry' => the (string) HTML of the generated entry
###'profile_sidebar_enter' ### 'profile_sidebar_enter'
* called prior to generating the sidebar "short" profile for a page * called prior to generating the sidebar "short" profile for a page
* $b is the person's profile array * $b is the person's profile array
###'profile_sidebar' ### 'profile_sidebar'
'profile_sidebar is called when generating the sidebar "short" profile for a page. 'profile_sidebar is called when generating the sidebar "short" profile for a page.
$b is an array: $b is an array:
'profile' => profile (array) record for the person from the database 'profile' => profile (array) record for the person from the database
'entry' => the (string) HTML of the generated entry 'entry' => the (string) HTML of the generated entry
###'contact_block_end' ### 'contact_block_end'
is called when formatting the block of contacts/friends on a profile sidebar has completed. is called when formatting the block of contacts/friends on a profile sidebar has completed.
$b is an array: $b is an array:
'contacts' => array of contacts 'contacts' => array of contacts
'output' => the (string) generated HTML of the contact block 'output' => the (string) generated HTML of the contact block
###'bbcode' ### 'bbcode'
* called during conversion of bbcode to html * called during conversion of bbcode to html
* $b is a string converted text * $b is a string converted text
###'html2bbcode' ### 'html2bbcode'
* called during conversion of html to bbcode (e.g. remote message posting) * called during conversion of html to bbcode (e.g. remote message posting)
* $b is a string converted text * $b is a string converted text
###'page_header' ### 'page_header'
* called after building the page navigation section * called after building the page navigation section
* $b is a string HTML of nav region * $b is a string HTML of nav region
###'personal_xrd' ### 'personal_xrd'
'personal_xrd' is called prior to output of personal XRD file. 'personal_xrd' is called prior to output of personal XRD file.
$b is an array: $b is an array:
'user' => the user record for the person 'user' => the user record for the person
'xml' => the complete XML to be output 'xml' => the complete XML to be output
###'home_content' ### 'home_content'
* called prior to output home page content, shown to unlogged users * called prior to output home page content, shown to unlogged users
* $b is (string) HTML of section region * $b is (string) HTML of section region
###'contact_edit' ### 'contact_edit'
is called when editing contact details on an individual from the Contacts page. is called when editing contact details on an individual from the Contacts page.
$b is an array: $b is an array:
'contact' => contact record (array) of target contact 'contact' => contact record (array) of target contact
'output' => the (string) generated HTML of the contact edit page 'output' => the (string) generated HTML of the contact edit page
###'contact_edit_post' ### 'contact_edit_post'
* called when posting the contact edit page. * called when posting the contact edit page.
* $b is the $_POST array * $b is the $_POST array
###'init_1' ### 'init_1'
* called just after DB has been opened and before session start * called just after DB has been opened and before session start
* $b is not used or passed * $b is not used or passed
###'page_end' ### 'page_end'
* called after HTML content functions have completed * called after HTML content functions have completed
* $b is (string) HTML of content div * $b is (string) HTML of content div
###'avatar_lookup' ### 'avatar_lookup'
'avatar_lookup' is called when looking up the avatar. 'avatar_lookup' is called when looking up the avatar.
$b is an array: $b is an array:
@ -245,7 +247,7 @@ $b is an array:
'email' => email to look up the avatar for 'email' => email to look up the avatar for
'url' => the (string) generated URL of the avatar 'url' => the (string) generated URL of the avatar
###'emailer_send_prepare' ### 'emailer_send_prepare'
'emailer_send_prepare' called from Emailer::send() before building the mime message. 'emailer_send_prepare' called from Emailer::send() before building the mime message.
$b is an array, params to Emailer::send() $b is an array, params to Emailer::send()
@ -258,7 +260,7 @@ $b is an array, params to Emailer::send()
'textVersion' => text only version of the message 'textVersion' => text only version of the message
'additionalMailHeader' => additions to the smtp mail header 'additionalMailHeader' => additions to the smtp mail header
###'emailer_send' ### 'emailer_send'
is called before calling PHP's mail(). is called before calling PHP's mail().
$b is an array, params to mail() $b is an array, params to mail()
@ -267,11 +269,11 @@ $b is an array, params to mail()
'body' 'body'
'headers' 'headers'
###'nav_info' ### 'nav_info'
is called after the navigational menu is build in include/nav.php. is called after the navigational menu is build in include/nav.php.
$b is an array containing $nav from nav.php. $b is an array containing $nav from nav.php.
###'template_vars' ### 'template_vars'
is called before vars are passed to the template engine to render the page. is called before vars are passed to the template engine to render the page.
The registered function can add,change or remove variables passed to template. The registered function can add,change or remove variables passed to template.
$b is an array with: $b is an array with:
@ -463,4 +465,3 @@ mod/cb.php: call_hooks('cb_afterpost');
mod/cb.php: call_hooks('cb_content', $o); mod/cb.php: call_hooks('cb_content', $o);
mod/directory.php: call_hooks('directory_item', $arr); mod/directory.php: call_hooks('directory_item', $arr);

View file

@ -1,4 +1,4 @@
**Friendica Addon/Plugin-Entwicklung** Friendica Addon/Plugin-Entwicklung
============== ==============
* [Zur Startseite der Hilfe](help) * [Zur Startseite der Hilfe](help)
@ -34,6 +34,9 @@ Das *sollte* "addon/plugin_name/plugin_name.php' sein.
$function ist ein String und der Name der Funktion, die ausgeführt wird, wenn der Hook aufgerufen wird. $function ist ein String und der Name der Funktion, die ausgeführt wird, wenn der Hook aufgerufen wird.
Argumente
---
Deine Hook-Callback-Funktion wird mit mindestens einem und bis zu zwei Argumenten aufgerufen Deine Hook-Callback-Funktion wird mit mindestens einem und bis zu zwei Argumenten aufgerufen
function myhook_function(&$a, &$b) { function myhook_function(&$a, &$b) {
@ -50,7 +53,8 @@ Diese Information ist speziell auf den Hook bezogen, der aktuell bearbeitet wird
Achte darauf, diese mit "&" zu deklarieren, wenn du sie bearbeiten willst. Achte darauf, diese mit "&" zu deklarieren, wenn du sie bearbeiten willst.
**Module** Module
---
Plugins/Addons können auch als "Module" agieren und alle Seitenanfragen für eine bestimte URL abfangen. Plugins/Addons können auch als "Module" agieren und alle Seitenanfragen für eine bestimte URL abfangen.
Um ein Plugin als Modul zu nutzen, ist es nötig, die Funktion "plugin_name_module()" zu definieren, die keine Argumente benötigt und nichts weiter machen muss. Um ein Plugin als Modul zu nutzen, ist es nötig, die Funktion "plugin_name_module()" zu definieren, die keine Argumente benötigt und nichts weiter machen muss.
@ -67,7 +71,8 @@ Sie können auch plugin_name_post(&$a) umfassen, welches vor der content-Funktio
Du kannst ebenso plugin_name_init(&$a) nutzen, was oft frühzeitig aufgerufen wird und das Modul initialisert. Du kannst ebenso plugin_name_init(&$a) nutzen, was oft frühzeitig aufgerufen wird und das Modul initialisert.
**Derzeitige Hooks:** Derzeitige Hooks
---
**'authenticate'** - wird aufgerufen, wenn sich der User einloggt. **'authenticate'** - wird aufgerufen, wenn sich der User einloggt.
$b ist ein Array $b ist ein Array
@ -180,6 +185,9 @@ Du kannst ebenso plugin_name_init(&$a) nutzen, was oft frühzeitig aufgerufen wi
- wird aufgerufen nachdem in include/nav,php der Inhalt des Navigations Menüs erzeugt wurde. - wird aufgerufen nachdem in include/nav,php der Inhalt des Navigations Menüs erzeugt wurde.
- $b ist ein Array, das $nav wiederspiegelt. - $b ist ein Array, das $nav wiederspiegelt.
Komplette Liste der Hook-Callbacks
---
Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 14-Feb-2012 generiert): Bitte schau in die Quellcodes für Details zu Hooks, die oben nicht dokumentiert sind. Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 14-Feb-2012 generiert): Bitte schau in die Quellcodes für Details zu Hooks, die oben nicht dokumentiert sind.
boot.php: call_hooks('login_hook',$o); boot.php: call_hooks('login_hook',$o);
@ -359,4 +367,3 @@ mod/cb.php: call_hooks('cb_afterpost');
mod/cb.php: call_hooks('cb_content', $o); mod/cb.php: call_hooks('cb_content', $o);
mod/directory.php: call_hooks('directory_item', $arr); mod/directory.php: call_hooks('directory_item', $arr);