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