special_helper.php 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/6/16
  6. * Time: 下午2:07
  7. */
  8. //将乱七八糟的格式输出,整合成统一的格式输出
  9. require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
  11. class brands_special
  12. {
  13. const publish_brands_special = 56;
  14. const local_brands_special = 50;
  15. const test_brands_special = 56;
  16. static private $stBImgContianers;
  17. public function brands_special()
  18. {
  19. if(self::$stBImgContianers == null) {
  20. self::$stBImgContianers = [];
  21. $this->init();
  22. }
  23. }
  24. public function info($brand_id)
  25. {
  26. if(isset(self::$stBImgContianers[$brand_id])) {
  27. return self::$stBImgContianers[$brand_id];
  28. } else {
  29. return false;
  30. }
  31. }
  32. private function init()
  33. {
  34. $special_id = self::special_id();
  35. if($special_id == false) return false;
  36. $helper = new special_formater($special_id);
  37. $blocks = $helper->format($goods_ids);
  38. foreach ($blocks as $block)
  39. {
  40. $items = $block['items'];
  41. if(empty($items) || is_array($items) == false) continue;
  42. foreach ($items as $item)
  43. {
  44. $brand_id = intval($item['data']);
  45. $data = $item;
  46. $data['scale'] = $block['scale'];
  47. self::$stBImgContianers[$brand_id] = $data;
  48. }
  49. if(!empty($items) && is_array($items)) {
  50. }
  51. }
  52. }
  53. private static function special_id()
  54. {
  55. if (is_pushoms()) {
  56. return self::publish_brands_special;
  57. }
  58. elseif(is_localdebug()) {
  59. return self::local_brands_special;
  60. }
  61. else {
  62. return self::test_brands_special;
  63. }
  64. }
  65. }
  66. class special_formater
  67. {
  68. const def_item_bg_color = '#F7F7F7';
  69. const def_item_bg_type = 'color';
  70. const def_divider_bg_img= '/mobile/defimg/divider_bg.png';
  71. private $special_id;
  72. private $filter_data;
  73. private $goods_ids;
  74. private $special_info;
  75. private $sender_info;
  76. private $old_version;
  77. public function __construct($special_id,$old_version = false)
  78. {
  79. $this->special_id = $special_id;
  80. $this->old_version = $old_version;
  81. $this->special_info = [];
  82. $this->sender_info = [];
  83. $this->read_cache();
  84. }
  85. public function special_info() {
  86. return $this->special_info;
  87. }
  88. public function sender_info() {
  89. return $this->sender_info;
  90. }
  91. public static function def_divider()
  92. {
  93. static $block = [];
  94. if(empty($block))
  95. {
  96. $block['item_type'] = 'divider';
  97. $block['item_title'] = '';
  98. $block['bg_type'] = 'image';
  99. $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
  100. $block['bg_data'] = $image;
  101. $block['has_margin'] = false;
  102. $block['scale'] = self::scale($image);
  103. }
  104. return $block;
  105. }
  106. public static function format_brand_sale($brand_id,$can_click)
  107. {
  108. if($brand_id <= 0) return array();
  109. $helper = new brands_special();
  110. $info = $helper->info($brand_id);
  111. if($info == false) return array();
  112. $result['item_title'] = '';
  113. $result['item_type'] = 'home1';
  114. $result['scale'] = $info['scale'];
  115. $item['image'] = $info['image'];
  116. $item['type'] = $info['type'];
  117. if($can_click == true) {
  118. $item['data'] = $info['data'];
  119. } else {
  120. $item['data'] = 0;
  121. }
  122. $item['title'] = $info['title'];
  123. $result['items'][] = $item;
  124. return $result;
  125. }
  126. public static function format_grid_brands($brands)
  127. {
  128. $result = [];
  129. $result['item_title'] = '';
  130. $result['item_type'] = 'home_grid';
  131. $result['scale'] = 3;
  132. $items = [];
  133. foreach ($brands as $brand) {
  134. $item['image'] = $brand['brand_logo'];
  135. $item['type'] = 'brand';
  136. $item['data'] = $brand['brand_id'];
  137. $item['title'] = $brand['brand_name'];
  138. $items[] = $item;
  139. }
  140. $result['items'] = $items;
  141. return $result;
  142. }
  143. public static function format_comments($comments)
  144. {
  145. $blocks = [];
  146. foreach ($comments as $val)
  147. {
  148. $block = [];
  149. $block['item_title'] = '';
  150. $block['item_type'] = 'home_comment';
  151. $block['scale'] = 1;
  152. $item['image'] = '';
  153. $item['type'] = 'comment';
  154. $item['data'] = intval($val['geval_id']);
  155. $item['title'] = $val['geval_goodsname'];
  156. $items[] = $item;
  157. $block['items'] = $items;
  158. $blocks[] = $block;
  159. }
  160. return $blocks;
  161. }
  162. public static function format_brand($brands)
  163. {
  164. if(empty($brands)) return array();
  165. if(count($brands) == 1)
  166. {
  167. $brand_id = intval($brands[0]['data']);
  168. return self::format_brand_sale($brand_id,true);
  169. }
  170. else
  171. {
  172. $result = [];
  173. $result['item_title'] = '';
  174. $result['item_type'] = 'homewords';
  175. foreach ($brands as $val) {
  176. $item['image'] = "";
  177. $item['type'] = $val['type'];
  178. $item['data'] = strval($val['data']);
  179. $item['title'] = $val['title'];
  180. $result['items'][] = $item;
  181. }
  182. return $result;
  183. }
  184. }
  185. public static function format_category($cats,$title = '')
  186. {
  187. if(empty($cats)) return array();
  188. $result = [];
  189. $result['item_title'] = $title;
  190. $result['item_type'] = 'homewords';
  191. foreach ($cats as $val) {
  192. $item['image'] = "";
  193. $item['type'] = $val['type'];
  194. $item['data'] = strval($val['data']);
  195. $item['title'] = $val['title'];
  196. $result['items'][] = $item;
  197. }
  198. return $result;
  199. }
  200. public static function format_keyword($words,$title='')
  201. {
  202. $result = [];
  203. $result['item_title'] = $title;
  204. $result['item_type'] = 'homewords';
  205. foreach ($words as $word) {
  206. $item['image'] = "";
  207. $item['type'] = 'keyword';
  208. $item['data'] = $word;
  209. $item['title'] = $word;
  210. $result['items'][] = $item;
  211. }
  212. return $result;
  213. }
  214. public static function format_ugc(ugc\special $special)
  215. {
  216. $special_id = $special->special_id();
  217. $url = BASE_SITE_URL . "/mobile/index.php?act=special&op=index&client_type=wap&special_id={$special_id}";
  218. $result = [];
  219. $result['item_title'] = $special->share_title();
  220. $result['item_type'] = 'home1';
  221. $item['show_type'] = 'ugc';
  222. $item['show_data'] = $special_id;
  223. $item['image'] = $special->share_img();
  224. $item['type'] = 'url';
  225. $item['data'] = $url;
  226. $item['title'] = $special->share_title();
  227. $result['items'][] = $item;
  228. return $result;
  229. }
  230. public static function format_bonus($bonuses,$title='')
  231. {
  232. $result = [];
  233. $result['item_title'] = $title;
  234. $result['item_type'] = 'home_bonus';
  235. foreach ($bonuses as $bonus) {
  236. $item['image'] = "";
  237. $item['type'] = 'bonus';
  238. $item['data'] = $bonus['bonus_sn'];
  239. $item['title'] = '';
  240. $result['items'][] = $item;
  241. }
  242. return $result;
  243. }
  244. public static function format_type($type_infos,$title='')
  245. {
  246. $result = [];
  247. $result['item_title'] = $title;
  248. $result['item_type'] = 'home_type';
  249. foreach ($type_infos as $type) {
  250. $item['image'] = "";
  251. $item['type'] = 'bonus_type';
  252. $item['data'] = $type['type_sn'];
  253. $item['title'] = '';
  254. $result['items'][] = $item;
  255. }
  256. return $result;
  257. }
  258. public static function format_goods($goods_ids,$title,$sort_summary)
  259. {
  260. $result = [];
  261. $result['item_title'] = empty($title) ? '' : $title;
  262. $result['item_type'] = 'home_goods';
  263. foreach ($goods_ids as $goods_id)
  264. {
  265. $summary = $sort_summary[$goods_id];
  266. $item['image'] = $summary['goods_image_url'];
  267. $item['show_type'] = 'goods';
  268. $item['show_data'] = strval($goods_id);
  269. $item['type'] = 'goods';
  270. $item['data'] = strval($goods_id);
  271. $item['title'] = $summary['goods_mobile_name'];
  272. $result['items'][] = $item;
  273. }
  274. return $result;
  275. }
  276. public static function format_ugc_goods($goods_ids,$title,$sort_summary)
  277. {
  278. $blocks = [];
  279. $count = count($goods_ids);
  280. $i = 1;
  281. foreach ($goods_ids as $goods_id)
  282. {
  283. $block = [];
  284. $block['item_title'] = empty($title) ? '' : $title;
  285. $block['item_type'] = 'home1';
  286. $summary = $sort_summary[$goods_id];
  287. $item['image'] = $summary['goods_image_url'];
  288. $item['show_type'] = 'goods_ugc';
  289. $item['show_data'] = strval($goods_id);
  290. $item['type'] = 'goods';
  291. $item['data'] = strval($goods_id);
  292. $item['title'] = $summary['goods_mobile_name'];
  293. $block['items'][] = $item;
  294. $blocks[] = $block;
  295. if($i != $count) {
  296. $blocks[] = self::def_divider();
  297. }
  298. }
  299. return $blocks;
  300. }
  301. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  302. public function format(&$goods_ids)
  303. {
  304. $goods_ids = $this->goods_ids;
  305. return $this->filter_data;
  306. }
  307. private function read_cache()
  308. {
  309. $mod_special = Model('mb_special');
  310. $specials = $mod_special->getMbSpecialItemUsableListByID($this->special_id);
  311. if(empty($specials)) {
  312. Log::record("getMbSpecialItemUsableListByID is empty",Log::ERR);
  313. }
  314. $from_user = spid_helper::instance()->special($this->special_id)->from_user();
  315. if(isset($specials["mobile_filter_data"]))
  316. {
  317. $this->filter_data = $specials['mobile_filter_data'];
  318. $this->goods_ids = $specials['mobile_goods_ids'];
  319. if($from_user) {
  320. $this->special_info = $specials['special_info'];
  321. $this->sender_info = $specials['sender_info'];
  322. }
  323. }
  324. else
  325. {
  326. $this->filter_data = $this->filter($specials['blocks'],$goods_ids);
  327. $this->goods_ids = $goods_ids;
  328. $specials['mobile_filter_data'] = $this->filter_data;
  329. $specials['mobile_goods_ids'] = $goods_ids;
  330. if($from_user)
  331. {
  332. $special_info = $mod_special->getMbSpecialByID($this->special_id);
  333. $specials['special_info'] = $special_info;
  334. $userid = $special_info['member_id'];
  335. if($userid > 0) {
  336. $mod_member = Model('member');
  337. $sender_info = $mod_member->getMemberInfoByID($userid);
  338. $specials['sender_info'] = $sender_info;
  339. $this->sender_info = $specials['sender_info'];
  340. }
  341. $this->special_info = $specials['special_info'];
  342. }
  343. $cache = array('special' => serialize($specials));
  344. wcache($this->special_id, $cache, 'mb_special');
  345. }
  346. }
  347. private function filter($specials,&$goods_ids)
  348. {
  349. $blocks = [];
  350. $goods_ids = [];
  351. foreach($specials as $special)
  352. {
  353. $ids = [];
  354. $block = $this->filter_item($special,$ids,$scale);
  355. if($scale != false && !empty($block)) {
  356. $blocks[] = $block;
  357. $goods_ids = array_merge($goods_ids,$ids);
  358. }
  359. }
  360. $goods_ids = array_unique($goods_ids);
  361. return $blocks;
  362. }
  363. private function filter_item($special,&$goods_ids,&$scale)
  364. {
  365. $block = [];
  366. $block['item_title'] = empty($special['title']) ? '' : $special['title'];
  367. $block['item_type'] = $special['item_type'];
  368. $block['bg_image'] = $special['bg_image'];
  369. $block['bg_type'] = $special['bg_type'];
  370. $block['bg_data'] = $special['bg_data'];
  371. $block['has_margin'] = $special['has_margin'];
  372. $block_scale = false;
  373. $this->format_property($block,$block_scale);
  374. $key = $special['item_type'];
  375. if ($key == 'divider') {
  376. $scale = $block_scale;
  377. $block['scale'] = $scale;
  378. return $block;
  379. }
  380. $org_items = $special['items'];
  381. if($key != 'divider' && empty($org_items)) {
  382. return false;
  383. }
  384. $scale = false;
  385. if($key == 'adv_list' || $key == 'home3' || $key == 'home5' || $key =='home6' || $key == 'home7' || $key == 'goods')
  386. {
  387. $items = $this->filter_normal($key,$org_items,$goods_ids,$scale);
  388. if($key == 'goods') {
  389. $block['item_type'] = 'home_goods';
  390. }
  391. elseif($key == 'home3') {
  392. if($this->old_version == false) $scale = $block_scale;
  393. }
  394. elseif($key == 'home6') {
  395. $block['item_type'] = 'horizon';
  396. $scale = $block_scale;
  397. }
  398. elseif($key == 'home7') {
  399. $block['item_type'] = 'horizon_goods';
  400. $scale = $block_scale;
  401. }
  402. }
  403. elseif($key == 'home1') {
  404. $items = $this->filter_home1($org_items,$goods_ids,$scale);
  405. }
  406. elseif($key == 'home2') {
  407. $items = $this->filter_home2($org_items,$goods_ids,$scale);
  408. }
  409. elseif($key == 'home4') {
  410. $items = $this->filter_home4($org_items,$goods_ids,$scale);
  411. }
  412. elseif($key == 'home_ugc')
  413. {
  414. $items = $this->filter_home_ugc($org_items,$goods_ids);
  415. $block['items'] = $items;
  416. $scale = 1;
  417. return $block;
  418. }
  419. else {
  420. return false;
  421. }
  422. if($items == false && $key != 'divider') {
  423. return false;
  424. }
  425. $this->decode($items);
  426. foreach ($items as &$item)
  427. {
  428. if($this->image_wh($item['image'],$w,$h)) {
  429. $item['width'] = $w;
  430. $item['height'] = $h;
  431. }
  432. }
  433. $block['items'] = $items;
  434. if($block_scale) {
  435. $block['scale'] = $scale;
  436. }
  437. else {
  438. $block['scale'] = $scale;
  439. }
  440. return $block;
  441. }
  442. /**
  443. * 处理type=url 时的&字符转义问题
  444. * @param array $data
  445. * @return array|bool
  446. */
  447. private function decode(&$items)
  448. {
  449. foreach($items as &$item)
  450. {
  451. static $action_types = array('url','innerurl','video','appjump');
  452. static $show_types = array('webview','video');
  453. if(in_array($item['type'],$action_types)){
  454. $item['data'] = htmlspecialchars_decode($item['data']);
  455. }
  456. if(in_array($item['show_type'],$show_types)){
  457. $item['show_data'] = htmlspecialchars_decode($item['show_data']);
  458. }
  459. }
  460. }
  461. public static function scale($image)
  462. {
  463. $image = trim($image);
  464. if(empty($image)) {
  465. Log::record("special scale error {$image}",Log::ERR);
  466. return false;
  467. }
  468. $ret = util::imgsize($image);
  469. if($ret != false) {
  470. $scale = doubleval($ret[0]) / doubleval($ret[1]);
  471. return $scale;
  472. } else {
  473. Log::record("special scale getimagesize error {$image}",Log::ERR);
  474. return false;
  475. }
  476. }
  477. private function safe_string($str)
  478. {
  479. if($str == null || empty($str)) {
  480. return "";
  481. }
  482. else {
  483. return $str;
  484. }
  485. }
  486. private function check_goods($ids)
  487. {
  488. if(empty($ids)) return true;
  489. $ids = array_unique($ids);
  490. $mod = Model('goods');
  491. $goods = $mod->getGoodsOnlineList(array("goods_id" => array("in",$ids)));
  492. $gids = [];
  493. foreach ($goods as $item) {
  494. $gids[] = intval($item['goods_id']);
  495. }
  496. if(count($ids) == count($gids)) {
  497. return true;
  498. } else {
  499. return false;
  500. }
  501. }
  502. private function filter_home1($val,&$goods_ids,&$scale)
  503. {
  504. $items = [];
  505. $item['image'] = $val['image'];
  506. $item['type'] = $val['type'];
  507. $item['data'] = $val['data'];
  508. $item['show_type'] = $val['show_type'];
  509. $item['show_data'] = $val['show_data'];
  510. $item['reserved'] = $this->safe_string($val['reserved']);
  511. $item['title'] = $this->safe_string($val['title']);
  512. $scale = self::scale($item['image']);
  513. $ids = [];
  514. if($item['type'] == 'goods') {
  515. $ids[] = intval($item['data']);
  516. }
  517. if(self::check_goods($ids)) {
  518. $goods_ids = array_merge($goods_ids,$ids);
  519. $items[] = $item;
  520. return $items;
  521. } else {
  522. return false;
  523. }
  524. }
  525. private function filter_home_ugc($val,&$goods_ids)
  526. {
  527. $items = [];
  528. $item['image'] = $val['image'];
  529. $item['type'] = $val['type'];
  530. $item['data'] = $val['data'];
  531. $item['show_type'] = $val['show_type'];
  532. $item['show_data'] = $val['show_data'];
  533. $item['reserved'] = $this->safe_string($val['reserved']);
  534. $item['title'] = $this->safe_string($val['title']);
  535. $ids = [];
  536. if($item['type'] == 'goods') {
  537. $ids[] = intval($item['data']);
  538. }
  539. if(self::check_goods($ids)) {
  540. $goods_ids = array_merge($goods_ids,$ids);
  541. $items[] = $item;
  542. return $items;
  543. } else {
  544. return false;
  545. }
  546. }
  547. private function filter_home2($val,&$goods_ids,&$scale)
  548. {
  549. $items = [];
  550. {
  551. $item['image'] = $val['square_image'];
  552. $item['type'] = $val['square_type'];
  553. $item['data'] = $val['square_data'];
  554. $item['show_type'] = $val['square_show_type'];
  555. $item['show_data'] = $val['square_show_data'];
  556. $item['title'] = $this->safe_string($val['square_title']);
  557. $item['reserved'] = $this->safe_string($val['square_reserved']);
  558. $items[] = $item;
  559. }
  560. {
  561. $item['image'] = $val['rectangle1_image'];
  562. $item['type'] = $val['rectangle1_type'];
  563. $item['data'] = $val['rectangle1_data'];
  564. $item['show_type'] = $val['rectangle1_show_type'];
  565. $item['show_data'] = $val['rectangle1_show_data'];
  566. $item['title'] = $this->safe_string($val['rectangle1_title']);
  567. $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
  568. $items[] = $item;
  569. $scale = self::scale($item['image']);
  570. }
  571. {
  572. $item['image'] = $val['rectangle2_image'];
  573. $item['type'] = $val['rectangle2_type'];
  574. $item['data'] = $val['rectangle2_data'];
  575. $item['show_type'] = $val['rectangle2_show_type'];
  576. $item['show_data'] = $val['rectangle2_show_data'];
  577. $item['title'] = $this->safe_string($val['rectangle2_title']);
  578. $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
  579. $items[] = $item;
  580. }
  581. $ids = [];
  582. foreach ($items as $item)
  583. {
  584. if($item['type'] == 'goods') {
  585. $ids[] = intval($item['data']);
  586. }
  587. }
  588. if(self::check_goods($ids)) {
  589. $goods_ids = array_merge($goods_ids,$ids);
  590. return $items;
  591. } else {
  592. Log::record("check_goods error {$ids}",Log::ERR);
  593. return false;
  594. }
  595. }
  596. private function filter_home4($val,&$goods_ids,&$scale)
  597. {
  598. $items = [];
  599. {
  600. $item['image'] = $val['rectangle1_image'];
  601. $item['type'] = $val['rectangle1_type'];
  602. $item['data'] = $val['rectangle1_data'];
  603. $item['show_type'] = $val['rectangle1_show_type'];
  604. $item['show_data'] = $val['rectangle1_show_data'];
  605. $item['title'] = $this->safe_string($val['rectangle1_title']);
  606. $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
  607. $items[] = $item;
  608. }
  609. {
  610. $item['image'] = $val['rectangle2_image'];
  611. $item['type'] = $val['rectangle2_type'];
  612. $item['data'] = $val['rectangle2_data'];
  613. $item['show_type'] = $val['rectangle2_show_type'];
  614. $item['show_data'] = $val['rectangle2_show_data'];
  615. $item['title'] = $this->safe_string($val['rectangle2_title']);
  616. $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
  617. $scale = self::scale($item['image']);
  618. $items[] = $item;
  619. }
  620. {
  621. $item['image'] = $val['square_image'];
  622. $item['type'] = $val['square_type'];
  623. $item['data'] = $val['square_data'];
  624. $item['show_type'] = $val['square_show_type'];
  625. $item['show_data'] = $val['square_show_data'];
  626. $item['title'] = $this->safe_string($val['square_title']);
  627. $item['reserved'] = $this->safe_string($val['square_reserved']);
  628. $items[] = $item;
  629. }
  630. $ids = [];
  631. foreach ($items as $item)
  632. {
  633. if($item['type'] == 'goods') {
  634. $ids[] = intval($item['data']);
  635. }
  636. }
  637. if(self::check_goods($ids)) {
  638. $goods_ids = array_merge($goods_ids,$ids);
  639. return $items;
  640. } else {
  641. return false;
  642. }
  643. }
  644. private function image_wh($image,&$width,&$height)
  645. {
  646. $ret = util::imgsize($image);
  647. if ($ret != false) {
  648. $width = $ret[0];
  649. $height = $ret[1];
  650. return true;
  651. } else {
  652. Log::record("cannt find image imgurl={$image}",Log::ERR);
  653. return false;
  654. }
  655. }
  656. private function format_property(&$block,&$block_scale)
  657. {
  658. $image = $block['bg_image'];
  659. if(empty($image))
  660. {
  661. if($block['item_type'] == 'divider') {
  662. $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
  663. }
  664. }
  665. else {
  666. $image = getMbSpecialImageUrl($image);
  667. }
  668. $block['bg_image'] = $image;
  669. if(!empty($image)) {
  670. $block_scale = self::scale($image);
  671. } else {
  672. $block_scale = false;
  673. }
  674. if($block['bg_type'] == 'image')
  675. {
  676. if($block_scale != false) {
  677. $block['bg_data'] = $image;
  678. } else {
  679. $block['bg_data'] = '';
  680. }
  681. }
  682. else
  683. {
  684. if(empty($block['bg_data'])) {
  685. $block['bg_data'] = self::def_item_bg_color;
  686. }
  687. }
  688. unset($block['bg_image']);
  689. }
  690. private function filter_normal($block_type,$items, &$goods_ids, &$scale)
  691. {
  692. $result = [];
  693. $has_set = false;
  694. foreach($items as $item)
  695. {
  696. $item['title'] = $this->safe_string($item['title']);
  697. if($has_set == false) {
  698. $scale = self::scale($item['image']);
  699. $has_set = true;
  700. }
  701. if($item['type'] == 'goods')
  702. {
  703. $goods_id = intval($item['data']);
  704. if(self::check_goods(array($goods_id))) {
  705. array_push($goods_ids,$goods_id);
  706. $result[] = $item;
  707. } else {
  708. Log::record("block_type={$block_type} cannt find goods ,goods_id={$goods_id}",Log::ERR);
  709. continue;
  710. }
  711. }
  712. else {
  713. $result[] = $item;
  714. }
  715. }
  716. if($has_set == true)
  717. {
  718. if($block_type == 'home3') {
  719. $scale = $scale * 2;
  720. }
  721. elseif($block_type == 'goods') {
  722. $scale = 1;
  723. }
  724. }
  725. if(empty($result)) {
  726. return false;
  727. } else {
  728. return $result;
  729. }
  730. }
  731. }
  732. class spid_item
  733. {
  734. private $mFromUser;
  735. private $mHasVote;
  736. private $mShareImage;
  737. private $mShareTitle;
  738. public function __construct($item)
  739. {
  740. $special = new ugc\special($item);
  741. $this->mFromUser = $special->from_user();
  742. $this->mHasVote = $special->has_vote();
  743. $this->mShareImage = $special->share_img();
  744. $this->mShareTitle = $special->share_title();
  745. }
  746. public function from_user() {
  747. return $this->mFromUser;
  748. }
  749. public function has_vote() {
  750. return $this->mHasVote;
  751. }
  752. public function share_image() {
  753. return $this->mShareImage;
  754. }
  755. public function share_title() {
  756. return $this->mShareTitle;
  757. }
  758. }
  759. class spid_helper
  760. {
  761. private static $stInstance = null;
  762. private $mContents;
  763. public function __construct() {
  764. $this->mContents = [];
  765. $this->add_home();
  766. }
  767. public static function instance() {
  768. if(self::$stInstance == null) {
  769. self::$stInstance = new spid_helper();
  770. }
  771. return self::$stInstance;
  772. }
  773. //home page is not in mb_special table.
  774. private function add_home()
  775. {
  776. $item['from_user'] = 0;
  777. $item['share_image'] = "";
  778. $item['share_title'] = "";
  779. $spitem = new spid_item($item);
  780. $this->mContents[0] = $spitem;
  781. }
  782. public function special($spid)
  783. {
  784. $spid = intval($spid);
  785. if(array_key_exists($spid,$this->mContents)) {
  786. return $this->mContents[$spid];
  787. }
  788. else
  789. {
  790. $item = $this->read($spid);
  791. if($item == false) {
  792. return false;
  793. } else {
  794. $this->mContents[$spid] = $item;
  795. return $item;
  796. }
  797. }
  798. }
  799. private function read($spid)
  800. {
  801. $mod_special = Model('mb_special');
  802. $item = $mod_special->getMbSpecialByID($spid);
  803. if(empty($item)) {
  804. return false;
  805. }
  806. else
  807. {
  808. $spitem = new spid_item($item);
  809. return $spitem;
  810. }
  811. }
  812. }
  813. class special_manager
  814. {
  815. private static $stInstance = null;
  816. private $mContents;
  817. public function __construct()
  818. {
  819. $this->mContents = [];
  820. }
  821. public static function instance() {
  822. if(self::$stInstance == null) {
  823. self::$stInstance = new special_manager();
  824. }
  825. return self::$stInstance;
  826. }
  827. public function special($special_id,&$goods_ids,$pub=true)
  828. {
  829. if($pub)
  830. {
  831. if(StatesHelper::fetch_state('special')) {
  832. $this->mContents = [];
  833. }
  834. $special_id = intval($special_id);
  835. if(array_key_exists($special_id,$this->mContents)) {
  836. $data = $this->mContents[$special_id]['data'];
  837. $goods_ids = $this->mContents[$special_id]['gids'];
  838. return $data;
  839. }
  840. else
  841. {
  842. $formater = new special_formater($special_id,$this->old_version($special_id));
  843. $data = $formater->format($goods_ids);
  844. $this->mContents[$special_id]['data'] = $data;
  845. $this->mContents[$special_id]['gids'] = $goods_ids;
  846. return $data;
  847. }
  848. }
  849. else
  850. {
  851. $formater = new special_formater($special_id,$this->old_version($special_id));
  852. $specials = $formater->format($goods_ids);
  853. $result['specials'] = $specials;
  854. $result['sender_info'] = $formater->sender_info();
  855. $result['special_info'] = $formater->special_info();
  856. return $result;
  857. }
  858. }
  859. private function old_version($special_id)
  860. {
  861. global $config;
  862. if($_SESSION['is_lasted']) return false;
  863. return in_array($special_id,$config['old_specials']);
  864. }
  865. }