summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/config/routes.php4
-rw-r--r--modules/gallery/helpers/gallery_event.php12
-rw-r--r--modules/gallery/helpers/gallery_task.php74
3 files changed, 85 insertions, 5 deletions
diff --git a/modules/gallery/config/routes.php b/modules/gallery/config/routes.php
index 63cc6150..8ccd5a01 100644
--- a/modules/gallery/config/routes.php
+++ b/modules/gallery/config/routes.php
@@ -21,6 +21,10 @@
// Admin controllers are not available, except via /admin
$config["^admin_.*"] = null;
+// Redirect /form/add/admin/controller and /form/edit/admin/controller to
+// admin/controller/form_(add|edit)/parms. provides the same as below for admin pages
+$config["^form/(edit|add)/admin/(\w+)/(.*)$"] = "admin/$2/form_$1/$3";
+
// Redirect /form/add and /form/edit to the module/form_(add|edit)/parms.
$config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3";
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 1df3a507..70c6de4a 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -399,18 +399,22 @@ class gallery_event_Core {
static function show_user_profile($data) {
$v = new View("user_profile_info.html");
- $fields = array("name" => t("Name"), "locale" => t("Locale"), "email" => t("Email"),
- "full_name" => t("Full name"), "url" => "Web site");
+ $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)) {
- $v->fields[(string)$label->for_html()] = $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);
+ $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