Пример #1
0
 public function get_captcha()
 {
     if (!$this->captcha) {
         $this->captcha = Captcha::factory($this->group);
     }
     return $this->captcha;
 }
 /**
  * @return void
  */
 private function _processCaptcha()
 {
     @session_start();
     $captchaHandler = CampRequest::GetVar('f_captcha_handler', '', 'POST');
     if (!empty($captchaHandler)) {
         $captcha = Captcha::factory($captchaHandler);
         if (!$captcha->validate()) {
             $this->m_error = new PEAR_Error('The code you entered is not the same as the one shown.',
             ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE);
             return FALSE;
         }
     } else {
         $f_captcha_code = CampRequest::GetVar('f_captcha_code');
         if (is_null($f_captcha_code) || empty($f_captcha_code)) {
             $this->m_error = new PEAR_Error('Please enter the code shown in the image.',
             ACTION_SUBMIT_COMMENT_ERR_NO_CAPTCHA_CODE);
             return FALSE;
         }
         if (!PhpCaptcha::Validate($f_captcha_code, true)) {
             $this->m_error = new PEAR_Error('The code you entered is not the same with the one shown in the image.',
             ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE);
             return FALSE;
         }
     }
     return TRUE;
 }
Пример #3
0
 public function index()
 {
     $this->template->header->this_page = 'contact';
     $this->template->content = new View('contact');
     $this->template->header->page_title .= Kohana::lang('ui_main.contact') . Kohana::config('settings.title_delimiter');
     // Setup and initialize form field names
     $form = array('contact_name' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_subject' => '', 'contact_message' => '', 'captcha' => '');
     // Copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $captcha = Captcha::factory();
     $errors = $form;
     $form_error = FALSE;
     $form_sent = FALSE;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('contact_name', 'required', 'length[3,100]');
         $post->add_rules('contact_email', 'required', 'email', 'length[4,100]');
         $post->add_rules('contact_subject', 'required', 'length[3,100]');
         $post->add_rules('contact_message', 'required');
         $post->add_rules('captcha', 'required', 'Captcha::valid');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid - Send email
             $site_email = Kohana::config('settings.site_email');
             $message = Kohana::lang('ui_admin.sender') . ": " . $post->contact_name . "\n";
             $message .= Kohana::lang('ui_admin.email') . ": " . $post->contact_email . "\n";
             $message .= Kohana::lang('ui_admin.phone') . ": " . $post->contact_phone . "\n\n";
             $message .= Kohana::lang('ui_admin.message') . ": \n" . $post->contact_message . "\n\n\n";
             $message .= "~~~~~~~~~~~~~~~~~~~~~~\n";
             $message .= Kohana::lang('ui_admin.sent_from_website') . url::base();
             // Send Admin Message
             email::send($site_email, $post->contact_email, $post->contact_subject, $message, FALSE);
             $form_sent = TRUE;
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('contact'));
             $form_error = TRUE;
         }
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_sent = $form_sent;
     $this->template->content->captcha = $captcha;
     // Rebuild Header Block
     $this->template->header->header_block = $this->themes->header_block();
     $this->template->footer->footer_block = $this->themes->footer_block();
 }
Пример #4
0
 public function render()
 {
     // create captcha object here if it's an image
     if (!$this->captcha) {
         $this->captcha = Captcha::factory($this->group);
     }
     // add the clear html to the close tag
     $this->close = $this->clear . $this->close;
     // only load the captcha if we're not sure it's a human
     if (!$this->captcha->promoted()) {
         return $this->captcha_open . "\n" . $this->captcha->render(TRUE) . "\n" . $this->captcha_close . $this->input_open . '<input type="text" name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . ' />' . "\n" . $this->input_close;
     }
 }
Пример #5
0
/**
 * Newscoop reCAPTCHA function plugin
 *
 * Type: function
 * Name: recaptcha
 * Purpose: Provide access to reCAPTCHA services
 *
 * @param empty
 *
 * @param object
 *     $p_smarty The Smarty object
 *
 * @return string
 */
