# HG changeset patch
# User Dan Fuhry
This version of Snapr requires Enano 1.1.6 or later.
'); } $magick_path = getConfig('imagemagick_path', '/usr/bin/convert'); $have_gd_scale_support = function_exists('imagecreatetruecolor') && function_exists('imagejpeg') && function_exists('imagecopyresampled'); if ( (!file_exists($magick_path) || !is_executable($magick_path)) && !$have_gd_scale_support ) { - $fn = basename(__FILE__); - // set disabled flag with new plugin system - if ( defined('ENANO_ATLEAST_1_1') && defined('PLUGIN_DISABLED') ) - { - $q = $db->sql_query('UPDATE ' . table_prefix . "plugins SET plugin_flags = plugin_flags | " . PLUGIN_DISABLED . " WHERE plugin_filename = 'Gallery.php';"); - if ( !$q ) - $db->_die(); + $fn = basename(__FILE__); + // set disabled flag with new plugin system + if ( defined('ENANO_ATLEAST_1_1') && defined('PLUGIN_DISABLED') ) + { + $q = $db->sql_query('UPDATE ' . table_prefix . "plugins SET plugin_flags = plugin_flags | " . PLUGIN_DISABLED . " WHERE plugin_filename = 'Gallery.php';"); + if ( !$q ) + $db->_die(); - // kill off cache - global $cache; - $cache->purge('plugins'); - } - else - { - // old plugin system - setConfig("plugin_$fn", '0'); - } - - die_semicritical('Snapr can\'t load on this site', 'You must have ImageMagick or GD installed and working to use this plugin. The plugin has been disabled, please setup ImageMagick and then re-enable it.
'); + // kill off cache + global $cache; + $cache->purge('plugins'); + } + else + { + // old plugin system + setConfig("plugin_$fn", '0'); + } + + die_semicritical('Snapr can\'t load on this site', 'You must have ImageMagick or GD installed and working to use this plugin. The plugin has been disabled, please setup ImageMagick and then re-enable it.
'); } +$plugins->attachHook('pgsql_set_serial_list', '$primary_keys[table_prefix."gallery"] = "img_id";'); + /**!install dbms="mysql"; ** CREATE TABLE {{TABLE_PREFIX}}gallery( @@ -59,6 +61,7 @@ img_filename varchar(255) NOT NULL, img_time_upload int(12) NOT NULL DEFAULT 0, img_time_mod int(12) NOT NULL DEFAULT 0, + img_author int(12) NOT NULL DEFAULT 1, img_tags longtext, PRIMARY KEY ( img_id ) ); @@ -91,6 +94,14 @@ /**!upgrade dbms="mysql"; from="0.1 beta 3"; to="0.1b3"; ** **!*/ +/**!upgrade dbms="mysql"; from="0.1b3"; to="0.1b4"; ** +ALTER TABLE {{TABLE_PREFIX}}gallery ADD COLUMN img_author int(12) NOT NULL DEFAULT 1; +ALTER TABLE {{TABLE_PREFIX}}gallery ADD COLUMN processed tinyint(1) NOT NULL DEFAULT 1; +-- Set all images to authorship by the first administrator we can find +UPDATE {{TABLE_PREFIX}}gallery SET img_author = ( SELECT user_id FROM {{TABLE_PREFIX}}users WHERE user_level = 9 ORDER BY user_id DESC LIMIT 1 ), processed = 1; + +**!*/ + require( ENANO_ROOT . '/plugins/gallery/functions.php' ); require( ENANO_ROOT . '/plugins/gallery/nssetup.php' ); require( ENANO_ROOT . '/plugins/gallery/viewimage.php' ); diff -r 0944c9354e9c -r 7c6e2e97aa08 plugins/gallery/browser.php --- a/plugins/gallery/browser.php Sat Aug 21 23:25:41 2010 -0400 +++ b/plugins/gallery/browser.php Sat Aug 21 23:32:06 2010 -0400 @@ -27,446 +27,447 @@ class SnaprFormatter { - - /** - * Main render method, called from pagination function - * @access private - */ - - function render($column_crap, $row, $row_crap = false) - { - global $db, $session, $paths, $template, $plugins; // Common objects - - $out = '' . print_r(gallery_folder_hierarchy(), true) . ''); - - $sort_column = ( isset($_GET['sort']) && in_array($_GET['sort'], array('img_title', 'img_time_upload', 'img_time_mod')) ) ? $_GET['sort'] : 'img_title'; - $sort_order = ( isset($_GET['order']) && in_array($_GET['order'], array('ASC', 'DESC')) ) ? $_GET['order'] : 'ASC'; - - // Determine number of pictures per page - $template->load_theme(); - - $where = 'WHERE folder_parent IS NULL ' . "\n ORDER BY is_folder DESC, $sort_column $sort_order, img_title ASC"; - $parms = $paths->getAllParams(); - - $sql = "SELECT img_id, img_title, is_folder, 'NULL' AS folder_id FROM ".table_prefix."gallery $where;"; - - // Breadcrumb browser - $breadcrumbs = array(); - $breadcrumbs[] = 'Gallery index'; - - $breadcrumb_urlcache = ''; - - // CSS for gallery browser - // Moved to search.php - //$template->add_header(''); - //$template->add_header(''); - - $header = $template->getHeader(); - - if ( !empty($parms) ) - { - $parms = dirtify_page_id($parms); - if ( strstr($parms, '/') ) - { - $folders = explode('/', $parms); - } - else - { - $folders = array(0 => $parms); - } - foreach ( $folders as $i => $_crap ) - { - $folder =& $folders[$i]; - - $f_url = sanitize_page_id($folder); - $breadcrumb_urlcache .= '/' . $f_url; - $breadcrumb_url = makeUrlNS('Special', 'Gallery' . $breadcrumb_urlcache); - - $folder = str_replace('_', ' ', $folder); - - if ( $i == ( count($folders) - 1 ) ) - { - $breadcrumbs[] = htmlspecialchars($folder); - } - else - { - $breadcrumbs[] = '' . htmlspecialchars($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 gm.img_id, gm.img_title, gm.is_folder, g0.img_title AS folder_name, g0.img_id AS folder_id FROM '.table_prefix.'gallery AS gm' . "\n " . 'LEFT JOIN '.table_prefix.'gallery AS g0' . "\n " . 'ON ( gm.folder_parent = g0.img_id )'; - $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 . "\n ORDER BY is_folder DESC, gm.$sort_column $sort_order, gm.img_title ASC" . ';'; - } - - $img_query = $db->sql_query($sql); - if ( !$img_query ) - $db->_die('The folder ID could not be selected.'); - - if ( $db->numrows() < 1 ) - { - // Nothing in this folder, for one of two reasons: - // 1) The folder doesn't exist - // 2) The folder exists but doesn't have any images in it - - if ( sizeof($folders) < 1 ) - { - // Nothing in the root folder - - $first_row['folder_id'] = 'NULL'; - if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) && isset($first_row['folder_id']) ) - { - if ( empty($_POST['create_folder']) ) - { - $f_errors[] = 'Please enter a folder name.'; - } - if ( $_POST['create_folder'] == '_id' ) - { - $f_errors[] = 'The name "_id" is reserved for internal functions and cannot be used on any image or folder.'; - } - if ( count($f_errors) < 1 ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'gallery(img_title, is_folder, folder_parent) VALUES(\'' . $db->escape($_POST['create_folder']) . '\', 1, ' . $first_row['folder_id'] . ');'); - if ( !$q ) - $db->_die(); - redirect(makeUrl($paths->fullpage), 'Folder created', 'The folder "' . htmlspecialchars($_POST['create_folder']) . '" has been created. Redirecting to last viewed folder...', 2); - } - } - - $html = ''; - if ( $session->user_level >= USER_LEVEL_ADMIN ) - { - $html .= ''; - $html .= '
No images have been uploaded to the gallery yet.
' . $html); - } - - /* - $folders_old = $folders; - $folders = array( - 0 => $folders_old[0] - ); - $x = $folders_old; - unset($x[0]); - $folders = array_merge($folders, $x); - unset($x); - */ - // die('' . print_r($folders, true) . ''); - - // This next query will try to determine if the folder itself exists - $sql = 'SELECT g0.img_id, g0.img_title 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"; - $where .= "\n AND g0.is_folder=1"; - $sql .= $where . ';'; - - $nameq = $db->sql_query($sql); - if ( !$nameq ) - $db->_die(); - - if ( $db->numrows($nameq) < 1 ) - { - die_friendly('Folder not found', '
The folder you requested doesn\'t exist. Please check the URL and try again, or return to the gallery index.
'); - } - - $row = $db->fetchrow($nameq); - - // Generate title - $title = dirtify_page_id($row['img_title']); - $title = str_replace('_', ' ', $title); - $title = htmlspecialchars($title); - - $template->tpl_strings['PAGE_NAME'] = $title; - - $first_row = $row; - - if ( $db->numrows($img_query) > 0 ) - $db->sql_data_seek(0, $img_query); - - /* $folders = $folders_old; */ - } - else if ( !empty($parms) ) - { - $row = $db->fetchrow($img_query); - $first_row = $row; - - // Generate title - $title = htmlspecialchars($row['folder_name']); - - $template->tpl_strings['PAGE_NAME'] = $title; - - $db->sql_data_seek(0, $img_query); - } - else - { - $row = $db->fetchrow($img_query); - $first_row = $row; - - $template->tpl_strings['PAGE_NAME'] = 'Image Gallery'; - $breadcrumbs = array('Gallery index'); - - $db->sql_data_seek(0, $img_query); - } - - $f_errors = array(); - - if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) ) - { - if ( !isset($first_row['folder_id']) ) - { - //die('FALLING' . print_r($first_row, true) . ''); - $first_row['folder_id'] =& $first_row['img_id']; - } - if ( !isset($first_row['folder_id']) ) - { - $f_errors[] = 'Internal error getting parent folder ID'; - } - if ( empty($_POST['create_folder']) ) - { - $f_errors[] = 'Please enter a folder name.'; - } - if ( $_POST['create_folder'] == '_id' ) - { - $f_errors[] = 'The name "_id" is reserved for internal functions and cannot be used on any image or folder.'; - } - if ( count($f_errors) < 1 ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'gallery(img_title, is_folder, folder_parent) VALUES(\'' . $db->escape($_POST['create_folder']) . '\', 1, ' . $first_row['folder_id'] . ');'); - if ( !$q ) - $db->_die(); - redirect(makeUrl($paths->fullpage), 'Folder created', 'The folder "' . htmlspecialchars($_POST['create_folder']) . '" has been created. Redirecting to last viewed folder...', 2); - } - } - - echo $header; - - if ( count($f_errors) > 0 ) - { - echo '
' . var_dump($row) . $db->sql_backtrace() . ''); - if ( !$row['img_id'] ) - break; - $all_list[] = $row['img_id']; - if ( $row['is_folder'] == 1 ) - $fol_list[] = $row['img_id']; - else - $img_list[] = $row['img_id']; - } - while ( $row = $db->fetchrow($img_query) ); - - $all_list = implode(',', $all_list); - $fol_list = implode(',', $fol_list); - $img_list = implode(',', $img_list); - - if ( !empty($all_list) ) - { - echo '
' . print_r(gallery_folder_hierarchy(), true) . ''); + + $sort_column = ( isset($_GET['sort']) && in_array($_GET['sort'], array('img_title', 'img_time_upload', 'img_time_mod')) ) ? $_GET['sort'] : 'img_title'; + $sort_order = ( isset($_GET['order']) && in_array($_GET['order'], array('ASC', 'DESC')) ) ? $_GET['order'] : 'ASC'; + + // Determine number of pictures per page + $template->load_theme(); + + $where = 'WHERE folder_parent IS NULL ' . "\n ORDER BY is_folder DESC, $sort_column $sort_order, img_title ASC"; + $parms = $paths->getAllParams(); + + $sql = "SELECT img_id, img_title, is_folder, 'NULL' AS folder_id FROM ".table_prefix."gallery $where;"; + + // Breadcrumb browser + $breadcrumbs = array(); + $breadcrumbs[] = 'Gallery index'; + + $breadcrumb_urlcache = ''; + + // CSS for gallery browser + // Moved to search.php + //$template->add_header(''); + //$template->add_header(''); + + $header = $template->getHeader(); + + $folders = $f_errors = array(); + if ( !empty($parms) ) + { + $parms = dirtify_page_id($parms); + if ( strstr($parms, '/') ) + { + $folders = explode('/', $parms); + } + else + { + $folders = array(0 => $parms); + } + foreach ( $folders as $i => $_crap ) + { + $folder =& $folders[$i]; + + $f_url = sanitize_page_id($folder); + $breadcrumb_urlcache .= '/' . $f_url; + $breadcrumb_url = makeUrlNS('Special', 'Gallery' . $breadcrumb_urlcache); + + $folder = str_replace('_', ' ', $folder); + + if ( $i == ( count($folders) - 1 ) ) + { + $breadcrumbs[] = htmlspecialchars($folder); + } + else + { + $breadcrumbs[] = '' . htmlspecialchars($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 gm.img_id, gm.img_title, gm.is_folder, g0.img_title AS folder_name, g0.img_id AS folder_id FROM '.table_prefix.'gallery AS gm' . "\n " . 'LEFT JOIN '.table_prefix.'gallery AS g0' . "\n " . 'ON ( gm.folder_parent = g0.img_id )'; + $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 . "\n ORDER BY is_folder DESC, gm.$sort_column $sort_order, gm.img_title ASC" . ';'; + } + + $img_query = $db->sql_query($sql); + if ( !$img_query ) + $db->_die('The folder ID could not be selected.'); + + if ( $db->numrows() < 1 ) + { + // Nothing in this folder, for one of two reasons: + // 1) The folder doesn't exist + // 2) The folder exists but doesn't have any images in it + + if ( count($folders) < 1 ) + { + // Nothing in the root folder + + $first_row['folder_id'] = 'NULL'; + if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) && isset($first_row['folder_id']) ) + { + if ( empty($_POST['create_folder']) ) + { + $f_errors[] = 'Please enter a folder name.'; + } + if ( $_POST['create_folder'] == '_id' ) + { + $f_errors[] = 'The name "_id" is reserved for internal functions and cannot be used on any image or folder.'; + } + if ( count($f_errors) < 1 ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'gallery(img_title, is_folder, folder_parent, img_author) VALUES(\'' . $db->escape($_POST['create_folder']) . '\', 1, ' . $first_row['folder_id'] . ', ' . $session->user_id . ');'); + if ( !$q ) + $db->_die(); + redirect(makeUrl($paths->fullpage), 'Folder created', 'The folder "' . htmlspecialchars($_POST['create_folder']) . '" has been created. Redirecting to last viewed folder...', 2); + } + } + + $html = ''; + if ( $session->user_level >= USER_LEVEL_ADMIN ) + { + $html .= ''; + $html .= '
No images have been uploaded to the gallery yet.
' . $html); + } + + /* + $folders_old = $folders; + $folders = array( + 0 => $folders_old[0] + ); + $x = $folders_old; + unset($x[0]); + $folders = array_merge($folders, $x); + unset($x); + */ + // die('' . print_r($folders, true) . ''); + + // This next query will try to determine if the folder itself exists + $sql = 'SELECT g0.img_id, g0.img_title 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"; + $where .= "\n AND g0.is_folder=1"; + $sql .= $where . ';'; + + $nameq = $db->sql_query($sql); + if ( !$nameq ) + $db->_die(); + + if ( $db->numrows($nameq) < 1 ) + { + die_friendly('Folder not found', '
The folder you requested doesn\'t exist. Please check the URL and try again, or return to the gallery index.
'); + } + + $row = $db->fetchrow($nameq); + + // Generate title + $title = dirtify_page_id($row['img_title']); + $title = str_replace('_', ' ', $title); + $title = htmlspecialchars($title); + + $template->tpl_strings['PAGE_NAME'] = $title; + + $first_row = $row; + + if ( $db->numrows($img_query) > 0 ) + $db->sql_data_seek(0, $img_query); + + /* $folders = $folders_old; */ + } + else if ( !empty($parms) ) + { + $row = $db->fetchrow($img_query); + $first_row = $row; + + // Generate title + $title = htmlspecialchars($row['folder_name']); + + $template->tpl_strings['PAGE_NAME'] = $title; + + $db->sql_data_seek(0, $img_query); + } + else + { + $row = $db->fetchrow($img_query); + $first_row = $row; + + $template->tpl_strings['PAGE_NAME'] = 'Image Gallery'; + $breadcrumbs = array('Gallery index'); + + $db->sql_data_seek(0, $img_query); + } + + $f_errors = array(); + + if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) ) + { + if ( !isset($first_row['folder_id']) ) + { + //die('FALLING' . print_r($first_row, true) . ''); + $first_row['folder_id'] =& $first_row['img_id']; + } + if ( !isset($first_row['folder_id']) ) + { + $f_errors[] = 'Internal error getting parent folder ID'; + } + if ( empty($_POST['create_folder']) ) + { + $f_errors[] = 'Please enter a folder name.'; + } + if ( $_POST['create_folder'] == '_id' ) + { + $f_errors[] = 'The name "_id" is reserved for internal functions and cannot be used on any image or folder.'; + } + if ( count($f_errors) < 1 ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'gallery(img_title, is_folder, folder_parent, img_author) VALUES(\'' . $db->escape($_POST['create_folder']) . '\', 1, ' . $first_row['folder_id'] . ', ' . $session->user_id . ');'); + if ( !$q ) + $db->_die(); + redirect(makeUrl($paths->fullpage), 'Folder created', 'The folder "' . htmlspecialchars($_POST['create_folder']) . '" has been created. Redirecting to last viewed folder...', 2); + } + } + + echo $header; + + if ( count($f_errors) > 0 ) + { + echo '
' . var_dump($row) . $db->sql_backtrace() . ''); + if ( !$row['img_id'] ) + break; + $all_list[] = $row['img_id']; + if ( $row['is_folder'] == 1 ) + $fol_list[] = $row['img_id']; + else + $img_list[] = $row['img_id']; + } + while ( $row = $db->fetchrow($img_query) ); + + $all_list = implode(',', $all_list); + $fol_list = implode(',', $fol_list); + $img_list = implode(',', $img_list); + + if ( !empty($all_list) ) + { + echo '
'.print_r($hier,true).print_r($lookup_table,true).print_r($persist_orphans,true).''); - } - while ( count($persist_orphans) > 0 ); - - return $hier; - + global $db, $session, $paths, $template, $plugins; // Common objects + + $q = $db->sql_query('SELECT img_id, img_title, folder_parent FROM '.table_prefix.'gallery WHERE is_folder=1'); + if ( !$q ) + $db->_die(); + + if ( $db->numrows() < 1 ) + { + return array('_id' => 'NULL'); + } + + $lookup_table = array(); + $hier = array('_id' => 'NULL'); + $orphans = array(); + $persist_orphans = array(); + + while ( $row = $db->fetchrow() ) + { + if ( !$row['folder_parent'] ) + { + // root-level folder + $hier[ $row['img_title'] ] = array('_id' => $row['img_id']); + $lookup_table[$row['img_id']] =& $hier[ $row['img_title'] ]; + } + else if ( $row['folder_parent'] && isset($lookup_table[$row['folder_parent']]) ) + { + // child folder, parent is resolved + $lookup_table[ $row['folder_parent'] ][ $row['img_title'] ] = array('_id' => $row['img_id']); + $lookup_table[ $row['img_id'] ] =& $lookup_table[ $row['folder_parent'] ][ $row['img_title'] ]; + } + else if ( $row['folder_parent'] && !isset($lookup_table[$row['folder_parent']]) ) + { + // child folder, orphan as of yet + $orphans[] = $row; + } + } + + // Resolve orphans + do + { + $persist_orphans = array(); + while ( count($orphans) > 0 ) + { + $orphan =& $orphans[ ( count($orphans) - 1 ) ]; + if ( isset($lookup_table[$orphan['folder_parent']]) ) + { + $lookup_table[ $orphan['folder_parent'] ][ $orphan['img_title'] ] = array('_id' => $orphan['img_id']); + $lookup_table[ $orphan['img_id'] ] =& $lookup_table[ $orphan['folder_parent'] ][ $orphan['img_title'] ]; + } + else + { + $persist_orphans[] = $orphans[ ( count($orphans) - 1 ) ]; + //echo 'BUG: ' . htmlspecialchars($orphan['img_title']) . ' (' . $orphan['img_id'] . ') is an orphan folder (parent is ' . $orphan['folder_parent'] . '); placing in root
'.print_r($hier,true).print_r($lookup_table,true).print_r($persist_orphans,true).''); + } + while ( count($persist_orphans) > 0 ); + + return $hier; + } /** @@ -170,15 +170,15 @@ function gallery_hier_formfield($field_name = 'folder_id', $autosel = true) { - $hier = gallery_folder_hierarchy(); - $img_join = scriptPath . '/images/icons/joinbottom.gif'; - $img_join_term = scriptPath . '/images/icons/join.gif'; - $img_line = scriptPath . '/images/icons/line.gif'; - $img_empty = scriptPath . '/images/icons/empty.gif'; - - $html = _gallery_hier_form_inner($hier, '
' || $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; } ?> diff -r 0944c9354e9c -r 7c6e2e97aa08 plugins/gallery/nssetup.php --- a/plugins/gallery/nssetup.php Sat Aug 21 23:25:41 2010 -0400 +++ b/plugins/gallery/nssetup.php Sat Aug 21 23:32:06 2010 -0400 @@ -16,17 +16,17 @@ function gallery_setup_namespace(&$paths) { - global $db, $session, $paths, $template, $plugins; // Common objects - - $paths->create_namespace('Gallery', 'Image:'); - - $session->register_acl_type('gal_full_res', AUTH_ALLOW, 'View image at full resolution', array('read'), 'Gallery'); - $session->register_acl_type('snapr_add_tag', AUTH_DISALLOW, 'Add image tags (separate from adding normal tags)', array('read'), 'Gallery'); - - $session->acl_extend_scope('read', 'Gallery', $paths); - $session->acl_extend_scope('post_comments', 'Gallery', $paths); - $session->acl_extend_scope('edit_comments', 'Gallery', $paths); - $session->acl_extend_scope('mod_comments', 'Gallery', $paths); + global $db, $session, $paths, $template, $plugins; // Common objects + + $paths->create_namespace('Gallery', 'Image:'); + + $session->register_acl_type('gal_full_res', AUTH_ALLOW, 'View image at full resolution', array('read'), 'Gallery'); + $session->register_acl_type('snapr_add_tag', AUTH_DISALLOW, 'Add image tags (separate from adding normal tags)', array('read'), 'Gallery'); + + $session->acl_extend_scope('read', 'Gallery', $paths); + $session->acl_extend_scope('post_comments', 'Gallery', $paths); + $session->acl_extend_scope('edit_comments', 'Gallery', $paths); + $session->acl_extend_scope('mod_comments', 'Gallery', $paths); } ?> diff -r 0944c9354e9c -r 7c6e2e97aa08 plugins/gallery/search.php --- a/plugins/gallery/search.php Sat Aug 21 23:25:41 2010 -0400 +++ b/plugins/gallery/search.php Sat Aug 21 23:32:06 2010 -0400 @@ -20,167 +20,167 @@ $plugins->attachHook('search_global_inner', 'snapr_search_new_api($query, $query_phrase, $scores, $page_data, $case_sensitive, $word_list);'); $plugins->attachHook('compile_template', ' - // CSS for gallery browser - $template->add_header(\'\'); - $template->add_header(\'\'); - '); + // CSS for gallery browser + $template->add_header(\'\'); + $template->add_header(\'\'); + '); function gal_searcher($q, $offset) { - global $db, $session, $paths, $template, $plugins; // Common objects - if ( defined('SNAPR_SEARCH_USING_NEW_API') || version_compare(enano_version(true), '1.0.2', '>=') ) - return false; - - $fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)'; - $sql = "SELECT img_id, img_title, img_desc, is_folder, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery - WHERE $fulltext_col > 0 - AND ( ( is_folder=1 AND folder_parent IS NULL ) OR is_folder!=1 ) - ORDER BY is_folder DESC, score DESC, img_title ASC;"; - if ( !$db->sql_unbuffered_query($sql) ) - { - echo $db->get_error(); - return false; - } - echo "
No image results.
'; - } + global $db, $session, $paths, $template, $plugins; // Common objects + if ( defined('SNAPR_SEARCH_USING_NEW_API') || version_compare(enano_version(true), '1.0.2', '>=') ) + return false; + + $fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)'; + $sql = "SELECT img_id, img_title, img_desc, is_folder, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery + WHERE $fulltext_col > 0 + AND ( ( is_folder=1 AND folder_parent IS NULL ) OR is_folder!=1 ) + ORDER BY is_folder DESC, score DESC, img_title ASC;"; + if ( !$db->sql_unbuffered_query($sql) ) + { + echo $db->get_error(); + return false; + } + echo "No image results.
'; + } } function snapr_search_new_api(&$query, &$query_phrase, &$scores, &$page_data, &$case_sensitive, &$word_list) { - global $db, $session, $paths, $template, $plugins; // Common objects - - if ( !defined('SNAPR_SEARCH_USING_NEW_API') ) - define('SNAPR_SEARCH_USING_NEW_API', 1); - - // Let's do this all in one query - $terms = array( - 'any' => array_merge($query['any'], $query_phrase['any']), - 'req' => array_merge($query['req'], $query_phrase['req']), - 'not' => $query['not'] - ); - $where = array('any' => array(), 'req' => array(), 'not' => array()); - $where_any =& $where['any']; - $where_req =& $where['req']; - $where_not =& $where['not']; - $title_col = ( $case_sensitive ) ? 'img_title' : 'lcase(img_title)'; - $desc_col = ( $case_sensitive ) ? 'img_desc' : 'lcase(img_desc)'; - foreach ( $terms['any'] as $term ) - { - $term = escape_string_like($term); - if ( !$case_sensitive ) - $term = strtolower($term); - $where_any[] = "( $title_col LIKE '%{$term}%' OR $desc_col LIKE '%{$term}%' )"; - } - foreach ( $terms['req'] as $term ) - { - $term = escape_string_like($term); - if ( !$case_sensitive ) - $term = strtolower($term); - $where_req[] = "( $title_col LIKE '%{$term}%' OR $desc_col LIKE '%{$term}%' )"; - } - foreach ( $terms['not'] as $term ) - { - $term = escape_string_like($term); - if ( !$case_sensitive ) - $term = strtolower($term); - $where_not[] = "$title_col NOT LIKE '%{$term}%' AND $desc_col NOT LIKE '%{$term}%'"; - } - if ( empty($where_any) ) - unset($where_any, $where['any']); - if ( empty($where_req) ) - unset($where_req, $where['req']); - if ( empty($where_not) ) - unset($where_not, $where['not']); - - $where_any = '(' . implode(' OR ', $where_any) . '' . ( isset($where['req']) || isset($where['not']) ? ' OR 1 = 1' : '' ) . ')'; - - if ( isset($where_req) ) - $where_req = implode(' AND ', $where_req); - if ( isset($where_not) ) - $where_not = implode( 'AND ', $where_not); - - $where = implode(' AND ', $where); - $sql = "SELECT img_id, img_title, img_desc FROM " . table_prefix . "gallery WHERE ( $where ) AND is_folder = 0;"; - - if ( !($q = $db->sql_unbuffered_query($sql)) ) - { - $db->_die('Error is in auto-generated SQL query in the Snapr plugin search module'); - } - - if ( $row = $db->fetchrow() ) - { - do - { - $idstring = 'ns=Gallery;pid=' . $row['img_id']; - foreach ( $word_list as $term ) - { - if ( $case_sensitive ) - { - if ( strstr($row['img_title'], $term) || strstr($row['img_desc'], $term) ) - { - ( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1; - } - } - else - { - if ( strstr(strtolower($row['img_title']), strtolower($term)) || strstr(strtolower($row['img_desc']), strtolower($term)) ) - { - ( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1; - } - } - } - // Generate text... - $text = highlight_and_clip_search_result(htmlspecialchars($row['img_desc']), $word_list); - - $preview_and_text = ' -- ' . $text . ' - | -- - | -
+ ' . $text . ' + | ++ + | +
' + response + ''); - return false; - } - response = parseJSON(response); - if ( response.mode ) - { - if ( response.mode == 'error' ) - { - alert(response.error); - return false; - } - } - var parent_obj = document.getElementById('snapr_preview_img').parentNode; - for ( var i = 0; i < response.length; i++ ) - { - var packet = response[i]; - switch(packet.mode) - { - case 'add': - snapr_draw_note(parent_obj, packet.tag, packet.canvas_data, packet.note_id, packet.initial_hide, packet.auth_delete); - break; - case 'remove': - // Server requested to remove a tag - var divs = parent_obj.getElementsByTagName('div'); - for ( var i = 0; i < divs.length; i++ ) - { - var box = divs[i]; - if ( box.className == 'canvasbox' ) - { - if ( box.tag_id == packet.note_id ) - { - // You. We have orders to shoot. Stand in front of wall. - var sibling = box.nextSibling; - var parent = box.parentNode; - // BLAM. - parent.removeChild(sibling); - parent.removeChild(box); - break; - } - } - } - break; - } - } - } + if ( ajax.readyState == 4 && ajax.status == 200 ) + { + var response = String(ajax.responseText + ''); + if ( response.substr(0, 1) != '[' && response.substr(0, 1) != '{' ) + { + new messagebox(MB_OK|MB_ICONSTOP, 'JSON response invalid', 'Received unexpected response:
' + response + ''); + return false; + } + response = parseJSON(response); + if ( response.mode ) + { + if ( response.mode == 'error' ) + { + alert(response.error); + return false; + } + } + var parent_obj = document.getElementById('snapr_preview_img').parentNode; + for ( var i = 0; i < response.length; i++ ) + { + var packet = response[i]; + switch(packet.mode) + { + case 'add': + snapr_draw_note(parent_obj, packet.tag, packet.canvas_data, packet.note_id, packet.initial_hide, packet.auth_delete); + break; + case 'remove': + // Server requested to remove a tag + var divs = parent_obj.getElementsByTagName('div'); + for ( var i = 0; i < divs.length; i++ ) + { + var box = divs[i]; + if ( box.className == 'canvasbox' ) + { + if ( box.tag_id == packet.note_id ) + { + // You. We have orders to shoot. Stand in front of wall. + var sibling = box.nextSibling; + var parent = box.parentNode; + // BLAM. + parent.removeChild(sibling); + parent.removeChild(box); + break; + } + } + } + break; + } + } + } } // Don't fire the tag init until JS init *and* image are finished. @@ -372,22 +372,22 @@ var snapr_tags_onload_real = function() { - // make sure we aren't waiting... - if ( snapr_lock_onload_img || snapr_lock_onload_js ) - return false; - - // add the new box - var parent_obj = document.getElementById('snapr_preview_img').parentNode; - var id = parent_obj.getAttribute('snapr:imgid'); - if ( !id ) - return false; - ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=get_tags', snapr_process_ajax_tag_packet); + // make sure we aren't waiting... + if ( snapr_lock_onload_img || snapr_lock_onload_js ) + return false; + + // add the new box + var parent_obj = document.getElementById('snapr_preview_img').parentNode; + var id = parent_obj.getAttribute('snapr:imgid'); + if ( !id ) + return false; + ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=get_tags', snapr_process_ajax_tag_packet); } var snapr_tags_onload = function() { - snapr_lock_onload_js = false; - snapr_tags_onload_real(); + snapr_lock_onload_js = false; + snapr_tags_onload_real(); } addOnloadHook(snapr_tags_onload); diff -r 0944c9354e9c -r 7c6e2e97aa08 plugins/gallery/upload.php --- a/plugins/gallery/upload.php Sat Aug 21 23:25:41 2010 -0400 +++ b/plugins/gallery/upload.php Sat Aug 21 23:32:06 2010 -0400 @@ -20,1071 +20,840 @@ function page_Special_GalleryUpload() { - global $db, $session, $paths, $template, $plugins; // Common objects - - if ( $session->user_level < USER_LEVEL_ADMIN ) - { - die_friendly('Access denied', '
You need to have administrative rights to use the gallery\'s upload features.
'); - } - - $zip_support = ( class_exists('ZipArchive') || ( file_exists('/usr/bin/unzip') && is_executable('/usr/bin/unzip') ) ); - - $errors = array(); - $template->add_header(''); - $template->add_header(''); - - $max_size = @ini_get('upload_max_filesize'); - $max_size_field = ''; - if ( $max_size ) - { - if ( preg_match('/M$/i', $max_size) ) - { - $max_size = intval($max_size) * 1048576; - } - else if ( preg_match('/K$/i', $max_size) ) - { - $max_size = intval($max_size) * 1024; - } - else if ( preg_match('/G$/i', $max_size) ) - { - $max_size = intval($max_size) * 1048576 * 1024; - } - $max_size = intval($max_size); - $max_size_field = "\n" . '' . "\n"; - } - - if ( isset($_GET['edit_img']) ) - { - $edit_parms = $_GET['edit_img']; - $regex = '/^((([0-9]+),)*)?([0-9]+?)$/'; - if ( !preg_match($regex, $edit_parms) ) - { - die_friendly('Bad request', '$_GET[\'edit_img\'] must be a comma-separated list of image IDs.
'); - } - - $idlist = explode(',', $edit_parms); - $num_edit = count($idlist); - $idlist = "SELECT img_id,img_title,img_desc,img_filename,is_folder FROM ".table_prefix."gallery WHERE img_id=" . implode(' OR img_id=', $idlist) . ';'; - - if ( !$e = $db->sql_query($idlist) ) - $db->_die(); - - $template->header(); - - if ( isset($_POST['edit_do_save']) ) - { - @set_time_limit(0); - - $arr_img_data = array(); - while ( $row = $db->fetchrow($e) ) - $arr_img_data[$row['img_id']] = $row; - - // Allow breaking out - switch(true):case true: - - if ( !is_array($_POST['img']) ) - { - $errors[] = 'No images passed to processor.'; - break; - } - - // Main updater loop - foreach ( $_POST['img'] as $img_id => $img_data ) - { - - if ( !preg_match('/^[0-9]+$/', $img_id) ) - { - $errors[] = 'SQL injection attempted!'; - break 2; - } - - // Array of columns to update - $to_update = array(); - - $key = 'reupload_' . $img_data['id']; - if ( isset($_FILES[$key]) ) - { - $file =& $_FILES[ $key ]; - if ( $file['tmp_name'] != '' ) - { - // Reupload - $filename = ENANO_ROOT . '/files/' . $arr_img_data[ $img_data['id'] ]['img_filename']; - if ( !unlink($filename) ) - { - $errors[] = "Could not delete $filename"; - break 2; - } - if ( !@move_uploaded_file($file['tmp_name'], $filename) ) - { - $errors[] = "Could not move uploaded file to $filename"; - break 2; - } - - // - // Create scaled images - // - - // Create thumbnail image - $thumb_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-thumb.jpg'; - if ( !unlink($thumb_filename) ) - { - $errors[] = "Could not delete $thumb_filename"; - break 2; - } - - if ( !scale_image($filename, $thumb_filename, 80, 80) ) - { - $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us'; - break 2; - } - - // Create preview image - $preview_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-preview.jpg'; - if ( !unlink($preview_filename) ) - { - $errors[] = "Could not delete $preview_filename"; - break 2; - } - - if ( !scale_image($filename, $preview_filename, 640, 480) ) - { - $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us'; - break 2; - } - - $to_update['img_time_mod'] = strval(time()); - } - } - - $vars = array( - 'year' => date('Y'), - 'month' => date('F'), - 'day' => date('d'), - 'time12' => date('g:i A'), - 'time24' => date('G:i') - ); - - // Image name/title - - $title = $template->makeParserText($img_data['title']); - $title->assign_vars($vars); - $executed = $title->run(); - if ( $executed == '_id' ) - { - $errors[] = 'You cannot name an image or folder "_id", this name is reserved for internal functions.'; - break 2; - } - if ( $executed == '' ) - { - $errors[] = 'Please enter a name for the item with unique ID ' . $img_data['id'] . '.' . print_r($_POST,true) . ''; - break 2; - } - $to_update['img_title'] = $executed; - - // Image description - - if ( isset($img_data['desc']) ) - { - $desc = $template->makeParserText($img_data['desc']); - $desc->assign_vars($vars); - $executed = $desc->run(); - $executed = RenderMan::preprocess_text($executed, false, false); - $to_update['img_desc'] = $executed; - } - - // Folder - $target_folder = false; - - if ( !empty($_POST['override_folder']) ) - { - if ( $_POST['override_folder'] == 'NULL' || preg_match('/^[0-9]+$/', $_POST['override_folder']) ) - { - $target_folder = $_POST['override_folder']; - } - } - - if ( !empty($img_data['folder']) ) - { - if ( $img_data['folder'] == 'NULL' || preg_match('/^[0-9]+$/', $img_data['folder']) ) - { - $target_folder = $img_data['folder']; - } - } - - if ( $target_folder ) - { - // Make sure we're not trying to move a folder to itself or a subdirectory of itself - - $children = gal_fetch_all_children(intval($img_data['id'])); - if ( $img_data['id'] == $target_folder || in_array($target_folder, $children) ) - { - $errors[] = 'You are trying to move a folder to itself, or to a subdirectory of itself, which is not allowed. If done manually (i.e. via an SQL client) this will result in infinite loops in the folder sorting code.'; - break 2; - } - - $to_update['folder_parent'] = $target_folder; - } - - if ( count($to_update) > 0 ) - { - $up_keys = array_keys($to_update); - $up_vals = array_values($to_update); - - $bin_cols = array('folder_parent'); - - $sql = 'UPDATE ' . table_prefix.'gallery SET '; - - foreach ( $up_keys as $i => $key ) - { - if ( in_array($key, $bin_cols) ) - { - $sql .= $key . '=' . $up_vals[$i] . ','; - } - else - { - $sql .= $key . '=\'' . $db->escape($up_vals[$i]) . '\','; - } - } - - $sql = preg_replace('/,$/i', '', $sql) . ' WHERE img_id=' . $img_data['id'] . ';'; - - if ( !$db->sql_query($sql) ) - { - $db->_die(); - } - - } - - } - - echo '
Information |
---|
- As with the upload form, the following variables can be used. Note that when editing images, the {id} and {autotitle} variables will be ignored.';
- ?>
-
|
Folder: ' . htmlspecialchars($row['img_title']) . ' | |
---|---|
Unique ID: | -' . $row['img_id'] . ' (view folder contents) | -
Parent folders: | -' . /* Yeah it's dirty, but hey, it gets the job done ;-) */ ( ( $x = str_replace('»', '»', htmlspecialchars(str_replace('_', ' ', implode(' » ', $folders)))) ) ? $x : '<in root>' ) . ' | -
Folder name: | -- |
Move to folder: | -
-
-
-
-
- Select folder
-
-
-
-
- - Unselect field - |
-
Image: ' . htmlspecialchars($row['img_title']) . ' | |
---|---|
Unique ID: | -' . $row['img_id'] . ' (view image\'s page) | -
Thumbnail: | -- |
Image title: | -- |
Image description: | -- |
Permissions: | -Only works in Firefox 1.5 or later, Safari 3.x or later, or Opera 9.0 or later. |
-
Move to folder: | -
-
-
-
-
- Select folder
-
-
-
-
- - Unselect field - |
- Upload new version: | -- '; - - // Finish table - echo ' |
Move all to folder: Other folder fields on this page can override this for individual images. |
-
-
-
-
-
- Select folder
-
-
-
-
- - Unselect field - |
- '; - echo ' |
---|
No images that matched the ID list could be found.
'; - } - - echo ''; - - $template->footer(); - return; - } - - if ( isset($_GET['rm']) ) - { - $warnings = array(); - - if ( !preg_match('/^[0-9]+$/', $_GET['rm']) ) - die_friendly('Bad Request', '$_GET[rm] needs to be an integer.
'); - - $rm_id = intval($_GET['rm']); - - if ( isset($_POST['confirmed']) ) - { - // The user confirmed the request. Start plowing through data to decide what to delete. - - // Array of images and folder rows to delete - $del_imgs = array($rm_id); - // Array of files to delete - $del_files = array(); - // Array of comment entries to delete - $del_comments = array(); - - $all_children = gal_fetch_all_children($rm_id); - $del_imgs = array_merge($del_imgs, $all_children); - - $imglist = 'img_id=' . implode(' OR img_id=', $del_imgs); - $sql = "SELECT img_id, img_filename FROM ".table_prefix."gallery WHERE ( $imglist ) AND is_folder!=1;"; - - if ( !$db->sql_query($sql) ) - { - $db->_die(); - } - - while ( $row = $db->fetchrow() ) - { - $files = array( - ENANO_ROOT . '/files/' . $row['img_filename'], - ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg', - ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg' - ); - $del_files = array_merge($del_files, $files); - - $del_comments[] = intval($row['img_id']); - } - - $commentlist = 'page_id=\'' . implode('\' OR page_id=\'', $del_imgs) . '\''; - - // Main deletion cycle - - foreach ( $del_files as $file ) - { - @unlink($file) or $warnings[] = 'Could not delete file ' . $file; - } - - if ( !$db->sql_query('DELETE FROM '.table_prefix.'gallery WHERE ' . $imglist . ';') ) - { - $warnings[] = 'Main delete query failed: ' . $db->get_error(); - } - - if ( !$db->sql_query('DELETE FROM '.table_prefix.'comments WHERE ( ' . $commentlist . ' ) AND namespace=\'Gallery\';') ) - { - $warnings[] = 'Comment delete query failed: ' . $db->get_error(); - } - - if ( count($warnings) > 0 ) - { - $template->header(); - - echo 'The deletion process generated some warnings which are shown below.
'; - echo 'Upload images to gallery | -|
---|---|
Image name template: | -- |
Image description template: | -- |
- The name and description templates can contain the following variables: -
Example: - |
- |
- Image files:
-
- - Your server has support for zip files. - Instead of uploading many image files, you can upload a single zip file here. Note that if you send a zip file through, - it must be the first and only file or it will be ignored. Any files in the zip archive that are not supported image - files will be ignored. - The maximum file size is {$sz}B."; - } - ?> - - - |
-
- - - - - - - - |
-
Upload to folder: | -
-
-
-
-
- Select folder
-
-
-
-
- |
-
- Please press the Upload button only once! Depending on the size of your image files and the speed of your connection, the upload may take several minutes. - | -
- - |
-
---|
You need to have administrative rights to use the gallery\'s upload features.
'); + } + + $zip_support = ( class_exists('ZipArchive') || ( file_exists('/usr/bin/unzip') && is_executable('/usr/bin/unzip') ) ); + + $errors = array(); + $template->add_header(''); + $template->add_header(''); + + $max_size_field = get_max_size_field(); + + // + // EDIT IMAGES + // + if ( isset($_GET['edit_img']) ) + { + $edit_parms = $_GET['edit_img']; + $regex = '/^((([0-9]+),)*)?([0-9]+?)$/'; + if ( !preg_match($regex, $edit_parms) ) + { + die_friendly('Bad request', '$_GET[\'edit_img\'] must be a comma-separated list of image IDs.
'); + } + + // process any uploaded images + // FIXME is this a bad place for this? + $limit = isset($_GET['ajax']) ? '' : "LIMIT 5"; + $q = $db->sql_query('SELECT img_id FROM ' . table_prefix . "gallery WHERE is_folder = 0 AND processed = 0 $limit;"); + if ( !$q ) + $db->_die(); + if ( $db->numrows() > 0 ) + { + while ( $row = $db->fetchrow($q) ) + { + snapr_process_image($row['img_id']); + } + $q = $db->sql_query('SELECT COUNT(img_id) FROM ' . table_prefix . "gallery WHERE is_folder = 0 AND processed = 0;"); + if ( !$q ) + $db->_die(); + list($count) = $db->fetchrow_num(); + $db->free_result(); + if ( intval($count) > 0 ) + redirect(makeUrlNS('Special', 'GalleryUpload', "edit_img={$_GET['edit_img']}"), "Processing images", "Processing images... $count remaining", 1); + } + + if ( !isset($_GET['ajax']) ) + $template->header(); + + snapr_editform($edit_parms); + + if ( !isset($_GET['ajax']) ) + $template->footer(); + + return; + } + // + // REMOVE IMAGES + // + else if ( isset($_GET['rm']) ) + { + $warnings = array(); + + if ( !preg_match('/^[0-9]+$/', $_GET['rm']) ) + die_friendly('Bad Request', '$_GET[rm] needs to be an integer.
'); + + $rm_id = intval($_GET['rm']); + + if ( isset($_POST['confirmed']) ) + { + // The user confirmed the request. Start plowing through data to decide what to delete. + + // Array of images and folder rows to delete + $del_imgs = array($rm_id); + // Array of files to delete + $del_files = array(); + // Array of comment entries to delete + $del_comments = array(); + + $all_children = gal_fetch_all_children($rm_id); + $del_imgs = array_merge($del_imgs, $all_children); + + $imglist = 'img_id=' . implode(' OR img_id=', $del_imgs); + $sql = "SELECT img_id, img_filename FROM ".table_prefix."gallery WHERE ( $imglist ) AND is_folder!=1;"; + + if ( !$db->sql_query($sql) ) + { + $db->_die(); + } + + while ( $row = $db->fetchrow() ) + { + $files = array( + ENANO_ROOT . '/files/' . $row['img_filename'], + ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg', + ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg' + ); + $del_files = array_merge($del_files, $files); + + $del_comments[] = intval($row['img_id']); + } + + $commentlist = 'page_id=\'' . implode('\' OR page_id=\'', $del_imgs) . '\''; + + // Main deletion cycle + + foreach ( $del_files as $file ) + { + @unlink($file) or $warnings[] = 'Could not delete file ' . $file; + } + + if ( !$db->sql_query('DELETE FROM '.table_prefix.'gallery WHERE ' . $imglist . ';') ) + { + $warnings[] = 'Main delete query failed: ' . $db->get_error(); + } + + if ( !$db->sql_query('DELETE FROM '.table_prefix.'comments WHERE ( ' . $commentlist . ' ) AND namespace=\'Gallery\';') ) + { + $warnings[] = 'Comment delete query failed: ' . $db->get_error(); + } + + if ( count($warnings) > 0 ) + { + $template->header(); + + echo 'The deletion process generated some warnings which are shown below.
'; + echo '' . print_r($_POST,true) . ''; + break 2; + } + $to_update['img_title'] = $executed; + + // Image description + + if ( isset($img_data['desc']) ) + { + $desc = $template->makeParserText($img_data['desc']); + $desc->assign_vars($vars); + $executed = $desc->run(); + $executed = RenderMan::preprocess_text($executed, false, false); + $to_update['img_desc'] = $executed; + } + + // Folder + $target_folder = false; + + if ( !empty($_POST['override_folder']) ) + { + if ( $_POST['override_folder'] == 'NULL' || preg_match('/^[0-9]+$/', $_POST['override_folder']) ) + { + $target_folder = $_POST['override_folder']; + } + } + + if ( !empty($img_data['folder']) ) + { + if ( $img_data['folder'] == 'NULL' || preg_match('/^[0-9]+$/', $img_data['folder']) ) + { + $target_folder = $img_data['folder']; + } + } + + if ( $target_folder ) + { + // Make sure we're not trying to move a folder to itself or a subdirectory of itself + + $children = gal_fetch_all_children(intval($img_data['id'])); + if ( $img_data['id'] == $target_folder || in_array($target_folder, $children) ) + { + $errors[] = 'You are trying to move a folder to itself, or to a subdirectory of itself, which is not allowed. If done manually (i.e. via an SQL client) this will result in infinite loops in the folder sorting code.'; + break 2; + } + + $to_update['folder_parent'] = $target_folder; + } + + if ( count($to_update) > 0 ) + { + $up_keys = array_keys($to_update); + $up_vals = array_values($to_update); + + $bin_cols = array('folder_parent'); + + $sql = 'UPDATE ' . table_prefix.'gallery SET '; + + foreach ( $up_keys as $i => $key ) + { + if ( in_array($key, $bin_cols) ) + { + $sql .= $key . '=' . $up_vals[$i] . ','; + } + else + { + $sql .= $key . '=\'' . $db->escape($up_vals[$i]) . '\','; + } + } + + $sql = preg_replace('/,$/i', '', $sql) . ' WHERE img_id=' . $img_data['id'] . ';'; + + if ( !$db->sql_query($sql) ) + { + $db->_die(); + } + + } + + } + + echo '