<?php

/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 16/6/16
 * Time: 下午2:07
 */
//将乱七八糟的格式输出，整合成统一的格式输出

require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');

class brands_special
{
    const publish_brands_special = 56;
    const local_brands_special = 50;
    const test_brands_special = 56;

    static private $stBImgContianers;

    public function brands_special()
    {
        if(self::$stBImgContianers == null) {
            self::$stBImgContianers = [];
            $this->init();
        }
    }

    public function info($brand_id)
    {
        if(isset(self::$stBImgContianers[$brand_id])) {
            return self::$stBImgContianers[$brand_id];
        } else {
            return false;
        }
    }

    private function init()
    {
        $special_id = self::special_id();
        if($special_id == false) return false;

        $helper = new special_formater($special_id);
        $blocks = $helper->format($goods_ids);

        foreach ($blocks as $block)
        {
            $items = $block['items'];
            if(empty($items) || is_array($items) == false) continue;

            foreach ($items as $item)
            {
                $brand_id = intval($item['data']);
                $data = $item;
                $data['scale'] = $block['scale'];

                self::$stBImgContianers[$brand_id] = $data;
            }
            if(!empty($items) && is_array($items)) {

            }
        }
    }

    private static function special_id()
    {
        if (is_pushoms()) {
            return self::publish_brands_special;
        }
        elseif(is_localdebug()) {
            return self::local_brands_special;
        }
        else {
            return self::test_brands_special;
        }
    }
}

class special_formater
{
    const def_item_bg_color = '#F7F7F7';
    const def_item_bg_type  = 'color';
    const def_divider_bg_img= '/mobile/defimg/divider_bg.png';

    private $special_id;
    private $filter_data;
    private $goods_ids;
    private $special_info;
    private $sender_info;
    private $tabs;

    private $old_version;

    public function __construct($special_id,$old_version = false)
    {
        $this->special_id = $special_id;
        $this->old_version = $old_version;
        $this->special_info = [];
        $this->sender_info = [];
        $this->read_cache();
    }
    public function special_info() {
        return $this->special_info;
    }
    public function sender_info() {
        return $this->sender_info;
    }
    public function tabs() {
        return $this->tabs;
    }

    public static function def_divider()
    {
        static $block = [];
        if(empty($block))
        {
            $block['item_type'] = 'divider';
            $block['item_title'] = '';
            $block['bg_type'] = 'image';
            $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
            $block['bg_data'] = $image;
            $block['has_margin'] = false;
            $block['scale'] = self::scale($image);
        }
        return $block;
    }

    public static function format_brand_sale($brand_id,$can_click)
    {
        if($brand_id <= 0) return array();

        $helper = new brands_special();
        $info = $helper->info($brand_id);
        if($info == false) return array();

        $result['item_title'] = '';
        $result['item_type'] = 'home1';
        $result['scale'] = $info['scale'];

        $item['image'] = $info['image'];
        $item['type']  = $info['type'];
        if($can_click == true) {
            $item['data']  = $info['data'];
        } else {
            $item['data']  = 0;
        }

        $item['title'] = $info['title'];
        $result['items'][] = $item;

        return $result;
    }
    public static function format_grid_brands($brands)
    {
        $result = [];
        $result['item_title'] = '';
        $result['item_type'] = 'home_grid';
        $result['scale'] = 3;

        $items = [];
        foreach ($brands as $brand) {
            $item['image'] = $brand['brand_logo'];
            $item['type']  = 'brand';
            $item['data']  = $brand['brand_id'];
            $item['title'] = $brand['brand_name'];
            $items[] = $item;
        }
        $result['items'] = $items;

        return $result;
    }
    public static function format_comments($comments)
    {
        $blocks = [];
        foreach ($comments as $val)
        {
            $block = [];
            $block['item_title'] = '';
            $block['item_type'] = 'home_comment';
            $block['scale'] = 1;

            $item['image'] = '';
            $item['type']  = 'comment';
            $item['data']  = intval($val['geval_id']);
            $item['title'] = $val['geval_goodsname'];
            $items[] = $item;

            $block['items'] = $items;
            $blocks[] = $block;
        }

        return $blocks;
    }

