Example #1
0
 /**
  * Processes .view and .language from the javascript calls.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function getResource()
 {
     $resources = JRequest::getVar('resource');
     if ($resources) {
         // Load language support for front end and back end.
         $lang = FD::language();
         $lang->loadSite();
         $lang->loadAdmin();
         foreach ($resources as &$resource) {
             $resource = (object) $resource;
             // Get the current method.
             $method = 'get' . ucfirst($resource->type);
             if (!method_exists($this, $method)) {
                 continue;
             }
             // Pass the resource over.
             $result = self::$method($resource->name);
             if ($result !== false) {
                 $resource->content = $result;
             }
         }
     }
     header('Content-type: text/x-json; UTF-8');
     echo FD::json()->encode($resources);
     exit;
 }
Example #2
0
 /**
  * Renders the user group tree listing.
  *
  * @since	1.0
  * @access	public
  * @param	object	The object to check against.
  * @param	string	The controller to be called.
  * @param	string	The key for the object.
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public static function groups($name = 'gid', $selected = '', $exclude = array(), $checkSuperAdmin = false)
 {
     static $count;
     $count++;
     // If selected value is a string, we assume that it's a json object.
     if (is_string($selected)) {
         $json = FD::json();
         $selected = $json->decode($selected);
     }
     $version = FD::getInstance('Version')->getVersion();
     if ($version >= '1.6') {
         $groups = self::getGroups();
         $theme = FD::themes();
         $selected = FD::makeArray($selected);
         $isSuperAdmin = JFactory::getUser()->authorise('core.admin');
         $theme->set('name', $name);
         $theme->set('checkSuperAdmin', $checkSuperAdmin);
         $theme->set('isSuperAdmin', $isSuperAdmin);
         $theme->set('selected', $selected);
         $theme->set('count', $count);
         $theme->set('groups', $groups);
         return $theme->output('admin/html/tree.groups');
     }
     return JHTML::_('select.genericlist', JFactory::getAcl()->get_group_children_tree(null, 'USERS', false), 'gid', 'size="10"', 'value', 'text', $selected);
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     $sql->select('#__social_fields_data', 'a')->column('a.*')->leftjoin('#__social_fields', 'b')->on('b.id', 'a.field_id')->leftjoin('#__social_apps', 'c')->on('c.id', 'b.app_id')->where('a.datakey', '')->where('c.type', 'fields')->where('c.element', 'joomla_fullname');
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     foreach ($result as $row) {
         if ($json->isJsonString($row->data)) {
             $data = $json->decode($row->data);
             // Split json object into each individual row
             foreach ($data as $k => $v) {
                 if (!empty($v)) {
                     $table = $this->getTable($row->field_id, $row->uid, $row->type, $k);
                     $table->data = $v;
                     $table->raw = $v;
                     $table->store();
                 }
             }
         }
         // Remove the row with empty key
         $sql->clear();
         $sql->delete('#__social_fields_data')->where('id', $row->id);
         $db->setQuery($sql);
         $db->query();
     }
     return true;
 }
Example #4
0
 /**
  * Retrieves a list of countries from the manifest file.
  *
  * @since   1.0
  * @access  public
  * @return  Array    An array of countries.
  *
  * @author  Jason Rey <*****@*****.**>
  */
 public static function getCountries($source = 'regions')
 {
     static $countries = array();
     if (!isset($countries[$source])) {
         $data = new stdClass();
         if ($source === 'file') {
             $file = JPATH_ADMINISTRATOR . '/components/com_easysocial/defaults/countries.json';
             $contents = JFile::read($file);
             $json = FD::json();
             $data = $json->decode($contents);
             $data = (array) $data;
             // Sort by alphabet
             asort($data);
             $data = (object) $data;
         }
         if ($source === 'regions') {
             $countries = FD::model('Regions')->getRegions(array('type' => SOCIAL_REGION_TYPE_COUNTRY, 'state' => SOCIAL_STATE_PUBLISHED, 'ordering' => 'ordering'));
             foreach ($countries as $country) {
                 $data->{$country->code} = $country->name;
             }
         }
         $countries[$source] = $data;
     }
     return $countries[$source];
 }
Example #5
0
 public function getAjaxTemplate()
 {
     $templateFiles = JRequest::getVar('names');
     // Ensure the integrity of each items submitted to be an array.
     if (!is_array($templateFiles)) {
         $templateFiles = array($templateFiles);
     }
     $result = array();
     $theme = FD::get('Themes');
     foreach ($templateFiles as $file) {
         // Remove any trailing .ejs in file name if exist.
         $file = str_replace('.ejs', '', $file);
         $template = $theme->getTemplate($file);
         ob_start();
         include $template->ejs;
         $output = ob_get_contents();
         ob_end_clean();
         $obj = new stdClass();
         $obj->name = $file;
         $obj->content = $output;
         $result[] = $obj;
     }
     if (!$result) {
         header('HTTP/1.1 404 Not Found');
         exit;
     }
     header('Content-type: text/x-json; UTF-8');
     $json = FD::json();
     echo $json->encode($result);
     exit;
 }
Example #6
0
 /**
  * Loads a set of configuration given the type.
  *
  * @since	1.0
  * @access	public
  * @param	string		The unique type of configuration.
  * @return
  */
 public function load($key)
 {
     // Specifically if the key is 'joomla' , we only want to use JConfig.
     if ($key == 'joomla') {
         $codeName = FD::getInstance('Version')->getCodeName();
         $helper = dirname(__FILE__) . '/helpers/' . $codeName . '.php';
         require_once $helper;
         $className = 'SocialConfig' . $codeName;
         $config = new $className();
     } else {
         // Object construct happens here
         $default = SOCIAL_ADMIN . '/defaults/' . $key . '.json';
         $defaultData = '';
         // Read the default data.
         $defaultData = JFile::read($default);
         $json = FD::json();
         // Load a new copy of Registry
         $config = FD::registry($defaultData);
         if (!defined('SOCIAL_COMPONENT_CLI')) {
             // @task: Now we need to get the user defined configuration that is stored in the database.
             $model = FD::model('Config');
             $storedConfig = $model->getConfig($key);
             // Get stored config
             if ($storedConfig) {
                 $storedConfig = FD::registry($storedConfig->value);
                 // Merge configurations
                 $config->mergeObjects($storedConfig->getRegistry());
             }
         }
     }
     $this->configs[$key] = $config;
 }
Example #7
0
 public function showProfile($view, &$params)
 {
     $userid = $view->profile->userid;
     $user = FD::user($userid);
     $gender = $user->getFieldData('GENDER');
     if (!empty($gender)) {
         $view->profile->gender = $gender;
     }
     $data = $user->getFieldData('BIRTHDAY');
     $json = FD::json();
     $birthday = null;
     // Legacy
     if (isset($data['date']) && $json->isJsonString($data['date']) && !$birthday) {
         $birthday = $this->getLegacyDate($data['date']);
     }
     // Legacy
     if ($json->isJsonString($data) && !$birthday) {
         $birthday = $this->getLegacyDate($data);
     }
     // New format
     if (isset($data['date']) && !$birthday) {
         $birthday = FD::date($data['date']);
     }
     if (!is_null($birthday)) {
         $view->profile->birthdate = $birthday->format('Y-m-d');
     }
 }
