Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1082724
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Subscribers
None
View Options
diff --git a/src/Controller/TYPProfileController.php b/src/Controller/TYPProfileController.php
--- a/src/Controller/TYPProfileController.php
+++ b/src/Controller/TYPProfileController.php
@@ -1,307 +1,308 @@
<?php
/**
* @file
* Contains \Drupal\page_example\Controller\TableSortExampleController.
*/
/**/
namespace Drupal\typ_profile\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Database\Query;
use Drupal\Core\Url;
/**
* Controller routines for tablesort example routes.
*/
class TYPProfileController extends ControllerBase
{
/*public function profile_redirect(){
return $this->redirect("<front>");
}*/
public function __construct(){
\Drupal::service('page_cache_kill_switch')->trigger();
}
public static function FormatPhoneNumber($r){
$p = str_replace('-','',$r);
$num_com = '';
$codeTelephone = array('032','034','035','036','037','038','039','042','043','044','045','053','054','055','056','073','074','075','076','077');
if(strlen($p) == 9){
$num_com = substr($p,0,1).'-'.substr($p,1,4).'-'.substr($p,5,4);
}elseif(strlen($p) == 10 ) {
if(in_array(substr($p,0,3), $codeTelephone) || substr($p,0,2) == '02'){
$num_com = substr($p,0,1).'-'.substr($p,1,4).'-'.substr($p,5,4).'-'.substr($p,9);
}else{
$num_com = substr($p,0,2).'-'.substr($p,2,4).'-'.substr($p,6,4);
}
}else if($p != ''){
if(in_array(substr($p,0,3), $codeTelephone) || substr($p,0,2) == '02'){
if(strlen($p) == 9){
$num_com = substr($p,0,1).'-'.substr($p,1,4).'-'.substr($p,5,4);
}elseif(strlen($p)>9){
$num_com = substr($p,0,1).'-'.substr($p,1,4).'-'.substr($p,5,4).'-'.substr($p,9);
}
}else{
$num_com = substr($p,0,2).'-'.substr($p,2,4).'-'.substr($p,6,4);
}
}
return $num_com;
}
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 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) {
return $this->redirect("<front>");
}
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 "<PRE>";print_r($proid);exit;
$result['address'][$data['headingcode']][$data['addressid']]['promotion'] = $proid['promotion'];
// echo "<PRE>";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($_GET['debug']){
echo "<pre>";
echo "<br>Service:<b style='color:red;'><u>";if($this->data['accounting_status'] == '1'){ echo "Don't have a Service";}else{ echo "Service"; } echo "</u></b>";
echo "<br>Hide:<b style='color:red;'><u>";if($this->data['hide'] == '1'){ echo "Hide"; }else{ echo "Don't Hide"; } echo "</u></b>";
echo "<br>Type:<b style='color:red;'><u>".$type."</u></b><br><br>";
var_export($this->data);
exit;
}
$pos = strpos(html_entity_decode($data['proddesc']),"<p>");
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 = '<p style="color:#333;">';
$tempdesc = $temp . $tempdesc;
}
if($type == "FL") {
$dataproddesct = iconv_substr($tempdesc,0,123,"UTF-8");
if(strlen($dataproddesct) > 123){
$dataproddesct .= '...';
}
}else{
$dataproddesct = $tempdesc;
}
$dataproddesct = str_replace("<p>","<p style='color:#333;'>",$dataproddesct);
if($type != "FL" && !empty($result_olc)){
$olcdata = $result_olc[0];
}
if (!empty($data['telno'])) {
foreach ($data['telno'] as $t) {
$data['_format']['telno'][] = $this->formatPhoneNumber($t);
}
}
if (!empty($data['fax'])) {
foreach ($data['fax'] as $t) {
$data['_format']['fax'][] = $this->formatPhoneNumber($t);
}
}
if($type == "FL"){
/*unset($data['_format']['telno']);
$data['_format']['telno'][] = $data['_format']['telno'][0];
unset($data['fax']);
$data['fax'][] = $data['fax'][0];
$exp = explode(",", $data['email']);
unset($data['email']);
$data['email'][] = $exp[0];*/
}else{
/*$exp = explode(",", $data['email']);
$data['email'] = $exp;*/
}
if(!empty($data['website'])){
$data['website_show'] = $data['website'];
$data['website'] = explode(",",$data['website']);
foreach($data['website'] as $key => $new){
$new = str_replace("http://","",$new);
$data['website'][$key] = $new;
}
}
$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('/<p[^>]*?>/','',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('/<p[^>]*?>/','',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'];
+
}
}
if($type == 'FL'){
$data['profile'] = strip_tags($data['profile']);
}
$data['profile'] = str_replace("<p>","<p style='color:#333;'>",$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 ($_SERVER['HTTP_REFERER']) {
}
$display[] = array(
'#theme' => 'typ_profile',
'#profile' => $data,
'#prodescription' => $dataproddesct,
'#catalog' => $olcdata,
'#type' => $type,
'#promotion' => $promotion_data,
'#breadcrumbs' => $breadcrumbs,
);
if ($type != 'FL')
$display['#attached']['drupalSettings']['disableAds'] = TRUE;
$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;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Dec 23, 8:18 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
193593
Attached To
rPF typ_profile
Event Timeline
Log In to Comment