From dc8ef1c489ddbdcb4dfa085998fa92321d8c43c6 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 10 Apr 2016 20:42:34 +0300 Subject: [PATCH] Monstra MultiLanguage Development Init Commit --- engine/Monstra.php | 9 +- engine/Plugin/I18n.php | 10 +- engine/Site.php | 34 +++++++ favicon.ico | Bin 1150 -> 32038 bytes index.php | 12 +++ plugins/blog/blog.plugin.php | 53 ++++++---- plugins/blog/views/frontend/index.view.php | 2 +- plugins/box/pages/pages.admin.php | 59 ++++++++--- plugins/box/pages/pages.plugin.php | 92 +++++++++++++----- .../box/pages/views/backend/index.view.php | 19 +++- plugins/box/system/system.admin.php | 4 +- plugins/box/system/system.plugin.php | 2 +- .../box/system/views/backend/index.view.php | 10 +- sitemap.xml | 38 +++++++- storage/database/options.table.xml | 2 +- storage/database/pages.table.xml | 2 +- storage/database/users.table.xml | 2 +- 17 files changed, 282 insertions(+), 68 deletions(-) diff --git a/engine/Monstra.php b/engine/Monstra.php index 80d8127..59d0ff9 100644 --- a/engine/Monstra.php +++ b/engine/Monstra.php @@ -224,7 +224,11 @@ class Monstra /** * Init I18n */ - I18n::init(Option::get('language')); + if (BACKEND) { + I18n::init('admin', Option::get('language')); + } else { + I18n::init('site', Site::getCurrentSiteLocale()); + } /** * Init Plugins API @@ -235,7 +239,7 @@ class Monstra * Init Notification service */ Notification::init(); - + /** * Init site module */ @@ -315,6 +319,7 @@ class Monstra if (count($namespaces = Dir::scan(CACHE)) > 0) foreach ($namespaces as $namespace) Dir::delete(CACHE . DS . $namespace); } + /** * Initialize Monstra Engine * diff --git a/engine/Plugin/I18n.php b/engine/Plugin/I18n.php index 99058f4..daac8e8 100644 --- a/engine/Plugin/I18n.php +++ b/engine/Plugin/I18n.php @@ -75,9 +75,9 @@ class I18n * * @param string $dir Plugins directory */ - public static function init($locale) + public static function init($namespace = 'default', $locale) { - if ( ! isset(self::$instance)) self::$instance = new I18n($locale); + if ( ! isset(self::$instance)) self::$instance = new I18n($namespace, $locale); return self::$instance; } @@ -94,13 +94,13 @@ class I18n /** * Construct */ - protected function __construct($locale) + protected function __construct($namespace = 'default', $locale) { // Redefine arguments $locale = (string) $locale; // Get lang table for current locale - $lang_table = Cache::get('i18n', $locale); + $lang_table = Cache::get('i18n_'.$namespace, $locale); // If lang_table is empty then create new if (! $lang_table) { @@ -136,7 +136,7 @@ class I18n } // Save lang table for current locale - Cache::put('i18n', $locale, $lang_table); + Cache::put('i18n_'.$namespace, $locale, $lang_table); // Update dictionary I18n::$dictionary = $lang_table; diff --git a/engine/Site.php b/engine/Site.php index b9edf05..abe3969 100644 --- a/engine/Site.php +++ b/engine/Site.php @@ -221,4 +221,38 @@ class Site return __('Powered by', 'system').' Monstra ' . Monstra::VERSION; } + /** + * + */ + public static function getLocales() { + $language_files = File::scan(PLUGINS_BOX . DS . 'system' . DS . 'languages' . DS, '.lang.php'); + foreach ($language_files as $language) { + $parts = explode('.', $language); + $languages_array[$parts[0]] = I18n::$locales[$parts[0]]; + } + return $languages_array; + } + + /** + * + */ + public static function getDefaultSiteLocale() { + return Option::get('site_language'); + } + + /** + * + */ + public static function getCurrentSiteLocale() { + $site_locales = Site::getLocales(); + + + if (Uri::segment(0) && array_key_exists(Uri::segment(0), $site_locales)) { + return Uri::segment(0); + } else { + $site_locale = Cookie::get('site_locale'); + return !empty($site_locale) ? $site_locale : Option::get('site_language'); + } + + } } diff --git a/favicon.ico b/favicon.ico index 68dec5c0ce8ced898757070b27379352762a9793..07297b281801f1b13956d6a661023ae5472b5848 100644 GIT binary patch literal 32038 zcmeHQeXvbc8$Uvlge0kyn}lSL)FAN^l2nqnB!fy`BgsgTg#6Kmq>>~VN#-S?M!HG5 zsU+!3Q%NP6k|arzB-Z=;t|T{@CXx5@izQ5>=}v z5b7lUQ!bI{#HTv{yw5}WBBV8KntZR9Nc_7-BGInhKkp6NClUu+B@zwrN)~khW%OU* zfX)s|sWL7AUKIeiC+Y*Lxo})*!2K6s1zq{@Em*KXKfnC)%j%+wE)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YKdHL;n;{II!2nEuGC4e~Ji)9(FnoRYvkjC&fa|NL%Mg8Y91mXjG|zl-|-rf;Y- z`#uSrADcd~=gTqM{|4~)+Ri-a5orx%+A2Dmu~|N@^{%~d#=Q>uz#KQokLw72Q)dUW z-jOaMc>8|v*M0#Xo^$dXHIyg&GqZoQ^|QZgryah)x^2p1y9x_o`voQ+$8)4R0-zi1 zpiR+{`K+&Yzf8S-YhSj1S8&Y{&GFNuVIL!PC5ny)&MNQ;t^1M>nzZA9!B_9gbN)+^ ze$UJ|pV?1vtfSvp?qTB?_fUw-eLmXFc|sQRo^E1alo&e4UJIG_7S(giGM75LIf~6D z4)o5b4iuH0#l$D0vKK!~x=0?f#SQp2ZxHOO%X^l`qbtUb&c3eBd=wMqLKzvLMU>j%qob`to^vv=mv cXZ1?E{0_@MG}_tWa>}lp(AExz|6>pQ54{QJKL7v# literal 1150 zcmbu8JxfAi7=|A+6awi`&>S=v4n@!}XlvC)`~@L6xmEPF_A43{q9qzFTKox3YK;k^ zvlegn^?Kfe$f1TFxz2gs`?>G)tyxCDC^Bug?PS$#%glC#Bq?)UJ2TC8_U8C?`sPUT zqc|38G4yE6eygm8x59}x@f1Uk#tctdZA!crp8{_h%<$k{EY^48OQhu%H9UC3F;>)H ziX@xOW?ivZbk%CrLysm;052J`2Vx-nESJlQ67 zg+jqYPcg$2{MwU!2y2erYPGy~G#a^Pv+1Fym@S>3?1f0~zf!5V$zx#T&-5~&@a7zykx?+{Gabnhw-(c z?YS6;select(null, 'all'); + + foreach($pages_list as $page) { + $pages->update($page['id'], array('locale' => 'en')); + } + */ + +// Option::add('site_language', 'ru'); + // Check for maintenance mod if ('on' == Option::get('maintenance_status')) { diff --git a/plugins/blog/blog.plugin.php b/plugins/blog/blog.plugin.php index 6d06f28..4be4746 100644 --- a/plugins/blog/blog.plugin.php +++ b/plugins/blog/blog.plugin.php @@ -64,14 +64,17 @@ class Blog { * * @return string */ - public static function breadcrumbs() { + public static function breadcrumbs($locale = '') { + + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + $current_page = Pages::$requested_page; $parent_page = ''; if ($current_page !== 'error404') { - $page = Pages::$pages->select('[slug="'.$current_page.'"]', null); + $page = Pages::$pages->select('[slug="'.$current_page.'" and locale="'.$locale.'"]', null); if (trim($page['parent']) !== '') { $parent = true; - $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'"]', null); + $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'" and locale="'.$locale.'"]', null); } else { $parent = false; } @@ -96,16 +99,18 @@ class Blog { * * @return array */ - public static function getTagsArray($slug = null) { + public static function getTagsArray($slug = null, $locale='') { // Init vars $tags = array(); $tags_string = ''; + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + if ($slug == null) { - $posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published"]', 'all'); + $posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'"]', 'all'); } else { - $posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published" and slug="'.$slug.'"]', 'all'); + $posts = Pages::$pages->select('[parent="'.Blog::$parent_page_name.'" and status="published" and slug="'.$slug.'" and locale="'.$locale.'"]', 'all'); } foreach($posts as $post) { @@ -151,16 +156,18 @@ class Blog { * @param integer $num Number of posts to show * @return string */ - public static function getPosts($nums = 10) { + public static function getPosts($nums = 10, $locale = '') { + + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; // Get page param $page = (Request::get('page')) ? (int)Request::get('page') : 1; if (Request::get('tag')) { - $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and contains(tags, "'.Request::get('tag').'")]'; + $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'" and contains(tags, "'.Request::get('tag').'")]'; Notification::set('tag', Request::get('tag')); } else { - $query = '[parent="'.Blog::$parent_page_name.'" and status="published"]'; + $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'"]'; Notification::clean(); } @@ -183,12 +190,14 @@ class Blog { if ($start < 0) $start = 0; // Get posts and sort by DESC - $posts = Pages::$pages->select($query, $nums, $start, array('slug', 'title', 'author', 'date'), 'date', 'DESC'); + $posts = Pages::$pages->select($query, $nums, $start, array('slug', 'title', 'author', 'date', 'locale', 'template'), 'date', 'DESC'); // Loop foreach($posts as $key => $post) { $post_short = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $post['id'] . '.page.txt'))); $posts[$key]['content'] = Filter::apply('content', $post_short[0]); + $posts[$key]['slug'] = $posts[$key]['slug']; + $posts[$key]['locale'] = ($posts[$key]['locale'] == Site::getCurrentSiteLocale()) ? '' : $posts[$key]['locale'].'/'; } // Display view @@ -216,10 +225,12 @@ class Blog { * @param integer $num Number of posts to show * @return string */ - public static function getPostsBlock($nums = 10) { + public static function getPostsBlock($nums = 10, $locale = '') { + + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; // XPath Query - $query = '[parent="'.Blog::$parent_page_name.'" and status="published"]'; + $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and locale="'.$locale.'"]'; // Get posts and sort by DESC $posts = Pages::$pages->select($query, $nums, 0, array('slug', 'title', 'author', 'date'), 'date', 'DESC'); @@ -247,14 +258,16 @@ class Blog { * * @return string */ - public static function getRelatedPosts($limit = null) { + public static function getRelatedPosts($limit = null, $locale = '') { + + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $related_posts = array(); $tags = Blog::getTagsArray(Page::slug()); foreach($tags as $tag) { - $query = '[parent="'.Blog::$parent_page_name.'" and status="published" and contains(tags, "'.$tag.'") and slug!="'.Page::slug().'"]'; + $query = '[parent="'.Blog::$parent_page_name.'" and locale="'.$locale.'" and status="published" and contains(tags, "'.$tag.'") and slug!="'.Page::slug().'"]'; if ($result = Arr::subvalSort(Pages::$pages->select($query, ($limit == null) ? 'all' : (int)$limit), 'date', 'DESC')) { $related_posts = $result; @@ -303,9 +316,11 @@ class Blog { * * @return string */ - public static function getPostBeforeCut($slug) { + public static function getPostBeforeCut($slug, $locale = '') { - $page = Pages::$pages->select('[slug="'.$slug.'"]', null); + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + + $page = Pages::$pages->select('[slug="'.$slug.'" and locale="'.$locale.'"]', null); // Get post $post = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt'))); @@ -327,9 +342,11 @@ class Blog { * * @return string */ - public static function getPostAfterCut($slug) { + public static function getPostAfterCut($slug, $locale = '') { - $page = Pages::$pages->select('[slug="'.$slug.'"]', null); + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + + $page = Pages::$pages->select('[slug="'.$slug.'" and locale="'.$locale.'"]', null); // Get post $post = explode("{cut}", Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt'))); diff --git a/plugins/blog/views/frontend/index.view.php b/plugins/blog/views/frontend/index.view.php index c9cec0a..2f6b338 100644 --- a/plugins/blog/views/frontend/index.view.php +++ b/plugins/blog/views/frontend/index.view.php @@ -1,5 +1,5 @@ -

+

/
diff --git a/plugins/box/pages/pages.admin.php b/plugins/box/pages/pages.admin.php index fbc9e4d..8be6b29 100755 --- a/plugins/box/pages/pages.admin.php +++ b/plugins/box/pages/pages.admin.php @@ -19,6 +19,13 @@ class PagesAdmin extends Backend */ public static $pages = null; + /** + * Locale + * + * @var string + */ + public static $locale_to_edit = ''; + /** * _pageExpandAjax */ @@ -27,7 +34,7 @@ class PagesAdmin extends Backend if (Request::post('page_slug')) { if (Security::check(Request::post('token'))) { $pages = new Table('pages'); - $pages->updateWhere('[slug="'.Request::post('page_slug').'"]', array('expand' => Request::post('page_expand'))); + $pages->updateWhere('[slug="'.Request::post('page_slug').'" and locale="'.PagesAdmin::$locale_to_edit.'"]', array('expand' => Request::post('page_expand'))); Request::shutdown(); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } @@ -45,6 +52,23 @@ class PagesAdmin extends Backend $errors = array(); + if (Request::get('locale_to_edit')) { + if (Security::check(Request::get('token'))) { + if (Arr::keyExists(Site::getLocales(), Request::get('locale_to_edit'))) { + Cookie::set('locale_to_edit', Request::get('locale_to_edit')); + Request::redirect(Site::url().'/admin/index.php?id=pages'); + } + } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } + } + + if (Cookie::get('locale_to_edit')) { + $locale_to_edit = Cookie::get('locale_to_edit'); + } else { + $locale_to_edit = Site::getDefaultSiteLocale(); + } + + PagesAdmin::$locale_to_edit = $locale_to_edit; + $pages = new Table('pages'); PagesAdmin::$pages = $pages; @@ -106,6 +130,7 @@ class PagesAdmin extends Backend 'keywords' => $orig_page['keywords'], 'tags' => $orig_page['tags'], 'date' => $orig_page['date'], + 'locale' => $orig_page['locale'], 'author' => $orig_page['author']))) { // Get cloned page ID @@ -149,7 +174,7 @@ class PagesAdmin extends Backend //-------------- if (trim(Request::post('page_name')) == '') $errors['pages_empty_name'] = __('Required field', 'pages'); if (trim(Request::post('page_title')) == '') $errors['pages_empty_title'] = __('Required field', 'pages'); - if (count($pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'"]')) != 0) $errors['pages_exists'] = __('This page already exists', 'pages'); + if (count($pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'" and locale="'.$locale_to_edit.'"]')) != 0) $errors['pages_exists'] = __('This page already exists', 'pages'); // Prepare date if (Valid::date(Request::post('page_date'))) { @@ -179,6 +204,7 @@ class PagesAdmin extends Backend 'keywords' => Request::post('page_keywords'), 'tags' => Request::post('page_tags'), 'date' => $date, + 'locale' => $locale_to_edit, 'author' => $author))) { // Get inserted page ID @@ -287,7 +313,7 @@ class PagesAdmin extends Backend // Validate //-------------- if (trim(Request::post('page_name')) == '') $errors['pages_empty_name'] = __('Required field', 'pages'); - if ((count($pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'"]')) != 0) and (Security::safeName(Request::post('page_old_name'), '-', true) !== Security::safeName(Request::post('page_name'), '-', true))) $errors['pages_exists'] = __('This page already exists', 'pages'); + if ((count($pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'" and locale="'.$locale_to_edit.'"]')) != 0) and (Security::safeName(Request::post('page_old_name'), '-', true) !== Security::safeName(Request::post('page_name'), '-', true))) $errors['pages_exists'] = __('This page already exists', 'pages'); if (trim(Request::post('page_title')) == '') $errors['pages_empty_title'] = __('Required field', 'pages'); // Save fields @@ -328,7 +354,7 @@ class PagesAdmin extends Backend } } - if ($pages->updateWhere('[slug="'.Request::get('name').'"]', + if ($pages->updateWhere('[slug="'.Request::get('name').'" and locale="'.$locale_to_edit.'"]', array('slug' => Security::safeName(Request::post('page_name'), '-', true), 'template' => Request::post('templates'), 'parent' => $parent_page, @@ -342,6 +368,7 @@ class PagesAdmin extends Backend 'status' => Request::post('status'), 'access' => Request::post('access'), 'date' => $date, + 'locale' => $locale_to_edit, 'author' => $author))) { File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor'))); @@ -353,7 +380,7 @@ class PagesAdmin extends Backend } else { - if ($pages->updateWhere('[slug="'.Request::get('name').'"]', + if ($pages->updateWhere('[slug="'.Request::get('name').'" and locale="'.$locale_to_edit.'"]', array('slug' => Security::safeName(Request::post('page_name'), '-', true), 'template' => Request::post('templates'), 'parent' => $parent_page, @@ -367,6 +394,7 @@ class PagesAdmin extends Backend 'status' => Request::post('status'), 'access' => Request::post('access'), 'date' => $date, + 'locale' => $locale_to_edit, 'author' => $author))) { File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor'))); @@ -412,7 +440,15 @@ class PagesAdmin extends Backend $templates_array[basename($file,'.template.php')] = basename($file, '.template.php'); } - $page = $pages->select('[slug="'.Request::get('name').'"]', null); + if (Request::get('name') == 'error404') { + $page = $pages->select('[slug="'.Request::get('name').'" and locale="'.$locale_to_edit.'"]', null); + if (count($page) == 0) { + + } + } else { + $page = $pages->select('[slug="'.Request::get('name').'" and locale="'.$locale_to_edit.'"]', null); + } + if ($page) { @@ -488,7 +524,7 @@ class PagesAdmin extends Backend if (Security::check(Request::get('token'))) { // Get specific page - $page = $pages->select('[slug="'.Request::get('name').'"]', null); + $page = $pages->select('[slug="'.Request::get('name').'" and locale="'.$locale_to_edit.'"]', null); // Delete page and update fields if ($pages->deleteWhere('[slug="'.$page['slug'].'" ]')) { @@ -524,7 +560,7 @@ class PagesAdmin extends Backend if (Security::check(Request::get('token'))) { - $pages->updateWhere('[slug="'.Request::get('slug').'"]', array('access' => Request::get('access'))); + $pages->updateWhere('[slug="'.Request::get('slug').'" and locale="'.$locale_to_edit.'"]', array('access' => Request::get('access'))); // Run delete extra actions Action::run('admin_pages_action_update_access'); @@ -548,7 +584,7 @@ class PagesAdmin extends Backend if (Security::check(Request::get('token'))) { - $pages->updateWhere('[slug="'.Request::get('slug').'"]', array('status' => Request::get('status'))); + $pages->updateWhere('[slug="'.Request::get('slug').'" and locale="'.$locale_to_edit.'"]', array('status' => Request::get('status'))); // Run delete extra actions Action::run('admin_pages_action_update_status'); @@ -578,7 +614,7 @@ class PagesAdmin extends Backend $count = 0; // Get pages - $pages_list = $pages->select(null, 'all', null, array('slug', 'title', 'status', 'date', 'author', 'expand', 'access', 'parent', 'template', 'tags')); + $pages_list = $pages->select('[locale="'.$locale_to_edit.'"]', 'all', null, array('slug', 'title', 'status', 'date', 'author', 'expand', 'access', 'parent', 'template', 'tags', 'locale')); // Loop foreach ($pages_list as $page) { @@ -595,6 +631,7 @@ class PagesAdmin extends Backend $pages_array[$count]['expand'] = $page['expand']; $pages_array[$count]['slug'] = $page['slug']; $pages_array[$count]['tags'] = $page['tags']; + $pages_array[$count]['locale'] = $page['locale']; $pages_array[$count]['template']= $page['template']; if (isset($page['parent'])) { @@ -605,7 +642,7 @@ class PagesAdmin extends Backend if ($c_p != '') { - $_page = $pages->select('[slug="'.$page['parent'].'"]', null); + $_page = $pages->select('[slug="'.$page['parent'].'" and locale="'.$locale_to_edit.'"]', null); if (isset($_page['title'])) { $_title = $_page['title']; diff --git a/plugins/box/pages/pages.plugin.php b/plugins/box/pages/pages.plugin.php index 88afb07..13ff671 100644 --- a/plugins/box/pages/pages.plugin.php +++ b/plugins/box/pages/pages.plugin.php @@ -57,6 +57,13 @@ class Pages extends Frontend */ public static $requested_page = null; + /** + * Locale + * + * @var string + */ + public static $locale = ''; + /** * Main function */ @@ -77,7 +84,16 @@ class Pages extends Frontend $requested_page = Pages::lowLoader(Uri::segments()); Pages::$requested_page = $requested_page; - return Pages::$pages->select('[slug="'.$requested_page.'"]', null); + if($requested_page == 'error404') { + $page = Pages::$pages->select('[slug="'.$requested_page.'" and locale="'.Pages::$locale.'"]', null); + if(count($page) == 0) { + $page = Pages::$pages->select('[slug="'.$requested_page.'" and locale="'.Site::getDefaultSiteLocale().'"]', null); + } + } else { + $page = Pages::$pages->select('[slug="'.$requested_page.'" and locale="'.Pages::$locale.'"]', null); + } + + return $page; } /** @@ -91,14 +107,34 @@ class Pages extends Frontend { $defpage = Option::get('defaultpage'); + if (Arr::keyExists(Site::getLocales(), $data[0])) { + $locale = $data[0]; + if ($locale == Site::getDefaultSiteLocale()) { + if ((isset($data[2])) && ($data[2] != '')) { + Request::redirect(Site::url().'/'.$data[1].'/'.$data[2], 301); + } else { + Request::redirect(Site::url().'/'.(isset($data[1]) ? $data[1] : '') , 301); + } + } + $data[0] = isset($data[1]) ? $data[1] : ''; + $data[1] = isset($data[2]) ? $data[2] : ''; + if ($data[0] == '') unset($data[0]); + if ($data[1] == '') unset($data[1]); + } else { + $locale = Site::getDefaultSiteLocale(); + } + + Pages::$locale = $locale; + Cookie::set('site_locale', $locale); + // If data count 2 then it has Parent/Child if (count($data) >= 2) { // If exists parent file - if (count(Pages::$pages->select('[slug="'.$data[0].'"]')) !== 0) { + if (count(Pages::$pages->select('[slug="'.$data[0].'" and locale="'.$locale.'"]')) !== 0) { // Get child file and get parent page name - $child_page = Pages::$pages->select('[slug="'.$data[1].'"]', null); + $child_page = Pages::$pages->select('[slug="'.$data[1].'" and locale="'.$locale.'"]', null); // If child page parent is not empty then get his parent if (count($child_page) == 0) { @@ -150,15 +186,17 @@ class Pages extends Frontend } } else { // Only parent page come + if (empty($data[0])) { $id = $defpage; } else { + // Get current page - $current_page = Pages::$pages->select('[slug="'.$data[0].'"]', null); - + $current_page = Pages::$pages->select('[slug="'.$data[0].'" and locale="'.$locale.'"]', null); + // Hack For old Monstra $current_page['access'] = (isset($current_page['access'])) ? $current_page['access'] : 'public' ; @@ -176,7 +214,7 @@ class Pages extends Frontend if ($c_p !== '') { if ($c_p == $data[0]) { - if (count(Pages::$pages->select('[slug="'.$data[0].'"]', null)) != 0) { + if (count(Pages::$pages->select('[slug="'.$data[0].'"] and locale="'.$locale.'"]', null)) != 0) { if ((($current_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and @@ -194,17 +232,17 @@ class Pages extends Frontend $id = 'error404'; Response::status(404); } - } else { + } else { $id = 'error404'; Response::status(404); } - } else { + } else { $id = 'error404'; Response::status(404); } } else { - if (count(Pages::$pages->select('[slug="'.$data[0].'"]', null)) != 0) { + if (count(Pages::$pages->select('[slug="'.$data[0].'" and locale="'.$locale.'"]', null)) != 0) { if ((($current_page['status'] == 'published') or (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and ($current_page['access'] == 'public')) { @@ -217,11 +255,12 @@ class Pages extends Frontend $id = $data[0]; - } else { + } else { $id = 'error404'; Response::status(404); } } else { + $id = 'error404'; Response::status(404); } @@ -248,11 +287,13 @@ class Pages extends Frontend * * @return string */ - public static function content($slug = '') + public static function content($slug = '', $locale = '') { if ( ! empty($slug)) { - $page = Table::factory('pages')->select('[slug="'.$slug.'"]', null); + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + + $page = Table::factory('pages')->select('[slug="'.$slug.'" and locale="'.$locale.'"]', null); if ( ! empty($page)) { @@ -318,17 +359,19 @@ class Pages extends Frontend /** * Get pages */ - public static function getPages() + public static function getPages($locale = '') { // Init vars $pages_array = array(); $count = 0; + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + // Get pages table $pages = new Table('pages'); // Get Pages List - $pages_list = $pages->select('[slug!="error404" and status="published"]'); + $pages_list = $pages->select('[slug!="error404" and status="published" and locale="'.$locale.'"]'); foreach ($pages_list as $page) { @@ -337,6 +380,7 @@ class Pages extends Frontend $pages_array[$count]['parent'] = $page['parent']; $pages_array[$count]['date'] = $page['date']; $pages_array[$count]['author'] = $page['author']; + $pages_array[$count]['locale'] = $page['locale']; $pages_array[$count]['slug'] = ($page['slug'] == Option::get('defaultpage')) ? '' : $page['slug'] ; if (isset($page['parent'])) { @@ -346,7 +390,7 @@ class Pages extends Frontend } if ($c_p != '') { - $_page = $pages->select('[slug="'.$page['parent'].'"]', null); + $_page = $pages->select('[slug="'.$page['parent'].'" and locale="'.$locale.'"]', null); if (isset($_page['title'])) { $_title = $_page['title']; @@ -414,9 +458,10 @@ class Page extends Pages * @param string $parent Parent page * @return array */ - public static function children($parent) + public static function children($parent, $locale = '') { - return Pages::$pages->select('[parent="'.(string) $parent.'"]', 'all'); + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + return Pages::$pages->select('[parent="'.(string) $parent.'" and locale="'.$locale.'"]', 'all'); } /** @@ -427,9 +472,11 @@ class Page extends Pages * * */ - public static function available() + public static function available($locale = '') { - $pages = Pages::$pages->select('[parent="'.Pages::$requested_page.'"]', 'all'); + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; + + $pages = Pages::$pages->select('[parent="'.Pages::$requested_page.'" and locale="'.$locale.'"]', 'all'); // Display view View::factory('box/pages/views/frontend/available_pages') @@ -445,16 +492,17 @@ class Page extends Pages * * */ - public static function breadcrumbs() + public static function breadcrumbs($locale = '') { if (Uri::command() == 'pages') { + $locale = ($locale == '') ? Site::getCurrentSiteLocale() : $locale; $current_page = Pages::$requested_page; $parent_page = ''; if ($current_page !== 'error404') { - $page = Pages::$pages->select('[slug="'.$current_page.'"]', null); + $page = Pages::$pages->select('[slug="'.$current_page.'" and locale="'.$locale.'"]', null); if (trim($page['parent']) !== '') { $parent = true; - $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'"]', null); + $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'" and locale="'.$locale.'"]', null); } else { $parent = false; } diff --git a/plugins/box/pages/views/backend/index.view.php b/plugins/box/pages/views/backend/index.view.php index a8e9a4e..ff2f1e8 100755 --- a/plugins/box/pages/views/backend/index.view.php +++ b/plugins/box/pages/views/backend/index.view.php @@ -9,6 +9,20 @@ Html::anchor(__('Edit 404 Page', 'pages'), 'index.php?id=pages&action=edit_page&name=error404', array('title' => __('Create New Page', 'pages'), 'class' => 'btn btn-phone btn-default')) ); ?> +   +
+ + +
@@ -39,7 +53,7 @@ rel="children_" > select('[parent="'.(string) $page['slug'].'"]', 'all')) > 0) { + if (count(PagesAdmin::$pages->select('[parent="'.(string) $page['slug'].'" and locale="'.PagesAdmin::$locale_to_edit.'"]', 'all')) > 0) { if (isset($page['expand']) && $page['expand'] == '1') { echo '+'; } else { @@ -50,10 +64,11 @@ '_blank', 'rel' => 'children_'.$_parent)); + echo $dash.Html::anchor(Html::toText($page['title']), $site_url.'/'.$page_locale.$parent.$page['slug'], array('target' => '_blank', 'rel' => 'children_'.$_parent)); ?> diff --git a/plugins/box/system/system.admin.php b/plugins/box/system/system.admin.php index b1372aa..d472054 100755 --- a/plugins/box/system/system.admin.php +++ b/plugins/box/system/system.admin.php @@ -57,7 +57,8 @@ class SystemAdmin extends Backend // Get all pages $pages_array = array(); - $pages_list = $pages->select('[slug!="error404" and parent="" and status="published"]'); + $pages_list = $pages->select('[slug!="error404" and parent="" and locale="'.Site::getDefaultSiteLocale().'" and status="published"]'); + foreach ($pages_list as $page) { $pages_array[$page['slug']] = Html::toText($page['title']); } @@ -131,6 +132,7 @@ class SystemAdmin extends Backend 'timezone' => Request::post('system_timezone'), 'system_email' => Request::post('system_email'), 'language' => Request::post('system_language'), + 'site_language' => Request::post('site_language'), 'maintenance_message' => Request::post('site_maintenance_message'))); Notification::set('success', __('Your changes have been saved.', 'system')); diff --git a/plugins/box/system/system.plugin.php b/plugins/box/system/system.plugin.php index 33b6469..d5b1fa5 100644 --- a/plugins/box/system/system.plugin.php +++ b/plugins/box/system/system.plugin.php @@ -34,4 +34,4 @@ if (Session::exists('user_role') && in_array(Session::get('user_role'), array('a } -Plugin::Admin('system', 'box'); +Plugin::Admin('system', 'box'); \ No newline at end of file diff --git a/plugins/box/system/views/backend/index.view.php b/plugins/box/system/views/backend/index.view.php index ee1fb72..fd0341d 100755 --- a/plugins/box/system/views/backend/index.view.php +++ b/plugins/box/system/views/backend/index.view.php @@ -80,12 +80,20 @@
'form-control')) ); ?>
+ 'form-control')) + ); + ?> +
+
- + + http://localhost/projects/monstra-cms/blog + 2014-08-17 + weekly + 1.0 + + + http://localhost/projects/monstra-cms/blog/begin + 2014-08-18 + weekly + 0.5 + + + http://localhost/projects/monstra-cms/ + 2014-08-17 + weekly + 1.0 + + + http://localhost/projects/monstra-cms/download + 2014-08-16 + weekly + 1.0 + + + http://localhost/projects/monstra-cms/download/system + 2014-08-17 + weekly + 0.5 + + + http://localhost/projects/monstra-cms/users + 2015-01-08 + weekly + 1.0 + + \ No newline at end of file diff --git a/storage/database/options.table.xml b/storage/database/options.table.xml index 67b37a8..d8ecc0a 100644 --- a/storage/database/options.table.xml +++ b/storage/database/options.table.xml @@ -1,2 +1,2 @@ -211527510b419sitenameSitename25fe7b20ebbkeywordsSite keywords32996da0de2descriptionSite description44056d724b8sloganSite slogan5620d3e963edefaultpagehome66c9cd389f6siteurlhttp://example.org/72db8769b1etimezoneKwajalein8a0b440adcelanguageen9d7bd60ad05maintenance_statusoff10c415980d92maintenance_message<h1>Monstra :: Maintenance mode</h1>114c4e8f0aa8theme_site_namedefault124c4e8f0aa8theme_admin_namedefault124c4e8f0aa8users_frontend_registrationtrue18f469fc791ccaptcha_installedtrue19f119fc791csystem_emailadmin@admin.com20f119fc121cstyles_version121f119fc133cjavascript_version1 \ No newline at end of file +221527510b419sitenameTest25fe7b20ebbkeywordsSite keywords32996da0de2descriptionSite description44056d724b8sloganSite slogan5620d3e963edefaultpagehome66c9cd389f6siteurlhttp://localhost/projects/monstra-cms72db8769b1etimezoneKwajalein8a0b440adcelanguageen9d7bd60ad05maintenance_statusoff10c415980d92maintenance_message<h1>Monstra :: Maintenance mode</h1>114c4e8f0aa8theme_site_namedefault124c4e8f0aa8theme_admin_namedefault124c4e8f0aa8users_frontend_registrationtrue18f469fc791ccaptcha_installedtrue19f119fc791csystem_emailadmin@admin.com20f119fc121cstyles_version121f119fc133cjavascript_version1223f15e35cd1site_languageru diff --git a/storage/database/pages.table.xml b/storage/database/pages.table.xml index 272a2c3..8226bea 100644 --- a/storage/database/pages.table.xml +++ b/storage/database/pages.table.xml @@ -1,2 +1,2 @@ -4