    public static function format_brand($brands)
    {
        if(empty($brands)) return array();

        if(count($brands) == 1)
        {
            $brand_id = intval($brands[0]['data']);
            return self::format_brand_sale($brand_id,true);
        }
        else
        {
            $result = [];
            $result['item_title'] = '';
            $result['item_type'] = 'homewords';

            foreach ($brands as $val) {
                $item['image'] = "";
                $item['type'] = $val['type'];
                $item['data'] = strval($val['data']);
                $item['title'] = $val['title'];

                $result['items'][] = $item;
            }

            return $result;
        }
    }

    public static function format_category($cats,$title = '')
    {
        if(empty($cats)) return array();

        $result = [];
        $result['item_title'] = $title;
        $result['item_type'] = 'homewords';

        foreach ($cats as $val) {
            $item['image'] = "";
            $item['type'] = $val['type'];
            $item['data'] = strval($val['data']);
            $item['title'] = $val['title'];

            $result['items'][] = $item;
        }

        return $result;
    }

    public static function format_keyword($words,$title='')
    {
        $result = [];

        $result['item_title'] = $title;
        $result['item_type'] = 'homewords';

        foreach ($words as $word) {
            $item['image'] = "";
            $item['type'] = 'keyword';
            $item['data'] = $word;
            $item['title'] = $word;

            $result['items'][] = $item;
        }

        return $result;
    }

    public static function format_ugc(ugc\special $special)
    {
        $special_id = $special->special_id();
        $url = BASE_SITE_URL . "/mobile/index.php?act=special&op=index&client_type=wap&special_id={$special_id}";

        $result = [];

        $result['item_title'] = $special->share_title();
        $result['item_type'] = 'home1';

        $item['show_type'] = 'ugc';
        $item['show_data'] = $special_id;
        $item['image'] = $special->share_img();
        $item['type'] = 'url';
        $item['data'] = $url;
        $item['title'] = $special->share_title();

        $result['items'][] = $item;

        return $result;
    }

    public static function format_bonus($bonuses,$title='')
    {
        $result = [];

        $result['item_title'] = $title;
        $result['item_type'] = 'home_bonus';

        foreach ($bonuses as $bonus) {
            $item['image'] = "";
            $item['type'] = 'bonus';
            $item['data'] = $bonus['bonus_sn'];
            $item['title'] = '';

            $result['items'][] = $item;
        }

        return $result;
    }

    public static function format_type($type_infos,$title='')
    {
        $result = [];

        $result['item_title'] = $title;
        $result['item_type'] = 'home_type';

        foreach ($type_infos as $type) {
            $item['image'] = "";
            $item['type'] = 'bonus_type';
            $item['data'] = $type['type_sn'];
            $item['title'] = '';

            $result['items'][] = $item;
        }

        return $result;
    }

    public static function format_goods($goods_ids,$title,$sort_summary)
    {
        $result = [];

        $result['item_title'] = empty($title) ? '' : $title;
        $result['item_type'] = 'home_goods';

        foreach ($goods_ids as $goods_id)
        {
            $summary = $sort_summary[$goods_id];
            $item['image'] = $summary['goods_image_url'];
            $item['show_type'] = 'goods';
            $item['show_data'] = strval($goods_id);
            $item['type'] = 'goods';
            $item['data'] = strval($goods_id);
            $item['title'] = $summary['goods_mobile_name'];
            $result['items'][] = $item;
        }

        return $result;
    }

