4 * Description: add an Internet Relay Chat chatroom on freenode
6 * Author: tony baldwin <https://free-haven.org/profile/tony>
7 * Author: Tobias Diekershoff <https://f.diekershoff.de/u/tobias>
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
15 function irc_install()
17 Hook::register('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
18 Hook::register('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
19 Hook::register('addon_settings_post', 'addon/irc/irc.php', 'irc_addon_settings_post');
22 function irc_addon_settings(array &$data)
24 if (!DI::userSession()->getLocalUserId()) {
28 $sitechats = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'irc', 'sitechats'); /* popular channels */
29 $autochans = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'irc', 'autochans'); /* auto connect chans */
31 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/irc/');
32 $html = Renderer::replaceMacros($t, [
33 '$info' => DI::l10n()->t('Here you can change the system wide settings for the channels to automatically join and access via the side bar. Note the changes you do here, only effect the channel selection if you are logged in.'),
34 '$autochans' => ['autochans', DI::l10n()->t('Channel(s) to auto connect (comma separated)'), $autochans, DI::l10n()->t('List of channels that shall automatically connected to when the app is launched.')],
35 '$sitechats' => ['sitechats', DI::l10n()->t('Popular Channels (comma separated)'), $sitechats, DI::l10n()->t('List of popular channels, will be displayed at the side and hotlinked for easy joining.')],
40 'title' => DI::l10n()->t('IRC Settings'),
45 function irc_addon_settings_post(array &$b)
47 if (!DI::userSession()->getLocalUserId()) {
51 if (!empty($_POST['irc-submit'])) {
52 if (isset($_POST['autochans'])) {
53 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'irc', 'autochans', trim(($_POST['autochans'])));
55 if (isset($_POST['sitechats'])) {
56 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'irc', 'sitechats', trim($_POST['sitechats']));
58 /* upid pop-up thing */
62 function irc_app_menu(array &$b)
64 $b['app_menu'][] = '<div class="app-title"><a href="irc">' . DI::l10n()->t('IRC Chatroom') . '</a></div>';
68 * This is a statement rather than an actual function definition. The simple
69 * existence of this method is checked to figure out if the addon offers a
72 function irc_module() {}
74 function irc_content()
76 $baseurl = DI::baseUrl() . '/addon/irc';
79 /* set the list of popular channels */
80 if (DI::userSession()->getLocalUserId()) {
81 $sitechats = DI::pConfig()->get( DI::userSession()->getLocalUserId(), 'irc', 'sitechats');
83 $sitechats = DI::config()->get('irc', 'sitechats');
86 $sitechats = DI::config()->get('irc','sitechats');
90 $chats = explode(',',$sitechats);
92 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
96 DI::page()['aside'] .= '<div class="widget"><h3>' . DI::l10n()->t('Popular Channels') . '</h3><ul>';
97 foreach ($chats as $chat) {
98 DI::page()['aside'] .= '<li><a href="' . DI::baseUrl() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
100 DI::page()['aside'] .= '</ul></div>';
102 /* setting the channel(s) to auto connect */
103 if (DI::userSession()->getLocalUserId()) {
104 $autochans = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'irc', 'autochans');
106 $autochans = DI::config()->get('irc','autochans');
108 $autochans = DI::config()->get('irc','autochans');
112 $channels = $autochans;
114 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
117 /* add the chatroom frame and some html */
120 <p><a href="https://tldp.org/HOWTO/IRC/beginners.html" target="_blank" rel="noopener noreferrer">A beginner's guide to using IRC. [en]</a></p>
121 <iframe src="//web.libera.chat?channels=$channels" style="width:100%; max-width:900px; height: 600px;"></iframe>
127 function irc_addon_admin_post ()
129 if (!DI::userSession()->isSiteAdmin()) {
133 if ($_POST['irc-submit']) {
134 DI::config()->set('irc', 'autochans', trim($_POST['autochans']));
135 DI::config()->set('irc', 'sitechats', trim($_POST['sitechats']));
138 function irc_addon_admin (string &$o) {
139 $sitechats = DI::config()->get('irc', 'sitechats'); /* popular channels */
140 $autochans = DI::config()->get('irc', 'autochans'); /* auto connect chans */
141 $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/irc/' );
142 $o = Renderer::replaceMacros($t, [
143 '$submit' => DI::l10n()->t('Save Settings'),
144 '$autochans' => [ 'autochans', DI::l10n()->t('Channel(s) to auto connect (comma separated)'), $autochans, DI::l10n()->t('List of channels that shall automatically connected to when the app is launched.')],
145 '$sitechats' => [ 'sitechats', DI::l10n()->t('Popular Channels (comma separated)'), $sitechats, DI::l10n()->t('List of popular channels, will be displayed at the side and hotlinked for easy joining.') ]