Skip to content

Commit

Permalink
Fix for ticket #1320. Hook the loading of the initial albums and chec…
Browse files Browse the repository at this point in the history
…k to see if the loaded item is the requested item.
  • Loading branch information
Tim Almdal committed Aug 31, 2010
2 parents 0f2daf2 + d5ebcb9 commit 866f8ee
Show file tree
Hide file tree
Showing 26 changed files with 137 additions and 129 deletions.
5 changes: 3 additions & 2 deletions installer/install.sql
Expand Up @@ -244,7 +244,7 @@ CREATE TABLE {modules} (
KEY `weight` (`weight`)
) AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO {modules} VALUES (1,1,'gallery',35,1);
INSERT INTO {modules} VALUES (1,1,'gallery',36,1);
INSERT INTO {modules} VALUES (2,1,'user',3,2);
INSERT INTO {modules} VALUES (3,1,'comment',3,3);
INSERT INTO {modules} VALUES (4,1,'organize',2,4);
Expand Down Expand Up @@ -395,7 +395,7 @@ CREATE TABLE {vars} (
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY `module_name` (`module_name`,`name`)
) AUTO_INCREMENT=44 DEFAULT CHARSET=utf8;
) AUTO_INCREMENT=45 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO {vars} VALUES (NULL,'gallery','active_site_theme','wind');
INSERT INTO {vars} VALUES (NULL,'gallery','active_admin_theme','admin_wind');
Expand All @@ -414,6 +414,7 @@ INSERT INTO {vars} VALUES (NULL,'gallery','maintenance_mode','0');
INSERT INTO {vars} VALUES (NULL,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}');
INSERT INTO {vars} VALUES (NULL,'gallery','visible_title_length','15');
INSERT INTO {vars} VALUES (NULL,'gallery','date_time_format','Y-M-d H:i:s');
INSERT INTO {vars} VALUES (NULL,'gallery','favicon_url','lib/images/favicon.ico');
INSERT INTO {vars} VALUES (NULL,'gallery','date_format','Y-M-d');
INSERT INTO {vars} VALUES (NULL,'gallery','blocks_dashboard_center','a:3:{i:6;a:2:{i:0;s:7:\"gallery\";i:1;s:7:\"welcome\";}i:7;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"photo_stream\";}i:8;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"log_entries\";}}');
INSERT INTO {vars} VALUES (NULL,'gallery','choose_default_tookit','1');
Expand Down
9 changes: 3 additions & 6 deletions modules/g2_import/controllers/g2.php
Expand Up @@ -35,12 +35,9 @@ public function map() {
$id = $input->get("g2_itemId");

if ($id) {
// Requests by id are either core.DownloadItem or
// core.ShowItem requests.
// Later versions of Gallery 2 don't specify g2_view if
// it's the default (core.ShowItem).
// And in some cases (bbcode, embedding) people are using
// the id style URLs although URL rewriting is enabled.
// Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of
// Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases
// (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled.
$where = array(array("g2_id", "=", $id));
$view = $input->get("g2_view");
if ($view) {
Expand Down
22 changes: 19 additions & 3 deletions modules/g2_import/helpers/g2_import.php
Expand Up @@ -178,7 +178,17 @@ static function init_embed($embed_path) {
"module", "rewrite", "modrewrite.embeddedLocation", $g2_embed_location));
g2($gallery->getStorage()->checkPoint());
}
self::$g2_base_url = $g2_embed_location;

if ($g2_embed_location) {
self::$g2_base_url = $g2_embed_location;
} else {
self::$g2_base_url = $GLOBALS["gallery"]->getUrlGenerator()->generateUrl(
array(),
array("forceSessionId" => false,
"htmlEntities" => false,
"urlEncode" => false,
"useAuthToken" => false));
}

return true;
}
Expand Down Expand Up @@ -689,8 +699,7 @@ static function import_item(&$queue) {
$title = $g2_item->getTitle();
$title or $title = $g2_item->getPathComponent();
$messages[] =
t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed; " .
"(imported as <a href=\"%g3_url\">%title</a>)",
t("<a href=\"%g2_url\">%title</a> from Gallery 2 could not be processed; (imported as <a href=\"%g3_url\">%title</a>)",
array("g2_url" => $g2_item_url,
"g3_url" => $item->url(),
"title" => $title));
Expand Down Expand Up @@ -846,6 +855,11 @@ static function import_comment(&$queue) {
array("id" => $g2_comment_id, "exception" => (string)$e));
}

