/** * Save an existing or a new mood form POST */ public function apply() { CommunityLicenseHelper::_(); JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN')); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $scss = $jinput->post->get('scss', null, 'array'); $settings = $jinput->post->get('settings', null, 'array'); if (JString::strtoupper($jinput->getMethod()) != 'POST') { $mainframe->redirect('index.php?option=com_community&view=moods', JText::_('COM_COMMUNITY_PERMISSION_DENIED'), 'error'); } if (!is_null($scss)) { CommunityThemeHelper::parseScss($scss, 'general'); } // Handle image uploads $images['frontpage-image'] = $jinput->files->get('frontpage-image-new', '', 'NONE'); foreach ($images as $key => $image) { if (!empty($image['tmp_name']) && isset($image['name']) && !empty($image['name'])) { $imagePath = COMMUNITY_PATH_ASSETS; // same as the image path //check the file extension first and only allow jpg or png $ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION)); if (!in_array($ext, array('jpg', 'png')) || $image['type'] != 'image/png' && $image['type'] != 'image/jpeg') { } $imageJpg = $imagePath . '/' . $key . '.jpg'; $imagePng = $imagePath . '/' . $key . '.png'; //check if existing image exist, if yes, delete it if (file_exists($imageJpg)) { unlink($imageJpg); } if (file_exists($imagePng)) { unlink($imagePng); } //let move the tmp image to the actual path $finalPath = $imagePath . $key . '.' . $ext; move_uploaded_file($image['tmp_name'], $finalPath); require JPATH_ROOT . "/components/com_community/helpers/image.php"; CImageHelper::resizeProportional($finalPath, $finalPath, "image/{$ext}", 1000, 1000); $settings[$key] = $ext; } } // Parse settings finish CommunityThemeHelper::parseSettings($settings, 'general'); $message = JText::_('COM_COMMUNITY_THEME_GENERAL_UPDATED'); $mainframe->redirect('index.php?option=com_community&view=themegeneral', $message, 'message'); // Get the view type $document = JFactory::getDocument(); $viewType = $document->getType(); // Get the view $viewName = JRequest::getCmd('view', 'community'); $view = $this->getView($viewName, $viewType); $view->setLayout('edit'); $model = $this->getModel($viewName, 'CommunityAdminModel'); if ($model) { $view->setModel($model, $viewName); } $view->display(); }
static function save_avatar_jomsocial($userid, $pic_url) { $pic = JoomdleHelperContent::get_file($pic_url); if (!$pic) { return; } require_once JPATH_ROOT . '/' . 'components' . '/' . 'com_community' . '/' . 'libraries' . '/' . 'core.php'; CFactory::load('helpers', 'image'); $config = CFactory::getConfig(); $imageMaxWidth = 160; $comp_params = JComponentHelper::getParams('com_joomdle'); $moodle_version = $comp_params->get('moodle_version'); if ($moodle_version == 19) { $extension = '.jpg'; // Moodle stores JPG always in 1.9 $type = 'image/jpeg'; } else { $extension = '.png'; // Moodle stores PNG always in 2.0 $type = 'image/png'; } $jconfig = JFactory::getConfig(); $tmp_file = $jconfig->get('tmp_path') . '/' . 'tmp_pic' . time(); file_put_contents($tmp_file, $pic); // Get a hash for the file name. $fileName = JApplication::getHash($pic_url . time()); $hashFileName = JString::substr($fileName, 0, 24); $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/' . 'avatar'; $storageImage = $storage . '/' . $hashFileName . $extension; $storageThumbnail = $storage . '/' . 'thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. list($currentWidth, $currentHeight) = getimagesize($tmp_file); if ($currentWidth < $imageMaxWidth) { $imageMaxWidth = $currentWidth; } CImageHelper::resizeProportional($tmp_file, $storageImage, $type, $imageMaxWidth); /* if( !CImageHelper::resizeProportional( $tmp_file , $storageImage , $type , $imageMaxWidth ) ) //Moodle always stores png in 2.0? XXX { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE' , $storageImage), 'error'); if(isset($url)){ $mainframe->redirect($url); } } */ // Generate thumbnail // if(!CImageHelper::createThumb( $tmp_file , $storageThumbnail , 'image/png' )) //Moodle always stores png CImageHelper::createThumb($tmp_file, $storageThumbnail, $type); /* if(!CImageHelper::createThumb( $tmp_file , $storageThumbnail , $type )) //Moodle always stores png { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE' , $storageThumbnail), 'error'); if(isset($url)){ $mainframe->redirect($url); } } */ $userModel->setImage($userid, $image, 'avatar'); $userModel->setImage($userid, $thumbnail, 'thumb'); }
/** * * @param type $type * @param type $id * @param type $sourceX * @param type $sourceY * @param type $width * @param type $height */ public static function updateAvatar($type, $id, $sourceX, $sourceY, $width, $height) { $filter = JFilterInput::getInstance(); /* Filter input values */ $type = $filter->clean($type, 'string'); $id = $filter->clean($id, 'integer'); $sourceX = $filter->clean($sourceX, 'float'); $sourceY = $filter->clean($sourceY, 'float'); $width = $filter->clean($width, 'float'); $height = $filter->clean($height, 'float'); $cTable = JTable::getInstance(ucfirst($type), 'CTable'); $cTable->load($id); $cTable->storage = 'file'; $cTable->store(); $srcPath = JPATH_ROOT . '/' . $cTable->avatar; $destPath = JPATH_ROOT . '/' . $cTable->thumb; /* */ $config = CFactory::getConfig(); $avatarFolder = $type != 'profile' && $type != '' ? $type . '/' : ''; /* Get original image */ $originalPath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $avatarFolder . '/' . $type . '-' . JFile::getName($cTable->avatar); /** * If original image does not exists than we use source image * @todo we should get from facebook original avatar file */ if (!JFile::exists($originalPath)) { $originalPath = $srcPath; } $srcPath = str_replace('/', '/', $srcPath); $destPath = str_replace('/', '/', $destPath); $info = getimagesize($srcPath); $destType = $info['mime']; $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH; $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH; /* thumb size */ $currentWidth = $width; $currentHeight = $height; /* avatar size */ $imageMaxWidth = 160; $imageMaxHeight = 160; /** * @todo Should we generate new filename and update into database ? */ /* do avatar resize */ CImageHelper::resize($originalPath, $srcPath, $destType, $imageMaxWidth, $imageMaxHeight, $sourceX, $sourceY, $currentWidth, $currentHeight); /* do thumb resize */ CImageHelper::resize($originalPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight); /** * Now we do check and process watermark */ /* Check multiprofile to reapply watermark for thumbnail */ $my = CFactory::getUser(); $profileType = $my->getProfileType(); $multiprofile = JTable::getInstance('MultiProfile', 'CTable'); $multiprofile->load($profileType); $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false; if ($useWatermark && $type == 'profile') { $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark); list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); list($thumbWidth, $thumbHeight) = getimagesize($destPath); list($avatarWidth, $avatarHeight) = getimagesize($srcPath); // Avatar Properties $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight); // The original image file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($srcPath, $srcPath, $destType, $watermarkPath, $avatarPosition->x, $avatarPosition->y); $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); /* addWatermark into thumbnail */ CImageHelper::addWatermark($destPath, $destPath, $destType, $watermarkPath, $thumbPosition->x, $thumbPosition->y); } // we need to update the activity stream of group if applicable, so the cropped image will be updated as well if ($type == 'group') { $groupParams = new JRegistry($cTable->params); $actId = $groupParams->get('avatar_activity_id'); if ($actId) { $act = JTable::getInstance('Activity', 'CTable'); $act->load($actId); $actParams = new JRegistry($act->params); $actParams->set('avatar_cropped_thumb', $cTable->avatar); $act->params = $actParams->toString(); $act->store(); } } $connectModel = CFactory::getModel('connect'); // For facebook user, we need to add the watermark back on if ($connectModel->isAssociated($my->id) && $config->get('fbwatermark') && $type == 'profile') { list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON); CImageHelper::addWatermark($destPath, $destPath, $destType, FACEBOOK_FAVICON, $destWidth - $watermarkWidth, $destHeight - $watermarkHeight); } }
public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark) { $image = ''; if (!empty($avatarUrl)) { // Make sure user is properly added into the database table first $user = CFactory::getUser($joomlaUserId); $fbUser = $this->getUser(); // Load image helper library as it is needed. CFactory::load('helpers', 'image'); // Store image on a temporary folder. $tmpPath = JPATH_ROOT . DS . 'images' . DS . 'originalphotos' . DS . 'facebook_connect_' . $fbUser; /* print_r($avatarUrl); exit; $url = parse_url( $avatarUrl ); $host = $url[ 'host' ]; $fp = fsockopen("profile.ak.fbcdn.net", 80, $errno, $errstr, 30); $path = CString::str_ireplace( $url['scheme'] . '://' . $host , '' , $avatarUrl ); $source = ''; if( $fp ) { $out = "GET $path HTTP/1.1\r\n"; $out .= "Host: " . $host . "\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); $body = false; while( !feof( $fp ) ) { $return = fgets( $fp , 1024 ); if( $body ) { $source .= $return; } if( $return == "\r\n" ) { $body = true; } } fclose($fp); } */ // Need to extract the non-https version since it will cause // certificate issue $avatarUrl = str_replace('https://', 'http://', $avatarUrl); CFactory::load('helpers', 'remote'); $source = CRemoteHelper::getContent($avatarUrl, true); list($headers, $source) = explode("\r\n\r\n", $source, 2); JFile::write($tmpPath, $source); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($fbUser . time()); $hashFileName = JString::substr($fileName, 0, 24); $extension = JString::substr($avatarUrl, JString::strrpos($avatarUrl, '.')); $type = 'image/jpg'; if ($extension == '.png') { $type = 'image/png'; } if ($extension == '.gif') { $type = 'image/gif'; } //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar'; $storageImage = $storage . DS . $hashFileName . $extension; $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth); CImageHelper::createThumb($tmpPath, $storageThumbnail, $type); if ($addWaterMark) { // Get the width and height so we can calculate where to place the watermark. list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON); list($imageWidth, $imageHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight); CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight); } // Update the CUser object with the correct avatar. $user->set('_thumb', $thumbnail); $user->set('_avatar', $image); // @rule: once user changes their profile picture, storage method should always be file. $user->set('_storage', 'file'); $userModel->setImage($joomlaUserId, $image, 'avatar'); $userModel->setImage($joomlaUserId, $thumbnail, 'thumb'); $user->save(); } }
/** * Step 5 * Upload a new user avatar */ public function registerAvatar() { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); $mySess = JFactory::getSession(); $user = $mySess->get('tmpUser', ''); /* Just for incase this's incomplete object */ if (!is_object($user) && gettype($user) == 'object') { $user = unserialize(serialize($user)); } if (empty($user)) { //throw error. JError::raiseError(500, JText::_('COM_COMMUNITY_REGISTRATION_MISSING_USER_OBJ')); return; } $view = $this->getView('register'); $profileType = JRequest::getInt('profileType', 0); // If uplaod is detected, we process the uploaded avatar if ($jinput->post->get('action', '')) { $my = CFactory::getUser($user->id); $fileFilter = new JInput($_FILES); $file = $fileFilter->get('Filedata', '', 'array'); if ($my->id == 0) { return $this->blockUnregister(); } if (!CImageHelper::isValidType($file['type'])) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error'); $url = $profileType !== 0 ? CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false) : CRoute::_('index.php?option=com_community&view=register&task=registerAvatar', false); $mainframe->redirect($url); return; } if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error'); } else { $config = CFactory::getConfig(); $uploadLimit = (double) $config->get('maxuploadsize'); $uploadLimit = $uploadLimit * 1024 * 1024; if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), 'error'); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false)); } if (!CImageHelper::isValid($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error'); } else { $config = CFactory::getConfig(); $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') ? true : false; // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JApplication::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar'; $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']); $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']); $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $userModel = CFactory::getModel('user'); // Generate full image if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error'); } // Generate thumbnail if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error'); } if ($useWatermark) { if (!JFolder::exists(JPATH_ROOT . '/images/watermarks/original')) { JFolder::create(JPATH_ROOT . '/images/watermarks/original'); } // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar, // it will be able to grab the original picture. JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type'])); JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type'])); $multiprofile = JTable::getInstance('MultiProfile', 'CTable'); $multiprofile->load($profileType); if ($multiprofile->watermark) { $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark); list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); list($avatarWidth, $avatarHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); $watermarkImage = $storageImage; $watermarkThumbnail = $storageThumbnail; // Avatar Properties $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight); // The original image file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y); //Thumbnail Properties $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); // The original thumbnail file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y); $my->set('_watermark_hash', $multiprofile->watermark_hash); $my->save(); } } // Since this is a new registration, we definitely do not want to remove the old image. $removeOldImage = false; $userModel->setImage($my->id, $image, 'avatar', $removeOldImage); $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage); // Update the user object so that the profile picture gets updated. $my->set('_avatar', $image); $my->set('_thumb', $thumbnail); } } } echo $view->get(__FUNCTION__); }
public function showimage($showPhoto = true) { jimport('joomla.filesystem.file'); $imgid = JRequest::getVar('imgid', '', 'GET'); $maxWidth = JRequest::getVar('maxW', '', 'GET'); $maxHeight = JRequest::getVar('maxH', '', 'GET'); // round up the w/h to the nearest 10 $maxWidth = round($maxWidth, -1); $maxHeight = round($maxHeight, -1); $photoModel = CFactory::getModel('photos'); $photo =& JTable::getInstance('Photo', 'CTable'); $photo->loadFromImgPath($imgid); CFactory::load('helpers', 'image'); $photoPath = JPATH_ROOT . DS . $photo->image; $config = CFactory::getConfig(); if (!JFile::exists($photoPath)) { $displayWidth = $config->getInt('photodisplaysize'); $info = getimagesize(JPATH_ROOT . DS . $photo->original); $imgType = image_type_to_mime_type($info[2]); $displayWidth = $info[0] < $displayWidth ? $info[0] : $displayWidth; CImageHelper::resizeProportional(JPATH_ROOT . DS . $photo->original, $photoPath, $imgType, $displayWidth); if ($config->get('deleteoriginalphotos')) { $originalPath = JPATH_ROOT . DS . $photo->original; if (JFile::exists($originalPath)) { JFile::delete($originalPath); } } } // Show photo if required if ($showPhoto) { $info = getimagesize(JPATH_ROOT . DS . $photo->image); // @rule: Clean whitespaces as this might cause errors when header is used. $ob_active = ob_get_length() !== FALSE; if ($ob_active) { while (@ob_end_clean()) { } if (function_exists('ob_clean')) { @ob_clean(); } } header('Content-type: ' . $info['mime']); echo JFile::read($photoPath); exit; } }
public function save() { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $id = JRequest::getInt('id', 0, 'POST'); $post = JRequest::get('POST'); $fields = $jinput->get('fields', '', 'NONE'); $name = $jinput->get('name', '', 'STRING'); $tmpParents = $jinput->get('parents', '', 'NONE'); $mainframe = JFactory::getApplication(); $task = JRequest::getCmd('task'); $isNew = $id == 0 ? true : false; $validated = true; $multiprofile = JTable::getInstance('MultiProfile', 'CTable'); $multiprofile->load($id); // Skip watermarking if it's the same location $skipWatermark = isset($multiprofile->watermark_location) && isset($post['watermark_location']) && $post['watermark_location'] == $multiprofile->watermark_location ? true : false; // Bind with form post $multiprofile->bind($post); // Can't have an empty name now can we? if (empty($name)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_NAME_EMPTY'), 'error'); } $date = JFactory::getDate(); $isNew = $multiprofile->id == 0 ? true : false; if ($isNew) { $multiprofile->created = $date->toSql(); } // Store watermarks for profile types. $watermark = $jinput->files->get('watermark', '', 'NONE'); //JRequest::getVar( 'watermark' , '' , 'FILES'); if (!empty($watermark['tmp_name'])) { // Do not allow image size to exceed maximum width and height if (isset($watermark['name']) && !empty($watermark['name'])) { list($width, $height) = getimagesize($watermark['tmp_name']); /** * watermark can't large than 16px * @todo use define for min width & height instead fixed number here */ if ($width > 16 || $height > 16) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error'); } } } if ($validated) { $multiprofile->store(); // If image file is specified, we need to store the thumbnail. if (!empty($watermark['tmp_name'])) { if (isset($watermark['name']) && !empty($watermark['name'])) { if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) { JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH); } $watermarkFile = 'watermark_' . $multiprofile->id . CImageHelper::getExtension($watermark['type']); JFile::copy($watermark['tmp_name'], JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $watermarkFile); $multiprofile->watermark = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $watermarkFile; $multiprofile->store(); } } // @rule: Create the watermarks folder if doesn't exists. if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) { if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER')); } } // @rule: Create original folder within watermarks to store original user photos. if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/original')) { if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/original')) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER')); } } if (!empty($watermark['tmp_name']) || !$isNew && !$skipWatermark) { if (isset($watermark['name']) && !empty($watermark['name'])) { $watermarkPath = $watermark['tmp_name']; $watermark_hash = md5($watermark['name'] . time()); } else { $watermarkPath = JPATH_ROOT . '/' . $multiprofile->watermark; $watermark_hash = $multiprofile->watermark_hash; } // Create default watermarks for avatar and thumbnails. // Generate filename $fileName = CImageHelper::getHashName($multiprofile->id . time()) . '.jpg'; $thumbFileName = 'thumb_' . $fileName; // Paths where the thumbnail and avatar should be saved. $thumbPath = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $thumbFileName; $avatarPath = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $fileName; // Copy existing default thumbnails into the path first. JFile::copy(JPATH_ROOT . '/' . DEFAULT_USER_THUMB, $thumbPath); JFile::copy(JPATH_ROOT . '/' . DEFAULT_USER_AVATAR, $avatarPath); $watermarkPath = $watermarkPath; list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); $oldDefaultAvatar = $multiprofile->avatar; $oldDefaultThumb = $multiprofile->thumb; // Avatar Properties $avatarInfo = getimagesize($avatarPath); $avatarWidth = $avatarInfo[0]; $avatarHeight = $avatarInfo[1]; $avatarMime = $avatarInfo['mime']; $avatarPosition = $this->_getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight); CImageHelper::addWatermark($avatarPath, $avatarPath, $avatarMime, $watermarkPath, $avatarPosition->x, $avatarPosition->y); $multiprofile->avatar = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $fileName; // Thumbnail properties. $thumbInfo = getimagesize($thumbPath); $thumbWidth = $thumbInfo[0]; $thumbHeight = $thumbInfo[1]; $thumbMime = $thumbInfo['mime']; $thumbPosition = $this->_getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermarkPath, $thumbPosition->x, $thumbPosition->y); $multiprofile->thumb = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $thumbFileName; // Since the default thumbnail is used by current users, we need to update their existing values. $multiprofile->updateUserDefaultImage('avatar', $oldDefaultAvatar); $multiprofile->updateUserDefaultImage('thumb', $oldDefaultThumb); $multiprofile->watermark_hash = $watermark_hash; $multiprofile->store(); } // Since it would be very tedious to check if previous fields were enabled or disabled. // We delete all existing mapping and remap it again to ensure data integrity. if (!$isNew && empty($fields)) { $multiprofile->deleteChilds(); } if (!empty($fields)) { $parents = array(); // We need to unique the parents first. foreach ($fields as $id) { $customProfile = JTable::getInstance('Profiles', 'CommunityTable'); $customProfile->load($id); // Need to only $parent = $customProfile->getCurrentParentId(); if (in_array($parent, $tmpParents)) { $parents[] = $parent; } } $parents = array_unique($parents); $fields = array_merge($fields, $parents); $fieldTable = JTable::getInstance('MultiProfileFields', 'CTable'); $fieldTable->cleanField($multiprofile->id); foreach ($fields as $id) { $field = JTable::getInstance('MultiProfileFields', 'CTable'); $field->parent = $multiprofile->id; $field->field_id = $id; $field->store(); } } if ($isNew) { $message = JText::_('COM_COMMUNITY_MULTIPROFILE_CREATED_SUCCESSFULLY'); } else { $message = JText::_('COM_COMMUNITY_MULTIPROFILE_UPDATED_SUCCESSFULLY'); } switch ($task) { case 'apply': $link = 'index.php?option=com_community&view=multiprofile&layout=edit&id=' . $multiprofile->id; break; case 'save': default: $link = 'index.php?option=com_community&view=multiprofile'; break; } $mainframe->redirect($link, $message, 'message'); return; } $document = JFactory::getDocument(); $viewName = JRequest::getCmd('view', 'community'); // Get the view type $viewType = $document->getType(); // Get the view $view = $this->getView($viewName, $viewType); $view->setLayout('edit'); $model = $this->getModel('Profiles'); if ($model) { $view->setModel($model, $viewName); } $view->display(); }
/** * Upload a new user avatar */ public function registerAvatar() { $mainframe =& JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); $mySess =& JFactory::getSession(); $user = $mySess->get('tmpUser', ''); if (empty($user)) { //throw error. JError::raiseError(500, JText::_('CC REGISTRATION MISSING USER OBJ')); return; } //CFactory::setActiveProfile($user->id); $view =& $this->getView('register'); CFactory::load('helpers', 'image'); $profileType = JRequest::getInt('profileType', 0); // If uplaod is detected, we process the uploaded avatar if (JRequest::getVar('action', '', 'POST')) { // Load avatar library CFactory::load('libraries', 'avatar'); $my = CFactory::getUser($user->id); $file = JRequest::getVar('Filedata', '', 'FILES', 'array'); if ($my->id == 0) { return $this->blockUnregister(); } if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error'); } else { if (!CImageHelper::isValid($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error'); } else { $config = CFactory::getConfig(); $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') ? true : false; // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar'; $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']); $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']); $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $userModel = CFactory::getModel('user'); // Generate full image if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error'); } // Generate thumbnail if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error'); } if ($useWatermark) { // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar, // it will be able to grab the original picture. JFile::copy($storageImage, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type'])); JFile::copy($storageThumbnail, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type'])); $multiprofile =& JTable::getInstance('MultiProfile', 'CTable'); $multiprofile->load($profileType); $watermarkPath = JPATH_ROOT . DS . JString::str_ireplace('/', DS, $multiprofile->watermark); list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); list($avatarWidth, $avatarHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); $watermarkImage = $storageImage; $watermarkThumbnail = $storageThumbnail; // Avatar Properties $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight); // The original image file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageImage, $watermarkImage, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y); //Thumbnail Properties $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); // The original thumbnail file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, 'image/jpg', $watermarkPath, $thumbPosition->x, $thumbPosition->y); $my->set('_watermark_hash', $multiprofile->watermark_hash); $my->save(); } // Since this is a new registration, we definitely do not want to remove the old image. $removeOldImage = false; $userModel->setImage($my->id, $image, 'avatar', $removeOldImage); $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage); // Update the user object so that the profile picture gets updated. $my->set('_avatar', $image); $my->set('_thumb', $thumbnail); } } //redirect to successful page $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerSucess&profileType=' . $profileType, false)); } echo $view->get(__FUNCTION__); }
/** * This function will regenerate the thumbnail of videos * @param int $id * @param bool $returnThumb * @return bool */ public function _fetchThumbnail($id = 0, $returnThumb = false) { if (!COwnerHelper::isRegisteredUser()) { return; } if (!$id) { return false; } $table = JTable::getInstance('Video', 'CTable'); $table->load($id); $config = CFactory::getConfig(); if ($table->type == 'file') { // We can only recreate the thumbnail for local video file only // it's not possible to process remote video file with ffmpeg if ($table->storage != 'file') { $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . 'FFmpeg cannot process remote video.'); return false; } $videoLib = new CVideoLibrary(); $videoFullPath = JPATH::clean(JPATH_ROOT . '/' . $table->path); if (!JFile::exists($videoFullPath)) { return false; } // Read duration $videoInfo = $videoLib->getVideoInfo($videoFullPath); if (!$videoInfo) { return false; } else { $videoFrame = CVideosHelper::formatDuration((int) ($videoInfo['duration']['sec'] / 2), 'HH:MM:SS'); // Create thumbnail $oldThumb = $table->thumb; $thumbFolder = CVideoLibrary::getPath($table->creator, 'thumb'); $thumbSize = CVideoLibrary::thumbSize(); $thumbFilename = $videoLib->createVideoThumb($videoFullPath, $thumbFolder, $videoFrame, $thumbSize); } if (!$thumbFilename) { return false; } } else { if (!CRemoteHelper::curlExists()) { $this->setError(JText::_('COM_COMMUNITY_CURL_NOT_EXISTS')); return false; } $videoLib = new CVideoLibrary(); $videoObj = $videoLib->getProvider($table->path); if ($videoObj == false) { $this->setError($videoLib->getError()); return false; } if (!$videoObj->isValid()) { $this->setError($videoObj->getError()); return false; } $remoteThumb = $videoObj->getThumbnail(); $thumbData = CRemoteHelper::getContent($remoteThumb, true); if (empty($thumbData)) { $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $remoteThumb); return false; } // split the header and body list($headers, $body) = explode("\r\n\r\n", $thumbData, 2); preg_match('/Content-Type: image\\/(.*)/i', $headers, $matches); if (!empty($matches)) { $thumbPath = CVideoLibrary::getPath($table->creator, 'thumb'); $thumbFileName = CFileHelper::getRandomFilename($thumbPath); $tmpThumbPath = $thumbPath . '/' . $thumbFileName; if (!JFile::write($tmpThumbPath, $body)) { $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $thumbFileName); return false; } // We'll remove the old or none working thumbnail after this $oldThumb = $table->thumb; // Get the image type first so we can determine what extensions to use $info = getimagesize($tmpThumbPath); $mime = image_type_to_mime_type($info[2]); $thumbExtension = CImageHelper::getExtension($mime); $thumbFilename = $thumbFileName . $thumbExtension; $thumbPath = $thumbPath . '/' . $thumbFilename; if (!JFile::move($tmpThumbPath, $thumbPath)) { $this->setError(JText::_('WARNFS_ERR02') . ': ' . $thumbFileName); return false; } // Resize the thumbnails //CImageHelper::resizeProportional( $thumbPath , $thumbPath , $mime , CVideoLibrary::thumbSize('width') , CVideoLibrary::thumbSize('height') ); list($width, $height) = explode('x', $config->get('videosThumbSize')); CImageHelper::resizeAspectRatio($thumbPath, $thumbPath, $width, $height); } else { $this->setError(JText::_('COM_COMMUNITY_PHOTOS_IMAGE_NOT_PROVIDED_ERROR')); return false; } } // Update the DB with new thumbnail $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename; $table->set('thumb', $thumb); $table->store(); // If this video storage is not on local, we move it to remote storage // and remove the old thumb if existed if ($table->storage != 'file') { // && ($table->storage == $storageType)) $config = CFactory::getConfig(); $storageType = $config->getString('videostorage'); $storage = CStorage::getStorage($storageType); $storage->delete($oldThumb); $localThumb = JPATH::clean(JPATH_ROOT . '/' . $table->thumb); $tempThumbname = JPATH::clean(JPATH_ROOT . '/' . md5($table->thumb)); if (JFile::exists($localThumb)) { JFile::copy($localThumb, $tempThumbname); } if (JFile::exists($tempThumbname)) { $storage->put($table->thumb, $tempThumbname); JFile::delete($localThumb); JFile::delete($tempThumbname); } } else { if (JFile::exists(JPATH_ROOT . '/' . $oldThumb)) { JFile::delete(JPATH_ROOT . '/' . $oldThumb); } } if ($returnThumb) { return $table->getThumbnail(); } return true; }
/** * Overrides parent store function as we need to clean up some variables * */ public function store($updateNulls = false) { if (!$this->check()) { return false; } $this->image = CString::str_ireplace('\\', '/', $this->image); $this->thumbnail = CString::str_ireplace('\\', '/', $this->thumbnail); $this->original = CString::str_ireplace('\\', '/', $this->original); // Store params $this->params = $this->_params->toString(); //lets add watermark if there is any and only for new photos if (CPhotosHelper::photoWatermarkEnabled() && !$this->id) { $config = CFactory::getConfig(); $watermark = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . WATERMARK_DEFAULT_NAME . '.png'; list($watermarkWidth, $watermarkHeight) = getimagesize($watermark); //original photo $thumbPath = JPATH_ROOT . '/' . $this->original; if (file_exists($thumbPath)) { $thumbInfo = getimagesize($thumbPath); $thumbWidth = $thumbInfo[0]; $thumbHeight = $thumbInfo[1]; $thumbMime = $thumbInfo['mime']; if ($config->get('min_width_img_watermark') <= $thumbWidth && $config->get('min_height_img_watermark') <= $thumbHeight && $thumbHeight >= $watermarkHeight && $thumbWidth >= $watermarkWidth) { $thumbPosition = $this->_getPositions($config->get('watermark_position'), $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermark, $thumbPosition->x, $thumbPosition->y); } } } //do not use the photo name as the caption for the first time when uploaded if (!$this->id) { $this->caption = ''; } $result = parent::store(); if ($this->status != 'temp' && $result) { // Changes in photos will affect the album. Do a store on album $album = JTable::getInstance('Album', 'CTable'); $album->load($this->albumid); $album->store(); } return $result; }
public function ajaxUpdateThumbnail($type, $id, $sourceX, $sourceY, $width, $height) { $filter = JFilterInput::getInstance(); $type = $filter->clean($type, 'string'); $id = $filter->clean($id, 'integer'); $sourceX = $filter->clean($sourceX, 'float'); $sourceY = $filter->clean($sourceY, 'float'); $width = $filter->clean($width, 'float'); $height = $filter->clean($height, 'float'); $objResponse = new JAXResponse(); $cTable =& JTable::getInstance(ucfirst($type), 'CTable'); $cTable->load($id); $srcPath = JPATH_ROOT . DS . $cTable->avatar; $destPath = JPATH_ROOT . DS . $cTable->thumb; $srcPath = str_replace('/', DS, $srcPath); $destPath = str_replace('/', DS, $destPath); $info = getimagesize($srcPath); $destType = $info['mime']; $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH; $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH; $currentWidth = $width; $currentHeight = $height; CFactory::load('helpers', 'image'); CImageHelper::resize($srcPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight); return $objResponse->sendResponse(); }
public function store() { CommunityLicenseHelper::_(); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; if (JString::strtoupper($jinput->getMethod()) != 'POST') { $mainframe->redirect('index.php?option=com_community&view=moods', JText::_('COM_COMMUNITY_PERMISSION_DENIED'), 'error'); } $mood = JTable::getInstance('Moods', 'CommunityTable'); $mood->load(JRequest::getInt('moodid')); $mood->title = $jinput->post->get('title', '', 'STRING'); $mood->published = $jinput->post->get('published', '', 'NONE'); $mood->description = $jinput->post->get('description', '', 'STRING'); $mood->custom = 1; $isNew = $mood->id < 1; // handle image upload $moodImage = $jinput->files->get('mood_image', '', 'NONE'); if (!empty($moodImage['tmp_name']) && isset($moodImage['name']) && !empty($moodImage['name'])) { $imagePath = COMMUNITY_PATH_ASSETS; // same as the image path //check the file extension first and only allow jpg or png $ext = strtolower(pathinfo($moodImage['name'], PATHINFO_EXTENSION)); if (!in_array($ext, array('jpg', 'png')) || $moodImage['type'] != 'image/png' && $moodImage['type'] != 'image/jpeg') { $mainframe->redirect('index.php?option=com_community&view=moods&layout=edit&id=' . $element, JText::_('COM_COMMUNITY_MOODS_ERROR_IMAGE_TYPE'), 'error'); } else { $mood->image = $ext; $mood->store(); } //check if existing image exist, if yes, delete it $finalPath = $imagePath . '/mood_' . $mood->id . "." . $ext; if (file_exists($finalPath)) { unlink($finalPath); } //let move the tmp image to the actual path move_uploaded_file($moodImage['tmp_name'], $finalPath); require JPATH_ROOT . "/components/com_community/helpers/image.php"; CImageHelper::resizeProportional($finalPath, $finalPath, "image/{$ext}", 35, 35); } $mood->store(); $mood->message = $isNew ? JText::_('COM_COMMUNITY_MOODS_CREATED') : JText::_('COM_COMMUNITY_MOODS_UPDATED'); return $mood; }
/** * Method to add watermark on existing image. * * @param string $backgroundImagePath The path to the image that needs to be added with watermark. * @param string $destinationPath The path to the image output * @param string $destinationType The type of the output file * @param string $watermarkImagePath The path to the watermark image. * @param int $positionX The x position of where the watermark should be positioned. * @param int $positionY The y position of where the watermark should be positioned. * * @return bool True on sucess. * */ public static function addWatermark($backgroundImagePath, $destinationPath, $destinationType, $watermarkImagePath, $positionX = 0, $positionY = 0, $deleteBackgroundImage = true) { // Set output quality $config = CFactory::getConfig(); $imgQuality = $config->get('output_image_quality'); $pngQuality = ($imgQuality - 100) / 11.111111; $pngQuality = round(abs($pngQuality)); $watermarkInfo = getimagesize($watermarkImagePath); $background = CImageHelper::open($backgroundImagePath, $destinationType); $watermark = CImageHelper::open($watermarkImagePath, $watermarkInfo['mime']); list($backgroundWidth, $backgroundHeight) = getimagesize($backgroundImagePath); // Get overlay image width and hight $watermarkWidth = imagesx($watermark); $watermarkHeight = imagesy($watermark); // Combine background image and watermark into a single output image imagecopy($background, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight); // Output ob_start(); // Test if type is png if ($destinationType == 'image/png' || $destinationType == 'image/x-png') { imagepng($background, null, $pngQuality); } elseif ($destinationType == 'image/gif') { imagegif($background); } else { imagejpeg($background, null, $imgQuality); } $output = ob_get_contents(); ob_end_clean(); // Delete old image if (JFile::exists($backgroundImagePath) && $deleteBackgroundImage) { JFile::delete($backgroundImagePath); } // Free any memory from the existing image resources imagedestroy($background); imagedestroy($watermark); return JFile::write($destinationPath, $output); }
/** * Return path to thumb image */ public function getThumbAvatar() { // @rule: Check if the current user's watermark matches the current system's watermark. $multiprofile = JTable::getInstance('MultiProfile', 'CTable'); $match = $multiprofile->isHashMatched($this->_profile_id, $this->_watermark_hash); if (!$match) { // @rule: Since the admin may have changed the watermark for the specific user profile type, we need to also update // the user's watermark as well. //CFactory::load( 'helpers' , 'image' ); $hashName = CImageHelper::getHashName($this->id . time()); $multiprofile->updateUserAvatar($this, $hashName); $multiprofile->updateUserThumb($this, $hashName); } if (JString::stristr($this->_thumb, 'default_thumb.jpg')) { $this->_thumb = ''; } // For user avatars that are stored in a remote location, we should return the proper path. // @rule: For default avatars and watermark avatars we don't want to alter the url behavior. // as it should be stored locally. if ($this->_storage != 'file' && !empty($this->_thumb) && JString::stristr($this->_thumb, 'images/watermarks') === false) { $storage = CStorage::getStorage($this->_storage); return $storage->getURI($this->_thumb); } if ($this->_thumb && file_exists(JPATH_ROOT . '/' . $this->_thumb)) { return JUri::root() . $this->_thumb; } $gender = $this->_getGender('male'); if (!strlen($gender)) { $gender = 'undefined'; } $td_path = "default-{$gender}-avatar"; if (file_exists(COMMUNITY_PATH_ASSETS . $td_path . '.png')) { return JUri::root() . str_replace(JPATH_ROOT, '', COMMUNITY_PATH_ASSETS) . "{$td_path}.png"; } if (file_exists(COMMUNITY_PATH_ASSETS . $td_path . '.jpg')) { return JUri::root() . str_replace(JPATH_ROOT, '', COMMUNITY_PATH_ASSETS) . "{$td_path}.jpg"; } if ($gender == 'undefined') { $gender = 'male'; } $thumb = CUrlHelper::avatarURI($this->_thumb, 'user-' . ucfirst($gender) . '-thumb.png'); return $thumb; }
public function uploadAvatar() { $mainframe =& JFactory::getApplication(); $document =& JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view =& $this->getView($viewName, '', $viewType); $my =& JFactory::getUser(); $config = CFactory::getConfig(); $groupid = JRequest::getVar('groupid', '', 'REQUEST'); $data = new stdClass(); $data->id = $groupid; $groupsModel =& $this->getModel('groups'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupid); if ($my->id == 0) { return $this->blockUnregister(); } if (!$group->isAdmin($my->id) && !COwnerHelper::isCommunityAdmin()) { echo $view->noAccess(); return; } if (JRequest::getMethod() == 'POST') { CFactory::load('helpers', 'image'); $file = JRequest::getVar('filedata', '', 'FILES', 'array'); if (!CImageHelper::isValidType($file['type'])) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error'); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id . '&task=uploadAvatar', false)); } CFactory::load('libraries', 'apps'); $appsLib =& CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-uploadavatar')); if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { if (empty($file)) { $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error'); } else { $uploadLimit = (double) $config->get('maxuploadsize'); $uploadLimit = $uploadLimit * 1024 * 1024; // @rule: Limit image size based on the maximum upload allowed. if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE SIZE EXCEEDED'), 'error'); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=uploadavatar&groupid=' . $group->id, false)); } if (!CImageHelper::isValid($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error'); } else { // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); // @todo: configurable path for avatar storage? $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar' . DS . 'groups'; $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']); $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $image = $config->getString('imagefolder') . '/avatar/groups/' . $hashFileName . CImageHelper::getExtension($file['type']); $thumbnail = $config->getString('imagefolder') . '/avatar/groups/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); // Generate full image if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error'); } // Generate thumbnail if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error'); } // Update the group with the new image $groupsModel->setImage($groupid, $image, 'avatar'); $groupsModel->setImage($groupid, $thumbnail, 'thumb'); // @rule: only add the activities of the news if the group is not private. if ($group->approvals == COMMUNITY_PUBLIC_GROUP) { $url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid); $act = new stdClass(); $act->cmd = 'group.avatar.upload'; $act->actor = $my->id; $act->target = 0; $act->title = JText::sprintf('CC ACTIVITIES NEW GROUP AVATAR', '{group_url}', $group->name); $act->content = '<img src="' . rtrim(JURI::root(), '/') . '/' . $thumbnail . '" style="border: 1px solid #eee;margin-right: 3px;" />'; $act->app = 'groups'; $act->cid = $group->id; $params = new JParameter(''); $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id); CFactory::load('libraries', 'activities'); CActivityStream::add($act, $params->toString()); } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('group.avatar.upload'); $mainframe =& JFactory::getApplication(); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid, false), JText::_('CC GROUP AVATAR UPLOADED')); exit; } } } } echo $view->get(__FUNCTION__, $data); }
/** * Save the profile information */ public function apply() { CommunityLicenseHelper::_(); JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN')); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; if (JString::strtoupper($jinput->getMethod()) != 'POST') { $mainframe->redirect('index.php?option=com_community&view=themeprofile', JText::_('COM_COMMUNITY_PERMISSION_DENIED'), 'error'); } $settings = $jinput->post->get('settings', array(), 'array'); $configs = $jinput->post->get('config', null, 'array'); // save the config first $model = $this->getModel('Configuration'); if (!empty($configs)) { $model->save($configs); } // First, parse the Cover Info fields and unset the extra keys $helper = new CommunityThemeHelper(); $settings['tagline'] = $helper->prepareCoverInfo($settings); // Handle image uploads #echo "<pre>";var_dump($post);die(); $images['default-cover'] = $jinput->files->get('default-cover-new', '', 'NONE'); $images['default-cover-male'] = $jinput->files->get('default-cover-male-new', '', 'NONE'); $images['default-cover-female'] = $jinput->files->get('default-cover-female-new', '', 'NONE'); $images['default-male-avatar'] = $jinput->files->get('default-male-avatar-new', '', 'NONE'); $images['default-female-avatar'] = $jinput->files->get('default-female-avatar-new', '', 'NONE'); $images['default-general-avatar'] = $jinput->files->get('default-general-avatar-new', '', 'NONE'); foreach ($images as $key => $image) { if (!empty($image['tmp_name']) && isset($image['name']) && !empty($image['name'])) { try { CImageHelper::autorotate($image['tmp_name']); } catch (Exception $e) { } $imagePath = COMMUNITY_PATH_ASSETS; // same as the image path //check the file extension first and only allow jpg or png $ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION)); if (!in_array($ext, array('jpg', 'jpeg', 'png')) || $image['type'] != 'image/png' && $image['type'] != 'image/jpeg') { $mainframe->redirect('index.php?option=com_community&view=themeprofile', JText::_('COM_COMMUNITY_THEME_IMAGE_ERROR'), 'error'); } $imageJpg = $imagePath . '/' . $key . '.jpg'; $imagePng = $imagePath . '/' . $key . '.png'; //check if existing image exist, if yes, delete it if (file_exists($imageJpg)) { unlink($imageJpg); } if (file_exists($imagePng)) { unlink($imagePng); } //let move the tmp image to the actual path $finalPath = $imagePath . $key . '.' . $ext; $finalPathThumb = $imagePath . $key . '-thumb.' . $ext; move_uploaded_file($image['tmp_name'], $finalPath); require_once JPATH_ROOT . "/components/com_community/helpers/image.php"; if (strstr($key, 'avatar')) { //avatars // Check 1:1 $size = CImageHelper::getSize($finalPath); if ($size->height != $size->width) { $message = JTEXT::_('COM_COMMUNITY_THEME_AVATAR_RESIZED'); } CImageHelper::resize($finalPath, $finalPath, "image/{$ext}", 160, 160); // thumb CImageHelper::resize($finalPath, $finalPathThumb, "image/{$ext}", 64, 64); } else { // other images CImageHelper::resizeProportional($finalPath, $finalPath, "image/{$ext}", 1000, 1000); } $settings[$key] = $ext; } } // Parse the rest of the settings afterwards $helper->parseSettings($settings, 'profile'); // There isn't much that can go wrong, no validation required if (!$message) { $message = JText::_('COM_COMMUNITY_THEME_PROFILE_UPDATED'); } $mainframe->redirect('index.php?option=com_community&view=themeprofile', $message, 'message'); }
public function save($data = array()) { jimport('joomla.filesystem.file'); //CFactory::load('helpers', 'string'); $config = JTable::getInstance('configuration', 'CommunityTable'); $config->load('config'); $config->name = 'config'; $params = new JRegistry($config->params); $postData = count($data) > 0 ? $data : JRequest::get('post', 2); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $session = JFactory::getSession(); $token = $session->getFormToken(false); unset($postData[$token]); foreach ($postData as $key => $value) { echo $key . ' = ' . $value . '<br/>'; if ($key != 'task' && $key != 'option' && $key != 'view' && $key != $token) { $params->set($key, $value); } } //@since 4.1, storing watermark for normal photo $watermark = $jinput->files->get('watermark', '', 'NONE'); if (!empty($watermark['tmp_name'])) { // Do not allow image size to exceed maximum width and height if (isset($watermark['name']) && !empty($watermark['name'])) { list($width, $height) = getimagesize($watermark['tmp_name']); /** * watermark can't large than 16px * @todo use define for min width & height instead fixed number here */ $validated = false; //watermark must be png if (CImageHelper::getExtension($watermark['type']) == '.png') { $validated = true; } else { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error'); } if ($validated) { // @rule: Create original folder within watermarks to store original user photos. if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) { if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER')); } } //move the watermark photo to the folder $watermarkFile = WATERMARK_DEFAULT_NAME . CImageHelper::getExtension($watermark['type']); JFile::copy($watermark['tmp_name'], JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $watermarkFile); } } } $config->params = $params->toString(); // Save it if (!$config->store()) { return false; } return true; }
public function store() { CommunityLicenseHelper::_(); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; if (JString::strtoupper($jinput->getMethod()) != 'POST') { $mainframe->redirect('index.php?option=com_community&view=badges', JText::_('COM_COMMUNITY_PERMISSION_DENIED'), 'error'); } $badge = JTable::getInstance('Badges', 'CommunityTable'); $badge->load(JRequest::getInt('badgeid')); $badge->title = $jinput->post->get('title', '', 'STRING'); $badge->published = $jinput->post->get('published', '', 'NONE'); $badge->points = $jinput->post->get('points', '', 'INT'); $isNew = $badge->id < 1; // handle image upload $badgeImage = $jinput->files->get('badge_image', '', 'NONE'); if (!empty($badgeImage['tmp_name']) && isset($badgeImage['name']) && !empty($badgeImage['name'])) { $imagePath = COMMUNITY_PATH_ASSETS; // same as the image path //check the file extension first and only allow jpg or png $ext = strtolower(pathinfo($badgeImage['name'], PATHINFO_EXTENSION)); if (!in_array($ext, array('jpg', 'png')) || $badgeImage['type'] != 'image/png' && $badgeImage['type'] != 'image/jpeg') { $mainframe->redirect('index.php?option=com_community&view=badges&layout=edit&id=' . $badge->id, JText::_('COM_COMMUNITY_BADGES_PARAMETERS_SAVE_ERROR'), 'error'); } else { $badge->image = $ext; $badge->store(); } $finalPath = COMMUNITY_PATH_ASSETS . "badge_" . $badge->id . ".{$ext}"; //check if existing image exist, if yes, delete it if (file_exists($finalPath)) { unlink($finalPath); } //let move the tmp image to the actual path move_uploaded_file($badgeImage['tmp_name'], $finalPath); $imgHeight = imagesx($finalPath); $imgWidth = imagesy($finalPath); if ($imgHeight >= 256 && $imgWidth >= 256) { //only resize if the width or height is larger require JPATH_ROOT . "/components/com_community/helpers/image.php"; CImageHelper::resizeProportional($finalPath, $finalPath, "image/{$ext}", 256, 256); } } $badge->store(); $badge->message = $isNew ? JText::_('COM_COMMUNITY_BADGES_CREATED') : JText::_('COM_COMMUNITY_BADGES_UPDATED'); return $badge; }
public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark) { $image = ''; if (!empty($avatarUrl)) { // Make sure user is properly added into the database table first $user = CFactory::getUser($joomlaUserId); $fbUser = $this->getUser(); // Store image on a temporary folder. $tmpPath = JPATH_ROOT . '/images/originalphotos/facebook_connect_' . $fbUser; // Need to extract the non-https version since it will cause // certificate issue $avatarUrl = str_replace('https://', 'http://', $avatarUrl); $source = CRemoteHelper::getContent($avatarUrl, true); list($headers, $source) = explode("\r\n\r\n", $source, 2); JFile::write($tmpPath, $source); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JApplication::getHash($fbUser . time()); $hashFileName = JString::substr($fileName, 0, 24); $uri_parts = explode('?', $avatarUrl, 2); $extension = JString::substr($uri_parts[0], JString::strrpos($uri_parts[0], '.')); $type = 'image/jpg'; if ($extension == '.png') { $type = 'image/png'; } if ($extension == '.gif') { $type = 'image/gif'; } //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar'; $storageImage = $storage . '/' . $hashFileName . $extension; $storageThumbnail = $storage . '/thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth); CImageHelper::createThumb($tmpPath, $storageThumbnail, $type); if ($addWaterMark) { // Get the width and height so we can calculate where to place the watermark. list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON); list($imageWidth, $imageHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight); CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight); } // Update the CUser object with the correct avatar. $user->set('_thumb', $thumbnail); $user->set('_avatar', $image); // @rule: once user changes their profile picture, storage method should always be file. $user->set('_storage', 'file'); $userModel->setImage($joomlaUserId, $image, 'avatar'); $userModel->setImage($joomlaUserId, $thumbnail, 'thumb'); $user->save(); } }
/** * Upload a new user avatar */ public function uploadAvatar() { CFactory::setActiveProfile(); jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); $view =& $this->getView('profile'); CFactory::load('helpers', 'image'); $my = CFactory::getUser(); if ($my->id == 0) { return $this->blockUnregister(); } // If uplaod is detected, we process the uploaded avatar if (JRequest::getVar('action', '', 'POST')) { $mainframe =& JFactory::getApplication(); $file = JRequest::getVar('Filedata', '', 'FILES', 'array'); $userid = $my->id; if (JRequest::getVar('userid', '', 'POST') != '') { $userid = JRequest::getInt('userid', '', 'POST'); $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid); } if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error'); if (isset($url)) { $mainframe->redirect($url); } } else { $config = CFactory::getConfig(); $uploadLimit = (double) $config->get('maxuploadsize'); $uploadLimit = $uploadLimit * 1024 * 1024; // @rule: Limit image size based on the maximum upload allowed. if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE SIZE EXCEEDED'), 'error'); if (isset($url)) { $mainframe->redirect($url); } $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false)); } if (!CImageHelper::isValidType($file['type'])) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error'); if (isset($url)) { $mainframe->redirect($url); } $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false)); } if (!CImageHelper::isValid($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error'); if (isset($url)) { $mainframe->redirect($url); } } else { // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $profileType = $my->getProfileType(); $fileName = JUtility::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); $multiprofile =& JTable::getInstance('MultiProfile', 'CTable'); $multiprofile->load($profileType); $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false; //@todo: configurable path for avatar storage? $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar'; $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']); $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']); $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error'); if (isset($url)) { $mainframe->redirect($url); } } // Generate thumbnail if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) { $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error'); if (isset($url)) { $mainframe->redirect($url); } } if ($useWatermark) { // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar, // it will be able to grab the original picture. JFile::copy($storageImage, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type'])); JFile::copy($storageThumbnail, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type'])); $watermarkPath = JPATH_ROOT . DS . JString::str_ireplace('/', DS, $multiprofile->watermark); list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); list($avatarWidth, $avatarHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); $watermarkImage = $storageImage; $watermarkThumbnail = $storageThumbnail; // Avatar Properties $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight); // The original image file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageImage, $watermarkImage, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y); //Thumbnail Properties $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); // The original thumbnail file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, 'image/jpg', $watermarkPath, $thumbPosition->x, $thumbPosition->y); $my->set('_watermark_hash', $multiprofile->watermark_hash); $my->save(); } $userModel->setImage($userid, $image, 'avatar'); $userModel->setImage($userid, $thumbnail, 'thumb'); // Update the user object so that the profile picture gets updated. $my->set('_avatar', $image); $my->set('_thumb', $thumbnail); // @rule: once user changes their profile picture, storage method should always be file. $my->set('_storage', 'file'); if (isset($url)) { $mainframe->redirect($url); } //add user points CFactory::load('libraries', 'userpoints'); CFactory::load('libraries', 'activities'); $act = new stdClass(); $act->cmd = 'profile.avatar.upload'; $act->actor = $userid; $act->target = 0; $act->title = JText::_('CC ACTIVITIES NEW AVATAR'); $act->content = ''; $act->app = 'profile'; $act->cid = 0; // Add activity logging CFactory::load('libraries', 'activities'); CActivityStream::add($act); CUserPoints::assignPoint('profile.avatar.upload'); } } } echo $view->get(__FUNCTION__); }
public function ajaxRotateAvatar($type, $id, $direction = 'right') { $my = CFactory::getUser(); if ($my->id == 0) { return $this->blockUnregister(); } if (!(COwnerHelper::isCommunityAdmin() || $my->id == $id)) { $json = array('error' => JText::_('Forbidden access.')); die(json_encode($json)); } $config = CFactory::getConfig(); $avatar = $my->get('_avatar'); if (!$avatar) { $json = array('error' => JText::_('Avatar not set.')); die(json_encode($json)); } $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar/'; $avatarFilename = $storage . basename($avatar); $cropperFilename = $storage . 'profile-' . basename($avatar); if ($direction === 'left') { $direction = 90; } else { $direction = -90; } CImageHelper::rotate($avatarFilename, $avatarFilename, $direction); CImageHelper::rotate($cropperFilename, $cropperFilename, $direction); $json = array('success' => true, 'avatar' => JURI::root(true) . '/' . $avatar); die(json_encode($json)); }
/** * Return path to thumb image */ public function getThumbAvatar() { // @rule: Check if the current user's watermark matches the current system's watermark. $multiprofile =& JTable::getInstance('MultiProfile', 'CTable'); $match = $multiprofile->isHashMatched($this->_profile_id, $this->_watermark_hash); if (!$match) { // @rule: Since the admin may have changed the watermark for the specific user profile type, we need to also update // the user's watermark as well. CFactory::load('helpers', 'image'); $hashName = CImageHelper::getHashName($this->id . time()); $multiprofile->updateUserAvatar($this, $hashName); $multiprofile->updateUserThumb($this, $hashName); } if (JString::stristr($this->_thumb, 'default_thumb.jpg')) { $this->_thumb = ''; } // For user avatars that are stored in a remote location, we should return the proper path. // @rule: For default avatars and watermark avatars we don't want to alter the url behavior. // as it should be stored locally. if ($this->_storage != 'file' && !empty($this->_thumb) && JString::stristr($this->_thumb, 'images/watermarks') === false) { $storage = CStorage::getStorage($this->_storage); return $storage->getURI($this->_thumb); } CFactory::load('helpers', 'url'); $thumb = CUrlHelper::avatarURI($this->_thumb, 'user_thumb.png'); return $thumb; }
/** * Method to add watermark on existing image. * * @param string $backgroundImagePath The path to the image that needs to be added with watermark. * @param string $destinationPath The path to the image output * @param string $destinationType The type of the output file * @param string $watermarkImagePath The path to the watermark image. * @param int $positionX The x position of where the watermark should be positioned. * @param int $positionY The y position of where the watermark should be positioned. * * @return bool True on sucess. **/ public static function addWatermark($backgroundImagePath, $destinationPath, $destinationType, $watermarkImagePath, $positionX = 0, $positionY = 0, $deleteBackgroundImage = true) { $watermarkInfo = getimagesize($watermarkImagePath); $background = CImageHelper::open($backgroundImagePath, $destinationType); $watermark = CImageHelper::open($watermarkImagePath, $watermarkInfo['mime']); list($backgroundWidth, $backgroundHeight) = getimagesize($backgroundImagePath); // Try to make the watermark image transparent imagecolortransparent($watermark, imagecolorat($watermark, 0, 0)); // Get overlay image width and hight $watermarkWidth = imagesx($watermark); $watermarkHeight = imagesy($watermark); // Combine background image and watermark into a single output image imagecopymerge($background, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight, 100); // Output ob_start(); // Test if type is png if ($destinationType == 'image/png' || $destinationType == 'image/x-png') { imagepng($background); } elseif ($destinationType == 'image/gif') { imagegif($background); } else { imagejpeg($background, null, 80); } $output = ob_get_contents(); ob_end_clean(); // Delete old image if (JFile::exists($backgroundImagePath) && $deleteBackgroundImage) { JFile::delete($backgroundImagePath); } // Free any memory from the existing image resources imagedestroy($background); imagedestroy($watermark); return JFile::write($destinationPath, $output); }
public function saveAvatarFromURL($url) { $tmpPath = JPATH_ROOT . DS . 'images'; $my = CFactory::getUser(); // Need to extract the non-https version since it will cause // certificate issue $avatarUrl = str_replace('https://', 'http://', $url); CFactory::load('helpers', 'remote'); $source = CRemoteHelper::getContent($url, true); JFile::write($tmpPath, $source); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($my->getDisplayName() . time()); $hashFileName = JString::substr($fileName, 0, 24); $extension = JString::substr($url, JString::strrpos($url, '.')); $type = 'image/jpg'; if ($extension == '.png') { $type = 'image/png'; } if ($extension == '.gif') { $type = 'image/gif'; } //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar'; $storageImage = $storage . DS . $hashFileName . $extension; $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth); CImageHelper::createThumb($tmpPath, $storageThumbnail, $type); $removeOldImage = false; $userModel->setImage($my->id, $image, 'avatar', $removeOldImage); $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage); // Update the user object so that the profile picture gets updated. $my->set('_avatar', $image); $my->set('_thumb', $thumbnail); return true; }
private function _updateUserWatermark($user, $type, $hashName) { $config = CFactory::getConfig(); $oldAvatar = $user->_avatar; // @rule: This is the original avatar path //CFactory::load( 'helpers' , 'image' ); $userImageType = '_' . $type; $data = @getimagesize(JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $user->{$userImageType})); $original = JPATH_ROOT . '/images/watermarks/original' . '/' . md5($user->id . '_' . $type) . CImageHelper::getExtension($data['mime']); if (!$config->get('profile_multiprofile') || !JFile::exists($original)) { return false; } static $types = array(); if (empty($types)) { $model = CFactory::getModel('Profile'); $rows = $model->getProfileTypes(); if ($rows) { foreach ($rows as $row) { $types[$row->id] = $row; } } } $model = CFactory::getModel('User'); if (isset($types[$user->_profile_id])) { // Bind the data to the current object so we can access it here. $this->bind($types[$user->_profile_id]); // Path to the watermark image. $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $this->watermark); // Retrieve original image info $originalData = getimagesize($original); // Generate image file name. $fileName = $type == 'thumb' ? 'thumb_' : ''; $fileName .= $hashName; $fileName .= CImageHelper::getExtension($originalData['mime']); // Absolute path to the image (local) $newImagePath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $fileName; // Relative path to the image (uri) $newImageUri = $config->getString('imagefolder') . '/avatar/' . $fileName; // Retrieve the height and width for watermark and original image. list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); list($originalWidth, $originalHeight) = getimagesize($original); // Retrieve the proper coordinates to the watermark location $position = CImageHelper::getPositions($this->watermark_location, $originalWidth, $originalHeight, $watermarkWidth, $watermarkHeight); // Create the new image with the watermarks. CImageHelper::addWatermark($original, $newImagePath, $originalData['mime'], $watermarkPath, $position->x, $position->y, false); $model->setImage($user->id, $newImageUri, $type); // Remove the user's old image $oldFile = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $user->{$userImageType}); if (JFile::exists($oldFile)) { JFile::delete($oldFile); } if ($type == 'avatar') { $oldImg = explode('avatar/', $oldAvatar); $oldImg = explode('.', $oldImg[1]); $oldImg = $config->getString('imagefolder') . '/avatar/' . $oldImg[0] . '_stream_.' . $oldImg[1]; JFile::copy($newImageUri, $oldImg); } // We need to update the property in CUser as well otherwise when we save the hash, it'll // use the old user avatar. $user->set($userImageType, $newImageUri); // We need to restore the storage method. $user->set('_storage', 'file'); // Update the watermark hash with the latest hash $user->set('_watermark_hash', $this->watermark_hash); $user->save(); } return true; }
public function ajaxRotatePhoto($photoId, $orientation) { CFactory::load('helpers', 'owner'); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $photo =& JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); if ($photo->storage != 'file') { // we don't want to support s3 return false; } if ($photo->storage != 'file') { // download the image files to local server CFactory::load('libraries', 'storage'); $storage = CStorage::getStorage($photoStorage); $currentStorage = CStorage::getStorage($photo->storage); if ($currentStorage->exists($photo->image)) { $jconfig = JFactory::getConfig(); $jTempPath = $jconfig->getValue('tmp_path'); $tempFilename = $jTempPath . DS . md5($photo->image); $currentStorage->get($photo->image, $tempFilename); $thumbsTemp = $jTempPath . DS . 'thumb_' . md5($photo->thumbnail); $currentStorage->get($photo->thumbnail, $thumbsTemp); if (JFile::exists($tempFilename) && JFile::exists($thumbsTemp) && $storage->put($row->image, $tempFilename) && $storage->put($photo->thumbnail, $thumbsTemp)) { $currentStorage->delete($photo->image); $currentStorage->delete($photo->thumbnail); JFile::delete($tempFilename); JFile::delete($thumbsTemp); } } } $photoPath = JPath::clean(JPATH_ROOT . DS . $photo->image); $thumbPath = JPath::clean(JPATH_ROOT . DS . $photo->thumbnail); // Hash the image file name so that it gets as unique possible $fileName = JUtility::getHash($photo->image . time()); $fileName = JString::substr($fileName, 0, 24); $fileName = $fileName . '.' . JFile::getExt($photo->image); $fileNameLength = strlen($photo->image) - strrpos($photo->image, '/') - 1; $newPhotoPath = substr_replace($photoPath, $fileName, -$fileNameLength); $newThumbPath = substr_replace($photoPath, 'thumb_' . $fileName, -$fileNameLength); $degrees = 0; if (JFile::exists($photoPath) && JFile::exists($thumbPath)) { switch ($orientation) { case 'left': $degrees = 90; break; case 'right': $degrees = -90; break; default: $degrees = 0; break; } if ($degrees !== 0) { CFactory::load('helpers', 'image'); CImageHelper::rotate($photoPath, $newPhotoPath, $degrees); CImageHelper::rotate($thumbPath, $newThumbPath, $degrees); $newPhotoPath = JString::str_ireplace(JPATH_ROOT . DS, '', $newPhotoPath); $newThumbPath = JString::str_ireplace(JPATH_ROOT . DS, '', $newThumbPath); $newPhotoPath = JString::str_ireplace('\\', '/', $newPhotoPath); $newThumbPath = JString::str_ireplace('\\', '/', $newThumbPath); $photo->storage = 'file'; //just to make sure it's in the local server $photo->image = $newPhotoPath; $photo->thumbnail = $newThumbPath; $photo->store(); } } $response = new JAXResponse(); $response->addScriptCall('__callback', $photo->id, $photo->getImageURI(), $photo->getThumbURI()); return $response->sendResponse(); }
public static function fromContent($content) { $urls = self::fetchUrlsFromContent($content); /** * Crawle data * We only work with first url */ if (count($urls) > 0) { $url = array_shift($urls); $curl = new CCurl(); $header = $curl->getHeaderOnly($url); if (strpos($header['Content-Type'], ';') !== false) { $header = explode(';', $header['Content-Type']); $header = trim($header[0]); } else { $header = $header['Content-Type']; } switch ($header) { case 'text/html': /* now we do curl again to get body */ /** * @todo Somehow it's bug here that incorrect body content */ //$curl->setCurl(CURLOPT_HEADER); /* ya don't need header again */ $response = $curl->get($url); $body = $response->getBody(); /* get meta object */ $metasParser = new CParserMetas(); $metasParser->setContent($body); $graphObject = $metasParser->extract(); /* Do image fetch into local and resize */ $images = $graphObject->get('image'); /** * @todo allow config save dir */ if (is_array($images)) { $saveDir = JPATH_ROOT . '/images/community/activities'; /* Create save dir if not exists */ if (!JFolder::exists($saveDir)) { JFolder::create($saveDir); } /* Do copy into local */ $localImages = array(); foreach ($images as $image) { /* Hashing remote image url to use as fileName */ $localFileName = md5($image); /* Get file extension */ $locaFileExt = JFile::getExt($image); /* Generate local filename from hashed and extesion */ $localFile = $localFileName . '.' . $locaFileExt; /* Local thumbnail filename by adding _thumb */ $localThumbFile = $localFileName . '_thumb.' . $locaFileExt; /* Do save local */ copy($image, $saveDir . '/' . $localFile); /* Get image file informantion */ $info = getimagesize($saveDir . '/' . $localFile); /* Get image type than use it to createThumb */ $imgType = image_type_to_mime_type($info[2]); /* Do make thumb */ CImageHelper::createThumb($saveDir . '/' . $localFile, $saveDir . '/' . $localThumbFile, $imgType); $localImages[] = array('image' => $localFile, 'thumb' => $localThumbFile); } /* Save back */ $graphObject->set('localImages', $localImages); } return $graphObject; break; default: break; } } }
/** * If remote storage is used, transfer some files to the remote storage * - fetch file from current storage to a temp location * - put file from temp to new storage * - delete file from old storage */ public function _processPhotoStorage($updateNum = 5) { $config = CFactory::getConfig(); $jconfig = JFactory::getConfig(); $photoStorage = $config->getString('photostorage'); CFactory::load('models', 'photos'); CFactory::load('libraries', 'storage'); CFactory::load('helpers', 'image'); $fileTranferCount = 0; $storage = CStorage::getStorage($photoStorage); $db =& JFactory::getDBO(); // @todo, we nee to find a way to make sure that we transfer most of // our photos remotely $sql = 'SELECT * FROM ' . $db->nameQuote('#__community_photos') . ' WHERE ' . $db->nameQuote('storage') . '!=' . $db->Quote($photoStorage) . ' AND ' . $db->nameQuote('albumid') . '!=' . $db->Quote(0) . ' ORDER BY rand() limit ' . $updateNum; $db->setQuery($sql); $result = $db->loadObjectList(); if (!$result) { $this->message[] = JText::_('No files to transfer.'); return; } foreach ($result as $row) { $currentStorage = CStorage::getStorage($row->storage); // If current storage is file based, create the image since we might not have them yet if ($row->storage == 'file' && !JFile::exists(JPATH_ROOT . DS . $row->image)) { // resize the original image to a smaller viewable version $this->message[] = 'Image file missing. Creating image file.'; // make sure original file exist if (JFile::exists(JPATH_ROOT . DS . $row->original)) { $displyWidth = $config->getInt('photodisplaysize'); $info = getimagesize(JPATH_ROOT . DS . $row->original); $imgType = image_type_to_mime_type($info[2]); $width = $info[0] < $displyWidth ? $info[0] : $displyWidth; CImageHelper::resizeProportional(JPATH_ROOT . DS . $row->original, JPATH_ROOT . DS . $row->image, $imgType, $width); } else { $this->message[] = 'Original file is missing!!'; } } // If it exist on current storage, we can transfer it to preferred storage if ($currentStorage->exists($row->image) && $currentStorage->exists($row->thumbnail)) { // File exist on remote storage, move it locally first $tempFilename = $jconfig->getValue('tmp_path') . DS . md5($row->image); $currentStorage->get($row->image, $tempFilename); $thumbsTemp = $jconfig->getValue('tmp_path') . DS . 'thumb_' . md5($row->thumbnail); $currentStorage->get($row->thumbnail, $thumbsTemp); if (JFile::exists($tempFilename) && JFile::exists($thumbsTemp)) { // we assume thumbnails is always there // put both image and thumbnails remotely if ($storage->put($row->image, $tempFilename) && $storage->put($row->thumbnail, $thumbsTemp)) { // if the put is successful, update storage type $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($row->id); $photo->storage = $photoStorage; $photo->store(); $currentStorage->delete($row->image); $currentStorage->delete($row->thumbnail); // remove temporary file JFile::delete($tempFilename); JFile::delete($thumbsTemp); $fileTranferCount++; } } } } $this->message[] = $fileTranferCount . ' files transferred.'; }
/** * Process Uploaded Photo Cover * @return [JSON OBJECT] [description] */ public function ajaxCoverUpload() { $jinput = JFactory::getApplication()->input; $parentId = $jinput->get->get('parentId', null, 'Int'); $type = strtolower($jinput->get->get('type', null, 'String')); $file = $jinput->files->get('uploadCover'); $config = CFactory::getConfig(); $my = CFactory::getUser(); $now = new JDate(); $addStream = true; if (!CImageHelper::checkImageSize(filesize($file['tmp_name']))) { $msg['error'] = JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')); echo json_encode($msg); exit; } //check if file is allwoed if (!CImageHelper::isValidType($file['type'])) { $msg['error'] = JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'); echo json_encode($msg); exit; } CImageHelper::autoRotate($file['tmp_name']); $album = JTable::getInstance('Album', 'CTable'); if (!($albumId = $album->isCoverExist($type, $parentId))) { $albumId = $album->addCoverAlbum($type, $parentId); } $imgMaxWidht = 1140; // Get a hash for the file name. $fileName = JApplication::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); if (!JFolder::exists(JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/')) { JFolder::create(JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/'); } $dest = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/' . md5($type . '_cover' . time()) . CImageHelper::getExtension($file['type']); $thumbPath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/thumb_' . md5($type . '_cover' . time()) . CImageHelper::getExtension($file['type']); // Generate full image if (!CImageHelper::resizeProportional($file['tmp_name'], $dest, $file['type'], $imgMaxWidht)) { $msg['error'] = JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage); echo json_encode($msg); exit; } CPhotos::generateThumbnail($file['tmp_name'], $thumbPath, $file['type']); $cTable = JTable::getInstance(ucfirst($type), 'CTable'); $cTable->load($parentId); if ($cTable->setCover(str_replace(JPATH_ROOT . '/', '', $dest))) { $photo = JTable::getInstance('Photo', 'CTable'); $photo->albumid = $albumId; $photo->image = str_replace(JPATH_ROOT . '/', '', $dest); $photo->caption = $file['name']; $photo->filesize = $file['size']; $photo->creator = $my->id; $photo->created = $now->toSql(); $photo->published = 1; $photo->thumbnail = str_replace(JPATH_ROOT . '/', '', $thumbPath); if ($photo->store()) { $album->load($albumId); $album->photoid = $photo->id; $album->store(); } $msg['success'] = true; $msg['path'] = JURI::root() . str_replace(JPATH_ROOT . '/', '', $dest); $msg['cancelbutton'] = JText::_('COM_COMMUNITY_CANCEL_BUTTON'); $msg['savebutton'] = JText::_("COM_COMMUNITY_SAVE_BUTTON"); // Generate activity stream. $act = new stdClass(); $act->cmd = 'cover.upload'; $act->actor = $my->id; $act->target = 0; $act->title = ''; $act->content = ''; $act->access = $type == 'profile' ? $my->_cparams->get("privacyPhotoView") : 0; $act->app = 'cover.upload'; $act->cid = $photo->id; $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'cover.upload'; $act->groupid = $type == 'group' ? $parentId : 0; $act->eventid = $type == 'event' ? $parentId : 0; $act->group_access = $type == 'group' ? $cTable->approvals : 0; $act->event_access = $type == 'event' ? $cTable->permission : 0; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'cover.upload'; $params = new JRegistry(); $params->set('attachment', str_replace(JPATH_ROOT . '/', '', $dest)); $params->set('type', $type); $params->set('album_id', $albumId); $params->set('photo_id', $photo->id); //assign points based on types. switch ($type) { case 'group': $addStream = CUserPoints::assignPoint('group.cover.upload'); break; case 'event': $addStream = CUserPoints::assignPoint('event.cover.upload'); break; default: $addStream = CUserPoints::assignPoint('profile.cover.upload'); } if ($type == 'event') { $event = JTable::getInstance('Event', 'CTable'); $event->load($parentId); $group = JTable::getInstance('Group', 'CTable'); $group->load($event->contentid); if ($group->approvals == 1) { $addStream = false; } } if ($addStream) { // Add activity logging if ($type != 'profile' || $type == 'profile' && $parentId == $my->id) { CActivityStream::add($act, $params->toString()); } } echo json_encode($msg); exit; } }
public function uploadAvatar() { $mainframe =& JFactory::getApplication(); $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view =& $this->getView($viewName, '', $viewType); $eventid = JRequest::getInt('eventid', '0', 'REQUEST'); $model =& $this->getModel('events'); $event =& JTable::getInstance('Event', 'CTable'); $event->load($eventid); CFactory::load('helpers', 'event'); $handler = CEventHelper::getHandler($event); if (!$handler->manageable()) { echo JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN'); return; } if (JRequest::getMethod() == 'POST') { JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN')); CFactory::load('libraries', 'apps'); $my = CFactory::getUser(); $config = CFactory::getConfig(); $appsLib =& CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-events-uploadavatar')); if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { CFactory::load('helpers', 'image'); $file = JRequest::getVar('filedata', '', 'FILES', 'array'); if (!CImageHelper::isValidType($file['type'])) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error'); $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id . '&task=uploadAvatar', false)); } if (empty($file)) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error'); } else { $uploadLimit = (double) $config->get('maxuploadsize'); $uploadLimit = $uploadLimit * 1024 * 1024; // @rule: Limit image size based on the maximum upload allowed. if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED'), 'error'); $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false)); } if (!CImageHelper::isValid($file['tmp_name'])) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error'); $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false)); } else { // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); // @todo: configurable path for avatar storage? $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar' . DS . 'events'; $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']); $image = $config->getString('imagefolder') . '/avatar/events/' . $hashFileName . CImageHelper::getExtension($file['type']); $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $thumbnail = $config->getString('imagefolder') . '/avatar/events/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); // Generate full image if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error'); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false)); } // Generate thumbnail if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error'); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false)); } // Update the event with the new image $event->setImage($image, 'avatar'); $event->setImage($thumbnail, 'thumb'); CFactory::load('helpers', 'event'); $handler = CEventHelper::getHandler($event); if ($handler->isPublic()) { $actor = $my->id; $target = 0; $content = '<img class="event-thumb" src="' . rtrim(JURI::root(), '/') . '/' . $image . '" style="border: 1px solid #eee;margin-right: 3px;" />'; $cid = $event->id; $app = 'events'; $act = $handler->getActivity('events.avatar.upload', $actor, $target, $content, $cid, $app); $act->eventid = $event->id; $params = new CParameter(''); $params->set('event_url', $handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false, true, false)); CFactory::load('libraries', 'activities'); CActivityStream::add($act, $params->toString()); } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('event.avatar.upload'); //$this->cacheClean( array(COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_FRONTPAGE,COMMUNITY_CACHE_TAG_ACTIVITIES) ); $mainframe =& JFactory::getApplication(); $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $eventid, false), JText::_('COM_COMMUNITY_EVENTS_AVATAR_UPLOADED')); exit; } } } } echo $view->get(__FUNCTION__); }