function dgUpload() { $app = JFactory::getApplication('administrator'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); require JPATH_COMPONENT . DS . 'config.datsogallery.php'; require_once JPATH_COMPONENT . DS . 'class.datsogallery.php'; require_once JPATH_COMPONENT . DS . 'images.datsogallery.php'; $db = JFactory::getDBO(); $user = JFactory::getUser(); $catid = JRequest::getVar('catid', 0, 'post', 'int'); jimport('joomla.access.access'); $tmp_dir = JPATH_SITE . DS . 'tmp' . DS . $user->id; dgChmod($tmp_dir, 0777); $dir = opendir($tmp_dir); while (false != ($file = readdir($dir))) { $files[] = $file; } sort($files); $i = 0; foreach ($files as $file) { if ($file != '.' && $file != '..' && strcasecmp($file, 'index.html') != 0 && strcasecmp($file, '__MACOSX') != 0) { $i++; $count = $i > 1 ? ' ' . $i : ''; $origfilename = $file; $imagetype = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); $imginfo = getimagesize($tmp_dir . DS . $origfilename); $ext = strtolower($imagetype[$imginfo[2]]); if (is_dir($tmp_dir . DS . $origfilename)) { JFolder::delete($tmp_dir); $msg = JText::sprintf('COM_DATSOGALLERY_ZIP_PACKAGE_ERROR', '<a href="http://www.datso.fr/en/video-guidelines.html" target="_blank">', '</a>'); $app->redirect('index.php?option=com_datsogallery&task=pictures', $msg); } if (!$ext) { JFile::delete($tmp_dir . DS . $origfilename); } else { $newfilename = $ad_fname ? $origfilename : dgImgId($catid, $ext); JFile::copy($tmp_dir . DS . $origfilename, JPath::clean(JPATH_SITE . $ad_pathoriginals . DS . $newfilename)); JFile::delete($tmp_dir . DS . $origfilename); $row = new DatsoImages($db); if (!$row->bind(JRequest::get('post'))) { return JError::raiseWarning(500, $row->getError()); } $row->ordering = $row->getNextOrder('catid = ' . (int) $catid); $row->imgtitle = JRequest::getVar('gentitle') . $count; $row->imgtext = JRequest::getVar('gendesc'); $row->imgauthor = JRequest::getVar('genimgauthor'); $row->imgauthorurl = JRequest::getVar('genimgauthorurl'); $row->imgdate = mktime(); $row->owner_id = $user->id; $row->published = 1; $row->approved = 1; $row->imgoriginalname = $newfilename; $row->useruploaded = 0; if (!$row->store()) { JError::raiseError(500, $row->getError()); } } } } closedir($dir); if (JFolder::exists($tmp_dir)) { JFolder::delete($tmp_dir); } $app->redirect("index.php?option=com_datsogallery&task=pictures"); }
function batchUpload() { $app = JFactory::getApplication('site'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); require JPATH_COMPONENT_ADMINISTRATOR . DS . 'config.datsogallery.php'; require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'class.datsogallery.php'; require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'images.datsogallery.php'; $db = JFactory::getDBO(); $user = JFactory::getUser(); $userGroups = JAccess::getGroupsByUser($user->id, true); $is_admin = array(7, 8); $catid = JRequest::getVar('catid', 0, 'post', 'int'); $menu = JSite::getMenu(); $ids = $menu->getItems('link', 'index.php?option=com_datsogallery&view=datsogallery'); $itemid = isset($ids[0]) ? '&Itemid=' . $ids[0]->id : ''; $tmp_dir = JPATH_SITE . DS . 'tmp' . DS . $user->id; dgChmod($tmp_dir, 0777); $dir = opendir($tmp_dir); while (false !== ($file = readdir($dir))) { $files[] = $file; } sort($files); $i = 0; foreach ($files as $file) { if ($file != '.' && $file != '..' && strcasecmp($file, 'index.html') != 0 && strcasecmp($file, 'Thumbs.db') != 0) { $i++; $count = $i > 1 ? ' ' . $i : ''; $origfilename = $file; $imagetype = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); $imginfo = getimagesize($tmp_dir . DS . $origfilename); $ext = strtolower($imagetype[$imginfo[2]]); if (is_dir($tmp_dir . DS . $origfilename)) { JFolder::delete($tmp_dir); $msg = JText::_('COM_DATSOGALLERY_ZIP_PACKAGE_ERROR'); $app->redirect(JRoute::_('index.php?option=com_datsogallery&task=userpanel' . $itemid, false), $msg, 'error'); } if (!$ext) { JFile::delete($tmp_dir . DS . $origfilename); } else { $newfilename = $ad_fname ? $origfilename : dgImgId($catid, $ext); JFile::copy($tmp_dir . DS . $origfilename, JPath::clean(JPATH_SITE . $ad_pathoriginals . DS . $newfilename)); JFile::delete($tmp_dir . DS . $origfilename); $row = new DatsoImages($db); if (!$row->bind(JRequest::get('post'))) { return JError::raiseWarning(500, $row->getError()); } $row->ordering = $row->getNextOrder('catid = ' . $catid); $row->imgtitle = JRequest::getVar('gentitle') . $count; $row->imgtext = JRequest::getVar('gendesc'); $row->imgauthor = JRequest::getVar('genimgauthor'); $row->imgauthorurl = JRequest::getVar('genimgauthorurl'); $row->imgdate = mktime(); $row->owner_id = $user->id; $row->published = 1; $row->approved = $ad_approve && !array_intersect($is_admin, $userGroups) ? 0 : 1; $row->imgoriginalname = $newfilename; $row->useruploaded = array_intersect($is_admin, $userGroups) ? 0 : 1; if (!$row->store()) { JError::raiseError(500, $row->getError()); } else { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_messages' . DS . 'tables' . DS . 'message.php'; $lang = JFactory::getLanguage(); $lang->load('com_messages'); $query = 'SELECT id FROM #__users WHERE sendEmail = 1'; $db->setQuery($query); $users = $db->loadResultArray(); foreach ($users as $user_id) { $msg = new MessagesTableMessage($db); $msg->publish($user->id, $user_id, JText::_('COM_DATSOGALLERY_NEW_PIC_SUBMITED'), sprintf(JText::_('COM_DATSOGALLERY_NEW_CONTENT_SUBMITED') . "%s " . JText::_('COM_DATSOGALLERY_TITLED') . " %s.", $user->username, $row->imgtitle)); } } } } } closedir($dir); if (JFolder::exists($tmp_dir)) { JFolder::delete($tmp_dir); } $db->setQuery('SELECT u.username, c.name AS category' . ' FROM #__users AS u,' . ' #__datsogallery_catg AS c' . ' WHERE u.id = ' . $user->id . ' AND c.cid = ' . $catid); $row = $db->loadObject(); if ($ad_upload_notify) { uploadNotify($row->username, $row->category); } $app->redirect(JRoute::_('index.php?option=com_datsogallery&task=userpanel' . $itemid, false), JText::_('COM_DATSOGALLERY_UPLOAD_SUCCESS')); }