Пример #1
0
 /**
  * Assign a stream to be associated with category
  * @default is 'Uncategorized';
  * @param mixed category is the identifier of the category
  * @param int $stream_id is the id of the stream to be assigned to
  */
 public function assign($category, $stream_id)
 {
     $table = $this->load(array('category' => $category));
     $this->id = $table->id;
     $this->stream_id = JXUtility::csvInsert($table->stream_id, $stream_id);
     return $this->store();
 }
Пример #2
0
 public function display($cachable = false, $urlparams = false)
 {
     // Only admin can use this function to invite guests
     $jxConfig = new JXConfig();
     $mainframe = JFactory::getApplication();
     $my = JXFactory::getUser();
     $email = JRequest::getVar('email', '');
     $token = JRequest::getString('token', '');
     $code = JRequest::getString('code', '');
     $userInviteTable = JTable::getInstance('usersInvite', 'AccountTable');
     $userInviteTable->load(array('invite_email' => $email, 'status' => AccountTableUsersInvite::PENDING, 'token' => $token));
     if ($userInviteTable->id) {
         if ($_POST) {
             $name = JRequest::getVar('name', '');
             $username = JRequest::getVar('username', '');
             $password1 = JRequest::getString('password', '');
             $password2 = JRequest::getString('confirm_password', '');
             $data = array('name' => $name, 'username' => $username, 'password' => $password1, 'conf_pass' => $password2, 'email' => $email, 'group_limited' => $userInviteTable->group_limited);
             $model = RegisterFactory::getModel('registration');
             if ($userid = $model->registerUser($data)) {
                 $userInviteTable->status = AccountTableUsersInvite::REGISTERED;
                 $userInviteTable->store();
                 // If user is invited to a certain group only, add the user into the group
                 if ($userInviteTable->group_limited) {
                     // Include tables
                     JTable::addIncludePath(JPATH_ROOT . DS . 'components' . DS . 'com_stream' . DS . 'tables');
                     $groups = explode(',', $userInviteTable->group_limited);
                     $user = JXFactory::getUser($userid);
                     foreach ($groups as $group_id) {
                         $group = $group = JTable::getInstance('Group', 'StreamTable');
                         $group->load($group_id);
                         // If you join, you'd also follow it
                         $group->members = JXUtility::csvInsert($group->members, $user->id);
                         $group->followers = JXUtility::csvInsert($group->followers, $user->id);
                         $group->store();
                         // Store user cache
                         $groupList = $user->getParam('groups_member');
                         $groupList = JXUtility::csvInsert($groupList, $group->id);
                         $user->setParam('groups_member', $groupList);
                         $user->save();
                     }
                 }
                 $mainframe->redirect(JURI::base(), JText::_('COM_REGISTER_MSG_REGISTRATION_SUCCESSFUL'));
             } else {
                 $mainframe->enqueueMessage($model->getError(), 'error');
             }
         }
         parent::display();
     } else {
         $mainframe->redirect(JURI::base(), JText::_('COM_REGISTER_ERRMSG_NO_VALID_INVITATION'), 'error');
     }
 }
Пример #3
0
 public function getTrending($group = null)
 {
     $db = JFactory::getDbo();
     $my = JXFactory::getUser();
     $groupModel = StreamFactory::getModel('groups');
     $now = new JXDate();
     $nowDate = $now->format('Y-m-d');
     // Get the week's top trending tags
     //$where  = 'WHERE YEARWEEK(' . $db->nameQuote('occurrence_date') . ') = YEARWEEK(' . $db->Quote($nowDate) . ')' . ' '
     // Get the trending tags for the past n weeks
     $where = 'WHERE ' . $db->nameQuote('occurrence_date') . ' BETWEEN DATE_SUB(' . $db->Quote($nowDate) . ', INTERVAL 2 WEEK) AND ' . $db->Quote($nowDate) . ' ' . ' AND ' . $db->nameQuote('frequency') . ' > 0' . ' ';
     // Filter tags in group
     if (!is_null($group)) {
         $where .= 'AND ' . $db->nameQuote('group_id') . ' = ' . $db->Quote($group->id) . ' ';
     } else {
         // Get the groups joined (including private ones)
         $groupIJoinCsv = $my->getParam('groups_member', '-1');
         // Get the other public groups
         $otherGroups = $groupModel->getGroups(array('!id' => $groupIJoinCsv, 'access' => 0), 100);
         $otherGroupsCsv = '0';
         if (count($otherGroups)) {
             foreach ($otherGroups as $group) {
                 $otherGroupsCsv = JXUtility::csvInsert($otherGroupsCsv, $group->id);
             }
         } else {
             $otherGroupsCsv = '-1';
         }
         $myGroupsCsv = JXUtility::csvMerge($otherGroupsCsv, $groupIJoinCsv);
         $where .= 'AND ' . $db->nameQuote('group_id') . ' IN (' . $myGroupsCsv . ')' . ' ';
     }
     // Build the query
     $query = 'SELECT * FROM ' . $db->nameQuote('#__stream_tags_trend') . ' ' . $where . 'GROUP BY ' . $db->nameQuote('tag') . ' ' . 'ORDER BY ' . $db->nameQuote('frequency') . ' DESC, ' . $db->nameQuote('tag') . ' ASC' . ' ' . 'LIMIT 10';
     $db->setQuery($query);
     $result = $db->loadObjectList();
     return $result;
 }
Пример #4
0
 /**
  * Ajax join
  */
 public function follow()
 {
     $my = JXFactory::getUser();
     $group = JTable::getInstance('Group', 'StreamTable');
     $group->load(JRequest::getVar('group_id'));
     $group->followers = JXUtility::csvInsert($group->followers, $my->id);
     $group->store();
     // Store user cache
     $groupList = $my->getParam('groups_follow');
     $groupList = JXUtility::csvInsert($groupList, $group->id);
     $my->setParam('groups_follow', $groupList);
     $my->save();
     // Trigger Group Follow Notification
     StreamNotification::trigger('group_follow', $group, $my);
     $data = array();
     $data['redirect'] = JRoute::_('index.php?option=com_stream&view=groups&task=show&group_id=' . $group->id, FALSE);
     header('Content-Type: text/json');
     echo json_encode($data);
     exit;
 }
Пример #5
0
 /**
  * The user has downloaded the file
  */
 public function downloaded($userid)
 {
     $this->followers = JXUtility::csvInsert($this->followers, $userid);
 }
Пример #6
0
 /**
  *  AJAX Add Tag
  */
 public function tagAdd()
 {
     $message_id = JRequest::getInt('message_id');
     $tag = JRequest::getVar('tag');
     // Filter unsupported characters. TODO: ajax error status/msg handling
     $unsupportedChars = array(',');
     $tag = str_replace($unsupportedChars, '', $tag);
     $hashedTag = '#' . trim($tag) . '#';
     // Unlike message hash tags, we wrap them in hashes for specific searching
     $stream = JTable::getInstance('Stream', 'StreamTable');
     $stream->load($message_id);
     $rawData = json_decode($stream->raw);
     $rawData->tags = isset($rawData->tags) ? $rawData->tags : '';
     /* TODO: TEMPORARY START: Wrap tags without them */
     if (!empty($rawData->tags)) {
         $tagsExploded = explode(',', $rawData->tags);
         $addHashesCallback = create_function('$value', 'if($value[0] != "#" && $value[strlen($value)-1] != "#") { return "#".$value."#"; } else { return $value; }');
         $tagsExploded = array_map($addHashesCallback, $tagsExploded);
         $rawData->tags = implode(',', $tagsExploded);
     }
     /* TEMPORARY END */
     if (!JXUtility::csvExist($rawData->tags, $hashedTag)) {
         $rawData->tags = JXUtility::csvInsert($rawData->tags, $hashedTag);
         $stream->raw = json_encode($rawData);
         $stream->store(true);
         $tagsTrend = new StreamTag();
         $tagsTrend->updateTrending($tag, $stream->group_id, true);
     }
     $tmpl = new StreamTemplate();
     $tmpl->set('stream', $stream);
     $data = array();
     $data['html'] = $tmpl->fetch('stream.tag');
     $data['id'] = $message_id;
     $group_id = JRequest::getVar('group_id');
     header('Content-Type: text/json');
     echo json_encode($data);
     exit;
 }
Пример #7
0
 public function addUser($userid)
 {
     $this->user_ids = JXUtility::csvInsert($this->user_ids, $userid);
 }
Пример #8
0
 /**
  * link the given task to current message.
  */
 public function attachTodo($message)
 {
     $todoList = $this->data->getParam('todo');
     $this->data->setParam('todo', JXUtility::csvInsert($todoList, $message->id));
 }
Пример #9
0
 public function attachMessage($message_id)
 {
     $this->message_ids = JXUtility::csvInsert($this->message_ids, $message_id);
 }
Пример #10
0
 /**
  * To mark the message as when advance action is applied
  * Blog: viewed
  * Video: viewed
  * Link: cliked
  * File: downloaded
  * @param int $user_id
  * @param int $item_id the id of the read item, for example files/message
  */
 public function actionIsTaken($user_id = NULL, $item_id = NULL)
 {
     $jxuser = JXFactory::getUser();
     $my = !$user_id ? $jxuser->id : $user_id;
     $items = json_decode($this->getParam('action_by_user'), true);
     // placeholder for previous value
     $readers = array();
     // since the implementation of individual tracking comes later convert the previous int to json string
     if (!is_array($items)) {
         // store the previous data
         $readers[0] = $items;
         // because of array_merge, make sure we always provide and array to merge
         $items = array();
     }
     // to enable tracking per unique item, (!IMPORTANT: id of 0 is general to the message)
     $params = $item_id ? $item_id : 0;
     $addUserToItem = isset($items[$params]) ? JXUtility::csvInsert($items[$params], $my) : $my;
     $readers[$params] = $addUserToItem;
     $readers = array_merge($items, $readers);
     // store the array of the reader based on item
     return $this->setParam('action_by_user', json_encode($readers));
 }