2012-03-02 23:12:34 +00:00
< ? php
/**
2018-01-20 13:57:41 +00:00
* Name : IRC Chat Addon
2015-07-08 08:02:18 +00:00
* Description : add an Internet Relay Chat chatroom on freenode
2015-07-08 08:36:48 +00:00
* Version : 1.1
2012-03-17 20:40:17 +00:00
* Author : tony baldwin < https :// free - haven . org / profile / tony >
2015-07-13 09:26:39 +00:00
* Author : Tobias Diekershoff < https :// f . diekershoff . de / u / tobias >
2012-03-02 23:12:34 +00:00
*/
2019-02-26 14:44:29 +00:00
2017-11-06 23:55:24 +00:00
use Friendica\Core\Config ;
2018-12-26 07:28:16 +00:00
use Friendica\Core\Hook ;
2018-10-31 14:55:15 +00:00
use Friendica\Core\Renderer ;
2019-12-30 02:55:10 +00:00
use Friendica\DI ;
2017-11-06 23:55:24 +00:00
2012-03-02 23:12:34 +00:00
function irc_install () {
2018-12-26 07:28:16 +00:00
Hook :: register ( 'app_menu' , 'addon/irc/irc.php' , 'irc_app_menu' );
Hook :: register ( 'addon_settings' , 'addon/irc/irc.php' , 'irc_addon_settings' );
Hook :: register ( 'addon_settings_post' , 'addon/irc/irc.php' , 'irc_addon_settings_post' );
2012-03-02 23:12:34 +00:00
}
function irc_uninstall () {
2018-12-26 07:28:16 +00:00
Hook :: unregister ( 'app_menu' , 'addon/irc/irc.php' , 'irc_app_menu' );
Hook :: unregister ( 'addon_settings' , 'addon/irc/irc.php' , 'irc_addon_settings' );
2012-03-02 23:12:34 +00:00
}
2012-04-13 03:33:26 +00:00
function irc_addon_settings ( & $a , & $s ) {
2015-07-08 08:02:18 +00:00
if ( ! local_user ())
2012-04-13 03:33:26 +00:00
return ;
/* Add our stylesheet to the page so we can make our settings look nice */
2019-12-30 20:53:43 +00:00
// DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
2012-04-13 03:33:26 +00:00
/* setting popular channels, auto connect channels */
2020-01-18 15:50:56 +00:00
$sitechats = DI :: pConfig () -> get ( local_user (), 'irc' , 'sitechats' ); /* popular channels */
$autochans = DI :: pConfig () -> get ( local_user (), 'irc' , 'autochans' ); /* auto connect chans */
2015-07-07 07:33:12 +00:00
2018-10-31 14:55:15 +00:00
$t = Renderer :: getMarkupTemplate ( " settings.tpl " , " addon/irc/ " );
$s .= Renderer :: replaceMacros ( $t , [
2020-01-18 19:52:33 +00:00
'$header' => DI :: l10n () -> t ( 'IRC Settings' ),
'$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.' ),
'$submit' => DI :: l10n () -> t ( 'Save Settings' ),
'$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.' )],
'$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.' ) ]
2018-01-15 13:15:33 +00:00
]);
2012-04-13 03:33:26 +00:00
return ;
}
2019-02-26 14:44:29 +00:00
function irc_addon_settings_post ( & $a , & $b ) {
if ( ! local_user ())
2012-04-13 03:33:26 +00:00
return ;
2019-02-26 14:47:17 +00:00
if ( ! empty ( $_POST [ 'irc-submit' ])) {
if ( isset ( $_POST [ 'autochans' ])) {
2020-01-18 15:54:49 +00:00
DI :: pConfig () -> set ( local_user (), 'irc' , 'autochans' , trim (( $_POST [ 'autochans' ])));
2019-02-26 14:44:29 +00:00
}
2019-02-26 14:47:17 +00:00
if ( isset ( $_POST [ 'sitechats' ])) {
2020-01-18 15:54:49 +00:00
DI :: pConfig () -> set ( local_user (), 'irc' , 'sitechats' , trim ( $_POST [ 'sitechats' ]));
2019-02-26 14:44:29 +00:00
}
2015-07-08 08:02:18 +00:00
/* upid pop-up thing */
2020-01-18 19:52:33 +00:00
info ( DI :: l10n () -> t ( 'IRC settings saved.' ) . EOL );
2012-04-13 03:33:26 +00:00
}
}
2012-03-02 23:12:34 +00:00
function irc_app_menu ( $a , & $b ) {
2020-01-18 19:52:33 +00:00
$b [ 'app_menu' ][] = '<div class="app-title"><a href="irc">' . DI :: l10n () -> t ( 'IRC Chatroom' ) . '</a></div>' ;
2012-03-02 23:12:34 +00:00
}
function irc_module () {
2015-07-08 08:02:18 +00:00
return ;
2012-03-02 23:12:34 +00:00
}
function irc_content ( & $a ) {
2019-12-30 02:55:10 +00:00
$baseurl = DI :: baseUrl () -> get () . '/addon/irc' ;
2012-04-02 00:54:17 +00:00
$o = '' ;
2012-04-13 03:33:26 +00:00
/* set the list of popular channels */
2015-07-08 08:02:18 +00:00
if ( local_user ()) {
2020-01-18 15:50:56 +00:00
$sitechats = DI :: pConfig () -> get ( local_user (), 'irc' , 'sitechats' );
2015-07-08 08:02:18 +00:00
if ( ! $sitechats )
2017-11-06 23:55:24 +00:00
$sitechats = Config :: get ( 'irc' , 'sitechats' );
2015-07-08 08:02:18 +00:00
} else {
2017-11-06 23:55:24 +00:00
$sitechats = Config :: get ( 'irc' , 'sitechats' );
2015-07-08 08:02:18 +00:00
}
2012-04-02 01:11:11 +00:00
if ( $sitechats )
$chats = explode ( ',' , $sitechats );
else
2018-01-15 13:15:33 +00:00
$chats = [ 'friendica' , 'chat' , 'chatback' , 'hottub' , 'ircbar' , 'dateroom' , 'debian' ];
2012-04-02 00:54:17 +00:00
2020-01-18 19:52:33 +00:00
DI :: page ()[ 'aside' ] .= '<div class="widget"><h3>' . DI :: l10n () -> t ( 'Popular Channels' ) . '</h3><ul>' ;
2012-04-02 00:54:17 +00:00
foreach ( $chats as $chat ) {
2019-12-30 20:53:43 +00:00
DI :: page ()[ 'aside' ] .= '<li><a href="' . DI :: baseUrl () -> get () . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>' ;
2012-04-02 00:54:17 +00:00
}
2019-12-30 20:53:43 +00:00
DI :: page ()[ 'aside' ] .= '</ul></div>' ;
2012-04-02 00:54:17 +00:00
2012-04-13 03:33:26 +00:00
/* setting the channel(s) to auto connect */
2015-07-08 08:02:18 +00:00
if ( local_user ()) {
2020-01-18 15:50:56 +00:00
$autochans = DI :: pConfig () -> get ( local_user (), 'irc' , 'autochans' );
2015-07-08 08:02:18 +00:00
if ( ! $autochans )
2017-11-06 23:55:24 +00:00
$autochans = Config :: get ( 'irc' , 'autochans' );
2015-07-08 08:02:18 +00:00
} else {
2017-11-06 23:55:24 +00:00
$autochans = Config :: get ( 'irc' , 'autochans' );
2015-07-08 08:02:18 +00:00
}
2012-04-13 03:33:26 +00:00
if ( $autochans )
$channels = $autochans ;
else
2019-10-13 16:07:27 +00:00
$channels = ( $_GET [ 'channels' ] ? ? '' ) ? : 'friendica' ;
2012-04-02 00:54:17 +00:00
2012-04-13 03:33:26 +00:00
/* add the chatroom frame and some html */
2012-03-02 23:21:37 +00:00
$o .= <<< EOT
< h2 > IRC chat </ h2 >
2012-04-02 00:54:17 +00:00
< p >< a href = " http://tldp.org/HOWTO/IRC/beginners.html " target = " _blank " > A beginner ' s guide to using IRC . [ en ] </ a ></ p >
2015-07-08 08:02:18 +00:00
< iframe src = " //webchat.freenode.net?channels= $channels " style = " width:100%; max-width:900px; height: 600px; " ></ iframe >
2012-03-02 23:21:37 +00:00
EOT ;
return $o ;
2018-01-15 13:15:33 +00:00
2012-03-02 23:12:34 +00:00
}
2018-01-20 13:57:41 +00:00
function irc_addon_admin_post ( & $a ) {
2015-07-08 08:02:18 +00:00
if ( ! is_site_admin ())
return ;
2012-03-02 23:12:34 +00:00
2015-07-08 08:02:18 +00:00
if ( $_POST [ 'irc-submit' ]) {
2017-11-06 23:55:24 +00:00
Config :: set ( 'irc' , 'autochans' , trim ( $_POST [ 'autochans' ]));
Config :: set ( 'irc' , 'sitechats' , trim ( $_POST [ 'sitechats' ]));
2015-07-08 08:02:18 +00:00
/* stupid pop-up thing */
2020-01-18 19:52:33 +00:00
info ( DI :: l10n () -> t ( 'IRC settings saved.' ) . EOL );
2015-07-08 08:02:18 +00:00
}
}
2018-01-20 13:57:41 +00:00
function irc_addon_admin ( & $a , & $o ) {
2017-11-06 23:55:24 +00:00
$sitechats = Config :: get ( 'irc' , 'sitechats' ); /* popular channels */
$autochans = Config :: get ( 'irc' , 'autochans' ); /* auto connect chans */
2018-10-31 14:55:15 +00:00
$t = Renderer :: getMarkupTemplate ( " admin.tpl " , " addon/irc/ " );
$o = Renderer :: replaceMacros ( $t , [
2020-01-18 19:52:33 +00:00
'$submit' => DI :: l10n () -> t ( 'Save Settings' ),
'$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.' )],
'$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.' ) ]
2018-01-15 13:15:33 +00:00
]);
2015-07-08 08:02:18 +00:00
}