1
0

Digibug went away, move the module out of the main repo into contrib.

This commit is contained in:
Bharat Mediratta 2013-02-15 12:58:50 -05:00
parent 20acc71371
commit 81fbbd3da1
13 changed files with 483 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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.
*/
/**
* PHP Mail Configuration parameters
* from => email address that appears as the from address
* line-length => word wrap length (PHP documentations suggest no larger tha 70 characters
* reply-to => what goes into the reply to header
*/
$config["ranges"] = array(
"Digibug1" => array("low" => "65.249.152.0", "high" => "65.249.159.255"),
"Digibug2" => array("low" => "208.122.55.0", "high" => "208.122.55.255")
);

View File

@ -0,0 +1,27 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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 Admin_Digibug_Controller extends Admin_Controller {
public function index() {
$v = new Admin_View("admin.html");
$v->page_title = t("Digibug");
$v->content = new View("admin_digibug.html");
print $v;
}
}

View File

@ -0,0 +1,121 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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 {
const ALLOW_PRIVATE_GALLERY = true;
public function print_photo($id) {
access::verify_csrf();
$item = ORM::factory("item", $id);
access::required("view", $item);
if (access::group_can(identity::everybody(), "view_full", $item)) {
$full_url = $item->file_url(true);
$thumb_url = $item->thumb_url(true);
} else {
$proxy = ORM::factory("digibug_proxy");
$proxy->uuid = random::hash();
$proxy->item_id = $item->id;
$proxy->save();
$full_url = url::abs_site("digibug/print_proxy/full/$proxy->uuid/$item->id");
$thumb_url = url::abs_site("digibug/print_proxy/thumb/$proxy->uuid/$item->id");
}
$v = new View("digibug_form.html");
$v->order_params = array(
"digibug_api_version" => "100",
"company_id" => module::get_var("digibug", "company_id"),
"event_id" => module::get_var("digibug", "event_id"),
"cmd" => "addimg",
"partner_code" => "69",
"return_url" => url::abs_site("digibug/close_window"),
"num_images" => "1",
"image_1" => $full_url,
"thumb_1" => $thumb_url,
"image_height_1" => $item->height,
"image_width_1" => $item->width,
"thumb_height_1" => $item->thumb_height,
"thumb_width_1" => $item->thumb_width,
"title_1" => html::purify($item->title));
print $v;
}
public function print_proxy($type, $uuid) {
// If its a request for the full size then make sure we are coming from an
// authorized address
if ($type == "full") {
$remote_addr = ip2long(Input::instance()->server("REMOTE_ADDR"));
if ($remote_addr === false) {
throw new Kohana_404_Exception();
}
$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) {
throw new Kohana_404_Exception();
}
}
$proxy = ORM::factory("digibug_proxy")->where("uuid", "=", $uuid)->find();
if (!$proxy->loaded() || !$proxy->item->loaded()) {
throw new Kohana_404_Exception();
}
$file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path();
if (!file_exists($file)) {
throw new Kohana_404_Exception();
}
// We don't need to save the session for this request
Session::instance()->abort_save();
if (!TEST_MODE) {
// Dump out the image
header("Content-Type: {$proxy->item->mime_type}");
Kohana::close_buffers(false);
$fd = fopen($file, "rb");
fpassthru($fd);
fclose($fd);
}
$this->_clean_expired();
}
public function close_window() {
print "<script type=\"text/javascript\">window.close();</script>";
}
private function _clean_expired() {
db::build()
->delete("digibug_proxies")
->where("request_date", "<=", db::expr("(CURDATE() - INTERVAL 90 DAY)"))
->limit(20)
->execute();
}
}

View File

@ -0,0 +1,52 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("digibug_menu")
->label(t("Digibug"))
->url(url::site("admin/digibug")));
}
static function site_menu($menu, $theme) {
$item = $theme->item();
if ($item && $item->type == "photo") {
$menu->get("options_menu")
->append(Menu::factory("link")
->id("digibug")
->label(t("Print with Digibug"))
->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf"))
->css_id("g-print-digibug-link")
->css_class("g-print-digibug-link ui-icon-print"));
}
}
static function context_menu($menu, $theme, $item) {
if ($item->type == "photo") {
$menu->get("options_menu")
->append(Menu::factory("link")
->id("digibug")
->label(t("Print with Digibug"))
->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf"))
->css_class("g-print-digibug-link ui-icon-print"));
}
}
}

View File

@ -0,0 +1,51 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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_installer {
static function install() {
Database::instance()
->query("CREATE TABLE {digibug_proxies} (
`id` int(9) NOT NULL AUTO_INCREMENT,
`uuid` char(32) NOT NULL,
`request_date` TIMESTAMP NOT NULL DEFAULT current_timestamp,
`item_id` int(9) NOT NULL,
PRIMARY KEY (`id`))
DEFAULT CHARSET=utf8;");
module::set_var("digibug", "company_id", "3153");
module::set_var("digibug", "event_id", "8491");
}
static function upgrade($version) {
if ($version == 1) {
module::clear_var("digibug", "default_company_id");
module::clear_var("digibug", "default_event_id");
module::clear_var("digibug", "basic_default_company_id");
module::clear_var("digibug", "basic_event_id");
module::set_var("digibug", "company_id", "3153");
module::set_var("digibug", "event_id", "8491");
module::set_version("digibug", $version = 2);
}
}
static function uninstall() {
Database::instance()->query("DROP TABLE IF EXISTS {digibug_proxies}");
module::delete("digibug");
}
}

