1
0

Initial commit of Fotomoto rW module.

This commit is contained in:
rWatcher 2012-05-31 00:05:33 -04:00
parent 21c5f51800
commit e9bd604a63
8 changed files with 409 additions and 0 deletions

View File

@ -0,0 +1,111 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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_FotomotorW_Controller extends Admin_Controller {
public function index() {
// Display the admin page.
$view = new Admin_View("admin.html");
$view->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");
}
}

View File

@ -0,0 +1,76 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 FotomotorW_Controller extends Controller {
public function resize($item_id) {
// Displayed the "resized" version of an image by it's ID number.
// This both gives fotomoto access to resizes regardless of permissions
// and forces fotomoto to track images by unique id instead of file name
// which is necessary for auto-pickup.
// Load the photo from the provided id#. If invalid, display a 404 error.
$item = ORM::factory("item", $item_id);
if (!$item->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);
}
}

View File

@ -0,0 +1,30 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 fotomotorw_event_Core {
static function admin_menu($menu, $theme) {
// Display an option under the admin Settings menu.
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("fotomotorw_menu")
->label(t("Fotomoto"))
->url(url::site("admin/fotomotorw")));
}
}

View File

@ -0,0 +1,35 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 fotomotorw_installer {
static function install() {
// Set up some default values.
module::set_var("fotomotorw", "fotomoto_site_key", '');
module::set_var("fotomotorw", "fotomoto_private_key", md5(random::hash() . access::private_key()));
module::set_var("fotomotorw", "fotomoto_buy_prints", 1);
module::set_var("fotomotorw", "fotomoto_buy_cards", 1);
module::set_var("fotomotorw", "fotomoto_buy_download", 1);
module::set_var("fotomotorw", "fotomoto_share_ecard", 1);
module::set_var("fotomotorw", "fotomoto_share_facebook", 1);
module::set_var("fotomotorw", "fotomoto_share_twitter", 1);
module::set_var("fotomotorw", "fotomoto_share_digg", 1);
module::set_version("fotomotorw", 1);
}
}

View File

@ -0,0 +1,71 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 fotomotorw_theme_Core {
static function head($theme) {
// Load fotomoto's js file on photo pages.
if($theme->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;
}
}

View File

@ -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"

View File

@ -0,0 +1,64 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-block">
<h1> <?= t("Fotomoto settings") ?> </h1>
<div class="g-block-content">
<table>
<tr>
<th> <?= t("Fotomoto Site Key") ?></th>
</tr>
<tr class="setting-row g-odd">
<td>
<a href="<?= url::site("admin/advanced_settings/edit/fotomotorw/fotomoto_site_key"); ?>" class="g-dialog-link">
<? if (module::get_var("fotomotorw", "fotomoto_site_key", "") == ""): ?>
<i> <?= t("Click to add your Fotomoto Site Key") ?> </i>
<? else: ?>
<?= module::get_var("fotomotorw", "fotomoto_site_key"); ?>
<? endif; ?>
</a>
</td>
</tr>
</table>
<p>(Log in to the <a href="http://my.fotomoto.com/">Fotomoto Dashboard</a> to get your Site Key.)</p>
<table>
<tr>
<th> <?= t("Fotomoto Display Options") ?></th>
</tr>
<tr>
<td>
<?=$display_form; ?>
</td>
</tr>
</table>
<table>
<tr>
<th> <?= t("Fotomoto Private Key") ?>
(<a href="<?= url::site("admin/fotomotorw/reset_private_key"); ?>"><?= t("Reset Private Key"); ?></a>)</th>
</tr>
<tr class="setting-row g-odd">
<td><?= module::get_var("fotomotorw", "fotomoto_private_key"); ?>
</td>
</tr>
</table>
</div>
</div>
<div class="g-block">
<h1> <?= t("Configuring Auto Pickup") ?> </h1>
<?
if (module::get_var("fotomotorw", "fotomoto_private_key") == "") {
print t("Please click the \"Reset Private Key\" link above to continue.");
} else {
?>
<?= t("Step 1: Log into your Fotomoto account and select Settings -> Auto Pickup, or <a href=\"http://my.fotomoto.com/cloud_storage_interfaces\" target=\"_blank\">click here</a>."); ?><br />
<?= t("Step 2: Select \"Create New Profile\"."); ?><br />
<?= t("Step 3: Enter in a Profile Name, and set \"Storage Type\" to \"HTTP\". Leave \"Username\" and \"Password\" blank."); ?><br />
<?= t("Step 4: For \"Host\", enter in \"") . substr(url::abs_site(), 0, strpos(substr(url::abs_site(), 7), "/")+7); ?>"<br />
<?= t("Step 5: For \"Path\", enter in \"") . str_replace(Kohana::config('core.url_suffix'), "", substr(url::site("fotomotorw/print_proxy/" . module::get_var("fotomotorw", "fotomoto_private_key")), 1)) . "\""; ?><br />
<?= t("Step 6: For \"Filename Lookup Pattern\", enter in \"FILENAME.EXT\"."); ?><br />
<?= t("Step 7: Press \"Save Profile\" to finish."); ?>
<? } ?>
</div>

View File

@ -0,0 +1,15 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<center>
<? if (count($details) > 0): ?>
<a href="javascript:void(0);" onclick="showFotomotoDialog(<?=$details[0][0]; ?>);" style="font-weight: bold; font-size: 14px;"><?=$details[0][1]; ?></a>
<? for ($i = 1; $i < count($details); $i++): ?>
<span style="font-weight: bold; font-size: 14px;"> | </span>
<a href="javascript:void(0);" onclick="showFotomotoDialog(<?=$details[$i][0]; ?>);" style="font-weight: bold; font-size: 14px;"><?=$details[$i][1]; ?></a>
<? endfor ?>
<? endif; ?>
</center>
<script>
function showFotomotoDialog(window_type) {
FOTOMOTO.API.showWindow(window_type, "<?= url::abs_site("fotomotorw/resize/{$item->id}"); ?>");
}
</script>