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

/www/lib/function.smarty.php

http://firmkernel.googlecode.com/
PHP | 930 lines | 850 code | 7 blank | 73 comment | 12 complexity | 52632d9126f58e15770b6ccd3e2185ea MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------------+
  4. | $Id: function.smarty.php 2009-10-12 11:21:29Z Bleakwind $
  5. | Global Smarty function
  6. | Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
  7. | http://www.weaverdream.com/
  8. | Release under the GNU Lesser General Public License Version 3 (LGPLv3):
  9. | http://www.gnu.org/licenses/lgpl.html
  10. +-----------------------------------------------------------------------------+
  11. */
  12. /*
  13. * Smarty plugin
  14. * -------------------------------------------------------------
  15. * File: modifier.str_count.php
  16. * Type: modifier
  17. * Name: str_count
  18. * Purpose: Count a string
  19. * -------------------------------------------------------------
  20. */
  21. function smarty_modifier_str_count($string, $encoding = "UTF-8")
  22. {
  23. return mb_strwidth($string, $encoding);
  24. }
  25. $t->register_modifier("str_count", "smarty_modifier_str_count");
  26. /*
  27. * Smarty plugin
  28. * -------------------------------------------------------------
  29. * File: modifier.str_cut.php
  30. * Type: modifier
  31. * Name: str_cut
  32. * Purpose: Return a part of string
  33. * -------------------------------------------------------------
  34. */
  35. function smarty_modifier_str_cut($string, $start, $width="", $trimmarker="", $encoding="UTF-8")
  36. {
  37. $start = (int)$start;
  38. $width = (int)$width;
  39. if ($width > 0) {
  40. return mb_strimwidth($string, $start, $width, $trimmarker, $encoding);
  41. } else {
  42. return $string;
  43. }
  44. }
  45. $t->register_modifier("str_cut", "smarty_modifier_str_cut");
  46. /*
  47. * Smarty plugin
  48. * -------------------------------------------------------------
  49. * File: modifier.print_format.php
  50. * Type: modifier
  51. * Name: print_format
  52. * Purpose: print_format
  53. * -------------------------------------------------------------
  54. */
  55. function smarty_modifier_print_format($string, $var)
  56. {
  57. $var_list = preg_split("/[\s,-]+/", $var);
  58. $_output = vsprintf($string, $var_list);
  59. return $_output;
  60. }
  61. $t->register_modifier("print_format", "smarty_modifier_print_format");
  62. /*
  63. * Smarty plugin
  64. * -------------------------------------------------------------
  65. * File: modifier.set_type.php
  66. * Type: modifier
  67. * Name: set_type
  68. * Purpose: Set type to something
  69. * -------------------------------------------------------------
  70. */
  71. function smarty_modifier_set_type($string, $type)
  72. {
  73. settype($string, $type);
  74. return $string;
  75. }
  76. $t->register_modifier("set_type", "smarty_modifier_set_type");
  77. /*
  78. * Smarty plugin
  79. * -------------------------------------------------------------
  80. * File: modifier.handle_value.php
  81. * Type: modifier
  82. * Name: handle_value
  83. * Purpose: handle_value
  84. * -------------------------------------------------------------
  85. */
  86. function smarty_modifier_handle_value($string, $value)
  87. {
  88. $string = explode("|", $string);
  89. if (is_array($string) && count($string)>0) {
  90. foreach($string as $v){
  91. $this_option = explode(":", $v);
  92. if ($this_option[0] == $value) {
  93. $this_value = $this_option;
  94. break;
  95. }
  96. }
  97. }
  98. return $this_value;
  99. }
  100. $t->register_modifier("handle_value", "smarty_modifier_handle_value");
  101. /*
  102. * Smarty plugin
  103. * -------------------------------------------------------------
  104. * File: modifier.strip_tags.php
  105. * Type: modifier
  106. * Name: strip_tags
  107. * Purpose: Strip HTML and PHP tags from a string
  108. * -------------------------------------------------------------
  109. */
  110. function smarty_modifier_strip_tags($string, $allow)
  111. {
  112. if (!empty($allow)) {
  113. $string = strip_tags($string, $allow);
  114. } else {
  115. $string = strip_tags($string);
  116. }
  117. return $string;
  118. }
  119. $t->register_modifier("strip_tags", "smarty_modifier_strip_tags");
  120. /*
  121. * Smarty plugin
  122. * -------------------------------------------------------------
  123. * File: modifier.format_date.php
  124. * Type: modifier
  125. * Name: format_date
  126. * Purpose: Strip HTML and PHP tags from a string
  127. * -------------------------------------------------------------
  128. */
  129. function smarty_modifier_format_date($string, $format="%Y-%m-%d")
  130. {
  131. if (!preg_match("/^[1-9][0-9]{0,10}$/",$string)){
  132. $return = "";
  133. } else {
  134. if (DIRECTORY_SEPARATOR == '\\') {
  135. $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
  136. $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
  137. if (strpos($format, '%e') !== false) {
  138. $_win_from[] = '%e';
  139. $_win_to[] = sprintf('%\' 2d', date('j', $string));
  140. }
  141. if (strpos($format, '%l') !== false) {
  142. $_win_from[] = '%l';
  143. $_win_to[] = sprintf('%\' 2d', date('h', $string));
  144. }
  145. $format = str_replace($_win_from, $_win_to, $format);
  146. }
  147. $return = strftime($format, $string);
  148. }
  149. return $return;
  150. }
  151. $t->register_modifier("format_date", "smarty_modifier_format_date");
  152. /*
  153. * Smarty plugin
  154. * -------------------------------------------------------------
  155. * File: modifier.is_num.php
  156. * Type: modifier
  157. * Name: is_num
  158. * Purpose: If in array
  159. * -------------------------------------------------------------
  160. */
  161. function smarty_modifier_is_num($string, $long="10")
  162. {
  163. $long = $long-1;
  164. if (preg_match("/^[1-9][0-9]{0,".$long."}$/", $string)) {
  165. return "1";
  166. } else {
  167. return "2";
  168. }
  169. }
  170. $t->register_modifier("is_num", "smarty_modifier_is_num");
  171. /*
  172. * Smarty plugin
  173. * -------------------------------------------------------------
  174. * File: modifier.in_array.php
  175. * Type: modifier
  176. * Name: in_array
  177. * Purpose: If in array
  178. * -------------------------------------------------------------
  179. */
  180. function smarty_modifier_in_array($str, $array)
  181. {
  182. if (!is_array($array)) {
  183. $array = explode(",", $array);
  184. }
  185. if (is_array($array)) {
  186. return in_array($str, $array);
  187. } else {
  188. return false;
  189. }
  190. }
  191. $t->register_modifier("in_array", "smarty_modifier_in_array");
  192. /*
  193. * Smarty plugin
  194. * -------------------------------------------------------------
  195. * File: modifier.in_array_key.php
  196. * Type: modifier
  197. * Name: in_array_key
  198. * Purpose: If in array
  199. * -------------------------------------------------------------
  200. */
  201. function smarty_modifier_in_array_key($str, $array)
  202. {
  203. if (!is_array($array)) {
  204. $array = explode(",", $array);
  205. }
  206. if (is_array($array)) {
  207. return array_key_exists($str, $array);
  208. } else {
  209. return false;
  210. }
  211. }
  212. $t->register_modifier("in_array_key", "smarty_modifier_in_array_key");
  213. /*
  214. * Smarty plugin
  215. * -------------------------------------------------------------
  216. * File: modifier.implode_str.php
  217. * Type: modifier
  218. * Name: implode_str
  219. * Purpose: implode_str string
  220. * -------------------------------------------------------------
  221. */
  222. function smarty_modifier_implode_str($str,$glue="")
  223. {
  224. if (!empty($str)) {
  225. if (!is_array($str)) {
  226. $str = preg_split("/[\s,]+/", $str);
  227. }
  228. if (is_array($str) && count($str) > 0) {
  229. $str = implode($glue, $str);
  230. }
  231. }
  232. return $str;
  233. }
  234. $t->register_modifier("implode_str", "smarty_modifier_implode_str");
  235. /*
  236. * Smarty plugin
  237. * -------------------------------------------------------------
  238. * File: modifier.against_array.php
  239. * Type: modifier
  240. * Name: against_array
  241. * Purpose: against_array string
  242. * -------------------------------------------------------------
  243. */
  244. function smarty_modifier_against_array($array)
  245. {
  246. if (is_array($array) && count($array) > 0) {
  247. krsort($array);
  248. }
  249. return $array;
  250. }
  251. $t->register_modifier("against_array", "smarty_modifier_against_array");
  252. /*
  253. * Smarty plugin
  254. * -------------------------------------------------------------
  255. * File: modifier.str_enbr.php
  256. * Type: modifier
  257. * Name: str_enbr
  258. * Purpose: str_enbr string
  259. * -------------------------------------------------------------
  260. */
  261. function smarty_modifier_str_enbr($str)
  262. {
  263. $str = func::str_enbr($str);
  264. return $str;
  265. }
  266. $t->register_modifier("str_enbr", "smarty_modifier_str_enbr");
  267. /*
  268. * Smarty plugin
  269. * -------------------------------------------------------------
  270. * File: modifier.str_debr.php
  271. * Type: modifier
  272. * Name: str_debr
  273. * Purpose: str_debr string
  274. * -------------------------------------------------------------
  275. */
  276. function smarty_modifier_str_debr($str)
  277. {
  278. $str = func::str_debr($str);
  279. return $str;
  280. }
  281. $t->register_modifier("str_debr", "smarty_modifier_str_debr");
  282. /*
  283. * Smarty plugin
  284. * -------------------------------------------------------------
  285. * File: modifier.str_stripbr.php
  286. * Type: modifier
  287. * Name: str_stripbr
  288. * Purpose: str_stripbr string
  289. * -------------------------------------------------------------
  290. */
  291. function smarty_modifier_str_stripbr($str)
  292. {
  293. $str = func::str_stripbr($str);
  294. return $str;
  295. }
  296. $t->register_modifier("str_stripbr", "smarty_modifier_str_stripbr");
  297. /*
  298. * Smarty plugin
  299. * -------------------------------------------------------------
  300. * File: modifier.str_enspace.php
  301. * Type: modifier
  302. * Name: str_enspace
  303. * Purpose: str_enspace string
  304. * -------------------------------------------------------------
  305. */
  306. function smarty_modifier_str_enspace($str)
  307. {
  308. $str = func::str_enspace($str);
  309. return $str;
  310. }
  311. $t->register_modifier("str_enspace", "smarty_modifier_str_enspace");
  312. /*
  313. * Smarty plugin
  314. * -------------------------------------------------------------
  315. * File: modifier.str_despace.php
  316. * Type: modifier
  317. * Name: str_despace
  318. * Purpose: str_despace string
  319. * -------------------------------------------------------------
  320. */
  321. function smarty_modifier_str_despace($str)
  322. {
  323. $str = func::str_despace($str);
  324. return $str;
  325. }
  326. $t->register_modifier("str_despace", "smarty_modifier_str_despace");
  327. /*
  328. * Smarty plugin
  329. * -------------------------------------------------------------
  330. * File: modifier.str_stripspace.php
  331. * Type: modifier
  332. * Name: str_stripspace
  333. * Purpose: str_stripspace string
  334. * -------------------------------------------------------------
  335. */
  336. function smarty_modifier_str_stripspace($str)
  337. {
  338. $str = func::str_stripspace($str);
  339. return $str;
  340. }
  341. $t->register_modifier("str_stripspace", "smarty_modifier_str_stripspace");
  342. /*
  343. * Smarty plugin
  344. * -------------------------------------------------------------
  345. * File: modifier.str_entag.php
  346. * Type: modifier
  347. * Name: str_entag
  348. * Purpose: str_entag string
  349. * -------------------------------------------------------------
  350. */
  351. function smarty_modifier_str_entag($str, $array="")
  352. {
  353. $str = func::str_entag($str, $array);
  354. return $str;
  355. }
  356. $t->register_modifier("str_entag", "smarty_modifier_str_entag");
  357. /*
  358. * Smarty plugin
  359. * -------------------------------------------------------------
  360. * File: modifier.str_detag.php
  361. * Type: modifier
  362. * Name: str_detag
  363. * Purpose: str_detag string
  364. * -------------------------------------------------------------
  365. */
  366. function smarty_modifier_str_detag($str, $array="")
  367. {
  368. $str = func::str_detag($str, $array);
  369. return $str;
  370. }
  371. $t->register_modifier("str_detag", "smarty_modifier_str_detag");
  372. /*
  373. * Smarty plugin
  374. * -------------------------------------------------------------
  375. * File: modifier.parse_bwbbcode.php
  376. * Type: modifier
  377. * Name: parse_bwbbcode
  378. * Purpose: parse_bwbbcode string
  379. * -------------------------------------------------------------
  380. */
  381. function smarty_modifier_parse_bwbbcode($str)
  382. {
  383. global $bwbbcode;
  384. $str = $bwbbcode->parse_bwbbcode($str);
  385. return $str;
  386. }
  387. $t->register_modifier("parse_bwbbcode", "smarty_modifier_parse_bwbbcode");
  388. /*
  389. * Smarty plugin
  390. * -------------------------------------------------------------
  391. * File: function.indent_space.php
  392. * Type: function
  393. * Name: indent_space
  394. * Purpose: indent_space
  395. * -------------------------------------------------------------
  396. */
  397. function smarty_function_indent_space($params, &$smarty)
  398. {
  399. $_output = '';
  400. foreach ($params as $_key => $_val) {
  401. switch ($_key) {
  402. case 'str':
  403. $str = (string)$_val;
  404. break;
  405. case 'limit':
  406. $limit = (int)$_val;
  407. break;
  408. default:
  409. $smarty->trigger_error("indent_space: unknown attribute '$_key'");
  410. }
  411. }
  412. $str = empty($str) ? "&nbsp;" : $str;
  413. return str_repeat($str, $limit);
  414. }
  415. $t->register_function("indent_space", "smarty_function_indent_space");
  416. /*
  417. * Smarty plugin
  418. * -------------------------------------------------------------
  419. * File: block.fill_space.php
  420. * Type: block
  421. * Name: fill_space
  422. * Purpose: fill space
  423. * -------------------------------------------------------------
  424. */
  425. function smarty_block_fill_space($params, $content, &$smarty)
  426. {
  427. global $sys;
  428. $_output = '';
  429. foreach ($params as $_key => $_val) {
  430. switch ($_key) {
  431. case 'limit':
  432. $limit = (int)$_val;
  433. break;
  434. default:
  435. $smarty->trigger_error("fill_space: unknown attribute '$_key'");
  436. }
  437. }
  438. return str_repeat($content, $limit);
  439. }
  440. $t->register_block("fill_space", "smarty_block_fill_space");
  441. /*
  442. * Smarty plugin
  443. * -------------------------------------------------------------
  444. * File: modifier.is_file.php
  445. * Type: modifier
  446. * Name: is_file
  447. * Purpose: is_file
  448. * -------------------------------------------------------------
  449. */
  450. function smarty_modifier_is_file($dir, $filename)
  451. {
  452. if (is_file($dir."/".$filename)) {
  453. return 1;
  454. } else {
  455. return 0;
  456. }
  457. }
  458. $t->register_modifier("is_file", "smarty_modifier_is_file");
  459. /*
  460. * Smarty plugin
  461. * -------------------------------------------------------------
  462. * File: modifier.is_dir.php
  463. * Type: modifier
  464. * Name: is_dir
  465. * Purpose: is_dir
  466. * -------------------------------------------------------------
  467. */
  468. function smarty_modifier_is_dir($dir)
  469. {
  470. if (is_dir($dir)) {
  471. return 1;
  472. } else {
  473. return 0;
  474. }
  475. }
  476. $t->register_modifier("is_dir", "smarty_modifier_is_dir");
  477. /*
  478. * Smarty plugin
  479. * -------------------------------------------------------------
  480. * File: function.return_db_list.php
  481. * Type: function
  482. * Name: return_db_list
  483. * Purpose: return_db_list
  484. * -------------------------------------------------------------
  485. */
  486. function smarty_function_return_db_list($params, &$smarty)
  487. {
  488. global $sys;
  489. $_output = '';
  490. foreach ($params as $_key => $_val) {
  491. switch ($_key) {
  492. case 'item':
  493. $item = (string)$_val;
  494. break;
  495. case 'option':
  496. $option = $_val;
  497. break;
  498. default:
  499. $smarty->trigger_error("return_db_list: unknown attribute '$_key'");
  500. }
  501. }
  502. if (empty($item)) {
  503. $smarty->trigger_error("return_db_list: missing 'item' attribute");
  504. }
  505. $list = func::return_db_list($option);
  506. $smarty->assign($item, $list);
  507. return;
  508. }
  509. $t->register_function("return_db_list", "smarty_function_return_db_list");
  510. /*
  511. * Smarty plugin
  512. * -------------------------------------------------------------
  513. * File: function.run_function.php
  514. * Type: function
  515. * Name: run_function
  516. * Purpose: run_function
  517. * -------------------------------------------------------------
  518. */
  519. function smarty_function_run_function($params, &$smarty)
  520. {
  521. $_output = '';
  522. foreach ($params as $_key => $_val) {
  523. switch ($_key) {
  524. case 'function':
  525. $function = (string)$_val;
  526. break;
  527. default:
  528. $smarty->trigger_error("run_function: unknown attribute '$_key'");
  529. }
  530. }
  531. $method = new func();
  532. if (method_exists($method, $function)) {
  533. $_output = func::$function();
  534. }
  535. return $_output;
  536. }
  537. $t->register_function("run_function", "smarty_function_run_function");
  538. /*
  539. * Smarty plugin
  540. * -------------------------------------------------------------
  541. * File: function.return_select.php
  542. * Type: function
  543. * Name: return_select
  544. * Purpose: return_select
  545. * -------------------------------------------------------------
  546. */
  547. function smarty_function_return_select($params, &$smarty)
  548. {
  549. global $sys;
  550. $_output = '';
  551. foreach ($params as $_key => $_val) {
  552. switch ($_key) {
  553. case 'sort':
  554. $sort = (string)$_val;
  555. break;
  556. default:
  557. $smarty->trigger_error("return_select: unknown attribute '$_key'");
  558. }
  559. }
  560. if (empty($sort)) {
  561. $smarty->trigger_error("return_select: missing 'sort' attribute");
  562. }
  563. $smarty->assign($sys->return_select($sort));
  564. return;
  565. }
  566. $t->register_function("return_select", "smarty_function_return_select");
  567. /*
  568. * Smarty plugin
  569. * -------------------------------------------------------------
  570. * File: function.build_page.php
  571. * Type: function
  572. * Name: build_page
  573. * Purpose: return content_list
  574. * -------------------------------------------------------------
  575. */
  576. function smarty_function_build_page($params, &$smarty)
  577. {
  578. global $sys, $bwpage;
  579. $_output = '';
  580. $condition = array();
  581. foreach ($params as $_key => $_val) {
  582. switch ($_key) {
  583. case 'item':
  584. $item = (string)$_val;
  585. break;
  586. case 'total':
  587. $total = (int)$_val;
  588. break;
  589. case 'listnum':
  590. $listnum = (int)$_val;
  591. break;
  592. case 'current':
  593. $current = (int)$_val;
  594. break;
  595. case 'url':
  596. $url = (string)$_val;
  597. break;
  598. default:
  599. $smarty->trigger_error("build_page: unknown attribute '$_key'");
  600. }
  601. }
  602. if (!preg_match("/^[a-z0-9_]+$/i", $item)) {
  603. $smarty->trigger_error("build_page: missing 'item' attribute");
  604. }
  605. $total = preg_match("/^[1-9][0-9]{0,10}$/i", $total) ? $total : "1";
  606. $listnum = preg_match("/^[1-9][0-9]{0,10}$/i", $listnum) ? $listnum : "1";
  607. $current = preg_match("/^[1-9][0-9]{0,10}$/i", $current) ? $current : "1";
  608. $bwpage->set_record($total);
  609. $bwpage->set_record_listnum($listnum);
  610. $bwpage->set_page_current($current);
  611. $bwpage->page($url);
  612. $smarty->assign($item, $bwpage->pagination);
  613. return;
  614. }
  615. $t->register_function("build_page", "smarty_function_build_page");
  616. /*
  617. * Smarty plugin
  618. * -------------------------------------------------------------
  619. * File: function.build_image.php
  620. * Type: function
  621. * Name: build_image
  622. * Purpose: build_image
  623. * -------------------------------------------------------------
  624. */
  625. function smarty_function_build_image($params, &$smarty)
  626. {
  627. global $sys, $SETTING;
  628. $_output = '';
  629. foreach ($params as $_key => $_val) {
  630. switch ($_key) {
  631. case 'item':
  632. $item = (string)$_val;
  633. break;
  634. case 'name':
  635. $name = (string)$_val;
  636. break;
  637. case 'sort':
  638. $sort = (string)$_val;
  639. break;
  640. case 'dir':
  641. $dir = (string)$_val;
  642. break;
  643. case 'image_dir':
  644. $image_dir = (string)$_val;
  645. break;
  646. case 'build_dir':
  647. $build_dir = (string)$_val;
  648. break;
  649. case 'filename':
  650. $filename = (string)$_val;
  651. break;
  652. case 'watermark':
  653. $watermark = (string)$_val;
  654. break;
  655. default:
  656. $smarty->trigger_error("build_image: unknown attribute '$_key'");
  657. }
  658. }
  659. if (empty($sort) ||
  660. empty($name) ||
  661. empty($image_dir) ||
  662. empty($build_dir)) {
  663. $build_image_this = "images/nopicture.png";
  664. } else {
  665. $product_image = $image_dir."/".$dir.$filename;
  666. if ( is_file($product_image) ) {
  667. $product_image_mktime = filemtime($product_image);
  668. $build_image_this = $build_dir."/".$dir.$name."_".$filename;
  669. $product_build_list = func::db_select(DB_TABLE_PRODUCT_BUILD_CONFIG, "*", "sort='".$sort."' AND name='".$name."'", "", "rank");
  670. if (count($product_build_list) > 0) {
  671. foreach ($product_build_list as $product_build_record) {
  672. $build_path = $build_dir."/".$dir;
  673. $build_image = $build_dir."/".$dir.$product_build_record['name']."_".$filename;
  674. $build_image_mktime = 0;
  675. if (is_file($build_image)){ $build_image_mktime = filemtime($build_image); }
  676. if (!is_file($build_image)
  677. || ($build_image_mktime < $product_image_mktime)
  678. || ($build_image_mktime < $product_build_record['time']) ) {
  679. if (!file_exists($build_path)) { func::make_dir($build_path); }
  680. $image_filename = $product_image;
  681. $build_width = $product_build_record['width'];
  682. $build_height = $product_build_record['height'];
  683. $build_filename = $build_image;
  684. $cut_type_align = $product_build_record['align'];
  685. $cut_type_valign = $product_build_record['valign'];
  686. $build_percent = $build_width/$build_height;
  687. list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_filename);
  688. $image_percent = $image_width/$image_height;
  689. $build_x = 0;
  690. $build_y = 0;
  691. if ($build_percent < $image_percent) {
  692. $build_image_width = $build_width;
  693. $build_image_height = $build_width/$image_percent;
  694. $build_x = 0;
  695. if ($cut_type_valign == "top"){
  696. $build_y = 0;
  697. }elseif ($cut_type_valign == "bottom"){
  698. $build_y = $build_height - $build_image_height;
  699. }else{
  700. $build_y = ($build_height - $build_image_height)/2;
  701. }
  702. } elseif ($build_percent > $image_percent) {
  703. $build_image_width = $build_height*$image_percent;
  704. $build_image_height = $build_height;
  705. if ($cut_type_valign == "left"){
  706. $build_x = 0;
  707. }elseif ($cut_type_valign == "right"){
  708. $build_x = $build_width - $build_image_width;
  709. }else{
  710. $build_x = ($build_width - $build_image_width)/2;
  711. }
  712. $build_y = 0;
  713. } else {
  714. $build_image_width = $build_width;
  715. $build_image_height = $build_height;
  716. $build_x = 0;
  717. $build_y = 0;
  718. }
  719. $bwcurve = new bwcurve($build_width,$build_height);
  720. $bwcurve->set_imagetype("gif");
  721. $bwcurve->set_bgcolor("FFFFFF");
  722. $bwcurve->set_copyimage($image_filename,$build_image_width,$build_x,$build_y);
  723. if (!empty($watermark)) {
  724. $watermark_image = $watermark;
  725. list($watermark_image_width, $watermark_image_height, $watermark_image_type, $watermark_image_attr) = getimagesize($watermark_image);
  726. $watermark_x = $build_width/3;
  727. $watermark_y = $build_height/3*2;
  728. $bwcurve->set_copyimage($watermark_image,$watermark_image_width,$watermark_x,$watermark_y);
  729. }
  730. $bwcurve->parse();
  731. $bwcurve->output($build_filename);
  732. }
  733. }
  734. }
  735. } else {
  736. $product_image = "images/nopicture.png";
  737. $product_image_mktime = filemtime($product_image);
  738. $build_path_this = $build_dir;
  739. $build_image_this = $build_dir."/".$name."_nopicture.gif";
  740. $build_image_this_mktime= 0;
  741. if (is_file($build_image_this)){ $build_image_this_mktime = filemtime($build_image_this); }
  742. if (!is_file($build_image_this) || ($build_image_this_mktime < $product_image_mktime) ) {
  743. if (!file_exists($build_path_this)) { func::make_dir($build_path_this); }
  744. $image_filename = $product_image;
  745. $product_build_list = func::db_select(DB_TABLE_PRODUCT_BUILD_CONFIG, "*", "sort='".$sort."' AND name='".$name."'", "", "rank");
  746. list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_filename);
  747. $image_percent = $image_width/$image_height;
  748. $build_width = $product_build_list[0]['width'] != "" ? $product_build_list[0]['width'] : $image_width;
  749. $build_height = $product_build_list[0]['height'] != "" ? $product_build_list[0]['height'] : $image_height;
  750. $build_filename = $build_image_this;
  751. $cut_type_align = $product_build_list[0]['align'] != "" ? $product_build_list[0]['align'] : "center";
  752. $cut_type_valign = $product_build_list[0]['valign'] != "" ? $product_build_list[0]['valign'] : "middle";
  753. $build_percent = $build_width/$build_height;
  754. list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_filename);
  755. $image_percent = $image_width/$image_height;
  756. $build_x = 0;
  757. $build_y = 0;
  758. if ($build_percent < $image_percent) {
  759. $build_image_width = $build_width;
  760. $build_image_height = $build_width/$image_percent;
  761. $build_x = 0;
  762. if ($cut_type_valign == "top"){
  763. $build_y = 0;
  764. }elseif ($cut_type_valign == "bottom"){
  765. $build_y = $build_height - $build_image_height;
  766. }else{
  767. $build_y = ($build_height - $build_image_height)/2;
  768. }
  769. } elseif ($build_percent > $image_percent) {
  770. $build_image_width = $build_height*$image_percent;
  771. $build_image_height = $build_height;
  772. if ($cut_type_valign == "left"){
  773. $build_x = 0;
  774. }elseif ($cut_type_valign == "right"){
  775. $build_x = $build_width - $build_image_width;
  776. }else{
  777. $build_x = ($build_width - $build_image_width)/2;
  778. }
  779. $build_y = 0;
  780. } else {
  781. $build_image_width = $build_width;
  782. $build_image_height = $build_height;
  783. $build_x = 0;
  784. $build_y = 0;
  785. }
  786. $bwcurve = new bwcurve($build_width,$build_height);
  787. $bwcurve->set_imagetype("gif");
  788. $bwcurve->set_bgcolor("FFFFFF");
  789. $bwcurve->set_copyimage($image_filename,$build_image_width,$build_x,$build_y);
  790. //$bwcurve->set_copyimage($watermark_source,$watermark_width,$watermark_x,$watermark_y);
  791. $bwcurve->parse();
  792. $bwcurve->output($build_filename);
  793. }
  794. }
  795. }
  796. if (!empty($item)) {
  797. $smarty->assign($item, $build_image_this);
  798. return;
  799. } else {
  800. return $build_image_this;
  801. }
  802. }
  803. $t->register_function("build_image", "smarty_function_build_image");
  804. /*
  805. * Smarty plugin
  806. * -------------------------------------------------------------
  807. * File: function.set_language.php
  808. * Type: function
  809. * Name: set_language
  810. * Purpose: set_language
  811. * -------------------------------------------------------------
  812. */
  813. function smarty_function_set_language($params, &$smarty)
  814. {
  815. global $sys, $SESSION, $LANGLIST, $CONFIG, $CONFIGURE;
  816. $_output = '';
  817. foreach ($params as $_key => $_val) {
  818. switch ($_key) {
  819. case 'lang':
  820. $lang = (int)$_val;
  821. break;
  822. default:
  823. $smarty->trigger_error("set_language: unknown attribute '$_key'");
  824. }
  825. }
  826. if ( $lang == "0") {
  827. $smarty->trigger_error("set_language: missing 'vid' attribute");
  828. }
  829. // Language
  830. if ( !empty($lang) && ($lang != $CONFIG['language']) ){
  831. // Set the Language
  832. $CONFIG['language'] = $CONFIG['default_language'];
  833. if ( preg_match("/^[0-9]{1,11}$/i",$lang) && array_key_exists($lang,$LANGLIST) ) {
  834. $SESSION->set("language", $lang);
  835. $SESSION->_['language'] = $lang;
  836. }
  837. if ( preg_match("/^[0-9]{1,11}$/i",$SESSION->_['language'])
  838. && array_key_exists($SESSION->_['language'],$LANGLIST)
  839. && file_exists('language/'.$LANGLIST[$SESSION->_['language']]['dir'].'/source/_public.php') ) {
  840. $CONFIG['language'] = $SESSION->_['language'];
  841. }
  842. include_once './language/'.$LANGLIST[$CONFIG['language']]['dir'].'/source/_public.php';
  843. include_once './language/'.$LANGLIST[$CONFIG['language']]['dir'].'/template/_public.php';
  844. $current_lang_s = './language/'.$LANGLIST[$CONFIG['language']]['dir'].'/source/'.$sys->get['act'].'.php';
  845. $current_lang_t = './language/'.$LANGLIST[$CONFIG['language']]['dir'].'/template/'.$sys->get['act'].'.php';
  846. if ( file_exists($current_lang_s) ) { include_once $current_lang_s; }
  847. if ( file_exists($current_lang_t) ) { include_once $current_lang_t; }
  848. @header('Content-Type: text/html; charset='.$LANGUAGE['s']['_public']['global']['charset']);
  849. }
  850. return;
  851. }
  852. $t->register_function("set_language", "smarty_function_set_language");
  853. /*
  854. * Smarty plugin
  855. * -------------------------------------------------------------
  856. * File: modifier.fp.php
  857. * Type: modifier
  858. * Name: fp
  859. * Purpose: format print string
  860. * -------------------------------------------------------------
  861. */
  862. function smarty_modifier_fp($str)
  863. {
  864. $_return = "<pre>".print_r($str, true)."</pre>";
  865. return $_return;
  866. }
  867. $t->register_modifier("fp", "smarty_modifier_fp");
  868. ?>