    public static function format_ugc_goods($goods_ids,$title,$sort_summary)
    {
        $blocks = [];

        $count = count($goods_ids);
        $i = 1;
        foreach ($goods_ids as $goods_id)
        {
            $block = [];
            $block['item_title'] = empty($title) ? '' : $title;
            $block['item_type'] = 'home1';

            $summary = $sort_summary[$goods_id];
            $item['image'] = $summary['goods_image_url'];
            $item['show_type'] = 'goods_ugc';
            $item['show_data'] = strval($goods_id);
            $item['type'] = 'goods';
            $item['data'] = strval($goods_id);
            $item['title'] = $summary['goods_mobile_name'];
            $block['items'][] = $item;
            $blocks[] = $block;

            if($i != $count) {
                $blocks[] = self::def_divider();
            }
        }

        return $blocks;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public function format(&$goods_ids)
    {
        $goods_ids = $this->goods_ids;
        return $this->filter_data;
    }

    private function read_cache()
    {
        $mod_special = Model('mb_special');

        if($this->special_id > 0)
        {
            $special = $mod_special->getMbSpecialByID($this->special_id);
            if(empty($special)) {
                return false;
            }
        }

        $sp_items = $mod_special->getMbSpecialItemUsableListByID($this->special_id);
        if(empty($sp_items)) {
            Log::record("getMbSpecialItemUsableListByID is empty",Log::ERR);
            return false;
        }

        $from_user = spid_helper::instance()->special($this->special_id)->from_user();
        if(array_key_exists('tabs',$sp_items)) {
            $this->tabs = $sp_items['tabs'];
        } else {
            $this->tabs = [];
        }

        if(isset($sp_items["mobile_filter_data"]))
        {
            $this->filter_data = $sp_items['mobile_filter_data'];
            $this->goods_ids   = $sp_items['mobile_goods_ids'];
            if($from_user) {
                $this->special_info = $sp_items['special_info'];
                $this->sender_info = $sp_items['sender_info'];
            }
        }
        else
        {
            $this->filter_data = $this->filter($sp_items['blocks'],$goods_ids);
            $this->goods_ids = $goods_ids;

            $sp_items['mobile_filter_data'] = $this->filter_data;
            $sp_items['mobile_goods_ids'] = $goods_ids;
            if($from_user)
            {
                $special_info = $mod_special->getMbSpecialByID($this->special_id);
                $sp_items['special_info'] = $special_info;
                $userid = $special_info['member_id'];
                if($userid > 0) {
                    $mod_member = Model('member');
                    $sender_info = $mod_member->getMemberInfoByID($userid);
                    $sp_items['sender_info'] = $sender_info;
                    $this->sender_info = $sp_items['sender_info'];
                }
                $this->special_info = $sp_items['special_info'];
            }
            $cache = array('special' => serialize($sp_items));

            wcache($this->special_id, $cache, 'mb_special');
        }
    }

    private function filter($specials,&$goods_ids)
    {
        $blocks = [];
        $goods_ids = [];
        foreach($specials as $special)
        {
            $ids = [];
            $block = $this->filter_item($special,$ids,$scale);
            if($scale != false && !empty($block)) {
                $blocks[] = $block;
                $goods_ids = array_merge($goods_ids,$ids);
            }
        }
        $goods_ids = array_unique($goods_ids);

        return $blocks;
    }

    private function filter_item($special,&$goods_ids,&$scale)
    {
        $block = [];
        $block['item_title'] = empty($special['title']) ? '' : $special['title'];
        $block['item_type'] = $special['item_type'];

        $block['bg_image'] = $special['bg_image'];
        $block['bg_type']  = $special['bg_type'];
        $block['bg_data']  = $special['bg_data'];
        $block['has_margin']  = $special['has_margin'];
        $block_scale = false;
        $this->format_property($block,$block_scale);

        $key = $special['item_type'];

        if ($key == 'divider') {
            $scale = $block_scale;
            $block['scale'] = $scale;
            return $block;
        }

        $org_items = $special['items'];
        if($key != 'divider' && empty($org_items)) {
            return false;
        }

        $scale = false;
        if($key == 'adv_list' || $key == 'home3' || $key == 'home5' || $key =='home6' || $key == 'home7' || $key == 'goods')
        {
            $items = $this->filter_normal($key,$org_items,$goods_ids,$scale);
            if($key == 'goods') {
                $block['item_type'] = 'home_goods';
            }
            elseif($key == 'home3') {
                if($this->old_version == false) $scale = $block_scale;
            }
            elseif($key == 'home6') {
                $block['item_type'] = 'horizon';
                $scale = $block_scale;
            }
            elseif($key == 'home7') {
                $block['item_type'] = 'horizon_goods';
                $scale = $block_scale;
            }
        }
        elseif($key == 'home1') {
            $items = $this->filter_home1($org_items,$goods_ids,$scale);
        }
        elseif($key == 'home2') {
            $items = $this->filter_home2($org_items,$goods_ids,$scale);
        }
        elseif($key == 'home4') {
            $items = $this->filter_home4($org_items,$goods_ids,$scale);
        }
        elseif($key == 'home_ugc')
        {
            $items = $this->filter_home_ugc($org_items,$goods_ids);
            $block['items'] = $items;
            $scale = 1;
            return $block;
        }
        else {
            return false;
        }

        if($items == false && $key != 'divider') {
            return false;
        }

        $this->decode($items);
        foreach ($items as &$item)
        {
            if($this->image_wh($item['image'],$w,$h)) {
                $item['width']  = $w;
                $item['height'] = $h;
            }
        }

        $block['items'] = $items;
        if($block_scale) {
            $block['scale'] = $scale;
        }
        else {
            $block['scale'] = $scale;
        }

        return $block;
    }

    /**
     * 处理type=url 时的&字符转义问题
     * @param array $data
     * @return array|bool
     */
    private function decode(&$items)
    {
        foreach($items as &$item)
        {
            static $action_types = array('url','innerurl','video','appjump');
            static $show_types = array('webview','video');

            if(in_array($item['type'],$action_types)){
                $item['data'] =  htmlspecialchars_decode($item['data']);
            }

            if(in_array($item['show_type'],$show_types)){
                $item['show_data'] =  htmlspecialchars_decode($item['show_data']);
            }
        }
    }

    public static function scale($image)
    {
        $image = trim($image);
        if(empty($image)) {
            Log::record("special scale error {$image}",Log::ERR);
            return false;
        }

        $ret = util::imgsize($image);
        if($ret != false) {
            $scale = doubleval($ret[0]) / doubleval($ret[1]);
            return $scale;
        } else {
            Log::record("special scale getimagesize error {$image}",Log::ERR);
            return false;
        }
    }

    private function safe_string($str)
    {
        if($str == null || empty($str)) {
            return "";
        }
        else {
            return $str;
        }
    }

    private function check_goods($ids)
    {
        if(empty($ids)) return true;

        $ids = array_unique($ids);
        $mod = Model('goods');
        $goods = $mod->getGoodsOnlineList(array("goods_id" => array("in",$ids)));

        $gids = [];
        foreach ($goods as $item) {
            $gids[] = intval($item['goods_id']);
        }
        if(count($ids) == count($gids)) {
            return true;
        } else {
            return false;
        }
    }

    private function filter_home1($val,&$goods_ids,&$scale)
    {
        $items = [];

        $item['image'] = $val['image'];
        $item['type']  = $val['type'];
        $item['data']  = $val['data'];
        $item['show_type']  = $val['show_type'];
        $item['show_data']  = $val['show_data'];
        $item['reserved']   = $this->safe_string($val['reserved']);
        $item['title']  = $this->safe_string($val['title']);
        $scale = self::scale($item['image']);

        $ids = [];
        if($item['type'] == 'goods') {
            $ids[] = intval($item['data']);
        }

        if(self::check_goods($ids)) {
            $goods_ids = array_merge($goods_ids,$ids);
            $items[] = $item;
            return $items;
        } else {
            return false;
        }
    }

    private function filter_home_ugc($val,&$goods_ids)
    {
        $items = [];

        $item['image'] = $val['image'];
        $item['type']  = $val['type'];
        $item['data']  = $val['data'];
        $item['show_type']  = $val['show_type'];
        $item['show_data']  = $val['show_data'];
        $item['reserved']   = $this->safe_string($val['reserved']);
        $item['title']  = $this->safe_string($val['title']);

        $ids = [];
        if($item['type'] == 'goods') {
            $ids[] = intval($item['data']);
        }

        if(self::check_goods($ids)) {
            $goods_ids = array_merge($goods_ids,$ids);
            $items[] = $item;
            return $items;
        } else {
            return false;
        }
    }

    private function filter_home2($val,&$goods_ids,&$scale)
    {
        $items = [];
        {
            $item['image'] =  $val['square_image'];
            $item['type']  =  $val['square_type'];
            $item['data']  =  $val['square_data'];
            $item['show_type']  = $val['square_show_type'];
            $item['show_data']  = $val['square_show_data'];
            $item['title'] =  $this->safe_string($val['square_title']);
            $item['reserved']  = $this->safe_string($val['square_reserved']);
            $items[] = $item;
        }

        {
            $item['image'] = $val['rectangle1_image'];
            $item['type'] = $val['rectangle1_type'];
            $item['data'] = $val['rectangle1_data'];
            $item['show_type']  = $val['rectangle1_show_type'];
            $item['show_data']  = $val['rectangle1_show_data'];
            $item['title'] = $this->safe_string($val['rectangle1_title']);
            $item['reserved']  = $this->safe_string($val['rectangle1_reserved']);

            $items[] = $item;
            $scale = self::scale($item['image']);
        }
        {
            $item['image'] = $val['rectangle2_image'];
            $item['type'] = $val['rectangle2_type'];
            $item['data'] = $val['rectangle2_data'];
            $item['show_type']  = $val['rectangle2_show_type'];
            $item['show_data']  = $val['rectangle2_show_data'];
            $item['title'] = $this->safe_string($val['rectangle2_title']);
            $item['reserved']  = $this->safe_string($val['rectangle2_reserved']);

            $items[] = $item;
        }

        $ids = [];
        foreach ($items as $item)
        {
            if($item['type'] == 'goods') {
                $ids[] = intval($item['data']);
            }
        }

        if(self::check_goods($ids)) {
            $goods_ids = array_merge($goods_ids,$ids);
            return $items;
        } else {
            Log::record("check_goods error {$ids}",Log::ERR);
            return false;
        }
    }

    private function filter_home4($val,&$goods_ids,&$scale)
    {
        $items = [];
        {
            $item['image'] = $val['rectangle1_image'];
            $item['type'] = $val['rectangle1_type'];
            $item['data'] = $val['rectangle1_data'];
            $item['show_type']  = $val['rectangle1_show_type'];
            $item['show_data']  = $val['rectangle1_show_data'];
            $item['title'] = $this->safe_string($val['rectangle1_title']);
            $item['reserved']  = $this->safe_string($val['rectangle1_reserved']);

            $items[] = $item;
        }
        {
            $item['image'] = $val['rectangle2_image'];
            $item['type'] = $val['rectangle2_type'];
            $item['data'] = $val['rectangle2_data'];
            $item['show_type']  = $val['rectangle2_show_type'];
            $item['show_data']  = $val['rectangle2_show_data'];
            $item['title'] = $this->safe_string($val['rectangle2_title']);
            $item['reserved']  = $this->safe_string($val['rectangle2_reserved']);

            $scale = self::scale($item['image']);
            $items[] = $item;
        }
        {
            $item['image'] = $val['square_image'];
            $item['type'] = $val['square_type'];
            $item['data'] = $val['square_data'];
            $item['show_type']  = $val['square_show_type'];
            $item['show_data']  = $val['square_show_data'];
            $item['title'] = $this->safe_string($val['square_title']);
            $item['reserved']  = $this->safe_string($val['square_reserved']);

            $items[] = $item;
        }

        $ids = [];
        foreach ($items as $item)
        {
            if($item['type'] == 'goods') {
                $ids[] = intval($item['data']);
            }
        }

        if(self::check_goods($ids)) {
            $goods_ids = array_merge($goods_ids,$ids);
            return $items;
        } else {
            return false;
        }
    }

    private function image_wh($image,&$width,&$height)
    {
        $ret = util::imgsize($image);
        if ($ret != false) {
            $width  = $ret[0];
            $height = $ret[1];
            return true;
        } else {
            Log::record("cannt find image imgurl={$image}",Log::ERR);
            return false;
        }
    }

    private function format_property(&$block,&$block_scale)
    {
        $image = $block['bg_image'];
        if(empty($image))
        {
            if($block['item_type'] == 'divider') {
                $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
            }
        }
        else {
            $image = getMbSpecialImageUrl($image);
        }
        $block['bg_image'] = $image;

        if(!empty($image)) {
            $block_scale = self::scale($image);
        } else {
            $block_scale = false;
        }

        if($block['bg_type'] == 'image')
        {
            if($block_scale != false) {
                $block['bg_data'] = $image;
            } else {
                $block['bg_data'] = '';
            }
        }
        else
        {
            if(empty($block['bg_data'])) {
                $block['bg_data'] = self::def_item_bg_color;
            }
        }

        unset($block['bg_image']);
    }

    private function filter_normal($block_type,$items, &$goods_ids, &$scale)
    {
        $result = [];
        $has_set = false;
        foreach($items as $item)
        {
            $item['title']  = $this->safe_string($item['title']);
            if($has_set == false) {
                $scale = self::scale($item['image']);
                $has_set = true;
            }

            if($item['type'] == 'goods')
            {
                $goods_id = intval($item['data']);
                if(self::check_goods(array($goods_id))) {
                    array_push($goods_ids,$goods_id);
                    $result[] = $item;
                } else {
                    Log::record("block_type={$block_type} cannt find goods ,goods_id={$goods_id}",Log::ERR);
                    continue;
                }
            }
            else {
                $result[] = $item;
            }
        }

        if($has_set == true)
        {
            if($block_type == 'home3') {
                $scale = $scale * 2;
            }
            elseif($block_type == 'goods') {
                $scale = 1;
            }
        }
        if(empty($result)) {
            return false;
        } else {
            return $result;
        }
    }
}

class spid_item
{
    private $mFromUser;
    private $mHasVote;
    private $mShareImage;
    private $mShareTitle;

