summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-06-27 15:55:47 -0700
committerBharat Mediratta <bharat@menalto.com>2009-06-27 15:55:47 -0700
commit2fbc03437ac6f861f597778964cf01737968bb94 (patch)
tree2aed23a35b499bac2814e3aeb6356a93008e2fa6
parentf98b7dc631afc4da595aa149b21b5d38f41afd22 (diff)
Digibug simplification cleanup. Upgrade digibug module to version 2.
1) Simplify the admin settings page to what most of our users want. Eliminate basic_ and default_ ids. We just have company_id and default_id. Advanced users can use advanced settings for now. 2) Fix security in print_photos (didn't get it right in my last commit) 3) Use the regular thumb and full urls if the images are publicly available to reduce load on the proxy. 4) Simplify proxy expiration code. 5) Eliminate all specialized styles from the admin theme.
-rw-r--r--modules/digibug/controllers/admin_digibug.php50
-rw-r--r--modules/digibug/controllers/digibug.php72
-rw-r--r--modules/digibug/helpers/digibug_installer.php30
-rw-r--r--modules/digibug/images/digibug_logo.png (renamed from themes/admin_default/images/digibug_logo.png)bin17296 -> 17296 bytes
-rw-r--r--modules/digibug/js/digibug.js31
-rw-r--r--modules/digibug/models/digibug_proxy.php1
-rw-r--r--modules/digibug/module.info2
-rw-r--r--modules/digibug/views/admin_digibug.html.php29
-rw-r--r--modules/digibug/views/digibug_form.html.php11
-rw-r--r--themes/admin_default/css/screen.css54
10 files changed, 82 insertions, 198 deletions
diff --git a/modules/digibug/controllers/admin_digibug.php b/modules/digibug/controllers/admin_digibug.php
index bd9e9d95..7124338f 100644
--- a/modules/digibug/controllers/admin_digibug.php
+++ b/modules/digibug/controllers/admin_digibug.php
@@ -19,56 +19,8 @@
*/
class Admin_Digibug_Controller extends Admin_Controller {
public function index() {
- print $this->_get_view();
- }
-
- public function update() {
- access::verify_csrf();
-
- $form = $this->_get_form();
- if ($form->validate()) {
- module::set_var("digibug", "company_id", $form->group->company_id->value);
- module::set_var("digibug", "event_id", $form->group->event_id->value);
- message::success(t("Successfully updated Digibug company and event id's"));
-
- url::redirect("admin/digibug");
- }
-
- print $this->_get_view($form);
- }
-
- public function default_settings() {
- access::verify_csrf();
-
- module::set_var("digibug", "company_id", null);
- module::set_var("digibug", "event_id", null);
- message::success(t("Successfully set Digibug company and event id's to default"));
-
- url::redirect("admin/digibug");
- }
-
- private function _get_view($form=null) {
$v = new Admin_View("admin.html");
$v->content = new View("admin_digibug.html");
- $v->content->form = empty($form) ? $this->_get_form() : $form;
- return $v;
- }
-
- private function _get_form() {
- $form = new Forge("admin/digibug/update", "", "post",
- array("id" => "gDigibugForm"));
- $group = $form->group("group")
- ->label(t("Enter your account information."));
- $group->input("company_id")
- ->label(t("Company Id"))
- ->rules("required")
- ->value(module::get_var("digibug", "company_id", ""));
- $group->input("event_id")
- ->label(t("Event Id"))
- ->rules("required")
- ->value(module::get_var("digibug", "event_id", ""));
- $group->submit("")->value(t("Submit"));
-
- return $form;
+ print $v;
}
} \ No newline at end of file
diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php
index 45d3fde4..c1852009 100644
--- a/modules/digibug/controllers/digibug.php
+++ b/modules/digibug/controllers/digibug.php
@@ -20,55 +20,47 @@
class Digibug_Controller extends Controller {
public function print_photo($id) {
access::verify_csrf();
-
$item = ORM::factory("item", $id);
- access::required("view_full", $id);
-
- $proxy = ORM::factory("digibug_proxy");
- $proxy->uuid = md5(rand());
- $proxy->item_id = $item->id;
- $proxy->save();
-
- $url = url::abs_site("digibug/print_proxy/{$proxy->uuid}");
- $company_id = module::get_var("digibug", "company_id",
- module::get_var("digibug", "default_company_id"));
- $event_id = module::get_var("digibug", "event_id",
- module::get_var("digibug", "default_event_id"));
+ access::required("view_full", $item);
+
+ if (access::group_can(group::everybody(), "view_full", $item)) {
+ $full_url = $item->file_url(true);
+ $thumb_url = $item->thumb_url(true);
+ } else {
+ $proxy = ORM::factory("digibug_proxy");
+ $proxy->uuid = md5(rand());
+ $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");
+ }
$v = new View("digibug_form.html");
$v->order_parms = array(
"digibug_api_version" => "100",
- "company_id" => $company_id,
- "event_id" => $event_id,
+ "company_id" => module::get_var("digibug", "company_id"),
+ "event_id" => module::get_var("digibug", "event_id"),
"cmd" => "addimg",
"return_url" => url::abs_site("digibug/close_window"),
"num_images" => "1",
- "image_1" => $url,
- "thumb_1" => "$url/thumb",
+ "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" => p::clean($item->title));
- Kohana::log("error", Kohana::debug($v->order_parms));
print $v;
}
- public function print_proxy($id, $thumb=null) {
- $proxy = ORM::factory("digibug_proxy")
- ->where("uuid", $id)
- ->find();
-
- if (!$proxy->loaded) {
- Kohana::show_404();
- }
-
- if (!$proxy->item->loaded) {
+ public function print_proxy($type, $id) {
+ $proxy = ORM::factory("digibug_proxy", array("uuid", $id));
+ if (!$proxy->loaded || !$proxy->item->loaded) {
Kohana::show_404();
}
- $file = empty($thumb) ? $proxy->item->file_path() : $proxy->item->thumb_path();
+ $file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path();
if (!file_exists($file)) {
kohana::show_404();
}
@@ -76,8 +68,6 @@ class Digibug_Controller extends Controller {
// We don't need to save the session for this request
Session::abort_save();
- $this->_clean_expired();
-
// Dump out the image
header("Content-Type: $proxy->item->mime_type");
Kohana::close_buffers(false);
@@ -86,9 +76,11 @@ class Digibug_Controller extends Controller {
fclose($fd);
// If the request was for the image and not the thumb, then delete the proxy.
- if (empty($thumb)) {
+ if ($type == "full") {
$proxy->delete();
}
+
+ $this->_clean_expired();
}
public function close_window() {
@@ -96,17 +88,9 @@ class Digibug_Controller extends Controller {
}
private function _clean_expired() {
- $expired = ORM::factory("digibug_proxy")
- ->where("request_date <= (CURDATE() - INTERVAL 10 DAY)")
- ->find_all();
-
- // Delete as many as we can in a second, so as to not slow up the request.
- $start = microtime(true);
- foreach ($expired as $proxy) {
- if (microtime(true) - $start > 1.0) {
- break;
- }
- $proxy->delete();
- }
+ Database::instance()>query(
+ "DELETE FROM {digibug_proxy} " .
+ "WHERE request_date <= (CURDATE() - INTERVAL 10 DAY) " .
+ "LIMIT 20");
}
} \ No newline at end of file
diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php
index f1308fd3..1cd78b44 100644
--- a/modules/digibug/helpers/digibug_installer.php
+++ b/modules/digibug/helpers/digibug_installer.php
@@ -21,16 +21,28 @@ 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`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ `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`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- module::set_var("digibug", "default_company_id", "3153");
- module::set_var("digibug", "default_event_id", "8491");
- module::set_version("digibug", 1);
+ module::set_var("digibug", "company_id", "3153");
+ module::set_var("digibug", "event_id", "8491");
+ module::set_version("digibug", 2);
+ }
+
+ 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() {
diff --git a/themes/admin_default/images/digibug_logo.png b/modules/digibug/images/digibug_logo.png
index 5eac2c7d..5eac2c7d 100644
--- a/themes/admin_default/images/digibug_logo.png
+++ b/modules/digibug/images/digibug_logo.png
Binary files differ
diff --git a/modules/digibug/js/digibug.js b/modules/digibug/js/digibug.js
index 837c8f7f..456dfecb 100644
--- a/modules/digibug/js/digibug.js
+++ b/modules/digibug/js/digibug.js
@@ -1,26 +1,25 @@
$(document).ready(function() {
$(".gDigibugPrintButton a").click(function(e) {
e.preventDefault();
- queue_print(e);
+ return popUp(e.currentTarget.href, { width: 800, height: 600 } );
});
$("#gDigibugLink").click(function(e) {
e.preventDefault();
- return queue_print(e);
+ return popUp(e.currentTarget.href, { width: 800, height: 600 } );
});
});
function popUp(url, options) {
options = $.extend({
/* default options */
- width: 400,
- height: 400,
target: 'dbPopWin',
scrollbars: 'yes',
resizable: 'no',
menuBar: 'no',
- addressBar: 'yes'}, options);
+ addressBar: 'yes'
+ }, options);
- /* center the window by default. */
+ // center the window by default.
if (!options.winY) {
options.winY = screen.height / 2 - options.height / 2;
};
@@ -32,19 +31,15 @@ function popUp(url, options) {
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
- );
+ ',height=' + options.height +
+ ',top=' + options.winY +
+ ',left=' + options.winX +
+ ',scrollbars=' + options.scrollbars +
+ ',resizable=' + options.resizable +
+ ',menubar=' + options.menuBar +
+ ',location=' + options.addressBar
+ );
return false;
}
-
-function queue_print(e) {
- return popUp(e.currentTarget.href, { width: 800, height: 600 } );
-};
diff --git a/modules/digibug/models/digibug_proxy.php b/modules/digibug/models/digibug_proxy.php
index c76afdae..036af9c7 100644
--- a/modules/digibug/models/digibug_proxy.php
+++ b/modules/digibug/models/digibug_proxy.php
@@ -18,5 +18,4 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Digibug_Proxy_Model extends ORM {
- protected $has_one = array("item");
}
diff --git a/modules/digibug/module.info b/modules/digibug/module.info
index 58602c0d..c25a2454 100644
--- a/modules/digibug/module.info
+++ b/modules/digibug/module.info
@@ -1,3 +1,3 @@
name = Digibug
description = Digibug Photo Printing Module
-version = 1
+version = 2
diff --git a/modules/digibug/views/admin_digibug.html.php b/modules/digibug/views/admin_digibug.html.php
index 769fd415..7e4436ff 100644
--- a/modules/digibug/views/admin_digibug.html.php
+++ b/modules/digibug/views/admin_digibug.html.php
@@ -1,21 +1,22 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
-<script type="text/javascript">
- $("#gDigibugForm").ready(function() {
- $("#gDigibugForm input:submit").parent().append('<a href="<?= url::site("admin/digibug/default_settings?csrf=$csrf") ?>" class="gDigibugDefault"><?= t("Set Default") ?></a>');
- });
-</script>
<div id="gAdminDigibug">
<div class="gAdminDigibugIntro">
+ <img id="DigibugLogo" src="<?= url::file("modules/digibug/images/digibug_logo.png") ?>">
+ <h2> <?= t("Digibug Photo Printing") ?> </h2>
<p>
- <?= t("allows you to turn your photos into a wide variety of prints, gifts and games.") ?>
+ <?= t("Turn your photos into a wide variety of prints, gifts and games!") ?>
+ </p>
+
+ <ul id="gMessage">
+ <li class="gSuccess">
+ <?= 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" => url::site("admin/advanced_settings"))) ?>
</p>
- </div>
- <div id="gDigibugAccount">
- <div style="width: 120px;" class="gDigibugText gDigibugSignIn">
- <?= t("Don't have an account?") ?>
- <br/> <br/>
- <a href="http://www.digibug.com/signup.php" style=""><?= t("Sign up") ?></a><?= t(" to get started") ?>
- </div>
- <?= $form ?>
</div>
</div>
diff --git a/modules/digibug/views/digibug_form.html.php b/modules/digibug/views/digibug_form.html.php
index e18cbc18..c6994cbe 100644
--- a/modules/digibug/views/digibug_form.html.php
+++ b/modules/digibug/views/digibug_form.html.php
@@ -1,16 +1,11 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<html>
- <head>
- <?= html::script("lib/jquery.js") ?>
- <script type="text/javascript">
- $("body form").ready(function() {
- $("body form").submit();
- });
- </script>
- </head>
<body>
<?= form::open("http://www.digibug.com/dapi/order.php") ?>
<?= form::hidden($order_parms) ?>
<?= form::close() ?>
+ <script type="text/javascript">
+ document.forms[0].submit();
+ </script>
</body>
</html>
diff --git a/themes/admin_default/css/screen.css b/themes/admin_default/css/screen.css
index d66115ef..f4173d4b 100644
--- a/themes/admin_default/css/screen.css
+++ b/themes/admin_default/css/screen.css
@@ -439,57 +439,3 @@ li.gDefaultGroup h4, li.gDefaultGroup .gUser {
overflow: hidden;
}
-/** *******************************************************************
- * 8) Digibug Print Administration
- **********************************************************************/
-.gAdminDigibugIntro {
- background-image: url(../images/digibug_logo.png);
- background-repeat: no-repeat;
- padding-bottom: 20px;
- width: 820px;
-}
-
-.gAdminDigibugIntro p {
- font-family: Trebuchet MS,Arial,Verdana,Helvetica,sans-serif;
- font-size: 1.3em;
- font-weight: bold;
- padding-left: 5px;
- padding-top: 15px;
- text-indent: 110px;
-}
-
-.gDigibugAccount {
- width: 820px;
- height: 420px;
-}
-
-.gDigibugTab .gDigibugText {
- font-size: 12px;
- font-weight: bold;
- line-height: 17px;
- padding-bottom: 15px;
-}
-
-.gDigibugSignIn {
- width: 115px;
- float: left;
-}
-
-.gDigibugSignIn a {
- color: black;
- font-size: 16px;
- font-weight: bold;
- text-decoration: underline;
-}
-
-#gDigibugForm {
- float: left;
- padding-left: 30px;
- width: 220px;
-}
-
-.gDigibugDefault {
- clear: none;
- float: left;
- margin: .3em 1em;
-}