PageRenderTime 74ms CodeModel.GetById 25ms RepoModel.GetById 1ms 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
Possible License(s): GPL-2.0, LGPL-3.0
  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. //include_once("Element.php");
  17. /**
  18. * LebelText - class LabelText is element that view value who binds
  19. * with a BizField
  20. *
  21. * @package openbiz.bin.easy.element
  22. * @author Rocky Swen
  23. * @copyright Copyright (c) 2009
  24. * @version 1.0
  25. * @access public
  26. */
  27. class HTMLPreview extends Element
  28. {
  29. public $m_FieldName;
  30. public $m_Label;
  31. public $m_DisplayFormat;
  32. public $m_Text;
  33. public $m_Link;
  34. public $m_Target;
  35. public $m_MaxLength;
  36. public $m_Percent;
  37. /**
  38. * Read array meta data, and store to meta object
  39. *
  40. * @param array $xmlArr
  41. * @return void
  42. */
  43. protected function readMetaData(&$xmlArr)
  44. {
  45. parent::readMetaData($xmlArr);
  46. $this->m_FieldName = isset($xmlArr["ATTRIBUTES"]["FIELDNAME"]) ? $xmlArr["ATTRIBUTES"]["FIELDNAME"] : null;
  47. $this->m_Label = isset($xmlArr["ATTRIBUTES"]["LABEL"]) ? $xmlArr["ATTRIBUTES"]["LABEL"] : null;
  48. $this->m_Text = isset($xmlArr["ATTRIBUTES"]["TEXT"]) ? $xmlArr["ATTRIBUTES"]["TEXT"] : null;
  49. $this->m_Link = isset($xmlArr["ATTRIBUTES"]["LINK"]) ? $xmlArr["ATTRIBUTES"]["LINK"] : null;
  50. $this->m_Target = isset($xmlArr["ATTRIBUTES"]["TARGET"]) ? $xmlArr["ATTRIBUTES"]["TARGET"] : null;
  51. $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGHT"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGHT"] : null;
  52. $this->m_MaxLength = isset($xmlArr["ATTRIBUTES"]["MAXLENGTH"]) ? $xmlArr["ATTRIBUTES"]["MAXLENGTH"] : null;
  53. $this->m_Percent = isset($xmlArr["ATTRIBUTES"]["PERCENT"]) ? $xmlArr["ATTRIBUTES"]["PERCENT"] : "N";
  54. $this->m_DisplayFormat = isset($xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"]) ? $xmlArr["ATTRIBUTES"]["DISPLAYFORMAT"] : null;
  55. }
  56. /**
  57. * Get target of link
  58. * <a target='...'>...</a>
  59. *
  60. * @return string
  61. */
  62. protected function getTarget()
  63. {
  64. if ($this->m_Target == null)
  65. return null;
  66. return "target='" . $this->m_Target ."'";
  67. ;
  68. }
  69. /**
  70. * Get link of LabelText
  71. *
  72. * @return string
  73. */
  74. protected function getLink()
  75. {
  76. if ($this->m_Link == null)
  77. return null;
  78. $formobj = $this->getFormObj();
  79. return Expression::evaluateExpression($this->m_Link, $formobj);
  80. }
  81. /**
  82. * Get text of label
  83. *
  84. * @return string
  85. */
  86. protected function getText()
  87. {
  88. if ($this->m_Text == null)
  89. return null;
  90. $formObj = $this->getFormObj();
  91. return Expression::evaluateExpression($this->m_Text, $formObj);
  92. }
  93. /**
  94. * Render label
  95. *
  96. * @return string HTML text
  97. */
  98. public function renderLabel()
  99. {
  100. return $this->m_Label;
  101. }
  102. /**
  103. * Render, draw the element according to the mode
  104. *
  105. * @return string HTML text
  106. */
  107. public function render()
  108. {
  109. $value = $this->m_Text ? $this->getText() : $this->m_Value;
  110. if ($value == null || $value =="")
  111. return "";
  112. $style = $this->getStyle();
  113. $id = $this->m_Name;
  114. $func = $this->getFunction();
  115. if ($this->m_Translatable == 'Y')
  116. $value = $this->translateString($value);
  117. $value_org = strip_tags($value);
  118. if((int)$this->m_MaxLength>0){
  119. if(function_exists('mb_strlen') && function_exists('mb_substr')){
  120. if(mb_strlen($value,'UTF8') > (int)$this->m_MaxLength){
  121. $value = mb_substr($value,0,(int)$this->m_MaxLength,'UTF8').'...';
  122. }
  123. }else{
  124. if(strlen($value) > (int)$this->m_MaxLength){
  125. $value = substr($value,0,(int)$this->m_MaxLength).'...';
  126. }
  127. }
  128. }
  129. if($this->m_Height)
  130. {
  131. $height = $this->m_Height.'px';
  132. }
  133. if ($value!=null)
  134. {
  135. $header = "
  136. <head><link href=\"".JS_URL."/ckeditor/contents.css\" rel=\"stylesheet\" type=\"text/css\"></head>
  137. ";
  138. $sHTML = "
  139. <script>".$id."_data=".json_encode($header.$value)."</script>
  140. <iframe border=\"0\" frameborder=\"0\" allowtransparency=\"true\"
  141. tabIndex=\"-1\" style=\"width:100%;height:$height;background: none repeat scroll 0 0 transparent;border: 0 none;border-collapse: collapse;\"
  142. 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)\">
  143. </iframe>
  144. ";
  145. }
  146. return $sHTML;
  147. }
  148. }
  149. ?>