function smarty_function_recaptcha($p_params, &$p_smarty)
{
    $html = '';
    $captcha = Captcha::factory('ReCAPTCHA');
    if ($captcha->isEnabled($p_params['form'] ?: '')) {
        $html = $captcha->render();
        if (is_array($html) && isset($html['error'])) {
            $html = '<p style="color:red;">' . $html['error'] . '</p>';
            return $html;
        }
        $html .= "\n<input type=\"hidden\" name=\"f_captcha_handler\" value=\"ReCAPTCHA\" />\n";
    }
    return $html;
}
 /**
  * @param  $request WebRequest
  * @return void
  */
 public function loadDataFromRequest($request)
 {
     $this->captcha = Captcha::factory();
     $this->captcha->loadFromRequest($request, $this);
     if (!$this->captcha->exists()) {
         // The captcha doesn't exist; probably because it's already been used and
         // then deleted for security.  Load the field up with a new captcha which
         // will be shown to the user when the validation of said new object fails
         $this->captcha = Captcha::newRandom();
     }
     // This will be useful as the difference between "the captcha doesn't exist" and
     // "you answered the captcha wrongly"
     return $this->captcha->exists();
 }
 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = FALSE)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports/detail');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     // Sanitize the report id before proceeding
     $id = intval($id);
     if ($id > 0) {
         $incident = ORM::factory('sharing_incident')->where('id', $id)->where('incident_active', 1)->find();
         // Not Found
         if (!$incident->loaded) {
             url::redirect('reports/');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST and Kohana::config('settings.allow_comments')) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             if (!$this->user) {
                 $post->add_rules('comment_author', 'required', 'length[3,100]');
                 $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             }
             $post->add_rules('comment_description', 'required');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 if ($api_akismet != "") {
                     // Run Akismet Spam Checker
                     $akismet = new Akismet();
                     // Comment data
                     $comment = array('website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                     if ($this->user) {
                         $comment['author'] = $this->user->name;
                         $comment['email'] = $this->user->email;
                     } else {
                         $comment['author'] = $post->comment_author;
                         $comment['email'] = $post->comment_email;
                     }
                     $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                     $akismet->init($config);
                     if ($akismet->errors_exist()) {
                         if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                             // throw new Kohana_Exception('akismet.api_key');
                         } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                             // throw new Kohana_Exception('akismet.server_failed');
                         } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                             // throw new Kohana_Exception('akismet.server_not_found');
                         }
                         $comment_spam = 0;
                     } else {
                         $comment_spam = $akismet->is_spam() ? 1 : 0;
                     }
                 } else {
                     // No API Key!!
                     $comment_spam = 0;
                 }
                 $comment = new Comment_Model();
                 $comment->incident_id = 0;
                 if ($this->user) {
                     $comment->user_id = $this->user->id;
                     $comment->comment_author = $this->user->name;
                     $comment->comment_email = $this->user->email;
                 } else {
                     $comment->comment_author = strip_tags($post->comment_author);
                     $comment->comment_email = strip_tags($post->comment_email);
                 }
                 $comment->comment_description = strip_tags($post->comment_description);
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 if ($comment_spam == 1) {
                     $comment->comment_spam = 1;
                     $comment->comment_active = 0;
                 } else {
                     $comment->comment_spam = 0;
                     $comment->comment_active = Kohana::config('settings.allow_comments') == 1 ? 1 : 0;
                 }
                 $comment->save();
                 // link comment to sharing_incident
                 $incident_comment = ORM::factory('sharing_incident_comment');
                 $incident_comment->comment_id = $comment->id;
                 $incident_comment->sharing_incident_id = $incident->id;
                 $incident_comment->save();
                 // Event::comment_add - Added a New Comment
                 Event::run('ushahidi_action.comment_add', $comment);
                 // Notify Admin Of New Comment
                 $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . utf8::strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/sharing/view/' . $id);
                 // Redirect
                 url::redirect('reports/sharing/view/' . $id);
             } else {
                 // No! We have validation errors, we need to show the form again, with the errors
                 // Repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // Populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('comments'));
                 $form_error = TRUE;
             }
         }
         // Filters
         $incident_title = $incident->incident_title;
         $incident_description = $incident->incident_description;
         Event::run('ushahidi_filter.report_title', $incident_title);
         Event::run('ushahidi_filter.report_description', $incident_description);
         $this->template->header->page_title .= $incident_title . Kohana::config('settings.title_delimiter');
         // Add Features
         // hardcode geometries to empty
         $this->template->content->features_count = 0;
         $this->template->content->features = array();
         $this->template->content->incident_id = $incident->id;
         $this->template->content->incident_title = $incident_title;
         $this->template->content->incident_description = $incident_description;
         $this->template->content->incident_location = $incident->location->location_name;
         $this->template->content->incident_latitude = $incident->location->latitude;
         $this->template->content->incident_longitude = $incident->location->longitude;
         $this->template->content->incident_date = date('M j Y', strtotime($incident->incident_date));
         $this->template->content->incident_time = date('H:i', strtotime($incident->incident_date));
         $this->template->content->incident_category = ORM::factory('sharing_incident_category')->where('sharing_incident_id', $incident->id)->find_all();
         // Incident rating
         $rating = ORM::factory('rating')->join('incident', 'incident.id', 'rating.incident_id', 'INNER')->where('rating.incident_id', $incident->id)->find();
         $this->template->content->incident_rating = $rating->rating == '' ? 0 : $rating->rating;
         // Retrieve Media
         $incident_news = array();
         $incident_video = array();
         $incident_photo = array();
         foreach ($incident->media as $media) {
             if ($media->media_type == 4) {
                 $incident_news[] = $media->media_link;
             } elseif ($media->media_type == 2) {
                 $incident_video[] = $media->media_link;
             } elseif ($media->media_type == 1) {
                 $incident_photo[] = array('large' => url::convert_uploaded_to_abs($media->media_link), 'thumb' => url::convert_uploaded_to_abs($media->media_thumb));
             }
         }
         $this->template->content->incident_verified = $incident->incident_verified;
         // Retrieve Comments (Additional Information)
         $this->template->content->comments = "";
         if (Kohana::config('settings.allow_comments')) {
             $this->template->content->comments = new View('reports/comments');
             $incident_comments = array();
             if ($id) {
                 $incident_comments = Sharing_Incident_Model::get_comments($id);
             }
             $this->template->content->comments->incident_comments = $incident_comments;
         }
     } else {
         url::redirect('reports');
     }
     // Add extra info to meta
     Event::add('ushahidi_action.report_display_media', array($this, 'report_display_media'));
     // Add Neighbors
     $this->template->content->incident_neighbors = Sharing_Incident_Model::get_neighbouring_incidents($id, TRUE, 0, 5);
     // News Source links
     $this->template->content->incident_news = $incident_news;
     // Video links
     $this->template->content->incident_videos = $incident_video;
     // Images
     $this->template->content->incident_photos = $incident_photo;
     // Create object of the video embed class
     $video_embed = new VideoEmbed();
     $this->template->content->videos_embed = $video_embed;
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->photoslider_enabled = TRUE;
     $this->themes->videoslider_enabled = TRUE;
     $this->themes->js = new View('reports/view_js');
     $this->themes->js->incident_id = $incident->id;
     $this->themes->js->incident_json_url = 'json/share/single/' . $incident->id;
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->themes->js->latitude = $incident->location->latitude;
     $this->themes->js->longitude = $incident->location->longitude;
     $this->themes->js->incident_zoom = null;
     //$incident->incident_zoom;
     $this->themes->js->incident_photos = $incident_photo;
     // Initialize custom field array
     $this->template->content->custom_forms = new View('reports/detail_custom_forms');
     $form_field_names = customforms::get_custom_form_fields($id, 1, FALSE, "view");
     $this->template->content->custom_forms->form_field_names = $form_field_names;
     // Are we allowed to submit comments?
     $this->template->content->comments_form = "";
     if (Kohana::config('settings.allow_comments')) {
         $this->template->content->comments_form = new View('reports/comments_form');
         $this->template->content->comments_form->user = $this->user;
         $this->template->content->comments_form->form = $form;
         $this->template->content->comments_form->form_field_names = $form_field_names;
         $this->template->content->comments_form->captcha = $captcha;
         $this->template->content->comments_form->errors = $errors;
         $this->template->content->comments_form->form_error = $form_error;
     }
     // If the Admin is Logged in - Allow for an edit link
     $this->template->content->logged_in = $this->logged_in;
     // Rebuild Header Block
     $this->template->header->header_block = $this->themes->header_block();
     $this->template->footer->footer_block = $this->themes->footer_block();
 }
