friendica-addons/fromapp/fromapp.php

101 lines
3.0 KiB
PHP
Raw Normal View History

2012-09-24 08:20:36 +00:00
<?php
/**
* Name: FromApp
* Description: Change the displayed application you are posting from
* Version: 1.0
* Author: Commander Zot
*
*/
function fromapp_install() {
register_hook('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook');
register_hook('plugin_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings');
register_hook('plugin_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post');
logger("installed fromapp");
}
function fromapp_uninstall() {
unregister_hook('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook');
unregister_hook('plugin_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings');
unregister_hook('plugin_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post');
logger("removed fromapp");
}
function fromapp_settings_post($a,$post) {
if(! local_user() || (! x($_POST,'fromapp-submit')))
return;
2012-09-25 00:21:30 +00:00
set_pconfig(local_user(),'fromapp','app',$_POST['fromapp-input']);
set_pconfig(local_user(),'fromapp','force',intval($_POST['fromapp-force']));
2012-09-24 08:20:36 +00:00
info( t('Fromapp settings updated.') . EOL);
}
function fromapp_settings(&$a,&$s) {
if(! local_user())
return;
/* Add our stylesheet to the page so we can make our settings look nice */
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/fromapp/fromapp.css' . '" media="all" />' . "\r\n";
/* Get the current state of our config variable */
$fromapp = get_pconfig(local_user(),'fromapp','app');
if($fromapp === false)
$fromapp = '';
2012-09-25 00:21:30 +00:00
$force = intval(get_pconfig(local_user(),'fromapp','force'));
$force_enabled = (($force) ? ' checked="checked" ' : '');
2012-09-24 08:20:36 +00:00
/* Add some HTML to the existing form */
$s .= '<div class="settings-block">';
$s .= '<h3>' . t('FromApp Settings') . '</h3>';
$s .= '<div id="fromapp-wrapper">';
2012-09-25 00:21:30 +00:00
$s .= '<label id="fromapp-label" for="fromapp-input">' . t('The application name you would like to show your posts originating from.') . '</label>';
$s .= '<input id="fromapp-input" type="text" name="fromapp-input" value="' . $fromapp . '" ' . '/>';
$s .= '<div class="clear"></div>';
$s .= '<label id="fromapp-force-label" for="fromapp-force">' . t('Use this application name even if another application was used.') . '</label>';
$s .= '<input id="fromapp-force" type="checkbox" name="fromapp-force" value="1" ' . $force_enabled . '/>';
2012-09-24 08:20:36 +00:00
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="fromapp-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
}
function fromapp_post_hook(&$a,&$item) {
if(! local_user())
return;
if(local_user() != $item['uid'])
return;
$app = get_pconfig(local_user(), 'fromapp', 'app');
2012-09-25 00:21:30 +00:00
$force = intval(get_pconfig(local_user(), 'fromapp','force'));
2012-09-24 08:20:36 +00:00
if(($app === false) || (! strlen($app)))
return;
2012-09-25 00:21:30 +00:00
if(strlen(trim($item['app'])) && (! $force))
return;
2012-09-24 19:24:46 +00:00
$apps = explode(',',$app);
$item['app'] = trim($apps[mt_rand(0,count($apps)-1)]);
2012-09-24 08:20:36 +00:00
return;
}