]> git.mxchange.org Git - friendica-addons.git/blob - irc/irc.php
6dccd4846209dfee0f085249d3e520bc0a739a5d
[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\Hook;
11 use Friendica\Core\Renderer;
12 use Friendica\DI;
13
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');
18 }
19
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');
23
24 }
25
26
27 function irc_addon_settings(&$a,&$s) {
28         if(! local_user())
29                 return;
30
31     /* Add our stylesheet to the page so we can make our settings look nice */
32
33 //      DI::page()['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->getBaseURL() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
34
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 */
38
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.') ]
46         ]);
47
48
49         return;
50
51 }
52
53 function irc_addon_settings_post(&$a, &$b) {
54         if(!local_user())
55                 return;
56
57         if(!empty($_POST['irc-submit'])) {
58                 if (isset($_POST['autochans'])) {
59                         DI::pConfig()->set(local_user(), 'irc', 'autochans', trim(($_POST['autochans'])));
60                 }
61                 if (isset($_POST['sitechats'])) {
62                         DI::pConfig()->set(local_user(), 'irc', 'sitechats', trim($_POST['sitechats']));
63                 }
64                 /* upid pop-up thing */
65         }
66 }
67
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>';
70 }
71
72
73 function irc_module() {
74         return;
75 }
76
77
78 function irc_content(&$a) {
79
80         $baseurl = DI::baseUrl()->get() . '/addon/irc';
81         $o = '';
82
83         /* set the list of popular channels */
84         if (local_user()) {
85             $sitechats = DI::pConfig()->get( local_user(), 'irc', 'sitechats');
86             if (!$sitechats)
87                 $sitechats = DI::config()->get('irc', 'sitechats');
88         } else {
89             $sitechats = DI::config()->get('irc','sitechats');
90         }
91         if($sitechats)
92                 $chats = explode(',',$sitechats);
93         else
94                 $chats = ['friendica','chat','chatback','hottub','ircbar','dateroom','debian'];
95
96
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>';
100         }
101         DI::page()['aside'] .= '</ul></div>';
102
103         /* setting the channel(s) to auto connect */
104         if (local_user()) {
105             $autochans = DI::pConfig()->get(local_user(), 'irc', 'autochans');
106             if (!$autochans)
107                 $autochans = DI::config()->get('irc','autochans');
108         } else {
109             $autochans = DI::config()->get('irc','autochans');
110         }
111         if($autochans)
112                 $channels = $autochans;
113         else
114                 $channels = ($_GET['channels'] ?? '') ?: 'friendica';
115
116 /* add the chatroom frame and some html */
117   $o .= <<< EOT
118 <h2>IRC chat</h2>
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>
121 EOT;
122
123 return $o;
124
125 }
126
127 function irc_addon_admin_post (&$a) {
128         if(! is_site_admin())
129                 return;
130
131         if($_POST['irc-submit']) {
132                 DI::config()->set('irc','autochans',trim($_POST['autochans']));
133                 DI::config()->set('irc','sitechats',trim($_POST['sitechats']));
134         }
135 }
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.') ]
144         ]);
145 }