/** * 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'); }
/** * Single upload * The user choose single picture files and upload them * concurrent uploads can be modified in backend * @param Category ID */ function Upload_Singles($catid) { $config = Joom_getConfig(); $mainframe =& JFactory::getApplication('site'); $database =& JFactory::getDBO(); $user =& JFactory::getUser(); jimport('joomla.filesystem.file'); $debugoutput = ''; //no user logged in if (!$user->get('id')) { $mainframe->redirect(JRoute::_('index.php?option=com_joomgallery' . _JOOM_ITEMID, false), JText::_('JGS_YOU_ARE_NOT_LOGGED')); } $catpath = Joom_GetCatPath($catid); $debugoutput .= '<p />'; for ($i = 0; $i < $config->jg_maxuploadfields; $i++) { $screenshot = $this->arrscreenshot["tmp_name"][$i]; $screenshot_name = $this->arrscreenshot["name"][$i]; $screenshot_filesize = $this->arrscreenshot["size"][$i]; $ii = $i + 1; //Any picture entry at position? //(4=UPLOAD_ERR_NO_FILE constant since PHP 4.3.0) //if not continue with next entry if ($this->arrscreenshot['error'][$i] == 4) { continue; } //Check for path exploits, and replace spaces $screenshot_name = Joom_FixFilename($screenshot_name); // Get extension $tag = strtolower(JFile::getExt($screenshot_name)); if ($config->jg_useruploadnumber == 1) { $filecounter = $i + 1; $praefix = substr($screenshot_name, 0, strpos(strtolower($screenshot_name), $tag) - 1); $newfilename = $this->Upload_GenFilename($praefix, $tag, $filecounter); } else { $newfilename = $this->Upload_GenFilename($screenshot_name, $tag); } //Picture size must not exceed the setting in backend //except for Admin/SuperAdmin if ($screenshot_filesize > $config->jg_maxfilesize && !$this->adminlogged) { $debugoutput .= JText::_('JGS_ALERT_MAX_ALLOWED_FILESIZE') . " " . $config->jg_maxfilesize . " " . JText::_('JGS_ALERT_BYTES'); continue; } //Check for right format if ($tag == 'jpeg' || $tag == 'jpg' || $tag == 'jpe' || $tag == 'gif' || $tag == 'png') { $debugoutput .= '<hr />Position: ' . $ii . '<br />'; $debugoutput .= $ii . ". " . $screenshot_name . "<br />"; //if picture already exists if (file_exists(JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename))) { $debugoutput .= JText::_('JGS_ALERT_SAME_PICTURE_ALREADY_EXIST'); continue; } // We'll assume that this file is ok because with open_basedir, // we can move the file, but may not be able to access it until it's moved $returnval = JFile::upload($screenshot, JPATH_ROOT . DS . $config->jg_pathoriginalimages . DS . $catpath . $newfilename); if (!$returnval) { $debugoutput .= JText::_('JGS_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename . '<br />'; continue; } $debugoutput .= JText::_('JGS_UPLOAD_COMPLETE') . '...<br />'; if (!($img_info = getimagesize(JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename)))) { // getimagesize didn't find a valid image or this is // some sort of hacking attempt JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . DS . $catpath . $newfilename); jexit(); } //check the possible available memory for picture resizing //if not available echo error message and continue with next picture if ($this->Upload_CheckMemory($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . DS . $catpath . $newfilename, $tag) == false) { $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, null); continue; } // create thumb $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename, $config->jg_useforresizedirection, $config->jg_thumbwidth, $config->jg_thumbheight, $config->jg_thumbcreation, $config->jg_thumbquality); if (!$returnval) { $debugoutput .= JText::_('JGS_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename; $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, null); continue; } $debugoutput .= JText::_('JGS_THUMBNAIL_CREATED') . '...<br />'; //create detail picture if ($config->jg_resizetomaxwidth && ($config->jg_special_gif_upload == 0 || $this->create_special_gif != 1 || $tag != 'gif' && $tag != 'png')) { $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, false, $config->jg_maxwidth, false, $config->jg_thumbcreation, $config->jg_picturequality, true); if (!$returnval) { $debugoutput .= JText::_('JGS_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename; $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); continue; } $debugoutput .= JText::_('JGS_RESIZED_TO_MAXWIDTH') . '<br />'; } else { $returnval = JFile::copy($config->jg_pathoriginalimages . $catpath . $newfilename, $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT); if (!$returnval) { $debugoutput .= JText::_('JGS_PROBLEM_COPYING ') . $config->jg_pathimages . $catpath . $newfilename; $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); continue; } } if ($config->jg_delete_original_user == 1 || $config->jg_delete_original_user == 2 && $this->original_delete == 1) { if (JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename)) { $debugoutput .= JText::_('JGS_ORIGINAL_DELETED') . '<br />'; } else { $debugoutput .= JText::_('JGS_PROBLEM_DELETING_ORIGINAL') . ' - ' . JText::_('JGS_CHECK_PERMISSIONS'); $this->Upload_Rollback($debugoutput, null, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); continue; } } $ordering = $this->Upload_GetOrdering($config->jg_uploadorder, $catid); $row = new mosjoomgallery($database); if (!$row->bind($_POST, JText::_('JGS_APPROVED_OWNER_PUBLISHED'))) { $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; jexit(); } $row->imgdate = mktime(); $row->owner = $user->get('id'); $row->published = 1; //Upload from admin/superadmin are approved if ($config->jg_approve == 1 && !$this->adminlogged) { $row->approved = 0; } else { $row->approved = 1; } $row->imgfilename = $newfilename; $row->imgthumbname = $newfilename; $row->useruploaded = 1; $row->ordering = $ordering; //Wenn im Backend die Vergabe von lfd. Nummern eingestellt wurde //wird dem Bildtitel die lfd. Nummer (+1) hinzugefügt if ($config->jg_useruploadnumber) { $row->imgtitle = $row->imgtitle . '_' . $filecounter; } if (!$row->store()) { $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); $debugoutput .= $row->getError(); continue; } else { // E-Mail ueber ein neues Bild an die User, die global als User Email-Empfang // erlaubt haben TODO -> In Backend-Konfig einstellen bzw. deaktivieren /* TODO // portierung: /administrator/components/com_messages/tables/message.php anstatt administrator/components/com_messages/messages.class.php require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_messages'.DS.'tables'.DS.'message.php' ); $database->setQuery("SELECT id FROM #__users WHERE sendEmail='1'"); $users = $database->loadResultArray(); foreach ($users as $user_id) { $msg = new TableMessage($database); // portierung: TableMessage anstatt mosMessage $msg->send($user->get('id'), $user_id, JText::_('JGS_NEW_PICTURE_UPLOADED'), sprintf( JText::_('JGS_NEW_CONTENT_SUBMITTED') . " %s " . JText::_('JGS_TITLED') ." %s.", $user->get('username'), $row->imgtitle)); } */ $debugoutput .= JText::_('JGS_ALERT_PICTURE_SUCCESSFULLY_ADDED') . '<br />'; $debugoutput .= JText::_('JGS_NEW_FILENAME') . ': ' . $newfilename . '<br /><br />'; } } else { $debugoutput .= JText::_('JGS_ALERT_INVALID_IMAGE_TYPE'); continue; } } echo $debugoutput; ?> <p> <img src="<?php echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png'; ?> " class="pngfile jg_icon" alt="arrow" /> <a href="<?php echo JRoute::_('index.php?option=com_joomgallery&func=showupload' . _JOOM_ITEMID); ?> "> <?php echo JText::_('JGS_MORE_UPLOADS'); ?> </a> </p> <p> <img src="<?php echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png'; ?> " class="pngfile jg_icon" alt="arrow" /> <a href="<?php echo JRoute::_('index.php?option=com_joomgallery&func=userpanel' . _JOOM_ITEMID); ?> "> <?php echo JText::_('JGS_BACK_TO_USER_PANEL'); ?> </a> </p> <p> <img src="<?php echo _JOOM_LIVE_SITE . 'components/com_joomgallery/assets/images/arrow.png'; ?> " class="pngfile jg_icon" alt="arrow" /> <a href="<?php echo JRoute::_('index.php?option=com_joomgallery&startpage=1' . _JOOM_ITEMID); ?> "> <?php echo JText::_('JGS_BACK_TO_GALLERY'); ?> </a> </p> <?php }
/** * JAVA Applet upload * @param Kategorie id of destination category */ function Upload_AppletReceive_Backend($catid) { // If the applet checks for the serverProtocol, it issues a HEAD request // -> Simply return an empty doc. if ($_SERVER['REQUEST_METHOD'] == 'HEAD') { jexit(); } $config = Joom_getConfig(); $database =& JFactory::getDBO(); $user =& JFactory::getUser(); $debugoutput = ''; //The Applet recognize an error with the text 'JOOMGALLERYUPLOADERROR' //and shows them within an JS alert box //check common requirements //no catid if ($catid == 0) { jexit('JOOMGALLERYUPLOADERROR ' . JText::_('JGA_JUPLOAD_YOU_MUST_SELECT_CATEGORY')); } //non common title if (!$config->jg_useorigfilename && empty($this->gentitle)) { jexit('JOOMGALLERYUPLOADERROR ' . JText::_('JGA_JUPLOAD_PICTURE_MUST_HAVE_TITLE')); } //Category path $catpath = Joom_GetCatPath($catid); foreach ($_FILES as $file => $fileArray) { //If 'delete originals' chosen in backend and the picture //shall be uploaded resized this will be done locally in the applet //then only the detail picture will be uploaded //therefore adjust path of destination category if ($config->jg_delete_original && $config->jg_resizetomaxwidth) { $no_original = true; $picpath = $config->jg_pathimages; } else { $no_original = false; $picpath = $config->jg_pathoriginalimages; } $screenshot = $fileArray["tmp_name"]; $screenshot_name = $fileArray["name"]; $screenshot_name = Joom_FixFilename($screenshot_name); $tag = strtolower(JFile::getExt($screenshot_name)); //check the possible available memory for picture resizing //if not available echo error message and continue with next picture if ($this->Upload_CheckMemory($debugoutput, $screenshot, $tag) == false) { $this->debug = 1; continue; } //Create new filename //if generic filename setted in backend use them if ($config->jg_useorigfilename) { $screenshot_name = Joom_FixFilename($screenshot_name); $newfilename = $this->Upload_GenFilename($screenshot_name, $tag); } else { $screenshot_name = Joom_FixFilename($this->gentitle); $newfilename = $this->Upload_GenFilename($screenshot_name, $tag); } //Move uploaded picture in destination folder (original or details) if (strlen($screenshot) > 0 && $screenshot != 'none') { $returnval = JFile::upload($screenshot, JPATH_ROOT . DS . $picpath . $catpath . $newfilename); if (!$returnval) { $debugoutput .= JText::_('JGA_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $picpath . $catpath . $newfilename . '<br />'; $this->debug = 1; continue; } Joom_Chmod(JPath::clean(JPATH_ROOT . DS . $picpath . $catpath . $newfilename)); if (!$returnval) { $debugoutput .= JPath::clean(JPATH_ROOT . DS . $picpath . $catpath . $newfilename) . ': ' . JText::_('JGA_CHECK_PERMISSIONS'); $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, null, null); $this->debug = 1; continue; } //Create thumbnail $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename, $config->jg_useforresizedirection, $config->jg_thumbwidth, $config->jg_thumbheight, $config->jg_thumbcreation, $config->jg_thumbquality); if (!$returnval) { $debugoutput .= JText::_('JGA_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename; $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); $this->debug = 1; continue; } $debugoutput .= JText::_('JGA_THUMBNAIL_CREATED') . "\n"; //evtl. create detail picture //not if 'delete originals' and resize setted in backend //In this case the applet made the resize and upload the detail picture if (!$no_original) { if ($config->jg_resizetomaxwidth && ($this->create_special_gif != 1 || $tag != 'gif' && $tag != 'png')) { $returnval = Joom_ResizeImage($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, false, $config->jg_maxwidth, false, $config->jg_thumbcreation, $config->jg_picturequality, true); if (!$returnval) { $debugoutput .= JText::_('JGA_WRONG_FILENAME') . ': ' . JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename; continue; } $debugoutput .= JText::_('JGA_RESIZED_TO_MAXWIDTH') . "\n"; } else { $returnval = JFile::copy($picpath . $catpath . $newfilename, $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT); if (!$returnval) { $debugoutput .= JText::_('JGA_PROBLEM_COPYING ') . $config->jg_pathimages . $catpath . $newfilename; $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, null, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); $this->debug = 1; continue; } } $returnval = Joom_Chmod(JPath::clean(JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename)); if (!$returnval) { $debugoutput .= JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename . ' ' . JText::_('JGA_CHECK_PERMISSIONS'); $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); $this->debug = 1; continue; } } //Delete original picture only if setted in upload window //not if setted in backend if ($config->jg_delete_original == 2 && $this->original_delete == 1) { if (JFile::delete(JPATH_ROOT . DS . $config->jg_pathoriginalimages . $catpath . $newfilename)) { $debugoutput .= JText::_('JGA_ORIGINAL_DELETED'); } else { $debugoutput .= JText::_('JGA_PROBLEM_DELETING_ORIGINAL') . ': ' . JPath::clean(JPATH_ROOT . DS . $config->jg_pathoriginalimages) . ' ' . JText::_('JGA_CHECK_PERMISSIONS'); $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); $this->debug = 1; } } //new entry for ordering $ordering = $this->Upload_GetOrdering($config->jg_uploadorder, $catid); $batchtime = mktime(); if ($config->jg_useorigfilename) { $fileextensionlength = strlen($tag); $filenamelength = strlen($screenshot_name); $imgname = substr($screenshot_name, -$filenamelength, -$fileextensionlength - 1); } else { $imgname = $this->gentitle; } $query = "INSERT INTO #__joomgallery(id, catid, imgtitle, imgauthor,\n imgtext, imgdate, imgcounter, imgvotes,\n imgvotesum, published, imgfilename, imgthumbname,\n checked_out,owner,approved, ordering)\n VALUES\n (NULL, '{$catid}', '{$imgname}', '{$this->photocred}',\n '{$this->gendesc}', '{$batchtime}', '0', '0',\n '0', '1', '{$newfilename}', '{$newfilename}',\n '0', '" . $user->get('id') . "', 1, '{$ordering}')"; $database->setQuery($query); if (!$database->query()) { $debugoutput .= $database->getErrorMsg(); $this->Upload_Rollback($debugoutput, JPATH_ROOT . DS . $picpath . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_pathimages . $catpath . $newfilename, JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $newfilename); $this->debug = 1; } } else { $debugoutput .= JText::_('JGA_WRONG_FILENAME'); $this->debug = 1; } } if ($this->debug) { echo "\nJOOMGALLERYUPLOADERROR\n"; } else { echo "\nJOOMGALLERYUPLOADSUCCESS\n"; } echo $debugoutput; jexit(); }
/** * 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; } }