#0 | Apps\Models\Partners\Partners->getSnippetLocalBusiness
/home/tafront/current/apps/Frontend/Controllers/CatalogController.php (761) <?php
namespace Apps\Frontend\Controllers;
use Apps\Models\AdsBusinesses;
use Apps\Models\Catalog\Categories\CategoriesStats;
use Apps\Models\Catalog\Categories\CategoriesStatsByCities;
use Apps\Models\Catalog\Categories\CategoriesStatsByCountries;
use Apps\Models\Catalog\Categories\CategoriesStatsByStates;
use Apps\Models\CatalogCategories;
use Apps\Models\CatalogTopPages;
use Apps\Models\GeoCities;
use Apps\Models\GeoCountries;
use Apps\Models\GeoStates;
use Apps\Models\PartnerServices;
use Apps\Models\Partners\PartnerDetails;
use Apps\Models\Partners\Partners;
use Apps\Models\Partners\PartnerSentimentals;
use Apps\Models\Partners\PartnerSocialLinks;
use Apps\Models\Partners\PartnerSubscription;
use Apps\Models\Partners\PartnerTypes;
use Apps\Models\Reviews\Reviews;
use Apps\Models\UserPartnerChanges;
use Carbon\Carbon;
use Phalcon\Mvc\View;
class CatalogController extends BaseController
{
public function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
$this->view->hideWidgets = true;
}
private function middleware($countryCode, $stateCode, $cityName, $categorySlug)
{
// check if request comes from catalog main page
if ($countryCode === "business" && $stateCode === "search") {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'business'
]
);
} else {
if ($countryCode === "business" && $stateCode === "getStates") {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'getStates'
]
);
} else {
if ($countryCode === "business" && $stateCode === "getCities") {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'getCities'
]
);
} else {
if ($countryCode === "business" && $stateCode === "autocomplete") {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'autocomplete'
]
);
} else {
if ($countryCode === "business" && $stateCode === "category") {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'category'
]
);
} // check if business keyword exists then forward to business controller
else {
if ($countryCode === "business") {
return $this->dispatcher->forward(
[
'controller' => 'business',
'action' => 'slug',
'params' => [$stateCode]
]
);
} else {
if ($countryCode === "online" && $stateCode === "reviews") {
return $this->dispatcher->forward(
[
'controller' => 'business',
'action' => 'online',
'params' => [$cityName]
]
);
} else {
if ($countryCode == "request-review") {
return $this->dispatcher->forward(
[
'controller' => 'request',
'action' => 'hash',
'params' => [$stateCode]
]
);
} else {
if ($countryCode == "social") {
return $this->dispatcher->forward(
[
'controller' => 'social',
'action' => 'callback',
'params' => [$cityName]
]
);
} else {
if ($countryCode === "reviews") {
return $this->dispatcher->forward(
[
'controller' => 'business',
'action' => 'index',
'params' => [$stateCode]
]
);
} else {
if ($countryCode === "online") {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'online',
'params' => [$stateCode]
]
);
}
}
}
}
}
}
}
}
}
}
}
// set defaults
$args = [$countryCode, $stateCode, $cityName, $categorySlug];
foreach ($args as $arg) {
if (preg_match('/[^A-Za-z0-9-\.]/', $arg) || gettype($arg) === "string" && strlen($arg) <= 0) {
return $this->route404Action();
}
}
// remove empty from args
$args = array_filter($args, function ($value) {
return $value !== false;
});
$countryCode = array_shift($args);
$categorySlug = array_pop($args);
if (empty($args)) {
$stateCode = false;
$cityName = false;
} else {
if (count($args) === 1) {
$stateCode = $args[0];
$cityName = false;
} else {
if (count($args) === 2) {
$stateCode = $args[0];
$cityName = $args[1];
}
}
}
if (!$categorySlug) {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'statesView',
'params' => [$countryCode]
]
);
}
if ($categorySlug == "establishment" || $categorySlug == "point_of_interest") {
return $this->route404Action();
}
$isTest = $this->request->get('query', ['trim', 'string'], '');
// 1
$category = CatalogCategories::findFirst([
'conditions' => 'type = 1 AND slug = :slug:',
'bind' => ['slug' => $categorySlug]
]);
if (!$category) {
// 2
$category = CatalogCategories::findFirst([
'conditions' => 'type = 2 AND slug = :slug:',
'bind' => ['slug' => $categorySlug]
]);
}
$subdomainCategories = [];
if ($isTest == 'remstyle') {
die(json_encode($category));
}
if(isset($category) && $category->category) {
array_push($subdomainCategories, $category->category);
}
$currentHost = $_SERVER['HTTP_HOST']; // e.g., "trustanalytica.org" or "lip-fillers.trustanalytica.org"
// Only redirect if the category exists in the array and the user is on "trustanalytica.org"
if (in_array('lip_fillers', $subdomainCategories)) {
if ($currentHost == "trustanalytica.org" || $currentHost !== "lip-fillers.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "lip-fillers.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('dermatologist', $subdomainCategories)) {
if ($currentHost == "trustanalytica.org" || $currentHost !== "dermatologist.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "dermatologist.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('essay_writing', $subdomainCategories)) {
if ($currentHost === "trustanalytica.org" || $currentHost !== "essay-writing.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "essay-writing.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('resume_service', $subdomainCategories)) {
if ($currentHost === "trustanalytica.org" || $currentHost !== "resume-service.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "resume-service.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('jewelry_store', $subdomainCategories)) {
if ($currentHost === "trustanalytica.org" || $currentHost !== "jewelry-store.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "jewelry-store.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('watch_store', $subdomainCategories)) {
if ($currentHost === "trustanalytica.org" || $currentHost !== "watch-store.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "watch-store.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('pest_control_service', $subdomainCategories)) {
if ($currentHost === "trustanalytica.org" || $currentHost !== "pest-control.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "pest-control.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (in_array('adjustable_bed', $subdomainCategories)) {
if ($currentHost === "trustanalytica.org" || $currentHost !== "adjustable-bed.trustanalytica.org") {
$cleanHost = $this->getCleanDomain($currentHost);
$currentUrl = "https://{$cleanHost}{$_SERVER['REQUEST_URI']}";
$newUrl = str_replace("trustanalytica.org", "adjustable-bed.trustanalytica.org", $currentUrl);
header("Location: $newUrl", true, 301);
exit;
}
}
if (!$category) {
if (!$stateCode && !$cityName) {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'citiesView',
'params' => [$countryCode, $categorySlug]
]
);
} else {
if ($stateCode && !$cityName) {
return $this->dispatcher->forward(
[
'controller' => 'catalog',
'action' => 'topListView',
'params' => [$countryCode, $stateCode, $categorySlug]
]
);
} else {
if (!$category) {
if ($cityName) {
return $this->response->redirect("/".$countryCode."/".$stateCode."/" . $cityName, false, 302);
}
if ($stateCode) {
return $this->response->redirect("/".$countryCode."/".$stateCode, false, 302);
}
if ($countryCode) {
return $this->response->redirect("/".$countryCode, false, 302);
}
}
return $this->route404Action();
}
}
}
if ($category->status == 0) {
if ($cityName) {
return $this->response->redirect("/".$countryCode."/".$stateCode."/" . $cityName, false, 302);
}
if ($stateCode) {
return $this->response->redirect("/".$countryCode."/".$stateCode, false, 302);
}
if ($countryCode) {
return $this->response->redirect("/".$countryCode, false, 302);
}
return $this->route404Action();
}
if ($cityName == 'sf') {
return $this->response->redirect("/".$countryCode."/".$stateCode."/san-francisco/".$category->slug, false,
301);
}
$title = $category->title;
$description = $category->description;
$metaTitle = $category->metaTitle;
$metaDescription = $category->metaDescription;
$faq = $category->faq;
if ($category->type == 1) {
// 3
$topPage = CatalogTopPages::getPageByLocation($countryCode, $stateCode, $cityName, $category->category);
if ($isTest == 'remstyle1') {
die(json_encode($topPage->title));
}
if ($topPage && $topPage->status == 0) {
if ($cityName) {
return $this->response->redirect("/".$countryCode."/".$stateCode."/" . $cityName, false, 302);
}
if ($stateCode) {
return $this->response->redirect("/".$countryCode."/".$stateCode, false, 302);
}
if ($countryCode) {
return $this->response->redirect("/".$countryCode, false, 302);
}
return $this->response->redirect($countryCode.'/'.$categorySlug, false, 302);
}
if ($topPage && strlen($topPage->title) > 0) {
$title = $topPage->title;
}
if ($topPage && strlen($topPage->faq) > 0) {
$faq = $topPage->faq;
}
if ($topPage && strlen($topPage->description) > 0) {
$description = $topPage->description;
}
if ($topPage && strlen($topPage->metaTitle) > 0) {
$metaTitle = $topPage->metaTitle;
}
if ($topPage && strlen($topPage->metaDescription) > 0) {
$metaDescription = $topPage->metaDescription;
}
}
return [
'countryCode' => $countryCode,
'stateCode' => $stateCode,
'cityName' => $cityName,
'categorySlug' => $categorySlug,
'category' => $category,
'topPage' => $topPage,
'title' => $title,
'description' => $description,
'metaTitle' => $metaTitle,
'faq' => $faq,
'metaDescription' => $metaDescription
];
}
function sortArrayByConditions($items) {
// Current timestamp
$current_timestamp = time();
// Arrays to hold sorted items
$priority_items = [];
$non_priority_items = [];
$current_timestamp = time();
// Iterate through the items and separate them based on the condition
foreach ($items as $item) {
if ($item['endDate'] != null && $item['planId'] != null && $item['planId'] !== 'price_1I4VKfLF3loXTllzSsabRzhi' && $item['endDate'] >= $current_timestamp && $item['subscriptionId'] != null) {
$priority_items[] = $item;
} else {
$non_priority_items[] = $item;
}
}
// die(json_encode($priority_items));
// Merge priority items at the top followed by non-priority items
return array_merge($priority_items, $non_priority_items);
}
function getCleanDomain($host) {
return preg_replace('/^(.+?)\.trustanalytica\.org$/', 'trustanalytica.org', $host);
}
public function indexAction($countryCode = false, $stateCode = false, $cityName = false, $categorySlug = false)
{
$isTestSub301 = $this->request->get('query', ['trim', 'string'], '');
$middleware = $this->middleware($countryCode, $stateCode, $cityName, $categorySlug);
if (!is_array($middleware)) {
return $middleware;
}
$countryCode = $middleware['countryCode'];
$stateCode = $middleware['stateCode'];
$cityName = $middleware['cityName'];
$categorySlug = $middleware['categorySlug'];
$category = $middleware['category'];
$topPage = $middleware['topPage'];
$redirectCategories = [
'adult_toy_store', 'gay_massage', 'asian_massage', 'cbd_store', 'cannabis_store'
];
if (in_array($category->category, $redirectCategories)) {
$linkTa = 'https://trustanalytica.com';
header('Location: '.$linkTa, true, 301);
exit;
}
if ($category && $category->type && $category->type != 1) {
$linkTa = 'https://trustanalytica.org/'.'online/'.$categorySlug;
header('Location: '.$linkTa, true, 301);
exit;
}
if ($topPage && $topPage->redirect != "") {
header('Location: '.$topPage->redirect, true, 301);
}
$columns = [
'p.id as id',
'p.isFollowWebsite as isFollowWebsite',
'p.slug as slug',
'p.googlePlaceId as googlePlaceId',
'p.fullName as fullName',
'p.countryCode as countryCode',
'p.stateCode as stateCode',
'p.cityName as cityName',
'p.raitingAvg as raitingAvg',
'p.reviewsCount as reviewsCount',
'p.fullDescr as fullDescr',
'p.aiContent as aiContent',
'p.fullAddress as fullAddress',
'p.facePhoto as facePhoto',
'p.website as website',
'p.phone as phone',
'p.lat as lat',
'p.lng as lng',
'p.aiPhoto as aiPhoto',
'p.websiteScreenshots as websiteScreenshots',
'ps.*',
'p.status as status',
];
$title = $middleware['title'];
$metaTitle = $middleware['metaTitle'];
$description = $middleware['description'];
$metaDescription = $middleware['metaDescription'];
$faq = isset($middleware['faq']) ? $middleware['faq'] : '';
$countryName = $countryCode;
$stateName = $stateCode;
$locationInfo = null;
if ($topPage || $cityName != false) {
$locationTag = ucwords(str_replace("-", " ", $cityName));
} else {
$locationTag = $countryCode;
// 4
if ($stateCode != false) {
$locationInfo = GeoStates::findFirst([
'columns' => ['name'],
'conditions' => 'country_code = :countryCode: AND iso2 = :stateCode:',
'bind' => ['countryCode' => $countryCode, 'stateCode' => $stateCode]
]);
} else {
$locationInfo = GeoCountries::findFirst([
'columns' => ['name'],
'conditions' => 'iso2 = :countryCode:',
'bind' => ['countryCode' => $countryCode]
]);
}
if ($locationInfo) {
$locationTag = $locationInfo->name;
}
}
$currentYear = Carbon::now()->format('Y');
$title = str_replace(['{location}', '{year}'], [$locationTag, $currentYear], $title);
$description = str_replace(['{location}', '{year}'], [$locationTag, $currentYear], $description);
$metaTitle = str_replace(['{location}', '{year}'], [$locationTag, $currentYear], $metaTitle);
$metaDescription = str_replace(['{location}', '{year}'], [$locationTag, $currentYear], $metaDescription);
if (!$countryCode || !$categorySlug) {
return $this->route404Action();
}
$perPage = 30;
$page = $this->request->get('page', 'int', 1);
if ($page <= 0) {
$page = 1;
}
// 5
$catalog = Partners::getCatalogPartners('local', $category->category, $page, $perPage, $countryCode, $stateCode,
$cityName);
if ($isTestSub301 == 'remstylex1') {
die(json_encode($catalog));
}
// $catalog = $this->sortArrayByConditions($catalog);
if ($isTestSub301 == 'remstylex2') {
die(json_encode($catalog));
}
if ($cityName != false) {
$params = new \stdClass();
$params->countryCode = $countryCode;
$params->stateCode = $stateCode;
$params->cityName = $cityName;
$params->category = $category->category;
$categoryStats = CategoriesStatsByCities::findStats($params);
} else {
if ($stateCode != false) {
$params = new \stdClass();
$params->countryCode = $countryCode;
$params->stateCode = $stateCode;
$params->category = $category->category;
$categoryStats = CategoriesStatsByStates::findStats($params);
} else {
$params = new \stdClass();
$params->countryCode = $countryCode;
$params->category = $category->category;
$categoryStats = CategoriesStatsByCountries::findStats($params);
}
}
// die(json_encode(count($catalog)));
$totalItems = $categoryStats->totalPartners;
if ($categoryStats) {
$stateLocationName = $categoryStats->stateName ?? null;
}
if ($isTestSub301 == 'remstylex3') {
die(json_encode('here'));
}
$ads_partners_count = 0;
$ads_partners_new = [];
$profileMapLocations = [];
$ldJsonProfiles = [];
$isTestSub = $this->request->get('query', ['trim', 'string'], '');
$uniqueAdProfiles = [];
if (!$this->request->isAjax()) {
$ads_partners = AdsBusinesses::getPartners($categorySlug, $countryCode, $stateCode, $cityName);
$ads_partners_count = count($ads_partners);
foreach ($ads_partners as $item) {
if (!isset($uniqueArray[$item->id])) {
$uniqueAdProfiles[$item->id] = $item;
}
$mapLocation = [(string) $item->lat, (string) $item->lng, $item->fullName, (string) $item->fullAddress];
if($item->lat != '' || $item->lat != null) {
$profileMapLocations[] = $mapLocation;
}
$facePhotox = $this->facePhotoToUse($item->id);
$item->facePhotoToUse = $facePhotox;
$profileMapLocations[] = $mapLocation;
$partnerClone = new Partners();
$partnerType = Partners::getActualType($item->id);
$partnerTimings = Partners::getWorkForFront($item);
$item->partnerTimings = $partnerTimings;
$item->partnerCategory = $partnerType;
$ldJsonProfile = $partnerClone->getSnippetLocalBusiness();
if ($isTestSub301 == 'remstylex51ad') {
die(json_encode($ldJsonProfile));
}
array_push($ldJsonProfiles, $ldJsonProfile);
array_push($ads_partners_new, $item);
}
// die(json_encode($ads_partners_new));
$this->view->ads_partners = $uniqueAdProfiles;
}
if ($isTestSub301 == 'remstylex4') {
die(json_encode('here'));
}
if ($totalItems == 0 && !$this->request->isAjax()) {
if ($cityName) {
return $this->response->redirect("/".$countryCode."/".$stateCode."/" . $cityName, false, 302);
}
if ($stateCode) {
return $this->response->redirect("/".$countryCode."/".$stateCode, false, 302);
}
if ($countryCode) {
return $this->response->redirect("/".$countryCode, false, 302);
}
return $this->route404Action();
}
if ($isTestSub301 == 'remstylex5') {
die(json_encode('here'));
}
preg_match('/\bin|IN\b/', $title, $titleMatchedWord, PREG_OFFSET_CAPTURE);
if (isset($titleMatchedWord[0][1])) {
$simpleTitle = substr($title, 0, $titleMatchedWord[0][1]);
} else {
$simpleTitle = $title;
}
$currentYear = Carbon::now()->format('Y');
$originalArray = $catalog;
$uniqueArray = [];
foreach ($originalArray as $object) {
$id = $object['id'];
$findServices = PartnerServices::find([
'conditions' => 'partner_id = :partnerId:',
'bind' => ['partnerId' => $id]
]);
$servicesArray = [];
$allSubs = []; // collect all sub-services across all services
foreach ($findServices as $srv) {
$parsedSubServices = [];
if (!empty($srv->sub_services)) {
// Split services safely on '),'
$subList = preg_split('/\)\s*,\s*/', $srv->sub_services);
foreach ($subList as $sub) {
$sub = trim($sub);
if ($sub === '') continue;
// Ensure trailing ) if it was cut by split
if (substr($sub, -1) !== ')') {
$sub .= ')';
}
$name = $sub;
$price = null;
if (preg_match('/^(.*?)\s*\(([^()]+)\)$/', $sub, $m)) {
$name = trim($m[1]);
$price = trim($m[2]);
// Remove currency labels (USD, CAD, etc.)
$price = preg_replace('/\s*(USD|CAD|EUR|GBP)\b/i', '', $price);
// Remove commas from numbers (1,000 → 1000)
$price = preg_replace('/,/', '', $price);
// Normalize dash spacing
$price = preg_replace('/\s*-\s*/', ' - ', $price);
// Add $ sign before numbers
$price = preg_replace_callback('/\d+/', function ($n) {
return '$' . $n[0];
}, $price);
}
$parsedSubServices[] = [
'name' => $name,
'price' => $price,
];
}
}
$row = $srv->toArray();
$row['sub_services_array'] = $parsedSubServices;
$servicesArray[] = $row;
$allSubs = array_merge($allSubs, $parsedSubServices);
}
// Flattened "first 4 + more"
$firstSubs = array_slice($allSubs, 0, 3);
$moreSubs = array_slice($allSubs, 4);
$object->services = (array) $servicesArray;
$object->firstSubs = $firstSubs;
$object->moreSubs = $moreSubs;
$mapLocation = [(string) $object->lat, (string) $object->lng, $object->fullName, (string) $object->fullAddress];
if ($object->lat != '' || $object->lat != null) {
$profileMapLocations[] = $mapLocation;
}
$facePhoto = $this->facePhotoToUse($object->id);
$object->facePhotoToUse = $facePhoto;
$partnerClone = new Partners();
$partnerTimings = Partners::getWorkForFront($object);
$object->partnerTimings = $partnerTimings;
if (!isset($uniqueArray[$id])) {
$uniqueArray[$id] = $object;
}
$ldJsonProfile = $partnerClone->getSnippetLocalBusiness();
if ($isTestSub301 == 'remstylex51') {
die(json_encode($ldJsonProfile));
}
array_push($ldJsonProfiles, $ldJsonProfile);
}
if ($isTestSub301 == 'remstylex6') {
die(json_encode('here'));
}
$catalog = array_values($uniqueArray);
$paginate = (object) [
'items' => $catalog,
'current' => $page * $perPage - $perPage,
];
// $totalItems = count($catalog) <= 30 ? count($catalog) : $totalItems;
$title = str_replace(["{total}", "{year}"], [$totalItems, $currentYear], $title);
$simpleTitle = str_replace(["{total}", "{year}"], ["", $currentYear], $simpleTitle);
$description = str_replace(["{total}", "{year}"], [$totalItems, $currentYear], $description);
$metaTitle = str_replace(["{total}", "{year}"], [$totalItems, $currentYear], $metaTitle);
$metaDescription = str_replace(["{total}", "{year}"], [$totalItems, $currentYear], $metaDescription);
if ($isTestSub301 == 'remstylex7') {
die(json_encode('here'));
}
if ($this->request->isAjax()) {
if ($isTestSub301 == 'remstylex8') {
die(json_encode('here'));
}
$this->response->setContentType('application/json');
$this->view->disable();
$html = $this->view->getPartial('partials/catalog/items', [
'partners' => $paginate,
'category' => $category,
'isAjax' => true,
]);
echo json_encode([
'html' => $html,
'showMore' => $totalItems > $page * $perPage,
]);
} else {
if ($isTestSub301 == 'remstylex9') {
die(json_encode('here'));
}
$this->assets->collection('header')
->addCss('assets/page/top-business/style.css?v=375')
->addCss('https://cdnjs.cloudflare.com/ajax/libs/tooltipster/4.2.8/css/tooltipster.bundle.min.css')
->addCss('assets/page/top-business/keyword-previewer.css');
$this->assets->collection('footer')
->addJs('src/vendor/jquery/dist/jquery.min.js')
->addJs('assets/packages/jquery.lazy/jquery.lazy.min.js')
->addJs('assets/page/top-business/keyword-previewer.js')
->addJs('assets/page/top-business/catalog.js?v=213')
->addJs('assets/js/catalog.js?v='.rand(10, 10000))
->addJs('assets/companent/devbridge-autocomplete/src/jquery.autocomplete.js')
->addJs('https://cdnjs.cloudflare.com/ajax/libs/tooltipster/4.2.8/js/tooltipster.bundle.min.js');
$paginate->items = $catalog;
$this->view->isAjax = false;
$this->view->partners = $paginate;
$this->view->category = $category;
$this->view->total_items = $totalItems;
$this->view->simpleTitle = html_entity_decode($simpleTitle, ENT_QUOTES);
$this->title = html_entity_decode($title, ENT_QUOTES);
$this->metaTitle = $metaTitle;
$this->description = html_entity_decode($description, ENT_QUOTES);
$this->seoTitle = html_entity_decode($metaTitle, ENT_QUOTES);
$this->view->isTopTen = 1;
$this->seoDescription = html_entity_decode($metaDescription, ENT_QUOTES);
if ($isTestSub301 == 'remstylex10') {
die(json_encode('here'));
}
// related categories logic
$this->view->relatedCategories = CatalogTopPages::getRelatedCategoriesPages($this->config->baseUri,
$category, $countryCode, $stateCode, $cityName);
if ($isTestSub301 == 'remstylex11') {
die(json_encode('here'));
}
$this->view->countryCode = $countryCode;
$this->view->countryName = $countryName;
$this->view->faq = html_entity_decode($faq, ENT_QUOTES);
$this->view->stateCode = $stateCode;
$this->view->stateName = $stateName;
$this->view->currentLocationName = $cityName ? $cityName : $stateLocationName;
$this->view->profileMapLocations = $profileMapLocations;
$this->view->categorySlug = $categorySlug;
$this->view->cityName = ucwords(str_replace('-', ' ', $cityName));
$this->view->cityCode = $cityName;
if ($isTestSub301 == 'remstylex12') {
die(json_encode('here'));
}
$this->view->countries = GeoCountries::getList();
$this->view->categories = CatalogCategories::getList($countryCode, $stateCode, $cityName);
$this->view->buildJsNoNeed = true;
$this->view->ldJsonProfiles = json_encode($ldJsonProfiles);
if ($isTestSub301 == 'remstylex13') {
die(json_encode('here'));
}
$ldJsonLocation = (object) [
"@context" => "https://schema.org/",
"@type" => "City",
"name" => $cityName,
"containedIn" => [
"@type" => "State",
"name" => $stateLocationName
]
];
if ($isTestSub301 == 'remstylex14') {
die(json_encode('here'));
}
$this->view->ldJsonLocation = json_encode($ldJsonLocation);
if ($isTestSub301 == 'remstylex15') {
die(json_encode('here'));
}
if ($category->type == 2) {
$this->view->faq = '';
}
}
}
public function getStatesAction()
{
$this->response->setContentType('application/json');
$this->view->disable();
$countryId = $this->request->getPost('countryId', ['trim', 'string'], '');
$countryCode = $this->request->getPost('countryCode', ['trim', 'string'], '');
$categorySlug = $this->request->getPost('categorySlug', ['trim', 'string'], '');
$states = GeoStates::getList($countryId, $countryCode, $categorySlug);
return $this->response->setJsonContent(['status' => 'success', 'states' => $states]);
}
public function getCitiesAction()
{
$this->response->setContentType('application/json');
$this->view->disable();
$countryId = $this->request->getPost('countryId', ['trim', 'string'], '');
$countryCode = $this->request->getPost('countryCode', ['trim', 'string'], '');
$stateId = $this->request->getPost('stateId', ['trim', 'string'], '');
$stateCode = $this->request->getPost('stateCode', ['trim', 'string'], '');
$categorySlug = $this->request->getPost('categorySlug', ['trim', 'string'], '');
$cities = GeoCities::getList($countryId, $stateId, $countryCode, $stateCode, $categorySlug);
return $this->response->setJsonContent(['status' => 'success', 'cities' => $cities]);
}
public function onlineViewAction()
{
$categories = $this->modelsManager->createBuilder()
->columns([
"category.category as category",
"category.slug as slug",
])
->from(['category' => CatalogCategories::class])
->where("category.type = :type:")
->andWhere("category.status = :status:")
->setBindParams([
"type" => 2,
"status" => 1
])
->orderBy('category.id DESC')
->getQuery()
->execute()
->toArray();
if (count($categories) <= 0) {
return $this->route404Action();
}
$linkItems = [];
foreach ($categories as $category) {
$categoryText = ucwords($category['category']);
$categoryText = str_replace('_', ' ', $categoryText);
$linkItems[] = [
"link" => $this->config->baseUri.'online'."/".$category['slug'],
"text" => $categoryText
];
}
$title = $this->seoTitle = "Best Online Business Directory Listings Globally - TrustAnalytica";
$description = "Below is the list of online business categories and listings that TrustAnalytica serves Globally.";
$this->assets->collection('headerGoogle')
->addCss('assets/css/logic-block.css?v='.$this->ver);
$this->assets->collection('footer')
->addJs('assets/js/logic-block.js');
$companies = Partners::getLogicBlockPartners($this->config->baseUri);
$reviews = Reviews::getLogicBlockReviews($this->config->baseUri);
$categories = CatalogTopPages::getLogicBlockPages($this->config->baseUri);
$logicBlock = [
'companies' => $companies,
'reviews' => $reviews,
'categories' => $categories
];
$this->view->logicBlock = $logicBlock;
$this->title = html_entity_decode($title, ENT_QUOTES);
$this->description = html_entity_decode($description, ENT_QUOTES);
$this->view->linkItems = $linkItems;
}
public function statesViewAction($countryCode)
{
$states = $this->modelsManager->createBuilder()
->columns([
"LOWER(cStats.countryName) as countryName",
"LOWER(cStats.stateCode) as stateCode",
"cStats.stateName as stateName",
])
->from(['cStats' => CategoriesStatsByStates::class])
->where("cStats.countryCode = :countryCode:")
->andWhere('cStats.totalPartners > 0')
->andWhere('cStats.category != "point_of_interest"')
->andWhere('cStats.category != "establishment"')
->setBindParams([
"countryCode" => $countryCode
])
->orderBy('cStats.totalPartners DESC')
->groupBy('cStats.stateCode')
->getQuery()
->execute()
->toArray();
// die(json_encode($states));
if (count($states) <= 0) {
return $this->route404Action();
}
$first = $states[0];
$this->seoTitle = "Best Local Business Directory Listings in ".$first['countryName'];
$title = "Best Local Businesses in ".$first['countryName'];
$description = "Below is the list of states and provinces that TrustAnalytica serves in ".$first['countryName'].".";
$linkItems = [];
foreach ($states as $state) {
$linkItems[] = [
"link" => $this->config->baseUri.$countryCode."/".$state['stateCode'],
"text" => $state['stateName'].' ('.strtoupper($state['stateCode']).')'
];
}
$this->assets->collection('headerGoogle')
->addCss('assets/css/logic-block.css?v='.$this->ver);
$this->assets->collection('footer')
->addJs('assets/js/logic-block.js');
$companies = Partners::getLogicBlockPartners($this->config->baseUri, $countryCode);
$reviews = Reviews::getLogicBlockReviews($this->config->baseUri, $countryCode);
$categories = CatalogTopPages::getLogicBlockPages($this->config->baseUri, $countryCode);
$logicBlock = [
'companies' => $companies,
'reviews' => $reviews,
'categories' => $categories
];
$this->view->logicBlock = $logicBlock;
$this->title = html_entity_decode($title, ENT_QUOTES);
$this->description = html_entity_decode($description, ENT_QUOTES);
$this->view->linkItems = $linkItems;
}
public function citiesViewAction($countryCode, $stateCode)
{
$cities = $this->modelsManager->createBuilder()
->columns([
"cStats.stateName as stateName",
"cStats.cityName as cityName",
])
->from(['cStats' => CategoriesStatsByCities::class])
->where("cStats.countryCode = :countryCode: AND cStats.stateCode = :stateCode:")
->andWhere('cStats.totalPartners > 0')
->andWhere('cStats.category != "point_of_interest"')
->andWhere('cStats.category != "establishment"')
->andWhere('cStats.totalPartners > 0')
->setBindParams([
"countryCode" => $countryCode,
"stateCode" => $stateCode,
])
->orderBy('cStats.totalPartners DESC')
->groupBy('cStats.cityName')
->getQuery()
->execute()
->toArray();
if (count($cities) <= 0) {
if ($countryCode) {
header("Location: " . env('PROJECT_BASE_URL') . $countryCode, true, 302);
exit();
}
return $this->route404Action();
}
$first = $cities[0];
$this->seoTitle = "Best Local Business Directory Listings in ".$first['stateName'];
$title = "Best Local Businesses in ".$first['stateName'];
$description = "Below is the list of cities that TrustAnalytica serves in ".$first['stateName'].".";
$linkItems = [];
foreach ($cities as $city) {
$linkItems[] = [
"link" => $this->config->baseUri.$countryCode."/".$stateCode."/".$city['cityName'],
"text" => ucwords(str_replace("-", " ", $city['cityName']))
];
}
$this->assets->collection('headerGoogle')
->addCss('assets/css/logic-block.css?v='.$this->ver);
$this->assets->collection('footer')
->addJs('assets/js/logic-block.js');
$companies = Partners::getLogicBlockPartners($this->config->baseUri, $countryCode, $stateCode);
$reviews = Reviews::getLogicBlockReviews($this->config->baseUri, $countryCode, $stateCode);
$categories = CatalogTopPages::getLogicBlockPages($this->config->baseUri, $countryCode, $stateCode);
// die(json_encode($linkItems));
$logicBlock = [
'companies' => $companies,
'reviews' => $reviews,
'categories' => $categories
];
$this->view->logicBlock = $logicBlock;
$this->title = html_entity_decode($title, ENT_QUOTES);
$this->description = html_entity_decode($description, ENT_QUOTES);
$this->view->linkItems = $linkItems;
$this->view->countryCode = $countryCode;
$this->view->stateCode = $stateCode;
}
public function topListViewAction($countryCode, $stateCode, $cityName)
{
if ($cityName == 'sf') {
return $this->response->redirect("/".$countryCode."/".$stateCode."/san-francisco", false, 301);
}
$topPages = $this->modelsManager->createBuilder()
->columns([
"cStats.stateName as stateName",
"cStats.category as category",
"c.slug as slug",
"IF(tp.title IS NULL, c.title, tp.title) as title",
"cStats.totalPartners as totalPartners",
])
->from(['cStats' => CategoriesStatsByCities::class])
->innerJoin(CatalogCategories::class, 'cStats.category = c.category AND c.status = 1 AND c.type = 1', 'c')
->leftJoin(CatalogTopPages::class,
'c.category = tp.category AND cStats.countryCode = tp.countryCode AND cStats.stateCode = tp.stateCode AND cStats.cityName = tp.cityName AND tp.status = 1',
'tp')
->where("cStats.countryCode = :countryCode: AND cStats.stateCode = :stateCode: AND cStats.cityName = :cityName:")
->andWhere('cStats.totalPartners > 0')
->setBindParams([
"countryCode" => $countryCode,
"stateCode" => $stateCode,
"cityName" => $cityName,
])
->orderBy('cStats.totalPartners DESC')
->getQuery()
->execute()
->toArray();
if (count($topPages) <= 0) {
if ($stateCode) {
header("Location: " . env('PROJECT_BASE_URL') . $countryCode . "/" . $stateCode, true, 302);
exit();
}
if ($countryCode) {
header("Location: " . env('PROJECT_BASE_URL') . $countryCode, true, 302);
exit();
}
return $this->route404Action();
}
$first = $topPages[0];
$actualCityName = ucwords(str_replace('-', ' ', $cityName));
$linkItems = [];
foreach ($topPages as $page) {
// die(json_encode($page));
$title = str_replace(['{total}', '{location}', '{year}'],
[$page['totalPartners'], $actualCityName, Carbon::now()->format('Y')], $page['title']);
$linkItems[] = [
"link" => strtolower($this->config->baseUri.$countryCode)."/". strtolower($stateCode)."/".$cityName."/".strtolower(str_replace('_',
'-', $page['slug'])),
"text" => $title
];
}
$this->assets->collection('headerGoogle')
->addCss('assets/css/logic-block.css?v='.$this->ver);
$this->assets->collection('footer')
->addJs('assets/js/logic-block.js');
$companies = Partners::getLogicBlockPartners($this->config->baseUri, $countryCode, $stateCode, $cityName);
$reviews = Reviews::getLogicBlockReviews($this->config->baseUri, $countryCode, $stateCode, $cityName);
$categories = CatalogTopPages::getLogicBlockPages($this->config->baseUri, $countryCode, $stateCode, $cityName);
$logicBlock = [
'companies' => $companies,
'reviews' => $reviews,
'categories' => $categories
];
$this->view->logicBlock = $logicBlock;
$this->seoTitle = "Best Local Business Directory Listings in ".$actualCityName.", ".$first['stateName'];
$this->title = "Best Local Businesses in ".$actualCityName.", ".$first['stateName'];
$this->description = "Below is the list of categories that TrustAnalytica serves in ".$actualCityName;
$this->view->linkItems = $linkItems;
$this->view->countryCode = strtolower($countryCode);
$this->view->stateCode = strtolower($stateCode);
$this->view->cityName = ucwords(str_replace('-', ' ', $cityName));
}
public function categoryAction()
{
$this->response->setContentType('application/json');
$this->view->disable();
$categoryPage = $this->request->getPost('page', 'int', 1);
$categoryType = $this->request->getPost('type', 'int', 1);
$categories = CatalogCategories::getCategories($categoryType, $categoryPage);
$html = $this->view->getPartial("partials/catalog/business-category-container",
['categories' => $categories['items']]);
echo json_encode([
'html' => $html,
'showMore' => $categories['showMore'],
]);
}
/**
* @return \Phalcon\Http\ResponseInterface
*/
public function autocompleteAction()
{
$this->view->disable();
$query = $this->request->get('query', ['trim', 'string'], '');
$type = $this->request->get('type', ['trim', 'string'], '');
$suggestions = [];
if (!empty($query) && $this->request->isPost() && $this->request->isAjax()) {
$suggestions = Partners::getAutocompleteList($query, $type);
return $this->response->setJsonContent(compact('query', 'suggestions'));
}
}
public function businessAction()
{
$search = $this->request->get('find_desc', ['trim', 'search'], '');
$page = $this->request->get('page', 'int', 1);
if (empty($search)) {
return $this->route404Action();
}
$suggestions = Partners::getAutocompleteList($search, 'fullName', 0);
$html = $this->view->getPartial('partials/catalog/items', [
'partners' => (object) [
'items' => $suggestions[0],
],
]);
$this->assets->collection('header')
->addCss('assets/page/top-business/style.css?v=375')
->addCss('assets/css/auto-complete.css')
->addCss('assets/page/top-business/keyword-previewer.css');
$this->assets->collection('footer')
->addJs('src/vendor/jquery/dist/jquery.min.js')
->addJs('assets/packages/jquery.lazy/jquery.lazy.min.js')
->addJs('assets/js/logic-block.js')
->addJs('assets/js/catalog.js?v='.rand(10, 10000))
->addJs('assets/page/top-business/keyword-previewer.js')
->addJs('assets/companent/devbridge-autocomplete/src/jquery.autocomplete.js');
if (!empty($search)) {
$totalSearchResult = count($suggestions);
foreach ($suggestions as $profile) {
$partnerTimings = Partners::getWorkForFront($profile);
$profile->partnerTimings = $partnerTimings;
$facePhotox = $this->facePhotoToUse($profile->id);
$profile->facePhotoToUse = $facePhotox;
}
$this->view->partners = $suggestions;
$this->view->searchResults = 1;
$this->view->totalSearchResult = $totalSearchResult;
}
$this->view->search = $search;
if (!empty($search) || !empty($find_loc)) {
$this->seoTitle = 'robots';
$this->seoDescription = 'noindex,nofollow';
$this->title = "Search Results - TrustAnalytica";
}
}
public function uniqueObjects($array, $key)
{
$tempArray = [];
$resultArray = [];
foreach ($array as $item) {
if (!isset($tempArray[$item[$key]])) {
$tempArray[$item[$key]] = true;
$resultArray[] = $item;
}
}
return $resultArray;
}
public function onlineAction($categorySlug)
{
$profileMapLocations = [];
$category = CatalogCategories::findFirst([
'conditions' => 'slug = :slug: AND type = 2',
'bind' => ['slug' => $categorySlug]
]);
if (!$category) {
return $this->route404Action();
}
if ($category->status == 0) {
return $this->route404Action();
}
$perPage = 30;
$page = $this->request->get('page', 'int', 1);
if ($page <= 0) {
$page = 1;
}
$totalItems = (int) (CategoriesStats::findFirst([
'columns' => 'totalPartners',
'conditions' => 'category = :category:',
'bind' => ['category' => $category->category],
]))->totalPartners;
$ads_partners_count = 0;
if (!$this->request->isAjax()) {
// $ads_partners = AdsBusinesses::getPartners($categorySlug, $countryCode, $stateCode, $cityName);
// $ads_partners_count = count($ads_partners);
$this->view->ads_partners = [];
}
if (!$this->request->isAjax() && $totalItems == 0 && $ads_partners_count == 0) {
return $this->route404Action();
}
$title = $category->title;
$description = $category->description;
$metaTitle = $category->metaTitle;
$metaDescription = $category->metaDescription;
preg_match('/\bin|IN\b/', $title, $titleMatchedWord, PREG_OFFSET_CAPTURE);
if (isset($titleMatchedWord[0][1])) {
$simpleTitle = substr($title, 0, $titleMatchedWord[0][1]);
} else {
$simpleTitle = $title;
}
$currentYear = Carbon::now()->format('Y');
$simpleTitle = str_replace(['{total}', '{year}'], ["", $currentYear], $simpleTitle);
$title = str_replace(['{total}', '{year}'], [$totalItems, $currentYear], $title);
$description = str_replace(['{total}', '{year}'], [$totalItems, $currentYear], $description);
$metaTitle = str_replace(['{total}', '{year}'], [$totalItems, $currentYear], $metaTitle);
$metaDescription = str_replace(['{total}', '{year}'], [$totalItems, $currentYear], $metaDescription);
$catalog = Partners::getCatalogPartners('online', $category->category, $page);
$catalog = $this->sortArrayByConditions($catalog);
$newCatalogArr = [];
$uniqueCatalog = $this->uniqueObjects($catalog, 'id');
foreach ($uniqueCatalog as $item) {
$id = $item['id'];
$checkSubscription = PartnerSubscription::checkSubscription($item->id);
if ($checkSubscription) {
$item->subscription = 1;
} else {
$item->subscription = 0;
}
array_push($newCatalogArr, $item);
$facePhotox = $this->facePhotoToUse($item->id);
$item->facePhotoToUse = $facePhotox;
$mapLocation = [(string) $item->lat, (string) $item->lng, $item->fullName, (string) $item->fullAddress];
if($item->lat != '' || $item->lat != null) {
$profileMapLocations[] = $mapLocation;
}
$profileMapLocations[] = $mapLocation;
$partnerType = Partners::getActualType($item->id);
$item->partnerCategory = $partnerType;
$partnerTimings = Partners::getWorkForFront($item);
$item->partnerTimings = $partnerTimings;
}
$paginate = (object) [
'items' => $uniqueCatalog,
'current' => $page * $perPage - $perPage,
];
if ($this->request->isAjax()) {
$this->response->setContentType('application/json');
$this->view->disable();
$html = $this->view->getPartial('partials/catalog/items', [
'partners' => $paginate,
'category' => $category,
'isAjax' => true,
]);
echo json_encode([
'html' => $html,
'showMore' => $totalItems > $page * $perPage,
]);
} else {
$this->view->pick('catalog/index');
$this->assets->collection('header')
->addCss('assets/page/top-business/style.css?v=375')
->addCss('assets/page/top-business/keyword-previewer.css');
$this->assets->collection('footer')
->addJs('src/vendor/jquery/dist/jquery.min.js')
->addJs('assets/packages/jquery.lazy/jquery.lazy.min.js')
->addJs('assets/page/top-business/keyword-previewer.js')
->addJs('assets/js/catalog.js?v='.rand(10, 10000))
->addJs('assets/companent/devbridge-autocomplete/src/jquery.autocomplete.js')
->addJs('assets/page/top-business/catalog.js?v=25');
$this->view->isAjax = false;
$this->view->partners = $paginate;
$this->view->category = $category;
$this->view->total_items = $totalItems;
$this->view->profileMapLocations = $profileMapLocations;
$this->view->simpleTitle = html_entity_decode($simpleTitle, ENT_QUOTES);
$this->view->faq = html_entity_decode($category->faq, ENT_QUOTES);
$this->view->categories = CatalogCategories::getCategories(2, 1, true);
$this->view->categorySlug = $categorySlug;
$this->view->isTopTen = 1;
$this->title = html_entity_decode($title, ENT_QUOTES);
$this->metaTitle = html_entity_decode($metaTitle, ENT_QUOTES);
$this->description = html_entity_decode($description, ENT_QUOTES);
$this->seoTitle = html_entity_decode($metaTitle, ENT_QUOTES);
$this->seoDescription = html_entity_decode($metaDescription, ENT_QUOTES);
// related categories logic
$this->view->relatedCategories = CatalogTopPages::getRelatedCategoriesPages($this->config->baseUri,
$category);
$this->view->buildJsNoNeed = true;
$this->view->setRenderLevel(
View::LEVEL_MAIN_LAYOUT
);
}
}
public function facePhotoToUse($id) {
$photos = PartnerDetails::findFirstByPartnerId($id);
if($photos) {
if($photos->apiPhotos == 1) {
$partner = Partners::findFirstById($id);
if($partner->facePhoto != null || $partner->facePhoto != '') {
return $partner->facePhoto;
} else {
if($partner->mediaPhotos != null) {
$photos = json_decode($partner->mediaPhotos, true);
return $photos[0];
}
}
}
if($photos->partnerDashPhotos == 1) {
$partnerChanges = UserPartnerChanges::findFirstByfkPartnersId($id);
if($partnerChanges->facePhoto != null || $partnerChanges->facePhoto != '') {
return $partnerChanges->facePhoto;
} else {
if($partnerChanges->mediaPhotos != null) {
$photos = json_decode($partnerChanges->mediaPhotos, true);
return $photos[0];
}
}
}
if($photos->websiteScreenshots == 1) {
$partner = Partners::findFirstById($id);
if($partner->websiteScreenshots != null) {
$photos = json_decode($partner->websiteScreenshots, true);
return $photos[0];
}
}
if($photos->categoryPhotos == 1) {
$partner = Partners::findFirstById($id);
if($partner->categoryPhotos != null) {
$photos = json_decode($partner->categoryPhotos, true);
return $photos[1];
}
}
} else {
$partner = Partners::findFirstById($id);
return $partner->facePhoto != null || $partner->facePhoto != '' ? $partner->facePhoto : $partner->mediaPhotos[0];
}
}
}
|