/** * Handles results of the java upload * * @return void * @since 1.5.7 */ public function concludejavaupload() { $this->_mainframe = JFactory::getApplication(); $this->_config = JoomConfig::getInstance(); // Send a message if setted in configuration manager if ($this->_config->get('jg_msg_upload_type') != 0) { require_once JPATH_COMPONENT . '/helpers/messenger.php'; $this->_user =& JFactory::getUser(); $counter = $this->_mainframe->getUserState('joom.upload.java.counter', 0); $messenger = new JoomMessenger(); $message = array('from' => $this->_user->get('id'), 'subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_IMAGES_SUBMITTED_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_IMAGES_SUBMITTED_BODY', $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'), $counter), 'mode' => 'upload'); $messenger->send($message); } $this->_mainframe->setUserState('joom.upload.java.counter', 0); $msg = JText::_('COM_JOOMGALLERY_UPLOAD_MSG_SUCCESSFULL'); // Set a redirect according to the correspondent setting in configuration manager $model = $this->getModel('upload'); $url = $model->getRedirectUrlAfterUpload('java', 'java'); if (!empty($url)) { $this->setRedirect($url, $msg); } }
/** * Method to save a new comment * * @return int 1 on success, 2 on success but approval necessary, boolean false otherwise * @since 1.5.5 */ public function save() { // Check for hacking attempt $authorised_viewlevels = implode(',', $this->_user->getAuthorisedViewLevels()); $query = $this->_db->getQuery(true)->select('c.cid')->from(_JOOM_TABLE_IMAGES . ' AS a')->leftJoin(_JOOM_TABLE_CATEGORIES . ' AS c ON c.cid = a.catid')->where('a.published = 1')->where('a.approved = 1')->where('a.id = ' . $this->_id)->where('a.access IN (' . $authorised_viewlevels . ')')->where('c.access IN (' . $authorised_viewlevels . ')'); $this->_db->setQuery($query); $result = $this->_db->loadResult(); if (!$result || !$this->_config->get('jg_showcomment') || !$this->_config->get('jg_anoncomment') && !$this->_user->get('id')) { die('Hacking attempt, aborted!'); } $categories = $this->_ambit->getCategoryStructure(); if (!isset($categories[$result])) { die('Hacking attempt, aborted!'); } // Comment text $filter = JFilterInput::getInstance(); $text = trim($filter->clean(JRequest::getVar('cmttext', '', 'post'))); if (!$text) { $this->_mainframe->redirect(JRoute::_('index.php?view=detail&id=' . $this->_id . '#joomcommentform', false), JText::_('COM_JOOMGALLERY_NO_COMMENT_ENTERED'), 'notice'); } // Name of the one who comments if ($this->_user->get('id')) { $name = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); } else { if ($this->_config->get('jg_namedanoncomment')) { $name = trim($filter->clean(JRequest::getVar('cmtname', '', 'post'))); if (!$name) { $name = JText::_('COM_JOOMGALLERY_COMMON_GUEST'); } } else { $name = JText::_('COM_JOOMGALLERY_COMMON_GUEST'); } } // Store the data in session $this->_mainframe->setUserState('joom.comments.name', $name); $this->_mainframe->setUserState('joom.comments.text', $text); // Captcha $valid = true; $plugins = $this->_mainframe->triggerEvent('onJoomCheckCaptcha'); foreach ($plugins as $key => $result) { if (is_array($result) && isset($result['valid']) && !$result['valid']) { $valid = false; if (isset($result['error']) && $result['error']) { $msg = $result['error']; } else { $msg = JText::_('COM_JOOMGALLERY_DETAIL_MSG_COMMENT_SECURITY_CODE_WRONG'); } break; } } if (!$valid) { $this->_mainframe->redirect(JRoute::_('index.php?view=detail&id=' . $this->_id . '#joomcommentform', false), $msg, 'notice'); } // Check whether the comment has to be approved by administrators if (!$this->_config->get('jg_approvecom') && $this->_user->get('id') || !$this->_config->get('jg_anonapprovecom') && !$this->_user->get('id')) { $approved = 1; // Load image data $image = $this->getTable('joomgalleryimages'); $image->load($this->_id); // Message about new comment to image owner // If comments have to be approved by administrators // this message will be sent as soon as the comment was approved if ($this->_config->get('jg_msg_comment_toowner') && $image->owner && $image->owner != $this->_user->get('id')) { // Load image data $row = $this->getTable('joomgalleryimages'); $row->load($this->_id); require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('from' => $this->_user->get('id'), 'recipient' => $image->owner, 'subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_TO_OWNER_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_TO_OWNER_BODY', $name, $image->imgtitle, $this->_id), 'type' => $messenger->getType('comment')); } } else { $approved = 0; // Message about new comment require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('from' => $this->_user->get('id'), 'subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_BODY', $name), 'mode' => 'comment'); } // Change \r\n or \n to <br /> $text = nl2br(stripcslashes($text)); $date = JFactory::getDate(); $row = $this->getTable('joomgallerycomments'); $row->cmtpic = $this->_id; $row->cmtip = $_SERVER['REMOTE_ADDR']; $row->userid = $this->_user->get('id'); $row->cmtname = $name; $row->cmttext = $text; $row->cmtdate = $date->toSQL(); $row->published = 1; $row->approved = $approved; // Trigger event 'onJoomBeforeComment' $plugins = $this->_mainframe->triggerEvent('onJoomBeforeComment', array(&$row)); if (in_array(false, $plugins, true)) { return false; } if (!$row->check()) { $this->setError($row->getError()); return false; } if (!$row->store()) { $this->setError(JText::_('COM_JOOMGALLERY_ERROR_SAVING_COMMENT')); return false; } if (isset($messenger)) { $messenger->send($message); } $this->_mainframe->triggerEvent('onJoomAfterComment', array($row)); // After successfully storing the comment remove the comment text from the session, but keep the name $this->_mainframe->setUserState('joom.comments.text', null); if ($approved) { return 1; } else { return 2; } }
/** * Raw view display method, outputs one image * * @param string $tpl The name of the template file to parse * @return void * @since 1.5.5 */ public function display($tpl = null) { jimport('joomla.filesystem.file'); $type = JRequest::getWord('type', 'thumb'); $download = JRequest::getCmd('download'); $crop_image = false; $cropwidth = JRequest::getInt('width'); $cropheight = JRequest::getInt('height'); if ($cropwidth && $cropheight) { $crop_image = true; } $model = $this->getModel(); if (!($image = $model->getImage(JRequest::getInt('id')))) { return $this->displayError($model->getError()); } $img = $this->_ambit->getImg($type . '_path', $image); $include_watermark = false; // Check access rights // If the thumbnail is required, we won't have to do more checks than the // general access level check in the model. // Additionally the hit counter gets only increased if we are not // displaying a thumbnail. if ($type != 'thumb') { // Downloading if ($download) { // Is the download allowed for the user group of the current user? if (!$this->_config->get('jg_download') || !$this->_config->get('jg_download_unreg') && !$this->_user->get('id')) { $this->_mainframe->redirect(JRoute::_('index.php?view=gallery', false), JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_ACCESS'), 'error'); } // Is the download of the requested image type allowed? if (!$this->_config->get('jg_downloadfile') && $type == 'orig') { $this->_mainframe->redirect(JRoute::_('index.php?view=gallery', false), JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_ACCESS'), 'notice'); } if ($this->_config->get('jg_downloadfile') == 1 && !JFile::exists($img)) { $this->_mainframe->redirect(JRoute::_('index.php?view=gallery', false), JText::_('COM_JOOMGALLERY_COMMON_MSG_ORIGINAL_NOT_AVAILABLE'), 'notice'); } if ($this->_config->get('jg_downloadfile') == 2 && $type == 'orig') { if (!JFile::exists($img)) { // Offer detail image for download if original images isn't available $type = 'img'; $img = $this->_ambit->getImg($type . '_path', $image); } } // Include watermark when downloading image? if ($this->_config->get('jg_downloadwithwatermark')) { $include_watermark = true; } // Trigger event 'onJoomBeforeDownload' $plugins = $this->_mainframe->triggerEvent('onJoomBeforeDownload', array(&$image, &$img, &$type, &$include_watermark)); if (in_array(false, $plugins, true)) { $this->_mainframe->redirect(JRoute::_('index.php?view=gallery', false)); } // Message about new download if (!$this->_user->get('username')) { $username = JText::_('COM_JOOMGALLERY_COMMON_GUEST'); } else { $username = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); } require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_DOWNLOAD_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_DOWNLOAD_BODY', $image->imgtitle, $image->imgfilename, $username), 'mode' => 'download'); $messenger->send($message); // Increase download counter $model->download(); } else { if (!$this->_config->get('jg_showdetailpage') && !$this->_user->get('id')) { return $this->displayError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_ACCESS')); } // Include watermark when displaying image in the detail view? if ($this->_config->get('jg_watermark')) { $include_watermark = true; } // Link to original image in detail view or category view if ($type == 'orig' && (is_numeric($this->_config->get('jg_detailpic_open')) && $this->_config->get('jg_detailpic_open') == 0 && (!$this->_config->get('jg_bigpic') && $this->_user->get('id') || !$this->_config->get('jg_bigpic_unreg') && !$this->_user->get('id')) || (!is_numeric($this->_config->get('jg_detailpic_open')) || $this->_config->get('jg_detailpic_open') > 0) && !$this->_config->get('jg_lightboxbigpic'))) { return $this->displayError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_ACCESS')); } } // Increase hit counter $model->hit(); } if (!JFile::exists($img)) { return $this->displayError(JText::_('COM_JOOMGALLERY_COMMON_MSG_IMAGE_NOT_EXIST')); } $info = getimagesize($img); switch ($info[2]) { case 1: $mime = 'image/gif'; break; case 2: $mime = 'image/jpeg'; break; case 3: $mime = 'image/png'; break; default: return $this->displayError(JText::sprintf('COM_JOOMGALLERY_COMMON_MSG_MIME_NOT_ALLOWED', $info[2])); } // Set mime encoding $this->_doc->setMimeEncoding($mime); // Set header to specify the file name $disposition = 'inline'; if ($download) { // Allow downloading $disposition = 'attachment'; } JResponse::setHeader('Content-disposition', $disposition . '; filename=' . basename($img)); // Inlude watermark and crop if (($include_watermark || $crop_image) && !$model->isGif($img)) { $img_resource = null; if ($crop_image) { $croppos = JRequest::getInt('pos'); $offsetx = JRequest::getInt('x'); $offsety = JRequest::getInt('y'); $img_resource = $model->cropImage($img, $cropwidth, $cropheight, $croppos, $offsetx, $offsety); } if ($include_watermark) { if (!($img_resource = $model->includeWatermark($img, $img_resource, $cropwidth, $cropheight))) { return $this->displayError($model->getError()); } } if (!$img_resource) { echo JFile::read($img); } else { switch ($mime) { case 'image/gif': imagegif($img_resource); break; case 'image/png': imagepng($img_resource); break; case 'image/jpeg': $quali = JRequest::getInt('quali', 95); imagejpeg($img_resource, null, $quali); break; default: return $this->displayError(JText::sprintf('COM_JOOMGALLERY_COMMON_MSG_MIME_NOT_ALLOWED', $mime)); } imagedestroy($img_resource); } } else { echo JFile::read($img); } }
/** * Sends message about reason of rejection to image owner * * @param int $id The image ID * @param string $message The message to send * @return boolean True on success, false otherwise * @since 3.1 */ public function sendRejectionMessage($id, $message) { if (!($image = $this->_ambit->getImgObject($id))) { return false; } if (!$image->owner) { return false; } require_once JPATH_COMPONENT_SITE . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('from' => $this->_user->get('id'), 'recipient' => $image->owner, 'subject' => JText::sprintf('COM_JOOMGALLERY_IMGMAN_REJECT_IMAGE_SUBJECT', $image->imgtitle), 'body' => $message, 'mode' => 'rejectimg'); return $messenger->send($message); }
/** * Method to create the zip archive with all selected images * * @return boolean True on success, false otherwise * @since 1.0.0 */ public function createZip() { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); $zip_adapter = JArchive::getAdapter('zip'); // Check whether zip download is allowed if (!$this->_config->get('jg_zipdownload') && ($this->_user->get('id') || !$this->_config->get('jg_usefavouritesforpubliczip'))) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), JText::_('COM_JOOMGALLERY_FAVOURITES_MSG_NOT_ALLOWED'), 'notice'); } if (is_null($this->piclist)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice'); } $query = $this->_db->getQuery(true)->select('id')->select('catid')->select('imgfilename')->from(_JOOM_TABLE_IMAGES . ' AS a')->from(_JOOM_TABLE_CATEGORIES . ' AS c')->where('id IN (' . $this->piclist . ')')->where('a.catid = c.cid')->where('a.published = 1')->where('a.approved = 1')->where('c.published = 1')->where('a.access IN (' . implode(',', $this->_user->getAuthorisedViewLevels()) . ')')->where('c.access IN (' . implode(',', $this->_user->getAuthorisedViewLevels()) . ')'); $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); if (!count($rows)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice'); } // Name of the zip archive $zipname = 'components/' . _JOOM_OPTION . '/joomgallery_' . date('d_m_Y') . '__'; if ($userid = $this->_user->get('id')) { $zipname .= $userid . '_'; } $zipname .= mt_rand(10000, 99999) . '.zip'; $files = array(); if ($this->_config->get('jg_downloadwithwatermark')) { $include_watermark = true; // Get the 'image' model $imageModel = parent::getInstance('image', 'joomgallerymodel'); // Get the temp path for storing the watermarked image temporarily if (!JFolder::exists($this->_ambit->get('temp_path'))) { $this->setError(JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_TEMP_MISSING')); return false; } else { $tmppath = $this->_ambit->get('temp_path'); } } else { $include_watermark = false; } $categories = $this->_ambit->getCategoryStructure(); foreach ($rows as &$row) { if (!isset($categories[$row->catid])) { continue; } // Get the original image if existent, otherwise the detail image $orig = $this->_ambit->getImg('orig_path', $row->id); $img = $this->_ambit->getImg('img_path', $row->id); if (file_exists($orig)) { $image = $orig; } else { if (file_exists($img)) { $image = $img; } else { $image = null; continue; } } $files[$row->id]['name'] = $row->imgfilename; // Watermark the image before if needed if ($include_watermark) { // Get the image resource of watermarked image $imgres = $imageModel->includeWatermark($image); // Start output buffering ob_start(); // According to mime type output the watermarked image resource to file $info = getimagesize($image); switch ($info[2]) { case 1: imagegif($imgres); break; case 2: imagejpeg($imgres); break; case 3: imagepng($imgres); break; default: JError::raiseError(404, JText::sprintf('COM_JOOMGALLERY_COMMON_MSG_MIME_NOT_ALLOWED', $mime)); break; } // Read the content from output buffer and fill the array element $files[$row->id]['data'] = ob_get_contents(); // Delete the output buffer ob_end_clean(); } else { $files[$row->id]['data'] = JFile::read($image); } // Increase download counter for that image $this->download($row->id); } if (!count($files)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice'); } // Trigger event 'onJoomBeforeZipDownload' $plugins = $this->_mainframe->triggerEvent('onJoomBeforeZipDownload', array(&$files)); if (in_array(false, $plugins, true)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false)); } $createzip = $zip_adapter->create($zipname, $files); if (!$createzip) { // Workaround for servers with wwwwrun problem JoomFile::chmod(JPATH_COMPONENT, '0777', true); $createzip = $zip_adapter->create($zipname, $files, 'zip'); JoomFile::chmod(JPATH_COMPONENT, '0755', true); } if (!$createzip) { $this->setError(JText::_('COM_JOOMGALLERY_FAVOURITES_ERROR_CREATEZIP')); return false; } if ($this->_user->get('id')) { if ($this->user_exists) { $query = $this->_db->getQuery(true)->select('zipname')->from(_JOOM_TABLE_USERS)->where('uuserid = ' . $this->_user->get('id')); $this->_db->setQuery($query); if ($old_zip = $this->_db->loadResult()) { if (file_exists($old_zip)) { jimport('joomla.filesystem.file'); JFile::delete($old_zip); } } $query = $this->_db->getQuery(true)->update(_JOOM_TABLE_USERS)->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname))->where('uuserid = ' . $this->_user->get('id')); $this->_db->setQuery($query); } else { $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_USERS)->set('uuserid = ' . $this->_user->get('id'))->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname)); $this->_db->setQuery($query); } } else { $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_USERS)->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname)); $this->_db->setQuery($query); } $this->_db->query(); $this->_mainframe->setUserState('joom.favourites.zipname', $zipname); // Message about new zip download if (!$this->_user->get('username')) { $username = JText::_('COM_JOOMGALLERY_COMMON_GUEST'); } else { $username = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); } if ($this->_config->get('jg_msg_zipdownload')) { $imagefiles = implode(",\n", $files); require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_ZIPDOWNLOAD_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_ZIPDOWNLOAD_BODY', $zipname, $username, $imagefiles), 'mode' => 'zipdownload'); $messenger->send($message); } return true; }
/** * Method to send a report * * @param string $redirect_url Internal URL to the page on which the report was send * @return boolean Redirect URL on success, false otherwise * @since 2.1 */ public function send($redirect_url = 'index.php') { $id = JRequest::getInt('id'); if (!$id) { $this->setError(JText::_('COM_JOOMGALLERY_COMMON_NO_IMAGE_SPECIFIED')); return false; } // Do some security checks if (!$this->_config->get('jg_report_images') || !$this->_config->get('jg_report_unreg') && !$this->_user->get('id')) { $msg = JText::_('JERROR_ALERTNOAUTHOR'); if (!$this->_user->get('id')) { $msg .= JText::_('COM_JOOMGALLERY_COMMON_MSG_YOU_ARE_NOT_LOGGED'); } $this->setError($msg); return false; } if (!$this->_user->get('id')) { $fromname = $this->_mainframe->getUserStateFromRequest('report.image.name', 'name', '', 'post'); $from = $this->_mainframe->getUserStateFromRequest('report.image.email', 'email', '', 'post'); } else { $fromname = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); $from = $this->_user->get('id'); } $report = $this->_mainframe->getUserStateFromRequest('report.image.report', 'report', '', 'post'); if (!$report || !$fromname || !$from) { $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_FORM_NOT_FILLED')); return false; } // Captcha $valid = true; $msg = ''; $plugins = $this->_mainframe->triggerEvent('onJoomCheckCaptcha'); foreach ($plugins as $key => $result) { if (is_array($result) && isset($result['valid']) && !$result['valid']) { $valid = false; if (isset($result['error']) && $result['error']) { $msg = $result['error']; } else { $msg = JText::_('COM_JOOMGALLERY_COMMON_MSG_SECURITY_CODE_WRONG'); } break; } } if (!$valid) { $this->setError($msg); return false; } // Prepare links $image = $this->_ambit->getImgObject($id); $link = JRoute::_($redirect_url); $img_src = JRoute::_($this->_ambit->getImg('img_url', $image)); $current_uri = JURI::getInstance(JURI::base()); $current_host = $current_uri->toString(array('scheme', 'host', 'port')); // Ensure that the correct host and path is prepended $uri = JFactory::getUri($link); $uri->setHost($current_host); $link = $uri->toString(); $uri = JFactory::getUri($img_src); $uri->setHost($current_host); $img_src = $uri->toString(); $text = JText::sprintf('COM_JOOMGALLERY_REPORT_IMAGE_BODY', $image->id, $image->imgtitle, $fromname, $from, $link, $img_src, $report); $subject = JText::sprintf('COM_JOOMGALLERY_REPORT_IMAGE_SUBJECT', $this->_mainframe->getCfg('sitename')); // Create the message require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('from' => $from, 'fromname' => $fromname, 'subject' => $subject, 'body' => $text, 'mode' => 'report'); // Message to image owner if ($this->_config->get('jg_msg_report_toowner')) { $messenger->addRecipients($image->owner); } // Send the message if (!$messenger->send($message)) { $this->setError(JText::_('COM_JOOMGALLERY_COMMON_REPORT_NOT_SENT')); return false; } // Delete data in session $this->_mainframe->setUserState('report.image', null); $this->_mainframe->triggerEvent('onJoomAfterReport', array($message)); return true; }
/** * Method to publish, unpublish, approve or reject one or more comments * * @param array $cid Array of comment IDs to perform the task on * @param int $publish 1 for publishing or approving, 0 for unpublishing or rejecting * @param string $task The task to perform ('publish' or 'approve') * @return int The number of successfully processed comments, false otherwise * @since 1.5.5 */ public function publish($cid, $publish = 1, $task = 'publish') { JArrayHelper::toInteger($cid); $cids = implode(',', $cid); $column = 'approved'; if ($task == 'publish') { $column = 'published'; } $query = $this->_db->getQuery(true)->update(_JOOM_TABLE_COMMENTS)->set($column . ' = ' . (int) $publish)->where('cmtid IN (' . $cids . ' )'); $this->_db->setQuery($query); if (!$this->_db->query()) { return false; } // Message about new comment to image owner if ($column == 'approved' && $publish && $this->_config->get('jg_msg_comment_toowner')) { require_once JPATH_COMPONENT_SITE . '/helpers/messenger.php'; $messenger = new JoomMessenger(); foreach ($cid as $id) { // Load comment data $comment = $this->getTable('joomgallerycomments'); $comment->load($id); if (!($name = $comment->cmtname)) { $user = JFactory::getUser($comment->userid); $name = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); } // Load image data $image = $this->getTable('joomgalleryimages'); $image->load($comment->cmtpic); if ($image->owner && $image->owner != $comment->userid) { $mode = $messenger->getModeData('comment'); $message = array('from' => $this->_user->get('id'), 'subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_TO_OWNER_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_TO_OWNER_BODY', $name, $image->imgtitle, $image->id), 'type' => $mode['type']); $message['recipient'] = $image->owner; $messenger->send($message); } } } return count($cid); }
/** * Method to save a name tag * * @return boolean True on success, false otherwise * @since 1.5.5 */ public function save() { $yvalue = JRequest::getInt('yvalue', 0, 'post'); $xvalue = JRequest::getInt('xvalue', 0, 'post'); $height = $this->_config->get('jg_nameshields_height'); // Access check if (!($by = $this->_user->get('id'))) { JError::raiseError(500, JText::_('COM_JOOMGALLERY_COMMON_PERMISSION_DENIED')); } // Check for hacking attempt $authorised_viewlevels = implode(',', $this->_user->getAuthorisedViewLevels()); $query = $this->_db->getQuery(true)->select('c.cid')->from(_JOOM_TABLE_IMAGES . ' AS a')->leftJoin(_JOOM_TABLE_CATEGORIES . ' AS c ON c.cid = a.catid')->where('a.published = 1')->where('a.approved = 1')->where('a.id = ' . $this->_id)->where('a.access IN (' . $authorised_viewlevels . ')')->where('c.access IN (' . $authorised_viewlevels . ')'); $this->_db->setQuery($query); if (!($result = $this->_db->loadResult())) { die('Hacking attempt, aborted!'); } $categories = $this->_ambit->getCategoryStructure(); if (!isset($categories[$result])) { die('Hacking attempt, aborted!'); } if ($this->_config->get('jg_nameshields_others')) { $userid = JRequest::getInt('userid'); } else { $userid = $by; } // Check whether an existing user was selected $user = JFactory::getUser($userid); if (!is_object($user)) { $this->setError(JText::_('COM_JOOMGALLERY_DETAIL_NAMETAGS_MSG_ERROR_SAVING')); return false; } $query = $this->_db->getQuery(true)->select('nid')->from(_JOOM_TABLE_NAMESHIELDS)->where('npicid = ' . $this->_id)->where('nuserid = ' . $userid); $this->_db->setQuery($query); if ($this->_db->loadResult()) { if ($userid == $by) { $this->setError(JText::_('COM_JOOMGALLERY_DETAIL_NAMETAGS_MSG_YOU_ARE_ALREADY_TAGGED')); } else { $this->setError(JText::_('COM_JOOMGALLERY_DETAIL_NAMETAGS_MSG_USER_ALREADY_TAGGED')); } return false; } $length = strlen($user->get('username')) * $this->_config->get('jg_nameshields_width'); if ($xvalue < $height && $yvalue < $length) { $this->setError(JText::_('COM_JOOMGALLERY_DETAIL_NAMETAGS_MSG_NOT_SAVED')); return false; } $query->clear()->select('MIN(nzindex)')->from(_JOOM_TABLE_NAMESHIELDS)->where('npicid = ' . $this->_id); $this->_db->setQuery($query); $zindex = $this->_db->loadResult(); if (!$zindex) { $zindex = 500; } else { $zindex--; } $row = $this->getTable('joomgallerynameshields'); $date = JFactory::getDate(); $row->npicid = $this->_id; $row->nuserid = $userid; $row->nxvalue = $xvalue; $row->nyvalue = $yvalue; $row->by = $by; $row->nuserip = $_SERVER['REMOTE_ADDR']; $row->ndate = $date->toSQL(); $row->nzindex = $zindex; if (!$row->store()) { $this->setError(JText::_('COM_JOOMGALLERY_DETAIL_NAMETAGS_MSG_ERROR_SAVING')); return false; } $this->_mainframe->triggerEvent('onJoomAfterTag', array($row)); // Send messages if ($this->_config->get('jg_msg_nametag_type')) { $image = $this->getTable('joomgalleryimages'); $image->load($this->_id); $user = JFactory::getUser($userid); $name = $this->_config->get('jg_realname') ? $user->get('name') : $user->get('username'); $by_name = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); // General Message if ($by != $userid) { $subject = JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_NAMETAG_OTHERS_BODY', $name, $by_name, $image->imgtitle, $this->_id); } else { $subject = JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_NAMETAG_BODY', $name, $image->imgtitle, $this->_id); } $message = array('from' => $by, 'subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_NAMETAG_SUBJECT'), 'body' => $subject, 'mode' => 'nametag'); // Message to image owner if ($this->_config->get('jg_msg_nametag_toowner') && $by != $image->owner) { // Simply add the owner to the list of recipients $message['recipient'] = $image->owner; } // Send general message $messenger->send($message); // Message to tagged user if ($this->_config->get('jg_msg_nametag_totaggeduser') && $by != $userid) { $url = JRoute::_('index.php?view=detail&id=' . $this->_id, false) . ($this->_config->get('jg_anchors') ? '#joomimg' : ''); // Ensure that the correct host and path is prepended $current_uri = JURI::getInstance(JURI::base()); $current_host = $current_uri->toString(array('scheme', 'host', 'port')); $uri = JFactory::getUri($url); $uri->setHost($current_host); $url = $uri->toString(); $message = array('from' => $by, 'recipient' => $userid, 'subject' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_YOU_WERE_TAGGED_SUBJECT', $this->_mainframe->getCfg('sitename')), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_YOU_WERE_TAGGED_BODY', $name, $image->imgtitle, $url), 'type' => $messenger->getType('nametag')); $messenger->send($message); } } return true; }
/** * AJAX upload * * An image is chosen and uploaded afore. * * @return void * @since 3.0 */ protected function uploadAJAX() { // Access check $category = $this->getCategory($this->catid); if (!$category || !$this->_user->authorise('joom.upload', _JOOM_OPTION . '.category.' . $this->catid) && (!$this->_user->authorise('joom.upload.inown', _JOOM_OPTION . '.category.' . $this->catid) || !$category->owner || $category->owner != $this->_user->get('id'))) { $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_YOU_ARE_NOT_ALLOWED_TO_UPLOAD_INTO_THIS_CATEGORY')); return false; } $image = JRequest::getVar('qqfile', '', 'files'); $qqtotalfilesize = JRequest::getInt('qqtotalfilesize', -1); $totalParts = JRequest::getInt('qqtotalparts', 1); $screenshot = $image['tmp_name']; $origfilename = JRequest::getString('qqfilename', ''); $screenshot_filesize = $image['size']; if (empty($origfilename)) { $origfilename = $image['name']; } // Clean up directory containing old image chunks $this->cleanupChunks(); if ($totalParts == 1 && $qqtotalfilesize > 0 && $screenshot_filesize != $qqtotalfilesize) { $this->setError(JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_FILE_PARTLY_UPLOADED')); return false; } if ($image['error'] > 0) { $errorMsg = JText::_('COM_JOOMGALLERY_AJAXUPLOAD_UPLOAD_FAILED') . ' ' . JText::sprintf('COM_JOOMGALLERY_UPLOAD_ERROR_CODE', $image['error']); $this->setError($errorMsg); return false; } if ($this->_site && $this->counter > $this->_config->get('jg_maxuserimage') - 1 && $this->_user->get('id')) { $timespan = $this->_config->get('jg_maxuserimage_timespan'); $errorMsg = JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_MAY_ADD_MAX_OF', $this->_config->get('jg_maxuserimage'), $timespan > 0 ? JText::plural('COM_JOOMGALLERY_UPLOAD_NEW_IMAGE_MAXCOUNT_TIMESPAN', $timespan) : ''); $this->setError($errorMsg); return false; } $cleanChunkDir = false; // Save a chunk if ($totalParts > 1) { $partIndex = JRequest::getInt('qqpartindex'); $uuid = JRequest::getVar('qquuid'); if (!is_writable($this->chunksFolder)) { $errorMsg = JText::sprintf('COM_JOOMGALLERY_AJAXUPLOAD_ERROR_CHUNKSDIR_NOTWRITABLE', $this->chunksFolder); $this->setError($errorMsg); return false; } // Create unique target folder for chunks $targetFolder = $this->chunksFolder . '/' . $uuid; if (!JFolder::exists($targetFolder)) { if (!JFolder::create($targetFolder)) { return false; } } // Save chunk in target folder $target = $targetFolder . '/' . $partIndex; if (JFile::upload($screenshot, $target) === true) { // Last chunk if ($totalParts - 1 == $partIndex) { $target = $targetFolder . '/' . ($partIndex + 1); $cleanChunkDir = $targetFolder; $screenshot = $target; $screenshot_filesize = 0; if ($fp_target = fopen($target, 'wb')) { for ($parts = 0; $parts < $totalParts; $parts++) { $fp_chunk = fopen($targetFolder . '/' . $parts, "rb"); $screenshot_filesize += stream_copy_to_stream($fp_chunk, $fp_target); fclose($fp_chunk); } fclose($fp_target); } else { // Complete image could not be created return false; } } else { // Another chunk will arrive later return true; } } else { // Chunk could not be saved return false; } } // Trigger onJoomBeforeUpload $plugins = $this->_mainframe->triggerEvent('onJoomBeforeUpload'); if (in_array(false, $plugins, true)) { $errorMsg = JText::_('COM_JOOMGALLERY_AJAXUPLOAD_UPLOAD_FAILED'); $this->setError($errorMsg); return false; } $this->_debugoutput = '<hr />'; $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_FILENAME', $origfilename) . '<br />'; // Image size must not exceed the setting in backend if we are in frontend if ($this->_site && $screenshot_filesize > $this->_config->get('jg_maxfilesize')) { $errorMsg = JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_MAX_ALLOWED_FILESIZE', $this->_config->get('jg_maxfilesize')); $this->setError($errorMsg); $this->_debugoutput .= $errorMsg . '<br />'; $this->debug = true; return false; } // Get extension $tag = strtolower(JFile::getExt($origfilename)); // Check for right format if ($tag != 'jpeg' && $tag != 'jpg' && $tag != 'jpe' && $tag != 'gif' && $tag != 'png' || strlen($screenshot) == 0 || $screenshot == 'none') { $errorMsg = JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_INVALID_IMAGE_TYPE'); $this->setError($errorMsg); $this->_debugoutput .= $errorMsg . '<br />'; $this->debug = true; return false; } $filecounter = null; if ($this->_site && $this->_config->get('jg_useruploadnumber') || !$this->_site && $this->_config->get('jg_filenamenumber')) { $filecounter = $this->_getSerial(); } // Create new filename // If generic filename set in backend use them if ($this->_site && $this->_config->get('jg_useruseorigfilename') || !$this->_site && $this->_config->get('jg_useorigfilename')) { $oldfilename = $origfilename; $newfilename = JoomFile::fixFilename($origfilename); } else { $oldfilename = $this->imgtitle; $newfilename = JoomFile::fixFilename($this->imgtitle); } // Check the new filename if (JoomFile::checkValidFilename($oldfilename, $newfilename) == false) { if ($this->_site) { $errorMsg = JText::_('COM_JOOMGALLERY_COMMON_ERROR_INVALID_FILENAME') . '<br />'; } else { $errorMsg = JText::sprintf('COM_JOOMGALLERY_UPLOAD_ERROR_INVALID_FILENAME', $newfilename, $oldfilename) . '<br />'; } $this->setError($errorMsg); $this->_debugoutput .= $errorMsg . '<br />'; $this->debug = true; return false; } $newfilename = $this->_genFilename($newfilename, $tag, $filecounter); if ($cleanChunkDir !== false) { $return = JFile::move($screenshot, $this->_ambit->getImg('orig_path', $newfilename, null, $this->catid)); // Clean up chunk directory JFolder::delete($cleanChunkDir); } else { // 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 $return = JFile::upload($screenshot, $this->_ambit->getImg('orig_path', $newfilename, null, $this->catid)); } if (!$return) { $errorMsg = JText::sprintf('COM_JOOMGALLERY_UPLOAD_ERROR_UPLOADING', $this->_ambit->getImg('orig_path', $newfilename, null, $this->catid)); $this->setError($errorMsg); $this->_debugoutput .= $errorMsg . '<br />'; $this->debug = true; return false; } $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_UPLOAD_COMPLETE') . '<br />'; // Set permissions of uploaded file $return = JoomFile::chmod($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), '0644'); // if(!$return) // { // $this->rollback($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), null, null); // $errorMsg = $this->_ambit->getImg('orig_path', $newfilename, null, $this->catid).' '.JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS'); // $this->_debugoutput .= $errorMsg.'<br />'; // $this->debug = true; // return false; // } // Create thumbnail and detail image if (!$this->resizeImage($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), $newfilename)) { $this->rollback($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), $this->_ambit->getImg('img_path', $newfilename, null, $this->catid), $this->_ambit->getImg('thumb_path', $newfilename, null, $this->catid)); $this->debug = true; return false; } // Insert database entry $row = JTable::getInstance('joomgalleryimages', 'Table'); if (!$this->registerImage($row, $origfilename, $newfilename, $tag, $filecounter)) { $this->rollback($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), $this->_ambit->getImg('img_path', $newfilename, null, $this->catid), $this->_ambit->getImg('thumb_path', $newfilename, null, $this->catid)); $this->debug = true; return false; } // Message about new image if ($this->_site) { require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('from' => $this->_user->get('id'), 'subject' => JText::_('COM_JOOMGALLERY_UPLOAD_MESSAGE_NEW_IMAGE_UPLOADED'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_IMAGE_SUBMITTED_BODY', $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'), $row->imgtitle), 'mode' => 'upload'); $messenger->send($message); } $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_IMAGE_SUCCESSFULLY_ADDED') . '<br />'; $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_NEW_FILENAME', $newfilename) . '<br />'; $this->_mainframe->triggerEvent('onJoomAfterUpload', array($row)); // Reset file counter, delete original and create special gif selection and debug information $this->_mainframe->setUserState('joom.upload.filecounter', 0); $this->_mainframe->setUserState('joom.upload.delete_original', false); $this->_mainframe->setUserState('joom.upload.create_special_gif', false); $this->_mainframe->setUserState('joom.upload.debug', false); $this->_mainframe->setUserState('joom.upload.debugoutput', null); return $row; }