@@ -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 | } |
@@ -286,7 +286,7 @@ |
||
| 286 | 286 | } |
| 287 | 287 | $teaser = $css = $btn = ''; |
| 288 | 288 | $loadData = $iframe = true; |
| 289 | - $btnTemplate = function (string $popoverText = '', ?string $btnClass = '', string $data = 'data-iframe="true"'): string { |
|
| 289 | + $btnTemplate = function(string $popoverText = '', ?string $btnClass = '', string $data = 'data-iframe="true"'): string { |
|
| 290 | 290 | $popoverText = \App\Language::translate($popoverText); |
| 291 | 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 | 292 | }; |