Exemplo n.º 1
0
 /**
  *  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');
 }
Exemplo n.º 2
0
 public function uploadAvatar()
 {
     $mainframe = JFactory::getApplication();
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $jinput = $mainframe->input;
     $viewName = $jinput->get('view', $this->getName(), 'String');
     $view = $this->getView($viewName, '', $viewType);
     $eventid = $jinput->request->get('eventid', 0, 'Int');
     $model = $this->getModel('events');
     $event = JTable::getInstance('Event', 'CTable');
     $event->load($eventid);
     $handler = CEventHelper::getHandler($event);
     if (!$handler->manageable()) {
         echo JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN');
         return;
     }
     if ($jinput->getMethod() == 'POST') {
         JSession::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' );
             $fileFilter = new JInput($_FILES);
             $file = $fileFilter->get('filedata', '', '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::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), '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 {
                     CImageHelper::autorotate($file['tmp_name']);
                     // @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?
                     $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar/events';
                     $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $image = $config->getString('imagefolder') . '/avatar/events/' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $storageThumbnail = $storage . '/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));
                     }
                     // Autorotate avatar based on EXIF orientation value
                     if ($file['type'] == 'image/jpeg') {
                         $orientation = CImageHelper::getOrientation($file['tmp_name']);
                         CImageHelper::autoRotate($storageImage, $orientation);
                         CImageHelper::autoRotate($storageThumbnail, $orientation);
                     }
                     // Update the event with the new image
                     $event->setImage($image, 'avatar');
                     $event->setImage($thumbnail, 'thumb');
                     $handler = CEventHelper::getHandler($event);
                     if ($handler->isPublic()) {
                         $actor = $my->id;
                         $target = 0;
                         $content = '<img class="event-thumb" src="' . JURI::root(true) . '/' . $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));
                         CActivityStream::add($act, $params->toString());
                     }
                     //add user points
                     CUserPoints::assignPoint('event.avatar.upload');
                     $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__);
 }