DirPath = $DirPath; $this->AlbumId = $DirId; $this->SectionId = $DirId; $this->DirTitle = $DirTitle; $this->ParentId = $DirId; $this->SessionId = $SessionId; #print_r($this); $this->ScanDir($SessionId,$DirPath,$Title,0,0,0); } public function ScanDir($SessionId,$DirPath,$Title,$Level,$Year,$Month) { if ($DirTitle) { $this->DirTitle = $DirTitle; } else { $this->DirTitle = basename($this->DirPath); } foreach(new DirectoryIterator($this->DirPath) as $file) { if (!$file->isDot()) { if ($file->isDir()) { $this->Timeless = 1; $newdir = $file->getPathname(); $filename = $file->getFilename(); echo "Level: $Level Filename: $filename Newdir $newdir\n"; $this->Timeless = 0; if ($Level == 0 && eregi("([1-2][0-9]{3})",$filename)) { echo "Found a year directory for newdir $filename\n"; $this->Timeless = 1; $Year = $this->Year = $filename; } if ($Level == 1) { $MonthTest = $this->getDateString($filename); if ($MonthTest != $filename) { $this->Timeless = 0; $this->Year = $Year; $Month = $this->Month = $MonthTest; } else { $this->Timeless = 2; } echo "Found a month Dir : $this->Month $filename\n"; } echo "Creating a Subdir for $newdir $Year and $Month\n"; $this->CreateSubDir($SessionId,$newdir,$Level,$Year,$Month); $SubDir = $this->$newdir; $SubDir->ScanDir($SessionId,$DirPath,'',$Level+1,$Year,$Month); } else { $this->Files[] = $file->getPathname(); # Check to see if it is a PhotoCD File $pathParts = pathinfo($file->getPathname()); if (stristr($pathParts['extension'],'pcd')) { $filename = $pathParts['filename']; echo "Converting $file->getFilename() PhotoCD to Large JPEG\n"; exec('convert -size 2048x2048 '.$file->getPathname().' /tmp/'.$filename.'.jpg'); $DirPath = "/tmp/".$filename.'.jpg'; echo "Temporary filename: $DirPath\n"; $params = array( 'method' => "Image.newImage", 'api_key' => "Lq62JmEpChazlehbw9Ty", 'session_id' => $SessionId, 'album_id' => $this->AlbumId, 'section_id' => $this->SectionId, 'filename' => $filename.'jpg' ); } if (stristr($pathParts['extension'],'avi')) { $params = array( 'method' => "Image.newImage", 'api_key' => "Lq62JmEpChazlehbw9Ty", 'session_id' => $SessionId, 'album_id' => $this->AlbumId, 'section_id' => $this->SectionId, 'filename' => $file->getFilename(), 'is_video' => 1 ); $DirPath = $file->getPathname(); } if (stristr($pathParts['extension'],'jpg')) { # If it's s straight JPEG - use this $params = array( 'method' => "Image.newImage", 'api_key' => "Lq62JmEpChazlehbw9Ty", 'session_id' => $SessionId, 'album_id' => $this->AlbumId, 'section_id' => $this->SectionId, 'filename' => $file->getFilename() ); #print_r($params); $DirPath = $file->getPathname(); } $xml = $this->upload_api($params,$DirPath); if ($filename) exec ('rm /tmp/'.$filename.'.jpg'); } } } } public function getDateString($MonthTest) { $aMonth = array( "jan"=>"01", "feb"=>"02", "mar"=>"03", "apr"=>"04", "may"=>"05", "jun"=>"06", "jul"=>"07", "aug"=>"08", "sep"=>"09", "oct"=>"10", "nov"=>"11", "dec"=>"12"); $Trunc = strtolower(substr($MonthTest,0,3)); $MonthNum = strtr($Trunc,$aMonth); if (strlen($Trunc) == strlen($MonthNum)) { return ($MonthTest); } else { return ($MonthNum); } } public function CreateSubdir($SessionId,$DirPath,$Level,$Year,$Month) { $this->SubDirs[] = $DirPath; $this->$DirPath = new PhanObj(); $this->Year = $Year; $this->Month = $Month; $this->$DirPath->ParentId = $this->AlbumId; $this->$DirPath->DirPath = $DirPath; $trans = array("_" => " ", "___" => " & ", "-" => "'"); $Title = strtr(basename($DirPath),$trans); echo "Level: $Level\n"; $dateString = $this->getDateString($DirPath); if($Level==0 || ($this->Timeless==0 && $Level==1)) { $SectionFlag = 0; echo "Making an Album for $DirPath\n"; if ($Year!=0) { $DateStart = $Year."-".$Month."-01"; $DateEnd = $Year."-".$Month."-28"; } else { $DateStart = "1950-01-01"; $DateEnd = "1950-01-31"; } $params = array( 'method' => "Album.newAlbum", 'api_key' => "Lq62JmEpChazlehbw9Ty", 'session_id' => $SessionId, 'album_name' => $Title, 'album_start_date' => $DateStart, 'album_end_date' => $DateEnd ); } else { $SectionFlag = 1; echo "Making a Section for $DirPath Level: $Level Album ID: $this->AlbumId\n"; $params = array( 'method' => "Album.newSection", 'api_key' => "Lq62JmEpChazlehbw9Ty", 'session_id' => $SessionId, 'album_id' => $this->AlbumId, 'section_name' => $Title); } # print_r($params); if ($this->Timeless != 1) { $xml = query_api($params); if (parse_xml($xml, $vals, $index)) { # print_r($index); # print_r($vals); $AlbumId = $vals[$index['ALBUM'][0]]['attributes']['ALBUM_ID']; $SectionId = $vals[$index['SECTION'][0]]['attributes']['SECTION_ID']; echo "\nGot a album ID: $AlbumId section ID: $SectionId\n"; } else { die ("Failed to get a Album ID, can not continue\n"); } if ($SectionFlag==0) { $this->$DirPath->AlbumId = $AlbumId; } else { $this->$DirPath->AlbumId = $this->$DirPath->ParentId; } $this->$DirPath->SectionId = $SectionId; } } public function query_api($params) { $base = 'http://api.phanfare.com/rest/?'; $query_string = ''; foreach ($params as $key => $value) { $base .= "$key=" . urlencode($value) . "&"; } $base = substr($base,0,-1); $url = "$base"; $xml = file_get_contents($url); return ($xml); } public function upload_api($params,$DirPath) { $base = 'http://api.phanfare.com/upload/?'; foreach ($params as $key => $value) { $base .= "$key=" . urlencode($value) . "&"; } $base = substr($base,0,-1); $url = $base; $file_contents = file_get_contents($DirPath); echo "uploading data to this URL: $url\n"; $r = new HttpRequest($url, HttpRequest::METH_POST); $headers = array('Content-Type' => 'multipart/form-data'); $r->setHeaders($headers); $r->setBody($file_contents); try { $xml = ($r->send()->getBody()); } catch (HttpException $ex) { #$xml = $ex; } return ($xml); } } ?>