Esempio n. 1
0
 /**
  * constructor, set to private for only singleton instance allowed
  * 
  * @param array $tplConfig
  * @throws TemplateException
  */
 private function __construct(array $tplConfig = array())
 {
     $this->_tplConfig = simphp_array_merge($this->_tplConfig, $tplConfig);
     if ('PlainTpl' === $this->driverClass) {
         $this->driverEntry = '/core/libs/plaintpl/PlainTpl.class.php';
     }
     //...other template engine
     $driverFile = SIMPHP_ROOT . $this->driverEntry;
     if (!file_exists($driverFile)) {
         throw new TemplateException("Template Driver Entry File '{$driverFile}' Not Found.");
     }
     include $driverFile;
     if (!SimPHP::isClassLoaded($this->driverClass)) {
         throw new TemplateClassNotFoundException($this->driverClass);
     }
     // Create and Configure Template Driver Class
     $this->driverObj = new $this->driverClass();
     if ($this->driverConfig) {
         foreach ($this->driverConfig as $key => $val) {
             $this->driverObj->{$key} = $val;
         }
     }
     // Register Template Functions
     $this->register_functions();
     // Regsiter Template Blocks
     $this->register_blocks();
 }
Esempio n. 2
0
 /**
  * on dispatch before hook
  * 
  * @param Request $request
  * @param Response $response
  */
 public static function on_dispatch_before(Request $request, Response $response)
 {
     // 检查q是否在白名单中
     $loginIgnore = false;
     $q = $request->q();
     if (!empty($q)) {
         foreach (self::$loginWhiteList as $key) {
             if (SimPHP::qMatchPattern($key, $q)) {
                 $loginIgnore = true;
                 break;
             }
         }
     }
     // 检查登录状态
     if (!$loginIgnore && !Member::isLogined()) {
         import('user/*');
         $user_Controller = new User_Controller();
         $user_Controller->login($request, $response);
         exit;
     }
     //读取最新用户信息以客户端缓存
     global $user;
     if ($user->uid) {
         $uinfo = Member::getTinyInfoByUid($user->uid, FALSE);
         $user->openid = $uinfo['openid'];
         $user->unionid = $uinfo['unionid'];
         $user->subscribe = $uinfo['subscribe'];
         $user->username = $uinfo['username'];
         $user->nickname = $uinfo['nickname'];
         $user->sex = $uinfo['sex'];
         $user->logo = $uinfo['logo'];
         //$user->ec_user_id= $uinfo['ec_user_id'];
         /*
         if (!$request->is_hashreq()) { //不是hash request,则查看购物车是否有商品
           $cartNum = Goods::getUserCartNum($user->ec_user_id);
           $user->ec_cart_num = $cartNum;
         }
         */
     }
 }
Esempio n. 3
0
<?php

/**
 * Mobile端请求入口
 *
 * @author Gavin<*****@*****.**>
 */
error_reporting(E_ALL);
ini_set('display_errors', 'on');
//~ require init.php
require __DIR__ . '/core/init.php';
$request = new Request();
$response = new Response();
//$response->send('<center style="font-size:36px;">系统维护中,请稍后再访问</center>');
try {
    SimPHP::I(['modroot' => 'mobiles'])->boot(RC_ALL ^ RC_MEMCACHE)->dispatch($request, $response);
} catch (SimPHPException $me) {
    $response->dump($me->getMessage());
} catch (Exception $e) {
    $response->dump($e->getMessage());
}
/*----- END FILE: mobile.php -----*/
Esempio n. 4
0
<?php

/**
 * Web端请求入口
 *
 * @author Gavin<*****@*****.**>
 */
//error_reporting(E_ALL);
//ini_set('display_errors', 'on');
//~ require init.php
require __DIR__ . '/core/init.php';
$request = new Request();
$response = new Response();
try {
    SimPHP::I()->boot(RC_SESSION)->dispatch($request, $response);
} catch (SimPHPException $me) {
    $response->dump($me->getMessage());
} catch (Exception $e) {
    $response->dump($e->getMessage());
}
/*----- END FILE: index.php -----*/
Esempio n. 5
0
<?php

/**
 * 通用API入口文件
 *
 * @author Gavin<*****@*****.**>
 */
