[Linpha-cvs] SF.net SVN: linpha: [4468] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-04-01 12:16:59
|
Revision: 4468 Author: fangehrn Date: 2006-04-01 04:16:49 -0800 (Sat, 01 Apr 2006) ViewCVS: http://svn.sourceforge.net/linpha/?rev=4468&view=rev Log Message: ----------- * big improvement in the import scripts -> removed redundancy -> added a "force_update" helpful to detect file permission changes! -> added possibility to check changes in the md5sum! for example: if the file is edited with an external program, linpha will now be able to check this and update the md5sum in the stats, comments etc.! (but the database has been up-to-date) Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/lib/classes/linpha.functions.php trunk/linpha2/lib/classes/linpha.import.class.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-04-01 11:09:56 UTC (rev 4467) +++ trunk/linpha2/ChangeLog 2006-04-01 12:16:49 UTC (rev 4468) @@ -7,6 +7,15 @@ * installer tested -> it works :-) + * big improvement in the import scripts + -> removed redundancy + -> added a "force_update" + helpful to detect file permission changes! + -> added possibility to check changes in the md5sum! + for example: if the file is edited with an external program, linpha will now be able + to check this and update the md5sum in the stats, comments etc.! + (but the database has been up-to-date) + 2006-03-31 bzrudi <linpha2_AT_tuxpower_DOT_de> * Installer: + at least mysql installation should work now Modified: trunk/linpha2/lib/classes/linpha.functions.php =================================================================== --- trunk/linpha2/lib/classes/linpha.functions.php 2006-04-01 11:09:56 UTC (rev 4467) +++ trunk/linpha2/lib/classes/linpha.functions.php 2006-04-01 12:16:49 UTC (rev 4468) @@ -79,21 +79,21 @@ function set_navigation_line( $id ) { - $array_files = $GLOBALS['linpha']->sql->getFullFilenameFromId( $id ); $str = '<a href="'.LINPHA_DIR.'/?cat=alb&id=0">></a> '; + $array_files = $GLOBALS['linpha']->sql->getFullFilenameFromId( $id ); foreach($array_files AS $key=>$value) { if($value != "") { - $str .= '<a href="'.LINPHA_DIR.'/?cat=alb&id='.$key.'">'.$value.'</a> > '; + $array_values[] = '<a href="'.LINPHA_DIR.'/?cat=alb&id='.$key.'">'.$value.'</a>'; } } - /** - * remove last spacer signs - */ - $str = substr($str,0,strlen($str)-6); + if(isset($array_values)) + { + $str .= implode(' > ',$array_values); + } return $str; Modified: trunk/linpha2/lib/classes/linpha.import.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.import.class.php 2006-04-01 11:09:56 UTC (rev 4467) +++ trunk/linpha2/lib/classes/linpha.import.class.php 2006-04-01 12:16:49 UTC (rev 4468) @@ -62,7 +62,10 @@ $d = dir( $dirname ); while( false !== ($entry = $d->read() ) ) { - $importarray_folder[] = $entry; + if($entry != '.' AND $entry != '..') + { + $importarray_folder[] = $entry; + } } /** @@ -81,6 +84,7 @@ */ $array_new = array_diff($importarray_folder, $importarray_db); $array_delete = array_diff($importarray_db, $importarray_folder); + $array_update = array_intersect($importarray_db,$importarray_folder); /** * parse deleted entries @@ -95,50 +99,19 @@ */ foreach($array_new AS $value) { - /** - * no output as it would occur on each view! - */ - $ext = linFilesys::getFileExtFromPath($value); - - if($value == '.' OR $value == '..') + LinImport::addNewEntry( $parent_id , $dirname , $value, $recursive ); + } + + /** + * parse updated entries + * not by default! (performance issues) + */ + if(isset($force_update) OR isset($_GET['force_update'])) + { + foreach($array_update AS $key=>$value) { - //no output + LinImport::updateEntry( $key , $dirname , $value ); } - elseif($value{0} == '.') - { - linSysLog("File ".$dirname.'/'.$value." Is Hidden<br />"); - } - elseif( in_array( $value, linImport::getIgnoreFilelist() ) ) - { - linSysLog("File ".$dirname.'/'.$value." Is In The Ignore List<br />"); - } - elseif( in_array($ext, linImport::getIgnoreFileext() ) ) - { - linSysLog("File ".$dirname.'/'.$value." Is In The Ignore List<br />"); - } - elseif( !is_readable( $dirname.'/'.$value) ) - { - linSysLog("File ".$dirname.'/'.$value." Is Not Readable<br />"); - } - /** - * no need for is_link as links are detected correctly - * with is_file, is_dir and is_readable ! - * elseif( is_link ($dirname.'/'.$value ) ) - { - linSysLog('link'); - }*/ - elseif( is_file( $dirname.'/'.$value ) ) - { - linImport::addNewFile( $parent_id, $dirname , $value ); - } - elseif( is_dir( $dirname.'/'.$entry ) ) - { - linImport::addNewDir( $parent_id, $dirname , $value , $recursive); - } - else - { - linSysLog('Error: what am i? '.$dirname.'/'.$entry.'<br />'); - } } /** @@ -151,7 +124,7 @@ "AND parent_id = '".$parent_id."'"); while($data = $query->FetchRow(ADODB_FETCH_ASSOC)) { - linImport::updateDir($data['id'], $recursive); + LinImport::updateDir($data['id'], $recursive); } } } @@ -169,79 +142,33 @@ * @param string $dirname name of current directory * @param string $filename filename of file currently processed */ -function addNewFile( $parent_id , $dirname , $filename ) +function addNewEntry( $parent_id , $dirname , $filename , $recursive ) { - linSysLog('new file '.$dirname.'/'.$filename.'<br />'); + linSysLog('new '.$dirname.'/'.$filename.'<br />'); - list($org_width,$org_height,$org_type) = linIdentify::linGetImageSize($dirname.'/'.$filename); - /** - * calculate md5sum (not for videos we have - * plenty of memory_limit problems here...) - * - * -> but we need an md5sum for statistics, comments, etc. - * -> calculate one of the full filename - * -> with a re-import all is lost... - * - * @todo as we're using php >= 5.0 in linpha 2.0, we can use the builtin md5_file - * do we have such limits with this function either??? - */ - if( linIdentify::isVideo($org_type) ) - { - $md5sum = md5($dirname.'/'.$filename); - } - elseif( linIdentify::isSupportedImage($org_type) ) - { - $md5sum = md5_file($dirname.'/'.$filename); - } - else - { - $md5sum = ''; - } - + list($md5sum,$file_type,$stats_number) = LinImport::getFileInformation($dirname,$filename); + $GLOBALS['linpha']->db->Execute("INSERT into ".PREFIX."photos ( " . "parent_id , name, img_type , md5sum , time_add , time_mod , stats_numbers ) " . "VALUES ( '".$parent_id."' , '".$GLOBALS['linpha']->sql->linAddslashes($filename)."', " . - "'".$org_type."' , '".$md5sum."', '".time()."', '".time()."', '1' )"); + "'".$file_type."' , '".$md5sum."', '".time()."', '".time()."', '".$stats_number."' )"); /** * delete thumbnail if one exists with the same id */ $inserted_id = $GLOBALS['linpha']->db->Insert_ID(); - linImage::deleteThumbnail($inserted_id); + LinImage::deleteThumbnail($inserted_id); /** * update number of photos */ - linImport::updateNumberPhotos( $parent_id ); -} + LinImport::updateNumberPhotos( $parent_id ); -/** - * import new directory - * @param int $parent_id parent id of folder in database - * @param string $dirname name of current directory - * @param string $filename filename of file currently processed - * @param bool $recursive scan directory recursive if true - */ -function addNewDir( $parent_id , $dirname , $filename , $recursive) -{ - linSysLog('new dir '.$dirname .'/'.$filename.'<br />'); - - $GLOBALS['linpha']->db->Execute("INSERT into ".PREFIX."photos " . - "( parent_id , img_type , name , time_add , time_mod )" . - " VALUES ( '".$parent_id."' , '0' , '". linSql::linAddSlashes($filename)."' , '".time()."' , '".time()."' )"); - - /** - * delete thumbnail if one exists with the same id - */ - $inserted_id = $GLOBALS['linpha']->db->Insert_ID(); - linImage::deleteThumbnail($inserted_id); - - if($recursive) + if($recursive && $file_type == 0) { - - linImport::addNewSubEntry( $inserted_id , $dirname.'/'.$filename , $recursive); + LinImport::addNewSubDir( $inserted_id , $dirname.'/'.$filename , $recursive); } } @@ -252,53 +179,16 @@ * @param string $dirname name of current directory * @param bool $recursive scan directory recursive if true */ -function addNewSubEntry( $parent_id , $dirname , $recursive) +function addNewSubDir( $parent_id , $dirname , $recursive) { $d = dir( $dirname ); - while( false !== ($entry = $d->read() ) ) { - $ext = linFilesys::getFileExtFromPath($entry); - if($entry == '.' OR $entry == '..') - { - //no output - } - elseif($entry{0} == '.') - { - linSysLog('hidden'); - } - elseif( in_array( $entry, linImport::getIgnoreFilelist() ) ) - { - linSysLog('ignore'); - } - elseif( in_array($ext, linImport::getIgnoreFileext() ) ) - { - linSysLog('ignore'); - } - elseif( !is_readable( $dirname.'/'.$entry) ) - { - linSysLog('not readable'); - } - /** - * no need for is_link as links are detected correctly with is_file, is_dir and is_readable ! - * elseif( is_link ($name.'/'.$entry ) ) - { - echo 'link'; - }*/ - elseif( is_file( $dirname.'/'.$entry ) ) - { - linImport::addNewFile( $parent_id, $dirname , $entry ); - } - elseif( is_dir( $dirname.'/'.$entry ) ) - { - linImport::addNewDir( $parent_id , $dirname , $entry , $recursive); - } + LinImport::addNewEntry( $parent_id , $dirname , $entry, $recursive ); } $d->close(); +} -} // end function addNew - - /** * recursive delete entries * @param int $photo_id id of current image in database @@ -338,7 +228,41 @@ } } +/** + * update entry (check md5sum and file_type) + * the file_type changes if a file changes to readable + */ +function updateEntry( $id , $dirname , $filename ) +{ + list($md5sum,$file_type,$stats_number) = LinImport::getFileInformation($dirname,$filename); + + $data = $GLOBALS['linpha']->db->GetRow("SELECT img_type, md5sum " . + "FROM ".PREFIX."photos WHERE id = '".$id."'"); + + /** + * update file_type + */ + if($file_type != $data[0]) + { + linSysLog("Detected a change of file_type in: ".$dirname.'/'.$filename.'<br />'); + $GLOBALS['linpha']->db->Execute("UPDATE ".PREFIX."photos " . + "SET img_type = '".$file_type."', stats_numbers = '".$stats_number."' " . + "WHERE id = '".$id."'"); + } + + /** + * update md5sum + */ + /** + * @todo hey, thats a nice feature! we are now able to detect + * changes on images and update the md5sum of the images in the comments etc.!! + */ + if($md5sum != $data[1]) + { + } +} + /** * update recursively number of photos in parent directories * @param int $id id of current image in database @@ -360,48 +284,82 @@ } } - /** - * print file table - * @todo $parent_id is defined but not used in function? + * returns an array containing md5sum, file_type and number of images + * number of images: 0 default, 1 if is_video or is_supported_image */ -function printFiles( $parent_id ) +function getFileInformation($dirname,$filename) { - $query = $GLOBALS['linpha']->db->Execute("SELECT id, name, img_type, parent_id " . - "FROM ".PREFIX."photos "); - rs2html($query,'',array('id','name','img_type','parent_id')); + $md5sum = ''; + $stats_number = 0; + $ext = linFilesys::getFileExtFromPath($filename); + if($filename{0} == '.') + { + linSysLog("File ".$dirname.'/'.$filename." Is Hidden<br />"); + $file_type = 9999999; + } + elseif( in_array( $filename, linImport::getIgnoreFilelist() ) ) + { + linSysLog("File ".$dirname.'/'.$filename." Is In The Ignore List<br />"); + $file_type = 9999999; + } + elseif( in_array($ext, linImport::getIgnoreFileext() ) ) + { + linSysLog("File ".$dirname.'/'.$filename." Is In The Ignore List<br />"); + $file_type = 9999999; + } + elseif( !is_readable( $dirname.'/'.$filename) ) + { + linSysLog("File ".$dirname.'/'.$filename." Is Not Readable<br />"); + $file_type = 9999999; + } + /** + * no need for is_link as links are detected correctly + * with is_file, is_dir and is_readable ! + * elseif( is_link ($dirname.'/'.$value ) ) + { + linSysLog('link'); + }*/ + elseif( is_dir( $dirname.'/'.$filename ) ) + { + $file_type = 0; + } + elseif( is_file( $dirname.'/'.$filename ) ) + { + list($org_width,$org_height,$file_type) = LinIdentify::linGetImageSize($dirname.'/'.$filename); - echo '<br />'; + /** + * calculate md5sum (not for videos we have + * plenty of memory_limit problems here...) + * + * -> but we need an md5sum for statistics, comments, etc. + * -> calculate one of the full filename + * -> with a re-import all is lost... + * + * @todo as we're using php >= 5.0 in linpha 2.0, we can use the builtin md5_file + * do we have such limits with this function either??? + */ + if( LinIdentify::isVideo($file_type) ) + { + $md5sum = md5($dirname.'/'.$filename); + $stats_number = 1; + } + elseif( LinIdentify::isSupportedImage($file_type) ) + { + $md5sum = md5_file($dirname.'/'.$filename); + $stats_number = 1; + } + } + else + { + linSysLog('Error: what am i? '.$dirname.'/'.$filename.'<br />'); + } + + return array($md5sum,$file_type,$stats_number); } - /** - * prints out the table with file permissions - */ -function printPermTable() -{ - $query = $GLOBALS['linpha']->db->Execute("SELECT id, photos_id, perm_type, permission " . - "FROM ".PREFIX."permissions"); - rs2html($query,'',array('id','photos_id','perm_type','permission')); - - - echo '<br />'; -} // end function printPermTable - - -/** - * truncate table - */ -function emptyTable() -{ - $GLOBALS['linpha']->db->Execute("TRUNCATE ".PREFIX."photos"); - -} // end function emptyTable - - - -/** * get an array with ignored filenames * * @author flo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |