Example #1
0
    /**
     * Displays the details for a talk.
     *
     * @param integer     $id      the id of the talk
     * @param string|null $add_act if 'claim' tries to claim the talk
     * @param string|null $code    code to claim talk with
     *
     * @return void
     */
    function view($id, $add_act = null, $code = null)
    {
        $this->load->model('talks_model');
        $this->load->model('event_model');
        $this->load->model('invite_list_model', 'ilm');
        $this->load->model('user_attend_model');
        $this->load->model('talk_track_model', 'talkTracks');
        $this->load->model('talk_comments_model', 'tcm');
        $this->load->model('talk_speaker_model', 'talkSpeakers');
        $this->load->helper('form');
        $this->load->helper('events');
        $this->load->helper('talk');
        $this->load->helper('reqkey');
        $this->load->plugin('captcha');
        $this->load->library('defensio');
        $this->load->library('spam');
        $this->load->library('validation');
        $this->load->library('timezone');
        $this->load->library('sendemail');
        $msg = '';
        // filter it down to just the numeric characters
        if (preg_match('/[0-9]+/', $id, $m)) {
            $id = $m[0];
        } else {
            redirect('talk');
        }
        $currentUserId = $this->session->userdata('ID');
        $talk_detail = $this->talks_model->getTalks($id);
        if (empty($talk_detail)) {
            redirect('talk');
        }
        if ($talk_detail[0]->private == 'Y') {
            if (!$this->user_model->isAuth()) {
                // denied!
                redirect('event/view/' . $talk_detail[0]->eid);
            }
            // if the event for this talk is private, be sure that
            // the user is allowed
            if (!$this->ilm->isInvited($talk_detail[0]->eid, $currentUserId) && !$this->user_model->isAdminEvent($talk_detail[0]->eid)) {
                redirect('event/view/' . $talk_detail[0]->eid);
            }
        }
        $claim_status = false;
        $claim_msg = '';
        if (isset($add_act) && $add_act == 'claim') {
            // be sure they're loged in first...
            if (!$this->user_model->isAuth()) {
                //redirect to the login form
                $this->session->set_userdata('ref_url', '/talk/view/' . $id . '/claim/' . $code);
                redirect('user/login');
            } else {
                $sp = explode(',', $talk_detail[0]->speaker);
                $codes = array();
                //loop through the speakers to make the codes
                foreach ($sp as $k => $v) {
                    // we should be logged in now... lets check and
                    // see if the code is right
                    $str = buildCode($id, $talk_detail[0]->event_id, $talk_detail[0]->talk_title, trim($v));
                    $codes[] = $str;
                }
                if (in_array($code, $codes)) {
                    //TODO: linking on the display side to the right user
                    $uid = $this->session->userdata('ID');
                    $ret = $this->talks_model->linkUserRes($uid, $id, 'talk', $code);
                    if (!$ret) {
                        $claim_status = false;
                        $claim_msg = 'There was an error claiming your talk!';
                    } else {
                        $claim_status = true;
                        $claim_msg = 'Talk claimed successfully!';
                    }
                } else {
                    $claim_status = false;
                    $claim_msg = 'There was an error claiming your talk!';
                }
            }
        }
        $cl = ($r = $this->talks_model->talkClaimDetail($id)) ? $r : false;
        $rules = array('rating' => $cl && $cl[0]->userid == $currentUserId ? null : 'required');
        $fields = array('comment' => 'Comment', 'rating' => 'Rating');
        // if it's past time for the talk, they're required
        // all other times they're not required...
        if (time() >= $talk_detail[0]->date_given) {
            $rules['comment'] = 'required';
        }
        // this is for the CAPTACHA - it was disabled for authenticated users
        if (!$this->user_model->isAuth()) {
            $rules['cinput'] = 'required|callback_cinput_check';
            $fields['cinput'] = 'Captcha';
        }
        $this->validation->set_rules($rules);
        $this->validation->set_fields($fields);
        if ($this->validation->run() == false) {
            // vote processing code removed
        } else {
            $is_auth = $this->user_model->isAuth();
            $arr = array('comment_type' => 'comment', 'comment_content' => $this->input->post('your_com'));
            $priv = $this->input->post('private');
            $priv = empty($priv) ? 0 : 1;
            $anonymous = $this->input->post('anonymous');
            $anonymous = empty($anonymous) ? 0 : 1;
            if (!$is_auth) {
                $sp_ret = $this->spam->check('regex', $this->input->post('comment'));
                error_log('sp: ' . $sp_ret);
                if ($is_auth) {
                    $ec['user_id'] = $this->session->userdata('ID');
                    $ec['cname'] = $this->session->userdata('username');
                } else {
                    $ec['user_id'] = 0;
                    $ec['cname'] = $this->input->post('cname');
                }
                $ec['comment'] = $this->input->post('comment');
                $def_ret = $this->defensio->check($ec['cname'], $ec['comment'], $is_auth, '/talk/view/' . $id);
                $is_spam = (string) $def_ret->spam;
            } else {
                // They're logged in, let their comments through
                $is_spam = false;
                $sp_ret = true;
            }
            if ($is_spam != 'true' && $sp_ret == true) {
                $arr = array('talk_id' => $id, 'rating' => $this->input->post('rating'), 'comment' => $this->input->post('comment'), 'date_made' => time(), 'private' => $priv, 'active' => 1, 'user_id' => $this->user_model->isAuth() && !$anonymous ? $this->session->userdata('ID') : '0');
                $out = '';
                if ($this->input->post('edit_comment')) {
                    $cid = $this->input->post('edit_comment');
                    $uid = $this->session->userdata('ID');
                    // be sure they have the right to update the comment
                    $com_detail = $this->tcm->getCommentDetail($cid);
                    if (isset($com_detail[0]) && $com_detail[0]->user_id == $uid) {
                        $this->db->where('ID', $cid);
                        $this->db->update('talk_comments', $arr);
                        $out = 'Comment updated!';
                    } else {
                        $out = 'Error on updating comment!';
                    }
                } else {
                    $this->db->insert('talk_comments', $arr);
                    $out = 'Comment added!';
                }
                //send an email when a comment's made
                $msg = '';
                $arr['spam'] = $is_spam == 'false' ? 'spam' : 'not spam';
                foreach ($arr as $ak => $av) {
                    $msg .= '[' . $ak . '] => ' . $av . "\n";
                }
                //if its claimed, be sure to send an email to the person to tell them
                if ($cl) {
                    $this->sendemail->sendTalkComment($id, $cl[0]->email, $talk_detail, $arr);
                }
                $this->session->set_flashdata('msg', $out);
            }
            redirect('talk/view/' . $talk_detail[0]->tid . '#comments', 'location', 302);
        }
        $captcha = create_captcha();
        $this->session->set_userdata(array('cinput' => $captcha['value']));
        $reqkey = buildReqKey();
        $talk_detail = $this->talks_model->setDisplayFields($talk_detail);
        // catch this early...if it's not a valid session...
        if (empty($talk_detail)) {
            redirect('talk');
        }
        $is_talk_admin = $this->user_model->isAdminTalk($id);
        // Retrieve ALL comments, then Reformat and filter out private comments
        $all_talk_comments = $this->talks_model->getTalkComments($id, null, true);
        $talk_comments = splitCommentTypes($all_talk_comments, $is_talk_admin, $this->session->userdata('ID'));
        // also given only makes sense if there's a speaker set
        if (!empty($talk_detail[0]->speaker)) {
            $also_given = $this->talks_model->talkAlsoGiven($id, $talk_detail[0]->event_id);
            $also_given = array('talks' => $also_given, 'title' => 'Talk Also Given At...');
        }
        $user_id = $this->user_model->isAuth() ? $this->session->userdata('ID') : null;
        $speakers = $this->talkSpeakers->getSpeakerByTalkId($id);
        // check if current user is one of the approved speakers
        $is_claim_approved = false;
        foreach ($speakers as $speaker) {
            if ($speaker->speaker_id && $speaker->speaker_id == $user_id) {
                $is_claim_approved = true;
            }
        }
        $arr = array('detail' => $talk_detail[0], 'comments' => isset($talk_comments['comment']) ? $talk_comments['comment'] : array(), 'admin' => $is_talk_admin ? true : false, 'site_admin' => $this->user_model->isSiteAdmin() ? true : false, 'auth' => $this->auth, 'claimed' => $this->talks_model->talkClaimDetail($id), 'claim_status' => $claim_status, 'claim_msg' => $claim_msg, 'is_claimed' => $this->talks_model->hasUserClaimed($id) || $is_claim_approved, 'speakers' => $speakers, 'reqkey' => $reqkey, 'seckey' => buildSecFile($reqkey), 'user_attending' => $this->user_attend_model->chkAttend($currentUserId, $talk_detail[0]->event_id) ? true : false, 'msg' => $msg, 'track_info' => $this->talkTracks->getSessionTrackInfo($id), 'user_id' => $this->user_model->isAuth() ? $this->session->userdata('ID') : null, 'captcha' => $captcha);
        $this->template->write('feedurl', '/feed/talk/' . $id);
        if (!empty($also_given['talks'])) {
            $this->template->write_view('sidebar2', 'talk/_also_given', $also_given, true);
        }
        if (!isTalkClaimFull($arr['speakers'])) {
            $this->template->write_view('sidebar3', 'main/_sidebar-block', array('title' => 'Claiming Talks', 'content' => '<p>Claiming a talk you let us know that you were the speaker 
					for it. When you claim it (and it\'s approved by the event admins) it will 
					be linked to your account.</p><p>You\'ll also receive emails when new comments 
					are posted to 	it.</p>'));
        }
        if ($is_talk_admin) {
            $this->template->write_view('sidebar3', 'talk/modules/_talk_howto', $arr);
        }
        $this->template->write_view('content', 'talk/detail', $arr, true);
        $this->template->render();
    }
Example #2
0
 /**
  * Displays the details for a talk.
  *
  * @param integer     $id      the id of the talk
  * @param string|null $add_act if 'claim' tries to claim the talk
  * @param string|null $code    code to claim talk with
  *
  * @return void
  */
 function view($id, $add_act = null, $code = null)
 {
     $this->load->model('talks_model');
     $this->load->model('event_model');
     $this->load->model('event_comments_model');
     $this->load->model('invite_list_model', 'ilm');
     $this->load->model('user_attend_model');
     $this->load->model('talk_track_model', 'talkTracks');
     $this->load->model('talk_comments_model', 'tcm');
     $this->load->model('talk_speaker_model', 'talkSpeakers');
     $this->load->helper('form');
     $this->load->helper('events');
     $this->load->helper('talk');
     $this->load->helper('reqkey');
     $this->load->plugin('captcha');
     $this->load->library('spamcheckservice', array('api_key' => $this->config->item('akismet_key')));
     $this->load->library('spam');
     $this->load->library('validation');
     $this->load->library('timezone');
     $this->load->library('sendemail');
     $msg = '';
     // filter it down to just the numeric characters
     if (preg_match('/[0-9]+/', $id, $m)) {
         $id = $m[0];
     } else {
         redirect('talk');
     }
     $currentUserId = $this->session->userdata('ID');
     $talk_detail = $this->talks_model->getTalks($id);
     if (empty($talk_detail)) {
         redirect('talk');
     }
     if ($talk_detail[0]->private == 'Y') {
         if (!$this->user_model->isAuth()) {
             // denied!
             redirect('event/view/' . $talk_detail[0]->eid);
         }
         // if the event for this talk is private, be sure that
         // the user is allowed
         if (!$this->ilm->isInvited($talk_detail[0]->eid, $currentUserId) && !$this->user_model->isAdminEvent($talk_detail[0]->eid)) {
             redirect('event/view/' . $talk_detail[0]->eid);
         }
     }
     $claim_status = false;
     $claim_msg = '';
     if (isset($add_act) && $add_act == 'claim') {
         // be sure they're loged in first...
         if (!$this->user_model->isAuth()) {
             //redirect to the login form
             $this->session->set_userdata('ref_url', '/talk/view/' . $id . '/claim/' . $code);
             redirect('user/login');
         } else {
             $sp = explode(',', $talk_detail[0]->speaker);
             $codes = array();
             //loop through the speakers to make the codes
             foreach ($sp as $k => $v) {
                 // we should be logged in now... lets check and
                 // see if the code is right
                 $str = buildCode($id, $talk_detail[0]->event_id, $talk_detail[0]->talk_title, trim($v));
                 $codes[] = $str;
             }
             if (in_array($code, $codes)) {
                 //TODO: linking on the display side to the right user
                 $uid = $this->session->userdata('ID');
                 $ret = $this->talks_model->linkUserRes($uid, $id, 'talk', $code);
                 if (!$ret) {
                     $claim_status = false;
                     $claim_msg = 'There was an error claiming your talk!';
                 } else {
                     $claim_status = true;
                     $claim_msg = 'Talk claimed successfully!';
                 }
             } else {
                 $claim_status = false;
                 $claim_msg = 'There was an error claiming your talk!';
             }
         }
     }
     $cl = ($r = $this->talks_model->talkClaimDetail($id)) ? $r : array();
     $already_rated = false;
     if ($this->user_model->isAuth()) {
         // Find out if there is at least 1 comment that is made by our
         // user for this talk
         foreach ($this->talks_model->getUserComments($this->user_model->getId()) as $comment) {
             if ($comment->talk_id == $id) {
                 $already_rated = $comment->ID;
                 break;
             }
         }
     }
     // build array of userIds with claim to this talk
     $claim_user_ids = array();
     foreach ($cl as $claim_item) {
         $claim_user_ids[] = $claim_item->userid;
     }
     $current_comment_id = 0;
     if ($this->input->post('edit_comment')) {
         $current_comment_id = $this->input->post('edit_comment');
     }
     // comment form validation rules:
     // rating:
     //      1. rating_check to ensure between 0 and 5
     //      2. required field if not already commented
     // comment:
     //      1. duplicate_comment_check to ensure exact comment isn't posted twice
     $rating_rule = 'callback_rating_check';
     $rating_rule .= in_array($currentUserId, $claim_user_ids) || $already_rated ? '' : '|required';
     $rules = array('rating' => $rating_rule, 'comment' => "callback_duplicate_comment_check[{$id}!{$current_comment_id}]");
     $fields = array('comment' => 'Comment', 'rating' => 'Rating');
     // this is for the CAPTACHA - it was disabled for authenticated users
     if (!$this->user_model->isAuth()) {
         $rules['cinput'] = 'required|callback_cinput_check';
         $fields['cinput'] = 'Captcha';
     }
     $this->validation->set_rules($rules);
     $this->validation->set_fields($fields);
     if ($this->validation->run() == false) {
         // vote processing code removed
     } else {
         $is_auth = $this->user_model->isAuth();
         $arr = array('comment_type' => 'comment', 'comment_content' => $this->input->post('your_com'));
         $priv = $this->input->post('private');
         $priv = empty($priv) ? 0 : 1;
         $anonymous = $this->input->post('anonymous');
         $anonymous = empty($anonymous) ? 0 : 1;
         if (!$is_auth) {
             $sp_ret = $this->spam->check('regex', $this->input->post('comment'));
             error_log('sp: ' . $sp_ret);
             if ($is_auth) {
                 $ec['user_id'] = $this->session->userdata('ID');
                 $ec['cname'] = $this->session->userdata('username');
             } else {
                 $ec['user_id'] = 0;
                 $ec['cname'] = $this->input->post('cname');
             }
             $ec['comment'] = $this->input->post('comment');
             $acceptable_comment = $this->spamcheckservice->isCommentAcceptable(array('comment' => $ec['comment']));
         } else {
             // They're logged in, let their comments through
             $acceptable_comment = true;
             $is_spam = false;
             $sp_ret = true;
         }
         if ($acceptable_comment && $sp_ret == true) {
             $arr = array('talk_id' => $id, 'rating' => $this->input->post('rating'), 'comment' => $this->input->post('comment'), 'date_made' => time(), 'private' => $priv, 'active' => 1, 'user_id' => $this->user_model->isAuth() && !$anonymous ? $this->session->userdata('ID') : '0');
             $out = '';
             if ($this->input->post('edit_comment')) {
                 $cid = $this->input->post('edit_comment');
                 $uid = $this->session->userdata('ID');
                 // be sure they have the right to update the comment
                 $com_detail = $this->tcm->getCommentDetail($cid);
                 if (isset($com_detail[0]) && $com_detail[0]->user_id == $uid) {
                     // if the user has already rated and we're not editing that comment,
                     // then the rating for this comment is zero
                     if ($already_rated && $already_rated != $cid) {
                         $arr['rating'] = 0;
                     }
                     $commentEditTime = $com_detail[0]->date_made + $this->config->item('comment_edit_time');
                     if (time() >= $commentEditTime) {
                         $out = 'This comment has passed its edit-time.' . ' You cannot edit this comment anymore.';
                     } else {
                         $this->db->where('ID', $cid);
                         // unset date made.
                         unset($arr['date_made']);
                         if ($com_detail[0]->rating == 0) {
                             $arr['rating'] = 0;
                         }
                         $this->db->update('talk_comments', $arr);
                         $out = 'Comment updated!';
                     }
                 } else {
                     $out = 'Error on updating comment!';
                 }
             } else {
                 $this->db->insert('talk_comments', $arr);
                 $out = 'Comment added!';
             }
             //send an email when a comment's made
             $msg = '';
             $arr['spam'] = $is_spam == 'false' ? 'spam' : 'not spam';
             foreach ($arr as $ak => $av) {
                 $msg .= '[' . $ak . '] => ' . $av . "\n";
             }
             //if its claimed, be sure to send an email to the person to tell them
             if ($cl) {
                 $this->sendemail->sendTalkComment($id, $cl[0]->email, $talk_detail, $arr);
             }
             $this->session->set_flashdata('msg', $out);
         }
         redirect('talk/view/' . $talk_detail[0]->tid . '#comments', 'location', 302);
     }
     $captcha = create_captcha();
     $this->session->set_userdata(array('cinput' => $captcha['value']));
     $reqkey = buildReqKey();
     $talk_detail = $this->talks_model->setDisplayFields($talk_detail);
     // catch this early...if it's not a valid session...
     if (empty($talk_detail)) {
         redirect('talk');
     }
     $is_talk_admin = $this->user_model->isAdminTalk($id);
     // Retrieve ALL comments, then Reformat and filter out private comments
     $all_talk_comments = $this->talks_model->getTalkComments($id, null, true);
     $talk_comments = splitCommentTypes($all_talk_comments, $is_talk_admin, $this->session->userdata('ID'));
     // also given only makes sense if there's a speaker set
     if (!empty($talk_detail[0]->speaker)) {
         $also_given = $this->talks_model->talkAlsoGiven($id, $talk_detail[0]->event_id);
         $also_given = array('talks' => $also_given, 'title' => 'Talk Also Given At...');
     }
     $user_id = $this->user_model->isAuth() ? $this->session->userdata('ID') : null;
     $speakers = $this->talkSpeakers->getSpeakerByTalkId($id);
     // check if current user is one of the approved speakers
     $is_claim_approved = false;
     foreach ($speakers as $speaker) {
         if ($speaker->speaker_id && $speaker->speaker_id == $user_id) {
             $is_claim_approved = true;
         }
     }
     if (isset($talk_comments['comment'])) {
         for ($i = 0; $i < count($talk_comments['comment']); $i++) {
             if ($talk_comments['comment'][$i]->user_id != 0) {
                 $talk_comments['comment'][$i]->user_comment_count = $this->event_comments_model->getUserCommentCount($talk_comments['comment'][$i]->user_id) + $this->tcm->getUserCommentCount($talk_comments['comment'][$i]->user_id);
             }
         }
     }
     $arr = array('detail' => $talk_detail[0], 'comments' => isset($talk_comments['comment']) ? $talk_comments['comment'] : array(), 'admin' => $is_talk_admin ? true : false, 'site_admin' => $this->user_model->isSiteAdmin() ? true : false, 'auth' => $this->auth, 'claimed' => $this->talks_model->talkClaimDetail($id), 'claim_status' => $claim_status, 'claim_msg' => $claim_msg, 'is_claimed' => $this->talks_model->hasUserClaimed($id) || $is_claim_approved, 'speakers' => $speakers, 'reqkey' => $reqkey, 'seckey' => buildSecFile($reqkey), 'user_attending' => $this->user_attend_model->chkAttend($currentUserId, $talk_detail[0]->event_id) ? true : false, 'msg' => $msg, 'track_info' => $this->talkTracks->getSessionTrackInfo($id), 'user_id' => $this->user_model->isAuth() ? $this->session->userdata('ID') : null, 'captcha' => $captcha, 'alreadyRated' => $already_rated);
     $this->template->write('feedurl', '/feed/talk/' . $id);
     if (!empty($also_given['talks'])) {
         $this->template->write_view('sidebar2', 'talk/_also_given', $also_given, true);
     }
     if (!isTalkClaimFull($arr['speakers'])) {
         $this->template->write_view('sidebar3', 'main/_sidebar-block', array('title' => 'Claiming Talks', 'content' => '<p>Is this your talk? Claim it! By doing so it
                 lets us know you are the speaker. Once your claim is
                 verified by event administration it will be linked to your
                 account.</p>'));
     }
     if ($is_talk_admin) {
         $this->template->write_view('sidebar3', 'talk/modules/_talk_howto', $arr);
     }
     $this->template->write_view('content', 'talk/detail', $arr, true);
     $this->template->render();
 }