[Spidertree-cvs] spidertree/classes SAlbum.php,1.6,1.7 SImage.php,1.3,1.4 SUserBase.php,1.3,1.4
Status: Pre-Alpha
Brought to you by:
spiderr
|
From: <sp...@us...> - 2004-02-09 06:26:12
|
Update of /cvsroot/spidertree/spidertree/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20017/classes Modified Files: SAlbum.php SImage.php SUserBase.php Log Message: uploads now working, thumbnailing still non-existent Index: SAlbum.php =================================================================== RCS file: /cvsroot/spidertree/spidertree/classes/SAlbum.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SAlbum.php 8 Feb 2004 02:37:16 -0000 1.6 +++ SAlbum.php 9 Feb 2004 06:23:02 -0000 1.7 @@ -45,6 +45,8 @@ var $mALID; /** The acct id that owns this album **/ var $mUID; + /** Array of images for this album, hash indexed my image_id **/ + var $mImages; // }}} @@ -75,7 +77,7 @@ **/ function load() { if( !empty( $this->mALID ) ) { - $sql = "SELECT *, subpath(path, -1) AS url FROM ".STREE_DB_PREFIX."album WHERE album_id=?"; + $sql = "SELECT *, subpath(path, -1) AS url, album_id AS alid FROM ".STREE_DB_PREFIX."album WHERE album_id=?"; $rs = $this->mDB->Execute($sql, array( $this->mALID ) ); if( empty($rs) || empty( $rs->fields['album_id'] ) ) { $this->mErrors['load'] = 'Album could not be loaded.'; @@ -86,6 +88,32 @@ } return( count( $this->mErrors ) == 0 ); } + // }}} + + // {{{ loadImages + /** + * Define and load Smarty components + * + * @param none + * @return TRUE if successful, FALSE if not. mErrors will hold error strings + * @access public + **/ + function loadImages( $iImageSize=IMAGE_SIZE_SMALL ) { + if( !empty( $this->mALID ) ) { + $sql = "SELECT i.* FROM ".STREE_DB_PREFIX."album a, ".STREE_DB_PREFIX."album_map am, ".STREE_DB_PREFIX."image i + WHERE a.album_id=? AND am.album_id=a.album_id AND am.image_id=i.image_id"; + $rs = $this->mDB->Execute($sql, array( $this->mALID ) ); + $this->mImages = array(); + while( !$rs->EOF ) { + $rs->fields['file_url'] = getImageURL( $rs->fields['file_name'], $rs->fields['user_id'], $iImageSize ); + array_push( $this->mImages, $rs->fields ); + $rs->MoveNext(); + } + } + return( count( $this->mErrors ) == 0 ); + } + // }}} + // {{{ verify /** @@ -184,21 +212,24 @@ * @return TRUE if successful, FALSE if not. mErrors will hold error strings * @access public **/ - function processUpload( &$pPostFiles, $iDestPath ) { + function processUpload( &$pPostFiles ) { +debug(99); $files = &$pPostFiles['UPLOAD']; + $this->mDB->StartTrans(); foreach( array_keys( $files['size'] ) as $i ) { if( $files['size'][$i] > 0 ) { $imageHash['tmp_loc'] = $files['tmp_name'][$i]; - $imageHash['dest_loc'] = $iDestPath.$files['name'][$i]; + $imageHash['dest_name'] = $files['name'][$i]; $imageHash['size'] = $files['size'][$i]; $image = new SImage( NULL, $this->mUID ); if( $image->store( $imageHash ) ) { - $this->addImage( ); + $this->addImage( $image->mIMID ); } else { pvd( $image->mErrors ); } } } + $this->mDB->CompleteTrans(); } // }}} @@ -213,8 +244,10 @@ function addImage( $iImageMixed ) { if( isset( $this->mALID ) && isset( $this->mUID ) ) { if( is_numeric( $iImageMixed ) ) { - $sql = "INSERT"; + $sql = "INSERT INTO album_map ( album_id, image_id ) VALUES ( ?, ? )"; } + $rs = $this->mDB->Execute($sql, array( $this->mALID, $iImageMixed ) ); + $this->mDB->CompleteTrans(); } } // }}} Index: SImage.php =================================================================== RCS file: /cvsroot/spidertree/spidertree/classes/SImage.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SImage.php 8 Feb 2004 02:09:43 -0000 1.3 +++ SImage.php 9 Feb 2004 06:23:02 -0000 1.4 @@ -37,6 +37,11 @@ require_once( KERNEL_PKG_PATH.'TikiBase.php' ); +define( 'IMAGE_SIZE_ORIGINAL', 'upload' ); +define( 'IMAGE_SIZE_SMALL', 'small' ); +define( 'IMAGE_SIZE_MEDIUM', 'medium' ); +define( 'IMAGE_SIZE_LARGE', 'large' ); + class SImage extends TikiBase { // {{{ properties @@ -72,20 +77,24 @@ * @return TRUE if successful, FALSE if not. mErrors will hold error strings * @access public **/ - function load() { + function load( $iImageSize = IMAGE_SIZE_LARGE ) { + global $gSpidertree; +//debug(); if( !empty( $this->mIMID ) ) { - $sql = "SELECT * FROM ".STREE_DB_PREFIX."image WHERE image_id=?"; + $sql = "SELECT i.*, i.image_id AS imid + FROM ".STREE_DB_PREFIX."image i WHERE i.image_id=?"; $rs = $this->mDB->Execute($sql, array( $this->mIMID ) ); if( empty($rs) || empty( $rs->fields['image_id'] ) ) { - $this->mErrors['load'] = 'Album could not be loaded.'; + $this->mErrors['load'] = 'Image could not be loaded.'; } else { $this->mRow = $rs->fields; + $this->mRow['file_url'] = getImageURL( $rs->fields['file_name'], $rs->fields['user_id'], $iImageSize ); $this->mRow['IMID'] = $rs->fields['image_id']; } } return( count( $this->mErrors ) == 0 ); } - + // {{{ verify /** * This verifies data integrity. NOTE: pass by reference is crucial, because some modifications @@ -106,10 +115,11 @@ } else { // move the uploaded file if( empty($this->IMID ) ) { - if( move_uploaded_file( $pParams['tmp_loc'], $pParams['dest_loc'] ) ) { - $pParams['file_name'] = basename( $pParams['dest_loc'] ); + $pParams['new_image_id'] = $this->mDB->GenID( 'image_id_seq' ); + $pParams['file_name'] = $pParams['new_image_id'].'.'.substr( $pParams['dest_name'], 0, (255-($pParams['new_image_id'] % 10) ) ); + if( move_uploaded_file( $pParams['tmp_loc'], getUploadPath( $this->mUID ).$pParams['file_name'] ) ) { if( empty( $pParams['title'] ) ) { - $pParams['title'] = substr( $pParams['file_name'], 0, strrpos( $pParams['file_name'], '.' ) ); + $pParams['title'] = substr( $pParams['dest_name'], 0, strrpos( $pParams['dest_name'], '.' ) ); } } else { $this->mErrors['upload'] = 'Could not store uploaded file '.basename( $pParams['dest_loc'] ).'.'; @@ -153,7 +163,7 @@ $sql = "UPDATE ".STREE_DB_PREFIX."image SET title=? WHERE user_id=? AND image_id=?"; $bindVars = array( $pParams['title'], $this->mUID, $pParams['IMID'] ); } else { - $pParams['IMID'] = $this->mDB->GenID( 'image_id_seq' ); + $pParams['IMID'] = $pParams['new_image_id']; $this->mIMID = $pParams['IMID']; // insert new row @@ -226,8 +236,417 @@ return( count( $this->mErrors ) == 0 ); } // }}} + + + function getFileInfo () { + if( isset( $this->mRow['file_path'] ) ) { + } + } + +} + +function getUserPath( $iUID ) { + return round( ($iUID / 1000) ).'/'.$iUID.'/'; } + +function getUploadPath( $iUID ) { + global $gSpidertree; + $ret = NULL; + if( is_numeric( $iUID ) ) { + $userDir = $gSpidertree['content_path'].'/'.getUserPath(); + mkdir_p( $userDir ); + mkdir_p( $userDir.IMAGE_SIZE_ORIGINAL ); + mkdir_p( $userDir.IMAGE_SIZE_SMALL ); + mkdir_p( $userDir.IMAGE_SIZE_MEDIUM ); + mkdir_p( $userDir.IMAGE_SIZE_LARGE ); + $ret = $userDir.IMAGE_SIZE_ORIGINAL.'/'; + if( !file_exists( $ret ) ) { +print "ERROR making upload path"; + } +pvd( $ret ); + } + return $ret; +} + + + +function getImageURL( $iFileName, $iUID, $iImageSize ) { + global $gSpidertree; + $tailPath = getUserPath( $iUID ).$iImageSize.'/'.$iFileName; + $fullPath = SPIDERTREE_PKG_PATH.$gSpidertree['content_url'].$tailPath; + if( file_exists( $fullPath ) ) { + $ret = SPIDERTREE_PKG_URL.$gSpidertree['content_url'].$tailPath; + } else { + $ret = SPIDERTREE_PKG_URL.'images/generating_thumbnails.gif'; + } + return $ret; +} + + +/* + + +// Snagged from Gallery for reference + +function getDimensions($file, $regs=false) { + global $gallery; + + if ($regs === false) + $regs = getimagesize($file); + if (($regs[0] > 1) && ($regs[1] > 1)) + return array($regs[0], $regs[1]); + else if (isDebugging()) + echo "<br>" .sprintf(_("PHP's %s unable to determine dimensions."), + "getimagesize()") ."<br>"; + + + // Just in case php can't determine dimensions. + switch($gallery->app->graphics) + { + case "NetPBM": + list($lines, $status) = + exec_internal(toPnmCmd($file) . + " | " . + NetPBM("pnmfile", "--allimages")); + break; + case "ImageMagick": + // This fails under windows, IM isn't returning parsable status output. + list($lines, $status) = + exec_internal(ImCmd("identify", fs_import_filename($file))); + break; + default: + if (isDebugging()) + echo "<br>" . _("You have no graphics package configured for use!") ."<br>"; + return array(0, 0); + break; + } + + if ($status == $gallery->app->expectedExecStatus) { + foreach ($lines as $line) { + switch($gallery->app->graphics) + { + case "NetPBM": + if (ereg("([0-9]+) by ([0-9]+)", $line, $regs)) + return array($regs[1], $regs[2]); + break; + case "ImageMagick": + if (ereg("([0-9]+)x([0-9]+)", $line, $regs)) + return array($regs[1], $regs[2]); + break; + } + } + } + + if (isDebugging()) + echo "<br>Unable to determine image dimensions!<br>"; + + return array(0, 0); +} + + +function rotate_image($src, $dest, $target, $type) { + global $gallery; + + if (!strcmp($src,$dest)) { + $useTemp = true; + $out = "$dest.tmp"; + } + else { + $out = $dest; + } + + $outFile = fs_import_filename($out, 1); + $srcFile = fs_import_filename($src, 1); + + $type = strtolower($type); + if (isset($gallery->app->use_jpegtran) && !empty($gallery->app->use_jpegtran) && ($type === 'jpg' || $type === 'jpeg')) { + if (!strcmp($target, '-90')) { + $args = '-rotate 90'; + } else if (!strcmp($target, '180')){ + $args = '-rotate 180'; + } else if (!strcmp($target, '90')) { + $args = '-rotate 270'; + } else if (!strcmp($target, 'fv')) { + $args = '-flip vertical'; + } else if (!strcmp($target, 'fh')) { + $args = '-flip horizontal'; + } else if (!strcmp($target, 'tr')) { + $args = '-transpose'; + } else if (!strcmp($target, 'tv')) { + $args = '-transverse'; + } else { + $args = ''; + } + + $path = $gallery->app->use_jpegtran; + // -copy all ensures all headers (i.e. EXIF) are copied to the rotated image + exec_internal(fs_import_filename($path, 1) . " $args -copy all -outfile $outFile $srcFile"); + } else { + switch($gallery->app->graphics) + { + case "NetPBM": + $args2 = ''; + if (!strcmp($target, '-90')) { + // NetPBM's docs mix up CW and CCW... + // We'll do it right. + $args = '-r270'; + } else if (!strcmp($target, '180')) { + $args = '-r180'; + } else if (!strcmp($target, '90')) { + $args = '-r90'; + } else if (!strcmp($target, 'fv')) { + $args = '-tb'; + } else if (!strcmp($target, 'fh')) { + $args = '-lr'; + } else if (!strcmp($target, 'tr')) { + $args = '-xy'; + } else if (!strcmp($target, 'tv')) { + // Because of NetPBM inconsistencies, the only + // way to do this transformation on *all* + // versions of NetPBM is to pipe two separate + // operations in sequence. Versions >= 10.13 + // have the new -xform flag, and versions <= + // 10.6 could take the '-xy -r180' commands in + // sequence, but versions 10.7--> 10.12 can't + // do *either*, so we're left with this little + // workaround. -Beckett 9/9/2003 + $args = '-xy'; + $args2 = ' | ' . NetPBM('pnmflip', '-r180'); + } else { + $args = ''; + } + + $err = exec_wrapper(toPnmCmd($src) . ' | ' . + NetPBM('pnmflip', $args) . + $args2 . + ' | ' . fromPnmCmd($out)); + + // copy exif headers from original image to rotated image + if (isset($gallery->app->use_exif)) { + $path = $gallery->app->use_exif; + exec_internal(fs_import_filename($path, 1) . " -te $srcFile $outFile"); + } + break; + case "ImageMagick": + if (!strcmp($target, '-90')) { + $im_cmd = '-rotate 90'; + } else if (!strcmp($target, '180')) { + $im_cmd = '-rotate 180'; + } else if (!strcmp($target, '90')) { + $im_cmd = '-rotate -90'; + } else if (!strcmp($target, 'fv')) { + $im_cmd = '-flip'; + } else if (!strcmp($target, 'fh')) { + $im_cmd = '-flop'; + } else if (!strcmp($target, 'tr')) { + $im_cmd = '-affine 0,1,1,0,0,0 -transform'; + } else if (!strcmp($target, 'tv')) { + $im_cmd = '-affine 0,-1,-1,0,0,0 -transform'; + } else { + $im_cmd = ''; + } + + + $src = fs_import_filename($src); + $out = fs_import_filename($out); + $err = exec_wrapper(ImCmd('convert', "$im_cmd $srcFile $outFile")); + break; + default: + if (isDebugging()) + echo "<br>". _("You have no graphics package configured for use!") ."<br>"; + return 0; + break; + } + } + + if (fs_file_exists("$out") && fs_filesize("$out") > 0) { + if ($useTemp) { + fs_copy($out, $dest); + fs_unlink($out); + } + return 1; + } else { + return 0; + } +} + + + +function cut_image($src, $dest, $x, $y, $width, $height) { + global $gallery; + if (!strcmp($src,$dest)) { + $useTemp = true; + $out = "$dest.tmp"; + } + else { + $out = $dest; + } + + switch($gallery->app->graphics) + { + case "NetPBM": + $err = exec_wrapper(toPnmCmd($src) . + " | " . + NetPBM("pnmcut") . + " $x $y $width $height" . + " | " . + fromPnmCmd($out)); + break; + case "ImageMagick": + $src = fs_import_filename($src); + $out = fs_import_filename($out); + $err = exec_wrapper(ImCmd("convert", "-crop " . + $width ."x". $height ."+". $x ."+". $y . + " $src $out")); + break; + default: + if (isDebugging()) + echo "<br>" . _("You have no graphics package configured for use!") ."<br>"; + return 0; + break; + } + + if (fs_file_exists("$out") && fs_filesize("$out") > 0) { + if ($useTemp) { + fs_copy($out, $dest); + fs_unlink($out); + } + return 1; + } else { + return 0; + } +} + +function compress_image($src, $out, $target, $quality, $keepProfiles=false) { + global $gallery; + + if ($target === 'off') { + $target = ''; + } + switch($gallery->app->graphics) { + case "NetPBM": + $err = exec_wrapper(toPnmCmd($src) . + (($target > 0) ? (' | ' .NetPBM('pnmscale', + " -xysize $target $target")) : '') + . ' | ' . fromPnmCmd($out, $quality)); + // copy over EXIF data if a JPEG if $keepProfiles is + // set. Unfortunately, we can't also keep comments. + if ($keepProfiles && eregi('\.jpe?g$', $src)) { + if (isset($gallery->app->use_exif)) { + exec_wrapper(fs_import_filename($gallery->app->use_exif, 1) . ' -te ' + . fs_import_filename($src, 1) . ' ' + . fs_import_filename($out, 1)); + } else { + processingMsg(_('Unable to preserve EXIF data (jhead not installed)') . "\n"); + } + } + break; + case "ImageMagick": + $src = fs_import_filename($src); + $out = fs_import_filename($out); + // Preserve comment, EXIF data if a JPEG if $keepProfiles is set. + $err = exec_wrapper(ImCmd('convert', "-quality $quality " + . ($target ? "-size ${target}x${target} " : '') + . ($keepProfiles ? ' ' : ' +profile \'*\' ') + . $src + . ($target ? " -geometry ${target}x${target} " : '') + . $out)); + break; + default: + if (isDebugging()) + echo "<br>" . _("You have no graphics package configured for use!")."<br>"; + return 0; + break; + } +} + +function toPnmCmd($file) { + global $gallery; + + if (eregi("\.png\$", $file)) { + $cmd = "pngtopnm"; + } else if (eregi("\.jpe?g\$", $file)) { + if (isDebugging()) { + $cmd = "jpegtopnm"; + } else { + $cmd = "jpegtopnm"; + } + } else if (eregi("\.gif\$", $file)) { + $cmd = "giftopnm"; + } + + if (!empty($cmd)) { + return NetPBM($cmd) . + " " . + fs_import_filename($file); + } else { + gallery_error(sprintf(_("Unknown file type: %s"), $file)); + return ""; + } +} + +function fromPnmCmd($file, $quality=NULL) { + global $gallery; + if ($quality == NULL) { + $quality=$gallery->app->jpegImageQuality; + } + + if (eregi("\.png(\.tmp)?\$", $file)) { + $cmd = NetPBM("pnmtopng"); + } else if (eregi("\.jpe?g(\.tmp)?\$", $file)) { + $cmd = NetPBM($gallery->app->pnmtojpeg, + "--quality=" . $quality); + } else if (eregi("\.gif(\.tmp)?\$", $file)) { + $cmd = NetPBM("ppmquant", "256") . " | " . NetPBM("ppmtogif"); + } + + if ($cmd) { + return "$cmd > " . fs_import_filename($file); + } else { + gallery_error(sprintf(_("Unknown file type: %s"), $file)); + return ""; + } +} + +function netPbm($cmd, $args="") { + global $gallery; + + $cmd = fs_import_filename($gallery->app->pnmDir . "/$cmd"); + if (!isDebugging()) { + $cmd .= " --quiet"; + } + $cmd .= " $args"; + return $cmd; +} + +function ImCmd($cmd, $args = "") { + global $gallery; + + $cmd = fs_import_filename($gallery->app->ImPath . "/$cmd"); + $cmd .= " $args"; + return $cmd; +} + +function exec_wrapper($cmd) { + global $gallery; + + list($results, $status) = exec_internal($cmd); + + if ($status == $gallery->app->expectedExecStatus) { + return 0; + } else { + if ($results) { + gallery_error(join("<br>", $results)); + } + return 1; + } +} + +*/ + + + ?> Index: SUserBase.php =================================================================== RCS file: /cvsroot/spidertree/spidertree/classes/SUserBase.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SUserBase.php 8 Feb 2004 02:09:43 -0000 1.3 +++ SUserBase.php 9 Feb 2004 06:23:02 -0000 1.4 @@ -72,20 +72,6 @@ return $ret; } - function getUploadPath() { - global $gSpidertree; - $ret = NULL; - if( $this->mUID ) { - $groupDir = '/'.($this->mUID % 1000).'/'; - $ret = $gSpidertree['content_path'].$groupDir.$this->mUID.'/'; - mkdir_p( $ret ); - if( !file_exists( $ret ) ) { -print "ERROR making upload path"; - } - } - return $ret; - } - } function mkdir_p($target){ |