2009-06-22 06:03:55 -07:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
2009-06-21 08:52:26 -07:00
|
|
|
* Gallery - a web based photo album viewer and editor
|
2010-03-03 10:15:34 -08:00
|
|
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
2009-06-21 08:52:26 -07:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
class Digibug_Controller extends Controller {
|
2010-12-23 23:34:04 -08:00
|
|
|
const ALLOW_PRIVATE_GALLERY = true;
|
|
|
|
|
|
2009-06-22 21:51:22 -07:00
|
|
|
public function print_photo($id) {
|
2009-06-21 08:52:26 -07:00
|
|
|
access::verify_csrf();
|
2009-06-22 21:51:22 -07:00
|
|
|
$item = ORM::factory("item", $id);
|
2009-07-23 07:02:10 -07:00
|
|
|
access::required("view", $item);
|
2009-06-27 15:55:47 -07:00
|
|
|
|
2009-10-22 13:09:20 -07:00
|
|
|
if (access::group_can(identity::everybody(), "view_full", $item)) {
|
2009-06-27 15:55:47 -07:00
|
|
|
$full_url = $item->file_url(true);
|
|
|
|
|
$thumb_url = $item->thumb_url(true);
|
|
|
|
|
} else {
|
|
|
|
|
$proxy = ORM::factory("digibug_proxy");
|
2010-12-15 14:57:00 -08:00
|
|
|
$proxy->uuid = random::hash();
|
2009-06-27 15:55:47 -07:00
|
|
|
$proxy->item_id = $item->id;
|
|
|
|
|
$proxy->save();
|
|
|
|
|
$full_url = url::abs_site("digibug/print_proxy/full/$proxy->uuid");
|
|
|
|
|
$thumb_url = url::abs_site("digibug/print_proxy/thumb/$proxy->uuid");
|
|
|
|
|
}
|
2009-06-25 21:41:54 -07:00
|
|
|
|
2009-06-23 22:13:28 -07:00
|
|
|
$v = new View("digibug_form.html");
|
2010-01-30 16:05:20 -08:00
|
|
|
$v->order_params = array(
|
2009-06-22 21:51:22 -07:00
|
|
|
"digibug_api_version" => "100",
|
2009-06-27 15:55:47 -07:00
|
|
|
"company_id" => module::get_var("digibug", "company_id"),
|
|
|
|
|
"event_id" => module::get_var("digibug", "event_id"),
|
2009-06-24 13:11:53 -07:00
|
|
|
"cmd" => "addimg",
|
2009-07-01 18:01:15 -07:00
|
|
|
"partner_code" => "69",
|
2009-06-23 22:13:28 -07:00
|
|
|
"return_url" => url::abs_site("digibug/close_window"),
|
2009-06-22 21:51:22 -07:00
|
|
|
"num_images" => "1",
|
2009-06-27 15:55:47 -07:00
|
|
|
"image_1" => $full_url,
|
|
|
|
|
"thumb_1" => $thumb_url,
|
2009-06-22 21:51:22 -07:00
|
|
|
"image_height_1" => $item->height,
|
|
|
|
|
"image_width_1" => $item->width,
|
|
|
|
|
"thumb_height_1" => $item->thumb_height,
|
|
|
|
|
"thumb_width_1" => $item->thumb_width,
|
2009-08-29 22:54:20 -07:00
|
|
|
"title_1" => html::purify($item->title));
|
2009-06-22 21:51:22 -07:00
|
|
|
|
2009-06-23 22:13:28 -07:00
|
|
|
print $v;
|
2009-06-21 08:52:26 -07:00
|
|
|
}
|
2009-06-22 06:03:55 -07:00
|
|
|
|
2009-12-21 16:40:18 -08:00
|
|
|
public function print_proxy($type, $uuid) {
|
2009-07-23 07:02:10 -07:00
|
|
|
// If its a request for the full size then make sure we are coming from an
|
|
|
|
|
// authorized address
|
|
|
|
|
if ($type == "full") {
|
2009-12-21 21:27:43 -08:00
|
|
|
$remote_addr = ip2long(Input::instance()->server("REMOTE_ADDR"));
|
2009-07-23 07:02:10 -07:00
|
|
|
if ($remote_addr === false) {
|
2009-11-25 13:49:40 -08:00
|
|
|
throw new Kohana_404_Exception();
|
2009-07-23 07:02:10 -07:00
|
|
|
}
|
|
|
|
|
$config = Kohana::config("digibug");
|
|
|
|
|
|
|
|
|
|
$authorized = false;
|
|
|
|
|
foreach ($config["ranges"] as $ip_range) {
|
|
|
|
|
$low = ip2long($ip_range["low"]);
|
|
|
|
|
$high = ip2long($ip_range["high"]);
|
|
|
|
|
$authorized = $low !== false && $high !== false &&
|
|
|
|
|
$low <= $remote_addr && $remote_addr <= $high;
|
|
|
|
|
if ($authorized) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!$authorized) {
|
2009-11-25 13:49:40 -08:00
|
|
|
throw new Kohana_404_Exception();
|
2009-07-23 07:02:10 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-21 16:40:18 -08:00
|
|
|
$proxy = ORM::factory("digibug_proxy")->where("uuid", "=", $uuid)->find();
|
2009-11-25 13:22:24 -08:00
|
|
|
if (!$proxy->loaded() || !$proxy->item->loaded()) {
|
2009-11-25 13:49:40 -08:00
|
|
|
throw new Kohana_404_Exception();
|
2009-06-23 06:06:33 -07:00
|
|
|
}
|
|
|
|
|
|
2009-06-27 15:55:47 -07:00
|
|
|
$file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path();
|
2009-06-23 06:06:33 -07:00
|
|
|
if (!file_exists($file)) {
|
2009-12-23 20:51:33 -08:00
|
|
|
throw new Kohana_404_Exception();
|
2009-06-23 06:06:33 -07:00
|
|
|
}
|
2009-06-22 21:51:22 -07:00
|
|
|
|
|
|
|
|
// We don't need to save the session for this request
|
2010-01-31 16:07:41 -08:00
|
|
|
Session::instance()->abort_save();
|
2009-06-21 08:52:26 -07:00
|
|
|
|
2009-07-23 07:02:10 -07:00
|
|
|
if (!TEST_MODE) {
|
|
|
|
|
// Dump out the image
|
2010-10-01 21:17:08 -07:00
|
|
|
header("Content-Type: {$proxy->item->mime_type}");
|
2009-07-23 07:02:10 -07:00
|
|
|
Kohana::close_buffers(false);
|
|
|
|
|
$fd = fopen($file, "rb");
|
|
|
|
|
fpassthru($fd);
|
|
|
|
|
fclose($fd);
|
2009-06-23 06:06:33 -07:00
|
|
|
}
|
2009-06-27 15:55:47 -07:00
|
|
|
|
|
|
|
|
$this->_clean_expired();
|
2009-06-21 08:52:26 -07:00
|
|
|
}
|
2009-06-22 21:51:22 -07:00
|
|
|
|
2009-06-23 22:13:28 -07:00
|
|
|
public function close_window() {
|
|
|
|
|
print "<script type=\"text/javascript\">window.close();</script>";
|
|
|
|
|
}
|
2009-06-25 19:58:14 -07:00
|
|
|
|
|
|
|
|
private function _clean_expired() {
|
2009-12-13 17:03:07 -08:00
|
|
|
db::build()
|
|
|
|
|
->delete("digibug_proxies")
|
2010-12-28 23:10:05 -08:00
|
|
|
->where("request_date", "<=", db::expr("(CURDATE() - INTERVAL 10 DAY)"))
|
2009-12-13 17:03:07 -08:00
|
|
|
->limit(20)
|
|
|
|
|
->execute();
|
2009-06-25 19:58:14 -07:00
|
|
|
}
|
2009-06-21 08:52:26 -07:00
|
|
|
}
|