Skip to content

Commit

Permalink
Merge branch 'master' into talmdal_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Almdal committed Nov 21, 2009
2 parents 1fec5e2 + 005cf8e commit 23a60fb
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 78 deletions.
25 changes: 19 additions & 6 deletions modules/gallery/controllers/simple_uploader.php
Expand Up @@ -26,9 +26,7 @@ public function app($id) {
$item = $item->parent();
}

$v = new View("simple_uploader.html");
$v->item = $item;
print $v;
print self::get_add_form($item);
}

public function start() {
Expand Down Expand Up @@ -67,9 +65,11 @@ public function add_photo($id) {
html::anchor("photos/$item->id", t("view photo")));
}

$tags = $this->input->post("tags");
if (!(empty($tags))) {
module::event("add_tags_to_item", $item, $tags);
// We currently have no way of showing errors if validation fails, so only call our event
// handlers if validation passes.
$form = self::get_add_form($album);
if ($form->validate()) {
module::event("add_photos_form_completed", $item, $form);
}
} catch (Exception $e) {
Kohana::log("alert", $e->__toString());
Expand All @@ -95,4 +95,17 @@ public function finish() {
print json_encode(array("result" => "success"));
}

public function get_add_form($album) {
$form = new Forge("simple_uploader/finish", "", "post", array("id" => "g-add-photos-form"));
$group = $form->group("add_photos")
->label(t("Add photos to %album_title", array("album_title" => html::purify($album->title))));
$group->uploadify("uploadify")->album($album);

$group = $form->group("actions");
$group->uploadify_buttons("");

module::event("add_photos_form", $album, $form);

return $form;
}
}
54 changes: 54 additions & 0 deletions modules/gallery/libraries/Form_Uploadify.php
@@ -0,0 +1,54 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 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 Form_Uploadify_Core extends Form_Input {
protected $data = array(
"name" => false,
"type" => "UNKNOWN",
"url" => "",
"text" => "");

public function __construct($name) {
parent::__construct($name);
$this->data["script_data"] = array(
"g3sid" => Session::instance()->id(),
"user_agent" => Input::instance()->server("HTTP_USER_AGENT"),
"csrf" => access::csrf_token());
}

public function album(Item_Model $album) {
$this->data["album"] = $album;
return $this;
}

public function script_data($key, $value) {
$this->data["script_data"][$key] = $value;
}

public function render() {
$v = new View("form_uploadify.html");
$v->album = $this->data["album"];
$v->script_data = $this->data["script_data"];
return $v;
}

public function validate() {
return true;
}
}
25 changes: 25 additions & 0 deletions modules/gallery/libraries/Form_Uploadify_buttons.php
@@ -0,0 +1,25 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 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 Form_Uploadify_buttons_Core extends Form_Input {
public function render() {
$v = new View("form_uploadify_buttons.html");
return $v;
}
}
3 changes: 2 additions & 1 deletion modules/gallery/module.info
@@ -1,4 +1,5 @@
name = "Gallery 3"
description = "Gallery core application"
version = 19 ; Note: skip version 20, use 21 as the next version
; Note: skip version 20, use 21 as the next version
version = 19

Expand Up @@ -18,12 +18,8 @@
$("#g-add-photos-canvas").ready(function () {
$("#g-uploadify").uploadify({
uploader: "<?= url::file("lib/uploadify/uploadify.swf") ?>",
script: "<?= url::site("simple_uploader/add_photo/{$item->id}") ?>",
scriptData: <?= json_encode(array(
"g3sid" => Session::instance()->id(),
"tags" => "",
"user_agent" => Input::instance()->server("HTTP_USER_AGENT"),
"csrf" => $csrf)) ?>,
script: "<?= url::site("simple_uploader/add_photo/{$album->id}") ?>",
scriptData: <?= json_encode($script_data) ?>,
fileExt: "*.gif;*.jpg;*.jpeg;*.png;*.flv;*.mp4;*.GIF;*.JPG;*.JPEG;*.PNG;*.FLV;*.MP4",
fileDesc: <?= t("Photos and movies")->for_js() ?>,
cancelImg: "<?= url::file("lib/uploadify/cancel.png") ?>",
Expand Down Expand Up @@ -92,68 +88,36 @@
return true;
}
});
<? if (module::active("tag")): ?>
$('#g-add-photos-tags').autocomplete(
'<?= url::site("tags/autocomplete") ?>',
{max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1}
);
$('#g-add-photos-tags').blur(function (event) {
$("#g-uploadify").uploadifySettings("scriptData", {"tags": $(this).val()});
});
<? endif ?>
});
</script>

<form id="g-add-photos-form" action="<?= url::site("simple_uploader/finish?csrf=$csrf") ?>">
<fieldset>
<legend> <?= t("Add photos to %album_title", array("album_title" => html::purify($item->title))) ?> </legend>

</fieldset>
<div id="g-add-photos">
<? if (ini_get("suhosin.session.encrypt")): ?>
<ul id="g-action-status" class="g-message-block">
<li class="g-error">
<?= t("Error: your server is configured to use the <a href=\"%encrypt_url\"><code>suhosin.session.encrypt</code></a> setting from <a href=\"%suhosin_url\">Suhosin</a>. You must disable this setting to upload photos.",
array("encrypt_url" => "http://www.hardened-php.net/suhosin/configuration.html#suhosin.session.encrypt",
"suhosin_url" => "http://www.hardened-php.net/suhosin/")) ?>
</li>
</ul>
<? endif ?>

