function HTMLTemplate($name, $replace, $with)
 {
     $loc = $this->templateKey[$name];
     $webRoot = getWebRoot();
     if (getType($replace) == getType($with) && getType($replace) == "array" && count($replace) > 0) {
         if (count($replace) == count($with)) {
             array_unshift($replace, "{webRoot}");
             array_unshift($with, $webRoot);
         } else {
             echo "error: Replace and With arrays are of different lengths.";
         }
     } else {
         $replace = array('{webRoot}');
         $with = array($webRoot);
     }
     if (isset($loc)) {
         $html = file_get_contents($loc);
         if ($html) {
             if ($replace && $with) {
                 $htmlWithVars = str_replace($replace, $with, $html);
             } else {
                 $htmlWithVars = $html;
             }
             echo $htmlWithVars;
         }
     } else {
         // echo header("Location:error.php?num=2");
         echo "error: Missing HTML template of {$name}";
     }
 }
Exemple #2
0
 /**
  * Construct function.
  * 
  * @access public
  * @return void
  */
 public function __construct()
 {
     if (!defined('IN_INSTALL')) {
         die;
     }
     parent::__construct();
     $this->app->loadLang('user');
     $this->app->loadLang('admin');
     $this->config->webRoot = getWebRoot();
 }
Exemple #3
0
 /**
  * Visual index
  *
  * @access public
  * @return void
  */
 public function index($referer = '')
 {
     $template = $this->config->template->{$this->device}->name;
     $this->loadModel('block')->loadTemplateLang($template);
     $this->view->referer = helper::safe64decode($referer);
     $this->view->title = $this->lang->visual->common;
     $this->view->blocks = $this->lang->block->{$template};
     if ($referer == '') {
         $this->view->referer = getWebRoot();
     }
     $this->display();
 }
Exemple #4
0
 /**
  * SSO login.
  * 
  * @param  string $type 
  * @access public
  * @return void
  */
 public function login($type = 'notify')
 {
     $referer = empty($_GET['referer']) ? '' : $this->get->referer;
     $locate = empty($referer) ? getWebRoot() : base64_decode($referer);
     if ($this->loadModel('user')->isLogon()) {
         die($this->locate($locate));
     }
     $this->app->loadConfig('sso');
     if (!$this->config->sso->turnon) {
         die($this->locate($locate));
     }
     $userIP = $this->server->remote_addr;
     $code = $this->config->sso->code;
     $key = $this->config->sso->key;
     if ($type != 'return') {
         $token = $this->get->token;
         $auth = md5($code . $userIP . $token . $key);
         $callback = urlencode(common::getSysURL() . inlink('login', "type=return"));
         $location = $this->config->sso->addr;
         if (strpos($location, '&') !== false) {
             $location = rtrim($location, '&') . "&token={$token}&auth={$auth}&userIP={$userIP}&callback={$callback}&referer={$referer}";
         } else {
             $location = rtrim($location, '?') . "?token={$token}&auth={$auth}&userIP={$userIP}&callback={$callback}&referer={$referer}";
         }
         $this->locate($location);
     }
     if ($this->get->status == 'success' and md5($this->get->data) == $this->get->md5) {
         $last = $this->server->request_time;
         $data = json_decode(base64_decode($this->get->data));
         $token = $data->token;
         if ($data->auth == md5($code . $userIP . $token . $key)) {
             $user = $this->sso->getBindUser($data->account);
             if (!$user) {
                 $this->session->set('ssoData', $data);
                 $this->locate($this->createLink('sso', 'bind', "referer=" . helper::safe64Encode($locate)));
             }
             $this->user->cleanLocked($user->account);
             /* Authorize him and save to session. */
             $user->rights = $this->user->authorize($user->account);
             $user->groups = $this->user->getGroups($user->account);
             $this->dao->update(TABLE_USER)->set('visits = visits + 1')->set('ip')->eq($userIP)->set('last')->eq($last)->where('account')->eq($user->account)->exec();
             $user->last = date(DT_DATETIME1, $last);
             $this->session->set('user', $user);
             $this->app->user = $this->session->user;
             $this->loadModel('action')->create('user', $user->id, 'login');
             die($this->locate($locate));
         }
     }
     $this->locate($this->createLink('user', 'login', empty($referer) ? '' : "referer={$referer}"));
 }
Exemple #5
0
 /**
  * Create a alipay link. 
  * 
  * @param  string    $orderNO 
  * @access public
  * @return string
  */
 public function createAlipayLink($order)
 {
     $this->app->loadClass('alipay', true);
     $this->config->alipay->notifyURL = getWebRoot(true) . ltrim(inlink('processorder', "type=alipay&mode=notify"), '/');
     $this->config->alipay->returnURL = getWebRoot(true) . ltrim(inlink('processorder', "type=alipay&mode=return"), '/');
     $alipay = new alipay($this->config->alipay);
     $subject = sprintf($this->lang->order->payInfo, $this->config->site->name, date('Y-m-d'));
     return $alipay->createPayLink($this->getHumanOrder($order->id), $subject, $order->amount);
 }
