diff --git a/bl-kernel/abstract/dblist.class.php b/bl-kernel/abstract/dblist.class.php index 75a9156d..a1b2ae1f 100644 --- a/bl-kernel/abstract/dblist.class.php +++ b/bl-kernel/abstract/dblist.class.php @@ -62,18 +62,27 @@ class dbList extends dbJSON public function generateKey($name) { - return Text::cleanUrl($name); + $key = Text::cleanUrl($name); + if (empty($key)) { + return false; + } + return $key; } public function add($name) { $key = $this->generateKey($name); - if( isset($this->db[$key]) ) { + if ($key===false) { + Log::set(__METHOD__.LOG_SEP.'Error when try to generate the key'); + return false; + } + + if (isset($this->db[$key])) { Log::set(__METHOD__.LOG_SEP.'Error key already exist: '.$key); return false; } - $this->db[$key]['name'] = $name; + $this->db[$key]['name'] = Sanitize::html($name); $this->db[$key]['list'] = array(); $this->sortAlphanumeric(); @@ -97,10 +106,10 @@ class dbList extends dbJSON { $newKey = $this->generateKey($newName); - $this->db[$newKey]['name'] = $newName; + $this->db[$newKey]['name'] = Sanitize::html($newName); $this->db[$newKey]['list'] = $this->db[$oldKey]['list']; - // Remove the old category + // Remove the old key if( $oldKey != $newKey ) { unset( $this->db[$oldKey] ); } diff --git a/bl-kernel/admin/controllers/new-category.php b/bl-kernel/admin/controllers/new-category.php index 52e50abf..b752efb5 100644 --- a/bl-kernel/admin/controllers/new-category.php +++ b/bl-kernel/admin/controllers/new-category.php @@ -13,36 +13,6 @@ if ($Login->role()!=='admin') { // Functions // ============================================================================ -function add($category) -{ - global $dbCategories; - global $Language; - global $Syslog; - - if( Text::isEmpty($category) ) { - Alert::set($Language->g('Category name is empty'), ALERT_STATUS_FAIL); - return false; - } - - if( $dbCategories->add($category) ) { - // Add to syslog - $Syslog->add(array( - 'dictionaryKey'=>'new-category-created', - 'notes'=>$category - )); - - // Create an alert - Alert::set($Language->g('Category added'), ALERT_STATUS_OK); - - // Redirect - Redirect::page('categories'); - } - else { - Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the category.'); - return false; - } -} - // ============================================================================ // Main before POST // ============================================================================ @@ -51,9 +21,9 @@ function add($category) // POST Method // ============================================================================ -if( $_SERVER['REQUEST_METHOD'] == 'POST' ) -{ - add($_POST['category']); +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + createCategory($_POST['category']); + Redirect::page('categories'); } // ============================================================================ diff --git a/bl-kernel/admin/themes/default/init.php b/bl-kernel/admin/themes/default/init.php index 0717b889..cdc2ce1b 100644 --- a/bl-kernel/admin/themes/default/init.php +++ b/bl-kernel/admin/themes/default/init.php @@ -2,6 +2,36 @@ class HTML { + // Returns HTML and Javascript code for the box TAGs when you create/edit content + public static function tags($args) { + global $L; + + // Javascript + $javascript = ''; + + // HTML + $html = '
'; + $html .= ' '; + $html .= ' '; + + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + + foreach ($args['allTags'] as $tag) { + $html .= ' '.$tag.''; + } + + $html .= '
'; + $html .= '
'; + $html .= '
'; + + echo $html.$javascript; + } + public static function title($args) { $id = empty($args['id']) ? '' : 'id="'.$args['id'].'"'; @@ -96,34 +126,7 @@ class HTML { echo $html; } - public static function tags($args) - { - global $L; - // Javascript code - include(PATH_JS.'bludit-tags.js'); - $html = '
'; - - $html .= ''; - - $html .= ''; - - $html .= '
'; - $html .= ''; - $html .= ''; - - $html .= '
'; - - foreach($args['allTags'] as $tag) { - $html .= ''.$tag.''; - } - - $html .= '
'; - $html .= '
'; - $html .= '
'; - - echo $html; - } public static function formInputPassword($args) { diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 886bc153..2e05710b 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -634,6 +634,34 @@ function editSettings($args) { return false; } +// Add a new category to the system +// Returns TRUE is success added, FALSE otherwise +function createCategory($category) { + global $dbCategories; + global $Language; + global $Syslog; + + if (Text::isEmpty($category)) { + // Set an alert + Alert::set($Language->g('Category name is empty'), ALERT_STATUS_FAIL); + return false; + } + + if ($dbCategories->add($category)) { + // Add to syslog + $Syslog->add(array( + 'dictionaryKey'=>'new-category-created', + 'notes'=>$category + )); + + // Set an alert + Alert::set($Language->g('Category added'), ALERT_STATUS_OK); + return true; + } + + return false; +} + function editCategory($oldCategoryKey, $newCategory) { global $Language; global $dbPages; diff --git a/bl-kernel/helpers/sanitize.class.php b/bl-kernel/helpers/sanitize.class.php index b5482f38..485ae135 100644 --- a/bl-kernel/helpers/sanitize.class.php +++ b/bl-kernel/helpers/sanitize.class.php @@ -81,4 +81,4 @@ class Sanitize { return 0; } -} +} \ No newline at end of file diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php index 58f0e36d..d6a92895 100644 --- a/bl-kernel/helpers/text.class.php +++ b/bl-kernel/helpers/text.class.php @@ -123,6 +123,9 @@ class Text { return str_replace(array_keys($replace), array_values($replace), $text); } + // Convert invalid characters to valid characters for a URL + // Characters that cannot be converted will be removed from the string + // This function can return an empty string public static function cleanUrl($string, $separator='-') { if (EXTREME_FRIENDLY_URL) { diff --git a/bl-kernel/js/bludit-tags.js b/bl-kernel/js/bludit-tags.js index 0292947d..b5e0a0d9 100644 --- a/bl-kernel/js/bludit-tags.js +++ b/bl-kernel/js/bludit-tags.js @@ -1,73 +1,65 @@ - \ No newline at end of file +}); \ No newline at end of file diff --git a/bl-kernel/js/functions.php b/bl-kernel/js/functions.php index e2d35257..fc5609e5 100644 --- a/bl-kernel/js/functions.php +++ b/bl-kernel/js/functions.php @@ -53,4 +53,16 @@ function generateSlug(text, parentKey, currentKey, writeResponse) { }); } +function sanitizeHTML(text) { + var map = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + return text.replace(/[&<>"']/g, function(m) { return map[m]; }); +} + \ No newline at end of file