4 * Description: Change the displayed application you are posting from
6 * Author: Commander Zot
11 use Friendica\Core\Hook;
12 use Friendica\Core\Logger;
13 use Friendica\Core\Renderer;
16 function fromapp_install()
18 Hook::register('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook');
19 Hook::register('addon_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings');
20 Hook::register('addon_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post');
21 Logger::notice("installed fromapp");
24 function fromapp_settings_post($post)
26 if (!DI::userSession()->getLocalUserId() || empty($_POST['fromapp-submit'])) {
30 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'fromapp', 'app', $_POST['fromapp-input']);
31 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'fromapp', 'force', intval($_POST['fromapp-force']));
34 function fromapp_settings(array &$data)
36 if (!DI::userSession()->getLocalUserId()) {
40 $fromapp = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'fromapp', 'app', '');
41 $force = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'fromapp', 'force'));
43 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/fromapp/');
44 $html = Renderer::replaceMacros($t, [
45 '$fromapp' => ['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.'), $fromapp],
46 '$force' => ['fromapp-force', DI::l10n()->t('Use this application name even if another application was used.'), $force],
51 'title' => DI::l10n()->t('FromApp Settings'),
56 function fromapp_post_hook(&$item)
58 if (!DI::userSession()->getLocalUserId()) {
62 if (DI::userSession()->getLocalUserId() != $item['uid']) {
66 $app = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'fromapp', 'app');
67 $force = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'fromapp', 'force'));
69 if (is_null($app) || (! strlen($app))) {
73 if (strlen(trim($item['app'])) && (! $force)) {
77 $apps = explode(',', $app);
78 $item['app'] = trim($apps[mt_rand(0, count($apps)-1)]);