Source for file ProgramGuide.class.php

Documentation is available at ProgramGuide.class.php

  1. <?php
  2.  
  3. class ProgramGuide {
  4.  
  5. /**
  6. * @access private
  7. * @var string
  8. */
  9.  
  10. /**
  11. * @access private
  12. * @var string
  13. */
  14. private $lIPNummer;
  15.  
  16. /**
  17. * @access private
  18. * @var string
  19. */
  20. private $lType;
  21.  
  22. /**
  23. * @access private
  24. * @var array
  25. */
  26. private $lPrograms;
  27.  
  28. /**
  29. * @access private
  30. * @var int
  31. */
  32. private $lProgramsQueueCounter;
  33.  
  34. /**
  35. * @access private
  36. * @var int
  37. */
  38. private $lProgramsCount;
  39.  
  40. /**
  41. * @access private
  42. * @var array
  43. */
  44. private $lAuthentication;
  45.  
  46. /**
  47. * Constructor. This creates a ProgramGuide object.
  48. * @param string $pIP
  49. * @param string $pType
  50. * @return ProgramGuide
  51. */
  52. public function __construct($pIP,$pType,$pAuthentication = array()) {
  53. $this->lIPNummer = trim($pIP);
  54. $this->lType = trim($pType);
  55. $this->lProgramQueueCounter = -1;
  56. $this->lPrograms = array();
  57. $this->lAuthentication = array();
  58. $this->lAuthentication[0] = trim($pAuthentication[0]);
  59. $this->lAuthentication[1] = trim($pAuthentication[1]);
  60. }
  61.  
  62. /**
  63. * Get the programs url for a channel.
  64. * @return string
  65. */
  66. private function getGuideUrl() {
  67. $lExtraUrl = "";
  68. if ($this->lAuthentication[0] != "" || $this->lAuthentication[1] != "") {
  69. $lExtraUrl = $this->lAuthentication[0] . ":" . $this->lAuthentication[1] . "@";
  70. }
  71. switch ($this->lType) {
  72. case "enigma1":
  73. return "http://" . $lExtraUrl . $this->lIPNummer . "/getcurrentepg?type=extended&ref=" . $this->lChannelID;
  74. break;
  75. case "enigma2";
  76. return "http://" . $lExtraUrl . $this->lIPNummer . "/web/epgservice?sRef=" . $this->lChannelID;
  77. break;
  78. default:
  79. return false;
  80. break;
  81. }
  82. }
  83.  
  84. /**
  85. * Load the program guide by adding programs to the array. It also resets the internal counter.
  86. * @param string $pChannelID
  87. * @param boolean $pRenew
  88. */
  89. public function loadProgramGuide($pChannelID,$pRenew = false) {
  90. $this->lChannelID = trim($pChannelID);
  91. if (!is_array($this->lPrograms["$this->lChannelID"])) {
  92. $pRenew = true;
  93. }
  94. if ($pRenew) {
  95. switch ($this->lType) {
  96. case "enigma1":
  97. $lData = explode("<tr",file_get_contents($this->getGuideUrl()));
  98. //$lData = explode("<tr",file_get_contents("./epg.txt"));
  99. $this->lPrograms["$this->lChannelID"] = array();
  100. for ($i = 2; $i < sizeof($lData); $i++) {
  101. $lStartPos = stripos($lData[$i],"javascript:record(") + strlen("javascript:record(");
  102. $lStopPos = stripos($lData[$i],")",$lStartPos+1);
  103. $lDataParts = explode(",",str_ireplace("'","",trim(substr($lData[$i],$lStartPos,$lStopPos-$lStartPos))));
  104.  
  105. $lStartPos = stripos($lData[$i],"class=\"description\"");
  106.  
  107. if ($lStartPos !== false) {
  108. $lStartPos += strlen("class=\"description\"")+1;
  109. $lStopPos = stripos($lData[$i],"</",$lStartPos+1);
  110. $lExtendedInfo = trim(substr($lData[$i],$lStartPos,$lStopPos-$lStartPos));
  111. }
  112. $this->addProgram($pChannelID,new Program(trim($lDataParts[1]),trim($lDataParts[1]),trim($lDataParts[2]),trim($lDataParts[3]),$lExtendedInfo,""));
  113. }
  114. break;
  115. case "enigma2";
  116. $lData = Utils::xml2array(file_get_contents($this->getGuideUrl()));
  117. if (is_array($lData) && is_array($lData["e2eventlist"])) {
  118. $this->lPrograms["$this->lChannelID"] = array();
  119. foreach ($lData["e2eventlist"][0]["e2event"] as $lProgram) {
  120. $this->addProgram($pChannelID,new Program($lProgram["e2eventid"],$lProgram["e2eventstart"],$lProgram["e2eventduration"],$lProgram["e2eventtitle"],$lProgram["e2eventdescription"],$lProgram["e2eventdescriptionextended"]));
  121. }
  122.  
  123. }
  124. break;
  125. default:
  126. return false;
  127. break;
  128. }
  129.  
  130.  
  131. }
  132. $this->lProgramsCount = sizeof($this->lPrograms);
  133. $this->resetProgramsCounter();
  134. }
  135.  
  136. /**
  137. * Sort the programs based in start time
  138. * @todo Make sorting based in start time
  139. */
  140. private function sortOnStartTime() {
  141.  
  142. }
  143.  
  144. /**
  145. * Add a program to a channel. Every channel has its own programs array.
  146. * @param string $pChannelID
  147. * @param Program $pProgramObj
  148. */
  149. public function addProgram($pChannelID,Program $pProgramObj) {
  150. $this->lPrograms["$this->lChannelID"][] = $pProgramObj;
  151. }
  152.  
  153. /**
  154. * Get the total programs inside a program guide.
  155. * @return int
  156. */
  157. public function getProgramsCount() {
  158. return $this->lProgramsCount;
  159. }
  160.  
  161. /**
  162. * Reset the internal program counter.
  163. */
  164. public function resetProgramsCounter() {
  165. $this->lProgramsQueueCounter = -1;
  166. }
  167.  
  168. /**
  169. * Get the next program from the program guide.
  170. * @return Channel
  171. */
  172. public function getNextProgram() {
  173. $this->lProgramsQueueCounter++;
  174. if (isset($this->lPrograms["$this->lChannelID"][$this->lProgramsQueueCounter])) {
  175. return $this->lPrograms["$this->lChannelID"][$this->lProgramsQueueCounter];
  176. }
  177. return false;
  178. }
  179.  
  180. /**
  181. * Get the current program based on current time.
  182. * @return Channel
  183. */
  184. public function getCurrentProgram() {
  185. foreach ($this->lPrograms["$this->lChannelID"] as $lProgram) {
  186. if ($lProgram->getStartTime() < time()) {
  187. return $lProgram;
  188. }
  189. }
  190. return false;
  191. }
  192.  
  193. public function searchProgram($pProgramID) {
  194. foreach ($this->lPrograms["$this->lChannelID"] as $lProgram) {
  195. if ($lProgram->getID() == $pProgramID) {
  196. return $lProgram;
  197. }
  198. }
  199. }
  200.  
  201. }
  202. ?>

Documentation generated on Sat, 19 Jan 2008 12:56:18 +0100 by phpDocumentor 1.3.0RC3