special_helper.php 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. $specials = $mod_special->getMbSpecialItemUsableListByID($this->special_id);
  315. if(empty($specials)) {
  316. Log::record("getMbSpecialItemUsableListByID is empty",Log::ERR);
  317. }
  318. $from_user = spid_helper::instance()->special($this->special_id)->from_user();
  319. if(array_key_exists('tabs',$specials)) {
  320. $this->tabs = $specials['tabs'];
  321. } else {
  322. $this->tabs = [];
  323. }
  324. if(isset($specials["mobile_filter_data"]))
  325. {
  326. $this->filter_data = $specials['mobile_filter_data'];
  327. $this->goods_ids = $specials['mobile_goods_ids'];
  328. if($from_user) {
  329. $this->special_info = $specials['special_info'];
  330. $this->sender_info = $specials['sender_info'];
  331. }
  332. }
  333. else
  334. {
  335. $this->filter_data = $this->filter($specials['blocks'],$goods_ids);
  336. $this->goods_ids = $goods_ids;
  337. $specials['mobile_filter_data'] = $this->filter_data;
  338. $specials['mobile_goods_ids'] = $goods_ids;
  339. if($from_user)
  340. {
  341. $special_info = $mod_special->getMbSpecialByID($this->special_id);
  342. $specials['special_info'] = $special_info;
  343. $userid = $special_info['member_id'];
  344. if($userid > 0) {
  345. $mod_member = Model('member');
  346. $sender_info = $mod_member->getMemberInfoByID($userid);
  347. $specials['sender_info'] = $sender_info;
  348. $this->sender_info = $specials['sender_info'];
  349. }
  350. $this->special_info = $specials['special_info'];
  351. }
  352. $cache = array('special' => serialize($specials));
  353. wcache($this->special_id, $cache, 'mb_special');
  354. }
  355. }
  356. private function filter($specials,&$goods_ids)
  357. {
  358. $blocks = [];
  359. $goods_ids = [];
  360. foreach($specials as $special)
  361. {
  362. $ids = [];
  363. $block = $this->filter_item($special,$ids,$scale);
  364. if($scale != false && !empty($block)) {
  365. $blocks[] = $block;
  366. $goods_ids = array_merge($goods_ids,$ids);
  367. }
  368. }
  369. $goods_ids = array_unique($goods_ids);
  370. return $blocks;
  371. }
  372. private function filter_item($special,&$goods_ids,&$scale)
  373. {
  374. $block = [];
  375. $block['item_title'] = empty($special['title']) ? '' : $special['title'];
  376. $block['item_type'] = $special['item_type'];
  377. $block['bg_image'] = $special['bg_image'];
  378. $block['bg_type'] = $special['bg_type'];
  379. $block['bg_data'] = $special['bg_data'];
  380. $block['has_margin'] = $special['has_margin'];
  381. $block_scale = false;
  382. $this->format_property($block,$block_scale);
  383. $key = $special['item_type'];
  384. if ($key == 'divider') {
  385. $scale = $block_scale;
  386. $block['scale'] = $scale;
  387. return $block;
  388. }
  389. $org_items = $special['items'];
  390. if($key != 'divider' && empty($org_items)) {
  391. return false;
  392. }
  393. $scale = false;
  394. if($key == 'adv_list' || $key == 'home3' || $key == 'home5' || $key =='home6' || $key == 'home7' || $key == 'goods')
  395. {
  396. $items = $this->filter_normal($key,$org_items,$goods_ids,$scale);
  397. if($key == 'goods') {
  398. $block['item_type'] = 'home_goods';
  399. }
  400. elseif($key == 'home3') {
  401. if($this->old_version == false) $scale = $block_scale;
  402. }
  403. elseif($key == 'home6') {
  404. $block['item_type'] = 'horizon';
  405. $scale = $block_scale;
  406. }
  407. elseif($key == 'home7') {
  408. $block['item_type'] = 'horizon_goods';
  409. $scale = $block_scale;
  410. }
  411. }
  412. elseif($key == 'home1') {
  413. $items = $this->filter_home1($org_items,$goods_ids,$scale);
  414. }
  415. elseif($key == 'home2') {
  416. $items = $this->filter_home2($org_items,$goods_ids,$scale);
  417. }
  418. elseif($key == 'home4') {
  419. $items = $this->filter_home4($org_items,$goods_ids,$scale);
  420. }
  421. elseif($key == 'home_ugc')
  422. {
  423. $items = $this->filter_home_ugc($org_items,$goods_ids);
  424. $block['items'] = $items;
  425. $scale = 1;
  426. return $block;
  427. }
  428. else {
  429. return false;
  430. }
  431. if($items == false && $key != 'divider') {
  432. return false;
  433. }
  434. $this->decode($items);
  435. foreach ($items as &$item)
  436. {
  437. if($this->image_wh($item['image'],$w,$h)) {
  438. $item['width'] = $w;
  439. $item['height'] = $h;
  440. }
  441. }
  442. $block['items'] = $items;
  443. if($block_scale) {
  444. $block['scale'] = $scale;
  445. }
  446. else {
  447. $block['scale'] = $scale;
  448. }
  449. return $block;
  450. }
  451. /**
  452. * 处理type=url 时的&字符转义问题
  453. * @param array $data
  454. * @return array|bool
  455. */
  456. private function decode(&$items)
  457. {
  458. foreach($items as &$item)
  459. {
  460. static $action_types = array('url','innerurl','video','appjump');
  461. static $show_types = array('webview','video');
  462. if(in_array($item['type'],$action_types)){
  463. $item['data'] = htmlspecialchars_decode($item['data']);
  464. }
  465. if(in_array($item['show_type'],$show_types)){
  466. $item['show_data'] = htmlspecialchars_decode($item['show_data']);
  467. }
  468. }
  469. }
  470. public static function scale($image)
  471. {
  472. $image = trim($image);
  473. if(empty($image)) {
  474. Log::record("special scale error {$image}",Log::ERR);
  475. return false;
  476. }
  477. $ret = util::imgsize($image);
  478. if($ret != false) {
  479. $scale = doubleval($ret[0]) / doubleval($ret[1]);
  480. return $scale;
  481. } else {
  482. Log::record("special scale getimagesize error {$image}",Log::ERR);
  483. return false;
  484. }
  485. }
  486. private function safe_string($str)
  487. {
  488. if($str == null || empty($str)) {
  489. return "";
  490. }
  491. else {
  492. return $str;
  493. }
  494. }
  495. private function check_goods($ids)
  496. {
  497. if(empty($ids)) return true;
  498. $ids = array_unique($ids);
  499. $mod = Model('goods');
  500. $goods = $mod->getGoodsOnlineList(array("goods_id" => array("in",$ids)));
  501. $gids = [];
  502. foreach ($goods as $item) {
  503. $gids[] = intval($item['goods_id']);
  504. }
  505. if(count($ids) == count($gids)) {
  506. return true;
  507. } else {
  508. return false;
  509. }
  510. }
  511. private function filter_home1($val,&$goods_ids,&$scale)
  512. {
  513. $items = [];
  514. $item['image'] = $val['image'];
  515. $item['type'] = $val['type'];
  516. $item['data'] = $val['data'];
  517. $item['show_type'] = $val['show_type'];
  518. $item['show_data'] = $val['show_data'];
  519. $item['reserved'] = $this->safe_string($val['reserved']);
  520. $item['title'] = $this->safe_string($val['title']);
  521. $scale = self::scale($item['image']);
  522. $ids = [];
  523. if($item['type'] == 'goods') {
  524. $ids[] = intval($item['data']);
  525. }
  526. if(self::check_goods($ids)) {
  527. $goods_ids = array_merge($goods_ids,$ids);
  528. $items[] = $item;
  529. return $items;
  530. } else {
  531. return false;
  532. }
  533. }
  534. private function filter_home_ugc($val,&$goods_ids)
  535. {
  536. $items = [];
  537. $item['image'] = $val['image'];
  538. $item['type'] = $val['type'];
  539. $item['data'] = $val['data'];
  540. $item['show_type'] = $val['show_type'];
  541. $item['show_data'] = $val['show_data'];
  542. $item['reserved'] = $this->safe_string($val['reserved']);
  543. $item['title'] = $this->safe_string($val['title']);
  544. $ids = [];
  545. if($item['type'] == 'goods') {
  546. $ids[] = intval($item['data']);
  547. }
  548. if(self::check_goods($ids)) {
  549. $goods_ids = array_merge($goods_ids,$ids);
  550. $items[] = $item;
  551. return $items;
  552. } else {
  553. return false;
  554. }
  555. }
  556. private function filter_home2($val,&$goods_ids,&$scale)
  557. {
  558. $items = [];
  559. {
  560. $item['image'] = $val['square_image'];
  561. $item['type'] = $val['square_type'];
  562. $item['data'] = $val['square_data'];
  563. $item['show_type'] = $val['square_show_type'];
  564. $item['show_data'] = $val['square_show_data'];
  565. $item['title'] = $this->safe_string($val['square_title']);
  566. $item['reserved'] = $this->safe_string($val['square_reserved']);
  567. $items[] = $item;
  568. }
  569. {
  570. $item['image'] = $val['rectangle1_image'];
  571. $item['type'] = $val['rectangle1_type'];
  572. $item['data'] = $val['rectangle1_data'];
  573. $item['show_type'] = $val['rectangle1_show_type'];
  574. $item['show_data'] = $val['rectangle1_show_data'];
  575. $item['title'] = $this->safe_string($val['rectangle1_title']);
  576. $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
  577. $items[] = $item;
  578. $scale = self::scale($item['image']);
  579. }
  580. {
  581. $item['image'] = $val['rectangle2_image'];
  582. $item['type'] = $val['rectangle2_type'];
  583. $item['data'] = $val['rectangle2_data'];
  584. $item['show_type'] = $val['rectangle2_show_type'];
  585. $item['show_data'] = $val['rectangle2_show_data'];
  586. $item['title'] = $this->safe_string($val['rectangle2_title']);
  587. $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
  588. $items[] = $item;
  589. }
  590. $ids = [];
  591. foreach ($items as $item)
  592. {
  593. if($item['type'] == 'goods') {
  594. $ids[] = intval($item['data']);
  595. }
  596. }
  597. if(self::check_goods($ids)) {
  598. $goods_ids = array_merge($goods_ids,$ids);
  599. return $items;
  600. } else {
  601. Log::record("check_goods error {$ids}",Log::ERR);
  602. return false;
  603. }
  604. }
  605. private function filter_home4($val,&$goods_ids,&$scale)
  606. {
  607. $items = [];
  608. {
  609. $item['image'] = $val['rectangle1_image'];
  610. $item['type'] = $val['rectangle1_type'];
  611. $item['data'] = $val['rectangle1_data'];
  612. $item['show_type'] = $val['rectangle1_show_type'];
  613. $item['show_data'] = $val['rectangle1_show_data'];
  614. $item['title'] = $this->safe_string($val['rectangle1_title']);
  615. $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
  616. $items[] = $item;
  617. }
  618. {
  619. $item['image'] = $val['rectangle2_image'];
  620. $item['type'] = $val['rectangle2_type'];
  621. $item['data'] = $val['rectangle2_data'];
  622. $item['show_type'] = $val['rectangle2_show_type'];
  623. $item['show_data'] = $val['rectangle2_show_data'];
  624. $item['title'] = $this->safe_string($val['rectangle2_title']);
  625. $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
  626. $scale = self::scale($item['image']);
  627. $items[] = $item;
  628. }
  629. {
  630. $item['image'] = $val['square_image'];
  631. $item['type'] = $val['square_type'];
  632. $item['data'] = $val['square_data'];
  633. $item['show_type'] = $val['square_show_type'];
  634. $item['show_data'] = $val['square_show_data'];
  635. $item['title'] = $this->safe_string($val['square_title']);
  636. $item['reserved'] = $this->safe_string($val['square_reserved']);
  637. $items[] = $item;
  638. }
  639. $ids = [];
  640. foreach ($items as $item)
  641. {
  642. if($item['type'] == 'goods') {
  643. $ids[] = intval($item['data']);
  644. }
  645. }
  646. if(self::check_goods($ids)) {
  647. $goods_ids = array_merge($goods_ids,$ids);
  648. return $items;
  649. } else {
  650. return false;
  651. }
  652. }
  653. private function image_wh($image,&$width,&$height)
  654. {
  655. $ret = util::imgsize($image);
  656. if ($ret != false) {
  657. $width = $ret[0];
  658. $height = $ret[1];
  659. return true;
  660. } else {
  661. Log::record("cannt find image imgurl={$image}",Log::ERR);
  662. return false;
  663. }
  664. }
  665. private function format_property(&$block,&$block_scale)
  666. {
  667. $image = $block['bg_image'];
  668. if(empty($image))
  669. {
  670. if($block['item_type'] == 'divider') {
  671. $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
  672. }
  673. }
  674. else {
  675. $image = getMbSpecialImageUrl($image);
  676. }
  677. $block['bg_image'] = $image;
  678. if(!empty($image)) {
  679. $block_scale = self::scale($image);
  680. } else {
  681. $block_scale = false;
  682. }
  683. if($block['bg_type'] == 'image')
  684. {
  685. if($block_scale != false) {
  686. $block['bg_data'] = $image;
  687. } else {
  688. $block['bg_data'] = '';
  689. }
  690. }
  691. else
  692. {
  693. if(empty($block['bg_data'])) {
  694. $block['bg_data'] = self::def_item_bg_color;
  695. }
  696. }
  697. unset($block['bg_image']);
  698. }
  699. private function filter_normal($block_type,$items, &$goods_ids, &$scale)
  700. {
  701. $result = [];
  702. $has_set = false;
  703. foreach($items as $item)
  704. {
  705. $item['title'] = $this->safe_string($item['title']);
  706. if($has_set == false) {
  707. $scale = self::scale($item['image']);
  708. $has_set = true;
  709. }
  710. if($item['type'] == 'goods')
  711. {
  712. $goods_id = intval($item['data']);
  713. if(self::check_goods(array($goods_id))) {
  714. array_push($goods_ids,$goods_id);
  715. $result[] = $item;
  716. } else {
  717. Log::record("block_type={$block_type} cannt find goods ,goods_id={$goods_id}",Log::ERR);
  718. continue;
  719. }
  720. }
  721. else {
  722. $result[] = $item;
  723. }
  724. }
  725. if($has_set == true)
  726. {
  727. if($block_type == 'home3') {
  728. $scale = $scale * 2;
  729. }
  730. elseif($block_type == 'goods') {
  731. $scale = 1;
  732. }
  733. }
  734. if(empty($result)) {
  735. return false;
  736. } else {
  737. return $result;
  738. }
  739. }
  740. }
  741. class spid_item
  742. {
  743. private $mFromUser;
  744. private $mHasVote;
  745. private $mShareImage;
  746. private $mShareTitle;
  747. public function __construct($item)
  748. {
  749. $special = new ugc\special($item);
  750. $this->mFromUser = $special->from_user();
  751. $this->mHasVote = $special->has_vote();
  752. $this->mShareImage = $special->share_img();
  753. $this->mShareTitle = $special->share_title();
  754. }
  755. public function from_user() {
  756. return $this->mFromUser;
  757. }
  758. public function has_vote() {
  759. return $this->mHasVote;
  760. }
  761. public function share_image() {
  762. return $this->mShareImage;
  763. }
  764. public function share_title() {
  765. return $this->mShareTitle;
  766. }
  767. }
  768. class spid_helper
  769. {
  770. private static $stInstance = null;
  771. private $mContents;
  772. public function __construct() {
  773. $this->mContents = [];
  774. $this->add_home();
  775. }
  776. public static function instance() {
  777. if(self::$stInstance == null) {
  778. self::$stInstance = new spid_helper();
  779. }
  780. return self::$stInstance;
  781. }
  782. //home page is not in mb_special table.
  783. private function add_home()
  784. {
  785. $item['from_user'] = 0;
  786. $item['share_image'] = "";
  787. $item['share_title'] = "";
  788. $spitem = new spid_item($item);
  789. $this->mContents[0] = $spitem;
  790. }
  791. public function special($spid)
  792. {
  793. $spid = intval($spid);
  794. if(array_key_exists($spid,$this->mContents)) {
  795. return $this->mContents[$spid];
  796. }
  797. else
  798. {
  799. $item = $this->read($spid);
  800. if($item == false) {
  801. return false;
  802. } else {
  803. $this->mContents[$spid] = $item;
  804. return $item;
  805. }
  806. }
  807. }
  808. private function read($spid)
  809. {
  810. $mod_special = Model('mb_special');
  811. $item = $mod_special->getMbSpecialByID($spid);
  812. if(empty($item)) {
  813. return false;
  814. }
  815. else
  816. {
  817. $spitem = new spid_item($item);
  818. return $spitem;
  819. }
  820. }
  821. }
  822. class special_manager
  823. {
  824. private static $stInstance = null;
  825. private $mContents;
  826. public function __construct()
  827. {
  828. $this->mContents = [];
  829. }
  830. public static function instance() {
  831. if(self::$stInstance == null) {
  832. self::$stInstance = new special_manager();
  833. }
  834. return self::$stInstance;
  835. }
  836. public function tabs($special_id)
  837. {
  838. if (array_key_exists($special_id, $this->mContents)) {
  839. return $this->mContents[$special_id]['tabs'];
  840. } else {
  841. return [];
  842. }
  843. }
  844. public function special($special_id,&$goods_ids,$pub=true)
  845. {
  846. if($pub)
  847. {
  848. if(StatesHelper::fetch_state('special')) {
  849. $this->mContents = [];
  850. }
  851. $special_id = intval($special_id);
  852. if(array_key_exists($special_id,$this->mContents)) {
  853. $data = $this->mContents[$special_id]['data'];
  854. $goods_ids = $this->mContents[$special_id]['gids'];
  855. return $data;
  856. }
  857. else
  858. {
  859. $formater = new special_formater($special_id,$this->old_version($special_id));
  860. $data = $formater->format($goods_ids);
  861. $this->mContents[$special_id]['data'] = $data;
  862. $this->mContents[$special_id]['gids'] = $goods_ids;
  863. $this->mContents[$special_id]['tabs'] = $formater->tabs();
  864. return $data;
  865. }
  866. }
  867. else
  868. {
  869. $formater = new special_formater($special_id,$this->old_version($special_id));
  870. $specials = $formater->format($goods_ids);
  871. $result['specials'] = $specials;
  872. $result['sender_info'] = $formater->sender_info();
  873. $result['special_info'] = $formater->special_info();
  874. return $result;
  875. }
  876. }
  877. private function old_version($special_id)
  878. {
  879. global $config;
  880. if($_SESSION['is_lasted']) return false;
  881. return in_array($special_id,$config['old_specials']);
  882. }
  883. }