示例#1
0
 /**
  * Unsubscribe user from forum emails
  *
  * @return void
  */
 public function unsubscribe()
 {
     // get the token
     $token = Request::getCmd('t', '');
     //token is required
     if ($token == '') {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_MISSING_TOKEN'), 'error');
     }
     // get the token lib
     $encryptor = new \Hubzero\Mail\Token();
     // get token details
     $tokenDetails = $encryptor->decryptEmailToken($token);
     // make sure token details are good
     if (empty($tokenDetails) || !isset($tokenDetails[1]) || $this->group->get('gidNumber') != $tokenDetails[1]) {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_INVALID_TOKEN'), 'error');
     }
     // neede member option lib
     include_once PATH_CORE . DS . 'plugins' . DS . 'groups' . DS . 'memberoptions' . DS . 'memberoption.class.php';
     // Find the user's group settings, do they want to get email (0 or 1)?
     $groupMemberOption = new GroupsTableMemberoption($this->database);
     $groupMemberOption->loadRecord($this->group->get('gidNumber'), $tokenDetails[0], GROUPS_MEMBEROPTION_TYPE_DISCUSSION_NOTIFICIATION);
     // mark that they dont want to be received anymore.
     $groupMemberOption->optionvalue = 0;
     // attempt to update
     if (!$groupMemberOption->save($groupMemberOption)) {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_UNABLE_TO_UNSUBSCRIBE'), 'error');
     }
     // success
     App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_SUCCESSFULLY_UNSUBSCRIBED'));
 }