Пример #8
0
 /**
  * Get the feedback
  */
 private function _get_feedback_form()
 {
     //setup and initialize form fields
     $form = array('feedback_message' => '', 'person_email' => '', 'feedback_captcha' => '');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     $captcha = Captcha::factory();
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     //has form been submitted, if so setup validation
     if ($_POST) {
         $post = Validation::factory($_POST);
         //Trim whitespaces
         $post->pre_filter('trim', TRUE);
         //Add validation rules
         $post->add_rules('feedback_message', 'required');
         $post->add_rules('person_email', 'required', 'email');
         $post->add_rules('feedback_captcha', 'required', 'Captcha::valid');
         if ($post->validate()) {
             if ($api_akismet != "") {
                 // Run Akismet Spam Checker
                 $akismet = new Akismet();
                 // comment data
                 $feedback = array('feedback_message' => $post->feedback_message, 'person_email' => $post->feedback_message);
                 $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'feedback' => $feedback);
                 $akismet->init($config);
                 if ($akismet->errors_exist()) {
                     if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                         // throw new Kohana_Exception('akismet.api_key');
                     } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                         // throw new Kohana_Exception('akismet.server_failed');
                     } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                         // throw new Kohana_Exception('akismet.server_not_found');
                     }
                     // If the server is down, we have to post
                     // the comment :(
                     // $this->_post_comment($comment);
                     $feedback_spam = 0;
                 } else {
                     if ($akismet->is_spam()) {
                         $feedback_spam = 1;
                     } else {
                         $feedback_spam = 0;
                     }
                 }
             } else {
                 // No API Key!!
                 $feedback_spam = 0;
             }
             $this->_dump_feedback($post);
             //send details to admin
             $frm = $post->person_email;
             $subject = Kohana::lang('feedback.feedback_details');
             $message = $post->feedback_message;
             $email = Kohana::config('settings.site_email');
             $this->_send_feedback($email, $message, $subject, $frm);
             //send details to ushahidi
             $frm = $post->person_email;
             $subject = Kohana::lang('feedback.feedback_details');
             $message = $post->feedback_message;
             $message .= "Instance: " . url::base();
             $email = "*****@*****.**";
             $this->_send_feedback($email, $message, $subject, $frm);
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('feedback'));
             $form_error = TRUE;
         }
     }
     $this->template->footer->js = new View('footer_form_js');
     $this->template->footer->form = $form;
     $this->template->footer->captcha = $captcha;
     $this->template->footer->errors = $errors;
     $this->template->footer->form_error = $form_error;
 }
Пример #9
0
 public function __call($method, $args)
 {
     // Output the Captcha challenge resource (no html)
     // Pull the config group name from the URL
     Captcha::factory($method)->render(NO);
 }
