[widgets] Remove superfluous $baseurl template variable
[friendica-addons.git/.git] / widgets / widgets.php
index 5cb8a27..5c07596 100644 (file)
@@ -7,20 +7,22 @@
  * Status: Unsupported
  */
 
-use Friendica\Core\Addon;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 
 function widgets_install() {
-       Addon::registerHook('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings');
-       Addon::registerHook('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
-       logger("installed widgets");
+       Hook::register('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings');
+       Hook::register('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
+       Logger::log("installed widgets");
 }
 
 function widgets_uninstall() {
-       Addon::unregisterHook('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings');
-       Addon::unregisterHook('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
+       Hook::unregister('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings');
+       Hook::unregister('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
 }
 
 function widgets_settings_post(){
@@ -57,10 +59,9 @@ function widgets_settings(&$a,&$o) {
 
 
 #      $t = file_get_contents( dirname(__file__). "/settings.tpl" );
-       $t = get_markup_template("settings.tpl", "addon/widgets/");
-       $o .= replace_macros($t, [
+       $t = Renderer::getMarkupTemplate("settings.tpl", "addon/widgets/");
+       $o .= Renderer::replaceMacros($t, [
                '$submit' => L10n::t('Generate new key'),
-               '$baseurl' => $a->getBaseURL(),
                '$title' => "Widgets",
                '$label' => L10n::t('Widgets key'),
                '$key' => $key,
@@ -75,7 +76,7 @@ function widgets_module() {
 }
 
 function _abs_url($s){
-       $a = get_app();
+       $a = \get_app();
        return preg_replace("|href=(['\"])([^h][^t][^t][^p])|", "href=\$1".$a->getBaseURL()."/\$2", $s);
 }
 
@@ -87,7 +88,7 @@ function _randomAlphaNum($length){
 function widgets_content(&$a) {
 
        if (!isset($_GET['k'])) {
-               if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
+               if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); exit();}
                return;
        }
 
@@ -95,7 +96,7 @@ function widgets_content(&$a) {
                        DBA::escape($_GET['k'])
                 );
        if (!count($r)){
-               if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
+               if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); exit();}
                return;
        }
        $conf = [];
@@ -108,7 +109,7 @@ function widgets_content(&$a) {
        if (file_exists($widgetfile)){
                require_once($widgetfile);
        } else {
-               if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
+               if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); exit();}
                return;
        }
 
@@ -141,7 +142,7 @@ function widgets_content(&$a) {
                $widget_size = call_user_func($a->argv[1].'_widget_size');
 
                $script = file_get_contents(dirname(__file__)."/widgets.js");
-               $o .= replace_macros($script, [
+               $o .= Renderer::replaceMacros($script, [
                        '$entrypoint' => $a->getBaseURL()."/widgets/".$a->argv[1]."/cb/",
                        '$key' => $conf['key'],
                        '$widget_id' => 'f9a_'.$a->argv[1]."_"._randomAlphaNum(6),
@@ -174,5 +175,5 @@ function widgets_content(&$a) {
        }
 
        echo $o;
-       killme();
+       exit();
 }