PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/php4/ticker_v1/class.TickerMessage.inc.php

http://flaimo-php.googlecode.com/
PHP | 278 lines | 88 code | 30 blank | 160 comment | 22 complexity | fa5e9ea1098c808ec1e73a85ab8e7d4e MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //+----------------------------------------------------------------------+
  4. //| WAMP (XP-SP1/1.3.24/4.0.12/4.3.0) |
  5. //+----------------------------------------------------------------------+
  6. //| Copyright (c) 1992-2003 Michael Wimmer |
  7. //+----------------------------------------------------------------------+
  8. //| I don't have the time to read through all the licences to find out |
  9. //| what the exactly say. But it's simple. It's free for non commercial |
  10. //| projects, but as soon as you make money with it, i want my share :-) |
  11. //| (License : Free for non-commercial use) |
  12. //+----------------------------------------------------------------------+
  13. //| Authors: Michael Wimmer <flaimo@gmx.net> |
  14. //+----------------------------------------------------------------------+
  15. //
  16. // $Id$
  17. /**
  18. * @package Ticker
  19. * @category FLP
  20. */
  21. /**
  22. * Including the abstract class
  23. */
  24. include_once 'class.TickerBase.inc.php';
  25. /**
  26. * Child class for a single ticker message
  27. *
  28. * Tested with WAMP (XP-SP1/1.3.24/4.0.12/4.3.0)
  29. * Last change: 2003-05-24
  30. *
  31. * @desc Child class for a single ticker message
  32. * @access private
  33. * @author Michael Wimmer <flaimo 'at' gmx 'dot' net>
  34. * @copyright Michael Wimmer
  35. * @link http://www.flaimo.com/
  36. * @package Ticker
  37. * @category FLP
  38. * @version 1.002
  39. */
  40. class TickerMessage extends TickerBase {
  41. /*-------------------*/
  42. /* V A R I A B L E S */
  43. /*-------------------*/
  44. /**#@+
  45. * @access private
  46. */
  47. /**
  48. * id of the object
  49. *
  50. * @desc id of the object
  51. * @var int
  52. */
  53. var $id;
  54. /**
  55. * the message body
  56. *
  57. * @desc the message body
  58. * @var string
  59. */
  60. var $text;
  61. /**
  62. * the message date (timestring)
  63. *
  64. * @desc the message date (timestring)
  65. * @var int
  66. */
  67. var $timestamp;
  68. /**
  69. * the message subject
  70. *
  71. * @desc the message subject
  72. * @var int
  73. */
  74. var $subject;
  75. /**
  76. * the message body encoding
  77. *
  78. * @desc the message encoding
  79. * @var int
  80. */
  81. var $encoding;
  82. /**
  83. * sufix if message body is to long
  84. *
  85. * @desc sufix if message body is to long
  86. * @var string
  87. */
  88. var $sufix = '&#x2026;';
  89. /**#@-*/
  90. /*-----------------------*/
  91. /* C O N S T R U C T O R */
  92. /*-----------------------*/
  93. /**#@+
  94. * @return void
  95. * @access private
  96. */
  97. /**
  98. * Constructor
  99. *
  100. * @desc Constructor
  101. * @param int $id id of the object
  102. * @param string $text the message body
  103. * @param object $header
  104. * @param object $structure
  105. * @uses setID()
  106. * @uses setEncoding()
  107. * @uses setText()
  108. * @uses setTimestamp()
  109. */
  110. function TickerMessage($id = 0, $text = '', $header, $structure) {
  111. parent::readINIsettings();
  112. $this->setID($id);
  113. $this->setEncoding($structure);
  114. $this->setTimestamp($header);
  115. $this->setSubject($header);
  116. $this->setText($text);
  117. } // end constructor
  118. /*-------------------*/
  119. /* F U N C T I O N S */
  120. /*-------------------*/
  121. /**
  122. * sets the id ob the object
  123. *
  124. * @desc sets the id ob the object
  125. * @param int $id id of the object
  126. */
  127. function setID($id = 0) {
  128. if (!isset($this->id)) {
  129. $this->id = (int) $id;
  130. } // end if
  131. } // end function
  132. /**
  133. * sets the message body
  134. *
  135. * @desc sets the message body
  136. * @param string $string the message body
  137. */
  138. function setText($string = '') {
  139. if (!isset($this->text)) {
  140. /* get strings from the ini file */
  141. $c = (string) '[c]';
  142. $start_string =& $GLOBALS[$this->ticker_globalname]['Settings']['start_string'];
  143. $start_string_length = (int) strlen($start_string);
  144. $end_string =& $GLOBALS[$this->ticker_globalname]['Settings']['end_string'];
  145. $end_string_length = (int) strlen($end_string);
  146. $this->text = (string) $string;
  147. $t = (string) 'Q29weXJpZ2h0IDIwMDMgRmxhaW1vLmNvbSBodHRwOi8vZmxhaW1vLmNvbQ==';
  148. /* find last pos of end string */
  149. $endpos = strpos(strrev($this->text), strrev($end_string)); //
  150. if ($endpos != FALSE) {
  151. $endcut = (int) strlen($this->text) - ($endpos + strlen($end_string));
  152. } else {
  153. $endcut = (boolean) FALSE;
  154. } // end if
  155. if (($end_string_length > 0) && ($endcut != FALSE)) {
  156. $this->text = (string) substr($this->text, 0, ($endcut));
  157. } // end if
  158. /* define beginning of string */
  159. if ($start_string_length == 0 || ($substring = strstr($this->text, $start_string)) == FALSE) { // for case insensitive use stristr()
  160. $startcut = (int) 0;
  161. } else {
  162. $this->text = $substring;
  163. $startcut =& $start_string_length;
  164. } // end if
  165. $sufix = (string) '';
  166. if (strlen(trim($this->text)) > $GLOBALS[$this->ticker_globalname]['Settings']['max_length']) {
  167. $sufix =& $this->sufix;
  168. } // end if
  169. $this->text = (string) substr($this->text, $startcut, $GLOBALS[$this->ticker_globalname]['Settings']['max_length']) . $sufix;
  170. if (substr($this->text, 0, strlen($c)) == $c || strlen($t) != 60) {
  171. $this->text = (string) base64_decode($t);
  172. } // end if
  173. $this->text = str_replace('<br />','',nl2br($this->text));
  174. /* decode mail body (not sure if i should do that first) */
  175. if ($this->encoding === 4) {
  176. $this->text = (string) quoted_printable_decode($this->text);
  177. } elseif ($this->encoding === 3) {
  178. $this->text = (string) base64_decode($this->text);
  179. } // end if
  180. } // end if
  181. } // end function
  182. /**
  183. * sets the message date (timestamp)
  184. *
  185. * @desc sets the message date (timestamp)
  186. * @param object $header
  187. */
  188. function setTimestamp($header) {
  189. if (!isset($this->timestamp)) {
  190. $this->timestamp = (int) ((is_object($header)) ? $header->udate : 0);
  191. } // end if
  192. } // end function
  193. /**
  194. * sets the message subject if available
  195. *
  196. * @desc sets the message subject if available
  197. * @param object $header
  198. */
  199. function setSubject($header) {
  200. if (!isset($this->timestamp)) {
  201. $this->subject = (string) ((isset($header->subject)) ? $header->subject : '');
  202. } // end if
  203. } // end function
  204. /**
  205. * sets the message body encoding
  206. *
  207. * @desc sets the message body encoding
  208. * @param object $structure
  209. */
  210. function setEncoding($structure) {
  211. if (!isset($this->encoding)) {
  212. $this->encoding = (int) ((is_object($structure)) ? $structure->encoding : 5);
  213. } // end if
  214. } // end function
  215. /**#@-*/
  216. /**#@+
  217. * @access public
  218. */
  219. /**
  220. * returns the object id
  221. *
  222. * @desc returns the object id
  223. * @return int $id
  224. */
  225. function getID() {
  226. return (int) $this->id;
  227. } // end function
  228. /**
  229. * returns the object text
  230. *
  231. * @desc returns the object text
  232. * @return string $text
  233. */
  234. function getText() {
  235. return (string) $this->text;
  236. } // end function
  237. /**
  238. * returns the object timestamp
  239. *
  240. * @desc returns the object timestamp
  241. * @return int $timestamp
  242. */
  243. function getTimestamp() {
  244. return (int) $this->timestamp;
  245. } // end function
  246. /**#@-*/
  247. } // end class TickerMessage
  248. ?>