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 */
65 info(DI::l10n()->t('IRC settings saved.') . EOL);
69 function irc_app_menu($a,&$b) {
70 $b['app_menu'][] = '<div class="app-title"><a href="irc">' . DI::l10n()->t('IRC Chatroom') . '</a></div>';
74 function irc_module() {
79 function irc_content(&$a) {
81 $baseurl = DI::baseUrl()->get() . '/addon/irc';
84 /* set the list of popular channels */
86 $sitechats = DI::pConfig()->get( local_user(), 'irc', 'sitechats');
88 $sitechats = DI::config()->get('irc', 'sitechats');
90 $sitechats = DI::config()->get('irc','sitechats');
93 $chats = explode(',',$sitechats);
95 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
98 DI::page()['aside'] .= '<div class="widget"><h3>' . DI::l10n()->t('Popular Channels') . '</h3><ul>';
99 foreach($chats as $chat) {
100 DI::page()['aside'] .= '<li><a href="' . DI::baseUrl()->get() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
102 DI::page()['aside'] .= '</ul></div>';
104 /* setting the channel(s) to auto connect */
106 $autochans = DI::pConfig()->get(local_user(), 'irc', 'autochans');
108 $autochans = DI::config()->get('irc','autochans');
110 $autochans = DI::config()->get('irc','autochans');
113 $channels = $autochans;
115 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
117 /* add the chatroom frame and some html */
120 <p><a href="http://tldp.org/HOWTO/IRC/beginners.html" target="_blank">A beginner's guide to using IRC. [en]</a></p>
121 <iframe src="//webchat.freenode.net?channels=$channels" style="width:100%; max-width:900px; height: 600px;"></iframe>
128 function irc_addon_admin_post (&$a) {
129 if(! is_site_admin())
132 if($_POST['irc-submit']) {
133 DI::config()->set('irc','autochans',trim($_POST['autochans']));
134 DI::config()->set('irc','sitechats',trim($_POST['sitechats']));
135 /* stupid pop-up thing */
136 info(DI::l10n()->t('IRC settings saved.') . EOL);
139 function irc_addon_admin (&$a, &$o) {
140 $sitechats = DI::config()->get('irc','sitechats'); /* popular channels */
141 $autochans = DI::config()->get('irc','autochans'); /* auto connect chans */
142 $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/irc/" );
143 $o = Renderer::replaceMacros($t, [
144 '$submit' => DI::l10n()->t('Save Settings'),
145 '$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.')],
146 '$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.') ]