]> git.mxchange.org Git - friendica-addons.git/blob - irc/irc.php
PL translation webrtc THX strebski
[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\App;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 function irc_install() {
16         Hook::register('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
17         Hook::register('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
18         Hook::register('addon_settings_post', 'addon/irc/irc.php', 'irc_addon_settings_post');
19 }
20
21 function irc_addon_settings(App &$a, array &$data)
22 {
23         if (!local_user()) {
24                 return;
25         }
26
27         $sitechats = DI::pConfig()->get(local_user(), 'irc', 'sitechats'); /* popular channels */
28         $autochans = DI::pConfig()->get(local_user(), 'irc', 'autochans');  /* auto connect chans */
29
30         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/irc/');
31         $html = Renderer::replaceMacros($t, [
32                 '$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.'),
33                 '$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.')],
34                 '$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.')],
35         ]);
36
37         $data = [
38                 'addon' => 'irc',
39                 'title' => DI::l10n()->t('IRC Settings'),
40                 'html'  => $html,
41         ];
42 }
43
44 function irc_addon_settings_post(&$a, &$b) {
45         if(!local_user())
46                 return;
47
48         if(!empty($_POST['irc-submit'])) {
49                 if (isset($_POST['autochans'])) {
50                         DI::pConfig()->set(local_user(), 'irc', 'autochans', trim(($_POST['autochans'])));
51                 }
52                 if (isset($_POST['sitechats'])) {
53                         DI::pConfig()->set(local_user(), 'irc', 'sitechats', trim($_POST['sitechats']));
54                 }
55                 /* upid pop-up thing */
56         }
57 }
58
59 function irc_app_menu($a,&$b) {
60         $b['app_menu'][] = '<div class="app-title"><a href="irc">' . DI::l10n()->t('IRC Chatroom') . '</a></div>';
61 }
62
63
64 function irc_module() {
65         return;
66 }
67
68
69 function irc_content(&$a) {
70
71         $baseurl = DI::baseUrl()->get() . '/addon/irc';
72         $o = '';
73
74         /* set the list of popular channels */
75         if (local_user()) {
76             $sitechats = DI::pConfig()->get( local_user(), 'irc', 'sitechats');
77             if (!$sitechats)
78                 $sitechats = DI::config()->get('irc', 'sitechats');
79         } else {
80             $sitechats = DI::config()->get('irc','sitechats');
81         }
82         if($sitechats)
83                 $chats = explode(',',$sitechats);
84         else
85                 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
86
87
88         DI::page()['aside'] .= '<div class="widget"><h3>' . DI::l10n()->t('Popular Channels') . '</h3><ul>';
89         foreach($chats as $chat) {
90                 DI::page()['aside'] .= '<li><a href="' . DI::baseUrl()->get() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
91         }
92         DI::page()['aside'] .= '</ul></div>';
93
94         /* setting the channel(s) to auto connect */
95         if (local_user()) {
96             $autochans = DI::pConfig()->get(local_user(), 'irc', 'autochans');
97             if (!$autochans)
98                 $autochans = DI::config()->get('irc','autochans');
99         } else {
100             $autochans = DI::config()->get('irc','autochans');
101         }
102         if($autochans)
103                 $channels = $autochans;
104         else
105                 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
106
107 /* add the chatroom frame and some html */
108   $o .= <<< EOT
109 <h2>IRC chat</h2>
110 <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>
111 <iframe src="//web.libera.chat?channels=$channels" style="width:100%; max-width:900px; height: 600px;"></iframe>
112 EOT;
113
114 return $o;
115
116 }
117
118 function irc_addon_admin_post (&$a) {
119         if(!$a->isSiteAdmin())
120                 return;
121
122         if($_POST['irc-submit']) {
123                 DI::config()->set('irc','autochans',trim($_POST['autochans']));
124                 DI::config()->set('irc','sitechats',trim($_POST['sitechats']));
125         }
126 }
127 function irc_addon_admin (&$a, &$o) {
128         $sitechats = DI::config()->get('irc','sitechats'); /* popular channels */
129         $autochans = DI::config()->get('irc','autochans');  /* auto connect chans */
130         $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/irc/" );
131         $o = Renderer::replaceMacros($t, [
132                 '$submit' => DI::l10n()->t('Save Settings'),
133                 '$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.')],
134                 '$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.') ]
135         ]);
136 }