]> git.mxchange.org Git - friendica-addons.git/blob - fromapp/fromapp.php
Merge pull request #438 from rebeka-catalina/rct/d/NSFW_README_examples
[friendica-addons.git] / fromapp / fromapp.php
1 <?php
2 /**
3  * Name: FromApp
4  * Description: Change the displayed application you are posting from
5  * Version: 1.0
6  * Author: Commander Zot
7  *
8  */
9
10
11 function fromapp_install() {
12
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');
16
17         logger("installed fromapp");
18 }
19
20
21 function fromapp_uninstall() {
22
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');
26
27
28         logger("removed fromapp");
29 }
30
31 function fromapp_settings_post($a,$post) {
32         if(! local_user() || (! x($_POST,'fromapp-submit')))
33                 return;
34
35         set_pconfig(local_user(),'fromapp','app',$_POST['fromapp-input']);
36         set_pconfig(local_user(),'fromapp','force',intval($_POST['fromapp-force']));
37
38         info( t('Fromapp settings updated.') . EOL);
39 }
40
41 function fromapp_settings(&$a,&$s) {
42
43         if(! local_user())
44                 return;
45
46         /* Add our stylesheet to the page so we can make our settings look nice */
47
48         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/fromapp/fromapp.css' . '" media="all" />' . "\r\n";
49
50         /* Get the current state of our config variable */
51
52         $fromapp = get_pconfig(local_user(),'fromapp','app');
53         if($fromapp === false)
54                 $fromapp = '';
55
56         $force = intval(get_pconfig(local_user(),'fromapp','force'));
57
58         $force_enabled = (($force) ? ' checked="checked" ' : '');
59
60         
61         /* Add some HTML to the existing form */
62
63         $s .= '<span id="settings_fromapp_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_fromapp_expanded\'); openClose(\'settings_fromapp_inflated\');">';
64         $s .= '<h3>' . t('FromApp Settings') . '</h3>';
65         $s .= '</span>';
66         $s .= '<div id="settings_fromapp_expanded" class="settings-block" style="display: none;">';
67         $s .= '<span class="fakelink" onclick="openClose(\'settings_fromapp_expanded\'); openClose(\'settings_fromapp_inflated\');">';
68         $s .= '<h3>' . t('FromApp Settings') . '</h3>';
69         $s .= '</span>';
70         $s .= '<div id="fromapp-wrapper">';
71         $s .= '<label id="fromapp-label" for="fromapp-input">' . t('The application name you would like to show your posts originating from.') . '</label>';
72         $s .= '<input id="fromapp-input" type="text" name="fromapp-input" value="' . $fromapp . '" ' . '/>';
73         $s .= '<div class="clear"></div>';
74
75         $s .= '<label id="fromapp-force-label" for="fromapp-force">' . t('Use this application name even if another application was used.') . '</label>';
76         $s .= '<input id="fromapp-force" type="checkbox" name="fromapp-force" value="1" ' . $force_enabled . '/>';
77
78         $s .= '</div><div class="clear"></div>';
79
80         /* provide a submit button */
81
82         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="fromapp-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
83
84 }
85
86 function fromapp_post_hook(&$a,&$item) {
87    if(! local_user())
88         return;
89
90     if(local_user() != $item['uid'])
91         return;
92
93     $app = get_pconfig(local_user(), 'fromapp', 'app');
94         $force = intval(get_pconfig(local_user(), 'fromapp','force'));
95
96     if(($app === false) || (! strlen($app)))
97         return;
98
99         if(strlen(trim($item['app'])) && (! $force))
100                 return;
101
102         $apps = explode(',',$app);
103         $item['app'] = trim($apps[mt_rand(0,count($apps)-1)]);
104         return;
105
106 }