3 * Name: New Member Widget
4 * Description: Adds a widget for new members into the sidebar of the network page. The widget will be displayed for the 1st 14days of a account existance and contains a link to the new member page and a free-form text the admin can define.
6 * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Core\Config;
11 use Friendica\Core\Hook;
12 use Friendica\Core\L10n;
13 use Friendica\Core\Logger;
14 use Friendica\Core\Renderer;
16 use Friendica\Util\Strings;
18 function newmemberwidget_install()
20 Hook::register( 'network_mod_init', 'addon/newmemberwidget/newmemberwidget.php', 'newmemberwidget_network_mod_init');
21 Logger::log('newmemberwidget installed');
24 function newmemberwidget_uninstall()
26 Hook::unregister( 'network_mod_init', 'addon/newmemberwidget/newmemberwidget.php', 'newmemberwidget_network_mod_init');
29 function newmemberwidget_network_mod_init ($a, $b)
31 if (empty($_SESSION['new_member'])) {
35 $t = '<div id="newmember_widget" class="widget">'.EOL;
36 $t .= '<h3>'.DI::l10n()->t('New Member').'</h3>'.EOL;
37 $t .= '<a href="newmember" id="newmemberwidget-tips">' . DI::l10n()->t('Tips for New Members') . '</a><br />'.EOL;
39 if (Config::get('newmemberwidget','linkglobalsupport', false)) {
40 $t .= '<a href="https://forum.friendi.ca/profile/helpers" target="_new">'.DI::l10n()->t('Global Support Forum').'</a><br />'.EOL;
43 if (Config::get('newmemberwidget','linklocalsupport', false)) {
44 $t .= '<a href="'.DI::baseUrl()->get().'/profile/'.Config::get('newmemberwidget','localsupport').'" target="_new">'.DI::l10n()->t('Local Support Forum').'</a><br />'.EOL;
47 $ft = Config::get('newmemberwidget','freetext', '');
49 $t .= '<p>'.BBCode::convert(trim($ft)).'</p>';
52 $t .= '</div><div class="clear"></div>';
53 DI::page()['aside'] = $t . DI::page()['aside'];
56 function newmemberwidget_addon_admin_post(&$a)
58 $ft = (!empty($_POST['freetext']) ? trim($_POST['freetext']) : "");
59 $lsn = (!empty($_POST['localsupportname']) ? Strings::escapeTags(trim($_POST['localsupportname'])) : "");
60 $gs = intval($_POST['linkglobalsupport']);
61 $ls = intval($_POST['linklocalsupport']);
62 Config::set('newmemberwidget', 'freetext', trim($ft));
63 Config::set('newmemberwidget', 'linkglobalsupport', $gs);
64 Config::set('newmemberwidget', 'linklocalsupport', $ls);
65 Config::set('newmemberwidget', 'localsupport', trim($lsn));
68 function newmemberwidget_addon_admin(&$a, &$o)
70 $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/newmemberwidget');
71 $o = Renderer::replaceMacros($t, [
72 '$submit' => DI::l10n()->t('Save Settings'),
73 '$freetext' => [ "freetext", DI::l10n()->t("Message"), Config::get("newmemberwidget", "freetext"), DI::l10n()->t("Your message for new members. You can use bbcode here.")],
74 '$linkglobalsupport' => [ "linkglobalsupport", DI::l10n()->t('Add a link to global support forum'), Config::get('newmemberwidget', 'linkglobalsupport'), DI::l10n()->t('Should a link to the global support forum be displayed?')." (<a href='https://forum.friendi.ca/profile/helpers'>@helpers</a>)"],
75 '$linklocalsupport' => [ "linklocalsupport", DI::l10n()->t('Add a link to the local support forum'), Config::get('newmemberwidget', 'linklocalsupport'), DI::l10n()->t('If you have a local support forum and want to have a link displayed in the widget, check this box.')],
76 '$localsupportname' => [ "localsupportname", DI::l10n()->t('Name of the local support group'), Config::get('newmemberwidget', 'localsupport'), DI::l10n()->t('If you checked the above, specify the <em>nickname</em> of the local support group here (i.e. helpers)')],