Пример #1
0
 /**
  * Retrieves the privacy object
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function getPrivacyItem($uid, $type, $ownerId, $command)
 {
     static $cached = array();
     // Build the index for cached item
     $index = $uid . $type . $ownerId . $command;
     $key = $uid . '.' . $type;
     if (isset($cached[$index])) {
         return $cached[$index];
     }
     $db = FD::db();
     $result = array();
     static $items = array();
     if (isset($items[$index])) {
         $result = $items[$index];
     } else {
         if (isset(self::$_privacyitems[$key])) {
             if (self::$_privacyitems[$key]) {
                 $result = clone self::$_privacyitems[$key];
             }
         } else {
             if ($uid) {
                 $query = 'select a.' . $db->nameQuote('id') . ', a.' . $db->nameQuote('value') . ' as ' . $db->nameQuote('default') . ', a.' . $db->nameQuote('options') . ', ';
                 $query .= 'b.' . $db->nameQuote('user_id') . ', b.' . $db->nameQuote('uid') . ', b.' . $db->nameQuote('type') . ', b.' . $db->nameQuote('value') . ',';
                 $query .= 'b.' . $db->nameQuote('id') . ' as ' . $db->nameQuote('pid');
                 $query .= ' from ' . $db->nameQuote('#__social_privacy') . ' as a';
                 $query .= '		inner join ' . $db->nameQuote('#__social_privacy_items') . ' as b on a.' . $db->nameQuote('id') . ' = b.' . $db->nameQuote('privacy_id');
                 $query .= ' where b.' . $db->nameQuote('uid') . ' = ' . $db->Quote($uid);
                 $query .= ' and b.' . $db->nameQuote('type') . ' = ' . $db->Quote($type);
                 $query .= ' and a.' . $db->nameQuote('state') . ' = ' . $db->Quote(SOCIAL_STATE_PUBLISHED);
                 if ($ownerId) {
                     $query .= ' and b.' . $db->nameQuote('user_id') . ' = ' . $db->Quote($ownerId);
                 }
                 // var_dump( $ownerId );
                 // echo $query;
                 // echo '<br /><br />';
                 $db->setQuery($query);
                 $result = $db->loadObject();
                 $items[$index] = $result;
             }
         }
     }
     // If we still can't find a result, then we need to load from the default items
     if (!$result || !isset($result->id)) {
         // Retrieve the core values
         $defaultValue = $this->getPrivacyDefaultValues($command, $ownerId);
         $result = clone $defaultValue;
         $result->uid = $uid;
         $result->type = $type;
         $result->user_id = $ownerId;
         $result->value = isset($result->default) ? $result->default : '';
         $result->pid = '0';
     }
     if (!isset($result->options)) {
         $result->options = '';
     }
     $default = FD::call('Privacy', 'toKey', $result->value);
     $options = FD::json()->decode($result->options);
     $result->option = array();
     if ($options) {
         foreach ($options->options as $key => $option) {
             $result->option[$option] = $default == $option ? '1' : '0';
         }
     }
     // get the custom user id.
     $result->custom = array();
     if ($result->value == SOCIAL_PRIVACY_CUSTOM) {
         if ($result->pid) {
             $result->custom = $this->getPrivacyCustom($result->pid);
         } else {
             if ($result->mapid) {
                 $result->custom = $this->getPrivacyCustom($result->mapid, SOCIAL_PRIVACY_TYPE_USER);
             }
         }
     }
     // This is where we define whether the privacy item is editable or not.
     $my = FD::user();
     $result->editable = false;
     if ($result->user_id && $result->user_id == $my->id) {
         $result->editable = true;
     }
     $cached[$index] = $result;
     return $cached[$index];
 }
Пример #2
0
 public function uploadPhoto($log_usr = 0, $type = null)
 {
     // Get current logged in user.
     $my = FD::user($log_usr);
     // Get user access
     $access = FD::access($my->id, SOCIAL_TYPE_USER);
     // Load up the photo library
     $lib = FD::photo($log_usr, $type);
     // Define uploader options
     $options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // Load the iamge object
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Detect if this is a really valid image file.
     if (!$image->isValid()) {
         return "invalid image";
     }
     // Load up the album's model.
     $albumsModel = FD::model('Albums');
     // Create the default album if necessary
     $album = $albumsModel->getDefaultAlbum($log_usr, $type, SOCIAL_ALBUM_STORY_ALBUM);
     // Bind photo data
     $photo = FD::table('Photo');
     $photo->uid = $log_usr;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->state = 1;
     $photo->ordering = 0;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     // Load the photos model
     $photosModel = FD::model('Photos');
     // Get the storage path for this photo
     $storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     if ($paths) {
         foreach ($paths as $type => $fileName) {
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_PATH;
             $meta->property = $type;
             $meta->value = $storage . '/' . $fileName;
             $meta->store();
             // We need to store the photos dimension here
             list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo dimensions
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_WIDTH;
             $meta->property = $type;
             $meta->value = $width;
             $meta->store();
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_HEIGHT;
             $meta->property = $type;
             $meta->value = $height;
             $meta->store();
         }
     }
     // After storing the photo, trigger rules that should occur after a photo is stored
     //$photo->afterStore( $file , $image );
     //$sphoto = new SocialPhotos($photo_obj->id);
     return $photo;
 }
Пример #3
0
 public function getResourcesSettings()
 {
     $config = FD::config();
     $assets = FD::get('Assets');
     $themes = FD::get('Themes');
     $locations = $assets->locations();
     // Build a deterministic cache
     $settings = array("language" => JFactory::getLanguage()->getTag(), "template" => array("site" => $config->get('theme.site', 'wireframe'), "admin" => $config->get('theme.admin', 'default')), "view" => array(), "modified" => filemtime($this->resourceManifestFile));
     // Determine if there are template overrides
     if (JFolder::exists($locations['site_override'])) {
         $settings["template"]["site_override"] = FD::call('Assets', 'getJoomlaTemplate', array('site'));
     }
     if (JFolder::exists($locations['admin_override'])) {
         $settings["template"]["admin_override"] = FD::call('Assets', 'getJoomlaTemplate', array('admin'));
     }
     // Get manifest
     $manifest = $this->getResourcesManifest();
     if (isset($manifest[0]->view) && $manifest[0]->view) {
         foreach ($manifest[0]->view as $view) {
             $original = $view;
             $view = 'themes:/' . $view;
             $path = FD::resolve($view . '.ejs');
             // If the file still does not exist, we'll skip this
             if (!JFile::exists($path)) {
                 continue;
             }
             $settings["view"][] = array("path" => str_ireplace(JPATH_ROOT, '', $path), "modified" => filemtime($path));
         }
     }
     // Build hash
     $settings["id"] = md5(serialize($settings));
     return $settings;
 }
Пример #4
0
 /**
  * Resolve a given POSIX path.
  *
  * <code>
  * <?php
  * // This would translate to administrator/components/com_easysocial/themes/CURRENT_THEME/users/default.php
  * FD::resolve( 'themes:/admin/users/default' );
  *
  * // This would translate to components/com_easysocial/themes/CURRENT_THEME/dashboard/default.php
  * FD::resolve( 'themes:/site/dashboard/default' );
  * ?>
  * </code>
  *
  * @since	1.0
  * @access	public
  * @param	string		The posix path to lookup for.
  * @return	string		The translated path
  */
 public static function resolve($path)
 {
     if (strpos($path, ':/') === false) {
         return false;
     }
     $parts = explode(':/', $path);
     // Get the protocol.
     $protocol = $parts[0];
     // Get the real path.
     $path = $parts[1];
     switch ($protocol) {
         case 'modules':
             return FD::call('Modules', 'resolve', $path);
             break;
         case 'themes':
             return FD::call('Themes', 'resolve', $path);
             break;
         case 'ajax':
             return FD::call('Ajax', 'resolveNamespace', $path);
             break;
         case 'emails':
             return FD::call('Mailer', 'resolve', $path);
             break;
         case 'fields':
         case 'admin':
         case 'apps':
         case 'site':
             $key = 'SOCIAL_' . strtoupper($protocol);
             $basePath = constant($key);
             return $basePath . '/' . $path;
             break;
     }
     return false;
 }