<div>
<p>
<?= t("Photos will be uploaded to album: ") ?>
</p>
<ul class="g-breadcrumbs">
<? foreach ($item->parents() as $i => $parent): ?>
<li<? if ($i == 0) print " class=\"g-first\"" ?>> <?= html::clean($parent->title) ?> </li>
<? endforeach ?>
<li class="g-active"> <?= html::purify($item->title) ?> </li>
</ul>
</div>

<div id="g-add-photos-canvas" style="text-align: center;">
<a id="g-add-photos-button" class="ui-corner-all" style="padding-bottom: 1em;" href="#"><?= t("Select Photos...") ?></a>
<span id="g-uploadify"></span>
</div>
<div id="g-add-photos-status" style="text-align: center;">
<ul>
</ul>
</div>
<? if (ini_get("suhosin.session.encrypt")): ?>
<ul id="g-action-status" class="g-message-block">
<li class="g-error">
<?= t("Error: your server is configured to use the <a href=\"%encrypt_url\"><code>suhosin.session.encrypt</code></a> setting from <a href=\"%suhosin_url\">Suhosin</a>. You must disable this setting to upload photos.",
array("encrypt_url" => "http://www.hardened-php.net/suhosin/configuration.html#suhosin.session.encrypt",
"suhosin_url" => "http://www.hardened-php.net/suhosin/")) ?>
</li>
</ul>
<? endif ?>

<? if (module::active("tag")): ?>
<div style="clear: both;">
<label for="g-add-photos-tags"><?= t("Add tags to all uploaded files") ?></label>
<input type="text" id="g-add-photos-tags" name="tags" value="" />
</div>
<? endif ?>
<div>
<p>
<?= t("Photos will be uploaded to album: ") ?>
</p>
<ul class="g-breadcrumbs">
<? foreach ($album->parents() as $i => $parent): ?>
<li<? if ($i == 0) print " class=\"g-first\"" ?>> <?= html::clean($parent->title) ?> </li>
<? endforeach ?>
<li class="g-active"> <?= html::purify($album->title) ?> </li>
</ul>
</div>

<!-- Proxy the done request back to our form, since its been ajaxified -->
<button id="g-upload-done" class="ui-state-default ui-corner-all" onclick="$('#g-add-photos-form').submit();return false;">
<?= t("Done") ?>
</button>
<button id="g-upload-cancel-all" class="ui-state-default ui-corner-all ui-state-disabled" onclick="$('#g-uploadify').uploadifyClearQueue();return false;" disabled="disabled">
<?= t("Cancel All") ?>
</button>
</div>
</form>
<div id="g-add-photos-canvas" style="text-align: center;">
<a id="g-add-photos-button" class="ui-corner-all" style="padding-bottom: 1em;" href="#"><?= t("Select Photos...") ?></a>
<span id="g-uploadify"></span>
</div>
<div id="g-add-photos-status" style="text-align: center;">
<ul>
</ul>
</div>
8 changes: 8 additions & 0 deletions modules/gallery/views/form_uploadify_buttons.html.php
@@ -0,0 +1,8 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<!-- Proxy the done request back to our form, since its been ajaxified -->
<button id="g-upload-done" class="ui-state-default ui-corner-all" onclick="$('#g-add-photos-form').submit();return false;">
<?= t("Done") ?>
</button>
<button id="g-upload-cancel-all" class="ui-state-default ui-corner-all ui-state-disabled" onclick="$('#g-uploadify').uploadifyClearQueue();return false;" disabled="disabled">
<?= t("Cancel All") ?>
</button>
26 changes: 22 additions & 4 deletions modules/tag/helpers/tag_event.php
Expand Up @@ -98,13 +98,31 @@ static function item_index_data($item, $data) {
$data[] = join(" ", tag::item_tags($item));
}

static function add_tags_to_item($item, $tags) {
foreach (split(",", $tags) as $tag_name) {
static function add_photos_form($album, $form) {
$group = $form->add_photos;
$group->input("tags")
->label(t("Add tags to all uploaded files"))
->value("");
$group->uploadify->script_data("tags", "");

$autocomplete_url = url::site("tags/autocomplete");
$group->script("")
->text("$('input[name=tags]')
.autocomplete(
'$autocomplete_url',
{max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1}
)
.change(function (event) {
$('#g-uploadify').uploadifySettings('scriptData', {'tags': $(this).val()});
});");
}

static function add_photos_form_completed($album, $form) {
foreach (split(",", $form->add_photos->tags->value) as $tag_name) {
$tag_name = trim($tag_name);
if ($tag_name) {
$tag = tag::add($item, $tag_name);
$tag = tag::add($album, $tag_name);
}
}
}

}
6 changes: 5 additions & 1 deletion themes/wind/views/page.html.php
Expand Up @@ -86,9 +86,13 @@
<? endif ?>
<?= $theme->user_menu() ?>
<?= $theme->header_top() ?>
<div id="g-site-menu">

<!-- hide the menu and make it visible after the page has loaded, to minimize menu flicker -->
<div id="g-site-menu" style="visibility: hidden">
<?= $theme->site_menu() ?>
</div>
<script> $(document).ready(function() { $("#g-site-menu").css("visibility", "visible"); }) </script>

<?= $theme->header_bottom() ?>
</div>

Expand Down

0 comments on commit 23a60fb

Please sign in to comment.