Пример #10
0
 /**
  * Displays a organization
  * @param boolean $id If id is supplied, an organization with that id will be
  * retrieved.
  */
 public function view($id = FALSE)
 {
     $this->template->header->this_page = 'help';
     $this->template->content = new View('help_view');
     if (!$id) {
         url::redirect('main');
     } else {
         $organization = ORM::factory('organization', $id);
         if ($organization->loaded == FALSE) {
             url::redirect('main');
         }
         // Comment Post?
         // setup and initialize form field names
         $form = array('name' => '', 'email' => '', 'phone' => '', 'message' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST) {
             // Instantiate Validation, use $post, so we don't overwrite
             // $_POST fields with our own things
             $post = Validation::factory($_POST);
             //  Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks,
             // carried out in order
             $post->add_rules('name', 'required', 'length[3, 100]');
             $post->add_rules('email', 'required', 'email', 'length[4, 100]');
             $post->add_rules('phone', 'length[3, 100]');
             $post->add_rules('message', 'required');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid - Send Message
                 if (!empty($organization->organization_email)) {
                     $to = $organization->organization_email;
                     $from = $post->email;
                     $subject = "New Message From " . Kohana::config('settings.site_name');
                     $message = "";
                     $message .= "Name: " . $post->name . "\n";
                     $message .= "Email: " . $post->email . "\n";
                     $message .= "Phone: " . $post->phone . "\n\n";
                     $message .= "Message:\n" . $post->message . "\n";
                     email::send($to, $from, $subject, $message, FALSE);
                 }
                 // Redirect
                 url::redirect('help/view/' . $id);
             } else {
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('message'));
                 $form_error = TRUE;
             }
         }
         $this->template->content->organization_id = $organization->id;
         $this->template->content->organization_name = $organization->organization_name;
         $this->template->content->organization_description = nl2br($organization->organization_description);
         $this->template->content->organization_website = text::auto_link($organization->organization_website);
         $this->template->content->organization_email = $organization->organization_email;
         $this->template->content->organization_phone1 = $organization->organization_phone1;
         $this->template->content->organization_phone2 = $organization->organization_phone2;
         // Forms
         $this->template->content->form = $form;
         $this->template->content->captcha = $captcha;
         $this->template->content->errors = $errors;
         $this->template->content->form_error = $form_error;
         // Javascript Header
         $this->template->header->js = new View('help_view_js');
     }
 }
Пример #11
0
 /**
  * Apply job page.
  */
 public function connect($id = false)
 {
     $this->template->header->this_page = 'job_apply';
     $this->template->content = new View('job_apply');
     if (!$id) {
         url::redirect('main');
     } else {
         $job = ORM::factory('incident', $id);
         $person = ORM::factory('incident_person')->where('incident_id', $id)->find();
         if ($job->id == 0) {
             url::redirect('main');
         }
         // Setup and initialize form field names
         $form = array('contact_name' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_subject' => '', 'contact_message' => '', 'captcha' => '');
         // Copy the form as errors, so the errors will be stored with keys
         // corresponding to the form field names
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         $form_sent = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('contact_name', 'required', 'length[3,100]');
             $post->add_rules('contact_email', 'required', 'email', 'length[4,100]');
             $post->add_rules('contact_subject', 'required', 'length[3,100]');
             $post->add_rules('contact_message', 'required');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 $form_sent = $this->_send_application($post, $person->person_email, $id);
             } else {
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('contact'));
                 $form_error = TRUE;
             }
         }
     }
     $this->template->content->job_title = $job->incident_title;
     $this->template->content->job_description = nl2br($job->incident_description);
     $this->template->content->job_id = $id;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_sent = $form_sent;
     $this->template->content->previous_page = url::base() . "reports/view/{$id}";
     $this->template->content->captcha = $captcha;
 }
Пример #12
0
 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = false)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports_view');
     if (!$id) {
         url::redirect('main');
     } else {
         $incident = ORM::factory('incident', $id);
         if ($incident->id == 0) {
             url::redirect('main');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('comment_author', 'required', 'length[3,100]');
             $post->add_rules('comment_description', 'required');
             $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 $comment = new Comment_Model();
                 $comment->incident_id = $id;
                 $comment->comment_author = $post->comment_author;
                 $comment->comment_description = $post->comment_description;
                 $comment->comment_email = $post->comment_email;
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 $comment->comment_active = 1;
                 $comment->save();
                 // Redirect
                 url::redirect('reports/view/' . $id);
             } else {
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('comments'));
                 $form_error = TRUE;
             }
         }
         $this->template->content->incident_id = $incident->id;
         $this->template->content->incident_title = $incident->incident_title;
         $this->template->content->incident_description = nl2br($incident->incident_description);
         $this->template->content->incident_location = $incident->location->location_name;
         $this->template->content->incident_latitude = $incident->location->latitude;
         $this->template->content->incident_longitude = $incident->location->longitude;
         $this->template->content->incident_date = date('M j Y', strtotime($incident->incident_date));
         $this->template->content->incident_time = date('H:i', strtotime($incident->incident_date));
         $this->template->content->incident_category = $incident->incident_category;
         if ($incident->incident_rating == '') {
             $this->template->content->incident_rating = 0;
         } else {
             $this->template->content->incident_rating = $incident->incident_rating;
         }
         // Retrieve Media
         $incident_news = array();
         $incident_video = array();
         $incident_photo = array();
         foreach ($incident->media as $media) {
             if ($media->media_type == 4) {
                 $incident_news[] = $media->media_link;
             } elseif ($media->media_type == 2) {
                 $incident_video[] = $media->media_link;
             } elseif ($media->media_type == 1) {
                 $incident_photo[] = $media->media_link;
             }
         }
         $this->template->content->incident_verified = $incident->incident_verified;
         // Retrieve Comments (Additional Information)
         $incident_comments = array();
         if ($id) {
             $incident_comments = ORM::factory('comment')->where('incident_id', $id)->where('comment_active', '1')->orderby('comment_date', 'asc')->find_all();
         }
         $this->template->content->incident_comments = $incident_comments;
     }
     // Add Neighbors
     $this->template->content->incident_neighbors = $this->_get_neighbors($incident->location->latitude, $incident->location->longitude);
     // Get RSS News Feeds
     $this->template->content->feeds = ORM::factory('feed_item')->limit('5')->orderby('item_date', 'desc')->find_all();
     // Video links
     $this->template->content->incident_videos = $incident_video;
     // Create object of the video embed class
     $video_embed = new VideoEmbed();
     $this->template->content->videos_embed = $video_embed;
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->photoslider_enabled = TRUE;
     $this->template->header->videoslider_enabled = TRUE;
     $this->template->header->js = new View('reports_view_js');
     $this->template->header->js->incident_id = $incident->id;
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->template->header->js->latitude = $incident->location->latitude;
     $this->template->header->js->longitude = $incident->location->longitude;
     $this->template->header->js->incident_photos = $incident_photo;
     // Pack the javascript using the javascriptpacker helper
     $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false);
     $this->template->header->js = $myPacker->pack();
     // Forms
     $this->template->content->form = $form;
     $this->template->content->captcha = $captcha;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
 }
