diff -r 0944c9354e9c -r 7c6e2e97aa08 plugins/gallery/imagetag.php
--- a/plugins/gallery/imagetag.php Sat Aug 21 23:25:41 2010 -0400
+++ b/plugins/gallery/imagetag.php Sat Aug 21 23:32:06 2010 -0400
@@ -17,8 +17,8 @@
function snapr_process_image_tags(&$text)
{
- $text = snapr_image_tags_stage1($text, $taglist);
- $text = snapr_image_tags_stage2($text, $taglist);
+ $text = snapr_image_tags_stage1($text, $taglist);
+ $text = snapr_image_tags_stage2($text, $taglist);
}
/*
@@ -34,208 +34,208 @@
function snapr_image_tags_stage1($text, &$taglist)
{
- global $db, $session, $paths, $template, $plugins; // Common objects
-
- static $idcache = array();
-
- $s_delim = "\xFF";
- $f_delim = "\xFF";
- $taglist = array();
-
- // Wicked huh?
- $regex = '/\[\[:' . str_replace('/', '\\/', preg_quote($paths->nslist['Gallery'])) . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|raw|\|(.+))?\]\]/i';
-
- preg_match_all($regex, $text, $matches);
-
- foreach ( $matches[0] as $i => $match )
- {
- $full_tag =& $matches[0][$i];
- $imagename =& $matches[1][$i];
- $scale_type =& $matches[2][$i];
- $width =& $matches[5][$i];
- $height =& $matches[6][$i];
- $clear =& $matches[7][$i];
- $caption =& $matches[8][$i];
-
- // determine the image name
- $imagename = sanitize_page_id($imagename);
- if ( isset($idcache[$imagename]) )
- {
- $found_image_id = true;
- $filename =& $idcache[$imagename];
- }
- else
- {
- $found_image_id = false;
- // get the image ID
- // Ech... he sent us a string... parse it and see what we get
- if ( strstr($imagename, '/') )
- {
- $folders = explode('/', $imagename);
- }
- else
- {
- $folders = array($imagename);
- }
- foreach ( $folders as $i => $_crap )
- {
- $folder =& $folders[$i];
- $folder = dirtify_page_id($folder);
- $folder = str_replace('_', ' ', $folder);
- }
- unset($folder);
-
- $folders = array_reverse($folders);
- // This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL
- $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.img_filename, g0.folder_parent, g0.img_tags FROM '.table_prefix.'gallery AS g0';
- $where = "\n " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\'';
- foreach ( $folders as $i => $folder )
- {
- if ( $i == 0 )
- continue;
- $i_dec = $i - 1;
- $folder = $db->escape($folder);
- $sql .= "\n LEFT JOIN ".table_prefix."gallery AS g{$i}\n ON ( g{$i}.img_id=g{$i_dec}.folder_parent AND g{$i}.img_title='$folder' )";
- $where .= "\n ".'AND g'.$i.'.img_id IS NOT NULL';
- }
- $where .= "\n AND g{$i}.folder_parent IS NULL";
- $sql .= $where . ';';
-
- if ( !$db->sql_query($sql) )
- {
- $db->_die('The image metadata could not be loaded.');
- }
-
- if ( $db->numrows() > 0 )
- {
- $found_image_id = true;
- $row = $db->fetchrow();
- $db->free_result();
- $idcache[$imagename] = $row['img_id'];
- $filename =& $idcache[$imagename];
- }
- }
-
- if ( !$found_image_id )
- {
- $text = str_replace($full_tag, '[[' . makeUrlNS('Gallery', $imagename) . ']]', $text);
- continue;
- }
-
- if ( $scale_type == '|thumb' )
- {
- $r_width = 225;
- $r_height = 225;
-
- $url = makeUrlNS('Special', 'GalleryFetcher/embed/' . $filename, 'width=' . $r_width . '&height=' . $r_height, true);
- }
- else if ( !empty($width) && !empty($height) )
- {
- $r_width = $width;
- $r_height = $height;
-
- $url = makeUrlNS('Special', 'GalleryFetcher/embed/' . $filename, 'width=' . $r_width . '&height=' . $r_height, true);
- }
- else
- {
- $url = makeUrlNS('Special', 'GalleryFetcher/' . $filename);
- }
-
- $img_tag = 'setHook('snapr_img_tag_parse_img');
- foreach ( $code as $cmd )
- {
- eval($cmd);
- }
-
- $img_tag .= '/>';
-
- $complete_tag = '';
-
- if ( !empty($scale_type) && $caption != '|raw' )
- {
- $complete_tag .= '
' || $pos == 0 || $check2 == "\n" )
- {
- // die('found at pos '.$pos);
- break;
- }
- $pos--;
- }
-
- $repl = "{$s_delim}e_img_{$i}{$f_delim}";
- $text = substr($text, 0, $pos) . $repl . substr($text, $pos);
-
- $text = str_replace($full_tag, '', $text);
-
- unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
-
- }
-
- return $text;
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ static $idcache = array();
+
+ $s_delim = "\xFF";
+ $f_delim = "\xFF";
+ $taglist = array();
+
+ // Wicked huh?
+ $regex = '/\[\[:' . str_replace('/', '\\/', preg_quote($paths->nslist['Gallery'])) . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|raw|\|(.+))?\]\]/i';
+
+ preg_match_all($regex, $text, $matches);
+
+ foreach ( $matches[0] as $i => $match )
+ {
+ $full_tag =& $matches[0][$i];
+ $imagename =& $matches[1][$i];
+ $scale_type =& $matches[2][$i];
+ $width =& $matches[5][$i];
+ $height =& $matches[6][$i];
+ $clear =& $matches[7][$i];
+ $caption =& $matches[8][$i];
+
+ // determine the image name
+ $imagename = sanitize_page_id($imagename);
+ if ( isset($idcache[$imagename]) )
+ {
+ $found_image_id = true;
+ $filename =& $idcache[$imagename];
+ }
+ else
+ {
+ $found_image_id = false;
+ // get the image ID
+ // Ech... he sent us a string... parse it and see what we get
+ if ( strstr($imagename, '/') )
+ {
+ $folders = explode('/', $imagename);
+ }
+ else
+ {
+ $folders = array($imagename);
+ }
+ foreach ( $folders as $i => $_crap )
+ {
+ $folder =& $folders[$i];
+ $folder = dirtify_page_id($folder);
+ $folder = str_replace('_', ' ', $folder);
+ }
+ unset($folder);
+
+ $folders = array_reverse($folders);
+ // This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL
+ $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.img_filename, g0.folder_parent, g0.img_tags FROM '.table_prefix.'gallery AS g0';
+ $where = "\n " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\'';
+ foreach ( $folders as $i => $folder )
+ {
+ if ( $i == 0 )
+ continue;
+ $i_dec = $i - 1;
+ $folder = $db->escape($folder);
+ $sql .= "\n LEFT JOIN ".table_prefix."gallery AS g{$i}\n ON ( g{$i}.img_id=g{$i_dec}.folder_parent AND g{$i}.img_title='$folder' )";
+ $where .= "\n ".'AND g'.$i.'.img_id IS NOT NULL';
+ }
+ $where .= "\n AND g{$i}.folder_parent IS NULL";
+ $sql .= $where . ';';
+
+ if ( !$db->sql_query($sql) )
+ {
+ $db->_die('The image metadata could not be loaded.');
+ }
+
+ if ( $db->numrows() > 0 )
+ {
+ $found_image_id = true;
+ $row = $db->fetchrow();
+ $db->free_result();
+ $idcache[$imagename] = $row['img_id'];
+ $filename =& $idcache[$imagename];
+ }
+ }
+
+ if ( !$found_image_id )
+ {
+ $text = str_replace($full_tag, '[[' . makeUrlNS('Gallery', $imagename) . ']]', $text);
+ continue;
+ }
+
+ if ( $scale_type == '|thumb' )
+ {
+ $r_width = 225;
+ $r_height = 225;
+
+ $url = makeUrlNS('Special', 'GalleryFetcher/embed/' . $filename, 'width=' . $r_width . '&height=' . $r_height, true);
+ }
+ else if ( !empty($width) && !empty($height) )
+ {
+ $r_width = $width;
+ $r_height = $height;
+
+ $url = makeUrlNS('Special', 'GalleryFetcher/embed/' . $filename, 'width=' . $r_width . '&height=' . $r_height, true);
+ }
+ else
+ {
+ $url = makeUrlNS('Special', 'GalleryFetcher/' . $filename);
+ }
+
+ $img_tag = 'setHook('snapr_img_tag_parse_img');
+ foreach ( $code as $cmd )
+ {
+ eval($cmd);
+ }
+
+ $img_tag .= '/>';
+
+ $complete_tag = '';
+
+ if ( !empty($scale_type) && $caption != '|raw' )
+ {
+ $complete_tag .= '
' || $pos == 0 || $check2 == "\n" ) + { + // die('found at pos '.$pos); + break; + } + $pos--; + } + + $repl = "{$s_delim}e_img_{$i}{$f_delim}"; + $text = substr($text, 0, $pos) . $repl . substr($text, $pos); + + $text = str_replace($full_tag, '', $text); + + unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); + + } + + return $text; } /** @@ -246,14 +246,14 @@ function snapr_image_tags_stage2($text, $taglist) { - $s_delim = "\xFF"; - $f_delim = "\xFF"; - foreach ( $taglist as $i => $tag ) - { - $repl = "{$s_delim}e_img_{$i}{$f_delim}"; - $text = str_replace($repl, $tag, $text); - } - return $text; + $s_delim = "\xFF"; + $f_delim = "\xFF"; + foreach ( $taglist as $i => $tag ) + { + $repl = "{$s_delim}e_img_{$i}{$f_delim}"; + $text = str_replace($repl, $tag, $text); + } + return $text; } ?>