1
0

Merge branch 'master' into talmdal

This commit is contained in:
Tim Almdal 2010-08-13 11:29:20 -07:00
commit 99551efe4b
6 changed files with 85 additions and 55 deletions

View File

@ -24,12 +24,14 @@ class Admin_Moduleorder_Controller extends Admin_Controller {
private function _get_view() {
$view = new Admin_View("admin.html");
$view->page_title = t("Manage Module Order");
$view->page_title = t("Manage module order");
$view->content = new View("admin_moduleorder.html");
$view->content->csrf = access::csrf_token();
$view->content->available = new View("admin_moduleorder_blocks.html");
$view->content->active = new View("admin_moduleorder_blocks.html");
$view->content->available->modules = $this->_get_modules();
if (module::get_version("gallery") > 31) {
$view->content->available->modules = $this->_get_modules();
}
return $view;
}
@ -38,7 +40,7 @@ class Admin_Moduleorder_Controller extends Admin_Controller {
$modulerawlist = explode("&", trim($_POST['modulelist'], "&"));
//Make sure that gallery and user modules are first in the list
$currentindex = 2;
$current_weight = 2;
$identity_provider = module::get_var("gallery", "identity_provider");
foreach ($modulerawlist as $row) {
$currentry = explode("=", $row);
@ -48,50 +50,25 @@ class Admin_Moduleorder_Controller extends Admin_Controller {
} elseif ($currentry[0] == $identity_provider) {
$modulelist[1] = $row;
} else {
$modulelist[$currentindex] = $row;
$currentindex++;
$modulelist[$current_weight] = $row;
$current_weight++;
}
}
ksort($modulelist);
//Get the highest used index
$highestindex = 0;
//Write the correct weight values
$current_weight = 0;
foreach ($modulelist as $row) {
$currentry = explode(":", $row);
if ($currentry[1] > $highestindex) {
$highestindex = $currentry[1];
}
}
$highestindex++; //Have a safety margin just in case
//To avoid conflicts on the index we now rewrite all indices of all modules
foreach ($modulelist as $row) {
$highestindex++;
$current_weight++;
$currentry = explode("=", $row);
$currentry = explode(":", $currentry[1]);
db::build()
->update("modules")
->set("id", $highestindex)
->where("name", "=", $currentry[0])
->set("weight", $current_weight)
->where("id", "=", $currentry[1])
->execute();
}
//Now we are ready to write the correct id values
$highestindex = 0;
foreach ($modulelist as $row) {
$highestindex++;
$currentry = explode("=", $row);
$currentry = explode(":", $currentry[1]);
db::build()
->update("modules")
->set("id", $highestindex)
->where("name", "=", $currentry[0])
->execute();
}
//As last step we optimize the table
db::query("OPTIMIZE TABLE `modules`")
->execute();
message::success(t("Your settings have been saved."));
url::redirect("admin/moduleorder");
print $this->_get_view();
@ -99,7 +76,7 @@ class Admin_Moduleorder_Controller extends Admin_Controller {
private function _get_modules() {
$active_blocks = array();
$available_modules = module_manager::get_available_site_modules();
$available_modules = moduleorder::get_available_site_modules();
return $available_modules;
}
}

View File

@ -17,16 +17,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class module_manager_Core {
class moduleorder_Core {
static function get_available_site_modules() {
return self::_get_modules();
}
private static function _get_modules() {
$modules = array();
foreach (db::build()->select("*")->from("modules")->order_by("id")->execute() as $row) {
foreach (db::build()->select("*")->from("modules")->order_by("weight")->execute() as $row) {
$modules["{$row->name}:$row->id"] = $row->name;
}
return $modules;
}
}
}

View File

@ -18,11 +18,22 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class moduleorder_event_Core {
static function module_change($changes) {
// Gallery version must be >= 32
if (module::get_version("gallery") < 32) {
site_status::warning(
t("The module 'Module Order' requires Gallery core version of 32 or higher."),
"moduleorder_needs_higherversion");
} else {
site_status::clear("moduleorder_needs_higherversion");
}
}
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("moduleorder_menu")
->label(t("Manage Module Order"))
->label(t("Module order"))
->url(url::site("admin/moduleorder")));
}
}

View File

@ -0,0 +1,38 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 moduleorder_installer {
static function install() {
// Set the module's version number.
module::set_version("moduleorder", 1);
}
static function upgrade($version) {
module::set_version("moduleorder", $version = 1);
}
static function deactivate() {
// Clear the require higher core version message.
site_status::clear("moduleorder_needs_higherversion");
}
static function uninstall() {
module::delete("moduleorder");
}
}

View File

@ -1,8 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<? if (module::get_version("gallery") > 31): ?>
<script type="text/javascript">
$(document).ready(function(){
$(".g-admin-blocks-list").height($(".g-admin-blocks-list").height());
});
$(function() {
$(".g-admin-blocks-list ul").sortable({
@ -23,23 +21,27 @@
document.moduleorder.submit();
}
</script>
<? endif ?>
<div id="g-block-admin" class="g-block ui-helper-clearfix">
<h1> <?= t("Manage Module Order") ?> </h1>
<h1> <?= t("Manage module order") ?> </h1>
<? if (module::get_version("gallery") < 32): ?>
<h2> <?= t("Warning") ?> </h2>
<p>
<?= t("You must have Gallery core version of 32 or higher installed to use this module. Please update your installation.") ?>
</p>
<? else: ?>
<p>
<?= t("Select and drag blocks to change the order. Click 'Save' to save your changes.") ?>
</p>
<h2> <?= t("Important notes") ?> </h2>
<p>
<?= t("You will only need to change this order in rare circumstances (e.g. if two modules display content at the bottom of the image and you want to change the order in which this content is being shown). If everything on your Gallery Site is looking normal then please do not touch this.") ?>
</p>
<h2> <?= t("Notes") ?> </h2>
<p>
<?= t("The core module ('gallery') and the identity provider module (default is 'user') cannot be sorted and are therefore hidden from this list.") ?>
</p>
<div class="g-block-content">
<div id="g-site-blocks">
<div class="g-admin-blocks-list g-left">
<div class="g-admin-blocks-list g-left" style="float: none !important;">
<h3><?= t("Installed Modules") ?></h3>
<div>
<ul id="g-active-blocks" class="g-sortable-blocks">
@ -48,9 +50,10 @@
</div>
</div>
</div>
<form name="moduleorder" action="<?= url::site("admin/moduleorder/update?csrf={$csrf}") ?>" method="post">
<input type="hidden" name="modulelist" value="">
</form>
</div>
<form name="moduleorder" action="<?= url::site("admin/moduleorder/update?csrf={$csrf}") ?>" method="post">
<input type="hidden" name="modulelist" value="">
</form>
<a class="ui-state-default ui-corner-all" style="padding: 5px;" href="javascript: buildmodulelist()">Save</a>
<a class="ui-state-default ui-corner-all" style="padding: 5px;" href="javascript: buildmodulelist()">Save</a>
<? endif ?>
</div>

View File

@ -1,9 +1,10 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<? $indent_provider = module::get_var("gallery", "identity_provider") ?>
<? foreach ($modules as $ref => $text): ?>
<? if ($text == "gallery" || $text == $indent_provider): ?>
<? $moduleinfo = module::info($text) ?>
<? if ($text == "gallery" || $text == $indent_provider || $moduleinfo->name == ""): ?>
<li style="background-color:#A8A8A8; margin:0.5em; padding:0.3em 0.8em; display: none" ref="<?= $ref ?>"><?= $text ?></li>
<? else: ?>
<li class="g-draggable" ref="<?= $ref ?>"><?= $text ?></li>
<li class="g-draggable" ref="<?= $ref ?>"><?= $moduleinfo->name ?></li>
<? endif ?>
<? endforeach ?>