From 27be4ae6064b8609a641f4bf239999d5a8ec2c60 Mon Sep 17 00:00:00 2001
From: shadlaws
Date: Sun, 10 Feb 2013 10:10:44 +0100
Subject: Follow-on to 0312d1b071bd4434ddb3f82888b0323da6bf3732 for #1994. -
Updated function comments to match revisions. - No functional changes.
---
modules/gallery/helpers/movie.php | 4 +---
modules/gallery/helpers/photo.php | 6 ++----
2 files changed, 3 insertions(+), 7 deletions(-)
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index d4b907a2..637d8ac0 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -138,9 +138,7 @@ class movie_Core {
* -> return metadata from ffmpeg
* Input is *not* standard movie type that is *not* supported by ffmpeg but is legal
* -> return zero width, height, and duration; mime type and extension according to legal_file
- * Input is *not* standard movie type that is *not* supported by ffmpeg and is *not* legal
- * -> return zero width, height, and duration; null mime type and extension
- * Input is not readable or does not exist
+ * Input is illegal, unidentifiable, unreadable, or does not exist
* -> throw exception
* Note: movie_get_file_metadata events can change any of the above cases (except the last one).
*/
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index 2d32f0d3..004cc7c4 100644
--- a/modules/gallery/helpers/photo.php
+++ b/modules/gallery/helpers/photo.php
@@ -94,10 +94,8 @@ class photo_Core {
* Input is *not* standard photo type that is supported by getimagesize (e.g. tif, bmp...)
* -> return metadata from getimagesize()
* Input is *not* standard photo type that is *not* supported by getimagesize but is legal
- * -> return zero width and height, mime type and extension according to legal_file
- * Input is *not* standard photo type that is *not* supported by getimagesize and is *not* legal
- * -> return zero width and height, null mime type and extension
- * Input is not readable or does not exist
+ * -> return metadata if found by photo_get_file_metadata events
+ * Input is illegal, unidentifiable, unreadable, or does not exist
* -> throw exception
* Note: photo_get_file_metadata events can change any of the above cases (except the last one).
*/
--
cgit v1.2.3
From f212f6a794c4aff96446b99e4824a9e2c8cfb259 Mon Sep 17 00:00:00 2001
From: shadlaws
Date: Thu, 14 Feb 2013 23:42:20 +0100
Subject: #2003 - Add admin/movies screen. Added admin/movies screen analogous
to the admin/graphics screen so the user can: - see how FFmpeg is configured
(path and version, similar to toolkits in admin/graphics) - get some
instructions on how to install FFmpeg if not found - change the
movie_allow_uploads setting - ask Gallery to rebuild their movie thumbs
Specifics: - admin_movies, admin_movies.html (new) - new Movies admin screen
- ffmpeg.png (new) - logo for admin screen - movie::get_ffmpeg_version (new)
- return version number and date of FFmpeg - form_uploadify.html - change
admin message if movie uploads are disabled - gallery_event::admin_menu -
added Movies link to Settings - xss_data.txt - updated golden file for unit
tests
---
modules/gallery/controllers/admin_movies.php | 72 ++++++++++++++++++++++++++
modules/gallery/helpers/gallery_event.php | 4 ++
modules/gallery/helpers/movie.php | 28 ++++++++++
modules/gallery/images/ffmpeg.png | Bin 0 -> 2888 bytes
modules/gallery/tests/xss_data.txt | 1 +
modules/gallery/views/admin_movies.html.php | 44 ++++++++++++++++
modules/gallery/views/form_uploadify.html.php | 2 +-
7 files changed, 150 insertions(+), 1 deletion(-)
create mode 100644 modules/gallery/controllers/admin_movies.php
create mode 100644 modules/gallery/images/ffmpeg.png
create mode 100644 modules/gallery/views/admin_movies.html.php
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/controllers/admin_movies.php b/modules/gallery/controllers/admin_movies.php
new file mode 100644
index 00000000..38fa44a5
--- /dev/null
+++ b/modules/gallery/controllers/admin_movies.php
@@ -0,0 +1,72 @@
+_get_admin_form();
+ $this->_print_view($form);
+ }
+
+ public function save() {
+ access::verify_csrf();
+ $form = $this->_get_admin_form();
+ if ($form->validate()) {
+ module::set_var("gallery", "movie_allow_uploads", $form->settings->allow_uploads->value);
+ if ($form->settings->rebuild_thumbs->value) {
+ graphics::mark_dirty(true, false, "movie");
+ }
+ // All done - redirect with message.
+ message::success(t("Movies settings updated successfully"));
+ url::redirect("admin/movies");
+ }
+ // Something went wrong - print view from existing form.
+ $this->_print_view($form);
+ }
+
+ private function _print_view($form) {
+ list ($ffmpeg_version, $ffmpeg_date) = movie::get_ffmpeg_version();
+ $ffmpeg_version = $ffmpeg_date ? "{$ffmpeg_version} ({$ffmpeg_date})" : $ffmpeg_version;
+ $ffmpeg_path = movie::find_ffmpeg();
+ $ffmpeg_dir = substr($ffmpeg_path, 0, strrpos($ffmpeg_path, "/"));
+
+ $view = new Admin_View("admin.html");
+ $view->page_title = t("Movies settings");
+ $view->content = new View("admin_movies.html");
+ $view->content->form = $form;
+ $view->content->ffmpeg_dir = $ffmpeg_dir;
+ $view->content->ffmpeg_version = $ffmpeg_version;
+ print $view;
+ }
+
+ private function _get_admin_form() {
+ $form = new Forge("admin/movies/save", "", "post", array("id" => "g-movies-admin-form"));
+ $group = $form->group("settings")->label(t("Settings"));
+ $group->dropdown("allow_uploads")
+ ->label(t("Allow movie uploads into Gallery (does not affect existing movies)"))
+ ->options(array("autodetect"=>t("only if FFmpeg is detected (default)"),
+ "always"=>t("always"), "never"=>t("never")))
+ ->selected(module::get_var("gallery", "movie_allow_uploads", "autodetect"));
+ $group->checkbox("rebuild_thumbs")
+ ->label(t("Rebuild all movie thumbnails (once FFmpeg is installed, use this to update existing movie thumbnails)"))
+ ->checked(false); // always set as false
+ $form->submit("save")->value(t("Save"));
+ return $form;
+ }
+}
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index aeb1c7eb..54c60296 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -398,6 +398,10 @@ class gallery_event_Core {
->id("graphics_toolkits")
->label(t("Graphics"))
->url(url::site("admin/graphics")))
+ ->append(Menu::factory("link")
+ ->id("movies_settings")
+ ->label(t("Movies"))
+ ->url(url::site("admin/movies")))
->append(Menu::factory("link")
->id("languages")
->label(t("Languages"))
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index 863e1cf9..aff2acc1 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -146,6 +146,34 @@ class movie_Core {
return $ffmpeg_path;
}
+ /**
+ * Return version number and build date of ffmpeg if found, empty string(s) if not. When using
+ * static builds that aren't official releases, the version numbers are strange, hence why the
+ * date can be useful.
+ */
+ static function get_ffmpeg_version() {
+ $ffmpeg = movie::find_ffmpeg();
+ if (empty($ffmpeg)) {
+ return array("", "");
+ }
+
+ // Find version using -h argument since -version wasn't available in early versions.
+ // To keep the preg_match searches quick, we'll trim the (otherwise long) result.
+ $cmd = escapeshellcmd($ffmpeg) . " -h 2>&1";
+ $result = substr(`$cmd`, 0, 1000);
+ if (preg_match("/ffmpeg version (\S+)/i", $result, $matches_version)) {
+ // Version number found - see if we can get the build date or copyright year as well.
+ if (preg_match("/built on (\S+\s\S+\s\S+)/i", $result, $matches_build_date)) {
+ return array(trim($matches_version[1], ","), trim($matches_build_date[1], ","));
+ } else if (preg_match("/copyright \S*\s?2000-(\d{4})/i", $result, $matches_copyright_date)) {
+ return array(trim($matches_version[1], ","), $matches_copyright_date[1]);
+ } else {
+ return array(trim($matches_version[1], ","), "");
+ }
+ }
+ return array("", "");
+ }
+
/**
* Return the width, height, mime_type, extension and duration of the given movie file.
* Metadata is first generated using ffmpeg (or set to defaults if it fails),
diff --git a/modules/gallery/images/ffmpeg.png b/modules/gallery/images/ffmpeg.png
new file mode 100644
index 00000000..6be8b62a
Binary files /dev/null and b/modules/gallery/images/ffmpeg.png differ
diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt
index 51347f86..67a8b948 100644
--- a/modules/gallery/tests/xss_data.txt
+++ b/modules/gallery/tests/xss_data.txt
@@ -111,6 +111,7 @@ modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY_ATTR $css
modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY $message
modules/gallery/views/admin_modules_confirm.html.php 16 DIRTY access::csrf_form_field()
modules/gallery/views/admin_modules_confirm.html.php 18 DIRTY form::hidden($module,1)
+modules/gallery/views/admin_movies.html.php 43 DIRTY $form
modules/gallery/views/admin_sidebar.html.php 50 DIRTY $available
modules/gallery/views/admin_sidebar.html.php 58 DIRTY $active
modules/gallery/views/admin_sidebar_blocks.html.php 4 DIRTY_ATTR $ref
diff --git a/modules/gallery/views/admin_movies.html.php b/modules/gallery/views/admin_movies.html.php
new file mode 100644
index 00000000..e7810711
--- /dev/null
+++ b/modules/gallery/views/admin_movies.html.php
@@ -0,0 +1,44 @@
+
+
+
= t("Movies settings") ?>
+
+ = t("Gallery comes with everything it needs to upload and play movies.") ?>
+ = t("However, it needs the FFmpeg toolkit to extract thumbnails and size information from them.") ?>
+
+
+ = t("Although popular, FFmpeg is not installed on all Linux systems.") ?>
+ = t("To use FFmpeg without fully installing it, download a pre-compiled, static build of FFmpeg from one of the links here.", array("url" => "http://ffmpeg.org/download.html")) ?>
+ = t("Then, put the \"ffmpeg\" file in Gallery's \"bin\" directory (e.g. \"/gallery/bin\"), where Gallery will auto-detect it.") ?>
+
+
+ = t("Movies will work without FFmpeg, but their thumbnails will be placeholders.") ?>
+
+
+ = t("Can't get FFmpeg configured on your system? We can help!",
+ array("url" => "http://codex.galleryproject.org/Gallery3:FAQ#Why_does_it_say_I.27m_missing_ffmpeg.3F")) ?>
+
+ = t("FFmpeg is a cross-platform standalone audio/video program.") ?>
+ = t("Please refer to the FFmpeg website for more information.", array("url" => "http://ffmpeg.org")) ?>
+
+
+ if ($ffmpeg_dir): ?>
+ if ($ffmpeg_version): ?>
+
= t("FFmpeg version %version was found in %dir", array("version" => $ffmpeg_version, "dir" => $ffmpeg_dir)) ?>
+ else: ?>
+
= t("FFmpeg (of unknown version) was found in %dir", array("dir" => $ffmpeg_dir)) ?>
+ endif ?>
+ else: ?>
+
= t("We could not locate FFmpeg on your system.") ?>
+ endif ?>
+
+
+
+
+ = $form ?>
+
diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php
index 4426514a..c13e3418 100644
--- a/modules/gallery/views/form_uploadify.html.php
+++ b/modules/gallery/views/form_uploadify.html.php
@@ -131,7 +131,7 @@
if (identity::active_user()->admin && !$movies_allowed): ?>
- = t("Can't find ffmpeg on your system. Movie uploading disabled. Help!", array("help_url" => "http://codex.galleryproject.org/Gallery3:FAQ#Why_does_it_say_I.27m_missing_ffmpeg.3F")) ?>
+ = t("Movie uploading is disabled on your system. Help!", array("help_url" => url::site("admin/movies"))) ?>
endif ?>
--
cgit v1.2.3
From 7bdccade98e76df3a7830bc45bc42321a77c709a Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Fri, 15 Feb 2013 19:09:06 -0500
Subject: Every 500th request prune a single old file from var/tmp and
var/logs. Might not be aggressive enough. Fixes #2005.
---
modules/gallery/helpers/gallery_event.php | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 54c60296..eb54e521 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -36,6 +36,34 @@ class gallery_event_Core {
locales::set_request_locale();
}
+ static function gallery_shutdown() {
+ // Every 500th request, do a pass over var/logs and var/tmp and delete old files.
+ // Limit ourselves to deleting a single file so that we don't spend too much CPU
+ // time on it. As long as servers call this at least twice a day they'll eventually
+ // wind up with a clean var/logs directory because we only create 1 file a day there.
+ // var/tmp might be stickier because theoretically we could wind up spamming that
+ // dir with a lot of files. But let's start with this and refine as we go.
+ if (!(rand() % 500)) {
+ // Note that this code is roughly duplicated in gallery_event::gallery_shutdown
+ $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) {
+ unlink("$dir/$file");
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
static function user_deleted($user) {
$admin = identity::admin_user();
if (!empty($admin)) { // could be empty if there is not identity provider
--
cgit v1.2.3
From 0dd12caa6f4c0452167b0e621a01bee28e71b0af Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Fri, 15 Feb 2013 19:12:08 -0500
Subject: Follow-on to 7bdccade98e76df3a7830bc45bc42321a77c709a - point out
that there's duplicated code in gallery_event.
---
modules/gallery/helpers/gallery_task.php | 1 +
1 file changed, 1 insertion(+)
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 856d2639..37de2f93 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -281,6 +281,7 @@ class gallery_task_Core {
switch ($task->get("mode", "init")) {
case "init":
$threshold = time() - 1209600; // older than 2 weeks
+ // Note that this code is roughly duplicated in gallery_event::gallery_shutdown
foreach(array("logs", "tmp") as $dir) {
$dir = VARPATH . $dir;
if ($dh = opendir($dir)) {
--
cgit v1.2.3
From 96ad7789c84b5b81320f9cb94b4c8cb4e10ad92f Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Fri, 15 Feb 2013 16:15:40 -0800
Subject: Follow-on to 7bdccade98e76df3a7830bc45bc42321a77c709a to exclude
directories for now.
---
modules/gallery/helpers/gallery_event.php | 5 +++++
modules/gallery/helpers/gallery_task.php | 5 +++++
2 files changed, 10 insertions(+)
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index eb54e521..26432ef5 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -54,6 +54,11 @@ class gallery_event_Core {
continue;
}
+ // Ignore directories for now, but we should really address them in the long term.
+ if (is_dir("$dir/$file")) {
+ continue;
+ }
+
if (filemtime("$dir/$file") <= $threshold) {
unlink("$dir/$file");
break;
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 37de2f93..a79cb2d5 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -290,6 +290,11 @@ class gallery_task_Core {
continue;
}
+ // Ignore directories for now, but we should really address them in the long term.
+ if (is_dir("$dir/$file")) {
+ continue;
+ }
+
if (filemtime("$dir/$file") <= $threshold) {
$files[] = "$dir/$file";
}
--
cgit v1.2.3
From fd0051dab7258c817ff01877bd4324530ce79398 Mon Sep 17 00:00:00 2001
From: shadlaws
Date: Sun, 17 Feb 2013 23:19:35 +0100
Subject: #2006 - Add system::mark_file_for_delete API to delete files at
shutdown. - added system::mark_file_for_delete to be called to mark a file -
added system::delete_marked_files to be called at shutdown to delete the list
- amended system::temp_filename to, by default, add the temp name to the list
- updated a few other places in code where this should be used
---
modules/gallery/controllers/quick.php | 1 -
modules/gallery/controllers/uploader.php | 2 +-
modules/gallery/helpers/gallery_event.php | 4 ++-
modules/gallery/helpers/system.php | 32 ++++++++++++++++++++--
modules/rest/controllers/rest.php | 2 +-
modules/watermark/controllers/admin_watermarks.php | 6 ++--
6 files changed, 38 insertions(+), 9 deletions(-)
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index 2ddf2a4b..4b21d9ee 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -41,7 +41,6 @@ class Quick_Controller extends Controller {
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
- unlink($tmpfile);
}
if (Input::instance()->get("page_type") == "collection") {
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 78437071..8e09dbed 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -55,7 +55,7 @@ class Uploader_Controller extends Controller {
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
- Event::add("system.shutdown", create_function("", "unlink(\"$temp_filename\");"));
+ system::delete_later($temp_filename);
try {
$item = ORM::factory("item");
$item->name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 26432ef5..a319b9c6 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -44,7 +44,7 @@ class gallery_event_Core {
// var/tmp might be stickier because theoretically we could wind up spamming that
// dir with a lot of files. But let's start with this and refine as we go.
if (!(rand() % 500)) {
- // Note that this code is roughly duplicated in gallery_event::gallery_shutdown
+ // Note that this code is roughly duplicated in gallery_task::file_cleanup
$threshold = time() - 1209600; // older than 2 weeks
foreach(array("logs", "tmp") as $dir) {
$dir = VARPATH . $dir;
@@ -67,6 +67,8 @@ class gallery_event_Core {
}
}
}
+ // Delete all files marked using system::delete_later.
+ system::delete_marked_files();
}
static function user_deleted($user) {
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index e1398103..7d56466e 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class system_Core {
+ private static $files_marked_for_deletion = array();
+
/**
* Return the path to an executable version of the named binary, or null.
* The paths are traversed in the following order:
@@ -66,8 +68,10 @@ class system_Core {
* This helper is similar to the built-in tempnam.
* It allows the caller to specify a prefix and an extension.
* It always places the file in TMPPATH.
+ * Unless specified with the $delete_later argument, it will be marked
+ * for deletion at shutdown using system::delete_later.
*/
- static function temp_filename($prefix="", $extension="") {
+ static function temp_filename($prefix="", $extension="", $delete_later=true) {
do {
$basename = tempnam(TMPPATH, $prefix);
if (!$basename) {
@@ -79,6 +83,30 @@ class system_Core {
@unlink($basename);
}
} while (!$success);
+
+ if ($delete_later) {
+ system::delete_later($filename);
+ }
+
return $filename;
}
-}
\ No newline at end of file
+
+ /**
+ * Mark a file for deletion at shutdown time. This is useful for temp files, where we can delay
+ * the deletion time until shutdown to keep page load time quick.
+ */
+ static function delete_later($filename) {
+ self::$files_marked_for_deletion[] = $filename;
+ }
+
+ /**
+ * Delete all files marked using system::delete_later. This is called at gallery shutdown.
+ */
+ static function delete_marked_files() {
+ foreach (self::$files_marked_for_deletion as $filename) {
+ // We want to suppress all errors, as it's possible that some of these
+ // files may have been deleted/moved before we got here.
+ @unlink($filename);
+ }
+ }
+}
diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php
index bd03b334..54ca6fe9 100644
--- a/modules/rest/controllers/rest.php
+++ b/modules/rest/controllers/rest.php
@@ -69,7 +69,7 @@ class Rest_Controller extends Controller {
$request->params = (object) $input->post();
if (isset($_FILES["file"])) {
$request->file = upload::save("file");
- Event::add("system.shutdown", create_function("", "unlink(\"{$request->file}\");"));
+ system::delete_later($request->file);
}
break;
}
diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php
index b058d6a5..222279e8 100644
--- a/modules/watermark/controllers/admin_watermarks.php
+++ b/modules/watermark/controllers/admin_watermarks.php
@@ -67,7 +67,7 @@ class Admin_Watermarks_Controller extends Admin_Controller {
$form = watermark::get_delete_form();
if ($form->validate()) {
if ($name = basename(module::get_var("watermark", "name"))) {
- @unlink(VARPATH . "modules/watermark/$name");
+ system::delete_later(VARPATH . "modules/watermark/$name");
module::clear_var("watermark", "name");
module::clear_var("watermark", "width");
@@ -108,7 +108,7 @@ class Admin_Watermarks_Controller extends Admin_Controller {
$name = legal_file::sanitize_filename($name, $extension, "photo");
} catch (Exception $e) {
message::error(t("Invalid or unidentifiable image file"));
- @unlink($file);
+ system::delete_later($file);
return;
}
@@ -120,7 +120,7 @@ class Admin_Watermarks_Controller extends Admin_Controller {
module::set_var("watermark", "position", $form->add_watermark->position->value);
module::set_var("watermark", "transparency", $form->add_watermark->transparency->value);
$this->_update_graphics_rules();
- @unlink($file);
+ system::delete_later($file);
message::success(t("Watermark saved"));
log::success("watermark", t("Watermark saved"));
--
cgit v1.2.3
From 94aadf03dadbfa01ba1744df60c97b6f3094ae88 Mon Sep 17 00:00:00 2001
From: shadlaws
Date: Wed, 20 Feb 2013 17:30:27 +0100
Subject: #2008 - Add warnings if some active modules are obsolete. - added
module::get_obsolete_modules_message function - put message on
admin/dashboard - put message on admin/modules - put message on upgrader -
updated unit test golden file xss_data
---
modules/gallery/controllers/admin_dashboard.php | 1 +
modules/gallery/controllers/admin_modules.php | 1 +
modules/gallery/controllers/upgrader.php | 1 +
modules/gallery/helpers/module.php | 30 +++++++++++++++++++
modules/gallery/tests/xss_data.txt | 39 +++++++++++++------------
modules/gallery/views/admin_dashboard.html.php | 7 +++++
modules/gallery/views/admin_modules.html.php | 6 ++++
modules/gallery/views/upgrader.html.php | 9 ++++++
8 files changed, 76 insertions(+), 18 deletions(-)
(limited to 'modules/gallery/helpers')
diff --git a/modules/gallery/controllers/admin_dashboard.php b/modules/gallery/controllers/admin_dashboard.php
index 6bd36b07..53172109 100644
--- a/modules/gallery/controllers/admin_dashboard.php
+++ b/modules/gallery/controllers/admin_dashboard.php
@@ -26,6 +26,7 @@ class Admin_Dashboard_Controller extends Admin_Controller {
$view->sidebar = "
";
+ $view->content->obsolete_modules_message = module::get_obsolete_modules_message();
print $view;
}
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index d13ec1c6..177a925d 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -26,6 +26,7 @@ class Admin_Modules_Controller extends Admin_Controller {
$view->page_title = t("Modules");
$view->content = new View("admin_modules.html");
$view->content->available = module::available();
+ $view->content->obsolete_modules_message = module::get_obsolete_modules_message();
print $view;
}
diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php
index d3c6e2ec..6b3a9ef6 100644
--- a/modules/gallery/controllers/upgrader.php
+++ b/modules/gallery/controllers/upgrader.php
@@ -46,6 +46,7 @@ class Upgrader_Controller extends Controller {
$view->available = module::available();
$view->failed = $failed ? explode(",", $failed) : array();
$view->done = $available_upgrades == 0;
+ $view->obsolete_modules_message = module::get_obsolete_modules_message();
print $view;
}
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index df258e87..d7429121 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -541,4 +541,34 @@ class module_Core {
static function get_version($module_name) {
return module::get($module_name)->version;
}
+
+ /**
+ * Check if obsolete modules are active and, if so, return a warning message.
+ * If none are found, return null.
+ */
+ static function get_obsolete_modules_message() {
+ // This is the obsolete modules list. Any active module that's on the list
+ // with version number at or below the one given will be considered obsolete.
+ // It is hard-coded here, and may be updated with future releases of Gallery.
+ $obsolete_modules = array("videos" => 4, "noffmpeg" => 1, "videodimensions" => 1,
+ "digibug" => 2);
+
+ $modules_found = array();
+ foreach ($obsolete_modules as $module => $version) {
+ if (module::is_active($module) && (module::get_version($module) <= $version)) {
+ $modules_found[] = $module;
+ }
+ }
+
+ if ($modules_found) {
+ // Need this to be on one super-long line or else the localization scanner may not work.
+ // (ref: http://sourceforge.net/apps/trac/gallery/ticket/1321)
+ return t("Recent upgrades to Gallery have made the following modules obsolete: %modules. We recommend that you deactivate the module(s). For more information, please see the documentation page.",
+ array("modules" => implode(", ", $modules_found),
+ "url_mod" => url::site("admin/modules"),
+ "url_doc" => "http://codex.galleryproject.org/Gallery3:User_guide:Obsolete_modules"));
+ }
+
+ return null;
+ }
}
diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt
index 457c157f..0028ac87 100644
--- a/modules/gallery/tests/xss_data.txt
+++ b/modules/gallery/tests/xss_data.txt
@@ -56,7 +56,8 @@ modules/gallery/views/admin_block_photo_stream.html.php 5 DIRTY_JS $photo
modules/gallery/views/admin_block_photo_stream.html.php 6 DIRTY photo::img_dimensions($photo->width,$photo->height,72)
modules/gallery/views/admin_block_photo_stream.html.php 7 DIRTY_ATTR $photo->thumb_url()
modules/gallery/views/admin_dashboard.html.php 5 DIRTY_JS $csrf
-modules/gallery/views/admin_dashboard.html.php 35 DIRTY $blocks
+modules/gallery/views/admin_dashboard.html.php 37 DIRTY $obsolete_modules_message
+modules/gallery/views/admin_dashboard.html.php 42 DIRTY $blocks
modules/gallery/views/admin_graphics.html.php 25 DIRTY newView("admin_graphics_none.html")
modules/gallery/views/admin_graphics.html.php 27 DIRTY newView("admin_graphics_$active.html",array("tk"=>$tk->$active,"is_active"=>true))
modules/gallery/views/admin_graphics.html.php 34 DIRTY newView("admin_graphics_$id.html",array("tk"=>$tk->$id,"is_active"=>false))
@@ -96,15 +97,16 @@ modules/gallery/views/admin_maintenance.html.php 181 DIRTY $task-
modules/gallery/views/admin_maintenance_show_log.html.php 8 DIRTY_JS url::site("admin/maintenance/save_log/$task->id?csrf=$csrf")
modules/gallery/views/admin_maintenance_show_log.html.php 13 DIRTY $task->name
modules/gallery/views/admin_maintenance_task.html.php 75 DIRTY $task->name
-modules/gallery/views/admin_modules.html.php 51 DIRTY access::csrf_form_field()
-modules/gallery/views/admin_modules.html.php 61 DIRTY_ATTR text::alternate("g-odd","g-even")
-modules/gallery/views/admin_modules.html.php 64 DIRTY form::checkbox($data,'1',module::is_active($module_name))
-modules/gallery/views/admin_modules.html.php 66 DIRTY $module_info->version
-modules/gallery/views/admin_modules.html.php 74 DIRTY_JS $module_info->author_url
-modules/gallery/views/admin_modules.html.php 81 DIRTY_ATTR $module_info->author_name
-modules/gallery/views/admin_modules.html.php 85 DIRTY $module_info->author_name
-modules/gallery/views/admin_modules.html.php 93 DIRTY_JS $module_info->info_url
-modules/gallery/views/admin_modules.html.php 106 DIRTY_JS $module_info->discuss_url
+modules/gallery/views/admin_modules.html.php 51 DIRTY $obsolete_modules_message
+modules/gallery/views/admin_modules.html.php 57 DIRTY access::csrf_form_field()
+modules/gallery/views/admin_modules.html.php 67 DIRTY_ATTR text::alternate("g-odd","g-even")
+modules/gallery/views/admin_modules.html.php 70 DIRTY form::checkbox($data,'1',module::is_active($module_name))
+modules/gallery/views/admin_modules.html.php 72 DIRTY $module_info->version
+modules/gallery/views/admin_modules.html.php 80 DIRTY_JS $module_info->author_url
+modules/gallery/views/admin_modules.html.php 87 DIRTY_ATTR $module_info->author_name
+modules/gallery/views/admin_modules.html.php 91 DIRTY $module_info->author_name
+modules/gallery/views/admin_modules.html.php 99 DIRTY_JS $module_info->info_url
+modules/gallery/views/admin_modules.html.php 112 DIRTY_JS $module_info->discuss_url
modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY_ATTR $css_class
modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY $message
modules/gallery/views/admin_modules_confirm.html.php 16 DIRTY access::csrf_form_field()
@@ -264,14 +266,15 @@ modules/gallery/views/quick_delete_confirm.html.php 11 DIRTY $form
modules/gallery/views/reauthenticate.html.php 9 DIRTY $form
modules/gallery/views/upgrade_checker_block.html.php 19 DIRTY $new_version
modules/gallery/views/upgrader.html.php 76 DIRTY_ATTR $done?"muted":""
-modules/gallery/views/upgrader.html.php 94 DIRTY_ATTR $done?"muted":""
-modules/gallery/views/upgrader.html.php 102 DIRTY_ATTR $module->version==$module->code_version?"current":"upgradeable"
-modules/gallery/views/upgrader.html.php 102 DIRTY_ATTR in_array($id,$failed)?"failed":""
-modules/gallery/views/upgrader.html.php 103 DIRTY_ATTR $id
-modules/gallery/views/upgrader.html.php 107 DIRTY $module->version
-modules/gallery/views/upgrader.html.php 110 DIRTY $module->code_version
-modules/gallery/views/upgrader.html.php 120 DIRTY_ATTR $done?"muted":""
-modules/gallery/views/upgrader.html.php 123 DIRTY_ATTR $done?"muted":""
+modules/gallery/views/upgrader.html.php 97 DIRTY $obsolete_modules_message
+modules/gallery/views/upgrader.html.php 103 DIRTY_ATTR $done?"muted":""
+modules/gallery/views/upgrader.html.php 111 DIRTY_ATTR $module->version==$module->code_version?"current":"upgradeable"
+modules/gallery/views/upgrader.html.php 111 DIRTY_ATTR in_array($id,$failed)?"failed":""
+modules/gallery/views/upgrader.html.php 112 DIRTY_ATTR $id
+modules/gallery/views/upgrader.html.php 116 DIRTY $module->version
+modules/gallery/views/upgrader.html.php 119 DIRTY $module->code_version
+modules/gallery/views/upgrader.html.php 129 DIRTY_ATTR $done?"muted":""
+modules/gallery/views/upgrader.html.php 132 DIRTY_ATTR $done?"muted":""
modules/gallery/views/user_languages_block.html.php 2 DIRTY form::dropdown("g-select-session-locale",$installed_locales,$selected)
modules/gallery/views/user_profile.html.php 34 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true))
modules/gallery/views/user_profile.html.php 43 DIRTY $info->view
diff --git a/modules/gallery/views/admin_dashboard.html.php b/modules/gallery/views/admin_dashboard.html.php
index f391547e..cf90ef28 100644
--- a/modules/gallery/views/admin_dashboard.html.php
+++ b/modules/gallery/views/admin_dashboard.html.php
@@ -31,6 +31,13 @@
});
});
+
+ if ($obsolete_modules_message): ?>
+
+ = $obsolete_modules_message ?>
+
+ endif ?>
+
= $blocks ?>
diff --git a/modules/gallery/views/admin_modules.html.php b/modules/gallery/views/admin_modules.html.php
index 5a7f7b6c..96576ae4 100644
--- a/modules/gallery/views/admin_modules.html.php
+++ b/modules/gallery/views/admin_modules.html.php
@@ -46,6 +46,12 @@
= t("Power up your Gallery by adding more modules! Each module provides new cool features.", array("url" => "http://codex.galleryproject.org/Category:Gallery_3:Modules")) ?>