Пример #13
0
 private function _get_job_app_form()
 {
     $form = array('captcha' => '', 'contact_name' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_subject' => '', 'contact_message' => '', 'comment' => 'Submit', 'apply' => 'Apply');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     $captcha = Captcha::factory();
     //  copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     //has form been submitted, if so setup validation
     if ($_POST) {
         $post = Validation::factory($_POST);
         //Trim whitespaces
         $post->pre_filter('trim', TRUE);
         //Add validation rules
         $post->add_rules('contact_name', 'required', 'length[3,100]');
         $post->add_rules('contact_email', 'required', 'email', 'length[4,100]');
         $post->add_rules('contact_subject', 'required', 'length[3,100]');
         $post->add_rules('contact_message', 'required');
         $post->add_rules('captcha', 'required', 'Captcha::valid');
         if ($post->validate()) {
             if ($api_akismet != "") {
                 // Run Akismet Spam Checker
                 $akismet = new Akismet();
                 // comment data
                 $jobapply = array('contact_name' => $post->contact_name, 'contact_email' => $post->contact_email, 'contact_subject' => $post->contact_subject, 'contact_message' => $post->contact_message);
                 $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'jobapply' => $jobapply);
                 $akismet->init($config);
                 if ($akismet->errors_exist()) {
                     if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                         // throw new Kohana_Exception('akismet.api_key');
                     } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                         // throw new Kohana_Exception('akismet.server_failed');
                     } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                         // throw new Kohana_Exception('akismet.server_not_found');
                     }
                     // If the server is down, we have to post
                     // the comment :(
                     // $this->_post_comment($comment);
                     $jobapply_spam = 0;
                 } else {
                     if ($akismet->is_spam()) {
                         $jobapply_spam = 1;
                     } else {
                         $jobapply_spam = 0;
                     }
                 }
             } else {
                 // No API Key!!
                 $feedback_spam = 0;
             }
             $this->_dump_feedback($post);
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('feedback'));
             $form_error = TRUE;
         }
     }
     $this->template->footer->js = new View('footer_form_js');
     $this->template->footer->form = $form;
     $this->template->footer->captcha = $captcha;
     $this->template->footer->errors = $errors;
     $this->template->footer->form_error = $form_error;
 }
