4 * Description: Change the displayed application you are posting from
6 * Author: Commander Zot
11 function fromapp_install() {
13 register_hook('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook');
14 register_hook('plugin_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings');
15 register_hook('plugin_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post');
17 logger("installed fromapp");
21 function fromapp_uninstall() {
23 unregister_hook('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook');
24 unregister_hook('plugin_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings');
25 unregister_hook('plugin_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post');
28 logger("removed fromapp");
31 function fromapp_settings_post($a,$post) {
32 if(! local_user() || (! x($_POST,'fromapp-submit')))
35 set_pconfig(local_user(),'fromapp','app',$_POST['fromapp-input']);
36 set_pconfig(local_user(),'fromapp','force',intval($_POST['fromapp-force']));
38 info( t('Fromapp settings updated.') . EOL);
41 function fromapp_settings(&$a,&$s) {
46 /* Add our stylesheet to the page so we can make our settings look nice */
48 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/fromapp/fromapp.css' . '" media="all" />' . "\r\n";
50 /* Get the current state of our config variable */
52 $fromapp = get_pconfig(local_user(),'fromapp','app');
53 if($fromapp === false)
56 $force = intval(get_pconfig(local_user(),'fromapp','force'));
58 $force_enabled = (($force) ? ' checked="checked" ' : '');
61 /* Add some HTML to the existing form */
63 $s .= '<div class="settings-block">';
64 $s .= '<h3>' . t('FromApp Settings') . '</h3>';
65 $s .= '<div id="fromapp-wrapper">';
66 $s .= '<label id="fromapp-label" for="fromapp-input">' . t('The application name you would like to show your posts originating from.') . '</label>';
67 $s .= '<input id="fromapp-input" type="text" name="fromapp-input" value="' . $fromapp . '" ' . '/>';
68 $s .= '<div class="clear"></div>';
70 $s .= '<label id="fromapp-force-label" for="fromapp-force">' . t('Use this application name even if another application was used.') . '</label>';
71 $s .= '<input id="fromapp-force" type="checkbox" name="fromapp-force" value="1" ' . $force_enabled . '/>';
73 $s .= '</div><div class="clear"></div>';
75 /* provide a submit button */
77 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="fromapp-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
81 function fromapp_post_hook(&$a,&$item) {
85 if(local_user() != $item['uid'])
88 $app = get_pconfig(local_user(), 'fromapp', 'app');
89 $force = intval(get_pconfig(local_user(), 'fromapp','force'));
91 if(($app === false) || (! strlen($app)))
94 if(strlen(trim($item['app'])) && (! $force))
97 $apps = explode(',',$app);
98 $item['app'] = trim($apps[mt_rand(0,count($apps)-1)]);