00001 <?php
00010 class STransStdXML3Helper extends SObject {
00011
00012 protected $parent;
00013 protected $translator;
00014
00015 protected $listNum;
00016 protected $listItemCount;
00017 protected $firstInSection;
00018 protected $catCount;
00019
00020 protected $albumNum;
00021
00022 protected $catBuf;
00023 protected $catIdBuf;
00024 protected $catCountBuf;
00025 protected $jsBuf;
00026 protected $curPrefix;
00027 protected $countByCat;
00028
00029 protected $callbacks;
00030
00031 protected $sectionDepth = 0;
00032
00040 public function doc() {
00041 return "STransStdXML3Helper is a class that helps STransStdXML3 and STransListXML3"
00042 . " perform their translation.";
00043 }
00044
00053 public function __construct($parent)
00054 {
00055 $this->listNum = 0;
00056 $this->albumNum = 0;
00057 if (parent::__construct($parent) === true) return false;
00058 $this->sectionDepth = 0;
00059 }
00060
00061
00070 public function setTranslator($t) {
00071 $this->translator = $t;
00072 }
00073
00081 public function getTranslator() {
00082 return $this->translator;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00109 public function translateResource($xmlResource) {
00110 return $this->processBlockLevelElementContainerXML($xmlResource);
00111 }
00112
00121 public function processBlockLevelElementContainerXML($xml) {
00122 return $this->processBlockOrMixedContentXMLHelper($xml, true);
00123 }
00124
00133 public function processMixedContentContainerXML($xml) {
00134 return $this->processBlockOrMixedContentXMLHelper($xml, false);
00135 }
00136
00137
00147 protected function processBlockOrMixedContentXMLHelper($xml, $block = true) {
00148 $content = "";
00149 $children = $xml->childNodes;
00150 foreach ($children as $child) {
00151 if ($child instanceof domElement) {
00152
00153
00154 if ($block) {
00155 $content .= $this->processBlockLevelElementXML($child);
00156 } else {
00157 $content .= $this->processMixedElementXML($child);
00158 }
00159 } else {
00160
00161
00162
00163 $nodeValue = str_replace(array('&lt;', '&gt;'), array('<', '>'), $child->nodeValue);
00164 if ($block && (trim($nodeValue) != "")) {
00165 $this->setPrettyWarning('processBlockOrMixedContentXMLHelper',
00166 'Encountered mixed content, which is not allowed inside a '
00167 . $xml->tagName . ' tag.');
00168 } else {
00169
00170 $content .= $nodeValue;
00171 }
00172 }
00173 }
00174 return $content;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00192 protected function processMixedElementXML($xml) {
00193 switch($xml->tagName) {
00194 case 'link':
00195 return $this->processLinkXML($xml);
00196 break;
00197 case 'media':
00198 return $this->processMediaXML($xml);
00199 break;
00200 case 'latex':
00201 return $this->processLatexXML($xml);
00202 break;
00203 case 'br':
00204 return $this->processBrXML($xml);
00205 break;
00206 case 'hr':
00207 return $this->processHrXML($xml);
00208 break;
00209 case 'b':
00210 return $this->processBoldXML($xml);
00211 break;
00212 case 'i':
00213 return $this->processItalicXML($xml);
00214 break;
00215 case 'u':
00216 return $this->processUnderlineXML($xml);
00217 break;
00218 case 'span':
00219 return $this->processSpanXML($xml);
00220 break;
00221 case 'sub':
00222 return $this->processSubXML($xml);
00223 break;
00224 case 'sup':
00225 return $this->processSupXML($xml);
00226 break;
00227 case 'pre':
00228 return $this->processPreXML($xml);
00229 break;
00230 case 'entity':
00231 return $this->processEntityXML($xml);
00232 break;
00233 default:
00234 return $this->processBlockLevelElementXML($xml);
00235 }
00236 }
00237
00246 protected function processBlockLevelElementXML($xml) {
00247 switch($xml->tagName) {
00248 case 'section':
00249 return $this->processSectionXML($xml);
00250 break;
00251 case 'p':
00252 return $this->processParagraphXML($xml);
00253 break;
00254 case 'ul':
00255 case 'ol':
00256 return $this->processListXML($xml);
00257 break;
00258 case 'table':
00259 return $this->processTableXML($xml);
00260 break;
00261 case 'div':
00262 return $this->processDivXML($xml);
00263 break;
00264 case 'map':
00265 return $this->processMapXML($xml);
00266 break;
00267 case 'name':
00268 case 'shortName':
00269 case 'listItemData':
00270 case 'sectionData':
00271 case 'resourceData':
00272 break;
00273 default:
00274 $result = $this->processCustomElementXML($xml);
00275 if ($result == null) {
00276 $this->setPrettyWarning('processXML', "Unknown tag '" . $xml->tagName . "'");
00277 }
00278 break;
00279 }
00280 return "";
00281 }
00282
00283
00292 protected function processCustomElementXML($xml) {
00293 switch($xml->tagName) {
00294 default;
00295 break;
00296 }
00297 return null;
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00315 protected function processSectionXML($xml) {
00316 $this->sectionDepth++;
00317 $ret = $this->processStandardTag($xml, "div",
00318 $this->processSectionTitle($xml) .
00319 $this->processBlockLevelElementContainerXML($xml),
00320 array('class' => 'section'));
00321 $this->sectionDepth--;
00322 return $ret;
00323 }
00324
00333 protected function processSectionTitle($xml) {
00334 $elt = simplexml_import_dom($xml);
00335 if (isset($elt->name)) {
00336 $class = isset($elt->name->attributes()->class) ? ' class="' . $elt->name->attributes()->class . '"' : '';
00337 return "<h" . ($this->sectionDepth+1) . "$class>" . $this->processBlockOrMixedContentXMLHelper($xml->getElementsByTagName('name')->item(0), false) .
00338 "</h" . ($this->sectionDepth+1) . ">";
00339 }
00340 return "";
00341 }
00342
00343
00344
00345
00346
00355 protected function processParagraphXML($xml) {
00356 return $this->processStandardTag($xml, "p",
00357 $this->processMixedContentContainerXML($xml));
00358 }
00359
00360
00361
00362
00363
00372 protected function processTableXML($xml) {
00373 return $this->processStandardTag($xml, $xml->tagName,
00374 $this->processTableBodyContainerXML($xml));
00375 }
00376
00386 protected function processTableBodyContainerXML($xml, $blockTbody = false) {
00387 $children = $xml->childNodes;
00388 $content = "";
00389 foreach ($children as $child) {
00390 if ($child instanceof DOMElement) {
00391 switch($child->tagName) {
00392 case 'tbody':
00393 if ($blockTbody == true) {
00394 $this->warnUnexpectedTag('processTableBodyContainerXML', $child,
00395 'tbody', 'tr');
00396 } else {
00397 $content .= $this->processTableBodyXML($child);
00398 }
00399 break;
00400 case 'tr':
00401 $content .= $this->processTableRowXML($child);
00402 break;
00403 default:
00404 $this->warnUnexpectedTag('processTableBodyContainerXML', $child,
00405 'table', 'tbody or tr');
00406 break;
00407 }
00408 } else {
00409 $this->warnInvalidMixedContent('processTableBodyContainerXML', $child, 'tbody or tr');
00410 }
00411 }
00412 return $content;
00413 }
00414
00423 protected function processTableDataContainerXML($xml) {
00424 $children = $xml->childNodes;
00425 $content = "";
00426 foreach ($children as $child) {
00427 if ($child instanceof DOMElement) {
00428 switch($child->tagName) {
00429 case 'td':
00430 $content .= $this->processTableDataXML($child);
00431 break;
00432 case 'th':
00433 $content .= $this->processTableHeaderXML($child);
00434 break;
00435 default:
00436 $this->warnUnexpectedTag('processTableDataContainerXML', $child,
00437 'tr', 'td or th');
00438 break;
00439 }
00440 } else {
00441 $this->warnInvalidMixedContent('processTableDataContainerXML', $child, 'td or th');
00442 }
00443 }
00444 return $content;
00445 }
00446
00455 protected function processTableDataXML($xml) {
00456 return $this->processStandardTag($xml, "td",
00457 $this->processMixedContentContainerXML($xml));
00458 }
00459
00468 protected function processTableHeaderXML($xml) {
00469 return $this->processStandardTag($xml, "th",
00470 $this->processMixedContentContainerXML($xml));
00471 }
00472
00481 protected function processTableBodyXML($xml) {
00482 return $this->processStandardTag($xml, $xml->tagName,
00483 $this->processTableBodyContainerXML($xml, true));
00484 }
00485
00494 protected function processTableRowXML($xml) {
00495 return $this->processStandardTag($xml, $xml->tagName,
00496 $this->processTableDataContainerXML($xml, true));
00497 }
00498
00499
00500
00501
00502
00511 protected function processListXML($xml) {
00512 return $this->processStandardTag($xml, $xml->tagName,
00513 $this->processListItemContainerXML($xml));
00514 }
00515
00524 protected function processListItemContainerXML($xml) {
00525 $children = $xml->childNodes;
00526 $content = "";
00527 foreach ($children as $child) {
00528 if ($child instanceof DOMElement) {
00529 switch($child->tagName) {
00530 case 'li':
00531 $content .= $this->processListItemXML($child);
00532 break;
00533 default:
00534 $this->warnUnexpectedTag('processListItemContainerXML', $child,
00535 $xml->tagName, 'li');
00536 break;
00537 }
00538 } else {
00539 $this->warnInvalidMixedContent('processListItemContainerXML', $child, 'li');
00540 }
00541 }
00542 return $content;
00543 }
00544
00553 protected function processListItemXML($xml) {
00554 return $this->processStandardTag($xml, "li",
00555 $this->processMixedContentContainerXML($xml));
00556 }
00557
00558
00559
00560
00569 protected function processMapXML($xml) {
00570 return $this->processStandardTag($xml, $xml->tagName,
00571 $this->processMapContainerXML($xml), array('name' => $xml->getAttribute('name')));
00572 }
00573
00582 protected function processMapContainerXML($xml) {
00583 $children = $xml->childNodes;
00584 $content = "";
00585 foreach ($children as $child) {
00586 if ($child instanceof DOMElement) {
00587 switch($child->tagName) {
00588 case 'area':
00589 $content .= $this->processAreaXML($child);
00590 break;
00591 default:
00592 $this->warnUnexpectedTag('processMapContainerXML', $child,
00593 $xml->tagName, 'area');
00594 break;
00595 }
00596 } else {
00597 $this->warnInvalidMixedContent('processMapContainerXML', $child, 'area');
00598 }
00599 }
00600 return $content;
00601 }
00602
00603
00604
00605
00614 protected function processLinkXML($xml) {
00615 $aLinkAttributes = array();
00616
00617 if ($xml->getAttribute('metaid') != "") {
00618
00619
00620 $metaid = trim($xml->getAttribute('metaid'));
00621
00622 $aLinkAttributes['target'] = '_blank';
00623 $url = SDR::getURLForResourceId($metaid);
00624 if($this->getTranslator()->getInputOption('enable_link_info')) {
00625 if(!isset($GLOBALS['ss_js_loaded'])) {
00626 $GLOBALS['prm']->setOption('swatjs', true);
00627 $GLOBALS['prm']->loadJS("SWAT.use('LinkInfo');\n");
00628 $GLOBALS['ss_js_loaded'] = true;
00629 }
00630 $aLinkAttributes['onmouseover'] = 'LinkInfo.show(\'' . $url . '\', this, event)';
00631 $aLinkAttributes['onmousemove'] = 'LinkInfo.show(\'' . $url . '\', this, event)';
00632 }
00633 $rebasePatterns = $this->getTranslator()->getInputOption('cserdUrlMap');
00634 if(!is_array($rebasePatterns))
00635 $rebasePatterns = SConfig::getOption('pr2.cserdUrlMap');
00636 if(is_array($rebasePatterns) && count($rebasePatterns) > 0)
00637 $url = preg_replace(array_keys($rebasePatterns), array_values($rebasePatterns), $url);
00638 } else if($xml->getAttribute('snapid') != "") {
00639 $snapId = $xml->getAttribute('snapid');
00640 if(ctype_digit((string) $snapId))
00641 $res = SnapResource::retrieve($snapId);
00642 else
00643 $res = SnapResource::lookup($snapId);
00644
00645 if($res == null || $res->getId() <= 0)
00646 $this->setWarning("Invalid snap ID/path given: '$snapId'");
00647 else {
00648 $v = $res->getActiveVersion();
00649 if($v == null)
00650 $this->setWarning("No active version for Snap resource '$snapId'");
00651 else
00652 $url = $v->getContentModule()->getLinkURL();
00653 }
00654 } else if ($xml->getAttribute('href') != "") {
00655 // otherwise, consult the HREF tag on the link if it is not empty
00656 $url = $xml->getAttribute('href');
00657 $base = $xml->getAttribute('base');
00658 $url = $this->rebaseUrl($base, $url);
00659 }
00660 else if($xml->getAttribute('name') != "") {
00661 $aLinkAttributes['name'] = $xml->getAttribute('name');
00662 }
00663
00664 if($xml->getAttribute('where') != ""){
00665 $aLinkAttributes['target'] = $xml->getAttribute('where');
00666 }
00667
00668
00669 // if the URL has some content, then create a link tag.
00670 if (isset($url) && $url != "") {
00671 $aLinkAttributes['href'] = $url;
00672 $aLinkAttributes['class'] = 'realLink';
00673 } else if(!isset($aLinkAttributes['name'])) {
00674 // otherwise, just create a span that is styled to look like a broken link (unless this is an anchor tag, in which case, do nothing)
00675 return $this->processStandardTag($xml, "span",
00676 $this->processMixedContentContainerXML($xml),
00677 array('class' => 'brokenLink'));
00678 }
00679
00680 return $this->processStandardTag($xml, "a",
00681 $this->processMixedContentContainerXML($xml),
00682 $aLinkAttributes);
00683 }
00684
00693 protected function processLatexXML($xml) {
00694
00695 $render = new LatexRenderModule();
00696 return($render->transform($xml->nodeValue));
00697
00698 }
00699
00708 protected function processMediaXML($xml) {
00709 STimer::startAvg('processMedia');
00710 $class = $xml->getAttribute('class');
00711 $id = $xml->getAttribute('id');
00712 $snapid = trim($xml->getAttribute('snapid'));
00713 $which = trim($xml->getAttribute('which'));
00714 $ismap = $xml->getAttribute('ismap');
00715 $usemap = $xml->getAttribute('usemap');
00716 $width = $xml->getAttribute('width');
00717 $height = $xml->getAttribute('height');
00718 $embed = $xml->getAttribute('embed');
00719 $style = $xml->getAttribute('style');
00720 $alt = $xml->getAttribute('alt');
00721 $title = $xml->getAttribute('title');
00722 $view = $xml->getAttribute('view');
00723 if($which == "") {
00724 $which = "original";
00725 }
00726 if($view == "") {
00727 $view = "embed";
00728 }
00729 else if($view == "download") {
00730 $downloadMessage = $xml->nodeValue;
00731 if($downloadMessage == '')
00732 $downloadMessage = 'Download';
00733 }
00734 if(strpos($snapid, "/") !== false)
00735 $res = SnapResource::lookup($snapid);
00736 else if(ctype_digit((string) $snapid))
00737 $res = SnapResource::retrieve((int)$snapid);
00738 else {
00739 $this->setWarning('snapid in media tag is not numeric: "' . htmlentities($snapid) . '"');
00740 $res = null;
00741 }
00742
00743 if($res != null) {
00744 $version = $res->getActiveVersion();
00745
00746 if($version == null) {
00747 $html = false;
00748 $msg = "No content (no active version for resource '$snapid')";
00749 }
00750 else {
00751 $cm = $version->getContentModule();
00752
00753 $config = array('which' => $which);
00754 if($class != '') $config['class'] = $class;
00755 if($id != '') $config['id'] = $id;
00756 if($ismap != '') $config['ismap'] = $ismap;
00757 if($usemap != '') $config['usemap'] = $usemap;
00758 if($width != '') $config['width'] = $width;
00759 if($height != '') $config['height'] = $height;
00760 if($embed != '') $config['embed'] = $embed;
00761 if($style != '') $config['style'] = $style;
00762 if($alt != '') $config['alt'] = $alt;
00763 else $config['alt'] = SnapContentMediaImage::ALT_DESC;
00764 if($title != '') $config['title'] = $title;
00765
00766 if($view == 'embed') {
00767 $html = $cm->getHTML($config);
00768 if(!$html)
00769 $msg = $cm->getLastError();
00770 }
00771 else if($view == 'download')
00772 $html = '<a href="/media/download' . $res->getCanonicalPath() . '">' . $downloadMessage . '</a>';
00773 else {
00774 $html = false;
00775 $msg = 'Invalid view type: ' . $view;
00776 }
00777 }
00778 }
00779 else {
00780 $html = false;
00781 $msg = "No content (no such resource '$snapid')";
00782 }
00783
00784 if($html === false)
00785 $html = "<div style=\"padding: 4px; border: 1px solid black; "
00786 . "background-color: #E0E0E0; width: 8em; text-align: center;\">$msg</div>";
00787
00788 STimer::endAvg('processMedia');
00789 return $html;
00790 }
00791
00800 protected function processAreaXML($xml) {
00801 $url = $xml->getAttribute('href');
00802 $base = $xml->getAttribute('base');
00803 $url = $this->rebaseUrl($base, $url);
00804 $result = $this->processStandardTag($xml, 'area', '',
00805 array('class' => $xml->getAttribute('class'),
00806 'id' => $xml->getAttribute('id'),
00807 'alt' => $xml->getAttribute('alt'),
00808 'title' => $xml->getAttribute('title'),
00809 'shape' => $xml->getAttribute('shape'),
00810 'coords' => $xml->getAttribute('coords'),
00811 'href' => $url,
00812 'nohref' => $xml->getAttribute('nohref'),
00813 'target' => $xml->getAttribute('target'),
00814 'onmouseover' => $xml->getAttribute('onmouseover'),
00815 'onmouseout' => $xml->getAttribute('onmouseout')), true);
00816 return $result;
00817 }
00818
00827 protected function processBrXML($xml) {
00828 return $this->processStandardTag($xml, "br", "", array(), true);
00829 }
00830
00839 protected function processHrXML($xml) {
00840 return $this->processStandardTag($xml, "hr", "", array(), true);
00841 }
00842
00851 protected function processBoldXML($xml) {
00852 return $this->processStandardTag($xml, "b",
00853 $this->processMixedContentContainerXML($xml));
00854 }
00855
00864 protected function processItalicXML($xml) {
00865 return $this->processStandardTag($xml, "i",
00866 $this->processMixedContentContainerXML($xml));
00867 }
00868
00877 protected function processUnderlineXML($xml) {
00878 return $this->processStandardTag($xml, "u",
00879 $this->processMixedContentContainerXML($xml));
00880 }
00881
00890 protected function processSpanXML($xml) {
00891 return $this->processStandardTag($xml, "span",
00892 $this->processMixedContentContainerXML($xml));
00893 }
00894
00903 protected function processDivXML($xml) {
00904 return $this->processStandardTag($xml, "div",
00905 $this->processMixedContentContainerXML($xml));
00906 }
00907
00916 protected function processSubXML($xml) {
00917 return $this->processStandardTag($xml, "sub",
00918 $this->processMixedContentContainerXML($xml));
00919 }
00920
00929 protected function processSupXML($xml) {
00930 return $this->processStandardTag($xml, "sup",
00931 $this->processMixedContentContainerXML($xml));
00932 }
00933
00942 protected function processPreXML($xml) {
00943 return $this->processStandardTag($xml, "pre",
00944 $this->processMixedContentContainerXML($xml));
00945 }
00946
00947
00948 protected function processEntityXML($xml) {
00949 return '&' . $xml->nodeValue . ';';
00950 }
00951
00952
00953 /* -------------------------------------------------- */
00954 /* Functions that do all the common work of processing
00955 /* different tag types. */
00956 /* -------------------------------------------------- */
00957
00970 protected function processStandardTag($xml, $name, $content,
00971 $attrs = array(), $singleton = false) {
00972
00973 //build the HTML version of the attributes list
00974 $attrlist = "";
00975
00976 // if an ID is set on the XML tag, change the ID
00977 // of the output tag
00978 if ($xml->getAttribute('id') != "") {
00979 $attrs['id'] = $xml->getAttribute('id');
00980 }
00981
00982 if (isset($attrs['class'])){
00983 $attrs['class'] .= " ";
00984 } else {
00985 $attrs['class'] = "";
00986 }
00987 $attrs['class'] .= "StdXML3";
00988
00989 // add custom classes to the output tag
00990 // if they are specified on the XML tag
00991 if ($xml->getAttribute('class') != "") {
00992 if (isset($attrs['class']) && ($attrs['class'] != "")) {
00993 $attrs['class'] .= " " . $xml->getAttribute('class');
00994 } else {
00995 $attrs['class'] = $xml->getAttribute('class');
00996 }
00997 }
00998 foreach ($attrs as $key => $value) {
00999 $value = trim($value);
01000 if($value != '')
01001 $attrlist .= " $key=\"$value\"";
01002 }
01003
01004 // check to see if element is singleton
01005 if ($singleton) {
01006 return "<$name$attrlist />\n";
01007 } else {
01008 return "<$name$attrlist>" . $content . "</$name>";
01009 }
01010 }
01011
01022 protected function warnInvalidMixedContent($function, $node, $expected) {
01023 $value = trim($node->nodeValue);
01024 if ($value != "") {
01025 if(property_exists($node, 'tagName'))
01026 $tagName = $node->tagName;
01027 else
01028 $tagName = "???";
01029 $this->setPrettyWarning($function, 'Encountered unexpected mixed content inside a '
01030 . $tagName . ' tag. ' . $expected . ' expected.');
01031 }
01032 }
01033
01045 protected function warnUnexpectedTag($function, $node, $parent, $expected) {
01046 $this->setPrettyWarning($function, 'Encountered unexpected tag ' . $node->tagName .
01047 ' inside a ' . $parent . '. ' . $expected . ' expected.');
01048
01049 }
01050
01060 protected function rebaseUrl($base, $url) {
01061 if($base == '')
01062 return $url;
01063
01064 $info = explode(':', $base);
01065 // we can have, e.g.:
01066 // rel="PATH:activities" (generates href="$PATH[activities]$href")
01067 // rel="SPath:Project" (generates href="SPath::getFullPath('Project')/href")
01068 // so href should begin with a slash unless it intends to be glommed on directly to the base path
01069 if(count($info) != 2) {
01070 $this->setWarning('Invalid path source specification; ignoring');
01071 }
01072 else if($info[0] == 'PATH') {
01073 if(!isset($GLOBALS['PATH'][$info[1]])) {
01074 $this->setWarning('No such $PATH entry: ' . $info[1] . '; if you are in Snap2, ignore this warning');
01075 }
01076 else {
01077 $url = $GLOBALS['PATH'][$info[1]] . $url;
01078 }
01079 }
01080 else if($info[0] == 'SPath') {
01081 $base = SPath::getFullPath($info[1]);
01082 $url = "$base$url";
01083 }
01084 else {
01085 $this->setWarning('Invalid path source: "' . $info[0] . '"; ignoring');
01086 }
01087 return $url;
01088 }
01089
01090 /* ------------------------------------------------- */
01091 /* LIST TRANSLATION WORKER FUNCTIONS */
01092 /* ------------------------------------------------- */
01093
01094
01095
01096 /*-----------------------------------------------------*/
01097 /* Translate a given SInput album object
01098 /*-----------------------------------------------------*/
01099
01100 /* Most of this code is copied from translateList, below.
01101 /* This function takes every section tag with the "item" mapping
01102 /* and sends it through the translateAlbumUnit function, below.
01103 /* It currently does NOT through an error on incorrect tags, or
01104 /* section tags mapped as something besides "item". */
01115 public function translateAlbum ($xmlAlbum, $parentTrans, $si) {
01116 // check to see if the right root tag has been passed in.
01117 if ($xmlAlbum->tagName != 'XMLAlbum'){
01118 $this->setPrettyError('translate', 'Root XML tag is not XMLAlbum.');
01119 return false;
01120 }
01121
01122 $xml = simplexml_import_dom($xmlAlbum);
01123
01124 $htmlCollector = "";
01125
01126 //These arrays store the same information they store in the on-page javascript. All of this information is pulled from SNAP Media.
01127 $photoPaths = array();
01128 $thumbPaths = array();
01129 $photoWidths = array();
01130 $photoHeights = array();
01131 $photoCaptions = array();
01132 $downloadPaths = array();
01133
01134 foreach($xml->section as $albumUnit)
01135 {
01136 if ($albumUnit['mapping'] = 'item') {
01137 $photoAttributes = $this->translateAlbumUnit($albumUnit);
01138 //if(!$photoAttributes) {
01139 //print "FALSE";
01140 //} else {
01141 if ($photoAttributes != null) {
01142 $photoPaths[] = $photoAttributes[0];
01143 $thumbPaths[] = $photoAttributes[1];
01144 $downloadPaths[] = $photoAttributes[2];
01145 $photoWidths[] = $photoAttributes[3];
01146 $photoHeights[] = $photoAttributes[4];
01147 $photoCaptions[] = $photoAttributes[5];
01148 }
01149 }
01150 }
01151
01152 // I have included this variable because it is in the old code, but because I am using SNAP media fo the paths it won't change.
01153 $basePath = "";
01154
01155 $numberOfPhotos = count($photoPaths);
01156
01157
01158
01159 $thumbsScript = SPath::getRelPath('Common')
01160 . '/pr2/components/photothumbs.php5';
01161
01162
01163 if ($numberOfPhotos > 0) {
01164
01165 $uiPath = SPath::getRelPath('DefaultSkin');
01166
01167 $htmlIfAnyPhotos = <<<END
01168 <div class="scrollFrame">
01169 <iframe name="photoview{$this->albumNum}_thumbnails" src='$thumbsScript?pvid={$this->albumNum}&pcount=$numberOfPhotos&basepath=$basePath' frameborder="0" width="100%" height="80">Picture Thumbnails</iframe>
01170 </div>
01171 <div class="viewFrame" id="photoview{$this->albumNum}_viewframe">
01172 <center><img id="photoview{$this->albumNum}_image" src="$uiPath/images/black_spinner_lg.gif" alt="photo" style="width:12px;height:12px;" /></center>
01173 </div>
01174 <div class=controlFrame>
01175 <img id="photoview{$this->albumNum}_bigleft" src="$uiPath/images/leftarr.gif" class="bigArrow clickable" alt="Previous" style="float:left;margin-right:10px;" onclick="javascript:photolistPrev({$this->albumNum});" />
01176 <img id="photoview{$this->albumNum}_bigright" src="$uiPath/images/rightarr.gif" class="bigArrow clickable" alt="Next" style="float:right;margin-left:10px;" onclick="javascript:photolistNext({$this->albumNum});" />
01177 <span id="photoview{$this->albumNum}_caption" class="caption">
01178 </span><br style="clear:both;" />
01179 <span class="download"><small><a id="photoview{$this->albumNum}_download" href="#" target="_blank">[View Full Quality Image]</a></small></span><br style="clear:both;" />
01180 </div>
01181 END;
01182 } else {
01183 $htmlIfAnyPhotos = <<<END
01184 <div class="photoviewMessage">This collection of photos is not currently available.</div>
01185 END;
01186 }
01187
01188
01189
01190 $htmlCollector= <<<END_OF_TEXT
01191 <div class="photoviewContainer">
01192 <div class="photoviewBox">
01193
01194 $htmlIfAnyPhotos
01195
01196 </div>
01197 </div>
01198 END_OF_TEXT;
01199
01200 $parentTrans->sendToTarget($si, $htmlCollector);
01201
01202
01203 $parentTrans->getPage()->appendToSlot("ExtraJS", "var downloadPaths = [];" .
01204 "photoPaths[" . $this->albumNum . "] = new Array('"
01205 . implode("','",$photoPaths) . "');\n"
01206 . "thumbPaths[" . $this->albumNum . "] = new Array('"
01207 . implode("','",$thumbPaths) . "');\n"
01208 . "downloadPaths[" . $this->albumNum . "] = new Array('"
01209 . implode("','" , $downloadPaths) . "');\n"
01210 . "photoWidths[" . $this->albumNum . "] = new Array('"
01211 . implode("','",$photoWidths) . "');\n"
01212 . "photoHeights[" . $this->albumNum . "] = new Array('"
01213 . implode("','",$photoHeights) . "');\n"
01214 . "photoCaptions[" . $this->albumNum . "] = new Array('"
01215 . implode("','",$photoCaptions) . "');\n");
01216
01217
01218 $this->albumNum++;
01219
01220 return true;
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01238 public function translateAlbumUnit ($albumUnit) {
01239
01240
01241 $photoPath = "";
01242 $thumbPath = "";
01243 $photoWidth = "960";
01244 $photoHeight = "960";
01245 $photoCaption = "";
01246 $downloadPath = '';
01247
01248
01249 $photoFound = FALSE;
01250
01251 foreach($albumUnit->children() as $child) {
01252
01253
01254 if($child->getName() == 'sectionData') {
01255 if(!$photoFound) {
01256 $photoInformation = $this->translateSectionData($child);
01257 if($photoInformation) {
01258 $photoFound = TRUE;
01259 $photoPath = $photoInformation[0];
01260 $thumbPath = $photoInformation[1];
01261 $downloadPath = $photoInformation[2];
01262 $photoWidth = $photoInformation[3];
01263 $photoHeight = $photoInformation[4];
01264 }
01265 }
01266 } else {
01267
01268 $domChild = dom_import_simplexml($child);
01269 $tmpCaption = $this->processMixedContentContainerXML($domChild);
01270 $tmpCaption = $this->escapeForJavascriptOutput($tmpCaption);
01271 $photoCaption .= $tmpCaption;
01272 }
01273 }
01274
01275 if(!$photoFound) {
01276 $photoPath = '';
01277 $photoCaption = "<p><b>PHOTO NOT FOUND (IMAGES ONLY)</b></p>" . $photoCaption;
01278 return null;
01279 }
01280
01281
01282
01283
01284
01285 $photoInformation = array($photoPath, $thumbPath, $downloadPath, $photoWidth, $photoHeight, $photoCaption);
01286
01287 return $photoInformation;
01288 }
01289
01290
01291
01300 public function translateSectionData ($sectionDataTag) {
01301 foreach($sectionDataTag->children() as $child) {
01302 if($child->getName() == "media") {
01303 $cm = NULL;
01304
01305 $sectionAttributes = $child->attributes();
01306 $snapid = $sectionAttributes["snapid"];
01307
01308 if(strpos($snapid, "/") === false) {
01309 $res = SnapResource::retrieve((int)$snapid);
01310 } else {
01311 $res = SnapResource::lookup($snapid);
01312 }
01313
01314
01315 if($res) {
01316 $version = $res->getActiveVersion();
01317 if($version)
01318 $cm = $version->getContentModule();
01319 }
01320 }
01321
01322
01323 if(isset($cm) && $cm->getName() == 'Media Image') {
01324
01325 $photoAttributes = array($cm->getURL('display'), $cm->getURL('thumb'), $cm->getURL('original'), $cm->getWidth(), $cm->getHeight());
01326 return $photoAttributes;
01327 }
01328 }
01329
01330 return FALSE;
01331 }
01332
01333
01334
01335 function escapeForJavascriptOutput($text)
01336 {
01337 $text = str_replace("\"", "“", $text);
01338 $text = str_replace("\'", "‘", $text);
01339 $text = preg_replace("/\n|\r|\t/", "", $text);
01340 $text = addSlashes($text);
01341 return $text;
01342 }
01343
01344
01345
01346
01357 public function translateList ($xmlList, $parentTrans, $si) {
01358
01359
01360 if ($xmlList->tagName != 'XMLList'){
01361 $this->setPrettyError('translate', 'Root XML tag is not XMLList.');
01362 return false;
01363 }
01364
01365 $parentTrans->setOption('thumbnailWidth', 150);
01366 $parentTrans->setOption('thumbnailHeight', 80);
01367 $parentTrans->setOption('showCategoryLinks', true);
01368 $parentTrans->setOption('showSearchBox', true);
01369
01370 $xml = simplexml_import_dom($xmlList);
01371
01372
01373 $this->listItemCount = 0;
01374 $this->catCount = 0;
01375 $this->jsBuf = "";
01376 $this->catBuf = array();
01377 $this->catIdBuf = array();
01378 $this->catCountBuf = array();
01379 $this->curPrefix = "listing" . $this->listNum;
01380
01381
01382 $collect =<<<END_TABLE
01383
01384 <div id="$this->curPrefix" class="Listing">
01385 END_TABLE;
01386
01387
01388
01389 foreach($xml->section as $curUnit)
01390 {
01391 if ($curUnit['mapping'] = 'category')
01392 $collect .= $this->translateListUnit($curUnit);
01393 }
01394 $collect .= "<div id=\"$this->curPrefix" . "_noresults" . "\" class=\"listingNoResults\"><div>No Results Found</div></div>";
01395 $collect .= "</div>";
01396
01397
01398 $queryName = $this->curPrefix . "query";
01399 $queryResultsName = $queryName . "_results";
01400 $searchBox = ($parentTrans->getOption('showSearchBox')) ? <<<END_SEARCHBOX
01401 <table class="ListingQuery" border="0"><tr><td><span class="queryContainer"><input type="text" id="$queryName" value="Search this list"
01402 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>
01403 END_SEARCHBOX
01404 : "";
01405
01406
01407 array_push($this->catBuf, <<<END_LIST_BOX
01408 <a href="javascript:listAll('$this->curPrefix');" style="font-weight:bold">Show All</a>
01409 END_LIST_BOX
01410 );
01411 $categoriesList = ($parentTrans->getOption('showCategoryLinks')) ? '<div class="CategoryLinks"><span class="categoryLinksContainer">' . implode(' • ', $this->catBuf) . "</span></div>" : "";
01412
01413
01414 $parentTrans->sendToTarget($si, $searchBox . $categoriesList . $collect);
01415
01416 $collectJS = "listings[$this->listNum] = new listing('$this->curPrefix',new Array(";
01417 $collectJSArr = array();
01418 for($i=0;$i<count($this->catIdBuf);$i++)
01419 {array_push($collectJSArr, "new ctg('" . $this->catIdBuf[$i] . "'," . $this->catCountBuf[$i] . ")"); }
01420 $collectJS .= implode(",", $collectJSArr);
01421 $collectJS .= "));";
01422 $parentTrans->getPage()->appendToSlot('ExtraJS', <<<END_JS
01423 queries[$this->listNum]='$queryName';queryValues[$this->listNum]='-1';
01424 $collectJS
01425 END_JS
01426 );
01427 $parentTrans->getPage()->appendToSlot('OnLoad', "setTimeout('queryLists();', 300);");
01428
01429
01430 $this->listNum++;
01431
01432 return true;
01433 }
01434
01435
01436
01437
01446 protected function translateListUnit ($curUnit)
01447 {
01448 if (!isset($curUnit->name)) {
01449 $this->setPrettyError('translate', '<section> XML tag missing a child <name> tag.');
01450 return false;
01451 }
01452
01453 $id = $this->curPrefix . "_ctg" . $this->catCount;
01454 $countid = $id . "_count";
01455 $headid = $id . "_header";
01456
01457 array_push($this->catIdBuf, $id);
01458 array_push($this->catBuf, <<<END_LINK
01459 <a href="javascript:listCat('$this->curPrefix',$this->catCount);">$curUnit->name</a>
01460 END_LINK
01461 );
01462
01463
01464 $collect = "<div id=\"$id\">";
01465 $collect .= <<<END_HEADER
01466
01467 <div class="listingHeader" id="$headid"><span class="listingHeaderText">$curUnit->name <span id="$countid">(...)</span></span></div>
01468 END_HEADER;
01469 $this->firstInSection = true;
01470 $localcount = 0;
01471 $this->countByCat = 0;
01472 foreach($curUnit->section as $page)
01473 {
01474 if ($page['mapping'] == 'item'){
01475 $collect .= $this->translateListPage($page);
01476 $this->listItemCount++;
01477 $this->firstInSection = false;
01478 $localcount++;
01479 $this->countByCat++;
01480 }
01481 }
01482 $collect .= "</div>";
01483
01484
01485 array_push($this->catCountBuf, $localcount);
01486 $this->catCount++;
01487 return $collect;
01488 }
01489
01490
01491
01492
01501 protected function translateListPage ($page)
01502 {
01503 $pageStyleClass = $pageStyleId = "";
01504
01505 $class = ($this->isEvenRow()) ? "evenRow" : "oddRow";
01506 $class .= ($this->isFirstInSection()) ? " firstInSection" : "";
01507
01508
01509 $content = "";
01510
01511 $doc = SXMLHelper::parse($page->asXML(), true);
01512 if(!$doc)
01513 return false;
01514
01515 foreach($doc->childNodes as $child) {
01516 $content .= $this->processBlockLevelElementContainerXML($child);
01517 }
01518
01519 if($page->listItemData->class) {
01520 $pageStyleClass .= " " . $page->listItemData->class . ' ';
01521 }
01522
01523
01524 if (!isset($page->name)) {
01525 $this->setPrettyError('translate', 'XML <section> item tag missing a <name> tag.');
01526 return false;
01527 }
01528
01529
01530 $pageName = $page->name;
01531
01532
01533
01534
01535
01536 $dataTag = 'sectionData';
01537 if(!isset($page->sectionData) && isset($page->listItemData))
01538 $dataTag = 'listItemData';
01539
01540 $link = "";
01541
01542 if (isset($page->$dataTag->link))
01543 {
01544 $link = $page->$dataTag->link['href'];
01545 $linkStart = "<a href=\"$link\">";
01546 $linkEnd = "</a>";
01547 } else { $linkStart = $linkEnd = ""; }
01548
01549 $thumbnail = "";
01550 if (isset($page->$dataTag)){
01551
01552
01553 if (isset($page->$dataTag->media))
01554 {
01555 $snapid = $page->$dataTag->media['snapid'];
01556 if($page->$dataTag->media['which'])
01557 $which = $page->$dataTag->media['which'];
01558 else
01559 $which = 'thumb';
01560
01561 if(strpos($snapid, "/") !== false)
01562 $res = SnapResource::lookup($snapid);
01563 else {
01564 $res = SnapResource::retrieve((int)$snapid);
01565 }
01566
01567 $imgURL = "";
01568
01569 if($res != null) {
01570 $version = $res->getActiveVersion();
01571 if($version != null) {
01572 $imgURL = $version->getContentModule()->getURL($which);
01573 $imgURL = $version->getContentModule()->getURL($which);
01574 }
01575 }
01576
01577 $linkThumbClass = "";
01578 if ($link == ""){ $thumblink = "";}
01579 else { $thumblink = " onclick=\"location.href='$link';\" "; $linkThumbClass = "clickable"; }
01580
01581
01582 $thumbnail = <<<END_THUMB
01583 <div class="thumbnail $linkThumbClass" style="background-image:url('$imgURL');" $thumblink > </div>
01584 END_THUMB;
01585
01586 }
01587
01588
01589 if (isset($page->$dataTag->style)) {
01590 $style = $page->$dataTag->style;
01591
01592
01593 if (isset($style['class'])) {
01594 $pageStyleClass = $style['class'];
01595 }
01596
01597 if (isset($style['id'])) {
01598 $pageStyleId = ' id="' . $stype['id'] .'" ';
01599 }
01600 }
01601
01602 }
01603
01604 $collect = "";
01605 $id = $this->curPrefix . "_" . "ctg" . $this->catCount . "_" . $this->countByCat;
01606 $collect .= <<<END_ROW
01607
01608 <div class="$class" id="$id">
01609 <div class="rowContainer $pageStyleClass" $pageStyleId>
01610 <div class="rowTitle">$thumbnail$linkStart$pageName$linkEnd</div>
01611 <div class="rowContent">$content</div><br style="clear:both;"/>
01612 </div></div>
01613 END_ROW;
01614 return $collect;
01615 }
01616
01617
01618
01619
01620
01621 protected function isEvenRow ()
01622 { return ($this->listItemCount % 2 == 0); }
01623
01624 protected function isFirstInSection ()
01625 { return ($this->firstInSection); }
01626 }
01627
01628
01629
01630 ?>