# HG changeset patch # User Dan # Date 1185401714 14400 # Node ID 88c954d2846c3896871a2fff9914b3ec5abb0440 # Parent 94af07c8f2f3d6c8f2a6c15e3bf4e5a70de0685b Added search functionality (WiP); removed stray .marks file diff -r 94af07c8f2f3 -r 88c954d2846c plugins/Gallery.php --- a/plugins/Gallery.php Wed Jul 25 16:43:47 2007 -0400 +++ b/plugins/Gallery.php Wed Jul 25 18:15:14 2007 -0400 @@ -34,9 +34,12 @@ img_time_mod int(12) NOT NULL DEFAULT 0, PRIMARY KEY ( img_id ) );'); + if ( !$q ) $db->_die(); + $q = $db->sql_query('CREATE FULLTEXT INDEX '.table_prefix.'gal_idx ON '.table_prefix.'gallery(img_title, img_desc);'); + setConfig('gallery_version', GALLERY_VERSION); } @@ -46,5 +49,6 @@ require( ENANO_ROOT . '/plugins/gallery/browser.php' ); require( ENANO_ROOT . '/plugins/gallery/upload.php' ); require( ENANO_ROOT . '/plugins/gallery/fetcher.php' ); +require( ENANO_ROOT . '/plugins/gallery/search.php' ); ?> diff -r 94af07c8f2f3 -r 88c954d2846c plugins/gallery/.upload.php.marks --- a/plugins/gallery/.upload.php.marks Wed Jul 25 16:43:47 2007 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -!u;8818;8818 -!e;12994;12994 -!z;22686;22686 -!f;35274;35274 diff -r 94af07c8f2f3 -r 88c954d2846c plugins/gallery/browser.php --- a/plugins/gallery/browser.php Wed Jul 25 16:43:47 2007 -0400 +++ b/plugins/gallery/browser.php Wed Jul 25 18:15:14 2007 -0400 @@ -163,8 +163,9 @@ $breadcrumb_urlcache = ''; // CSS for gallery browser - $template->add_header(''); - $template->add_header(''); + // Moved to search.php + //$template->add_header(''); + //$template->add_header(''); $header = $template->getHeader(); @@ -226,6 +227,45 @@ // 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 .= '

Upload an image

'; + $html .= '
Create new folder'; + $html .= '
'; + $html .= '
'; + $html .= ' '; + $html .= '
'; + $html .= '
 

'; + } + + die_friendly('No images', '

No images have been uploaded to the gallery yet.

' . $html); + } + /* $folders_old = $folders; $folders = array( @@ -303,8 +343,16 @@ $f_errors = array(); - if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) && isset($first_row['folder_id']) ) + if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) ) { + if ( !isset($first_row['folder_id']) ) + { + $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.'; @@ -435,7 +483,7 @@ $per_page = $rows_in_browser * 5; - $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'start=%s', true), $start, $per_page, $callers, '', '
'); + $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'sort=' . $sort_column . '&order=' . $sort_order . '&start=%s', true), $start, $per_page, $callers, '', '
'); echo $html; if ( $session->user_level >= USER_LEVEL_ADMIN ) diff -r 94af07c8f2f3 -r 88c954d2846c plugins/gallery/search.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/gallery/search.php Wed Jul 25 18:15:14 2007 -0400 @@ -0,0 +1,59 @@ +attachHook('search_results', 'gal_searcher($q, $offset);'); + +$plugins->attachHook('compile_template', ' + // CSS for gallery browser + $template->add_header(\'\'); + $template->add_header(\'\'); + '); + +function gal_searcher($q, $offset) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + $fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)'; + $sql = "SELECT img_id, img_title, img_desc, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery + WHERE $fulltext_col > 0 + AND is_folder=0 + ORDER BY score DESC;"; + if ( !$db->sql_unbuffered_query($sql) ) + { + echo $db->get_error(); + return false; + } + echo "

Image results

"; + if ( $row = $db->fetchrow() ) + { + echo ''; + $renderer = new SnaprFormatter(); + do + { + echo $renderer->render(false, $row, false); + } + while ( $row = $db->fetchrow() ); + echo '
'; + } + else + { + echo '

No image results.

'; + } +} + +?> diff -r 94af07c8f2f3 -r 88c954d2846c plugins/gallery/upload.php --- a/plugins/gallery/upload.php Wed Jul 25 16:43:47 2007 -0400 +++ b/plugins/gallery/upload.php Wed Jul 25 18:15:14 2007 -0400 @@ -41,6 +41,26 @@ $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']; @@ -284,6 +304,8 @@ echo '
'; + echo $max_size_field; + if ( $row = $db->fetchrow($e) ) { @@ -486,7 +508,7 @@ echo gallery_hier_formfield('override_folder', false); ?>
- Unselect folder override field + Unselect field @@ -594,6 +616,7 @@ $template->header(); echo ''; + echo $max_size_field; echo '

Are you sure you want to delete this item?

'; echo '

If you continue, this item will be permanently deleted from the gallery – no rollbacks.

'; @@ -954,6 +977,7 @@ '; + echo $max_size_field; if ( count($errors) > 0 ) { echo '
diff -r 94af07c8f2f3 -r 88c954d2846c plugins/gallery/viewimage.php --- a/plugins/gallery/viewimage.php Wed Jul 25 16:43:47 2007 -0400 +++ b/plugins/gallery/viewimage.php Wed Jul 25 18:15:14 2007 -0400 @@ -200,7 +200,7 @@ if ( $perms->get_permissions('gal_full_res') ) { - echo ''; + echo ''; } echo 'Image preview (640px max width)';