00001 <?php
00008 class STransListXML extends STransXML
00009 {
00012 protected $listNum;
00015 protected $listItemCount;
00018 protected $firstInSection;
00021 protected $catCount;
00022
00025 protected $catBuf;
00028 protected $catIdBuf;
00031 protected $catCountBuf;
00034 protected $jsBuf;
00037 protected $curPrefix;
00038 protected $countByCat;
00039
00042 protected $transHelperClass = "STransStdXMLHelper";
00043
00048 public function doc() {
00049 return "STransListXML generates a dynamically searchable listing "
00050 . "using Javascript, given a ListXML string.";
00051 }
00052
00056 function __construct($parent)
00057 {
00058 $this->listNum = 0;
00059 if (parent::__construct($parent) === true) return false;
00060 $this->setOption('thumbnailWidth', 150);
00061 $this->setOption('thumbnailHeight', 80);
00062 $this->setOption('showCategoryLinks', true);
00063 $this->setOption('showSearchBox', true);
00064 }
00065
00066
00067
00068
00074 public function translate ($si) {
00075 if (parent::translate($si) === false){ return false; }
00076 $source = str_replace(array('<', '>', '&'), array('&lt;', '&gt;', '&amp;'), $si->getSource());
00077 $xml = SXMLHelper::parse($source);
00078
00079
00080 $this->listItemCount = 0;
00081 $this->catCount = 0;
00082 $this->jsBuf = "";
00083 $this->catBuf = array();
00084 $this->catIdBuf = array();
00085 $this->catCountBuf = array();
00086 $this->curPrefix = "listing" . $this->listNum;
00087
00088
00089
00090 $collect =<<<END_TABLE
00091
00092 <div id="$this->curPrefix" class="Listing">
00093 END_TABLE;
00094
00095 if (!isset($xml->module)) {
00096 $this->setPrettyError('translate', 'Input XML missing a module tag.');
00097 return false;
00098 }
00099
00100 foreach($xml->module->unit as $curUnit)
00101 { $collect .= $this->translateListUnit($curUnit); }
00102
00103 $collect .= "<div id=\"$this->curPrefix" . "_noresults" . "\" class=\"listingNoResults\"><div>No Results Found</div></div>";
00104 $collect .= "</div>";
00105
00106
00107 $queryName = $this->curPrefix . "query";
00108 $queryResultsName = $queryName . "_results";
00109 $searchBox = ($this->getOption('showSearchBox')) ? <<<END_SEARCHBOX
00110 <table class="ListingQuery" border="0"><tr><td><span class="queryContainer"><input type="text" id="$queryName" value="Search this list"
00111 onclick="javascript:if(this.value=='Search this list') this.value='';" onblur="javascript:if(this.value=='') this.value='Search this list';" /><span id="$queryResultsName" class="results" >Calculating...</span></span></td></tr></table>
00112 END_SEARCHBOX
00113 : "";
00114
00115
00116 array_push($this->catBuf, <<<END_LIST_BOX
00117 <a href="javascript:listAll('$this->curPrefix');" style="font-weight:bold">Show All</a>
00118 END_LIST_BOX
00119 );
00120 $categoriesList = ($this->getOption('showCategoryLinks')) ? '<div class="CategoryLinks"><span class="categoryLinksContainer">' . implode(' • ', $this->catBuf) . "</span></div>" : "";
00121
00122
00123 $this->sendToTarget($si, $searchBox . $categoriesList . $collect);
00124
00125 $collectJS = "listings[$this->listNum] = new listing('$this->curPrefix',new Array(";
00126 $collectJSArr = array();
00127 for($i=0;$i<count($this->catIdBuf);$i++)
00128 {array_push($collectJSArr, "new ctg('" . $this->catIdBuf[$i] . "'," . $this->catCountBuf[$i] . ")"); }
00129 $collectJS .= implode(",", $collectJSArr);
00130 $collectJS .= "));";
00131 $this->page->appendToSlot('ExtraJS', <<<END_JS
00132 queries[$this->listNum]='$queryName';queryValues[$this->listNum]='-1';
00133 $collectJS
00134 END_JS
00135 );
00136 $this->page->appendToSlot('OnLoad', "setTimeout('queryLists();', 300);");
00137
00138
00139 $this->listNum++;
00140
00141 return true;
00142
00143
00144 }
00145
00146
00147
00148
00153 protected function translateListUnit ($curUnit)
00154 {
00155 if (!isset($curUnit->name)) {
00156 $this->setPrettyError('translate', 'Input XML unit tag missing a name.');
00157 return false;
00158 }
00159
00160 $id = $this->curPrefix . "_ctg" . $this->catCount;
00161 $countid = $id . "_count";
00162 $headid = $id . "_header";
00163
00164 array_push($this->catIdBuf, $id);
00165 array_push($this->catBuf, <<<END_LINK
00166 <a href="javascript:listCat('$this->curPrefix',$this->catCount);">$curUnit->name</a>
00167 END_LINK
00168 );
00169
00170
00171 $collect = "<div id=\"$id\">";
00172
00173 $collect .= <<<END_HEADER
00174
00175 <div class="listingHeader" id="$headid"><span class="listingHeaderText">$curUnit->name <span id="$countid">(...)</span></span></div>
00176 END_HEADER;
00177 $this->firstInSection = true;
00178 $localcount = 0;
00179 $this->countByCat = 0;
00180 foreach($curUnit->page as $page)
00181 {
00182 $collect .= $this->translateListPage($page);
00183 $this->listItemCount++;
00184 $this->firstInSection = false;
00185 $localcount++;
00186 $this->countByCat++;
00187 }
00188 $collect .= "</div>";
00189
00190
00191 array_push($this->catCountBuf, $localcount);
00192 $this->catCount++;
00193 return $collect;
00194 }
00195
00196
00197
00198
00203 protected function translateListPage ($page)
00204 {
00205 $class = ($this->isEvenRow()) ? "evenRow" : "oddRow";
00206 $class .= ($this->isFirstInSection()) ? " firstInSection" : "";
00207 $content = $this->transHelper->formatBlockHtml($page->section->block);
00208
00209
00210 if (!isset($page->name) && !isset($page->pageData->name)) {
00211 $this->setPrettyError('translate', 'Input XML page tag missing a name.');
00212 return false;
00213 }
00214
00215
00216 $pageName = (isset($page->pageData->name)) ? $page->pageData->name : $page->name;
00217
00218 $link = "";
00219
00220 if (isset($page->pageData->shortName) || isset($page->shortName))
00221 {
00222 $link = (isset($page->pageData->shortName)) ? $page->pageData->shortName : $page->shortName;
00223 $linkStart = "<a href=\"$link\">";
00224 $linkEnd = "</a>";
00225 } else { $linkStart = $linkEnd = ""; }
00226
00227
00228
00229 $thumbnail = "";
00230 if (isset($page->thumbnail))
00231 {
00232 $offset = (isset($page->thumbnailOffset)) ? "background-position:0px " . (-($this->getOption('thumbnailHeight')) * $page->thumbnailOffset) . "px;" : "";
00233
00234 $linkThumbClass = "";
00235
00236 if ($link == ""){ $thumblink = "";}
00237 else { $thumblink = " onclick=\"location.href='$link';\" "; $linkThumbClass = "clickable"; }
00238 $limgdir = SPath::getRelPath('ProjectImage');
00239 $thumbnailPath = ($limgdir == '') ? $page->thumbnail : ($limgdir . '/' . $page->thumbnail);
00240
00241 $thumbnail = <<<END_THUMB
00242
00243 <div class="thumbnail $linkThumbClass" style="background-image:url('$thumbnailPath');$offset" $thumblink > </div>
00244 END_THUMB;
00245
00246 }
00247
00248
00249
00250 $collect = "";
00251 $id = $this->curPrefix . "_" . "ctg" . $this->catCount . "_" . $this->countByCat;
00252 $collect .= <<<END_ROW
00253
00254 <div class="$class" id="$id">
00255 <div class="rowContainer">
00256 <div class="rowTitle">$thumbnail$linkStart$pageName$linkEnd</div>
00257 <div class="rowContent">$content</div><br style="clear:both;"/>
00258 </div></div>
00259 END_ROW;
00260 return $collect;
00261 }
00262
00263
00264
00265
00266
00269 protected function isEvenRow ()
00270 { return ($this->listItemCount % 2 == 0); }
00271
00274 protected function isFirstInSection ()
00275 { return ($this->firstInSection); }
00276 }
00277
00278 ?>