Пример #5
0
 /**
  * Posting photos via story
  *
  * @since   1.0
  * @access  public
  */
 public function uploadStory()
 {
     // Check for request forgeries
     FD::checkToken();
     // Only registered users should be allowed to upload photos
     FD::requireLogin();
     // Get the current view
     $view = $this->getCurrentView();
     // Get current logged in user.
     $my = FD::user();
     // Get user access
     $access = FD::access($my->id, SOCIAL_TYPE_USER);
     // Get the uid and type
     $uid = $this->input->get('uid', 0, 'int');
     $type = $this->input->get('type', '', 'cmd');
     // Load up the photo library
     $lib = FD::photo($uid, $type);
     // Determines if the person exceeded their upload limit
     if ($lib->exceededUploadLimit()) {
         $view->setMessage($lib->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Determines if the person exceeded their daily upload limit
     if ($lib->exceededDailyUploadLimit()) {
         $view->setMessage($lib->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Define uploader options
     $options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($file instanceof SocialException) {
         $view->setMessage($file, SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load the iamge object
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Detect if this is a really valid image file.
     if (!$image->isValid()) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_FILE_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load up the album's model.
     $albumsModel = FD::model('Albums');
     // Create the default album if necessary
     $album = $albumsModel->getDefaultAlbum($uid, $type, SOCIAL_ALBUM_STORY_ALBUM);
     // Bind photo data
     $photo = FD::table('Photo');
     $photo->uid = $uid;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->ordering = 0;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     if (!$state) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_UPLOAD_ERROR_STORING_DB'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load the photos model
     $photosModel = FD::model('Photos');
     // Get the storage path for this photo
     $storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     if ($paths) {
         foreach ($paths as $type => $fileName) {
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_PATH;
             $meta->property = $type;
             $meta->value = $storage . '/' . $fileName;
             $meta->store();
             // We need to store the photos dimension here
             list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo dimensions
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_WIDTH;
             $meta->property = $type;
             $meta->value = $width;
             $meta->store();
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_HEIGHT;
             $meta->property = $type;
             $meta->value = $height;
             $meta->store();
         }
     }
     // After storing the photo, trigger rules that should occur after a photo is stored
     $photo->afterStore($file, $image);
     return $view->call(__FUNCTION__, $photo, $paths, $width, $height);
 }