Example #1
0
 /**
  * subscription toggle.
  *
  * @since 1.0
  * @access public
  */
 public function toggle()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Ensure that the user needs to be logged in.
     FD::requireLogin();
     $uid = JRequest::getInt('uid');
     $type = JRequest::getVar('type');
     $group = JRequest::getVar('group', SOCIAL_APPS_GROUP_USER);
     $notify = JRequest::getVar('notify', '0');
     $my = FD::user();
     $view = FD::view('Subscriptions', false);
     $subscribe = FD::get('Subscriptions');
     $isFollowed = $subscribe->isFollowing($uid, $type, $group, $my->id);
     $verb = $isFollowed ? 'unfollow' : 'follow';
     $state = '';
     if ($isFollowed) {
         // unsubscribe user.
         $state = $subscribe->unfollow($uid, $type, $group, $my->id);
     } else {
         $state = $subscribe->follow($uid, $type, $group, $my->id, $notify);
     }
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'Subscription: Unable to ' . $verb . ' the stream item because of the error message ' . $subscribe->getError());
         // Set the view with error
         $view->setMessage($subscribe->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, $verb);
     }
     return $view->call(__FUNCTION__, $verb);
 }
Example #2
0
 public function __construct($adapter, $options = array())
 {
     $adapter = strtolower($adapter);
     $file = dirname(__FILE__) . '/adapters/' . $adapter . '.php';
     if (!JFile::exists($file)) {
         FD::logError(__FILE__, __LINE__, 'CAPTCHA: Library file ' . $file . ' not found.');
         return false;
     }
     // Include adapter's file.
     require_once $file;
     $class = 'SocialCaptcha' . ucfirst($adapter);
     if (!class_exists($class)) {
         FD::logError(__FILE__, __LINE__, 'CAPTCHA: Library class ' . $class . ' not found.');
         return false;
     }
     // Now we will have to create an instance of the class.
     $this->adapter = new $class($options);
     return $this;
 }
