From 161b7c392c1e8bd3871bd48620df863ea6794f50 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Wed, 8 Jul 2015 10:02:18 +0200 Subject: [PATCH] IRC plugin now uses smarty3 for forms, config splittet for system and logged in users, the user config wins over the system wide config --- irc/irc.php | 96 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/irc/irc.php b/irc/irc.php index a4a824af..7f5f3b1b 100644 --- a/irc/irc.php +++ b/irc/irc.php @@ -1,18 +1,12 @@ +* Author: Tobias Diekershoff */ -/* enable in admin->plugins - * you will then have "irc chatroom" listed at yoursite/apps - * and the app will run at yoursite/irc - * documentation at http://tonybaldwin.me/hax/doku.php?id=friendica:irc - * admin can set popular chans, auto connect chans in settings->plugin settings - */ - function irc_install() { register_hook('app_menu', 'addon/irc/irc.php', 'irc_app_menu'); register_hook('plugin_settings', 'addon/irc/irc.php', 'irc_addon_settings'); @@ -27,62 +21,50 @@ function irc_uninstall() { function irc_addon_settings(&$a,&$s) { - - - if(! is_site_admin()) + if(! local_user()) return; /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; +// $a->page['htmlhead'] .= '' . "\r\n"; /* setting popular channels, auto connect channels */ - $sitechats = get_config('irc','sitechats'); /* popular channels */ - $autochans = get_config('irc','autochans'); /* auto connect chans */ + $sitechats = get_pconfig( local_user(), 'irc','sitechats'); /* popular channels */ + $autochans = get_pconfig( local_user(), 'irc','autochans'); /* auto connect chans */ - $s .= ''; - $s .= '

' . t('IRC Settings') . '

'; - $s .= '
'; - $s .= ''; return; } function irc_addon_settings_post(&$a,&$b) { - if(! is_site_admin()) + if(! local_user()) return; if($_POST['irc-submit']) { - set_config('irc','autochans',trim($_POST['autochans'])); - set_config('irc','sitechats',trim($_POST['sitechats'])); - /* stupid pop-up thing */ + set_pconfig( local_user(), 'irc','autochans',trim($_POST['autochans'])); + set_pconfig( local_user(), 'irc','sitechats',trim($_POST['sitechats'])); + /* upid pop-up thing */ info( t('IRC settings saved.') . EOL); } } function irc_app_menu($a,&$b) { -$b['app_menu'][] = ''; + $b['app_menu'][] = ''; } function irc_module() { -return; + return; } @@ -92,7 +74,13 @@ function irc_content(&$a) { $o = ''; /* set the list of popular channels */ - $sitechats = get_config('irc','sitechats'); + if (local_user()) { + $sitechats = get_pconfig( local_user(), 'irc', 'sitechats'); + if (!$sitechats) + $sitechats = get_config('irc', 'sitechats'); + } else { + $sitechats = get_config('irc','sitechats'); + } if($sitechats) $chats = explode(',',$sitechats); else @@ -106,7 +94,13 @@ function irc_content(&$a) { $a->page['aside'] .= ''; /* setting the channel(s) to auto connect */ - $autochans = get_config('irc','autochans'); + if (local_user()) { + $autochans = get_pconfig(local_user(), 'irc', 'autochans'); + if (!$autochans) + $autochans = get_config('irc','autochans'); + } else { + $autochans = get_config('irc','autochans'); + } if($autochans) $channels = $autochans; else @@ -116,11 +110,31 @@ function irc_content(&$a) { $o .= <<< EOT

IRC chat

A beginner's guide to using IRC. [en]

- + EOT; return $o; } +function irc_plugin_admin_post (&$a) { + if(! is_site_admin()) + return; + if($_POST['irc-submit']) { + set_config('irc','autochans',trim($_POST['autochans'])); + set_config('irc','sitechats',trim($_POST['sitechats'])); + /* stupid pop-up thing */ + info( t('IRC settings saved.') . EOL); + } +} +function irc_plugin_admin (&$a, &$o) { + $sitechats = get_config('irc','sitechats'); /* popular channels */ + $autochans = get_config('irc','autochans'); /* auto connect chans */ + $t = get_markup_template( "admin.tpl", "addon/irc/" ); + $o = replace_macros($t, array( + '$submit' => t('Save Settings'), + '$autochans' => array( 'autochans', t('Channel(s) to auto connect (comma separated)'), $autochans, t('List of channels that shall automatically connected to when the app is launched.')), + '$sitechats' => array( 'sitechats', t('Popular Channels (comma separated)'), $sitechats, t('List of popular channels, will be displayed at the side and hotlinked for easy joining.') ) + )); +}