Skip to content

Commit

Permalink
added check for existing category when using 'INT name'
Browse files Browse the repository at this point in the history
  • Loading branch information
pe7er committed Dec 9, 2015
1 parent 67230ad commit c438663
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
26 changes: 26 additions & 0 deletions administrator/components/com_categories/helpers/categories.php
Expand Up @@ -138,6 +138,32 @@ public static function getAssociations($pk, $extension = 'com_content')
return $associations;
}

/**
* Check if Category ID exists otherwise assign to ROOT category.
*
* @param mixed $catid Name or ID of category.
* @param string $extension Extension that triggers this function
*
* @return int $catid Category ID.
*/
public static function validateCategoryId($catid, $extension)
{
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables');

$categoryTable = JTable::getInstance('Category');

$data = array();
$data['id'] = $catid;
$data['extension'] = $extension;

if (!$categoryTable->load($data))
{
$catid = 0;
}

return (int) $catid;
}

/**
* Create new Category from within item view.
*
Expand Down
15 changes: 12 additions & 3 deletions administrator/components/com_content/models/article.php
Expand Up @@ -487,11 +487,20 @@ public function save($data)
$data['images'] = (string) $registry;
}

// Save New Category
if ((int) $data['catid'] == 0)
require_once JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php';

// Cast catid to integer for comparison
$catid = (int) $data['catid'];

// Check if New Category exists
if ($catid > 0)
{
require_once JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php';
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content');
}

// Save New Category
if ($catid == 0)
{
$category = array();
$category['title'] = $data['catid'];
$category['parent_id'] = 1;
Expand Down
2 changes: 1 addition & 1 deletion administrator/language/en-GB/en-GB.ini
Expand Up @@ -187,7 +187,7 @@ JFIELD_BASIS_LOGOUT_DESCRIPTION_DESC="Text for logout page."
JFIELD_BASIS_LOGOUT_DESCRIPTION_LABEL="Logout Description Text"
JFIELD_BASIS_LOGOUT_DESCRIPTION_SHOW_DESC="Show or hide logout description."
JFIELD_BASIS_LOGOUT_DESCRIPTION_SHOW_LABEL="Logout Text"
JFIELD_CATEGORY_DESC="The category that this item is assigned to. You may select an existing category or enter your own category by typing the name in the field and pressing enter."
JFIELD_CATEGORY_DESC="The category that this item is assigned to. You may select an existing category or enter a NEW category by typing the name in the field and pressing enter."
JFIELD_ENABLED_DESC="The enabled status of this item."
JFIELD_KEY_REFERENCE_DESC="Used to store information referring to an external resource."
JFIELD_KEY_REFERENCE_LABEL="Key Reference"
Expand Down
2 changes: 1 addition & 1 deletion language/en-GB/en-GB.ini
Expand Up @@ -147,8 +147,8 @@ JFIELD_ORDERING_LABEL="Ordering"
JFIELD_PUBLISHED_DESC="Set publication status."
JFIELD_TITLE_DESC="Title for the article."

JGLOBAL_ARTICLES="Articles"
JGLOBAL_ADD_CUSTOM_CATEGORY="Add new Category"
JGLOBAL_ARTICLES="Articles"
JGLOBAL_AUTH_ACCESS_DENIED="Access Denied"
JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted"
JGLOBAL_AUTH_BIND_FAILED="Failed binding to LDAP server"
Expand Down

0 comments on commit c438663

Please sign in to comment.