PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/include/shopPage.php

http://phpfor.googlecode.com/
PHP | 423 lines | 312 code | 63 blank | 48 comment | 70 complexity | 373d33710ecec412d056a288fd8ab0a0 MD5 | raw file
  1. <?php
  2. /**
  3. * pagefactory
  4. *
  5. * @package
  6. * @version $Id: shopPage.php 2049 2008-04-29 06:53:26Z flaboy $
  7. * @copyright 2003-2007 ShopEx
  8. * @author Wanglei <flaboy@zovatech.com>
  9. * @license Commercial
  10. */
  11. require_once('pageFactory.php');
  12. class shopPage extends pageFactory{
  13. var $noCache = false;
  14. var $_running = true;
  15. var $contentType = 'text/html;charset=utf-8';
  16. var $member;
  17. var $header='';
  18. var $keyWords=null;
  19. var $metaDesc=null;
  20. var $title=null;
  21. var $type=null;
  22. var $transaction_start = false;
  23. var $__tmpl=null;
  24. var $path = array();
  25. /**
  26. * pagefactory
  27. *
  28. * @access public
  29. * @return void
  30. */
  31. function shopPage(){
  32. parent::pageFactory();
  33. $this->system = &$GLOBALS['system'];
  34. $this->setError();
  35. $this->header.="<meta name=\"generator\" content=\"ShopEx ".$this->system->_app_version."\" />\n";
  36. /*
  37. $theme_id=$this->system->getConf('system.ui.current_theme');
  38. $this->header.="<meta name=\"TemplateID\" content=\"".$theme_id."\">";
  39. $o_theme=$this->system->loadModel('system/template');
  40. $them_info=$o_theme->getThemeInfo($theme_id);
  41. $this->header.="<meta name=\"TemplateName\" content=\"".$them_info['name']."\">";
  42. */
  43. if(constant('WITHOUT_STRIP_HTML')){
  44. $this->enable_strip_whitespace = false;
  45. }
  46. $this->system->controller = &$this;
  47. if(!$this->system->_base_link){
  48. if((!$this->system->getConf('system.seo.emuStatic') || $this->system->getConf('system.seo.emuStatic') == 'false')){
  49. $this->system->_base_link.=APP_ROOT_PHP.'?';
  50. }
  51. }
  52. //review ?setting?
  53. $this->_env_vars = array('base_url'=>$this->system->_base_link);
  54. }
  55. function error_jump($errMsg,$tpl='default.html'){
  56. $this->__tmpl = 'user:'.TPL_ID.'/'.$tpl.':exception/index';
  57. $this->title = "error";
  58. $this->pagedata['errormsg'] = $errMsg;
  59. $this->output();
  60. }
  61. function output(){
  62. // BEGIN ????????????? by yangbing 2010-9-2 20:12
  63. /*if($_COOKIE['SYNLOGIN'] == '1' && $_COOKIE['MEMBER'] && $_COOKIE['UNAME']){
  64. $member = explode('-',$_COOKIE['MEMBER']);
  65. $ucObj = $this->system->loadUcenter();
  66. $this->header.= $ucObj->login($member[0],$url);
  67. error_log(3,3,HOME_DIR.'/aaa.txt');
  68. $this->system->setCookie('SYNLOGIN','');
  69. }*/
  70. // END
  71. /* ????????????? */
  72. if($this->action['type']=='xml' || $this->action['type']=='json'){
  73. require(CORE_INCLUDE_DIR.'/shop/shop.front_api.php');
  74. shop_front_api($this,$this->action['type']);
  75. }
  76. if(($this->system->getConf('system.seo.emuStatic') || $this->system->getConf('system.seo.emuStatic') == 'true')){
  77. $this->pagedata['emuenable']= true;
  78. }
  79. $sitemap = &$this->system->loadModel('content/sitemap');
  80. if(!isset($this->type))$type = 'action';
  81. if(!isset($this->id))$this->id = array('action'=>$this->action['controller'].':'.urldecode($this->action['method']));
  82. if($this->title){
  83. if($this->path[count($this->path)-1]['title']!=$this->title && count($this->path)){
  84. $this->path[]=array('title'=>$this->title);
  85. }
  86. }
  87. if($this->cat_type){
  88. $GLOBALS['runtime']['path'] = array_merge($sitemap->getPath($this->type,$this->cat_type,$this->action['method']),$this->path);
  89. }else{
  90. $GLOBALS['runtime']['path'] = array_merge($sitemap->getPath($this->type,$this->id,$this->action['method']),$this->path);
  91. }
  92. // BEIGN ??current by yangbing 2010-9-12 16:24
  93. if($GLOBALS['runtime']['path']['cat_id']){
  94. $this->pagedata['current_cat_id'] = $GLOBALS['runtime']['path']['cat_id'];
  95. unset($GLOBALS['runtime']['path']['cat_id']);
  96. }else{
  97. $this->pagedata['current_cat_id'] = $this->id;
  98. }
  99. // END
  100. $this->pagedata['request'] = &$this->system->request;
  101. $this->pagedata['member'] = &$this->member;
  102. if(!$this->title){
  103. if($GLOBALS['runtime']['path']){
  104. array_shift($GLOBALS['runtime']['path']);
  105. $shopTitle = $GLOBALS['runtime']['path'];
  106. krsort($shopTitle);
  107. foreach($shopTitle as $tk => $tl){
  108. if ($tk==intval(count($shopTitle)-1))
  109. $this->title.=trim($tl['title'])." ";
  110. else
  111. $this->title.=trim($tl['title'])." ";
  112. }
  113. }
  114. }
  115. if($titleFormat = $this->system->getConf('site.title_format')){
  116. $this->pagedata['title'] = $this->system->sprintf($titleFormat,$this->title);
  117. }else{
  118. $this->pagedata['title'] = $this->title;
  119. }
  120. if(DEBUG_TEMPLETE){
  121. $o = &$this->system->loadModel('system/template');
  122. $theme=$this->system->getConf('system.ui.current_theme');
  123. $o->resetTheme($theme);
  124. }
  125. if(!$this->keywords){
  126. $this->keywords = $this->system->getConf('site.meta_key_words');
  127. }
  128. if(!$this->desc){
  129. $this->desc = $this->system->getConf('site.meta_desc');
  130. }
  131. $oTemplate=&$this->system->loadModel('system/template');
  132. $theme = $oTemplate->applyTheme(constant('TPL_ID'));
  133. $this->theme = $theme['theme'];
  134. if(is_array($theme['config'])){
  135. foreach($theme['config']['config'] as $c){
  136. if(isset($c['key']))$this->pagedata['theme'][$c['key']] = $c['value'];
  137. }
  138. }
  139. if(!isset($this->pagedata['_MAIN_']))$this->pagedata['_MAIN_'] = $this->action['controller'].'/'.$this->action['method'].'.html';//passport/index.html
  140. if($this->customer_template_type && $this->customer_template_id){
  141. $oTemplate=$this->system->loadModel('system/template');
  142. $tpl=$oTemplate->get_customer_template($this->customer_template_type,$this->customer_template_id,$this->customer_source_type);
  143. if($tpl){
  144. $this->__tmpl=$oTemplate->get_template_path($this->theme,$tpl);
  145. }
  146. }
  147. if(!$this->__tmpl){
  148. if($this->customer_template_type=='page' && $this->customer_template_id=='index'){
  149. $this->customer_template_type='index';
  150. }
  151. if(!$this->customer_template_type){
  152. $this->customer_template_type = $this->action['controller'];
  153. }
  154. $this->__tmpl=$this->system->getConf('system.custom_template_'.$this->customer_template_type)?$this->system->getConf('system.custom_template_'.$this->customer_template_type):$this->system->getConf('system.custom_template_default');
  155. if($this->customer_template_type == 'artlist')
  156. $this->__tmpl = $this->system->getConf('system.custom_template_article');
  157. if(!file_exists(THEME_DIR.'/'.$this->theme.'/'.$this->__tmpl)){
  158. unset($this->__tmpl);
  159. }
  160. }
  161. if(!isset($this->__tmpl)){
  162. $tmpl_file = $this->_get_view(TPL_ID,
  163. $ctl=$this->system->request['action']['controller']
  164. ,$act=$this->system->request['action']['method']);
  165. $this->__tmpl = 'user:'.$this->theme.'/'.$tmpl_file;
  166. }else if(!$tpl){
  167. $this->__tmpl = $this->template_exists(THEME_DIR.'/'.$this->theme.'/'.$this->__tmpl)?'user:'.$this->theme.'/'.$this->__tmpl:'shop:'.$this->__tmpl;
  168. }
  169. $this->system->_debugger['log'] = ob_get_contents();
  170. ob_clean();
  171. $output = $this->fetch($this->__tmpl,false);
  172. $GLOBALS['runtime']['theme_dir'] = $GLOBALS['runtime']['base_url'].'themes/'.$this->theme;
  173. if(preg_match_all('/\{([a-z][a-z0-9_]+)\}/i', $output, $matches)){
  174. $to_fetchv = null;
  175. $to_replace = null;
  176. foreach($matches[1] as $v){
  177. if(substr($v,0,4)=='ENV_'){
  178. $v = substr($v,4);
  179. if(array_key_exists($v, $GLOBALS['runtime'])){
  180. $to_replace['{ENV_'.$v.'}'] = $GLOBALS['runtime'][$v];
  181. }else{
  182. $to_replace['{ENV_'.$v.'}'] = '';
  183. }
  184. }else{
  185. $to_fetchv[] = $v;
  186. }
  187. }
  188. $magic_value = &$this->system->loadModel("system/magicvars");
  189. $magic_value->filter = null;
  190. foreach($magic_value->getList('var_name,var_value',array('var_name'=>$matches[0])) as $r){
  191. $to_replace[$r['var_name']] = $r['var_value'];
  192. }
  193. if($to_replace['{ENV_goods_cat}'] == ""){
  194. $output = str_replace('_{ENV_shopname}','{ENV_shopname}',$output);
  195. }
  196. $output = str_replace(array_keys($to_replace),array_values($to_replace),$output);
  197. $re = array('/(\\s+name=["\'][a-z0-9]+["\']\\s+content=\')(.*?)(\'>\\s*<meta)/is',
  198. '/(\<title\>)(.*?)(\<\/title\>)/s');
  199. $output =preg_replace_callback($re,array(&$this,'_fix_header'),$output);
  200. $this->system->apply_modifiers($output,'shop');
  201. echo $output;
  202. }else{
  203. echo $output;
  204. }
  205. }
  206. function _fix_header($match){
  207. return $match[1].htmlspecialchars(preg_replace('/\s+/s',' ',strip_tags($match[2]))).$match[3];
  208. }
  209. function splash($status='success',$jumpto=null,$msg=null,$links=array(),$wait=false,$js=null){
  210. if(!$msg)$msg = __("????");
  211. $this->system->_succ = true;
  212. $this->pagedata['_MAIN_'] = 'splash/'.$status.'.html';
  213. $this->pagedata['msg'] = $msg;
  214. $this->pagedata['jumpto'] = $jumpto;
  215. $this->pagedata['links'] = $links;
  216. $this->pagedata['js'] = $js;
  217. if($wait){
  218. $this->pagedata['wait'] = $wait;
  219. }elseif($status='success'){
  220. $this->pagedata['wait'] = 1;
  221. }else{
  222. $this->pagedata['wait'] = 10;
  223. }
  224. $this->pagedata['error_info'] = &$this->system->_err;
  225. header('Content-type: '.$this->contentType);
  226. $this->title = $status=='success'?__('????'):__('????');
  227. $this->output();
  228. exit;
  229. }
  230. function redirect($ctl=null,$act='index',$args=null,$jsJump=false){
  231. if(!$ctl)$ctl=$this->system->request['action']['controller'];
  232. $url = $this->system->mkUrl($ctl,$act,$args);
  233. $this->system->_succ=true;
  234. if($jsJump){
  235. echo "<header><meta http-equiv=\"refresh\" content=\"0; url={$url}\"></header>";
  236. }else{
  237. header('Location: '.$url);
  238. }
  239. exit();
  240. }
  241. /**
  242. * _verifyMember
  243. *
  244. * @param mixed $required ??????????????????
  245. * @access protected
  246. * @return void
  247. */
  248. function _verifyMember($member_id=true){
  249. if($_COOKIE['MEMBER']){ //??????????Cookie??????editor:Ever 2008-07-03
  250. $member = explode('-',$_COOKIE['MEMBER']);
  251. }else{
  252. $member = array(0);
  253. }
  254. $memberObj = &$this->system->loadModel('member/account');
  255. $memberInfo = $memberObj->verify($member[0],$member[2]);
  256. if($member_id!==false && (!$member[0] || !$memberInfo)){
  257. $this->system->setCookie('MEMBER', '', time()-1000);
  258. $this->system->setCookie('MLV', '', time()-1000);
  259. $this->system->setCookie('UNAME', '', time()-1000);
  260. $this->system->_succ = true;
  261. $this->system->location($this->system->mkUrl('passport','login',array(base64_encode(str_replace(array('+','/','='),array('_',',','~'),$this->system->mkUrl($this->system->request['action']['controller'],$this->system->request['action']['method'],$this->system->request['action']['args']))))));
  262. }else{
  263. $this->member = &$memberInfo;
  264. if($member_id!==true && $memberInfo['member_id']!=$member_id && is_numeric($member_id)){
  265. $this->system->error(404);
  266. return false;
  267. }
  268. $GLOBALS['runtime']['member_lv']=$this->member['member_lv_id'];
  269. }
  270. }
  271. function _get_view($theme,$ctl,$act='index'){
  272. if($ctl=='page' && $act=='index'){
  273. if(file_exists(THEME_DIR.'/'.$theme.'/index.html')){
  274. return 'index.html';
  275. }else{
  276. if($cust_defalut = $this->system->getConf('system.custom_template_default'))return $cust_defalut;
  277. else return 'default.html' ;
  278. }
  279. }
  280. if(file_exists(THEME_DIR.'/'.$theme.'/'.$ctl.'-'.$act.'.html')){
  281. return $ctl.'-'.$act.'.html';
  282. }elseif(file_exists(THEME_DIR.'/'.$theme.'/'.$ctl.'.html')){
  283. return $ctl.'.html';
  284. }else{
  285. if($cust_defalut = $this->system->getConf('system.custom_template_default'))return $cust_defalut;
  286. else return 'default.html' ;
  287. }
  288. }
  289. function setError($errorno=0,$jumpto='back',$msg='',$links=array(),$time=3,$js=null){
  290. $this->system->ErrorSet = array('errorno'=>$errorno,'message'=>$msg,'jumpto'=>$jumpto,'links'=>$links,'time'=>$time,'js'=>$js);
  291. }
  292. function begin($url=null,$errAction=null,$shutHandle=null){
  293. set_error_handler(array(&$this,'_errorHandler'));
  294. if($this->transaction_start) trigger_error('The transaction has been started',E_USER_ERROR);
  295. if(!$url)trigger_error('The transaction has been started',E_USER_ERROR);
  296. $this->transaction_start = true;
  297. $this->_shutHandle = $shutHandle?$shutHandle:(E_USER_ERROR | E_ERROR);
  298. $this->_action_url = $url;
  299. $this->_errAction = $errAction;
  300. $this->_err = array();
  301. }
  302. function end($result=true,$message=null,$url=null,$showNotice=false){
  303. if(!$this->transaction_start) trigger_error('The transaction has not started yet',E_USER_ERROR);
  304. $this->transaction_start = false;
  305. restore_error_handler();
  306. if(is_null($url)){
  307. $url = $this->_action_url;
  308. }
  309. $this->splash($result?'success':'failed',$url,$result?$message:($message?$message:__('????')),$showNotice?$this->_err:null);
  310. }
  311. function end_only(){
  312. if(!$this->transaction_start) trigger_error('The transaction has not started yet',E_USER_ERROR);
  313. $this->transaction_start = false;
  314. restore_error_handler();
  315. }
  316. function _errorHandler($errno, $errstr, $errfile, $errline){
  317. $errorlevels = array(
  318. 2048 => 'Warning',
  319. 2048 => 'Notice',
  320. 1024 => 'Warning',
  321. 1024 => 'Notice',
  322. 512 => 'Warning',
  323. 256 => 'Error',
  324. 128 => 'Warning',
  325. 64 => 'Error',
  326. 32 => 'Warning',
  327. 16 => 'Error',
  328. 8 => 'Notice',
  329. 4 => 'Error',
  330. 2 => 'Warning',
  331. 1 => 'Error');
  332. $this->_err[] = array('code'=>$errno, 'string'=>$errstr, 'file'=>$errfile, 'line'=>$errline,'codeinfo'=>$errorlevels[$errno]);
  333. if(isset($this->system->ErrorSet['errorno']) && isset($this->_errAction[$this->system->ErrorSet['errorno']])){
  334. $this->splash('failed',$this->_errAction[$this->system->ErrorSet['errorno']],$errstr);
  335. }else{
  336. switch($errno){
  337. /* case $errno & ( E_NOTICE | E_USER_NOTICE | E_WARNING):
  338. break;*/
  339. case $errno & ( $this->_shutHandle ):
  340. restore_error_handler();
  341. $this->splash('failed',$this->_action_url,$errstr,$this->_err);
  342. /*default:
  343. restore_error_handler();
  344. $this->splash('failed',$this->_action_url,$errstr,$this->_err);*/
  345. }
  346. }
  347. return true;
  348. }
  349. function get_shopname(){
  350. return $this->system->getConf('system.shopname');
  351. }
  352. function getGlobal($seo,&$result,$list=0){
  353. foreach($seo as $val){
  354. $funcName="get_".$val;
  355. $GLOBALS['runtime'][$val]=$this->$funcName($result,$list);
  356. }
  357. }
  358. }
  359. ?>