View File

@ -0,0 +1,24 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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_theme_Core {
static function head($theme) {
return $theme->script("digibug.js");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,43 @@
$(document).ready(function() {
$(".g-print-digibug-link").click(function(e) {
e.preventDefault();
return digibug_popup(e.currentTarget.href, { width: 800, height: 600 } );
});
});
function digibug_popup(url, options) {
options = $.extend({
/* default options */
width: '800',
height: '600',
target: 'dbPopWin',
scrollbars: 'yes',
resizable: 'no',
menuBar: 'no',
addressBar: 'yes'
}, options);
// center the window by default.
if (!options.winY) {
options.winY = screen.height / 2 - options.height / 2;
};
if (!options.winX) {
options.winX = screen.width / 2 - options.width / 2;
};
open(
url,
options['target'],
'width= ' + options.width +
',height=' + options.height +
',top=' + options.winY +
',left=' + options.winX +
',scrollbars=' + options.scrollbars +
',resizable=' + options.resizable +
',menubar=' + options.menuBar +
',location=' + options.addressBar
);
return false;
}

View File

@ -0,0 +1,22 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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_Proxy_Model_Core extends ORM {
protected $belongs_to = array("item");
}

View File

@ -0,0 +1,7 @@
name = "Digibug"
description = "Digibug Photo Printing Module"
version = 2
author_name = "Gallery Team"
author_url = "http://codex.galleryproject.org/Gallery:Team"
info_url = "http://codex.galleryproject.org/Gallery3:Modules:digibug"
discuss_url = "http://galleryproject.org/forum_module_digibug"

View File

@ -0,0 +1,74 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2013 Bharat Mediratta
*
* 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_Test extends Gallery_Unit_Test_Case {
private $_server;
public function setup() {
$this->_server = $_SERVER;
}
public function teardown() {
$_SERVER = $this->_server;
}
private function _get_proxy() {
$album = test::random_album();
$photo = test::random_photo($album);
access::deny(identity::everybody(), "view_full", $album);
access::deny(identity::registered_users(), "view_full", $album);
$proxy = ORM::factory("digibug_proxy");
$proxy->uuid = random::hash();
$proxy->item_id = $photo->id;
return $proxy->save();
}
public function digibug_request_thumb_test() {
$proxy = $this->_get_proxy();
$controller = new Digibug_Controller();
$controller->print_proxy("thumb", $proxy->uuid);
}
public function digibug_request_full_malicious_ip_test() {
$_SERVER["REMOTE_ADDR"] = "123.123.123.123";
try {
$controller = new Digibug_Controller();
$controller->print_proxy("full", $this->_get_proxy()->uuid);
$this->assert_true(false, "Should have failed with an 404 exception");
} catch (Kohana_404_Exception $e) {
// expected behavior
}
}
public function digibug_request_full_authorized_ip_test() {
$config = Kohana::config("digibug");
$this->assert_true(!empty($config), "The Digibug config is empty");
$ranges = array_values($config["ranges"]);
$low = ip2long($ranges[0]["low"]);
$high = ip2long($ranges[0]["high"]);
$_SERVER["REMOTE_ADDR"] = long2ip(rand($low, $high));
$controller = new Digibug_Controller();
$controller->print_proxy("full", $this->_get_proxy()->uuid);
}
}

View File

@ -0,0 +1,20 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-block">
<img src="<?= url::file("modules/digibug/images/digibug_logo.png") ?>" alt="Digibug logo" class="g-right"/>
<h1> <?= t("Digibug photo printing") ?> </h1>
<div class="g-block-content">
<p>
<?= t("Turn your photos into a wide variety of prints, gifts and games!") ?>
</p>
<ul>
<li class="g-module-status g-success">
<?= t("You're ready to print photos!") ?>
</li>
</ul>
<p>
<?= t("You don't need an account with Digibug, but if you <a href=\"%signup_url\">register with Digibug</a> and enter your Digibug id in the <a href=\"%advanced_settings_url\">Advanced Settings</a> page you can make money off of your photos!",
array("signup_url" => "http://www.digibug.com/signup.php",
"advanced_settings_url" => html::mark_clean(url::site("admin/advanced_settings")))) ?>
</p>
</div>
</div>

View File

@ -0,0 +1,13 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<html>
<body>
<?= form::open("http://www.digibug.com/dapi/order.php") ?>
<? foreach ($order_params as $key => $value): ?>
<?= form::hidden($key, $value) ?>
<? endforeach ?>
</form>
<script type="text/javascript">
document.forms[0].submit();
</script>
</body>
</html>