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>
10 use Friendica\Core\Hook;
11 use Friendica\Core\Renderer;
14 function irc_install() {
15 Hook::register('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
16 Hook::register('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
17 Hook::register('addon_settings_post', 'addon/irc/irc.php', 'irc_addon_settings_post');
20 function irc_uninstall() {
21 Hook::unregister('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
22 Hook::unregister('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
27 function irc_addon_settings(&$a,&$s) {
31 /* Add our stylesheet to the page so we can make our settings look nice */
33 // DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
35 /* setting popular channels, auto connect channels */
36 $sitechats = DI::pConfig()->get( local_user(), 'irc','sitechats'); /* popular channels */
37 $autochans = DI::pConfig()->get( local_user(), 'irc','autochans'); /* auto connect chans */
39 $t = Renderer::getMarkupTemplate( "settings.tpl", "addon/irc/" );
40 $s .= Renderer::replaceMacros($t, [
41 '$header' => DI::l10n()->t('IRC Settings'),
42 '$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.'),
43 '$submit' => DI::l10n()->t('Save Settings'),
44 '$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.')],
45 '$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.') ]
53 function irc_addon_settings_post(&$a, &$b) {
57 if(!empty($_POST['irc-submit'])) {
58 if (isset($_POST['autochans'])) {
59 DI::pConfig()->set(local_user(), 'irc', 'autochans', trim(($_POST['autochans'])));
61 if (isset($_POST['sitechats'])) {
62 DI::pConfig()->set(local_user(), 'irc', 'sitechats', trim($_POST['sitechats']));
64 /* upid pop-up thing */
68 function irc_app_menu($a,&$b) {
69 $b['app_menu'][] = '<div class="app-title"><a href="irc">' . DI::l10n()->t('IRC Chatroom') . '</a></div>';
73 function irc_module() {
78 function irc_content(&$a) {
80 $baseurl = DI::baseUrl()->get() . '/addon/irc';
83 /* set the list of popular channels */
85 $sitechats = DI::pConfig()->get( local_user(), 'irc', 'sitechats');
87 $sitechats = DI::config()->get('irc', 'sitechats');
89 $sitechats = DI::config()->get('irc','sitechats');
92 $chats = explode(',',$sitechats);
94 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
97 DI::page()['aside'] .= '<div class="widget"><h3>' . DI::l10n()->t('Popular Channels') . '</h3><ul>';
98 foreach($chats as $chat) {
99 DI::page()['aside'] .= '<li><a href="' . DI::baseUrl()->get() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
101 DI::page()['aside'] .= '</ul></div>';
103 /* setting the channel(s) to auto connect */
105 $autochans = DI::pConfig()->get(local_user(), 'irc', 'autochans');
107 $autochans = DI::config()->get('irc','autochans');
109 $autochans = DI::config()->get('irc','autochans');
112 $channels = $autochans;
114 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
116 /* add the chatroom frame and some html */
119 <p><a href="http://tldp.org/HOWTO/IRC/beginners.html" target="_blank" rel="noopener noreferrer">A beginner's guide to using IRC. [en]</a></p>
120 <iframe src="//webchat.freenode.net?channels=$channels" style="width:100%; max-width:900px; height: 600px;"></iframe>
127 function irc_addon_admin_post (&$a) {
128 if(! is_site_admin())
131 if($_POST['irc-submit']) {
132 DI::config()->set('irc','autochans',trim($_POST['autochans']));
133 DI::config()->set('irc','sitechats',trim($_POST['sitechats']));
136 function irc_addon_admin (&$a, &$o) {
137 $sitechats = DI::config()->get('irc','sitechats'); /* popular channels */
138 $autochans = DI::config()->get('irc','autochans'); /* auto connect chans */
139 $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/irc/" );
140 $o = Renderer::replaceMacros($t, [
141 '$submit' => DI::l10n()->t('Save Settings'),
142 '$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.')],
143 '$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.') ]