Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Avoid html entity encoding for html templates text on compile and change utf8 to UTF-8 for consistent locale https://github.com/givanz/Vvveb/issues/327
givanz0a5cc3d0ca22
diff --git a/system/functions.php b/system/functions.phpindex bd9d951..b3f4b09 100755--- a/system/functions.php+++ b/system/functions.php@@ -505,40 +505,13 @@ function slugify($text, $divider = '-') {return $text;}-$vvvebTranslationDomains = ['vvveb', 'landing-theme'];--function addTranslationDomain($domain) {- global $vvvebTranslationDomains;-- if (! in_array($domain, $vvvebTranslationDomains)) {- array_push($vvvebTranslationDomains, $domain);- }-}-if (function_exists('_')) {function __($text, $plural = false, $count = false) {- global $vvvebTranslationDomains;-- $text = substr($text, 0, 1024);if ($plural) {- $plural = substr($plural, 0, 1024);-- foreach ($vvvebTranslationDomains as $domain) {- $translation = dngettext($domain, $text, $plural, $count);-- if ($translation && ($translation != $text)) {- break;- }- }+ $translation = ngettext($text, $plural, $count);} else {- foreach ($vvvebTranslationDomains as $domain) {- $translation = dgettext($domain, $text);-- if ($translation && ($translation != $text)) {- break;- }- }+ $translation = gettext($text);}return $translation;@@ -961,6 +934,7 @@ function getDefaultTemplateList() {'content/page.html','content/index.html','content/category.html',+ 'content/tag.html','product/index.html','product/product.html','product/category.html',@@ -979,6 +953,7 @@ function getTemplateList($theme = null, $skip = []) {'error500' => ['name' => __('Server error'), 'description' => __('Site error display page'), 'global' => true],'content-index' => ['name' => __('Blog homepage'), 'description' => __('Blog page with latest posts'), 'global' => true],'content-post' => ['name' => __('Blog post'), 'description' => __('Blog post'), 'editor' => ['template' => 'post'], 'global' => true],+ 'content-page' => ['name' => __('Page'), 'description' => __('Page'), 'editor' => ['template' => 'page'], 'global' => true],'product-index' => ['name' => __('Shop page'), 'description' => __('Shop homepage'), 'global' => true],'search-index' => ['name' => __('Search page'), 'description' => __('Search page'), 'global' => true],'user-index' => ['name' => __('Dashboard'), 'description' => __('User dashboard'), 'global' => true],@@ -1019,7 +994,7 @@ function getTemplateList($theme = null, $skip = []) {$url = PUBLIC_PATH . "themes/$theme/$file";- $pages[$name] = ['name' => $name, 'filename' => $filename, 'file' => $file, 'url' => $url, 'title' => humanReadable($title), 'folder' => $path, 'description' => $description];+ $pages[$name] = ['name' => $name, 'filename' => $filename, 'file' => $file, 'url' => $url, 'title' => humanReadable($title), 'folder' => $path, 'description' => $description, 'global' => $friendlyNames[$name]['global'] ?? false];if (isset($friendlyNames[$name]['editor'])) {$pages[$name]['editor'] = $friendlyNames[$name]['editor'];@@ -1069,8 +1044,10 @@ function parseQuantity($string) {switch ($multiplier) {case 'k':return $number * 1024;+case 'm':return $number * 1048576;+case 'g':return $number * 1073741824;}@@ -1307,7 +1284,6 @@ function userPreferedLanguage() {* @return mixed*/function setLanguage($langCode = 'en_US', $domain = 'vvveb') {- global $vvvebTranslationDomains;//setlocale(LC_TIME, "");//\putenv('LOCPATH=' . DIR_ROOT. "locale");@@ -1317,12 +1293,9 @@ function setLanguage($langCode = 'en_US', $domain = 'vvveb') {}if (function_exists('bindtextdomain')) {- foreach ($vvvebTranslationDomains as $tdomain) {- bindtextdomain($tdomain, DIR_ROOT . 'locale');- }bindtextdomain($domain, DIR_ROOT . 'locale');textdomain($domain);- bind_textdomain_codeset($domain, 'utf8');+ bind_textdomain_codeset($domain, 'UTF-8');setlocale(LC_ALL,'C.UTF-8');@@ -1334,12 +1307,12 @@ function setLanguage($langCode = 'en_US', $domain = 'vvveb') {}if (defined('LC_MESSAGES')) {- setlocale(LC_MESSAGES, "$langCode.utf8");- setlocale(LC_CTYPE,"$langCode.utf8");+ setlocale(LC_MESSAGES, "$langCode.UTF-8");+ setlocale(LC_CTYPE,"$langCode.UTF-8");} else {- setlocale(5, "$langCode.utf8");- setlocale(6,"$langCode.utf8");- setlocale(LC_ALL, "$langCode.utf8");+ setlocale(5, "$langCode.UTF-8");+ setlocale(6,"$langCode.UTF-8");+ setlocale(LC_ALL, "$langCode.UTF-8");}}}@@ -1356,7 +1329,7 @@ function clearLanguageCache($langCode = 'en_US', $domain = 'vvveb') {opcache_reset();}- if (function_exists('symlink') && symlink($locale, $nocache)) {+ if (function_exists('symlink') && @symlink($locale, $nocache)) {bindtextdomain($domain, $nocache);textdomain($domain);bind_textdomain_codeset($domain, 'different_codeset');@@ -1739,8 +1712,8 @@ function unzip($file) {function htmlToText($html) {$html = preg_replace('/\s+/', ' ', $html);$html = str_replace('<br>', "\n", $html);- $html = str_replace('<p>', "\n<p>", $html);- $html = str_replace('<h', "\n<h", $html);+ //add new line for block elements+ $html = preg_replace('/<(div|p|li|hr|pre|blockquote|section|h\d+)/', "\n<$1", $html);return trim(strip_tags($html));}@@ -1877,7 +1850,6 @@ function invoiceFormat($format, $data) {}, $format);}-/*remove <?xml declaration to avoid issues with php short start tag*/diff --git a/system/vtpl/vtpl.php b/system/vtpl/vtpl.phpindex 6c0d160..a1d9242 100755--- a/system/vtpl/vtpl.php+++ b/system/vtpl/vtpl.php@@ -350,6 +350,7 @@ class Vtpl {if (! $this->template || ! $this->xpath) {return;}+$foundImports = true;//expand importswhile ($foundImports) {@@ -530,6 +531,9 @@ class Vtpl {// [foo]: Matches any element with the "foo" attribute set (whatever the value)'/\[([a-z][\w_\-]*)\]/', // *[ @\1 ]+ // [!foo]: Matches any element without the "foo" attribute set (whatever the value)+ '/\[!([a-z][\w_\-]*)\]/', // *[ not(@\1) ]+// element[foo*]: Matches any element that starts with "foo" attribute (whatever the value)'/(\w+)\[([a-z][\w\-]*)\*\]/', // \1 [ @*[starts-with(name(), "\2")] ]@@ -577,6 +581,7 @@ class Vtpl {'[ends-with(@\1,"\2")]', //[foo$="warning"]'[ @\1 ]', //[attribute][attribute]'*[ @\1 ]', //[attribute]+ '[ not(@\1) ]', //[!attribute]'\1 [ @*[starts-with(name(), "\2")] ]', //element[attr*]'[ @*[starts-with(name(), "\1")] ]', //[attr*] - attribute with other attributes'*[ @*[starts-with(name(), "\1")] ]', //[attr*] - single attribute@@ -1858,7 +1863,7 @@ class Vtpl {$xml = Vvveb\array2xml($json);$html = $xml;}- @$this->document->loadXML($html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET);+ @$this->document->loadXML($html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);}$errors = libxml_get_errors();@@ -1947,6 +1952,7 @@ class Vtpl {$length = $currentNode->childNodes->length;$publicLen = strlen(PUBLIC_PATH);+for ($i = 0; $i < $length; $i++) {$node = $currentNode->childNodes[$i];@@ -1968,7 +1974,7 @@ class Vtpl {//set relative media to theme folderif (($name == 'src' || $name == 'href' || $name == 'srcset') && $this->relativePath) {- if ($value && $value[0] != '#' && $value[0] != '@' && (strncmp($value, 'http', 4) != 0)) {+ if ($value && $value[0] != '#' && $value[0] != '@' && (strpos($value, ':') === false)) {if ($value[0] == '/') {if (strncmp($value, PUBLIC_PATH, $publicLen) == 0) {$value = substr($value, $publicLen);@@ -2047,6 +2053,7 @@ class Vtpl {$before = $currentNode->childNodes->length;if ($trimmed != '') {+ //don't translate long textsif (strlen($trimmed) < 1024) {/*$php = '<_script language="php"><![CDATA[ echo ' . $this->translationFunction . '(\'' . $trimmed . '\');]]></_script>';@@ -2238,7 +2245,15 @@ class Vtpl {}, $html);$html = str_replace(['<_script language="php"><![CDATA[', ']]></_script>', '<_script language="php">', '</_script>'], ['<?php ', ' ?>', '<?php ', ' ?>'], $html);-+ //decode html entities to match translation strings+ $translationFunction = preg_quote($this->translationFunction);+ $html = preg_replace_callback("/<\?php echo $translationFunction\('(.+?)'\); \?>/",+ function ($matches) {+ $translation = html_entity_decode($matches[1], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5);+ //keep <> encoded to avoid xss+ $translation = str_replace(['<', '>'], ['<','>'], $translation);+ return "<?php echo {$this->translationFunction}('$translation'); ?>";+ }, $html);//remove data-v- attributes//$html = preg_replace('/data-v-[\-\w]+\s*=\s*"[^"]*"|data-v-[\-\w]+/','', $html);}