From: Alan H. <min...@us...> - 2005-05-26 17:46:33
|
Update of /cvsroot/gallery/gallery2/modules/rewrite/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11709/modules/rewrite/classes Modified Files: RewriteCheckConflictTask.class RewriteHelper.class RewriteUrlGenerator.class Log Message: New multisite system that is compatible with both URL rewrite module and embedded G2. New system uses a directory with some wrapper scripts to define the new site. This directory has its own config.php (and .htaccess for url rewrite). Symlink/htaccess multisite method and galleryId concept are gone. UrlGenerator - Add generate-url logic to support new multisites.. For 'href' urls always use G2 base url (direct to G2 codebase location, even if multisite or embedded), For 'core:DownloadItem' urls always use G2 site url (direct to main.php in dir for active config.php, even if embedded) Otherwise use application url (embed url; same as G2 site url if not embedded) - Urlencode all parameters instead of using htmlentities. Removed some now not needed urlencodes/decodes. - Support arbitrary depth of nest[ed][arrays] in params. - Additional code cleanup and optimization. - Maintain navId in RewriteUrlGenerator. Installer - Removed old multisite processing in installer and replaced with new installer step that selects between standard install or multisite install which collects location for new config. - Updated SecureStep to also check permissions of parent dir. Upgrader - Added mini url generator so it can run from a multisite install. - Added ability to update config.php during upgrade. - Added warning about old style multisite config.php and instructions in README to migrate this to the new system. Applets - Generate correct url to work in embedded G2. Index: RewriteUrlGenerator.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/rewrite/classes/RewriteUrlGenerator.class,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- RewriteUrlGenerator.class 11 May 2005 15:56:32 -0000 1.11 +++ RewriteUrlGenerator.class 26 May 2005 17:45:48 -0000 1.12 @@ -42,7 +42,7 @@ /** * If there's an error, use parent GalleryUrlGenerator functions. * - * @var bool has an error uccured? + * @var bool has an error occured? * @access private */ var $_error = false; @@ -58,7 +58,7 @@ /** * @see GalleryUrlGenerator::init */ - function init($baseFile, $embedPath=null, $relativeG2Path=null, $embedSessionString=null) { + function init($baseFile=null, $embedPath=null, $relativeG2Path=null, $embedSessionString=null) { parent::init($baseFile, $embedPath, $relativeG2Path, $embedSessionString); list($ret, $this->_shortUrls) = RewriteMap::getShortUrls(); @@ -105,8 +105,6 @@ * @see GalleryUrlGenerator::getNavigationReturnUrl */ function getNavigationReturnUrl() { - global $gallery; - $formUrl = GalleryUtilities::getRequestVariables('formUrl'); if (!empty($formUrl)) { /* @@ -135,15 +133,12 @@ * @see GalleryUrlGenerator::generateUrl */ function generateUrl($params=array(), $forceSessionId=null) { - global $gallery; - if ($this->_error) { return parent::generateUrl($params, $forceSessionId); } if (isset($params['view'])) { $index = $params['view']; - if (isset($params['subView'])) { $index .= '|' . $params['subView']; } @@ -151,6 +146,18 @@ /* Build the short style URL */ if (isset($index) && isset($this->_shortUrls[$index]) && !isset($params['href'])) { + /* Navigation */ + global $gallery; + $currentView = $gallery->getCurrentView(); + if (!empty($this->_navId) && (empty($currentView) || + $currentView == $params['view'] || !empty($params['controller']))) { + /* + * We are moving around in the same view or we are redirecting to a controller, + * who knows where it will redirect to. Let's keep the navigation. + */ + $params['navId'] = $this->_navId; + } + $url = $this->_shortUrls[$index]; unset($params['view']); unset($params['subView']); @@ -158,10 +165,10 @@ /* Load the entity if we need it later on */ if ((strpos($url, '%path%') !== false || strpos($url, '%fileName%') !== false || strpos($url, '%serialNumber%') !== false)) { - /* Assume rootAlbum idemId if not specified */ + /* Assume rootAlbum itemId if not specified */ if (!isset($params['itemId'])) { list ($ret, $params['itemId']) = - GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum'); + GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum'); if ($ret->isError()) { unset($params['itemId']); return parent::generateUrl($params, $forceSessionId); @@ -174,7 +181,7 @@ } } - preg_match_all('/\%([^\%]+)\%/', $url, $regs); + preg_match_all('/%([^%]+)%/', $url, $regs); foreach ($regs[1] as $arg) { if ($arg == 'path' && isset($entity)) { list ($ret, $path) = $entity->fetchLogicalPath(); @@ -182,32 +189,31 @@ if (!GalleryUtilities::isA($entity, 'GalleryAlbumItem')) { $path .= '.html'; } - $path = str_replace(' ', '+', $path); - $path = str_replace('#', '%23', $path); - - $url = str_replace('%' . $arg . '%', substr($path, 1), $url); + /* urlencode except for path separators(/) */ + $url = str_replace('%path%', + str_replace('%2F', '/', urlencode(substr($path, 1))), $url); unset($params['itemId']); } } else if ($arg == 'fileName' && isset($entity)) { list ($ret, $pseudoFileName) = GalleryUtilities::getPseudoFileName($entity); if ($ret->isError()) { - return null; + return parent::generateUrl($params, $forceSessionId); } if (strpos($pseudoFileName, '.') === false) { - list ($ret, $extensions) = GalleryCoreApi::convertMimeToExtensions( - $entity->getMimeType()); + list ($ret, $extensions) = + GalleryCoreApi::convertMimeToExtensions($entity->getMimeType()); if (!empty($extensions)) { $pseudoFileName .= '.' . $extensions[0]; } } - $url = str_replace('%' . $arg . '%', $pseudoFileName, $url); + $url = str_replace('%fileName%', urlencode($pseudoFileName), $url); } else if ($arg == 'serialNumber' && isset($entity)) { - $url = str_replace('%' . $arg . '%', $entity->getSerialNumber(), $url); + $url = str_replace('%serialNumber%', $entity->getSerialNumber(), $url); unset($params['serialNumber']); } else { - $url = str_replace('%' . $arg . '%', $params[$arg], $url); + $url = str_replace('%' . $arg . '%', urlencode($params[$arg]), $url); unset($params[$arg]); } } @@ -216,11 +222,10 @@ $url = $this->_baseFile; } - $params['href'] = $this->getCurrentUrlDir() . $url; + return parent::generateUrl($params, $forceSessionId, $this->getCurrentUrlDir() . $url); } return parent::generateUrl($params, $forceSessionId); } } - ?> Index: RewriteHelper.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/rewrite/classes/RewriteHelper.class,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- RewriteHelper.class 13 May 2005 00:07:36 -0000 1.14 +++ RewriteHelper.class 26 May 2005 17:45:48 -0000 1.15 @@ -78,7 +78,7 @@ $Htaccess['directory'] = $Htaccess['galleryDirectory']; $Htaccess['rewriteBase'] = $Htaccess['galleryDirectory']; - $Htaccess['baseFile'] = 'main.php'; + $Htaccess['baseFile'] = GALLERY_MAIN_PHP; if ($embedded) { $Htaccess['baseFile'] = $urlGenerator->_baseFile; list ($ret, $Htaccess['directory']) = @@ -122,8 +122,7 @@ return array(GalleryStatus::success(), $path . '/.htaccess'); } - return array(GalleryStatus::success(), - dirname(dirname(dirname(dirname(__FILE__)))) . '/.htaccess'); + return array(GalleryStatus::success(), GALLERY_CONFIG_DIR . '/.htaccess'); } /** @@ -224,31 +223,29 @@ global $gallery; $urlGenerator =& $gallery->getUrlGenerator(); - /* Get the correct Gallery directory. */ - $components = parse_url($urlGenerator->getCurrentUrlDir(true)); - $path = $components['path']; - if (preg_match('/\/(upgrade|install)\/index.php$/', $path)) { - $path = dirname(dirname($path)); - $path .= ($path != '/') ? '/' : ''; + $baseUrl = $gallery->getConfig('galleryBaseUrl'); + if (empty($baseUrl)) { + $baseUrl = preg_replace('{(install|upgrade)/index\.php.*}', '', + $urlGenerator->getCurrentUrlDir(true)); } + $baseUrl .= 'modules/rewrite/test/'; + $components = parse_url($baseUrl); + $path = $components['path']; /* * Testing mod_rewrite functionality. In order for mod_rewrite to work * properly, it needs a .htaccess file containing a RewriteBase * directive that matches the URL of its containing directory. */ - if ($path == '/gallery2/') { + if (!strncmp($path, '/gallery2/', 10)) { $target = 'gallery2'; - } else if ($path == '/gallery/') { + } else if (!strncmp($path, '/gallery/', 9)) { $target = 'gallery'; } else { $target = 'custom'; } - $fetch = $urlGenerator->generateUrl( - array('href' => $urlGenerator->makeUrl($path) . - 'modules/rewrite/test/mod_rewrite_no_options/' . $target . - '/Rewrite.txt')); + $fetch = $baseUrl . "mod_rewrite_no_options/$target/Rewrite.txt"; list ($body, $headers, $url) = GalleryCoreAPI::fetchWebPage($fetch); if ($headers == 'HTTP/1.1 200 OK' && $body == "PASS_REWRITE\n") { @@ -264,9 +261,7 @@ * Apache mod_rewrite needs Options +FollowSymlinks, and we might need to explicit * require it in the .htaccess file. */ - $fetch = $urlGenerator->generateUrl( - array('href' => $urlGenerator->makeUrl($path) . - 'modules/rewrite/test/mod_rewrite/' . $target . '/Rewrite.txt')); + $fetch = $baseUrl . "mod_rewrite/$target/Rewrite.txt"; list ($body, $headers, $url) = GalleryCoreAPI::fetchWebPage($fetch); if ($headers == 'HTTP/1.1 200 OK' && $body == "PASS_REWRITE\n") { Index: RewriteCheckConflictTask.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/rewrite/classes/RewriteCheckConflictTask.class,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- RewriteCheckConflictTask.class 8 May 2005 15:13:49 -0000 1.2 +++ RewriteCheckConflictTask.class 26 May 2005 17:45:48 -0000 1.3 @@ -95,7 +95,7 @@ $path = substr($path, 0, $query); } - if ($platform->file_exists($baseDir . $path) && $path != '/main.php') { + if ($platform->file_exists($baseDir . $path) && $path != ('/' . GALLERY_MAIN_PHP)) { list ($ret, $item) = GalleryCoreApi::loadEntitiesById($result[0]); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null, null); @@ -104,7 +104,7 @@ 'subView' => 'core:ItemEdit', 'editPlugin' => 'ItemEditItem', 'itemId' => $result[0]); - + $status[++$badPath] = $module->translate('Bad path:') . sprintf(' <a href="%s">%s</a>: %s', $urlGenerator->generateUrl($params), @@ -121,7 +121,7 @@ } } } - + $status[0] = $module->translate(array('text' => 'Checked %d items and found %d conflicts', 'arg1' => $total, 'arg2' => $badPath)); return array(GalleryStatus::success(), true, $status); |