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
Add url slug option for site primary language also
givanz482591fbadfa
diff --git a/app/component/breadcrumb.php b/app/component/breadcrumb.phpindex 8d3a39e..84c1a2a 100644--- a/app/component/breadcrumb.php+++ b/app/component/breadcrumb.php@@ -60,7 +60,7 @@ class Breadcrumb extends ComponentBase {$urlOptions += ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http'];}- if ($this->options['default_language'] != $this->options['language']) {+ if (($this->options['default_language'] != $this->options['language']) || self :: $global['default_lang_slug']) {$urlOptions += ['language'=> $this->options['language']];}diff --git a/app/component/comments.php b/app/component/comments.phpindex 4297201..e626c71 100755--- a/app/component/comments.php+++ b/app/component/comments.php@@ -94,6 +94,16 @@ class Comments extends ComponentBase {$level = 0;$parent_id = 0;++ $language = ['language'=> $this->options['language']];++ if (self :: $global['default_language'] != self :: $global['language']) {+ } else {+ if (!self :: $global['default_lang_slug']) {+ $language = [];+ }+ }+foreach ($results[$this->type] as $id => &$comment) {if ($comment['parent_id'] == 0) {$level = 0;@@ -118,8 +128,24 @@ class Comments extends ComponentBase {$comment['pubDate'] = date('r', strtotime($comment['created_at']));$anchor = '#comment-' . $comment[$this->type . '_id'];- $comment['url'] = url($this->route, $comment) . $anchor;- $comment['full-url'] = url($this->route, $comment + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http']) . $anchor;++ //url+ $url = $language;++ if ($comment['type'] != 'post' && $comment['type'] != 'page') {+ $url['type'] = $comment['type'];+ $type = 'post';+ }++ //if translation is missing slug is not available+ if (isset($comment['slug']) && $comment['slug']) {+ $url['slug'] = $comment['slug'];+ } else {+ $url['post_id'] = $comment['post_id'];+ }++ $comment['url'] = url($this->route, $url) . $anchor;+ $comment['full-url'] = url($this->route, $url + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http']) . $anchor;}$comment['level'] = $level;diff --git a/app/component/language.php b/app/component/language.phpindex b206fe8..8a0e64c 100755--- a/app/component/language.php+++ b/app/component/language.php@@ -100,7 +100,7 @@ class Language extends ComponentBase {$params = ['language' => $language['slug'], 'host' => $_SERVER['HTTP_HOST'] ?? '', 'scheme' => $scheme] + $content + $request->get;- if ($language['language_id'] == $options['default_language_id']) {+ if (($language['language_id'] == $options['default_language_id']) && !self :: $global['default_lang_slug']) {unset($params['language']);}diff --git a/app/component/menu.php b/app/component/menu.phpindex 632187e..700b6fd 100644--- a/app/component/menu.php+++ b/app/component/menu.php@@ -57,11 +57,14 @@ class Menu extends ComponentBase {$noTranslationText = '[' . __('No translation') . ']';$defaultLanguage = true;- $languageOption = [];+ $language = ['language'=> $options['language']];if (self :: $global['default_language'] != self :: $global['language']) {- $languageOption = ['language'=> $options['language']];$defaultLanguage = false;+ } else {+ if (!self :: $global['default_lang_slug']) {+ $language = [];+ }}//count the number of child menus (subcategories) for each category@@ -114,17 +117,17 @@ class Menu extends ComponentBase {}if ($type == 'home') {- $category['url'] = url('index/index', $languageOption);+ $category['url'] = url('index/index', $language);$category['name'] = $category['name'] ?: __('Home');}if ($type == 'blog') {- $category['url'] = url('content', $languageOption);+ $category['url'] = url('content', $language);$category['name'] = $category['name'] ?: __('Blog');}if ($type == 'shop') {- $category['url'] = url('product/index', $languageOption);+ $category['url'] = url('product/index', $language);$category['name'] = $category['name'] ?: __('Shop');}@@ -153,7 +156,21 @@ class Menu extends ComponentBase {$taxonomy_item_id = $productTaxonomy[$product['product_id']];$category = &$results['menu_item'][$taxonomy_item_id];$route = "product/{$category['type']}/index";- $category['url'] = url($route, ['slug'=> $product['slug'], 'product_id'=> $product['product_id']] + $languageOption);++ $url = $language;++ if ($product['type'] != 'product') {+ $url['type'] = $product['type'];+ }++ //if translation is missing slug is not available+ if (isset($product['slug'])) {+ $url['slug'] = $product['slug'];+ } else {+ $url['product_id'] = $product['product_id'];+ }++ $category['url'] = url($route, $url);$category['name'] = $product['name'] ?? (! $defaultLanguage ? $noTranslationText : null);$category['language_id'] = $product['language_id'] ?: $options['language_id'];}@@ -177,8 +194,24 @@ class Menu extends ComponentBase {foreach ($taxonomyPosts[$post['post_id']] as $taxonomy_item_id) {$category = &$results['menu_item'][$taxonomy_item_id];$route = "content/{$category['type']}/index";- $url = $post['slug'] ? url($route, ['slug'=> $post['slug'], 'post_id'=> $post['post_id']] + $languageOption) : '/';- $category['url'] = $url;+ $url = $post['slug'] ? url($route, ['slug'=> $post['slug'], 'post_id'=> $post['post_id']] + $language) : '/';++ //url+ $url = $language;++ if ($post['type'] != 'post' && $post['type'] != 'page') {+ $url['type'] = $post['type'];+ $type = 'post';+ }++ //if translation is missing slug is not available+ if (isset($post['slug']) && $post['slug']) {+ $url['slug'] = $post['slug'];+ } else {+ $url['post_id'] = $post['post_id'];+ }++ $category['url'] = url($route, $url);$category['name'] = $post['name'] ?? (! $defaultLanguage ? $noTranslationText : null);$category['language_id'] = $post['language_id'] ?? $options['language_id'];}@@ -218,25 +251,31 @@ class Menu extends ComponentBase {$name = $field['name'];$value = $field['value'];- $name = str_replace('item-', '', $name);+ $name = trim(str_replace('item', '', $name), '- ');++ if (! $name) {+ continue;+ }if ($name == 'name') {$menu_item_content[$name] = strip_tags($value);} else {if ($name == 'content') {$menu_item_content[$name] = sanitizeHTML($value);+ } else if ($name == 'img') {} else {$menu_item[$name] = $value;}}}- //$menu_item['menu_item_content']['post_id'] = $id;$menu_item_content['language_id'] = self :: $global['language_id'];- $menu_item_content['content'] = $menu_item_content['content'] ?? '';- $menu_item['menu_item_content'][] = $menu_item_content;$menu_item['menu_item_id'] = $id;+ if ($menu_item_content) {+ $menu_item_content['content'] = $menu_item_content['content'] ?? '';+ $menu_item['menu_item_content'][] = $menu_item_content;+ }if ((isset($menu_item_content['name']) && $menu_item_content['name']) ||(isset($menu_item_content['content']) && $menu_item_content['content'])) {diff --git a/app/component/site.php b/app/component/site.phpold mode 100755new mode 100644index 65f1725..b6038bb--- a/app/component/site.php+++ b/app/component/site.php@@ -57,7 +57,7 @@ class Site extends ComponentBase {$urlOptions = [];- if ($this->options['default_language'] != $this->options['language']) {+ if ($this->options['default_language'] != $this->options['language'] || self :: $global['default_lang_slug']) {$urlOptions = ['language' => $this->options['language']];} else {}diff --git a/system/component/component-base.php b/system/component/component-base.phpindex f4cb18c..808bed6 100644--- a/system/component/component-base.php+++ b/system/component/component-base.php@@ -57,8 +57,9 @@ class ComponentBase {self :: $global['user_id'] = $user['user_id'] ?? null;self :: $global['user_group_id'] = $user['user_group_id'] ?? 1;self :: $global['languages'] = $site['languages'] ?? [];- self :: $global['default_language'] = sess('default_language') ?? $site['language'] ?? 'en';- self :: $global['default_language_id'] = (int)(sess('default_language_id') ?? $site['language_id'] ?? 1);+ self :: $global['default_language'] = $site['language'] ?? 'en';+ self :: $global['default_language_id'] = $site['language_id'] ?? 1;+ self :: $global['default_lang_slug'] = $site['default_lang_slug'] ?? false;self :: $global['language'] = ($site['language'] ?? '') ?: 'en';self :: $global['language_id'] = (int)($site['language_id'] ?? '') ?: 1;self :: $global['currency_id'] = (int)(sess('currency_id') ?? $site['currency_id'] ?? 1);diff --git a/system/traits/post.php b/system/traits/post.phpindex a746cc9..1a65de2 100644--- a/system/traits/post.php+++ b/system/traits/post.php@@ -91,7 +91,10 @@ trait Post {}//date formatting that can be used for url parameters- $date = date_parse($post['created_at']);+ $date = [];+ if (isset($post['created_at']) && $post['created_at']) {+ $date = date_parse($post['created_at']);+ }foreach (['year', 'day', 'month', 'hour', 'minute'] as $key) {$post[$key] = $date[$key] ?? '';@@ -99,7 +102,7 @@ trait Post {$language = [];- if ($post['language_id'] != $options['default_language_id']) {+ if (($post['language_id'] != $options['default_language_id'])) {$language = ['language' => $options['language']];if ($post['name'] === null && isset($post['post_content'][$this->options['default_language_id']])) {@@ -113,11 +116,15 @@ trait Post {$post['name'] = '[' . __('No translation') . ']';}}+ } else {+ if (self :: $global['default_lang_slug']) {+ $language = ['language' => $options['language']];+ }}//rfc- $createdTime = strtotime($post['created_at']);- $updatedTime = strtotime($post['updated_at']);+ $createdTime = strtotime($post['created_at'] ?? '');+ $updatedTime = strtotime($post['updated_at'] ?? '');$post['pubDate'] = date('r', $createdTime);$post['modDate'] = date('r', $updatedTime);@@ -130,14 +137,18 @@ trait Post {}//url- $url = ['post_id' => $post['post_id']] + $language;- //if translation is missing slug is not available- if (isset($post['slug'])) {- $url['slug'] = $post['slug'];- }+ $url = $language;- if ($post['type'] != 'post') {+ if ($type != 'post' && $type != 'page') {$url['type'] = $post['type'];+ $type = 'post';+ }++ //if translation is missing slug is not available+ if (isset($post['slug']) && $post['slug']) {+ $url['slug'] = $post['slug'];+ } else {+ $url['post_id'] = $post['post_id'];}$post['url'] = url("content/$type/index", $url);diff --git a/system/traits/product.php b/system/traits/product.phpindex a36fafc..69e77fd 100644--- a/system/traits/product.php+++ b/system/traits/product.php@@ -57,11 +57,24 @@ trait Product {$this->currency = Currency::getInstance($options);}- if ($product['language_id'] != $options['default_language_id']) {- $language = ['language' => $options['language']];- if (! $product['name']) {- $product['name'] = '[' . __('No translation') . ']';+ if (($product['language_id'] != $options['default_language_id'])) {+ $language = ['language' => $options['language']];++ if ($product['name'] === null && isset($product['post_content'][$this->options['default_language_id']])) {+ $langFallback = $product['product_content'][$this->options['default_language_id']];+ $product['name'] = $langFallback['name'];+ $product['slug'] = $langFallback['slug'];+ $product['content'] = $langFallback['content'];+ $product['language_id'] = $langFallback['language_id'];+ } else {+ if (! $product['name']) {+ $product['name'] = '[' . __('No translation') . ']';+ }+ }+ } else {+ if (self :: $global['default_lang_slug']) {+ $language = ['language' => $options['language']];}}@@ -83,10 +96,17 @@ trait Product {$product['modDate'] = date('r', strtotime($product['updated_at']));$product['lastMod'] = date('Y-m-d\TH:i:sP', strtotime($product['updated_at']));- $url = ['type' => $product['type'], 'product_id' => $product['product_id']] + $language;+ $url = $language;++ if ($product['type'] != 'product') {+ $url['type'] = $product['type'];+ }+//if translation is missing slug is not availableif (isset($product['slug'])) {$url['slug'] = $product['slug'];+ } else {+ $url['product_id'] = $product['product_id'];}$product['url'] = url('product/product/index', $url);