Example #3
0
 /**
  * Renders a sample data given the application id.
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function renderSample()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Load the view
     $view = FD::view('Fields');
     // Get fields library.
     $lib = FD::fields();
     // Get the group from the query.
     $group = JRequest::getWord('group', SOCIAL_FIELDS_GROUP_USER);
     // Get the application id from the query.
     $id = JRequest::getInt('appid');
     // Get the profile id
     $profileId = JRequest::getInt('profileid');
     // If id is not passed in, we need to throw an error.
     if (!$id) {
         FD::logError(__FILE__, __LINE__, 'FIELDS: Application id $appid is invalid.');
         $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILES_FORM_FIELDS_INVALID_APPLICATION'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, false);
     }
     $field = FD::table('Field');
     $field->app_id = $id;
     $app = $field->getApp();
     if (!$app) {
         FD::logError(__FILE__, __LINE__, 'FIELDS: Application id $appid is invalid.');
         $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILES_FORM_FIELDS_INVALID_APPLICATION'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, false);
     }
     // Manually push in the profile id
     $field->profile_id = $profileId;
     $field->element = $app->element;
     // Need to be placed in an array as it is being passed as reference.
     $fields = array(&$field);
     // Prepare the data to be passed to the application
     $data = array();
     // Load language string.
     FD::language()->loadSite();
     // Process onSample trigger
     $lib->trigger('onSample', $group, $fields, $data);
     $field = $fields[0];
     // Call the view.
     return $view->call(__FUNCTION__, $field);
 }
Example #4
0
 /**
  * Retrieves a list of user that shared a particular item
  *
  * @since	1.0
  * @access	public
  */
 public function getSharers()
 {
     // Check for request forgeries
     FD::checkToken();
     // User needs to be logged in
     FD::requireLogin();
     // Get the current view
     $view = $this->getCurrentView();
     // Get the current stream property.
     $id = JRequest::getInt('id');
     $element = JRequest::getString('element');
     // If id is invalid, throw an error.
     if (!$id || !$element) {
         //Internal error logging.
         FD::logError(__FILE__, __LINE__, 'Likes: Unable to process because id or element provided is invalid.');
         $view->setMessage(JText::_('COM_EASYSOCIAL_ERROR_UNABLE_TO_LOCATE_ID'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     $model = FD::model('Repost');
     $sharers = $model->getRepostUsers($id, $element, false);
     return $view->call(__FUNCTION__, $sharers);
 }
Example #5
0
 /**
  * to update privacy on an object by current logged in user
  *
  * @since	1.0
  * @access	public
  * @param
  * @return	string
  */
 public function update()
 {
     FD::checkToken();
     FD::requireLogin();
     $my = FD::user();
     // get data from form post.
     $uid = JRequest::getInt('uid');
     $utype = JRequest::getVar('utype');
     $value = JRequest::getVar('value');
     $pid = JRequest::getVar('pid');
     $customIds = JRequest::getVar('custom', '');
     $streamid = JRequest::getVar('streamid', '');
     $view = FD::view('Privacy', false);
     // If id is invalid, throw an error.
     if (!$uid) {
         //Internal error logging.
         FD::logError(__FILE__, __LINE__, 'Privacy Log: Unable to update privacy on item because id provided is invalid.');
         $view->setError(JText::_('COM_EASYSOCIAL_ERROR_UNABLE_TO_LOCATE_ID'));
         return $view->call(__FUNCTION__);
     }
     $model = FD::model('Privacy');
     $state = $model->update($my->id, $pid, $uid, $utype, $value, $customIds);
     // If there's an error, log this down.
     if (!$state) {
         //Internal error logging.
         FD::logError(__FILE__, __LINE__, 'Privacy Log: Unable to update privacy on item because model returned the error, ' . $model->getError());
         $view->setError($model->getError());
         return $view->call(__FUNCTION__);
     }
     // lets check if there is stream id presented or not. if yes, means we need to update
     // privacy access in stream too.
     if ($streamid) {
         $access = FD::privacy()->toValue($value);
         $stream = FD::stream();
         $stream->updateAccess($streamid, $access, $customIds);
     }
     return $view->call(__FUNCTION__);
 }
Example #6
0
 /**
  * Given a path to the file, install the points.
  *
  * @since	1.0
  * @access	public
  * @param	string		The path to the .points file.
  * @return	bool		True if success false otherwise.
  */
 public function install($path)
 {
     // Import platform's file library.
     jimport('joomla.filesystem.file');
     // Read the contents
     $contents = JFile::read($path);
     // If contents is empty, throw an error.
     if (empty($contents)) {
         FD::logError(__FILE__, __LINE__, 'POINTS: Unable to read the file ' . $path);
         $this->setError(JText::_('Unable to read points file'));
         return false;
     }
     $json = FD::json();
     $data = $json->decode($contents);
     // @TODO: Double check that this file is a valid JSON file.
     // Ensure that it's in an array form.
     $data = FD::makeArray($data);
     // Let's test if there's data.
     if (empty($data)) {
         FD::logError(__FILE__, __LINE__, 'POINTS: Unable to read the file ' . $path);
         $this->setError(JText::_('Unable to read points file'));
         return false;
     }
     $result = array();
     foreach ($data as $row) {
         // Load the tables
         $point = FD::table('Points');
         // If this already exists, we need to skip this.
         $state = $point->load(array('command' => $row->command, 'extension' => $row->extension));
         if ($state) {
             continue;
         }
         $point->bind($row);
         // If there is params set on the rule file, we need to be able to detect it.
         $params = null;
         if (isset($row->params) && $row->params) {
             // Ensure that the params are json encoded.
             $point->params = FD::json()->encode($row->params);
         }
         // Store it now.
         $point->store();
         // Load language file.
         JFactory::getLanguage()->load($row->extension, JPATH_ROOT . '/administrator');
         $result[] = JText::_($point->title);
     }
     return $result;
 }
Example #7
0
 public function install($path)
 {
     jimport('joomla.filesystem.file');
     $data = FD::makeObject($path);
     if (empty($data)) {
         FD::logError(__FILE__, __LINE__, 'ACCESS: Unable to read the file ' . $path);
         $this->setError(JText::_('Unable to read access file'));
         return false;
     }
     $json = FD::json();
     $now = FD::date()->toSQL();
     $result = array();
     foreach ($data as $row) {
         if (empty($row->name)) {
             continue;
         }
         $name = $row->name;
         unset($row->name);
         $element = '';
         if (!empty($row->element)) {
             $element = $row->element;
         } else {
             // If no element is defined, then we check if the name has a . starting from index 1 to get the first segment
             if (strpos($name, '.') > 0) {
                 $tmp = explode('.', $name);
                 $element = $tmp[0];
             }
         }
         unset($row->element);
         $group = !empty($row->group) ? $row->group : SOCIAL_TYPE_USER;
         unset($row->group);
         $extension = !empty($row->extension) ? $row->extension : SOCIAL_COMPONENT_NAME;
         unset($row->extension);
         $table = FD::table('accessrules');
         $state = $table->load(array('name' => $name, 'element' => $element, 'group' => $group, 'extension' => $extension));
         if ($state) {
             continue;
         }
         $table->name = $name;
         $table->element = $element;
         $table->group = $group;
         $table->extension = $extension;
         $this->loadLanguage($extension);
         // JText here because the title/description is not used in frontend, and also due to "search" using SQL like to perform, we should store translated text into db
         $table->title = !empty($row->title) ? JText::_($row->title) : '';
         $table->description = !empty($row->description) ? JText::_($row->description) : '';
         unset($row->title);
         unset($row->description);
         $table->state = SOCIAL_STATE_PUBLISHED;
         $table->created = $now;
         $table->params = $json->encode($row);
         $table->store();
         $result[] = $table->title;
     }
     return $result;
 }
Example #8
0
 /**
  * Deletes a file from the system.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	null
  */
 public function delete()
 {
     // Check for request forgeries
     FD::checkToken();
     // Only logged in users are allowed to delete anything
     FD::requireLogin();
     // Get the current view
     $view = $this->getCurrentView();
     // Get the current user
     $my = FD::user();
     // Get the uploader id
     $id = JRequest::getInt('id');
     $uploader = FD::table('Uploader');
     $uploader->load($id);
     // Check if the user is really permitted to delete the item
     if (!$id || !$uploader->id || $uploader->user_id != $my->id) {
         return $view->call(__FUNCTION__);
     }
     $state = $uploader->delete();
     // If deletion fails, silently log the error
     if (!$state) {
         FD::logError(__FILE__, __LINE__, JText::_('UPLOADER: Unable to delete the item [' . $uploader->id . '] because ' . $uploader->getError()));
     }
     return $view->call(__FUNCTION__);
 }
Example #9
0
 /**
  * Hides a stream item.
  *
  * @since	1.0
  * @access	public
  */
 public function unhideapp()
 {
     // Check for request forgeries!
     FD::checkToken();
     FD::requireLogin();
     $context = JRequest::getVar('context');
     $my = FD::user();
     $view = FD::view('Stream', false);
     // Get the view.
     $view = FD::view('Stream', false);
     if (empty($context)) {
         FD::logError(__FILE__, __LINE__, 'STREAM: Unable to unhide stream because app provided is invalid or not found.');
         $view->setErrors(JText::_('COM_EASYSOCIAL_ERROR_UNABLE_TO_LOCATE_APP'));
         return $view->call(__FUNCTION__);
     }
     $model = FD::model('Stream');
     $state = $model->unhideapp($context, $my->id);
     if (!$state) {
         $view->setErrors(JText::_('COM_EASYSOCIAL_STREAM_FAILED_UNHIDE'));
         return $view->call(__FUNCTION__);
     }
     return $view->call(__FUNCTION__);
 }
Example #10
0
 /**
  * Override parent's behavior of deleting as we also need to delete physical files.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return	bool
  */
 public function delete($pk = null)
 {
     $state = parent::delete();
     if (!$state) {
         return false;
     }
     // Get config
     $config = FD::config();
     // Get the default avatars storage location.
     $avatarsPath = JPATH_ROOT . '/' . FD::cleanPath($config->get('avatars.storage.container'));
     // Test if the avatars path folder exists. If it doesn't we need to create it.
     if (!FD::makeFolder($avatarsPath)) {
         FD::logError(__FILE__, __LINE__, 'AVATARS: Unable to create the path ' . $avatarsPath);
         $this->setError(JText::_('Errors when creating default container for avatar'));
         return false;
     }
     // Get the default avatars storage location for this type.
     $typePath = $config->get('avatars.storage.' . $this->type);
     $storagePath = $avatarsPath . '/' . FD::cleanPath($typePath);
     // Set the absolute path based on the uid.
     $storagePath = $storagePath . '/' . $this->uid;
     $this->deleteFolder($storagePath);
     return $state;
 }
Example #11
0
 /**
  * Processes before the user account is created when user signs in with oauth.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function onRegisterOAuthAfterSave(&$data, &$oauthClient, SocialUser &$user)
 {
     // Let's see if avatarUrl is provided.
     if (!isset($data['avatar']) || empty($data['avatar'])) {
         return;
     }
     $avatarUrl = $data['avatar'];
     // Store the avatar internally.
     $key = md5($data['oauth_id'] . $data['username']);
     $tmpAvatarPath = SOCIAL_MEDIA . '/tmp/' . $key;
     $tmpAvatarFile = $tmpAvatarPath . '/' . $key;
     jimport('joomla.filesystem.folder');
     if (!JFolder::exists($tmpAvatarPath)) {
         $state = JFolder::create($tmpAvatarPath);
         if (!$state) {
             FD::logError(__FILE__, __LINE__, 'OAUTH: Unable to create avatar folder.');
         }
     }
     $connector = FD::get('Connector');
     $connector->addUrl($avatarUrl);
     $connector->connect();
     $contents = $connector->getResult($avatarUrl);
     jimport('joomla.filesystem.file');
     if (!JFile::write($tmpAvatarFile, $contents)) {
         dump('here');
         FD::logError(__FILE__, __LINE__, 'AVATAR: Unable to store oauth avatar to tmp folder, ' . $tmpAvatarFile);
         return;
     }
     $image = FD::image();
     $image->load($tmpAvatarFile);
     $avatar = FD::avatar($image, $user->id, SOCIAL_TYPE_USER);
     // Check if there's a profile photos album that already exists.
     $albumModel = FD::model('Albums');
     // Retrieve the user's default album
     $album = $albumModel->getDefaultAlbum($user->id, SOCIAL_TYPE_USER, SOCIAL_ALBUM_PROFILE_PHOTOS);
     $photo = FD::table('Photo');
     $photo->uid = $user->id;
     $photo->user_id = $user->id;
     $photo->type = SOCIAL_TYPE_USER;
     $photo->album_id = $album->id;
     $photo->title = $user->getName();
     $photo->caption = JText::_('COM_EASYSOCIAL_PHOTO_IMPORTED_FROM_FACEBOOK');
     $photo->ordering = 0;
     // We need to set the photo state to "SOCIAL_PHOTOS_STATE_TMP"
     $photo->state = SOCIAL_PHOTOS_STATE_TMP;
     // Try to store the photo first
     $state = $photo->store();
     if (!$state) {
         $this->setError(JText::_('PLG_FIELDS_AVATAR_ERROR_CREATING_PHOTO_OBJECT'));
         return false;
     }
     // Push all the ordering of the photo down
     $photosModel = FD::model('photos');
     $photosModel->pushPhotosOrdering($album->id, $photo->id);
     // If album doesn't have a cover, set the current photo as the cover.
     if (!$album->hasCover()) {
         $album->cover_id = $photo->id;
         // Store the album
         $album->store();
     }
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $storage = $photoLib->getStoragePath($album->id, $photo->id);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     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();
     }
     // Synchronize Indexer
     $indexer = FD::get('Indexer');
     $template = $indexer->getTemplate();
     $template->setContent($photo->title, $photo->caption);
     // $url 	= FRoute::photos(array('layout' => 'item', 'id' => $photo->getAlias()));
     $url = $photo->getPermalink();
     $url = '/' . ltrim($url, '/');
     $url = str_replace('/administrator/', '/', $url);
     $template->setSource($photo->id, SOCIAL_INDEXER_TYPE_PHOTOS, $photo->uid, $url);
     $template->setThumbnail($photo->getSource('thumbnail'));
     $indexer->index($template);
     $options = array();
     if ($user->state == SOCIAL_USER_STATE_PENDING) {
         $options['addstream'] = false;
     }
     // Create the avatars now
     $avatar->store($photo, $options);
     // Once we are done creating the avatar, delete the temporary folder.
     $state = JFolder::delete($tmpAvatarPath);
 }
Example #12
0
 /**
  * Allows caller to uninstall an application
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function uninstallApp()
 {
     // Check for request forgeries
     FD::checkToken();
     // Only allow registered users
     FD::requireLogin();
     // Get app id.
     $id = JRequest::getInt('id');
     // Check if app is a valid app
     $app = FD::table('App');
     // Get the current view
     $view = $this->getCurrentView();
     if (!$app->load($id)) {
         FD::logError(__FILE__, __LINE__, 'Apps: invalid appid: $id provided');
         $view->setMessage(JText::_('COM_EASYSOCIAL_APPS_UNINSTALL_ERROR_OCCURED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, false);
     }
     // Try to uninstall the app.
     $result = $app->uninstallUserApp();
     if (!$result) {
         FD::logError(__FILE__, __LINE__, 'Error occured during uninstallation');
         $view->setMessage(JText::_('COM_EASYSOCIAL_APPS_UNINSTALL_ERROR_OCCURED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, false);
     }
     return $view->call(__FUNCTION__, true);
 }
Example #13
0
 /**
  * Allows caller to uninstall this app from the site.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function uninstall()
 {
     $path = SOCIAL_APPS . '/' . $this->group . '/' . $this->element;
     // Check if the folder exists.
     if (!JFolder::exists($path)) {
         FD::logError(__FILE__, __LINE__, 'APPS: Removal of app folder failed because the folder ' . $path . ' does not exist.');
     } else {
         // Try to delete the folder
         $state = JFolder::delete($path);
         if (!$state) {
             FD::logError(__FILE__, __LINE__, 'APPS: Removal of app folder ' . $path . ' failed because of permission issues.');
         }
     }
     // Delete app views
     $model = FD::model('Apps');
     $model->deleteExistingViews($this->id);
     // Just delete this record from the database.
     $state = $this->delete();
     // Remove the stream item as well.
     FD::stream()->delete($this->id, SOCIAL_TYPE_APPS);
     return $state;
 }
Example #14
0
 public function registerUser($user_id)
 {
     $table = FD::table('alertmap');
     $loaded = $table->loadByAlertId($this->id, $user_id);
     if (!$loaded) {
         $table->alert_id = $this->id;
         $table->user_id = $user_id;
         $table->email = $this->email;
         $table->system = $this->system;
         $state = $table->store();
         if (!$state) {
             FD::logError(__FILE__, __LINE__, $table->getError());
             return false;
         }
     }
     return true;
 }
Example #15
0
 public function update(array $newData)
 {
     // IMPORTANT:
     // No escape is required here as we store the data as is
     // General loop to update the rest of the new data
     foreach ($newData as $key => $value) {
         if (property_exists($this, $key)) {
             $this->{$key} = $value;
         }
     }
     $state = $this->store();
     if (!$state) {
         FD::logError(__FILE__, __LINE__, $this->getError());
         return false;
     }
     return true;
 }
Example #16
0
 /**
  * Given a path to the file, install the badge rule file.
  *
  * @since	1.0
  * @access	public
  * @param	string		The path to the .points file.
  * @return	bool		True if success false otherwise.
  */
 public function install($path)
 {
     // Import platform's file library.
     jimport('joomla.filesystem.file');
     // Read the contents
     $contents = JFile::read($path);
     // If contents is empty, throw an error.
     if (empty($contents)) {
         FD::logError(__FILE__, __LINE__, 'BADGES: Unable to read the file ' . $path);
         $this->setError(JText::_('COM_EASYSOCIAL_BADGES_UNABLE_TO_READ_BADGE_FILE'));
         return false;
     }
     $json = FD::json();
     $data = $json->decode($contents);
     // @TODO: Double check that this file is a valid JSON file.
     // Ensure that it's in an array form.
     $data = FD::makeArray($data);
     // Let's test if there's data.
     if (empty($data)) {
         FD::logError(__FILE__, __LINE__, 'BADGES: Unable to read the file ' . $path);
         $this->setError(JText::_('COM_EASYSOCIAL_BADGES_UNABLE_TO_READ_BADGE_FILE'));
         return false;
     }
     $result = array();
     foreach ($data as $row) {
         // Load the tables
         $badge = FD::table('Badge');
         // If this already exists, we need to skip this.
         $state = $badge->load(array('extension' => $row->extension, 'command' => $row->command));
         if ($state) {
             continue;
         }
         // Set to published by default.
         $badge->state = SOCIAL_STATE_PUBLISHED;
         // Bind the badge data.
         $badge->bind($row);
         // Store it now.
         $badge->store();
         // Load language file.
         JFactory::getLanguage()->load($row->extension, JPATH_ROOT . '/administrator');
         $result[] = JText::_($badge->title);
     }
     return $result;
 }
Example #17
0
 /**
  * Returns a list of menus for the admin sidebar.
  *
  * Example:
  * <code>
  * <?php
  * $model 	= FD::model( 'Sidebar' );
  *
  * // Returns an array of menu items.
  * $model->getItems();
  * ?>
  * </code>
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	Array
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public function getItems()
 {
     // @TODO: Configurable theme path for the back end.
     // Get the sidebar ordering from defaults first
     $defaults = SOCIAL_ADMIN_DEFAULTS . '/sidebar.json';
     $sidebarOrdering = FD::makeObject($defaults);
     if (!$sidebarOrdering) {
         return false;
     }
     $items = array();
     jimport('joomla.filesystem.folder');
     $path = SOCIAL_ADMIN_DEFAULTS . '/sidebar';
     $files = JFolder::files($path, '.json');
     foreach ($sidebarOrdering as $sidebarItem) {
         // Remove the reference from the $files array if it is defined in the ordering
         $index = array_search($sidebarItem . '.json', $files);
         if ($index !== false) {
             unset($files[$index]);
         }
         // Get the sidebar items in the defined order
         $content = FD::makeObject($path . '/' . $sidebarItem . '.json');
         if ($content !== false) {
             $items[] = $content;
         }
     }
     // Add any remaining files into items
     foreach ($files as $file) {
         $content = FD::makeObject($path . '/' . $file);
         if ($content !== false) {
             $items[] = $content;
         }
     }
     // If there are no items there, it should throw an error.
     if (!$items) {
         FD::logError(__FILE__, __LINE__, 'SIDEBAR: Unable to parse menu.json file.');
         return false;
     }
     // Initialize default result.
     $result = array();
     foreach ($items as $item) {
         // Generate a unique id.
         $uid = uniqid();
         // Generate a new group object for the sidebar.
         $obj = clone $item;
         // Assign the unique id.
         $obj->uid = $uid;
         // Initialize the counter
         $obj->count = 0;
         // Test if there's a counter key.
         if (isset($obj->counter)) {
             $namespace = explode('/', $obj->counter);
             $method = $namespace[1];
             $namespace = $namespace[0];
             $model = FD::model($namespace);
             $count = $model->{$method}();
             $obj->count = $count;
         }
         if (!empty($obj->childs)) {
             $childItems = array();
             usort($obj->childs, array('EasySocialModelSidebar', 'sortItems'));
             foreach ($obj->childs as $child) {
                 // Clone the child object.
                 $childObj = clone $child;
                 // Let's get the URL.
                 $url = array('index.php?option=com_easysocial');
                 $query = FD::makeArray($child->url);
                 // Set the url into the child item so that we can determine the active submenu.
                 $childObj->url = $child->url;
                 if ($query) {
                     foreach ($query as $queryKey => $queryValue) {
                         $url[] = $queryKey . '=' . $queryValue;
                         // If this is a call to the controller, it must have a valid token id.
                         if ($queryKey == 'controller') {
                             $url[] = FD::token() . '=1';
                         }
                     }
                 }
                 // Set the item link.
                 $childObj->link = implode('&amp;', $url);
                 // Initialize the counter
                 $childObj->count = 0;
                 // Check if there's any sql queries to execute.
                 if (isset($childObj->counter)) {
                     $namespace = explode('/', $childObj->counter);
                     $method = $namespace[1];
                     $namespace = $namespace[0];
                     $model = FD::model($namespace);
                     $count = $model->{$method}();
                     $childObj->count = $count;
                 }
                 // Add a unique id for the side bar for accordion purposes.
                 $childObj->uid = $uid;
                 // Add the menu item to the child items.
                 $childItems[] = $childObj;
             }
             $obj->childs = $childItems;
         }
         $result[] = $obj;
     }
     // @TODO: Render applications to see if they want to add any menu's here.
     return $result;
 }
Example #18
0
 /**
  * Processes the installation package from directory method.
  *
  * @since	1.0
  * @access	public
  * @return	null
  *
  * @author	Mark Lee <*****@*****.**>
  **/
 public function installFromDirectory($path = '')
 {
     // Check for request forgeries.
     FD::checkToken();
     if (empty($path)) {
         $path = JRequest::getVar('package-directory', '');
     }
     $view = $this->getCurrentView();
     $jConfig = FD::jconfig();
     $info = FD::info();
     // Try to detect if the temporary path is the same as the default path.
     if ($path == $jConfig->getValue('tmp_path') || empty($path)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_INSTALLER_PLEASE_SPECIFY_DIRECTORY'), SOCIAL_MSG_ERROR);
         return $view->call('install');
     }
     // Retrieve the installer library.
     $installer = FD::get('Installer');
     // Try to load the installation from path.
     $state = $installer->load($path);
     // If there's an error, we need to log it down.
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'APPS: Unable to install apps from directory ' . $path . ' because of the error ' . $installer->getError());
         $view->setMessage($installer->getError(), SOCIAL_MSG_ERROR);
         return $view->call('install');
     }
     // Let's try to install it now.
     $app = $installer->install();
     // If there's an error installing, log this down.
     if ($app === false) {
         FD::logError(__FILE__, __LINE__, 'APPS: Unable to install apps from directory ' . $path . ' because of the error ' . $installer->getError());
         $view->setMessage($installer->getError(), SOCIAL_MSG_ERROR);
         return $view->call('install');
     }
     return $view->installCompleted($app);
 }
Example #19
0
 public function getComments($options = array())
 {
     // Available options
     // element
     // uid
     // start
     // limit
     // order
     // direction
     // Define the default parameters
     $defaults = array('start' => 0, 'limit' => 5, 'order' => 'created', 'direction' => 'asc');
     $options = array_merge($defaults, $options);
     $db = FD::db();
     $sql = $db->sql();
     $useCache = true;
     // SELECT
     $sql->column('a.*');
     $sql->select($this->table, 'a');
     if (FD::config()->get('users.blocking.enabled') && !JFactory::getUser()->guest) {
         $sql->leftjoin('#__social_block_users', 'bus');
         $sql->on('a.created_by', 'bus.user_id');
         $sql->on('bus.target_id', JFactory::getUser()->id);
         $sql->isnull('bus.id');
     }
     // WHERE
     if (isset($options['stream_id'])) {
         $sql->where('a.stream_id', $options['stream_id']);
     }
     if (isset($options['element'])) {
         $sql->where('a.element', $options['element']);
     }
     if (isset($options['uid'])) {
         $sql->where('a.uid', $options['uid']);
     }
     if (isset($options['commentid'])) {
         $useCache = false;
         $sql->where('a.id', $options['commentid'], '>=');
     }
     if (isset($options['parentid'])) {
         if ($options['parentid']) {
             $useCache = false;
         }
         $sql->where('a.parent', $options['parentid']);
     }
     if ($options['order'] != 'created') {
         $useCache = false;
     }
     // ORDER
     $sql->order($options['order'], $options['direction']);
     // LIMIT
     if (!empty($options['limit'])) {
         $sql->limit($options['start'], $options['limit']);
     }
     // echo $sql;exit;
     $comments = false;
     $loadSQL = true;
     $key = '';
     if ($useCache) {
         // $key = $options['uid'] . '.' . $options['element'] . '.' . $options['limit'];
         if (isset($options['stream_id'])) {
             // lets try to get the count from the static variable.
             $key = $options['stream_id'] . '.' . 'stream';
         } else {
             $key = $options['uid'] . '.' . $options['element'];
         }
         if (isset(self::$_data[$key])) {
             $loaded = self::$_data[$key];
             if ($loaded) {
                 if ($options['direction'] == 'asc') {
                     asort($loaded);
                 } else {
                     arsort($loaded);
                 }
                 if (!empty($options['limit'])) {
                     $loaded = array_slice($loaded, $options['start'], $options['limit']);
                 }
                 $comments = $loaded;
                 $loadSQL = false;
             }
         }
     }
     if ($loadSQL) {
         // var_dump('getComments::' . $key);
         // exit;
         //
         $db->setQuery($sql);
         $comments = $db->loadObjectList();
     }
     if ($comments === false) {
         FD::logError(__FILE__, __LINE__, 'Unable to get comments');
         return false;
     }
     $tables = array();
     foreach ($comments as $comment) {
         $table = FD::table('comments');
         $table->bind($comment);
         $tables[] = $table;
     }
     return $tables;
 }
Example #20
0
 public function loadRule($rulename)
 {
     if (empty($this->rules[$rulename])) {
         $table = FD::table('Alert');
         $rule = $table->load(array('element' => $this->element, 'rule' => $rulename, 'published' => SOCIAL_STATE_PUBLISHED));
         if (!$rule) {
             FD::logError(__FILE__, __LINE__, 'No such rule.');
             return false;
         }
         $this->rules[$rulename] = $table;
     }
     return $this;
 }
Example #21
0
 /**
  * Allows caller to delete an activity item
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function delete()
 {
     FD::checkToken();
     FD::requireLogin();
     // get required form post variable
     $id = JRequest::getInt('id');
     // Get the view.
     $view = $this->getCurrentView();
     // Load the stream item
     $item = FD::table('StreamItem');
     $item->load($id);
     // If id is invalid, throw an error.
     if (!$id || !$item->id) {
         //Internal error logging.
         FD::logError(__FILE__, __LINE__, 'Activity Log: Unable to delete item because id provided is invalid.');
         $view->setError(JText::_('COM_EASYSOCIAL_ERROR_UNABLE_TO_LOCATE_ID'));
         return $view->call(__FUNCTION__);
     }
     // Check if the current user is allowed to delete this stream item
     if (!$item->deleteable()) {
         $view->setError(JText::_('COM_EASYSOCIAL_ACTIVITIES_NOT_ALLOWED_TO_DELETE_ITEM'));
         return $view->call(__FUNCTION__);
     }
     $model = FD::model('Activities');
     $state = $model->delete($id);
     if (!$state) {
         //Internal error logging.
         FD::logError(__FILE__, __LINE__, 'Activity Log: Unable to delete item because model returned the error, ' . $model->getError());
         $view->setError($model->getError());
         return $view->call(__FUNCTION__);
     }
     return $view->call(__FUNCTION__);
 }
Example #22
0
 public function getVendor($name)
 {
     static $vendorClasses = array();
     if (empty($vendorClasses[$name])) {
         $vendorFile = dirname(__FILE__) . '/vendors/' . $name . '.php';
         if (JFile::exists($vendorFile)) {
             require_once $vendorFile;
             $vendorClass = 'SocialSharing' . ucfirst($name);
             if (class_exists($vendorClass)) {
                 $vendor = new $vendorClass($name, $this->options);
             } else {
                 FD::logError(__FILE__, __LINE__, 'Vendor class not found: ' . $vendorClass);
                 return false;
             }
         } else {
             FD::logError(__FILE__, __LINE__, 'Vendor file not found: ' . $vendorFile);
             return false;
         }
         $vendorClasses[$name] = $vendor;
     }
     return $vendorClasses[$name];
 }
Example #23
0
 /**
  * Logics to store a profile avatar.
  *
  * @since	1.0
  * @access	public
  * @author	Mark Lee <*****@*****.**>
  */
 public function uploadAvatar($file)
 {
     $avatar = FD::table('Avatar');
     $state = $avatar->load(array('uid' => $this->id, 'type' => SOCIAL_TYPE_PROFILES));
     if (!$state) {
         $avatar->uid = $this->id;
         $avatar->type = SOCIAL_TYPE_PROFILES;
         $avatar->store();
     }
     // Determine the state of the upload.
     $state = $avatar->upload($file);
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'PROFILES: Unable to upload the avatar.');
         $this->setError(JText::_('There was some problems uploading the avatar'));
         return false;
     }
     // Store the data.
     $avatar->store();
     return;
 }
