Ejemplo n.º 1
0
 public function renderFeature()
 {
     //Retina Image
     if ($this->helix3->getParam('logo_type') == 'image') {
         jimport('joomla.image.image');
         if ($this->helix3->getParam('logo_image')) {
             $path = JPATH_ROOT . '/' . $this->helix3->getParam('logo_image');
         } else {
             $path = JPATH_ROOT . '/templates/' . $this->helix3->getTemplate() . '/images/presets/' . $this->helix3->Preset() . '/logo.png';
         }
         if (file_exists($path)) {
             $image = new JImage($path);
             $width = $image->getWidth();
             $height = $image->getHeight();
         } else {
             $width = '';
             $height = '';
         }
     }
     $html = '';
     $custom_logo_class = '';
     $sitename = JFactory::getApplication()->get('sitename');
     if ($this->helix3->getParam('mobile_logo')) {
         $custom_logo_class = ' hidden-xs';
     }
     $html .= '<a class="logo" href="' . JURI::base(true) . '/">';
     if ($this->helix3->getParam('logo_type') == 'image') {
         if ($this->helix3->getParam('logo_image')) {
             $html .= '<div>';
             $html .= '<img class="sp-default-logo' . $custom_logo_class . '" src="' . $this->helix3->getParam('logo_image') . '" alt="' . $sitename . '">';
             if ($this->helix3->getParam('logo_image_2x')) {
                 $html .= '<img class="sp-retina-logo' . $custom_logo_class . '" src="' . $this->helix3->getParam('logo_image_2x') . '" alt="' . $sitename . '" width="' . $width . '" height="' . $height . '">';
             }
             if ($this->helix3->getParam('mobile_logo')) {
                 $html .= '<img class="sp-default-logo visible-xs" src="' . $this->helix3->getParam('mobile_logo') . '" alt="' . $sitename . '">';
             }
             $html .= '</div>';
         } else {
             $html .= '<div>';
             $html .= '<img class="sp-default-logo' . $custom_logo_class . '" src="' . $this->helix3->getTemplateUri() . '/images/presets/' . $this->helix3->Preset() . '/logo.png" alt="' . $sitename . '">';
             $html .= '<img class="sp-retina-logo' . $custom_logo_class . '" src="' . $this->helix3->getTemplateUri() . '/images/presets/' . $this->helix3->Preset() . '/logo@2x.png" alt="' . $sitename . '" width="' . $width . '" height="' . $height . '">';
             if ($this->helix3->getParam('mobile_logo')) {
                 $html .= '<img class="sp-default-logo visible-xs" src="' . $this->helix3->getParam('mobile_logo') . '" alt="' . $sitename . '">';
             }
             $html .= '</div>';
         }
     } else {
         if ($this->helix3->getParam('logo_text')) {
             $html .= '<div>' . $this->helix3->divtParam('logo_text') . '</div>';
         } else {
             $html .= '<div>' . $sitename . '</div>';
         }
         if ($this->helix3->getParam('logo_slogan')) {
             $html .= '<p class="logo-slogan">' . $this->helix3->getParam('logo_slogan') . '</p>';
         }
     }
     $html .= '<div class="site-name">' . $sitename . '</div>';
     $html .= '</a>';
     return $html;
 }
