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"); }
header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'images.datsogallery.php'; $user = JFactory::getUser(); if (!$user->id) { jexit(); } $targetDir = JPATH_ROOT . DS . 'tmp' . DS . $user->id; if (!JFolder::exists(JPATH_ROOT . DS . 'tmp' . DS . $user->id)) { JFolder::create(JPATH_ROOT . DS . 'tmp' . DS . $user->id); } dgChmod($targetDir, 0777); //$finalDir = JPATH_ROOT.DS.'tmp'.DS.$user->id; $cleanupTargetDir = false; $maxFileAge = 60 * 60; @set_time_limit(5 * 60); $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; $fileName = preg_replace('/[^\\w\\._]+/', '', $fileName); if (!JFolder::exists($targetDir)) { JFolder::create($targetDir); } if (is_dir($targetDir) && ($dir = opendir($targetDir))) { while (($file = readdir($dir)) !== false) { $filePath = $targetDir . DS . $file; if (preg_match('/\\.tmp$/', $file) && filemtime($filePath) < time() - $maxFileAge) {
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')); }
function resize($original, $w, $h, $crop, $cropratio = 0, $wm = 0, $catid = '') { require dirname(__FILE__) . DS . 'config.datsogallery.php'; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $cro = str_replace(':', 'x', $cropratio); $dirname = "datsogallery_catid-{$catid}_{$w}x{$h}_{$cro}"; $types = array(1 => 'gif', 'jpeg', 'png'); if (!JFolder::exists(JPATH_SITE . DS . 'cache' . DS . $dirname)) { JFolder::create(JPATH_SITE . DS . 'cache' . DS . $dirname); $content = '<html><body bgcolor="#ffffff"></body></html>'; JFile::write(JPATH_SITE . DS . 'cache' . DS . $dirname . DS . 'index.html', $content); } if (!JFile::exists(JPATH_SITE . $ad_pathoriginals . DS . 'blank.jpg')) { JFile::copy(JPATH_COMPONENT_SITE . DS . 'images' . DS . 'blank.jpg', JPATH_SITE . $ad_pathoriginals . DS . 'blank.jpg'); } $path = JPath::clean(JPATH_SITE . $ad_pathoriginals . DS . $original); dgFileCheck($path); if (!file_exists($path) || is_dir($path) || !($size = getimagesize($path))) { return; } $width = $size[0]; $height = $size[1]; $mw = $w; $mh = $h; $x = 0; $y = 0; if ($crop == '1') { $cr = explode(':', $cropratio); if (count($cr) == 2) { $rc = $width / $height; $crc = (double) $cr[0] / (double) $cr[1]; if ($rc < $crc) { $oh = $height; $height = $width / $crc; $y = ($oh - $height) / 2; } else { if ($rc > $crc) { $ow = $width; $width = $height * $crc; $x = ($ow - $width) / 2; } } } } $xr = $mw / $width; $yr = $mh / $height; if ($xr * $height < $mh) { $th = ceil($xr * $height); $tw = $mw; } else { $tw = ceil($yr * $width); $th = $mh; } $relfile = JURI::root(true) . '/cache/' . $dirname . '/' . basename($original); $cachefile = JPATH_SITE . DS . 'cache' . DS . $dirname . DS . basename($original); if (file_exists($cachefile)) { $cachesize = getimagesize($cachefile); $cached = $cachesize[0] == $tw && $cachesize[1] == $th; if (filemtime($cachefile) < filemtime($path)) { $cached = false; } } else { $cached = false; } if (!$cached && ($size[0] >= $w || $size[1] >= $h)) { $resize = $size[0] >= $w || $size[1] >= $h; } elseif (!$cached && ($size[0] <= $w || $size[1] <= $h)) { $resize = true; } else { $resize = false; } if ($resize) { @increasememory($original); $image = call_user_func('imagecreatefrom' . $types[$size[2]], $path); $temp = $size[0] <= $w || $size[1] <= $h ? imagecreatetruecolor($width, $height) : imagecreatetruecolor($tw, $th); if (function_exists('imagecreatetruecolor') && $temp) { if (in_array($types[$size[2]], array('gif', 'png'))) { $color = 'F5F5F5'; $background = imagecolorallocate($temp, hexdec($color[0] . $color[1]), hexdec($color[2] . $color[3]), hexdec($color[4] . $color[5])); imagefillalpha($temp, $background); } if ($resize && ($size[0] <= $w || $size[1] <= $h)) { if (in_array($types[$size[2]], array('gif', 'png'))) { imagecopyresampled($temp, $image, 0, 0, 0, 0, $size[0], $size[1], $width, $height); } else { fastimagecopyresampled($temp, $image, 0, 0, 0, 0, $size[0], $size[1], $width, $height); } } else { if (in_array($types[$size[2]], array('gif', 'png'))) { imagecopyresampled($temp, $image, 0, 0, $x, $y, $tw, $th, $width, $height); } else { fastimagecopyresampled($temp, $image, 0, 0, $x, $y, $tw, $th, $width, $height); } } imagedestroy($image); $sharpness = findsharp($width, $tw); $sharpenMatrix = array(array(-1, -2, -1), array(-2, $sharpness + 12, -2), array(-1, -2, -1)); $divisor = $sharpness; $offset = 0; imageconvolution($temp, $sharpenMatrix, $divisor, $offset); if ($wm) { $watermarkPNGFile = JPATH_SITE . DS . 'components' . DS . 'com_datsogallery' . DS . 'images' . DS . 'watermark.png'; $watermarkMargin = 5; $watermark = imagecreatefrompng($watermarkPNGFile); $watermarkWidth = imagesx($watermark); $watermarkHeight = imagesy($watermark); $imageWidth = imagesx($temp); $imageHeight = imagesy($temp); switch ($ad_wmpos) { case 'topleft': $placeWatermarkX = $watermarkMargin; $placeWatermarkY = $watermarkMargin; break; case 'topright': $placeWatermarkX = $imageWidth - $watermarkWidth - $watermarkMargin; $placeWatermarkY = $watermarkMargin; break; case 'bottomleft': $placeWatermarkX = $watermarkMargin; $placeWatermarkY = $imageHeight - $watermarkHeight - $watermarkMargin; break; case 'bottomright': $placeWatermarkX = $imageWidth - $watermarkWidth - $watermarkMargin; $placeWatermarkY = $imageHeight - $watermarkHeight - $watermarkMargin; break; case 'center': $placeWatermarkX = ($imageWidth - $watermarkWidth) / 2 - $watermarkMargin; $placeWatermarkY = ($imageHeight - $watermarkHeight) / 2 - $watermarkMargin; break; } imagecopymerge_alpha($temp, $watermark, $placeWatermarkX, $placeWatermarkY, 0, 0, $watermarkWidth, $watermarkHeight, 0); } } if ($types[$size[2]] == 'jpeg') { dgChmod(JPATH_SITE . DS . 'cache' . DS . $dirname, 0777); call_user_func('image' . $types[$size[2]], $temp, $cachefile, $ad_thumbquality); dgChmod(JPATH_SITE . DS . 'cache' . DS . $dirname); } else { dgChmod(JPATH_SITE . DS . 'cache' . DS . $dirname, 0777); call_user_func('image' . $types[$size[2]], $temp, $cachefile); dgChmod(JPATH_SITE . DS . 'cache' . DS . $dirname); } imagedestroy($temp); } return $relfile; exit; }