Example #24
0
 /**
  * Creates a new friend list.
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function storeList()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Check if user is valid.
     FD::requireLogin();
     // Check if friends list is enabled
     $config = FD::config();
     // Get the current view.
     $view = $this->getCurrentView();
     // Get current logged in user.
     $my = FD::user();
     // @friends.list.enabled
     // Check if the friend list feature is enabled
     if (!$config->get('friends.list.enabled')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LIST_DISABLED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get post data.
     $data = JRequest::get('POST');
     // Detect if this is an edited list or a new list
     $id = JRequest::getVar('id');
     // Generate a new list.
     $list = FD::table('List');
     // Get the access
     $access = FD::access();
     // @access friends.list.enabled
     // Check if the user is allowed to create friend lists
     if (!$access->allowed('friends.list.enabled')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LISTS_ACCESS_NOT_ALLOWED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Check for title
     if (empty($data['title'])) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LISTS_TITLE_REQUIRED'), SOCIAL_MSG_ERROR);
         return $view->call('listForm');
     }
     if (!empty($id)) {
         $list->load($id);
     } else {
         // This will be a new friend list, check if the user has already reached the limit
         $listModel = FD::model('Lists');
         // Get the total friends list a user has
         $totalFriendsList = $listModel->getTotalLists($my->id);
         if ($access->exceeded('friends.list.limit', $totalFriendsList)) {
             $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LISTS_ACCESS_LIMIT_EXCEEDED'));
             return $view->call(__FUNCTION__);
         }
     }
     // Bind the list with the posted data.
     $list->bind($data);
     // Check if the user owns this list item.
     if (!empty($list->id) && $my->id != $list->user_id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_LISTS_ERROR_LIST_IS_NOT_OWNED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Set the creator of the list.
     $list->user_id = $my->id;
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$list);
     // @trigger: onFriendListBeforeSave
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendListBeforeSave', $args);
     // Try to store the list.
     $state = $list->store();
     // @trigger: onFriendListBeforeSave
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendListAfterSave', $args);
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'FRIENDS: Unable to create new friend list for user ' . $my->id);
         $view->setMessage(JText::_('COM_EASYSOCIAL_LISTS_ERROR_CREATING_LIST'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, $list);
     }
     // Get friends from this list
     $friends = JRequest::getVar('uid');
     // Assign these friends into the list.
     $list->addFriends($friends);
     $view->setMessage(JText::_('COM_EASYSOCIAL_LISTS_CREATED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS);
     return $view->call(__FUNCTION__, $list);
 }
Example #25
0
 private function triggerBeforeGetStream(&$options)
 {
     if (!$options) {
         return;
     }
     $view = JRequest::getCmd('view', '');
     // Get apps library.
     $apps = FD::getInstance('Apps');
     // Determine the app group
     $group = SOCIAL_APPS_GROUP_USER;
     // If it is in the group view we should render the apps based on the appropriate group
     if ($view && ($view == 'groups' || $view == 'events' || $view == 'stream') && (isset($options['clusterType']) && $options['clusterType'])) {
         $group = $options['clusterType'];
     }
     // Try to load user apps
     $state = $apps->load($group);
     // By default return true.
     $result = true;
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'STREAMS: No applications loaded.');
         return false;
     }
     // Only go through dispatcher when there is some apps loaded, otherwise it's pointless.
     $dispatcher = FD::dispatcher();
     // Pass arguments by reference.
     $args = array(&$options, $view);
     $dispatcher->trigger($group, 'onBeforeGetStream', $args);
 }
Example #26
0
 /**
  * Processes before the user account is created when user signs in with oauth.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function onRegisterOAuthAfterSave(&$data, &$oauthClient, SocialUser &$user)
 {
     $cover = isset($data['cover']) ? $data['cover'] : '';
     // If cover is not provided, skip this.
     if (!$cover) {
         return;
     }
     // Get the cover URL
     $coverUrl = $cover->url;
     // Get the session object.
     $uid = SocialFieldsUserCoverHelper::genUniqueId($this->inputName);
     // Get the user object.
     $user = FD::user();
     // Store the cover internally first.
     $tmpPath = SOCIAL_TMP . '/' . $uid . '_cover';
     $tmpFile = $tmpPath . '/' . $uid;
     // Now we need to get the image data.
     $connector = FD::connector();
     $connector->addUrl($coverUrl);
     $connector->connect();
     $contents = $connector->getResult($coverUrl);
     jimport('joomla.filesystem.file');
     if (!JFile::write($tmpFile, $contents)) {
         FD::logError(__FILE__, __LINE__, 'AVATAR: Unable to store oauth cover to tmp folder, ' . $tmpPath);
         return;
     }
     // Ensure that the image is valid.
     if (!SocialFieldsUserCoverHelper::isValid($tmpFile)) {
         FD::logError(__FILE__, __LINE__, 'AVATAR: Invalid image provided for cover ' . $tmpFile);
         return;
     }
     // Create the default album for this cover.
     $album = SocialFieldsUserCoverHelper::getDefaultAlbum($user->id);
     // Once the album is created, create the photo object.
     $photo = SocialFieldsUserCoverHelper::createPhotoObject($user->id, SOCIAL_TYPE_USER, $album->id, $data['oauth_id'], true);
     // Set the new album with the photo as the cover.
     $album->cover_id = $photo->id;
     $album->store();
     // Generates a unique name for this image.
     $name = md5($data['oauth_id'] . $this->inputName . FD::date()->toMySQL());
     // Load our own image library
     $image = FD::image();
     // Load up the file.
     $image->load($tmpFile, $name);
     // Load up photos library
     $photos = FD::get('Photos', $image);
     $storage = $photos->getStoragePath($album->id, $photo->id);
     // Create avatars
     $sizes = $photos->create($storage);
     foreach ($sizes as $size => $path) {
         // Now we will need to store the meta for the photo.
         $meta = SocialFieldsUserCoverHelper::createPhotoMeta($photo, $size, $path);
     }
     // Once all is done, we just need to update the cover table so the user
     // will start using this cover now.
     $coverTable = FD::table('Cover');
     $state = $coverTable->load(array('uid' => $user->id, 'type' => SOCIAL_TYPE_USER));
     // User does not have a cover.
     if (!$state) {
         $coverTable->uid = $user->id;
         $coverTable->type = SOCIAL_TYPE_USER;
         $coverTable->y = $cover->offset_y;
     }
     // Set the cover to pull from photo
     $coverTable->setPhotoAsCover($photo->id);
     // Save the cover.
     $coverTable->store();
 }
Example #27
0
 /**
  * Scans for .alert rules throughout the site.
  *
  * @since	1.0
  * @access	public
  */
 public function scan()
 {
     FD::checkToken();
     // Get the allowed rule scan sections
     $config = FD::config();
     // Retrieve the view.
     $view = $this->getCurrentView();
     // Get the current path that we should be searching for.
     $file = JRequest::getVar('file', '');
     // Log errors when invalid data is passed in.
     if (empty($file)) {
         FD::logError(__FILE__, __LINE__, 'ALERTS: Invalid file path given to scan.');
     }
     // Retrieve the points model to scan for the path
     $model = FD::model('Alert');
     $obj = new stdClass();
     // Format the output to display the relative path.
     $obj->file = str_ireplace(JPATH_ROOT, '', $file);
     $obj->rules = $model->install($file);
     return $view->call(__FUNCTION__, $obj);
 }
