diff --git a/index-differences-from-2-3-2-to-2-4-0.php b/index-differences-from-2-3-2-to-2-4-0.php index a1e6ab8..6921517 100644 --- a/index-differences-from-2-3-2-to-2-4-0.php +++ b/index-differences-from-2-3-2-to-2-4-0.php @@ -1,130 +1,150 @@ {'config'}->{'dbVersion'})) { - if (file_exists(__DIR__ . '/themes/default/theme.php')) file_put_contents(__DIR__ . '/themes/default/theme.php', wCMS::_getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/themes/default/theme.php')); - if (file_exists(__DIR__ . '/themes/default/css/style.css')) file_put_contents(__DIR__ . '/themes/default/css/style.css', wCMS::_getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/themes/default/css/style.css')); - if (file_exists('.htaccess')) file_put_contents('.htaccess', wCMS::_getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/.htaccess')); - unlink('database.js'); - wCMS::_createDatabase(); - $newdb = wCMS::db(); - $newdb->{'config'}->{'siteTitle'} = $olddb->{'config'}->{'siteTitle'}; - $newdb->{'config'}->{'theme'} = 'default'; - $newdb->{'config'}->{'defaultPage'} = $olddb->{'config'}->{'defaultPage'}; - $newdb->{'config'}->{'login'} = $olddb->{'config'}->{'login'}; - $newdb->{'config'}->{'password'} = $olddb->{'config'}->{'password'}; - $newdb->{'config'}->{'menuItems'} = $olddb->{'config'}->{'menuItems'}; - $newdb->{'pages'} = $olddb->{'pages'}; - $newdb->{'blocks'}->{'subside'}->{'content'} = $olddb->{'config'}->{'subside'}; - $newdb->{'blocks'}->{'footer'}->{'content'} = $olddb->{'config'}->{'copyright'}; - wCMS::save($newdb); - } - if ($olddb->config->dbVersion < '2.1.0') { - $newMenu = new stdClass(); - $newPages = new stdClass(); - $i = 0; - foreach ($olddb->pages as $pageName => $page) { - $slugPage = wCMS::_slugify($pageName); - $newPages->$slugPage = $page; - $newMenu->{$i} = new stdClass; - $newMenu->{$i}->name = $page->title; - $newMenu->{$i}->slug = $slugPage; - $newMenu->{$i}->visibility = "show"; - $i++; + private static $db = false; + private static $listeners = []; + public static $loggedIn = false; + + public static function init() + { + wCMS::createDatabase(); + wCMS::installThemePluginAction(); + wCMS::loadPlugins(); + if (isset($_SESSION['l'], $_SESSION['i']) && $_SESSION['i'] == __DIR__) { + wCMS::$loggedIn = true; + } + wCMS::$currentPage = empty(wCMS::parseUrl()) ? wCMS::get('config', 'defaultPage') : wCMS::parseUrl(); + if (isset(wCMS::get('pages')->{wCMS::$currentPage})) { + wCMS::$currentPageExists = true; + } + if (isset($_GET['page']) && ! wCMS::$loggedIn) { + if (wCMS::$currentPage !== wCMS::slugify($_GET['page'])) { + wCMS::$currentPageExists = false; } - unset($olddb->config->menuItems); - unset($olddb->pages); - $olddb->config->menuItems = $newMenu; - $olddb->pages = $newPages; - $olddb->config->dbVersion = '2.1.0'; - wCMS::save($olddb); - } elseif ($olddb->config->dbVersion < '2.3.0') { - if (file_exists(__DIR__ . '/themes/default/theme.php')) file_put_contents(__DIR__ . '/themes/default/theme.php', wCMS::_getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/themes/default/theme.php')); - if (file_exists(__DIR__ . '/themes/default/css/style.css')) file_put_contents(__DIR__ . '/themes/default/css/style.css', wCMS::_getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/themes/default/css/style.css')); - $olddb->config->dbVersion = '2.3.0'; - wCMS::save($olddb); - } - } - public static function init() { - wCMS::_loadPlugins(); - wCMS::_createDatabase(); - wCMS::_updateOtherFiles(); - wCMS::_installThemePlugin(); - if (isset($_SESSION['l'], $_SESSION['i']) && $_SESSION['i'] == __DIR__) wCMS::$loggedIn = true; - wCMS::$currentPage = empty(wCMS::parseUrl()) ? wCMS::get('config','defaultPage') : wCMS::parseUrl(); - if (isset(wCMS::get('pages')->{wCMS::$currentPage})) wCMS::$currentPageExists = true; - if (isset($_GET['page']) && ! wCMS::$loggedIn) if (wCMS::$currentPage !== wCMS::_slugify($_GET['page'])) wCMS::$currentPageExists = false; - wCMS::_logoutAction(); wCMS::_loginAction(); wCMS::_saveAction(); wCMS::_changePasswordAction(); wCMS::_deleteAction(); wCMS::_upgradeAction(); wCMS::_notify(); wCMS::_removeFile(); wCMS::_uploadFile(); wCMS::_backUp(); - if ( ! wCMS::$loggedIn && ! wCMS::$currentPageExists) header("HTTP/1.1 404 Not Found"); - if (file_exists(__DIR__ . '/themes/' . wCMS::get('config','theme') . '/functions.php')) require_once __DIR__ . '/themes/' . wCMS::get('config','theme') . '/functions.php'; - require_once __DIR__ . '/themes/' . wCMS::get('config','theme') . '/theme.php'; - } - public static function editable($id, $content, $dataTarget = '') { + } + wCMS::backupAction(); + wCMS::changePasswordAction(); + wCMS::deleteFileThemePluginAction(); + wCMS::deletePageAction(); + wCMS::loginAction(); + wCMS::logoutAction(); + wCMS::notifyAction(); + wCMS::saveAction(); + wCMS::upgradeAction(); + wCMS::uploadFileAction(); + if (! wCMS::$loggedIn && ! wCMS::$currentPageExists) { + header("HTTP/1.1 404 Not Found"); + } + if (file_exists(__DIR__ . '/themes/' . wCMS::get('config', 'theme') . '/functions.php')) { + require_once __DIR__ . '/themes/' . wCMS::get('config', 'theme') . '/functions.php'; + } + require_once __DIR__ . '/themes/' . wCMS::get('config', 'theme') . '/theme.php'; + } + + public static function editable($id, $content, $dataTarget = '') + { return '
Once you do that, this page will be eventually visited by search engines.
'; + + public static function page($key) + { + $segments = wCMS::$currentPageExists ? wCMS::get('pages', wCMS::$currentPage) : (wCMS::get('config','login') == wCMS::$currentPage ? (object) wCMS::loginView() : (object) wCMS::notFoundView()); + $segments->content = isset($segments->content) ? $segments->content: 'Once you do that, this page will be eventually visited by search engines.
'; $keys = ['title' => $segments->title, 'description' => $segments->description, 'keywords' => $segments->keywords, 'content' => (wCMS::$loggedIn ? wCMS::editable('content', $segments->content, 'pages') : $segments->content)]; $content = isset($keys[$key]) ? $keys[$key] : ''; - return wCMS::_hook('page', $content, $key)[0]; + return wCMS::hook('page', $content, $key)[0]; } - public static function block($key) { + + public static function block($key) + { $blocks = wCMS::get('blocks'); return isset($blocks->{$key}) ? (wCMS::$loggedIn ? wCMS::editable($key, $blocks->{$key}->content, 'blocks') : $blocks->{$key}->content) : ''; } - public static function menu() { + + public static function menu() + { $output = ''; - foreach (wCMS::get('config','menuItems') as $key => $value) { - if ($value->visibility == "hide") continue; + foreach (wCMS::get('config', 'menuItems') as $key => $value) { + if ($value->visibility == "hide") { + continue; + } $output .= 'Menu
Once you do that, this page will be eventually visited by search engines.
']; return ['title' => 'Page not found', 'description' => '', 'keywords' => '', 'content' => 'Once you do that, this page will be eventually visited by search engines.
']; + } + return ['title' => 'Page not found', 'description' => '', 'keywords' => '', 'content' => '- Backup your website and check what\'s new before updating.
', true); + wCMS::alert('info', 'New WonderCMS update available.- Backup your website and check what\'s new before updating.
', true); } } - private static function _getOfficialVersion() { - $data = trim(wCMS::_getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/version')); + + private static function getOfficialVersion() + { + $data = trim(wCMS::getExternalFile('https://raw.githubusercontent.com/robiso/wondercms/master/version')); return $data; } - public static function _getExternalFile($url) { - $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); - $data = curl_exec($ch); curl_close($ch); return $data; + + public static function getExternalFile($url) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + $data = curl_exec($ch); + curl_close($ch); + return $data; } - public static function _loadPlugins() { - if ( ! is_dir(__DIR__ . '/plugins')) mkdir(__DIR__ . '/plugins'); - if ( ! is_dir(__DIR__ . '/files/images') || ! is_dir(__DIR__ . '/files/docs') || ! is_dir(__DIR__ . '/files/docs')) { - mkdir(__DIR__ . '/files'); mkdir(__DIR__ . '/files/docs'); mkdir(__DIR__ . '/files/images'); + + private static function loadPlugins() + { + if (! is_dir(__DIR__ . '/plugins')) { + mkdir(__DIR__ . '/plugins'); + } + if (! is_dir(__DIR__ . '/files')) { + mkdir(__DIR__ . '/files'); + } + foreach (glob(__DIR__ . '/plugins/*', GLOB_ONLYDIR) as $dir) { + if (file_exists($dir . '/' . basename($dir) . '.php')) { + include $dir . '/' . basename($dir) . '.php'; + } } - foreach (glob(__DIR__ . '/plugins/*', GLOB_ONLYDIR) as $dir) if (file_exists($dir . '/' . basename($dir) . '.php')) include $dir . '/' . basename($dir) . '.php'; } - public static function _createPage($slug = false) { + + private static function createPage($slug = false) + { $db = wCMS::db(); - $db->pages->{( ! $slug) ? wCMS::$currentPage : $slug} = new stdClass; + $db->pages->{(! $slug) ? wCMS::$currentPage : $slug} = new stdClass; wCMS::save($db); - wCMS::set('pages', ( ! $slug) ? wCMS::_slugify(wCMS::$currentPage) : $slug, 'title', ( ! $slug) ? mb_convert_case(str_replace("-", " ", wCMS::$currentPage), MB_CASE_TITLE) : mb_convert_case(str_replace("-", " ", $slug), MB_CASE_TITLE)); - wCMS::set('pages', ( ! $slug) ? wCMS::_slugify(wCMS::$currentPage) : $slug, 'keywords', 'Keywords, are, good, for, search, engines'); - wCMS::set('pages', ( ! $slug) ? wCMS::_slugify(wCMS::$currentPage) : $slug, 'description', 'A short description is also good.'); - if ( ! $slug) wCMS::_newMenuItem(wCMS::_slugify(wCMS::$currentPage), null, "show"); + wCMS::set('pages', (! $slug) ? wCMS::slugify(wCMS::$currentPage) : $slug, 'title', (! $slug) ? mb_convert_case(str_replace("-", " ", wCMS::$currentPage), MB_CASE_TITLE) : mb_convert_case(str_replace("-", " ", $slug), MB_CASE_TITLE)); + wCMS::set('pages', (! $slug) ? wCMS::slugify(wCMS::$currentPage) : $slug, 'keywords', 'Keywords, are, good, for, search, engines'); + wCMS::set('pages', (! $slug) ? wCMS::slugify(wCMS::$currentPage) : $slug, 'description', 'A short description is also good.'); + if (! $slug) { + wCMS::createMenuItem(wCMS::slugify(wCMS::$currentPage), null, "show"); + } } - public static function _slugify($text) { - $text = preg_replace('~[^\\pL\d]+~u','-', $text); + + public static function slugify($text) + { + $text = preg_replace('~[^\\pL\d]+~u', '-', $text); $text = trim(htmlspecialchars(mb_strtolower($text), ENT_QUOTES), '/'); - $text = trim($text,'-'); + $text = trim($text, '-'); return empty($text) ? "-" : $text; } - public static function _hook() { + + private static function hook() + { $numArgs = func_num_args(); $args = func_get_args(); - if ($numArgs < 2) trigger_error('Insufficient arguments', E_USER_ERROR); + if ($numArgs < 2) { + trigger_error('Insufficient arguments', E_USER_ERROR); + } $hookName = array_shift($args); - if ( ! isset(wCMS::$_listeners[$hookName])) return $args; - foreach (wCMS::$_listeners[$hookName] as $func) $args = $func($args); + if (! isset(wCMS::$listeners[$hookName])) { + return $args; + } + foreach (wCMS::$listeners[$hookName] as $func) { + $args = $func($args); + } return $args; } - public static function _installThemePlugin() { - if ( ! wCMS::$loggedIn && ! isset($_POST['installAddon'])) return; - if ($_REQUEST['token'] == wCMS::_generateToken()) { - $installLocation = $_POST['installLocation']; + + private static function installThemePluginAction() + { + if (! wCMS::$loggedIn && ! isset($_POST['installAddon'])) { + return; + } + if (hash_equals($_REQUEST['token'], wCMS::generateToken())) { + $installLocation = trim(strtolower($_POST['installLocation'])); $addonURL = $_POST['addonURL']; - if ($installLocation == 'themes' || $installLocation == 'plugins' && ! empty($addonURL)) { + $validPaths = array("themes", "plugins"); + if (in_array($installLocation, $validPaths) && ! empty($addonURL)) { $zipFile = __DIR__ . '/files/ZIPFromURL.zip'; $zipResource = fopen($zipFile, "w"); - $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $addonURL); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FILE, $zipResource); curl_exec($ch); curl_close($ch); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $addonURL); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_FILE, $zipResource); + curl_exec($ch); + curl_close($ch); $zip = new ZipArchive; $extractPath = __DIR__ . '/' . $installLocation . '/'; - if ($zip->open($zipFile) != 'true' || (stripos($addonURL,'.zip') != true)) { - wCMS::_recursiveDelete(__DIR__ . '/files/ZIPFromURL.zip'); wCMS::alert('danger', 'Error openning ZIP file.'); wCMS::redirect(); + if ($zip->open($zipFile) != 'true' || (stripos($addonURL, '.zip') != true)) { + wCMS::recursiveDelete(__DIR__ . '/files/ZIPFromURL.zip'); + wCMS::alert('danger', 'Error openning ZIP file.'); + wCMS::redirect(); } $zip->extractTo($extractPath); $zip->close(); - wCMS::_recursiveDelete(__DIR__ . '/files/ZIPFromURL.zip'); wCMS::alert('success', 'Installed successfully.'); wCMS::redirect(); + wCMS::recursiveDelete(__DIR__ . '/files/ZIPFromURL.zip'); + wCMS::alert('success', 'Installed successfully.'); + wCMS::redirect(); + } elseif (empty($addonURL)) { + wCMS::alert('danger', 'Error openning ZIP file.'); } else { - wCMS::alert('danger', 'Choose between theme or plugin and enter link to ZIP file.'); wCMS::redirect(); + wCMS::alert('danger', 'Choose between theme or plugin and enter link to ZIP file.'); + wCMS::redirect(); } } } - public static function _uploadFile() { - if ( ! wCMS::$loggedIn && ! isset($_FILES['uploadFile']) && ! isset($_REQUEST['token'])) return; - if (isset($_REQUEST['token']) && $_REQUEST['token'] == wCMS::_generateToken() && isset($_FILES['uploadFile'])) { + + private static function uploadFileAction() + { + if (! wCMS::$loggedIn && ! isset($_FILES['uploadFile']) && ! isset($_REQUEST['token'])) { + return; + } + if (isset($_REQUEST['token']) && hash_equals($_REQUEST['token'], wCMS::generateToken()) && isset($_FILES['uploadFile'])) { try { - if ( ! isset($_FILES['uploadFile']['error']) || is_array($_FILES['uploadFile']['error'])) { - wCMS::alert('danger', 'Invalid parameters.'); wCMS::redirect(wCMS::$currentPage); + if (! isset($_FILES['uploadFile']['error']) || is_array($_FILES['uploadFile']['error'])) { + wCMS::alert('danger', 'Invalid parameters.'); + wCMS::redirect(wCMS::$currentPage); } switch ($_FILES['uploadFile']['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_NO_FILE: - wCMS::alert('danger', 'No file selected.'); wCMS::redirect(wCMS::$currentPage); + wCMS::alert('danger', 'No file selected.'); + wCMS::redirect(wCMS::$currentPage); case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: - wCMS::alert('danger', 'File too large. Change maximum upload size limit or contact your host.'); wCMS::redirect(wCMS::$currentPage); + wCMS::alert('danger', 'File too large. Change maximum upload size limit or contact your host.'); + wCMS::redirect(wCMS::$currentPage); default: - wCMS::alert('danger', 'Unknown error.'); wCMS::redirect(wCMS::$currentPage); + wCMS::alert('danger', 'Unknown error.'); + wCMS::redirect(wCMS::$currentPage); } $mimeType = ''; if (class_exists('finfo')) { $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($_FILES['uploadFile']['tmp_name']); - } else if (function_exists('mime_content_type')) { + } elseif (function_exists('mime_content_type')) { $mimeType = mime_content_type($_FILES['uploadFile']['tmp_name']); } else { $ext = strtolower(array_pop(explode('.', $_FILES['uploadFile']['name']))); } - if ( ! move_uploaded_file($_FILES['uploadFile']['tmp_name'], sprintf(__DIR__ . '/files/%s', $_FILES['uploadFile']['name']))) { - wCMS::alert('danger', 'Failed to move uploaded file.'); wCMS::redirect(wCMS::$currentPage); + if (! move_uploaded_file($_FILES['uploadFile']['tmp_name'], sprintf(__DIR__ . '/files/%s', $_FILES['uploadFile']['name']))) { + wCMS::alert('danger', 'Failed to move uploaded file.'); + wCMS::redirect(wCMS::$currentPage); } - wCMS::alert('success', 'File uploaded.'); wCMS::redirect(wCMS::$currentPage); + wCMS::alert('success', 'File uploaded.'); + wCMS::redirect(wCMS::$currentPage); } catch (RuntimeException $e) { - wCMS::alert('danger', 'Error: ' . $e->getMessage()); wCMS::redirect(wCMS::$currentPage); + wCMS::alert('danger', 'Error: ' . $e->getMessage()); + wCMS::redirect(wCMS::$currentPage); } } } - public static function _recursiveDelete($file) { + + private static function recursiveDelete($file) + { if (is_dir($file)) { $list = glob($file . '*', GLOB_MARK); - foreach ($list as $dir) wCMS::_recursiveDelete($dir); - rmdir($file); - } elseif (is_file($file)) unlink($file); - } - public static function _removeFile() { - if ( ! wCMS::$loggedIn) return; - if (isset($_REQUEST['deleteFile']) || isset($_REQUEST['deleteTheme']) || isset($_REQUEST['deletePlugin']) && isset($_REQUEST['token']) && $_REQUEST['token'] == wCMS::_generateToken()) { - $fileList = array_slice(scandir(__DIR__ . '/files/'), 2); - foreach ($fileList as $file) { - if (isset($_REQUEST['deleteFile']) && $_REQUEST['deleteFile'] == $file) { - wCMS::_recursiveDelete(__DIR__ . '/files/' . $file); wCMS::alert('success', 'File removed.'); wCMS::redirect(); - } - } - $fileImagesList = array_slice(scandir(__DIR__ . '/files/images/'), 2); - foreach ($fileImagesList as $fileImage) { - if (isset($_REQUEST['deleteFile']) && $_REQUEST['deleteFile'] == $fileImage) { - wCMS::_recursiveDelete(__DIR__ . '/files/images/' . $fileImage); wCMS::alert('success', 'File removed.'); wCMS::redirect(); - } - } - $fileDocsList = array_slice(scandir(__DIR__ . '/files/docs/'), 2); - foreach ($fileDocsList as $fileDoc) { - if (isset($_REQUEST['deleteFile']) && $_REQUEST['deleteFile'] == $fileDoc) { - wCMS::_recursiveDelete(__DIR__ . '/files/docs/' . $fileDoc); wCMS::alert('success', 'File removed.'); wCMS::redirect(); - } + foreach ($list as $dir) { + wCMS::recursiveDelete($dir); } - $themeList = array_slice(scandir(__DIR__ . '/themes'), 2); - foreach ($themeList as $theme) { - if (isset($_REQUEST['deleteTheme']) && wCMS::get('config','theme') == $_REQUEST['deleteTheme']) { - wCMS::alert('danger', 'Cannot remove currently active theme.'); wCMS::redirect(); + rmdir($file); + } elseif (is_file($file)) { + unlink($file); + } + } + + private static function deleteFileThemePluginAction() + { + if (! wCMS::$loggedIn) { + return; + } + if (isset($_REQUEST['deleteFile']) || isset($_REQUEST['deleteTheme']) || isset($_REQUEST['deletePlugin']) && isset($_REQUEST['token'])) { + if (hash_equals($_REQUEST['token'], wCMS::generateToken())) { + $fileList = array_slice(scandir(__DIR__ . '/files/'), 2); + foreach ($fileList as $file) { + if (isset($_REQUEST['deleteFile']) && $_REQUEST['deleteFile'] == $file) { + wCMS::recursiveDelete(__DIR__ . '/files/' . $file); + wCMS::alert('success', 'File deleted.'); + wCMS::redirect(); + } } - elseif (isset($_REQUEST['deleteTheme']) && $_REQUEST['deleteTheme'] == $theme) { - wCMS::_recursiveDelete(__DIR__ . '/themes/' . $theme . '/'); wCMS::alert('success', 'Theme removed.'); wCMS::redirect(); + $themeList = array_slice(scandir(__DIR__ . '/themes'), 2); + foreach ($themeList as $theme) { + if (isset($_REQUEST['deleteTheme']) && wCMS::get('config', 'theme') == $_REQUEST['deleteTheme']) { + wCMS::alert('danger', 'Cannot delete currently active theme.'); + wCMS::redirect(); + } elseif (isset($_REQUEST['deleteTheme']) && $_REQUEST['deleteTheme'] == $theme) { + wCMS::recursiveDelete(__DIR__ . '/themes/' . $theme . '/'); + wCMS::alert('success', 'Theme deleted.'); + wCMS::redirect(); + } } - } - $pluginList = array_slice(scandir(__DIR__ . '/plugins'), 2); - foreach ($pluginList as $plugin) { - if (isset($_REQUEST['deletePlugin']) && $_REQUEST['deletePlugin'] == $plugin) { - wCMS::_recursiveDelete(__DIR__ . '/plugins/' . $plugin . '/'); wCMS::alert('success', 'Plugin removed.'); wCMS::redirect(); + $pluginList = array_slice(scandir(__DIR__ . '/plugins'), 2); + foreach ($pluginList as $plugin) { + if (isset($_REQUEST['deletePlugin']) && $_REQUEST['deletePlugin'] == $plugin) { + wCMS::recursiveDelete(__DIR__ . '/plugins/' . $plugin . '/'); + wCMS::alert('success', 'Plugin deleted.'); + wCMS::redirect(); + } } - } + } } } - public static function _backUp() { - if ( ! wCMS::$loggedIn) return; - $backups = glob(__DIR__ . '/files/backup-*.zip'); - if ( ! empty($backups)) { - $backups = implode(' and ', array_map('basename', $backups)); - wCMS::alert('danger', 'Remove backup files. (Settings -> Files -> Remove files)'); + + private static function backupAction() + { + if (! wCMS::$loggedIn) { + return; + } + $backupList = glob(__DIR__ . '/files/backup-*.zip'); + if (! empty($backupList)) { + wCMS::alert('danger', 'Delete backup files. (Settings -> Files -> Delete files)'); } $backup = 'backup-' . date('Y-m-d-') . substr(md5(microtime()), rand(0, 26), 5) . '.zip'; - if ( ! isset($_POST['backup'])) return; - if ($_POST['token'] == wCMS::_generateToken()) { - if (wCMS::zipBackUp(__DIR__, __DIR__ . '/files/' . $backup) !== false) wCMS::redirect('files/'.$backup); + if (! isset($_POST['backup'])) { + return; + } + if (hash_equals($_POST['token'], wCMS::generateToken())) { + if (wCMS::zipBackup(__DIR__, __DIR__ . '/files/' . $backup) !== false) { + wCMS::redirect('files/'.$backup); + } } } - public static function zipBackUp($source, $destination) { + + private static function zipBackup($source, $destination) + { if (extension_loaded('zip')) { if (file_exists($source)) { $zip = new ZipArchive(); @@ -531,11 +730,11 @@ public static function zipBackUp($source, $destination) { $file = realpath($file); if (is_dir($file)) { $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); - } else if (is_file($file)) { + } elseif (is_file($file)) { $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); } } - } else if (is_file($source)) { + } elseif (is_file($source)) { $zip->addFromString(basename($source), file_get_contents($source)); } } @@ -544,8 +743,12 @@ public static function zipBackUp($source, $destination) { } return false; } - public static function _createDatabase() { - if (wCMS::db() !== false) return; + + private static function createDatabase() + { + if (wCMS::db() !== false) { + return; + } wCMS::save([ 'config' => [ 'dbVersion' => '2.3.0',