PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/3.0/modules/ratings/controllers/admin_ratings.php

https://github.com/tbleher/gallery3-contrib
PHP | 140 lines | 94 code | 14 blank | 32 comment | 8 complexity | d79abfeb193d1f786d16243f6aac56f0 MD5 | raw file
  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-2012 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_Ratings_Controller extends Admin_Controller {
  21. public function index() {
  22. // Generate a new admin page.
  23. $view = new Admin_View("admin.html");
  24. $view->content = new View("admin_ratings.html");
  25. $view->content->ratings_form = $this->_get_admin_form();
  26. print $view;
  27. }
  28. public function saveprefs() {
  29. // Prevent Cross Site Request Forgery
  30. access::verify_csrf();
  31. // Save Settings.
  32. module::set_var("ratings", "showunderphoto", Input::instance()->post("showunderphoto"));
  33. module::set_var("ratings", "showinsidebar", Input::instance()->post("showinsidebar"));
  34. module::set_var("ratings", "imageword", Input::instance()->post("imageword"));
  35. module::set_var("ratings", "votestring", Input::instance()->post("votestring"));
  36. module::set_var("ratings", "castyourvotestring", Input::instance()->post("castyourvotestring"));
  37. # module::set_var("ratings", "bgcolor", Input::instance()->post("bgcolor"));
  38. module::set_var("ratings", "fillcolor", Input::instance()->post("fillcolor"));
  39. module::set_var("ratings", "votedcolor", Input::instance()->post("votedcolor"));
  40. module::set_var("ratings", "hovercolor", Input::instance()->post("hovercolor"));
  41. module::set_var("ratings", "textcolor", Input::instance()->post("textcolor"));
  42. module::set_var("ratings", "regonly", Input::instance()->post("regonly"));
  43. $iconset = Input::instance()->post("iconset");
  44. $iconset = preg_replace("/\/index\.php/","",$iconset);
  45. module::set_var("ratings", "iconset", $iconset);
  46. message::success(t("Your Settings Have Been Saved."));
  47. site_status::clear("ratings_configuration");
  48. // Load Admin page.
  49. $view = new Admin_View("admin.html");
  50. $view->content = new View("admin_ratings.html");
  51. $view->content->ratings_form = $this->_get_admin_form();
  52. print $view;
  53. }
  54. private function _get_admin_form() {
  55. if($showunderphoto = module::get_var("ratings", "showunderphoto")){ $showunderphoto = 1; };
  56. if($showinsidebar = module::get_var("ratings", "showinsidebar")){ $showinsidebar = 1; };
  57. if(!$fillcolor = module::get_var("ratings","fillcolor")){ $fillcolor = "#FF0000"; }
  58. if(!$votedcolor = module::get_var("ratings","votedcolor")){ $votedcolor = "#0069FF"; }
  59. if(!$hovercolor = module::get_var("ratings","hovercolor")){ $hovercolor = "#FFA800"; }
  60. if(!$castyourvotestring = module::get_var("ratings","castyourvotestring")){ $castyourvotestring="Click on a heart to cast your vote:"; }
  61. $iconsets[url::file("modules/ratings/vendor/img/")."hearts.png"] = 1;
  62. $iconsets[url::file("modules/ratings/vendor/img/")."filmstrip.png"] = 2;
  63. $iconsets[url::file("modules/ratings/vendor/img/")."stars.png"] = 3;
  64. $iconsets[url::file("modules/ratings/vendor/img/")."camera.png"] = 4;
  65. $regonlyvote[1] = "true";
  66. $regonlyvote[0] = "false";
  67. // Make a new Form.
  68. $form = new Forge("admin/ratings/saveprefs", "", "post",
  69. array("id" => "g-ratings-api-adminForm"));
  70. // Set up some text boxes for the site owners Name, email and the
  71. // text for the contact link.
  72. $ratings_form = $form->group("RatingsBlockSettings");
  73. $ratings_form->dropdown("regonly")
  74. ->label(t("Allow only registered users to vote"))
  75. ->options($regonlyvote)
  76. ->selected(module::get_var("ratings","regonly"));
  77. $ratings_form->dropdown("iconset")
  78. ->label(t("Choose an Icon Set"))
  79. ->options($iconsets)
  80. ->selected(module::get_var("ratings","iconset"));
  81. # $ratings_form->input("bgcolor")
  82. # ->label(t("Background Color (behind icon set) [-- not yet working --]"))
  83. # ->class("js_color {hash:true}")
  84. # ->value(module::get_var("ratings","bgcolor"));
  85. $ratings_form->input("fillcolor")
  86. ->label(t("Fill Color"))
  87. ->class("js_color {hash:true}")
  88. ->value(module::get_var("ratings","fillcolor"));
  89. $ratings_form->input("hovercolor")
  90. ->label(t("Hover Fill Color"))
  91. ->class("js_color {hash:true}")
  92. ->value(module::get_var("ratings","hovercolor"));
  93. $ratings_form->input("votedcolor")
  94. ->label(t("Once Voted Fill Color"))
  95. ->class("js_color {hash:true}")
  96. ->value(module::get_var("ratings","votedcolor"));
  97. $ratings_form->checkbox("showunderphoto")
  98. ->label(t("Show block under photo"))
  99. ->class("g-unique g-button-text")
  100. ->checked($showunderphoto);
  101. $ratings_form->checkbox("showinsidebar")
  102. ->label(t("Show block in the sidebar"))
  103. ->class("g-unique g-button-text")
  104. ->checked($showinsidebar);
  105. $ratings_form->input("imageword")
  106. ->label(t("Word to descibe the rating icon (IE: heart or star or filmstrip)"))
  107. ->class("g-button-text")
  108. ->value(module::get_var("ratings", "imageword"));
  109. $ratings_form->input("votestring")
  110. ->label(t("Word for 'vote'"))
  111. ->class("g-button-text")
  112. ->value(module::get_var("ratings", "votestring"));
  113. $ratings_form->input("castyourvotestring")
  114. ->label(t("Wording for 'Click on a heart to cast your vote:'"))
  115. ->class("g-button-text")
  116. ->value(module::get_var("ratings", "castyourvotestring"));
  117. $ratings_form->input("textcolor")
  118. ->label(t("Text Color"))
  119. ->class("js_color {hash:true}")
  120. ->value(module::get_var("ratings","textcolor"));
  121. // Add a save button to the form.
  122. $form->submit("SaveSettings")->value(t("Save"));
  123. // Return the newly generated form.
  124. return $form;
  125. }
  126. }