based on the migrate module by Jesse Mullan * @version $Revision: 17580 $ */ class SelectPicasaExportPathController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest($form) { global $gallery; /* Verify that active user is an admin */ $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); if ($ret) { return array($ret, null); } $error = $status = array(); if (isset($form['action']['select'])) { if (empty($form['picasaXmlPath'])) { $error[] = 'form[error][picasaXmlPath][missing]'; } else { $platform =& $gallery->getPlatform(); $slash = $platform->getDirectorySeparator(); $tmp = trim($form['picasaXmlPath']); if ($tmp[strlen($tmp)-1] != $slash) { $tmp .= $slash; } GalleryUtilities::unsanitizeInputValues($tmp, false); $form['picasaXmlPath'] = trim($tmp); if (!Picasa2DataParser::isValidPicasaXmlPath($form['picasaXmlPath'])) { $error[] = 'form[error][picasaXmlPath][invalid]'; } } if (empty($error)) { $session =& $gallery->getSession(); $recentPaths = $session->get('picasa.view.SelectPicasaExportPath.recentPaths'); if (empty($recentPaths)) { $recentPaths = array(); } if (isset($recentPaths[$form['picasaXmlPath']])) { $recentPaths[$form['picasaXmlPath']]++; } else { $recentPaths[$form['picasaXmlPath']] = 1; } $session->put('picasa.view.SelectPicasaExportPath.recentPaths', $recentPaths); $redirect['view'] = 'core.SiteAdmin'; $redirect['subView'] = 'picasa.ConfirmPicasaImport'; $redirect['picasaXmlPath'] = $form['picasaXmlPath']; $redirect['destinationAlbumId'] = $form['destinationAlbumId']; } } if (!empty($redirect)) { $results['redirect'] = $redirect; } else { $results['delegate']['view'] = 'core.SiteAdmin'; $results['delegate']['subView'] = 'picasa.SelectPicasaExportPath'; } $results['status'] = $status; $results['error'] = $error; return array(null, $results); } } /** * First step of import process */ class SelectPicasaExportPathView extends GalleryView { /** * @see GalleryView::loadTemplate */ function loadTemplate(&$template, &$form) { global $gallery; $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); if ($ret) { return array($ret, null); } if ($form['formName'] != 'SelectPicasaExportPath') { $form['formName'] = 'SelectPicasaExportPath'; $form['picasaXmlPath'] = ''; $form['destinationAlbumId'] = ''; } /* Load our recent paths from the session */ $session =& $gallery->getSession(); $recentPaths = $session->get('picasa.view.SelectPicasaExportPath.recentPaths'); if (empty($recentPaths)) { $recentPaths = array(); } list ($ret, $operations) = GalleryCoreApi::getToolkitOperations('image/jpeg'); if ($ret) { return array($ret, null); } $hasToolkit = false; for ($i = 0; $i < sizeof($operations); $i++) { if ($operations[$i]['name'] == 'thumbnail') { $hasToolkit = true; break; } } /* Get ids of all all albums where we can add new album items */ list ($ret, $albumIds) = GalleryCoreApi::fetchAllItemIds('GalleryAlbumItem', 'core.addAlbumItem'); if ($ret) { return array($ret, null); } /* Load all the album entities */ list ($ret, $albums) = GalleryCoreApi::loadEntitiesById($albumIds, 'GalleryAlbumItem'); if ($ret) { return array($ret, null); } $albumTree = GalleryUtilities::createAlbumTree($albums); $SelectPicasaExportPath = array(); $SelectPicasaExportPath['recentPaths'] = $recentPaths; $SelectPicasaExportPath['hasToolkit'] = $hasToolkit; $SelectPicasaExportPath['g2AlbumTree'] = $albumTree; $template->setVariable('controller', 'picasa.SelectPicasaExportPath'); $template->setVariable('SelectPicasaExportPath', $SelectPicasaExportPath); return array(null, array('body' => 'modules/picasa/templates/SelectPicasaExportPath.tpl')); } } ?>