Source for file Boutique.class.php

Documentation is available at Boutique.class.php

  1. <?php
  2.  
  3. class Boutique {
  4.  
  5. /**
  6. * @access private
  7. * @var string
  8. */
  9. private $lID;
  10.  
  11. /**
  12. * @access private
  13. * @var string
  14. */
  15. private $lName;
  16.  
  17. /**
  18. * @access private
  19. * @var string
  20. */
  21. private $lIPNummer;
  22.  
  23. /**
  24. * @access private
  25. * @var string
  26. */
  27. private $lType;
  28.  
  29. /**
  30. * @access private
  31. * @var array
  32. */
  33. private $lChannels;
  34.  
  35. /**
  36. * @access private
  37. * @var int
  38. */
  39. private $lChannelCount;
  40.  
  41. /**
  42. * @access private
  43. * @var int
  44. */
  45. private $lChannelQueueCounter;
  46.  
  47. /**
  48. * @access private
  49. * @var array
  50. */
  51. private $lAuthentication;
  52.  
  53. /**
  54. * Constructor. This creates a Boutique object.
  55. * @param int $pID
  56. * @param string $pIP
  57. * @param string $pType
  58. * @param string $pName
  59. * @return Channel
  60. */
  61. function __construct($pID,$pIP,$pType, $pAuthentication = array(), $pName = null) {
  62. $this->lID = trim($pID);
  63. $this->lIPNummer = trim($pIP);
  64. $this->lType = trim($pType);
  65. $this->lName = trim($pName);
  66. $this->lChannelCount = 0;
  67. $this->lAuthentication = array();
  68. $this->lAuthentication[0] = trim($pAuthentication[0]);
  69. $this->lAuthentication[1] = trim($pAuthentication[1]);
  70. $this->resetChannelCounter();
  71. }
  72.  
  73. /**
  74. * Get the Channel url. This is used for getting channels from a boutique.
  75. * @return string
  76. */
  77. private function getChannelUrl() {
  78. $lExtraUrl = "";
  79. if ($this->lAuthentication[0] != "" || $this->lAuthentication[1] != "") {
  80. $lExtraUrl = $this->lAuthentication[0] . ":" . $this->lAuthentication[1] . "@";
  81. }
  82. switch ($this->lType) {
  83. case "enigma1":
  84. return "http://" . $lExtraUrl . $this->lIPNummer . "/body?mode=zap&zapmode=0&zapsubmode=4";
  85. break;
  86. case "enigma2";
  87. return "http://" . $lExtraUrl . $this->lIPNummer . "/web/getservices?sRef=1:7:1:0:0:0:0:0:0:0:FROM%20BOUQUET%20%22" . $this->lID . "%22%20ORDER%20BY%20bouquet";
  88. break;
  89. default:
  90. return false;
  91. break;
  92. }
  93. }
  94.  
  95. /**
  96. * Get the boutique ID.
  97. * @return string
  98. */
  99. public function getID() {
  100. return $this->lID;
  101. }
  102.  
  103. /**
  104. * Get the boutique name.
  105. * @return string
  106. */
  107. public function getName() {
  108. return $this->lName;
  109. }
  110.  
  111. /**
  112. * Load all channels in the boutique.
  113. * Set $pReNew to 1 to force a reload of the boutique data.
  114. * @param int $pReNew
  115. * @return boolean
  116. */
  117. function loadChannels($pReNew = 0) {
  118. if ($this->getChannelCount() == 0 || $pReNew == 1) {
  119. switch ($this->lType) {
  120. case "enigma1":
  121. $lData = file_get_contents($this->getBoutiqueUrl());
  122. //$lData = file_get_contents("enigma1.txt"); // Test
  123. $lStartPos = stripos($lData,"var bouquets = new Array(");
  124. $lStartPos = stripos($lData,"\n",$lStartPos);
  125. $lStopPos = stripos($lData,"\n",$lStartPos+1);
  126. $lDataNames = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
  127.  
  128. $lStartPos = stripos($lData,"var bouquetRefs = new Array(");
  129. $lStartPos = stripos($lData,"\n",$lStartPos);
  130. $lStopPos = stripos($lData,"\n",$lStartPos+1);
  131. $lDataIDs = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
  132.  
  133.  
  134. for ($i = 0; $i < sizeof($lDataIDs); $i++) {
  135. if (trim($this->lID) == trim($lDataIDs[$i])) { // This is me....
  136. $lStartPos = stripos($lData,"channels[$i] = new Array(");
  137.  
  138. if ($lStartPos !== false) {
  139. $lStartPos += strlen("channels[$i] = new Array(");
  140. $lStopPos = stripos($lData,");",$lStartPos);
  141. $lDataNames2 = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
  142.  
  143. $lStartPos = stripos($lData,"channelRefs[$i] = new Array(");
  144. if ($lStartPos !== false) {
  145. $lStartPos += strlen("channelRefs[$i] = new Array(");
  146. $lStopPos = stripos($lData,");",$lStartPos);
  147. $lDataIDs2 = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
  148.  
  149. for ($j = 0; $j < sizeof($lDataIDs2); $j++) {
  150.  
  151. $this->addChannel(new Channel($lDataIDs2[$j],$this->lIPNummer,$this->lType,$lDataNames2[$j]));
  152. }
  153. }
  154.  
  155. }
  156. break; // Stop looping, because current Boutique is found and the channels are loaded
  157. }
  158. }
  159. break;
  160.  
  161. case "enigma2";
  162. $lData = Utils::xml2array(file_get_contents($this->getChannelUrl()));
  163. if (is_array($lData) && is_array($lData["e2servicelist"])) {
  164. foreach ($lData["e2servicelist"][0]["e2service"] as $lChannel) {
  165. $this->addChannel(new Channel($lChannel["e2servicereference"],$this->lIPNummer,$this->lType,$lChannel["e2servicename"]));
  166. }
  167.  
  168. }
  169. break;
  170. default:
  171. return false;
  172. break;
  173. }
  174. $this->lChannelCount = sizeof($this->lChannels);
  175. }
  176. }
  177.  
  178. /**
  179. * Add a channel to the boutique.
  180. * @param Channel $pChannel
  181. */
  182. public function addChannel(Channel $pChannel) {
  183. $this->lChannels[] = $pChannel;
  184. }
  185.  
  186. /**
  187. * Get the channel object based in channel id.
  188. * @param string $pChannelID
  189. * @return Channel
  190. */
  191. public function getChannel($pChannelID) {
  192. if ( ($pChannelID = trim($pChannelID)) == "") return false;
  193. foreach ($this->lChannels as $lChannel) {
  194. if ($lChannel->getID() == $pChannelID) {
  195. return $lChannel;
  196. }
  197. }
  198. }
  199.  
  200. /**
  201. * Get the total channels inside a boutique.
  202. * @return int
  203. */
  204. public function getChannelCount() {
  205. return $this->lChannelCount;
  206. }
  207.  
  208. /**
  209. * Reset the internal channel counter.
  210. */
  211. public function resetChannelCounter() {
  212. $this->lChannelQueueCounter = -1;
  213. }
  214.  
  215. /**
  216. * Get the next channel from the boutique.
  217. * @return Channel
  218. */
  219. public function getNextChannel() {
  220. $this->lChannelQueueCounter++;
  221. if (isset($this->lChannels[$this->lChannelQueueCounter])) {
  222. return $this->lChannels[$this->lChannelQueueCounter];
  223. }
  224. return null;
  225. }
  226.  
  227. }
  228.  
  229. ?>

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