/** * save a edited category * * @param int $cid id of category */ function Joom_SaveEditCategory(&$cid) { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('administrator'); $database =& JFactory::getDBO(); jimport('joomla.filesystem.folder'); $row = new mosCatgs($database); //read category from DB $row->load($cid); //read old parent assignment $parentold = $row->parent; //read old title $catnameold = $row->name; //get new values if (!$row->bind($_POST)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (get_magic_quotes_gpc()) { $row->name = stripslashes($row->name); $row->description = stripslashes($row->description); } if (intval($row->owner) == 0) { $row->owner = null; } //make the new category title safe if ($catnameold != $row->name) { JFilterOutput::objectHTMLSafe($row->name); $catname = $row->name; $catnamemodif = true; } else { $catname = $catnameold; $catnamemodif = false; } //move the category folder, if parent assignment or category name changed if ($parentold != $row->parent || $catnamemodif == true) { //save old path $catpathold = $row->catpath; $parentpathnew = Joom_GetCatPath($row->parent); //Joom_FixFilename() convert/remove special chars except the underscore //affects only catpath $catname = Joom_FixFilename($catname); $catpathnew = $parentpathnew . $catname . '_' . $row->cid; $cat_originalpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathold); $cat_picturepathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpathold); $cat_thumbnailpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathold); $cat_originalpathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathnew); $cat_picturepathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpathnew); $cat_thumbnailpathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathnew); //move folders //actualize catpath in DB $row->catpath = $catpathnew; //TODO error messages JFolder::move($cat_originalpathold, $cat_originalpathnew); JFolder::move($cat_picturepathold, $cat_picturepathnew); JFolder::move($cat_thumbnailpathold, $cat_thumbnailpathnew); //if parent category changes, modify catpath of all subcategories in DB $rowid = $row->cid; Joom_UpdateNewCatpath($rowid, $catpathold, $catpathnew); } if (!$row->store(true)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } // redirect to category manager //TODO aha: message $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=categories'); }
/** * Update of category path in DB for subcategories if a parent category has * been moved or the name changed * recursive call to each count of depth * * @param integer $catids_values: ID(s) of the modifie category * @param string $oldpath: former rel. category path * @param string $newpath: actual rel. category path * */ function Joom_UpdateNewCatpath($catids_values, &$oldpath, &$newpath) { $database =& JFactory::getDBO(); //query for subcategories with parent in $catids_values $database->setQuery("SELECT cid\n FROM #__joomgallery_catg\n WHERE parent in ({$catids_values}) "); $subcatids = $database->loadResultArray(); if ($database->getErrorNum()) { echo $database->stderr(true); } // nothing found, return if (count($subcatids) == 0) { return; } $row = new mosCatgs($database); foreach ($subcatids as $subcatid) { $row->load($subcatid); $catpath = $row->catpath; //replace former category path with actual one $catpath = str_replace($oldpath . '/', $newpath . '/', $catpath); //and save it $row->catpath = $catpath; if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } } //split the array in comme seperated string $catids_values = implode(",", $subcatids); //call again with subcategories as parent Joom_UpdateNewCatpath($catids_values, $oldpath, $newpath); }
/** * saves a changed or a new category * * @param integer $cid, if null -> new category */ function Joom_User_SaveUserCat(&$cid) { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('site'); $database =& JFactory::getDBO(); $user =& JFactory::getUser(); jimport('joomla.filesystem.file'); $row = new mosCatgs($database); if ($cid == 0) { $database->setQuery(" SELECT \n COUNT(cid)\n FROM \n #__joomgallery_catg\n WHERE \n owner=" . $user->get('id') . " \n "); $countcat = $database->loadResult(); if ($countcat >= $config->jg_maxusercat) { $mainframe->redirect('index.php?option=com_joomgallery&func=showusercats' . _JOOM_ITEMID, false); } $newcat = true; } else { $newcat = false; //load an existing category $row->load($cid); //get old parent category $parentold = $row->parent; //get old category name $catnameold = $row->name; } //get new values if (!$row->bind($_POST)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (get_magic_quotes_gpc()) { $row->name = stripslashes($row->name); $row->description = stripslashes($row->description); } if (!$newcat) { if ($catnameold != $row->name) { // Macht den neuen Kategorienamen sicher, wenn geaendert JFilterOutput::objectHTMLSafe($row->name); // Joom_FixCatname; Umlaute werden umgewandelt und alle Sonderzeichen bis auf // den Unterstrich entfernt, gilt nur fuer den catpath $catname = Joom_FixCatname($row->name); $catnamemodif = true; } else { $catname = $catnameold; $catnamemodif = false; } //Kategorieordner verschieben, wenn die Parentzuordnung oder der Kategoriename //geaendert wurde if ($parentold != $row->parent || $catnamemodif == true) { //alten Pfad sichern $catpathold = $row->catpath; //Kategoriepfad der Parent-Kategorie lesen, nur noetig wenn parent != 0 if ($row->parent != 0) { $row_parent = new mosCatgs($database); $row_parent->load($row->parent); $catpathnew = $row_parent->catpath . '/' . $catname . '_' . $row->cid; } else { $catpathnew = $catname . '_' . $row->cid; } //Kategoriepfad in DB aktualisieren $row->catpath = $catpathnew; $cat_originalpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathold); $cat_picturepathold = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpathold); $cat_thumbnailpathold = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathold); $cat_originalpathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathnew); $cat_picturepathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpathnew); $cat_thumbnailpathnew = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathnew); //Ordner verschieben //TODO Fehlermeldungen JFolder::move($cat_originalpathold, $cat_originalpathnew); JFolder::move($cat_picturepathold, $cat_picturepathnew); JFolder::move($cat_thumbnailpathold, $cat_thumbnailpathnew); //wenn Parentkategorie geaendert wurde, den Catpath aller Unterkategorien //in DB anpassen $rowid = $row->cid; Joom_UpdateNewCatpath($rowid, $catpathold, $catpathnew); } if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } } else { //Neue Kategorie //Kategorienamen absichern JFilterOutput::objectHTMLSafe($row->name); // Joom_FixCatname; Umlaute werden umgewandelt und alle Sonderzeichen bis auf // den Unterstrich entfernt, gilt nur fuer den catpath $catname = Joom_FixCatname($row->name); $row->img_position = 0; $row->catimage = null; //access von der Elternkategorie erben, wenn nicht Admin/SuperAdmin if (!$this->adminlogged) { $row->owner = $user->get('id'); $rowparent = new mosCatgs($database); $rowparent->load($row->parent); $row->access = $rowparent->access; } else { $row->owner = null; } //Anlegen des DB Eintrages if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } //catpath mit vergebener cid aufbauen $parentpathnew = Joom_GetCatPath($row->parent); $catpathnew = $parentpathnew . $catname . '_' . $row->cid; $row->catpath = $catpathnew; $row->store(); //Kategorieverzeichnisse anlegen Joom_MakeDirectory(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpathnew); Joom_MakeDirectory(JPATH_ROOT . DS . $config->jg_pathimages . $catpathnew); Joom_MakeDirectory(JPATH_ROOT . DS . $config->jg_paththumbs . $catpathnew); } // Redirect zur Kategorieuebersicht $mainframe->redirect(JRoute::_('index.php?option=com_joomgallery&func=showusercats&uid=' . $user->get('id') . _JOOM_ITEMID, false)); }
/** * creates a new category out of the information of the given object * * @param object should hold all the information about the new category * @return int/boolean id of the created category on success, false otherwise */ function createCategory($obj) { $database =& JFactory::getDBO(); jimport('joomla.filesystem.file'); /*JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomgallery'.DS.'tables'); $row = & JTable::getInstance('joomgallerycategories', 'Table');*/ /* deprecated (use JTable instead as shown above): */ require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomgallery' . DS . 'joomgallery.class.php'; $row = new mosCatgs($database); $row->bind($obj); //store data in the database if (!$row->store()) { return false; } //now we have the id of the new category //and the catpath can be built $row->catpath = Joom_FixFilename($row->name) . '_' . $row->cid; if ($row->parent) { $row->catpath = Joom_GetCatPath($row->parent) . $row->catpath; } //so store again if (!$row->store()) { return false; } //create necessary folders and files $origpath = JPATH_ROOT . DS . $this->_jg_config->jg_pathoriginalimages . $row->catpath; $imgpath = JPATH_ROOT . DS . $this->_jg_config->jg_pathimages . $row->catpath; $thumbpath = JPATH_ROOT . DS . $this->_jg_config->jg_paththumbs . $row->catpath; $index = JPATH_SITE . DS . 'components' . DS . 'com_joomgallery' . DS . 'assets' . DS . 'index.html'; $result = array(); $result[] = JFolder::create($origpath); $result[] = JFile::copy($index, $origpath . DS . 'index.html'); $result[] = JFolder::create($imgpath); $result[] = JFile::copy($index, $imgpath . DS . 'index.html'); $result[] = JFolder::create($thumbpath); $result[] = JFile::copy($index, $thumbpath . DS . 'index.html'); if (in_array(false, $result)) { return false; } else { return $row->cid; } }