From 050c5a0383b6b1729dbd828d820d5eb347d1b795 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 30 Jun 2009 17:58:33 -0700 Subject: Unlink the old rewritten path files in var/modules/g2_import when we validate the embed path. This resolves an issue with b1 installs which had versions of the rewritten code that were buggy and can be replaced. --- modules/g2_import/helpers/g2_import.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 91ca1e63..910f9342 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -46,6 +46,10 @@ class g2_import_Core { } static function is_valid_embed_path($embed_path) { + $mod_path = VARPATH . "modules/g2_import/" . md5($embed_path); + if (file_exists($mod_path)) { + dir::unlink($mod_path); + } return file_exists($embed_path) && g2_import::init_embed($embed_path); } -- cgit v1.2.3 From 6f3ec5f03914324f596e51f22f2df49ec48e8053 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 1 Jul 2009 22:18:52 -0700 Subject: Fix for ticket #357. Changed the set the created date as part of the import and change models/comment::save() to not set the creation date if it is already set. --- modules/comment/models/comment.php | 2 +- modules/g2_import/helpers/g2_import.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index ec4d4794..22c465df 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -59,7 +59,7 @@ class Comment_Model extends ORM { public function save() { if (!empty($this->changed)) { $this->updated = time(); - if (!$this->loaded) { + if (!$this->loaded && empty($this->created)) { $this->created = $this->updated; } } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 910f9342..c2ad443c 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -554,6 +554,7 @@ class g2_import_Core { $comment->text = $text; $comment->state = "published"; $comment->server_http_host = $g2_comment->getHost(); + $comment->created = $g2_comment->getDate(); $comment->save(); self::map($g2_comment->getId(), $comment->id); -- cgit v1.2.3 From 7bc40fd3152c35d95b69b320c351d91a7ca0675a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 1 Jul 2009 23:14:01 -0700 Subject: Start of fixing a problem with importing movies w/o a thumbnail --- modules/g2_import/helpers/g2_import.php | 48 ++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index c2ad443c..93d92659 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -638,33 +638,37 @@ class g2_import_Core { $target_thumb_size = module::get_var("gallery", "thumb_size"); $target_resize_size = module::get_var("gallery", "resize_size"); - foreach ($derivatives[$g2_item_id] as $derivative) { - if ($derivative->getPostFilterOperations()) { - // Let's assume for now that this is a watermark operation, which we can't handle. - continue; - } + if (!empty($derivatives[$g2_item_id])) { + foreach ($derivatives[$g2_item_id] as $derivative) { + if ($derivative->getPostFilterOperations()) { + // Let's assume for now that this is a watermark operation, which we can't handle. + continue; + } - if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_THUMBNAIL && - $item->thumb_dirty && - ($derivative->getWidth() == $target_thumb_size || - $derivative->getHeight() == $target_thumb_size)) { - if (@copy(g2($derivative->fetchPath()), $item->thumb_path())) { - $item->thumb_height = $derivative->getHeight(); - $item->thumb_width = $derivative->getWidth(); - $item->thumb_dirty = false; + if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_THUMBNAIL && + $item->thumb_dirty && + ($derivative->getWidth() == $target_thumb_size || + $derivative->getHeight() == $target_thumb_size)) { + if (@copy(g2($derivative->fetchPath()), $item->thumb_path())) { + $item->thumb_height = $derivative->getHeight(); + $item->thumb_width = $derivative->getWidth(); + $item->thumb_dirty = false; + } } - } - if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_RESIZE && - $item->resize_dirty && - ($derivative->getWidth() == $target_resize_size || - $derivative->getHeight() == $target_resize_size)) { - if (@copy(g2($derivative->fetchPath()), $item->resize_path())) { - $item->resize_height = $derivative->getHeight(); - $item->resize_width = $derivative->getWidth(); - $item->resize_dirty = false; + if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_RESIZE && + $item->resize_dirty && + ($derivative->getWidth() == $target_resize_size || + $derivative->getHeight() == $target_resize_size)) { + if (@copy(g2($derivative->fetchPath()), $item->resize_path())) { + $item->resize_height = $derivative->getHeight(); + $item->resize_width = $derivative->getWidth(); + $item->resize_dirty = false; + } } } + } else { + // @todo Figure out away to create the thumbnail and resizes? } $item->save(); } -- cgit v1.2.3 From a13ddfea8fb461d38263fc90f40ecbe37a15029b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 2 Jul 2009 07:53:24 -0700 Subject: Suppress the filesize error if the thumbnail is not found so we can get an EMPTY_INPUT_FILE exception which we can then log and continue. --- modules/g2_import/helpers/g2_import.php | 2 -- modules/gallery/helpers/graphics.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 93d92659..71199eaf 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -667,8 +667,6 @@ class g2_import_Core { } } } - } else { - // @todo Figure out away to create the thumbnail and resizes? } $item->save(); } diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 71b8ddd8..bbae0602 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"); } -- cgit v1.2.3 From 1c9dee93de837e7bf4a2ba038388ae1836653e0a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 2 Jul 2009 09:54:50 -0700 Subject: Fix for ticket #390. Added a call to GalleryCoreApi::fetchItemViewCounts to retrieve the gallery2 view counts forthe imported items. --- modules/g2_import/helpers/g2_import.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 71199eaf..0a4013ca 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -402,6 +402,7 @@ class g2_import_Core { $g2_album = ORM::factory("item", $g3_album_id); $g2_album->album_cover_item_id = $item->id; $g2_album->thumb_dirty = 1; + $g2_album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); $g2_album->save(); graphics::generate($g2_album); } @@ -498,6 +499,8 @@ class g2_import_Core { if (isset($item)) { self::set_map($g2_item_id, $item->id); + $item->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id)); + $item->save(); } if ($corrupt) { -- cgit v1.2.3 From adb820e37c95277b07ade93b2404fb3bc213380a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 2 Jul 2009 20:48:47 -0700 Subject: Fix for ticket #359 and a partial fix for ticket #345. In G2, text strings have the &, ", < and > replaced by &, "e;, < and > respectively. Created the _decode_html_special_chars method in helpers/g2_import.php to revert these character strings. --- modules/g2_import/helpers/g2_import.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 0a4013ca..a2d0797d 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -341,8 +341,8 @@ class g2_import_Core { $album = album::create( $parent_album, $g2_album->getPathComponent(), - $g2_album->getTitle(), - self::extract_description($g2_album), + self::_decode_html_special_chars($g2_album->getTitle()), + self::_decode_html_special_chars(self::extract_description($g2_album)), self::map($g2_album->getOwnerId())); $album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); @@ -455,12 +455,14 @@ class g2_import_Core { $corrupt = 1; } try { + Kohana::log("error", "description: " . self::extract_description($g2_item)); + Kohana::log("error", "title: " . $g2_item->getTitle()); $item = photo::create( $parent, $g2_path, $g2_item->getPathComponent(), - $g2_item->getTitle(), - self::extract_description($g2_item), + self::_decode_html_special_chars($g2_item->getTitle()), + self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { Kohana::log( @@ -477,8 +479,8 @@ class g2_import_Core { $parent, $g2_path, $g2_item->getPathComponent(), - $g2_item->getTitle(), - self::extract_description($g2_item), + self::_decode_html_special_chars($g2_item->getTitle()), + self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); } catch (Exception $e) { Kohana::log("alert", "Corrupt movie $g2_path\n" . @@ -528,6 +530,15 @@ class g2_import_Core { self::$current_g2_item = null; } + /** + * g2 encoded'&', '"', '<' and '>' as '&', '"', '<' and '>' respectively. + * This function undoes that encoding. + */ + private static function _decode_html_special_chars($value) { + return str_replace(array("&", """, "<", ">"), + array("&", "\"", "<", ">"), $value); + } + /** * Import a single comment. */ -- cgit v1.2.3 From cf279fc315841836f92c8a81935db00bb3a919ff Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 3 Jul 2009 08:14:28 -0700 Subject: Fix for #364 = G2 Import Doesn't support markup Create a _transform_bbcode which coverts the g2 bbcode to html. The html won't be rendered until ticket #400 is implemented as pclean() excapse the html --- modules/g2_import/helpers/g2_import.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index a2d0797d..91fcbe8e 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -565,7 +565,7 @@ class g2_import_Core { $comment->author_id = self::map($g2_comment->getCommenterId()); $comment->guest_name = $g2_comment->getAuthor(); $comment->item_id = self::map($g2_comment->getParentId()); - $comment->text = $text; + $comment->text = self::_transform_bbcode($text); $comment->state = "published"; $comment->server_http_host = $g2_comment->getHost(); $comment->created = $g2_comment->getDate(); @@ -752,7 +752,29 @@ class g2_import_Core { } else { $description = $g2_summary . " " . $g2_description; } - return $description; + return self::_transform_bbcode($description); + } + + static $bbcode_mappings = array( + "#\\[b\\](.*?)\\[/b\\]#" => "$1", + "#\\[i\\](.*?)\\[/i\\]#" => "$1", + "#\\[u\\](.*?)\\[/u\\]#" => "$1", + "#\\[s\\](.*?)\\[/s\\]#" => "$1", + "#\\[url\\](.*?)\[/url\\]#" => "$1", + "#\\[url=(.*?)\\](.*?)\[/url\\]#" => "$2", + "#\\[img\\](.*?)\\[/img\\]#" => "", + "#\\[quote\\](.*?)\\[/quote\\]#" => "

$1

", + "#\\[code\\](.*?)\\[/code\\]#" => "
$1
", + "#\\[color=([^\\[]*)\\]([^\\[]*)\\[/color\\]#" => "$2/span>", + "#\\[ul\\](.*?)\\/ul\\]#" => "
    $1
", + "#\\[li\\](.*?)\\[/li\\]#" => "
  • $1
  • ", + ); + private static function _transform_bbcode($text) { + if (strpos($text, "[") !== false) { + $text = preg_replace(array_keys(self::$bbcode_mappings), array_values(self::$bbcode_mappings), + $text); + } + return $text; } /** -- cgit v1.2.3