Пример #14
0
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        $p_context->default_url->reset_parameter('f_'.$this->m_name);
        $p_context->url->reset_parameter('f_'.$this->m_name);

        if (PEAR::isError($this->m_error)) {
            return false;
        }

        $metaUser = $p_context->user;
        if (!$metaUser->defined) {
            $this->m_properties['type'] = 'add';
            if (!MetaAction::ValidateInput($this->m_properties, 'name', 1,
            $this->m_error, 'The user name was not filled in.', ACTION_EDIT_USER_ERR_NO_NAME)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'uname', 1,
            $this->m_error, 'The user login name was not filled in.',
            ACTION_EDIT_USER_ERR_NO_USER_NAME)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'password', 6,
            $this->m_error, 'The user password was not filled in or was too short.',
            ACTION_EDIT_USER_ERR_NO_PASSWORD)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'passwordagain', 6,
            $this->m_error, 'The password confirmation was not filled in or was too short.',
            ACTION_EDIT_USER_ERR_NO_PASSWORD_CONFIRMATION)) {
                return false;
            }
            if (!MetaAction::ValidateInput($this->m_properties, 'email', 8,
            $this->m_error, 'The user email was not filled in or was invalid.',
            ACTION_EDIT_USER_ERR_NO_EMAIL)) {
                return false;
            }

            if (SystemPref::Get('PLUGIN_RECAPTCHA_SUBSCRIPTIONS_ENABLED') == 'Y') {
                $captcha = Captcha::factory('ReCAPTCHA');
                if (!$captcha->validate()) {
                    $this->m_error = new PEAR_Error('The code you entered is not the same as the one shown.',
                        ACTION_SUBMIT_COMMENT_ERR_INVALID_CAPTCHA_CODE);
                    return false;
                }
            }
        } else {
            $this->m_properties['type'] = 'edit';
            if (isset($this->m_properties['password'])) {
                if (!MetaAction::ValidateInput($this->m_properties, 'password', 6,
                $this->m_error, 'The user password was not filled in or was too short.',
                ACTION_EDIT_USER_ERR_NO_PASSWORD)) {
                    return false;
                }
                if (!MetaAction::ValidateInput($this->m_properties, 'passwordagain', 6,
                $this->m_error, 'The password confirmation was not filled in or was too short.',
                ACTION_EDIT_USER_ERR_NO_PASSWORD_CONFIRMATION)) {
                    return false;
                }
            }
        }

        if (isset($this->m_properties['password'])
        && $this->m_properties['password'] != $this->m_properties['passwordagain']) {
            $this->m_error = new PEAR_Error("The password and password confirmation do not match.",
            ACTION_EDIT_USER_ERR_PASSWORD_MISMATCH);
            return false;
        }

        if (!$metaUser->defined) {
            if (User::UserNameExists($this->m_properties['uname'])
            || Phorum_user::UserNameExists($this->m_properties['uname'])) {
                $this->m_error = new PEAR_Error("The login name already exists, please choose a different one.",
                ACTION_EDIT_USER_ERR_DUPLICATE_USER_NAME);
                return false;
            }
            if (User::EmailExists($this->m_properties['email'])) {
                $this->m_error = new PEAR_Error("Another user is registered with this e-mail address, please choose a different one.",
                ACTION_EDIT_USER_ERR_DUPLICATE_EMAIL);
                return false;
            }
            $user = new User();
            $phorumUser = new Phorum_user();
            if (!$user->create($this->m_data)
            || !$phorumUser->create($this->m_properties['uname'], $this->m_properties['password'], $this->m_properties['email'], $user->getUserId())) {
                $user->delete();
                $phorumUser->delete();
                $this->m_error = new PEAR_Error("There was an internal error creating the account (code 1).",
                ACTION_EDIT_USER_ERR_INTERNAL);
                return false;
            }
            setcookie("LoginUserId", $user->getUserId(), null, '/');
            $user->initLoginKey();
            setcookie("LoginUserKey", $user->getKeyId(), null, '/');
            $p_context->user = new MetaUser($user->getUserId());
        } else {
            $user = new User($metaUser->identifier);
            if (!$user->exists()) {
                $this->m_error = new PEAR_Error("There was an internal error updating the account (code 2).",
                ACTION_EDIT_USER_ERR_INTERNAL);
                return false;
            }
            $phorumUser = Phorum_user::GetByUserName($user->getUserName());
            if (is_null($phorumUser)) {
                $phorumUser = new Phorum_user();
                if (!$phorumUser->create($user->getUserName(), $user->getPassword(), $user->getEmail(), $user->getUserId(), true)) {
                    $this->m_error = new PEAR_Error("There was an internal error updating the account (code 3).",
                    ACTION_EDIT_USER_ERR_INTERNAL);
                    return false;
                }
            }
            foreach ($this->m_properties as $property=>$value) {
                if (!isset(MetaActionEdit_User::$m_fields[$property]['db_field'])) {
                    continue;
                }
                $dbProperty = MetaActionEdit_User::$m_fields[$property]['db_field'];
                if ($property != 'password' && $property != 'passwordagain') {
                    $user->setProperty($dbProperty, $value, false);
                    if ($property == 'email') {
                        $phorumUser->setProperty('email', $value, false);
                    }
                } elseif ($property == 'password') {
                    $user->setPassword($this->m_properties['password'], false);
                    $phorumUser->setPassword($this->m_properties['password'], false);
                }
            }
            if (!$user->commit() || !$phorumUser->commit()) {
                $this->m_error = new PEAR_Error("There was an internal error updating the account (code 4).",
                ACTION_EDIT_USER_ERR_INTERNAL);
                return false;
            }
        }

        foreach ($this->m_properties as $property=>$value) {
            $p_context->default_url->reset_parameter('f_user_'.$property);
            $p_context->url->reset_parameter('f_user_'.$property);
        }

        $this->m_error = ACTION_OK;
        return true;
    }
Пример #15
0
 public function __call($method, $args)
 {
     // Output the Captcha challenge resource (no html)
     // Pull the config group name from the URL
     Captcha::factory($this->uri->segment(2))->render(FALSE);
 }
Пример #16
0
 /**
  * Submit comments
  *
  * @return int
  */
 private function _add_comment()
 {
     $api_akismet = Kohana::config('settings.api_akismet');
     // Comment Post?
     // Setup and initialize form field names
     $form = array('incident_id' => '', 'comment_author' => '', 'comment_description' => '', 'comment_email' => '');
     $captcha = Captcha::factory();
     $errors = $form;
     $form_error = FALSE;
     $ret_value = 0;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST and Kohana::config('settings.allow_comments')) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('incident_id', 'required');
         $post->add_rules('comment_author', 'required', 'length[3,100]');
         $post->add_rules('comment_description', 'required');
         $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             $incident = ORM::factory('incident')->where('id', $post->incident_id)->where('incident_active', 1)->find();
             if ($incident->id == 0) {
                 return $this->response(1, "No incidents with that ID");
             }
             if ($api_akismet != "") {
                 // Run Akismet Spam Checker
                 $akismet = new Akismet();
                 // Comment data
                 $comment = array('author' => $post->comment_author, 'email' => $post->comment_email, 'website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                 $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                 $akismet->init($config);
                 if ($akismet->errors_exist()) {
                     if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                         // throw new Kohana_Exception('akismet.api_key');
                     } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                         // throw new Kohana_Exception('akismet.server_failed');
                     } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                         // throw new Kohana_Exception('akismet.server_not_found');
                     }
                     // If the server is down, we have to post
                     // the comment :(
                     // $this->_post_comment($comment);
                     $comment_spam = 0;
                 } else {
                     if ($akismet->is_spam()) {
                         $comment_spam = 1;
                     } else {
                         $comment_spam = 0;
                     }
                 }
             } else {
                 // No API Key!!
                 $comment_spam = 0;
             }
             $comment = new Comment_Model();
             $comment->incident_id = strip_tags($post->incident_id);
             $comment->comment_author = strip_tags($post->comment_author);
             $comment->comment_description = strip_tags($post->comment_description);
             $comment->comment_email = strip_tags($post->comment_email);
             $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
             $comment->comment_date = date("Y-m-d H:i:s", time());
             // Activate comment for now
             if ($comment_spam == 1) {
                 $comment->comment_spam = 1;
                 $comment->comment_active = 0;
             } else {
                 $comment->comment_spam = 0;
                 if (Kohana::config('settings.allow_comments') == 1) {
                     // Auto Approve
                     $comment->comment_active = 1;
                 } else {
                     // Manually Approve
                     $comment->comment_active = 0;
                 }
             }
             $comment->save();
             // Notify Admin Of New Comment
             $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/view/' . $post->incident_id);
         } else {
             // No! We have validation errors, we need to show the form again, with the errors
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // Populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('comments'));
             foreach ($errors as $error_item => $error_description) {
                 if (!is_array($error_description)) {
                     $this->error_messages .= $error_description;
                     if ($error_description != end($errors)) {
                         $this->error_messages .= " - ";
                     }
                 }
             }
             $ret_value = 1;
             // Validation error
         }
     } else {
         $ret_value = 3;
     }
     return $this->response($ret_value, $this->error_messages);
 }
