public function search($params) { $query = YBoardMember::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'birthdate' => $this->birthdate, 'show_online' => $this->show_online, 'contact_email' => $this->contact_email, 'contact_pm' => $this->contact_pm, 'first_visit' => $this->first_visit, 'last_visit' => $this->last_visit, 'warning' => $this->warning, 'posts' => $this->posts, 'group_id' => $this->group_id, 'upvoted' => $this->upvoted, 'moderator' => $this->moderator]); $query->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'personal_text', $this->personal_text])->andFilterWhere(['like', 'signature', $this->signature])->andFilterWhere(['like', 'avatar', $this->avatar])->andFilterWhere(['like', 'timezone', $this->timezone])->andFilterWhere(['like', 'blogger', $this->blogger])->andFilterWhere(['like', 'facebook', $this->facebook])->andFilterWhere(['like', 'github', $this->github])->andFilterWhere(['like', 'google', $this->google])->andFilterWhere(['like', 'linkedin', $this->linkedin])->andFilterWhere(['like', 'metacafe', $this->metacafe])->andFilterWhere(['like', 'skype', $this->skype])->andFilterWhere(['like', 'orkut', $this->orkut])->andFilterWhere(['like', 'tumblr', $this->tumblr])->andFilterWhere(['like', 'twitter', $this->twitter])->andFilterWhere(['like', 'website', $this->website])->andFilterWhere(['like', 'wordpress', $this->wordpress])->andFilterWhere(['like', 'yahoo', $this->yahoo])->andFilterWhere(['like', 'youtube', $this->youtube]); return $dataProvider; }
/** * Return the timezone notation for the user * @return string */ public static function userTimezoneNotation() { if (\Yii::$app->user->isGuest) { $timezone = date_default_timezone_get(); } else { $timezone = YBoardMember::findOne(\Yii::$app->user->id); if (isset($timezone->profile->timezone)) { $timezone = $timezone->profile->timezone; } if (empty($timezone)) { $timezone = date_default_timezone_get(); } } $dateTime = new DateTime(); $dateTime->setTimeZone(new DateTimeZone($timezone)); return $dateTime->format('T'); }
/** * @return \yii\db\ActiveQuery */ public function getMember() { return $this->hasOne(YBoardMember::className(), ['id' => 'member_id']); }
?> </div> <div class="col-md-1"><?php echo YBoardMember::find()->count(); ?> </div> <div class="col-md-9"></div> </div> <div class="row"> <div class="col-md-2"><?php echo YBoard::t('yboard', 'Newest member'); ?> </div> <div class="col-md-1"><?php $member = YBoardMember::find()->newestScope()->one(); echo $member == null ? YBoard::t('yboard', 'None') : Html::a($member->profile->username, ['member/view', 'id' => $member->id]); ?> </div> <div class="col-md-9"></div> </div> <div class="row"> <div class="col-md-2"><?php echo YBoard::t('yboard', 'Visitors today'); ?> </div> <div class="col-md-1"><?php echo YBoardSession::find()->count(); ?> </div>
/** * handle Ajax call for sending a report on a post */ public function actionSendReport() { if (!Yii::$app->user->can('app.forum.message.send-report')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.')); } $json = []; if (isset($_POST['YBoardMessage'])) { $model = new YBoardMessage(); $model->attributes = $_POST['YBoardMessage']; $post = YBoardPost::findOne($model->post_id); $model->subject = YBoard::t('yboard', 'Post reported:') . ' ' . $post->subject; $model->sendto = 0; //reported post No recipient $model->sendfrom = Yii::$app->user->id; $model->outbox = 0; // not put to outbox $model->type = 2; //notifications $model->ip = Yii::$app->request->userIP; $user = YBoardMember::findOne(Yii::$app->user->id); $content = YBoard::t('yboard', 'Reporter: {user} Reason:{reason} . The link to the post is attached below"', ['reason' => $model->content, 'user' => $user->profile->username]) . '<p>' . Html::a(YBoard::t('yboard', 'click to view post'), ['/' . $this->module->id . '/forum/topic', 'id' => $post->topic_id, '#' => $post->id], ['target' => '_blank']) . '</p> <p>' . Html::a(YBoard::t('yboard', 'click to view reporter [{username}]', ['username' => $user->profile->username]), ['/' . $this->module->id . '/member/view', 'id' => $user->id], ['target' => '_blank']) . '</p>' . '<p>' . YBoard::t('yboard', ' Reporter IP: {ip}]', ['ip' => Yii::$app->request->userIP]) . '</p>'; $model->content = $content; if ($model->save()) { $json['success'] = 'yes'; $json['message'] = YBoard::t('yboard', 'Thank you for your report.'); } else { $json['success'] = 'no'; $json['message'] = YBoard::t('yboard', 'Could not register your report.') . json_encode($_POST) . " ===== " . json_encode($model->errors); } } echo json_encode($json); Yii::$app->end(); }
public function updateOnlineStatus($action) { //Timed JS function //fetch current user list and add update statistics //js to Update it for a time session_start(); Yii::$app->view->registerJs(" \n function updateOnlineUsers() {\n \$.get('" . Yii::$app->urlManager->createUrl([$this->id . '/member/update-online-status', 'id' => Yii::$app->session->id, 'uid' => Yii::$app->user->id]) . "')\n .done(function(data){\n data = \$.parseJSON(data);\n console.log(data);\n \$('#online-record').html(data.message);\n }); \n }\n \n //call function to immediately update online users\n updateOnlineUsers();\n setInterval(updateOnlineUsers," . $this->onlineLimit * 1000 . ");\n "); // register visit by guest or user /*$session = YBoardSession::findOne(Yii::$app->session->id); if($session == null) { $session = new YBoardSession; $session->setAttributes([ 'id'=>Yii::$app->session->id, 'user_id'=>Yii::$app->user->isGuest ? NULL : Yii::$app->user->id, 'last_visit'=>time(), ]); } $session->save() ; */ // register last visit by member if (!Yii::$app->user->isGuest) { $model = YBoardMember::findOne(Yii::$app->user->id); if ($model !== null) { $model->last_visit = date('Y-m-d H:i:s'); $model->save(); //banned user are not allowed to access anything. So they have to be guests if ($action->id != 'banned' && $action->id != 'error') { Event::on(self::className(), self::EVENT_AFTER_ACTION, function ($event) { //if banned redirect to banned $ban = YBoardBan::find()->where(['user_id' => Yii::$app->user->id])->orWhere(['ip' => Yii::$app->request->userIP])->andWhere('expires>' . time())->one(); if ($ban != null) { return Yii::$app->response->redirect([$this->id . '/forum/banned', 'id' => $ban->id])->send(); } }); } } else { //redirect to associate member with forum account //no user can access forum logged in without member account if ($action->id != 'banned' && $action->id != 'error' && $action->id != 'associate' && $action->controller->id != 'member') { Event::on(self::className(), self::EVENT_AFTER_ACTION, function ($event) { return Yii::$app->response->redirect([$this->id . '/member/associate', 'id' => Yii::$app->user->id])->send(); }); } } } }
/** * @return \yii\db\ActiveQuery */ public function getBanner() { return $this->hasOne(YBoardMember::className(), ['id' => 'banned_by']); }
public static function getForumOptions($isGuest, $uid) { $return = []; $category = YBoardForum::find()->where(['type' => 0])->orderBy('sort')->all(); foreach ($category as $group) { $forum = YBoardForum::find()->where(['type' => 1])->andWhere(['cat_id' => $group->id])->orderBy('sort')->all(); foreach ($forum as $option) { if ($option->public || !$isGuest) { if ($option->membergroup_id == 0) { $return[] = ['id' => $option->id, 'name' => $option->name, 'group' => $group->name]; } else { if (!$isGuest) { $groupId = YBoardMember::findOne($uid)->group_id; if ($option->membergroup_id == $groupId) { $return[] = ['id' => $option->id, 'name' => $option->name, 'group' => $group->name]; } } } } } } return $return; }
/** * @return \yii\db\ActiveQuery */ public function getMembers() { return $this->hasMany(YBoardMember::className(), ['group_id' => 'id']); }
<?php /* @var $post_id integer */ use app\modules\yboard\YBoard; use app\modules\yboard\models\YBoardUpvoted; use app\modules\yboard\models\YBoardMember; use yii\helpers\Html; $models = YBoardUpvoted::find()->where(['post_id' => $post_id])->all(); $count = count($models); if ($count) { echo '<div class="post-upvote-footer">' . PHP_EOL; echo YBoard::t('yboard', 'This post is appreciated by {no} member{plural}', ['no' => $count, 'plural' => $count > 1 ? 's' : '']) . ' '; $users = []; foreach ($models as $model) { $member = YBoardMember::findOne($model->member_id); if ($member !== null) { $users[] = Html::a(Html::encode($member->profile->username), ["member/view", "id" => $member->id], ['target' => '_blank']); } } $members = '<b>' . implode(', ', $users) . '</b>'; echo Html::a(YBoard::t('yboard', '[view]'), '#', ['onclick' => 'showAppreciation(\'' . $members . '\'); return false;']); echo '</div>' . PHP_EOL; }
/** * @return \yii\db\ActiveQuery */ public function getReceiver() { return $this->hasOne(YBoardMember::className(), ['id' => 'sendto']); }
public function actionChangePost() { if (!Yii::$app->user->can('app.forum.moderator.change-post')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.')); } $json = []; $id = $_POST['YBoardPost']['id']; $model = YBoardPost::findOne($id); if ($model == null) { $json['success'] = 'no'; $json['error'] = YBoard::t('yboard', 'Post not found.'); } else { $model->attributes = $_POST['YBoardPost']; $model->change_reason = YBoard::t('yboard', 'Post modearated by {user}', ['user' => YBoardMember::findOne(Yii::$app->user->id)->profile->username]); if ($model->save()) { $json['success'] = 'yes'; } else { $json['success'] = 'no'; $json['error'] = YBoard::t('yboard', 'Post was not updated.'); } } echo json_encode($json); Yii::$app->end(); }
protected function resetRank() { $author = YBoardMember::findOne($this->user_id); if ($author !== null) { $query = new Query(); $query->select('id')->from('YBoardRank')->orderBy('min_posts ASC')->where('min_posts>=' . $author->totalReplies)->limit(1); $count = $query->count(); $id = $query->one(); if ($author->rank_id != $id['id'] && $count > 0) { $author->setAttribute('rank_id', $id['id']); $author->save(); } } }
/** * Displays a single YBoardMember model for Editing and other bells. * @param string $id * @return mixed */ public function actionEditProfile($id) { if (!Yii::$app->user->can('app.forum.setting.edit-profile')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.')); } $model = YBoardMember::findOne($id); if ($model == null) { throw new NotFoundHttpException('The requested User does not exist.'); } return $this->render('profile', ['model' => $model]); }
/** * Finds the YBoardMember model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return YBoardMember the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = YBoardMember::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Displays a single YBoardBan model. * @param integer $id * @return mixed */ public function actionBanned($id) { $model = YBoardBan::findOne($id); $user = YBoardMember::findOne($model->user_id); $isIP = true; if ($user !== null) { $isIP = false; } if ($model == null) { throw new NotFoundHttpException(YBoard::t('yboard', 'The requested Banned User does not exist.')); } $settings = YBoardSetting::find()->where(['key' => 'email'])->one(); return $this->render('banned', ['model' => $model, 'member' => $user, 'isIp' => $isIP, 'email' => $settings == null ? YBoard::t('board', 'no email') : $settings->value]); }