示例#1
0
 function SmallImage($Source, $Attributes = array())
 {
     if (function_exists('Debug') && Debug()) {
         trigger_error('SmallImage() is deprecated. Use Thumbnail().', E_USER_DEPRECATED);
     }
     $Width = ArrayValue('width', $Attributes, '');
     $Height = ArrayValue('height', $Attributes, '');
     $ImageQuality = GetValue('ImageQuality', $Attributes, 100, True);
     $Crop = GetValue('Crop', $Attributes, False, True);
     $Hash = Crc32Value($Source, array($Width, $Height, $ImageQuality, $Crop));
     $TargetFolder = 'uploads/cached';
     // cache directory
     if (!is_dir($TargetFolder)) {
         mkdir($TargetFolder, 0777, True);
     }
     $Filename = pathinfo($Source, 8);
     $Extension = pathinfo($Source, 4);
     $SmallImage = GenerateCleanTargetName($TargetFolder, $Filename . '-' . $Hash, $Extension, False, True);
     if (!file_exists($SmallImage)) {
         Gdn_UploadImage::SaveImageAs($Source, $SmallImage, $Height, $Width, $Crop);
     }
     if (GetValue('MakeOnly', $Attributes, False, True)) {
         if (GetValue('OutOriginalImageSize', $Attributes, False, True)) {
             // TEMP, TODO: FIX ME
             $Return = array();
             $Return['ImageSize'] = getimagesize($Source);
             $Return['Result'] = Url($SmallImage);
             return $Return;
         }
         return Url($SmallImage);
     }
     TouchValue('alt', $Attributes, $Filename);
     // Fail. ImageSY expects parameter 1 to be resource
     //if (!array_key_exists('height', $Attributes)) TouchValue('height', $Attributes, ImageSY($SmallImage));
     //if (!array_key_exists('width', $Attributes)) TouchValue('width', $Attributes, ImageSX($SmallImage));
     return Img($SmallImage, $Attributes);
 }
