[pageheader] Avoid notice
[friendica-addons.git/.git] / irc / irc.php
index 6aeacbe..aa727e2 100644 (file)
@@ -6,20 +6,22 @@
 * Author: tony baldwin <https://free-haven.org/profile/tony>
 * Author: Tobias Diekershoff <https://f.diekershoff.de/u/tobias>
 */
-use Friendica\Core\Addon;
+
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
 
 function irc_install() {
-       Addon::registerHook('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
-       Addon::registerHook('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
-       Addon::registerHook('addon_settings_post', 'addon/irc/irc.php', 'irc_addon_settings_post');
+       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');
 }
 
 function irc_uninstall() {
-       Addon::unregisterHook('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
-       Addon::unregisterHook('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
+       Hook::unregister('app_menu', 'addon/irc/irc.php', 'irc_app_menu');
+       Hook::unregister('addon_settings', 'addon/irc/irc.php', 'irc_addon_settings');
 
 }
 
@@ -30,14 +32,14 @@ function irc_addon_settings(&$a,&$s) {
 
     /* Add our stylesheet to the page so we can make our settings look nice */
 
-//     $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
+//     $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->getBaseURL() . '/addon/irc/irc.css' . '" media="all" />' . "\r\n";
 
     /* setting popular channels, auto connect channels */
        $sitechats = PConfig::get( local_user(), 'irc','sitechats'); /* popular channels */
        $autochans = PConfig::get( local_user(), 'irc','autochans');  /* auto connect chans */
 
-       $t = get_markup_template( "settings.tpl", "addon/irc/" );
-       $s .= replace_macros($t, [
+       $t = Renderer::getMarkupTemplate( "settings.tpl", "addon/irc/" );
+       $s .= Renderer::replaceMacros($t, [
                '$header' => L10n::t('IRC Settings'),
                '$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.'),
                '$submit' => L10n::t('Save Settings'),
@@ -50,13 +52,17 @@ function irc_addon_settings(&$a,&$s) {
 
 }
 
-function irc_addon_settings_post(&$a,&$b) {
-       if(! local_user())
+function irc_addon_settings_post(&$a, &$b) {
+       if(!local_user())
                return;
 
-       if($_POST['irc-submit']) {
-               PConfig::set( local_user(), 'irc','autochans',trim($_POST['autochans']));
-               PConfig::set( local_user(), 'irc','sitechats',trim($_POST['sitechats']));
+       if(!empty($_POST['irc-submit'])) {
+               if (isset($_POST['autochans'])) {
+                       PConfig::set(local_user(), 'irc', 'autochans', trim(($_POST['autochans'])));
+               }
+               if (isset($_POST['sitechats'])) {
+                       PConfig::set(local_user(), 'irc', 'sitechats', trim($_POST['sitechats']));
+               }
                /* upid pop-up thing */
                info(L10n::t('IRC settings saved.') . EOL);
        }
@@ -74,7 +80,7 @@ function irc_module() {
 
 function irc_content(&$a) {
 
-       $baseurl = $a->get_baseurl() . '/addon/irc';
+       $baseurl = $a->getBaseURL() . '/addon/irc';
        $o = '';
 
        /* set the list of popular channels */
@@ -93,7 +99,7 @@ function irc_content(&$a) {
 
        $a->page['aside'] .= '<div class="widget"><h3>' . L10n::t('Popular Channels') . '</h3><ul>';
        foreach($chats as $chat) {
-               $a->page['aside'] .= '<li><a href="' . $a->get_baseurl() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
+               $a->page['aside'] .= '<li><a href="' . $a->getBaseURL() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
        }
        $a->page['aside'] .= '</ul></div>';
 
@@ -108,7 +114,7 @@ function irc_content(&$a) {
        if($autochans)
                $channels = $autochans;
        else
-               $channels = ((x($_GET,'channels')) ? $_GET['channels'] : 'friendica');
+               $channels = defaults($_GET, 'channels', 'friendica');
 
 /* add the chatroom frame and some html */
   $o .= <<< EOT
@@ -135,8 +141,8 @@ function irc_addon_admin_post (&$a) {
 function irc_addon_admin (&$a, &$o) {
        $sitechats = Config::get('irc','sitechats'); /* popular channels */
        $autochans = Config::get('irc','autochans');  /* auto connect chans */
-       $t = get_markup_template( "admin.tpl", "addon/irc/" );
-       $o = replace_macros($t, [
+       $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/irc/" );
+       $o = Renderer::replaceMacros($t, [
                '$submit' => L10n::t('Save Settings'),
                '$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.')],
                '$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.') ]