123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- defined('GNUSOCIAL') || die();
- class Plugin
- {
- function __construct()
- {
- Event::addHandler('InitializePlugin', array($this, 'initialize'));
- Event::addHandler('CleanupPlugin', array($this, 'cleanup'));
- foreach (get_class_methods($this) as $method) {
- if (mb_substr($method, 0, 2) == 'on') {
- Event::addHandler(mb_substr($method, 2), array($this, $method));
- }
- }
- $this->setupGettext();
- }
- function initialize()
- {
- return true;
- }
- function cleanup()
- {
- return true;
- }
-
- public function onAutoload($cls) {
- $cls = basename($cls);
- $basedir = INSTALLDIR . '/local/plugins/' . mb_substr(get_called_class(), 0, -6);
- if (!file_exists($basedir)) {
- $basedir = INSTALLDIR . '/plugins/' . mb_substr(get_called_class(), 0, -6);
- }
- $file = null;
- if (preg_match('/^(\w+)(Action|Form)$/', $cls, $type)) {
- $type = array_map('strtolower', $type);
- $file = "$basedir/{$type[2]}s/{$type[1]}.php";
- }
- if (!file_exists($file)) {
- $file = "$basedir/classes/{$cls}.php";
-
-
- if (!file_exists($file)) {
- $type = strtolower($cls);
- $type = str_replace('_', '/', $type);
- $file = "$basedir/lib/{$type}.php";
- }
- }
- if (!is_null($file) && file_exists($file)) {
- require_once($file);
- return false;
- }
- return true;
- }
-
- protected function setupGettext()
- {
- $class = get_class($this);
- if (substr($class, -6) == 'Plugin') {
- $name = substr($class, 0, -6);
- $path = common_config('plugins', 'locale_path');
- if (!$path) {
-
-
- $path = INSTALLDIR . "/plugins/$name/locale";
- if (!file_exists($path)) {
- $path = INSTALLDIR . "/local/plugins/$name/locale";
- }
- }
- if (file_exists($path) && is_dir($path)) {
- bindtextdomain($name, $path);
- bind_textdomain_codeset($name, 'UTF-8');
- }
- }
- }
- protected function log($level, $msg)
- {
- common_log($level, get_class($this) . ': '.$msg);
- }
- protected function debug($msg)
- {
- $this->log(LOG_DEBUG, $msg);
- }
-
- public function name()
- {
- $cls = get_class($this);
- return mb_substr($cls, 0, -6);
- }
- public function version()
- {
- return GNUSOCIAL_VERSION;
- }
- protected function userAgent() {
- return HTTPClient::userAgent()
- . ' (' . get_class($this) . ' v' . $this->version() . ')';
- }
- function onPluginVersion(array &$versions)
- {
- $name = $this->name();
- $versions[] = array('name' => $name,
-
- 'version' => _('Unknown'));
- return true;
- }
- function path($relative)
- {
- return self::staticPath($this->name(), $relative);
- }
- static function staticPath($plugin, $relative)
- {
- if (GNUsocial::useHTTPS()) {
- $server = common_config('plugins', 'sslserver');
- } else {
- $server = common_config('plugins', 'server');
- }
- if (empty($server)) {
- if (GNUsocial::useHTTPS()) {
- $server = common_config('site', 'sslserver');
- }
- if (empty($server)) {
- $server = common_config('site', 'server');
- }
- }
- if (GNUsocial::useHTTPS()) {
- $path = common_config('plugins', 'sslpath');
- } else {
- $path = common_config('plugins', 'path');
- }
- if (empty($path)) {
-
- if (@file_exists(PUBLICDIR.'/local/plugins/'.$plugin.'/'.$relative)) {
- $path = common_config('site', 'path') . '/local/plugins/';
- } else {
- $path = common_config('site', 'path') . '/plugins/';
- }
- }
- if ($path[strlen($path)-1] != '/') {
- $path .= '/';
- }
- if ($path[0] != '/') {
- $path = '/'.$path;
- }
- $protocol = GNUsocial::useHTTPS() ? 'https' : 'http';
- return $protocol.'://'.$server.$path.$plugin.'/'.$relative;
- }
- }
|