]> git.mxchange.org Git - friendica-addons.git/blob - irc/irc.php
Update obsolete App::getBaseUrl calls to DI::baseUrl
[friendica-addons.git] / irc / irc.php
1 <?php
2 /**
3 * Name: IRC Chat Addon
4 * Description: add an Internet Relay Chat chatroom on freenode
5 * Version: 1.1
6 * Author: tony baldwin <https://free-haven.org/profile/tony>
7 * Author: Tobias Diekershoff <https://f.diekershoff.de/u/tobias>
8 */
9
10 use Friendica\Core\Config;
11 use Friendica\Core\Hook;
12 use Friendica\Core\L10n;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\Renderer;
15 use Friendica\DI;
16
17 function irc_install() {
18         Hook::register('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
19         Hook::register('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
20         Hook::register('addon_settings_post', 'addon/irc/irc.php', 'irc_addon_settings_post');
21 }
22
23 function irc_uninstall() {
24         Hook::unregister('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
25         Hook::unregister('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
26
27 }
28
29
30 function irc_addon_settings(&$a,&$s) {
31         if(! local_user())
32                 return;
33
34     /* Add our stylesheet to the page so we can make our settings look nice */
35
36 //      $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->getBaseURL() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
37
38     /* setting popular channels, auto connect channels */
39         $sitechats = PConfig::get( local_user(), 'irc','sitechats'); /* popular channels */
40         $autochans = PConfig::get( local_user(), 'irc','autochans');  /* auto connect chans */
41
42         $t = Renderer::getMarkupTemplate( "settings.tpl", "addon/irc/" );
43         $s .= Renderer::replaceMacros($t, [
44                 '$header' => L10n::t('IRC Settings'),
45                 '$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.'),
46                 '$submit' => L10n::t('Save Settings'),
47                 '$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.')],
48                 '$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.') ]
49         ]);
50
51
52         return;
53
54 }
55
56 function irc_addon_settings_post(&$a, &$b) {
57         if(!local_user())
58                 return;
59
60         if(!empty($_POST['irc-submit'])) {
61                 if (isset($_POST['autochans'])) {
62                         PConfig::set(local_user(), 'irc', 'autochans', trim(($_POST['autochans'])));
63                 }
64                 if (isset($_POST['sitechats'])) {
65                         PConfig::set(local_user(), 'irc', 'sitechats', trim($_POST['sitechats']));
66                 }
67                 /* upid pop-up thing */
68                 info(L10n::t('IRC settings saved.') . EOL);
69         }
70 }
71
72 function irc_app_menu($a,&$b) {
73         $b['app_menu'][] = '<div class="app-title"><a href="irc">' . L10n::t('IRC Chatroom') . '</a></div>';
74 }
75
76
77 function irc_module() {
78         return;
79 }
80
81
82 function irc_content(&$a) {
83
84         $baseurl = DI::baseUrl()->get() . '/addon/irc';
85         $o = '';
86
87         /* set the list of popular channels */
88         if (local_user()) {
89             $sitechats = PConfig::get( local_user(), 'irc', 'sitechats');
90             if (!$sitechats)
91                 $sitechats = Config::get('irc', 'sitechats');
92         } else {
93             $sitechats = Config::get('irc','sitechats');
94         }
95         if($sitechats)
96                 $chats = explode(',',$sitechats);
97         else
98                 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
99
100
101         $a->page['aside'] .= '<div class="widget"><h3>' . L10n::t('Popular Channels') . '</h3><ul>';
102         foreach($chats as $chat) {
103                 $a->page['aside'] .= '<li><a href="' . DI::baseUrl()->get() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
104         }
105         $a->page['aside'] .= '</ul></div>';
106
107         /* setting the channel(s) to auto connect */
108         if (local_user()) {
109             $autochans = PConfig::get(local_user(), 'irc', 'autochans');
110             if (!$autochans)
111                 $autochans = Config::get('irc','autochans');
112         } else {
113             $autochans = Config::get('irc','autochans');
114         }
115         if($autochans)
116                 $channels = $autochans;
117         else
118                 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
119
120 /* add the chatroom frame and some html */
121   $o .= <<< EOT
122 <h2>IRC chat</h2>
123 <p><a href="http://tldp.org/HOWTO/IRC/beginners.html" target="_blank">A beginner's guide to using IRC. [en]</a></p>
124 <iframe src="//webchat.freenode.net?channels=$channels" style="width:100%; max-width:900px; height: 600px;"></iframe>
125 EOT;
126
127 return $o;
128
129 }
130
131 function irc_addon_admin_post (&$a) {
132         if(! is_site_admin())
133                 return;
134
135         if($_POST['irc-submit']) {
136                 Config::set('irc','autochans',trim($_POST['autochans']));
137                 Config::set('irc','sitechats',trim($_POST['sitechats']));
138                 /* stupid pop-up thing */
139                 info(L10n::t('IRC settings saved.') . EOL);
140         }
141 }
142 function irc_addon_admin (&$a, &$o) {
143         $sitechats = Config::get('irc','sitechats'); /* popular channels */
144         $autochans = Config::get('irc','autochans');  /* auto connect chans */
145         $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/irc/" );
146         $o = Renderer::replaceMacros($t, [
147                 '$submit' => L10n::t('Save Settings'),
148                 '$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.')],
149                 '$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.') ]
150         ]);
151 }