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. break;
  124. default:
  125. return false;
  126. break;
  127. }
  128.  
  129.  
  130. }
  131. $this->lProgramsCount = sizeof($this->lPrograms);
  132. $this->resetProgramsCounter();
  133. }
  134.  
  135. /**
  136. * Sort the programs based in start time
  137. * @todo Make sorting based in start time
  138. */
  139. private function sortOnStartTime() {
  140.  
  141. }
  142.  
  143. /**
  144. * Add a program to a channel. Every channel has its own programs array.
  145. * @param string $pChannelID
  146. * @param Program $pProgramObj
  147. */
  148. public function addProgram($pChannelID,Program $pProgramObj) {
  149. $this->lPrograms["$this->lChannelID"][] = $pProgramObj;
  150. }
  151.  
  152. /**
  153. * Get the total programs inside a program guide.
  154. * @return int
  155. */
  156. public function getProgramsCount() {
  157. return $this->lProgramsCount;
  158. }
  159.  
  160. /**
  161. * Reset the internal program counter.
  162. */
  163. public function resetProgramsCounter() {
  164. $this->lProgramsQueueCounter = -1;
  165. }
  166.  
  167. /**
  168. * Get the next program from the program guide.
  169. * @return Channel
  170. */
  171. public function getNextProgram() {
  172. $this->lProgramsQueueCounter++;
  173. if (isset($this->lPrograms["$this->lChannelID"][$this->lProgramsQueueCounter])) {
  174. return $this->lPrograms["$this->lChannelID"][$this->lProgramsQueueCounter];
  175. }
  176. return false;
  177. }
  178.  
  179. /**
  180. * Get the current program based on current time.
  181. * @return Channel
  182. */
  183. public function getCurrentProgram($pChannelID) {
  184. //print_r($this);
  185. //return false;
  186. foreach ($this->lPrograms[$pChannelID] as $lProgram) {
  187. if ($lProgram->getStartTime() < time()) {
  188. return $lProgram;
  189. }
  190. }
  191. return false;
  192. }
  193.  
  194. public function searchProgram($pProgramID) {
  195. foreach ($this->lPrograms as $lChannelID => $lPrograms) {
  196. foreach($lPrograms as $lProgram) {
  197. if ($lProgram->getID() == $pProgramID) {
  198. return $lProgram;
  199. }
  200. }
  201. }
  202. }
  203.  
  204. }
  205. ?>

Documentation generated on Tue, 24 Jun 2008 18:59:36 +0200 by phpDocumentor 1.3.0RC3