Documentation is available at Dreambox.class.php
- <?php
- class Dreambox {
- /**
- * @access private
- * @var string
- */
- private $lIPNummer;
- /**
- * @access private
- * @var string
- */
- private $lBoutiques;
- /**
- * @access private
- * @var string
- */
- private $lType;
- /**
- * @access private
- * @var int
- */
- private $lBoutiqueQueueCounter;
- /**
- * @access private
- * @var string
- */
- private $lCurrentBoutique;
- /**
- * @access private
- * @var string
- */
- private $lCurrentChannel;
- /**
- * @access private
- * @var ProgramGuide
- */
- private $lProgramGuide;
- /**
- * @access private
- * @var array
- */
- private $lAuthentication;
- /**
- * Constructor. This creates the Dreambox object. If it exists in the session cache, it will be recreated from the cahce instead a new object.
- * @param string $pIP
- * @param string $pType
- * @param array $pAuthentication
- * @param int $pReNew
- * @return Dreambox
- */
- function __construct($pIP = "",$pType = "",$pAuthentication = array(), $pReNew = 0) {
- // Session based caching....
- if ($pReNew == 0 && isset($_SESSION["dreambox"])) {
- $lTMPObj = unserialize($_SESSION["dreambox"]);
- $this->lIPNummer = $lTMPObj->lIPNummer;
- $this->lType = $lTMPObj->lType;
- $this->lAuthentication = $lTMPObj->lAuthentication;
- $this->lBoutiques = $lTMPObj->lBoutiques;
- $this->lBoutiqueQueueCounter = $lTMPObj->lBoutiqueQueueCounter;
- $this->lCurrentBoutique = $lTMPObj->lCurrentBoutique;
- $this->lCurrentChannel = $lTMPObj->lCurrentChannel;
- $this->lProgramGuide = $lTMPObj->lProgramGuide;
- $this->saveObjectCache();
- } else {
- $this->lIPNummer = $pIP;
- $this->lType = $pType;
- $this->lAuthentication = array();
- $this->lAuthentication[0] = trim($pAuthentication[0]);
- $this->lAuthentication[1] = trim($pAuthentication[1]);
- $this->lBoutiques = array();
- $this->lCurrentBoutique = null;
- $this->lCurrentChannel = null;
- $this->lProgramGuide = new ProgramGuide($this->lIPNummer,$this->lType,$this->getAthentication());
- $this->resetBoutiqueCounter(); // This function also saves the object to session cache..
- //$this->saveObjectCache(); // So a manual request is not needed
- }
- }
- /**
- * Save the current Dreambox object state to a session. This is used for caching.
- */
- private function saveObjectCache() {
- $_SESSION["dreambox"] = serialize($this);
- }
- /**
- * Get the Boutique url. This is used for getting boutique information from your dreambox.
- * @return string
- */
- private function getBoutiqueUrl() {
- $lExtraUrl = "";
- if ($this->lAuthentication[0] != "" || $this->lAuthentication[1] != "") {
- $lExtraUrl = $this->lAuthentication[0] . ":" . $this->lAuthentication[1] . "@";
- }
- switch ($this->lType) {
- case "enigma1":
- return "http://" . $lExtraUrl . $this->lIPNummer . "/body?mode=zap&zapmode=0&zapsubmode=4";
- break;
- case "enigma2";
- return "http://" . $lExtraUrl . $this->lIPNummer . "/web/getservices?sRef=1:7:1:0:0:0:0:0:0:0:FROM%20BOUQUET%20%22bouquets.tv%22%20ORDER%20BY%20bouquet";
- break;
- default:
- return false;
- break;
- }
- }
- /**
- * Set the Dreambox IP nummer. If the IP nummer is not valid, it will be ignored.
- * @param string $pIp
- * @return boolean
- */
- public function setDreamboxIP($pIp) {
- function checkIP($pIp) { // Should be Regex.... but to lazy at the moment.... ;)
- $pIp = explode(".",trim($pIp));
- return (sizeof($pIp) == 4 &&
- $pIp[0] > 0 && $pIp[0] <= 255 &&
- $pIp[1] > 0 && $pIp[1] <= 255 &&
- $pIp[2] > 0 && $pIp[2] <= 255 &&
- $pIp[3] > 0 && $pIp[3] <= 255 );
- }
- $pIp = trim($pIp);
- if (checkIP($pIp) || checkIP(gethostbyname($pIp))) {
- $this->lIPNummer = $pIp;
- $this->saveObjectCache();
- return true;
- }
- return false;
- }
- /**
- * Get the current IP of the Dreambox object.
- * @return boolean
- */
- public function getDreamboxIP() {
- return trim($this->lIPNummer);
- }
- /**
- * Check if the Dreambox is online.
- * @return boolean
- */
- public function isOnline() {
- $ping = explode("\n",shell_exec ('ping -l 1 -w 2 ' . $this->lIPNummer));
- $ping = explode(",",$ping[sizeof($ping)-3]);
- $ping = explode(" ",trim($ping[1]));
- return ($ping[0] != 0);
- }
- /**
- * Set the Dreambox type. Valid values are 'enigma1' and 'enigma2'.
- * @param string $pType
- * @return boolean
- */
- public function setDreamboxType($pType) {
- if ( ($pType == trim($pType)) == "") return false;
- switch ($pType) {
- case "enigma1":
- $this->lType = "enigma1";
- break;
- case "enigma2";
- $this->lType = "enigma2";
- break;
- default:
- return false;
- break;
- }
- // Should only reached when a valid type is entered
- $this->saveObjectCache();
- return true;
- }
- public function getDreamboxUserName() {
- return trim($this->lAuthentication[0]);
- }
- public function getDreamboxPassWord() {
- return trim($this->lAuthentication[1]);
- }
- public function getAthentication() {
- return array($this->getDreamboxUserName(),$this->getDreamboxPassWord());
- }
- /**
- * Load the data from the Dreambox. Here all youre boutiques will be collected and saved in the dreambox object.
- * Set $pReNew to 1 to force a reload of the boutique data.
- * @param int $pReNew
- * @return boolean
- */
- public function loadBoutiques($pReNew = 0) {
- if (sizeof($this->lBoutiques) == 0 || $pReNew == 1) { // Only load boutique data the first time ... later.. it should be cached
- switch ($this->lType) {
- case "enigma1":
- $lData = file_get_contents($this->getBoutiqueUrl());
- //$lData = file_get_contents("./enigma1.txt"); // Test
- $lStartPos = stripos($lData,"var bouquets = new Array(");
- $lStartPos = stripos($lData,"\n",$lStartPos);
- $lStopPos = stripos($lData,"\n",$lStartPos+1);
- $lDataNames = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
- $lStartPos = stripos($lData,"var bouquetRefs = new Array(");
- $lStartPos = stripos($lData,"\n",$lStartPos);
- $lStopPos = stripos($lData,"\n",$lStartPos+1);
- $lDataIDs = explode(",",str_ireplace("\"","",trim(substr($lData,$lStartPos,$lStopPos-$lStartPos))));
- for ($i = 0; $i < sizeof($lDataIDs); $i++) {
- $this->lBoutiques[] = new Boutique($lDataIDs[$i],$this->lIPNummer,$this->lType,$this->getAthentication(),$lDataNames[$i]);
- }
- break;
- case "enigma2";
- $lData = Utils::xml2array(file_get_contents($this->getBoutiqueUrl()));
- if (!is_array($lData) || !is_array($lData["e2servicelist"][0]["e2service"])) return false;
- foreach ($lData["e2servicelist"][0]["e2service"] as $lBoutique) {
- $lBoutiqueId = explode(""",$lBoutique["e2servicereference"]);
- $lBoutiqueId = $lBoutiqueId[1];
- $this->lBoutiques[] = new Boutique($lBoutiqueId,$this->lIPNummer,$this->lType,$this->getAthentication(),$lBoutique["e2servicename"]);
- }
- break;
- default:
- return false;
- break;
- }
- $this->saveObjectCache();
- }
- return true;
- }
- /**
- * Load the channel data. This is done after the boutiques are loaded. The actual loading of the data happens in the Boutique class.
- * Set $pReNew to 1 to force a reload of the channel data
- * @param int $pReNew
- */
- function loadChannels($pReNew = 0) {
- foreach ($this->lBoutiques as $lBoutique) {
- $lBoutique->loadChannels($pReNew);
- }
- $this->saveObjectCache();
- }
- /**
- * Reset the boutiquecounter. This is an internal counter to keep track of the possituin in the boutique list.
- */
- function resetBoutiqueCounter() {
- $this->lBoutiqueQueueCounter = -1;
- $this->saveObjectCache();
- }
- /**
- * Get the total boutiques.
- * @return int
- */
- function getBoutiquesCount() {
- return sizeof($this->lBoutiques);
- }
- /**
- * Get the next boutique. This function gives the next boutique and updates it internal counter.
- * @return Boutique
- */
- function getNextBoutique() {
- $this->lBoutiqueQueueCounter++;
- $this->saveObjectCache();
- if (isset($this->lBoutiques[$this->lBoutiqueQueueCounter])) {
- return $this->lBoutiques[$this->lBoutiqueQueueCounter];
- }
- return null;
- }
- /**
- * Search for a boutique base on boutiqueID. This function returns a boutique when ID is valid and found. Else it returns false.
- * @param string $pBoutiqueID
- * @return Boutique
- */
- function searchBoutique($pBoutiqueID) {
- if ( ($pBoutiqueID = trim($pBoutiqueID)) == "") return false;
- foreach ($this->lBoutiques as $lBoutique) {
- if ($lBoutique->getID() == $pBoutiqueID) {
- return $lBoutique;
- }
- }
- return null;
- }
- /**
- * Zap the dreambox to the new channel. This function saves the boutique and channel in the dreambox object so that you can ask the dreambox what you are wachting.
- * @param string $pBoutiqueID
- * @param string $pChannelID
- */
- function zap($pBoutiqueID,$pChannelID) {
- $this->lCurrentBoutique = $pBoutiqueID;
- $this->lCurrentChannel = $pChannelID;
- $this->saveObjectCache();
- }
- /**
- * Return the programguide object. You can use the programguide to find programs and show a soort of tv guide.
- * @return ProgramGuide
- */
- public function programGuide() {
- return $this->lProgramGuide;
- }
- /**
- * Load the program guide of a channel. The function uses the ProgramGuide object to load the data.
- * @param string $pChannelID
- */
- public function loadProgramGuide($pChannelID = "") {
- if ($pChannelID == "") $pChannelID = $this->lCurrentChannel;
- $this->lProgramGuide->loadProgramGuide($pChannelID);
- $this->saveObjectCache();
- }
- /**
- * Dump the complete object to screen.
- */
- public function dump() {
- print_r($this);
- }
- }
- ?>
Documentation generated on Sat, 19 Jan 2008 12:56:15 +0100 by phpDocumentor 1.3.0RC3