X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fstatusnet.php;h=a9b05388c393f6e0e6a4a51c55c96407a2a08845;hb=6e181a2454e888b09313344138f66713d5c9c99f;hp=85b46bbb3fed09904a31878c5f91caa01f5fd495;hpb=0dcfcbd51732bdb73368461cc3cd5d9898de5484;p=quix0rs-gnu-social.git diff --git a/lib/statusnet.php b/lib/statusnet.php index 85b46bbb3f..a9b05388c3 100644 --- a/lib/statusnet.php +++ b/lib/statusnet.php @@ -31,6 +31,7 @@ class StatusNet { protected static $have_config; protected static $is_api; + protected static $is_ajax; protected static $plugins = array(); /** @@ -43,9 +44,17 @@ class StatusNet * * @throws ServerException if plugin can't be found */ - public static function addPlugin($name, $attrs = null) + public static function addPlugin($name, array $attrs=array()) { $name = ucfirst($name); + + if (isset(self::$plugins[$name])) { + // We have already loaded this plugin. Don't try to + // do it again with (possibly) different values. + // Försten till kvarn får mala. + return true; + } + $pluginclass = "{$name}Plugin"; if (!class_exists($pluginclass)) { @@ -69,15 +78,29 @@ class StatusNet } } + // Doesn't this $inst risk being garbage collected or something? + // TODO: put into a static array that makes sure $inst isn't lost. $inst = new $pluginclass(); - if (!empty($attrs)) { - foreach ($attrs as $aname => $avalue) { - $inst->$aname = $avalue; - } + foreach ($attrs as $aname => $avalue) { + $inst->$aname = $avalue; } // Record activated plugins for later display/config dump - self::$plugins[] = array($name, $attrs); + self::$plugins[$name] = $attrs; + + return true; + } + + public static function delPlugin($name) + { + // Remove our plugin if it was previously loaded + $name = ucfirst($name); + if (isset(self::$plugins[$name])) { + unset(self::$plugins[$name]); + } + + // make sure initPlugins will avoid this + common_config_set('plugins', 'disable-'.$name, true); return true; } @@ -107,9 +130,15 @@ class StatusNet */ public static function init($server=null, $path=null, $conffile=null) { - StatusNet::initDefaults($server, $path); - StatusNet::loadConfigFile($conffile); + Router::clear(); + self::initDefaults($server, $path); + self::loadConfigFile($conffile); + + $sprofile = common_config('site', 'profile'); + if (!empty($sprofile)) { + self::loadSiteProfile($sprofile); + } // Load settings from database; note we need autoload for this Config::loadSettings(); @@ -141,7 +170,7 @@ class StatusNet return true; } - $sn = Status_network::staticGet('nickname', $nickname); + $sn = Status_network::getKV('nickname', $nickname); if (empty($sn)) { return false; throw new Exception("No such site nickname '$nickname'"); @@ -174,20 +203,36 @@ class StatusNet */ protected static function initPlugins() { + // User config may have already added some of these plugins, with + // maybe configured parameters. The self::addPlugin function will + // ignore the new call if it has already been instantiated. + + // Load core plugins + foreach (common_config('plugins', 'core') as $name => $params) { + call_user_func('self::addPlugin', $name, $params); + } + // Load default plugins foreach (common_config('plugins', 'default') as $name => $params) { + $key = 'disable-' . $name; + if (common_config('plugins', $key)) { + continue; + } + + // TODO: We should be able to avoid this is_null and assume $params + // is an array, since that's how it is typed in addPlugin if (is_null($params)) { - addPlugin($name); + self::addPlugin($name); } else if (is_array($params)) { if (count($params) == 0) { - addPlugin($name); + self::addPlugin($name); } else { $keys = array_keys($params); if (is_string($keys[0])) { - addPlugin($name, $params); + self::addPlugin($name, $params); } else { foreach ($params as $paramset) { - addPlugin($name, $paramset); + self::addPlugin($name, $paramset); } } } @@ -210,21 +255,31 @@ class StatusNet * * @return bool */ - public function haveConfig() + public static function haveConfig() { return self::$have_config; } - public function isApi() + public static function isApi() { return self::$is_api; } - public function setApi($mode) + public static function setApi($mode) { self::$is_api = $mode; } + public static function isAjax() + { + return self::$is_ajax; + } + + public static function setAjax($mode) + { + self::$is_ajax = $mode; + } + /** * Build default configuration array * @return array @@ -240,9 +295,9 @@ class StatusNet * Establish default configuration based on given or default server and path * Sets global $_server, $_path, and $config */ - protected static function initDefaults($server, $path) + public static function initDefaults($server, $path) { - global $_server, $_path, $config; + global $_server, $_path, $config, $_PEAR; Event::clearHandlers(); self::$plugins = array(); @@ -274,21 +329,24 @@ class StatusNet // default configuration, overwritten in config.php // Keep DB_DataObject's db config synced to ours... - $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); + $config['db'] = &$_PEAR->getStaticProperty('DB_DataObject','options'); $config['db'] = $default['db']; - // Backward compatibility - - $config['site']['design'] =& $config['design']; - if (function_exists('date_default_timezone_set')) { /* Work internally in UTC */ date_default_timezone_set('UTC'); } } - protected function _sn_to_path($sn) + public static function loadSiteProfile($name) + { + global $config; + $settings = SiteProfile::getSettings($name); + $config = array_replace_recursive($config, $settings); + } + + protected static function _sn_to_path($sn) { $past_root = substr($sn, 1); $last_slash = strrpos($past_root, '/'); @@ -306,7 +364,7 @@ class StatusNet * * @throws NoConfigException */ - protected function loadConfigFile($conffile=null) + protected static function loadConfigFile($conffile=null) { global $_server, $_path, $config; @@ -337,6 +395,7 @@ class StatusNet if (@file_exists($_config_file)) { // Ignore 0-byte config files if (filesize($_config_file) > 0) { + common_log(LOG_INFO, "Including config file: " . $_config_file); include($_config_file); self::$have_config = true; } @@ -348,23 +407,10 @@ class StatusNet $config_files); } - // Fixup for statusnet.ini - $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1); - - if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) { - $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini'; - } + // Check for database server; must exist! - // Backwards compatibility - - if (array_key_exists('memcached', $config)) { - if ($config['memcached']['enabled']) { - addPlugin('Memcache', array('servers' => $config['memcached']['server'])); - } - - if (!empty($config['memcached']['base'])) { - $config['cache']['base'] = $config['memcached']['base']; - } + if (empty($config['db']['database'])) { + throw new ServerException("No database server for this site."); } }