if (!isset($_GET['q']) || empty($_GET['q'])) {
    $_GET['q'] = 'weixin/fxmgou';
}
//~ require init.php
require __DIR__ . '/core/init.php';
$request = new Request();
$response = new Response();
try {
    SimPHP::I(['modroot' => 'apis'])->boot(RC_DATABASE)->dispatch($request, $response);
} catch (SimPHPException $me) {
    $response->dump($me->getMessage());
} catch (Exception $e) {
    $response->dump($e->getMessage());
}
/*----- END FILE: api.php -----*/
Esempio n. 6
0
<?php

/**
 * 
 *
 * @author Gavin<*****@*****.**>
 */
//error_reporting(E_ALL);
//ini_set('display_errors', 'on');
//~ require init.php
require __DIR__ . '/core/init.php';
//~ use Smarty template engine
Config::set('env.tplclass', 'Smarty');
Config::set('env.tplpostfix', '.htm');
$request = new Request();
$response = new Response();
try {
    SimPHP::I(['modroot' => 'admins', 'sessnode' => 'adm'])->boot(RC_ALL ^ RC_MEMCACHE)->dispatch($request, $response);
} catch (SimPHPException $me) {
    $response->dump($me->getMessage());
} catch (Exception $e) {
    $response->dump($e->getMessage());
}
/*----- END FILE: admin.php -----*/
Esempio n. 7
0
#!/usr/bin/php
<?php 
/**
 * cron 脚步执行入口
 *
 * @author Gavin<*****@*****.**>
 */
