From 03596be790e2183a44a42023e3a4e425b63b9dbe Mon Sep 17 00:00:00 2001 From: lBrieu Date: Thu, 11 Aug 2011 12:35:47 +0000 Subject: [PATCH] [+] Add the TinyMCE editor on categories description git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8024 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Category.php | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/classes/Category.php b/classes/Category.php index 27aa1efc0..be15d7bd4 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -87,7 +87,7 @@ class CategoryCore extends ObjectModel protected $fieldsValidate = array('nleft' => 'isUnsignedInt', 'nright' => 'isUnsignedInt', 'level_depth' => 'isUnsignedInt', 'active' => 'isBool', 'id_parent' => 'isUnsignedInt', 'groupBox' => 'isArrayWithIds'); protected $fieldsRequiredLang = array('name', 'link_rewrite'); protected $fieldsSizeLang = array('name' => 64, 'link_rewrite' => 64, 'meta_title' => 128, 'meta_description' => 255, 'meta_keywords' => 255); - protected $fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isCleanHtml', + protected $fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isString', 'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName'); protected $table = 'category'; @@ -132,6 +132,16 @@ class CategoryCore extends ObjectModel $fields['date_upd'] = pSQL($this->date_upd); return $fields; } + + /** + * Allows to display the category description without HTML tags and slashes + * + * @return string + */ + public static function getDescriptionClean($description) + { + return strip_tags(stripslashes($description)); + } /** * Check then return multilingual fields for database interaction @@ -140,8 +150,36 @@ class CategoryCore extends ObjectModel */ public function getTranslationsFieldsChild() { - parent::validateFieldsLang(); - return parent::getTranslationsFields(array('name', 'description', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description')); + self::validateFieldsLang(); + + $fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description'); + $fields = array(); + $languages = Language::getLanguages(false); + $defaultLanguage = Configuration::get('PS_LANG_DEFAULT'); + foreach ($languages as $language) + { + $fields[$language['id_lang']]['id_lang'] = $language['id_lang']; + $fields[$language['id_lang']][$this->identifier] = (int)($this->id); + $fields[$language['id_lang']]['id_shop'] = (int)$this->id_shop; // @todo ID shop in product ??? + $fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? addslashes($this->description[$language['id_lang']]) : ''; + foreach ($fieldsArray as $field) + { + if (!Validate::isTableOrIdentifier($field)) + die(Tools::displayError()); + + /* Check fields validity */ + if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']])) + $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]); + elseif (in_array($field, $this->fieldsRequiredLang)) + { + if ($this->{$field} != '') + $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]); + } + else + $fields[$language['id_lang']][$field] = ''; + } + } + return $fields; } public function add($autodate = true, $nullValues = false) @@ -223,7 +261,7 @@ class CategoryCore extends ObjectModel 'id' => (int)$this->id_category, 'link' => Context::getContext()->link->getCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, - 'desc'=> $this->description, + 'desc'=> Category::getDescriptionClean($this->description), 'children' => $children ); }