Пример #1
0
 /**
  * Retrieves the uri for this image
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return	
  */
 public function getUrl()
 {
     $config = FD::config();
     // Get the container location
     $container = FD::cleanPath($config->get('links.cache.location'));
     // Relative path to the item
     $relativePath = $this->getRelativePath();
     // Default base url
     $url = rtrim(JURI::root(), '/') . $relativePath;
     // Get the storage type for cached images for links
     if ($this->storage != 'joomla') {
         $storage = FD::storage($this->storage);
         $url = $storage->getPermalink($relativePath);
     }
     return $url;
 }
Пример #2
0
 /**
  * Processes the saving of the settings.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @author	Mark Lee <*****@*****.**>
  */
 public function save()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Since there are more than 1 tasks are linked here, get the appropriate task here.
     $task = $this->getTask();
     $method = $task;
     $page = JRequest::getVar('page', '');
     $view = FD::view('Settings');
     // Get the posted data.
     $post = JRequest::get('POST');
     // Only load the config that is already stored.
     // We don't want to store everything as we want to have hidden settings.
     $configTable = FD::table('Config');
     $config = FD::registry();
     if ($configTable->load('site')) {
         $config->load($configTable->value);
     }
     $token = FD::token();
     if (!$post) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_INVALID_POST_DATA'), SOCIAL_MSG_ERROR);
         return $view->call($method, $page);
     }
     // Some post vars are unwanted / unecessary because of the hidden inputs.
     $ignored = array('task', 'option', 'controller', 'view', $token, 'page');
     $updatedUserIndexing = false;
     foreach ($post as $key => $value) {
         if (!in_array($key, $ignored)) {
             // Replace all _ with .
             $key = str_ireplace('_', '.', $key);
             // If the value is an array, and there's only 1 index,
             // the input might need to be checked if it needs to be in an array form.
             // E.g: some,values,here,should,be,an,array
             if (is_array($value) && count($value) == 1) {
                 $value = FD::makeArray($value[0], ',');
             }
             if ($key == 'users.indexer.name' || $key == 'users.indexer.email') {
                 $previousVal = $config->get($key);
                 if ($previousVal != $value) {
                     $updatedUserIndexing = true;
                 }
             }
             $config->set($key, $value);
         }
     }
     // Convert the config object to a json string.
     $jsonString = $config->toString();
     $configTable = FD::table('Config');
     if (!$configTable->load('site')) {
         $configTable->type = 'site';
     }
     $configTable->set('value', $jsonString);
     // Try to store the configuration.
     if (!$configTable->store()) {
         $view->setMessage($configTable->getError(), SOCIAL_MSG_ERROR);
         return $view->call($method, $page);
     }
     // Check if any of the configurations are stored as non local
     if (($config->get('storage.photos') == 'amazon' || $config->get('storage.conversations') == 'amazon') && $config->get('storage.amazon.bucket') == '') {
         // Initialize the storage
         $bucket = FD::storage('Amazon')->init();
         $config->set('storage.amazon.bucket', $bucket);
         $configTable->set('value', $config->toString());
         $configTable->store();
     }
     $message = $updatedUserIndexing ? JText::_('COM_EASYSOCIAL_SETTINGS_SAVED_SUCCESSFULLY_WITH_USER_INDEXING_UPDATED') : JText::_('COM_EASYSOCIAL_SETTINGS_SAVED_SUCCESSFULLY');
     $view->setMessage($message, SOCIAL_MSG_SUCCESS);
     return $view->call($method, $page);
 }
