1
0

Added the initial version of the Gallery1 Import module.

This commit is contained in:
Thomas E. Horner 2011-05-18 18:50:44 +02:00
parent 799a692ff9
commit 601c2b58d6
12 changed files with 2265 additions and 0 deletions

View File

@ -0,0 +1,126 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_g1_import_Controller extends Admin_Controller {
public function index() {
if (g1_import::is_configured()) {
g1_import::init();
}
$view = new Admin_View('admin.html');
$view->page_title = t('Gallery 1 import');
$view->content = new View('admin_g1_import.html');
if (is_dir(g1_import::$album_dir)) {
$view->content->g1_stats = $g1_stats = g1_import::g1_stats();
$view->content->g3_stats = $g3_stats = g1_import::g3_stats();
$view->content->g1_sizes = g1_import::common_sizes();
$view->content->g1_version = g1_import::version();
// Don't count tags because we don't track them in g1_map
$view->content->g1_resource_count =
$g1_stats['users'] + $g1_stats['groups'] + $g1_stats['albums'] +
$g1_stats['photos'] + $g1_stats['movies'] + $g1_stats['comments'];
$view->content->g3_resource_count =
$g3_stats['user'] + $g3_stats['group'] + $g3_stats['album'] +
$g3_stats['item'] + $g3_stats['comment'] + $g3_stats['tag'];
}
$view->content->form = $this->_get_import_form();
$view->content->version = '';
$view->content->thumb_size = module::get_var('gallery', 'thumb_size');
$view->content->resize_size = module::get_var('gallery', 'resize_size');
if (g1_import::is_initialized()) {
if ((bool)ini_get('eaccelerator.enable') || (bool)ini_get('xcache.cacher')) {
message::warning(t('The eAccelerator and XCache PHP performance extensions are known to cause issues. If you\'re using either of those and are having problems, please disable them while you do your import. Add the following lines: <pre>%lines</pre> to gallery3/.htaccess and remove them when the import is done.', array('lines' => "\n\n php_value eaccelerator.enable 0\n php_value xcache.cacher off\n php_value xcache.optimizer off\n\n")));
}
foreach (array('notification', 'search', 'exif') as $module_id) {
if (module::is_active($module_id)) {
message::warning(
t('<a href="%url">Deactivating</a> the <b>%module_id</b> module during your import will make it faster',
array('url' => url::site('admin/modules'), 'module_id' => $module_id)));
}
}
} else if (g1_import::is_configured()) {
$view->content->form->configure_g1_import->albums_path->add_error('invalid', 1);
}
print $view;
}
public function save() {
access::verify_csrf();
$form = $this->_get_import_form();
if ($form->validate()) {
$albums_path = $form->configure_g1_import->albums_path->value;
if (!is_file($albums_path) && file_exists("$albums_path/albums.php")) {
$albums_path = "$albums_path/albums.php";
}
if (($g1_init_error = g1_import::is_valid_albums_path($albums_path)) == 'ok') {
message::success(t('Gallery 1 path saved'));
module::set_var('g1_import', 'albums_path', $albums_path);
url::redirect('admin/g1_import');
} else {
$form->configure_g1_import->albums_path->add_error($g1_init_error, 1);
}
}
$view = new Admin_View('admin.html');
$view->content = new View('admin_g1_import.html');
$view->content->form = $form;
print $view;
}
public function autocomplete() {
$directories = array();
$path_prefix = Input::instance()->get('q');
foreach (glob('{$path_prefix}*') as $file) {
if (is_dir($file) && !is_link($file)) {
$directories[] = $file;
// If we find an albums.php, include it as well
if (file_exists("$file/albums.php")) {
$directories[] = "$file/albums.php";
}
}
}
print implode("\n", $directories);
}
private function _get_import_form() {
$albums_path = module::get_var('g1_import', 'albums_path', '');
$form = new Forge(
'admin/g1_import/save', '', 'post', array('id' => 'g-admin-configure-g1-import-form'));
$group = $form->group('configure_g1_import')->label(t('Configure Gallery 1 Import'));
$group->input('albums_path')->label(t('Filesystem path to your Gallery 1 albums.php file'))
->value($albums_path);
$group->albums_path->error_messages(
'invalid', t('The path you entered is not a Gallery 1 installation.'));
$group->albums_path->error_messages(
'broken', t('Your Gallery 1 install isn\'t working properly. Please verify it!'));
$group->albums_path->error_messages(
'missing', t('The path you entered does not exist.'));
$group->submit('')->value(g1_import::$album_dir=='' ? t('Change') : t('Continue'));
return $form;
}
}

