[Clipart] r39 - makerelease

noreply at openclipart.org noreply at openclipart.org
Sun Jun 28 02:21:26 PDT 2009


Author: rejon
Date: Sun Jun 28 09:21:26 2009
New Revision: 39

Log:
cleaning up some code separation

Modified:
   makerelease/downloader.php
   makerelease/makerelease.php

Modified: makerelease/downloader.php
==============================================================================
--- makerelease/downloader.php	Sun Jun 28 09:10:42 2009	(r38)
+++ makerelease/downloader.php	Sun Jun 28 09:21:26 2009	(r39)
@@ -92,264 +92,4 @@
 	
 }
 
-class HTMLPreviewBuilder extends opsysDependendEntity {
-	private $images;
-	private $logger;
-	private $destinationPath;
-	private $thumbsProPage=50;
-	private $currentPageIndex=0;
-	private $numPages=0;
-	private $templateLines=array();
-	private $version;
-	private $pagesLinked;
-	
-	public function __construct(logger $logger, $version) {
-		$this->images=array();
-		$this->logger=$logger;
-		$this->version=$version;
-		$this->checkOpsys();		
-	}
-	
-	public function addImage($filepath) {
-		$this->images[]=$filepath;
-	}
-	
-	private function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false)
-	{// source: http://de3.php.net/copy#89299
-	    // A function to copy files from one directory to another one, including subdirectories and
-	    // nonexisting or newer files. Function returns number of files copied.
-	    // This function is PHP implementation of Windows xcopy  A:\dir1\* B:\dir2 /D /E /F /H /R /Y
-	    // Syntaxis: [$returnstring =] dircopy($sourcedirectory, $destinationdirectory [, $offset] [, $verbose]);
-	    // Example: $num = dircopy('A:\dir1', 'B:\dir2', 1);
-	
-	    // Original by SkyEye.  Remake by AngelKiha.
-	    // Linux compatibility by marajax.
-	    // ([danbrown AT php DOT net): *NIX-compatibility noted by Belandi.]
-	    // Offset count added for the possibilty that it somehow miscounts your files.  This is NOT required.
-	    // Remake returns an explodable string with comma differentiables, in the order of:
-	    // Number copied files, Number of files which failed to copy, Total size (in bytes) of the copied files,
-	    // and the files which fail to copy.  Example: 5,2,150000,\SOMEPATH\SOMEFILE.EXT|\SOMEPATH\SOMEOTHERFILE.EXT
-	    // If you feel adventurous, or have an error reporting system that can log the failed copy files, they can be
-	    // exploded using the | differentiable, after exploding the result string.
-	    //
-	    if(!isset($offset)) $offset=0;
-	    $num = 0;
-	    $fail = 0;
-	    $sizetotal = 0;
-	    $fifail = '';
-	    if(!is_dir($dstdir)) mkdir($dstdir);
-	    if($curdir = opendir($srcdir)) {
-	        while($file = readdir($curdir)) {
-	            if($file != '.' && $file != '..') {
-	//                $srcfile = $srcdir . '\\' . $file;    # deleted by marajax
-	//                $dstfile = $dstdir . '\\' . $file;    # deleted by marajax
-	                $srcfile = $srcdir . '/' . $file;    # added by marajax
-	                $dstfile = $dstdir . '/' . $file;    # added by marajax
-	                if(is_file($srcfile)) {
-	                    if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1;
-	                    if($ow > 0) {
-	                        if($verbose) echo "Copying '$srcfile' to '$dstfile'...<br />";
-	                        if(copy($srcfile, $dstfile)) {
-	                            touch($dstfile, filemtime($srcfile)); $num++;
-	                            chmod($dstfile, 0777);    # added by marajax
-	                            $sizetotal = ($sizetotal + filesize($dstfile));
-	                            if($verbose) echo "OK\n";
-	                        }
-	                        else {
-	                            echo "Error: File '$srcfile' could not be copied!<br />\n";
-	                            $fail++;
-	                            $fifail = $fifail.$srcfile.'|';
-	                        }
-	                    }
-	                }
-	                else if(is_dir($srcfile)) {
-	                    $res = explode(',',$ret);
-	//                    $ret = dircopy($srcfile, $dstfile, $verbose); # deleted by patrick
-	                    $ret = $this->dir_copy($srcfile, $dstfile, $verbose); # added by patrick
-	                    $mod = explode(',',$ret);
-	                    $imp = array($res[0] + $mod[0],$mod[1] + $res[1],$mod[2] + $res[2],$mod[3].$res[3]);
-	                    $ret = implode(',',$imp);
-	                }
-	            }
-	        }
-	        closedir($curdir);
-	    }
-	    $red = explode(',',$ret);
-	    $ret = ($num + $red[0]).','.(($fail-$offset) + $red[1]).','.($sizetotal + $red[2]).','.$fifail.$red[3];
-	    return $ret;
-	} 
-	
-	private function copyTemplateFiles() {
-		$this->dir_copy("template",$this->destinationPath);		
-	}
-	
-	private function getFilenameForIndex($idx) {
-		$filenameSuffix="_".$idx;
-		if ($idx==1) {
-			$filenameSuffix="";
-		}
-		return "index".$filenameSuffix.".html";
-	}
-
-	private function calculateLink($fromWhere, $distance, $ascending) {
-		$target=null;
-		if ($fromWhere%$distance==0) {
-			if ($ascending) {
-				$target=$fromWhere+$distance;
-			} else {
-				$target=$fromWhere-$distance;	
-			}
-				
-		} else {
-			if ($ascending) {
-				$target=ceil($fromWhere/$distance)*$distance;
-			} else {
-				$target=floor($fromWhere/$distance)*$distance;
-			}
-			
-		}
-		return $target;
-		
-	}
-	/**
-	 * will return 1 for OK, 0 for try again and -1 for not ok
-	 * */
-	private function checkAndInsertLink($toWhere) {
-		$possible=($toWhere>0)&&($toWhere<=$this->numPages);
-		if (!$possible) {
-			return -1;			
-		} else if (in_array($toWhere, $this->pagesLinked)) {
-			return 0;
-		} else {
-			$this->pagesLinked[]=$toWhere;
-			return 1;
-		}
-	}
-	
-	private function linkFarAway($distance, $ascending) {
-		//can only link to e.g. the last 10 if page number >10
-
-		$target=$this->calculateLink($this->currentPageIndex, $distance, $ascending);
-		$successful=$this->checkAndInsertLink($target);
-		while ($successful===0) {
-			// was already there
-			if ($ascending) {
-				$target+=$distance;
-			} else {
-				$target-=$distance;
-				
-			}
-			$successful=$this->checkAndInsertLink($target);
-		} 
-		
-		
-	}
-	/**
-	 * Copies the dependencies (.css, .js, .jpg files) to the directory specified
-	 * in $path and generates the index .html file and the .html files for all pages
-	 * */
-	public function writeHTML($path) {
-		$this->destinationPath=$path;
-		$this->logger->shoutNewStatus("Generating HTML");
-		$this->copyTemplateFiles();
-		$this->templateLines=file("template".$this->opsysDirSep."index.html");
-		unlink($path.$this->opsysDirSep."index.html");
-		$this->numPages	=ceil(count($this->images)/$this->thumbsProPage);
-		for($pageStartIndex=0; $pageStartIndex<count($this->images); $pageStartIndex+=$this->thumbsProPage) {
-			$this->currentPageIndex++;
-			
-			$f=fopen($path.$this->opsysDirSep.$this->getFilenameForIndex($this->currentPageIndex), "w");
-			
-			$contentHTML="";
-			for ($thumbIndex=$pageStartIndex; (($thumbIndex<count($this->images))&&($thumbIndex<$pageStartIndex+$this->thumbsProPage));$thumbIndex++) {
-				$image=$this->images[$thumbIndex];
-				$svgFile=substr($image,strlen($path));
-				$svgFile=str_replace($this->opsysDirSep,"/",$svgFile);
-				$dirParts=explode($this->opsysDirSep,$image);
-				$artist="undefined";
-				$artistDisplayName=$artist;
-				$title="undefined";
-				if (count($dirParts)>2) {
-					// the lower most directory name is also the name of the artist
-					$artist=$dirParts[count($dirParts)-2];
-					$artistDisplayName=str_replace("_"," ",$artist);
-					
-				}
-				if (count($dirParts)>1) {
-					// the lower most directory name is also the name of the artist
-					$title=substr($dirParts[count($dirParts)-1], strlen($artist)+1);
-					$title=str_replace("_"," ", $title);
-					$title=substr($title,0,strrpos($title, "."));
-					
-				}
-				$pngFile=str_replace(".svg",".png",$svgFile);
-				$contentHTML.="		
-				<div class='r-img'>
-					<div>
-						<a href='$svgFile' title='$title'><img src='$pngFile' alt='#'></a>
-					</div>
-					<h4><a href='$svgFile'>$title</a></h4>
-					<p>by <a href='http://openclipart.org/media/people/$artist'>$artistDisplayName</a></p>
-				</div> \n";
-			}
-			// page navi: e.g. for page 136 we want links like
-			// 1 100 130 134 135 *136* 137 138 140 200 236
-			// means: the current page is always visible w/o link
-			// if the page>1 insert link to page one
-			// if the page>2 insert link to previous page as well
-			// if the page>3 insert link to pre-previous page as well
-			
-			// if the page>50, insert link to last 50er (floor(page/50))*50 and, if available, to the next 50er
-			// if the page%100>0 insert link to last 10er (floor(page%100/10))*10 and, if available, to the next 10er
-
-			// if the page<last page insert link to last page
-			
-			$this->pagesLinked=array();
-			// first: link first, last, next 2 and previous 2 pages
-			$this->checkAndInsertLink(1);
-			$this->checkAndInsertLink($this->numPages);
-			$this->checkAndInsertLink($this->currentPageIndex);
-			$this->checkAndInsertLink($this->currentPageIndex-1);
-			$this->checkAndInsertLink($this->currentPageIndex-2);
-			$this->checkAndInsertLink($this->currentPageIndex+1);
-			$this->checkAndInsertLink($this->currentPageIndex+2);
-			
-			// now find out what to do with 10ers and 50ers, and keep in mind 
-			// next 10er or 50er page might already be linked via the "next two"
-			// pages e.g. on pg 48 (49,50...)
-
-			// link to next 50er have lower priority than to next 10er, i.e. on 99 link to 100 (10) and 150 
-			$this->linkFarAway(10,false); 			
-			$this->linkFarAway(10,true); 			
-			$this->linkFarAway(50,false); 			
-			$this->linkFarAway(50,true); 			
-			
-			
-			$pageNavi="";
-			sort($this->pagesLinked);
-			foreach ($this->pagesLinked as $pageLink) {
-				$prefix="<li><a href='".$this->getFilenameForIndex($pageLink)."'>";
-				$suffix="</a></li>";
-				if ($pageLink==$this->currentPageIndex) {
-					$prefix="<li id='active'>";
-					$suffix="</li>";
-				}
-				$pageNavi.=$prefix.$pageLink.$suffix;
-			}
-			
-			foreach ($this->templateLines as $indexLine) {
-				$indexLine=str_replace("[title]","OpenClipart $this->version",$indexLine);
-				$indexLine=str_replace("[subtitle]","Page {$this->currentPageIndex} of {$this->numPages}",$indexLine);
-				$indexLine=str_replace("[pages]",$pageNavi,$indexLine);
-				$indexLine=str_replace("[thumbnails]",$contentHTML,$indexLine);
-				fwrite($f, $indexLine);
-			}
-		}
-		
-		
-		
-		fclose($f);
-	}
-}
-
 ?>

Modified: makerelease/makerelease.php
==============================================================================
--- makerelease/makerelease.php	Sun Jun 28 09:10:42 2009	(r38)
+++ makerelease/makerelease.php	Sun Jun 28 09:21:26 2009	(r39)
@@ -174,6 +174,7 @@
 
 include_once 'downloader.php';
 include_once 'releaser.php';
+include_once 'HTMLPreviewBuilder.php';
 
 
 $rel = new releaser();



More information about the clipart mailing list