PageRenderTime 59ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/libraries/cache.class.php

https://github.com/sahilbabu/phpb2b
PHP | 701 lines | 636 code | 10 blank | 55 comment | 48 complexity | c2155b7813b1c97eb2685a3c67631062 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
  4. * The contents of this file are subject to the License; you may not use this file except in compliance with the License.
  5. *
  6. * @version $Revision: 2075 $
  7. */
  8. if( !function_exists('json_encode') ) {
  9. require(PHPB2B_ROOT. "libraries/json_config.php");
  10. }
  11. class Caches extends PbObject {
  12. var $cache_name = null;
  13. var $lang_dirname = null;
  14. var $cache_path = null;
  15. function Caches($cache_name = null)
  16. {
  17. // if (!empty($this->lang_dirname)) {
  18. // $this->cache_path = PHPB2B_ROOT."data".DS."cache".DS.$this->lang_dirname.DS;
  19. // }else{
  20. $this->cache_path = CACHE_PATH;
  21. // }
  22. if (!empty($cache_name)) {
  23. $this->cache_name = $cache_name;
  24. }
  25. }
  26. function updateSettings() {
  27. global $_PB_CACHE;
  28. if(isset($_PB_CACHE['setting']) && is_array($_PB_CACHE['setting'])) {
  29. writeCache('setting', '', '$_PB_CACHE[\'setting\'] = '.evalArray($_PB_CACHE['setting']).";\n\n");
  30. }
  31. }
  32. function updateIndexCache()
  33. {
  34. global $pdb, $tb_prefix;
  35. $pdb->setFetchMode(ADODB_FETCH_ASSOC);
  36. $letters = range('a', 'z');
  37. $return = array();
  38. foreach ($letters as $val) {
  39. $tmp_arr = $pdb->GetArray("SELECT id,name,picture FROM ".$tb_prefix."brands WHERE letter='".$val."' ORDER BY id DESC LIMIT 0,7");
  40. if (!empty($tmp_arr)) {
  41. $return[$val] = $tmp_arr;
  42. }
  43. }
  44. $data = "\$_PB_CACHE['brand'] = ".$this->evalArray($return);
  45. return $this->writeCache("brand", null, $data);
  46. }
  47. function updateTypes($cache_name = '', $extra_data = '')
  48. {
  49. global $pdb, $tb_prefix;
  50. $datas = $tmp_arr = array();
  51. $cache_data = null;
  52. $cache_types = array("announcementtype", "areatype", "companytype", "expotype", "friendlinktype", "industrytype", "markettype", "membertype", "newstype", "tradetype", "productsort", "companynewstype", "albumtype","standardtype","dicttype","helptype","markettype","goodtype");
  53. foreach ($cache_types as $table) {
  54. $extra_col = ",name";
  55. if ($table=="helptype") {
  56. $extra_col = ",title AS name";
  57. }
  58. $tmp_arr = $pdb->GetArray("SELECT id".$extra_col." FROM ".$tb_prefix.$table."s");
  59. if (!empty($tmp_arr)) {
  60. foreach ($tmp_arr as $key=>$val) {
  61. $datas[$val['id']] = $val['name'];
  62. }
  63. if ($table=="tradetype") {
  64. $table = "offertype";
  65. }
  66. $cache_data.= "\$_PB_CACHE['".$table."'] = ".$this->evalArray($datas).";\n";
  67. unset($datas, $tmp_arr);
  68. }
  69. }
  70. $cache_data.= "\$_PB_CACHE = array_map_recursive('pb_lang_split', \$_PB_CACHE);\n\n";
  71. return $this->writeCache('type', '', $cache_data);
  72. }
  73. function updateTypevars()
  74. {
  75. global $pdb, $tb_prefix;
  76. $cur_data = $type_js_data = null;
  77. $sql = "SELECT id,type_name FROM {$tb_prefix}typemodels tm";
  78. $Typemodels = $pdb->GetArray($sql);
  79. $type_js_data = "<!--// Created ".date("M j, Y, G:i")." \n";
  80. if (!empty($Typemodels)) {
  81. foreach ($Typemodels as $key=>$val) {
  82. $data = array();
  83. $tmp_js_option = null;
  84. $tmp_options = $pdb->GetArray("SELECT option_value,option_label FROM {$tb_prefix}typeoptions WHERE typemodel_id=".$val['id']." ORDER BY id ASC");
  85. $type_js_data.="var ".$val['type_name']." = [";
  86. if (!empty($tmp_options)) {
  87. foreach ($tmp_options as $option_key=>$option_val) {
  88. $tmp_js_option[] = "['".$option_val['option_label']."','".$option_val['option_value']."']";
  89. $data[$option_val['option_value']] = $option_val['option_label'];
  90. }
  91. }
  92. $tmp_js = implode(",", $tmp_js_option);
  93. $type_js_data.=$tmp_js."];\n";
  94. $cachename = $val['type_name'];
  95. $cur_data.= "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n";
  96. }
  97. $cur_data.= "\$_PB_CACHE = array_map_recursive('pb_lang_split', \$_PB_CACHE);\n\n";
  98. $this->writeCache('typeoption', '', $cur_data);
  99. $type_js_data.="//-->";
  100. if (!class_exists("JSMinException")) {
  101. include_once(LIB_PATH. "jsmin.class.php");
  102. }
  103. file_put_contents($this->cache_path. "type.js", $type_js_data);
  104. $jsMin = new JSMin(file_get_contents($this->cache_path. "type.js"), false);
  105. $out = $jsMin->minify();
  106. return file_put_contents($this->cache_path. "type.js", $out);
  107. }
  108. $false = false;
  109. return $false;
  110. }
  111. function evalArray($array, $level = 0) {
  112. if(!is_array($array)) {
  113. return "'".$array."'";
  114. }
  115. if(is_array($array) && function_exists('var_export')) {
  116. return var_export($array, true);
  117. }
  118. $space = '';
  119. for($i = 0; $i <= $level; $i++) {
  120. $space .= "\t";
  121. }
  122. $evaluate = "Array\n$space(\n";
  123. $comma = $space;
  124. if(is_array($array)) {
  125. foreach($array as $key => $val) {
  126. $key = is_string($key) ? '\''.addcslashes($key, '\'\\').'\'' : $key;
  127. $val = !is_array($val) && (!preg_match("/^\-?[1-9]\d*$/", $val) || strlen($val) > 12) ? '\''.addcslashes($val, '\'\\').'\'' : $val;
  128. if(is_array($val)) {
  129. $evaluate .= "$comma$key => ".evalArray($val, $level + 1);
  130. } else {
  131. $evaluate .= "$comma$key => $val";
  132. }
  133. $comma = ",\n$space";
  134. }
  135. }
  136. $evaluate .= "\n$space)";
  137. return $evaluate;
  138. }
  139. function writeCache($script, $cachenames = '', $cachedata = '', $prefix = 'cache_') {
  140. global $phpb2b_auth_key;
  141. $fpc = true;
  142. // if (!empty($this->lang_dirname)) {
  143. // $app_lang = $this->lang_dirname;
  144. // }
  145. //after 4.3, this is not mustable.
  146. // else {
  147. // $app_lang = $this->lang_dirname = $GLOBALS['app_lang'];
  148. // }
  149. $mod_label = "Created";
  150. if (!empty($cachenames)) {
  151. if(is_array($cachenames) && !$cachedata) {
  152. foreach($cachenames as $name) {
  153. $cachedata .= $this->getCacheArray($name, $script);
  154. }
  155. }else{
  156. $cachedata.= $this->getCacheArray($cachenames);
  157. }
  158. }
  159. if(!empty($cachedata)){
  160. if(!empty($this->lang_dirname))
  161. $dir = PHPB2B_ROOT.'data'.DS.'cache'.DS.$this->lang_dirname.DS;
  162. else
  163. $dir = PHPB2B_ROOT.'data'.DS.'cache'.DS;
  164. if(!is_dir($dir)) {
  165. pb_create_folder($dir);
  166. }
  167. $file_name = $dir.$prefix.$script.".php";
  168. if(file_exists($file_name)) {
  169. $mod_label = "Modified";
  170. }
  171. $fpc = file_put_contents($file_name, "<?php\n/**\n * PHPB2B cache file, DO NOT change me!".
  172. "\n * {$mod_label}: ".date("M j, Y, G:i").
  173. "\n * Id: ".md5($prefix.$script.'.php'.$cachedata.$phpb2b_auth_key)."\n */\n\n$cachedata\n?>");
  174. }
  175. if(!$fpc) {
  176. exit(L("write_file_error_and_retry"));
  177. }else{
  178. return true;
  179. }
  180. }
  181. function getCacheArray($cachename = '', $script = '') {
  182. global $pdb, $tb_prefix;
  183. $conditions = $curdata = '';
  184. $data = array();
  185. if (empty($cachename) && !empty($this->cache_name)) {
  186. $cachename = $this->cache_name;
  187. }
  188. switch($cachename) {
  189. case 'nav':
  190. $this->lang_dirname = '';
  191. $navs = $pdb->GetArray("SELECT id,name,description,url,target,display_order,highlight FROM {$tb_prefix}navs WHERE status=1 ORDER BY display_order ASC");
  192. $navmns = $_nlink = array();
  193. if (!empty($navs)) {
  194. foreach ($navs as $nav=>$nav_val) {
  195. $lang_title = $nav_val['name'];
  196. $_tmp = pb_lang_split($lang_title, true);
  197. foreach ($_tmp as $_nk=>$_nv) {
  198. $_nlink[$_nk] = '<a href="'.$nav_val['url'].'" title="'.$_nv.'"'.parse_highlight($nav_val['highlight']).'"><span>'.$_nv.'</span></a>';
  199. }
  200. $navmns[$nav_val['id']]['link'] = pb_lang_merge($_nlink);
  201. $navmns[$nav_val['id']]['id'] = $nav_val['id'];
  202. $navmns[$nav_val['id']]['name'] = $lang_title;
  203. $navmns[$nav_val['id']]['url'] = $nav_val['url'];
  204. $navmns[$nav_val['id']]['level'] = $nav_val['display_order'];
  205. }
  206. $data['navs'] = $navmns;
  207. }
  208. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n\n";
  209. break;
  210. case 'trusttype':
  211. $this->lang_dirname = '';
  212. $pdb->setFetchMode(ADODB_FETCH_ASSOC);
  213. $conditions = "";
  214. $sql = "SELECT * FROM {$tb_prefix}trusttypes ORDER BY display_order ASC,id DESC";
  215. $result = $pdb->GetArray($sql);
  216. foreach ($result as $key=>$val) {
  217. $result[$key]['avatar'] = $val['image'];
  218. unset($result[$key]['description'], $result[$key]['display_order'], $result[$key]['status'], $result[$key]['image']);
  219. $data[$val['id']] = $result[$key];
  220. }
  221. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n\n";
  222. break;
  223. case 'country':
  224. $this->lang_dirname = '';
  225. $pdb->setFetchMode(ADODB_FETCH_ASSOC);
  226. $conditions = "";
  227. $sql = "SELECT * FROM {$tb_prefix}countries ORDER BY display_order ASC,id ASC";
  228. $result = $pdb->GetArray($sql);
  229. foreach ($result as $key=>$val) {
  230. $result[$key]['image'] = $val['picture'];
  231. unset($result[$key]['display_order']);
  232. $data[$val['id']] = $result[$key];
  233. }
  234. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray(pb_lang_split_recursive($data)).";\n\n";
  235. break;
  236. case 'setting':
  237. $this->lang_dirname = '';
  238. $tmp_mail = array();
  239. $table = 'setting';
  240. $conditions = "";
  241. $sql = "SELECT * FROM {$tb_prefix}settings WHERE type_id IN (0,1)";
  242. $setting = $pdb->GetArray($sql);
  243. // $tmp = '';
  244. foreach ($setting as $key=>$val) {
  245. //For multi
  246. $s_title = $val['valued'];
  247. // $tmp = unserialize($val['valued']);
  248. // if (!empty($tmp[$this->lang_dirname]) && !is_array($tmp[$this->lang_dirname])) {
  249. // $s_title = $tmp[$this->lang_dirname];
  250. // }
  251. $data[$val['variable']] = $s_title;
  252. }
  253. //set sendmail
  254. $tmp_mail['send_mail'] = $data['send_mail'];
  255. $tmp_mail['auth_protocol'] = $data['auth_protocol'];
  256. $tmp_mail['smtp_server'] = $data['smtp_server'];
  257. $tmp_mail['smtp_port'] = $data['smtp_port'];
  258. $tmp_mail['smtp_auth'] = $data['smtp_auth'];
  259. $tmp_mail['mail_from'] = $data['mail_from'];
  260. $tmp_mail['mail_fromwho'] = $data['mail_fromwho'];
  261. $tmp_mail['auth_username'] = $data['auth_username'];
  262. $tmp_mail['auth_password'] = $data['auth_password'];
  263. $tmp_mail['mail_delimiter'] = $data['mail_delimiter'];
  264. $tmp_mail['sendmail_silent'] = $data['sendmail_silent'];
  265. $data['mail'] = serialize($tmp_mail);
  266. unset($tmp_mail,$data['send_mail'],$data['smtp_server'],$data['smtp_port'],$data['smtp_auth'],$data['mail_from'],$data['mail_fromwho'],$data['auth_username'],$data['auth_password'],$data['mail_delimiter'],$data['sendmail_silent']);
  267. $data['capt_auth'] = bindec($data['capt_logging'].$data['capt_register'].$data['capt_post_free'].$data['capt_add_market'].$data['capt_login_admin'].$data['capt_apply_friendlink'].$data['capt_service']);
  268. unset($data['capt_logging'],$data['capt_register'],$data['capt_post_free'],$data['capt_add_market'],$data['capt_login_admin'],$data['capt_apply_friendlink'],$data['capt_service']);
  269. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n\n";
  270. break;
  271. case 'area':
  272. $this->lang_dirname = '';
  273. $sql = "select * from {$tb_prefix}areas a where a.parent_id=0 ORDER by display_order asc";
  274. $top_areas = $sec_areas = $third_areas = $areas = $total_areas = array();
  275. $area1 = $pdb->GetArray($sql);
  276. $op = "<!--// Created ".date("M j, Y, G:i")." -->\n";
  277. $op .= "var data_area = { \n";
  278. foreach($area1 as $key=>$val){
  279. //For multi
  280. $i_title = $val['name'];
  281. // $tmp = unserialize($val['description']);
  282. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  283. $top_areas[$val['id']] = $total_areas[1][$val['id']] = $i_title;
  284. $sql = "select * from {$tb_prefix}areas a where level=2 AND parent_id=".$val['id']." ORDER by display_order asc";
  285. $sec_areas = $pdb->GetArray($sql);
  286. foreach($sec_areas as $key2=>$val2){
  287. //For multi
  288. $i_title = $val2['name'];
  289. // $tmp = unserialize($val2['description']);
  290. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  291. $third_areas = $pdb->GetArray("select id,name,parent_id,top_parentid from {$tb_prefix}areas a where level=3 AND parent_id=".$val2['id']." ORDER by display_order asc");
  292. $areas[$val['id']]['sub'][$val2['id']] = $i_title;
  293. $total_areas[2][$val2['id']] = $i_title;
  294. foreach($third_areas as $key3=>$val3){
  295. //For multi
  296. $i_title = $val3['name'];
  297. // $tmp = unserialize($val3['description']);
  298. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  299. $areas[$val2['id']]['sub'][$val3['id']] = $total_areas[3][$val3['id']] = $i_title;
  300. }
  301. }
  302. }
  303. $top_areas = pb_lang_split_recursive($this->convert2utf8($top_areas));
  304. $areas = pb_lang_split_recursive($this->convert2utf8($areas));
  305. $op .= "'0':".json_encode($top_areas);
  306. $tmp_op = array();
  307. foreach ($top_areas as $js_key=>$js_val){
  308. if(isset($areas[$js_key])){
  309. foreach ($areas[$js_key] as $js_key1=>$js_val1) {
  310. $tmp_op[] = "'0,{$js_key}':".json_encode($areas[$js_key]['sub']);
  311. foreach ($areas[$js_key]['sub'] as $js_key2=>$js_val2) {
  312. if(!empty($areas[$js_key2]['sub'])) $tmp_op[] = "'0,{$js_key},{$js_key2}':".json_encode($areas[$js_key2]['sub']);
  313. }
  314. }
  315. }
  316. }
  317. if (!empty($tmp_op)) {
  318. $op .=",\n";
  319. $tmp_op = implode(",\n", $tmp_op);
  320. $op .= $tmp_op."\n}";
  321. }else{
  322. $op .= "\n}";
  323. }
  324. $fp = file_put_contents($this->cache_path. "area.js", $op);
  325. ksort($total_areas);
  326. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($total_areas).";\n\n";
  327. break;
  328. case 'industry':
  329. $this->lang_dirname = '';
  330. if (!function_exists("smarty_function_the_url")) {
  331. require(PLUGIN_PATH."slug/function.the_url.php");
  332. }
  333. $sql = "SELECT name,id,name AS title,description FROM {$tb_prefix}industries i WHERE i.parent_id=0 and available=1 ORDER BY display_order ASC";
  334. $top_levels = $sec_levels = $third_levels = $datas = $total_datas = array();
  335. $level1 = $pdb->GetArray($sql);
  336. $op = "<!--// Created ".date("M j, Y, G:i")." -->\n";
  337. $op .= "var data_industry = { \n";
  338. foreach($level1 as $key=>$val){
  339. //For multi
  340. $i_title = $val['name'];
  341. // $tmp = unserialize($val['description']);
  342. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  343. $top_levels[$val['id']] = $total_datas[1][$val['id']] = $i_title;
  344. $sql = "SELECT id,name,parent_id,top_parentid,name AS title,description FROM {$tb_prefix}industries t WHERE available=1 AND level=2 AND parent_id=".$val['id']." ORDER BY display_order ASC";
  345. $sec_levels = $pdb->GetArray($sql);
  346. foreach($sec_levels as $key2=>$val2){
  347. //For multi
  348. $i_title = $val2['name'];
  349. // $tmp = unserialize($val2['description']);
  350. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  351. $third_levels = $pdb->GetArray("SELECT id,name,parent_id,top_parentid,name AS title,description FROM {$tb_prefix}industries t WHERE available=1 AND level=3 AND parent_id=".$val2['id']." ORDER BY display_order ASC");
  352. $datas[$val['id']]['sub'][$val2['id']] = $i_title;
  353. $total_datas[2][$val2['id']] = $i_title;
  354. foreach($third_levels as $key3=>$val3){
  355. //For multi
  356. $i_title = $val3['name'];
  357. // $tmp = unserialize($val3['description']);
  358. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  359. $datas[$val2['id']]['sub'][$val3['id']] = $total_datas[3][$val3['id']] = $i_title;
  360. }
  361. }
  362. }
  363. $top_levels = pb_lang_split_recursive($this->convert2utf8($top_levels));
  364. $datas = pb_lang_split_recursive($this->convert2utf8($datas));
  365. $op .= "'0':".json_encode($top_levels);
  366. $tmp_op = array();
  367. foreach ($top_levels as $js_key=>$js_val){
  368. if(isset($datas[$js_key])){
  369. foreach ($datas[$js_key] as $js_key1=>$js_val1) {
  370. $tmp_op[] = "'0,{$js_key}':".json_encode($datas[$js_key]['sub']);
  371. foreach ($datas[$js_key]['sub'] as $js_key2=>$js_val2) {
  372. if(!empty($datas[$js_key2]['sub'])) $tmp_op[] = "'0,{$js_key},{$js_key2}':".json_encode($datas[$js_key2]['sub']);
  373. }
  374. }
  375. }
  376. }
  377. if (!empty($tmp_op)) {
  378. $op .=",\n";
  379. $tmp_op = implode(",\n", $tmp_op);
  380. $op .= $tmp_op."\n}";
  381. }else{
  382. $op .= "\n}";
  383. }
  384. $fp = file_put_contents($this->cache_path. "industry.js", $op);
  385. unset($op);
  386. ksort($total_datas);
  387. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($total_datas).";\n\n";
  388. unset($top_levels,$sec_levels,$third_levels,$datas,$total_datas,$op);
  389. //db cache.
  390. $data = array();
  391. $op = "<?php\n";
  392. $op.="return ";
  393. $tmp_level_top = $pdb->GetArray("SELECT * FROM ".$tb_prefix."industries WHERE parent_id=0 and available=1 ORDER BY display_order ASC");
  394. if (!empty($tmp_level_top)) {
  395. foreach ($tmp_level_top as $tmp_val) {
  396. //For multi
  397. $i_title = $tmp_val['name'];
  398. // $tmp = unserialize($tmp_val['description']);
  399. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  400. $level_top[$tmp_val['id']] = $i_title;
  401. }
  402. }
  403. foreach ($level_top as $key1=>$val1) {
  404. $data[$key1]['id'] = $key1;
  405. $data[$key1]['name'] = $val1;
  406. $data[$key1]['parent_id'] = 0;
  407. $data[$key1]['level'] = 1;
  408. $url = $pdb->GetOne("SELECT url FROM ".$tb_prefix."industries WHERE id={$key1} ORDER BY display_order ASC");
  409. if ($url) {
  410. $data[$key1]['url'] = $url;
  411. }else{
  412. $data[$key1]['url'] = smarty_function_the_url(array("module"=>"special", "type"=>"industry", "id"=>$key1));
  413. }
  414. $tmp_result1 = $pdb->GetArray("SELECT * FROM ".$tb_prefix."industries WHERE level=2 AND parent_id=".$key1." AND available=1 ORDER BY display_order ASC");
  415. if (!empty($tmp_result1)) {
  416. foreach ($tmp_result1 as $key2=>$val2) {
  417. //For multi
  418. $i_title = $val2['name'];
  419. // $tmp = unserialize($val2['description']);
  420. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  421. $data[$key1]['sub'][$key2]['id'] = $val2['id'];
  422. $data[$key1]['sub'][$key2]['name'] = $i_title;
  423. $data[$key1]['sub'][$key2]['available'] = $val2['available'];
  424. $data[$key1]['sub'][$key2]['parent_id'] = $val2['parent_id'];
  425. $data[$key1]['sub'][$key2]['level'] = $val2['level'];
  426. $url = $pdb->GetRow("SELECT * FROM ".$tb_prefix."industries WHERE id={$val2['id']}");
  427. if (!empty($url['url'])) {
  428. $data[$key1]['sub'][$key2]['url'] = $url['url'];
  429. }else{
  430. $data[$key1]['sub'][$key2]['url'] = smarty_function_the_url(array("module"=>"special", "type"=>"industry", "id"=>$val2['id']));
  431. }
  432. $tmp_result2 = $pdb->GetArray("SELECT * FROM ".$tb_prefix."industries WHERE level=3 AND parent_id=".$val2['id']." AND available=1 ORDER BY display_order ASC");
  433. if (!empty($tmp_result2)) {
  434. foreach ($tmp_result2 as $key3=>$val3) {
  435. //For multi
  436. $i_title = $val3['name'];
  437. // $tmp = unserialize($val3['description']);
  438. // if(!empty($tmp[$this->lang_dirname])) $i_title = $tmp[$this->lang_dirname];
  439. $data[$key1]['sub'][$key2]['sub'][$key3]['id'] = $val3['id'];
  440. $data[$key1]['sub'][$key2]['sub'][$key3]['name'] = $i_title;
  441. $data[$key1]['sub'][$key2]['sub'][$key3]['available'] = $val3['available'];
  442. $data[$key1]['sub'][$key2]['sub'][$key3]['parent_id'] = $val3['parent_id'];
  443. $data[$key1]['sub'][$key2]['sub'][$key3]['level'] = $val3['level'];
  444. $url = $pdb->GetRow("SELECT * FROM ".$tb_prefix."industries WHERE id={$val3['id']}");
  445. if (!empty($url['url'])) {
  446. $data[$key1]['sub'][$key2]['sub'][$key3]['url'] = $url['url'];
  447. }else{
  448. $data[$key1]['sub'][$key2]['sub'][$key3]['url'] = smarty_function_the_url(array("module"=>"special", "type"=>"industry", "id"=>$val3['id']));
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. $op.=$this->evalArray($data);
  456. unset($data);
  457. $op.="\n";
  458. $op.="?>";
  459. $fp = file_put_contents(CACHE_COMMON_PATH. "industry.php", $op);
  460. // $fp = file_put_contents($this->cache_path. "industry.php", $op);
  461. break;
  462. case 'userpage':
  463. $this->lang_dirname = '';
  464. $sql = "SELECT id,name,title,url,digest FROM {$tb_prefix}userpages ORDER BY display_order ASC,id ASC";
  465. $result = $pdb->GetArray($sql);
  466. if (!empty($result)) {
  467. $i=0;
  468. foreach ($result as $key=>$val) {
  469. $data[$i]['id'] = $val['id'];
  470. $data[$i]['title'] = $val['title'];
  471. $data[$i]['name'] = $val['name'];
  472. $data[$i]['digest'] = $val['digest'];
  473. if (!empty($val['url'])) {
  474. $data[$i]['url'] = $val['url'];
  475. }else{
  476. $data[$i]['url'] = "";
  477. }
  478. $i++;
  479. }
  480. }
  481. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n\n";
  482. break;
  483. case 'form':
  484. $this->lang_dirname = '';
  485. $form_result = $pdb->GetArray("SELECT * FROM {$tb_prefix}forms ORDER BY id ASC");
  486. if (!empty($form_result)) {
  487. foreach ($form_result as $val) {
  488. $item_result = $pdb->GetArray("SELECT * FROM {$tb_prefix}formitems WHERE id IN (".$val['items'].") ORDER BY id ASC");
  489. if (!empty($item_result)) {
  490. foreach ($item_result as $val1) {
  491. $data[$val['id']][$val1['id']]['id'] = $val1['identifier'];
  492. $data[$val['id']][$val1['id']]['label'] = $val1['title'];
  493. }
  494. }
  495. }
  496. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n\n";
  497. }
  498. break;
  499. case 'membergroup':
  500. $this->lang_dirname = '';
  501. $sql = "SELECT * FROM {$tb_prefix}membergroups mg ORDER BY mg.id DESC";
  502. $membergroup_result = $pdb->GetArray($sql);
  503. if (!empty($membergroup_result)) {
  504. foreach ($membergroup_result as $key=>$val) {
  505. $data[$val['id']]['name'] = $val['name'];
  506. $data[$val['id']]['max_offer'] = $val['max_offer'];
  507. $data[$val['id']]['type_id'] = $val['membertype_id'];
  508. $data[$val['id']]['max_product'] = $val['max_product'];
  509. $data[$val['id']]['max_job'] = $val['max_job'];
  510. $data[$val['id']]['max_companynews'] = $val['max_companynews'];
  511. $data[$val['id']]['max_market'] = $val['max_companynews'];
  512. $data[$val['id']]['max_album'] = $val['max_companynews'];
  513. $data[$val['id']]['max_producttype'] = $val['max_producttype'];
  514. $data[$val['id']]['max_attach_size'] = $val['max_attach_size'];
  515. $data[$val['id']]['max_size_perday'] = $val['max_size_perday'];
  516. $data[$val['id']]['max_favorite'] = $val['max_favorite'];
  517. $data[$val['id']]['type'] = $val['type'];
  518. $data[$val['id']]['avatar'] = $val['picture'];
  519. $data[$val['id']]['allow_space'] = $val['allow_space'];
  520. $tmp_allow = sprintf("%02b", $val['allow_offer']);
  521. $data[$val['id']]['offer_allow'] = intval($tmp_allow[0]);
  522. $data[$val['id']]['offer_check'] = intval($tmp_allow[1]);
  523. $tmp_allow = sprintf("%02b", $val['allow_market']);
  524. $data[$val['id']]['market_allow'] = intval($tmp_allow[0]);
  525. $data[$val['id']]['market_check'] = intval($tmp_allow[1]);
  526. $tmp_allow = sprintf("%02b", $val['allow_company']);
  527. $data[$val['id']]['company_allow'] = intval($tmp_allow[0]);
  528. $data[$val['id']]['company_check'] = intval($tmp_allow[1]);
  529. $tmp_allow = sprintf("%02b", $val['allow_product']);
  530. $data[$val['id']]['product_allow'] = intval($tmp_allow[0]);
  531. $data[$val['id']]['product_check'] = intval($tmp_allow[1]);
  532. $tmp_allow = sprintf("%02b", $val['allow_job']);
  533. $data[$val['id']]['job_allow'] = intval($tmp_allow[0]);
  534. $data[$val['id']]['job_check'] = intval($tmp_allow[1]);
  535. $tmp_allow = sprintf("%02b", $val['allow_companynews']);
  536. $data[$val['id']]['companynews_allow'] = intval($tmp_allow[0]);
  537. $data[$val['id']]['companynews_check'] = intval($tmp_allow[1]);
  538. $tmp_allow = sprintf("%02b", $val['allow_album']);
  539. $data[$val['id']]['album_allow'] = intval($tmp_allow[0]);
  540. $data[$val['id']]['album_check'] = intval($tmp_allow[1]);
  541. $data[$val['id']]['auth_level'] = intval($val['exempt']);
  542. }
  543. }
  544. $curdata = "\$_PB_CACHE['$cachename'] = ".$this->evalArray($data).";\n\n";
  545. break;
  546. case "javascript":
  547. $this->lang_dirname = '';
  548. require(CACHE_LANG_PATH. "lang_javascript.php");
  549. //arrTemplate is the language pack
  550. $op = "<!--// Created ".date("M j, Y, G:i")." -->\n";
  551. $op .= "var pb_lang = { \n";
  552. if(!empty($arrTemplate)){
  553. foreach ($arrTemplate as $key=>$val) {
  554. $val = str_replace("\"", "", $val);
  555. $op .= "\t".strtoupper(trim($key, '_')).' : "'.$val.'",';
  556. $op .="\n";
  557. }
  558. }
  559. $op .="\tEND : ''\n};";
  560. $fp = file_put_contents($this->cache_path. "locale.js", $op);
  561. unset($op);
  562. break;
  563. default:
  564. break;
  565. }
  566. return $curdata;
  567. }
  568. function convert2utf8($str, $force = false)
  569. {
  570. global $charset;
  571. if ($charset!="utf-8") {
  572. if(is_array($str)){
  573. return array_map(array('Caches','convert2utf8'), $str);
  574. }else{
  575. return iconv($charset, "utf-8", $str);
  576. }
  577. }else{
  578. return $str;
  579. }
  580. }
  581. function cacheAll()
  582. {
  583. if (!empty($this->lang_dirname)) {
  584. $this->cache_path = PHPB2B_ROOT."data".DS."cache".DS.$this->lang_dirname.DS;
  585. }else{
  586. $this->cache_path = CACHE_PATH;
  587. }
  588. $this->writeCache("setting", "setting");
  589. $this->updateLanguages();
  590. $this->writeCache("javascript", "javascript");
  591. $this->updateIndexCache();
  592. $this->updateTypes();
  593. $this->writeCache("area", "area");
  594. $this->updateTypevars();
  595. $this->writeCache("industry", "industry");
  596. $this->writeCache("nav", "nav");
  597. $this->writeCache("userpage", "userpage");
  598. $this->writeCache("trusttype", "trusttype");
  599. $this->writeCache("membergroup", "membergroup");
  600. $this->writeCache("form", "form");
  601. $this->writeCache("country", "country");
  602. return true;
  603. }
  604. /**
  605. * version 4.3
  606. * javascript language
  607. * @description
  608. */
  609. function updateLanguages()
  610. {
  611. global $smarty;
  612. $lang_array = array(
  613. 'admin',
  614. 'adminmenu',
  615. 'emails',
  616. 'install',
  617. 'message',
  618. 'office',
  619. 'site',
  620. 'space',
  621. 'wap',
  622. 'javascript'
  623. );
  624. foreach ($lang_array as $val) {
  625. $this->lang_load(array('file'=>'default.dot','section'=>$val, 'scope' => 'global'), $smarty);
  626. }
  627. }
  628. function lang_load($params, &$smarty)
  629. {
  630. if (!empty($this->lang_dirname)) {
  631. $app_lang = $this->lang_dirname;
  632. }else{
  633. $app_lang = $GLOBALS['app_lang'];
  634. }
  635. if(function_exists("dequote")){
  636. $_file = isset($params['file']) ? dequote($params['file']) : null;
  637. $_section = isset($params['section']) ? dequote($params['section']) : null;
  638. $_scope = isset($params['scope']) ? dequote($params['scope']) : 'global';
  639. $_global = isset($params['global']) ? dequote($params['global']) : false;
  640. }else{
  641. $_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;
  642. $_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;
  643. $_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';
  644. $_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;
  645. }
  646. if (!isset($_file) || strlen($_file) == 0) {
  647. $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
  648. }
  649. if (isset($_scope)) {
  650. if ($_scope != 'local' &&
  651. $_scope != 'parent' &&
  652. $_scope != 'global') {
  653. $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
  654. }
  655. } else {
  656. if ($_global) {
  657. $_scope = 'parent';
  658. } else {
  659. $_scope = 'local';
  660. }
  661. }
  662. $config_dir = PHPB2B_ROOT. 'languages'.DS. $app_lang.DS;
  663. require_once PHPB2B_ROOT.'libraries/language.class.php';
  664. $smarty->_conf_obj = new ConfigFile($config_dir);
  665. $smarty->_conf_obj->overwrite = $smarty->config_overwrite;
  666. $smarty->_conf_obj->booleanize = $smarty->config_booleanize;
  667. $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
  668. $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
  669. $_params['source_content'] = '';
  670. $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']);
  671. $_config_vars = array_merge($smarty->_conf_obj->get($_file),
  672. $smarty->_conf_obj->get($_file, $_section));
  673. // if(function_exists("pb_lang_split"))
  674. // $_config_vars = pb_lang_split_recursive($_config_vars);
  675. if(function_exists('var_export')) {
  676. $_output = '<?php $arrTemplate = ' . var_export($_config_vars, true) . '; ?>';
  677. } else {
  678. $_output = '<?php $arrTemplate = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
  679. }
  680. if(!is_dir($this->cache_path)) {
  681. pb_create_folder($this->cache_path);
  682. }
  683. file_put_contents($this->cache_path.'lang_'.$_section.".php", $_output);
  684. }
  685. }
  686. ?>