    public function __construct($item)
    {
        $special = new ugc\special($item);

        $this->mFromUser = $special->from_user();
        $this->mHasVote  = $special->has_vote();
        $this->mShareImage = $special->share_img();
        $this->mShareTitle = $special->share_title();
    }

    public function from_user() {
        return $this->mFromUser;
    }
    public function has_vote() {
        return $this->mHasVote;
    }
    public function share_image() {
        return $this->mShareImage;
    }
    public function share_title() {
        return $this->mShareTitle;
    }
}

class spid_helper
{
    private static $stInstance = null;
    private $mContents;

    public function __construct() {
        $this->mContents = [];
        $this->add_home();
    }

    public static function instance() {
        if(self::$stInstance == null) {
            self::$stInstance = new spid_helper();
        }

        return self::$stInstance;
    }

    //home page is not in mb_special table.
    private function add_home()
    {
        $item['from_user']   = 0;
        $item['share_image'] = "";
        $item['share_title'] = "";

        $spitem = new spid_item($item);
        $this->mContents[0] = $spitem;
    }

    public function special($spid)
    {
        $spid = intval($spid);
        if(array_key_exists($spid,$this->mContents)) {
            return $this->mContents[$spid];
        }
        else
        {
            $item = $this->read($spid);
            if($item == false) {
                return false;
            } else {
                $this->mContents[$spid] = $item;
                return $item;
            }
        }
    }

