]> git.mxchange.org Git - friendica-addons.git/blobdiff - randplace/randplace.php
Update t() calls
[friendica-addons.git] / randplace / randplace.php
old mode 100755 (executable)
new mode 100644 (file)
index 27589b1..abf59e2
@@ -1,46 +1,48 @@
 <?php
 /**
  * Name: Random place
- * Description: Sample Friendica plugin/addon. Set a random place when posting.
+ * Description: Sample Friendica addon. Set a random place when posting.
  * Version: 1.0
  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
- * 
- * 
- * 
+ *
+ *
+ *
  *
  * Addons are registered with the system through the admin
  * panel.
  *
- * When registration is detected, the system calls the plugin
+ * When registration is detected, the system calls the addon
  * name_install() function, located in 'addon/name/name.php',
  * where 'name' is the name of the addon.
- * If the addon is removed from the configuration list, the 
+ * If the addon is removed from the configuration list, the
  * system will call the name_uninstall() function.
  *
  */
-
+use Friendica\Core\Addon;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
 
 function randplace_install() {
 
        /**
-        * 
-        * Our demo plugin will attach in three places.
+        *
+        * Our demo addon will attach in three places.
         * The first is just prior to storing a local post.
         *
         */
 
-       register_hook('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook');
+       Addon::registerHook('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook');
 
        /**
         *
-        * Then we'll attach into the plugin settings page, and also the 
+        * Then we'll attach into the addon settings page, and also the
         * settings post hook so that we can create and update
         * user preferences.
         *
         */
 
-       register_hook('plugin_settings', 'addon/randplace/randplace.php', 'randplace_settings');
-       register_hook('plugin_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post');
+       Addon::registerHook('addon_settings', 'addon/randplace/randplace.php', 'randplace_settings');
+       Addon::registerHook('addon_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post');
 
        logger("installed randplace");
 }
@@ -56,9 +58,9 @@ function randplace_uninstall() {
         *
         */
 
-       unregister_hook('post_local',    'addon/randplace/randplace.php', 'randplace_post_hook');
-       unregister_hook('plugin_settings', 'addon/randplace/randplace.php', 'randplace_settings');
-       unregister_hook('plugin_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post');
+       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("removed randplace");
@@ -73,7 +75,7 @@ function randplace_post_hook($a, &$item) {
         * An item was posted on the local system.
         * We are going to look for specific items:
         *      - A status post by a profile owner
-        *      - The profile owner must have allowed our plugin
+        *      - The profile owner must have allowed our addon
         *
         */
 
@@ -90,7 +92,7 @@ function randplace_post_hook($a, &$item) {
 
        /* Retrieve our personal config setting */
 
-       $active = get_pconfig(local_user(), 'randplace', 'enable');
+       $active = PConfig::get(local_user(), 'randplace', 'enable');
 
        if(! $active)
                return;
@@ -104,7 +106,7 @@ function randplace_post_hook($a, &$item) {
         *
         */
 
-       $cities = array();
+       $cities = [];
        $zones = timezone_identifiers_list();
        foreach($zones as $zone) {
                if((strpos($zone,'/')) && (! stristr($zone,'US/')) && (! stristr($zone,'Etc/')))
@@ -135,13 +137,13 @@ function randplace_settings_post($a,$post) {
        if(! local_user())
                return;
        if($_POST['randplace-submit'])
-               set_pconfig(local_user(),'randplace','enable',intval($_POST['randplace']));
+               PConfig::set(local_user(),'randplace','enable',intval($_POST['randplace']));
 }
 
 
 /**
  *
- * Called from the Plugin Setting form. 
+ * Called from the Addon Setting form.
  * Add our own settings info to the page.
  *
  */
@@ -159,21 +161,21 @@ function randplace_settings(&$a,&$s) {
 
        /* Get the current state of our config variable */
 
-       $enabled = get_pconfig(local_user(),'randplace','enable');
+       $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>' . t('Randplace Settings') . '</h3>';
+       $s .= '<h3>' . L10n::t('Randplace Settings') . '</h3>';
        $s .= '<div id="randplace-enable-wrapper">';
-       $s .= '<label id="randplace-enable-label" for="randplace-checkbox">' . t('Enable Randplace Plugin') . '</label>';
+       $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 */
 
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="randplace-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
+       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="randplace-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
 
 }