From 8c9198dcff05415f69ccef25a0448ede26af6b04 Mon Sep 17 00:00:00 2001 From: michu2k Date: Sat, 6 Jun 2020 22:59:12 +0200 Subject: [PATCH 1/6] getUserInfo() returns null if userCache doesn't exist, Updated defines.php --- inc/core/Main.php | 12 +++---- inc/core/defines.php | 82 ++++++++++++++++++++++---------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/inc/core/Main.php b/inc/core/Main.php index 54609c8..aad26a9 100644 --- a/inc/core/Main.php +++ b/inc/core/Main.php @@ -28,7 +28,7 @@ abstract class Main * @var array */ public $lang = []; - + /** * Templates instance * @@ -95,13 +95,13 @@ abstract class Main $this->settings = new Settings($this); date_default_timezone_set($this->settings->get('settings.timezone')); - + $this->tpl = new Templates($this); $this->router = new Router; $this->append(base64_decode('PG1ldGEgbmFtZT0iZ2VuZXJhdG9yIiBjb250ZW50PSJCYXRmbGF0IiAvPg=='), 'header'); } - + /** * New instance of QueryBuilder * @@ -309,7 +309,7 @@ abstract class Main } setcookie('batflat_remember', null, -1, '/'); } - + return false; } @@ -329,7 +329,7 @@ abstract class Main self::$userCache = $this->db('users')->where('id', $id)->oneArray(); } - return self::$userCache[$field]; + return self::$userCache ? self::$userCache[$field] : null; } /** @@ -374,7 +374,7 @@ abstract class Main $core->db('modules')->save(['dir' => $name, 'sequence' => $order]); } - + redirect(url()); } } diff --git a/inc/core/defines.php b/inc/core/defines.php index d14d57b..bfbd287 100644 --- a/inc/core/defines.php +++ b/inc/core/defines.php @@ -1,51 +1,51 @@ - * @author Wojciech Król - * @copyright 2017 Paweł Klockiewicz, Wojciech Król - * @license https://batflat.org/license - * @link https://batflat.org - */ +/** +* This file is part of Batflat ~ the lightweight, fast and easy CMS +* +* @author Paweł Klockiewicz +* @author Wojciech Król +* @copyright 2017 Paweł Klockiewicz, Wojciech Król +* @license https://batflat.org/license +* @link https://batflat.org +*/ - if (!version_compare(PHP_VERSION, '5.5.0', '>=')) { - exit("Batflat requires at least PHP 5.5"); - } +if (!version_compare(PHP_VERSION, '5.5.0', '>=')) { + exit("Batflat requires at least PHP 5.5"); +} - // Admin cat name - define('ADMIN', 'admin'); +// Admin cat name +define('ADMIN', 'admin'); - // Themes path - define('THEMES', BASE_DIR . '/themes'); +// Themes path +define('THEMES', BASE_DIR . '/themes'); - // Modules path - define('MODULES', BASE_DIR . '/inc/modules'); +// Modules path +define('MODULES', BASE_DIR . '/inc/modules'); - // Uploads path - define('UPLOADS', BASE_DIR . '/uploads'); +// Uploads path +define('UPLOADS', BASE_DIR . '/uploads'); - // Lock files - define('FILE_LOCK', false); +// Lock files +define('FILE_LOCK', false); - // Basic modules - define('BASIC_MODULES', serialize([ - 8 => 'settings', - 0 => 'dashboard', - 2 => 'pages', - 3 => 'navigation', - 7 => 'users', - 1 => 'blog', - 4 => 'galleries', - 5 => 'snippets', - 6 => 'modules', - 9 => 'contact', - 10 => 'langswitcher', - 11 => 'devbar', - ])); +// Basic modules +define('BASIC_MODULES', serialize([ + 8 => 'settings', + 0 => 'dashboard', + 2 => 'pages', + 3 => 'navigation', + 7 => 'users', + 1 => 'blog', + 4 => 'galleries', + 5 => 'snippets', + 6 => 'modules', + 9 => 'contact', + 10 => 'langswitcher', + 11 => 'devbar', +])); - // HTML beautifier - define('HTML_BEAUTY', false); +// HTML beautifier +define('HTML_BEAUTY', false); - // Developer mode - define('DEV_MODE', false); \ No newline at end of file +// Developer mode +define('DEV_MODE', false); \ No newline at end of file From ce11aaea8d1512ca6a804a223d03fba48f3aa3bd Mon Sep 17 00:00:00 2001 From: michu2k Date: Sat, 6 Jun 2020 23:06:55 +0200 Subject: [PATCH 2/6] Login: Fixed count() error in dev mode --- inc/core/Admin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/core/Admin.php b/inc/core/Admin.php index 321ad9b..799fd11 100644 --- a/inc/core/Admin.php +++ b/inc/core/Admin.php @@ -82,7 +82,7 @@ class Admin extends Main private function loadLanguage($language) { $this->lang['name'] = $language; - + foreach (glob(MODULES.'/*/lang/admin/'.$language.'.ini') as $file) { $base = str_replace($language, 'en_english', $file); $module = str_replace([MODULES.'/', '/lang/admin/'.$language.'.ini'], null, $file); @@ -142,7 +142,7 @@ class Admin extends Main { $nav = []; $modules = $this->module->getArray(); - + if ($this->getUserInfo('access') != 'all') { $modules = array_intersect_key($modules, array_fill_keys(explode(',', $this->getUserInfo('access')), null)); } @@ -207,7 +207,7 @@ class Admin extends Main { $file = MODULES.'/'.$dir.'/Info.php'; $core = $this; - + if (file_exists($file)) { return include($file); } else { @@ -241,7 +241,7 @@ class Admin extends Main if (method_exists($this->module->{$name}, $method)) { return call_user_func_array([$this->module->{$name}, $method], array_values($params)); } - + $this->setNotify('failure', $this->lang['general']['unknown_method']); return false; } @@ -274,7 +274,7 @@ class Admin extends Main $row = $this->db('users')->where('username', $username)->oneArray(); - if (count($row) && password_verify(trim($password), $row['password'])) { + if ($row && count($row) && password_verify(trim($password), $row['password'])) { // Reset fail attempts for this IP $this->db('login_attempts')->where('ip', $_SERVER['REMOTE_ADDR'])->save(['attempts' => 0]); From e2fc3c0e43efd4d4c708ec537e5e5eb37812c8d8 Mon Sep 17 00:00:00 2001 From: michu2k Date: Tue, 9 Jun 2020 22:39:05 +0200 Subject: [PATCH 3/6] searchbox/lang: Added it_italian.ini --- inc/modules/searchbox/lang/it_italian.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 inc/modules/searchbox/lang/it_italian.ini diff --git a/inc/modules/searchbox/lang/it_italian.ini b/inc/modules/searchbox/lang/it_italian.ini new file mode 100644 index 0000000..7db2ce8 --- /dev/null +++ b/inc/modules/searchbox/lang/it_italian.ini @@ -0,0 +1,4 @@ +placeholder = "Cerca per..." +results_for = "Risultati trovati per '%s' " +too_short_phrase = "La parole inserite sono troppo corte! Inserisci una frase che contenga almeno %d caratteri." +no_results = "Non sono stati trovati risultati'%s'." \ No newline at end of file From ecaff8d53e6dfa73e6aded50992fc65de931c0fb Mon Sep 17 00:00:00 2001 From: michu2k Date: Tue, 9 Jun 2020 22:43:18 +0200 Subject: [PATCH 4/6] navigation/Admin.php: Missing arrow --- inc/modules/navigation/Admin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/modules/navigation/Admin.php b/inc/modules/navigation/Admin.php index 2eff3bb..3bf39a3 100644 --- a/inc/modules/navigation/Admin.php +++ b/inc/modules/navigation/Admin.php @@ -112,7 +112,7 @@ class Admin extends AdminModule // list of parents $this->assign['navs'] = $this->_getParents($lang, $row['nav'], $row['parent'], $row['id']); - + $this->assign['title'] = $this->lang('edit_link'); return $this->draw('form.link.html', ['navigation' => $this->assign]); } else { @@ -126,7 +126,7 @@ class Admin extends AdminModule public function postSaveLink($id = null) { unset($_POST['save']); - + // check if it's an external link if ($_POST['page']) { $fields = ['name', 'page', 'lang', 'parent']; @@ -219,7 +219,7 @@ class Admin extends AdminModule redirect(url([ADMIN, 'navigation', 'manage'])); } - return $this->draw('form.nav.html', ['navigation', $this->assign]); + return $this->draw('form.nav.html', ['navigation' => $this->assign]); } /** From 9d6996d27046634a07de393f6db0ca72534a5276 Mon Sep 17 00:00:00 2001 From: michu2k Date: Tue, 9 Jun 2020 23:18:35 +0200 Subject: [PATCH 5/6] functions.php: Return '-' slug if text is empty --- inc/core/lib/functions.php | 3 ++- inc/modules/blog/Admin.php | 37 +++++++++++++++++++------------------ inc/modules/pages/Admin.php | 36 ++++++++++++++++++------------------ 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/inc/core/lib/functions.php b/inc/core/lib/functions.php index 5bd31d9..148a89d 100644 --- a/inc/core/lib/functions.php +++ b/inc/core/lib/functions.php @@ -60,8 +60,9 @@ function createSlug($text) $text = str_replace('.', '-', trim($text)); $text = iconv('utf-8', 'ascii//translit', $text); $text = preg_replace('#[^a-z0-9\-]#si', '', $text); + $text = str_replace('\'', '', $text); - return strtolower(str_replace('\'', '', $text)); + return strtolower($text ? $text : '-'); } /** diff --git a/inc/modules/blog/Admin.php b/inc/modules/blog/Admin.php index 43dbe61..d6c10ef 100644 --- a/inc/modules/blog/Admin.php +++ b/inc/modules/blog/Admin.php @@ -25,7 +25,7 @@ class Admin extends AdminModule $this->lang('settings') => 'settings' ]; } - + /** * list of posts */ @@ -59,12 +59,12 @@ class Admin extends AdminModule } else { $lang = $this->settings('settings.lang_site'); } - + // pagination $totalRecords = count($this->db('blog')->where('lang', $lang)->toArray()); $pagination = new \Inc\Core\Lib\Pagination($page, $totalRecords, 10, url([ADMIN, 'blog', 'manage', '%d'])); $this->assign['pagination'] = $pagination->nav(); - + // list $this->assign['newURL'] = url([ADMIN, 'blog', 'add']); $this->assign['postCount'] = 0; @@ -73,7 +73,7 @@ class Admin extends AdminModule ->limit($pagination->offset().', '.$pagination->getRecordsPerPage()) ->desc('published_at')->desc('created_at') ->toArray(); - + $this->assign['posts'] = []; if ($totalRecords) { $this->assign['postCount'] = $totalRecords; @@ -86,7 +86,7 @@ class Admin extends AdminModule $fullname = $this->core->getUserInfo('fullname', $row['user_id'], true); $username = $this->core->getUserInfo('username', $row['user_id'], true); $row['user'] = !empty($fullname) ? $fullname.' ('.$username.')' : $username; - + $row['comments'] = $row['comments'] ? $this->lang('comments_on') : $this->lang('comments_off'); switch ($row['status']) { @@ -116,7 +116,7 @@ class Admin extends AdminModule return $this->draw('manage.html', ['blog' => $this->assign]); } - + /** * add new post */ @@ -124,8 +124,8 @@ class Admin extends AdminModule { return $this->getEdit(null); } - - + + /** * edit post */ @@ -155,7 +155,7 @@ class Admin extends AdminModule } else { $blog = $this->db('blog')->where('id', $id)->oneArray(); } - + if (!empty($blog)) { $this->assign['langs'] = $this->_getLanguages($blog['lang'], 'selected'); $this->assign['form'] = htmlspecialchars_array($blog); @@ -163,7 +163,7 @@ class Admin extends AdminModule $this->assign['form']['date'] = date("Y-m-d\TH:i", $blog['published_at']); $tags_array = $this->db('blog_tags')->leftJoin('blog_tags_relationship', 'blog_tags.id = blog_tags_relationship.tag_id')->where('blog_tags_relationship.blog_id', $blog['id'])->select(['blog_tags.name'])->toArray(); - + $this->assign['form']['tags'] = $tags_array; $this->assign['users'] = $this->db('users')->toArray(); $this->assign['author'] = $this->core->getUserInfo('id', $blog['user_id'], true); @@ -175,7 +175,7 @@ class Admin extends AdminModule redirect(url([ADMIN, 'blog', 'manage'])); } } - + /** * Save post * @@ -191,7 +191,7 @@ class Admin extends AdminModule } else { $tags = []; } - + unset($_POST['tags']); // redirect location @@ -213,6 +213,7 @@ class Admin extends AdminModule $_POST['slug'] = createSlug($_POST['title']); } else { $_POST['slug'] = createSlug($_POST['slug']); + $_POST['slug'] = $_POST['slug'] ? $_POST['slug'] : createSlug($_POST['title']); } // check slug and append with iterator @@ -250,7 +251,7 @@ class Admin extends AdminModule $_POST['cover_photo'] = $_POST['slug'].".".$img->getInfos('type'); } } - + if (!$id) { // new $_POST['created_at'] = strtotime(date('Y-m-d H:i:s')); @@ -268,7 +269,7 @@ class Admin extends AdminModule $blogId = $id ? $id : $this->db()->pdo()->lastInsertId(); } - + // Attach or create new tag foreach ($tags as $tag) { if (preg_match("/[`~!@#$%^&*()_|+\-=?;:\'\",.<>\{\}\[\]\\\/]+/", $tag)) { @@ -300,7 +301,7 @@ class Admin extends AdminModule redirect($location); } - + /** * Remove post * @@ -395,7 +396,7 @@ class Admin extends AdminModule if (isset($_FILES['file']['tmp_name'])) { $img = new \Inc\Core\Lib\Image; - + if ($img->load($_FILES['file']['tmp_name'])) { $imgPath = $dir.'/'.time().'.'.$img->getInfos('type'); $img->save($imgPath); @@ -448,7 +449,7 @@ class Admin extends AdminModule if ($this->settings('settings.lang_admin') != 'en_english') { $this->core->addJS(url('inc/jscripts/wysiwyg/lang/'.$this->settings('settings.lang_admin').'.js')); } - + // HTML & MARKDOWN EDITOR $this->core->addCSS(url('/inc/jscripts/editor/markitup.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/markitup.highlight.min.css')); @@ -459,7 +460,7 @@ class Admin extends AdminModule $this->core->addJS(url('/inc/jscripts/editor/markitup.highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/html/set.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/markdown/set.min.js')); - + // ARE YOU SURE? $this->core->addJS(url('inc/jscripts/are-you-sure.min.js')); diff --git a/inc/modules/pages/Admin.php b/inc/modules/pages/Admin.php index 20fe236..a43e83f 100644 --- a/inc/modules/pages/Admin.php +++ b/inc/modules/pages/Admin.php @@ -24,7 +24,7 @@ class Admin extends AdminModule $this->lang('add_new') => 'add' ]; } - + /** * list of pages */ @@ -48,7 +48,7 @@ class Admin extends AdminModule $rows = $this->db('pages')->where('lang', $lang) ->limit($pagination->offset().', '.$pagination->getRecordsPerPage()) ->toArray(); - + $this->assign['list'] = []; if (count($rows)) { foreach ($rows as $row) { @@ -61,11 +61,11 @@ class Admin extends AdminModule $this->assign['list'][] = $row; } } - + $this->assign['langs'] = $this->_getLanguages($lang); return $this->draw('manage.html', ['pages' => $this->assign]); } - + /** * add new page */ @@ -73,14 +73,14 @@ class Admin extends AdminModule { $this->assign['editor'] = $this->settings('settings', 'editor'); $this->_addHeaderFiles(); - + // Unsaved data with failure if (!empty($e = getRedirectData())) { $this->assign['form'] = ['title' => isset_or($e['title'], ''), 'desc' => isset_or($e['desc'], ''), 'content' => isset_or($e['content'], ''), 'slug' => isset_or($e['slug'], '')]; } else { $this->assign['form'] = ['title' => '', 'desc' => '', 'content' => '', 'slug' => '', 'markdown' => 0]; } - + $this->assign['title'] = $this->lang('new_page'); $this->assign['langs'] = $this->_getLanguages($this->settings('settings.lang_site'), 'selected'); $this->assign['templates'] = $this->_getTemplates(isset_or($e['template'], 'index.html')); @@ -88,8 +88,8 @@ class Admin extends AdminModule return $this->draw('form.html', ['pages' => $this->assign]); } - - + + /** * edit page */ @@ -99,13 +99,13 @@ class Admin extends AdminModule $this->_addHeaderFiles(); $page = $this->db('pages')->where('id', $id)->oneArray(); - + if (!empty($page)) { // Unsaved data with failure if (!empty($e = getRedirectData())) { $page = array_merge($page, ['title' => isset_or($e['title'], ''), 'desc' => isset_or($e['desc'], ''), 'content' => isset_or($e['content'], ''), 'slug' => isset_or($e['slug'], '')]); } - + $this->assign['form'] = htmlspecialchars_array($page); $this->assign['form']['content'] = $this->tpl->noParse($this->assign['form']['content']); @@ -119,7 +119,7 @@ class Admin extends AdminModule redirect(url([ADMIN, 'pages', 'manage'])); } } - + /** * save data */ @@ -142,7 +142,7 @@ class Admin extends AdminModule if (!isset($_POST['markdown'])) { $_POST['markdown'] = 0; } - + if (empty($_POST['slug'])) { $_POST['slug'] = createSlug($_POST['title']); } else { @@ -173,7 +173,7 @@ class Admin extends AdminModule redirect($location); } - + /** * remove page */ @@ -204,7 +204,7 @@ class Admin extends AdminModule if (isset($_FILES['file']['tmp_name'])) { $img = new \Inc\Core\Lib\Image; - + if ($img->load($_FILES['file']['tmp_name'])) { $imgPath = $dir.'/'.time().'.'.$img->getInfos('type'); $img->save($imgPath); @@ -229,7 +229,7 @@ class Admin extends AdminModule echo $this->draw(MODULES.'/pages/js/admin/pages.js'); exit(); } - + /** * list of theme's templates * @param string $selected @@ -239,7 +239,7 @@ class Admin extends AdminModule { $theme = $this->settings('settings', 'theme'); $tpls = glob(THEMES.'/'.$theme.'/*.html'); - + $result = []; foreach ($tpls as $tpl) { if ($selected == basename($tpl)) { @@ -260,7 +260,7 @@ class Admin extends AdminModule if ($this->settings('settings', 'lang_admin') != 'en_english') { $this->core->addJS(url('inc/jscripts/wysiwyg/lang/'.$this->settings('settings', 'lang_admin').'.js')); } - + // HTML & MARKDOWN EDITOR $this->core->addCSS(url('/inc/jscripts/editor/markitup.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/markitup.highlight.min.css')); @@ -271,7 +271,7 @@ class Admin extends AdminModule $this->core->addJS(url('/inc/jscripts/editor/markitup.highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/html/set.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/markdown/set.min.js')); - + // ARE YOU SURE? $this->core->addJS(url('inc/jscripts/are-you-sure.min.js')); From 464f497cebe659dc3b151c0c2e398cd4b63a99c7 Mon Sep 17 00:00:00 2001 From: michu2k Date: Sun, 21 Jun 2020 13:55:42 +0200 Subject: [PATCH 6/6] Cleanup --- inc/modules/blog/Admin.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/modules/blog/Admin.php b/inc/modules/blog/Admin.php index d6c10ef..9725af5 100644 --- a/inc/modules/blog/Admin.php +++ b/inc/modules/blog/Admin.php @@ -213,7 +213,6 @@ class Admin extends AdminModule $_POST['slug'] = createSlug($_POST['title']); } else { $_POST['slug'] = createSlug($_POST['slug']); - $_POST['slug'] = $_POST['slug'] ? $_POST['slug'] : createSlug($_POST['title']); } // check slug and append with iterator