00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Block_Product_Gallery extends Mage_Core_Block_Template
00035 {
00036 protected function _prepareLayout()
00037 {
00038 if ($headBlock = $this->getLayout()->getBlock('head')) {
00039 $headBlock->setTitle($this->getProduct()->getMetaTitle());
00040 }
00041 return parent::_prepareLayout();
00042 }
00043 public function getProduct()
00044 {
00045 return Mage::registry('product');
00046 }
00047
00048 public function getGalleryCollection()
00049 {
00050 return $this->getProduct()->getMediaGalleryImages();
00051 }
00052
00053 public function getCurrentImage()
00054 {
00055 $imageId = $this->getRequest()->getParam('image');
00056 $image = null;
00057 if ($imageId) {
00058 $image = $this->getGalleryCollection()->getItemById($imageId);
00059 }
00060
00061 if (!$image) {
00062 $image = $this->getGalleryCollection()->getFirstItem();
00063 }
00064 return $image;
00065 }
00066
00067 public function getImageUrl()
00068 {
00069 return $this->getCurrentImage()->getUrl();
00070 }
00071
00072 public function getImageFile()
00073 {
00074 return $this->getCurrentImage()->getFile();
00075 }
00076
00077 public function getImageWidth()
00078 {
00079 $file = $this->getCurrentImage()->getPath();
00080 if (file_exists($file)) {
00081 $size = getimagesize($file);
00082 if (isset($size[0]) && $size[0]>600) {
00083 return 600;
00084 }
00085 }
00086 return false;
00087 }
00088
00089 public function getPreviusImage()
00090 {
00091 $current = $this->getCurrentImage();
00092 if (!$current) {
00093 return false;
00094 }
00095 $previus = false;
00096 foreach ($this->getGalleryCollection() as $image) {
00097 if ($image->getValueId() == $current->getValueId()) {
00098 return $previus;
00099 }
00100 $previus = $image;
00101 }
00102 return $previus;
00103 }
00104
00105 public function getNextImage()
00106 {
00107 $current = $this->getCurrentImage();
00108 if (!$current) {
00109 return false;
00110 }
00111
00112 $next = false;
00113 $currentFind = false;
00114 foreach ($this->getGalleryCollection() as $image) {
00115 if ($currentFind) {
00116 return $image;
00117 }
00118 if ($image->getValueId() == $current->getValueId()) {
00119 $currentFind = true;
00120 }
00121 }
00122 return $next;
00123 }
00124
00125 public function getPreviusImageUrl()
00126 {
00127 if ($image = $this->getPreviusImage()) {
00128 return $this->getUrl('*/*/*', array('_current'=>true, 'image'=>$image->getValueId()));
00129 }
00130 return false;
00131 }
00132
00133 public function getNextImageUrl()
00134 {
00135 if ($image = $this->getNextImage()) {
00136 return $this->getUrl('*/*/*', array('_current'=>true, 'image'=>$image->getValueId()));
00137 }
00138 return false;
00139 }
00140 }