]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/plugin.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / lib / plugin.php
index 97ff8f19aa40ecc0b533d3dcb0d1440215a9fb5e..65ccdafbb02af1b82277b42f77aa7cd1734f446e 100644 (file)
  *
  * @category  Plugin
  * @package   StatusNet
- * @author    Evan Prodromou <evan@controlyourself.ca>
+ * @author    Evan Prodromou <evan@status.net>
  * @copyright 2008 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
@@ -46,7 +46,7 @@ if (!defined('LACONICA')) {
  *
  * @category Plugin
  * @package  StatusNet
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  *
@@ -65,6 +65,8 @@ class Plugin
                 Event::addHandler(mb_substr($method, 2), array($this, $method));
             }
         }
+
+        $this->setupGettext();
     }
 
     function initialize()
@@ -76,4 +78,42 @@ class Plugin
     {
         return true;
     }
+
+    /**
+     * Checks if this plugin has localization that needs to be set up.
+     * Gettext localizations can be called via the _m() helper function.
+     */
+    protected function setupGettext()
+    {
+        $class = get_class($this);
+        if (substr($class, -6) == 'Plugin') {
+            $name = substr($class, 0, -6);
+            $path = INSTALLDIR . "/plugins/$name/locale";
+            if (file_exists($path) && is_dir($path)) {
+                bindtextdomain($name, $path);
+            }
+        }
+    }
+
+    protected function log($level, $msg)
+    {
+        common_log($level, get_class($this) . ': '.$msg);
+    }
+
+    protected function debug($msg)
+    {
+        $this->log(LOG_DEBUG, $msg);
+    }
+
+    function onPluginVersion(&$versions)
+    {
+        $cls = get_class($this);
+        $name = mb_substr($cls, 0, -6);
+
+        $versions[] = array('name' => $name,
+                            'version' => _('Unknown'));
+
+        return true;
+    }
 }
+