diff --git a/admin/controllers/add-user.php b/admin/controllers/add-user.php index 8988d60b..1cb13fe7 100644 --- a/admin/controllers/add-user.php +++ b/admin/controllers/add-user.php @@ -1,5 +1,14 @@ role()!=='admin') { + Alert::set('You do not have sufficient permissions to access this page, contact the administrator.'); + Redirect::page('admin', 'dashboard'); +} + // ============================================================================ // Functions // ============================================================================ @@ -45,3 +54,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) Redirect::page('admin', 'users'); } } + +// ============================================================================ +// Main +// ============================================================================ diff --git a/admin/controllers/edit-user.php b/admin/controllers/edit-user.php index 7fdd0da5..f2fe4d9e 100644 --- a/admin/controllers/edit-user.php +++ b/admin/controllers/edit-user.php @@ -1,5 +1,9 @@ role()!=='admin') + { + $_POST['username'] = $Login->username(); + unset($_POST['role']); + } + if( editUser($_POST) ) { Alert::set('User saved successfuly.'); } + +} + +// ============================================================================ +// Main +// ============================================================================ + +if($Login->role()!=='admin') { + $layout['parameters'] = $Login->username(); } $_user = $dbUsers->get($layout['parameters']); // If the user doesn't exist, redirect to the users list. -if($_user===false) - Redirect::page('admin', 'users'); \ No newline at end of file +if($_user===false) { + Redirect::page('admin', 'users'); +} + +$_user['username'] = $layout['parameters']; \ No newline at end of file diff --git a/admin/controllers/login.php b/admin/controllers/login.php index 4dc0d4ca..4dc23ea9 100644 --- a/admin/controllers/login.php +++ b/admin/controllers/login.php @@ -9,4 +9,8 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { Redirect::page('admin', 'dashboard'); } + else + { + Alert::set('Login failed'); + } } diff --git a/admin/controllers/logout.php b/admin/controllers/logout.php new file mode 100644 index 00000000..53702e42 --- /dev/null +++ b/admin/controllers/logout.php @@ -0,0 +1,6 @@ +logout()) +{ + Redirect::home(); +} diff --git a/admin/controllers/settings.php b/admin/controllers/settings.php index 90a926dc..3b9d3bff 100644 --- a/admin/controllers/settings.php +++ b/admin/controllers/settings.php @@ -1,5 +1,14 @@ role()!=='admin') { + Alert::set('You do not have sufficient permissions to access this page, contact the administrator.'); + Redirect::page('admin', 'dashboard'); +} + // ============================================================================ // Functions // ============================================================================ @@ -28,3 +37,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { setSettings($_POST); } + +// ============================================================================ +// Main +// ============================================================================ diff --git a/admin/controllers/users.php b/admin/controllers/users.php index 7e550c48..cb1667da 100644 --- a/admin/controllers/users.php +++ b/admin/controllers/users.php @@ -1,6 +1,23 @@ role()!=='admin') { + Alert::set('You do not have sufficient permissions to access this page, contact the administrator.'); + Redirect::page('admin', 'dashboard'); +} + +// ============================================================================ +// POST Method +// ============================================================================ + if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { $Site->set($_POST); } + +// ============================================================================ +// Main +// ============================================================================ diff --git a/admin/themes/default/css/installer.css b/admin/themes/default/css/installer.css new file mode 100644 index 00000000..8b77bd52 --- /dev/null +++ b/admin/themes/default/css/installer.css @@ -0,0 +1,25 @@ +a { + text-decoration: none; + color: #333; +} + +a:hover { + color: #2672ec !important; + text-decoration: none !important; +} + +/* ----------- FONTS AWESOME ----------- */ +.fa-right { + margin-right: 5px; +} + +/* ----------- ----------- */ +div.main { + text-align: center; + margin: 30px 0; +} +h1.title { + font-weight: lighter; + font-size: 4em; +} + diff --git a/admin/themes/default/index.php b/admin/themes/default/index.php index 9b9dc3fb..673c36c1 100644 --- a/admin/themes/default/index.php +++ b/admin/themes/default/index.php @@ -22,7 +22,7 @@ + + + +
+
+
+

Bludit Installer

+

Welcome to the Bludit installer

+ + + +

Complete the form, choose a password for the username admin

+
+
+ + + + + + + +

+ +

