00001 <?PHP 00017 include_once("Element.php"); 00018 00029 class HTMLPreview extends Element 00030 { 00031 public $m_FieldName; 00032 public $m_Label; 00033 public $m_DisplayFormat; 00034 public $m_Text; 00035 public $m_Link; 00036 public $m_Target; 00037 public $m_MaxLength; 00038 public $m_Percent; 00045 protected function readMetaData(&$xmlArr) 00046 { 00047 parent::readMetaData($xmlArr); 00048 $this->m_FieldName = isset($xmlArr["ATTRIBUTES"]["FIELDNAME"]) ? $xmlArr["ATTRIBUTES"]["FIELDNAME"] : null; 00049 $this->m_Label = isset($xmlArr["ATTRIBUTES"]["LABEL"]) ? $xmlArr["ATTRIBUTES"]["LABEL"] : null; 00050 $this->m_Text = isset($xmlArr["ATTRIBUTES"]["TEXT"]) ? $xmlArr["ATTRIBUTES"]["TEXT"] : null; 00051 $this->m_Link = isset($xmlArr["ATTRIBUTES"]["LINK"]) ? $xmlArr["ATTRIBUTES"]["LINK"] : null; 00052 $this->m_Target = isset($xmlArr["ATTRIBUTES"]["TARGET"]) ? $xmlArr["ATTRIBUTES"]["TARGET"] : null; 00053 $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGHT"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGHT"] : null; 00054 $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGTH"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGTH"] : null; 00055 $this->m_Percent = isset($xmlArr["ATTRIBUTES"]["PERCENT"]) ? $xmlArr["ATTRIBUTES"]["PERCENT"] : "N"; 00056 $this->m_DisplayFormat = isset($xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"]) ? $xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"] : null; 00057 } 00058 00065 protected function getTarget() 00066 { 00067 if ($this->m_Target == null) 00068 return null; 00069 00070 return "target='" . $this->m_Target ."'"; 00071 ; 00072 } 00073 00079 protected function getLink() 00080 { 00081 if ($this->m_Link == null) 00082 return null; 00083 $formobj = $this->getFormObj(); 00084 return Expression::evaluateExpression($this->m_Link, $formobj); 00085 } 00086 00092 protected function getText() 00093 { 00094 if ($this->m_Text == null) 00095 return null; 00096 $formObj = $this->getFormObj(); 00097 return Expression::evaluateExpression($this->m_Text, $formObj); 00098 } 00099 00105 public function renderLabel() 00106 { 00107 return $this->m_Label; 00108 } 00109 00115 public function render() 00116 { 00117 $value = $this->m_Text ? $this->getText() : $this->m_Value; 00118 00119 if ($value == null || $value =="") 00120 return ""; 00121 00122 $style = $this->getStyle(); 00123 $id = $this->m_Name; 00124 $func = $this->getFunction(); 00125 00126 if ($this->m_Translatable == 'Y') 00127 $value = $this->translateString($value); 00128 $value_org = strip_tags($value); 00129 if((int)$this->m_MaxLength>0){ 00130 if(function_exists('mb_strlen') && function_exists('mb_substr')){ 00131 if(mb_strlen($value,'UTF8') > (int)$this->m_MaxLength){ 00132 $value = mb_substr($value,0,(int)$this->m_MaxLength,'UTF8').'...'; 00133 } 00134 }else{ 00135 if(strlen($value) > (int)$this->m_MaxLength){ 00136 $value = substr($value,0,(int)$this->m_MaxLength).'...'; 00137 } 00138 } 00139 } 00140 if($this->m_Height) 00141 { 00142 $height = $this->m_Height.'px'; 00143 } 00144 if ($value!=null) 00145 { 00146 $header = " 00147 <head><link href=\"".JS_URL."/ckeditor/contents.css\" rel=\"stylesheet\" type=\"text/css\"></head> 00148 "; 00149 $sHTML = " 00150 <script>".$id."_data=".json_encode($header.$value)."</script> 00151 <iframe border=\"0\" frameborder=\"0\" allowtransparency=\"true\" 00152 tabIndex=\"-1\" style=\"width:100%;height:$height;background: none repeat scroll 0 0 transparent;border: 0 none;border-collapse: collapse;\" 00153 src=\"javascript:setTimeout(%20function()%7Bdocument.open()%3Bdocument.write(%20window.parent%5B%20%22".$id."_data%22%20%5D%20)%3Bdocument.close()%3Bwindow.parent%5B%20%22".$id."_data%22%20%5D%20%3D%20null%3B%7D%2C%20200%20)\"> 00154 </iframe> 00155 "; 00156 00157 } 00158 00159 return $sHTML; 00160 } 00161 00162 } 00163 00164 ?>