//~ require init.php
require __DIR__ . '/core/init.php';
SimPHP::I()->boot();
if (!defined('CRON_ROOT')) {
    define('CRON_ROOT', SIMPHP_ROOT . '/cron');
}
if (!defined('BR')) {
    define('BR', IS_CLI ? "\n" : "<br>");
}
class JobManager
{
    // PHP commond path, maybe need changing here
    const PHP_CMD = '/usr/bin/php';
    //const PHP_CMD = '/usr/local/php-fcgi/bin/php';
    private function jobs()
    {
        $dir = CRON_ROOT;
        $jobs = [];
        $_handler = opendir($dir);
        while (false !== ($filename = readdir($_handler))) {
            if (preg_match("/^(.+Job)\\.php\$/", $filename, $matches) && is_file("{$dir}/{$filename}")) {
                $jobs[$matches[1]] = "{$dir}/{$filename}";
            }
        }
Esempio n. 8
0
}
if (!function_exists('show_emptyimg')) {
    function show_emptyimg($format = 'gif')
    {
        header('Content-Type: image/' . $format);
        $width = 1;
        $height = 1;
        $img = imageCreate($width, $height);
        //imageFilledRectangle($img, 0, 0, $width, $height, imagecolorallocate($img, 255, 255, 255));
        ImageColorTransparent($img, imagecolorallocate($img, 255, 255, 255));
        imagegif($img);
        imagedestroy($img);
        exit;
    }
}
SimPHP::I()->boot(RC_SESSION);
if (isset($_GET['act'])) {
    $_action = trim($_GET['act']);
    switch ($_action) {
        case 'onload_stat':
            $vid = isset($_GET['vid']) ? intval($_GET['vid']) : 0;
            $onload_time = isset($_GET['t']) ? intval($_GET['t']) : 0;
            $params = array('onloadTime' => $onload_time);
            $vid = V($vid, $params, $_action);
            //show_jsonmsg(array('msg'=>'OK', 't'=>$onload_time));
            show_emptyimg();
            break;
        case 'retention_stat':
            $vid = isset($_GET['vid']) ? intval($_GET['vid']) : 0;
            $retention_time = isset($_GET['rt']) ? intval($_GET['rt']) : 0;
            $params = array('retentionTime' => $retention_time);
Esempio n. 9
0
<?php

/**
 * Verify Code Generating
 *
 * @author Gavin<*****@*****.**>
 */
//error_reporting(E_ALL);
//ini_set('display_errors', 'on');
//~ require init.php
require __DIR__ . '/core/init.php';
SimPHP::I(['modroot' => 'admins', 'sessnode' => 'adm'])->boot(RC_SESSION);
$_SESSION['verifycode'] = '';
function _getcolor($color)
{
    global $image;
    $color = preg_replace("/^#/", "", $color);
    $r = $color[0] . $color[1];
    $r = hexdec($r);
    $b = $color[2] . $color[3];
    $b = hexdec($b);
    $g = $color[4] . $color[5];
    $g = hexdec($g);
    $color = imagecolorallocate($image, $r, $b, $g);
    return $color;
}
function _setnoise()
{
    global $image, $width, $height, $back, $noisenum;
    for ($i = 0; $i < $noisenum; $i++) {
        $randColor = imageColorAllocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
Esempio n. 10
0
/**
 * import models of other module
 * 
 * usage:
 *   import('user/User_Model'); // just import User_Model class
 *   import('user/*');
 *   import('user/');
 *   import('user');
 * @param string $model_name
 * @param string $dir_prefix, dir prefix, no the trailing slash, default equal to SimPHP::$gConfig['modroot']
 * @return mixed(boolean or object)
 */
function import($model_name, $dir_prefix = '')
{
    if ('' == $model_name) {
        return FALSE;
    }
    // find class name and dir prefix
    $modroot = SimPHP::$gConfig['modroot'];
    if ('' != $dir_prefix) {
        $modroot = rtrim($dir_prefix, '/');
    }
    $moddir = SIMPHP_ROOT . DS . $modroot;
    $clsname = '';
    $tarr = explode('/', $model_name);
    $tarr[0] = strtolower($tarr[0]);
    //make sure dir is lower
    if (count($tarr) > 1) {
        $clsname = array_pop($tarr);
        //the last one is the checking one
        $moddir .= DS . implode(DS, $tarr);
    } else {
        //When import like Model::import('user');,equal to Model::import('user/*');
        $clsname = '';
        $moddir .= DS . $tarr[0];
    }
    if (!is_dir($moddir)) {
        return FALSE;
    }
    $is_import_dir = '*' == $clsname || '' == $clsname ? TRUE : FALSE;
    // Only import a class
    if (!$is_import_dir) {
        if (SimPHP::isClassLoaded($clsname)) {
            return TRUE;
        }
        $class_file = $moddir . '/' . $clsname . '.php';
        if (file_exists($class_file)) {
            include $class_file;
        }
        return SimPHP::isClassLoaded($clsname);
    }
    // Set class auto load
    SimPHP::registerAutoload(function ($className) use($moddir) {
        if (SimPHP::isClassLoaded($className)) {
            return TRUE;
        }
        $class_file = $moddir . '/' . $className . '.php';
        if (file_exists($class_file)) {
            include $class_file;
        }
        return SimPHP::isClassLoaded($className);
    });
    return TRUE;
}
Esempio n. 11
0
<?php

/**
 * Web端请求入口
 *
 * @author Gavin<*****@*****.**>
 */
//error_reporting(E_ALL);
//ini_set('display_errors', 'on');
//~ require init.php
require __DIR__ . '/core/init.php';
$request = new Request();
$response = new Response();
try {
    SimPHP::I()->boot(RC_ALL ^ RC_MEMCACHE)->dispatch($request, $response);
} catch (SimPHPException $me) {
    $response->dump($me->getMessage());
} catch (Exception $e) {
    $response->dump($e->getMessage());
}
/*----- END FILE: index.php -----*/
Esempio n. 12
0
 /**
  * Check q & menu pattern whether match
  * 
  * @param string $pattern
  * @param string $q
  * @return boolean
  */
 public static function qMatchPattern($pattern, $q = NULL)
 {
     if (!isset($q)) {
         $q = Request::q();
     }
     $match = false;
     if ($pattern == $q) {
         $match = true;
     } else {
         if (preg_match(SimPHP::genMenuRegexp($pattern), $q)) {
             $match = true;
         }
     }
     return $match;
 }
Esempio n. 13
0
<?php

/**
 * Verify Code Generating
 *
 * @author Gavin<*****@*****.**>
 */
//~ require init.php
require __DIR__ . '/core/init.php';
SimPHP::I(['modroot' => 'mobiles'])->boot(RC_SESSION);
$_SESSION['verifycode'] = '';
function _getcolor($color)
{
    global $image;
    $color = preg_replace("/^#/", "", $color);
    $r = $color[0] . $color[1];
    $r = hexdec($r);
    $b = $color[2] . $color[3];
    $b = hexdec($b);
    $g = $color[4] . $color[5];
    $g = hexdec($g);
    $color = imagecolorallocate($image, $r, $b, $g);
    return $color;
}
function _setnoise()
{
    global $image, $width, $height, $back, $noisenum;
    for ($i = 0; $i < $noisenum; $i++) {
        $randColor = imageColorAllocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
        imageSetPixel($image, rand(0, $width), rand(0, $height), $randColor);
    }