Merge branch 'master' of git://github.com/friendika/friendika
This commit is contained in:
commit
b39f2e3fac
2 changed files with 138 additions and 3 deletions
127
addon/README
Normal file
127
addon/README
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
Friendika Addon/Plugin development
|
||||||
|
|
||||||
|
This is an early specification and hook details may be subject to change.
|
||||||
|
|
||||||
|
Please see the sample addon 'randplace' for a working example of using these features.
|
||||||
|
|
||||||
|
|
||||||
|
You must register plugins with the system in the .htconfig.php file.
|
||||||
|
|
||||||
|
$a->config['system']['addon'] = 'plugin1name, plugin2name, another_name';
|
||||||
|
|
||||||
|
Plugin names cannot contain spaces and are used as filenames.
|
||||||
|
|
||||||
|
|
||||||
|
Register your plugin hooks during installation.
|
||||||
|
|
||||||
|
register_hook($hookname, $file, $function);
|
||||||
|
|
||||||
|
$hookname is a string and corresponds to a known Friendika hook
|
||||||
|
$file is a pathname relative to the top-level Friendika directory.
|
||||||
|
This *should* be 'addon/plugin_name/plugin_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.
|
||||||
|
|
||||||
|
|
||||||
|
Your hook functions will be called with at least one and possibly two arguments
|
||||||
|
|
||||||
|
function myhook_function(&$a, &$b) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
If you wish to make changes to the calling data, you must declare them as
|
||||||
|
reference variables (with '&') during function declaration.
|
||||||
|
|
||||||
|
$a is the Friendika 'App' class - which contains a wealth of information
|
||||||
|
about the current state of Friendika, such as which module has been called,
|
||||||
|
configuration info, the page contents at the point the hook was invoked, profile
|
||||||
|
and user information, etc. It is recommeded you call this '$a' to match its usage
|
||||||
|
elsewhere.
|
||||||
|
|
||||||
|
$b can be called anything you like. This is information which is 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.
|
||||||
|
|
||||||
|
|
||||||
|
Current hooks:
|
||||||
|
|
||||||
|
'authenticate' - called when a user attempts to login.
|
||||||
|
$b is an array
|
||||||
|
'username' => the supplied username
|
||||||
|
'password' => the supplied password
|
||||||
|
'authenticated' => set this to non-zero to authenticate the user.
|
||||||
|
|
||||||
|
'logged_in' - called after a user has successfully logged in.
|
||||||
|
$b contains the $a->user array
|
||||||
|
|
||||||
|
|
||||||
|
'display_item' - 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
|
||||||
|
|
||||||
|
'post_local' - 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
|
||||||
|
{Please note: body contents are bbcode - not HTML)
|
||||||
|
|
||||||
|
'post_remote' - 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.
|
||||||
|
|
||||||
|
'settings_form' - called when generating the HTML for the user Settings page
|
||||||
|
$b is the (string) HTML of the settings page before the final '</form>' tag.
|
||||||
|
|
||||||
|
'plugin_settings' - 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.
|
||||||
|
|
||||||
|
'settings_post' - called when the Settings and Addon Settings pages are submitted.
|
||||||
|
$b is the $_POST array
|
||||||
|
|
||||||
|
'profile_advanced' - 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
|
||||||
|
|
||||||
|
'directory_item' - 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
|
||||||
|
'entry' => the (string) HTML of the generated entry
|
||||||
|
|
||||||
|
'profile_sidebar' - called when generating the sidebar "short" profile for a page
|
||||||
|
$b is the (string) generated HTML of the entry
|
||||||
|
(The profile array details are in $a->profile)
|
||||||
|
|
||||||
|
'contact_block_end' - called when formatting the block of contacts/friends on a
|
||||||
|
profile sidebar has completed
|
||||||
|
$b is an array
|
||||||
|
'contacts' => contact array of entries
|
||||||
|
'output' => the (string) generated HTML of the contact block
|
||||||
|
|
||||||
|
|
||||||
|
*** = subject to change
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Not yet documented:
|
||||||
|
|
||||||
|
'atom_feed'
|
||||||
|
|
||||||
|
'atom_feed_end'
|
||||||
|
|
||||||
|
'parse_atom'
|
||||||
|
|
||||||
|
'atom_author'
|
||||||
|
|
||||||
|
'atom_entry'
|
||||||
|
|
||||||
|
'parse_link'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
14
boot.php
14
boot.php
|
@ -1742,6 +1742,11 @@ if(! function_exists('contact_block')) {
|
||||||
function contact_block() {
|
function contact_block() {
|
||||||
$o = '';
|
$o = '';
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
|
$shown = get_pconfig($a->profile['uid'],'system','display_friend_count');
|
||||||
|
if(! $shown)
|
||||||
|
$shown = 24;
|
||||||
|
|
||||||
if((! is_array($a->profile)) || ($a->profile['hide-friends']))
|
if((! is_array($a->profile)) || ($a->profile['hide-friends']))
|
||||||
return $o;
|
return $o;
|
||||||
$r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0",
|
$r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0",
|
||||||
|
@ -1754,8 +1759,9 @@ function contact_block() {
|
||||||
$o .= '<h4 class="contact-h4">' . t('No contacts') . '</h4>';
|
$o .= '<h4 class="contact-h4">' . t('No contacts') . '</h4>';
|
||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT 24",
|
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d",
|
||||||
intval($a->profile['uid'])
|
intval($a->profile['uid']),
|
||||||
|
intval($shown)
|
||||||
);
|
);
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
$o .= '<h4 class="contact-h4">' . $total . ' ' . t('Contacts') . '</h4><div id="contact-block">';
|
$o .= '<h4 class="contact-h4">' . $total . ' ' . t('Contacts') . '</h4><div id="contact-block">';
|
||||||
|
@ -1778,7 +1784,9 @@ function contact_block() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
call_hooks('contact_block_end', $o);
|
$arr = array('contacts' => $r, 'output' => $o);
|
||||||
|
|
||||||
|
call_hooks('contact_block_end', $arr);
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue