public function getBreadcrumbs() { $trail = array(); $trail[] = array('url' => $this->discuss->request->makeUrl(), 'text' => $this->modx->getOption('discuss.forum_title')); $userParams = array(); if ($this->user->get('id') != $this->discuss->user->get('id')) { $userParams = array('user' => $this->user->get('id')); } $trail[] = array('text' => $this->modx->lexicon('discuss.user.trail', array('user' => $this->user->get('username'))), 'url' => $this->discuss->request->makeUrl('user', $userParams)); $trail[] = array('text' => $this->modx->lexicon('discuss.stats'), 'active' => true); return $trail; }
/** * Handle Quote functionality that will append the quoted post into the initial message * @return void */ public function handleQuote() { if (empty($_POST) && !empty($this->scriptProperties['quote'])) { $message = str_replace(array('[', ']'), array('[', ']'), $this->post->br2nl($this->post->get('message'))); $message = '[quote author=' . $this->author->get('username') . ' date=' . strtotime($this->post->get('createdon')) . ']' . $message . '[/quote]' . "\n"; $this->setPlaceholder('message', $message); } elseif (empty($_POST) && empty($this->scriptProperties['quote'])) { $this->setPlaceholder('message', ''); } }
/** * Log forum activity (destructive/creative only, ie, delete_post, delete_thread, create_post, etc) * @param string $action The action key that happened * @param array $data An array of extra data to store with the activity * @param string $url An optional URL to store * @return boolean */ public function logActivity($action, array $data = array(), $url = '') { if (empty($url)) { $url = !empty($_SERVER['HTTPS']) ? "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; } /** @var disLogActivity $activity */ $activity = $this->modx->newObject('disLogActivity'); $activity->set('createdon', $this->now()); $activity->set('user', $this->user->get('id')); $activity->set('ip', $this->getIp()); $activity->set('action', $action); $activity->set('data', $this->modx->toJSON($data)); $activity->set('url', $url); return $activity->save(); }
/** * Merge another user into this account * * @param disUser $oldUser * @return boolean */ public function merge(disUser &$oldUser) { $success = true; $user = $this->getOne('User'); if (empty($user)) { return false; } $oldModxUser = $oldUser->getOne('User'); if (empty($oldModxUser)) { return false; } $this->xpdo->beginTransaction(); /* merge post count */ $posts = $user->get('posts'); $posts = $posts + $oldUser->get('posts'); $this->set('posts', $posts); /* merge ignore boards */ $ibs = $this->get('ignore_boards'); $ibs = explode(',', $ibs); $oldIbs = $oldUser->get('ignore_boards'); $oldIbs = explode(',', $oldIbs); $ibs = array_merge($oldIbs, $ibs); $this->set('ignore_boards', implode(',', $ibs)); /* merge signature if needed */ $signature = $this->get('signature'); $oldSignature = $oldUser->get('signature'); if (empty($signature) && !empty($oldSignature)) { $this->set('signature', $oldSignature); } /* merge title if needed */ $title = $this->get('title'); $oldTitle = $oldUser->get('title'); if (empty($title) && !empty($oldTitle)) { $this->set('title', $oldTitle); } /* merge primary_group if needed */ $pg = $this->get('primary_group'); $oldPg = $oldUser->get('primary_group'); if (empty($pg) && !empty($oldPg)) { $this->set('primary_group', $oldPg); } $this->set('integrated_id', $oldUser->get('integrated_id')); $this->set('synced', true); $this->set('syncedat', $this->xpdo->discuss->now()); $this->save(); /* grant old usergroups to this user */ $oldUserGroups = $this->xpdo->getCollection('modUserGroupMember', array('member' => $oldModxUser->get('id'))); $ugs = array(); foreach ($oldUserGroups as $oldUserGroup) { $ugs[] = $oldUserGroup->get('user_group'); } $ugs = array_unique($ugs); foreach ($ugs as $ug) { $user->joinGroup($ug); } /* merge in posts, change authors */ $sql = 'UPDATE ' . $this->xpdo->getTableName('disPost') . ' SET `author` = ' . $this->get('id') . ' WHERE `author` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); $sql = 'UPDATE ' . $this->xpdo->getTableName('disThread') . ' SET `author_first` = ' . $this->get('id') . ' WHERE `author_first` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); $sql = 'UPDATE ' . $this->xpdo->getTableName('disThread') . ' SET `author_last` = ' . $this->get('id') . ' WHERE `author_last` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* merge in disThreadRead */ $sql = 'UPDATE ' . $this->xpdo->getTableName('disThreadRead') . ' SET `user` = ' . $this->get('id') . ' WHERE `user` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* merge in disThreadUser */ $sql = 'UPDATE ' . $this->xpdo->getTableName('disThreadUser') . ' SET `user` = ' . $this->get('id') . ' WHERE `user` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* merge in disUserFriend */ $sql = 'UPDATE ' . $this->xpdo->getTableName('disUserFriend') . ' SET `user` = ' . $this->get('id') . ' WHERE `user` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); $sql = 'UPDATE ' . $this->xpdo->getTableName('disUserFriend') . ' SET `friend` = ' . $this->get('id') . ' WHERE `friend` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* merge in disUserNotification */ $sql = 'UPDATE ' . $this->xpdo->getTableName('disUserNotification') . ' SET `user` = ' . $this->get('id') . ' WHERE `user` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* merge in disModerator */ $sql = 'UPDATE ' . $this->xpdo->getTableName('disModerator') . ' SET `user` = ' . $this->get('id') . ' WHERE `user` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* remove old user sessions */ $sql = 'DELETE FROM ' . $this->xpdo->getTableName('disUserFriend') . ' WHERE `user` = ' . $oldUser->get('id') . ' '; $this->xpdo->query($sql); /* merge all PMs users fields for user */ $c = $this->xpdo->newQuery('disThread'); $c->innerJoin('disThreadUser', 'Users'); $c->leftJoin('disThreadRead', 'Reads', 'Reads.user = '******'id') . ' AND disThread.id = Reads.thread'); $c->where(array('disThread.private' => true, 'Users.user' => $oldUser->get('id'))); $pms = $this->xpdo->getCollection('disThread', $c); foreach ($pms as $pm) { $users = $pm->get('users'); $users = explode(',', $users); $users = array_diff($users, array($oldUser->get('id'))); $users[] = $this->get('id'); $pm->set('users', implode(',', $users)); $pm->save(); } /* remove old users */ $oldUser->remove(); $oldModxUser->remove(); /* check for post group advance */ $this->checkForPostGroupAdvance(); $this->xpdo->commit(); return $success; }
/** * Import the UserGroup memberships for the specified User * * @param disUser $user * @param array $row * @return boolean */ public function importUserGroupMemberships(disUser $user, array $row) { $groups = array(); /* if a default group */ if (!empty($row['ID_GROUP'])) { $groups[] = $row['ID_GROUP']; } /* if any additional SMF groups */ if (!empty($row['additionalGroups'])) { $groups = array_merge(explode(',', $row['additionalGroups'])); } /* default user group import option */ if (!empty($this->config['default_user_group'])) { /** @var modUserGroup $dug */ $dug = $this->modx->getObject('modUserGroup', array('name' => $this->config['default_user_group'])); if ($dug) { $groups[] = $dug->get('id'); } } $groups = array_unique($groups); foreach ($groups as $group) { if (!empty($this->memberGroupCache[$group])) { /** @var modUserGroupMember $member */ $member = $this->modx->newObject('modUserGroupMember'); $member->set('user_group', $this->memberGroupCache[$group]); $member->set('member', $user->get('user')); if ($this->config['live']) { $member->save(); } } } return true; }