diff options
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 26 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 74 | ||||
-rw-r--r-- | modules/gallery/helpers/locales.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/module.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/user_profile.php | 54 |
5 files changed, 154 insertions, 6 deletions
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 6175e049..b35ae3c4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -111,11 +111,11 @@ class gallery_event_Core { ->label(t("Login"))); } else { $csrf = access::csrf_token(); - $menu->append(Menu::factory("dialog") + $menu->append(Menu::factory("link") ->id("user_menu_edit_profile") ->css_id("g-user-profile-link") ->view("login_current_user.html") - ->url(url::site("form/edit/user/{$user->id}")) + ->url(user_profile::url($user->id)) ->label($user->display_name())); $menu->append(Menu::factory("link") ->id("user_menu_logout") @@ -377,4 +377,26 @@ class gallery_event_Core { } } } + + static function show_user_profile($data) { + $v = new View("user_profile_info.html"); + + $fields = array("name" => t("Name"), "locale" => t("Language Preference"), + "email" => t("Email"), "full_name" => t("Full name"), "url" => "Web site"); + if (!$data->display_all) { + $fields = array("name" => t("Name"), "full_name" => t("Full name"), "url" => "Web site"); + } + $v->fields = array(); + foreach ($fields as $field => $label) { + if (!empty($data->user->$field)) { + $value = $data->user->$field; + if ($field == "locale") { + $value = locales::display_name($value); + } + $v->fields[(string) $label] = html::clean($value); + } + } + $data->content[] = (object) array("title" => t("User information"), "view" => $v); + + } } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index b3b79e06..5402b5d1 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -37,6 +37,11 @@ class gallery_task_Core { ->description(t("Download new and updated translated strings")) ->severity(log::SUCCESS); + $tasks[] = Task_Definition::factory() + ->callback("gallery_task::file_cleanup") + ->name(t("Remove old files")) + ->description(t("Remove files from the logs and tmp directory")) + ->severity(log::SUCCESS); return $tasks; } @@ -116,7 +121,7 @@ class gallery_task_Core { } } - static function update_l10n(&$task) { + static function update_l10n($task) { $errors = array(); try { $start = microtime(true); @@ -218,4 +223,71 @@ class gallery_task_Core { $task->log($errors); } } + + /** + * Task that removes old files from var/logs and var/tmp. + * @param Task_Model the task + */ + static function file_cleanup($task) { + $errors = array(); + try { + $start = microtime(true); + $data = Cache::instance()->get("file_cleanup_cache:{$task->id}"); + if ($data) { + $files = unserialize($data); + } + $i = 0; + + switch ($task->get("mode", "init")) { + case "init": // 0% + $threshold = time() - 1209600; // older than 2 weeks + foreach(array("logs", "tmp") as $dir) { + $dir = VARPATH . $dir; + if ($dh = opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if ($file[0] == ".") { + continue; + } + + if (filemtime("$dir/$file") <= $threshold) { + $files[] = "$dir/$file"; + } + } + } + } + $task->set("mode", "delete_files"); + $task->set("current", 0); + $task->set("total", count($files)); + Cache::instance()->set("file_cleanup_cache:{$task->id}", serialize($files)); + if (count($files) == 0) { + break; + } + case "delete_files": + $current = $task->get("current"); + $total = $task->get("total"); + while ($current < $total && microtime(true) - $start < 1) { + @unlink($files[$current]); + $task->log(t("%file removed", array("file" => $files[$current++]))); + } + $task->percent_complete = $current / $total * 100; + $task->set("current", $current); + } + + $task->status = t("Removed: %count files. Total: %total_count.", + array("count" => $current, "total_count" => $total)); + + if ($total == $current) { + $task->done = true; + $task->state = "success"; + } + } catch (Exception $e) { + $task->done = true; + $task->state = "error"; + $task->status = $e->getMessage(); + $errors[] = $e->__toString(); + } + if ($errors) { + $task->log($errors); + } + } }
\ No newline at end of file diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index 8d76e333..5c8c227a 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -41,7 +41,7 @@ class locales_Core { $default = module::get_var("gallery", "default_locale"); $codes = explode("|", module::get_var("gallery", "installed_locales", $default)); foreach ($codes as $code) { - if (isset($available->$code)) { + if (isset($available[$code])) { $installed[$code] = $available[$code]; } } @@ -127,7 +127,7 @@ class locales_Core { } $locale or $locale = Gallery_I18n::instance()->locale(); - return self::$locales["$locale"]; + return self::$locales[$locale]; } static function is_rtl($locale=null) { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index f680ff6a..95e426c4 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -98,7 +98,7 @@ class module_Core { $m->active = self::is_active($module_name); $m->code_version = $m->version; $m->version = self::get_version($module_name); - $m->locked = !empty($m->no_module_admin); + $m->locked = false; } // Lock certain modules diff --git a/modules/gallery/helpers/user_profile.php b/modules/gallery/helpers/user_profile.php new file mode 100644 index 00000000..95a994bc --- /dev/null +++ b/modules/gallery/helpers/user_profile.php @@ -0,0 +1,54 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 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 user_profile_Core { + /** + * Generate the url to display the profile + * @return url for the profile display + */ + static function url($user_id) { + return url::site("user_profile/show/{$user_id}"); + } + + static function get_contact_form($user) { + $form = new Forge("user_profile/send/{$user->id}", "", "post", + array("id" => "g-user-profile-contact-form")); + $group = $form->group("message") + ->label(t("Compose message to %name", array("name" => $user->display_name()))); + $group->input("reply_to") + ->label(t("From:")) + ->rules("required|length[1, 256]|valid_email") + ->error_messages("required", t("Field is required")) + ->error_messages("max_length", t("Field exceeds 256 bytes")) + ->error_messages("valid_email", t("Field is not a valid email address")); + $group->input("subject") + ->label(t("Subject:")) + ->rules("required|length[1, 256]") + ->error_messages("required", t("Field is required")) + ->error_messages("max_length", t("Field exceeds 256 bytes")); + $group->textarea("message") + ->label(t("Message:")) + ->rules("required") + ->error_messages("required", t("Field is required")); + module::event("user_profile_contact_form", $form); + $group->submit("")->value(t("Send")); + return $form; + } +} |