Exemple #6
0
?>
</description>
  <copyright><?php 
echo $config->company->name . $config->site->copyright . '-' . date('Y');
?>
</copyright>
  <lastBuildDate><?php 
echo $lastDate;
?>
</lastBuildDate>
  
  <?php 
foreach ($articles as $article) {
    $category = current($article->categories);
    $article->content = str_replace('src="/data/upload/', 'src="' . getWebRoot(true) . 'data/upload/', $article->content);
    $article->content = str_replace("src='/data/upload/", "src='" . getWebRoot(true) . 'data/upload/', $article->content);
    ?>
  <item>
    <title><?php 
    echo $article->title;
    ?>
</title>
    <description><![CDATA[  <?php 
    echo $article->content;
    ?>
]]></description>
    <link><?php 
    echo str_replace('&', '&amp;', $siteLink . $this->createLink('blog', 'view', "id={$article->id}", "category={$category->alias}&name={$article->alias}", 'html'));
    ?>
</link>
    <category><?php 
Exemple #7
0
 /**
  * Parse products. 
  * 
  * @param  object    $content 
  * @access public
  * @return object
  */
 public function parseProducts($content)
 {
     $orderByList = array('latestProduct' => 'id_desc', 'hotProduct' => 'views_desc');
     $this->app->loadClass('pager', true);
     $pager = new pager($recTotal = 0, $recPerPage = $content->limit, 1);
     $products = $this->loadModel('product')->getList($content->category, $orderByList[$content->block], $pager);
     $response = new stdclass();
     $response->msgType = 'news';
     foreach ($products as $product) {
         $categories = $product->categories;
         $categoryAlias = current($categories)->alias;
         $article = new stdclass();
         $article->title = $product->name;
         $article->url = getHostURL() . commonModel::createFrontLink('product', 'view', "productID={$product->id}", "name={$product->alias}&category={$categoryAlias}");
         $article->description = isset($product->summary) ? $product->summary : '';
         if (!empty($product->image)) {
             $article->picUrl = rtrim(getWebRoot(true), '/') . $product->image->primary->smallURL;
         }
         $response->articles[] = $article;
     }
     return $response;
 }
Exemple #8
0
    }
}
if (!function_exists('getWebRoot')) {
    function getWebRoot()
    {
    }
}
/* The basic settings. */
$config = new config();
$config->version = '4.3.beta';
// The version number, don't change.
$config->encoding = 'UTF-8';
// The encoding.
$config->cookiePath = '/';
// The path of cookies.
$config->webRoot = getWebRoot();
// The web root.
$config->cookieLife = time() + 2592000;
// The lifetime of cookies.
$config->timezone = 'Asia/Shanghai';
// Time zone setting, more plese visit http://www.php.net/manual/en/timezones.php
$config->multi = false;
// The config of multi site.
/* The request settins. */
$config->requestType = 'PATH_INFO';
// PATH_INFO or GET.
$config->seoMode = true;
// Whether turn on seo mode or not.
$config->requestFix = '-';
// RequestType=PATH_INFO: the divider of the params, can be - _ or /
$config->moduleVar = 'm';
Exemple #9
0
 /**
  * Create a alipay link. 
  * 
  * @param  object $order
  * @access public
  * @return string
  */
 public function createAlipayLink($order, $type = '')
 {
     $this->app->loadClass('alipay', true);
     $alipayConfig = $order->payment == 'alipay' ? $this->config->alipay->direct : $this->config->alipay->secured;
     /* Create right link that module is not order in order-browse page, such as score. */
     $notifyURL = empty($type) ? inlink('processorder', "type=alipay&mode=notify") : helper::createLink($type, 'processorder', "type=alipay&mode=notify");
     $returnURL = empty($type) ? inlink('processorder', "type=alipay&mode=return") : helper::createLink($type, 'processorder', "type=alipay&mode=return");
     $alipayConfig->notifyURL = getWebRoot(true) . ltrim($notifyURL, '/');
     $alipayConfig->returnURL = getWebRoot(true) . ltrim($returnURL, '/');
     $alipayConfig->pid = $this->config->alipay->pid;
     $alipayConfig->key = $this->config->alipay->key;
     $alipayConfig->email = $this->config->alipay->email;
     $alipay = new alipay($alipayConfig);
     $subject = sprintf($this->lang->order->payInfo, $this->config->site->name, date('Y-m-d'));
     return $alipay->createPayLink($this->getHumanOrder($order->id), $subject, $order->amount);
 }
