From 71866708351b4afcf2788e9d14b09648ae2344a5 Mon Sep 17 00:00:00 2001 From: Max Kremmel Date: Tue, 22 Nov 2005 07:25:48 +0000 Subject: merge recent changes into HEAD --- FisheyeGallery.php | 74 ++++++++++---- FisheyeImage.php | 29 +++--- admin/admin_fisheye_inc.php | 4 + admin/schema_inc.php | 3 +- browse.php | 6 +- edit.php | 7 +- edit_image.php | 6 +- image/generating_thumbnails.png | Bin 4410 -> 0 bytes image_order.php | 6 +- list_galleries.php | 23 ++--- modules/mod_navigation.tpl | 26 +++++ templates/center_list_galleries.php | 2 +- templates/edit_image.tpl | 2 - templates/gallery_nav.tpl | 8 ++ templates/image_order.tpl | 44 ++++---- templates/list_galleries.tpl | 3 + templates/upload_fisheye.tpl | 28 +++-- templates/view_image.tpl | 15 +-- upload.php | 199 ++---------------------------------- upload_inc.php | 126 +++++++++++++++++++++++ 20 files changed, 324 insertions(+), 287 deletions(-) delete mode 100644 image/generating_thumbnails.png create mode 100644 modules/mod_navigation.tpl create mode 100644 upload_inc.php diff --git a/FisheyeGallery.php b/FisheyeGallery.php index 3957230..37e7c12 100644 --- a/FisheyeGallery.php +++ b/FisheyeGallery.php @@ -1,6 +1,6 @@ mDb->query($query, array( $this->mContentId ) ) ) { @@ -114,9 +115,25 @@ class FisheyeGallery extends FisheyeBase { if( $rows[$i]['image_id'] == $pCurrentImageId ) { if( $i > 0 ) { $this->mInfo['previous_image_id'] = $rows[$i-1]['image_id']; + + $trailingName = dirname( $rows[$i-1]['storage_path'] )."/avatar.jpg"; + if( file_exists( BIT_ROOT_PATH.$trailingName ) ) { + $this->mInfo['previous_image_avatar'] = BIT_ROOT_URL.$trailingName; + } else { + $mime_type = BitSystem::lookupMimeType( preg_match( "/\..*?$/", $rows[$i-1]['storage_path'] ) ); + $this->mInfo['previous_image_avatar'] = LibertySystem::getMimeThumbnailURL( $mime_type ); + } } if( $i + 1 < count( $rows ) ) { $this->mInfo['next_image_id'] = $rows[$i+1]['image_id']; + + $trailingName = dirname( $rows[$i+1]['storage_path'] )."/avatar.jpg"; + if( file_exists( BIT_ROOT_PATH.$trailingName ) ) { + $this->mInfo['next_image_avatar'] = BIT_ROOT_URL.$trailingName; + } else { + $mime_type = BitSystem::lookupMimeType( preg_match( "/\..*?$/", $rows[$i+1]['storage_path'] ) ); + $this->mInfo['next_image_avatar'] = LibertySystem::getMimeThumbnailURL( $mime_type ); + } } } } @@ -157,7 +174,7 @@ class FisheyeGallery extends FisheyeBase { foreach ($rows as $row) { $pass = TRUE; if( $gBitSystem->isPackageActive( 'gatekeeper' ) ) { - $pass = empty( $row['security_id'] ) || ( $row['user_id'] == $gBitUser->mUserId ) || !empty( $_SESSION['gatekeeper_security'][$row['security_id']] ); + $pass = $gBitUser->hasPermission( 'bit_p_admin_fisheye' ) || empty( $row['security_id'] ) || ( $row['user_id'] == $gBitUser->mUserId ) || !empty( $_SESSION['gatekeeper_security'][$row['security_id']] ); } if( $pass && $item = $gLibertySystem->getLibertyObject( $row['item_content_id'], $row['content_type_guid'] ) ) { $item->loadThumbnail( $this->mInfo['thumbnail_size'] ); @@ -460,16 +477,15 @@ vd( $this->mErrors ); function getList( &$pListHash ) { -// function getList($pUserId = NULL, $pFindString = NULL, $pSortMode = NULL, $pMaxRows = NULL) { global $gBitUser,$gBitSystem, $commentsLib; $this->prepGetList( $pListHash ); $bindVars = array(); $select = ''; $mid = ''; + $sort = ''; $join = ''; - $mapJoin = empty( $pListHash['show_empty'] ) ? ' INNER JOIN ' : ' LEFT OUTER JOIN '; // this *has* to go first because of bindVars order if( empty( $pListHash['show_empty'] ) ) { // This will nicely pull out the unused rows, but it is dog slow @@ -490,9 +506,9 @@ vd( $this->mErrors ); $mid .= " AND tc.`user_id` = ? "; $bindVars[] = $pListHash['user_id']; } - if( !empty( $pListHash['search'] ) ) { - $mid .= " AND UPPER(tc.`title`) LIKE ? "; - $bindVars[] = '%'.strtoupper( $pListHash['search'] ).'%'; + if( !empty( $pListHash['find'] ) ) { + $mid .= " AND UPPER( tc.`title` ) LIKE ? "; + $bindVars[] = '%'.strtoupper( $pListHash['find'] ).'%'; } if( $gBitSystem->isPackageActive( 'gatekeeper' ) ) { $select .= ' ,ts.`security_id`, ts.`security_description`, ts.`is_private`, ts.`is_hidden`, ts.`access_question`, ts.`access_answer` '; @@ -503,31 +519,51 @@ vd( $this->mErrors ); } } + // weed out empty galleries if we don't need them + if( empty( $pListHash['show_empty'] ) ) { + $mapJoin = "INNER JOIN `".BIT_DB_PREFIX."tiki_fisheye_gallery_image_map` tfgim ON (tfgim.`gallery_content_id`=tc.`content_id`)"; + } else { + $mapJoin = ""; + } + + if ( !empty( $pListHash['sort_mode'] ) ) { //converted in prepGetList() - $mid .= " ORDER BY ".$this->mDb->convert_sortmode( $pListHash['sort_mode'] )." "; + $sort .= " ORDER BY tc.".$this->mDb->convert_sortmode( $pListHash['sort_mode'] )." "; } $query = "SELECT DISTINCT( tfg.`gallery_id` ) AS `hash_key`, tfg.*, tc.*, uu.`login`, uu.`real_name`, ptc.`content_type_guid` AS `preview_content_type_guid` $select - FROM `".BIT_DB_PREFIX."tiki_fisheye_gallery` tfg LEFT OUTER JOIN `".BIT_DB_PREFIX."tiki_content` ptc ON( tfg.`preview_content_id`=ptc.`content_id` ), `".BIT_DB_PREFIX."users_users` uu, `".BIT_DB_PREFIX."tiki_content` tc $join - WHERE tfg.`content_id` = tc.`content_id` AND uu.`user_id` = tc.`user_id` $mid"; - if( $rs = $this->mDb->query( $query, $bindVars, $pListHash['max_records'],$pListHash['offset'] ) ) { - $ret = $rs->GetAssoc(); + FROM `".BIT_DB_PREFIX."tiki_fisheye_gallery` tfg + LEFT OUTER JOIN `".BIT_DB_PREFIX."tiki_content` ptc ON( tfg.`preview_content_id`=ptc.`content_id` ), `".BIT_DB_PREFIX."users_users` uu, `".BIT_DB_PREFIX."tiki_content` tc + $mapJoin $join + WHERE tfg.`content_id` = tc.`content_id` AND uu.`user_id` = tc.`user_id` $mid $sort"; + if( $rs = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] ) ) { + $data = $rs->GetAssoc(); if( empty( $pListHash['no_thumbnails'] ) ) { $thumbsize = !empty( $pListHash['thumbnail_size'] ) ? $pListHash['thumbnail_size'] : 'small'; - foreach( array_keys( $ret ) as $galleryId ) { - $ret[$galleryId]['display_url'] = $this->getDisplayUrl( $galleryId ); - if( $thumbImage = $this->getThumbnailImage( $ret[$galleryId]['content_id'], $ret[$galleryId]['preview_content_id'], $ret[$galleryId]['preview_content_type_guid'] ) ) { - $ret[$galleryId]['thumbnail_url'] = $thumbImage->getThumbnailUrl( $thumbsize ); + foreach( array_keys( $data ) as $galleryId ) { + $data[$galleryId]['display_url'] = $this->getDisplayUrl( $galleryId ); + if( $thumbImage = $this->getThumbnailImage( $data[$galleryId]['content_id'], $data[$galleryId]['preview_content_id'], $data[$galleryId]['preview_content_type_guid'] ) ) { + $data[$galleryId]['thumbnail_url'] = $thumbImage->getThumbnailUrl( $thumbsize ); } elseif( !empty( $pListHash['show_empty'] ) ) { - $ret[$galleryId]['thumbnail_url'] = FISHEYE_PKG_URL.'image/no_image.png'; + $data[$galleryId]['thumbnail_url'] = FISHEYE_PKG_URL.'image/no_image.png'; } else { - unset( $ret[$galleryId] ); + unset( $data[$galleryId] ); } } } } + // count galleries + $query_c = "SELECT COUNT( DISTINCT( tfg.`gallery_id` ) ) + FROM `".BIT_DB_PREFIX."tiki_fisheye_gallery` tfg + LEFT OUTER JOIN `".BIT_DB_PREFIX."tiki_content` ptc ON( tfg.`preview_content_id`=ptc.`content_id` ), `".BIT_DB_PREFIX."users_users` uu, `".BIT_DB_PREFIX."tiki_content` tc + $mapJoin $join + WHERE tfg.`content_id` = tc.`content_id` AND uu.`user_id` = tc.`user_id` $mid"; + $cant = $this->mDb->getOne( $query_c, $bindVars ); + + $ret['cant'] = $cant; + $ret['data'] = $data; return $ret; } } diff --git a/FisheyeImage.php b/FisheyeImage.php index 0311862..72c8021 100644 --- a/FisheyeImage.php +++ b/FisheyeImage.php @@ -1,6 +1,6 @@ mInfo['image_file']['storage_path'] ).'/'; $fileHash['name'] = $this->mInfo['image_file']['filename']; $fileHash['degrees'] = $pDegrees; - $rotateFunc = ($gBitSystem->getPreference( 'image_processor' ) == 'imagick' ) ? 'liberty_imagick_rotate_image' : 'liberty_gd_rotate_image'; + $rotateFunc = liberty_get_function( 'rotate' ); if( $rotateFunc( $fileHash ) ) { liberty_clear_thumbnails( $fileHash ); $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."tiki_fisheye_image` SET `width`=`height`, `height`=`width` WHERE `content_id`=?", array( $this->mContentId ) ); @@ -296,11 +296,15 @@ class FisheyeImage extends FisheyeBase { $info = NULL; $pFilePath = ($pFilePath ? $pFilePath : (empty($this->mInfo['image_file']['storage_path']) ? NULL : BIT_ROOT_PATH.$this->mInfo['image_file']['storage_path'])); - if ($pFilePath && file_exists($pFilePath) && filesize( $pFilePath ) ) { - if( $info = getimagesize(rtrim($pFilePath)) ) { - $info['width'] = $info[0]; - $info['height'] = $info[1]; - $info['size'] = filesize($pFilePath); + $checkFiles = array( $pFilePath, dirname( $pFilePath ).'/original.jpg' ); + + foreach( $checkFiles as $cf ) { + if ($cf && file_exists( $cf ) && filesize( $cf ) ) { + if( $info = getimagesize( rtrim( $cf ) ) ) { + $info['width'] = $info[0]; + $info['height'] = $info[1]; + $info['size'] = filesize( $cf ); + } } } @@ -382,16 +386,7 @@ class FisheyeImage extends FisheyeBase { if( empty( $this->mInfo['image_file']['gallery_thumbnail_url'] ) ) { $this->loadThumbnail( $pSize ); } - // this is not the cleanest file_exists check, but has to be this way since $this->mInfo['image_file']* - // have BIT_ROOT_URL in them, and you will end up with dual prefixes if you do somethingn like - // file_exists( BIT_ROOT_PATH.$this->mInfo['image_file']['gallery_thumbnail_url'] ) - if( !empty( $this->mInfo['image_file']['storage_path'] ) && file_exists( BIT_ROOT_PATH.dirname( $this->mInfo['image_file']['storage_path'] )."/$pSize.jpg" ) ) { - $ret = $this->mInfo['image_file']['gallery_thumbnail_url']; - } else { - $ret = FISHEYE_PKG_URL.'image/generating_thumbnails.png'; - } - - return $ret; + return $this->mInfo['image_file']['gallery_thumbnail_url']; } function expunge() { diff --git a/admin/admin_fisheye_inc.php b/admin/admin_fisheye_inc.php index 6776759..9fb8844 100644 --- a/admin/admin_fisheye_inc.php +++ b/admin/admin_fisheye_inc.php @@ -101,6 +101,10 @@ $formImageLists = array( 'label' => 'Use icons in the gallery bar', 'note' => 'When viewing an image, show previous and next links as images instead of words', ), + "gallery_bar_use_thumbnails" => array( + 'label' => 'Use Thumbnails in gallery bar', + 'note' => 'When viewing an image, show previous and next thumbnails with the appropriate links.', + ), ); $gBitSmarty->assign( 'formImageLists', $formImageLists); diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 5dc5317..a649975 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -95,7 +95,8 @@ $gBitInstaller->registerUserPermissions( FISHEYE_PKG_NAME, array( array('bit_p_create_fisheye', 'Can create an image gallery', 'registered', FISHEYE_PKG_NAME), array('bit_p_edit_fisheye', 'Can edit image gallery', 'registered', FISHEYE_PKG_NAME), array('bit_p_upload_fisheye', 'Can upload images to gallery', 'registered', FISHEYE_PKG_NAME), - array('bit_p_admin_fisheye', 'Can admin image galleries', 'editors', FISHEYE_PKG_NAME) + array('bit_p_admin_fisheye', 'Can admin image galleries', 'editors', FISHEYE_PKG_NAME), + array('bit_p_fisheye_upload_nonimages', 'Can upload non_image files', 'editors', FISHEYE_PKG_NAME) ) ); ?> diff --git a/browse.php b/browse.php index e52d33e..8d7310a 100644 --- a/browse.php +++ b/browse.php @@ -1,6 +1,6 @@ getList( $_REQUEST ); -$gBitSmarty->assign_by_ref('galleryList', $galleryList); +$gBitSmarty->assign_by_ref( 'galleryList', $galleryList['data'] ); -$gBitSystem->display("bitpackage:fisheye/browse_galleries.tpl"); +$gBitSystem->display( "bitpackage:fisheye/browse_galleries.tpl" ); ?> diff --git a/edit.php b/edit.php index caf923f..66182f7 100644 --- a/edit.php +++ b/edit.php @@ -1,6 +1,6 @@ mErrors) ? $gContent->mErrors : array()); $gBitSmarty->assign_by_ref('errors', $errors); -$gBitSmarty->assign_by_ref( 'parentGalleries', $gContent->getParentGalleries() ); +$gallery = $gContent->getParentGalleries(); +$gBitSmarty->assign_by_ref( 'parentGalleries', $gallery ); $getHash = array( 'user_id' => $gBitUser->mUserId, 'contain_item' => $gContent->mContentId, 'max_records' => -1, 'no_thumbnails' => TRUE, 'sort_mode'=>'title_asc' ); $galleryList = $gContent->getList( $getHash ); -$gBitSmarty->assign_by_ref('galleryList', $galleryList); +$gBitSmarty->assign_by_ref( 'galleryList', $galleryList['data'] ); $gContent->invokeServices( 'content_edit_function' ); diff --git a/edit_image.php b/edit_image.php index dbe2323..64d7283 100644 --- a/edit_image.php +++ b/edit_image.php @@ -1,6 +1,6 @@ loadParentGalleries(); // Get a list of all existing galleries $gFisheyeGallery = new FisheyeGallery(); -$listHash = array( 'user_id'=>$gContent->mInfo['user_id'], 'max_records' => -1, 'no_thumbnails' => TRUE, 'sort_mode'=>'title_asc' ); +$listHash = array( 'user_id' => $gContent->mInfo['user_id'], 'max_records' => -1, 'no_thumbnails' => TRUE, 'sort_mode' => 'title_asc', 'show_empty' => TRUE ); $galleryList = $gFisheyeGallery->getList( $listHash ); -$gBitSmarty->assign_by_ref('galleryList', $galleryList); +$gBitSmarty->assign_by_ref( 'galleryList', $galleryList['data'] ); $gBitSmarty->assign('requested_gallery', !empty($_REQUEST['gallery_id']) ? $_REQUEST['gallery_id'] : NULL); diff --git a/image/generating_thumbnails.png b/image/generating_thumbnails.png deleted file mode 100644 index 7fbb59d..0000000 Binary files a/image/generating_thumbnails.png and /dev/null differ diff --git a/image_order.php b/image_order.php index f23ceeb..3911d43 100644 --- a/image_order.php +++ b/image_order.php @@ -1,6 +1,6 @@ $gBitUser->mUserId, 'max_records'=>-1, 'no_thumbnails' => TRUE, 'sort_mode'=>'title_asc' ); +$listHash = array( 'user_id' => $gBitUser->mUserId, 'max_records' => -1, 'no_thumbnails' => TRUE, 'sort_mode' => 'title_asc', 'show_empty' => TRUE ); $galleryList = $gContent->getList( $listHash ); -$gBitSmarty->assign_by_ref('galleryList', $galleryList); +$gBitSmarty->assign_by_ref( 'galleryList', $galleryList['data'] ); $gContent->loadImages(); $gBitSmarty->assign_by_ref('galleryImages', $gContent->mItems); diff --git a/list_galleries.php b/list_galleries.php index 033b872..684ff93 100644 --- a/list_galleries.php +++ b/list_galleries.php @@ -1,6 +1,6 @@ getPreference( 'fisheye_list_thumbnail_size', 'small' ); $galleryList = $gFisheyeGallery->getList( $_REQUEST ); -$gBitSmarty->assign_by_ref('galleryList', $galleryList); -if (!empty($_REQUEST['offset']) && is_numeric($_REQUEST['offset'])) { - $gBitSmarty->assign_by_ref('iMaxRows', $iMaxRows); -} -if (!empty($_REQUEST['sort_mode'])) { - $gBitSmarty->assign_by_ref('iSortMode', $_REQUEST['sort_mode']); -} -if (!empty($_REQUEST['search'])) { - $gBitSmarty->assign_by_ref('iSearchString', $iSearchtring); -} +// pagination +$offset = !empty( $_REQUEST['offset'] ) ? $_REQUEST['offset'] : 0; +$gBitSmarty->assign( 'curPage', $page = !empty( $_REQUEST['page'] ) ? $_REQUEST['page'] : 1 ); +$offset = ( $page - 1 ) * $gBitSystem->mPrefs['maxRecords']; + +// calculate page number +$numPages = ceil( $galleryList['cant'] / $gBitSystem->mPrefs['maxRecords'] ); +$gBitSmarty->assign( 'numPages', $numPages ); -$gBitSystem->display("bitpackage:fisheye/$template", "List Galleries" ); +$gBitSmarty->assign( 'galleryList', $galleryList['data'] ); +$gBitSystem->display( "bitpackage:fisheye/$template", "List Galleries" ); ?> diff --git a/modules/mod_navigation.tpl b/modules/mod_navigation.tpl new file mode 100644 index 0000000..1c2caff --- /dev/null +++ b/modules/mod_navigation.tpl @@ -0,0 +1,26 @@ +{strip} +{if $gGallery} + {bitmodule title="$moduleTitle" name="fisheye_navigation"} +
+ {if $gGallery->mInfo.previous_image_id} + + +
+ « {tr}previous{/tr} +
+ {else} {/if} +
+ +
+ {if $gGallery->mInfo.next_image_id} + + +
+ {tr}next{/tr} » +
+ {else} {/if} +
+ {/bitmodule} +{/if} +{/strip} + diff --git a/templates/center_list_galleries.php b/templates/center_list_galleries.php index d5c3975..cc3641e 100644 --- a/templates/center_list_galleries.php +++ b/templates/center_list_galleries.php @@ -6,7 +6,7 @@ $_REQUEST['root_only'] = TRUE; $_REQUEST['get_thumbnails'] = TRUE; $galleryList = $gFisheyeGallery->getList( $_REQUEST ); - $gBitSmarty->assign_by_ref('galleryList', $galleryList); + $gBitSmarty->assign_by_ref( 'galleryList', $galleryList['data'] ); /* Process the input parameters this page accepts */ if (!empty($gQueryUser) && $gQueryUser->isRegistered()) { diff --git a/templates/edit_image.tpl b/templates/edit_image.tpl index 04f4a70..d5d3ec4 100644 --- a/templates/edit_image.tpl +++ b/templates/edit_image.tpl @@ -1,7 +1,5 @@ {strip} -{include file="bitpackage:fisheye/crop_image_js.tpl"} -
{biticon ipackage="liberty" iname="upload" iexplain="upload new image"}
diff --git a/templates/gallery_nav.tpl b/templates/gallery_nav.tpl index 1328950..e6c3cd5 100644 --- a/templates/gallery_nav.tpl +++ b/templates/gallery_nav.tpl @@ -17,6 +17,10 @@ {else} « {tr}previous{/tr} {/if} + {if $gBitSystem->isFeatureActive( 'gallery_bar_use_thumbnails' )} +
+ + {/if} {else} {/if} @@ -29,6 +33,10 @@ {else} {tr}next{/tr} » {/if} + {if $gBitSystem->isFeatureActive( 'gallery_bar_use_thumbnails' )} +
+ + {/if} {else} {/if} diff --git a/templates/image_order.tpl b/templates/image_order.tpl index 0a33c30..ad57cc5 100644 --- a/templates/image_order.tpl +++ b/templates/image_order.tpl @@ -13,7 +13,7 @@ - + @@ -54,7 +54,7 @@
{formlabel label="Position" for="imagePosition-`$galleryImages[ix]->mContentId`"} {forminput} - + {/forminput}
@@ -106,24 +106,32 @@ - - + + + + {if $gBitSystem->isPackageActive( 'gatekeeper' ) } - - {foreach from=$securities key=secId item=sec} - - {/foreach} + + + {foreach from=$securities key=secId item=sec} + + {/foreach} + {/if} - {foreach from=$galleryList item=gal key=galleryId} - {if $gContent->mInfo.content_id ne $gal.content_id} - - {/if} - {/foreach} - {foreach from=$galleryList item=gal key=galleryId} - {if $gContent->mInfo.content_id ne $gal.content_id} - - {/if} - {/foreach} + + {foreach from=$galleryList item=gal key=galleryId} + {if $gContent->mInfo.content_id ne $gal.content_id} + + {/if} + {/foreach} + + + {foreach from=$galleryList item=gal key=galleryId} + {if $gContent->mInfo.content_id ne $gal.content_id} + + {/if} + {/foreach} + {formhelp note=""} {/forminput} diff --git a/templates/list_galleries.tpl b/templates/list_galleries.tpl index bf4350f..56e173d 100644 --- a/templates/list_galleries.tpl +++ b/templates/list_galleries.tpl @@ -26,6 +26,8 @@ + {minifind} +
+ {libertypagination page=$curPage numPages=$numPages find=$find} {/strip} diff --git a/templates/upload_fisheye.tpl b/templates/upload_fisheye.tpl index 1976136..85bbc9f 100644 --- a/templates/upload_fisheye.tpl +++ b/templates/upload_fisheye.tpl @@ -1,15 +1,15 @@
-

{tr}Upload Images{/tr}

+

{tr}Upload Files{/tr}

- {form enctype="multipart/form-data" legend="Upload Images"} + {form enctype="multipart/form-data" legend="Upload Files"} {formfeedback note=$quotaMessage} {formfeedback warning="The maximum file size you can upload is `$uploadMax` Megabytes"} {formfeedback error=$errors} - {formhelp note="Here you can upload images. You can upload single image files, or you can upload archived files (.zip's, .sit's, .tar's, etc.) Archvied uploads will automatically be decompressed, and a gallery will created for every gallery in it. If you have nested folders, the hierarchy will be maintained for you with nested galleries." force=true} + {formhelp note="Here you can upload files. You can upload single files, or you can upload archived files (.zip's, .sit's, .tar's, etc.) Archvied uploads will automatically be decompressed, and a gallery will created for every gallery in it. If you have nested folders, the hierarchy will be maintained for you with nested galleries." force=true} {if $browserInfo.platform=='mac'} {formhelp note="Mac Users: The newer .sitx format is not supported currently because the makers of the StuffIt application have not released new versions of their software for servers. Please use DropZip or similar for best results." force=true} {/if} @@ -21,8 +21,8 @@
{formlabel label="Select File(s)"} {forminput} - - {formhelp note=""} + + {formhelp note="To upload more than one file, please click on choose repeatedly
(javascript has to be enabled for this to work)."} {/forminput}
@@ -35,13 +35,25 @@ {/forminput}
+ {if $gBitUser->hasPermission( 'bit_p_fisheye_upload_nonimages' )} +
+ {formlabel label="Process Archive(s)" for="process_archive"} + {forminput} + + {formhelp note="If you don't want to have archived files processed and extracted, please uncheck the above box."} + {/forminput} +
+ {else} + + {/if} +
- {formlabel label="Add Image(s) to these Galleries"} + {formlabel label="Add File(s) to these Galleries"} {forminput} {foreach from=$galleryList key=galId item=gal} {$gal.title}
{foreachelse} -
{tr}No Galleries Found{/tr}. {tr}A gallery named {displayname hash=$gBitUser->mInfo nolink=1}'s Gallery will be created for you and images will be added to it.{/tr}
+
{tr}No Galleries Found{/tr}. {tr}A gallery named {displayname hash=$gBitUser->mInfo nolink=1}'s Gallery will be created for you and files will be added to it.{/tr}
{/foreach} {/forminput}
diff --git a/templates/view_image.tpl b/templates/view_image.tpl index c70a351..8699bdd 100644 --- a/templates/view_image.tpl +++ b/templates/view_image.tpl @@ -11,8 +11,8 @@ {/if} {/if} {if $gContent->hasUserPermission('bit_p_admin')} - {biticon ipackage=liberty iname="edit" iexplain="Edit Image"} - {biticon ipackage=liberty iname="delete" iexplain="Delete Image"} + {biticon ipackage=liberty iname="edit" iexplain="Edit Image"} + {biticon ipackage=liberty iname="delete" iexplain="Delete Image"} {/if}
@@ -36,12 +36,13 @@ {/box} diff --git a/upload.php b/upload.php index e2bef19..e72c8c7 100644 --- a/upload.php +++ b/upload.php @@ -1,6 +1,6 @@ 0) && is_uploaded_file( $upImages[$key]['tmp_name'] ) ) { - // make a copy for each image we need to store - $storeHash = $_REQUEST; - $image = new FisheyeImage(); - // Store/Update the image - if (isset($_FILES[$key])) { - $storeHash['upload'] = &$_FILES[$key]; - $storeHash['upload']['process_storage'] = STORAGE_IMAGE; - } - $storeHash['purge_from_galleries'] = TRUE; - if( !$image->store( $storeHash ) ) { - array_merge( $upErrors, array_values( $image->mErrors ) ); - } - - $image->addToGalleries( $_REQUEST['galleryAdditions'], $order ); - $order += 10; - } + fisheye_store_upload( $upImages[$key], $order ); + $order += 10; } if( !is_object( $gContent ) || !$gContent->isValid() ) { @@ -109,178 +95,11 @@ if( $gBitSystem->isPackageActive( 'quota' ) ) { // Get a list of all existing galleries $gFisheyeGallery = new FisheyeGallery(); -$listHash = array( 'user_id' => $gBitUser->mUserId, 'show_empty' => true, 'max_records'=>-1, 'no_thumbnails'=>TRUE, 'sort_mode'=>'title_asc' ); +$listHash = array( 'user_id' => $gBitUser->mUserId, 'show_empty' => true, 'max_records'=>-1, 'no_thumbnails'=>TRUE, 'sort_mode'=>'title_asc', 'show_empty' => TRUE ); $galleryList = $gFisheyeGallery->getList( $listHash ); -$gBitSmarty->assign_by_ref('galleryList', $galleryList); +$gBitSmarty->assign_by_ref( 'galleryList', $galleryList['data'] ); $gBitSmarty->assign( 'uploadMax', $uploadMax ); $gBitSystem->display( 'bitpackage:fisheye/upload_fisheye.tpl', 'Upload Images' ); - -function fisheye_get_default_gallery_id( $pUserId, $pNewName ) { - $gal = new FisheyeGallery(); - $getHash = array( 'user_id' => $pUserId, 'max_records' => 1, 'sort_mode' => 'created_desc' ); - if( $upList = $gal->getList( $getHash ) ) { - $ret = key( $upList ); - } else { - $galleryHash = array( 'title' => $pNewName ); - if( $gal->store( $galleryHash ) ) { - $ret = $gal->mGalleryId; - } - } - - global $gContent; - if( !is_object( $gContent ) || !$gContent->isValid() ) { - $gContent = new FisheyeGallery( $ret ); - $gContent->load(); - } - return $ret; -} - -function liberty_process_archive( &$pFileHash ) { - $cwd = getcwd(); - $dir = dirname( $pFileHash['tmp_name'] ); - $upExt = strtolower( substr( $pFileHash['name'], (strrpos( $pFileHash['name'], '.' ) + 1) ) ); - $baseDir = $dir.'/'; - if( is_uploaded_file( $pFileHash['tmp_name'] ) ) { - global $gBitUser; - $baseDir .= $gBitUser->mUserId; - } - $destDir = $baseDir.'/'.basename( $pFileHash['tmp_name'] ); - if( (is_dir( $baseDir ) || mkdir( $baseDir )) && @mkdir( $destDir ) ) { - // Some commands don't nicely support extracting to other directories - chdir( $destDir ); - list( $mimeType, $mimeExt ) = split( '/', $pFileHash['type'] ); - switch( $mimeExt ) { - case 'x-rar-compressed': - case 'x-rar': - $shellResult = shell_exec( "rar x -w\"$destDir\" $pFileHash[tmp_name] " ); - break; - case 'x-bzip2': - case 'bzip2': - case 'x-gzip': - case 'gzip': - case 'x-tgz': - case 'x-tar': - case 'tar': - switch( $upExt ) { - case 'gz': - case 'tgz': $compressFlag = '-z'; break; - case 'bz2': $compressFlag = '-j'; break; - default: $compressFlag = ''; break; - } - $shellResult = shell_exec( "tar -x $compressFlag -f $pFileHash[tmp_name] -C \"$destDir\"" ); - break; - case 'x-zip-compressed': - case 'x-zip': - case 'zip': - $shellResult = shell_exec( "unzip $pFileHash[tmp_name] -d \"$destDir\"" ); - break; - case 'x-stuffit': - case 'stuffit': - $shellResult = shell_exec( "unstuff -d=\"$destDir\" $pFileHash[tmp_name] " ); - break; - default: - if( $upExt == 'zip' ) { - $shellResult = shell_exec( "unzip $pFileHash[tmp_name] -d \"$destDir\"" ); - } elseif( $upExt == 'rar' ) { - $shellResult = shell_exec( "rar x -w\"$destDir\" $pFileHash[tmp_name] " ); - } elseif( $upExt == 'sit' || $upExt == 'sitx' ) { - print( "unstuff -d=\"$destDir\" $pFileHash[tmp_name] " ); - $shellResult = shell_exec( "unstuff -d=\"$destDir\" $pFileHash[tmp_name] " ); - vd( $shellResult ); - } - break; - } - } - chdir( $cwd ); - return $destDir; -} - - -// Recursively builds a tree where each directory represents a gallery, and files are assumed to be images. -function fisheye_process_archive( &$pFileHash, &$pParentGallery, $pRoot=FALSE ) { - $errors = NULL; - $destDir = liberty_process_archive( $pFileHash ); - - if( empty( $pParentGallery ) && !is_uploaded_file( $pFileHash['tmp_name'] ) ) { - $pParentGallery = new FisheyeGallery(); - $galleryHash = array( 'title' => basename( $destDir ) ); - if( !$pParentGallery->store( $galleryHash ) ) { - $errors = array_merge( $errors, array_values( $pParentGallery->mErrors ) ); - } - global $gContent; - $gContent = &$pParentGallery; - } - - if( $archiveDir = opendir( $destDir ) ) { - $order = 100; - while( $fileName = readdir($archiveDir) ) { - $sortedNames[] = $fileName; - } - sort( $sortedNames ); - foreach( $sortedNames as $fileName ) { - if( !preg_match( '/^\./', $fileName ) ) { - $scanFile = array( - 'name' => $fileName, - 'size' => filesize( "$destDir/$fileName" ), - 'tmp_name' => "$destDir/$fileName", - ); - - if( !empty( $_REQUEST['resize'] ) && is_numeric( $_REQUEST['resize'] ) ) { - $scanFile['max_height'] = $scanFile['max_width'] = $_REQUEST['resize']; - } - - if( is_dir( $destDir.'/'.$fileName ) ) { - // We found a new Gallery! - $newGallery = new FisheyeGallery(); - $galleryHash = array( 'title' => str_replace( '_', ' ', $fileName ) ); - if( $newGallery->store( $galleryHash ) ) { - if( $pRoot ) { - $newGallery->addToGalleries( $_REQUEST['galleryAdditions'] ); - } - if( is_object( $pParentGallery ) ) { - $pParentGallery->addItem( $newGallery->mContentId, $order ); - } - //recurse down in! - $errors = array_merge( $errors, fisheye_process_archive( $scanFile, $newGallery ) ); - } else { - $errors = array_merge( $errors, array_values( $newGallery->mErrors ) ); - } - } else { - // support for the fileinfo pecl package: http://pecl.php.net/package/fileinfo - if( function_exists( 'finfo_open' ) ) { - $res = finfo_open(FILEINFO_MIME); - $scanFile['type'] = finfo_file($res, $scanFile['tmp_name']); - finfo_close($res); - } - if( empty( $scanFile['type'] ) ) { - $scanFile['type'] = ( "image/unknown" ); - } - $newImage = new FisheyeImage(); - $imageHash = array( 'upload' => $scanFile ); - if( $newImage->store( $imageHash ) ) { - if( $pRoot ) { - $newImage->addToGalleries( $_REQUEST['galleryAdditions'] ); - } - if( !is_object( $pParentGallery ) ) { - global $gBitUser; - $pParentGallery = new FisheyeGallery( fisheye_get_default_gallery_id( $gBitUser->mUserId, $gBitUser->getDisplayName()."'s Gallery" ) ); - $pParentGallery->load(); - } - $pParentGallery->addItem( $newImage->mContentId ); - } else { - $errors = array_merge( $errors, array_values( $newImage->mErrors ) ); - } - } - $order += 10; - } - } - } - return $errors; -} - - - - ?> diff --git a/upload_inc.php b/upload_inc.php new file mode 100644 index 0000000..e92b362 --- /dev/null +++ b/upload_inc.php @@ -0,0 +1,126 @@ + $pUserId, 'max_records' => 1, 'sort_mode' => 'created_desc' ); + $upList = $gal->getList( $getHash ); + if( !empty( $upList['data'] ) ) { + $ret = key( $upList['data'] ); + } else { + $galleryHash = array( 'title' => $pNewName ); + if( $gal->store( $galleryHash ) ) { + $ret = $gal->mGalleryId; + } + } + + global $gContent; + if( !is_object( $gContent ) || !$gContent->isValid() ) { + $gContent = new FisheyeGallery( $ret ); + $gContent->load(); + } + return $ret; +} + +function fisheye_store_upload( &$pFileHash, $pOrder = 10 ) { + if( !empty( $pFileHash ) && ($pFileHash['size'] > 0) && is_uploaded_file( $pFileHash['tmp_name'] ) ) { + // make a copy for each image we need to store + $storeHash = $_REQUEST; + $image = new FisheyeImage(); + // Store/Update the image + $storeHash['upload'] = &$pFileHash; + $storeHash['upload']['process_storage'] = STORAGE_IMAGE; + $storeHash['purge_from_galleries'] = TRUE; + if( !$image->store( $storeHash ) ) { + array_merge( $upErrors, array_values( $image->mErrors ) ); + } + + $image->addToGalleries( $_REQUEST['galleryAdditions'], $pOrder ); + } +} + +// Recursively builds a tree where each directory represents a gallery, and files are assumed to be images. +function fisheye_process_archive( &$pFileHash, &$pParentGallery, $pRoot=FALSE ) { + global $gBitSystem, $gBitUser; + $errors = array(); + if( ($destDir = liberty_process_archive( $pFileHash )) && (!empty( $_REQUEST['process_archive'] ) || !$gBitUser->hasPermission( 'bit_p_fisheye_upload_nonimages' )) ) { + if( empty( $pParentGallery ) && !is_uploaded_file( $pFileHash['tmp_name'] ) ) { + $pParentGallery = new FisheyeGallery(); + $galleryHash = array( 'title' => basename( $destDir ) ); + if( !$pParentGallery->store( $galleryHash ) ) { + $errors = array_merge( $errors, array_values( $pParentGallery->mErrors ) ); + } + global $gContent; + $gContent = &$pParentGallery; + } + + fisheye_process_directory( $destDir, $pParentGallery, $pRoot ); + } else { + global $gBitUser; + if( $gBitUser->hasPermission( 'bit_p_fisheye_upload_nonimages' ) ) { + fisheye_store_upload( $pFileHash ); + } else { + $errors['upload'] = tra( 'Your upload could not be processed because it was determined to be a non-image and you only have permission to upload images.' ); + } + } + return $errors; +} + +// Recursively builds a tree where each directory represents a gallery, and files are assumed to be images. +function fisheye_process_directory( $pDestinationDir, &$pParentGallery, $pRoot=FALSE ) { + $errors = array(); + if( $archiveDir = opendir( $pDestinationDir ) ) { + $order = 100; + while( $fileName = readdir($archiveDir) ) { + $sortedNames[] = $fileName; + } + sort( $sortedNames ); + foreach( $sortedNames as $fileName ) { + if( !preg_match( '/^\./', $fileName ) ) { + $scanFile = array( + 'name' => $fileName, + 'size' => filesize( "$pDestinationDir/$fileName" ), + 'tmp_name' => "$pDestinationDir/$fileName", + ); + + if( !empty( $_REQUEST['resize'] ) && is_numeric( $_REQUEST['resize'] ) ) { + $scanFile['max_height'] = $scanFile['max_width'] = $_REQUEST['resize']; + } + + if( is_dir( $pDestinationDir.'/'.$fileName ) ) { + // We found a new Gallery! + $newGallery = new FisheyeGallery(); + $galleryHash = array( 'title' => str_replace( '_', ' ', $fileName ) ); + if( $newGallery->store( $galleryHash ) ) { + if( $pRoot ) { + $newGallery->addToGalleries( $_REQUEST['galleryAdditions'] ); + } + if( is_object( $pParentGallery ) ) { + $pParentGallery->addItem( $newGallery->mContentId, $order ); + } + //recurse down in! + $errors = array_merge( $errors, fisheye_process_archive( $scanFile, $newGallery ) ); + } else { + $errors = array_merge( $errors, array_values( $newGallery->mErrors ) ); + } + } else { + $newImage = new FisheyeImage(); + $imageHash = array( 'upload' => $scanFile ); + if( $newImage->store( $imageHash ) ) { + if( $pRoot ) { + $newImage->addToGalleries( $_REQUEST['galleryAdditions'] ); + } + if( !is_object( $pParentGallery ) ) { + global $gBitUser; + $pParentGallery = new FisheyeGallery( fisheye_get_default_gallery_id( $gBitUser->mUserId, $gBitUser->getDisplayName()."'s Gallery" ) ); + $pParentGallery->load(); + } + $pParentGallery->addItem( $newImage->mContentId ); + } else { + $errors = array_merge( $errors, array_values( $newImage->mErrors ) ); + } + } + $order += 10; + } + } + } +} +?> -- cgit v1.3
{tr}Image Order{/tr}
{tr}Thumbnail{/tr} {tr}Title and Position{/tr} {tr}Miscellaneous{/tr}