1: <?php
2:
3: 4: 5: 6:
7:
8:
9: $_zp_extra_filetypes = array();
10:
11: define('WATERMARK_IMAGE', 1);
12: define('WATERMARK_THUMB', 2);
13: define('WATERMARK_FULL', 4);
14:
15: 16: 17: 18: 19: 20: 21: 22:
23: function newImage($album, $filename, $quiet = false) {
24: global $_zp_extra_filetypes, $_zp_missing_image;
25: if (is_array($filename)) {
26: $xalbum = newAlbum($filename['folder'], true, true);
27: $filename = $filename['filename'];
28: } else {
29: if ($album->isDynamic()) {
30: $xalbum = NULL;
31: foreach ($album->getImages() as $image) {
32: if ($filename == $image['filename']) {
33: $xalbum = newAlbum($image['folder']);
34: break;
35: }
36: }
37: } else {
38: $xalbum = $album;
39: }
40: }
41: if (!is_object($xalbum) || !$xalbum->exists || !isAlbumClass($xalbum)) {
42: if (!$quiet) {
43: $msg = sprintf(gettext('Bad album object parameter to newImage(%s)'), $filename);
44: trigger_error($msg, E_USER_NOTICE);
45: }
46: return $_zp_missing_image;
47: }
48: if ($object = Gallery::validImageAlt($filename)) {
49: $image = New $object($xalbum, $filename, $quiet);
50: } else {
51: if (Gallery::validImage($filename)) {
52: $image = New Image($xalbum, $filename, $quiet);
53: } else {
54: $image = NULL;
55: }
56: }
57: if ($image) {
58: if ($album && $album->isDynamic()) {
59: $image->albumname = $album->name;
60: $image->albumlink = $album->linkname;
61: $image->albumnamealbum = $album;
62: }
63: zp_apply_filter('image_instantiate', $image);
64: if ($image->exists) {
65: return $image;
66: } else {
67: return $_zp_missing_image;
68: }
69: }
70:
71: if (!$quiet) {
72: $msg = sprintf(gettext('Bad filename suffix in newImage(%s)'), $filename);
73: trigger_error($msg, E_USER_NOTICE);
74: }
75: return $_zp_missing_image;
76: }
77:
78: 79: 80: 81: 82: 83:
84: function isImageClass($image = NULL) {
85: global $_zp_current_image;
86: if (is_null($image)) {
87: if (!in_context(ZP_IMAGE))
88: return false;
89: $image = $_zp_current_image;
90: }
91: return is_object($image) && ($image->table == 'images');
92: }
93:
94: 95: 96:
97: class Image extends MediaObject {
98:
99: var $filename;
100: var $exists = true;
101: var $webpath;
102: var $localpath;
103: var $displayname;
104: var $album;
105: var $albumname;
106: var $albumnamealbum;
107: var $albumlink;
108: var $imagefolder;
109: protected $index;
110: protected $sortorder;
111: var $filemtime;
112: var $sidecars = array();
113: var $manage_rights = MANAGE_ALL_ALBUM_RIGHTS;
114: var $manage_some_rights = ALBUM_RIGHTS;
115: var $view_rights = ALL_ALBUMS_RIGHTS;
116:
117: var $objectsThumb = NULL;
118:
119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130:
131: function __construct($album, $filename, $quiet = false) {
132: global $_zp_current_admin_obj;
133:
134: $msg = false;
135: if (!is_object($album) || !$album->exists) {
136: $msg = gettext('Invalid image instantiation: Album does not exist');
137: } else {
138: if (!$this->classSetup($album, $filename) || !file_exists($this->localpath) || is_dir($this->localpath)) {
139: $msg = gettext('Invalid image instantiation: file does not exist');
140: }
141: }
142: if ($msg) {
143: $this->exists = false;
144: if (!$quiet) {
145: trigger_error($msg, E_USER_ERROR);
146: }
147: return;
148: }
149:
150:
151: $album_name = $album->name;
152: $new = $this->instantiate('images', array('filename' => $filename, 'albumid' => $this->album->getID()), 'filename', false, empty($album_name));
153: if ($new || $this->filemtime != $this->get('mtime')) {
154: if ($new)
155: $this->setTitle($this->displayname);
156: $this->updateMetaData();
157: $this->updateDimensions();
158: $this->set('mtime', $this->filemtime);
159: $this->save();
160: if ($new)
161: zp_apply_filter('new_image', $this);
162: }
163: }
164:
165: 166: 167: 168:
169: protected function setDefaults() {
170: global $_zp_gallery;
171: $this->setShow($_zp_gallery->getImagePublish());
172: $this->set('mtime', $this->filemtime);
173: $this->updateDimensions();
174: }
175:
176: 177: 178: 179: 180: 181: 182: 183: 184:
185: protected function classSetup(&$album, $filename) {
186: if (TEST_RELEASE) {
187: $bt = debug_backtrace();
188: $good = false;
189: foreach ($bt as $b) {
190: if ($b['function'] == "newImage") {
191: $good = true;
192: break;
193: }
194: }
195: if (!$good) {
196: zp_error(gettext('An image object was instantiated without using the newImage() function.'), E_USER_WARNING);
197: }
198: }
199:
200: global $_zp_current_admin_obj;
201: $fileFS = internalToFilesystem($filename);
202: if ($filename != filesystemToInternal($fileFS)) {
203: return false;
204: }
205: $this->albumnamealbum = $this->album = &$album;
206: if ($album->name == '') {
207: $this->webpath = ALBUM_FOLDER_WEBPATH . $filename;
208: $this->encwebpath = ALBUM_FOLDER_WEBPATH . rawurlencode($filename);
209: $this->localpath = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($filename);
210: } else {
211: $this->webpath = ALBUM_FOLDER_WEBPATH . $album->name . "/" . $filename;
212: $this->encwebpath = ALBUM_FOLDER_WEBPATH . pathurlencode($album->name) . "/" . rawurlencode($filename);
213: $this->localpath = $album->localpath . $fileFS;
214: }
215: $this->imagefolder = $this->albumlink = $this->albumname = $album->name;
216: $this->filename = $filename;
217: $this->displayname = substr($this->filename, 0, strrpos($this->filename, '.'));
218: if (empty($this->displayname))
219: $this->displayname = $this->filename;
220: $this->comments = null;
221: $this->filemtime = @filemtime($this->localpath);
222: $this->imagetype = strtolower(get_class($this)) . 's';
223: $date = $this->get('date');
224: if (empty($date)) {
225: $this->set('date', strftime('%Y-%m-%d %H:%M:%S', $this->filemtime));
226: }
227: return true;
228: }
229:
230: 231: 232: 233: 234:
235: function getFileName() {
236: return $this->filename;
237: }
238:
239: 240: 241: 242: 243:
244: protected function fileChanged() {
245: $storedmtime = $this->get('mtime');
246: return (empty($storedmtime) || $this->filemtime > $storedmtime);
247: }
248:
249: 250: 251: 252: 253:
254: function getMetaData() {
255: global $_zp_exifvars;
256: $exif = array();
257:
258: foreach ($_zp_exifvars as $field => $exifvar) {
259:
260: if ($_zp_exifvars[$field][5]) {
261: $exif[$field] = $this->get($field);
262: }
263: }
264: return $exif;
265: }
266:
267: 268: 269: 270:
271: function updateMetaData() {
272: global $_zp_exifvars, $_zp_gallery;
273: require_once(dirname(__FILE__) . '/exif/exif.php');
274: $IPTCtags = array(
275: 'SKIP' => '2#000',
276: 'ObjectType' => '2#003',
277: 'ObjectAttr' => '2#004',
278: 'ObjectName' => '2#005',
279: 'EditStatus' => '2#007',
280: 'EditorialUpdate' => '2#008',
281: 'Urgency' => '2#010',
282: 'SubRef' => '2#012',
283: 'Category' => '2#015',
284: 'SuppCategory' => '2#020',
285: 'FixtureID' => '2#022',
286: 'Keywords' => '2#025',
287: 'ContentLocationCode' => '2#026',
288: 'ContentLocationName' => '2#027',
289: 'ReleaseDate' => '2#030',
290: 'ReleaseTime' => '2#035',
291: 'ExpireDate' => '2#037',
292: 'ExpireTime' => '2#038',
293: 'SpecialInstru' => '2#040',
294: 'ActionAdvised' => '2#042',
295: 'RefService' => '2#045',
296: 'RefDate' => '2#047',
297: 'RefNumber' => '2#050',
298: 'DateCreated' => '2#055',
299: 'TimeCreated' => '2#060',
300: 'DigitizeDate' => '2#062',
301: 'DigitizeTime' => '2#063',
302: 'OriginatingProgram' => '2#065',
303: 'ProgramVersion' => '2#070',
304: 'ObjectCycle' => '2#075',
305: 'ByLine' => '2#080',
306: 'ByLineTitle' => '2#085',
307: 'City' => '2#090',
308: 'SubLocation' => '2#092',
309: 'State' => '2#095',
310: 'LocationCode' => '2#100',
311: 'LocationName' => '2#101',
312: 'TransmissionRef' => '2#103',
313: 'ImageHeadline' => '2#105',
314: 'ImageCredit' => '2#110',
315: 'Source' => '2#115',
316: 'Copyright' => '2#116',
317: 'Contact' => '2#118',
318: 'ImageCaption' => '2#120',
319: 'ImageCaptionWriter' => '2#122',
320: 'ImageType' => '2#130',
321: 'Orientation' => '2#131',
322: 'LangID' => '2#135',
323: 'Subfile' => '8#010'
324: );
325: $this->set('hasMetadata', 0);
326: $result = array();
327: if (get_class($this) == 'Image') {
328: $localpath = $this->localpath;
329: } else {
330: $localpath = $this->getThumbImageFile();
331: }
332: $xdate = false;
333:
334: if (!empty($localpath)) {
335: $exifraw = read_exif_data_protected($localpath);
336: if (isset($exifraw['ValidEXIFData'])) {
337: $this->set('hasMetadata', 1);
338: foreach ($_zp_exifvars as $field => $exifvar) {
339: $exif = NULL;
340: if ($exifvar[5]) {
341: if (isset($exifraw[$exifvar[0]][$exifvar[1]])) {
342: $exif = trim(sanitize($exifraw[$exifvar[0]][$exifvar[1]], 1));
343: } else if (isset($exifraw[$exifvar[0]]['MakerNote'][$exifvar[1]])) {
344: $exif = trim(sanitize($exifraw[$exifvar[0]]['MakerNote'][$exifvar[1]], 1));
345: }
346: }
347: $this->set($field, $exif);
348: }
349: }
350:
351: $iptcdata = zp_imageIPTC($localpath);
352: if (!empty($iptcdata)) {
353: $iptc = iptcparse($iptcdata);
354: if ($iptc) {
355: $this->set('hasMetadata', 1);
356: $characterset = $this->getIPTCTag('1#090', $iptc);
357: if (!$characterset) {
358: $characterset = getOption('IPTC_encoding');
359: } else if (substr($characterset, 0, 1) == chr(27)) {
360: $characterset = substr($characterset, 1);
361: if ($characterset == '%G') {
362: $characterset = 'UTF-8';
363: } else {
364: $characterset = getOption('IPTC_encoding');
365: }
366: } else if ($characterset == 'UTF8') {
367: $characterset = 'UTF-8';
368: }
369:
370: foreach ($_zp_exifvars as $field => $exifvar) {
371: if ($exifvar[0] == 'IPTC') {
372: if ($exifvar[5]) {
373: $datum = $this->getIPTCTag($IPTCtags[$exifvar[1]], $iptc);
374: $this->set($field, $this->prepIPTCString($datum, $characterset));
375: } else {
376: $this->set($field, NULL);
377: }
378: }
379: }
380:
381: if ($_zp_exifvars['IPTCKeywords'][5]) {
382: $datum = $this->getIPTCTagArray($IPTCtags['Keywords'], $iptc);
383: if (is_array($datum)) {
384: $tags = array();
385: $result['tags'] = array();
386: foreach ($datum as $item) {
387: $tags[] = $this->prepIPTCString(sanitize($item, 3), $characterset);
388: }
389: $this->setTags($tags);
390: }
391: }
392: }
393: }
394: }
395:
396: zp_apply_filter('image_metadata', $this);
397:
398:
399: $date = $this->get('IPTCDateCreated');
400: if (!empty($date)) {
401: if (strlen($date) > 8) {
402: $time = substr($date, 8);
403: } else {
404:
405: $time = $this->get('IPTCTimeCreated');
406: }
407: $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2);
408: if (!empty($time)) {
409: $date = $date . ' ' . substr($time, 0, 2) . ':' . substr($time, 2, 2) . ':' . substr($time, 4, 2);
410: }
411: }
412:
413: if (empty($date)) {
414: $date = $this->get('EXIFDateTime');
415: }
416: if (empty($date)) {
417: $date = $this->get('EXIFDateTimeOriginal');
418: }
419: if (empty($date)) {
420: $date = $this->get('EXIFDateTimeDigitized');
421: }
422: if (!empty($date)) {
423: $xdate = $date;
424: $this->setDateTime($date);
425: }
426:
427:
428: $title = $this->get('IPTCObjectName');
429: if (empty($title)) {
430: $title = $this->get('IPTCImageHeadline');
431: }
432:
433: if (empty($title)) {
434: $title = $this->get('EXIFDescription');
435: }
436: if (!empty($title)) {
437: $this->setTitle($title);
438: }
439:
440:
441: $desc = $this->get('IPTCImageCaption');
442: if (!empty($desc)) {
443: if(getOption('IPTC_convert_linebreaks')) {
444: $desc = nl2br($desc);
445: }
446: $this->setDesc($desc);
447: }
448:
449:
450: $loc = $this->get('IPTCSubLocation');
451: if (!empty($loc)) {
452: $this->setLocation($loc);
453: }
454: $city = $this->get('IPTCCity');
455: if (!empty($city)) {
456: $this->setCity($city);
457: }
458: $state = $this->get('IPTCState');
459: if (!empty($state)) {
460: $this->setState($state);
461: }
462: $country = $this->get('IPTCLocationName');
463: if (!empty($country)) {
464: $this->setCountry($country);
465: }
466:
467:
468: $credit = $this->get('IPTCByLine');
469: if (empty($credit)) {
470: $credit = $this->get('IPTCImageCredit');
471: }
472: if (empty($credit)) {
473: $credit = $this->get('IPTCSource');
474: }
475: if (!empty($credit)) {
476: $this->setCredit($credit);
477: }
478:
479:
480: $this->setCopyright($this->get('IPTCCopyright'));
481:
482: if (empty($xdate)) {
483: $this->setDateTime(strftime('%Y-%m-%d %H:%M:%S', $this->filemtime));
484: }
485: $alb = $this->album;
486: if (!is_null($alb)) {
487: if (!$this->get('owner')) {
488: $this->setOwner($alb->getOwner());
489: }
490: $save = false;
491: if (strtotime($alb->getUpdatedDate()) < strtotime($this->getDateTime())) {
492: $alb->setUpdatedDate($this->getDateTime());
493: $save = true;
494: }
495: if (is_null($albdate = $alb->getDateTime()) || ($_zp_gallery->getAlbumUseImagedate() && strtotime($albdate) < strtotime($this->getDateTime()))) {
496: $alb->setDateTime($this->getDateTime());
497: $save = true;
498: }
499: if ($save) {
500: $alb->save();
501: }
502: }
503: }
504:
505: 506: 507: 508: 509: 510:
511: private function getIPTCTag($tag, $iptc) {
512: if (isset($iptc[$tag])) {
513: $iptcTag = $iptc[$tag];
514: $r = "";
515: $ct = count($iptcTag);
516: for ($i = 0; $i < $ct; $i++) {
517: $w = $iptcTag[$i];
518: if (!empty($r)) {
519: $r .= ", ";
520: }
521: $r .= $w;
522: }
523: return trim($r);
524: }
525: return '';
526: }
527:
528: 529: 530: 531: 532: 533:
534: private function getIPTCTagArray($tag, $iptc) {
535: if (array_key_exists($tag, $iptc)) {
536: return $iptc[$tag];
537: }
538: return NULL;
539: }
540:
541: 542: 543: 544: 545: 546: 547:
548: private function prepIPTCString($iptcstring, $characterset) {
549: global $_zp_UTF8;
550:
551: if (substr($iptcstring, -1) === 0x0) {
552: $iptcstring = substr($iptcstring, 0, -1);
553: }
554: $outputset = LOCAL_CHARSET;
555: if ($characterset == $outputset)
556: return $iptcstring;
557: $iptcstring = $_zp_UTF8->convert($iptcstring, $characterset, $outputset);
558: return trim(sanitize($iptcstring, 1));
559: }
560:
561: 562: 563: 564:
565: function updateDimensions() {
566: $discard = NULL;
567: $size = zp_imageDims($this->localpath);
568: $width = $size['width'];
569: $height = $size['height'];
570: if (zp_imageCanRotate()) {
571:
572: $splits = preg_split('/!([(0-9)])/', $this->get('EXIFOrientation'));
573: $rotation = $splits[0];
574: switch ($rotation) {
575: case 5:
576: case 6:
577: case 7:
578: case 8:
579: $width = $size['height'];
580: $height = $size['width'];
581: break;
582: }
583: }
584: $this->set('width', $width);
585: $this->set('height', $height);
586: }
587:
588: 589: 590: 591: 592:
593: function getWidth() {
594: $w = $this->get('width');
595: if (empty($w)) {
596: $this->updateDimensions();
597: $this->save();
598: $w = $this->get('width');
599: }
600: return $w;
601: }
602:
603: 604: 605: 606: 607:
608: function getHeight() {
609: $h = $this->get('height');
610: if (empty($h)) {
611: $this->updateDimensions();
612: $this->save();
613: $h = $this->get('height');
614: }
615: return $h;
616: }
617:
618: 619: 620: 621: 622:
623: function getAlbum() {
624: return $this->album;
625: }
626:
627: 628: 629: 630: 631:
632: function getAlbumName() {
633: return $this->albumname;
634: }
635:
636: 637: 638: 639: 640:
641: function getLocation($locale = NULL) {
642: $text = $this->get('location');
643: if ($locale !== 'all') {
644: $text = get_language_string($text, $locale);
645: }
646: $text = zpFunctions::unTagURLs($text);
647: return $text;
648: }
649:
650: 651: 652: 653: 654:
655: function setLocation($location) {
656: $this->set('location', $location);
657: }
658:
659: 660: 661: 662: 663:
664: function getCity($locale = NULL) {
665: $text = $this->get('city');
666: if ($locale !== 'all') {
667: $text = get_language_string($text, $locale);
668: }
669: $text = zpFunctions::unTagURLs($text);
670: return $text;
671: }
672:
673: 674: 675: 676: 677:
678: function setCity($city) {
679: $this->set('city', zpFunctions::tagURLs($city));
680: }
681:
682: 683: 684: 685: 686:
687: function getState($locale = NULL) {
688: $text = $this->get('state');
689: if ($locale !== 'all') {
690: $text = get_language_string($text, $locale);
691: }
692: $text = zpFunctions::unTagURLs($text);
693: return $text;
694: }
695:
696: 697: 698: 699: 700:
701: function setState($state) {
702: $this->set('state', zpFunctions::tagURLs($state));
703: }
704:
705: 706: 707: 708: 709:
710: function getCountry($locale = NULL) {
711: $text = $this->get('country');
712: if ($locale !== 'all') {
713: $text = get_language_string($text, $locale);
714: }
715: $text = zpFunctions::unTagURLs($text);
716: return $text;
717: }
718:
719: 720: 721: 722: 723:
724: function setCountry($country) {
725: $this->set('country', zpFunctions::tagURLs($country));
726: }
727:
728: 729: 730: 731: 732:
733: function getCredit($locale = NULL) {
734: $text = $this->get('credit');
735: if ($locale !== 'all') {
736: $text = get_language_string($text, $locale);
737: }
738: $text = zpFunctions::unTagURLs($text);
739: return $text;
740: }
741:
742: 743: 744: 745: 746:
747: function setCredit($credit) {
748: $this->set('credit', zpFunctions::tagURLs($credit));
749: }
750:
751: 752: 753: 754: 755:
756: function getCopyright($locale = NULL) {
757: $text = $this->get('copyright');
758: if ($locale !== 'all') {
759: $text = get_language_string($text, $locale);
760: }
761: $text = zpFunctions::unTagURLs($text);
762: return $text;
763: }
764:
765: 766: 767: 768: 769:
770: function setCopyright($copyright) {
771: $this->set('copyright', zpFunctions::tagURLs($copyright));
772: }
773:
774: 775: 776: 777: 778: 779:
780: function remove() {
781: $result = false;
782: if (parent::remove()) {
783: $result = true;
784: $filestodelete = safe_glob(substr($this->localpath, 0, strrpos($this->localpath, '.')) . '.*');
785: foreach ($filestodelete as $file) {
786: @chmod($file, 0777);
787: $result = $result && @unlink($file);
788: }
789: if ($result) {
790: query("DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='images' AND `objectid`=" . $this->id);
791: query("DELETE FROM " . prefix('comments') . "WHERE `type` ='images' AND `ownerid`=" . $this->id);
792: $cachepath = SERVERCACHE . '/' . pathurlencode($this->album->name) . '/' . $this->filename;
793: $cachefilestodelete = safe_glob(substr($cachepath, 0, strrpos($cachepath, '.')) . '_*');
794: foreach ($cachefilestodelete as $file) {
795: @chmod($file, 0777);
796: @unlink($file);
797: }
798: }
799: }
800: clearstatcache();
801: return $result;
802: }
803:
804: 805: 806: 807: 808: 809: 810:
811: function move($newalbum, $newfilename = null) {
812: if (is_string($newalbum))
813: $newalbum = newAlbum($newalbum, false);
814: if ($newfilename == null) {
815: $newfilename = $this->filename;
816: } else {
817: if (getSuffix($this->filename) != getSuffix($newfilename)) {
818: return 6;
819: }
820: }
821: if ($newalbum->getID() == $this->album->getID() && $newfilename == $this->filename) {
822:
823: return 2;
824: }
825: $newpath = $newalbum->localpath . internalToFilesystem($newfilename);
826: if (file_exists($newpath)) {
827:
828: if (!(CASE_INSENSITIVE && strtolower($newpath) == strtolower($this->localpath))) {
829: return 2;
830: }
831: }
832: $filename = basename($this->localpath);
833: @chmod($filename, 0777);
834: $result = @rename($this->localpath, $newpath);
835: @chmod($filename, FILE_MOD);
836: $this->localpath = $newpath;
837: clearstatcache();
838: if ($result) {
839: $filestomove = safe_glob(substr($this->localpath, 0, strrpos($this->localpath, '.')) . '.*');
840: foreach ($filestomove as $file) {
841: if (in_array(strtolower(getSuffix($file)), $this->sidecars)) {
842: $result = $result && @rename($file, stripSuffix($newpath) . '.' . getSuffix($file));
843: }
844: }
845: }
846: if ($result) {
847: if (parent::move(array('filename' => $newfilename, 'albumid' => $newalbum->getID()))) {
848: $this->set('mtime', filemtime($newpath));
849: $this->save();
850: return 0;
851: }
852: }
853: return 1;
854: }
855:
856: 857: 858: 859: 860: 861:
862: function rename($newfilename) {
863: return $this->move($this->album, $newfilename);
864: }
865:
866: 867: 868: 869: 870:
871: function copy($newalbum) {
872: if (is_string($newalbum)) {
873: $newalbum = newAlbum($newalbum, false);
874: }
875: if ($newalbum->getID() == $this->album->getID()) {
876:
877: return 2;
878: }
879: $newpath = $newalbum->localpath . internalToFilesystem($this->filename);
880: if (file_exists($newpath)) {
881:
882: return 2;
883: }
884: $filename = basename($this->localpath);
885: $result = @copy($this->localpath, $newpath);
886: if ($result) {
887: $filestocopy = safe_glob(substr($this->localpath, 0, strrpos($this->localpath, '.')) . '.*');
888: foreach ($filestocopy as $file) {
889: if (in_array(strtolower(getSuffix($file)), $this->sidecars)) {
890: $result = $result && @copy($file, $newalbum->localpath . basename($file));
891: }
892: }
893: }
894: if ($result) {
895: if ($newID = parent::copy(array('filename' => $filename, 'albumid' => $newalbum->getID()))) {
896: storeTags(readTags($this->getID(), 'images'), $newID, 'images');
897: query('UPDATE ' . prefix('images') . ' SET `mtime`=' . filemtime($newpath) . ' WHERE `filename`="' . $filename . '" AND `albumid`=' . $newalbum->getID());
898: return 0;
899: }
900: }
901: return 1;
902: }
903:
904:
905:
906: 907: 908: 909: 910:
911: function getLink() {
912: if (is_array($this->filename)) {
913: $albumq = $album = dirname($this->filename['source']);
914: $image = basename($this->filename['source']);
915: } else {
916: $album = $this->albumlink;
917: $albumq = $this->albumnamealbum->name;
918: $image = $this->filename;
919: }
920: return zp_apply_filter('getLink', rewrite_path(pathurlencode($album) . '/' . urlencode($image) . IM_SUFFIX, '/index.php?album=' . pathurlencode($albumq) . '&image=' . urlencode($image)), $this, NULL);
921: }
922:
923: 924: 925: 926: 927:
928: function getImageLink() {
929: internal_deprecations::getImageLink();
930: return $this->getLink();
931: }
932:
933: 934: 935: 936: 937: 938: 939:
940: function getFullImage($path = WEBPATH) {
941: global $_zp_conf_vars;
942: if ($path == WEBPATH && $_zp_conf_vars['album_folder_class'] == 'external') {
943: return false;
944: }
945: if (is_array($this->filename)) {
946: $album = dirname($this->filename['source']);
947: $image = basename($this->filename['source']);
948: } else {
949: $album = $this->imagefolder;
950: $image = $this->filename;
951: }
952: return getAlbumFolder($path) . $album . "/" . $image;
953: }
954:
955: 956: 957:
958: function getFullImageURL() {
959: return $this->getFullImage(WEBPATH);
960: }
961:
962: 963: 964: 965: 966: 967:
968: function getSizedImage($size) {
969: $wmt = getWatermarkParam($this, WATERMARK_IMAGE);
970: $args = getImageParameters(array($size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, $wmt), $this->album->name);
971: return getImageURI($args, $this->album->name, $this->filename, $this->filemtime);
972: }
973:
974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985: 986: 987:
988: function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = false, $effects = NULL) {
989: if ($thumbStandin < 0) {
990: $wmt = '!';
991: } else {
992: if ($thumbStandin) {
993: $wmt = getWatermarkParam($this, WATERMARK_THUMB);
994: } else {
995: $wmt = getWatermarkParam($this, WATERMARK_IMAGE);
996: }
997: }
998: $args = getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, $wmt, NULL, $effects), $this->album->name);
999: return getImageURI($args, $this->album->name, $this->filename, $this->filemtime);
1000: }
1001:
1002: 1003: 1004: 1005: 1006:
1007: function getContent() {
1008: $class = '';
1009: if (!$this->getShow()) {
1010: $class .= " not_visible";
1011: }
1012: $album = $this->getAlbum();
1013: $pwd = $album->getPassword();
1014: if (!empty($pwd)) {
1015: $class .= " password_protected";
1016: }
1017: $size = getOption('image_size');
1018: $h = $this->getHeight();
1019: $w = $this->getWidth();
1020: $side = getOption('image_use_side');
1021: $us = getOption('image_allow_upscale');
1022: $dim = $size;
1023:
1024: if ($w == 0) {
1025: $hprop = 1;
1026: } else {
1027: $hprop = round(($h / $w) * $dim);
1028: }
1029: if ($h == 0) {
1030: $wprop = 1;
1031: } else {
1032: $wprop = round(($w / $h) * $dim);
1033: }
1034:
1035: if (($size && ($side == 'longest' && $h > $w) || ($side == 'height') || ($side == 'shortest' && $h < $w))) {
1036:
1037: $newh = $dim;
1038: $neww = $wprop;
1039: } else {
1040:
1041: $neww = $dim;
1042: $newh = $hprop;
1043: }
1044: if (!$us && $newh >= $h && $neww >= $w) {
1045: $neww = $w;
1046: $newh = $h;
1047: }
1048: $html = '<img src="' . html_encode(pathurlencode($this->getSizedImage($size))) . '" alt="' . html_encode($this->getTitle()) . '"' .
1049: ' width="' . $neww . '" height="' . $newh . '"' .
1050: (($class) ? " class=\"$class\"" : "") . " />";
1051: $html = zp_apply_filter('standard_image_html', $html);
1052: return $html;
1053: }
1054:
1055: 1056: 1057: 1058: 1059: 1060: 1061:
1062: function getThumbImageFile() {
1063: return $local = $this->localpath;
1064: }
1065:
1066: 1067: 1068: 1069: 1070: 1071:
1072: function getThumbCropping($ts, $sw, $sh) {
1073: $cy = $this->get('thumbY');
1074: if (is_null($cy)) {
1075: $custom = $cx = $cw = $ch = NULL;
1076: } else {
1077: $custom = true;
1078: $cx = $this->get('thumbX');
1079: $cw = $this->get('thumbW');
1080: $ch = $this->get('thumbH');
1081:
1082: if ($sw == $sh) {
1083: $sw = $sh = $ts;
1084: } else {
1085: if ($sw > $sh) {
1086: $r = $ts / $sw;
1087: $sw = $ts;
1088: $sh = $sh * $r;
1089: } else {
1090: $r = $ts / $sh;
1091: $sh = $ts;
1092: $sh = $r * $sh;
1093: }
1094: }
1095: }
1096: return array($custom, $cw, $ch, $cx, $cy);
1097: }
1098:
1099: 1100: 1101: 1102: 1103:
1104: function getThumb($type = 'image') {
1105: $ts = getOption('thumb_size');
1106: if (getOption('thumb_crop')) {
1107: $sw = getOption('thumb_crop_width');
1108: $sh = getOption('thumb_crop_height');
1109: list($custom, $cw, $ch, $cx, $cy) = $this->getThumbCropping($ts, $sw, $sh);
1110: if ($custom) {
1111: return $this->getCustomImage(NULL, $sw, $sh, $cw, $ch, $cx, $cy, true);
1112: }
1113: } else {
1114: $sw = $sh = NULL;
1115: }
1116: $wmt = getWatermarkParam($this, WATERMARK_THUMB);
1117: $args = getImageParameters(array($ts, NULL, NULL, $sw, $sh, NULL, NULL, NULL, true, NULL, true, $wmt, NULL, NULL), $this->album->name);
1118:
1119: return getImageURI($args, $this->album->name, $this->filename, $this->filemtime);
1120: }
1121:
1122: 1123: 1124: 1125: 1126:
1127: function getIndex() {
1128: global $_zp_current_search, $_zp_current_album;
1129: if ($this->index == NULL) {
1130: $album = $this->albumnamealbum;
1131: if (!is_null($_zp_current_search) && !in_context(ZP_ALBUM_LINKED) || $album->isDynamic()) {
1132: if ($album->isDynamic()) {
1133: $images = $album->getImages();
1134: for ($i = 0; $i < count($images); $i++) {
1135: $image = $images[$i];
1136: if ($this->filename == $image['filename']) {
1137: $this->index = $i;
1138: break;
1139: }
1140: }
1141: } else {
1142: $this->index = $_zp_current_search->getImageIndex($this->imagefolder, $this->filename);
1143: }
1144: } else {
1145: $images = $this->album->getImages(0);
1146: for ($i = 0; $i < count($images); $i++) {
1147: $image = $images[$i];
1148: if ($this->filename == $image) {
1149: $this->index = $i;
1150: break;
1151: }
1152: }
1153: }
1154: }
1155: return $this->index;
1156: }
1157:
1158: 1159: 1160: 1161: 1162:
1163: function getNextImage() {
1164: global $_zp_current_search;
1165: $index = $this->getIndex();
1166: if (!is_null($_zp_current_search) && !in_context(ZP_ALBUM_LINKED)) {
1167: $image = $_zp_current_search->getImage($index + 1);
1168: } else {
1169: $album = $this->albumnamealbum;
1170: $image = $album->getImage($index + 1);
1171: }
1172: return $image;
1173: }
1174:
1175: 1176: 1177: 1178: 1179:
1180: function getPrevImage() {
1181: global $_zp_current_search;
1182: $index = $this->getIndex();
1183: if (!is_null($_zp_current_search) && !in_context(ZP_ALBUM_LINKED)) {
1184: $image = $_zp_current_search->getImage($index - 1);
1185: } else {
1186: $album = $this->albumnamealbum;
1187: $image = $album->getImage($index - 1);
1188: }
1189: return $image;
1190: }
1191:
1192: 1193: 1194: 1195: 1196:
1197: function getImageFootprint() {
1198: return filesize($this->localpath);
1199: }
1200:
1201: 1202: 1203: 1204: 1205:
1206: function getWatermark() {
1207: return $this->get('watermark');
1208: }
1209:
1210: 1211: 1212: 1213: 1214:
1215: function setWatermark($wm) {
1216: $this->set('watermark', $wm);
1217: }
1218:
1219: 1220: 1221: 1222: 1223:
1224: function getWMUse() {
1225: return $this->get('watermark_use');
1226: }
1227:
1228: 1229: 1230: 1231: 1232:
1233: function setWMUse($use) {
1234: $this->set('watermark_use', $use);
1235: }
1236:
1237: 1238: 1239:
1240: function getOwner() {
1241: $owner = $this->get('owner');
1242: if (empty($owner)) {
1243: $owner = $this->album->getOwner();
1244: }
1245: return $owner;
1246: }
1247:
1248: function setOwner($owner) {
1249: $this->set('owner', $owner);
1250: }
1251:
1252: function isMyItem($action) {
1253: $album = $this->album;
1254: return $album->isMyItem($action);
1255: }
1256:
1257: 1258: 1259:
1260: function checkAccess(&$hint = NULL, &$show = NULL) {
1261: $album = $this->getAlbum();
1262: if ($album->isMyItem(LIST_RIGHTS)) {
1263: return $this->getShow() || $album->albumSubRights() & (MANAGED_OBJECT_RIGHTS_EDIT | MANAGED_OBJECT_RIGHTS_VIEW);
1264: }
1265: return $album->checkforGuest($hint, $show) && $this->getShow() && $album->getShow();
1266: }
1267:
1268: 1269: 1270: 1271: 1272:
1273: function checkforGuest(&$hint = NULL, &$show = NULL) {
1274: if (!parent::checkForGuest()) {
1275: return false;
1276: }
1277: $album = $this->getAlbum();
1278: return $album->checkforGuest($hint, $show);
1279: }
1280:
1281: 1282: 1283: 1284:
1285: function isProtected() {
1286: return $this->checkforGuest() != 'zp_public_access';
1287: }
1288:
1289: }
1290:
1291: class Transientimage extends Image {
1292:
1293: 1294: 1295: 1296: 1297: 1298:
1299: function __construct($album, $image) {
1300: if (!is_object($album)) {
1301: $album = new AlbumBase('Transient');
1302: }
1303: $this->album = $album;
1304: $this->localpath = $image;
1305: $filename = makeSpecialImageName($image);
1306: $this->filename = $filename;
1307: $this->displayname = stripSuffix(basename($image));
1308: if (empty($this->displayname)) {
1309: $this->displayname = $this->filename['name'];
1310: }
1311: $this->filemtime = @filemtime($this->localpath);
1312: $this->comments = null;
1313: $this->instantiate('images', array('filename' => $filename['name'], 'albumid' => $this->album->getID()), 'filename', true, true);
1314: $this->exists = false;
1315: }
1316:
1317: }
1318:
1319: ?>
1320: