@@ -1003,8 +1003,8 @@ |
||
| 1003 | 1003 | } |
| 1004 | 1004 | if ($this->searchFieldsForDuplicates) { |
| 1005 | 1005 | $duplicateCheckClause = []; |
| 1006 | - $queryGenerator = new self($this->moduleName, $this->user->getId()); |
|
| 1007 | - $queryGenerator->setStateCondition($this->getState()); |
|
| 1006 | + $queryGenerator = new self($this->moduleName, $this->user->getId()); |
|
| 1007 | + $queryGenerator->setStateCondition($this->getState()); |
|
| 1008 | 1008 | $queryGenerator->permissions = $this->permissions; |
| 1009 | 1009 | $queryGenerator->setFields(array_keys($this->searchFieldsForDuplicates)); |
| 1010 | 1010 | foreach ($this->searchFieldsForDuplicates as $fieldName => $ignoreEmptyValue) { |
@@ -19,52 +19,52 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class YetiForce extends Base |
| 21 | 21 | { |
| 22 | - /** {@inheritdoc} */ |
|
| 23 | - public function getCoordinates(array $addressInfo) |
|
| 24 | - { |
|
| 25 | - $product = \App\YetiForce\Register::getProduct('YetiForceMap'); |
|
| 26 | - if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) { |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 29 | - $params = array_merge([ |
|
| 30 | - 'version' => 2.0, |
|
| 31 | - 'format' => 'json', |
|
| 32 | - 'addressdetails' => 1, |
|
| 33 | - 'limit' => 1, |
|
| 34 | - 'accept-language' => \App\Language::getLanguage() . ',' . \App\Config::main('default_language') . ',en-US', |
|
| 35 | - ], $addressInfo); |
|
| 36 | - $options = [ |
|
| 37 | - 'timeout' => 60, |
|
| 38 | - 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()], |
|
| 39 | - ]; |
|
| 40 | - if (isset($product['params']['token'])) { |
|
| 41 | - $params['yf_token'] = $product['params']['token']; |
|
| 42 | - } else { |
|
| 43 | - $options['auth'] = [$product['params']['login'], $product['params']['pass']]; |
|
| 44 | - } |
|
| 45 | - $coordinates = false; |
|
| 46 | - try { |
|
| 47 | - $url = 'https://osm-search.yetiforce.eu/?' . \http_build_query($params); |
|
| 48 | - \App\Log::beginProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__); |
|
| 49 | - $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options); |
|
| 50 | - \App\Log::endProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__); |
|
| 51 | - if (200 === $response->getStatusCode()) { |
|
| 52 | - $coordinates = \App\Json::decode($response->getBody()); |
|
| 53 | - } else { |
|
| 54 | - throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody()); |
|
| 55 | - } |
|
| 56 | - } catch (\Exception $ex) { |
|
| 57 | - \App\Log::error('Error - ' . $ex->getMessage(), __CLASS__); |
|
| 58 | - } |
|
| 59 | - return $coordinates; |
|
| 60 | - } |
|
| 22 | + /** {@inheritdoc} */ |
|
| 23 | + public function getCoordinates(array $addressInfo) |
|
| 24 | + { |
|
| 25 | + $product = \App\YetiForce\Register::getProduct('YetiForceMap'); |
|
| 26 | + if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | + $params = array_merge([ |
|
| 30 | + 'version' => 2.0, |
|
| 31 | + 'format' => 'json', |
|
| 32 | + 'addressdetails' => 1, |
|
| 33 | + 'limit' => 1, |
|
| 34 | + 'accept-language' => \App\Language::getLanguage() . ',' . \App\Config::main('default_language') . ',en-US', |
|
| 35 | + ], $addressInfo); |
|
| 36 | + $options = [ |
|
| 37 | + 'timeout' => 60, |
|
| 38 | + 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()], |
|
| 39 | + ]; |
|
| 40 | + if (isset($product['params']['token'])) { |
|
| 41 | + $params['yf_token'] = $product['params']['token']; |
|
| 42 | + } else { |
|
| 43 | + $options['auth'] = [$product['params']['login'], $product['params']['pass']]; |
|
| 44 | + } |
|
| 45 | + $coordinates = false; |
|
| 46 | + try { |
|
| 47 | + $url = 'https://osm-search.yetiforce.eu/?' . \http_build_query($params); |
|
| 48 | + \App\Log::beginProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__); |
|
| 49 | + $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options); |
|
| 50 | + \App\Log::endProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__); |
|
| 51 | + if (200 === $response->getStatusCode()) { |
|
| 52 | + $coordinates = \App\Json::decode($response->getBody()); |
|
| 53 | + } else { |
|
| 54 | + throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody()); |
|
| 55 | + } |
|
| 56 | + } catch (\Exception $ex) { |
|
| 57 | + \App\Log::error('Error - ' . $ex->getMessage(), __CLASS__); |
|
| 58 | + } |
|
| 59 | + return $coordinates; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** {@inheritdoc} */ |
|
| 63 | - public function getCoordinatesByValue(string $value): array |
|
| 64 | - { |
|
| 65 | - if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) { |
|
| 66 | - return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']]; |
|
| 67 | - } |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 62 | + /** {@inheritdoc} */ |
|
| 63 | + public function getCoordinatesByValue(string $value): array |
|
| 64 | + { |
|
| 65 | + if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) { |
|
| 66 | + return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']]; |
|
| 67 | + } |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -17,50 +17,50 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class YetiForce extends Base |
| 19 | 19 | { |
| 20 | - /** {@inheritdoc} */ |
|
| 21 | - public $url = 'YetiForce'; |
|
| 22 | - /** {@inheritdoc} */ |
|
| 23 | - public $infoUrl = 'index.php?module=YetiForce&parent=Settings&view=Shop&product=YetiForcePassword&mode=showProductModal'; |
|
| 20 | + /** {@inheritdoc} */ |
|
| 21 | + public $url = 'YetiForce'; |
|
| 22 | + /** {@inheritdoc} */ |
|
| 23 | + public $infoUrl = 'index.php?module=YetiForce&parent=Settings&view=Shop&product=YetiForcePassword&mode=showProductModal'; |
|
| 24 | 24 | |
| 25 | - /** {@inheritdoc} */ |
|
| 26 | - public function check(string $password): array |
|
| 27 | - { |
|
| 28 | - $status = ['status' => true]; |
|
| 29 | - $product = \App\YetiForce\Register::getProduct('YetiForcePassword'); |
|
| 30 | - if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) { |
|
| 31 | - return $status; |
|
| 32 | - } |
|
| 33 | - try { |
|
| 34 | - $url = 'https://passwords.yetiforce.eu/pwned'; |
|
| 35 | - \App\Log::beginProfile("POST|YetiForce::check|{$url}", __NAMESPACE__); |
|
| 36 | - $request = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request( |
|
| 37 | - 'POST', |
|
| 38 | - $url, |
|
| 39 | - ['json' => ['sha1' => sha1($password)], 'timeout' => 2, 'http_errors' => false, 'auth' => [$product['params']['login'], $product['params']['pass']], 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()]] |
|
| 40 | - ); |
|
| 41 | - \App\Log::endProfile("POST|YetiForce::check|{$url}", __NAMESPACE__); |
|
| 42 | - if (200 === $request->getStatusCode()) { |
|
| 43 | - $response = \App\Json::decode($request->getBody()); |
|
| 44 | - if (isset($response['count'])) { |
|
| 45 | - $status = [ |
|
| 46 | - 'message' => \App\Language::translate('LBL_ALERT_PWNED_PASSWORD', 'Settings:Password'), |
|
| 47 | - 'status' => 0 === (int) $response['count'], |
|
| 48 | - ]; |
|
| 49 | - } elseif ($response['error']) { |
|
| 50 | - throw new \App\Exceptions\AppException('Error with response |' . $response['error']); |
|
| 51 | - } |
|
| 52 | - } else { |
|
| 53 | - throw new \App\Exceptions\AppException('Error with connection |' . $request->getReasonPhrase()); |
|
| 54 | - } |
|
| 55 | - } catch (\Exception $ex) { |
|
| 56 | - \App\Log::error($ex->getMessage(), __CLASS__); |
|
| 57 | - } |
|
| 58 | - return $status; |
|
| 59 | - } |
|
| 25 | + /** {@inheritdoc} */ |
|
| 26 | + public function check(string $password): array |
|
| 27 | + { |
|
| 28 | + $status = ['status' => true]; |
|
| 29 | + $product = \App\YetiForce\Register::getProduct('YetiForcePassword'); |
|
| 30 | + if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) { |
|
| 31 | + return $status; |
|
| 32 | + } |
|
| 33 | + try { |
|
| 34 | + $url = 'https://passwords.yetiforce.eu/pwned'; |
|
| 35 | + \App\Log::beginProfile("POST|YetiForce::check|{$url}", __NAMESPACE__); |
|
| 36 | + $request = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request( |
|
| 37 | + 'POST', |
|
| 38 | + $url, |
|
| 39 | + ['json' => ['sha1' => sha1($password)], 'timeout' => 2, 'http_errors' => false, 'auth' => [$product['params']['login'], $product['params']['pass']], 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()]] |
|
| 40 | + ); |
|
| 41 | + \App\Log::endProfile("POST|YetiForce::check|{$url}", __NAMESPACE__); |
|
| 42 | + if (200 === $request->getStatusCode()) { |
|
| 43 | + $response = \App\Json::decode($request->getBody()); |
|
| 44 | + if (isset($response['count'])) { |
|
| 45 | + $status = [ |
|
| 46 | + 'message' => \App\Language::translate('LBL_ALERT_PWNED_PASSWORD', 'Settings:Password'), |
|
| 47 | + 'status' => 0 === (int) $response['count'], |
|
| 48 | + ]; |
|
| 49 | + } elseif ($response['error']) { |
|
| 50 | + throw new \App\Exceptions\AppException('Error with response |' . $response['error']); |
|
| 51 | + } |
|
| 52 | + } else { |
|
| 53 | + throw new \App\Exceptions\AppException('Error with connection |' . $request->getReasonPhrase()); |
|
| 54 | + } |
|
| 55 | + } catch (\Exception $ex) { |
|
| 56 | + \App\Log::error($ex->getMessage(), __CLASS__); |
|
| 57 | + } |
|
| 58 | + return $status; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** {@inheritdoc} */ |
|
| 62 | - public function isActive(): bool |
|
| 63 | - { |
|
| 64 | - return \App\YetiForce\Shop::check('YetiForcePassword'); |
|
| 65 | - } |
|
| 61 | + /** {@inheritdoc} */ |
|
| 62 | + public function isActive(): bool |
|
| 63 | + { |
|
| 64 | + return \App\YetiForce\Shop::check('YetiForcePassword'); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public $listFields = [ |
| 26 | 26 | 'name' => 'LBL_NAME', |
| 27 | - 'email' => 'LBL_EMAIL', |
|
| 28 | - 'vat_id' => 'LBL_VAT_ID', |
|
| 29 | - 'country' => 'LBL_COUNTRY', |
|
| 30 | - 'industry' => 'LBL_INDUSTRY', |
|
| 27 | + 'email' => 'LBL_EMAIL', |
|
| 28 | + 'vat_id' => 'LBL_VAT_ID', |
|
| 29 | + 'country' => 'LBL_COUNTRY', |
|
| 30 | + 'industry' => 'LBL_INDUSTRY', |
|
| 31 | 31 | 'website' => 'LBL_WEBSITE', |
| 32 | 32 | ]; |
| 33 | 33 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public static array $formFields = [ |
| 40 | 40 | 'name' => [], |
| 41 | - 'email' => [], |
|
| 41 | + 'email' => [], |
|
| 42 | 42 | 'vat_id' => [ |
| 43 | 43 | 'infoText' => 'LBL_VAT_ID_INFO', |
| 44 | 44 | ], |
@@ -17,28 +17,28 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Settings_Magento_Edit_View extends Settings_Vtiger_Index_View |
| 19 | 19 | { |
| 20 | - /** {@inheritdoc} */ |
|
| 21 | - public function checkPermission(Request $request) |
|
| 22 | - { |
|
| 23 | - parent::checkPermission($request); |
|
| 24 | - if(!\App\YetiForce\Register::getProduct('YetiForceMagento')) { |
|
| 25 | - throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED'); |
|
| 26 | - } |
|
| 27 | - } |
|
| 28 | - /** {@inheritdoc} */ |
|
| 29 | - public function process(App\Request $request) |
|
| 30 | - { |
|
| 31 | - $moduleName = $request->getModule(false); |
|
| 32 | - $viewer = $this->getViewer($request); |
|
| 33 | - $record = !$request->isEmpty('record') ? $request->getInteger('record') : ''; |
|
| 34 | - if ($record) { |
|
| 35 | - $recordModel = Settings_Magento_Record_Model::getInstanceById($record); |
|
| 36 | - } else { |
|
| 37 | - $recordModel = Settings_Magento_Record_Model::getCleanInstance(); |
|
| 38 | - } |
|
| 39 | - $viewer->assign('RECORD_MODEL', $recordModel); |
|
| 40 | - $viewer->assign('RECORD_ID', $record); |
|
| 41 | - $viewer->assign('QUALIFIED_MODULE', $moduleName); |
|
| 42 | - $viewer->view('Edit.tpl', $moduleName); |
|
| 43 | - } |
|
| 20 | + /** {@inheritdoc} */ |
|
| 21 | + public function checkPermission(Request $request) |
|
| 22 | + { |
|
| 23 | + parent::checkPermission($request); |
|
| 24 | + if(!\App\YetiForce\Register::getProduct('YetiForceMagento')) { |
|
| 25 | + throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED'); |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | + /** {@inheritdoc} */ |
|
| 29 | + public function process(App\Request $request) |
|
| 30 | + { |
|
| 31 | + $moduleName = $request->getModule(false); |
|
| 32 | + $viewer = $this->getViewer($request); |
|
| 33 | + $record = !$request->isEmpty('record') ? $request->getInteger('record') : ''; |
|
| 34 | + if ($record) { |
|
| 35 | + $recordModel = Settings_Magento_Record_Model::getInstanceById($record); |
|
| 36 | + } else { |
|
| 37 | + $recordModel = Settings_Magento_Record_Model::getCleanInstance(); |
|
| 38 | + } |
|
| 39 | + $viewer->assign('RECORD_MODEL', $recordModel); |
|
| 40 | + $viewer->assign('RECORD_ID', $record); |
|
| 41 | + $viewer->assign('QUALIFIED_MODULE', $moduleName); |
|
| 42 | + $viewer->view('Edit.tpl', $moduleName); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -12,88 +12,88 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class OpenStreetMap_TileLayer_File extends Vtiger_Basic_File |
| 14 | 14 | { |
| 15 | - /** {@inheritdoc} */ |
|
| 16 | - public function getCheckPermission(App\Request $request) |
|
| 17 | - { |
|
| 18 | - if (!\App\Privilege::isPermitted('OpenStreetMap')) { |
|
| 19 | - throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406); |
|
| 20 | - } |
|
| 21 | - return true; |
|
| 22 | - } |
|
| 15 | + /** {@inheritdoc} */ |
|
| 16 | + public function getCheckPermission(App\Request $request) |
|
| 17 | + { |
|
| 18 | + if (!\App\Privilege::isPermitted('OpenStreetMap')) { |
|
| 19 | + throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406); |
|
| 20 | + } |
|
| 21 | + return true; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Download layer and show. |
|
| 26 | - * |
|
| 27 | - * @param \App\Request $request |
|
| 28 | - * |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public function get(App\Request $request) |
|
| 32 | - { |
|
| 33 | - if (!\App\RequestUtil::isNetConnection()) { |
|
| 34 | - $this->error(); |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 37 | - $product = \App\YetiForce\Register::getProduct('YetiForceMap'); |
|
| 38 | - if ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token'])) { |
|
| 39 | - $this->error('map_server_not_purchased'); |
|
| 40 | - return false; |
|
| 41 | - } |
|
| 42 | - $url = str_replace(['{z}', '{x}', '{y}'], [ |
|
| 43 | - $request->getByType('z', 'Integer'), |
|
| 44 | - $request->getByType('x', 'Integer'), |
|
| 45 | - $request->getByType('y', 'Integer'), |
|
| 46 | - ], 'https://osm-tile.yetiforce.eu/tile/{z}/{x}/{y}.png'); |
|
| 47 | - $options = [ |
|
| 48 | - 'timeout' => 60, |
|
| 49 | - 'headers' => [ |
|
| 50 | - 'InsKey' => \App\YetiForce\Register::getInstanceKey() |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - if (isset($product['params']['token'])) { |
|
| 54 | - $url += '?yf_token=' . $product['params']['token']; |
|
| 55 | - } else { |
|
| 56 | - $options['auth'] = [$product['params']['login'], $product['params']['pass']]; |
|
| 57 | - } |
|
| 58 | - try { |
|
| 59 | - \App\Log::beginProfile("GET|TileLayer::get|{$url}", __NAMESPACE__); |
|
| 60 | - $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options); |
|
| 61 | - \App\Log::endProfile("GET|TileLayer::get|{$url}", __NAMESPACE__); |
|
| 62 | - if (200 !== $response->getStatusCode()) { |
|
| 63 | - \App\Log::error($url . ' | Error: ' . $response->getReasonPhrase(), __CLASS__); |
|
| 64 | - $this->error(); |
|
| 65 | - return false; |
|
| 66 | - } |
|
| 67 | - $body = $response->getBody(); |
|
| 68 | - header('pragma: public'); |
|
| 69 | - header('cache-control: max-age=86400, public'); |
|
| 70 | - header('expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); |
|
| 71 | - header('content-type: image/png'); |
|
| 72 | - header('content-transfer-encoding: binary'); |
|
| 73 | - header('content-length: ' . $body->getSize()); |
|
| 74 | - echo $body->getContents(); |
|
| 75 | - } catch (\Throwable $ex) { |
|
| 76 | - \App\Log::error($url . ' | Error: ' . $ex->getMessage(), __CLASS__); |
|
| 77 | - $this->error(); |
|
| 78 | - } |
|
| 79 | - } |
|
| 24 | + /** |
|
| 25 | + * Download layer and show. |
|
| 26 | + * |
|
| 27 | + * @param \App\Request $request |
|
| 28 | + * |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public function get(App\Request $request) |
|
| 32 | + { |
|
| 33 | + if (!\App\RequestUtil::isNetConnection()) { |
|
| 34 | + $this->error(); |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 37 | + $product = \App\YetiForce\Register::getProduct('YetiForceMap'); |
|
| 38 | + if ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token'])) { |
|
| 39 | + $this->error('map_server_not_purchased'); |
|
| 40 | + return false; |
|
| 41 | + } |
|
| 42 | + $url = str_replace(['{z}', '{x}', '{y}'], [ |
|
| 43 | + $request->getByType('z', 'Integer'), |
|
| 44 | + $request->getByType('x', 'Integer'), |
|
| 45 | + $request->getByType('y', 'Integer'), |
|
| 46 | + ], 'https://osm-tile.yetiforce.eu/tile/{z}/{x}/{y}.png'); |
|
| 47 | + $options = [ |
|
| 48 | + 'timeout' => 60, |
|
| 49 | + 'headers' => [ |
|
| 50 | + 'InsKey' => \App\YetiForce\Register::getInstanceKey() |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + if (isset($product['params']['token'])) { |
|
| 54 | + $url += '?yf_token=' . $product['params']['token']; |
|
| 55 | + } else { |
|
| 56 | + $options['auth'] = [$product['params']['login'], $product['params']['pass']]; |
|
| 57 | + } |
|
| 58 | + try { |
|
| 59 | + \App\Log::beginProfile("GET|TileLayer::get|{$url}", __NAMESPACE__); |
|
| 60 | + $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options); |
|
| 61 | + \App\Log::endProfile("GET|TileLayer::get|{$url}", __NAMESPACE__); |
|
| 62 | + if (200 !== $response->getStatusCode()) { |
|
| 63 | + \App\Log::error($url . ' | Error: ' . $response->getReasonPhrase(), __CLASS__); |
|
| 64 | + $this->error(); |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | + $body = $response->getBody(); |
|
| 68 | + header('pragma: public'); |
|
| 69 | + header('cache-control: max-age=86400, public'); |
|
| 70 | + header('expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); |
|
| 71 | + header('content-type: image/png'); |
|
| 72 | + header('content-transfer-encoding: binary'); |
|
| 73 | + header('content-length: ' . $body->getSize()); |
|
| 74 | + echo $body->getContents(); |
|
| 75 | + } catch (\Throwable $ex) { |
|
| 76 | + \App\Log::error($url . ' | Error: ' . $ex->getMessage(), __CLASS__); |
|
| 77 | + $this->error(); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Error function. |
|
| 83 | - * |
|
| 84 | - * @param string $type |
|
| 85 | - * |
|
| 86 | - * @return void |
|
| 87 | - */ |
|
| 88 | - public function error(string $type = 'map_server_unavailable'): void |
|
| 89 | - { |
|
| 90 | - $fileName = ROOT_DIRECTORY . "/public_html/layouts/basic/images/{$type}.png"; |
|
| 91 | - header('pragma: public'); |
|
| 92 | - header('cache-control: max-age=86400, public'); |
|
| 93 | - header('expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); |
|
| 94 | - header('content-type: ' . \App\Fields\File::getMimeContentType($fileName)); |
|
| 95 | - header('content-transfer-encoding: binary'); |
|
| 96 | - header('content-length: ' . filesize($fileName)); |
|
| 97 | - readfile($fileName); |
|
| 98 | - } |
|
| 81 | + /** |
|
| 82 | + * Error function. |
|
| 83 | + * |
|
| 84 | + * @param string $type |
|
| 85 | + * |
|
| 86 | + * @return void |
|
| 87 | + */ |
|
| 88 | + public function error(string $type = 'map_server_unavailable'): void |
|
| 89 | + { |
|
| 90 | + $fileName = ROOT_DIRECTORY . "/public_html/layouts/basic/images/{$type}.png"; |
|
| 91 | + header('pragma: public'); |
|
| 92 | + header('cache-control: max-age=86400, public'); |
|
| 93 | + header('expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400)); |
|
| 94 | + header('content-type: ' . \App\Fields\File::getMimeContentType($fileName)); |
|
| 95 | + header('content-transfer-encoding: binary'); |
|
| 96 | + header('content-length: ' . filesize($fileName)); |
|
| 97 | + readfile($fileName); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -20,309 +20,309 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class Layout |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Get active layout name. |
|
| 25 | - * |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public static function getActiveLayout() |
|
| 29 | - { |
|
| 30 | - if (Session::has('layout')) { |
|
| 31 | - return Session::get('layout'); |
|
| 32 | - } |
|
| 33 | - return \App\Config::main('defaultLayout'); |
|
| 34 | - } |
|
| 23 | + /** |
|
| 24 | + * Get active layout name. |
|
| 25 | + * |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public static function getActiveLayout() |
|
| 29 | + { |
|
| 30 | + if (Session::has('layout')) { |
|
| 31 | + return Session::get('layout'); |
|
| 32 | + } |
|
| 33 | + return \App\Config::main('defaultLayout'); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Set the active layout name. |
|
| 38 | - * |
|
| 39 | - * @param string $layoutName |
|
| 40 | - * @return void |
|
| 41 | - * @throws \InvalidArgumentException |
|
| 42 | - */ |
|
| 43 | - public static function setActiveLayout(string $layoutName): void |
|
| 44 | - { |
|
| 45 | - if (in_array($layoutName, array_keys(self::getAllLayouts()), true)) { |
|
| 46 | - Session::set('layout', $layoutName); |
|
| 47 | - } else { |
|
| 48 | - throw new \InvalidArgumentException('Invalid layout name.'); |
|
| 49 | - } |
|
| 50 | - } |
|
| 36 | + /** |
|
| 37 | + * Set the active layout name. |
|
| 38 | + * |
|
| 39 | + * @param string $layoutName |
|
| 40 | + * @return void |
|
| 41 | + * @throws \InvalidArgumentException |
|
| 42 | + */ |
|
| 43 | + public static function setActiveLayout(string $layoutName): void |
|
| 44 | + { |
|
| 45 | + if (in_array($layoutName, array_keys(self::getAllLayouts()), true)) { |
|
| 46 | + Session::set('layout', $layoutName); |
|
| 47 | + } else { |
|
| 48 | + throw new \InvalidArgumentException('Invalid layout name.'); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get file from layout. |
|
| 54 | - * |
|
| 55 | - * @param string $name |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public static function getLayoutFile($name) |
|
| 60 | - { |
|
| 61 | - $basePath = 'layouts' . '/' . \App\Config::main('defaultLayout') . '/'; |
|
| 62 | - $filePath = \Vtiger_Loader::resolveNameToPath('~' . $basePath . $name); |
|
| 63 | - if (is_file($filePath)) { |
|
| 64 | - if (!IS_PUBLIC_DIR) { |
|
| 65 | - $basePath = 'public_html/' . $basePath; |
|
| 66 | - } |
|
| 67 | - return $basePath . $name; |
|
| 68 | - } |
|
| 69 | - $basePath = 'layouts' . '/' . \Vtiger_Viewer::getDefaultLayoutName() . '/'; |
|
| 70 | - if (!IS_PUBLIC_DIR) { |
|
| 71 | - $basePath = 'public_html/' . $basePath; |
|
| 72 | - } |
|
| 73 | - return $basePath . $name; |
|
| 74 | - } |
|
| 52 | + /** |
|
| 53 | + * Get file from layout. |
|
| 54 | + * |
|
| 55 | + * @param string $name |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public static function getLayoutFile($name) |
|
| 60 | + { |
|
| 61 | + $basePath = 'layouts' . '/' . \App\Config::main('defaultLayout') . '/'; |
|
| 62 | + $filePath = \Vtiger_Loader::resolveNameToPath('~' . $basePath . $name); |
|
| 63 | + if (is_file($filePath)) { |
|
| 64 | + if (!IS_PUBLIC_DIR) { |
|
| 65 | + $basePath = 'public_html/' . $basePath; |
|
| 66 | + } |
|
| 67 | + return $basePath . $name; |
|
| 68 | + } |
|
| 69 | + $basePath = 'layouts' . '/' . \Vtiger_Viewer::getDefaultLayoutName() . '/'; |
|
| 70 | + if (!IS_PUBLIC_DIR) { |
|
| 71 | + $basePath = 'public_html/' . $basePath; |
|
| 72 | + } |
|
| 73 | + return $basePath . $name; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Gets layout paths. |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public static function getLayoutPaths(): array |
|
| 82 | - { |
|
| 83 | - $basePrefix = 'layouts/' . self::getActiveLayout() . \DIRECTORY_SEPARATOR; |
|
| 84 | - $defaultPrefix = 'layouts/' . \Vtiger_Viewer::getDefaultLayoutName() . \DIRECTORY_SEPARATOR; |
|
| 85 | - $layoutsPath = []; |
|
| 76 | + /** |
|
| 77 | + * Gets layout paths. |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public static function getLayoutPaths(): array |
|
| 82 | + { |
|
| 83 | + $basePrefix = 'layouts/' . self::getActiveLayout() . \DIRECTORY_SEPARATOR; |
|
| 84 | + $defaultPrefix = 'layouts/' . \Vtiger_Viewer::getDefaultLayoutName() . \DIRECTORY_SEPARATOR; |
|
| 85 | + $layoutsPath = []; |
|
| 86 | 86 | |
| 87 | - if (\App\Config::performance('LOAD_CUSTOM_FILES')) { |
|
| 88 | - $layoutsPath['custom/'] = 'custom/'; |
|
| 89 | - $layoutsPath["custom/{$basePrefix}"] = "custom/{$basePrefix}"; |
|
| 90 | - $layoutsPath["custom/{$defaultPrefix}"] = "custom/{$defaultPrefix}"; |
|
| 91 | - } |
|
| 92 | - $layoutsPath[''] = ''; |
|
| 93 | - $layoutsPath[$basePrefix] = $basePrefix; |
|
| 94 | - $layoutsPath[$defaultPrefix] = $defaultPrefix; |
|
| 87 | + if (\App\Config::performance('LOAD_CUSTOM_FILES')) { |
|
| 88 | + $layoutsPath['custom/'] = 'custom/'; |
|
| 89 | + $layoutsPath["custom/{$basePrefix}"] = "custom/{$basePrefix}"; |
|
| 90 | + $layoutsPath["custom/{$defaultPrefix}"] = "custom/{$defaultPrefix}"; |
|
| 91 | + } |
|
| 92 | + $layoutsPath[''] = ''; |
|
| 93 | + $layoutsPath[$basePrefix] = $basePrefix; |
|
| 94 | + $layoutsPath[$defaultPrefix] = $defaultPrefix; |
|
| 95 | 95 | |
| 96 | - return $layoutsPath; |
|
| 97 | - } |
|
| 96 | + return $layoutsPath; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get all layouts list. |
|
| 101 | - * |
|
| 102 | - * @return string[] |
|
| 103 | - */ |
|
| 104 | - public static function getAllLayouts() |
|
| 105 | - { |
|
| 106 | - $all = (new \App\Db\Query())->select(['name', 'label'])->from('vtiger_layout')->all(); |
|
| 107 | - $folders = [ |
|
| 108 | - 'basic' => Language::translate('LBL_DEFAULT'), |
|
| 109 | - ]; |
|
| 110 | - foreach ($all as $row) { |
|
| 111 | - $folders[$row['name']] = Language::translate($row['label']); |
|
| 112 | - } |
|
| 113 | - return $folders; |
|
| 114 | - } |
|
| 99 | + /** |
|
| 100 | + * Get all layouts list. |
|
| 101 | + * |
|
| 102 | + * @return string[] |
|
| 103 | + */ |
|
| 104 | + public static function getAllLayouts() |
|
| 105 | + { |
|
| 106 | + $all = (new \App\Db\Query())->select(['name', 'label'])->from('vtiger_layout')->all(); |
|
| 107 | + $folders = [ |
|
| 108 | + 'basic' => Language::translate('LBL_DEFAULT'), |
|
| 109 | + ]; |
|
| 110 | + foreach ($all as $row) { |
|
| 111 | + $folders[$row['name']] = Language::translate($row['label']); |
|
| 112 | + } |
|
| 113 | + return $folders; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Get metadata for a specific layout. |
|
| 118 | - * |
|
| 119 | - * @param string $layoutName |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public static function getLayoutMetadata(string $layoutName): array |
|
| 123 | - { |
|
| 124 | - $metadata = [ |
|
| 125 | - 'name' => $layoutName, |
|
| 126 | - 'creation_date' => 'unknown', |
|
| 127 | - 'author' => 'unknown', |
|
| 128 | - 'version' => '1.0', |
|
| 129 | - ]; |
|
| 116 | + /** |
|
| 117 | + * Get metadata for a specific layout. |
|
| 118 | + * |
|
| 119 | + * @param string $layoutName |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public static function getLayoutMetadata(string $layoutName): array |
|
| 123 | + { |
|
| 124 | + $metadata = [ |
|
| 125 | + 'name' => $layoutName, |
|
| 126 | + 'creation_date' => 'unknown', |
|
| 127 | + 'author' => 'unknown', |
|
| 128 | + 'version' => '1.0', |
|
| 129 | + ]; |
|
| 130 | 130 | |
| 131 | - // Example placeholder for fetching real metadata. |
|
| 132 | - // You can replace this with actual data retrieval logic. |
|
| 133 | - // $layout = (new \App\Db\Query())->select(['creation_date', 'author', 'version']) |
|
| 134 | - // ->from('vtiger_layout_metadata')->where(['name' => $layoutName])->one(); |
|
| 135 | - // if ($layout) { |
|
| 136 | - // $metadata = $layout; |
|
| 137 | - // } |
|
| 131 | + // Example placeholder for fetching real metadata. |
|
| 132 | + // You can replace this with actual data retrieval logic. |
|
| 133 | + // $layout = (new \App\Db\Query())->select(['creation_date', 'author', 'version']) |
|
| 134 | + // ->from('vtiger_layout_metadata')->where(['name' => $layoutName])->one(); |
|
| 135 | + // if ($layout) { |
|
| 136 | + // $metadata = $layout; |
|
| 137 | + // } |
|
| 138 | 138 | |
| 139 | - return $metadata; |
|
| 140 | - } |
|
| 139 | + return $metadata; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Get layout files of a specific type. |
|
| 144 | - * |
|
| 145 | - * @param string $fileType |
|
| 146 | - * @return array |
|
| 147 | - */ |
|
| 148 | - public static function getLayoutFilesByType(string $fileType): array |
|
| 149 | - { |
|
| 150 | - $layoutsPath = self::getLayoutPaths(); |
|
| 151 | - $files = []; |
|
| 142 | + /** |
|
| 143 | + * Get layout files of a specific type. |
|
| 144 | + * |
|
| 145 | + * @param string $fileType |
|
| 146 | + * @return array |
|
| 147 | + */ |
|
| 148 | + public static function getLayoutFilesByType(string $fileType): array |
|
| 149 | + { |
|
| 150 | + $layoutsPath = self::getLayoutPaths(); |
|
| 151 | + $files = []; |
|
| 152 | 152 | |
| 153 | - foreach ($layoutsPath as $prefix => $path) { |
|
| 154 | - $directory = __DIR__ . '/' . $path; |
|
| 155 | - if (is_dir($directory)) { |
|
| 156 | - foreach (glob($directory . '*.' . $fileType) as $file) { |
|
| 157 | - $files[] = str_replace(__DIR__ . '/', '', $file); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 153 | + foreach ($layoutsPath as $prefix => $path) { |
|
| 154 | + $directory = __DIR__ . '/' . $path; |
|
| 155 | + if (is_dir($directory)) { |
|
| 156 | + foreach (glob($directory . '*.' . $fileType) as $file) { |
|
| 157 | + $files[] = str_replace(__DIR__ . '/', '', $file); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $files; |
|
| 163 | - } |
|
| 162 | + return $files; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Validate if the layout exists. |
|
| 167 | - * |
|
| 168 | - * @param string $layoutName |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - public static function validateLayout(string $layoutName): bool |
|
| 172 | - { |
|
| 173 | - return in_array($layoutName, array_keys(self::getAllLayouts()), true); |
|
| 174 | - } |
|
| 165 | + /** |
|
| 166 | + * Validate if the layout exists. |
|
| 167 | + * |
|
| 168 | + * @param string $layoutName |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + public static function validateLayout(string $layoutName): bool |
|
| 172 | + { |
|
| 173 | + return in_array($layoutName, array_keys(self::getAllLayouts()), true); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Get public url from file. |
|
| 178 | - * |
|
| 179 | - * @param string $name |
|
| 180 | - * @param bool $full |
|
| 181 | - * |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - public static function getPublicUrl($name, $full = false) |
|
| 185 | - { |
|
| 186 | - $basePath = ''; |
|
| 187 | - if ($full) { |
|
| 188 | - $basePath .= \App\Config::main('site_URL'); |
|
| 189 | - } |
|
| 190 | - if (!IS_PUBLIC_DIR) { |
|
| 191 | - $basePath .= 'public_html/'; |
|
| 192 | - } |
|
| 193 | - return $basePath . $name; |
|
| 194 | - } |
|
| 176 | + /** |
|
| 177 | + * Get public url from file. |
|
| 178 | + * |
|
| 179 | + * @param string $name |
|
| 180 | + * @param bool $full |
|
| 181 | + * |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + public static function getPublicUrl($name, $full = false) |
|
| 185 | + { |
|
| 186 | + $basePath = ''; |
|
| 187 | + if ($full) { |
|
| 188 | + $basePath .= \App\Config::main('site_URL'); |
|
| 189 | + } |
|
| 190 | + if (!IS_PUBLIC_DIR) { |
|
| 191 | + $basePath .= 'public_html/'; |
|
| 192 | + } |
|
| 193 | + return $basePath . $name; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * The function get path to the image. |
|
| 198 | - * |
|
| 199 | - * @param string $imageName |
|
| 200 | - * |
|
| 201 | - * @return array |
|
| 202 | - */ |
|
| 203 | - public static function getImagePath($imageName) |
|
| 204 | - { |
|
| 205 | - return \Vtiger_Theme::getImagePath($imageName); |
|
| 206 | - } |
|
| 196 | + /** |
|
| 197 | + * The function get path to the image. |
|
| 198 | + * |
|
| 199 | + * @param string $imageName |
|
| 200 | + * |
|
| 201 | + * @return array |
|
| 202 | + */ |
|
| 203 | + public static function getImagePath($imageName) |
|
| 204 | + { |
|
| 205 | + return \Vtiger_Theme::getImagePath($imageName); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Function takes a template path. |
|
| 210 | - * |
|
| 211 | - * @param string $templateName |
|
| 212 | - * @param string $moduleName |
|
| 213 | - * |
|
| 214 | - * @return string |
|
| 215 | - */ |
|
| 216 | - public static function getTemplatePath(string $templateName, string $moduleName = ''): string |
|
| 217 | - { |
|
| 218 | - return \Vtiger_Viewer::getInstance()->getTemplatePath($templateName, $moduleName); |
|
| 219 | - } |
|
| 208 | + /** |
|
| 209 | + * Function takes a template path. |
|
| 210 | + * |
|
| 211 | + * @param string $templateName |
|
| 212 | + * @param string $moduleName |
|
| 213 | + * |
|
| 214 | + * @return string |
|
| 215 | + */ |
|
| 216 | + public static function getTemplatePath(string $templateName, string $moduleName = ''): string |
|
| 217 | + { |
|
| 218 | + return \Vtiger_Viewer::getInstance()->getTemplatePath($templateName, $moduleName); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Check if template exists. |
|
| 223 | - * |
|
| 224 | - * @param string $templateName |
|
| 225 | - * @param string $moduleName |
|
| 226 | - * |
|
| 227 | - * @return bool |
|
| 228 | - */ |
|
| 229 | - public static function checkTemplatePath(string $templateName, string $moduleName = ''): bool |
|
| 230 | - { |
|
| 231 | - self::getTemplatePath($templateName, $moduleName); |
|
| 232 | - return file_exists(\Vtiger_Viewer::$completeTemplatePath); |
|
| 233 | - } |
|
| 221 | + /** |
|
| 222 | + * Check if template exists. |
|
| 223 | + * |
|
| 224 | + * @param string $templateName |
|
| 225 | + * @param string $moduleName |
|
| 226 | + * |
|
| 227 | + * @return bool |
|
| 228 | + */ |
|
| 229 | + public static function checkTemplatePath(string $templateName, string $moduleName = ''): bool |
|
| 230 | + { |
|
| 231 | + self::getTemplatePath($templateName, $moduleName); |
|
| 232 | + return file_exists(\Vtiger_Viewer::$completeTemplatePath); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Get unique id for HTML ids. |
|
| 237 | - * |
|
| 238 | - * @param string $name |
|
| 239 | - * |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public static function getUniqueId($name = '') |
|
| 243 | - { |
|
| 244 | - return str_replace([' ', '"', "'"], '', $name) . random_int(100, 99999); |
|
| 245 | - } |
|
| 235 | + /** |
|
| 236 | + * Get unique id for HTML ids. |
|
| 237 | + * |
|
| 238 | + * @param string $name |
|
| 239 | + * |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public static function getUniqueId($name = '') |
|
| 243 | + { |
|
| 244 | + return str_replace([' ', '"', "'"], '', $name) . random_int(100, 99999); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Truncating plain text and adding a button showing all the text. |
|
| 249 | - * |
|
| 250 | - * @param string $text |
|
| 251 | - * @param int $length |
|
| 252 | - * @param bool $showIcon |
|
| 253 | - * @param bool $nl2br |
|
| 254 | - * |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public static function truncateText(string $text, int $length, bool $showIcon = false, bool $nl2br = false): string |
|
| 258 | - { |
|
| 259 | - if (\mb_strlen($text) < $length) { |
|
| 260 | - return $nl2br ? nl2br($text) : $text; |
|
| 261 | - } |
|
| 262 | - $teaser = Purifier::encodeHtml(TextUtils::textTruncate($text, $length)); |
|
| 263 | - $text = Purifier::encodeHtml($text); |
|
| 264 | - if ($showIcon) { |
|
| 265 | - $btn = '<span class="mdi mdi-overscan"></span>'; |
|
| 266 | - } else { |
|
| 267 | - $btn = Language::translate('LBL_MORE_BTN'); |
|
| 268 | - } |
|
| 269 | - return "<div class=\"js-more-content c-text-divider\"><pre class=\"teaserContent u-pre\">$teaser</pre><span class=\"fullContent d-none\"><pre class=\"u-pre\">$text</pre></span><span class=\"text-right\"><button type=\"button\" class=\"btn btn-link btn-sm p-0 js-more\">{$btn}</button></span></div>"; |
|
| 270 | - } |
|
| 247 | + /** |
|
| 248 | + * Truncating plain text and adding a button showing all the text. |
|
| 249 | + * |
|
| 250 | + * @param string $text |
|
| 251 | + * @param int $length |
|
| 252 | + * @param bool $showIcon |
|
| 253 | + * @param bool $nl2br |
|
| 254 | + * |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public static function truncateText(string $text, int $length, bool $showIcon = false, bool $nl2br = false): string |
|
| 258 | + { |
|
| 259 | + if (\mb_strlen($text) < $length) { |
|
| 260 | + return $nl2br ? nl2br($text) : $text; |
|
| 261 | + } |
|
| 262 | + $teaser = Purifier::encodeHtml(TextUtils::textTruncate($text, $length)); |
|
| 263 | + $text = Purifier::encodeHtml($text); |
|
| 264 | + if ($showIcon) { |
|
| 265 | + $btn = '<span class="mdi mdi-overscan"></span>'; |
|
| 266 | + } else { |
|
| 267 | + $btn = Language::translate('LBL_MORE_BTN'); |
|
| 268 | + } |
|
| 269 | + return "<div class=\"js-more-content c-text-divider\"><pre class=\"teaserContent u-pre\">$teaser</pre><span class=\"fullContent d-none\"><pre class=\"u-pre\">$text</pre></span><span class=\"text-right\"><button type=\"button\" class=\"btn btn-link btn-sm p-0 js-more\">{$btn}</button></span></div>"; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Truncating HTML and adding a button showing all the text. |
|
| 274 | - * |
|
| 275 | - * @param string $html |
|
| 276 | - * @param string $size |
|
| 277 | - * @param int $length |
|
| 278 | - * @param mixed $showBtn |
|
| 279 | - * |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 282 | - public static function truncateHtml(?string $html, ?string $size = 'medium', ?int $length = 200, $showBtn = false): string |
|
| 283 | - { |
|
| 284 | - if (empty($html)) { |
|
| 285 | - return ''; |
|
| 286 | - } |
|
| 287 | - $teaser = $css = $btn = ''; |
|
| 288 | - $loadData = $iframe = true; |
|
| 289 | - $btnTemplate = function (string $popoverText = '', ?string $btnClass = '', string $data = 'data-iframe="true"'): string { |
|
| 290 | - $popoverText = \App\Language::translate($popoverText); |
|
| 291 | - return "<a href=\"#\" class=\"js-more noLinkBtn font-weight-lighter js-popover-tooltip ml-2 {$btnClass}\" {$data} data-content=\"{$popoverText}\"><span class=\"mdi mdi-overscan\"></span></a>"; |
|
| 292 | - }; |
|
| 293 | - $iframeClass = 'modal-iframe js-modal-iframe'; |
|
| 294 | - switch ($size) { |
|
| 295 | - case 'full': |
|
| 296 | - $iframeClass = 'js-iframe-full-height'; |
|
| 297 | - break; |
|
| 298 | - case 'medium': |
|
| 299 | - $btn = $btnTemplate('LBL_FULLSCREEN', 'c-btn-floating-right-bottom btn btn-primary'); |
|
| 300 | - break; |
|
| 301 | - case 'mini': |
|
| 302 | - $btn = $btnTemplate('LBL_SHOW_ORIGINAL_CONTENT'); |
|
| 303 | - $css = 'display: none;'; |
|
| 304 | - $teaser = TextUtils::textTruncate(trim(strip_tags($html)), $length); |
|
| 305 | - $loadData = false; |
|
| 306 | - break; |
|
| 307 | - case 'miniHtml': |
|
| 308 | - $btn = $btnTemplate('LBL_SHOW_ORIGINAL_CONTENT', '', 'data-modal-size="modal-md"'); |
|
| 309 | - $css = 'display: none;'; |
|
| 310 | - $teaserBefore = str_replace('<br>', '', $html); |
|
| 311 | - $teaser = TextUtils::htmlTruncateByWords(str_replace('<br>', '', $teaserBefore), $length); |
|
| 312 | - if (false === $showBtn && $teaserBefore == $teaser) { |
|
| 313 | - $html = $btn = ''; |
|
| 314 | - } |
|
| 315 | - $iframe = false; |
|
| 316 | - break; |
|
| 317 | - default: |
|
| 318 | - break; |
|
| 319 | - } |
|
| 320 | - if ($iframe) { |
|
| 321 | - $html = Purifier::encodeHtml($html); |
|
| 322 | - $content = "<div class=\"js-iframe-content\">{$teaser}<iframe sandbox=\"allow-same-origin allow-popups allow-popups-to-escape-sandbox\" class=\"w-100 {$iframeClass}\" frameborder=\"0\" style=\"{$css}\" " . ($loadData ? 'srcdoc' : 'srcdoctemp') . "=\"{$html}\"></iframe>"; |
|
| 323 | - } else { |
|
| 324 | - $content = "<div class=\"js-more-content\">{$teaser}<div class=\"w-100 {$iframeClass} fullContent\" style=\"{$css}\">{$html}</div>"; |
|
| 325 | - } |
|
| 326 | - return $content . $btn . '</div>'; |
|
| 327 | - } |
|
| 272 | + /** |
|
| 273 | + * Truncating HTML and adding a button showing all the text. |
|
| 274 | + * |
|
| 275 | + * @param string $html |
|
| 276 | + * @param string $size |
|
| 277 | + * @param int $length |
|
| 278 | + * @param mixed $showBtn |
|
| 279 | + * |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | + public static function truncateHtml(?string $html, ?string $size = 'medium', ?int $length = 200, $showBtn = false): string |
|
| 283 | + { |
|
| 284 | + if (empty($html)) { |
|
| 285 | + return ''; |
|
| 286 | + } |
|
| 287 | + $teaser = $css = $btn = ''; |
|
| 288 | + $loadData = $iframe = true; |
|
| 289 | + $btnTemplate = function (string $popoverText = '', ?string $btnClass = '', string $data = 'data-iframe="true"'): string { |
|
| 290 | + $popoverText = \App\Language::translate($popoverText); |
|
| 291 | + return "<a href=\"#\" class=\"js-more noLinkBtn font-weight-lighter js-popover-tooltip ml-2 {$btnClass}\" {$data} data-content=\"{$popoverText}\"><span class=\"mdi mdi-overscan\"></span></a>"; |
|
| 292 | + }; |
|
| 293 | + $iframeClass = 'modal-iframe js-modal-iframe'; |
|
| 294 | + switch ($size) { |
|
| 295 | + case 'full': |
|
| 296 | + $iframeClass = 'js-iframe-full-height'; |
|
| 297 | + break; |
|
| 298 | + case 'medium': |
|
| 299 | + $btn = $btnTemplate('LBL_FULLSCREEN', 'c-btn-floating-right-bottom btn btn-primary'); |
|
| 300 | + break; |
|
| 301 | + case 'mini': |
|
| 302 | + $btn = $btnTemplate('LBL_SHOW_ORIGINAL_CONTENT'); |
|
| 303 | + $css = 'display: none;'; |
|
| 304 | + $teaser = TextUtils::textTruncate(trim(strip_tags($html)), $length); |
|
| 305 | + $loadData = false; |
|
| 306 | + break; |
|
| 307 | + case 'miniHtml': |
|
| 308 | + $btn = $btnTemplate('LBL_SHOW_ORIGINAL_CONTENT', '', 'data-modal-size="modal-md"'); |
|
| 309 | + $css = 'display: none;'; |
|
| 310 | + $teaserBefore = str_replace('<br>', '', $html); |
|
| 311 | + $teaser = TextUtils::htmlTruncateByWords(str_replace('<br>', '', $teaserBefore), $length); |
|
| 312 | + if (false === $showBtn && $teaserBefore == $teaser) { |
|
| 313 | + $html = $btn = ''; |
|
| 314 | + } |
|
| 315 | + $iframe = false; |
|
| 316 | + break; |
|
| 317 | + default: |
|
| 318 | + break; |
|
| 319 | + } |
|
| 320 | + if ($iframe) { |
|
| 321 | + $html = Purifier::encodeHtml($html); |
|
| 322 | + $content = "<div class=\"js-iframe-content\">{$teaser}<iframe sandbox=\"allow-same-origin allow-popups allow-popups-to-escape-sandbox\" class=\"w-100 {$iframeClass}\" frameborder=\"0\" style=\"{$css}\" " . ($loadData ? 'srcdoc' : 'srcdoctemp') . "=\"{$html}\"></iframe>"; |
|
| 323 | + } else { |
|
| 324 | + $content = "<div class=\"js-more-content\">{$teaser}<div class=\"w-100 {$iframeClass} fullContent\" style=\"{$css}\">{$html}</div>"; |
|
| 325 | + } |
|
| 326 | + return $content . $btn . '</div>'; |
|
| 327 | + } |
|
| 328 | 328 | } |