Example #28
0
 /**
  * Responsible to attach the list of field apps into the dispatcher object.
  *
  * @since	1.0
  * @access	public
  */
 public function load($fieldGroup, &$fields)
 {
     // If there is no fields, there's no point running them at all.
     if (!$fields) {
         return false;
     }
     // Final result
     $finalItems = array();
     // Go through each of the fields.
     foreach ($fields as $field) {
         // Set the key.
         $element = $field->element;
         // Load the language file for this field.
         // $languageElement 	= 'plg_fields_' . $fieldGroup . '_' . $element;
         // JFactory::getLanguage()->load( $languageElement , JPATH_ROOT . '/administrator' );
         // $field->loadLanguage();
         // If field is already loaded, ignore and continue.
         if (isset($this->loaded[$element]) && $this->loaded[$element] !== false) {
             // If he field has already been loaded, add them to the final items.
             $finalItems[] = $this->loaded[$element];
             continue;
         }
         // Get the file path
         $filePath = SOCIAL_APPS . '/' . SOCIAL_APPS_TYPE_FIELDS . '/' . $fieldGroup . '/' . $element . '/' . $element . '.php';
         // If file doesn't exist, ignore this
         if (!JFile::exists($filePath)) {
             // @TODO: Log error when the file of the field does not exist.
             FD::logError(__FILE__, __LINE__, 'FIELDS: file ' . $filePath . ' not found');
             $this->loaded[$element] = false;
             continue;
         }
         // Include the fields file.
         include_once $filePath;
         // Build the class name.
         $className = 'SocialFields' . ucfirst($fieldGroup) . ucfirst($field->element);
         // If the class doesn't exist in this context, skip the whole loading.
         if (!class_exists($className)) {
             // Log error when the class does not exist.
             FD::logError(__FILE__, __LINE__, 'FIELDS: Field element class not found, ' . $className);
             $this->loaded[$element] = false;
             continue;
         }
         // Initialize configuration.
         $config = array('element' => $field->element, 'group' => $fieldGroup);
         // Instantiate the new object here.
         $fieldObj = new $className($config);
         // If the class is not part of our package, skip this.
         if (!$fieldObj instanceof SocialFieldItem) {
             // Log error when the class does not exist.
             FD::logError(__FILE__, __LINE__, 'FIELDS: Field element class ' . $className . ' not a descendent of SocialFieldItem');
             // @TODO: Log error when class is not part of the package.
             $this->loaded[$field->element] = false;
             continue;
         }
         // Add this to the property so we know that it wouldn't get executed again.
         $this->loaded[$field->element] = $fieldObj;
         // Assign the field object to the final items.
         $finalItems[] = $fieldObj;
     }
     return $finalItems;
     // // Only people has this app.
     // FD::getInstance( 'Apps' )->load( SOCIAL_APPS_TYPE_FIELDS );
 }
