special_helper.php 29 KB

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