Example #8
0
 /**
  * Does a remote call to the server to fetch contents of a given url.
  *
  * @since	1.0
  * @access	public
  */
 public function fetch()
 {
     // Check for request forgeries!
     $urls = JRequest::getVar('urls');
     // Ensure that the urls are in an array
     FD::makeArray($urls);
     // Get the current view.
     $view = $this->getCurrentView();
     // Result placeholder
     $result = array();
     if (!$urls || empty($urls)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CRAWLER_INVALID_URL_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     $crawler = FD::get('Crawler');
     foreach ($urls as $url) {
         $hash = md5($url);
         $link = FD::table('Link');
         $exists = $link->load(array('hash' => $hash));
         // If it doesn't exist, store it.
         if (!$exists) {
             $crawler->crawl($url);
             $data = $crawler->getData();
             $link->hash = $hash;
             $link->data = FD::json()->encode($data);
             // Store the new link
             $link->store();
         }
         $result[$url] = FD::json()->decode($link->data);
     }
     return $view->call(__FUNCTION__, $result);
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     $sql->select('#__social_fields_data', 'a');
     $sql->column('a.*');
     $sql->leftjoin('#__social_fields', 'b');
     $sql->on('a.field_id', 'b.id');
     $sql->leftjoin('#__social_apps', 'c');
     $sql->on('b.app_id', 'c.id');
     $sql->where('c.type', 'fields');
     $sql->where('c.element', array('birthday', 'datetime'), 'IN');
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     foreach ($result as $row) {
         $table = FD::table('fielddata');
         $table->bind($row);
         if ($json->isJsonString($table->data)) {
             $table->datakey = 'date';
             $table->store();
         }
     }
     return true;
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     // For country field
     $sql->select('#__social_fields_data', 'a')->column('a.*')->leftjoin('#__social_fields', 'b')->on('b.id', 'a.field_id')->leftjoin('#__social_apps', 'c')->on('c.id', 'b.app_id')->where('a.datakey', '')->where('c.type', 'fields')->where('c.element', 'country');
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     // Load up the list of countries
     $file = SOCIAL_ADMIN_DEFAULTS . '/countries.json';
     $list = FD::makeObject($file);
     foreach ($result as $row) {
         if ($json->isJsonString($row->data)) {
             $data = $json->decode($row->data);
             // Split json object into each individual row
             foreach ($data as $k => $v) {
                 if (!empty($v)) {
                     $table = $this->getTable($row->field_id, $row->uid, $row->type, $k);
                     $country = $list->{$v};
                     $table->data = $country;
                     $table->raw = $country;
                     $table->store();
                 }
             }
         }
         // Remove the row with empty key
         $sql->clear();
         $sql->delete('#__social_fields_data')->where('id', $row->id);
         $db->setQuery($sql);
         $db->query();
     }
     return true;
 }
Example #11
0
 /**
  * This is the center of the brain to process all views.
  *
  * @since	1.0
  * @access	public
  * @param	array
  */
 public function display($cacheable = false, $urlparams = false)
 {
     $document = JFactory::getDocument();
     $type = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     // Set the layout
     $viewLayout = JRequest::getCmd('layout', 'default');
     $view = $this->getView($viewName, $type, '');
     $view->setLayout($viewLayout);
     if ($type == 'ajax') {
         if (!method_exists($view, $viewLayout)) {
             $view->display();
         } else {
             $json = FD::json();
             $params = $json->decode(JRequest::getVar('params'));
             call_user_func_array(array($view, $viewLayout), $params);
         }
     } else {
         if ($viewLayout != 'default') {
             if (!method_exists($view, $viewLayout)) {
                 $view->display();
             } else {
                 call_user_func_array(array($view, $viewLayout), array());
             }
         } else {
             $view->display();
         }
     }
 }
Example #12
0
 /**
  * Allows caller to update a stream
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function update()
 {
     // Check for request forgeries
     FD::checkToken();
     // Check for valid users
     FD::requireLogin();
     // Get the current view
     $view = $this->getCurrentView();
     // Get the stream id
     $id = JRequest::getInt('id');
     $stream = FD::table('Stream');
     $stream->load($id);
     // Check for valid stream id's.
     if (!$id || !$stream->id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_STREAM_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // @TODO: Check for permissions
     $my = FD::user();
     if ($stream->cluster_id) {
         $group = FD::group($stream->cluster_id);
         if (!$my->isSiteAdmin() && $stream->actor_id != $my->id && !$group->isAdmin()) {
             $view->setMessage(JText::_('COM_EASYSOCIAL_STREAM_NO_PERMISSIONS_TO_EDIT'), SOCIAL_MSG_ERROR);
             return $view->call(__FUNCTION__);
         }
     } else {
         if (!$my->isSiteAdmin() && $stream->actor_id != $my->id) {
             $view->setMessage(JText::_('COM_EASYSOCIAL_STREAM_NO_PERMISSIONS_TO_EDIT'), SOCIAL_MSG_ERROR);
             return $view->call(__FUNCTION__);
         }
     }
     $content = JRequest::getVar('content', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $mentions = JRequest::getVar('mentions');
     // Format the json string to array
     if (!empty($mentions)) {
         foreach ($mentions as &$mention) {
             $mention = FD::json()->decode($mention);
         }
     }
     // Process the content
     $stream->content = $content;
     // Set the last edited date
     $stream->edited = FD::date()->toSql();
     // Get the stream model and remove mentions
     $model = FD::model('Stream');
     $model->removeMentions($stream->id);
     // Now we need to add new mentions
     if ($mentions) {
         $model->addMentions($stream->id, $mentions);
     }
     // Save the stream
     $stream->store();
     // Because we know that story posts only has 1 item, we may safely assume that the first index.
     $items = $stream->getItems();
     $item = $items[0];
     return $view->call(__FUNCTION__, $item);
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     $sql->select('#__social_fields_data', 'a');
     $sql->column('a.id');
     $sql->column('a.data');
     $sql->leftjoin('#__social_fields', 'b');
     $sql->on('a.field_id', 'b.id');
     $sql->leftjoin('#__social_apps', 'c');
     $sql->on('b.app_id', 'c.id');
     $sql->where('c.type', 'fields');
     $sql->where('c.element', 'address');
     $sql->where('a.datakey', '');
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     // Load up the list of countries
     $file = SOCIAL_ADMIN_DEFAULTS . '/countries.json';
     $list = FD::makeObject($file);
     foreach ($result as $row) {
         if (!$json->isJsonString($row->data)) {
             continue;
         }
         $data = $json->decode($row->data);
         if ($data->city) {
             $data->city = str_replace('`', '\'', $data->city);
         }
         if ($data->state) {
             $data->state = str_replace('`', '\'', $data->state);
         }
         if ($data->zip) {
             $data->zip = str_replace('`', '\'', $data->zip);
         }
         if (!empty($data->country) && strlen($data->country) === 2 && isset($list->{$data->country})) {
             $data->country = $list->{$data->country};
         }
         // Recreate the json string
         $string = $json->encode($data);
         // Recreate the raw data
         unset($data->latitude);
         unset($data->longitude);
         $raw = implode(array_values((array) $data), ' ');
         $raw = str_replace('`', '\'', $raw);
         $sql->clear();
         $sql->update('#__social_fields_data');
         $sql->set('data', $string);
         $sql->set('raw', $raw);
         $sql->where('id', $row->id);
         $db->setQuery($sql);
         $db->query();
     }
     return true;
 }
Example #14
0
 /**
  * Class constructor.
  *
  * @since	1.0
  * @access	public
  */
 public function __construct($params = array())
 {
     // Helper json library.
     $this->json = FD::json();
     // Field library
     $this->lib = FD::fields();
     // Field handlers
     $this->handler = $this->lib->getHandler();
     // Init params
     $this->init($params);
 }
Example #15
0
 /**
  * Responsible to output upload response.
  *
  * @since	1.0
  * @access	public
  */
 public function upload()
 {
     $json = FD::json();
     // If there was an error uploading,
     // return error message.
     if ($this->hasErrors()) {
         $json->send($this->getMessage());
     }
     // TODO: Huh is this used? This is an empty object.
     $response = new stdClass();
     $json->send($response);
 }
Example #16
0
 public function onEditValidate(&$post, &$user)
 {
     $value = isset($post[$this->inputName]) ? $post[$this->inputName] : '';
     $json = FD::json();
     $value = $json->isJsonString($value) ? $json->decode($value) : (object) array();
     $date = isset($value->date) ? $value->date : '';
     if (!$this->checkAge($date)) {
         return false;
     }
     $state = parent::onEditValidate($post, $user);
     return $state;
 }
Example #17
0
 public function onEditAfterSave(&$post, &$user)
 {
     $json = FD::json();
     $params = $json->decode($post[$this->inputName]);
     if (!isset($params->type)) {
         return false;
     }
     // We set it as array here to follow the standard of textboxlist passing in target as array even for single target
     if (!isset($params->target)) {
         $params->target = array(0);
     }
     $model = $this->model('relations');
     $relation = $model->getActorRelationship($user->id);
     // If no relationship data is found, then we init a new one
     if ($relation === false) {
         $relation = $this->table('relations');
     }
     $origType = $relation->type;
     $origTarget = $relation->getTargetUser()->id;
     $currentType = $params->type;
     // Do not use $relation->isConnect because the type might change
     $typeInfo = $relation->getType($currentType);
     $currentTarget = $typeInfo && $typeInfo->connect ? $params->target[0] : 0;
     // Only process if there is a change in type or target
     if ($origType !== $currentType || $origTarget !== $currentTarget) {
         // If original target is not empty, we need to find the target's relationship and change it to empty target since this person is no longer tied to that target
         if (!empty($origTarget)) {
             $targetRel = $model->getActorRelationship($origTarget, array('target' => $user->id));
             if ($targetRel) {
                 $targetRel->target = 0;
                 $targetRel->state = 1;
                 $targetRel->store();
             }
         }
         // If this relationship has an id, means it is from an existing record.
         // We need to delete and recreate it in order to have a new id.
         // When the target approves, the genereted stream needs to use the new id instead of the old id.
         if (!empty($relation->id)) {
             $relation->remove();
             $relation = $this->table('relations');
         }
         $relation->actor = $user->id;
         $relation->type = $currentType;
         $relation->target = $currentTarget;
         $state = $relation->request();
         if (!$state) {
             return false;
         }
     }
     return true;
 }
 public function main()
 {
     // Only birthday field and datetime field is affected
     $birthdayTable = FD::table('app');
     $birthdayTable->load(array('type' => SOCIAL_APPS_TYPE_FIELDS, 'group' => SOCIAL_FIELDS_GROUP_USER, 'element' => 'birthday'));
     $datetimeTable = FD::table('app');
     $datetimeTable->load(array('type' => SOCIAL_APPS_TYPE_FIELDS, 'group' => SOCIAL_FIELDS_GROUP_USER, 'element' => 'datetime'));
     // $appid = array($birthdayTable->id, $datetimeTable->id);
     $db = FD::db();
     $sql = $db->sql();
     // $sql->select('#__social_fields_data')
     // 	->where('field_id', $appid, 'in')
     // 	->where('data', '', '!=');
     $query = "select a.* from `#__social_fields_data` as a";
     $query .= "\tinner join `#__social_fields` as b on a.`field_id` = b.`id`";
     $query .= " where b.`app_id` IN ({$birthdayTable->id}, {$datetimeTable->id})";
     $query .= " and a.`data` != ''";
     // echo $query;exit;
     $sql->raw($query);
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     foreach ($result as $row) {
         if (empty($row->data)) {
             continue;
         }
         $table = FD::table('fielddata');
         $table->bind($row);
         if ($json->isJsonString($table->data)) {
             $val = $json->decode($table->data);
             if ($val->year && $val->month && $val->day) {
                 $dateVal = $val->year . '-' . $val->month . '-' . $val->day;
                 $table->raw = FD::date($val->year . '-' . $val->month . '-' . $val->day)->toSql();
             }
         } else {
             try {
                 $val = FD::date($table->data);
             } catch (Exception $e) {
                 $table->data = '';
                 $table->raw = '';
                 $table->store();
                 continue;
             }
             $table->data = $json->encode(array('year' => $val->toFormat('Y'), 'month' => $val->toFormat('n'), 'day' => $val->toFormat('j')));
             $table->raw = $val->toSql();
         }
         $table->store();
     }
     return true;
 }
Example #19
0
 public function getShareId()
 {
     $url = $this->getParamUrl();
     $params = FD::json()->encode($this->params);
     $table = FD::table('tmp');
     $table->type = 'sharing';
     $table->key = $url;
     $table->value = $params;
     $result = $table->store();
     if ($result === false) {
         return false;
     }
     return $table->id;
 }
 public function getTarget()
 {
     static $nodes = array();
     if (!isset($nodes[$this->target])) {
         // @rule: Allow multiple targets in a single action.
         $target = FD::json()->decode($this->target);
         $targets = array();
         foreach ($target as $targetId) {
             $targets[] = FD::get('People', $targetId, SOCIAL_PEOPLE_NODE_ID);
         }
         $nodes[$this->target] = $targets;
     }
     return $nodes[$this->target];
 }
Example #21
0
 public function store($updateNulls = false)
 {
     $now = FD::date();
     // Set created to now by default
     if (empty($this->created)) {
         $this->created = $now->toSql();
     }
     // Set expired to 1 day later by default
     if (empty($this->expired)) {
         $this->expired = FD::date($now->toUnix() + 24 * 60 * 60)->toSql();
     }
     if (is_array($this->value) || is_object($this->value)) {
         $this->value = FD::json()->encode($this->value);
     }
     return parent::store($updateNulls);
 }
Example #22
0
 public function confirmInviteGuests()
 {
     $theme = FD::themes();
     $guests = $this->input->get('guests');
     if (empty($guests)) {
         $contents = $theme->output('admin/events/dialog.inviteGuests.empty');
         return $this->ajax->resolve($contents);
     }
     $theme->set('guests', $guests);
     $userids = array();
     foreach ($guests as $id => $guest) {
         $userids[] = $id;
     }
     $theme->set('userids', FD::json()->encode($userids));
     $eventid = $this->input->getInt('eventid');
     $theme->set('eventid', $eventid);
     $contents = $theme->output('admin/events/dialog.inviteGuests.confirm');
     return $this->ajax->resolve($contents);
 }
 public function main()
 {
     $json = FD::json();
     $db = FD::db();
     $sql = $db->sql();
     // update [""] to empty string.
     $query = 'update `#__social_fields_data` set `raw` = \'\' where `raw` = ' . $db->Quote('[""]');
     $sql->raw($query);
     $db->setQuery($sql);
     $db->query();
     //now let retrieve data that the raw data is json string.
     $query = 'select id, raw from `#__social_fields_data`';
     $query .= ' where `raw` like ' . $db->Quote('["%');
     $sql->raw($query);
     $db->setQuery($sql);
     $results = $db->loadObjectList();
     if ($results) {
         foreach ($results as $row) {
             if ($json->isJsonString($row->raw)) {
                 $raw = $json->decode($row->raw);
                 if (is_array($raw)) {
                     $raw = implode(',', $raw);
                 }
                 if (!empty($raw)) {
                     //update the row.
                     $update = "update `#__social_fields_data` set raw = '{$raw}' where id = '{$row->id}'";
                     $sql->clear();
                     $sql->raw($update);
                     $db->setQuery($sql);
                     $db->query();
                 }
             }
             //if
         }
         //foreach
     }
     //if
     return true;
 }
Example #24
0
 public function process(&$obj, $item, $currentUserId)
 {
     // Check for the content
     $content = isset($item['message']) ? $item['message'] : '';
     $picture = isset($item['picture']) ? $item['picture'] : '';
     $title = isset($item['name']) ? $item['name'] : '';
     $place = isset($item['place']) ? $item['place'] : '';
     if (!$content) {
         $content = isset($item['story']) ? $item['story'] : '';
     }
     if ($place) {
         $place = FD::json()->encode($place);
     }
     // if( $item[ 'from' ][ 'id' ] != $currentUserId )
     // {
     // 	$content 	= JText::_( 'was tagged at ' . $title );
     // }exit;
     $obj->set('place', $place);
     $obj->set('picture', $picture);
     $obj->set('title', $title);
     $obj->set('content', $content);
 }
Example #25
0
 /**
  * Allows a javascript caller to load a language string via javascript.
  *
  * @since 	1.0
  * @access	public
  * @param	null
  * @return	JSON
  */
 public function getLanguage()
 {
     $languages = JRequest::getVar('languages');
     $result = array();
     // If this is not an array, make it as an array.
     if (!is_array($languages)) {
         $languages = array($languages);
     }
     // Load language support for front end and back end.
     JFactory::getLanguage()->load(JPATH_ROOT . DS . 'administrator');
     JFactory::getLanguage()->load(JPATH_ROOT);
     foreach ($languages as $key) {
         $result[$key] = JText::_(strtoupper($key));
     }
     if (!$result) {
         header('HTTP/1.1 404 Not Found');
         exit;
     }
     header('Content-type: text/x-json; UTF-8');
     $json = FD::json();
     echo $json->encode($result);
     exit;
 }
Example #26
0
 /**
  * Handle the output after a reply is posted.
  */
 public function reply($data)
 {
     echo FD::json()->encode($data);
     parent::display();
 }
Example #27
0
 /**
  * Given a path to the file, install the privacy rules.
  *
  * @since	1.0
  * @access	public
  * @param	string		The path to the privacy .json 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)) {
         $this->setError(JText::_('COM_EASYSOCIAL_PRIVACY_UNABLE_TO_READ_PRIVACY_RULE_FILE'));
         return false;
     }
     $json = FD::json();
     $data = $json->decode($contents);
     if (!is_array($data)) {
         $data = array($data);
     }
     // Let's test if there's data.
     if (empty($data)) {
         $this->setError(JText::_('COM_EASYSOCIAL_PRIVACY_UNABLE_TO_READ_PRIVACY_RULE_FILE'));
         return false;
     }
     $privLib = FD::privacy();
     $result = array();
     foreach ($data as $row) {
         $type = $row->type;
         $rules = $row->rules;
         if (count($rules) > 0) {
             foreach ($rules as $rule) {
                 $command = $rule->command;
                 $description = $rule->description;
                 $default = $rule->default;
                 $options = $rule->options;
                 $optionsArr = array();
                 foreach ($options as $option) {
                     $optionsArr[] = $option->name;
                 }
                 $ruleOptions = array('options' => $optionsArr);
                 $optionString = $json->encode($ruleOptions);
                 // Load the tables
                 $privacy = FD::table('Privacy');
                 // If this already exists, we need to skip this.
                 $state = $privacy->load(array('type' => $type, 'rule' => $command));
                 if ($state) {
                     continue;
                 }
                 $privacy->core = isset($rule->core) && $rule->core ? true : false;
                 $privacy->state = SOCIAL_STATE_PUBLISHED;
                 $privacy->type = $type;
                 $privacy->rule = $command;
                 $privacy->description = $description;
                 $privacy->value = $privLib->toValue($default);
                 $privacy->options = $optionString;
                 $addState = $privacy->store();
                 if ($addState) {
                     // now we need to add this new privacy rule into all the profile types.
                     $this->addRuleProfileTypes($privacy->id, $privacy->value);
                 }
                 $result[] = $type . '.' . $command;
             }
         }
     }
     return $result;
 }
Example #28
0
 /**
  * Generates the stream title of event.
  *
  * @since    1.0
  * @access    public
  * @param    object    $params        A standard object with key / value binding.
  *
  * @return    none
  */
 public function onPrepareStream(SocialStreamItem &$stream, $includePrivacy = true)
 {
     if ($stream->context != 'links') {
         return;
     }
     // event access checking
     $event = FD::event($stream->cluster_id);
     if (!$event || !$event->canViewItem()) {
         return;
     }
     //get links object, in this case, is the stream_item
     $uid = $stream->uid;
     $stream->color = '#5580BE';
     $stream->fonticon = 'ies-link';
     $stream->label = FD::_('APP_EVENT_LINKS_STREAM_TOOLTIP', true);
     // Apply likes on the stream
     $likes = FD::likes();
     $likes->get($stream->uid, $stream->context, $stream->verb, SOCIAL_APPS_GROUP_EVENT, $stream->uid);
     $stream->likes = $likes;
     // Apply comments on the stream
     $comments = FD::comments($stream->uid, $stream->context, $stream->verb, SOCIAL_APPS_GROUP_EVENT, array('url' => FRoute::stream(array('layout' => 'item', 'id' => $stream->uid))), $stream->uid);
     $stream->comments = $comments;
     // Apply repost on the stream
     $stream->repost = FD::get('Repost', $stream->uid, SOCIAL_TYPE_STREAM, SOCIAL_APPS_GROUP_EVENT);
     $my = FD::user();
     $privacy = FD::privacy($my->id);
     if ($includePrivacy && !$privacy->validate('story.view', $uid, SOCIAL_TYPE_LINKS, $stream->actor->id)) {
         return;
     }
     $actor = $stream->actor;
     $target = count($stream->targets) > 0 ? $stream->targets[0] : '';
     $stream->display = SOCIAL_STREAM_DISPLAY_FULL;
     $assets = $stream->getAssets();
     if (empty($assets)) {
         return;
     }
     $assets = $assets[0];
     $videoHtml = '';
     // Retrieve the link that is stored.
     $hash = md5($assets->get('link'));
     $link = FD::table('Link');
     $link->load(array('hash' => $hash));
     $linkObj = FD::json()->decode($link->data);
     // Determine if there's any embedded object
     $oembed = isset($linkObj->oembed) ? $linkObj->oembed : '';
     // Get app params
     $params = $this->getParams();
     $this->set('event', $event);
     $this->set('params', $params);
     $this->set('oembed', $oembed);
     $this->set('assets', $assets);
     $this->set('actor', $actor);
     $this->set('target', $target);
     $this->set('stream', $stream);
     $stream->title = parent::display('streams/title.' . $stream->verb);
     $stream->preview = parent::display('streams/preview.' . $stream->verb);
     return true;
 }
Example #29
0
 /**
  * Retrieves a field configuration.
  *
  * @since	1.0
  * @access	public
  * @param	int		The key to #__social_apps
  * @param	int		Optional field id. If there's no field id, we assume that it's a new field being added to the form.
  * @param	bool	If true, method will return a json string instead of an object.
  *
  * @return	object	The field configuration
  */
 public function getFieldConfigParameters($appId, $groupTabs = false, $jsonString = false)
 {
     // Note: We put this function here instead of field table because sometimes a field might not have a field id to load the parameters
     static $configParams = array();
     if (empty($configParams[$appId])) {
         // Load json library
         $json = FD::json();
         $app = $this->loadAppData($appId);
         $config = $app->getManifest();
         if (empty($config)) {
             $config = new stdClass();
         }
         // Get the default core parameters
         $defaults = $this->getDefaultManifest($app->group);
         // Manually perform a deep array merge to carry the defaults over to the config object
         foreach ($defaults as $name => $params) {
             if (property_exists($config, $name)) {
                 if (is_bool($config->{$name})) {
                     $params = $config->{$name};
                 } else {
                     $params = (object) array_merge((array) $params, (array) $config->{$name});
                 }
             }
             $config->{$name} = $params;
         }
         foreach ($config as $name => &$field) {
             $this->translateConfigParams($field);
             if (isset($field->subfield)) {
                 foreach ($field->subfields as $subname => &$subfield) {
                     $this->translateConfigParams($subfield);
                 }
             }
         }
         $configParams[$appId] = $config;
     }
     // Make a clone to prevent pass by reference
     $data = clone $configParams[$appId];
     if ($groupTabs) {
         $groupedConfig = new stdClass();
         foreach ($data as $key => $value) {
             if (!is_bool($value)) {
                 // This will enforce group to be either basic or advance
                 // $type = property_exists( $value, 'group' ) && $value->group == 'advance' ? 'advance' : 'basic';
                 // This will allow any group
                 $type = property_exists($value, 'group') ? $value->group : 'basic';
                 if (!property_exists($groupedConfig, $type)) {
                     $groupedConfig->{$type} = new stdClass();
                 }
                 $groupedConfig->{$type}->title = JText::_('COM_EASYSOCIAL_PROFILES_FORM_FIELDS_TAB_' . strtoupper($type));
                 if (!property_exists($groupedConfig->{$type}, 'fields')) {
                     $groupedConfig->{$type}->fields = new stdClass();
                 }
                 $groupedConfig->{$type}->fields->{$key} = $value;
             }
         }
         $data = $groupedConfig;
     }
     if ($jsonString) {
         return $json->encode($data);
     }
     return $data;
 }
Example #30
0
 /**
  * Retrieves a list of users by sitewide search filter
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public function getUsersByProfileFilter()
 {
     // Check for request forgeries
     FD::checkToken();
     $config = FD::config();
     $view = $this->getCurrentView();
     // Get the profile id
     $id = $this->input->get('id', 0, 'int');
     // fields filtering data
     $data = $this->input->getVar('data', null);
     $values = array();
     if (!is_null($data) && $data) {
         // data saved as json format. so we need to decode it.
         $dataFilter = FD::json()->decode($data);
         $values['criterias'] = $dataFilter->{'criterias[]'};
         $values['datakeys'] = $dataFilter->{'datakeys[]'};
         $values['operators'] = $dataFilter->{'operators[]'};
         $values['conditions'] = $dataFilter->{'conditions[]'};
     } else {
         $values['criterias'] = $this->input->getVar('criterias');
         $values['datakeys'] = $this->input->getVar('datakeys');
         $values['operators'] = $this->input->getVar('operators');
         $values['conditions'] = $this->input->getVar('conditions');
     }
     $profile = FD::table('Profile');
     $profile->load($id);
     $options = array();
     $admin = $config->get('users.listings.admin') ? true : false;
     $options = array('includeAdmin' => $admin);
     // setup the limit
     $limit = FD::themes()->getConfig()->get('userslimit');
     $options['limit'] = $limit;
     $searchOptions = array();
     // lets do some clean up here.
     for ($i = 0; $i < count($values['criterias']); $i++) {
         $criteria = $values['criterias'][$i];
         $condition = $values['conditions'][$i];
         $datakey = $values['datakeys'][$i];
         $operator = $values['operators'][$i];
         if (trim($condition)) {
             $searchOptions['criterias'][] = $criteria;
             $searchOptions['datakeys'][] = $datakey;
             $searchOptions['operators'][] = $operator;
             $field = explode('|', $criteria);
             $fieldCode = $field[0];
             $fieldType = $field[1];
             if ($fieldType == 'birthday') {
                 // currently the value from form is in age format. we need to convert it into date time.
                 $ages = explode('|', $condition);
                 if (!isset($ages[1])) {
                     // this happen when start has value and end has no value
                     $ages[1] = $ages[0];
                 }
                 if ($ages[1] && !$ages[0]) {
                     //this happen when start is empty and end has value
                     $ages[0] = $ages[1];
                 }
                 $startdate = '';
                 $enddate = '';
                 $currentTimeStamp = FD::date()->toUnix();
                 if ($ages[0] == $ages[1]) {
                     $start = strtotime('-' . $ages[0] . ' years', $currentTimeStamp);
                     $year = FD::date($start)->toFormat('Y');
                     $startdate = $year . '-01-01 00:00:01';
                     $enddate = FD::date($start)->toFormat('Y-m-d') . ' 23:59:59';
                 } else {
                     if ($ages[0]) {
                         $start = strtotime('-' . $ages[0] . ' years', $currentTimeStamp);
                         $year = FD::date($start)->toFormat('Y');
                         $enddate = $year . '-12-31 23:59:59';
                     }
                     if ($ages[1]) {
                         $end = strtotime('-' . $ages[1] . ' years', $currentTimeStamp);
                         $year = FD::date($end)->toFormat('Y');
                         $startdate = $year . '-01-01 00:00:01';
                     }
                 }
                 $condition = $startdate . '|' . $enddate;
             }
             $searchOptions['conditions'][] = $condition;
         }
     }
     $searchOptions['match'] = 'and';
     $searchOptions['avatarOnly'] = false;
     if ($id) {
         $searchOptions['profile'] = $id;
     }
     // Retrieve the users
     $model = FD::model('Users');
     $pagination = null;
     $result = $model->getUsersByFilter('0', $options, $searchOptions);
     $pagination = $model->getPagination();
     // Define those query strings here
     $pagination->setVar('Itemid', FRoute::getItemId('users'));
     $pagination->setVar('view', 'users');
     $pagination->setVar('filter', 'profiletype');
     $pagination->setVar('id', $profile->id);
     for ($i = 0; $i < count($values['criterias']); $i++) {
         $criteria = $values['criterias'][$i];
         $condition = $values['conditions'][$i];
         $datakey = $values['datakeys'][$i];
         $operator = $values['operators'][$i];
         $pagination->setVar('criterias[' . $i . ']', $criteria);
         $pagination->setVar('datakeys[' . $i . ']', $datakey);
         $pagination->setVar('operators[' . $i . ']', $operator);
         $pagination->setVar('conditions[' . $i . ']', $condition);
     }
     $users = array();
     // preload users.
     $arrIds = array();
     foreach ($result as $obj) {
         $arrIds[] = FD::user($obj->id);
     }
     if ($arrIds) {
         FD::user($arrIds);
     }
     foreach ($result as $obj) {
         $users[] = FD::user($obj->id);
     }
     return $view->call(__FUNCTION__, $users, $profile, $data, $pagination);
 }