PageRenderTime 156ms CodeModel.GetById 145ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/cubi/openbiz/bin/easy/element/HTMLPreview.php

http://openbiz-cubi.googlecode.com/
PHP | 164 lines | 92 code | 15 blank | 57 comment | 18 complexity | ee49f43ebcc1203f7ec36eec5bfebd6f MD5 | raw file
  1<?PHP
  2/**
  3 * PHPOpenBiz Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 *
 10 * @package   openbiz.bin.easy.element
 11 * @copyright Copyright (c) 2005-2011, Rocky Swen
 12 * @license   http://www.opensource.org/licenses/bsd-license.php
 13 * @link      http://www.phpopenbiz.org/
 14 * @version   $Id: LabelList.php 543 2009-10-03 08:50:00Z mr_a_ton$
 15 */
 16
 17//include_once("Element.php");
 18
 19/**
 20 * LebelText - class LabelText is element that view value who binds
 21 * with a BizField
 22 *
 23 * @package openbiz.bin.easy.element
 24 * @author Rocky Swen
 25 * @copyright Copyright (c) 2009
 26 * @version 1.0
 27 * @access public
 28 */
 29class HTMLPreview extends Element
 30{
 31    public $m_FieldName;
 32    public $m_Label;
 33    public $m_DisplayFormat;
 34    public $m_Text;
 35    public $m_Link;    
 36    public $m_Target;
 37    public $m_MaxLength;
 38    public $m_Percent;
 39    /**
 40     * Read array meta data, and store to meta object
 41     *
 42     * @param array $xmlArr
 43     * @return void
 44     */
 45    protected function readMetaData(&$xmlArr)
 46    {
 47        parent::readMetaData($xmlArr);
 48        $this->m_FieldName = isset($xmlArr["ATTRIBUTES"]["FIELDNAME"]) ? $xmlArr["ATTRIBUTES"]["FIELDNAME"] : null;
 49        $this->m_Label = isset($xmlArr["ATTRIBUTES"]["LABEL"]) ? $xmlArr["ATTRIBUTES"]["LABEL"] : null;
 50        $this->m_Text = isset($xmlArr["ATTRIBUTES"]["TEXT"]) ? $xmlArr["ATTRIBUTES"]["TEXT"] : null;
 51        $this->m_Link = isset($xmlArr["ATTRIBUTES"]["LINK"]) ? $xmlArr["ATTRIBUTES"]["LINK"] : null;
 52        $this->m_Target = isset($xmlArr["ATTRIBUTES"]["TARGET"]) ? $xmlArr["ATTRIBUTES"]["TARGET"] : null;
 53        $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGHT"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGHT"] : null;
 54        $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGTH"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGTH"] : null;
 55        $this->m_Percent = isset($xmlArr["ATTRIBUTES"]["PERCENT"]) ? $xmlArr["ATTRIBUTES"]["PERCENT"] : "N";
 56        $this->m_DisplayFormat = isset($xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"]) ? $xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"] : null;
 57    }
 58
 59    /**
 60     * Get target of link
 61     * <a target='...'>...</a>
 62     *
 63     * @return string
 64     */
 65    protected function getTarget()
 66    {
 67        if ($this->m_Target == null)
 68            return null;
 69
 70        return "target='" . $this->m_Target ."'";
 71        ;
 72    }
 73
 74    /**
 75     * Get link of LabelText
 76     *
 77     * @return string
 78     */
 79    protected function getLink()
 80    {
 81        if ($this->m_Link == null)
 82            return null;
 83        $formobj = $this->getFormObj();
 84        return Expression::evaluateExpression($this->m_Link, $formobj);
 85    }
 86
 87    /**
 88     * Get text of label
 89     *
 90     * @return string
 91     */
 92    protected function getText()
 93    {
 94        if ($this->m_Text == null)
 95            return null;   
 96        $formObj = $this->getFormObj();
 97        return Expression::evaluateExpression($this->m_Text, $formObj);
 98    }
 99    
100    /**
101     * Render label
102     *
103     * @return string HTML text
104     */
105    public function renderLabel()
106    {
107        return $this->m_Label;
108    }
109
110    /**
111     * Render, draw the element according to the mode
112     *
113     * @return string HTML text
114     */
115    public function render()
116    {
117        $value = $this->m_Text ? $this->getText() : $this->m_Value;
118        
119        if ($value == null || $value =="")
120            return "";
121
122        $style = $this->getStyle();
123        $id = $this->m_Name;
124        $func = $this->getFunction();
125
126        if ($this->m_Translatable == 'Y')
127            $value = $this->translateString($value);
128        $value_org = strip_tags($value);
129        if((int)$this->m_MaxLength>0){
130	        if(function_exists('mb_strlen') && function_exists('mb_substr')){
131	        	if(mb_strlen($value,'UTF8') > (int)$this->m_MaxLength){
132	        		$value = mb_substr($value,0,(int)$this->m_MaxLength,'UTF8').'...';
133	        	}        	
134	        }else{
135	        	if(strlen($value) > (int)$this->m_MaxLength){
136	        		$value = substr($value,0,(int)$this->m_MaxLength).'...';
137	        	}         	
138	        }
139        }
140        if($this->m_Height)
141        {
142        	$height = $this->m_Height.'px';
143        }
144        if ($value!=null)
145        {
146        	$header = "
147        	<head><link href=\"".JS_URL."/ckeditor/contents.css\" rel=\"stylesheet\" type=\"text/css\"></head>
148        	";
149           $sHTML = "
150           			<script>".$id."_data=".json_encode($header.$value)."</script>
151           			<iframe border=\"0\" frameborder=\"0\" allowtransparency=\"true\"
152           				tabIndex=\"-1\" style=\"width:100%;height:$height;background: none repeat scroll 0 0 transparent;border: 0 none;border-collapse: collapse;\"
153           				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)\">
154           			</iframe>
155           			";
156            
157        }
158
159        return $sHTML;
160    }
161
162}
163
164?>