示例#2
0
 function UploadFile($TargetFolder, $InputName, $Options = False)
 {
     /*		if (is_array($InputName)) {
     			$Options = $InputName;
     			$InputName = $TargetFolder;
     		}*/
     $FileName = ArrayValue('name', ArrayValue($InputName, $_FILES));
     if ($FileName == '') {
         return;
     }
     // no upload, return null
     // options
     $AllowFileExtension = ArrayValue('AllowFileExtension', $Options);
     // TODO: $Overwrite is not used yet
     $CanOverwrite = ArrayValue('Overwrite', $Options, False);
     $CreateTargetFolder = ArrayValue('CreateTargetFolder', $Options, True);
     $WebTarget = ArrayValue('WebTarget', $Options);
     if ($CreateTargetFolder === True) {
         if (!file_exists($TargetFolder)) {
             mkdir($TargetFolder, 0777, True);
         }
         if (!is_writable($TargetFolder)) {
             throw new Exception(sprintf('Directory (%s) is not writable.', $TargetFolder));
         }
     }
     $Upload = new Gdn_Upload();
     if ($AllowFileExtension != False) {
         if (!is_array($AllowFileExtension)) {
             $AllowFileExtension = SplitString($AllowFileExtension);
         }
         foreach ($AllowFileExtension as $Extension) {
             $Upload->AllowFileExtension($Extension);
         }
     }
     $IsMultipleUpload = is_array($FileName);
     $Count = $IsMultipleUpload ? count($FileName) : 1;
     $OriginalFiles = $_FILES;
     $Result = array();
     for ($i = 0; $i < $Count; $i++) {
         if ($IsMultipleUpload != False) {
             $_FILES[$InputName] = array();
             foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $Key) {
                 $Value = GetValueR($InputName . '.' . $Key . '.' . $i, $OriginalFiles);
                 SetValue($Key, $_FILES[$InputName], $Value);
             }
         } else {
             $FileName = array($FileName);
         }
         $TempFile = $Upload->ValidateUpload($InputName);
         $TargetFile = GenerateCleanTargetName($TargetFolder, $FileName[$i], '', $TempFile, $CanOverwrite);
         // 2.0.18 screwed Gdn_Upload::SaveAs()
         //$Upload->SaveAs($TempFile, $TargetFile);
         if (!move_uploaded_file($TempFile, $TargetFile)) {
             throw new Exception(sprintf(T('Failed to move uploaded file to target destination (%s).'), $TargetFile));
         }
         if ($WebTarget != False) {
             $File = str_replace(DS, '/', $TargetFile);
         } elseif (array_key_exists('WithTargetFolder', $Options)) {
             $File = $TargetFile;
         } else {
             $File = pathinfo($TargetFile, PATHINFO_BASENAME);
         }
         $Result[] = $File;
     }
     $_FILES = $OriginalFiles;
     if ($IsMultipleUpload) {
         return $Result;
     }
     return $File;
 }
 function FancyZoomImage($Source, $Attributes = array())
 {
     // defaults
     if (!is_array($Attributes)) {
         $Attributes = array();
     }
     $NoHiding = GetValue('NoHiding', $Attributes, '', True);
     $bSaveImage = False;
     $Hash = Crc32Value($Source, $Attributes);
     $Filename = pathinfo($Source, PATHINFO_FILENAME);
     $Extension = pathinfo($Source, PATHINFO_EXTENSION);
     if (!array_key_exists('SmallImage', $Attributes)) {
         // make directory
         $TargetFolder = 'uploads/cached';
         // cache directory
         if (!is_dir($TargetFolder)) {
             mkdir($TargetFolder, 0777, True);
         }
         $SmallImage = GenerateCleanTargetName($TargetFolder, $Filename . '-' . $Hash, $Extension, False, True);
         $Attributes['SmallImage'] = $SmallImage;
         if (!file_exists($SmallImage)) {
             $bSaveImage = True;
         }
     }
     // get attributes
     $Width = ArrayValue('width', $Attributes, '');
     $Height = ArrayValue('height', $Attributes, '');
     $Crop = GetValue('Crop', $Attributes, False, True);
     $SmallImage = GetValue('SmallImage', $Attributes, '', True);
     $ZoomAttributes = array('id' => 'p' . $Hash);
     if (!$NoHiding) {
         $ZoomAttributes['style'] = 'display:none';
     }
     //if (!array_key_exists('alt', $Attributes)) $Attributes['alt'] = $Filename;
     TouchValue('alt', $Attributes, $Filename);
     if ($bSaveImage) {
         Gdn_UploadImage::SaveImageAs($Source, $SmallImage, $Height, $Width, $Crop);
     }
     $SmallImage = Img($SmallImage, $Attributes);
     $ZoomImage = Img($Source, array('alt' => ArrayValue('alt', $Attributes, '')));
     return "\n" . Wrap($SmallImage, 'a', array('href' => '#p' . $Hash)) . Wrap($ZoomImage, 'div', $ZoomAttributes);
 }
 public function RetrieveAttachments()
 {
     $Parts = $this->Mailbox->IMAP2->getParts($this->Number, '0', True, array('retrieve_all' => True));
     $InlineParts = @$Parts['in']['ftype'];
     $AttachmentsParts = @$Parts['at']['ftype'];
     $Parts = array_merge((array) $InlineParts, (array) $AttachmentsParts);
     if (Count($Parts) == 0) {
         return False;
     }
     $Mimes = array();
     foreach ($Parts as $MimeType) {
         if (preg_match('#^(application|image|video)/#', $MimeType)) {
             $Mimes[] = $MimeType;
         }
     }
     $Pids = $this->Mailbox->IMAP2->extractMIME($this->Number, array_unique($Mimes));
     if (!$Pids) {
         return False;
     }
     $TempFolder = realpath(sys_get_temp_dir());
     foreach ($Pids as $Pid) {
         $Body = $this->Mailbox->IMAP2->getBody($this->Number, $Pid);
         $Dummy = new StdClass();
         $Dummy->MimeType = $Body['ftype'];
         $Dummy->FileName = self::DecodeMimeString($Body['fname']);
         $Dummy->TempFilePath = GenerateCleanTargetName($TempFolder, $Dummy->FileName);
         file_put_contents($Dummy->TempFilePath, $Body['message']);
         $this->Attachs[] = $Dummy;
     }
     return $this;
 }