special_helper.php 30 KB

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