Ejemplo n.º 2
0
 /**
  * Save user profile data.
  *
  * @param   array    $data    Entered user data
  * @param   boolean  $isNew   True if this is a new user
  * @param   boolean  $result  True if saving the user worked
  * @param   string   $error   Error message
  *
  * @return  boolean
  */
 public function onUserAfterSave($data, $isNew, $result, $error)
 {
     // Only run in front-end.
     if (!JFactory::getApplication()->isSite()) {
         return true;
     }
     $userId = JArrayHelper::getValue($data, 'id', 0, 'int');
     $folder = $this->params->get('folder', '');
     $avatarFolder = JPATH_ROOT . '/' . $folder;
     // If the avatar folder doesn't exist, we don't do anything.
     if (!JFolder::exists($avatarFolder)) {
         return false;
     }
     $jinput = JFactory::getApplication()->input;
     $delete = $jinput->get('delete-avatar', '', 'word');
     if ($delete == 'yes') {
         $this->deleteAvatar($userId);
         return true;
     }
     if ($result && $userId > 0) {
         $files = $jinput->files->get('jform', array(), 'array');
         if (!isset($files['cmavatar']['cmavatar'])) {
             return false;
         }
         $file = $files['cmavatar']['cmavatar'];
         if (empty($file['name'])) {
             return true;
         }
         $fileTypes = explode('.', $file['name']);
         if (count($fileTypes) < 2) {
             // There seems to be no extension.
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
             return false;
         }
         array_shift($fileTypes);
         // Check if the file has an executable extension.
         $executable = array('php', 'js', 'exe', 'phtml', 'java', 'perl', 'py', 'asp', 'dll', 'go', 'ade', 'adp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'hta', 'ins', 'isp', 'jse', 'lib', 'mde', 'msc', 'msp', 'mst', 'pif', 'scr', 'sct', 'shb', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh');
         $check = array_intersect($fileTypes, $executable);
         if (!empty($check)) {
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
             return false;
         }
         $fileType = array_pop($fileTypes);
         $allowable = array_map('trim', explode(',', $this->params->get('allowed_extensions')));
         if ($fileType == '' || $fileType == false || !in_array($fileType, $allowable)) {
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TYPE'));
             return false;
         }
         $uploadMaxSize = $this->params->get('max_size', 0) * 1024 * 1024;
         $uploadMaxFileSize = $this->toBytes(ini_get('upload_max_filesize'));
         if ($file['error'] == 1 || $uploadMaxSize > 0 && $file['size'] > $uploadMaxSize || $uploadMaxFileSize > 0 && $file['size'] > $uploadMaxFileSize) {
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_TOO_LARGE'));
             return false;
         }
         // Make the file name unique.
         $md5String = $userId . $file['name'] . JFactory::getDate();
         $avatarFileName = JFile::makeSafe(md5($md5String));
         if (empty($avatarFileName)) {
             // No file name after the name was cleaned by JFile::makeSafe.
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_NO_FILENAME'));
             return false;
         }
         $avatarPath = JPath::clean($avatarFolder . '/' . $avatarFileName . '.' . $this->extension);
         if (JFile::exists($avatarPath)) {
             // A file with this name already exists. It is almost impossible.
             throw new RuntimeException(JText::_('PLG_USER_CMAVATAR_ERROR_FILE_EXISTS'));
             return false;
         }
         // Start resizing the file.
         $avatar = new JImage($file['tmp_name']);
         $originalWidth = $avatar->getWidth();
         $originalHeight = $avatar->getHeight();
         $ratio = $originalWidth / $originalHeight;
         $maxWidth = (int) $this->params->get('width', 100);
         $maxHeight = (int) $this->params->get('height', 100);
         // Invalid value in the plugin configuration. Set avatar width to 100.
         if ($maxWidth <= 0) {
             $maxWidth = 100;
         }
         if ($maxHeight <= 0) {
             $maxHeight = 100;
         }
         if ($originalWidth > $maxWidth) {
             $ratio = $originalWidth / $originalHeight;
             $newWidth = $maxWidth;
             $newHeight = $newWidth / $ratio;
             if ($newHeight > $maxHeight) {
                 $ratio = $newWidth / $newHeight;
                 $newHeight = $maxHeight;
                 $newWidth = $newHeight * $ratio;
             }
         } elseif ($originalHeight > $maxHeight) {
             $ratio = $originalWidth / $originalHeight;
             $newHeight = $maxHeight;
             $newWidth = $newHeight * $ratio;
             if ($newWidth > $maxWidth) {
                 $ratio = $newWidth / $newHeight;
                 $newWidth = $maxWidth;
                 $newHeight = $newWidth / $ratio;
             }
         } else {
             $newWidth = $originalWidth;
             $newHeight = $originalHeight;
         }
         $resizedAvatar = $avatar->resize($newWidth, $newHeight, true);
         $resizedAvatar->toFile($avatarPath);
         // Delete current avatar if exists.
         $this->deleteAvatar($userId);
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         // Save avatar's file name to database.
         if (!empty($currentAvatar)) {
             $query->update($db->qn('#__user_profiles'))->set($db->qn('profile_value') . ' = ' . $db->q($avatarFileName))->where($db->qn('user_id') . ' = ' . $db->q($userId))->where($db->qn('profile_key') . ' = ' . $db->quote($this->profileKey));
         } else {
             $query->insert($db->qn('#__user_profiles'))->columns($db->qn(array('user_id', 'profile_key', 'profile_value', 'ordering')))->values($db->q($userId) . ', ' . $db->q($this->profileKey) . ', ' . $db->q($avatarFileName) . ', ' . $db->q('1'));
         }
         $db->setQuery($query)->execute();
         // Check for a database error.
         if ($error = $db->getErrorMsg()) {
             throw new RuntimeException($error);
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Get an image address, height and width.
  *
  * @return  array an associative array containing image address, height and width.
  *
  * @since   3.2
  */
 public function getImage()
 {
     if ($template = $this->getTemplate()) {
         $app = JFactory::getApplication();
         $client = JApplicationHelper::getClientInfo($template->client_id);
         $fileName = base64_decode($app->input->get('file'));
         $path = JPath::clean($client->path . '/templates/' . $template->element . '/');
         if (stristr($client->path, 'administrator') == false) {
             $folder = '/templates/';
         } else {
             $folder = '/administrator/templates/';
         }
         $uri = JUri::root(true) . $folder . $template->element;
         if (file_exists(JPath::clean($path . $fileName))) {
             $JImage = new JImage(JPath::clean($path . $fileName));
             $image['address'] = $uri . $fileName;
             $image['path'] = $fileName;
             $image['height'] = $JImage->getHeight();
             $image['width'] = $JImage->getWidth();
         } else {
             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_IMAGE_FILE_NOT_FOUND'), 'error');
             return false;
         }
         return $image;
     }
 }
Ejemplo n.º 4
0
 function onUserAfterSave($data, $isNew, $result, $error)
 {
     $userId = JArrayHelper::getValue($data, 'id', 0, 'int');
     $files = JRequest::getVar('jform', null, 'files');
     $post = JRequest::getVar('jform', null);
     /*var_dump($_GET["task"]);
     		var_dump($_POST["task"]);
     		die;*/
     if ($_GET["task"] != "registration.register" && $_POST["task"] != "register") {
         $savedNewProfilePicture = false;
         // Save original picture, resized pictures and save them
         if ($files['error']['profilepicture']['file'] == 0) {
             $profilepicture = new JImage($files['tmp_name']['profilepicture']['file']);
             $sourceWidth = $profilepicture->getWidth();
             $sourceHeight = $profilepicture->getHeight();
             if ($sourceWidth < PROFILEPICTURE_SIZE_200 || $sourceHeight < PROFILEPICTURE_SIZE_200) {
                 throw new Exception(JText::_('PLG_USER_PROFILEPICTURE_ERROR_TOO_SMALL'));
             }
             $pp_filename = sha1($userId . uniqid()) . '.' . plgUserProfilePicture::FILE_EXTENSION;
             foreach ($this->sizes as $size) {
                 if ($size == PROFILEPICTURE_SIZE_ORIGINAL) {
                     $profilepicture->toFile(PROFILEPICTURE_PATH_ORIGINAL . $pp_filename);
                     $savedNewProfilePicture = true;
                 } else {
                     $ratio = max($sourceWidth, $sourceHeight) / $size;
                     $ratio = max($ratio, 1.0);
                     $resizedWidth = (int) ($sourceWidth / $ratio);
                     $resizedHeight = (int) ($sourceHeight / $ratio);
                     $left = 0;
                     $top = 0;
                     if ($this->square && $sourceWidth > $size && $sourceHeight > $size) {
                         if ($sourceWidth > $sourceHeight) {
                             $left = (int) ($sourceWidth - $sourceHeight) / 2;
                             $top = 0;
                             $croppedWidth = $sourceHeight;
                             $croppedHeight = $sourceHeight;
                             $resizedHeight = $resizedWidth;
                         } elseif ($sourceHeight > $sourceWidth) {
                             $left = 0;
                             $top = (int) (($sourceHeight - $sourceWidth) / 2);
                             $croppedWidth = $sourceWidth;
                             $croppedHeight = $sourceWidth;
                             $resizedWidth = $resizedHeight;
                         }
                         $cropped = $profilepicture->crop($croppedWidth, $croppedHeight, $left, $top, true);
                         $resized = $cropped->resize($resizedWidth, $resizedHeight, true, JImage::SCALE_OUTSIDE);
                         $resized->toFile(constant('PROFILEPICTURE_PATH_' . $size) . $pp_filename);
                         $savedNewProfilePicture = true;
                     } else {
                         $resized = $profilepicture->resize($size, $size, true, JImage::SCALE_INSIDE);
                         $resized->toFile(constant('PROFILEPICTURE_PATH_' . $size) . $pp_filename);
                         $savedNewProfilePicture = true;
                     }
                 }
             }
         }
         // Remove profile picture if an existing profile picture is
         // checked for removal or a new picture has been uploaded
         // replacing the existing picture.
         if (isset($userId) && (!empty($post['profilepicture']['file']['remove']) || $savedNewProfilePicture)) {
             $this->removeProfilePicture($userId);
         }
         if ($userId && $savedNewProfilePicture) {
             try {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query = $db->getQuery(true);
                 $query->insert('#__user_profiles')->columns('user_id, profile_key, profile_value, ordering')->values($userId . ', ' . $db->quote(plgUserProfilePicture::PROFILE_KEY) . ', ' . $db->quote($pp_filename) . ', ' . ' 1');
                 $db->setQuery($query);
                 if (!$db->query()) {
                     throw new Exception($db->getErrorMsg());
                 }
             } catch (JException $e) {
                 $this->_subject->setError($e->getMessage());
                 return false;
             }
         }
         return true;
     } else {
         return true;
     }
 }
Ejemplo n.º 5
0
 /**
  * Test the JImage::getWidth method without a loaded image.
  *
  * @return  void
  *
  * @expectedException  LogicException
  * @since   11.3
  */
 public function testGetWidthWithoutLoadedImage()
 {
     // Create a new JImage object without loading an image.
     $image = new JImage();
     $image->getWidth();
 }
Ejemplo n.º 6
0
 function uploadImages($file, $currentImage = null)
 {
     if ($file) {
         $maxSize = 2 * 1024 * 1024;
         $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico');
         // Create folder
         $tzFolder = 'tz_portfolio';
         $tzUserFolder = 'users';
         $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $tzFolder;
         $tzUserFolderPath = $tzFolderPath . DIRECTORY_SEPARATOR . $tzUserFolder;
         if (!JFolder::exists($tzFolderPath)) {
             JFolder::create($tzFolderPath);
             if (!JFile::exists($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                 JFile::write($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
             }
         }
         if (JFolder::exists($tzFolderPath)) {
             if (!JFolder::exists($tzUserFolderPath)) {
                 JFolder::create($tzUserFolderPath);
                 if (!JFile::exists($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                     JFile::write($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
                 }
             }
         }
         if (is_array($file)) {
             foreach ($file as $key => $val) {
                 if (is_array($val)) {
                     foreach ($val as $key2 => $val2) {
                         $file[$key] = $val2;
                     }
                 }
             }
             //Upload image
             if (in_array($file['type'], $arr)) {
                 if ($file['size'] <= $maxSize) {
                     $desFileName = 'user_' . time() . uniqid() . '.' . JFile::getExt($file['name']);
                     $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
                     if (JFile::exists($file['tmp_name'])) {
                         if (!JFile::copy($file['tmp_name'], $desPath)) {
                             JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_CAN_NOT_UPLOAD_FILE'));
                         }
                         $image = new JImage();
                         $image->loadFile($desPath);
                         $params = JComponentHelper::getParams('com_tz_portfolio');
                         if ($params->get('tz_user_image_width', 100)) {
                             $width = $params->get('tz_user_image_width', 100);
                         }
                         $height = ceil($image->getHeight() * $width / $image->getWidth());
                         $image = $image->resize($width, $height);
                         $type = $this->_getImageType($file['name']);
                         $image->toFile($desPath, $type);
                         $this->deleteImages($currentImage);
                         return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
                     }
                 } else {
                     JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_SIZE_TOO_LARGE'));
                 }
             } else {
                 JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_FILE_NOT_SUPPORTED'));
             }
         } else {
             tzportfolioimport('HTTPFetcher');
             tzportfolioimport('readfile');
             $image = new Services_Yadis_PlainHTTPFetcher();
             $image = $image->get($file);
             if (in_array($image->headers['Content-Type'], $arr)) {
                 if ($image->headers['Content-Length'] > $maxSize) {
                     $this->deleteImages($currentImage);
                     $desFileName = 'user_' . time() . uniqid() . '.' . str_replace('image/', '', $image->headers['Content-Type']);
                     $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
                     if (JFolder::exists($tzFolderPath)) {
                         if (!JFile::write($desPath, $image->body)) {
                             $this->setError(JText::_('COM_TZ_PORTFOLIO_CAN_NOT_UPLOAD_FILE'));
                             return false;
                         }
                         return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
                     }
                 } else {
                     JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_SIZE_TOO_LARGE'));
                 }
             } else {
                 JError::raiseNotice(300, JText::_('COM_TZ_PORTFOLIO_IMAGE_FILE_NOT_SUPPORTED'));
             }
         }
     }
     if ($currentImage) {
         return $currentImage;
     }
     return '';
 }
Ejemplo n.º 7
0
 function uploadImages($file)
 {
     if ($file) {
         $maxSize = 2 * 1024 * 1024;
         $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico');
         // Create folder
         $tzFolder = 'tz_pinboard';
         $tzUserFolder = 'users';
         $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $tzFolder;
         $tzUserFolderPath = $tzFolderPath . DIRECTORY_SEPARATOR . $tzUserFolder;
         if (!JFolder::exists($tzFolderPath)) {
             JFolder::create($tzFolderPath);
             if (!JFile::exists($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                 JFile::write($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
             }
         }
         if (JFolder::exists($tzFolderPath)) {
             if (!JFolder::exists($tzUserFolderPath)) {
                 JFolder::create($tzUserFolderPath);
                 if (!JFile::exists($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                     JFile::write($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
                 }
             }
         }
         if (is_array($file)) {
             foreach ($file as $key => $val) {
                 if (is_array($val)) {
                     foreach ($val as $key2 => $val2) {
                         $file[$key] = $val2;
                     }
                 }
             }
             //Upload image
             if (!in_array($file['type'], $arr)) {
                 $this->setError(JText::_('Invalid file type'));
                 return false;
             }
             if ($file['size'] > $maxSize) {
                 $this->setError(JText::_('This file size too large'));
                 return false;
             }
             $desFileName = 'user_' . time() . uniqid() . '.' . JFile::getExt($file['name']);
             $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
             if (JFile::exists($file['tmp_name'])) {
                 if (!JFile::copy($file['tmp_name'], $desPath)) {
                     $this->setError(JText::_('Can not upload file'));
                     return false;
                 }
                 $image = new JImage();
                 $image->loadFile($desPath);
                 $params = JComponentHelper::getParams('com_tz_pinboard');
                 if ($params->get('tz_user_image_width', 100)) {
                     $width = $params->get('tz_user_image_width', 100);
                 }
                 $height = ceil($image->getHeight() * $width / $image->getWidth());
                 $image = $image->resize($width, $height);
                 $type = $this->_getImageType($file['name']);
                 $image->toFile($desPath, $type);
                 return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
             }
         } else {
             require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'HTTPFetcher.php';
             require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'readfile.php';
             $image = new Services_Yadis_PlainHTTPFetcher();
             $image = $image->get($file);
             if (!in_array($image->headers['Content-Type'], $arr)) {
                 $this->setError(JText::_('Invalid file'));
                 return false;
             }
             if ($image->headers['Content-Length'] > $maxSize) {
                 $this->setError(JText::_('This file size too large'));
                 return false;
             }
             $desFileName = 'user_' . time() . uniqid() . '.' . str_replace('image/', '', $image->headers['Content-Type']);
             $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
             if (JFolder::exists($tzFolderPath)) {
                 if (!JFile::write($desPath, $image->body)) {
                     $this->setError(JText::_('Can not upload file'));
                     return false;
                 }
                 return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
             }
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Generate the file preview. U
  */
 private function _generatePreview()
 {
     // Create thumbnail (for jpeg) if there is none
     $supportedImageMine = array('image/png', 'image/jpeg');
     if (in_array($this->mimetype, $supportedImageMine)) {
         jimport('joomla.image');
         require_once JPATH_ROOT . DS . 'libraries' . DS . 'joomla' . DS . 'image' . DS . 'filters' . DS . 'sharpen.php';
         $image = new JImage(JPATH_ROOT . DS . $this->path);
         if (!$image->isLoaded()) {
             return false;
         }
         $pathinfo = pathinfo($this->path);
         $width = $image->getWidth();
         $height = $image->getHeight();
         // Generate preview
         if ($width > 640) {
             $height = 640 / $width * $height;
             $width = 640;
         }
         if ($height > 640) {
             $width = 640 / $height * $width;
             $height = 640;
         }
         // Resize for preview
         $image = $image->resize($width, $height);
         $previewPath = JPATH_ROOT . DS . $pathinfo['dirname'] . DS . $pathinfo['filename'] . '_preview.jpg';
         $image->filter('sharpen');
         $image->toFile($previewPath, IMAGETYPE_JPEG, array('quality' => 90));
         // crop them to predefined aspect ratio if necessary
         // and the resize them
         if ($width / $height > 1.3) {
             $image = $image->crop($height * 1.3, $height, ($width - $height * 1.3) / 2, 0);
             $image = $image->resize(StreamTableFile::PHOTO_THUMB_WIDTH, StreamTableFile::PHOTO_THUMB_HEIGHT);
         } elseif ($height / $width > 1.3) {
             $image = $image->crop($width, $width * 1.3, 0, $height - $width * 1.3);
             $image = $image->resize(StreamTableFile::PHOTO_THUMB_HEIGHT, StreamTableFile::PHOTO_THUMB_WIDTH);
         } else {
             $image = $image->resize(StreamTableFile::PHOTO_THUMB_WIDTH, StreamTableFile::PHOTO_THUMB_WIDTH);
         }
         $thumbPath = JPATH_ROOT . DS . $pathinfo['dirname'] . DS . $pathinfo['filename'] . '_thumb.jpg';
         $image->toFile($thumbPath, IMAGETYPE_JPEG, array('quality' => 100));
         if (JFile::exists($thumbPath)) {
             $this->setParam('has_preview', true);
             $this->setParam('thumb_path', $pathinfo['dirname'] . DS . $pathinfo['filename'] . '_thumb.jpg');
             $this->setParam('preview_path', $pathinfo['dirname'] . DS . $pathinfo['filename'] . '_preview.jpg');
             $this->setParam('width', $width);
             $this->setParam('height', $height);
         }
     } else {
         $this->setParam('has_preview', false);
         $this->setParam('thumb_path', '');
         $this->setParam('preview_path', '');
         $this->setParam('width', '');
         $this->setParam('height', '');
     }
 }
Ejemplo n.º 9
0
 function onUserAfterSave($data, $isNew, $result, $error)
 {
     $userId = JArrayHelper::getValue($data, 'id', 0, 'int');
     $files = JRequest::getVar('jform', null, 'files');
     $post = JRequest::getVar('jform', null);
     $savedNewProfileCover = false;
     // Save original cover, resized covers and save them
     if ($files['error']['profilecover']['file'] == 0 && !empty($files['tmp_name']['profilecover']['file'])) {
         // Throw new exception if the uploaded file exceed the maximum allowed file size.
         if ($this->doesExceedFileSizeLimit($files['size']['profilecover']['file'])) {
             throw new Exception(JText::sprintf('PLG_USER_PROFILECOVER_ERROR_FILE_SIZE_TOO_BIG', $this->maxUploadSizeInBytes() / 1000));
         }
         $profilecover = new JImage($files['tmp_name']['profilecover']['file']);
         $sourceWidth = $profilecover->getWidth();
         $sourceHeight = $profilecover->getHeight();
         if ($sourceWidth < PROFILECOVER_SIZE_200 || $sourceHeight < PROFILECOVER_SIZE_200) {
             throw new Exception(JText::_('PLG_USER_PROFILECOVER_ERROR_TOO_SMALL'));
         }
         $pp_filename = sha1($userId . uniqid()) . '.' . plgUserProfileCover::FILE_EXTENSION;
         foreach ($this->sizes as $size) {
             if ($size == PROFILECOVER_SIZE_ORIGINAL) {
                 $profilecover->toFile(PROFILECOVER_PATH_ORIGINAL . $pp_filename);
                 $savedNewProfileCover = true;
             } else {
                 $ratio = max($sourceWidth, $sourceHeight) / $size;
                 $ratio = max($ratio, 1.0);
                 $resizedWidth = (int) ($sourceWidth / $ratio);
                 $resizedHeight = (int) ($sourceHeight / $ratio);
                 $left = 0;
                 $top = 0;
                 if ($this->square && $sourceWidth > $size && $sourceHeight > $size) {
                     if ($sourceWidth > $sourceHeight) {
                         $left = (int) ($sourceWidth - $sourceHeight) / 2;
                         $top = 0;
                         $croppedWidth = $sourceHeight;
                         $croppedHeight = $sourceHeight;
                         $resizedHeight = $resizedWidth;
                     } elseif ($sourceHeight >= $sourceWidth) {
                         $left = 0;
                         $top = (int) (($sourceHeight - $sourceWidth) / 2);
                         $croppedWidth = $sourceWidth;
                         $croppedHeight = $sourceWidth;
                         $resizedWidth = $resizedHeight;
                     }
                     $cropped = $profilecover->crop($croppedWidth, $croppedHeight, $left, $top, true);
                     $resized = $cropped->resize($resizedWidth, $resizedHeight, true, JImage::SCALE_OUTSIDE);
                     $resized->toFile(constant('PROFILECOVER_PATH_' . $size) . $pp_filename);
                     $savedNewProfileCover = true;
                 } else {
                     $resized = $profilecover->resize($size, $size, true, JImage::SCALE_INSIDE);
                     $resized->toFile(constant('PROFILECOVER_PATH_' . $size) . $pp_filename);
                     $savedNewProfileCover = true;
                 }
             }
         }
     }
     // Remove profile cover if an existing profile cover is
     // checked for removal or a new cover has been uploaded
     // replacing the existing cover.
     if (isset($userId) && (!empty($post['profilecover']['file']['remove']) || $savedNewProfileCover)) {
         $this->removeProfileCover($userId);
     }
     if ($userId && $savedNewProfileCover) {
         try {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query = $db->getQuery(true);
             $query->insert('#__user_profiles')->columns('user_id, profile_key, profile_value, ordering')->values($userId . ', ' . $db->quote(plgUserProfileCover::PROFILE_KEY) . ', ' . $db->quote($pp_filename) . ', ' . ' 1');
             $db->setQuery($query);
             if (!$db->query()) {
                 throw new Exception($db->getErrorMsg());
             }
         } catch (JException $e) {
             $this->_subject->setError($e->getMessage());
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 10
0
 public function resizeImage($src, $gallery = null, $dest = null)
 {
     if ($src) {
         $type = JFile::getExt($src);
         $org_file = str_replace('.' . $type, '_o.' . $type, $src);
         $params = $this->getState('params');
         $sizes = $this->getState('sizeImage');
         if ($gallery) {
             $sizes = $this->getState('size');
         }
         if (!JFile::exists($org_file)) {
             $this->setError(JText::_('COM_TZ_PORTFOLIO_IMAGE_FILE_DOES_NOT_EXIST'));
             return false;
         }
         $dest_path = $dest;
         if ($sizes) {
             $image = new JImage($org_file);
             $width = $image->getWidth();
             $height = $image->getHeight();
             // Resize images
             foreach ($sizes as $key => $newWidth) {
                 $newHeight = $height * $newWidth / $width;
                 $newImage = $image->resize($newWidth, $newHeight);
                 if (!$dest) {
                     $dest_path = str_replace('.' . $type, '_' . $key . '.' . $type, $src);
                 }
                 if (JFile::exists($dest_path)) {
                     JFile::delete($dest_path);
                 }
                 $newImage->toFile($dest_path, $this->_getImageType($src));
             }
             return true;
         }
         return false;
     }
     return false;
 }
Ejemplo n.º 11
0
 function uploadImages($file, $url = null)
 {
     if ($file) {
         $maxSize = 2 * 1024 * 1024;
         $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico');
         // Create folder
         $tzFolder = 'tz_portfolio_plus';
         $tzUserFolder = 'categories';
         $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $tzFolder;
         $tzUserFolderPath = $tzFolderPath . DIRECTORY_SEPARATOR . $tzUserFolder;
         if (!JFolder::exists($tzFolderPath)) {
             JFolder::create($tzFolderPath);
             if (!JFile::exists($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                 JFile::write($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
             }
         }
         if (JFolder::exists($tzFolderPath)) {
             if (!JFolder::exists($tzUserFolderPath)) {
                 JFolder::create($tzUserFolderPath);
                 if (!JFile::exists($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                     JFile::write($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
                 }
             }
         }
         $params = JComponentHelper::getParams('com_tz_portfolio_plus');
         if (!$url) {
             $image = new JImage(JPATH_SITE . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file));
             $desFileName = 'categories_' . time() . uniqid() . '.' . JFile::getExt($file);
             $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
             if ($params->get('tz_catimage_width', 400)) {
                 $newWidth = $params->get('tz_catimage_width', 400);
             }
             $type = strtolower(JFile::getExt($file));
             $_type = null;
             if ($type == 'gif') {
                 $_type = IMAGETYPE_GIF;
             } elseif ($type == 'png') {
                 $_type = IMAGETYPE_PNG;
             }
             $height = ceil($image->getHeight() * $newWidth / $image->getWidth());
             $image = $image->resize($newWidth, $height);
             $image->toFile($desPath, $_type);
             return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
         } else {
             tzportfolioplusimport('HTTPFetcher');
             tzportfolioplusimport('readfile');
             $image = new Services_Yadis_PlainHTTPFetcher();
             $image = $image->get($file);
             if (!in_array($image->headers['Content-Type'], $arr)) {
                 $this->setError(JText::_('COM_TZ_PORTFOLIO_PLUS_INVALID_FILE'));
                 return false;
             }
             if ($image->headers['Content-Length'] > $maxSize) {
                 $this->setError(JText::_('COM_TZ_PORTFOLIO_PLUS_IMAGE_SIZE_TOO_LARGE'));
                 return false;
             }
             $desFileName = 'categories_' . time() . uniqid() . '.' . str_replace('image/', '', $image->headers['Content-Type']);
             $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
             if (JFolder::exists($tzFolderPath)) {
                 if (!JFile::write($desPath, $image->body)) {
                     $this->setError(JText::_('COM_TZ_PORTFOLIO_PLUS_CAN_NOT_UPLOADED_FILEs'));
                     return false;
                 }
                 $image = new JImage($desPath);
                 $newWidth = $params->get('tz_catimage_width', 400);
                 $newHeight = ceil($image->getHeight() * $newWidth / $image->getWidth());
                 $newImage = $image->resize((int) $newWidth, $newHeight, false);
                 $type = strtolower(JFile::getExt($file));
                 $_type = $type == 'gif' ? IMAGETYPE_GIF : $type == 'png' ? IMAGETYPE_PNG : null;
                 $newImage->toFile($desPath, $_type);
                 return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
             }
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 public static function profileImage($profileID, $variable = 'profile')
 {
     $files = JRequest::getVar('jform', null, 'files');
     $jform = JRequest::getVar('jform', null, 'ARRAY');
     // Check that user want upload image or delete image
     $image_delete = empty($jform[$variable]['image_delete']) ? false : true;
     $image_error = empty($variable) ? $files['error']['image'] : $files['error'][$variable]['image'];
     $image_tmp_name = empty($variable) ? $files['tmp_name']['image'] : $files['tmp_name'][$variable]['image'];
     // Minimum image size
     $imageSize = 200;
     $profileImage = -1;
     // Upload Profile Image
     if ($image_error == 0 && !$image_delete) {
         // Resize Image
         $image = new JImage($image_tmp_name);
         $sourceWidth = $image->getWidth();
         $sourceHeight = $image->getHeight();
         if ($sourceWidth < $imageSize || $sourceHeight < $imageSize) {
             return JText::sprintf('COM_SIBDIET_ERROR_PROFILE_IMAGE_TOO_SMALL', $imageSize);
         }
         // Set image name to user profile ID
         $image_filename = $profileID . '.jpg';
         $ratio = max($sourceWidth, $sourceHeight) / $imageSize;
         $ratio = max($ratio, 1.0);
         $resizedWidth = (int) ($sourceWidth / $ratio);
         $resizedHeight = (int) ($sourceHeight / $ratio);
         $resized = $image->resize($resizedWidth, $resizedHeight, true, JImage::SCALE_INSIDE);
         $resized->toFile(JPATH_ROOT . '/images/sibdiet/profiles/' . $image_filename, 'IMAGETYPE_JPEG');
     } elseif ($image_delete) {
         $image_path = JPATH_ROOT . '/images/sibdiet/profiles/' . $profileID . '.jpg';
         jimport('joomla.filesystem.file');
         if (JFile::exists($image_path)) {
             JFile::delete($image_path);
         }
     }
     return true;
 }
Ejemplo n.º 13
0
 function uploadLocal()
 {
     $img = $_FILES['upload_pinl'];
     $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico');
     $maxSize = 10 * 1024 * 1024;
     $erro = array();
     $size_img = $this->getState('size_img');
     $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'tz_pinboard' . DIRECTORY_SEPARATOR . 'article' . DIRECTORY_SEPARATOR . 'cache';
     if (!JFolder::exists($tzFolderPath)) {
         JFolder::create($tzFolderPath);
     }
     $check_file_type = in_array(strtolower($img['type']), $arr);
     if ($check_file_type == false) {
         $erro[] = "incorrect file type";
     }
     if ($img['size'] > $maxSize) {
         $erro[] = "file too large";
     }
     $_erro = count($erro);
     if ($_erro == '0') {
         $FileName_img = 'Pin_' . time() . uniqid() . '.' . str_replace('image/', '', $img['type']);
         $_FILES['upload_pinl']['name'] = $FileName_img;
         $type = $this->_getImageType($FileName_img);
         if ($type == 1) {
             $uploadfile = $tzFolderPath . '/' . basename($_FILES['upload_pinl']['name']);
             move_uploaded_file($_FILES['upload_pinl']['tmp_name'], $uploadfile);
             $desttamp = $tzFolderPath . DIRECTORY_SEPARATOR . $FileName_img;
             preg_match('/media.*?$/', $desttamp, $path_img);
             return $path_img1 = str_replace('\\', '/', $path_img[0]);
         } else {
             $desttamp = $tzFolderPath . DIRECTORY_SEPARATOR . $FileName_img;
             $obj = new JImage($img['tmp_name']);
             $width = $obj->getWidth();
             $height = $obj->getHeight();
             $arr_upload = array();
             foreach ($size_img as $key => $newWidth) {
                 $destPath = $tzFolderPath . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $FileName_img);
                 $destPath = str_replace('.' . JFile::getExt($destPath), '_' . $key . '.' . JFile::getExt($destPath), $destPath);
                 $newHeight = $height * (int) $newWidth / $width;
                 $newImage = $obj->resize($newWidth, $newHeight, true);
                 $arr_upload[] = $newImage->toFile($destPath, $type);
             }
             if ($arr_upload[0] == true) {
                 preg_match('/media.*?$/', $desttamp, $path_img);
                 return $path_img1 = str_replace('\\', '/', $path_img[0]);
             } else {
                 return false;
             }
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 14
0
 function uploadImages($file, $url = null)
 {
     if ($file) {
         $maxSize = 2 * 1024 * 1024;
         $arr = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico');
         // Create folder
         $tzFolder = 'tz_pinboard';
         $tzUserFolder = 'categories';
         $tzFolderPath = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $tzFolder;
         $tzUserFolderPath = $tzFolderPath . DIRECTORY_SEPARATOR . $tzUserFolder;
         if (!JFolder::exists($tzFolderPath)) {
             JFolder::create($tzFolderPath);
             if (!JFile::exists($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                 JFile::write($tzFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
             }
         }
         if (JFolder::exists($tzFolderPath)) {
             if (!JFolder::exists($tzUserFolderPath)) {
                 JFolder::create($tzUserFolderPath);
                 if (!JFile::exists($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html')) {
                     JFile::write($tzUserFolderPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>'));
                 }
             }
         }
         $params = JComponentHelper::getParams('com_tz_pinboard');
         if (!$url) {
             $image = new JImage(JPATH_SITE . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file));
             $desFileName = 'categories_' . time() . uniqid() . '.' . JFile::getExt($file);
             $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
             if ($params->get('tz_catimage_width', 400)) {
                 $newWidth = $params->get('tz_catimage_width', 400);
             }
             $height = ceil($image->getHeight() * $newWidth / $image->getWidth());
             $image = $image->resize($newWidth, $height);
             $image->toFile($desPath);
             return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
         } else {
             require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'HTTPFetcher.php';
             require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'readfile.php';
             $image = new Services_Yadis_PlainHTTPFetcher();
             $image = $image->get($file);
             if (!in_array($image->headers['Content-Type'], $arr)) {
                 $this->setError(JText::_('Invalid file'));
                 return false;
             }
             if ($image->headers['Content-Length'] > $maxSize) {
                 $this->setError(JText::_('This file size too large'));
                 return false;
             }
             $desFileName = 'categories_' . time() . uniqid() . '.' . str_replace('image/', '', $image->headers['Content-Type']);
             $desPath = $tzUserFolderPath . DIRECTORY_SEPARATOR . $desFileName;
             if (JFolder::exists($tzFolderPath)) {
                 if (!JFile::write($desPath, $image->body)) {
                     $this->setError(JText::_('Can not upload file'));
                     return false;
                 }
                 $image = new JImage($desPath);
                 $newWidth = $params->get('tz_catimage_width', 400);
                 $newHeight = ceil($image->getHeight() * $newWidth / $image->getWidth());
                 $newImage = $image->resize((int) $newWidth, $newHeight, false);
                 $newImage->toFile($desPath);
                 return 'media/' . $tzFolder . '/' . $tzUserFolder . '/' . $desFileName;
             }
         }
     }
     return true;
 }
Ejemplo n.º 15
0
 /**
  * Create a cropped and resized image from the uploaded original
  *
  * @return bool
  *
  * @since   1.0.0.3
  */
 protected function createImage($src, $dest, $width, $height)
 {
     $original = new JImage($src);
     $org_width = $original->getWidth();
     $org_height = $original->getHeight();
     if ($org_width / $width < $org_height / $height) {
         $original->resize($width, 0, false);
     } else {
         $original->resize(0, $height, false);
     }
     $thumb = $original->crop($width, $height, null, null, true);
     $filename = pathinfo($original->getPath(), PATHINFO_FILENAME);
     $extension = pathinfo($original->getPath(), PATHINFO_EXTENSION);
     if (!$thumb->toFile(JPATH_ROOT . $dest . $filename . "." . $extension)) {
         return false;
     }
     $original->destroy();
     $thumb->destroy();
     return true;
 }