1<?php 2 3/** 4 * A FeedHtmlField describes and generates 5 * a feed, item or image html field (probably a description). Output is 6 * generated based on $truncSize, $syndicateHtml properties. 7 * 8 * @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info> 9 * @version 1.6 10 * @package de.bitfolge.feedcreator 11 */ 12class FeedHtmlField 13{ 14 /** 15 * Mandatory attributes of a FeedHtmlField. 16 */ 17 protected $rawFieldContent; 18 19 /** 20 * Optional attributes of a FeedHtmlField. 21 */ 22 public $truncSize, $syndicateHtml; 23 24 /** 25 * Creates a new instance of FeedHtmlField. 26 * 27 * @param string $parFieldContent if given, sets the rawFieldContent property 28 */ 29 public function __construct($parFieldContent) 30 { 31 if ($parFieldContent) { 32 $this->rawFieldContent = $parFieldContent; 33 } 34 } 35 36 /** 37 * Creates the right output, depending on $truncSize, $syndicateHtml properties. 38 * 39 * @return string the formatted field 40 */ 41 public function output() 42 { 43 // when field available and syndicated in html we assume 44 // - valid html in $rawFieldContent and we enclose in CDATA tags 45 // - no truncation (truncating risks producing invalid html) 46 if (!$this->rawFieldContent) { 47 $result = ""; 48 } elseif ($this->syndicateHtml) { 49 $result = "<![CDATA[".$this->rawFieldContent."]]>"; 50 } else { 51 if ($this->truncSize and is_int($this->truncSize)) { 52 $result = FeedCreator::iTrunc(htmlspecialchars($this->rawFieldContent), $this->truncSize); 53 } else { 54 $result = htmlspecialchars($this->rawFieldContent); 55 } 56 } 57 58 return $result; 59 } 60} 61