diff options
Diffstat (limited to 'modules/g2_import/helpers')
-rw-r--r-- | modules/g2_import/helpers/g2_import.php | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 00e3d31a..2eee564a 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -38,24 +38,22 @@ class g2_import_Core { } $embed_path = module::get_var("g2_import", "embed_path"); - $multi_path = module::get_var("g2_import", "multi_path"); - if (empty($embed_path)) { throw new Exception("@todo G2_IMPORT_NOT_CONFIGURED"); } - g2_import::$init = g2_import::init_embed($embed_path, $multi_path); + g2_import::$init = g2_import::init_embed($embed_path); } - static function is_valid_embed_path($embed_path, $multi_path) { - return file_exists($embed_path) && (empty($multi_path) || file_exists($multi_path)) && g2_import::init_embed($embed_path, $multi_path); + static function is_valid_embed_path($embed_path) { + return file_exists($embed_path) && g2_import::init_embed($embed_path); } /** * Initialize the embedded Gallery2 instance. Call this before any other Gallery2 calls. */ - static function init_embed($embed_path, $multi_path) { - if (!is_file($embed_path) && (empty($multi_path) || is_dir($multi_path))) { + static function init_embed($embed_path) { + if (!is_file($embed_path)) { return false; } @@ -72,11 +70,17 @@ class g2_import_Core { @dir::unlink($mod_path); mkdir($mod_path); - $base_dir = dirname($embed_path); - if (!empty($multi_path)) - $config_dir = dirname($multi_path); - else - $config_dir = $base_dir; + $config_dir = dirname($embed_path); + if (filesize($embed_path) > 200) { + // Regular install + $base_dir = $config_dir; + } else { + // Multisite install. Line 2 of embed.php will be something like: + // require('/usr/home/bharat/public_html/gallery2/embed.php'); + $lines = file($embed_path); + preg_match("#require\('(.*)/embed.php'\);#", $lines[2], $matches); + $base_dir = $matches[1]; + } file_put_contents( "$mod_path/embed.php", @@ -108,11 +112,13 @@ class g2_import_Core { array("require_once(dirname(__FILE__) . '/modules/core/classes/Gallery.class');", "require_once(dirname(__FILE__) . '/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', dirname(__FILE__));", - "\$gallery =& new Gallery();"), + "\$gallery =& new Gallery();", + "\$gallery = new Gallery();"), array("require_once(dirname(__FILE__) . '/Gallery.class');", "require_once('$base_dir/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', '$config_dir');", - "\$gallery =& new G2_Gallery();"), + "\$gallery =& new G2_Gallery();", + "\$gallery = new G2_Gallery();"), array_merge(array("<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n"), file("$base_dir/bootstrap.inc")))); @@ -576,7 +582,18 @@ class g2_import_Core { return; } - foreach (preg_split("/[,;]/", $keywords) as $keyword) { + // Keywords in G2 are free form. So we don't know what our user used as a separator. Try to + // be smart about it. If we see a comma or a semicolon, expect the keywords to be separated + // by that delimeter. Otherwise, use space as the delimiter. + if (strpos($keywords, ";")) { + $delim = ";"; + } else if (strpos($keywords, ",")) { + $delim = ","; + } else { + $delim = " "; + } + + foreach (preg_split("/$delim/", $keywords) as $keyword) { $keyword = trim($keyword); if ($keyword) { tag::add($item, $keyword); |