Пример #3
0
 /**
  * Synchronizes photos from local storage to remote storage.
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function syncPhotos()
 {
     $storageType = $this->getStorageType();
     // If site is configured to storage in joomla, we don't need to do anything
     if ($storageType == 'joomla') {
         return JText::_('Current photos storage is set to local.');
     }
     // Load up the storage library
     $storage = FD::storage($storageType);
     // Get the number of files to process at a time
     $limit = $this->getUploadLimit();
     // Get a list of photos that failed during the transfer
     $exclusion = $this->getFailedObjects('photos');
     // Get a list of files to be synchronized over.
     $model = FD::model('Photos');
     $options = array('pagination' => $limit, 'storage' => SOCIAL_STORAGE_JOOMLA, 'ordering' => 'created', 'sort' => 'asc', 'exclusion' => $exclusion);
     // Get a list of photos to sync to amazon
     $photos = $model->getPhotos($options);
     $total = 0;
     if (!$photos) {
         return JText::_('No photos to upload to Amazon S3 right now.');
     }
     // Get list of allowed photos
     $allowed = array('thumbnail', 'large', 'square', 'featured', 'medium', 'original', 'stock');
     foreach ($photos as $photo) {
         // Load the album
         $album = FD::table('Album');
         $album->load($photo->album_id);
         // If the album no longer exists, skip this
         if (!$album->id) {
             continue;
         }
         // Get the base path for the album
         $basePath = $photo->getStoragePath($album);
         $states = array();
         // Now we need to get all the available files for this photo
         $metas = $model->getMeta($photo->id, SOCIAL_PHOTOS_META_PATH);
         // Go through each meta
         foreach ($metas as $meta) {
             // To prevent some faulty data, we need to manually reconstruct the path here.
             $absolutePath = $meta->value;
             $file = basename($absolutePath);
             $container = FD::cleanPath($this->config->get('photos.storage.container'));
             // Reconstruct the path to the source file
             $source = JPATH_ROOT . '/' . $container . '/' . $album->id . '/' . $photo->id . '/' . $file;
             // To prevent faulty data, manually reconstruct the path here.
             $dest = $container . '/' . $album->id . '/' . $photo->id . '/' . $file;
             $dest = ltrim($dest, '/');
             // We only want to upload certain files
             if (in_array($meta->property, $allowed)) {
                 // Upload the file to the remote storage now
                 $state = $storage->push($photo->title . $photo->getExtension(), $source, $dest);
                 // Delete the source file if successfull and configured to do so.
                 if ($state && $this->deleteable()) {
                     JFile::delete($source);
                 }
                 $states[] = $state;
             }
         }
         $success = !in_array(false, $states);
         // If there are no errors, we want to update the storage for the photo
         if ($success) {
             $photo->storage = $storageType;
             $state = $photo->store();
             // if photo storage successfully updated to amazon, we need to update the cached object in stream_item.
             // Find and update the object from stream_item.
             $stream = FD::table('StreamItem');
             $options = array('context_type' => SOCIAL_TYPE_PHOTO, 'context_id' => $photo->id);
             $exists = $stream->load($options);
             if ($exists) {
                 $stream->params = FD::json()->encode($photo);
                 $stream->store();
             }
             $total += 1;
         }
         // Add this to the storage logs
         $this->log($photo->id, 'photos', $success);
     }
     if ($total > 0) {
         return JText::sprintf('%1s photos uploaded to remote storage', $total);
     }
     return JText::sprintf('No photos to upload to remote storage');
 }
Пример #4
0
 /**
  * Cleanup a folder
  *
  * @since	1.0
  * @access	public
  * @param	string		The target location to store the avatars
  * @return
  */
 public function cleanup($avatarTable)
 {
     // Don't delete if the avatar is from gallery
     if (!empty($avatarTable->avatar_id)) {
         return true;
     }
     // Delete previous avatars.
     $paths = $avatarTable->getPaths(true);
     $storage = FD::storage($avatarTable->storage);
     $storage->delete($paths);
     return true;
 }
Пример #5
0
 /**
  * Ends the output and allow user to download the file
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function download()
 {
     // Update the hit counter
     $this->hits += 1;
     $this->store();
     if ($this->storage != 'joomla') {
         $storage = FD::storage($this->storage);
         $path = $this->getStoragePath(true);
         $path = $path . '/' . $this->hash;
         return JFactory::getApplication()->redirect($storage->getPermalink($path));
     }
     $storage = $this->getStoragePath();
     $file = $storage . '/' . $this->hash;
     jimport('joomla.filesystem.file');
     // If the file no longer exists, throw a 404
     if (!JFile::exists($file)) {
         JError::raiseError(404);
     }
     // Get the real file name
     $fileName = $this->name;
     // Get the file size
     $fileSize = filesize($file);
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="' . $fileName . '"');
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Length: ' . $fileSize);
     ob_clean();
     flush();
     readfile($file);
     exit;
 }
Пример #6
0
 /**
  * Retrieves the permalink to the image given the size
  *
  * @since   1.0
  * @access  public
  * @param   string
  * @return
  */
 public function getSource($type = 'thumbnail')
 {
     static $paths = array();
     $config = FD::config();
     // Load the paths for this photo
     $model = FD::model('Photos');
     $metas = $model->getMeta($this->id, SOCIAL_PHOTOS_META_PATH);
     $obj = new stdClass();
     $path = FD::cleanPath($config->get('photos.storage.container'));
     $allowed = array('thumbnail', 'large', 'original', 'square', 'featured', 'medium');
     foreach ($metas as $meta) {
         $relative = $path . '/' . $this->album_id . '/' . $this->id . '/' . basename($meta->value);
         if ($this->storage != SOCIAL_STORAGE_JOOMLA && in_array($meta->property, $allowed)) {
             $storage = FD::storage($this->storage);
             $url = $storage->getPermalink($relative);
         } else {
             $url = rtrim(JURI::root(), '/') . '/' . $relative;
         }
         $obj->{$meta->property} = $url;
     }
     $paths[$this->id] = $obj;
     if (!isset($paths[$this->id]->{$type})) {
         $paths[$this->id]->{$type} = false;
     }
     return $paths[$this->id]->{$type};
 }