Example #29
0
 public function saveFields($uid, $type, &$data, $options = array())
 {
     // The fact that we come in here means there are some thing changed
     $isCopy = isset($options['copy']) && $options['copy'];
     if (!$isCopy && isset($data->deleted)) {
         $deleted = $data->deleted;
         foreach ($deleted as $deletedtype => $deletedids) {
             if (!empty($deletedids)) {
                 $name = $deletedtype == 'pages' ? 'fieldstep' : 'field';
                 foreach ($deletedids as $deletedid) {
                     $table = FD::table($name);
                     $state = $table->load($deletedid);
                     if ($state) {
                         $table->delete();
                     }
                 }
             }
         }
     }
     $sequence = 1;
     foreach ($data->data as $step) {
         $stepTable = FD::table('fieldstep');
         $state = false;
         if (!$step->newpage) {
             $state = $stepTable->load($step->id);
         }
         if ($isCopy) {
             $stepTable->_isCopy = true;
             $stepTable->id = null;
             $state = false;
         }
         // If there's a problem retrieving this step, this is probably a new step.
         if (!$state) {
             $stepTable->uid = $uid;
             $stepTable->type = $type;
             $stepTable->state = SOCIAL_STATE_PUBLISHED;
             $stepTable->created = FD::date()->toMySQL();
         }
         $stepTable->sequence = $sequence;
         // Set the step values
         $stepTable->processParams($step);
         // Try to store the step.
         $state = $stepTable->store();
         // If there's a problem storing the state, we should log errors here.
         if (!$state) {
             FD::logError(__FILE__, __LINE__, 'FIELDS: Unable to store step for id ' . $uid . ' with the sequence of ' . $sequence);
             return false;
         }
         // Assign back the id to pass back to client
         $step->id = $stepTable->id;
         $sequence++;
         // When there's no fields for this step, just skip the rest of processing.
         if (!isset($step->fields)) {
             continue;
         }
         // Reset the ordering for the fields.
         $ordering = 0;
         // Now let's go through the list of fields for this step.
         foreach ($step->fields as $field) {
             $appTable = FD::table('App');
             $fieldTable = FD::table('Field');
             $appTable->load($field->appid);
             if (!empty($field->fieldid)) {
                 $fieldTable->load($field->fieldid);
             }
             if ($isCopy) {
                 // Before we set the id to null, get the choices first
                 $checkChoices = (array) $field->choices;
                 if (empty($checkChoices)) {
                     $field->choices = $fieldTable->getOptions();
                 }
                 $fieldTable->_isCopy = true;
                 $fieldTable->id = null;
             }
             // Set the application id.
             $fieldTable->app_id = $field->appid;
             // Set the step id since we now know the step id.
             $fieldTable->step_id = $stepTable->id;
             // Let's process the params
             if (isset($field->params)) {
                 $fieldTable->processParams($field->params);
             }
             // Set the ordering now.
             $fieldTable->ordering = $ordering;
             // The core state would be dependent on the app's settings.
             $fieldTable->core = $appTable->core;
             // Let's try to store the field now.
             $state = $fieldTable->store();
             // If there's any problems storing the state, we should log errors and not proceed.
             if (!$state) {
                 FD::logError(__FILE__, __LINE__, 'FIELDS: Unable to store the field for the step id ' . $stepTable->id);
                 return false;
             }
             // Carry out actions that can only be done after the initial store to generate field id here
             // Assign back the field id to pass back to client
             $field->fieldid = $fieldTable->id;
             // Check if unique key for this field is valid and assign it back for the client
             $field->unique_key = $fieldTable->checkUniqueKey();
             // Save any post actions
             $fieldTable->store();
             // Check for choices here
             if (isset($field->choices)) {
                 foreach ($field->choices as $name => $choices) {
                     $origChoices = $fieldTable->getOptions($name);
                     $currentChoices = array();
                     $choiceOrdering = 1;
                     foreach ($choices as $choice) {
                         $fieldoptionsTable = FD::table('FieldOptions');
                         if (!empty($choice->id)) {
                             $fieldoptionsTable->load($choice->id);
                         }
                         if ($isCopy) {
                             $fieldoptionsTable->id = null;
                         }
                         $fieldoptionsTable->parent_id = $fieldTable->id;
                         $fieldoptionsTable->key = $name;
                         $fieldoptionsTable->title = $choice->title;
                         $fieldoptionsTable->value = $choice->value;
                         $fieldoptionsTable->ordering = $choiceOrdering;
                         if (isset($choice->default)) {
                             $fieldoptionsTable->default = $choice->default;
                         }
                         if (!$fieldoptionsTable->store()) {
                             FD::logError(__FILE__, __LINE__, 'FIELDS: Unable to store the choices for the field id ' . $fieldTable->id);
                             return false;
                         }
                         // Assign back the options id to pass back to client
                         $choice->id = $fieldoptionsTable->id;
                         $currentChoices[] = $choice->id;
                         $choiceOrdering++;
                     }
                     if (!$isCopy) {
                         foreach ($origChoices as $origId => $origChoices) {
                             if (!in_array($origId, $currentChoices)) {
                                 $origChoices->delete();
                             }
                         }
                     }
                 }
             }
             $ordering++;
         }
     }
     return true;
 }
