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\Config;
11 use Friendica\Core\Hook;
12 use Friendica\Core\L10n;
13 use Friendica\Core\Renderer;
16 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_uninstall() {
23 Hook::unregister('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
24 Hook::unregister('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
29 function irc_addon_settings(&$a,&$s) {
33 /* Add our stylesheet to the page so we can make our settings look nice */
35 // DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
37 /* setting popular channels, auto connect channels */
38 $sitechats = DI::pConfig()->get( local_user(), 'irc','sitechats'); /* popular channels */
39 $autochans = DI::pConfig()->get( local_user(), 'irc','autochans'); /* auto connect chans */
41 $t = Renderer::getMarkupTemplate( "settings.tpl", "addon/irc/" );
42 $s .= Renderer::replaceMacros($t, [
43 '$header' => L10n::t('IRC Settings'),
44 '$info' => 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.'),
45 '$submit' => L10n::t('Save Settings'),
46 '$autochans' => [ 'autochans', L10n::t('Channel(s) to auto connect (comma separated)'), $autochans, L10n::t('List of channels that shall automatically connected to when the app is launched.')],
47 '$sitechats' => [ 'sitechats', L10n::t('Popular Channels (comma separated)'), $sitechats, L10n::t('List of popular channels, will be displayed at the side and hotlinked for easy joining.') ]
55 function irc_addon_settings_post(&$a, &$b) {
59 if(!empty($_POST['irc-submit'])) {
60 if (isset($_POST['autochans'])) {
61 DI::pConfig()->set(local_user(), 'irc', 'autochans', trim(($_POST['autochans'])));
63 if (isset($_POST['sitechats'])) {
64 DI::pConfig()->set(local_user(), 'irc', 'sitechats', trim($_POST['sitechats']));
66 /* upid pop-up thing */
67 info(L10n::t('IRC settings saved.') . EOL);
71 function irc_app_menu($a,&$b) {
72 $b['app_menu'][] = '<div class="app-title"><a href="irc">' . L10n::t('IRC Chatroom') . '</a></div>';
76 function irc_module() {
81 function irc_content(&$a) {
83 $baseurl = DI::baseUrl()->get() . '/addon/irc';
86 /* set the list of popular channels */
88 $sitechats = DI::pConfig()->get( local_user(), 'irc', 'sitechats');
90 $sitechats = Config::get('irc', 'sitechats');
92 $sitechats = Config::get('irc','sitechats');
95 $chats = explode(',',$sitechats);
97 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
100 DI::page()['aside'] .= '<div class="widget"><h3>' . L10n::t('Popular Channels') . '</h3><ul>';
101 foreach($chats as $chat) {
102 DI::page()['aside'] .= '<li><a href="' . DI::baseUrl()->get() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
104 DI::page()['aside'] .= '</ul></div>';
106 /* setting the channel(s) to auto connect */
108 $autochans = DI::pConfig()->get(local_user(), 'irc', 'autochans');
110 $autochans = Config::get('irc','autochans');
112 $autochans = Config::get('irc','autochans');
115 $channels = $autochans;
117 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
119 /* add the chatroom frame and some html */
122 <p><a href="http://tldp.org/HOWTO/IRC/beginners.html" target="_blank">A beginner's guide to using IRC. [en]</a></p>
123 <iframe src="//webchat.freenode.net?channels=$channels" style="width:100%; max-width:900px; height: 600px;"></iframe>
130 function irc_addon_admin_post (&$a) {
131 if(! is_site_admin())
134 if($_POST['irc-submit']) {
135 Config::set('irc','autochans',trim($_POST['autochans']));
136 Config::set('irc','sitechats',trim($_POST['sitechats']));
137 /* stupid pop-up thing */
138 info(L10n::t('IRC settings saved.') . EOL);
141 function irc_addon_admin (&$a, &$o) {
142 $sitechats = Config::get('irc','sitechats'); /* popular channels */
143 $autochans = Config::get('irc','autochans'); /* auto connect chans */
144 $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/irc/" );
145 $o = Renderer::replaceMacros($t, [
146 '$submit' => L10n::t('Save Settings'),
147 '$autochans' => [ 'autochans', L10n::t('Channel(s) to auto connect (comma separated)'), $autochans, L10n::t('List of channels that shall automatically connected to when the app is launched.')],
148 '$sitechats' => [ 'sitechats', L10n::t('Popular Channels (comma separated)'), $sitechats, L10n::t('List of popular channels, will be displayed at the side and hotlinked for easy joining.') ]