View File

@ -0,0 +1,93 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class G1_Controller extends Controller {
/**
* Redirect Gallery 1 urls to their appropriate matching Gallery 3 url.
*
* We use mod_rewrite to create this path, so Gallery 1 urls like this:
* /gallery/Wedding/
* /gallery/Wedding/aaa
* /albums/Wedding/aaa.jpg
*
* Show up here like this:
* /g1/map?path=/gallery/Wedding/
* /g1/map?path=/gallery/Wedding/aaa
* /g1/map?path=/albums/Wedding/aaa.jpg
*/
public function map() {
$input = Input::instance();
$path = $input->get('path');
$page = $input->get('page');
if(!is_numeric($page)) $page = '';
if($path=='view_album.php' || $path=='slideshow.php') $path = $input->get('set_albumName');
if($path=='view_photo.php') $path = $input->get('set_albumName').'/'.$input->get('id');
if($path=='main.php') { //we do only name based g2 mapping here
$item = item::root();
access::required('view', $item);
url::redirect($item->abs_url(), '301');
}
// Item names come in as FolderX/ItemX
$album = 0;
$pos = strrpos($path, '/');
if($pos!==false) {
// Get ItemX into g1_item
$g1_item = substr($path,$pos+1);
// Get FolderX into g1_item
$g1_album = substr($path,0,$pos);
}
else {
$album = 1;
$g1_item = '';
$g1_album = $path;
}
// Only binary files (the item itself, not the html) may have file extensions
$binary = 0;
$pos = strrpos($g1_item, '.');
if($pos!==false) {
$binary = 1;
$g1_item = substr($g1_item, 0, $pos);
}
$mapping = ORM::factory('g1_map')->where('album', '=', $g1_album)->where('item', '=', $g1_item)->where('resource_type', '=', $album ? 'album':'item')->find();
if(!$mapping->loaded()) {
throw new Kohana_404_Exception();
}
$item = ORM::factory('item', $mapping->id);
if (!$item->loaded()) {
throw new Kohana_404_Exception();
}
access::required('view', $item);
if($binary) {
url::redirect($item->file_url(true), '301');
}
else {
$url = $item->abs_url();
if($page!='') {
$url .= (strpos($url,'?')!==false ? '&':'?').'page='.$page;
}
url::redirect($url, '301');
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,413 @@
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* This class provides an API for parsing Gallery 1 data files
* Updated to Gallery 3 by Thomas E. Horner
*/
class Gallery1DataParser {
/**
* Verify that the given path holds an albumdb and that the albumdb is readable
*
* @param string $path Path to albums
* @return boolean True if the path is valid, otherwise false
*/
function isValidAlbumsPath($path) {
if (file_exists($path . 'albumdb.dat')
&& is_readable($path . 'albumdb.dat')) {
return true;
} else {
return false;
}
}
/**
* Load and return user metadata from given file
*
* @param string $fileName Path to user file to unserialize
* @return array GalleryStatus a status code,
* object Unserialized user metadata
*/
function loadFile($fileName) {
if (!file_exists($fileName) || !is_readable($fileName)) {
if (file_exists($fileName . '.bak') &&
is_readable($fileName . '.bak')) {
$fileName .= '.bak';
} else {
return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__,
"Missing or not readable file: $fileName"), null);
}
}
$tmp = file($fileName);
if (empty($tmp)) {
return array(GalleryCoreApi::error(ERROR_MISSING_VALUE), null);
}
$tmp = join('', $tmp);
/*
* We renamed User.php to Gallery_User.php in v1.2, so port forward
* any saved user objects.
*/
if (!strcmp(substr($tmp, 0, 10), 'O:4:"user"')) {
$tmp = str_replace('O:4:"user"', 'O:12:"gallery_user"', $tmp);
}
/*
* Gallery3 already contains a class named Image so
* we need to rename the G1 Image class to G1Img here
*/
if (strpos($tmp, 'O:5:"Image"')!==false) {
$tmp = str_replace('O:5:"Image"', 'O:5:"G1Img"', $tmp);
}
$object = unserialize($tmp);
return array(null, $object);
}
/**
* Fetch an array of albums from a given path
*
* @param string $path Path to albums directory
* @return array GalleryStatus a status code,
* array of objects
*/
function getAlbumList($path) {
list ($ret, $albumOrder) = Gallery1DataParser::loadFile($path . 'albumdb.dat');
if ($ret) {
return array($ret, null);
}
/* TODO: check that there is an $albumOrder */
foreach ($albumOrder as $albumName) {
list ($ret, $albumFields) =
Gallery1DataParser::loadAlbumFields($path . $albumName . DIRECTORY_SEPARATOR);
if ($ret) {
return array($ret,'');
}
$albumList[$albumName] = $albumFields;
}
return array(null, $albumList);
}
/**
* Fetch an associative array of parentalbum names from a given path to gallery1 albums
*
* @param string $path Path to albums directory
* @return array GalleryStatus a status code,
* array of albums and their parents
*/
function getParentAlbumList($path) {
list ($ret, $albumOrder) = Gallery1DataParser::loadFile($path . 'albumdb.dat');
if ($ret) {
return array($ret, null);
}
foreach ($albumOrder as $albumName) {
list ($ret, $albumFields) =
Gallery1DataParser::loadAlbumFields($path . $albumName . DIRECTORY_SEPARATOR);
if ($ret) {
return array($ret,'');
}
$parentAlbumList[$albumName] = $albumFields['parentAlbumName'];
}
return array(null, $parentAlbumList);
}
/**
* Build a data tree of albums
*
* @param string $path Path to albums directory
* @return array GalleryStatus a status code,
* array of albumnames and their children, and their children...
*/
function getAlbumHierarchy($path) {
list ($ret, $parentAlbumList) = Gallery1DataParser::getParentAlbumList($path);
if ($ret) {
return array($ret, null);
}
foreach ($parentAlbumList as $myName => $parentName) {
if (!isset($tempAlbums[$myName])) {
$tempAlbums[$myName] = array();
}
if (empty($parentName) || $parentName == '.root') {
$hierarchy[$myName] = &$tempAlbums[$myName];
} else {
if (!isset($tempAlbums[$parentName])) {
$tempAlbums[$parentName] = array();
}
$tempAlbums[$parentName][$myName] = &$tempAlbums[$myName];
}
}
return array(null, $hierarchy);
}
/**
* Fetch an array of albums with no parents
*
* @param string $path Path to albums directory
* @return array GalleryStatus a status code,
* array of albumnames
*/
function getRootAlbums($path) {
list ($ret, $albumOrder) = Gallery1DataParser::loadFile($path . 'albumdb.dat');
if ($ret) {
return array($ret, null);
}
foreach ($albumOrder as $albumName) {
list ($ret, $albumFields) =
Gallery1DataParser::loadAlbumFields($path . $albumName . DIRECTORY_SEPARATOR);
if ($ret) {
return array($ret,'');
}
if ($albumFields['parentAlbumName'] == '.root') {
$rootAlbums[] = $albumName;
}
}
return array(null, $rootAlbums);
}
/**
* Load and return album metadata from given directory
*
* @param string $path Path to album directory
* @return array GalleryStatus a status code,
* object Unserialized album metadata
*/
function loadAlbumFields($path) {
$tmp = trim($path);
if ($tmp[strlen($tmp)-1] != DIRECTORY_SEPARATOR) {
$tmp .= DIRECTORY_SEPARATOR;
}
$path = trim($tmp);
$albumPath = explode(DIRECTORY_SEPARATOR, $path);
$albumName = $albumPath[count($albumPath)-2];
list ($ret, $album) = Gallery1DataParser::loadFile($path . 'album.dat');
if ($ret) {
return array($ret, null);
}
$album->fields['name'] = $albumName;
if (!$album->fields['parentAlbumName']) {
$album->fields['parentAlbumName'] = '.root';
}
return array(null, $album->fields);
}
/**
* Count the number of photos in an album dir
*
* @param string $path Path to album directory
* @return array GalleryStatus a status code,
* integer Count of photos
*/
function getPhotoCount($path) {
list ($ret, $photos) = Gallery1DataParser::loadFile($path . 'photos.dat');
if ($ret) {
return array($ret, null);
}
$photoCount = count($photos);
return array(null, $photoCount);
}
/**
* Count the photo data from an album dir
*
* @param string $path Path to album directory
* @return array GalleryStatus a status code,
* array Galleryphotos
*/
function getPhotos($path) {
list ($ret, $photos) = Gallery1DataParser::loadFile($path . DIRECTORY_SEPARATOR . 'photos.dat');
if ($ret) {
return array($ret, null);
}
return array(null, $photos);
}
/**
* Load user uids from path
*
* @param string $path Path to album directory
* @return array GalleryStatus a status code,
* array Associative array of uids and usernames
*/
function getUserUids($path) {
static $uids;
if (!isset($uids[$path])) {
if (!isset($uids)) {
$uids = array();
}
list ($ret, $userDB) =
Gallery1DataParser::loadFile($path . '.users' . DIRECTORY_SEPARATOR . 'userdb.dat');
if ($ret) {
return array($ret, null);
}
$uids[$path] = array();
foreach ($userDB->userMap as $username => $uid) {
if (Gallery1DataParser::isValidUid($path, $uid)
&& !Gallery1DataParser::isValidUid($path, $username)
&& !preg_match('/nobody|everybody|loggedin/i', $username)) {
$uids[$path][$uid] = $username;
}
}
}
return array(null, $uids[$path]);
}
/**
* Validate user id string from gallery v1.x.x
*
* @param string $uid Uid to be tested
* @return boolean
*/
function isValidUidString($uid) {
if (preg_match('/^\d{9,}_\d+$/', $uid)) {
return TRUE;
} else {
return FALSE;
}
}
/**
* Validate user id from gallery v1.x.x
*
* @param string $path
* @param string $uid Uid to be tested
* @return boolean
*/
function isValidUid($path, $uid) {
static $valid;
if (!isset($valid[$path][$uid])) {
if (!isset($valid)) {
$valid = array();
}
if (!isset($valid[$path])) {
$valid[$path] = array();
}
if (Gallery1DataParser::isValidUidString($uid)) {
list ($ret, $fields) = Gallery1DataParser::getUserFieldsByUid($path, $uid);
if (!$ret) {
$valid[$path][$uid] = TRUE;
} else {
$valid[$path][$uid] = FALSE;
}
} else {
$valid[$path][$uid] = FALSE;
}
}
return $valid[$path][$uid];
}
/**
* Load user metadata given a path and uid
*
* @param string $path Path to album directory
* @param string $uid Uid to import
* @return array GalleryStatus a status code,
* array User metadata
*/
function getUserFieldsByUid($path, $uid) {
static $fields;
if (!isset($fields[$path][$uid])) {
if (!isset($fields)) {
$fields = array();
}
if (!isset($fields[$path])) {
$fields[$path] = array();
}
$fields[$path][$uid] = array();
if (Gallery1DataParser::isValidUidString($uid)) {
list ($ret, $user) = Gallery1DataParser::loadFile($path . '.users' . DIRECTORY_SEPARATOR . $uid);
if ($ret) {
return array($ret, null);
}
foreach ($user as $key => $value) {
$fields[$path][$uid][$key] = $value;
}
}
}
return array(null, $fields[$path][$uid]);
}
/**
* Load user metadata given a path and username
*
* @param string $path Path to album directory
* @param string $username Username to import
* @return array GalleryStatus a status code,
* array User metadata
*/
function getUserFieldsByUsername($path, $username) {
list ($ret, $uids) = Gallery1DataParser::getUserUids($path);
if ($ret) {
return array($ret, null);
}
$usernames = array_flip($uids);
$uid = $usernames[$username];
list ($ret, $fields) = Gallery1DataParser::getUserFieldsByUid($path, $uid);
if ($ret) {
return array($ret, null);
}
return array(null, $fields);
}
}
/* Define these classes so that unserialize can use them */
/**
* A stub class into which various G1 objects can be unserialized.
*/
class G1AlbumDB{ }
/**
* A stub class into which various G1 objects can be unserialized.
*/
class Album { }
/**
* A stub class into which various G1 objects can be unserialized.
*/
class Gallery_UserDB { }
/**
* A stub class into which various G1 objects can be unserialized.
*/
class Gallery_User { }
/**
* A stub class into which various G1 objects can be unserialized.
*/
class AlbumItem { }
/**
* A stub class into which various G1 objects can be unserialized.
*/
class G1Img { }
/**
* A stub class into which various G1 objects can be unserialized.
*/
class Comment { }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class g1_import_event_Core {
static function item_deleted($item) {
db::build()
->delete("g1_maps")
->where("id", "=", $item->id)
->execute();
}
static function item_created($item) {
g1_import::copy_matching_thumbnails_and_resizes($item);
}
static function admin_menu($menu, $theme) {
$menu
->get("settings_menu")
->append(Menu::factory("link")
->id("g1_import")
->label(t("Gallery 1 import"))
->url(url::site("admin/g1_import")));
}
}

View File

@ -0,0 +1,46 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class g1_import_installer {
static function install() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {g1_maps} (
`id` int(9) NOT NULL,
`album` varchar(128) NOT NULL,
`item` varchar(128) default NULL,
`resource_type` varchar(64) default NULL,
PRIMARY KEY (`id`, `resource_type`),
KEY `g1_map_index` (`album`, `item`))
DEFAULT CHARSET=utf8;");
module::set_version("g1_import", 1);
}
static function upgrade($version) {
$db = Database::instance();
/* reserved for future versions
if ($version == 1) {
module::set_version('g1_import', $version = 2);
}
//*/
}
static function uninstall() {
}
}

