special_helper.php 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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 brands_special()
  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 array();
  114. $helper = new brands_special();
  115. $info = $helper->info($brand_id);
  116. if($info == false) return array();
  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 array();
  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 array();
  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'] = 'web';
  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 = array('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 = array('url','innerurl','video','appjump');
  486. static $show_types = array('webview','video');
  487. if(in_array($item['type'],$action_types)){
  488. $item['data'] = htmlspecialchars_decode($item['data']);
  489. }
  490. if(in_array($item['show_type'],$show_types)){
  491. $item['show_data'] = htmlspecialchars_decode($item['show_data']);
  492. }
  493. }
  494. }
  495. public static function scale($image)
  496. {
  497. $image = trim($image);
  498. if(empty($image)) {
  499. Log::record("special scale error {$image}",Log::ERR);
  500. return false;
  501. }
  502. $ret = util::imgsize($image);
  503. if($ret != false) {
  504. $scale = doubleval($ret[0]) / doubleval($ret[1]);
  505. return $scale;
  506. } else {
  507. Log::record("special scale getimagesize error {$image}",Log::ERR);
  508. return false;
  509. }
  510. }
  511. private function safe_string($str)
  512. {
  513. if($str == null || empty($str)) {
  514. return "";
  515. }
  516. else {
  517. return $str;
  518. }
  519. }
  520. private function check_goods($ids)
  521. {
  522. if(empty($ids)) return true;
  523. $ids = array_unique($ids);
  524. $mod = Model('goods');
  525. $goods = $mod->getGoodsOnlineList(array("goods_id" => array("in",$ids)));
  526. $gids = [];
  527. foreach ($goods as $item) {
  528. $gids[] = intval($item['goods_id']);
  529. }
  530. if(count($ids) == count($gids)) {
  531. return true;
  532. } else {
  533. return false;
  534. }
  535. }
  536. private function filter_home1($val,&$goods_ids,&$scale)
  537. {
  538. $items = [];
  539. $item['image'] = $val['image'];
  540. $item['type'] = $val['type'];
  541. $item['data'] = $val['data'];
  542. $item['show_type'] = $val['show_type'];
  543. $item['show_data'] = $val['show_data'];
  544. $item['reserved'] = $this->safe_string($val['reserved']);
  545. $item['title'] = $this->safe_string($val['title']);
  546. $scale = self::scale($item['image']);
  547. $ids = [];
  548. if($item['type'] == 'goods') {
  549. $ids[] = intval($item['data']);
  550. }
  551. if(self::check_goods($ids)) {
  552. $goods_ids = array_merge($goods_ids,$ids);
  553. $items[] = $item;
  554. return $items;
  555. } else {
  556. return false;
  557. }
  558. }
  559. private function filter_home_ugc($val,&$goods_ids)
  560. {
  561. $items = [];
  562. $item['image'] = $val['image'];
  563. $item['type'] = $val['type'];
  564. $item['data'] = $val['data'];
  565. $item['show_type'] = $val['show_type'];
  566. $item['show_data'] = $val['show_data'];
  567. $item['reserved'] = $this->safe_string($val['reserved']);
  568. $item['title'] = $this->safe_string($val['title']);
  569. $ids = [];
  570. if($item['type'] == 'goods') {
  571. $ids[] = intval($item['data']);
  572. }
  573. if(self::check_goods($ids)) {
  574. $goods_ids = array_merge($goods_ids,$ids);
  575. $items[] = $item;
  576. return $items;
  577. } else {
  578. return false;
  579. }
  580. }
  581. private function filter_home2($val,&$goods_ids,&$scale)
  582. {
  583. $items = [];
  584. {
  585. $item['image'] = $val['square_image'];
  586. $item['type'] = $val['square_type'];
  587. $item['data'] = $val['square_data'];
  588. $item['show_type'] = $val['square_show_type'];
  589. $item['show_data'] = $val['square_show_data'];
  590. $item['title'] = $this->safe_string($val['square_title']);
  591. $item['reserved'] = $this->safe_string($val['square_reserved']);
  592. $items[] = $item;
  593. }
  594. {
  595. $item['image'] = $val['rectangle1_image'];
  596. $item['type'] = $val['rectangle1_type'];
  597. $item['data'] = $val['rectangle1_data'];
  598. $item['show_type'] = $val['rectangle1_show_type'];
  599. $item['show_data'] = $val['rectangle1_show_data'];
  600. $item['title'] = $this->safe_string($val['rectangle1_title']);
  601. $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
  602. $items[] = $item;
  603. $scale = self::scale($item['image']);
  604. }
  605. {
  606. $item['image'] = $val['rectangle2_image'];
  607. $item['type'] = $val['rectangle2_type'];
  608. $item['data'] = $val['rectangle2_data'];
  609. $item['show_type'] = $val['rectangle2_show_type'];
  610. $item['show_data'] = $val['rectangle2_show_data'];
  611. $item['title'] = $this->safe_string($val['rectangle2_title']);
  612. $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
  613. $items[] = $item;
  614. }
  615. $ids = [];
  616. foreach ($items as $item)
  617. {
  618. if($item['type'] == 'goods') {
  619. $ids[] = intval($item['data']);
  620. }
  621. }
  622. if(self::check_goods($ids)) {
  623. $goods_ids = array_merge($goods_ids,$ids);
  624. return $items;
  625. } else {
  626. Log::record("check_goods error {$ids}",Log::ERR);
  627. return false;
  628. }
  629. }
  630. private function filter_home4($val,&$goods_ids,&$scale)
  631. {
  632. $items = [];
  633. {
  634. $item['image'] = $val['rectangle1_image'];
  635. $item['type'] = $val['rectangle1_type'];
  636. $item['data'] = $val['rectangle1_data'];
  637. $item['show_type'] = $val['rectangle1_show_type'];
  638. $item['show_data'] = $val['rectangle1_show_data'];
  639. $item['title'] = $this->safe_string($val['rectangle1_title']);
  640. $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
  641. $items[] = $item;
  642. }
  643. {
  644. $item['image'] = $val['rectangle2_image'];
  645. $item['type'] = $val['rectangle2_type'];
  646. $item['data'] = $val['rectangle2_data'];
  647. $item['show_type'] = $val['rectangle2_show_type'];
  648. $item['show_data'] = $val['rectangle2_show_data'];
  649. $item['title'] = $this->safe_string($val['rectangle2_title']);
  650. $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
  651. $scale = self::scale($item['image']);
  652. $items[] = $item;
  653. }
  654. {
  655. $item['image'] = $val['square_image'];
  656. $item['type'] = $val['square_type'];
  657. $item['data'] = $val['square_data'];
  658. $item['show_type'] = $val['square_show_type'];
  659. $item['show_data'] = $val['square_show_data'];
  660. $item['title'] = $this->safe_string($val['square_title']);
  661. $item['reserved'] = $this->safe_string($val['square_reserved']);
  662. $items[] = $item;
  663. }
  664. $ids = [];
  665. foreach ($items as $item)
  666. {
  667. if($item['type'] == 'goods') {
  668. $ids[] = intval($item['data']);
  669. }
  670. }
  671. if(self::check_goods($ids)) {
  672. $goods_ids = array_merge($goods_ids,$ids);
  673. return $items;
  674. } else {
  675. return false;
  676. }
  677. }
  678. private function image_wh($image,&$width,&$height)
  679. {
  680. $ret = util::imgsize($image);
  681. if ($ret != false) {
  682. $width = $ret[0];
  683. $height = $ret[1];
  684. return true;
  685. } else {
  686. Log::record("cannt find image imgurl={$image}",Log::ERR);
  687. return false;
  688. }
  689. }
  690. private function format_property(&$block,&$block_scale)
  691. {
  692. $image = $block['bg_image'];
  693. if(empty($image))
  694. {
  695. if($block['item_type'] == 'divider') {
  696. $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
  697. }
  698. }
  699. else {
  700. $image = getMbSpecialImageUrl($image);
  701. }
  702. $block['bg_image'] = $image;
  703. if(!empty($image)) {
  704. $block_scale = self::scale($image);
  705. } else {
  706. $block_scale = false;
  707. }
  708. if($block['bg_type'] == 'image')
  709. {
  710. if($block_scale != false) {
  711. $block['bg_data'] = $image;
  712. } else {
  713. $block['bg_data'] = '';
  714. }
  715. }
  716. else
  717. {
  718. if(empty($block['bg_data'])) {
  719. $block['bg_data'] = self::def_item_bg_color;
  720. }
  721. }
  722. unset($block['bg_image']);
  723. }
  724. private function filter_normal($block_type,$items, &$goods_ids, &$scale)
  725. {
  726. $result = [];
  727. $has_set = false;
  728. foreach($items as $item)
  729. {
  730. $item['title'] = $this->safe_string($item['title']);
  731. if($has_set == false) {
  732. $scale = self::scale($item['image']);
  733. $has_set = true;
  734. }
  735. if($item['type'] == 'goods')
  736. {
  737. $goods_id = intval($item['data']);
  738. if(self::check_goods(array($goods_id))) {
  739. array_push($goods_ids,$goods_id);
  740. $result[] = $item;
  741. } else {
  742. Log::record("block_type={$block_type} cannt find goods ,goods_id={$goods_id}",Log::ERR);
  743. continue;
  744. }
  745. }
  746. else {
  747. $result[] = $item;
  748. }
  749. }
  750. if($has_set == true)
  751. {
  752. if($block_type == 'home3') {
  753. $scale = $scale * 2;
  754. }
  755. elseif($block_type == 'goods') {
  756. $scale = 1;
  757. }
  758. }
  759. if(empty($result)) {
  760. return false;
  761. } else {
  762. return $result;
  763. }
  764. }
  765. }
  766. class spid_item
  767. {
  768. private $mFromUser;
  769. private $mHasVote;
  770. private $mShareImage;
  771. private $mShareTitle;
  772. public function __construct($item)
  773. {
  774. $special = new ugc\special($item);
  775. $this->mFromUser = $special->from_user();
  776. $this->mHasVote = $special->has_vote();
  777. $this->mShareImage = $special->share_img();
  778. $this->mShareTitle = $special->share_title();
  779. }
  780. public function from_user() {
  781. return $this->mFromUser;
  782. }
  783. public function has_vote() {
  784. return $this->mHasVote;
  785. }
  786. public function share_image() {
  787. return $this->mShareImage;
  788. }
  789. public function share_title() {
  790. return $this->mShareTitle;
  791. }
  792. }
  793. class spid_helper
  794. {
  795. private static $stInstance = null;
  796. private $mContents;
  797. public function __construct() {
  798. $this->mContents = [];
  799. $this->add_home();
  800. }
  801. public static function instance() {
  802. if(self::$stInstance == null) {
  803. self::$stInstance = new spid_helper();
  804. }
  805. return self::$stInstance;
  806. }
  807. //home page is not in mb_special table.
  808. private function add_home()
  809. {
  810. $item['from_user'] = 0;
  811. $item['share_image'] = "";
  812. $item['share_title'] = "";
  813. $spitem = new spid_item($item);
  814. $this->mContents[0] = $spitem;
  815. }
  816. public function special($spid)
  817. {
  818. $spid = intval($spid);
  819. if(array_key_exists($spid,$this->mContents)) {
  820. return $this->mContents[$spid];
  821. }
  822. else
  823. {
  824. $item = $this->read($spid);
  825. if($item == false) {
  826. return false;
  827. } else {
  828. $this->mContents[$spid] = $item;
  829. return $item;
  830. }
  831. }
  832. }
  833. private function read($spid)
  834. {
  835. $mod_special = Model('mb_special');
  836. $item = $mod_special->getMbSpecialByID($spid);
  837. if(empty($item)) {
  838. return false;
  839. }
  840. else
  841. {
  842. $spitem = new spid_item($item);
  843. return $spitem;
  844. }
  845. }
  846. }
  847. class special_manager
  848. {
  849. private static $stInstance = null;
  850. private $mContents;
  851. public function __construct()
  852. {
  853. $this->mContents = [];
  854. }
  855. public static function instance() {
  856. if(self::$stInstance == null) {
  857. self::$stInstance = new special_manager();
  858. }
  859. return self::$stInstance;
  860. }
  861. public function tabs($special_id)
  862. {
  863. if (array_key_exists($special_id, $this->mContents)) {
  864. return $this->mContents[$special_id]['tabs'];
  865. } else {
  866. return [];
  867. }
  868. }
  869. public function special($special_id,&$goods_ids,$pub=true)
  870. {
  871. if($pub)
  872. {
  873. if(StatesHelper::fetch_state('special')) {
  874. $this->mContents = [];
  875. }
  876. $special_id = intval($special_id);
  877. if(array_key_exists($special_id,$this->mContents)) {
  878. $data = $this->mContents[$special_id]['data'];
  879. $goods_ids = $this->mContents[$special_id]['gids'];
  880. return $data;
  881. }
  882. else
  883. {
  884. $formater = new special_formater($special_id,$this->old_version($special_id));
  885. $data = $formater->format($goods_ids);
  886. $this->mContents[$special_id]['data'] = $data;
  887. $this->mContents[$special_id]['gids'] = $goods_ids;
  888. $this->mContents[$special_id]['tabs'] = $formater->tabs();
  889. return $data;
  890. }
  891. }
  892. else
  893. {
  894. $formater = new special_formater($special_id,$this->old_version($special_id));
  895. $specials = $formater->format($goods_ids);
  896. $result['specials'] = $specials;
  897. $result['sender_info'] = $formater->sender_info();
  898. $result['special_info'] = $formater->special_info();
  899. return $result;
  900. }
  901. }
  902. private function old_version($special_id)
  903. {
  904. global $config;
  905. if($_SESSION['is_lasted'] || empty($config['old_specials'])) return false;
  906. return in_array($special_id,$config['old_specials']);
  907. }
  908. }