Page MenuHomePhabricator

TYPProfileShareBlock.php
No OneTemporary

TYPProfileShareBlock.php

<?php /** * @file * Contains \Drupal\search\Plugin\Block\SearchBlock. */ namespace Drupal\typ_profile\Plugin\Block; use Drupal\Core\Block\BlockBase; use Drupal\Core\Url; use Drupal\typ_legacy\Service\TYPLegacyLandingPageService; use Drupal\typ_search\Service\TYPSearchService; use Drupal\typ_legacy\Serivee; /** * Provides a 'Search form' block. * * @Block( * id = "typ_profile_share_block", * admin_label = @Translation("Profile Share"), * category = @Translation("TYP") * ) */ class TYPProfileShareBlock extends BlockBase { public function formatPhoneNumber($s) { foreach( explode(",", $s) as $p) { $num_com = null; $num_first = null; $num_second = null; $num_ex = explode("-", trim($p)); for($i = 0; $i < count($num_ex); $i++) { if(($i+1) < count($num_ex)) { $num_first .= $num_ex[$i]; } else { $num_second .= $num_ex[$i]; } } if(empty($num_first)) { $num_first = $num_second; $num_second = null; } if(strlen($num_first) == 9) { $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4); if(!empty($num_second)) { $num_com .= '-'.$num_second; } } else { if(strlen($num_first) < 9) { $num_first .= $num_second; if(strlen($num_first) == 9) { $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4); } elseif(strlen($num_first) == 10){ $num_com = substr($num_first, 0, 2) . '-'. substr($num_first, 2, 4). '-'. substr($num_first, 6,7); }else { $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4).'-'.substr($num_first, 9,strlen($num_first)); } } else { if(strlen($num_first) == 10) { $num_com = substr($num_first, 0, 2) . '-'. substr($num_first, 2, 4). '-'. substr($num_first, 6,7); } else { $num_first .= $num_second; $num_com = substr($num_first, 0, 1) . '-'. substr($num_first, 1, 4). '-'. substr($num_first, 5,4).'-'.substr($num_first, 9,strlen($num_first)); } } } $ps[] = $num_com; } return implode(", ", $ps); } public function formatWorkingHour($s) { foreach( explode(",", $s) as $p) { $ps[] = $p; } return implode(", ", $ps); } protected $data; protected $result; public function build(){ $fullurl = 'http://'.$_SERVER[HTTP_HOST].$_SERVER['REQUEST_URI']; $url = \Drupal::request()->getRequestUri(); $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $s = explode("/",$url); $bid = end($s); $this->data = \Drupal::service("typ.search")->getProfile($bid ,AUTO); $this->result = \Drupal::service('typ.unvservice')->loadListing($this->data['customerid'],NULL); $type = $this->result['address'][$this->data['headingcode']][$this->data['addressid']]['customertype']; $telno = '';$fax = '';$workinghours = ''; if (!empty($this->data['telno'])) { foreach ($this->data['telno'] as $t) { $telno .= $this->formatPhoneNumber($t); } } if (!empty($this->data['fax'])) { foreach ($this->data['fax'] as $t) { $fax .= $this->formatPhoneNumber($t); } } if (!empty($this->data['workinghours'])) { $workinghours .= $this->formatWorkingHour($this->data['workinghours']); } $body_email = '<table> <tbody> <tr valign="top"> <td style="width:120px;"><b>'.t('Address').'</b></td> <td>'.$this->data['fulladdr'].'</td> </tr> <tr valign="top"> <td style="width:120px;"><b>'.t('Tel').'</b></td> <td>'.$telno.'</td> </tr> <tr valign="top"> <td style="width:120px;"><b>'.t('Fax').'</b></td> <td>'.$fax.'</td> </tr> <tr valign="top"> <td style="width:120px;"><b>'.t('Email').'</b></td> <td>'.$this->data['email'].'</td> </tr> <tr valign="top"> <td style="width:120px;"><b>'.t('Website').'</b></td> <td>'.$this->data['website'].'</td> </tr> <tr valign="top"> <td style="width:120px;"><b>'.t('Work-Time').'</b></td> <td>'.$workinghours.'</td> </tr> <tr valign="top"> <td style="width:120px;"><b>'.t('Link').'</b></td> <td>'.$fullurl.'</td> </tr> </tbody> </table>'; switch ($type){ case "FL": $email = urlencode((string)$body_email); $facebook = 'https://www.facebook.com/sharer/sharer.php?u='.format_string($this->data['proddesc']).$fullurl; $twitter = format_string($this->data['proddesc']).$fullurl; $gplus = 'https://plus.google.com/share?url='.$fullurl; break; default: $email = urlencode((string)$body_email); $facebook = 'https://www.facebook.com/sharer/sharer.php?u='.format_string($this->data['proddesc']).$fullurl; $twitter = format_string($this->data['proddesc']).$fullurl; $gplus = 'https://plus.google.com/share?url='.$fullurl; } $base_url_images = '/themes/bootstrap/typ/images/icon-service-profilepage/'.$language; $email = base64_encode($email); header('Content-Type: text/html; charset=UTF-8'); $build = array(); $build[] = array( '#markup' => format_string('<div class="col-xs-12 col-md-12 col-lg-12 form-inline text-center profile_share"> <div class="col-xs-4 col-md-4 col-lg-4" style="padding: 5px !important;"> <a href=".profile_email" data-from="'.base64_encode($this->data['humanname']).'" data-value="'.$email.'" onclick="sendmail(this); return false" ><img class="profile_email" onmouseover="hover_share(this);" onmouseout="out_share(this);" src="'.$base_url_images.'/pf-icon-email1-'.$language.'.png"></a> </div> <div class="col-xs-4 col-md-4 col-lg-4" style="padding: 5px !important;"> <a href="#" onclick="print_content()"><img class="profile_print" onmouseover="hover_share(this);" onmouseout="out_share(this);" src="'.$base_url_images.'/pf-icon-print1-'.$language.'.png"></a> </div> <div class="col-xs-4 col-md-4 col-lg-4" style="padding: 5px !important;"> <a href="#" onclick="window.open(\''.$facebook.'\',\'name\',\'width=600,height=400\')" ><img class="profile_facebook" onmouseover="hover_share(this);" onmouseout="out_share(this);" src="'.$base_url_images.'/pf-icon-facebook1-'.$language.'.png"></a> </div> <div class="col-xs-4 col-md-4 col-lg-4" style="padding: 5px !important;"> <a href="#" data-url="'.$twitter.'" data-text="'.$this->data['humanname'].'" onclick="window.open(\'https://twitter.com/share\',\'name\',\'width=600,height=400\')" ><img class="profile_twitter" onmouseover="hover_share(this);" onmouseout="out_share(this);" src="'.$base_url_images.'/pf-icon-twitter+1-'.$language.'.png"></a> </div> <div class="col-xs-4 col-md-4 col-lg-4" style="padding: 5px !important;"> <a href="" onclick="window.open(\''.$gplus.'\',\'name\',\'width=600,height=400\')" ><img class="profile_google" onmouseover="hover_share(this);" onmouseout="out_share(this);" src="'.$base_url_images.'/pf-icon-google+1-'.$language.'.png"></a> </div> <div class="col-xs-4 col-md-4 col-lg-4" style="padding: 5px !important;"> <a href="http://promotion.yellowpages.co.th/" TARGET="_blank" ><img class="profile_promotion" onmouseover="hover_share(this);" onmouseout="out_share(this);" src="'.$base_url_images.'/pf-icon-promation1-'.$language.'.png"></a> </div> </div>'), ); $build['#attached']['library'] = array( 'typ_profile/profile_share' ); return $build; } } ?>

File Metadata

Mime Type
text/x-php
Expires
Fri, Mar 14, 6:35 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
205576

Event Timeline