00001 <?php
00007 class STransPhotoXML extends STransXML
00008 {
00011 protected $photoNum = 0;
00015 protected $prefix = "";
00018 protected $curPhotoCount = 0;
00021 protected $thumbscriptpath;
00022
00027 public function doc() {
00028 return "STransPhotoXML creates a photo album given a PhotoXML string.";
00029 }
00030
00031
00032
00033
00039 public function translate ($si)
00040 {
00041 global $COMMON_PATH_KEY, $MEDIA_SITE;
00042
00043 #Use processMediaXML in XML3Helper instead
00044 SMedia::adminConnect($MEDIA_SITE);
00045
00046 if(parent::translate($si) === false ) return false;
00047 $xml = SXMLHelper::parse($si->getSource());
00048
00049 $this->curPhotoCount = 0;
00050 $this->prefix = "photoview" . $this->photoNum;
00051
00052 $this->thumbscriptpath = "/$COMMON_PATH_KEY[common]/$COMMON_PATH_KEY[pr2]/components/photothumbs.php5";
00053
00054 $this->createPhotoJS($xm3l);
00055 $this->sendToTarget($si, $this->createPhotoHTML($xml));
00056
00057 $this->photoNum++;
00058 }
00059
00064 protected function createPhotoJS($xmlobj)
00065 {
00066 $photoPaths = array();
00067 $photoWidths = array();
00068 $photoHeights = array();
00069 $photoCaptions = array();
00070 $thumbPaths = array();
00071 $pvid = $this->photoNum;
00072
00073 $width = 1280; $height = 960;
00074
00075 $album = $xmlobj->module->unit->page->album;
00076 $isection = $this->getOption('photoview_section');
00077 $section = $album->section[$isection];
00078
00079 if (isset($album->width)){ $width = $album->width; }
00080 if (isset($album->height)){ $height = $album->height; }
00081
00082 if (isset($section->width)){ $width = $section->width; }
00083 if (isset($section->height)){ $width = $section->height; }
00084
00085 foreach($section->photo as $p)
00086 {
00087 $curWidth = (isset($p->width)) ? $p->width : $width;
00088 $curHeight = (isset($p->height)) ? $p->height : $height;
00089 $caption = (isset($p->caption)) ? $p->caption : "";
00090
00091 if (isset($p->media)){
00092
00093 $type = $p->media['type'];
00094 $id = $p->media['id'];
00095
00096 if($type == "image") {
00097 #Swap in code for STransMediaXML retrieving media from SNAP.
00098 $img = SMedia::$IMAGE_TABLE->retrieve(intval($id));
00099 if($img == null) {
00100 array_push($photoPaths, "");
00101 array_push($thumbPaths, "");
00102 array_push($photoHeights, $curWidth);
00103 array_push($photoWidths, $curHeight);
00104 }
00105 else {
00106 $width = $img->attr_width;
00107 $height = $img->attr_height;
00108 array_push($photoPaths, $img->fobj_display->attr_webPath);
00109 array_push($thumbPaths, $img->fobj_thumb->attr_webPath);
00110 array_push($photoWidths, $width);
00111 array_push($photoHeights, $height);
00112 }
00113 }
00114 } else {
00115 array_push($photoPaths, $p->path);
00116 array_push($thumbPaths, "");
00117
00118
00119 if(isset($p->rotate)){
00120 array_push($photoHeights, $curWidth);
00121 array_push($photoWidths, $curHeight);
00122 }else{
00123 array_push($photoWidths, $curWidth);
00124 array_push($photoHeights, $curHeight);
00125 }
00126
00127 }
00128
00129 array_push($photoCaptions, $this->escapeForJavascriptOutput($p->caption));
00130
00131 $this->curPhotoCount++;
00132 }
00133 $catPhotoPaths = "'" . implode("','", $photoPaths) . "'";
00134 $catThumbPaths = "'" . implode("','", $thumbPaths) . "'";
00135
00136 $catPhotoWidths = implode(",", $photoWidths);
00137 $catPhotoHeights = implode(",", $photoHeights);
00138 $catPhotoCaptions = "'" . implode("','", $photoCaptions) . "'";
00139
00140 $output =<<<END_OUTPUT
00141
00142 photoPaths[$this->photoNum]=new Array($catPhotoPaths);
00143 thumbPaths[$this->photoNum]=new Array($catThumbPaths);
00144 photoWidths[$this->photoNum]=new Array($catPhotoWidths);
00145 photoHeights[$this->photoNum]=new Array($catPhotoHeights);
00146 photoCaptions[$this->photoNum]= new Array($catPhotoCaptions);
00147
00148 END_OUTPUT;
00149 $this->page->appendToSlot('ExtraJS', $output);
00150 }
00151
00156 protected function createPhotoHTML($xmlobj)
00157 {
00158 $scriptpath = $this->thumbscriptpath;
00159
00160 $vf="_viewframe0";$vf2="_viewframe1";$tn="_thumbnails";$cap="_caption";$left="_bigleft";$right="_bigright";$img="_image0"; $img2="_image1";$dnld="_download";
00161
00162 $isection = $this->getOption('photoview_section');
00163 $section = $xmlobj->module->unit->page->album->section[$isection];
00164 $path = $this->getOption('photoview_basepath') . $section->year . "/" . $section->month . "-" . $section->day . "-" . $section->shortName;
00165 $path = "";
00166
00167 $duidir = $this->parent->getPath('relDefaultUIDirURL');
00168
00169 $output =<<<END_OUTPUT
00170 <div class="photoviewContainer" align="center">
00171 <div class="photoviewBox">
00172 <div class="scrollFrame">
00173 <iframe name="$this->prefix$tn" src="$scriptpath?pvid=$this->photoNum&pcount=$this->curPhotoCount&basepath=$path" frameborder="0"
00174 width="100%" height="80">Picture Thumbnails</iframe>
00175 </div>
00176 <div style="position:relative; height: 400px;">
00177 <div class="viewFrame" id="$this->prefix$vf" style="position:absolute; visibility:visible">
00178 <img id="$this->prefix$img" src="$duidir/images/tiny_space.gif" alt="photo" style="width:600px;height:400px;position:absolute;top:0px;left:0px;" />
00179 </div>
00180 <div class="viewFrame" id="$this->prefix$vf2" style="position:absolute; visibility:hidden;">
00181 <img id="$this->prefix$img2" src="$duidir/images/tiny_space.gif" alt="photo" style="width:600px;height:400px;position:absolute;top:0px;left:0px;" />
00182 </div>
00183 </div>
00184 <div class="controlFrame">
00185 <img id="$this->prefix$left" src="$duidir/images/leftarr.gif" class="bigArrow clickable" alt="Previous" style="float:left;margin-right:10px;" onclick="javascript:photolistPrev($this->photoNum);" />
00186 <img id="$this->prefix$right" src="$duidir/images/rightarr.gif" class="bigArrow clickable" alt="Next" style="float:right;margin-left:10px;" onclick="javascript:photolistNext($this->photoNum);" />
00187
00188 <span id="$this->prefix$cap" class="caption"></span><br style="clear:both;" />
00189 <span class="download"><small><a id="$this->prefix$dnld" href="#" target="_blank">[View Full Quality Image]</a></small></span><br style="clear:both;" />
00190 </div>
00191 </div>
00192 </div>
00193
00194 END_OUTPUT;
00195 return $output;
00196 }
00197
00198
00203 public function escapeForJavascriptOutput($text)
00204 {
00205 $text = str_replace("\"", "“", $text);
00206 $text = str_replace("\'", "‘", $text);
00207 $text = preg_replace("/\n|\r|\t/", "", $text);
00208 $text = addSlashes($text);
00209 return $text;
00210 }
00211
00212 }