]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.9.x' of git@gitorious.org:laconica/mainline into 0.9.x
authorEvan Prodromou <evan@controlyourself.ca>
Fri, 21 Aug 2009 20:17:45 +0000 (16:17 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Fri, 21 Aug 2009 20:17:45 +0000 (16:17 -0400)
classes/Config.php [new file with mode: 0755]
classes/laconica.ini
db/laconica.sql
lib/common.php

diff --git a/classes/Config.php b/classes/Config.php
new file mode 100755 (executable)
index 0000000..5bec13f
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, Control Yourself, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.     If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+/**
+ * Table Definition for config
+ */
+
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class Config extends Memcached_DataObject
+{
+    ###START_AUTOCODE
+    /* the code below is auto generated do not remove the above tag */
+
+    public $__table = 'config';                          // table name
+    public $section;                         // varchar(32)  primary_key not_null
+    public $setting;                         // varchar(32)  primary_key not_null
+    public $value;                           // varchar(255)
+
+    /* Static get */
+    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Config',$k,$v); }
+
+    /* the code above is auto generated do not remove the tag below */
+    ###END_AUTOCODE
+
+    const settingsKey = 'config:settings';
+
+    static function loadSettings()
+    {
+        $settings = self::_getSettings();
+        if (!empty($settings)) {
+            self::_applySettings($settings);
+        }
+    }
+
+    static function _getSettings()
+    {
+        $c = self::memcache();
+
+        if (!empty($c)) {
+            $settings = $c->get(common_cache_key(self::settingsKey));
+            if (!empty($settings)) {
+                return $settings;
+            }
+        }
+
+        $settings = array();
+
+        $config = new Config();
+
+        $config->find();
+
+        while ($config->fetch()) {
+            $settings[] = array($config->section, $config->setting, $config->value);
+        }
+
+        $config->free();
+
+        if (!empty($c)) {
+            $c->set(common_cache_key(self::settingsKey), $settings);
+        }
+
+        return $settings;
+    }
+
+    static function _applySettings($settings)
+    {
+        global $config;
+
+        foreach ($settings as $s) {
+            list($section, $setting, $value) = $s;
+            $config[$section][$setting] = $value;
+        }
+    }
+
+    function insert()
+    {
+        $result = parent::insert();
+        if ($result) {
+            Config::_blowSettingsCache();
+        }
+        return $result;
+    }
+
+    function delete()
+    {
+        $result = parent::delete();
+        if ($result) {
+            Config::_blowSettingsCache();
+        }
+        return $result;
+    }
+
+    function update($orig=null)
+    {
+        $result = parent::update($orig);
+        if ($result) {
+            Config::_blowSettingsCache();
+        }
+        return $result;
+    }
+
+    function _blowSettingsCache()
+    {
+        $c = self::memcache();
+
+        if (!empty($c)) {
+            $c->delete(common_cache_key(self::settingsKey));
+        }
+    }
+}
index c02996b3f2cb082ef6f4d2d68e3f51932a53619b..7edeeebe4fa3ec7b0e49ef05615f61b63feee1e7 100755 (executable)
@@ -16,6 +16,15 @@ width = K
 height = K
 url = U
 
+[config]
+section = 130
+setting = 130
+value = 2
+
+[config__keys]
+section = K
+setting = K
+
 [confirm_address]
 code = 130
 user_id = 129
index 56bd4b1e38496f5fe0e7eab1d1614760e36a90cc..1662ef7a8be6bc074c1c76b4a25937cd3955ad3d 100644 (file)
@@ -547,3 +547,13 @@ create table deleted_notice (
     index deleted_notice_profile_id_idx (profile_id)
 
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
+create table config (
+
+    section varchar(32) comment 'configuration section',
+    setting varchar(32) comment 'configuration setting',
+    value varchar(255) comment 'configuration value',
+
+    constraint primary key (section, setting)
+
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
index 84ee5be15f2332d5f63572c0880605df91b7184d..067a5a2a61bafcdfb8a6cb42c7078e1dcf58298b 100644 (file)
@@ -21,6 +21,8 @@ if (!defined('LACONICA')) { exit(1); }
 
 define('LACONICA_VERSION', '0.9.0dev');
 
+// XXX: move these to class variables
+
 define('AVATAR_PROFILE_SIZE', 96);
 define('AVATAR_STREAM_SIZE', 48);
 define('AVATAR_MINI_SIZE', 24);
@@ -387,7 +389,25 @@ if (!$config['openid']['enabled']) {
     $config['site']['openidonly'] = false;
 }
 
+function __autoload($cls)
+{
+    if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
+        require_once(INSTALLDIR.'/classes/' . $cls . '.php');
+    } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
+        require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
+    } else if (mb_substr($cls, -6) == 'Action' &&
+               file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
+        require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
+    } else if ($cls == 'OAuthRequest') {
+        require_once('OAuth.php');
+    } else {
+        Event::handle('Autoload', array(&$cls));
+    }
+}
+
 // XXX: how many of these could be auto-loaded on use?
+// XXX: note that these files should not use config options
+// at compile time since DB config options are not yet loaded.
 
 require_once 'Validate.php';
 require_once 'markdown.php';
@@ -403,26 +423,14 @@ require_once INSTALLDIR.'/lib/twitter.php';
 require_once INSTALLDIR.'/lib/clientexception.php';
 require_once INSTALLDIR.'/lib/serverexception.php';
 
+// Load settings from database; note we need autoload for this
+
+Config::loadSettings();
+
 // XXX: other formats here
 
 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
 
-function __autoload($cls)
-{
-    if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
-        require_once(INSTALLDIR.'/classes/' . $cls . '.php');
-    } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
-        require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
-    } else if (mb_substr($cls, -6) == 'Action' &&
-               file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
-        require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
-    } else if ($cls == 'OAuthRequest') {
-        require_once('OAuth.php');
-    } else {
-        Event::handle('Autoload', array(&$cls));
-    }
-}
-
 // Give plugins a chance to initialize in a fully-prepared environment
 
 Event::handle('InitializePlugin');