    private function read($spid)
    {
        $mod_special = Model('mb_special');
        $item = $mod_special->getMbSpecialByID($spid);
        if(empty($item)) {
            return false;
        }
        else
        {
            $spitem = new spid_item($item);
            return $spitem;
        }
    }
}

class special_manager
{
    private static $stInstance = null;
    private $mContents;

    public function __construct()
    {
        $this->mContents = [];
    }
    public static function instance() {
        if(self::$stInstance == null) {
            self::$stInstance = new special_manager();
        }

        return self::$stInstance;
    }
    public function tabs($special_id)
    {
        if (array_key_exists($special_id, $this->mContents)) {
            return $this->mContents[$special_id]['tabs'];
        } else {
            return [];
        }
    }
    public function special($special_id,&$goods_ids,$pub=true)
    {
        if($pub)
        {
            if(StatesHelper::fetch_state('special')) {
                $this->mContents = [];
            }

            $special_id = intval($special_id);
            if(array_key_exists($special_id,$this->mContents)) {
                $data = $this->mContents[$special_id]['data'];
                $goods_ids = $this->mContents[$special_id]['gids'];
                return $data;
            }
            else
            {

                $formater = new special_formater($special_id,$this->old_version($special_id));
                $data = $formater->format($goods_ids);

                $this->mContents[$special_id]['data'] = $data;
                $this->mContents[$special_id]['gids'] = $goods_ids;
                $this->mContents[$special_id]['tabs'] = $formater->tabs();

                return $data;
            }
        }
        else
        {
            $formater = new special_formater($special_id,$this->old_version($special_id));
            $specials = $formater->format($goods_ids);

            $result['specials'] = $specials;
            $result['sender_info'] = $formater->sender_info();
            $result['special_info'] = $formater->special_info();

            return $result;
        }
    }
    private function old_version($special_id)
    {
        global $config;
        if($_SESSION['is_lasted'] || empty($config['old_specials'])) return false;

        return in_array($special_id,$config['old_specials']);
    }
}