Exemple #1
0
 public static function parse($configFile)
 {
     self::$_tmpPrefix = 0;
     self::$_tmpData = array();
     $cacheKey = "SConfig_Cache_" . md5(realpath($configFile));
     if (self::$CACHE) {
         if (isset(self::$_result[$cacheKey])) {
             return self::$_result[$cacheKey];
         }
         $tmp_file = self::_tmpDir() . "/" . self::$_tmpPrefix . $cacheKey;
         if (is_file($tmp_file) && filemtime($tmp_file) >= filemtime($configFile)) {
             $result = unserialize(file_get_contents($tmp_file, false));
             self::$_result[$cacheKey] = $result;
             return $result;
         }
     }
     $content = file_get_contents($configFile, false);
     //去掉注释,#号表示注释
     $content = preg_replace("/^(\\s*)#(.*)/m", "", $content);
     //保存临时变量,单引号,双引号里特殊字符
     $content = preg_replace_callback("/(\\S+?)[\\s:]+([\\'\"])(.*?)\\2;/m", array("SConfig", "_tmpData"), $content);
     //获取最直接的k,v值
     $result = self::_getKV($content);
     self::_split($content, $result);
     if (self::$CACHE) {
         file_put_contents($tmp_file, serialize($result), LOCK_EX);
         self::$_result[$cacheKey] = $result;
     }
     return $result;
 }
Exemple #2
0
 /**
  * @param string $zone
  * @param string $type	main|query
  * @return array
  */
 static function getConfig($zone = null, $type = "main")
 {
     $config = SConfig::getConfig(self::$_config_file, $zone);
     if (isset($config->{$type})) {
         return $config->{$type};
     } elseif (isset($config->main)) {
         return $config->main;
     }
     return;
 }
Exemple #3
0
 /**
  * @param string $zone
  * @return array
  */
 static function getConfig($zone = null, $type = "host")
 {
     $config = SConfig::getConfig(self::$_config, $zone);
     if (isset($config->{$type})) {
         return $config->{$type};
     } elseif (isset($config->host)) {
         return $config->host;
     }
     return;
 }
Exemple #4
0
 public function render()
 {
     if (!$this->view) {
         die('View is empty.');
     } else {
         $content = $this->view . '.php';
     }
     foreach ($this->vars as $var) {
         ${$var['key']} = $var['value'];
     }
     # Variável contem as informações da empresa
     #$this->company = new Company(1);
     require SConfig::get('view_path') . SConfig::get('template_default') . '.php';
 }
 function _read_file()
 {
     global $SConfig;
     if (!isset($SConfig)) {
         SConfig::create();
     }
     if (!file_exists($SConfig->_filename)) {
         SError::add("file " . $SConfig->_filename . " does not exists.");
         return false;
     }
     $fd = fopen($SConfig->_filename, "r");
     if (!$fd) {
         SError::add("error opening file for reading");
         return false;
     }
     $buffer = "";
     while (!feof($fd)) {
         $buffer .= fgets($fd, 4096);
     }
     fclose($fd);
     $buffer = eregi_replace("\n\n", "\n", $buffer);
     return $buffer;
 }
Exemple #6
0
 static function getConfig($zone = null)
 {
     return SConfig::getConfig(self::$_config, $zone);
 }
Exemple #7
0
<?php

error_reporting(E_ALL ^ E_NOTICE);
include "../www/global.php";
chdir(dirname(__FILE__));
SLog::$LOGFILE = "log/run.log";
SConfig::$CACHE = false;
$info = array();
for (;;) {
    usleep(1000 * 500);
    $config = SConfig::parse("backend.conf");
    foreach ($config as $conf) {
        if (!empty($conf->app) || !empty($conf->interval)) {
            if (empty($info[$conf->app]['starttime']) || $info[$conf->app]['starttime'] + $conf->interval <= time()) {
                $info[$conf->app]['starttime'] = time();
                $fname = _tmpDir() . "/crontab.pid." . $info[$conf->app]['pid'];
                if (!empty($info[$conf->app]['pid']) && file_exists($fname)) {
                    $fp = fopen($fname, "r");
                    if (flock($fp, LOCK_SH | LOCK_NB) == false) {
                        //上次运行的进程还没有结束
                        fclose($fp);
                        continue;
                    }
                    fclose($fp);
                }
                $ret = pcntl_fork();
                $command = $conf->app;
                if (!empty($conf->params)) {
                    $params = $conf->params;
                } else {
                    $params = new stdclass();
Exemple #8
0
 protected function _getDBConf($db)
 {
     $dbConf = SConfig::getDBConfig($db);
     if (strcasecmp($dbConf['driver'], 'mysql')) {
         throw new __Exception("Not supported database type: {$dbConf['driver']}", SCRIPT_ERR_CONFIG);
     }
     return $dbConf;
 }
$err='';
$config['rows_per_page']='';
$config['cols_per_page']='';
require_once($config['BASE_DIR'].'/smarty/libs/Smarty.class.php');
require_once($config['BASE_DIR'].'/classes/mysmarty.class.php');
require_once($config['BASE_DIR'].'/classes/SConfig.php');
require_once($config['BASE_DIR'].'/classes/SError.php');
require_once($config['BASE_DIR'].'/include/adodb/adodb.inc.php');
require_once($config['BASE_DIR'].'/include/phpmailer/class.phpmailer.php');
require_once($config['BASE_DIR'].'/classes/SEmail.php');

$DBTYPE = 'mysql';
$DBHOST = SConfig::get("Database", "host");
$DBUSER = SConfig::get("Database", "user_name");
$DBPASSWORD = SConfig::get("Database", "password");
$DBNAME = SConfig::get("Database", "db_name");

$conn = &ADONewConnection($DBTYPE);
$conn->PConnect($DBHOST, $DBUSER, $DBPASSWORD, $DBNAME);

$sql = "SELECT * from sconfig";
$rsc = $conn->Execute($sql);

if($rsc){while(!$rsc->EOF)
{
$field = $rsc->fields['soption'];
$config[$field] = $rsc->fields['svalue'];
STemplate::assign($field, $config[$field]);
@$rsc->MoveNext();
}}
Exemple #10
0
 /**
  * @return log
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         $startTime = microtime(true) * 1000;
         $logConf = !empty($GLOBALS['LOG_CONF']) ? $GLOBALS['LOG_CONF'] : 'default';
         $logConfig = SConfig::getConfig(ROOT_CONFIG . "/log.conf", $logConf);
         if (!empty($logConfig->filename)) {
             $logConfig->filename = sprintf($logConfig->filename, date('Ymd'));
             self::$instance = new SLog($logConfig, $startTime);
         } else {
             $stdClass = new stdClass();
             $stdClass->appName = 'AllLog';
             $stdClass->type = 'LOCAL_LOG';
             $stdClass->level = '0x15';
             $stdClass->path = '/tmp';
             $stdClass->filename = 'All_log.' . date('Ymd');
             self::$instance = new SLog($stdClass, $startTime);
         }
     }
     return self::$instance;
 }