CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

SPTImage.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: SPTImage.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2002-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
13 class SPTImage
14 {
15
16 # ---- PUBLIC INTERFACE --------------------------------------------------
17
19 const CACHE_PATH = "local/data/caches/ImageLinks";
20
21 const SIZE_FULL = 3;
22 const SIZE_PREVIEW = 2;
23 const SIZE_THUMBNAIL = 1;
24
37 public function __construct($ImageIdOrFileNameOrImageObj,
38 $MaxWidth = NULL, $MaxHeight = NULL,
39 $MaxPreviewWidth = NULL, $MaxPreviewHeight = NULL,
40 $MaxThumbnailWidth = NULL, $MaxThumbnailHeight = NULL)
41 {
42 # clear error status (0 = AI_OKAY)
43 $this->ErrorStatus = 0;
44
45 # trigger the Image class file to be autoloaded since some parts of this
46 # class (SPTImage) use constants defined in it but don't construct Image
47 # objects
48 new Image(NULL);
49
50 # create and save a database handle for our use
51 $this->DB = new Database();
52
53 # if image object was passed in
54 if (is_object($ImageIdOrFileNameOrImageObj)
55 && method_exists($ImageIdOrFileNameOrImageObj, "SPTImage"))
56 {
57 # create copy of image passed in
58 $this->CreateCopyOfImage($ImageIdOrFileNameOrImageObj);
59 }
60 # else if image ID was passed in
61 elseif (($ImageIdOrFileNameOrImageObj > 0)
62 && preg_match("/[0-9]+/", $ImageIdOrFileNameOrImageObj))
63 {
64 # load info on existing image
65 $this->LoadImageInfo($ImageIdOrFileNameOrImageObj);
66 }
67 # else assume that value passed in is file name
68 else
69 {
70 # create new image from named file
71 $this->CreateNewImage($ImageIdOrFileNameOrImageObj,
72 $MaxWidth, $MaxHeight,
73 $MaxPreviewWidth, $MaxPreviewHeight,
74 $MaxThumbnailWidth, $MaxThumbnailHeight);
75 }
76 }
77
82 public function Id()
83 {
84 return $this->Id;
85 }
86
91 public function Url()
92 {
93 $Url = $this->FileName;
94 $SignalResult = $GLOBALS["AF"]->SignalEvent(
95 "EVENT_IMAGE_URL_FILTER", array(
96 "Url" => $Url,
97 "ImageSize" => "Full"));
98 $Url = $SignalResult["Url"];
99 return $Url;
100 }
101
106 public function PreviewUrl()
107 {
108 $Url = $this->PreviewFileName;
109 $SignalResult = $GLOBALS["AF"]->SignalEvent(
110 "EVENT_IMAGE_URL_FILTER", array(
111 "Url" => $Url,
112 "ImageSize" => "Preview"));
113 $Url = $SignalResult["Url"];
114 return $Url;
115 }
116
121 public function ThumbnailUrl()
122 {
123 $Url = $this->ThumbnailFileName;
124 $SignalResult = $GLOBALS["AF"]->SignalEvent(
125 "EVENT_IMAGE_URL_FILTER", array(
126 "Url" => $Url,
127 "ImageSize" => "Thumbnail"));
128 $Url = $SignalResult["Url"];
129 return $Url;
130 }
131
137 public function Format()
138 {
139 return $this->Format;
140 }
141
146 public function Mimetype()
147 {
148 $Image = new Image($this->FileName);
149 return $Image->Mimetype();
150 }
151
156 public function Height()
157 {
158 return $this->Height;
159 }
160
165 public function Width()
166 {
167 return $this->Width;
168 }
169
174 public function PreviewHeight()
175 {
176 return $this->PreviewHeight;
177 }
178
183 public function PreviewWidth()
184 {
185 return $this->PreviewWidth;
186 }
187
192 public function ThumbnailHeight()
193 {
194 return $this->ThumbnailHeight;
195 }
196
201 public function ThumbnailWidth()
202 {
203 return $this->ThumbnailWidth;
204 }
205
210 public static function ImageStorageDirectory()
211 {
212 # for each possible storage location
213 foreach (self::$ImageStorageLocations as $Dir)
214 {
215 # if location exists
216 if (is_dir($Dir))
217 {
218 # return location to caller
219 return $Dir;
220 }
221 }
222
223 # return default (most preferred) location to caller
224 return self::$ImageStorageLocations[0];
225 }
226
231 public static function PreviewStorageDirectory()
232 {
233 # for each possible storage location
234 foreach (self::$PreviewStorageLocations as $Dir)
235 {
236 # if location exists
237 if (is_dir($Dir))
238 {
239 # return location to caller
240 return $Dir;
241 }
242 }
243
244 # return default (most preferred) location to caller
245 return self::$PreviewStorageLocations[0];
246 }
247
252 public static function ThumbnailStorageDirectory()
253 {
254 # for each possible storage location
255 foreach (self::$ThumbnailStorageLocations as $Dir)
256 {
257 # if location exists
258 if (is_dir($Dir))
259 {
260 # return location to caller
261 return $Dir;
262 }
263 }
264
265 # return default (most preferred) location to caller
266 return self::$ThumbnailStorageLocations[0];
267 }
268
273 public function GetLink()
274 {
275 return $this->FileName;
276 }
277
284 public function AltText($NewValue = NULL)
285 {
286 # if new value supplied and new value differs from existing value
287 if (($NewValue !== NULL) && ($NewValue != $this->AltText))
288 {
289 # save new value to database
290 $this->DB->Query("UPDATE Images SET"
291 ." AltText = '".addslashes($NewValue)."'"
292 ." WHERE ImageId = ".$this->Id);
293
294 # save new value locally
295 $this->AltText = $NewValue;
296 }
297
298 # return attribute value to caller
299 return $this->AltText;
300 }
301
307 public function LinkTarget($NewValue = NULL)
308 {
309 if (($NewValue !== NULL) && ($NewValue != $this->LinkTarget))
310 {
311 $this->DB->Query("UPDATE Images SET"
312 ." LinkTarget = '".addslashes($NewValue)."'"
313 ." WHERE ImageId = ".$this->Id);
314 $this->LinkTarget = $NewValue;
315 }
316
317 return $this->LinkTarget;
318 }
319
324 public function Delete()
325 {
326 # delete base image file
327 if (file_exists($this->FileName)) { unlink($this->FileName); }
328
329 # delete preview image file
330 if (file_exists($this->PreviewFileName)) { unlink($this->PreviewFileName); }
331
332 # delete thumbnail image file
333 if (file_exists($this->ThumbnailFileName)) { unlink($this->ThumbnailFileName); }
334
335 # delete image info record in database
336 $this->DB->Query("DELETE FROM Images WHERE ImageId = ".$this->Id);
337 }
338
343 public function Status()
344 {
345 return $this->ErrorStatus;
346 }
347
353 public static function CheckDirectories()
354 {
355 # determine paths
356 $ImagePath = self::ImageStorageDirectory();
357 $PreviewPath = self::PreviewStorageDirectory();
358 $ThumbnailPath = self::ThumbnailStorageDirectory();
359
360 # assume everything will be okay
361 $ErrorsFound = NULL;
362
363 # check base image directory
364 if (!is_dir($ImagePath) || !is_writable($ImagePath))
365 {
366 if (!is_dir($ImagePath))
367 {
368 @mkdir($ImagePath, 0755);
369 }
370 else
371 {
372 @chmod($ImagePath, 0755);
373 }
374 if (!is_dir($ImagePath))
375 {
376 $ErrorsFound[] = "Image Storage Directory Not Found";
377 }
378 elseif (!is_writable($ImagePath))
379 {
380 $ErrorsFound[] = "Image Storage Directory Not Writable";
381 }
382 }
383
384 # check preview directory
385 if (!is_dir($PreviewPath) || !is_writable($PreviewPath))
386 {
387 if (!is_dir($PreviewPath))
388 {
389 @mkdir($PreviewPath, 0755);
390 }
391 else
392 {
393 @chmod($PreviewPath, 0755);
394 }
395 if (!is_dir($PreviewPath))
396 {
397 $ErrorsFound[] = "Preview Storage Directory Not Found";
398 }
399 elseif (!is_writable($PreviewPath))
400 {
401 $ErrorsFound[] = "Preview Storage Directory Not Writable";
402 }
403 }
404
405 # check thumbnail directory
406 if (!is_dir($ThumbnailPath) || !is_writable($ThumbnailPath))
407 {
408 if (!is_dir($ThumbnailPath))
409 {
410 @mkdir($ThumbnailPath, 0755);
411 }
412 else
413 {
414 @chmod($ThumbnailPath, 0755);
415 }
416 if (!is_dir($ThumbnailPath))
417 {
418 $ErrorsFound[] = "Thumbnail Storage Directory Not Found";
419 }
420 elseif (!is_writable($ThumbnailPath))
421 {
422 $ErrorsFound[] = "Thumbnail Storage Directory Not Writable";
423 }
424 }
425
426 # return any errors found to caller
427 return $ErrorsFound;
428 }
429
440 public function Resize($MaxWidth, $MaxHeight,
441 $MaxPreviewWidth, $MaxPreviewHeight,
442 $MaxThumbnailWidth, $MaxThumbnailHeight)
443 {
444 $SrcImage = new Image($this->FileName);
445
446 # scale the original image if necessary
447 $MaxWidth = min($MaxWidth, $SrcImage->XSize());
448 $MaxHeight = min($MaxHeight, $SrcImage->YSize());
449 $SrcImage->ScaleTo($MaxWidth, $MaxHeight, TRUE);
450
451 # save and reload image info
452 $SrcImage->SaveAs($this->FileName);
453 $SrcImage = new Image($this->FileName);
454
455 # retrieve image width and height
456 $this->Height = $SrcImage->YSize();
457 $this->Width = $SrcImage->XSize();
458
459 # generate preview image and calculate width and height
460 $MaxPreviewWidth = min($MaxPreviewWidth, $this->Width);
461 $MaxPreviewHeight = min($MaxPreviewHeight, $this->Height);
462 $SrcImage->ScaleTo($MaxPreviewWidth, $MaxPreviewHeight, TRUE);
463 $SrcImage->SaveAs($this->PreviewFileName);
464 if (($this->Width * $MaxPreviewHeight)
465 > ($this->Height * $MaxPreviewWidth))
466 {
467 $this->PreviewWidth = $MaxPreviewWidth;
468 $this->PreviewHeight =
469 ($MaxPreviewWidth * $SrcImage->YSize()) / $SrcImage->XSize();
470 }
471 else
472 {
473 $this->PreviewWidth =
474 ($MaxPreviewHeight * $SrcImage->XSize()) / $SrcImage->YSize();
475 $this->PreviewHeight = $MaxPreviewHeight;
476 }
477
478 # generate thumbnail image and calculate width and height
479 $MaxThumbnailWidth = min($MaxThumbnailWidth, $this->Width);
480 $MaxThumbnailHeight = min($MaxThumbnailHeight, $this->Height);
481 $SrcImage->ScaleTo($MaxThumbnailWidth, $MaxThumbnailHeight, TRUE);
482 $SrcImage->SaveAs($this->ThumbnailFileName);
483 if (($this->Width * $MaxThumbnailHeight)
484 > ($this->Height * $MaxThumbnailWidth))
485 {
486 $this->ThumbnailWidth = $MaxThumbnailWidth;
487 $this->ThumbnailHeight =
488 ($MaxThumbnailWidth * $SrcImage->YSize()) / $SrcImage->XSize();
489 }
490 else
491 {
492 $this->ThumbnailWidth =
493 ($MaxThumbnailHeight * $SrcImage->XSize()) / $SrcImage->YSize();
494 $this->ThumbnailHeight = $MaxThumbnailHeight;
495 }
496
497 # save image attributes to database
498 $this->SaveImageInfo();
499 }
500
508 public function GetImageUrlForResource($ResourceId, $FieldId, $Index, $Size)
509 {
510 StdLib::CheckMyCaller(
511 "Resource",
512 "Attempt to get ImageLinks at %FILE%:%LINE%."
513 ." (ImageLinks many only be fetched by Resource.)");
514
515 switch ($Size)
516 {
517 case self::SIZE_FULL:
518 $Suffix = "f";
519 break;
520 case self::SIZE_PREVIEW:
521 $Suffix = "p";
522 break;
523 case self::SIZE_THUMBNAIL:
524 $Suffix = "t";
525 break;
526 default:
527 throw new Exception("Unknown image size requested");
528 }
529
530 $Files = array(
531 "t" => $this->ThumbnailFileName,
532 "p" => $this->PreviewFileName,
533 "f" => $this->FileName);
534
535 # default to returning the path to the file
536 $ReturnValue = $Files[$Suffix];
537
538 # but if we have CleanURL support
539 if ($GLOBALS["AF"]->HtaccessSupport())
540 {
541 # make sure our ImageLinks dir exists
542 if (!is_dir(self::CACHE_PATH))
543 {
544 mkdir(self::CACHE_PATH);
545 }
546
547 # create symlinks for this field if they don't already exist
548 $BaseDir = dirname(__DIR__)."/";
549 foreach ($Files as $FileSuffix => $SrcFile)
550 {
551 $LinkName =
552 implode("_", array($ResourceId, $FieldId, $Index, $FileSuffix))
553 .".".Image::Extension($this->Format());
554
555 if (!file_exists(self::CACHE_PATH."/".$LinkName))
556 {
557 symlink($BaseDir.$SrcFile, self::CACHE_PATH."/".$LinkName);
558 }
559
560 # if this is the requested symlink, generate a url to return
561 if ($Suffix == $FileSuffix)
562 {
563 $ReturnValue = ApplicationFramework::BaseUrl()."viewimage/".$LinkName;
564 }
565 }
566 }
567
568 return $ReturnValue;
569 }
570
576 public static function ClearImageSymlinksForResource($ResourceId, $FieldId)
577 {
578 StdLib::CheckMyCaller(
579 "Resource",
580 "Attempt to delete ImageLinks of a resource at %FILE%:%LINE%."
581 ." (ImageLinks many only be cleared by Resource.)");
582
583 if (!is_dir(self::CACHE_PATH))
584 {
585 return;
586 }
587
588 $Files = glob(self::CACHE_PATH."/".$ResourceId."_".$FieldId."_*");
589 foreach ($Files as $File)
590 {
591 if (file_exists($File) && is_link($File))
592 {
593 unlink($File);
594 }
595 }
596 }
597
601 public static function ClearImageSymlinks()
602 {
603 if (!is_dir(self::CACHE_PATH))
604 {
605 return;
606 }
607
608 foreach (scandir(self::CACHE_PATH) as $Entry)
609 {
610 $Link = self::CACHE_PATH."/".$Entry;
611 if (is_link($Link))
612 {
613 unlink($Link);
614 }
615 }
616 }
617
621 public static function ExpireImageSymlinks()
622 {
623 if (!is_dir(self::CACHE_PATH))
624 {
625 return;
626 }
627
628 foreach (scandir(self::CACHE_PATH) as $Entry)
629 {
630 $Link = self::CACHE_PATH."/".$Entry;
631 if (is_link($Link))
632 {
633 $link_info = lstat($Link);
634
635 if (time() - $link_info['ctime'] > self::$SymlinkExpirationTime)
636 {
637 unlink($Link);
638 }
639 }
640 }
641 }
642
647 public function ResourceId()
648 {
649 $this->LoadResourceAndFieldIds();
650 return $this->ResourceId;
651 }
652
657 public function FieldId()
658 {
659 $this->LoadResourceAndFieldIds();
660 return $this->FieldId;
661 }
662
663
664 # ---- PRIVATE INTERFACE -------------------------------------------------
665
666 private $Id;
667 private $FileName;
668 private $PreviewFileName;
669 private $ThumbnailFileName;
670 private $Format;
671 private $AltText;
672 private $LinkTarget;
673 private $Url;
674 private $PreviewUrl;
675 private $ThumbnailUrl;
676 private $Height;
677 private $Width;
678 private $PreviewHeight;
679 private $PreviewWidth;
680 private $ResourceId;
681 private $FieldId;
682 private $ThumbnailHeight;
683 private $ThumbnailWidth;
684 private $DB;
685 private $ErrorStatus;
686
687 static private $SymlinkExpirationTime = 86400;
688
690 static private $ImageStorageLocations = array(
691 "local/data/images",
692 "ImageStorage",
693 );
694 static private $PreviewStorageLocations = array(
695 "local/data/images/previews",
696 "ImageStorage/Previews",
697 );
698 static private $ThumbnailStorageLocations = array(
699 "local/data/images/thumbnails",
700 "ImageStorage/Thumbnails",
701 );
702
714 private function CreateNewImage($FileName, $MaxWidth, $MaxHeight,
715 $MaxPreviewWidth, $MaxPreviewHeight, $MaxThumbnailWidth, $MaxThumbnailHeight)
716 {
717 # if file does not exist or is not readable
718 $IsReadable = @is_readable($FileName);
719 if ($IsReadable !== TRUE)
720 {
721 # set error status
722 $this->ErrorStatus = AI_FILEUNREADABLE;
723 }
724 else
725 {
726 # if image is invalid or unsupported type
727 $SrcImage = new Image($FileName);
728 $this->Format = $SrcImage->Type();
729 if ($SrcImage->Status() != AI_OKAY)
730 {
731 # set error status
732 $this->ErrorStatus = $SrcImage->Status();
733 }
734 else
735 {
736 # generate new image ID
737 $this->Id = $this->GenerateNewImageId();
738
739 # generate and set file names
740 $this->SetFileNames();
741
742 # if our image file name differs from file name passed in
743 if (realpath($this->FileName) != realpath($FileName))
744 {
745 # create image file
746 $SrcImage->SaveAs($this->FileName);
747
748 # if create failed set error status and bail out
749 if ($SrcImage->Status() != AI_OKAY)
750 {
751 $this->DB->Query("DELETE FROM Images WHERE ImageId = "
752 .intval($this->Id));
753 $this->ErrorStatus = $SrcImage->Status();
754 return;
755 }
756 }
757
758 # scale the original image if necessary
759 $MaxWidth = min($MaxWidth, $SrcImage->XSize());
760 $MaxHeight = min($MaxHeight, $SrcImage->YSize());
761
762 # change the minimum width if the height is the limiting factor
763 if ($SrcImage->YSize() * $MaxWidth / $SrcImage->XSize() > $MaxHeight)
764 {
765 $MaxWidth = round(
766 $SrcImage->XSize() * $MaxHeight / $SrcImage->YSize());
767 }
768
769 # change the minimum height since the width is the limiting factor
770 else
771 {
772 $MaxHeight = round(
773 $SrcImage->YSize() * $MaxWidth / $SrcImage->XSize());
774 }
775
776 # scale the image
777 $SrcImage->ScaleTo($MaxWidth, $MaxHeight, TRUE);
778
779 # save and reload image info
780 $SrcImage->SaveAs($this->FileName);
781 $SrcImage = new Image($this->FileName);
782
783 # retrieve image width and height
784 $this->Height = $SrcImage->YSize();
785 $this->Width = $SrcImage->XSize();
786
787 # create the preview and thumbnail images
788 foreach (array("Preview", "Thumbnail") as $ImageType)
789 {
790 # variable name strings to use in the variable variables below
791 $MaxWidthVar = "Max".$ImageType."Width";
792 $MaxHeightVar = "Max".$ImageType."Height";
793
794 # find the mininum values for the width and height
795 $$MaxWidthVar = min($$MaxWidthVar, $this->Width);
796 $$MaxHeightVar= min($$MaxHeightVar, $this->Height);
797
798 # change the minimum width if the height is the limiting factor
799 if ($this->Height * $$MaxWidthVar / $this->Width > $$MaxHeightVar)
800 {
801 $$MaxWidthVar =
802 round($this->Width * $$MaxHeightVar / $this->Height);
803 }
804
805 # change the minimum height since the width is the limiting factor
806 else
807 {
808 $$MaxHeightVar =
809 round($this->Height * $$MaxWidthVar / $this->Width);
810 }
811
812 # scale the image and save it to a new file
813 $SrcImage->ScaleTo($$MaxWidthVar, $$MaxHeightVar, TRUE);
814 $SrcImage->SaveAs($this->{$ImageType."FileName"});
815
816 # scaling/saving failed
817 if ($SrcImage->Status() != AI_OKAY)
818 {
819 $this->DB->Query("DELETE FROM Images WHERE ImageId = "
820 .intval($this->Id));
821 $this->ErrorStatus = $SrcImage->Status();
822 return;
823 }
824
825 # save the dimensions
826 $this->{$ImageType."Width"} = $$MaxWidthVar;
827 $this->{$ImageType."Height"} = $$MaxHeightVar;
828 }
829
830 # save image attributes to database
831 $this->SaveImageInfo();
832 }
833 }
834 }
835
840 private function LoadImageInfo($ImageId)
841 {
842 # save image ID
843 $this->Id = $ImageId;
844
845 # load image record from database
846 $this->DB->Query("SELECT * FROM Images WHERE ImageId = ".$ImageId);
847
848 # if the ID is invalid
849 if (!$this->DB->NumRowsSelected())
850 {
851 $this->ErrorStatus = AI_INTERNALERROR;
852 return;
853 }
854
855 $Record = $this->DB->FetchRow();
856
857 # load in values from record
858 $this->Format = $Record["Format"];
859 $this->AltText = $Record["AltText"];
860 $this->LinkTarget = $Record["LinkTarget"];
861 $this->Height = $Record["Height"];
862 $this->Width = $Record["Width"];
863 $this->PreviewHeight = $Record["PreviewHeight"];
864 $this->PreviewWidth = $Record["PreviewWidth"];
865 $this->ThumbnailHeight = $Record["ThumbnailHeight"];
866 $this->ThumbnailWidth = $Record["ThumbnailWidth"];
867
868 # generate file names
869 $this->SetFileNames();
870 }
871
876 private function CreateCopyOfImage($SrcImage)
877 {
878 $Image = new Image($SrcImage->Url());
879 if ($Image->Status() != AI_OKAY)
880 {
881 # set error status
882 $this->ErrorStatus = $Image->Status();
883 return;
884 }
885
886 # generate new image ID
887 $this->Id = $this->GenerateNewImageId();
888
889 # generate file names
890 $this->SetFileNames();
891
892 # copy attributes from source image
893 $this->Format = $SrcImage->Format();
894 $this->AltText = $SrcImage->AltText();
895 $this->Width = $SrcImage->Width();
896 $this->Height = $SrcImage->Height();
897 $this->PreviewWidth = $SrcImage->PreviewWidth();
898 $this->PreviewHeight = $SrcImage->PreviewHeight();
899 $this->ThumbnailWidth = $SrcImage->ThumbnailWidth();
900 $this->ThumbnailHeight = $SrcImage->ThumbnailHeight();
901
902 # copy source image files
903 copy($SrcImage->Url(), $this->FileName);
904 copy($SrcImage->PreviewUrl(), $this->PreviewFileName);
905 copy($SrcImage->ThumbnailUrl(), $this->ThumbnailFileName);
906
907 # save image attributes to database
908 $this->SaveImageInfo();
909 }
910
915 private function SetFileNames()
916 {
917 if (Image::Extension($this->Format))
918 {
919 $FileExtension = Image::Extension($this->Format);
920 }
921 else
922 {
923 $FileExtension = "";
924 }
925
926 $this->FileName = $this->DetermineFileName(
927 self::$ImageStorageLocations, "Img--", $FileExtension);
928 $this->PreviewFileName = $this->DetermineFileName(
929 self::$PreviewStorageLocations, "Preview--", $FileExtension);
930 $this->ThumbnailFileName = $this->DetermineFileName(
931 self::$ThumbnailStorageLocations, "Thumb--", $FileExtension);
932 }
933
943 private function DetermineFileName($Locations, $Prefix, $Extension)
944 {
945 # build base name for file
946 $BaseName = $Prefix.sprintf("%08d.", $this->Id).$Extension;
947
948 # for each possible location
949 foreach ($Locations as $Dir)
950 {
951 # build full file name for location
952 $FileName = $Dir."/".$BaseName;
953
954 # if file exists in location return full file name
955 if (file_exists($FileName)) { return $FileName; }
956 }
957
958 # for each possible location
959 foreach ($Locations as $Dir)
960 {
961 # build full file name for location
962 $FileName = $Dir."/".$BaseName;
963
964 # if location is writable return full file name
965 if (is_dir($Dir) && is_writable($Dir)) { return $FileName; }
966 }
967
968 # return full file name for default location
969 return $Locations[0]."/".$BaseName;
970 }
971
976 private function GenerateNewImageId()
977 {
978 # add new entry to database
979 $this->DB->Query("INSERT INTO Images (AltText) VALUES ('')");
980
981 # return ID of inserted image
982 return $this->DB->LastInsertId();
983 }
984
988 private function SaveImageInfo()
989 {
990 # update existing image record
991 $this->DB->Query("UPDATE Images SET"
992 ." Format = '" .$this->Format."',"
993 ." AltText = '" .addslashes($this->AltText)."',"
994 ." Height = '" .$this->Height."',"
995 ." Width = '" .$this->Width."',"
996 ." PreviewHeight = '" .$this->PreviewHeight."',"
997 ." PreviewWidth = '" .$this->PreviewWidth."',"
998 ." ThumbnailHeight = '".$this->ThumbnailHeight."',"
999 ." ThumbnailWidth = '" .$this->ThumbnailWidth."'"
1000 ." WHERE ImageId = ".$this->Id);
1001 }
1002
1006 private function LoadResourceAndFieldIds()
1007 {
1008 if (!isset($this->ResourceId))
1009 {
1010 $this->DB->Query("SELECT ResourceId, FieldId FROM ResourceImageInts"
1011 ." WHERE ImageId = '".addslashes($this->Id)."'");
1012 if ($this->DB->NumRowsSelected())
1013 {
1014 $Row = $this->DB->FetchRow();
1015 $this->ResourceId = $Row["ResourceId"];
1016 $this->FieldId = $Row["FieldId"];
1017 }
1018 else
1019 {
1020 $this->ResourceId = NULL;
1021 $this->FieldId = NULL;
1022 }
1023 }
1024 }
1025 }
SPTImage\SIZE_PREVIEW
const SIZE_PREVIEW
Definition: SPTImage.php:22
SPTImage\Mimetype
Mimetype()
Get the MIME type for the image.
Definition: SPTImage.php:146
SPTImage\__construct
__construct($ImageIdOrFileNameOrImageObj, $MaxWidth=NULL, $MaxHeight=NULL, $MaxPreviewWidth=NULL, $MaxPreviewHeight=NULL, $MaxThumbnailWidth=NULL, $MaxThumbnailHeight=NULL)
Object constructor.
Definition: SPTImage.php:37
SPTImage\LinkTarget
LinkTarget($NewValue=NULL)
Get or set the link target value for the image.
Definition: SPTImage.php:307
StdLib\CheckMyCaller
static CheckMyCaller($DesiredCaller, $ExceptionMsg=NULL)
Check the caller of the current function.
Definition: StdLib.php:69
SPTImage\ThumbnailWidth
ThumbnailWidth()
Get the width of the thumbnail image for this image.
Definition: SPTImage.php:201
ApplicationFramework\BaseUrl
static BaseUrl()
Get current base URL (the part before index.php) (e.g.
Definition: ApplicationFramework.php:3773
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
AI_OKAY
const AI_OKAY
Definition: Image.php:552
SPTImage\Delete
Delete()
Delete the image, that is, remove its record from the database and delete the associated image files ...
Definition: SPTImage.php:324
SPTImage\ResourceId
ResourceId()
Get ID of resource associated with image.
Definition: SPTImage.php:647
SPTImage\PreviewHeight
PreviewHeight()
Get the height of the preview image for this image.
Definition: SPTImage.php:174
SPTImage\FieldId
FieldId()
Get ID of field associated with image.
Definition: SPTImage.php:657
SPTImage\PreviewWidth
PreviewWidth()
Get the width of the preview image for this image.
Definition: SPTImage.php:183
SPTImage\SIZE_THUMBNAIL
const SIZE_THUMBNAIL
Definition: SPTImage.php:23
SPTImage\Status
Status()
Get the error status set by the constructor.
Definition: SPTImage.php:343
SPTImage\CheckDirectories
static CheckDirectories()
Check that the image storage directories are available, creating them and attempting to change their ...
Definition: SPTImage.php:353
PHP
PHP
Definition: RSSClient--Test.php:12
SPTImage\CACHE_PATH
const CACHE_PATH
path containg the symlinks mapping images/fields to resources
Definition: SPTImage.php:19
SPTImage\ThumbnailHeight
ThumbnailHeight()
Get the height of the thumbnail image for this image.
Definition: SPTImage.php:192
SPTImage\Width
Width()
Get the width of the image.
Definition: SPTImage.php:165
SPTImage
Encapsulates a full-size, preview, and thumbnail image.
Definition: SPTImage.php:13
SPTImage\Url
Url()
Get the path to the image.
Definition: SPTImage.php:91
SPTImage\PreviewStorageDirectory
static PreviewStorageDirectory()
Get the path to the preview image storage directory.
Definition: SPTImage.php:231
SPTImage\PreviewUrl
PreviewUrl()
Get the path to the preview image for this image.
Definition: SPTImage.php:106
SPTImage\Format
Format()
Get the format of the image.
Definition: SPTImage.php:137
AI_FILEUNREADABLE
const AI_FILEUNREADABLE
Definition: Image.php:553
SPTImage\GetLink
GetLink()
Get the path to the full-size image.
Definition: SPTImage.php:273
SPTImage\Id
Id()
Get the ID of the image in the database.
Definition: SPTImage.php:82
Image\Status
Status()
Definition: Image.php:462
SPTImage\Height
Height()
Get the height of the image.
Definition: SPTImage.php:156
SPTImage\Resize
Resize($MaxWidth, $MaxHeight, $MaxPreviewWidth, $MaxPreviewHeight, $MaxThumbnailWidth, $MaxThumbnailHeight)
Resize the full-size, preview, and thumbnail images based on the given dimension restrictions.
Definition: SPTImage.php:440
Image
Definition: Image.php:15
SPTImage\GetImageUrlForResource
GetImageUrlForResource($ResourceId, $FieldId, $Index, $Size)
Get the URL pointing to an image.
Definition: SPTImage.php:508
SPTImage\ExpireImageSymlinks
static ExpireImageSymlinks()
Expire old symlinks used for cached image mappings.
Definition: SPTImage.php:621
SPTImage\SIZE_FULL
const SIZE_FULL
Definition: SPTImage.php:21
SPTImage\ClearImageSymlinksForResource
static ClearImageSymlinksForResource($ResourceId, $FieldId)
Remove symlinks used for to cache image mappings.
Definition: SPTImage.php:576
SPTImage\ClearImageSymlinks
static ClearImageSymlinks()
Remove all symlinks used for a cached image mapping.
Definition: SPTImage.php:601
SPTImage\AltText
AltText($NewValue=NULL)
Get or set the alternate text value for the image.
Definition: SPTImage.php:284
SPTImage\ThumbnailStorageDirectory
static ThumbnailStorageDirectory()
Get the path to the thumbnail image storage directory.
Definition: SPTImage.php:252
SPTImage\ImageStorageDirectory
static ImageStorageDirectory()
Get the path to the (full-size) image storage directory.
Definition: SPTImage.php:210
SPTImage\ThumbnailUrl
ThumbnailUrl()
Get the path to the thumbnail image for this image.
Definition: SPTImage.php:121
AI_INTERNALERROR
const AI_INTERNALERROR
Definition: Image.php:556
Image\Extension
static Extension($Type=NULL)
Definition: Image.php:377