diff --git a/src/Controller/TYPProfileController.php b/src/Controller/TYPProfileController.php --- a/src/Controller/TYPProfileController.php +++ b/src/Controller/TYPProfileController.php @@ -1,388 +1,388 @@ trigger(); } public function formatWorkingHour($s) { foreach( explode(",", $s) as $p) { $ps[] = $p; } return implode(", ", $ps); } protected $data; protected static function insertVisit($bizid, $customerid){ // DO NOT DO THIS! THIS IS NOT PROPER PLACE.. AND TOO BIG DATA! // VORAPOAP 1/10/2558 /*db_set_active("typ_data"); $data['businessid'] = trim($bizid); $data['customerid'] = trim($customerid); $data['goodsid'] = ""; db_insert('last_visit_product')->fields($data)->execute(); db_set_active();*/ } public function checkLPRedirect($options = array()){ $data = \Drupal::service('typ.api')->getLandingpage($options); $customer = array(); if($data){ $info = $data['_info']; $res = $data['_res']; $sub = $res['subdomains'][$info['headingcode']]; $datenow = date('Y-m-d'); $status = 0; if($datenow <= date('Y-m-d', strtotime($sub['enddate']))){ if($datenow >= date('Y-m-d', strtotime($sub['startdate'])) && $datenow <= date('Y-m-d', strtotime($sub['enddate']))){ $status = 1; }else{ $status = 2; } } $lp = $res['landingpages'][$info['headingcode']]; if(intval($lp['hide']) == '1' || intval($lp['accounting_status']) == 1){ $status = 0; } $customer['busid'] = $info['customerid'].$info['headingcode'].$lp['addressid']; $customer['custid'] = $info['customerid']; $customer['subdomain'] = $sub['subdomain']; $customer['headingcode'] = $info['headingcode']; $customer['URL'] = $sub['url']; $customer['title'] = $sub['title']; $customer['keyword'] = $sub['keyword']; $customer['desc'] = $sub['desc']; $customer['theme'] = $lp['theme']; $customer['siteid'] = $sub['siteclick']; $customer['status'] = $status; } return $customer; } public function profileTitle($bizid) { $this->data = \Drupal::service("typ.search")->getProfile($bizid ,AUTO); if (!$this->data) return ''; else return $this->data['humanname']; } public function profilePage($bizid){ $this->data = \Drupal::service("typ.search")->getProfile($bizid ,AUTO); $result = \Drupal::service('typ.unvservice')->loadListing($this->data['customerid']); $address_id = ""; $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); if(isset($_COOKIE['breadcrumbs'])) { $breadcrumbs_data = $_COOKIE['breadcrumbs']; $breadcrumbs_ex= explode(",", $breadcrumbs_data); $breadcrumbs[$breadcrumbs_ex[0]] = $breadcrumbs_ex[0]; $breadcrumbs['data'] = $breadcrumbs_ex[1]; $breadcrumbs['businessid'] = $breadcrumbs_ex[2]; } $data = $this->data; if (!$data) { throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(); } if(!empty($data['redirect'])){ $lp = $data['redirect']; if(strpos($data['redirect'], 'http://') === false){ $lp = 'http://'.$data['redirect']; } $chk_lp = array(); if($lp){ $redirect = str_replace(array("http://", "/"), "", $lp); - if(strpos($redirect, '.yellowpages.co.th') !== false){ + if(strpos($redirect, \Drupal\typ_legacy\Service\TYP::config('typ.subdomain')) !== false){ //Subdomain $options['type'] = 'subdomain'; $exp = explode(".", $redirect); $options['SUBDOMAIN'] = current($exp); }else{ //Domian $options['type'] = 'domain'; $options['DOMAIN'] = $redirect; } $chk_lp = $this->checkLPRedirect($options); } if($chk_lp['status'] == '1'){ header('Location: '.$lp); exit(); } }else{ if(!empty($data['landingpage']) && !empty($data['subdomain'])){ $options['customerid'] = $data['customerid']; $options['headingcode'] = $data['headingcode']; - $onserv = \Drupal::service('typ.subdomain')->onserviceSubdomain($options, true); + $onserv = \Drupal::service('typ.subdomain')->getOnServiceSubdomain($options, true); if($onserv[0] == true){ $lp = $data['landingpage']; if(strpos($data['landingpage'], 'http://') === false){ $lp = 'http://'.$data['landingpage']; } if(!empty($lp)){ header('Location: '.$lp); exit(); } } } } if($this->data['onlinepromotion']){ $promotiond_mongo = \Drupal::service("typ.profile")->_getpromotion($bizid); $promo = iterator_to_array($promotiond_mongo); $proid = array(); foreach ($promo as $key => $value) { foreach ($value as $k => $val) { if($k == 'th'){ $proid['promotion'] += $val; }if($k == 'en'){ $proid['promotion'] += $val; }else{ $proid['promotion'][$k] = $val; } } } // echo "
";print_r($proid);exit;
             $result['address'][$data['headingcode']][$data['addressid']]['promotion'] = $proid['promotion'];
             // echo "";print_r($result);exit;
         }
         //Insesrt visit page
         //self::insertVisit($data['businessid'], $data['customerid']);
         /*if($data['landingpage'] == ""){
             $address_id = $data['addressid'];
         }
         if(is_numeric($address_id)){
             $result = \Drupal::service('typ.unvservice')->loadListing($data['customerid']);
             $rs_details = (!empty($result['address'][$data['headingcod']][$address_id]['frontviews']))?$result['address'][$headingcode][$data['headingcod']]['frontviews']:array();
         } else {
             $result = \Drupal::service('typ.unvservice')->loadService($data['customerid']);
         }*/
         // PLEASE COMMENT?? WHY WE LOAD PROFILE AND THEN LOAD SERVICE?
 
         //(!empty($result['landingpages'][$data['headingcode']]))?$result['landingpages'][$data['headingcode']]:array();
         //$type = '';
         $address_id = $data['addressid'];
         $type = $this->data['customertype'];
 
         if($this->data['accounting_status'] == '1' || $this->data['hide'] == '1'){   // Check Disable Packet and Hide content
             $result['customertype'] = 'FL';
             $type = 'FL';
         }
 
         if( $type== 'FL' || $this->data['customertype'] == ''){
             $type = 'FL';
         }else{
             $result_olc = \Drupal::service('typ.catalog')->listData($data['customerid']);
         }
         if($language == 'en'){
             $base_path = '/en/';
         }else{
             $base_path = '/';
         }
 
         if($_GET['debug']){
             echo "";
             echo "
Service:";if($this->data['accounting_status'] == '1'){ echo "Don't have a Service";}else{ echo "Service"; } echo "";
             echo "
Hide:";if($this->data['hide'] == '1'){ echo "Hide"; }else{ echo "Don't Hide"; } echo "";
             echo "
Type:".$type."
";
             var_export($this->data);
             exit;
         }
 
         if($type == 'FL'){
             $data['profile'] = strip_tags($data['profile']);
             $data['proddesc'] = strip_tags($data['proddesc']);
         }
 
         $pos = strpos(html_entity_decode($data['proddesc']),"");
         if($pos !== false && $data['proddesc']){
             $tempdesc = substr(html_entity_decode($data['proddesc']),3);
         }else{
             $tempdesc = html_entity_decode(html_entity_decode($data['proddesc'])) ;
             //$tempdesc = $data['proddesc'];
         }
 
         if(strlen($tempdesc) != 0) {
             $temp = '
';
             $tempdesc = $temp . $tempdesc;
         }
 
 
         if($type == "FL") {
             $dataproddesct = iconv_substr($tempdesc,0,150,"UTF-8");
             if(strlen($dataproddesct) > 150){
                 $dataproddesct .= '...';
             }
         }else{
             $dataproddesct = $tempdesc;
         }
         $dataproddesct = str_replace("
","
",$dataproddesct);
         if($type != "FL" && !empty($result_olc)){
             $olcdata = $result_olc[0];
         }
 
         if (!empty($data['telno'])) {
             foreach ($data['telno'] as $t) {
                 $data['_format']['telno'][] = TYPUtilsService::formatPhoneNumber($t);
             }
         }
         if (!empty($data['fax'])) {
             foreach ($data['fax'] as $t) {
                 $data['_format']['fax'][] = TYPUtilsService::formatPhoneNumber($t);
             }
         }
         if(!empty($data['website'])){
             $data['website_show'] = $data['website'];
             $data['website'] = explode(",",$data['website']);
             $item = array();
             if(!empty($data['website'])){
                 foreach($data['website'] as $key => $new){
                     if(strpos($new, 'http://') === FALSE && strpos($new, 'https://') === FALSE){
                         $item['http://'.$new] = $new;
                     }else{
                         $item[$new] = $new;
                     }
                 }
                 $data['website'] = $item;
             }
         }
         
         $thai_month_arr = array('01'=>'ม.ค.','02'=>'ก.พ.','03'=>'มี.ค.','04'=>'เม.ย.','05'=>'พ.ค.','06'=>'มิ.ย.','07'=>'ก.ค.','08'=>'ส.ค.','09'=>'ก.ย.','10'=>'ต.ค.','11'=>'พ.ย.','12'=>'ธ.ค.');
         list($year, $month,$day) = explode('-', $result['address'][$data['headingcode']][$data['addressid']]['promotion']['enddate']);
         $date_e = $day." ".$thai_month_arr[$month]." ".($year+543);
         $end_date_promotion =  $result['address'][$data['headingcode']][$data['addressid']]['promotion']['enddate'];
         list($year, $month,$day) = explode('-', $result['address'][$data['headingcode']][$data['addressid']]['promotion']['startdate']);
         $date_s = $day." ".$thai_month_arr[$month]." ".($year+543);
         $result['address'][$data['headingcode']][$data['addressid']]['promotion']['startdate'] = $date_s;
         $result['address'][$data['headingcode']][$data['addressid']]['promotion']['enddate'] = $date_e;
         $result['address'][$data['headingcode']][$data['addressid']]['promotion']['subject'] = preg_replace('/
]*?>/','',html_entity_decode($result['address'][$data['headingcode']][$data['addressid']]['promotion']['subject']));
 
         if(date("Y-m-d") > $end_date_promotion){
             $promotion_data = '';
         }else{
             $promotion_data = $result['address'][$data['headingcode']][$data['addressid']]['promotion'];
         }
         if(!empty($data['profile'])){
             $data['profile'] = preg_replace('/
]*?>/','',html_entity_decode($data['profile']));
         }
         if (!empty($data['workinghours'])) {
             $data['_format']['workinghours'] = $this->formatWorkingHour($data['workinghours']);
             $data['customertyp'] = $data['customertype'];
         }
         if(!empty($data['cityname'])){
             $bangkok = array('กรุงเทพ','กรุงเทพฯ','ก.ท.ม.','กรุงเทพมหานคร','กทม','จังหวัดกรุงเทพมหานคร','จังหวัด กรุงเทพมหานคร');
             if(!in_array($data['cityname'],$bangkok)){
                 $data['cityname'] = t('Province') .' '. $data['cityname'];
 
             }
         }
         
         $data['profile'] =  str_replace("
","
",$data['profile']);
         $data['lang'] = $this->data['lang'];
 
         if(!empty($promotion_data['promoimg']) && @file_exists('http://promotion.yellowpages.co.th/media/promotion/'.$promotion_data['promoimg'])){    //  images from Old system
             $promotion_data['baseurl'] = 'http://promotion.yellowpages.co.th/media/promotion/';
         }else{
             $promotion_data['baseurl'] = 'http://media.yellowpages.co.th/yellowpages/promotion/';
         }
         
         if(empty($data['printads']) && ($data['printadstf'] || $data['printadsef'])){
         	if($data['lang'] == 'th'){
         		$exp = explode('.', $data['printadstf']);
         	}else{
         		$exp = explode('.', $data['printadsef']);
         	}
 
         	if($exp){
         		$data['printads'] = $exp[0];
         	}
         }
 
         $link_url = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
         $check_lang = explode("/", $link_url);
         if($check_lang[1] == 'en'){
             $link_url = str_replace("/en/", "/", $link_url);
         }
 
         $display[] = array(
             '#theme' => 'typ_profile',
             '#profile' => $data,
             '#prodescription' => $dataproddesct,
             '#catalog' => $olcdata,
             '#type' => $type,
             '#promotion' => $promotion_data,
             '#breadcrumbs' => $breadcrumbs,
             '#base_path' => $base_path,
             '#facebook_comment' => $link_url,
         );
         if ($type != 'FL')
             $display['#attached']['drupalSettings']['disableAds'] = TRUE;
 
         $display['#attached']['library'] = array(
             'typ_profile/profile.popup',
             'typ_contrib/colorbox',
         );
         if($type == 'FL'){
             $display['#attached']['library'] = array(
                 'typ_profile/profile.popup',
                 'typ_contrib/colorbox',
                 'typ_ads/ads_unit'
             );
             $display[] = array(
                 '#markup' => format_string('
',array())
             );
         }else{
             $display['#attached']['library'] = array(
                 'typ_profile/profile.popup',
                 'typ_contrib/colorbox',
             );
         }
         return $display;
     }
 
     public function getTitlePromotion(){
         return t('How to get promotion');
     }
 
     public function getPromotion(){
 
         $mobileDetector = \Drupal::service('krs.mobile_detect');
         if($mobileDetector->isAndroidOS() == 1 ){
             header('Location: https://play.google.com/store/apps/details?id=com.initialive.yellowpages.act&hl=th');
             exit;
         }if($mobileDetector->isIOS() == 1){
             header('Location: https://itunes.apple.com/th/app/thailand-yellowpages/id387848017?mt=8');
             exit;
         }else{
             header('Location: http://m.yellowpages.co.th/mobile/typliveplus/user/');
             exit;
         }
 
         $display[] = array(
             '#theme' => 'typ_promotion',
         );
         $display['#attached']['library'] = array(
             'typ_profile/profile.popup',
         );
 
         return $display;
     }
 }
diff --git a/templates/typ-profile.html.twig b/templates/typ-profile.html.twig
--- a/templates/typ-profile.html.twig
+++ b/templates/typ-profile.html.twig
@@ -1,532 +1,532 @@
 {% set base_images = 'http://media.yellowpages.co.th/yellowpages' %}
 {% set base_promotion = promotion.baseurl %}
 
     
     
 
         
             
                 {#{% if profile.logo %}#}
                 {##}
                 {#
#}
                 {##}
                 {#{% else %}#}
                 {##}
                 {#
#}
                 {##}
                 {#{% endif %}#}
 
                 
             
         
 
         
             
             {% if type != 'FL' %}
                 
             {% endif %}
             
             
 
                 {% if type != 'FL' %}
                     {{ profile.profile|raw}}
                     {% if profile.profile %}
{% endif %}
                 {% else %}
                     {#{{ profile.profile|raw|slice(0, 100)}}{% if profile.profile|length > 100 %}{{ '...' }} {% endif %} #}
                     {#{% if profile.profile %}
{% endif %}
 #}
                 {% endif %}
                 {#{% if not profile.addr %}{% else %}#}
                 {#{% trans %} Address {% endtrans %}#}
                 {#{{ [profile.addr,profile.soi,profile.road,profile.subdistrictname,#}
                 {#profile.districtname,profile.cityname,profile.postcode]|join(' ') }}#}
                 {#{% endif %}#}
                 {#{% if profile.location.lat %}#}
                 {#
 
#}
                 {#{% else %}#}
                 {#
 
#}
                 {#{% endif %}#}
 
                 
                     
                         
                             {% if profile.addr or profile.soi or profile.road or profile.subdistrictname or profile.districtname or profile.cityname %}
                                 
                                     {% trans %} Address {% endtrans %}: 
                                      {{ [profile.addr,profile.soi,profile.road,profile.subdistrictname,profile.districtname,profile.cityname,profile.postcode]|join(' ') }} 
                                  
                             {% endif %}
                             {% if not profile.telno %}{% else %}
                                 
                                    {% trans %} Tel {% endtrans %}: 
                                     
                                         {% if not profile.telno %}
                                         {% else %}
                                             {% if type == 'FL' %}
                                                 {{ profile._format.telno.0 }}
                                             {% else %}
                                                 {% for key, tel in profile._format.telno %}
                                                     {% if loop.last != key+1 %}{{ tel }}{{ "," }}
                                                     {% else %}{{ tel }}{% endif %}
                                                 {% endfor %}
                                             {% endif %}
                                         {% endif %}
                                      
                                  
                             {% endif %}
                             {% if not profile.fax %}{% else %}
                                 
                                    {% trans %} Fax {% endtrans %}: 
                                     
                                         {% if not profile.fax %}
                                         {% else %}
                                             {% if type == 'FL' %}
                                                 {{ profile._format.fax.0 }}
                                             {% else %}
                                                 {% for key, fax in profile._format.fax %}
                                                     {% if loop.last != key+1 %}{{ fax }}{{ "," }}
                                                     {% else %}{{ fax }}{% endif %}
                                                 {% endfor %}
                                             {% endif %}
                                         {% endif %}
                                      
                                  
                             {% endif %}
                             {% if not profile.email %}{% else %}
                                 
                                    {% trans %} Email {% endtrans %}: 
                                     
                                         {% if not profile.email %}
                                         {% else %}
                                             {% if type == 'FL' %}
                                                 {% set email =  profile.email|split(',') %}
                                                 {{ email.0 }}
                                                 {#{% for key , mail in email %}#}
                                                     {#{% if loop.last != key+1 %}{{ mail }},
#}
                                                     {#{% else %}{{ mail }}
{% endif %}#}
                                                 {#{% endfor %}#}
                                             {% else %}
                                                 {% set email =  profile.email|split(',') %}
                                                 {% for key , mail in email %}
                                                     {% if loop.last != key+1 %}{{ mail }},
                                                     {% else %}{{ mail }}
{% endif %}
                                                 {% endfor %}
                                             {% endif %}
                                         {% endif %}
                                      
                                  
                             {% endif %}
                             {% if not profile.website %}{% else %}
                                 
                                    {% trans %} Website {% endtrans %}: 
                                     
                                         {% if not profile.website %}
                                         {% else %}
                                             {# {% set website_show =  profile.website_show|split(',') %}
                                                 {% if type == 'FL' %}
                                                     {{  website_show.0 }}
                                                     {% else %}
                                                     {% for key , web in website_show %}
                                                         {% if loop.last != key+1 %}{{web}},
                                                         {% else %}{{web}}
{% endif %}
                                                     {% endfor %}
                                                 {% endif %} #}
                                                 {% if type == 'FL' %}
                                                     {% set website_show =  profile.website_show|split(',') %}
                                                     {{  website_show.0 }}
                                                 {% else %}
                                                     {% for key , web in profile.website %}
                                                         {% if loop.last %}
                                                             {{web}}
                                                         {% else %}
                                                             {{web}},
                                                         {% endif %}
                                                     {% endfor %}
                                                 {% endif %}
                                         {% endif %}
                                      
                                  
                             {% endif %}
                             {% if not profile.workinghours %}{% else %}
                                 
                                    {% trans %} Work-Time {% endtrans %}: 
                                     
                                         {% if not profile.workinghours %}
                                         {% else %}
                                             {{ profile._format.workinghours }}
                                         {% endif %}
                                      
                                  
                             {% endif %}
                         
                     
 
 
 
                     
                         
                             {% if type != 'FL' %}
                                 {% if not prodescription or prodescription is empty %}
                                 {% else %}
                                     
{% trans %} Product And Service {% endtrans %}
                                     {{ prodescription|raw }}
                                 {% endif %}
 
                                 
                                 {% if not profile.brandname %}
-                                {% else %}{% trans %} Banner {% endtrans %} 
 {{ profile.brandname|replace({"":" ","
":" "}) }}
+                                {% else %}{% trans %}Brand Name% endtrans %} 
 {{ profile.brandname|replace({"":" ","
":" "}) }}
                                 {% endif %}
                                 
 
                             {% else %}
                                 {% if not prodescription or prodescription is empty %}
                                 {% else %}
                                     
{% trans %} Product And Service {% endtrans %}
                                     {{ prodescription|raw }}
                                     {% if prodescription and profile.brandname %}
{% endif %}
                                 {% endif %}
 
                             {% endif %}
 
                             
                             {# TAB #}
                             {% if type == 'FL' %}
                                 
                                     
 
                                     
 
                                         {% if promotion.promotionid %}
                                             
                                         {% endif %}
 
                                         {% if profile.location.lat %}
                                             
                                         {% endif %}
 
                                     
                                 
                             {% else %}
                                 
                                     
 
                                     
                                 
 
                             {% endif %}
 
                             {#
#}
                             {#{% if not profile.custname %}#}
                             {#{% else %}#}
                             {#{{ profile.custname|raw }} : แสดงความคิดเห็น#}
                             {#{% endif %}#}
                             {#
#}
 
                             {# TAB #}
                             {##}
                             {##}
 
                             {##}
                             {##}
                             {##}
                             {#{##}#}
                             {##}
                             {##}
                             {# END TAB #}
                             
                         
                     
                     
                     {{ app.request.getRequestUri() }}