From e9bd604a6320238700cd7194ca283fcd3756b9ec Mon Sep 17 00:00:00 2001 From: rWatcher Date: Thu, 31 May 2012 00:05:33 -0400 Subject: [PATCH] Initial commit of Fotomoto rW module. --- .../controllers/admin_fotomotorw.php | 111 ++++++++++++++++++ .../fotomotorw/controllers/fotomotorw.php | 76 ++++++++++++ .../fotomotorw/helpers/fotomotorw_event.php | 30 +++++ .../helpers/fotomotorw_installer.php | 35 ++++++ .../fotomotorw/helpers/fotomotorw_theme.php | 71 +++++++++++ 3.0/modules/fotomotorw/module.info | 7 ++ .../views/admin_fotomotorw.html.php | 64 ++++++++++ .../views/fotomotorw_block.html.php | 15 +++ 8 files changed, 409 insertions(+) create mode 100644 3.0/modules/fotomotorw/controllers/admin_fotomotorw.php create mode 100644 3.0/modules/fotomotorw/controllers/fotomotorw.php create mode 100644 3.0/modules/fotomotorw/helpers/fotomotorw_event.php create mode 100644 3.0/modules/fotomotorw/helpers/fotomotorw_installer.php create mode 100644 3.0/modules/fotomotorw/helpers/fotomotorw_theme.php create mode 100644 3.0/modules/fotomotorw/module.info create mode 100644 3.0/modules/fotomotorw/views/admin_fotomotorw.html.php create mode 100644 3.0/modules/fotomotorw/views/fotomotorw_block.html.php diff --git a/3.0/modules/fotomotorw/controllers/admin_fotomotorw.php b/3.0/modules/fotomotorw/controllers/admin_fotomotorw.php new file mode 100644 index 00000000..f487b53a --- /dev/null +++ b/3.0/modules/fotomotorw/controllers/admin_fotomotorw.php @@ -0,0 +1,111 @@ +page_title = t("Fotomoto"); + $view->content = new View("admin_fotomotorw.html"); + + // Generate a form to allow the user to choose which links to display under photos. + $form = new Forge("admin/fotomotorw/savedisplay", "", "post", + array("id" => "g-fotomotorw-admin-display-prefs")); + + $display_links_group = $form->group("fotomoto_display_links_group"); + $link_options["fotomoto_buy_prints"] = array(t("Buy Prints"), module::get_var("fotomotorw", "fotomoto_buy_prints")); + $link_options["fotomoto_buy_cards"] = array(t("Buy Cards"), module::get_var("fotomotorw", "fotomoto_buy_cards")); + $link_options["fotomoto_buy_download"] = array(t("Download"), module::get_var("fotomotorw", "fotomoto_buy_download")); + $link_options["fotomoto_share_ecard"] = array(t("Send eCard"), module::get_var("fotomotorw", "fotomoto_share_ecard")); + $link_options["fotomoto_share_facebook"] = array(t("Share on Facebook"), module::get_var("fotomotorw", "fotomoto_share_facebook")); + $link_options["fotomoto_share_twitter"] = array(t("Share on Twitter"), module::get_var("fotomotorw", "fotomoto_share_twitter")); + $link_options["fotomoto_share_digg"] = array(t("Share on Digg"), module::get_var("fotomotorw", "fotomoto_share_digg")); + + // Turn the array into a series of checkboxes. + $display_links_group->checklist("fotomoto_display_links") + ->options($link_options); + + // Add a save button to the form. + $form->submit("SaveSettings")->value(t("Save")); + + $view->content->display_form = $form; + print $view; + } + + public function reset_private_key() { + // Generate a new (random) private key. + module::set_var("fotomotorw", "fotomoto_private_key", md5(random::hash() . access::private_key())); + message::success(t("Your Photomoto private key has been reset.")); + url::redirect("admin/fotomotorw"); + } + + public function savedisplay() { + // Save the admin's preferences for which fotomoto links to display under each photo. + + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + // Figure out which boxes where checked + $linkOptions_array = Input::instance()->post("fotomoto_display_links"); + $buy_prints = false; + $buy_cards = false; + $buy_download = false; + $share_ecard = false; + $share_facebook = false; + $share_twitter = false; + $share_digg = false; + for ($i = 0; $i < count($linkOptions_array); $i++) { + if ($linkOptions_array[$i] == "fotomoto_buy_prints") { + $buy_prints = true; + } + if ($linkOptions_array[$i] == "fotomoto_buy_cards") { + $buy_cards = true; + } + if ($linkOptions_array[$i] == "fotomoto_buy_download") { + $buy_download = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_ecard") { + $share_ecard = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_facebook") { + $share_facebook = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_twitter") { + $share_twitter = true; + } + if ($linkOptions_array[$i] == "fotomoto_share_digg") { + $share_digg = true; + } + } + + // Save Settings. + module::set_var("fotomotorw", "fotomoto_buy_prints", $buy_prints); + module::set_var("fotomotorw", "fotomoto_buy_cards", $buy_cards); + module::set_var("fotomotorw", "fotomoto_buy_download", $buy_download); + module::set_var("fotomotorw", "fotomoto_share_ecard", $share_ecard); + module::set_var("fotomotorw", "fotomoto_share_facebook", $share_facebook); + module::set_var("fotomotorw", "fotomoto_share_twitter", $share_twitter); + module::set_var("fotomotorw", "fotomoto_share_digg", $share_digg); + + // Display a success message and reload the admin page. + message::success(t("Your Settings Have Been Saved.")); + url::redirect("admin/fotomotorw"); + } +} diff --git a/3.0/modules/fotomotorw/controllers/fotomotorw.php b/3.0/modules/fotomotorw/controllers/fotomotorw.php new file mode 100644 index 00000000..1be2def0 --- /dev/null +++ b/3.0/modules/fotomotorw/controllers/fotomotorw.php @@ -0,0 +1,76 @@ +loaded()) { + throw new Kohana_404_Exception(); + } + + // If the resize file doesn't exist for some reason, display a 404 error. + if (!file_exists($item->resize_path())) { + throw new Kohana_404_Exception(); + } + + // Display the image. + header("Content-Type: {$item->mime_type}"); + Kohana::close_buffers(false); + $fd = fopen($item->resize_path(), "rb"); + fpassthru($fd); + fclose($fd); + } + + public function print_proxy($site_key, $file_id) { + // This function retrieves the full-sized image for fotomoto. + // As this function by-passes normal Gallery security, a private + // site-key is used to try and prevent people other then fotomoto + // from finding the URL. + + // If the site key doesn't match, display a 404 error. + if ($site_key != module::get_var("fotomotorw", "fotomoto_private_key")) { + throw new Kohana_404_Exception(); + } + + // Load the photo from the provided id. If the id# is invalid, display a 404 error. + $item = ORM::factory("item", $file_id); + if (!$item->loaded()) { + throw new Kohana_404_Exception(); + } + + // If the image file doesn't exist for some reason, display a 404 error. + if (!file_exists($item->file_path())) { + throw new Kohana_404_Exception(); + } + + // Display the image. + header("Content-Type: {$item->mime_type}"); + Kohana::close_buffers(false); + $fd = fopen($item->file_path(), "rb"); + fpassthru($fd); + fclose($fd); + } +} diff --git a/3.0/modules/fotomotorw/helpers/fotomotorw_event.php b/3.0/modules/fotomotorw/helpers/fotomotorw_event.php new file mode 100644 index 00000000..24bdc5f1 --- /dev/null +++ b/3.0/modules/fotomotorw/helpers/fotomotorw_event.php @@ -0,0 +1,30 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("fotomotorw_menu") + ->label(t("Fotomoto")) + ->url(url::site("admin/fotomotorw"))); + } +} diff --git a/3.0/modules/fotomotorw/helpers/fotomotorw_installer.php b/3.0/modules/fotomotorw/helpers/fotomotorw_installer.php new file mode 100644 index 00000000..b949b61a --- /dev/null +++ b/3.0/modules/fotomotorw/helpers/fotomotorw_installer.php @@ -0,0 +1,35 @@ +page_subtype == "photo") { + return html::script('http://widget.fotomoto.com/stores/script/' . module::get_var("fotomotorw", "fotomoto_site_key") . '.js?api=true'); + } + } + + static function resize_bottom($theme) { + // Generate an array of links to display below photos. + $block = new Block; + $block->css_id = "g-fotomoto"; + $block->anchor = "fotomoto"; + + $link_array = array(); + $counter = 0; + if (module::get_var("fotomotorw", "fotomoto_buy_prints")) { + $link_array[$counter] = array("100", "Buy Prints"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_buy_cards")) { + $link_array[$counter] = array("300", "Buy Cards"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_buy_download")) { + $link_array[$counter] = array("400", "Download"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_ecard")) { + $link_array[$counter] = array("200", "Send eCard"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_facebook")) { + $link_array[$counter] = array("201", "Share on Facebook"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_twitter")) { + $link_array[$counter] = array("202", "Share on Twitter"); + $counter++; + } + if (module::get_var("fotomotorw", "fotomoto_share_digg")) { + $link_array[$counter] = array("203", "Share on Digg"); + $counter++; + } + + $view = new View("fotomotorw_block.html"); + $view->details = $link_array; + $block->content = $view; + return $block; + } +} diff --git a/3.0/modules/fotomotorw/module.info b/3.0/modules/fotomotorw/module.info new file mode 100644 index 00000000..593ab7e3 --- /dev/null +++ b/3.0/modules/fotomotorw/module.info @@ -0,0 +1,7 @@ +name = "Fotomoto (rWatcher)" +description = "Sell photos on your site through Fotomoto" +version = 1 +author_name = "rWatcher" +author_url = "http://codex.gallery2.org/User:RWatcher" +info_url = "http://codex.gallery2.org/Gallery3:Modules:fotomotorw" +discuss_url = "http://gallery.menalto.com/node/106765" diff --git a/3.0/modules/fotomotorw/views/admin_fotomotorw.html.php b/3.0/modules/fotomotorw/views/admin_fotomotorw.html.php new file mode 100644 index 00000000..b8175472 --- /dev/null +++ b/3.0/modules/fotomotorw/views/admin_fotomotorw.html.php @@ -0,0 +1,64 @@ + + +
+

+
+ + + + + + + + +
+ " class="g-dialog-link"> + + + + + + +
+

(Log in to the Fotomoto Dashboard to get your Site Key.)

+ + + + + + + + +
+ +
+ + + + + + + + +
+ (">)
+
+
+
+ +
+

+ + Auto Pickup, or click here."); ?>
+
+
+ "
+
+
+ + +
diff --git a/3.0/modules/fotomotorw/views/fotomotorw_block.html.php b/3.0/modules/fotomotorw/views/fotomotorw_block.html.php new file mode 100644 index 00000000..f0f4b91a --- /dev/null +++ b/3.0/modules/fotomotorw/views/fotomotorw_block.html.php @@ -0,0 +1,15 @@ + +
+ 0): ?> + + + | + + + +
+