4 * Description: Change the displayed application you are posting from
6 * Author: Commander Zot
9 use Friendica\Core\Hook;
10 use Friendica\Core\Logger;
13 function fromapp_install()
15 Hook::register('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook');
16 Hook::register('addon_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings');
17 Hook::register('addon_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post');
18 Logger::log("installed fromapp");
21 function fromapp_settings_post($a, $post)
23 if (!local_user() || empty($_POST['fromapp-submit'])) {
27 DI::pConfig()->set(local_user(), 'fromapp', 'app', $_POST['fromapp-input']);
28 DI::pConfig()->set(local_user(), 'fromapp', 'force', intval($_POST['fromapp-force']));
31 function fromapp_settings(&$a, &$s)
37 /* Add our stylesheet to the page so we can make our settings look nice */
39 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/fromapp/fromapp.css' . '" media="all" />' . "\r\n";
41 /* Get the current state of our config variable */
43 $fromapp = DI::pConfig()->get(local_user(), 'fromapp', 'app', '');
45 $force = intval(DI::pConfig()->get(local_user(), 'fromapp', 'force'));
47 $force_enabled = (($force) ? ' checked="checked" ' : '');
50 /* Add some HTML to the existing form */
52 $s .= '<span id="settings_fromapp_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_fromapp_expanded\'); openClose(\'settings_fromapp_inflated\');">';
53 $s .= '<h3>' . DI::l10n()->t('FromApp Settings') . '</h3>';
55 $s .= '<div id="settings_fromapp_expanded" class="settings-block" style="display: none;">';
56 $s .= '<span class="fakelink" onclick="openClose(\'settings_fromapp_expanded\'); openClose(\'settings_fromapp_inflated\');">';
57 $s .= '<h3>' . DI::l10n()->t('FromApp Settings') . '</h3>';
59 $s .= '<div id="fromapp-wrapper">';
60 $s .= '<label id="fromapp-label" for="fromapp-input">' . DI::l10n()->t('The application name you would like to show your posts originating from. Separate different app names with a comma. A random one will then be selected for every posting.') . '</label>';
61 $s .= '<input id="fromapp-input" type="text" name="fromapp-input" value="' . $fromapp . '" ' . '/>';
62 $s .= '<div class="clear"></div>';
64 $s .= '<label id="fromapp-force-label" for="fromapp-force">' . DI::l10n()->t('Use this application name even if another application was used.') . '</label>';
65 $s .= '<input id="fromapp-force" type="checkbox" name="fromapp-force" value="1" ' . $force_enabled . '/>';
67 $s .= '</div><div class="clear"></div>';
69 /* provide a submit button */
71 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="fromapp-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
74 function fromapp_post_hook(&$a, &$item)
80 if (local_user() != $item['uid']) {
84 $app = DI::pConfig()->get(local_user(), 'fromapp', 'app');
85 $force = intval(DI::pConfig()->get(local_user(), 'fromapp', 'force'));
87 if (is_null($app) || (! strlen($app))) {
91 if (strlen(trim($item['app'])) && (! $force)) {
95 $apps = explode(',', $app);
96 $item['app'] = trim($apps[mt_rand(0, count($apps)-1)]);