00001 <?php
00002
00008 class STransHTMLMedia extends STransHTML {
00015 private function replaceMediaTag($tag) {
00016 $doc = new DOMDocument();
00017 $doc->loadXML($tag[0]);
00018 if(!is_object($doc->documentElement))
00019 return "ERROR";
00020
00021 $tagName = $tag[1];
00022
00023 $snapid = trim($doc->documentElement->getAttribute("snapid"));
00024
00025 $attrs = array();
00026
00027 if($doc->documentElement->hasAttribute("which"))
00028 $attrs['which'] = $doc->documentElement->getAttribute("which");
00029 else
00030 $attrs['which'] = "original";
00031
00032 if($doc->documentElement->hasAttribute('class'))
00033 $attrs['class'] = $doc->documentElement->getAttribute('class');
00034 if(strpos($snapid, "/") !== false)
00035 $res = SnapResource::lookup($snapid);
00036 else {
00037 $res = SnapResource::retrieve($snapid);
00038 }
00039 if($res != null) {
00040 $version = $res->getActiveVersion();
00041
00042 if($version == null) {
00043 $html = false;
00044 $msg = "No content (no active version for resource '$snapid')";
00045 }
00046 else {
00047 $html = $version->getContentModule()->getHTML($attrs);
00048 if($html === false)
00049 $msg = $version->getContentModule()->getLastError();
00050 }
00051 }
00052 else {
00053 $html = false;
00054 $msg = "No content (no such resource '$snapid')";
00055 }
00056
00057 if($html === false)
00058 $html = "<div style=\"padding: 4px; border: 1px solid black; "
00059 . "background-color: #E0E0E0; width: 8em; text-align: center;\">$msg</div>";
00060
00061 return $html;
00062 }
00063
00068 public function translate($si) {
00069 $input = $si->getSource();
00070
00071 if($input instanceof SnapContent)
00072 $input = $input->getHTML();
00073
00074 $output = preg_replace_callback("/(<(media|content)\s*[^>]*>)/", array($this, 'replaceMediaTag'), $input);
00075 $this->sendToTarget($si, $output);
00076
00077 return true;
00078 }
00079 }
00080
00081 ?>