View File

@ -0,0 +1,215 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class g1_import_task_Core {
static function available_tasks() {
$version = '';
if (g1_import::is_configured()) {
g1_import::init();
// Guard from common case where the import has been
// completed and the original files have been removed.
if (is_dir(g1_import::$album_dir)) {
$version = g1_import::version();
}
}
if (g1_import::is_initialized()) {
return array(Task_Definition::factory()
->callback('g1_import_task::import')
->name(t('Import from Gallery 1'))
->description(
t('Gallery %version detected', array('version' => $version)))
->severity(log::SUCCESS));
}
return array();
}
static function import($task) {
$start = microtime(true);
g1_import::init();
$stats = $task->get('stats');
$done = $task->get('done');
$total = $task->get('total');
$completed = $task->get('completed');
$mode = $task->get('mode');
$queue = $task->get('queue');
if (!isset($mode)) {
$stats = g1_import::g1_stats();
$stats['items'] = $stats['photos'] + $stats['movies'];
unset($stats['photos']);
unset($stats['movies']);
$stats['fix'] = 1;
$task->set('stats', $stats);
$task->set('total', $total = array_sum(array_values($stats)));
$completed = 0;
$mode = 0;
$done = array();
foreach (array_keys($stats) as $key) {
$done[$key] = 0;
}
$task->set('done', $done);
}
$modes = array('users', 'albums', 'items', 'comments', 'highlights', 'fix', 'done');
while (!$task->done && microtime(true) - $start < 1.5) {
if ($done[$modes[$mode]] >= $stats[$modes[$mode]]) {
// Nothing left to do for this mode. Advance.
$mode++;
$task->set('last_id', 0);
$queue = array();
// Start the loop from the beginning again. This way if we get to a mode that requires no
// actions (eg, if the G1 comments module isn't installed) we won't try to do any comments
// queries.. in the next iteration we'll just skip over that mode.
if ($modes[$mode] != 'done') {
continue;
}
}
switch($modes[$mode]) {
case 'users':
$done['users'] = $stats['users']-1;
$task->status = t(
'Ignoring users (%count of %total)',
array('count' => $done['users'], 'total' => $stats['users']));
break;
case 'albums':
if (empty($queue)) {
if(count(g1_import::$tree)==0) {
g1_import::g1_stats();
}
$task->set('queue', $queue = array('' => g1_import::$tree));
}
$log_message = g1_import::import_album($queue);
if ($log_message) {
$task->log($log_message);
}
$task->status = t(
'Importing albums (%count of %total)',
array('count' => $done['albums'] + 1, 'total' => $stats['albums']));
break;
case 'items':
if (empty($queue)) {
if (count(g1_import::$queued_items)==0) {
g1_import::g1_stats();
}
$queuelen = 100;
$thisstart = $task->get('last_id', 0);
$nextstart = $thisstart + $queuelen;
$task->set('last_id', $nextstart);
$task->set('queue', $queue = array_splice(g1_import::$queued_items, $thisstart, $queuelen));
}
$log_message = g1_import::import_item($queue);
if ($log_message) {
$task->log($log_message);
}
$task->status = t(
'Importing photos (%count of %total)',
array('count' => $done['items'] + 1, 'total' => $stats['items']));
break;
case 'comments':
if (empty($queue)) {
if (count(g1_import::$queued_comments)==0) {
g1_import::g1_stats();
}
$queuelen = 100;
$thisstart = $task->get('last_id', 0);
$nextstart = $thisstart + $queuelen;
$task->set('last_id', $nextstart);
$task->set('queue', $queue = array_splice(g1_import::$queued_comments, $thisstart, $queuelen));
}
$log_message = g1_import::import_comment($queue);
if ($log_message) {
$task->log($log_message);
}
$task->status = t(
'Importing comments (%count of %total)',
array('count' => $done['comments'] + 1, 'total' => $stats['comments']));
break;
case 'highlights':
if (empty($queue)) {
if (count(g1_import::$queued_highlights)==0) {
g1_import::g1_stats();
}
$queuelen = 100;
$thisstart = $task->get('last_id', 0);
$nextstart = $thisstart + $queuelen;
$task->set('last_id', $nextstart);
$task->set('queue', $queue = array_splice(g1_import::$queued_highlights, $thisstart, $queuelen));
}
$log_message = g1_import::set_album_highlight($queue);
if ($log_message) {
$task->log($log_message);
}
$task->status = t(
'Album highlights (%count of %total)',
array('count' => $done['highlights'] + 1, 'total' => $stats['highlights']));
break;
case 'fix':
if (empty($queue)) {
if (count(g1_import::$albums_flat)==0) {
g1_import::g1_stats();
}
$task->set('queue', $queue = 'dummy');
}
$log_message = g1_import::hotfix_all();
if ($log_message) {
$task->log($log_message);
}
$task->status = t(
'Final Hotfixing (%count of %total)',
array('count' => $done['fix'] + 1, 'total' => $stats['fix']));
break;
case 'done':
$task->status = t('Import complete');
$task->done = true;
$task->state = 'success';
break;
}
if (!$task->done) {
$done[$modes[$mode]]++;
$completed++;
}
}
$task->percent_complete = 100 * ($completed / $total);
$task->set('completed', $completed);
$task->set('mode', $mode);
$task->set('queue', $queue);
$task->set('done', $done);
}
}