if (self::map($g2_comment->getId())) {
// Already imported
return;
}

$item_id = self::map($g2_comment->getParentId());
if (empty($item_id)) {
// Item was not mapped.
Expand Down Expand Up @@ -878,6 +892,8 @@ static function import_comment(&$queue) {
$e);
}

self::set_map($g2_comment->getId(), $comment->id, "comment");

// Backdate the creation date. We can't do this at creation time because
// Comment_Model::save() will override it.
db::update("comments")
Expand Down
40 changes: 38 additions & 2 deletions modules/gallery/controllers/admin_theme_options.php
Expand Up @@ -22,14 +22,14 @@ public function index() {
$view = new Admin_View("admin.html");
$view->page_title = t("Theme options");
$view->content = new View("admin_theme_options.html");
$view->content->form = theme::get_edit_form_admin();
$view->content->form = $this->_get_edit_form_admin();
print $view;
}

public function save() {
access::verify_csrf();

$form = theme::get_edit_form_admin();
$form = $this->_get_edit_form_admin();
if ($form->validate()) {
module::set_var("gallery", "page_size", $form->edit_theme->page_size->value);

Expand Down Expand Up @@ -58,6 +58,7 @@ public function save() {
module::set_var("gallery", "header_text", $form->edit_theme->header_text->value);
module::set_var("gallery", "footer_text", $form->edit_theme->footer_text->value);
module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value);
module::set_var("gallery", "favicon_url", $form->edit_theme->favicon_url->value);

module::event("theme_edit_form_completed", $form);

Expand All @@ -70,5 +71,40 @@ public function save() {
print $view;
}
}

private function _get_edit_form_admin() {
$form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form"));
$group = $form->group("edit_theme")->label(t("Theme layout"));
$group->input("page_size")->label(t("Items per page"))->id("g-page-size")
->rules("required|valid_digit")
->error_messages("required", t("You must enter a number"))
->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "page_size"));
$group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("g-thumb-size")
->rules("required|valid_digit")
->error_messages("required", t("You must enter a number"))
->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "thumb_size"));
$group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("g-resize-size")
->rules("required|valid_digit")
->error_messages("required", t("You must enter a number"))
->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "resize_size"));
$group->input("favicon_url")->label(t("URL (or relative path) to your favicon.ico"))
->id("g-favicon")
->value(module::get_var("gallery", "favicon_url"));
$group->textarea("header_text")->label(t("Header text"))->id("g-header-text")
->value(module::get_var("gallery", "header_text"));
$group->textarea("footer_text")->label(t("Footer text"))->id("g-footer-text")
->value(module::get_var("gallery", "footer_text"));
$group->checkbox("show_credits")->label(t("Show site credits"))->id("g-footer-text")
->checked(module::get_var("gallery", "show_credits"));

module::event("theme_edit_form", $form);

$group = $form->group("buttons");
$group->submit("")->value(t("Save"));
return $form;
}
}

