protected function _rate() { if (!is_numeric($this->input->post('id'))) { View::global_error('Invalid Quote ID'); } if ($this->input->post('rating') == '') { View::global_error('Invalid Rating'); } if (View::errors_set()) { return; } $quote = ORM::factory('quote', $_POST['id']); if ($quote->id == 0) { return View::global_error('Missing Quote'); } $rating = ORM::factory('quote_rating')->where(array('quote_id' => $quote->id, 'ip' => $this->input->ip_address()))->find(); $rating->quote_id = $quote->id; $rating->ip = $this->input->ip_address(); switch ($_POST['rating']) { case '+': $rating->rating = +1; break; case '-': $rating->rating = -1; break; } $rating->save(); $quote->recalculate(); }
protected function _image_upload($gallery) { if (request::is_ajax()) { $this->_use_json_errors(); } if ($gallery->id == 0) { return View::global_error('Invalid Gallery id'); } if (isset($_POST['username']) && isset($_POST['password'])) { Auth::instance()->login($_POST['username'], $_POST['password']); } if (!Auth::instance()->logged_in('login')) { return View::global_error('Image upload requires login'); } if ($gallery->user_id != 0 && $gallery->user_id != Auth::instance()->get_user()->id) { return View::global_error('User not gallery owner'); } if (empty($_FILES['file'])) { return View::global_error('Error with upload'); } if ($this->input->post('name') == '') { View::global_error('Missing Image Name'); } if ($_FILES['file']['name'] == '') { View::global_error('Missing File'); } if (View::errors_set()) { return; } $image = ORM::factory('image'); $image->gallery_id = $gallery->id; $image->name = $this->input->post('name'); $image->mime = file::mime($_FILES['file']['tmp_name']); $image->description = $_FILES['file']['name']; $image->size = $_FILES['file']['size']; $image->uploaded_on = time(); $image->uploaded_by = Auth::instance()->get_user()->id; if (!$image->validate()) { return View::global_error('Error validating Image'); } if (!$image->move_uploaded_file($_FILES['file']['tmp_name'])) { return View::global_error('Error moving Image'); } if (!$image->save()) { return View::global_error('Error saving Image'); } if (!$image->generate_thumb()) { return View::global_error('Error generating thumb'); } $_POST = array(); if (request::is_ajax()) { die(json_encode(array('result' => 'OK', 'id' => $image->id, 'name' => $image->name, 'url' => $image->generate_url()))); } }