View File

@ -0,0 +1,39 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* A wrapper for exceptions to report more details in case
* it's a ORM validation exception.
*/
class G1_Import_Exception extends Exception {
public function __construct($message, Exception $previous=null, $additional_messages=null) {
if ($additional_messages) {
$message .= "\n" . implode("\n", $additional_messages);
}
if ($previous && $previous instanceof ORM_Validation_Exception) {
$message .= "\nORM validation errors: " . print_r($previous->validation->errors(), true);
}
if ($previous) {
$message .= "\n" . (string) $previous;
}
// The $previous parameter is supported in PHP 5.3.0+.
parent::__construct($message);
}
}

View File

@ -0,0 +1,21 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class G1_Map_Model_Core extends ORM {
}

View File

@ -0,0 +1,7 @@
name = "Gallery1 Import"
description = "Import your Gallery 1 content into Gallery 3"
version = 1
author_name = "Thomas E. Horner"
author_url = "http://www.t-horner.com"
info_url = "http://www.t-horner.com/g1_import"
discuss_url = "http://gallery.menalto.com/forum_module_g1_import"

View File

@ -0,0 +1,180 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<?= $theme->css("jquery.autocomplete.css") ?>
<?= $theme->script("jquery.autocomplete.js") ?>
<script type="text/javascript">
$("document").ready(function() {
$("form input[name=albums_path]").autocomplete(
"<?= url::site("__ARGS__") ?>".replace("__ARGS__", "admin/g1_import/autocomplete"),
{
max: 256,
loadingClass: "g-loading-small",
});
});
</script>
<div id="g-admin-g1-import" class="g-block">
<h1> <?= t("Gallery 1 import") ?> </h1>
<p>
<?= t("Import your Gallery 1 photos, movies and comments into your new Gallery 3 installation.") ?>
</p>
<script type="text/javascript">
$(document).ready(function() {
$("#g-admin-g1-import-tabs").tabs()
<? if (!isset($g1_version)): ?>
.tabs("disable", 1)
.tabs("disable", 2)
<? elseif ($g3_resource_count > .9 * $g1_resource_count): ?>
.tabs("select", 2)
<? else: ?>
.tabs("select", 1)
<? endif ?>
;
// Show the tabs after the page has loaded to prevent Firefox from rendering the
// unstyled page and then flashing.
$("#g-admin-g1-import-tabs").show();
});
</script>
<div id="g-admin-g1-import-tabs" class="g-block-content" style="display: none">
<ul>
<li>
<a href="#g-admin-g1-import-configure"><?= t("1. Configure Gallery 1 path") ?></a>
</li>
<li>
<a href="#g-admin-g1-import-import"><?= t("2. Import!") ?></a>
</li>
<li>
<a href="#g-admin-g1-import-notes"><?= t("3. After your import") ?></a>
</li>
<li>
<form action="https://www.paypal.com/cgi-bin/webscr" target="_blank" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----">
<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online." style="background-color: transparent">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
</li>
</ul>
<div id="g-admin-g1-import-configure" class="g-block-content">
<?= $form ?>
</div>
<div id="g-admin-g1-import-import">
<? if (isset($g1_version)): ?>
<ul>
<li>
<?= t("Gallery version %version detected", array("version" => $g1_version)) ?>
</li>
<? if ($g1_sizes["thumb"]["size"] && $thumb_size != $g1_sizes["thumb"]["size"]): ?>
<li>
<?= t("Your most common thumbnail size in Gallery 1 is %g1_pixels pixels, but your Gallery 3 thumbnail size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.",
array("g1_pixels" => $g1_sizes["thumb"]["size"],
"g3_pixels" => $thumb_size,
"url" => html::mark_clean(url::site("admin/theme_options")))) ?>
</li>
<? endif ?>
<? if ($g1_sizes["resize"]["size"] && $resize_size != $g1_sizes["resize"]["size"]): ?>
<li>
<?= t("Your most common intermediate size in Gallery 1 is %g1_pixels pixels, but your Gallery 3 intermediate size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.",
array("g1_pixels" => $g1_sizes["resize"]["size"],
"g3_pixels" => $resize_size,
"url" => html::mark_clean(url::site("admin/theme_options")))) ?>
</li>
<? endif ?>
<li>
<?
$t = array();
$t[] = t2("1 user", "%count users", $g1_stats["users"]);
$t[] = t2("1 group", "%count groups", $g1_stats["groups"]);
$t[] = t2("1 album", "%count albums", $g1_stats["albums"]);
$t[] = t2("1 photo", "%count photos/movies", $g1_stats["photos"] + $g1_stats["movies"]);
$t[] = t2("1 comment", "%count comments", $g1_stats["comments"]);
$t[] = t2("1 tagged photo/movie/album", "%count tagged photos/movies/albums",
$g1_stats["tags"]);
?>
<?= t("Your Gallery 1 has the following importable data in it: %t0, %t1, %t2, %t3, %t4, %t5",
array("t0" => $t[0], "t1" => $t[1], "t2" => $t[2],
"t3" => $t[3], "t4" => $t[4], "t5" => $t[5])) ?>
</li>
<? if ($g3_resource_count): ?>
<li>
<?
$t = array();
$t[] = t2("1 user", "%count users", $g3_stats["user"]);
$t[] = t2("1 group", "%count groups", $g3_stats["group"]);
$t[] = t2("1 album", "%count albums", $g3_stats["album"]);
$t[] = t2("1 photo/movie", "%count photos/movies", $g3_stats["item"]);
$t[] = t2("1 comment", "%count comments", $g3_stats["comment"]);
$t[] = t2("1 tagged photo/movie/album", "%count tagged photos/movies/albums", $g3_stats["tag"]);
?>
<?= t("It looks like you've imported the following Gallery 1 data already: %t0, %t1, %t2, %t3, %t4, %t5",
array("t0" => $t[0], "t1" => $t[1], "t2" => $t[2],
"t3" => $t[3], "t4" => $t[4], "t5" => $t[5])) ?>
</li>
<? endif ?>
</ul>
<p>
<a class="g-button g-dialog-link ui-state-default ui-corner-all"
href="<?= url::site("admin/maintenance/start/g1_import_task::import?csrf=$csrf") ?>">
<?= t("Begin import!") ?>
</a>
</p>
<? endif ?>
</div>
<div id="g-admin-g1-import-notes" class="g-text">
<ul>
<li>
<?= t("Gallery 3 does not support per-user / per-item permissions. <b>Review permissions!</b>") ?>
</li>
<li>
<?= t("The only supported file formats are JPG, PNG and GIF, FLV and MP4. Other formats will be skipped.") ?>
</li>
<li>
<p>
<?= t("Redirecting G1 Gallery URLs once your migration is complete. Put this block at the top of %path and all gallery urls will be redirected to Gallery 3",
array("path" => g1_import::$gallery_dir.DIRECTORY_SEPARATOR.'.htaccess') ) ?>
</p>
<textarea id="g-g1-gallery-redirect-rules" rows="4" cols="60">&lt;IfModule mod_rewrite.c&gt;
Options +FollowSymLinks
RewriteEngine On
<? /* RewriteBase <?= html::clean(g1_import::$gallery_url) ?> */ ?>
RewriteRule ^(.*)$ <?= url::site("g1/map?path=\$1") ?> [QSA,L,R=301]
&lt;/IfModule&gt;</textarea>
<script type="text/javascript">
$(document).ready(function() {
$("#g-g1-gallery-redirect-rules").click(function(event) {
this.select();
});
});
</script>
</li>
<li>
<p>
<?= t("Redirecting G1 Album URLs once your migration is complete. Put this block at the top of %path and all album image urls will be redirected to Gallery 3",
array("path" => g1_import::$album_dir.DIRECTORY_SEPARATOR.'.htaccess') ) ?>
</p>
<textarea id="g-g1-album-redirect-rules" rows="4" cols="60">&lt;IfModule mod_rewrite.c&gt;
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ <?= url::site("g1/map?path=\$1") ?> [QSA,L,R=301]
&lt;/IfModule&gt;</textarea>
<script type="text/javascript">
$(document).ready(function() {
$("#g-g1-album-redirect-rules").click(function(event) {
this.select();
});
});
</script>
</li>
</ul>
</div>
</div>
</div>