Example #30
0
 /**
  * Installs a single custom field
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function installField($path)
 {
     // Include core library
     require_once JPATH_ROOT . '/administrator/components/com_easysocial/includes/foundry.php';
     // Retrieve the installer library.
     $installer = FD::get('Installer');
     // Get the element
     $element = basename($path);
     // Try to load the installation from path.
     $state = $installer->load($path);
     // If there's an error, we need to log it down.
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'APPS: Unable to install apps from directory ' . $path . ' because of the error ' . $installer->getError());
         $result = $this->getResultObj(JText::sprintf('COM_EASYSOCIAL_INSTALLATION_FIELD_ERROR_LOADING_FIELD', ucfirst($element)), false);
         return $result;
     }
     // Let's try to install it now.
     $app = $installer->install();
     // If there's an error installing, log this down.
     if ($app === false) {
         $result = $this->getResultObj(JText::sprintf('COM_EASYSOCIAL_INSTALLATION_FIELD_ERROR_INSTALLING_FIELD', ucfirst($element)), false);
         return $result;
     }
     // Ensure that the app is published
     $app->state = SOCIAL_STATE_PUBLISHED;
     $app->store();
     $result = $this->getResultObj(JText::sprintf('COM_EASYSOCIAL_INSTALLATION_FIELD_SUCCESS_INSTALLING_FIELD', ucfirst($element)), true);
     return $result;
 }