db['language-data']['native']; $locale = basename($file, '.json'); $tmp[$locale] = $native; } return $tmp; } // Generate a random string. // Thanks, http://stackoverflow.com/questions/4356289/php-random-string-generator function getRandomString($length = 10) { return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length); } // Check if Bludit is installed. function alreadyInstalled() { return file_exists(PATH_DATABASES.'site.php'); } // Check the system, permissions, php version, modules, etc. // Returns an array with the problems otherwise empty array. function checkSystem() { $stdOut = array(); $dirpermissions = 0755; $phpModules = array(); if(function_exists('get_loaded_extensions')) { $phpModules = get_loaded_extensions(); } // If the php version is less than 5.3, then don't check others requirements. if(!version_compare(phpversion(), '5.3', '>=')) { $errorText = 'Current PHP version '.phpversion().', you need > 5.3. (ERR_202)'; error_log($errorText, 0); $tmp['title'] = 'PHP version'; $tmp['errorText'] = $errorText; array_push($stdOut, $tmp); return $stdOut; } if(!file_exists(PATH_ROOT.'.htaccess')) { $errorText = 'Missing file, upload the file .htaccess (ERR_201)'; error_log($errorText, 0); $tmp['title'] = 'File .htaccess'; $tmp['errorText'] = $errorText; array_push($stdOut, $tmp); } if(!in_array('dom', $phpModules)) { $errorText = 'PHP module DOM is not installed. (ERR_203)'; error_log($errorText, 0); $tmp['title'] = 'PHP module'; $tmp['errorText'] = $errorText; array_push($stdOut, $tmp); } if(!in_array('json', $phpModules)) { $errorText = 'PHP module JSON is not installed. (ERR_204)'; error_log($errorText, 0); $tmp['title'] = 'PHP module'; $tmp['errorText'] = $errorText; array_push($stdOut, $tmp); } if(!is_writable(PATH_CONTENT)) { $errorText = 'Writing test failure, check directory content permissions. (ERR_205)'; error_log($errorText, 0); $tmp['title'] = 'PHP permissions'; $tmp['errorText'] = $errorText; array_push($stdOut, $tmp); } return $stdOut; } // Finish with the installation. function install($adminPassword, $email, $timezoneOffset) { global $Language; $stdOut = array(); $timezone = timezone_name_from_abbr('', $timezoneOffset, 1); if($timezone === false) { $timezone = timezone_name_from_abbr('', $timezoneOffset, 0); } // Workaround bug #44780 date_default_timezone_set($timezone); $currentDate = Date::current(DB_DATE_FORMAT); // ============================================================================ // Create directories // ============================================================================ // 7=read,write,execute | 5=read,execute $dirpermissions = 0755; $firstPostSlug = 'first-post'; if(!mkdir(PATH_POSTS.$firstPostSlug, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>'.PATH_POSTS.$firstPostSlug; error_log($errorText, 0); } if(!mkdir(PATH_PAGES.'error', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'error'; error_log($errorText, 0); } if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'pages'; error_log($errorText, 0); } if(!mkdir(PATH_PLUGINS_DATABASES.'simplemde', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'simplemde'; error_log($errorText, 0); } if(!mkdir(PATH_PLUGINS_DATABASES.'tags', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'tags'; error_log($errorText, 0); } if(!mkdir(PATH_UPLOADS, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS; error_log($errorText, 0); } // ============================================================================ // Create files // ============================================================================ $dataHead = "".PHP_EOL; // File pages.php $data = array( 'error'=>array( 'description'=>'Error page', 'username'=>'admin', 'tags'=>array(), 'status'=>'published', 'date'=>$currentDate, 'position'=>0 ) ); file_put_contents(PATH_DATABASES.'pages.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File posts.php $data = array( $firstPostSlug=>array( 'description'=>'Welcome to Bludit', 'username'=>'admin', 'status'=>'published', 'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'), 'allowComments'=>'false', 'date'=>$currentDate ) ); file_put_contents(PATH_DATABASES.'posts.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File site.php $data = array( 'title'=>'Bludit', 'slogan'=>'cms', 'description'=>'', 'footer'=>Date::current('Y'), 'language'=>$Language->getCurrentLocale(), 'locale'=>$Language->getCurrentLocale(), 'timezone'=>$timezone, 'theme'=>'pure', 'adminTheme'=>'default', 'homepage'=>'', 'postsperpage'=>'6', 'uriPost'=>'/post/', 'uriPage'=>'/', 'uriTag'=>'/tag/', 'url'=>'http://'.DOMAIN.HTML_PATH_ROOT, 'cliMode'=>'true', 'emailFrom'=>'no-reply@'.DOMAIN ); file_put_contents(PATH_DATABASES.'site.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File users.php $salt = getRandomString(); $passwordHash = sha1($adminPassword.$salt); $data = array( 'admin'=>array( 'firstName'=>'', 'lastName'=>'', 'twitter'=>'', 'role'=>'admin', 'password'=>$passwordHash, 'salt'=>$salt, 'email'=>$email, 'registered'=>$currentDate ) ); file_put_contents(PATH_DATABASES.'users.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File security.php $randomKey = getRandomString(); $randomKey = sha1($randomKey); $data = array( 'key1'=>$randomKey, 'minutesBlocked'=>5, 'numberFailuresAllowed'=>10, 'blackList'=>array() ); file_put_contents(PATH_DATABASES.'security.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File tags.php file_put_contents( PATH_DATABASES.'tags.php', $dataHead.json_encode( array( 'postsIndex'=>array( 'bludit'=>array('name'=>'Bludit', 'posts'=>array('first-post')), 'cms'=>array('name'=>'CMS', 'posts'=>array('first-post')), 'flat-files'=>array('name'=>'Flat files', 'posts'=>array('first-post')) ), 'pagesIndex'=>array() ), JSON_PRETTY_PRINT), LOCK_EX ); // PLUGINS // File plugins/pages/db.php file_put_contents( PATH_PLUGINS_DATABASES.'pages'.DS.'db.php', $dataHead.json_encode( array( 'position'=>0, 'homeLink'=>true, 'label'=>$Language->get('Pages') ), JSON_PRETTY_PRINT), LOCK_EX ); // File plugins/simplemde/db.php file_put_contents( PATH_PLUGINS_DATABASES.'simplemde'.DS.'db.php', $dataHead.json_encode( array( 'position'=>0, 'tabSize'=>4, 'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"' ), JSON_PRETTY_PRINT), LOCK_EX ); // File plugins/tags/db.php file_put_contents( PATH_PLUGINS_DATABASES.'tags'.DS.'db.php', $dataHead.json_encode( array( 'position'=>0, 'label'=>$Language->get('Tags') ), JSON_PRETTY_PRINT), LOCK_EX ); // File index.txt for error page $data = 'Title: '.$Language->get('Error').' Content: '.$Language->get('The page has not been found'); file_put_contents(PATH_PAGES.'error'.DS.'index.txt', $data, LOCK_EX); // File index.txt for welcome post $data = 'Title: '.$Language->get('First post').' Content: ## '.$Language->get('Congratulations you have successfully installed your Bludit').' ### '.$Language->get('Whats next').' - '.$Language->get('Manage your Bludit from the admin panel').' - '.$Language->get('Follow Bludit on').' [Twitter](https://twitter.com/bludit) / [Facebook](https://www.facebook.com/bluditcms) / [Google+](https://plus.google.com/+Bluditcms) - '.$Language->get('Visit the support forum').' - '.$Language->get('Read the documentation for more information').' - '.$Language->get('Share with your friends and enjoy'); file_put_contents(PATH_POSTS.$firstPostSlug.DS.'index.txt', $data, LOCK_EX); return true; } // Check form's parameters and finish Bludit installation. function checkPOST($args) { global $Language; // Check empty password if( strlen($args['password']) < 6 ) { return '
get('Complete the form choose a password for the username admin') ?>
'.$error.'get('Choose your language') ?>