/** * Method to store the individual data * * @access public * @return boolean True on success * @since 1.5 */ function store($data, $picture, $picture_small) { // Require the base controller require_once JPATH_COMPONENT_ADMINISTRATOR . '/' . 'tables' . '/' . 'individual.php'; $table = $this->getTable('individual'); $params = JComponentHelper::getParams('com_tracks'); $user = JFactory::getUser(); $username = $user->get('username'); if ($data['id']) { $table->load($data['id']); if ($table->user_id != $user->get('id') && !$user->authorise('core.manage', 'com_tracks')) { JError::raiseError(403, JText::_('COM_TRACKS_ACCESS_NOT_ALLOWED')); } } // Bind the form fields to the user table if (!$table->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } $targetpath = 'images' . '/' . $params->get('default_individual_images_folder', 'tracks/individuals'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); if (!empty($picture['name'])) { $base_Dir = JPATH_SITE . '/' . $targetpath . '/'; if (!JFolder::exists($base_Dir)) { JFolder::create($base_Dir); } //check the image $check = ImageSelect::check($picture); if ($check === false) { $this->setError('IMAGE CHECK FAILED'); return false; } //sanitize the image filename $filename = ImageSelect::sanitize($base_Dir, $picture['name']); $filepath = $base_Dir . $filename; //dump($filepath); if (!JFile::upload($picture['tmp_name'], $filepath)) { $this->setError(JText::_('COM_TRACKS_UPLOAD_FAILED')); return false; } else { $table->picture = $targetpath . '/' . $filename; } } else { //keep image if edited and left blank unset($table->picture); } //end image upload if if (!empty($picture_small['name'])) { jimport('joomla.filesystem.file'); $base_Dir = JPATH_SITE . '/' . $targetpath . '/' . 'small' . '/'; if (!JFolder::exists($base_Dir)) { JFolder::create($base_Dir); } //check the image $check = ImageSelect::check($picture_small); if ($check === false) { $this->setError('IMAGE CHECK FAILED'); return false; } //sanitize the image filename $filename = ImageSelect::sanitize($base_Dir, $picture_small['name']); $filepath = $base_Dir . $filename; if (!JFile::upload($picture_small['tmp_name'], $filepath)) { $this->setError(JText::_('COM_TRACKS_UPLOAD_FAILED')); return false; } else { $table->picture_small = $targetpath . '/' . 'small' . '/' . $filename; } } else { //keep image if edited and left blank unset($table->picture_small); } //end image upload if // Store the individual to the database if (!$table->save($data)) { $this->setError($user->getError()); return false; } $this->id = $table->id; return $this->id; }
/** * logic to mass delete images * * @access public * @return void * @since 0.9 */ function delete() { $mainframe = JFactory::getApplication(); $option = JRequest::getCmd('option'); // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); // Get some data from the request $images = JRequest::getVar('rm', array(), '', 'array'); $type = JRequest::getVar('type'); $folder = ImageSelect::getfolder($type); if (count($images)) { foreach ($images as $image) { if ($image !== JFilterInput::clean($image, 'path')) { JError::raiseWarning(100, JText::_('COM_TRACKS_UNABLE_TO_DELETE') . ' ' . htmlspecialchars($image, ENT_COMPAT, 'UTF-8')); continue; } $fullPath = JPath::clean(JPATH_SITE . '/' . 'media' . '/' . 'com_tracks' . '/' . 'images' . '/' . $folder . '/' . $image); $fullPaththumb = JPath::clean(JPATH_SITE . '/' . 'media' . '/' . 'com_tracks' . '/' . 'images' . '/' . $folder . '/' . 'small' . '/' . $image); if (is_file($fullPath)) { JFile::delete($fullPath); if (JFile::exists($fullPaththumb)) { JFile::delete($fullPaththumb); } } } } $mainframe->redirect('index.php?option=com_tracks&view=imagehandler&type=' . $type . '&tmpl=component'); }