+
+
+ + '; + echo ''; + + foreach ($system as $value) + { + echo ''; + } + + echo '
'.$value.'
'; + echo ' + +
+
+
+ + \ No newline at end of file diff --git a/kernel/boot/admin.php b/kernel/boot/admin.php index bd2e11f4..38811c98 100644 --- a/kernel/boot/admin.php +++ b/kernel/boot/admin.php @@ -14,6 +14,15 @@ $layout['controller'] = $layout['view'] = $layout['slug'] = $explodeSlug[0]; unset($explodeSlug[0]); $layout['parameters'] = implode('/', $explodeSlug); +// Disable Magic Quotes +// Thanks, http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting +if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) ) +{ + $_POST = array_map('stripslashes', $_POST); + $_GET = array_map('stripslashes', $_GET); + $_COOKIE = array_map('stripslashes', $_COOKIE); +} + // AJAX if( $Login->isLogged() && ($layout['slug']==='ajax') ) { diff --git a/kernel/boot/init.php b/kernel/boot/init.php index 64d6cc52..6f0a7bf9 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -26,6 +26,19 @@ define('PATH_ADMIN_VIEWS', PATH_ROOT.'admin/views/'); // Log separator define('LOG_SEP', ' | '); +// JSON pretty print +if(!defined('JSON_PRETTY_PRINT')) { + define('JSON_PRETTY_PRINT', 128); +} + +// Salt length +define('SALT_LENGTH', 8); + +// Bludit version +define('BLUDIT_VERSION', '0.1 beta1'); +define('BLUDIT_CODENAME', ''); +define('BLUDIT_RELEASE_DATE', '2015-05-13'); + // define('NO_PARENT_CHAR', '—'); @@ -102,6 +115,8 @@ else { define('HTML_PATH_THEMES', HTML_PATH_ROOT.'themes/'); define('HTML_PATH_THEME', HTML_PATH_ROOT.'themes/'.$Site->theme().'/'); +define('HTML_PATH_THEME_CSS', HTML_PATH_THEME.'css/'); +define('HTML_PATH_THEME_JS', HTML_PATH_THEME.'js/'); define('HTML_PATH_ADMIN_THEME', HTML_PATH_ROOT.'admin/themes/'.$Site->adminTheme().'/'); define('HTML_PATH_ADMIN_ROOT', HTML_PATH_ROOT.'admin/'); @@ -112,4 +127,4 @@ $Login = new Login( $dbUsers ); $Url->checkFilters( $Site->uriFilters() ); // Objects shortcuts -$L = $Language; \ No newline at end of file +$L = $Language; diff --git a/kernel/boot/rules/70.build_posts.php b/kernel/boot/rules/70.build_posts.php index 8b5014fe..5b4dc5e2 100644 --- a/kernel/boot/rules/70.build_posts.php +++ b/kernel/boot/rules/70.build_posts.php @@ -55,12 +55,18 @@ function buildPost($key) return $Post; } -function build_posts_per_page($draftPosts=false) +function build_posts_per_page($pageNumber=0, $amount=5, $draftPosts=false) { global $dbPosts; global $posts; + global $Url; - $list = $dbPosts->getPage(0, 5, $draftPosts); + $list = $dbPosts->getPage($pageNumber, $amount, $draftPosts); + + // There are not post for the pageNumber then NotFound page + if(empty($list)) { + $Url->setNotFound(true); + } foreach($list as $slug=>$db) { @@ -98,10 +104,10 @@ else { if($Url->whereAmI()==='admin') { // Build post for admin area with drafts - build_posts_per_page(true); + build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), true); } else { - build_posts_per_page(); + build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), false); } } diff --git a/kernel/dbusers.class.php b/kernel/dbusers.class.php index 666bc4e0..bc4eb56f 100644 --- a/kernel/dbusers.class.php +++ b/kernel/dbusers.class.php @@ -6,9 +6,9 @@ class dbUsers extends dbJSON 'firstName'=> array('inFile'=>false, 'value'=>''), 'lastName'=> array('inFile'=>false, 'value'=>''), 'username'=> array('inFile'=>false, 'value'=>''), - 'role'=> array('inFile'=>false, 'value'=>''), + 'role'=> array('inFile'=>false, 'value'=>'editor'), 'password'=> array('inFile'=>false, 'value'=>''), - 'salt'=> array('inFile'=>false, 'value'=>''), + 'salt'=> array('inFile'=>false, 'value'=>'!Pink Floyd!Welcome to the machine!'), 'email'=> array('inFile'=>false, 'value'=>''), 'registered'=> array('inFile'=>false, 'value'=>0) ); @@ -24,7 +24,6 @@ class dbUsers extends dbJSON if($this->userExists($username)) { $user = $this->db[$username]; - $user['username'] = $username; return $user; } @@ -45,25 +44,37 @@ class dbUsers extends dbJSON public function set($args) { - $username = Sanitize::html($args['username']); + $dataForDb = array(); + $user = $this->get($args['username']); + + if($user===false) + { + Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the username '.$args['username']); + return false; + } + + // Verify arguments with the database fields. foreach($args as $field=>$value) { if( isset($this->dbFields[$field]) ) { - // Sanitize or not. - if($this->dbFields[$field]['sanitize']=='html') { - $tmpValue = Sanitize::html($value); - } - else { - $tmpValue = $value; - } + // Sanitize if will be saved on database. + $tmpValue = Sanitize::html($value); - $this->db[$username][$field] = $tmpValue; + // Set type + settype($tmpValue, gettype($this->dbFields[$field]['value'])); + + $user[$field] = $tmpValue; } } - $this->save(); + // Save the database + $this->db[$args['username']] = $user; + if( $this->save() === false ) { + Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.'); + return false; + } return true; } @@ -78,8 +89,8 @@ class dbUsers extends dbJSON // If the user send the field. if( isset($args[$field]) ) { - // Sanitize or not. - if($options['sanitize']=='html') { + // Sanitize if will be saved on database. + if( !$options['inFile'] ) { $tmpValue = Sanitize::html($args[$field]); } else { @@ -92,6 +103,10 @@ class dbUsers extends dbJSON $tmpValue = $options['value']; } + // Set type + settype($tmpValue, gettype($options['value'])); + + // Save on database $dataForDb[$field] = $tmpValue; } @@ -104,12 +119,15 @@ class dbUsers extends dbJSON $dataForDb['registered'] = Date::unixTime(); // Password - $dataForDb['salt'] = helperText::randomText(8); + $dataForDb['salt'] = helperText::randomText(SALT_LENGTH); $dataForDb['password'] = sha1($dataForDb['password'].$dataForDb['salt']); // Save the database $this->db[$dataForDb['username']] = $dataForDb; - $this->save(); + if( $this->save() === false ) { + Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.'); + return false; + } return true; } diff --git a/kernel/helpers/alert.class.php b/kernel/helpers/alert.class.php index 413dd916..b1265998 100644 --- a/kernel/helpers/alert.class.php +++ b/kernel/helpers/alert.class.php @@ -5,21 +5,21 @@ class Alert { // new public static function set($value, $key='alert') { - Session::set('displayed', false); + Session::set('defined', true); Session::set($key, $value); } public static function get($key='alert') { - Session::set('displayed', true); + Session::set('defined', false); return Session::get($key); } - public static function displayed() + public static function defined() { - return Session::get('displayed'); + return Session::get('defined'); } } diff --git a/kernel/helpers/date.class.php b/kernel/helpers/date.class.php index de8a188b..42968c0f 100644 --- a/kernel/helpers/date.class.php +++ b/kernel/helpers/date.class.php @@ -37,27 +37,10 @@ class Date { } } - // Old - - public static function set_locale($string) - { - if(setlocale(LC_ALL,$string.'.UTF-8')!==false) - return true; - - if(setlocale(LC_ALL,$string.'.UTF8')!==false) - return true; - - return setlocale(LC_ALL,$string); - } - - public static function set_timezone($string) - { - return(date_default_timezone_set($string)); - } - + // DEBUG: Check this function, need to be more fast // Return array('Africa/Abidjan'=>'Africa/Abidjan (GMT+0)', ..., 'Pacific/Wallis'=>'Pacific/Wallis (GMT+12)'); // PHP supported list. http://php.net/manual/en/timezones.php - public static function get_timezones() + public static function timezoneList() { $tmp = array(); @@ -76,12 +59,29 @@ class Date { $text = str_replace("_"," ",$timezone_identifier); - $tmp[$timezone_identifier]=$text.' ('.$hours.':'.$mins.')'; + $tmp[$text.' ('.$hours.':'.$mins.')'] = $timezone_identifier; } - return($tmp); + return $tmp; } + // Old + + public static function set_locale($string) + { + if(setlocale(LC_ALL,$string.'.UTF-8')!==false) + return true; + + if(setlocale(LC_ALL,$string.'.UTF8')!==false) + return true; + + return setlocale(LC_ALL,$string); + } + + public static function set_timezone($string) + { + return(date_default_timezone_set($string)); + } // Format a GMT/UTC+0 date/time diff --git a/kernel/helpers/redirect.class.php b/kernel/helpers/redirect.class.php index c7b891ba..7e9a8f48 100644 --- a/kernel/helpers/redirect.class.php +++ b/kernel/helpers/redirect.class.php @@ -17,4 +17,10 @@ class Redirect { { self::url(HTML_PATH_ROOT.$base.'/'.$page); } + + public static function home() + { + self::url(HTML_PATH_ROOT); + } + } \ No newline at end of file diff --git a/kernel/helpers/session.class.php b/kernel/helpers/session.class.php index d853c823..ec3993bc 100644 --- a/kernel/helpers/session.class.php +++ b/kernel/helpers/session.class.php @@ -22,15 +22,15 @@ class Session { $cookieParams = session_get_cookie_params(); session_set_cookie_params($cookieParams["lifetime"], - $cookieParams["path"], - $cookieParams["domain"], + $cookieParams["path"], + $cookieParams["domain"], $secure, $httponly ); // Sets the session name to the one set above. session_name($session_name); - + // Start session. self::$started = session_start(); @@ -48,14 +48,16 @@ class Session { session_destroy(); unset($_SESSION); - + self::$started = false; + + return !isset($_SESSION); } public static function set($key, $value) { $key = 's_'.$key; - + $_SESSION[$key] = $value; } diff --git a/kernel/helpers/text.class.php b/kernel/helpers/text.class.php index 74116839..e6b5df2e 100644 --- a/kernel/helpers/text.class.php +++ b/kernel/helpers/text.class.php @@ -37,16 +37,25 @@ class helperText { return $text; } - public static function cleanUrl($string, $separator = '-') + public static function cleanUrl($text, $separator='-') { - $accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i'; - $special_cases = array( '&' => 'and'); - $string = self::lowercase( trim( $string ), 'UTF-8' ); - $string = str_replace( array_keys($special_cases), array_values( $special_cases), $string ); - $string = preg_replace( $accents_regex, '$1', htmlentities( $string, ENT_QUOTES, 'UTF-8' ) ); - $string = preg_replace("/[^a-z0-9]/u", "$separator", $string); - $string = preg_replace("/[$separator]+/u", "$separator", $string); - return $string; + // Delete characters + $text = str_replace(array("“", "”", "!", "*", "'", """, "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$text); + $text = preg_replace('![^\\pL\d]+!u', $separator, $text); + + // Remove spaces + $text = str_replace(' ',$separator, $text); + + //remove any additional characters that might appear after translit + //$text = preg_replace('![^-\w]+!', '', $text); + + // Replace multiple dashes + $text = preg_replace('/-{2,}/', $separator, $text); + + // Make a string lowercase + $text = self::lowercase($text); + + return $text; } // Replace all occurrences of the search string with the replacement string. @@ -212,45 +221,6 @@ class helperText { return( strcmp($value1, $value2) == 0 ); } - // Clean text for URL - public static function clean_url($text, $spaces='-', $translit=false) - { - // Delete characters - $text = str_replace(array("“", "”", "!", "*", "'", """, "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "|"),'',$text); - $text = preg_replace('![^\\pL\d]+!u', '-', $text); - - // Translit - if($translit!=false) - { - $text = str_replace(array_keys($translit),array_values($translit),$text); - } - if (function_exists('iconv')) - { - $ret = iconv('utf-8', 'us-ascii//TRANSLIT//IGNORE', $text); - if ($ret!==false){ //iconv might return false on error - $text = $ret; - } - } - - // Replace spaces by $spaces - $text = str_replace(' ',$spaces,$text); - - //remove any additional characters that might appear after translit - $text = preg_replace('![^-\w]+!', '', $text); - - // Replace multiple dashes - $text = preg_replace('/-{2,}/', '-', $text); - - // Make a string lowercase - $text = self::str2lower($text); - - return $text; - } - - - - - public static function replace_assoc(array $replace, $text) { return str_replace(array_keys($replace), array_values($replace), $text); diff --git a/kernel/helpers/theme.class.php b/kernel/helpers/theme.class.php index fae91603..64e7432e 100644 --- a/kernel/helpers/theme.class.php +++ b/kernel/helpers/theme.class.php @@ -2,6 +2,89 @@ class Theme { + // NEW + + public static function css($files, $path=HTML_PATH_THEME_CSS, $echo=true) + { + if(!is_array($files)) { + $files = array($files); + } + + $tmp = ''; + foreach($files as $file) { + $tmp .= ''.PHP_EOL; + } + + if($echo) { + echo $tmp; + } + + return $tmp; + } + + public static function javascript($files, $path=HTML_PATH_THEME_JS, $echo=true) + { + if(!is_array($files)) { + $files = array($files); + } + + $tmp = ''; + foreach($files as $file) { + $tmp .= ''.PHP_EOL; + } + + if($echo) { + echo $tmp; + } + + return $tmp; + } + + public static function title($title, $echo=true) + { + $tmp = ''.$title.''.PHP_EOL; + + if($echo) { + echo $tmp; + } + + return $tmp; + } + + public static function description($description, $echo=true) + { + $tmp = ''.PHP_EOL; + + if($echo) { + echo $tmp; + } + + return $tmp; + } + + public static function viewport($content='width=device-width, initial-scale=1.0', $echo=true) + { + $tmp = ''.PHP_EOL; + + if($echo) { + echo $tmp; + } + + return $tmp; + } + + public static function charset($charset, $echo=true) + { + $tmp = ''.PHP_EOL; + + if($echo) { + echo $tmp; + } + + return $tmp; + } + + // OLD public static function plugins($type) { global $plugins; @@ -12,7 +95,8 @@ class Theme { } } - // OLD + + public static function url($relative = true) { if($relative) @@ -21,29 +105,9 @@ class Theme { return BLOG_URL; } - public static function css($files, $path=HTML_THEME_CSS) - { - if(!is_array($files)) - $files = array($files); - $tmp = ''; - foreach($files as $file) - $tmp .= ''.PHP_EOL; - return $tmp; - } - public static function javascript($files, $path=HTML_THEME_JS) - { - if(!is_array($files)) - $files = array($files); - - $tmp = ''; - foreach($files as $file) - $tmp .= ''.PHP_EOL; - - return $tmp; - } public static function jquery($path=JS_JQUERY) { diff --git a/kernel/login.class.php b/kernel/login.class.php index 571c1b2e..de29b120 100644 --- a/kernel/login.class.php +++ b/kernel/login.class.php @@ -91,4 +91,9 @@ class Login { return sha1($agent); } + public function logout() + { + return Session::destroy(); + } + } diff --git a/kernel/url.class.php b/kernel/url.class.php index 0096bbcc..ae937d92 100644 --- a/kernel/url.class.php +++ b/kernel/url.class.php @@ -8,14 +8,19 @@ class Url private $slug; private $filters; // Filters for the URI private $notFound; + private $parameters; function __construct() { // Decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character. - $this->uri = urldecode($_SERVER['REQUEST_URI']); + $decode = urldecode($_SERVER['REQUEST_URI']); - // URI Lowercase - //$this->uri = helperText::lowercase($this->uri); + // Parse, http://php.net/parse_url + $parse = parse_url($decode); + + $this->uri = $parse['path']; + + $this->parameters = $_GET; $this->uriStrlen = helperText::length($this->uri); @@ -104,6 +109,14 @@ class Url return $this->notFound; } + public function pageNumber() + { + if(isset($this->parameters['page'])) { + return $this->parameters['page']; + } + return 0; + } + public function setNotFound($error = true) { $this->notFound = $error; diff --git a/themes/pure/php/head.php b/themes/pure/php/head.php index 2ea50f8d..8b975df8 100644 --- a/themes/pure/php/head.php +++ b/themes/pure/php/head.php @@ -1,19 +1,36 @@ - - - - +Blog – Layout Examples – Pure + Theme::viewport(); - - + // Site title + Theme::title( $Site->title() ); - - - - + // + Theme::description( $Site->description() ); - + // + // + // + // + Theme::css(array( + 'pure-min.css', + 'grids-responsive-min.css', + 'blog.css', + 'rainbow.github.css' + )); + + Theme::css(array( + 'http://fonts.googleapis.com/css?family=Open+Sans:400,300,600&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,cyrillic,latin-ext', + 'http://fonts.googleapis.com/css?family=Muli:400,300' + ), ''); + + // + Theme::javascript(array( + 'rainbow.min.js' + )); + +?>