2 changes: 1 addition & 1 deletion modules/gallery/controllers/albums.php
Expand Up @@ -68,7 +68,7 @@ public function show($album) {
$template->set_global("item", $album);
$template->set_global("children", $album->viewable()->children($page_size, $offset));
$template->set_global("children_count", $children_count);
$template->set_global("parents", $album->parents());
$template->set_global("parents", $album->parents()->as_array()); // view calls empty() on this
$template->content = new View("album.html");

// We can't use math in ORM or the query builder, so do this by hand. It's important
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/controllers/movies.php
Expand Up @@ -41,7 +41,7 @@ public function show($movie) {
$template->set_global("item", $movie);
$template->set_global("children", array());
$template->set_global("children_count", 0);
$template->set_global("parents", $movie->parents());
$template->set_global("parents", $movie->parents()->as_array());
$template->set_global("next_item", $next_item);
$template->set_global("previous_item", $previous_item);
$template->set_global("sibling_count", $movie->parent()->viewable()->children_count($where));
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/controllers/photos.php
Expand Up @@ -41,7 +41,7 @@ public function show($photo) {
$template->set_global("item", $photo);
$template->set_global("children", array());
$template->set_global("children_count", 0);
$template->set_global("parents", $photo->parents());
$template->set_global("parents", $photo->parents()->as_array());
$template->set_global("next_item", $next_item);
$template->set_global("previous_item", $previous_item);
$template->set_global("sibling_count", $photo->parent()->viewable()->children_count($where));
Expand Down
8 changes: 7 additions & 1 deletion modules/gallery/helpers/gallery_installer.php
Expand Up @@ -301,7 +301,8 @@ static function install() {
module::set_var("gallery", "admin_area_timeout", 90 * 60);
module::set_var("gallery", "maintenance_mode", 0);
module::set_var("gallery", "visible_title_length", 15);
module::set_version("gallery", 35);
module::set_var("gallery", "favicon_url", "lib/images/favicon.ico");
module::set_version("gallery", 36);
}

static function upgrade($version) {
Expand Down Expand Up @@ -590,6 +591,11 @@ static function upgrade($version) {
module::set_var("gallery", "visible_title_length", 15);
module::set_version("gallery", $version = 35);
}

if ($version == 35) {
module::set_var("gallery", "favicon_url", "lib/images/favicon.ico");
module::set_version("gallery", $version = 36);
}
}

static function uninstall() {
Expand Down
3 changes: 1 addition & 2 deletions modules/gallery/helpers/gallery_task.php
Expand Up @@ -58,8 +58,7 @@ static function available_tasks() {
$tasks[] = Task_Definition::factory()
->callback("gallery_task::fix")
->name(t("Fix your Gallery"))
->description(t("Fix a variety of problems that might cause your Gallery to act " .
"strangely. Requires maintenance mode."))
->description(t("Fix a variety of problems that might cause your Gallery to act strangely. Requires maintenance mode."))
->severity(log::SUCCESS);

return $tasks;
Expand Down
6 changes: 2 additions & 4 deletions modules/gallery/helpers/graphics.php
Expand Up @@ -338,8 +338,7 @@ static function detect_toolkits() {
} else {
$toolkits->imagemagick->installed = false;
$toolkits->imagemagick->error =
t("ImageMagick is installed, but PHP's open_basedir restriction " .
"prevents Gallery from using it.");
t("ImageMagick is installed, but PHP's open_basedir restriction prevents Gallery from using it.");
}
} else {
$toolkits->imagemagick->installed = false;
Expand All @@ -363,8 +362,7 @@ static function detect_toolkits() {
} else {
$toolkits->graphicsmagick->installed = false;
$toolkits->graphicsmagick->error =
t("GraphicsMagick is installed, but PHP's open_basedir restriction " .
"prevents Gallery from using it.");
t("GraphicsMagick is installed, but PHP's open_basedir restriction prevents Gallery from using it.");
}
} else {
$toolkits->graphicsmagick->installed = false;
Expand Down
37 changes: 31 additions & 6 deletions modules/gallery/helpers/l10n_scanner.php
Expand Up @@ -74,10 +74,21 @@ static function scan_php_file($file, &$cache) {
unset($raw_tokens);

if (!empty($func_token_list["t"])) {
l10n_scanner::_parse_t_calls($tokens, $func_token_list["t"], $cache);
$errors = l10n_scanner::_parse_t_calls($tokens, $func_token_list["t"], $cache);
foreach ($errors as $line => $error) {
Kohana_Log::add(
"error", "Translation scanner error. " .
"file: " . substr($file, strlen(DOCROOT)) . ", line: $line, context: $error");
}
}

if (!empty($func_token_list["t2"])) {
l10n_scanner::_parse_plural_calls($tokens, $func_token_list["t2"], $cache);
$errors = l10n_scanner::_parse_plural_calls($tokens, $func_token_list["t2"], $cache);
foreach ($errors as $line => $error) {
Kohana_Log::add(
"error", "Translation scanner error. " .
"file: " . substr($file, strlen(DOCROOT)) . ", line: $line, context: $error");
}
}
}

Expand All @@ -91,6 +102,7 @@ static function scan_info_file($file, &$cache) {
}

private static function _parse_t_calls(&$tokens, &$call_list, &$cache) {
$errors = array();
foreach ($call_list as $index) {
$function_name = $tokens[$index++];
$parens = $tokens[$index++];
Expand All @@ -103,14 +115,21 @@ private static function _parse_t_calls(&$tokens, &$call_list, &$cache) {
$message = self::_escape_quoted_string($first_param[1]);
l10n_scanner::process_message($message, $cache);
} else {
// t() found, but inside is something which is not a string literal.
// @todo Call status callback with error filename/line.
if (is_array($first_param) && ($first_param[0] == T_CONSTANT_ENCAPSED_STRING)) {
// Malformed string literals; escalate this
$errors[$first_param[2]] =
var_export(array($function_name, $parens, $first_param, $next_token), 1);
} else {
// t() found, but inside is something which is not a string literal. That's fine.
}
}
}
}
return $errors;
}

private static function _parse_plural_calls(&$tokens, &$call_list, &$cache) {
$errors = array();
foreach ($call_list as $index) {
$function_name = $tokens[$index++];
$parens = $tokens[$index++];
Expand All @@ -127,11 +146,17 @@ private static function _parse_plural_calls(&$tokens, &$call_list, &$cache) {
$plural = self::_escape_quoted_string($second_param[1]);
l10n_scanner::process_message(array("one" => $singular, "other" => $plural), $cache);
} else {
// t2() found, but inside is something which is not a string literal.
// @todo Call status callback with error filename/line.
if (is_array($first_param) && $first_param[0] == T_CONSTANT_ENCAPSED_STRING) {
$errors[$first_param[2]] = var_export(
array($function_name, $parens, $first_param,
$first_separator, $second_param, $next_token), 1);
} else {
// t2() found, but inside is something which is not a string literal. That's fine.
}
}
}
}
return $errors;
}

/**
Expand Down
33 changes: 0 additions & 33 deletions modules/gallery/helpers/theme.php
Expand Up @@ -77,39 +77,6 @@ static function load_themes() {
$config->set("core.modules", $modules);
}

static function get_edit_form_admin() {
$form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form"));
$group = $form->group("edit_theme")->label(t("Theme layout"));
$group->input("page_size")->label(t("Items per page"))->id("g-page-size")
->rules("required|valid_digit")
->error_messages("required", t("You must enter a number"))
->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "page_size"));
$group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("g-thumb-size")
->rules("required|valid_digit")
->error_messages("required", t("You must enter a number"))
->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "thumb_size"));
$group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("g-resize-size")
->rules("required|valid_digit")
->error_messages("required", t("You must enter a number"))
->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "resize_size"));
$group->textarea("header_text")->label(t("Header text"))->id("g-header-text")
->value(module::get_var("gallery", "header_text"));
$group->textarea("footer_text")->label(t("Footer text"))->id("g-footer-text")
->value(module::get_var("gallery", "footer_text"));
$group->checkbox("show_credits")->label(t("Show site credits"))->id("g-footer-text")
->checked(module::get_var("gallery", "show_credits"));

module::event("theme_edit_form", $form);

$group = $form->group("buttons")
->set_attr("style","border: none");
$group->submit("")->value(t("Save"));
return $form;
}

static function get_info($theme_name) {
$theme_name = preg_replace("/[^a-zA-Z0-9\._-]/", "", $theme_name);
$file = THEMEPATH . "$theme_name/theme.info";
Expand Down
6 changes: 2 additions & 4 deletions modules/gallery/libraries/IdentityProvider.php
Expand Up @@ -61,8 +61,7 @@ static function reset() {
* Return a commen confirmation message
*/
static function confirmation_message() {
return t("Are you sure you want to change your Identity Provider? " .
"Continuing will delete all existing users.");
return t("Are you sure you want to change your Identity Provider? Continuing will delete all existing users.");
}

static function change_provider($new_provider) {
Expand Down Expand Up @@ -113,8 +112,7 @@ static function change_provider($new_provider) {
}

message::error(
t("Error attempting to enable \"%new_provider\" identity provider, " .
"reverted to \"%old_provider\" identity provider",
t("Error attempting to enable \"%new_provider\" identity provider, reverted to \"%old_provider\" identity provider",
array("new_provider" => $new_provider, "old_provider" => $current_provider)));

$restore_already_running = false;
Expand Down
9 changes: 9 additions & 0 deletions modules/gallery/libraries/Theme_View.php
Expand Up @@ -236,6 +236,13 @@ public function __call($function, $args) {
case "thumb_bottom":
case "thumb_info":
case "thumb_top":
if ($function == "head") {
// Stash any CSS we have already; that came from the theme and we want theme CSS to
// override module CSs
$save_css = $this->css;
$this->css = array();
}

$blocks = array();
if (method_exists("gallery_theme", $function)) {
switch (count($args)) {
Expand Down Expand Up @@ -275,6 +282,8 @@ public function __call($function, $args) {
}

if ($function == "head") {
// Merge the theme CSS/JS at the end
$this->css = array_merge($this->css, $save_css);
array_unshift($blocks, $this->combine_files($this->css, "css"));
array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
}
Expand Down

0 comments on commit 866f8ee

Please sign in to comment.