summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2008-12-11 17:20:55 +0000
committerTim Almdal <tnalmdal@shaw.ca>2008-12-11 17:20:55 +0000
commite1f2a5d4e60f431e0a94c998afc026f1136fb26b (patch)
tree76d05837701cbe78a6a2b3a845fd05cf971f4693
parent773d7024eb57765822e345380be7682ce5f14d17 (diff)
1) Begins the creation of the local import module by adding the administation component to the scaffolding Actions tab. The importing functionality will follow shortly.
2) Defines a routining pattern for module administration controllers. URI's of the form admin/module/method/parameters gets remapped into module_admin/method/parameters. This will result in the lookup of the the controller Module_Admin_Controller
-rw-r--r--core/config/routes.php8
-rw-r--r--core/controllers/welcome.php11
-rw-r--r--core/views/welcome.html.php11
-rw-r--r--modules/local_import/controllers/local_import_admin.php56
-rw-r--r--modules/local_import/helpers/local_import.php49
-rw-r--r--modules/local_import/helpers/local_import_block.php30
-rw-r--r--modules/local_import/helpers/local_import_installer.php41
-rw-r--r--modules/local_import/images/bin_closed.pngbin0 -> 363 bytes
-rw-r--r--modules/local_import/js/local_import.js67
-rw-r--r--modules/local_import/views/local_import_admin.html.php31
-rw-r--r--modules/local_import/views/local_import_dir_list.html.php28
11 files changed, 329 insertions, 3 deletions
diff --git a/core/config/routes.php b/core/config/routes.php
index 9e36f881..9a802a27 100644
--- a/core/config/routes.php
+++ b/core/config/routes.php
@@ -19,10 +19,12 @@
*/
// The abstract REST_Controller is not directly routable.
-$config['^rest\b.*'] = null;
+$config["^rest\b.*"] = null;
// Redirect /form/add and /form/edit to REST_Controller.
-$config['^form/(edit|add)/(\w+)/(.*)$'] = '$2/form_$1/$3';
+$config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3";
+
+$config["^admin/(\w+)/(.*)$"] = "$1_admin/$2";
// For now our default page is the scaffolding.
-$config['_default'] = 'welcome';
+$config["_default"] = "welcome";
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index dacaa87f..bddca606 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -36,6 +36,11 @@ class Welcome_Controller extends Template_Controller {
$this->template->album_tree = $this->_load_album_tree();
$this->template->rearrange_html = new View("rearrange.html");
$this->template->add_photo_html = $this->_get_add_photo_html();
+ if (module::is_installed("local_import")) {
+ $this->template->local_import_html = $this->_get_local_import_html();
+ } else {
+ $this->template->local_import_html = "";
+ }
} catch (Exception $e) {
$this->template->album_count = 0;
$this->template->photo_count = 0;
@@ -43,6 +48,7 @@ class Welcome_Controller extends Template_Controller {
$this->template->album_tree = array();
$this->template->rearrange_html = "";
$this->template->add_photo_html = "";
+ $this->template->local_import_html = "";
}
$this->_load_user_info();
@@ -513,4 +519,9 @@ class Welcome_Controller extends Template_Controller {
$parent = ORM::factory("item", $parent_id);
return photo::get_add_form($parent);
}
+
+ public function _get_local_import_html($user_name="admin") {
+ $user = ORM::factory("user")->where("name", $user_name)->find();
+ return local_import::get_admin_page($user);
+ }
}
diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php
index 47d9bd84..c8352592 100644
--- a/core/views/welcome.html.php
+++ b/core/views/welcome.html.php
@@ -148,11 +148,18 @@
margin-left: -1.5em;
list-style-type: none;
}
+
+ .gHide {
+ display: none;
+ }
</style>
<?= html::script("lib/jquery.js") ?>
<?= html::script("lib/jquery.form.js") ?>
<?= html::script("lib/jquery.cookie.js") ?>
<?= html::script("lib/jquery.MultiFile.js") ?>
+ <? if (class_exists("local_import_block")): ?>
+ <?= local_import_block::head(null) ?>
+ <? endif ?>
<? if (class_exists("rearrange_block")): ?>
<?= rearrange_block::head(null) ?>
<? endif ?>
@@ -257,6 +264,10 @@
</p>
<?= $add_photo_html ?>
<fieldset>
+ <legend>Local Server Import Admininstration</legend>
+ <?= $local_import_html ?>
+ </fieldset>
+ <fieldset>
<legend>Server Side Photos</legend>
<form method="post" action="<?= url::site("welcome/add_photos") ?>">
<input type="submit" value="upload"/>
diff --git a/modules/local_import/controllers/local_import_admin.php b/modules/local_import/controllers/local_import_admin.php
new file mode 100644
index 00000000..18733c22
--- /dev/null
+++ b/modules/local_import/controllers/local_import_admin.php
@@ -0,0 +1,56 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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 Local_Import_Admin_Controller extends Controller {
+ public function add_path() {
+ $form = local_import::get_admin_form();
+ $paths = unserialize(module::get_var("local_import", "authorized_paths"));
+ if ($form->validate()) {
+ $paths[$form->path->value] = 1;
+ module::set_var("local_import", "authorized_paths", serialize($paths));
+ }
+ $view = new View("local_import_dir_list.html");
+ $view->paths = array_keys($paths);
+
+ print $view;
+ }
+
+ public function remove() {
+ $path = $this->input->post("path");
+ $paths = unserialize(module::get_var("local_import", "authorized_paths"));
+ unset($paths[$path]);
+ module::set_var("local_import", "authorized_paths", serialize($paths));
+
+ $view = new View("local_import_dir_list.html");
+ $view->paths = array_keys($paths);
+
+ print $view;
+ }
+
+ public function autocomplete() {
+ $files = array();
+
+ $path_prefix = $this->input->get("q");
+ foreach (glob("{$path_prefix}*") as $file) {
+ $files[] = $file;
+ }
+
+ print implode("\n", $files);
+ }
+} \ No newline at end of file
diff --git a/modules/local_import/helpers/local_import.php b/modules/local_import/helpers/local_import.php
new file mode 100644
index 00000000..045201c7
--- /dev/null
+++ b/modules/local_import/helpers/local_import.php
@@ -0,0 +1,49 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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 local_import {
+ public static function get_admin_page() {
+// @todo check for admin permission
+// if (!$user->admin) {
+// throw new Exception("@todo ACCESS DENIED");
+// }
+
+ $template = new View("local_import_admin.html");
+
+ $paths = unserialize(module::get_var("local_import", "authorized_paths"));
+ if (!empty($paths)) {
+ $template->dir_list = new View("local_import_dir_list.html");
+ $template->dir_list->paths = array_keys($paths);
+ } else {
+ $template->dir_list = "";
+ }
+
+ $template->add_form = self::get_admin_form()->render();
+
+ return $template;
+ }
+
+ public static function get_admin_form() {
+ $form = new Forge("admin/local_import/add_path", "", "post", array("id" => "gLocalImportAdminForm"));
+ $form->input("path")->label(true);
+ $form->submit(_("Add"));
+
+ return $form;
+ }
+}
diff --git a/modules/local_import/helpers/local_import_block.php b/modules/local_import/helpers/local_import_block.php
new file mode 100644
index 00000000..c337af41
--- /dev/null
+++ b/modules/local_import/helpers/local_import_block.php
@@ -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-2008 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 local_import_block_Core {
+ public static function head($theme) {
+ $head[] = html::script("modules/local_import/js/local_import.js");
+
+ $url = url::file("modules/local_import/css/local_import.css");
+ $head[] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\" " .
+ "media=\"screen,print,projection\" />";
+
+ return implode("\n", $head);
+ }
+}
diff --git a/modules/local_import/helpers/local_import_installer.php b/modules/local_import/helpers/local_import_installer.php
new file mode 100644
index 00000000..72f42c97
--- /dev/null
+++ b/modules/local_import/helpers/local_import_installer.php
@@ -0,0 +1,41 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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 local_import_installer {
+ public static function install() {
+ $db = Database::instance();
+ $version = module::get_version("local_import");
+ if ($version == 0) {
+// access::register_permission("local_import");
+
+ module::set_version("local_import", 1);
+ module::set_var("local_import", "authorized_paths", serialize(array()));
+ }
+ }
+
+ public static function uninstall() {
+// access::delete_permission("local_import");
+ $module = module::get("local_import");
+
+ $db = Database::instance();
+ $db->query("DELETE FROM `vars` WHERE `module_id` = {$module->id};");
+
+ module::delete("local_import");
+ }
+}
diff --git a/modules/local_import/images/bin_closed.png b/modules/local_import/images/bin_closed.png
new file mode 100644
index 00000000..afe22ba9
--- /dev/null
+++ b/modules/local_import/images/bin_closed.png
Binary files differ
diff --git a/modules/local_import/js/local_import.js b/modules/local_import/js/local_import.js
new file mode 100644
index 00000000..3ad01ce8
--- /dev/null
+++ b/modules/local_import/js/local_import.js
@@ -0,0 +1,67 @@
+/**
+ * Set up autocomplete on the server path list
+ *
+ */
+$("document").ready(function() {
+ var previous_search = "";
+ $("#gLocalImportAdmin input").autocomplete({
+ url: base_url + "admin/local_import/autocomplete",
+ mustMatch: true,
+ });
+ ajaxify_form({
+ form: "#gLocalImportAdmin form",
+ url: "admin/local_import/",
+ returnCode: 200,
+ callback: function(xhr, statusText) {
+ $("#gImportLocalDirList").html(xhr.responseText);
+ setDroppable("#gImportLocalDirList #gRemoveDir");
+ setDraggable("#gImportLocalDirList li");
+ }
+ });
+
+ setDroppable("#gImportLocalDirList #gRemoveDir");
+ setDraggable("#gImportLocalDirList li");
+});
+
+function setDraggable(selector) {
+ $(selector).draggable({
+ helper: 'clone',
+// containment: "#gImportLocalDirList",
+ opacity: .6,
+ revert: "invalid"
+ });
+}
+
+function setDroppable(selector) {
+ $(selector).droppable({
+ accept: "#gImportLocalDirList li",
+ drop: function(ev, ui) {
+ var element = ui.draggable[0];
+
+ if (confirm("Do you really want to remove " + element.textContent)) {
+ $.ajax({
+ data: "path=" + element.textContent,
+ url: base_url + "admin/local_import/remove",
+ success: function(data, textStatus) {
+ $("#gImportLocalDirList").html(data);
+ setDroppable("#gImportLocalDirList #gRemoveDir");
+ setDraggable("#gImportLocalDirList li");
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ alert("Text Status: " + textStatus + " Http Error Code: " + xhr.status);
+ },
+ type: "POST"
+ });
+ }
+ }
+ });
+}
+
+function ajaxify_form(options) {
+ $(options.form).ajaxForm({
+ complete:function(xhr, statusText) {
+ options.callback(xhr, statusText);
+ $(options.form).clearForm();
+ }
+ });
+}
diff --git a/modules/local_import/views/local_import_admin.html.php b/modules/local_import/views/local_import_admin.html.php
new file mode 100644
index 00000000..58daeab6
--- /dev/null
+++ b/modules/local_import/views/local_import_admin.html.php
@@ -0,0 +1,31 @@
+<? defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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.
+ */
+?>
+<script>
+ var base_url = "<?= url::base(true) ?>";
+</script>
+<div id="gLocalImportAdmin">
+ <div id="gImportLocalDirList">
+ <?= $dir_list ?>
+ </div>
+ <div>
+ <?= $add_form ?>
+ </div>
+</div>
diff --git a/modules/local_import/views/local_import_dir_list.html.php b/modules/local_import/views/local_import_dir_list.html.php
new file mode 100644
index 00000000..db34d1bf
--- /dev/null
+++ b/modules/local_import/views/local_import_dir_list.html.php
@@ -0,0 +1,28 @@
+<? defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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.
+ */
+?>
+<? if (!empty($paths)): ?>
+<span id="gRemoveDir">Remove</span>
+<ul id="gPathList">
+ <? foreach ($paths as $id => $path): ?>
+ <li id="<?= $id ?>"><?= $path ?></li>
+ <? endforeach ?>
+</ul>
+<? endif ?>