| Current Path : /proc/1908984/root/proc/2603263/cwd/ |
| Current File : //proc/1908984/root/proc/2603263/cwd/app.tar |
Company.php 0000644 00000026053 15235341141 0006670 0 ustar 00 <?php
/**
* @package Google Structured Data
* @version 5.6.5 Pro
*
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
defined('_JEXEC') or die('Restricted access');
use GSD\Helper;
use NRFramework\Functions;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
trait Company
{
/**
* Provides the payload for Company pages.
*
* Producing Schema: Local Business
*
* @return mixed
*/
protected function viewCompanies()
{
// Make sure we have a valid ID
if (!$id = $this->getThingID())
{
return;
}
if (!class_exists('JBusinessUtil'))
{
return;
}
$model = BaseDatabaseModel::getInstance('ManageCompany', 'JBusinessDirectoryModel', ['ignore_request' => true]);
if (!$this->item = $model->getItem($id))
{
return;
}
// Get reviews for this business
$reviews = $this->getReviews(1);
$country = $this->getItemCountry($this->item->countryId);
// Get the currency
$currency = JBusinessUtil::getCurrency($this->getAppSettingPropertyValue('currency_id'));
$price = $this->getPackageProperty('price');
// Prepare Data
$payload = [
'id' => $id,
'alias' => $this->item->alias,
'headline' => $this->item->name,
'image' => BD_PICTURES_PATH . $this->item->logoLocation,
'imagetext' => Helper::getFirstImageFromString($this->item->short_description . $this->item->description),
'introtext' => $this->item->short_description,
'description' => empty($this->item->short_description) ? $this->item->description : $this->item->short_description,
'fulltext' => $this->item->description,
'created' => Functions::dateToUTC($this->item->creationDate),
'created_by' => $this->item->userId,
'modified' => Functions::dateToUTC($this->item->modified),
'streetAddress' => $this->item->address,
'addressCountry' => $country ? $country->country_name : '',
'postalCode' => $this->item->postalCode,
'addressRegion' => $this->item->city . ', ' . $this->item->county,
'addressLocality' => $this->item->address . ' ' . $this->item->street_number,
'geo' => $this->item->latitude . ',' . $this->item->longitude,
'telephone' => $this->item->phone,
'offerPrice' => $price,
'priceRange' => $price ? ($currency->currency_symbol === '#' ? $currency->currency_name : $currency->currency_symbol . $price) : '',
'reviews' => $reviews,
'reviewCount' => is_array($reviews) ? count($reviews) : 0,
'ratingValue' => JBusinessUtil::getReviewsAverageScore($reviews),
'metadesc' => $this->item->meta_description,
'openinghours' => $this->getCompanyOpeningHours()
];
// Add shared fields values
$payload = array_merge($payload, $this->getSharedFieldValues());
// Add business fields values
$payload = array_merge($payload, $this->getCompanyFieldValues());
// Add business custom fields (Custom Attributes) values
$payload = array_merge($payload, $this->getItemCustomFieldsValues('company'));
return $payload;
}
/**
* Company fields of a J-BusinessDirectory item.
*
* @return array
*/
private function getCompanyFields()
{
$fields = [
// Package Name
'package_name' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_PACKAGE_NAME'),
// Package Description
'package_description' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_PACKAGE_DESCRIPTION'),
// Package Price
'package_price' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_PACKAGE_PRICE'),
// Package Special Price
'package_special_price' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_PACKAGE_SPECIAL_PRICE'),
// Package Renewal Price
'package_renewal_price' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_PACKAGE_RENEWAL_PRICE'),
// Telephone
'telephone' => Text::_('LNG_TELEPHONE'),
// Business Name
'name' => Text::_('LNG_COMPANY_NAME'),
// Website
'website' => Text::_('LNG_WEBSITE'),
// Business Type
'business_type' => Text::_('LNG_COMPANY_TYPE'),
// Establishment Year
'establishment_year' => Text::_('LNG_ESTABLISHMENT_YEAR'),
// Employees
'employees' => Text::_('LNG_EMPLOYEES'),
// Keywords
'keywords' => Text::_('LNG_KEYWORDS'),
// Slogan
'slogan' => Text::_('LNG_COMPANY_SLOGAN'),
// Categories
'selectedCategories' => Text::_('LNG_CATEGORIES'),
// Main Category
'mainSubcategory' => Text::_('LNG_MAIN_SUBCATEGORY'),
// Activity Radius
'activity_radius' => Text::_('LNG_ACTIVITY_RADIUS'),
// Business Contact Information - Email
'email' => 'PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CONTACT_INFORMATION_EMAIL',
// Company Editors
'companyEditors' => 'LNG_COMPANY_EDITORS',
// Business Cover Image
'business_cover_image' => Text::_('LNG_BUSINESS_COVER_IMAGE'),
// Business Opening Hours Notes
'business_opening_hours_notes' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_OPENING_HOURS_NOTES'),
// Business Custom Tab Name
'business_custom_tab_name' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CUSTOM_TAB_NAME'),
// Business Custom Tab Content
'business_custom_tab_content' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CUSTOM_TAB_CONTENT')
];
/**
* Business Contact Person consists from a Repeater field
* which we do not know how many items can have per Business listing.
*
* For this purpose, we assume 5 person details are enough and add them
* manually. If we later need more items, we can increase them.
*/
for ($i = 0; $i < 5; $i++)
{
$fields = array_merge($fields, [
// Business Contact Person - Contact #XX - Department
'contact_department_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CONTACT_PERSON_DEPARTMENT'), ($i + 1)),
// Business Contact Person - Contact #XX - Name
'contact_name_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CONTACT_PERSON_NAME'), ($i + 1)),
// Business Contact Person - Contact #XX - Telephone
'contact_phone_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CONTACT_PERSON_TELEPHONE'), ($i + 1)),
// Business Contact Person - Contact #XX - Email
'contact_email_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_BUSINESS_CONTACT_PERSON_EMAIL'), ($i + 1))
]);
}
return $fields;
}
/**
* Returns the company related field values.
*
* @return array
*/
private function getCompanyFieldValues()
{
$payload = [
'company.package_name' => $this->getPackageProperty('name'),
'company.package_description' => $this->getPackageProperty('description'),
'company.package_price' => $this->getPackageProperty('price'),
'company.package_special_price' => $this->getPackageProperty('special_price'),
'company.package_renewal_price' => $this->getPackageProperty('renewal_price'),
'company.telephone' => $this->item->phone,
'company.name' => $this->item->name,
'company.website' => $this->item->website,
'company.business_type' => $this->getCompanyTypesNames(),
'company.establishment_year' => $this->item->establishment_year,
'company.employees' => $this->item->employees,
'company.keywords' => $this->item->keywords,
'company.slogan' => $this->item->slogan,
'company.selectedCategories' => $this->getItemSelectedCategories($this->item->selectedCategories),
'company.mainCategory' => $this->getItemCategoryByID($this->item->mainSubcategory),
'company.activity_radius' => $this->item->activity_radius,
'company.email' => $this->item->email,
'company.companyEditors' => $this->getCompanyEditors(),
'company.business_cover_image' => BD_PICTURES_PATH . $this->item->business_cover_image,
'company.business_opening_hours_notes' => $this->item->notes_hours,
'company.business_custom_tab_name' => $this->item->custom_tab_name,
'company.business_custom_tab_content' => $this->item->custom_tab_content
];
return array_merge($payload, $this->getBusinessContacts($this->item->contacts));
}
/**
* Get all Business Contacts of a business listing.
*
* @param array $contacts
*
* @return mixed
*/
private function getBusinessContacts($contacts = [])
{
if (!$contacts || !is_array($contacts) || !count($contacts))
{
return;
}
$payload = [];
for ($i = 0; $i < count($contacts); $i++)
{
$payload['company.contact_department_' . $i] = $contacts[$i]->contact_department;
$payload['company.contact_name_' . $i] = $contacts[$i]->contact_name;
$payload['company.contact_phone_' . $i] = $contacts[$i]->contact_phone;
$payload['company.contact_email_' . $i] = $contacts[$i]->contact_email;
}
return $payload;
}
/**
* Returns the company Opening Hours
*
* @return object
*/
private function getCompanyOpeningHours()
{
$opening_hours = new stdClass();
$opening_hours->option = 2;
$companyModel = BaseDatabaseModel::getInstance('Company', 'JBusinessDirectoryModel', ['ignore_request' => true]);
$working_days = $companyModel->getWorkingDays($this->item->id);
foreach ($working_days as $key => $value)
{
$lc_day = strtolower($value->name);
$oh_item_value = new stdClass();
$oh_item_value->enabled = $value->workHours['status'] === '1';
$oh_item_value->start = $value->workHours['start_time'];
$oh_item_value->end = $value->workHours['end_time'];
// Add break hours
if (isset($value->breakHours))
{
$oh_item_value->start1 = isset($value->breakHours['start_time'][0]) ? $value->breakHours['start_time'][0] : false;
$oh_item_value->end1 = isset($value->breakHours['end_time'][0]) ? $value->breakHours['end_time'][0] : false;
}
$opening_hours->$lc_day = $oh_item_value;
}
return $opening_hours;
}
/**
* Returns the company editors names.
*
* @return mixed
*/
private function getCompanyEditors()
{
if (!$this->item->editors || !is_array($this->item->editors) || !count($this->item->editors))
{
return;
}
$names = [];
foreach ($this->item->editors as $key => $value)
{
$names[] = trim($value->name);
}
return implode(', ', $names);
}
/**
* Finds and returns all company types names
*
* @return mixed
*/
private function getCompanyTypesNames()
{
if (!$this->item->typeId)
{
return;
}
if (!$typesTable = Table::getInstance('CompanyTypes', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
$names = [];
foreach ($this->item->typeId as $id)
{
if (!$name = $typesTable->getCompanyType($id))
{
continue;
}
$names[] = trim($name->name);
}
return implode(', ', $names);
}
/**
* Returns the company.
*
* @var int $id
*
* @return object
*/
private function getCompany($id)
{
if (!$table = Table::getInstance('Company', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
return $table->getCompany($id);
}
/**
* Returns a property value of the item's package.
*
* @param string $prop
*
* @return mixed
*/
private function getPackageProperty($prop = null)
{
if (!$prop)
{
return;
}
if (!isset($this->item->package))
{
return;
}
if (!property_exists($this->item->package, $prop))
{
return;
}
return $this->item->package->$prop;
}
} Event.php 0000644 00000020533 15235341141 0006340 0 ustar 00 <?php
/**
* @package Google Structured Data
* @version 5.6.5 Pro
*
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
defined('_JEXEC') or die('Restricted access');
use GSD\Helper;
use NRFramework\Functions;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
trait Event
{
/**
* Provides the payload for Event pages.
*
* Producing Schema: Event
*
* @return mixed
*/
protected function viewEvent()
{
$this->thingRequestIDName = 'eventId';
// Make sure we have a valid ID
if (!$id = $this->getThingID())
{
return;
}
if (!class_exists('JBusinessUtil'))
{
return;
}
$model = BaseDatabaseModel::getInstance('Event', 'JBusinessDirectoryModel', ['ignore_request' => true]);
if (!$this->item = $model->getItem($id))
{
return;
}
if ($videosTable = Table::getInstance('EventVideos', '\\Joomla\\CMS\\Table\\', []))
{
$this->item->videos = $videosTable->getEventVideos($id);
}
if ($attributesTable = Table::getInstance('EventAttributes', '\\Joomla\\CMS\\Table\\', []))
{
$this->item->customFields = $attributesTable->getEventAttributes($id);
}
$country = $this->getItemCountry($this->item->countryId);
$shared_fields_values = $this->getSharedFieldValues();
$payload = [
'id' => $id,
'alias' => $this->item->alias,
'headline' => $this->item->name,
// Since there isn't a specific image we can set, get the first image from the Pictures field
'image' => isset($shared_fields_values['shared.picture_url_0']) ? $shared_fields_values['shared.picture_url_0'] : '',
'imagetext' => Helper::getFirstImageFromString($this->item->short_description . $this->item->description),
'introtext' => $this->item->short_description,
'description' => empty($this->item->short_description) ? $this->item->description : $this->item->short_description,
'fulltext' => $this->item->description,
'created' => Functions::dateToUTC($this->item->created),
'startDate' => Functions::dateToUTC($this->item->start_date . ' ' . $this->item->start_time),
'endDate' => Functions::dateToUTC($this->item->end_date . ' ' . $this->item->end_time),
'locationName' => $this->item->address,
'locationAddress' => $this->item->address,
'addressCountry' => $country ? $country->country_name : '',
'addressLocality' => $this->item->address . ' ' . $this->item->street_number,
'addressRegion' => $this->item->city . ', ' . $this->item->county,
'postalCode' => $this->item->postalCode,
'offerPrice' => $this->item->price,
'metakey' => $this->item->meta_keywords,
'metadesc' => $this->item->meta_description,
'online_url' => $this->item->attendance_url
];
// Add shared fields values
$payload = array_merge($payload, $shared_fields_values);
// Add event fields values
$payload = array_merge($payload, $this->getEventFieldValues());
// Add event custom fields (Custom Attributes) values
$payload = array_merge($payload, $this->getItemCustomFieldsValues('event'));
return $payload;
}
/**
* Event fields of a J-BusinessDirectory item.
*
* @return array
*/
private function getEventFields()
{
$fields = [
// Hosted By
'company' => Text::_('LNG_HOSTED_BY'),
// Attendance Mode
'attendance_mode' => Text::_('LNG_ATTENDANCE_MODE'),
// Attendance URL
'attendance_url' => Text::_('LNG_ATTENDANCE_URL'),
// Type
'type' => Text::_('LNG_TYPE'),
// Price
'price' => Text::_('LNG_PRICE'),
// Currency
'currency' => Text::_('LNG_CURRENCY'),
// Minimum Age
'min_age' => Text::_('LNG_MIN_AGE'),
// Maximum Age
'max_age' => Text::_('LNG_MAX_AGE'),
// Category
'categories' => Text::_('LNG_CATEGORY'),
// Main Category
'main_subcategory' => Text::_('LNG_MAIN_SUBCATEGORY'),
// Start Date
'start_date' => Text::_('LNG_START_DATE'),
// Start Datetime
'start_date_time' => Text::_('NR_START_PUBLISHING'),
// End Date
'end_date' => Text::_('LNG_END_DATE'),
// End Datetime
'end_date_time' => Text::_('NR_FINISH_PUBLISHING'),
// Start Time
'start_time' => Text::_('LNG_START_TIME'),
// End Time
'end_time' => Text::_('LNG_END_TIME'),
// Time Zone
'time_zone' => Text::_('LNG_TIME_ZONE'),
// Doors Open Time
'doors_open_time' => Text::_('LNG_DOORS_OPEN_TIME'),
// Participating Companies
'associated_companies' => Text::_('LNG_ASSOCIATED_COMPANIES'),
// Event Contact Telephone
'contact_phone' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_EVENT_CONTACT_TELEPHONE'),
// Event Contact Email
'contact_email' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_EVENT_CONTACT_EMAIL'),
// Meta Keywords
'meta_keywords' => Text::_('LNG_META_KEYWORDS')
];
/**
* Attachments consists from a Repeater field
* which we do not know how many items can have per Event.
*
* For this purpose, we assume 5 attachments details are enough and add them
* manually. If we later need more items, we can increase them.
*/
for ($i = 0; $i < 5; $i++)
{
$fields = array_merge($fields, [
'attachment_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_ATTACHMENT'), $i + 1)
]);
}
return $fields;
}
/**
* Returns the event related field values.
*
* @return array
*/
private function getEventFieldValues()
{
// Get the company
$company = $this->getCompany($this->item->company_id);
// Get the currency
$currency = JBusinessUtil::getCurrency($this->item->currency_id);
$currency_symbol = $currency->currency_symbol === '#' ? $currency->currency_name : $currency->currency_symbol;
$payload = [
'event.company' => $company->name,
'event.attendance_mode' => $this->getAttendanceMode($this->item->attendance_mode),
'event.attendance_url' => $this->item->attendance_url,
'event.type' => $this->item->eventType,
'event.price' => $currency_symbol . $this->item->price,
'event.currency' => $currency_symbol,
'event.min_age' => $this->item->min_age,
'event.max_age' => $this->item->max_age,
'event.categories' => $this->getItemCategories(),
'event.main_subcategory' => $this->getItemCategoryByID($this->item->main_subcategory),
'event.start_date' => $this->item->start_date,
'event.start_date_time' => Functions::dateToUTC($this->item->start_date . ' ' . $this->item->start_time),
'event.end_date' => $this->item->end_date,
'event.end_date_time' => Functions::dateToUTC($this->item->end_date . ' ' . $this->item->end_time),
'event.start_time' => $this->item->start_time,
'event.end_time' => $this->item->end_time,
'event.time_zone' => $this->item->time_zone,
'event.doors_open_time' => $this->item->doors_open_time,
'event.associated_companies' => $this->getEventAssociatedCompanies(),
'event.contact_phone' => $this->item->contact_phone,
'event.contact_email' => $this->item->contact_email,
'event.meta_keywords' => $this->item->meta_keywords
];
return array_merge($payload, $this->getItemAttachments('event.'));
}
/**
* Returns all event associated companies.
*
* @return mixed
*/
private function getEventAssociatedCompanies()
{
if (!$eventAssociatedCompanies = Table::getInstance('EventAssociatedCompanies', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
// Ensure this event is tied to a company
if (!$eventAssociatedCompanies->getAssociatedCompaniesByEvent($this->item->id))
{
return;
}
if (!$associated_companies = $eventAssociatedCompanies->getAssociatedCompanyOptions($this->item->id))
{
return;
}
$labels = [];
foreach ($associated_companies as $key => $value)
{
if (!isset($value->name))
{
continue;
}
$labels[] = $value->name;
}
return implode(', ', $labels);
}
/**
* Returns the attendance mode label.
*
* @param string $value
*
* @return mixed
*/
private function getAttendanceMode($value)
{
$mode = 'Offline';
foreach(JBusinessUtil::getAttendanceModes() as $md)
{
if ($md->value !== $value)
{
continue;
}
$mode = $md->text;
}
switch (strtolower($mode)) {
case 'live':
$mode = 'Offline';
break;
case 'virtual':
$mode = 'Online';
break;
case 'mixed':
$mode = 'Mixed';
break;
}
return 'https://schema.org/' . $mode . 'EventAttendanceMode';
}
} Offer.php 0000644 00000020061 15235341141 0006314 0 ustar 00 <?php
/**
* @package Google Structured Data
* @version 5.6.5 Pro
*
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
defined('_JEXEC') or die('Restricted access');
use GSD\Helper;
use NRFramework\Functions;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
trait Offer
{
/**
* The currency.
*
* @var object
*/
protected $currency;
/**
* The currency symbol.
*
* @var string
*/
protected $currency_symbol;
/**
* Provides the payload for Offer pages.
*
* Producing Schema: Service
*
* @return mixed
*/
protected function viewOffer()
{
$this->thingRequestIDName = 'offerId';
// Make sure we have a valid ID
if (!$id = $this->getThingID())
{
return;
}
if (!class_exists('JBusinessUtil'))
{
return;
}
$model = BaseDatabaseModel::getInstance('Offer', 'JBusinessDirectoryModel', ['ignore_request' => true]);
if (!$this->item = $model->getItem($id))
{
return;
}
if ($attributesTable = Table::getInstance('OfferAttributes', '\\Joomla\\CMS\\Table\\', []))
{
$this->item->customFields = $attributesTable->getOfferAttributes($id);
}
$country = $this->getItemCountry($this->item->countryId);
// Get the currency
$this->currency = JBusinessUtil::getCurrency($this->item->currencyId);
$this->currency_symbol = $this->currency ? ($this->currency->currency_symbol === '#' ? $this->currency->currency_name : $this->currency->currency_symbol) : '';
$shared_fields_values = $this->getSharedFieldValues();
$lowestPrice = $this->item->specialPrice ? $this->item->specialPrice : $this->item->price;
$payload = [
'id' => $id,
'alias' => $this->item->alias,
'headline' => $this->item->subject,
// Since there isn't a specific image we can set, get the first image from the Pictures field
'image' => isset($shared_fields_values['shared.picture_url_0']) ? $shared_fields_values['shared.picture_url_0'] : '',
'imagetext' => Helper::getFirstImageFromString($this->item->short_description . $this->item->description),
'introtext' => $this->item->short_description,
'description' => empty($this->item->short_description) ? $this->item->description : $this->item->short_description,
'fulltext' => $this->item->description,
// Set the provider name to the company name
'provider_name' => $this->item->company->name,
// Set the provider image as the company's logo
'provider_image' => BD_PICTURES_PATH . $this->item->company->logoLocation,
'provider_streetAddress' => $this->item->address,
'provider_country' => $country ? $country->country_name : '',
'provider_city' => $this->item->city,
'provider_addressRegion' => $this->item->city . ', ' . $this->item->county,
'provider_postalCode' => $this->item->postalCode,
'offerPrice' => $lowestPrice,
'priceRange' => ($this->item->specialPrice ? $this->currency_symbol . $this->item->specialPrice . '-' : '') . $this->currency_symbol . $this->item->price,
'currency' => $this->currency_symbol,
'metakey' => $this->item->meta_keywords,
'metadesc' => $this->item->meta_description,
'created' => Functions::dateToUTC($this->item->created)
];
// Add shared fields values
$payload = array_merge($payload, $shared_fields_values);
// Add offer fields values
$payload = array_merge($payload, $this->getOfferFieldValues());
// Add offer custom fields (Custom Attributes) values
$payload = array_merge($payload, $this->getItemCustomFieldsValues('offer'));
return $payload;
}
/**
* Offer fields of a J-BusinessDirectory item.
*
* @return array
*/
private function getOfferFields()
{
$fields = [
// Select a business
'company' => Text::_('LNG_SELECT_A_BUSINESS'),
// Subject
'subject' => Text::_('LNG_SUBJECT'),
// Start Date
'startDate' => Text::_('LNG_START_DATE'),
// End Date
'endDate' => Text::_('LNG_END_DATE'),
// Publish start date
'publish_start_date' => Text::_('LNG_PUBLISH_START_DATE'),
// Publish end date
'publish_end_date' => Text::_('LNG_PUBLISH_END_DATE'),
// Publish start date time
'publish_start_date_time' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_START_DATE_TIME'),
// Publish end date time
'publish_end_date_time' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_END_DATE_TIME'),
// Time Zone
'time_zone' => Text::_('LNG_TIME_ZONE'),
// Publish start time
'publish_start_time' => Text::_('LNG_PUBLISH_START_TIME'),
// Publish end time
'publish_end_time' => Text::_('LNG_PUBLISH_END_TIME'),
// Price
'price' => Text::_('LNG_PRICE'),
// Price base
'price_base' => Text::_('LNG_PRICE_BASE'),
// Price base unit
'price_base_unit' => Text::_('LNG_PRICE_BASE_UNIT'),
// Special price
'specialPrice' => Text::_('LNG_SPECIAL_PRICE'),
// Special price base
'special_price_base' => Text::_('LNG_SPECIAL_PRICE_BASE'),
// Special price base unit
'special_price_base_unit' => Text::_('LNG_SPECIAL_PRICE_BASE_UNIT'),
// Currency
'currency' => Text::_('LNG_CURRENCY'),
// Price Text
'price_text' => Text::_('LNG_PRICE_TEXT'),
// Contact Email
'contact_email' => Text::_('PLG_GSD_JBUSINESSDIRECTORY_OFFER_CONTACT_EMAIL'),
// Offer Type
'offer_type' => Text::_('LNG_TYPE'),
// Coupons number
'total_coupons' => Text::_('LNG_COUPONS_NUMBER'),
// Category
'categories' => Text::_('LNG_CATEGORY'),
// Main Category
'main_subcategory' => Text::_('LNG_MAIN_SUBCATEGORY'),
// Meta Keywords
'meta_keywords' => Text::_('LNG_META_KEYWORDS')
];
/**
* Attachments consists from a Repeater field
* which we do not know how many items can have per Event.
*
* For this purpose, we assume 5 attachments details are enough and add them
* manually. If we later need more items, we can increase them.
*/
for ($i = 0; $i < 5; $i++)
{
$fields = array_merge($fields, [
'attachment_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_ATTACHMENT'), $i + 1)
]);
}
return $fields;
}
/**
* Returns the offer related field values.
*
* @return array
*/
private function getOfferFieldValues()
{
$payload = [
'offer.company' => $this->item->company->name,
'offer.subject' => $this->item->subject,
'offer.startDate' => $this->item->startDate,
'offer.endDate' => $this->item->endDate,
'offer.publish_start_date' => $this->item->publish_start_date,
'offer.publish_end_date' => $this->item->publish_end_date,
'offer.publish_start_date_time' => Functions::dateToUTC($this->item->publish_start_date . ' ' . $this->item->publish_start_time),
'offer.publish_end_date_time' => Functions::dateToUTC($this->item->publish_end_date . ' ' . $this->item->publish_end_time),
'offer.price' => $this->currency_symbol . $this->item->price,
'offer.price_base' => $this->item->price_base,
'offer.price_base_unit' => $this->item->price_base_unit,
'offer.specialPrice' => $this->item->specialPrice,
'offer.special_price_base' => $this->item->special_price_base,
'offer.special_price_base_unit' => $this->item->special_price_base_unit,
'offer.currency' => $this->currency_symbol,
'offer.price_text' => $this->item->price_text,
'offer.contact_email' => $this->item->contact_email,
'offer.offer_type' => $this->getOfferType(),
'offer.total_coupons' => $this->item->total_coupons,
'offer.categories' => $this->getItemCategories(),
'offer.main_subcategory' => $this->getItemCategoryByID($this->item->main_subcategory),
'offer.meta_keywords' => $this->item->meta_keywords
];
return array_merge($payload, $this->getItemAttachments('offer.'));
}
/**
* Return the offer name
*
* @return mixed
*/
private function getOfferType()
{
if (!$offerTable = Table::getInstance('OfferType', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
if (!$this->item->offer_type)
{
return;
}
if (!$offer = $offerTable->getOfferType($this->item->offer_type))
{
return;
}
return $offer->name;
}
} Shared.php 0000644 00000023613 15235341141 0006467 0 ustar 00 <?php
/**
* @package Google Structured Data
* @version 5.6.5 Pro
*
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
defined('_JEXEC') or die('Restricted access');
use GSD\MappingOptions;
use NRFramework\Functions;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
class Shared extends GSD\PluginBase
{
/**
* Returns the schema allowed in the current page to be rendered.
*
* @return string
*/
protected function getCurrentPageAllowedContentType()
{
$allowed_schema = 'localbusiness';
switch ($this->app->input->get('view')) {
case 'event':
$allowed_schema = 'event';
break;
case 'offer':
$allowed_schema = 'service';
break;
}
return $allowed_schema;
}
/**
* Returns all the event/offer categories.
*
* @return mixed
*/
protected function getItemCategories()
{
if (!isset($this->item->categories))
{
return;
}
if (!$categories = $this->item->categories)
{
return;
}
$cats = [];
foreach ($categories as $key => $value)
{
if (!isset($value[1]))
{
continue;
}
$cats[] = $value[1];
}
return implode(', ', $cats);
}
/**
* Returns an items custom fields values
*
* @param string $prefix
*
* @return array
*/
protected function getItemCustomFieldsValues($prefix = '')
{
if (!isset($this->item->customFields))
{
return [];
}
if (!$customFields = $this->item->customFields)
{
return [];
}
$payload = [];
foreach ($customFields as $key => $cf)
{
// skip custom field without a value
if (!$cf->attributeValue)
{
continue;
}
if (in_array($cf->attributeTypeCode, ['select_box', 'checkbox', 'radio', 'multiselect']))
{
$value = $this->getArrayCustomFieldValue($cf->attributeValue, $cf->optionsIDS, $cf->options);
}
else
{
$value = $cf->attributeValue;
}
$payload[$prefix . '.cf.' . $cf->id] = $value;
}
return $payload;
}
/**
* Returns all item attachments.
*
* @param string $prefix
*
* @return mixed
*/
protected function getItemAttachments($prefix = '')
{
if (!isset($this->item->attachments))
{
return [];
}
if (!is_array($this->item->attachments) || empty($this->item->attachments))
{
return [];
}
$urls = [];
foreach ($this->item->attachments as $key => $value)
{
$urls[$prefix . 'attachment_' . $key] = BD_ATTACHMENT_PATH . $value->path;
}
return $urls;
}
/**
* Returns the country object of the given country ID.
*
* @param int $countryId
*
* @return object
*/
protected function getItemCountry($countryId)
{
if (!$this->item->countryId)
{
return;
}
if (!$countryTable = Table::getInstance('Country', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
return $countryTable->getCountry($this->item->countryId);
}
/**
* Find the value of a custom field with the following type:
*
* - Select Box
* - Checkbox
* - Radio
* - MultiSelector
*
* @param string $value
* @param string $keys
* @param string $values
*
* @return string
*/
protected function getArrayCustomFieldValue($value, $keys, $values)
{
// Create a new array combined by $keys, $values
$keys = explode('|#', $keys);
$values = explode('|#', $values);
$keys = array_slice($keys, 0, count($values));
$choices = array_combine($keys, $values);
// Transform value to an array of values
$value = explode(',', $value);
$data = [];
foreach ($choices as $key => $label)
{
if (!in_array($key, $value))
{
continue;
}
$data[] = $label;
}
return implode(', ', $data);
}
/**
* Returns a category's name given its ID.
*
* @param int $id
*
* @return mixed
*/
protected function getItemCategoryByID($id)
{
if (!$categoryTable = Table::getInstance('Category', 'JBusinessTable', []))
{
return;
}
if (!$category = $categoryTable->getCategoryById($id))
{
return;
}
return $category->name;
}
/**
* Returns an items selected categories.
*
* @param array $selctedCategories
*
* @return string
*/
protected function getItemSelectedCategories($selectedCategories)
{
$names = [];
foreach ($selectedCategories as $key => $value)
{
$names[] = trim($value->name);
}
return implode(', ', $names);
}
/**
* Returns the shared field values.
*
* @return array
*/
protected function getSharedFieldValues()
{
$shared_fields = $this->getSharedFields();
$prefix = 'shared.';
$data = [];
// Add all data directly from the item object
foreach ($shared_fields as $key => $label)
{
// Only add directly existing properties
if (!property_exists($this->item, $key))
{
continue;
}
$data[$prefix . $key] = $this->item->$key;
}
// Add pictures
if (count($pictures = $this->item->pictures))
{
$pictures_urls = [];
foreach ($pictures as $key => &$picture)
{
$picture = (array) $picture;
$pictures_urls[] = BD_PICTURES_PATH . $picture['picture_path'];
}
$data[$prefix . 'pictures'] = implode(',', $pictures_urls);
}
// Add pictures data
if (count($pictures = $this->item->pictures))
{
foreach ($pictures as $key => $picture)
{
$picture = (array) $picture;
// Picture URL
$data[$prefix . 'picture_url_' . $key] = BD_PICTURES_PATH . $picture['picture_path'];
// Picture Title
$data[$prefix . 'picture_title_' . $key] = $picture['picture_title'];
// Picture Description
$data[$prefix . 'picture_description_' . $key] = $picture['picture_info'];
}
}
// Add videos
if (isset($this->item->videos) && count($videos = $this->item->videos))
{
foreach ($videos as $key => $video)
{
$data[$prefix . 'video_' . $key] = $video->url;
}
}
return $data;
}
/**
* Returns the reviews of the item.
*
* @param int $status The J-BusinessDirectory Item status
*
* @return array
*/
protected function getReviews($status = 1)
{
if (!$reviewTable = Table::getInstance('Review', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
if (!$reviews = $reviewTable->getReviews($this->getThingID(), true, $status))
{
return [];
}
$data = [];
foreach ($reviews as $key => $review)
{
$data[] = (object) [
'author' => $review->name,
'datePublished' => Functions::dateToUTC($review->creationDate, true),
'description' => $review->description,
'rating' => $review->rating
];
}
return $data;
}
/**
* Shared fields between J-BusinessDirectory items.
*
* @return array
*/
protected function getSharedFields()
{
$fields = [
// Street Number
'street_number' => Text::_('LNG_STREET_NUMBER'),
// Address
'address' => Text::_('LNG_ADDRESS'),
// Area
'area' => Text::_('LNG_AREA'),
// Country
'countryId' => Text::_('LNG_COUNTRY'),
// County / Region
'county' => Text::_('LNG_COUNTY'),
// City
'city' => Text::_('LNG_CITY'),
// Province
'province' => Text::_('LNG_PROVINCE'),
// Postal Code
'postalCode' => Text::_('LNG_POSTAL_CODE'),
// Latitude
'latitude' => Text::_('LNG_LATITUDE'),
// Longitude
'longitude' => Text::_('LNG_LONGITUDE'),
// Meta Title
'meta_title' => Text::_('LNG_META_TITLE'),
// All pictures
'pictures' => Text::_('LNG_PICTURES')
];
/**
* Pictures consists from a Repeater field
* which we do not know how many items can have per listing.
*
* For this purpose, we assume 5 pictures are enough and add them
* manually. If we later need more items, we can increase them.
*/
for ($i = 0; $i < 5; $i++)
{
$fields = array_merge($fields, [
// Picture URL #XX
'picture_url_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_PICTURE_URL'), ($i + 1)),
// Picture Title #XX
'picture_title_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_PICTURE_TITLE'), ($i + 1)),
// Picture Description #XX
'picture_description_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_PICTURE_DESCRIPTION'), ($i + 1))
]);
}
/**
* Videos consists from a Repeater field
* which we do not know how many items can have per listing.
*
* For this purpose, we assume 5 videos are enough and add them
* manually. If we later need more items, we can increase them.
*/
for ($i = 0; $i < 5; $i++)
{
$fields = array_merge($fields, [
// Video #XX
'video_' . $i => sprintf(Text::_('PLG_GSD_JBUSINESSDIRECTORY_VIDEO'), ($i + 1))
]);
}
return $fields;
}
/**
* Company custom fields of a J-BusinessDirectory item.
*
* @param int $status The J-BusinessDirectory Item status
*
* @return array
*/
protected function getItemCustomFields($status = 1)
{
if (!$attributeTable = Table::getInstance('Attribute', '\\Joomla\\CMS\\Table\\', []))
{
return;
}
if (!$attributes = $attributeTable->getAttributes($status))
{
return [];
}
/**
* Holds a list of attributes IDs that should not be displayed in the list
* as they do not hold any value.
*/
$skipped_atts = [
// "Header" Custom Attribute
'5'
];
$fields = [];
foreach ($attributes as $key => $attribute)
{
// Skip custom fields that do not contain a value
if (in_array($attribute->type, $skipped_atts))
{
continue;
}
$fields[$attribute->id] = $attribute->name;
}
return $fields;
}
/**
* Returns an app setting property value.
*
* @param string $property
*
* @return mixed
*/
protected function getAppSettingPropertyValue($property)
{
if (!is_string($property) || empty($property))
{
return;
}
$appSettings = JBusinessUtil::getApplicationSettings();
if (!property_exists($appSettings, $property))
{
return;
}
return $appSettings->$property;
}
}