mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-07-11 01:33:51 -04:00
Refactor dashboard -> block_manager since it'll manage blocks site
wide, not just in the dashboard.
This commit is contained in:
@@ -27,8 +27,8 @@ class Admin_Dashboard_Controller extends Admin_Controller {
|
||||
$block_adder->content = $this->get_add_block_form();
|
||||
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = dashboard::get_blocks($blocks["main"]);
|
||||
$view->sidebar = $block_adder . dashboard::get_blocks($blocks["sidebar"]);
|
||||
$view->content = block_manager::get_html("dashboard_center");
|
||||
$view->sidebar = $block_adder . block_manager::get_html("dashboard_sidebar");
|
||||
print $view;
|
||||
}
|
||||
|
||||
@@ -36,16 +36,16 @@ class Admin_Dashboard_Controller extends Admin_Controller {
|
||||
$form = $this->get_add_block_form();
|
||||
if ($form->validate()) {
|
||||
list ($module_name, $block_id) = explode(":", $form->add_block->id->value);
|
||||
$blocks = dashboard::get_active();
|
||||
$available = dashboard::get_available();
|
||||
$blocks = block_manager::get_active();
|
||||
$available = block_manager::get_available();
|
||||
|
||||
if ($form->add_block->center->value) {
|
||||
dashboard::add_block("main", $module_name, $block_id);
|
||||
block_manager::add("dashboard_center", $module_name, $block_id);
|
||||
message::success(
|
||||
t("Added <b>%title</b> block to the main dashboard area",
|
||||
t("Added <b>%title</b> block to the dashboard center",
|
||||
array("title" => $available["$module_name:$id"])));
|
||||
} else {
|
||||
dashboard::add_block("sidebar", $module_name, $block_id);
|
||||
block_manager::add("dashboard_sidebar", $module_name, $block_id);
|
||||
message::success(
|
||||
t("Added <b>%title</b> to the dashboard sidebar",
|
||||
array("title" => $available["$module_name:$id"])));
|
||||
@@ -56,17 +56,17 @@ class Admin_Dashboard_Controller extends Admin_Controller {
|
||||
|
||||
public function remove_block($id) {
|
||||
access::verify_csrf();
|
||||
$blocks = dashboard::get_active();
|
||||
$blocks = block_manager::get_active();
|
||||
if (array_key_exists($id, $blocks["sidebar"])) {
|
||||
$deleted = $blocks["sidebar"][$id];
|
||||
dashboard::remove_block("sidebar", $id);
|
||||
block_manager::remove("dashboard_sidebar", $id);
|
||||
} else if (array_key_exists($id, $blocks["main"])) {
|
||||
$deleted = $blocks["main"][$id];
|
||||
dashboard::remove_block("main", $id);
|
||||
block_manager::remove("dashboard_main", $id);
|
||||
}
|
||||
|
||||
if (!empty($deleted)) {
|
||||
$available = dashboard::get_available();
|
||||
$available = block_manager::get_available();
|
||||
$title = $available[join(":", $deleted)];
|
||||
message::success(t("Removed <b>%title</b> block", array("title" => $title)));
|
||||
}
|
||||
@@ -77,10 +77,9 @@ class Admin_Dashboard_Controller extends Admin_Controller {
|
||||
public function get_add_block_form() {
|
||||
$form = new Forge("admin/dashboard/add_block", "", "post");
|
||||
$group = $form->group("add_block")->label(t("Add Block"));
|
||||
$group->dropdown("id")->label("Available Blocks")->options(dashboard::get_available());
|
||||
$group->dropdown("id")->label("Available Blocks")->options(block_manager::get_available());
|
||||
$group->submit("center")->value(t("Add to center"));
|
||||
$group->submit("sidebar")->value(t("Add to sidebar"));
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,30 +17,30 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class dashboard_Core {
|
||||
class block_manager_Core {
|
||||
static function get_active() {
|
||||
return unserialize(module::get_var("core", "dashboard_blocks", "a:0:{}"));
|
||||
return unserialize(module::get_var("core", "blocks", "a:0:{}"));
|
||||
}
|
||||
|
||||
static function add_block($location, $module_name, $block_id) {
|
||||
static function add($location, $module_name, $block_id) {
|
||||
$blocks = self::get_active();
|
||||
$blocks[$location][rand()] = array($module_name, $block_id);
|
||||
module::set_var("core", "dashboard_blocks", serialize($blocks));
|
||||
module::set_var("core", "blocks", serialize($blocks));
|
||||
}
|
||||
|
||||
static function remove_block($location, $block_id) {
|
||||
static function remove($location, $block_id) {
|
||||
$blocks = self::get_active();
|
||||
unset($blocks[$location][$block_id]);
|
||||
unset($blocks[$location][$block_id]);
|
||||
module::set_var("core", "dashboard_blocks", serialize($blocks));
|
||||
module::set_var("core", "blocks", serialize($blocks));
|
||||
}
|
||||
|
||||
static function get_available() {
|
||||
$blocks = array();
|
||||
|
||||
foreach (module::installed() as $module) {
|
||||
if (method_exists("{$module->name}_dashboard", "get_list")) {
|
||||
foreach (call_user_func(array("{$module->name}_dashboard", "get_list")) as $id => $title) {
|
||||
$class_name = "{$module->name}_block";
|
||||
if (method_exists($class_name, "get_list")) {
|
||||
foreach (call_user_func(array($class_name, "get_list")) as $id => $title) {
|
||||
$blocks["{$module->name}:$id"] = $title;
|
||||
}
|
||||
}
|
||||
@@ -48,11 +48,15 @@ class dashboard_Core {
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
static function get_blocks($blocks) {
|
||||
$result = "";
|
||||
foreach ($blocks as $id => $desc) {
|
||||
if (method_exists("$desc[0]_dashboard", "get_block")) {
|
||||
$block = call_user_func(array("$desc[0]_dashboard", "get_block"), $desc[1]);
|
||||
static function get_html($location) {
|
||||
$active = self::get_active();
|
||||
if (empty($active[$location])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($active[$location] as $id => $desc) {
|
||||
if (method_exists("$desc[0]_block", "get")) {
|
||||
$block = call_user_func(array("$desc[0]_block", "get"), $desc[1]);
|
||||
$block->id = $id;
|
||||
$result .= $block;
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class core_dashboard_Core {
|
||||
class core_block_Core {
|
||||
static function get_list() {
|
||||
return array(
|
||||
"welcome" => t("Welcome to Gallery 3!"),
|
||||
@@ -28,7 +28,7 @@ class core_dashboard_Core {
|
||||
"project_news" => t("Gallery Project News"));
|
||||
}
|
||||
|
||||
static function get_block($block_id) {
|
||||
static function get($block_id) {
|
||||
$block = new Block();
|
||||
switch($block_id) {
|
||||
case "welcome":
|
||||
@@ -234,12 +234,12 @@ class core_installer {
|
||||
$theme->save();
|
||||
}
|
||||
|
||||
dashboard::add_block("sidebar", "core", "stats");
|
||||
dashboard::add_block("sidebar", "core", "platform_info");
|
||||
dashboard::add_block("sidebar", "core", "project_news");
|
||||
dashboard::add_block("main", "core", "welcome");
|
||||
dashboard::add_block("main", "core", "photo_stream");
|
||||
dashboard::add_block("main", "core", "log_entries");
|
||||
block_manager::add("dashboard_sidebar", "core", "stats");
|
||||
block_manager::add("dashboard_sidebar", "core", "platform_info");
|
||||
block_manager::add("dashboard_sidebar", "core", "project_news");
|
||||
block_manager::add("dashboard_center", "core", "welcome");
|
||||
block_manager::add("dashboard_center", "core", "photo_stream");
|
||||
block_manager::add("dashboard_center", "core", "log_entries");
|
||||
|
||||
module::set_version("core", 1);
|
||||
module::set_var("core", "version", "3.0");
|
||||
|
||||
@@ -166,7 +166,7 @@
|
||||
<?= html::script("lib/jquery.cookie.js") ?>
|
||||
<?= html::script("lib/jquery.MultiFile.js") ?>
|
||||
<? if (module::is_installed("rearrange")): ?>
|
||||
<?= rearrange_block::head(null) ?>
|
||||
<?= rearrange_theme::head(null) ?>
|
||||
<? endif ?>
|
||||
</head>
|
||||
<body>
|
||||
@@ -485,7 +485,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="package" class="activity">
|
||||
<?= $package ?>
|
||||
</div>
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class comment_dashboard_Core {
|
||||
class comment_block_Core {
|
||||
static function get_list() {
|
||||
return array("recent_comments" => t("Recent Comments"));
|
||||
}
|
||||
|
||||
static function get_block($block_id) {
|
||||
static function get($block_id) {
|
||||
$block = new Block();
|
||||
switch ($block_id) {
|
||||
case "recent_comments":
|
||||
@@ -50,7 +50,7 @@ class comment_installer {
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
|
||||
|
||||
dashboard::add_block("main", "comment", "recent_comments");
|
||||
block_manager::add("dashboard_center", "comment", "recent_comments");
|
||||
module::set_var("comment", "spam_caught", 0);
|
||||
module::set_version("comment", 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user