Пример #17
0
 public function contact()
 {
     $this->template->header->this_body = 'crowdmap-contact';
     $this->template->content = new View('mhi/mhi_contact');
     $form = array('contact_email' => '', 'contact_subject' => '', 'contact_message' => '', 'contact_captcha' => '');
     $errors = $form;
     $success_message = '';
     $form_error = FALSE;
     $captcha = Captcha::factory();
     if ($_POST) {
         $post = Validation::factory($_POST)->pre_filter('trim')->add_rules('contact_email', 'required', array('valid', 'email'))->add_rules('contact_subject', 'required')->add_rules('contact_message', 'required')->add_rules('contact_captcha', 'required', 'Captcha::valid');
         if ($post->validate()) {
             email::send(Kohana::config('settings.site_email'), $post->contact_email, $post->contact_subject, $post->contact_message, FALSE);
             $success_message = 'Email sent. We will get back to you as quickly as we can. Thank you!';
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors('mhi'));
             $form_error = TRUE;
         }
     }
     $this->template->content->form = $form;
     $this->template->content->form_error = $form_error;
     $this->template->content->errors = $errors;
     $this->template->content->success_message = $success_message;
     $this->template->content->captcha = $captcha;
 }
Пример #18
0
 /**
  * Displays a report.
  * @param boolean $id If id is supplied, a report with that id will be
  * retrieved.
  */
 public function view($id = false)
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports_view');
     // Load Akismet API Key (Spam Blocker)
     $api_akismet = Kohana::config('settings.api_akismet');
     if (!$id) {
         url::redirect('main');
     } else {
         $incident = ORM::factory('incident', $id);
         if ($incident->id == 0) {
             url::redirect('main');
         }
         // Comment Post?
         // Setup and initialize form field names
         $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => '');
         $captcha = Captcha::factory();
         $errors = $form;
         $form_error = FALSE;
         // Check, has the form been submitted, if so, setup validation
         if ($_POST) {
             // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
             $post = Validation::factory($_POST);
             // Add some filters
             $post->pre_filter('trim', TRUE);
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('comment_author', 'required', 'length[3,100]');
             $post->add_rules('comment_description', 'required');
             $post->add_rules('comment_email', 'required', 'email', 'length[4,100]');
             $post->add_rules('captcha', 'required', 'Captcha::valid');
             // Test to see if things passed the rule checks
             if ($post->validate()) {
                 // Yes! everything is valid
                 if ($api_akismet != "") {
                     // Run Akismet Spam Checker
                     $akismet = new Akismet();
                     // comment data
                     $comment = array('author' => $post->comment_author, 'email' => $post->comment_email, 'website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']);
                     $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment);
                     $akismet->init($config);
                     if ($akismet->errors_exist()) {
                         if ($akismet->is_error('AKISMET_INVALID_KEY')) {
                             // throw new Kohana_Exception('akismet.api_key');
                         } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) {
                             // throw new Kohana_Exception('akismet.server_failed');
                         } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) {
                             // throw new Kohana_Exception('akismet.server_not_found');
                         }
                         // If the server is down, we have to post
                         // the comment :(
                         // $this->_post_comment($comment);
                         $comment_spam = 0;
                     } else {
                         if ($akismet->is_spam()) {
                             $comment_spam = 1;
                         } else {
                             $comment_spam = 0;
                         }
                     }
                 } else {
                     // No API Key!!
                     $comment_spam = 0;
                 }
                 $comment = new Comment_Model();
                 $comment->incident_id = $id;
                 $comment->comment_author = strip_tags($post->comment_author);
                 $comment->comment_description = strip_tags($post->comment_description);
                 $comment->comment_email = strip_tags($post->comment_email);
                 $comment->comment_ip = $_SERVER['REMOTE_ADDR'];
                 $comment->comment_date = date("Y-m-d H:i:s", time());
                 // Activate comment for now
                 if ($comment_spam == 1) {
                     $comment->comment_spam = 1;
                     $comment->comment_active = 0;
                 } else {
                     $comment->comment_spam = 0;
                     $comment->comment_active = 1;
                 }
                 $comment->save();
                 // Notify Admin Of New Comment
                 $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/view/' . $id);
                 // Redirect
                 url::redirect('reports/view/' . $id);
             } else {
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, $post->errors('comments'));
                 $form_error = TRUE;
             }
         }
         $this->template->content->incident_id = $incident->id;
         $this->template->content->incident_title = $incident->incident_title;
         $this->template->content->incident_description = nl2br($incident->incident_description);
         $this->template->content->incident_location = $incident->location->location_name;
         $this->template->content->incident_latitude = $incident->location->latitude;
         $this->template->content->incident_longitude = $incident->location->longitude;
         $this->template->content->incident_date = date('M j Y', strtotime($incident->incident_date));
         $this->template->content->incident_time = date('H:i', strtotime($incident->incident_date));
         $this->template->content->incident_category = $incident->incident_category;
         if ($incident->incident_rating == '') {
             $this->template->content->incident_rating = 0;
         } else {
             $this->template->content->incident_rating = $incident->incident_rating;
         }
         // Retrieve Media
         $incident_news = array();
         $incident_video = array();
         $incident_photo = array();
         foreach ($incident->media as $media) {
             if ($media->media_type == 4) {
                 $incident_news[] = $media->media_link;
             } elseif ($media->media_type == 2) {
                 $incident_video[] = $media->media_link;
             } elseif ($media->media_type == 1) {
                 $incident_photo[] = $media->media_link;
             }
         }
         $this->template->content->incident_verified = $incident->incident_verified;
         // Retrieve Comments (Additional Information)
         $incident_comments = array();
         if ($id) {
             $incident_comments = ORM::factory('comment')->where('incident_id', $id)->where('comment_active', '1')->where('comment_spam', '0')->orderby('comment_date', 'asc')->find_all();
         }
         $this->template->content->incident_comments = $incident_comments;
     }
     // Add Neighbors
     $this->template->content->incident_neighbors = $this->_get_neighbors($incident->location->latitude, $incident->location->longitude);
     // Get RSS News Feeds
     $this->template->content->feeds = ORM::factory('feed_item')->limit('5')->orderby('item_date', 'desc')->find_all();
     // Video links
     $this->template->content->incident_videos = $incident_video;
     //images
     $this->template->content->incident_photos = $incident_photo;
     // Create object of the video embed class
     $video_embed = new VideoEmbed();
     $this->template->content->videos_embed = $video_embed;
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->photoslider_enabled = TRUE;
     $this->template->header->videoslider_enabled = TRUE;
     $this->template->header->js = new View('reports_view_js');
     $this->template->header->js->incident_id = $incident->id;
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->template->header->js->latitude = $incident->location->latitude;
     $this->template->header->js->longitude = $incident->location->longitude;
     $this->template->header->js->incident_photos = $incident_photo;
     // Pack the javascript using the javascriptpacker helper
     $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false);
     $this->template->header->js = $myPacker->pack();
     // initialize custom field array
     $form_field_names = $this->_get_custom_form_fields($id, $incident->form_id, false);
     // Retrieve Custom Form Fields Structure
     $disp_custom_fields = $this->_get_custom_form_fields($id, $incident->form_id, true);
     $this->template->content->disp_custom_fields = $disp_custom_fields;
     // Forms
     $this->template->content->form = $form;
     $this->template->content->form_field_names = $form_field_names;
     $this->template->content->captcha = $captcha;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     // If the Admin is Logged in - Allow for an edit link
     $this->template->content->logged_in = $this->logged_in;
 }