Exemple #10
0
 /**
  * Create a link to a module's method.
  * 
  * This method also mapped in control class to call conveniently.
  * <code>
  * <?php
  * helper::createLink('hello', 'index', 'var1=value1&var2=value2');
  * helper::createLink('hello', 'index', array('var1' => 'value1', 'var2' => 'value2');
  * ?>
  * </code>
  * @param string       $moduleName     module name
  * @param string       $methodName     method name
  * @param string|array $vars           the params passed to the method, can be array('key' => 'value') or key1=value1&key2=value2) or key1=value1&key2=value2
  * @param string|array $alias          the alias  params passed to the method, can be array('key' => 'value') or key1=value1&key2=value2) or key1=value1&key2=value2
  * @param string       $viewType       the view type
  * @static
  * @access public
  * @return string the link string.
  */
 public static function createLink($moduleName, $methodName = 'index', $vars = '', $alias = array(), $viewType = '')
 {
     global $app, $config;
     $requestType = $config->requestType;
     if (defined('FIX_PATH_INFO2') and FIX_PATH_INFO2) {
         $config->requestType = 'PATH_INFO2';
     }
     $clientLang = $app->getClientLang();
     $lang = $config->langCode;
     /* Set viewType is mhtml if visit with mobile.*/
     if (!$viewType and RUN_MODE == 'front' and helper::getDevice() == 'mobile' and $methodName != 'oauthCallback') {
         $viewType = 'mhtml';
     }
     /* Set vars and alias. */
     if (!is_array($vars)) {
         parse_str($vars, $vars);
     }
     if (!is_array($alias)) {
         parse_str($alias, $alias);
     }
     foreach ($alias as $key => $value) {
         $alias[$key] = urlencode($value);
     }
     /* Seo modules return directly. */
     if (helper::inSeoMode() and method_exists('uri', 'create' . $moduleName . $methodName)) {
         if ($config->requestType == 'PATH_INFO2') {
             $config->webRoot = $_SERVER['SCRIPT_NAME'] . '/';
         }
         $link = call_user_func_array('uri::create' . $moduleName . $methodName, array('param' => $vars, 'alias' => $alias, 'viewType' => $viewType));
         /* Add client lang. */
         if ($lang and $link) {
             $link = $config->webRoot . $lang . '/' . substr($link, strlen($config->webRoot));
         }
         if ($config->requestType == 'PATH_INFO2') {
             $config->webRoot = getWebRoot();
         }
         $config->requestType = $requestType;
         if ($link) {
             return $link;
         }
     }
     /* Set the view type. */
     if (empty($viewType)) {
         $viewType = $app->getViewType();
     }
     if ($config->requestType == 'PATH_INFO') {
         $link = $config->webRoot;
     }
     if ($config->requestType == 'PATH_INFO2') {
         $link = $_SERVER['SCRIPT_NAME'] . '/';
     }
     if ($config->requestType == 'GET') {
         $link = $_SERVER['SCRIPT_NAME'];
     }
     if ($config->requestType != 'GET' and $lang) {
         $link .= "{$lang}/";
     }
     /* Common method. */
     if (helper::inSeoMode()) {
         /* If the method equal the default method defined in the config file and the vars is empty, convert the link. */
         if ($methodName == $config->default->method and empty($vars)) {
             /* If the module also equal the default module, change index-index to index.html. */
             if ($moduleName == $config->default->module) {
                 $link .= 'index.' . $viewType;
             } elseif ($viewType == $app->getViewType()) {
                 $link .= $moduleName . '/';
             } else {
                 $link .= $moduleName . '.' . $viewType;
             }
         } else {
             $link .= "{$moduleName}{$config->requestFix}{$methodName}";
             foreach ($vars as $value) {
                 $link .= "{$config->requestFix}{$value}";
             }
             $link .= '.' . $viewType;
         }
     } else {
         $link .= "?{$config->moduleVar}={$moduleName}&{$config->methodVar}={$methodName}";
         if ($viewType != 'html') {
             $link .= "&{$config->viewVar}=" . $viewType;
         }
         foreach ($vars as $key => $value) {
             $link .= "&{$key}={$value}";
         }
         if ($lang and RUN_MODE != 'admin') {
             $link .= "&l={$lang}";
         }
     }
     $config->requestType = $requestType;
     return $link;
 }
