PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/gallery/controllers/admin_dashboard.php

http://github.com/gallery/gallery3
PHP | 97 lines | 68 code | 11 blank | 18 comment | 7 complexity | a70115eacd567cf5963cecf6da68a1ad MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php defined("SYSPATH") or die("No direct script access.");
  2. /**
  3. * Gallery - a web based photo album viewer and editor
  4. * Copyright (C) 2000-2013 Bharat Mediratta
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. class Admin_Dashboard_Controller extends Admin_Controller {
  21. public function index() {
  22. $view = new Admin_View("admin.html");
  23. $view->page_title = t("Dashboard");
  24. $view->content = new View("admin_dashboard.html");
  25. $view->content->blocks = block_manager::get_html("dashboard_center");
  26. $view->sidebar = "<div id=\"g-admin-dashboard-sidebar\">" .
  27. block_manager::get_html("dashboard_sidebar") .
  28. "</div>";
  29. $view->content->obsolete_modules_message = module::get_obsolete_modules_message();
  30. print $view;
  31. }
  32. public function add_block() {
  33. access::verify_csrf();
  34. $form = gallery_block::get_add_block_form();
  35. if ($form->validate()) {
  36. list ($module_name, $id) = explode(":", $form->add_block->id->value);
  37. $available = block_manager::get_available_admin_blocks();
  38. if ($form->add_block->center->value) {
  39. block_manager::add("dashboard_center", $module_name, $id);
  40. message::success(
  41. t("Added <b>%title</b> block to the dashboard center",
  42. array("title" => $available["$module_name:$id"])));
  43. } else {
  44. block_manager::add("dashboard_sidebar", $module_name, $id);
  45. message::success(
  46. t("Added <b>%title</b> to the dashboard sidebar",
  47. array("title" => $available["$module_name:$id"])));
  48. }
  49. }
  50. url::redirect("admin/dashboard");
  51. }
  52. public function remove_block($id) {
  53. access::verify_csrf();
  54. $blocks_center = block_manager::get_active("dashboard_center");
  55. $blocks_sidebar = block_manager::get_active("dashboard_sidebar");
  56. if (array_key_exists($id, $blocks_sidebar)) {
  57. $deleted = $blocks_sidebar[$id];
  58. block_manager::remove("dashboard_sidebar", $id);
  59. } else if (array_key_exists($id, $blocks_center)) {
  60. $deleted = $blocks_center[$id];
  61. block_manager::remove("dashboard_center", $id);
  62. }
  63. if (!empty($deleted)) {
  64. $available = block_manager::get_available_admin_blocks();
  65. $title = $available[join(":", $deleted)];
  66. message::success(t("Removed <b>%title</b> block", array("title" => $title)));
  67. }
  68. url::redirect("admin");
  69. }
  70. public function reorder() {
  71. access::verify_csrf();
  72. $active_set = array();
  73. foreach (array("dashboard_sidebar", "dashboard_center") as $location) {
  74. foreach (block_manager::get_active($location) as $id => $info) {
  75. $active_set[$id] = $info;
  76. }
  77. }
  78. foreach (array("dashboard_sidebar", "dashboard_center") as $location) {
  79. $new_blocks = array();
  80. foreach (Input::instance()->get($location, array()) as $id) {
  81. $new_blocks[$id] = $active_set[$id];
  82. }
  83. block_manager::set_active($location, $new_blocks);
  84. }
  85. }
  86. }