Пример #19
0
 public function index()
 {
     // If contact page disabled, or site_email not set then return 404
     if (!Kohana::config('settings.site_contact_page') or Kohana::config('settings.site_email') == "") {
         throw new Kohana_404_Exception();
     }
     $this->template->header->this_page = 'contact';
     $this->template->content = new View('contact');
     $this->template->header->page_title .= Kohana::lang('ui_main.contact') . Kohana::config('settings.title_delimiter');
     // Setup and initialize form field names
     $form = array('contact_name' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_subject' => '', 'contact_message' => '', 'captcha' => '');
     // Copy the form as errors, so the errors will be stored with keys
     // corresponding to the form field names
     $captcha = Captcha::factory();
     $errors = $form;
     $form_error = FALSE;
     $form_sent = FALSE;
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('contact_name', 'required', 'length[3,100]');
         $post->add_rules('contact_email', 'required', 'email', 'length[4,100]');
         $post->add_rules('contact_subject', 'required', 'length[3,100]');
         $post->add_rules('contact_message', 'required');
         $post->add_rules('captcha', 'required', 'Captcha::valid');
         // Test to see if things passed the rule checks
         // Skip CSRF check since we have a CAPTCHA already
         if ($post->validate(FALSE)) {
             // Yes! everything is valid - Send email
             $site_email = Kohana::config('settings.site_email');
             $message = Kohana::lang('ui_admin.sender') . ": " . $post->contact_name . "\n";
             $message .= Kohana::lang('ui_admin.email') . ": " . $post->contact_email . "\n";
             $message .= Kohana::lang('ui_admin.phone') . ": " . $post->contact_phone . "\n\n";
             $message .= Kohana::lang('ui_admin.message') . ": \n" . $post->contact_message . "\n\n\n";
             $message .= "~~~~~~~~~~~~~~~~~~~~~~\n";
             $message .= Kohana::lang('ui_admin.sent_from_website') . url::base();
             // Send Admin Message
             try {
                 email::send($site_email, $post->contact_email, $post->contact_subject, $message, FALSE);
                 $form_sent = TRUE;
             } catch (Exception $e) {
                 // repopulate the form fields
                 $form = arr::overwrite($form, $post->as_array());
                 // Manually add an error message for the email send failure.
                 $errors['email_send'] = Kohana::lang('contact.email_send.failed');
                 // populate the error fields, if any
                 $errors = arr::merge($errors, $post->errors('contact'));
                 $form_error = TRUE;
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::merge($errors, $post->errors('contact'));
             $form_error = TRUE;
         }
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_sent = $form_sent;
     $this->template->content->captcha = $captcha;
 }