PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/gallery/helpers/gallery.php

https://github.com/ChrisRut/gallery3
PHP | 117 lines | 49 code | 10 blank | 58 comment | 10 complexity | 3941f7744c391406cb47e9bdeb6a374e 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-2009 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 gallery_Core {
  21. const VERSION = "3.0 git (pre-RC1)";
  22. /**
  23. * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is
  24. * down for maintenance" page.
  25. */
  26. static function maintenance_mode() {
  27. $maintenance_mode = Kohana::config("core.maintenance_mode", false, false);
  28. if (Router::$controller != "login" && !empty($maintenance_mode) && !identity::active_user()->admin) {
  29. Router::$controller = "maintenance";
  30. Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php";
  31. Router::$method = "index";
  32. }
  33. }
  34. /**
  35. * This function is called when the Gallery is fully initialized. We relay it to modules as the
  36. * "gallery_ready" event. Any module that wants to perform an action at the start of every
  37. * request should implement the <module>_event::gallery_ready() handler.
  38. */
  39. static function ready() {
  40. module::event("gallery_ready");
  41. }
  42. /**
  43. * This function is called right before the Kohana framework shuts down. We relay it to modules
  44. * as the "gallery_shutdown" event. Any module that wants to perform an action at the start of
  45. * every request should implement the <module>_event::gallery_shutdown() handler.
  46. */
  47. static function shutdown() {
  48. module::event("gallery_shutdown");
  49. }
  50. /**
  51. * Return a unix timestamp in a user specified format including date and time.
  52. * @param $timestamp unix timestamp
  53. * @return string
  54. */
  55. static function date_time($timestamp) {
  56. return date(module::get_var("gallery", "date_time_format", "Y-M-d H:i:s"), $timestamp);
  57. }
  58. /**
  59. * Return a unix timestamp in a user specified format that's just the date.
  60. * @param $timestamp unix timestamp
  61. * @return string
  62. */
  63. static function date($timestamp) {
  64. return date(module::get_var("gallery", "date_format", "Y-M-d"), $timestamp);
  65. }
  66. /**
  67. * Return a unix timestamp in a user specified format that's just the time.
  68. * @param $timestamp unix timestamp
  69. * @return string
  70. */
  71. static function time($timestamp) {
  72. return date(module::get_var("gallery", "time_format", "H:i:s"), $timestamp);
  73. }
  74. /**
  75. * Provide a wrapper function for Kohana::find_file that first strips the extension and
  76. * then calls the Kohana::find_file and supplies the extension as the type.
  77. * @param string directory to search in
  78. * @param string filename to look for
  79. * @param boolean file required (optional: default false)
  80. * @return array if the extension is config, i18n or l10n
  81. * @return string if the file is found (relative to the DOCROOT)
  82. * @return false if the file is not found
  83. */
  84. static function find_file($directory, $file, $required=false) {
  85. $file_name = substr($file, 0, -strlen($ext = strrchr($file, '.')));
  86. $file_name = Kohana::find_file($directory, $file_name, $required, substr($ext, 1));
  87. if (!$file_name) {
  88. if (file_exists(DOCROOT . "lib/$directory/$file")) {
  89. return "lib/$directory/$file";
  90. } else if (file_exists(DOCROOT . "lib/$file")) {
  91. return "lib/$file";
  92. }
  93. }
  94. if (is_string($file_name)) {
  95. // make relative to DOCROOT
  96. $parts = explode("/", $file_name);
  97. foreach ($parts as $idx => $part) {
  98. if (in_array($part, array("application", "modules", "themes", "lib"))) {
  99. break;
  100. }
  101. unset($parts[$idx]);
  102. }
  103. $file_name = implode("/", $parts);
  104. }
  105. return $file_name;
  106. }
  107. }