Пример #7
0
 /**
  * Retrieves the user's avatar location
  *
  * @access	public
  * @param   string	$size 	The avatar size to retrieve for.
  * @return  string  The current user's username.
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public function getAvatar($size = SOCIAL_AVATAR_MEDIUM)
 {
     $config = FD::config();
     // If avatar id is being set, we need to get the avatar source
     if ($this->defaultAvatar) {
         $default = $this->defaultAvatar->getSource($size);
         return $default;
     }
     // If the avatar size that is being requested is invalid, return default avatar.
     $default = $this->getDefaultAvatar($size);
     if (!$this->avatars[$size] || empty($this->avatars[$size])) {
         return $default;
     }
     // Get the path to the avatar storage.
     $avatarLocation = FD::cleanPath($config->get('avatars.storage.container'));
     $usersAvatarLocation = FD::cleanPath($config->get('avatars.storage.user'));
     // Build the path now.
     $path = $avatarLocation . '/' . $usersAvatarLocation . '/' . $this->id . '/' . $this->avatars[$size];
     if ($this->avatarStorage == SOCIAL_STORAGE_JOOMLA) {
         // Build final storage path.
         $absolutePath = JPATH_ROOT . '/' . $path;
         // Detect if this file really exists.
         if (!JFile::exists($absolutePath)) {
             return $default;
         }
         $uri = rtrim(JURI::root(), '/') . '/' . $path;
     } else {
         $storage = FD::storage($this->avatarStorage);
         $uri = $storage->getPermalink($path);
     }
     return $uri;
 }
Пример #8
0
 /**
  * Synchronizes avatars from the site over to remote storage
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function syncAvatars()
 {
     $config = FD::config();
     $type = $config->get('storage.photos', 'joomla');
     if ($type == 'joomla') {
         return JText::_('Current avatar storage is set to local.');
     }
     $storage = FD::storage($type);
     // Get the number of files to process at a time
     $limit = $config->get('storage.' . $type . '.limit', 20);
     // Get a list of excluded avatars that previously failed.
     $exclusion = $this->getFailedObjects('avatars');
     // Get a list of avatars to be synchronized over.
     $model = FD::model('Avatars');
     $options = array('limit' => $limit, 'storage' => SOCIAL_STORAGE_JOOMLA, 'uploaded' => true, 'ordering' => 'random', 'exclusion' => $exclusion);
     $avatars = $model->getAvatars($options);
     $total = 0;
     if (!$avatars) {
         return JText::_('No avatars to upload to Amazon S3 right now.');
     }
     foreach ($avatars as $avatar) {
         $small = $avatar->getPath(SOCIAL_AVATAR_SMALL, false);
         $medium = $avatar->getPath(SOCIAL_AVATAR_MEDIUM, false);
         $large = $avatar->getPath(SOCIAL_AVATAR_LARGE, false);
         $square = $avatar->getPath(SOCIAL_AVATAR_SQUARE, false);
         $smallPath = JPATH_ROOT . '/' . $small;
         $mediumPath = JPATH_ROOT . '/' . $medium;
         $largePath = JPATH_ROOT . '/' . $large;
         $squarePath = JPATH_ROOT . '/' . $square;
         $success = false;
         if ($storage->push($avatar->id, $smallPath, $small) && $storage->push($avatar->id, $mediumPath, $medium) && $storage->push($avatar->id, $largePath, $large) && $storage->push($avatar->id, $squarePath, $square)) {
             $avatar->storage = $type;
             // Delete all the files now
             JFile::delete($smallPath);
             JFile::delete($mediumPath);
             JFile::delete($largePath);
             JFile::delete($squarePath);
             $avatar->store();
             $success = true;
         }
         // Add this to the storage logs
         $log = FD::table('StorageLog');
         $log->object_id = $avatar->id;
         $log->object_type = 'avatars';
         $log->target = $type;
         $log->state = $success;
         $log->created = FD::date()->toSql();
         $log->store();
         $total += 1;
     }
     if ($total > 0) {
         return JText::sprintf('%1s avatars uploaded to remote storage', $total);
     }
 }
Пример #9
0
 /**
  * Retrieves the user's avatar location
  *
  * @author  Mark Lee <*****@*****.**>
  * @since   1.2
  * @access  public
  * @param   string  $size   The avatar size to retrieve for.
  * @return  string          The avatar uri.
  */
 public function getAvatar($size = SOCIAL_AVATAR_MEDIUM)
 {
     $config = FD::config();
     // If the avatar size that is being requested is invalid, return default avatar.
     $default = $this->getDefaultAvatar($size);
     if (!$this->avatars[$size] || empty($this->avatars[$size])) {
         // Check if parent exist and call the parent.
         if ($this->hasParent()) {
             return $this->getParent()->getAvatar($size);
         }
         return $default;
     }
     // Get the path to the avatar storage.
     $container = FD::cleanPath($config->get('avatars.storage.container'));
     $location = FD::cleanPath($config->get('avatars.storage.' . $this->cluster_type));
     // Build the path now.
     $path = $container . '/' . $location . '/' . $this->id . '/' . $this->avatars[$size];
     if ($this->avatarStorage == SOCIAL_STORAGE_JOOMLA) {
         // Build final storage path.
         $absolutePath = JPATH_ROOT . '/' . $path;
         // Detect if this file really exists.
         if (!JFile::exists($absolutePath)) {
             return $default;
         }
         $uri = rtrim(JURI::root(), '/') . '/' . $path;
     } else {
         $storage = FD::storage($this->avatarStorage);
         $uri = $storage->getPermalink($path);
     }
     return $uri;
 }