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 string
- */
- private $lRecordings;
- /**
- * @access private
- * @var int
- */
- private $lRecordingsQueueCounter;
- /**
- * @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->lRecordings = $lTMPObj->lRecordings;
- $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->lRecordings = array();
- // This function also saves the object to session cache..
- $this->resetBoutiqueCounter();
- //$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;
- }
- }
- /**
- * Get the Recording url. This is used for getting recoring information from your dreambox.
- * @return string
- */
- public function getRecordingUrl()
- {
- $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=3&zapsubmode=1";
- break;
- case "enigma2";
- return "http://" . $lExtraUrl . $this->lIPNummer . "/web/movielist?tag=";
- break;
- default:
- break;
- }
- }
- /**
- * Get all recordings from the dreambox. The recordings will be save in a recording object array.
- * It can self see with enigma version is used, and what the code will be that will be returned from the dreambox
- */
- public function getRecordings()
- {
- $this->lRecordings = array();
- switch ($this->lType) {
- case "enigma1":
- $lData = file_get_contents($this->getRecordingUrl());
- $lStartPos = stripos($lData, "channels[0] = new Array(\"") + strlen("channels[0] = new Array(\"");
- $lStopPos = stripos($lData, "\");", $lStartPos + 1);
- $lDataNames = explode(",", str_ireplace("\"", "", trim(substr($lData, $lStartPos, $lStopPos - $lStartPos))));
- $lStartPos = stripos($lData, "channelRefs[0] = new Array(\"") + strlen("channelRefs[0] = new Array(\"");
- $lStopPos = stripos($lData, "\");", $lStartPos + 1);
- $lDataIDs = explode(",", str_ireplace("\"", "", trim(substr($lData, $lStartPos, $lStopPos - $lStartPos))));
- for ($i = 0; $i < sizeof($lDataIDs); $i++) {
- $lDataLine = trim($lDataNames[$i]);
- $lTitle = trim(substr($lDataLine, stripos($lDataLine, "]") + 1));
- $lFileSize = substr($lDataLine, 1, stripos($lDataLine, "]") - 4) * 1024;
- $lFileDate = explode("-", trim(substr($lDataLine, stripos($lDataLine, "]") + 1, 9)));
- if (sizeof($lFileDate) == 3) {
- $lFileDate = mktime(0, 0, 0, $lFileDate[1], $lFileDate[2], $lFileDate[0]);
- $lTitle = trim(substr($lTitle, 11));
- } else {
- $lFileDate = mktime();
- }
- $this->lRecordings[] = new Recording($lDataIDs[$i], $this->lIPNummer, $this->lType, $lTitle, "", "", $lFileDate, "", $lDataIDs[$i], $lFileSize);
- }
- break;
- case "enigma2";
- $lData = Utils::xml2array(file_get_contents($this->getRecordingUrl()));
- if (!is_array($lData) || !is_array($lData["e2movielist"][0]["e2movie"])) return false;
- foreach ($lData["e2movielist"][0]["e2movie"] as $lRecording) {
- $this->lRecordings[] = new Recording($lRecording["e2servicereference"], $this->lIPNummer, $this->lType, $lRecording["e2title"], $lRecording["e2description"], $lRecording["e2servicename"], $lRecording["e2time"], $lRecording["e2length"], $lRecording["e2filename"], $lRecording["e2filesize"]);
- }
- break;
- default:
- break;
- }
- $this->lRecordingsQueueCounter = -1;
- }
- /**
- * Iterate trough the recordings.
- * @return Recording
- */
- function getNextRecording()
- {
- $this->lRecordingsQueueCounter++;
- $this->saveObjectCache();
- if (isset($this->lRecordings[$this->lRecordingsQueueCounter])) return $this->lRecordings[$this->lRecordingsQueueCounter];
- return null;
- }
- /**
- * 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", trim(shell_exec('ping -l 1 -w 2 ' . $this->lIPNummer)));
- for ($i = 0; $i < sizeof($ping); $i++) {
- if ($i >= 3 && trim($ping[$i]) == "") {
- $i += 2;
- break;
- }
- }
- $ping = explode(",", $ping[$i]);
- $ping = explode(" ", trim($ping[1]));
- if (is_numeric(trim($ping[0]))) {
- // Linux
- return(trim($ping[0]) != 0);
- } else {
- // Windows
- return(trim($ping[2]) != 0);
- }
- }
- /**
- * Set the Dreambox type. Valid values are 'enigma1' and 'enigma2'.
- * @param string $pType
- * @return boolean
- */
- public function setDreamboxType($pType)
- {
- switch ($pType) {
- case "enigma1":
- $this->lType = "enigma1";
- break;
- case "enigma2";
- $this->lType = "enigma2";
- break;
- default:
- return false;
- break;
- }
- $this->saveObjectCache();
- return true;
- }
- /**
- * Get the dreambox username for authorization
- * @return string
- */
- public function getDreamboxUserName()
- {
- return trim($this->lAuthentication[0]);
- }
- /**
- * Get the dreambox password for authorization in plain text
- * @return password
- */
- public function getDreamboxPassWord()
- {
- return trim($this->lAuthentication[1]);
- }
- /**
- * Get the authentication array. This will containt the username and password in an array.
- * @return array
- */
- 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());
- $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) {
- // Suhosin Patch wierdness....?
- $lBoutique["e2servicereference"] = str_replace("\\", "", $lBoutique["e2servicereference"]);
- if (strpos(""", $lBoutique["e2servicereference"]) !== false) {
- $lBoutiqueId = explode(""", $lBoutique["e2servicereference"]);
- } else {
- $lBoutiqueId = explode("\"", $lBoutique["e2servicereference"]);
- }
- $lBoutiqueId = trim($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 false;
- }
- /**
- * Find the boutique that holds the channel. So you can search for the boutique that contains a specifeid channel. Return null when not found
- * @return Boutique
- */
- function findBoutiqueWithChannel($pChannelID)
- {
- if (($pChannelID = trim($pChannelID)) == "") return false;
- foreach ($this->lBoutiques as $lBoutique) {
- if ($lBoutique->getChannel($pChannelID) != false) return $lBoutique;
- }
- return false;
- }
- /**
- * 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();
- }
- /**
- * Sanity check. This checks all settings that are needed. You can easy append the checks. When everything is ok, a empty string is returned. Else the error message is returned
- * @return string
- */
- public function sanityCheck()
- {
- $lSafeMode = strtolower(ini_get("safe_mode"));
- $lMaxTime = ini_get("max_execution_time");
- if ($lSafeMode == "on" || $lSafeMode == "true" || $lSafeMode == "1") return "PHP Safe_mode is active. Change it in the php.ini file to Off";
- if ($lMaxTime < 60) return "Your PHP max_execution_time setting is to low in your php.ini";
- return "";
- }
- /**
- * Dump the complete object to screen.
- */
- public function dump()
- {
- print_r($this);
- }
- }
- ?>
Documentation generated on Tue, 24 Jun 2008 18:59:32 +0200 by phpDocumentor 1.3.0RC3