/** * get the data about the image * * @param integer $image (optional - if not passed, used uri segment 3) * @return object * @author Andy Bennett */ protected function get_image_row($image = false) { // use URI segment 3 if no id is passed if (!$image) { $image = end(URI::instance()->segment_array()); } // strip any file extensions (actually strip anything that isn't a number) $image = pathinfo(Kohana::instance()->uri->string(), PATHINFO_FILENAME); // make sure the id is numeric - if not exit if (!preg_match('/[0-9]+/i', $image)) { exit; } // get the ORM object $row = ORM::factory($this->setup['model'] . '_upload', $image); // make sure the object has been loaded properly and the parent model matches if (!$row->loaded) { Kohana::log('error', 'File model row error: ' . $image); throw new Kohana_404_Exception($image, 'common/error_404'); } if ($row->parent_model != $this->setup['model']) { Kohana::log('error', 'File model error: ' . $row->id); throw new Kohana_403_Exception($row->id, 'common/error_403'); } // make sure the object's status is true if (!$row->parent->status and !User::instance()->is_moderator()) { Kohana::log('error', 'File status: ' . $row->id); throw new Kohana_403_Exception($row->id, 'common/error_403'); } // $data = array( 'action' => URI::instance()->segment(2), 'name' => $this->setup['name'], 'role' => User::instance()->get_role() ); // Event::run( 'acl.check', $data ); $row->full_path = Kohana::config('upload.directory') . '/' . $row->file_name; if (!file_exists($row->full_path)) { $this->delete_fullpath = $row->full_path; file_put_contents($row->full_path, filestore::get($row->file_name)); } else { if (!file_exists($row->full_path) and isset($row->file_data) and !empty($row->file_data)) { file_put_contents($row->full_path, $row->file_data); } } if (!file_exists($row->full_path)) { Kohana::log('error', 'Invalid file path: ' . $row->full_path); throw new Kohana_404_Exception($row->orig_name, 'common/error_404'); } return $row; }