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->getChannelUrl());
  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. for ($i = 0; $i < sizeof($lDataIDs); $i++) {
  134. if (trim($this->lID) == trim($lDataIDs[$i])) { // This is me....
  135. $lStartPos = stripos($lData,"channels[$i] = new Array(");
  136.  
  137. if ($lStartPos !== false) {
  138. $lStartPos += strlen("channels[$i] = new Array(");
  139. $lStopPos = stripos($lData,");",$lStartPos);
  140. $lDataNames2 = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
  141.  
  142. $lStartPos = stripos($lData,"channelRefs[$i] = new Array(");
  143. if ($lStartPos !== false) {
  144. $lStartPos += strlen("channelRefs[$i] = new Array(");
  145. $lStopPos = stripos($lData,");",$lStartPos);
  146. $lDataIDs2 = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
  147.  
  148. for ($j = 0; $j < sizeof($lDataIDs2); $j++) {
  149. $this->addChannel(new Channel($lDataIDs2[$j],$this->lIPNummer,$this->lType,$lDataNames2[$j]));
  150. }
  151. }
  152. }
  153. break; // Stop looping, because current Boutique is found and the channels are loaded
  154. }
  155. }
  156. break;
  157.  
  158. case "enigma2";
  159. $lData = Utils::xml2array(file_get_contents($this->getChannelUrl()));
  160. if (is_array($lData) && is_array($lData["e2servicelist"])) {
  161. foreach ($lData["e2servicelist"][0]["e2service"] as $lChannel) {
  162. $this->addChannel(new Channel($lChannel["e2servicereference"],$this->lIPNummer,$this->lType,$lChannel["e2servicename"]));
  163. }
  164. }
  165. break;
  166. default:
  167. return false;
  168. break;
  169. }
  170. $this->lChannelCount = sizeof($this->lChannels);
  171. }
  172. }
  173.  
  174. /**
  175. * Add a channel to the boutique.
  176. * @param Channel $pChannel
  177. */
  178. public function addChannel(Channel $pChannel) {
  179. $this->lChannels[] = $pChannel;
  180. }
  181.  
  182. /**
  183. * Get the channel object based in channel id.
  184. * @param string $pChannelID
  185. * @return Channel
  186. */
  187. public function getChannel($pChannelID) {
  188. if ( ($pChannelID = trim($pChannelID)) == "") return false;
  189. foreach ($this->lChannels as $lChannel) {
  190. if ($lChannel->getID() == $pChannelID) {
  191. return $lChannel;
  192. }
  193. }
  194. return false;
  195. }
  196.  
  197. /**
  198. * Get the total channels inside a boutique.
  199. * @return int
  200. */
  201. public function getChannelCount() {
  202. return $this->lChannelCount;
  203. }
  204.  
  205. /**
  206. * Reset the internal channel counter.
  207. */
  208. public function resetChannelCounter() {
  209. $this->lChannelQueueCounter = -1;
  210. }
  211.  
  212. /**
  213. * Get the next channel from the boutique.
  214. * @return Channel
  215. */
  216. public function getNextChannel() {
  217. $this->lChannelQueueCounter++;
  218. if (isset($this->lChannels[$this->lChannelQueueCounter])) {
  219. return $this->lChannels[$this->lChannelQueueCounter];
  220. }
  221. return null;
  222. }
  223.  
  224. }
  225. ?>

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