]> git.mxchange.org Git - friendica-addons.git/blobdiff - randplace/randplace.php
regen webrtc messeages.po file
[friendica-addons.git] / randplace / randplace.php
index 7784d80b41d90e00f48d1e523bb989890d349720..69ad4d52d8051196b64eb43cc4ab9f3256a698f8 100644 (file)
  * system will call the name_uninstall() function.
  *
  */
-use Friendica\Core\Addon;
-use Friendica\Core\L10n;
+
+use Friendica\App;
+use Friendica\Core\Hook;
 use Friendica\Core\Logger;
-use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\DI;
 
 function randplace_install() {
 
@@ -32,7 +34,7 @@ function randplace_install() {
         *
         */
 
-       Addon::registerHook('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook');
+       Hook::register('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook');
 
        /**
         *
@@ -42,10 +44,10 @@ function randplace_install() {
         *
         */
 
-       Addon::registerHook('addon_settings', 'addon/randplace/randplace.php', 'randplace_settings');
-       Addon::registerHook('addon_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post');
+       Hook::register('addon_settings', 'addon/randplace/randplace.php', 'randplace_settings');
+       Hook::register('addon_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post');
 
-       Logger::log("installed randplace");
+       Logger::notice("installed randplace");
 }
 
 
@@ -53,18 +55,13 @@ function randplace_uninstall() {
 
        /**
         *
-        * uninstall unregisters any hooks created with register_hook
-        * during install. It may also delete configuration settings
-        * and any other cleanup.
+        * This function should undo anything that was done in name_install()
+        *
+        * Except hooks, they are all unregistered automatically and don't need to be unregistered manually.
         *
         */
 
-       Addon::unregisterHook('post_local',    'addon/randplace/randplace.php', 'randplace_post_hook');
-       Addon::unregisterHook('addon_settings', 'addon/randplace/randplace.php', 'randplace_settings');
-       Addon::unregisterHook('addon_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post');
-
-
-       Logger::log("removed randplace");
+       Logger::notice("removed randplace");
 }
 
 
@@ -80,7 +77,7 @@ function randplace_post_hook($a, &$item) {
         *
         */
 
-       Logger::log('randplace invoked');
+       Logger::notice('randplace invoked');
 
        if(! local_user())   /* non-zero if this is a logged in user of this system */
                return;
@@ -93,7 +90,7 @@ function randplace_post_hook($a, &$item) {
 
        /* Retrieve our personal config setting */
 
-       $active = PConfig::get(local_user(), 'randplace', 'enable');
+       $active = DI::pConfig()->get(local_user(), 'randplace', 'enable');
 
        if(! $active)
                return;
@@ -138,7 +135,7 @@ function randplace_settings_post($a,$post) {
        if(! local_user())
                return;
        if($_POST['randplace-submit'])
-               PConfig::set(local_user(),'randplace','enable',intval($_POST['randplace']));
+               DI::pConfig()->set(local_user(),'randplace','enable',intval($_POST['randplace']));
 }
 
 
@@ -151,32 +148,22 @@ function randplace_settings_post($a,$post) {
 
 
 
-function randplace_settings(&$a,&$s) {
-
-       if(! local_user())
+function randplace_settings(App &$a, array &$data)
+{
+       if(! local_user()) {
                return;
+       }
 
-       /* 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->getBaseURL() . '/addon/randplace/randplace.css' . '" media="all" />' . "\r\n";
-
-       /* Get the current state of our config variable */
-
-       $enabled = PConfig::get(local_user(),'randplace','enable');
-
-       $checked = (($enabled) ? ' checked="checked" ' : '');
-
-       /* Add some HTML to the existing form */
-
-       $s .= '<div class="settings-block">';
-       $s .= '<h3>' . L10n::t('Randplace Settings') . '</h3>';
-       $s .= '<div id="randplace-enable-wrapper">';
-       $s .= '<label id="randplace-enable-label" for="randplace-checkbox">' . L10n::t('Enable Randplace Addon') . '</label>';
-       $s .= '<input id="randplace-checkbox" type="checkbox" name="randplace" value="1" ' . $checked . '/>';
-       $s .= '</div><div class="clear"></div>';
-
-       /* provide a submit button */
+       $enabled = DI::pConfig()->get(local_user(),'randplace','enable');
 
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="randplace-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
+       $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/randplace/');
+       $html = Renderer::replaceMacros($t, [
+               '$enabled' => ['randplace', DI::l10n()->t('Enable Randplace Addon'), $enabled],
+       ]);
 
+       $data = [
+               'addon' => 'randplace',
+               'title' => DI::l10n()->t('Randplace Settings'),
+               'html'  => $html,
+       ];
 }