Exemple #11
0
 /**
  * Check domain and header 301.
  * 
  * @access public
  * @return void
  */
 public function checkDomain()
 {
     if (RUN_MODE == 'install' or RUN_MODE == 'upgrade' or RUN_MODE == 'shell' or RUN_MODE == 'admin' or !$this->config->installed) {
         return true;
     }
     $domains = isset($this->config->site->allowedDomain) ? $this->config->site->allowedDomain : '';
     $domains = str_replace(array('http://', 'https://'), '', $domains);
     $mainDomain = isset($this->config->site->domain) ? $this->config->site->domain : '';
     $mainDomain = str_replace(array('http://', 'https://'), '', $mainDomain);
     $host = $this->server->http_host;
     /* Check domain is allowed. */
     if (!empty($domains)) {
         $allowed = false;
         $domains = explode(',', str_replace(',', ',', $domains));
         $domains[] = $mainDomain;
         foreach ($domains as $domain) {
             if (empty($domain)) {
                 continue;
             }
             if (strpos($host, $domain) !== false and substr($host, strpos($host, $domain)) == $domain) {
                 $allowed = true;
                 break;
             }
         }
         if (!$allowed) {
             die('domain denied.');
         }
     }
     /* Check main domain. */
     $redirect = false;
     $redirectURI = getWebRoot(true) . $this->app->getURI();
     if ($mainDomain and $mainDomain != $host) {
         $redirect = true;
         $redirectURI = str_replace($host, $mainDomain, $redirectURI);
     }
     /* Check scheme. */
     $scheme = isset($this->config->site->scheme) ? $this->config->site->scheme : 'http';
     if (strpos($redirectURI, $scheme . '://') !== 0) {
         $redirect = true;
         $redirectURI = $scheme . substr($redirectURI, strpos($redirectURI, '://'));
     }
     if ($redirect) {
         header301($redirectURI);
     }
 }
Exemple #12
0
 /**
  * Create thread view.
  *
  * @params array    $params
  * @params array    $alias  
  * @params string   $viewType  
  * return string
  */
 public static function createThreadView($params, $alias, $viewType = '')
 {
     global $config;
     $viewType = $viewType ? $viewType : $config->default->view;
     $link = 'thread/' . array_shift($params);
     if (isset($alias['pageID'])) {
         $link .= '/p' . $alias['pageID'];
     }
     $link .= '.' . $viewType;
     if (isset($alias['replyID'])) {
         $link .= '#' . $alias['replyID'];
     }
     return getWebRoot(true) . $link;
 }
Exemple #13
0
 /**
  * Get modeulList.
  * 
  * @access public
  * @return void
  */
 public function getModuleList()
 {
     $webRoot = rtrim(getWebRoot(true), '/');
     foreach ($this->lang->wechat->response->moduleList as $module => $title) {
         if ($module != 'manual') {
             $moduleList[$webRoot . $this->loadModel('common')->createFrontLink($module, 'index')] = $title;
         }
         if ($module == 'manual') {
             $moduleList[$module] = $title;
         }
     }
     return $moduleList;
 }
 /**
  * Check domain and header 301.
  * 
  * @access public
  * @return void
  */
 public function checkDomain()
 {
     if (RUN_MODE == 'install' or RUN_MODE == 'upgrade' or RUN_MODE == 'shell' or RUN_MODE == 'admin' or !$this->config->installed) {
         return true;
     }
     $httpHost = $this->server->http_host;
     $currentURI = getWebRoot(true) . $this->app->getURI();
     $scheme = isset($this->config->site->scheme) ? $this->config->site->scheme : 'http';
     $mainDomain = isset($this->config->site->domain) ? $this->config->site->domain : '';
     $mainDomain = str_replace(array('http://', 'https://'), '', $mainDomain);
     /* Check main domain and scheme. */
     $redirectURI = $currentURI;
     if (strpos($redirectURI, $scheme . '://') !== 0) {
         $redirectURI = $scheme . substr($redirectURI, strpos($redirectURI, '://'));
     }
     if (!empty($mainDomain) and $httpHost != $mainDomain) {
         $redirectURI = str_replace($httpHost, $mainDomain, $redirectURI);
     }
     if ($redirectURI != $currentURI) {
         header301($redirectURI);
     }
     /* Check domain is allowed. */
     $allowedDomains = isset($this->config->site->allowedDomain) ? $this->config->site->allowedDomain : '';
     $allowedDomains = str_replace(array('http://', 'https://'), '', $allowedDomains);
     if (!empty($allowedDomains)) {
         if (strpos($allowedDomains, $httpHost) !== false) {
             return true;
         }
         if (!empty($mainDomain) and hepler::getSiteCode($httpHost) == hepler::getSiteCode($mainDomain)) {
             return true;
         }
         die('domain denied.');
     }
 }
#!/usr/bin/env php
<?php 
<<<TC
title: testing the getWebRoot method.
TC;
/* Include the helper class. */
include '../../helper.class.php';
/* Create two objects named obj and obj2. */
$_SERVER['SCRIPT_NAME'] = '/index.php';
$webRoot = getWebRoot();
echo $webRoot . "\n";
$_SERVER['SCRIPT_NAME'] = '/zentao/index.php';
$webRoot = getWebRoot();
echo $webRoot . "\n";