diff options
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r-- | modules/gallery/helpers/MY_remote.php | 27 | ||||
-rw-r--r-- | modules/gallery/helpers/album.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 47 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_menu.php | 7 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_rss.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 223 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 31 | ||||
-rw-r--r-- | modules/gallery/helpers/graphics.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/l10n_client.php | 10 | ||||
-rw-r--r-- | modules/gallery/helpers/l10n_scanner.php | 9 | ||||
-rw-r--r-- | modules/gallery/helpers/locale.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/movie.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/p.php | 15 | ||||
-rw-r--r-- | modules/gallery/helpers/photo.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/task.php | 19 |
17 files changed, 255 insertions, 157 deletions
diff --git a/modules/gallery/helpers/MY_remote.php b/modules/gallery/helpers/MY_remote.php index 4abf5bf1..af2a05d8 100644 --- a/modules/gallery/helpers/MY_remote.php +++ b/modules/gallery/helpers/MY_remote.php @@ -21,11 +21,11 @@ class remote extends remote_Core { static function post($url, $post_data_array, $extra_headers=array()) { $post_data_raw = self::_encode_post_data($post_data_array, $extra_headers); - + /* Read the web page into a buffer */ list ($response_status, $response_headers, $response_body) = self::do_request($url, 'POST', $extra_headers, $post_data_raw); - + return array($response_body, $response_status, $response_headers); } @@ -49,22 +49,23 @@ class remote extends remote_Core { } $post_data_raw .= urlencode($key) . '=' . urlencode($value); } - + $extra_headers['Content-Type'] = 'application/x-www-form-urlencoded'; $extra_headers['Content-Length'] = strlen($post_data_raw); - + return $post_data_raw; } /** * A single request, without following redirects * - * @todo: Handle redirects? If so, only for GET (i.e. not for POST), and use G2's WebHelper_simple::_parseLocation logic. + * @todo: Handle redirects? If so, only for GET (i.e. not for POST), and use G2's + * WebHelper_simple::_parseLocation logic. */ static function do_request($url, $method='GET', $headers=array(), $body='') { /* Convert illegal characters */ $url = str_replace(' ', '%20', $url); - + $url_components = self::_parse_url_for_fsockopen($url); $handle = fsockopen( $url_components['fsockhost'], $url_components['port'], $errno, $errstr, 5); @@ -72,12 +73,12 @@ class remote extends remote_Core { // log "Error $errno: '$errstr' requesting $url"; return array(null, null, null); } - + $header_lines = array('Host: ' . $url_components['host']); foreach ($headers as $key => $value) { $header_lines[] = $key . ': ' . $value; } - + $success = fwrite($handle, sprintf("%s %s HTTP/1.0\r\n%s\r\n\r\n%s", $method, $url_components['uri'], @@ -89,7 +90,7 @@ class remote extends remote_Core { return array(null, null, null); } fflush($handle); - + /* * Read the status line. fgets stops after newlines. The first line is the protocol * version followed by a numeric status code and its associated textual phrase. @@ -99,7 +100,7 @@ class remote extends remote_Core { // 'Empty http response code, maybe timeout' return array(null, null, null); } - + /* Read the headers */ $response_headers = array(); while (!feof($handle)) { @@ -107,10 +108,10 @@ class remote extends remote_Core { if (empty($line)) { break; } - + /* Normalize the line endings */ $line = str_replace("\r", '', $line); - + list ($key, $value) = explode(':', $line, 2); if (isset($response_headers[$key])) { if (!is_array($response_headers[$key])) { @@ -121,7 +122,7 @@ class remote extends remote_Core { $response_headers[$key] = trim($value); } } - + /* Read the body */ $response_body = ''; while (!feof($handle)) { diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 362b93d0..1197f243 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -111,7 +111,7 @@ class album_Core { $sort_order->dropdown("column", array("id" => "gAlbumSortColumn")) ->label(t("Sort by")) - ->options(array("weight" => t("Default"), + ->options(array("weight" => t("Order Added"), "captured" => t("Capture Date"), "created" => t("Creation Date"), "title" => t("Title"), diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index e22cc17f..a32ac484 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_Core { + const VERSION = "3.0 beta 2"; + /** * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is * down for maintenance" page. diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index a10f2bbf..b7816954 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -33,7 +33,7 @@ class gallery_block_Core { switch($block_id) { case "welcome": $block->css_id = "gWelcome"; - $block->title = t("Welcome to Gallery3"); + $block->title = t("Welcome to Gallery 3"); $block->content = new View("admin_block_welcome.html"); break; diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index df555d52..28c1990f 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -32,6 +32,16 @@ class gallery_installer { PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE {caches} ( + `id` int(9) NOT NULL auto_increment, + `key` varchar(255) NOT NULL, + `tags` varchar(255), + `expiration` int(9) NOT NULL, + `cache` longblob, + PRIMARY KEY (`id`), + KEY (`tags`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE {graphics_rules} ( `id` int(9) NOT NULL auto_increment, `active` BOOLEAN default 0, @@ -241,7 +251,6 @@ class gallery_installer { block_manager::add("dashboard_center", "gallery", "photo_stream"); block_manager::add("dashboard_center", "gallery", "log_entries"); - module::set_var("gallery", "version", "3.0 pre beta 2 (git)"); module::set_var("gallery", "choose_default_tookit", 1); module::set_var("gallery", "date_format", "Y-M-d"); module::set_var("gallery", "date_time_format", "Y-M-d H:i:s"); @@ -249,15 +258,15 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); // @todo this string needs to be picked up by l10n_scanner module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>"); - module::set_version("gallery", 3); + module::set_version("gallery", 7); } static function upgrade($version) { + $db = Database::instance(); if ($version == 1) { module::set_var("gallery", "date_format", "Y-M-d"); module::set_var("gallery", "date_time_format", "Y-M-d H:i:s"); module::set_var("gallery", "time_format", "H:i:s"); - module::set_var("gallery", "version", "3.0 pre beta 2 (git)"); module::set_version("gallery", $version = 2); } @@ -265,6 +274,37 @@ class gallery_installer { module::set_var("gallery", "show_credits", 1); module::set_version("gallery", $version = 3); } + + if ($version == 3) { + $db->query("CREATE TABLE {caches} ( + `id` varchar(255) NOT NULL, + `tags` varchar(255), + `expiration` int(9) NOT NULL, + `cache` text, + PRIMARY KEY (`id`), + KEY (`tags`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + module::set_version("gallery", $version = 4); + } + + if ($version == 4) { + Cache::instance()->delete_all(); + $db->query("ALTER TABLE {caches} MODIFY COLUMN `cache` LONGBLOB"); + module::set_version("gallery", $version = 5); + } + + if ($version == 5) { + Cache::instance()->delete_all(); + $db->query("ALTER TABLE {caches} DROP COLUMN `id`"); + $db->query("ALTER TABLE {caches} ADD COLUMN `key` varchar(255) NOT NULL"); + $db->query("ALTER TABLE {caches} ADD COLUMN `id` int(9) NOT NULL auto_increment PRIMARY KEY"); + module::set_version("gallery", $version = 6); + } + + if ($version == 6) { + module::clear_var("gallery", "version"); + module::set_version("gallery", $version = 7); + } } static function uninstall() { @@ -282,6 +322,7 @@ class gallery_installer { $db->query("DROP TABLE IF EXISTS {tasks}"); $db->query("DROP TABLE IF EXISTS {themes}"); $db->query("DROP TABLE IF EXISTS {vars}"); + $db->query("DROP TABLE IF EXISTS {caches}"); foreach (array("albums", "resizes", "thumbs", "uploads", "modules", "logs", "database.php") as $entry) { system("/bin/rm -rf " . VARPATH . $entry); diff --git a/modules/gallery/helpers/gallery_menu.php b/modules/gallery/helpers/gallery_menu.php index a25832fe..b6f763b8 100644 --- a/modules/gallery/helpers/gallery_menu.php +++ b/modules/gallery/helpers/gallery_menu.php @@ -94,6 +94,13 @@ class gallery_menu_Core { static function tag($menu, $theme) { } + static function thumb($menu, $theme, $item) { + $menu->append(Menu::factory("submenu") + ->id("options_menu") + ->label(t("Options")) + ->css_class("gThumbMenu")); + } + static function photo($menu, $theme) { if (access::can("view_full", $theme->item())) { $menu->append(Menu::factory("link") diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 6e966bdb..7daf6170 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -52,9 +52,9 @@ class gallery_rss_Core { ->viewable() ->descendants($limit, $offset, "photo"); $feed->max_pages = ceil($item->viewable()->descendants_count("photo") / $limit); - $feed->title = $item->title; + $feed->title = p::purify($item->title); $feed->link = url::abs_site("albums/{$item->id}"); - $feed->description = $item->description; + $feed->description = nl2br(p::purify($item->description)); return $feed; } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 2493c49e..9ce2c4a0 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -45,131 +45,154 @@ class gallery_task_Core { * @param Task_Model the task */ static function rebuild_dirty_images($task) { - $result = graphics::find_dirty_images_query(); - $completed = $task->get("completed", 0); - $ignored = $task->get("ignored", array()); - $remaining = $result->count() - count($ignored); - - $i = 0; - foreach ($result as $row) { - if (array_key_exists($row->id, $ignored)) { - continue; - } + $message = array(); + try { + $result = graphics::find_dirty_images_query(); + $completed = $task->get("completed", 0); + $ignored = $task->get("ignored", array()); + $remaining = $result->count() - count($ignored); + + $i = 0; + foreach ($result as $row) { + if (array_key_exists($row->id, $ignored)) { + continue; + } - $item = ORM::factory("item", $row->id); - if ($item->loaded) { - $success = graphics::generate($item); - if (!$success) { - $ignored[$item->id] = 1; + $item = ORM::factory("item", $row->id); + if ($item->loaded) { + $success = graphics::generate($item); + if (!$success) { + $ignored[$item->id] = 1; + $message[] = t("Unable to rebuild images for '%title'", + array("title" => p::purify($item->title))); + } else { + $message[] = t("Successfully rebuilt images for '%title'", + array("title" => p::purify($item->title))); + } } - } - $completed++; - $remaining--; + $completed++; + $remaining--; - if (++$i == 2) { - break; + if (++$i == 2) { + break; + } } - } - $task->status = t2("Updated: 1 image. Total: %total_count.", - "Updated: %count images. Total: %total_count.", - $completed, - array("total_count" => ($remaining + $completed))); + $task->status = t2("Updated: 1 image. Total: %total_count.", + "Updated: %count images. Total: %total_count.", + $completed, + array("total_count" => ($remaining + $completed))); - if ($completed + $remaining > 0) { - $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); - } else { - $task->percent_complete = 100; - } + if ($completed + $remaining > 0) { + $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); + } else { + $task->percent_complete = 100; + } - $task->set("completed", $completed); - $task->set("ignored", $ignored); - if ($remaining == 0) { + $task->set("completed", $completed); + $task->set("ignored", $ignored); + if ($remaining == 0) { + $task->done = true; + $task->state = "success"; + site_status::clear("graphics_dirty"); + } + } catch (Exception $e) { $task->done = true; - $task->state = "success"; - site_status::clear("graphics_dirty"); + $task->state = "error"; + $task->status = $e->getMessage(); + $message[] = $e->__toString(); } + $task->log($message); } static function update_l10n(&$task) { - $start = microtime(true); - $dirs = $task->get("dirs"); - $files = $task->get("files"); - $cache = $task->get("cache", array()); - $i = 0; - - switch ($task->get("mode", "init")) { - case "init": // 0% - $dirs = array("gallery", "modules", "themes", "installer"); - $files = array(); - $task->set("mode", "find_files"); - $task->status = t("Finding files"); - break; - - case "find_files": // 0% - 10% - while (($dir = array_pop($dirs)) && microtime(true) - $start < 0.5) { - if (basename($dir) == "tests") { - continue; - } + $message = array(); + try { + $start = microtime(true); + $dirs = $task->get("dirs"); + $files = $task->get("files"); + $cache = $task->get("cache", array()); + $i = 0; + + switch ($task->get("mode", "init")) { + case "init": // 0% + $dirs = array("gallery", "modules", "themes", "installer"); + $files = array(); + $task->set("mode", "find_files"); + $task->status = t("Finding files"); + break; - foreach (glob(DOCROOT . "$dir/*") as $path) { - $relative_path = str_replace(DOCROOT, "", $path); - if (is_dir($path)) { - $dirs[] = $relative_path; - } else { - $files[] = $relative_path; + case "find_files": // 0% - 10% + while (($dir = array_pop($dirs)) && microtime(true) - $start < 0.5) { + if (in_array(basename($dir), array("tests", "lib"))) { + continue; + } + + foreach (glob(DOCROOT . "$dir/*") as $path) { + $relative_path = str_replace(DOCROOT, "", $path); + if (is_dir($path)) { + $dirs[] = $relative_path; + } else { + $files[] = $relative_path; + } } } - } - $task->status = t2("Finding files: found 1 file", - "Finding files: found %count files", count($files)); + $message[] = $task->status = t2("Finding files: found 1 file", + "Finding files: found %count files", count($files)); - if (!$dirs) { - $task->set("mode", "scan_files"); - $task->set("total_files", count($files)); - $task->status = t("Scanning files"); - $task->percent_complete = 10; - } - break; - - case "scan_files": // 10% - 90% - while (($file = array_pop($files)) && microtime(true) - $start < 0.5) { - $file = DOCROOT . $file; - switch (pathinfo($file, PATHINFO_EXTENSION)) { - case "php": - l10n_scanner::scan_php_file($file, $cache); - break; + if (!$dirs) { + $task->set("mode", "scan_files"); + $task->set("total_files", count($files)); + $task->status = t("Scanning files"); + $task->percent_complete = 10; + } + break; - case "info": - l10n_scanner::scan_info_file($file, $cache); - break; + case "scan_files": // 10% - 90% + while (($file = array_pop($files)) && microtime(true) - $start < 0.5) { + $file = DOCROOT . $file; + switch (pathinfo($file, PATHINFO_EXTENSION)) { + case "php": + l10n_scanner::scan_php_file($file, $cache); + break; + + case "info": + l10n_scanner::scan_info_file($file, $cache); + break; + } } - } - $total_files = $task->get("total_files"); - $task->status = t2("Scanning files: scanned 1 file", - "Scanning files: scanned %count files", $total_files - count($files)); + $total_files = $task->get("total_files"); + $message[] = $task->status = t2("Scanning files: scanned 1 file", + "Scanning files: scanned %count files", $total_files - count($files)); - $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files; - if (empty($files)) { - $task->set("mode", "fetch_updates"); - $task->status = t("Fetching updates"); - $task->percent_complete = 90; + $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files; + if (empty($files)) { + $task->set("mode", "fetch_updates"); + $task->status = t("Fetching updates"); + $task->percent_complete = 90; + } + break; + + case "fetch_updates": // 90% - 100% + $message = array_merge($message, l10n_client::fetch_updates()); + $task->done = true; + $task->state = "success"; + $task->status = t("Translations installed/updated"); + $task->percent_complete = 100; } - break; - case "fetch_updates": // 90% - 100% - l10n_client::fetch_updates(); + $task->set("files", $files); + $task->set("dirs", $dirs); + $task->set("cache", $cache); + } catch (Exception $e) { $task->done = true; - $task->state = "success"; - $task->status = t("Translations installed/updated"); - $task->percent_complete = 100; + $task->state = "error"; + $task->status = $e->getMessage(); + $message[] = $e->__toString(); } - - $task->set("files", $files); - $task->set("dirs", $dirs); - $task->set("cache", $cache); + $task->log($message); } }
\ No newline at end of file diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index a96c8f5b..226b8a42 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -22,14 +22,12 @@ class gallery_theme_Core { $session = Session::instance(); $buf = ""; if ($session->get("debug")) { - $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . - url::file("modules/gallery/css/debug.css") . "\" />"; + $theme->css("modules/gallery/css/debug.css"); } if (($theme->page_type == "album" || $theme->page_type == "photo") && access::can("edit", $theme->item())) { - $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . - url::file("modules/gallery/css/quick.css") . "\" />"; - $buf .= html::script("modules/gallery/js/quick.js"); + $theme->css("modules/gallery/css/quick.css"); + $theme->script("modules/gallery/js/quick.js"); } if (module::is_active("rss")) { @@ -41,10 +39,9 @@ class gallery_theme_Core { } if ($session->get("l10n_mode", false)) { - $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . - url::file("modules/gallery/css/l10n_client.css") . "\" />"; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("modules/gallery/js/l10n_client.js"); + $theme->css("modules/gallery/css/l10n_client.css"); + $theme->script("lib/jquery.cookie.js"); + $theme->script("modules/gallery/js/l10n_client.js"); } return $buf; @@ -78,20 +75,15 @@ class gallery_theme_Core { static function admin_head($theme) { $session = Session::instance(); - $buf = ""; if ($session->get("debug")) { - $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . - url::file("modules/gallery/css/debug.css") . "\" />"; + $theme->css("modules/gallery/css/debug.css"); } if ($session->get("l10n_mode", false)) { - $buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . - url::file("modules/gallery/css/l10n_client.css") . "\" />"; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("modules/gallery/js/l10n_client.js"); + $theme->css("modules/gallery/css/l10n_client.css"); + $theme->script("lib/jquery.cookie.js"); + $theme->script("modules/gallery/js/l10n_client.js"); } - - return $buf; } static function page_bottom($theme) { @@ -124,8 +116,7 @@ class gallery_theme_Core { static function credits() { return "<li class=\"first\">" . t(module::get_var("gallery", "credits"), - array("url" => "http://gallery.menalto.com", - "version" => module::get_var("gallery", "version"))) . + array("url" => "http://gallery.menalto.com", "version" => gallery::VERSION)) . "</li>"; } diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 71b8ddd8..db9b2ef5 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -195,7 +195,7 @@ class graphics_Core { self::init_toolkit(); } - if (filesize($input_file) == 0) { + if (@filesize($input_file) == 0) { throw new Exception("@todo EMPTY_INPUT_FILE"); } @@ -331,7 +331,7 @@ class graphics_Core { if (!isset($gd["GD Version"])) { $gd["GD Version"] = false; } - putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin"); + putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin"); return array("gd" => $gd, "imagemagick" => $exec ? dirname(exec("which convert")) : false, "graphicsmagick" => $exec ? dirname(exec("which gm")) : false); diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 20f81ecc..6d4da0eb 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -67,6 +67,9 @@ class l10n_client_Core { return true; } + /** + * @return an array of messages that will be written to the task log + */ static function fetch_updates() { $request->locales = array(); $request->messages = new stdClass(); @@ -101,8 +104,7 @@ class l10n_client_Core { throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status); } if (empty($response_data)) { - log::info("translations", "Translations fetch request resulted in an empty response"); - return; + return array(t("Translations fetch request resulted in an empty response")); } $response = json_decode($response_data); @@ -112,7 +114,8 @@ class l10n_client_Core { // {key:<key_2>, ...} // ] $count = count($response); - log::info("translations", "Installed $count new / updated translation messages"); + $message[] = t2("Installed 1 new / updated translation message", + "Installed %count new / updated translation messages", $count); foreach ($response as $message_data) { // @todo Better input validation @@ -150,6 +153,7 @@ class l10n_client_Core { $entry->translation = $translation; $entry->save(); } + return $message; } static function submit_translations() { diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php index a68aa28b..a8059b3a 100644 --- a/modules/gallery/helpers/l10n_scanner.php +++ b/modules/gallery/helpers/l10n_scanner.php @@ -82,11 +82,10 @@ class l10n_scanner_Core { } static function scan_info_file($file, &$cache) { - $code = file_get_contents($file); - if (preg_match("#name\s*?=\s*(.*?)\ndescription\s*?=\s*(.*)\n#", $code, $matches)) { - unset($matches[0]); - foreach ($matches as $string) { - l10n_scanner::process_message($string, $cache); + $info = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); + foreach (array('name', 'description') as $property) { + if (isset($info->$property)) { + l10n_scanner::process_message($info->$property, $cache); } } } diff --git a/modules/gallery/helpers/locale.php b/modules/gallery/helpers/locale.php index 9783a53a..41b78834 100644 --- a/modules/gallery/helpers/locale.php +++ b/modules/gallery/helpers/locale.php @@ -50,7 +50,9 @@ class locale_Core { static function update_installed($locales) { // Ensure that the default is included... $default = module::get_var("gallery", "default_locale"); - $locales = array_merge($locales, array($default)); + $locales = in_array($default, $locales) + ? $locales + : array_merge($locales, array($default)); module::set_var("gallery", "installed_locales", join("|", $locales)); } diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index fcf1cc54..d62ead76 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -82,7 +82,7 @@ class movie_Core { $movie->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); // Randomize the name if there's a conflict - while (ORM::Factory("item") + while (ORM::factory("item") ->where("parent_id", $parent->id) ->where("name", $movie->name) ->find()->id) { @@ -145,7 +145,7 @@ class movie_Core { static function find_ffmpeg() { if (!$ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) { - putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin"); + putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin"); if (function_exists("exec")) { $ffmpeg_path = exec("which ffmpeg"); } diff --git a/modules/gallery/helpers/p.php b/modules/gallery/helpers/p.php index 0a6210dc..862c769b 100644 --- a/modules/gallery/helpers/p.php +++ b/modules/gallery/helpers/p.php @@ -18,7 +18,22 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class p_Core { + private static $_purifier = null; static function clean($dirty_html) { return html::specialchars($dirty_html); } + + static function purify($dirty_html) { + if (empty(self::$_purifier)) { + require_once(dirname(__file__) . "/../lib/HTMLPurifier/HTMLPurifier.auto.php"); + $config = HTMLPurifier_Config::createDefault(); + foreach (Kohana::config('purifier') as $category => $key_value) { + foreach ($key_value as $key => $value) { + $config->set("$category.$key", $value); + } + } + self::$_purifier = new HTMLPurifier($config); + } + return self::$_purifier->purify($dirty_html); + } } diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index a4bc853b..e8a4f357 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -81,7 +81,7 @@ class photo_Core { $photo->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); // Randomize the name if there's a conflict - while (ORM::Factory("item") + while (ORM::factory("item") ->where("parent_id", $parent->id) ->where("name", $photo->name) ->find()->id) { diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index a8a004ab..6a9f63c2 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -56,6 +56,8 @@ class task_Core { } $task->done = 1; $task->state = "cancelled"; + $task->log(t("Task %task_name cancelled (task id %task_id)", + array("task_name" => $task->name, "task_id" => $task->id))); $task->save(); return $task; @@ -74,9 +76,20 @@ class task_Core { throw new Exception("@todo MISSING_TASK"); } - $task->state = "running"; - call_user_func_array($task->callback, array(&$task)); - $task->save(); + try { + $task->state = "running"; + call_user_func_array($task->callback, array(&$task)); + if ($task->done) { + $task->log($task->status); + } + $task->save(); + } catch (Exception $e) { + $task->log($e->__toString()); + $task->state = "error"; + $task->done = true; + $task->status = $e->getMessage(); + $task->save(); + } return $task; } |