<?php
 namespace Moto\Twig\Extension; use Moto; class MotoCallbackExtension extends AbstractExtension { protected $_name = 'MotoCallback'; protected static $_settings; public function getGlobals() { return array( 'MotoCallback' => $this ); } protected static function _loadSettings() { if (static::$_settings) { return; } static::$_settings = Moto\Website\Settings::get('integration_feedback'); } protected static function _getSettings($name = null, $default = null) { return Moto\Util::getValue(static::$_settings, $name, $default); } protected function _onInitRuntime() { parent::_onInitRuntime(); static::_loadSettings(); } public function getProviderName() { return $this->_name; } public function isEnabled() { return ($this->getProviderName() === static::_getSettings('provider', 'none')); } public function isAllowOnPage($page = null) { if (!$this->isEnabled()) { return false; } if (!($page instanceof Moto\Website\ContentPage)) { return false; } return true; } public function getDescription() { return static::_getSettings('providers.' . $this->getProviderName() . '.description'); } public function getThumbnailType($name = 'openButton') { return static::_getSettings('providers.' . $this->getProviderName() . '.thumbnails.' . $name . '.type', 'icon'); } public function getThumbnailValue($name = 'openButton') { if ($this->getThumbnailType($name) === 'image') { return Moto\System::getUploadUrl(static::_getSettings('providers.' . $this->getProviderName() . '.thumbnails.' . $name . '.image.path')); } return static::_getSettings('providers.' . $this->getProviderName() . '.thumbnails.' . $name . '.icon.id'); } public function getMoreDetailsProperties() { return static::_getSettings('providers.' . $this->getProviderName() . '.moreDetails.properties'); } public function getMoreDetailsItems() { return static::_getSettings('providers.' . $this->getProviderName() . '.moreDetails.items'); } public function getMoreDetailsItemHref($item) { switch ($item->name) { case 'telegram_chat': return 'https://t.me/' . $item->value; case 'whatsapp_chat': return 'https://wa.me/' . (($item->value[0] !== '+') ? $item->value : substr($item->value, 1)); case 'viber_public_account': return 'viber://pa/info?uri=' . $item->value; case 'fb_messenger_chat': return 'https://m.me/' . $item->value; case 'skype_chat': return 'skype:' . $item->value . '?chat'; case 'skype_call': return 'skype:' . $item->value . '?call'; case 'vk_chat': return 'https://vk.me/' . $item->value; case 'email': return 'mailto:' . $item->value; default: return '#'; } } } 