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 first 14 days of an account's existence and contains a link to the new member page and free-form text the admin can define.
6 * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Logger;
13 use Friendica\Core\Renderer;
15 use Friendica\Model\User;
17 function newmemberwidget_install()
19 Hook::register( 'network_mod_init', 'addon/newmemberwidget/newmemberwidget.php', 'newmemberwidget_network_mod_init');
20 Logger::notice('newmemberwidget installed');
23 function newmemberwidget_network_mod_init ($b)
25 if (empty($_SESSION['new_member'])) {
29 $t = '<div id="newmember_widget" class="widget">';
30 $t .= '<h3>'.DI::l10n()->t('New Member').'</h3>';
31 $t .= '<a href="newmember" id="newmemberwidget-tips">' . DI::l10n()->t('Tips for New Members') . '</a><br />';
33 if (DI::config()->get('newmemberwidget','linkglobalsupport', false)) {
34 $t .= '<a href="https://forum.friendi.ca/profile/helpers" target="_new">' . DI::l10n()->t('Global Support Group') . '</a><br />';
37 if (DI::config()->get('newmemberwidget','linklocalsupport', false)) {
38 $t .= '<a href="' . DI::baseUrl() . '/profile/' . DI::config()->get('newmemberwidget', 'localsupport') . '" target="_new">' . DI::l10n()->t('Local Support Group') . '</a><br />';
41 $ft = DI::config()->get('newmemberwidget','freetext', '');
43 $t .= '<p>'.BBCode::convertForUriId(User::getSystemUriId(), trim($ft)).'</p>';
46 $t .= '</div><div class="clear"></div>';
47 DI::page()['aside'] = $t . DI::page()['aside'];
50 function newmemberwidget_addon_admin_post()
52 DI::config()->set('newmemberwidget', 'freetext', (!empty($_POST['freetext']) ? trim($_POST['freetext']) : ""));
53 DI::config()->set('newmemberwidget', 'linkglobalsupport', intval($_POST['linkglobalsupport']));
54 DI::config()->set('newmemberwidget', 'linklocalsupport', intval($_POST['linklocalsupport']));
55 DI::config()->set('newmemberwidget', 'localsupport', trim($_POST['localsupportname'] ?? ''));
58 function newmemberwidget_addon_admin(string &$o)
60 $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/newmemberwidget');
62 $o = Renderer::replaceMacros($t, [
63 '$submit' => DI::l10n()->t('Save Settings'),
64 '$freetext' => ["freetext", DI::l10n()->t("Message"), DI::config()->get("newmemberwidget", "freetext"), DI::l10n()->t("Your message for new members. You can use bbcode here.")],
65 '$linkglobalsupport' => ["linkglobalsupport", DI::l10n()->t('Add a link to global support group'), DI::config()->get('newmemberwidget', 'linkglobalsupport'), DI::l10n()->t('Should a link to the global support group be displayed?')." (<a href='https://forum.friendi.ca/profile/helpers'>@helpers</a>)"],
66 '$linklocalsupport' => ["linklocalsupport", DI::l10n()->t('Add a link to the local support group'), DI::config()->get('newmemberwidget', 'linklocalsupport'), DI::l10n()->t('If you have a local support group and want to have a link displayed in the widget, check this box.')],
67 '$localsupportname' => ["localsupportname", DI::l10n()->t('Name of the local support group'), DI::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)')],