Documentation is available at ProgramGuide.class.php
- <?php
- class ProgramGuide {
- /**
- * @access private
- * @var string
- */
- /**
- * @access private
- * @var string
- */
- private $lIPNummer;
- /**
- * @access private
- * @var string
- */
- private $lType;
- /**
- * @access private
- * @var array
- */
- private $lPrograms;
- /**
- * @access private
- * @var int
- */
- private $lProgramsQueueCounter;
- /**
- * @access private
- * @var int
- */
- private $lProgramsCount;
- /**
- * @access private
- * @var array
- */
- private $lAuthentication;
- /**
- * Constructor. This creates a ProgramGuide object.
- * @param string $pIP
- * @param string $pType
- * @return ProgramGuide
- */
- public function __construct($pIP,$pType,$pAuthentication = array()) {
- $this->lIPNummer = trim($pIP);
- $this->lType = trim($pType);
- $this->lProgramQueueCounter = -1;
- $this->lPrograms = array();
- $this->lAuthentication = array();
- $this->lAuthentication[0] = trim($pAuthentication[0]);
- $this->lAuthentication[1] = trim($pAuthentication[1]);
- }
- /**
- * Get the programs url for a channel.
- * @return string
- */
- private function getGuideUrl() {
- $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 . "/getcurrentepg?type=extended&ref=" . $this->lChannelID;
- break;
- case "enigma2";
- return "http://" . $lExtraUrl . $this->lIPNummer . "/web/epgservice?sRef=" . $this->lChannelID;
- break;
- default:
- return false;
- break;
- }
- }
- /**
- * Load the program guide by adding programs to the array. It also resets the internal counter.
- * @param string $pChannelID
- * @param boolean $pRenew
- */
- public function loadProgramGuide($pChannelID,$pRenew = false) {
- $this->lChannelID = trim($pChannelID);
- if (!is_array($this->lPrograms["$this->lChannelID"])) {
- $pRenew = true;
- }
- if ($pRenew) {
- switch ($this->lType) {
- case "enigma1":
- $lData = explode("<tr",file_get_contents($this->getGuideUrl()));
- //$lData = explode("<tr",file_get_contents("./epg.txt"));
- $this->lPrograms["$this->lChannelID"] = array();
- for ($i = 2; $i < sizeof($lData); $i++) {
- $lStartPos = stripos($lData[$i],"javascript:record(") + strlen("javascript:record(");
- $lStopPos = stripos($lData[$i],")",$lStartPos+1);
- $lDataParts = explode(",",str_ireplace("'","",trim(substr($lData[$i],$lStartPos,$lStopPos-$lStartPos))));
- $lStartPos = stripos($lData[$i],"class=\"description\"");
- if ($lStartPos !== false) {
- $lStartPos += strlen("class=\"description\"")+1;
- $lStopPos = stripos($lData[$i],"</",$lStartPos+1);
- $lExtendedInfo = trim(substr($lData[$i],$lStartPos,$lStopPos-$lStartPos));
- }
- $this->addProgram($pChannelID,new Program(trim($lDataParts[1]),trim($lDataParts[1]),trim($lDataParts[2]),trim($lDataParts[3]),$lExtendedInfo,""));
- }
- break;
- case "enigma2";
- $lData = Utils::xml2array(file_get_contents($this->getGuideUrl()));
- if (is_array($lData) && is_array($lData["e2eventlist"])) {
- $this->lPrograms["$this->lChannelID"] = array();
- foreach ($lData["e2eventlist"][0]["e2event"] as $lProgram) {
- $this->addProgram($pChannelID,new Program($lProgram["e2eventid"],$lProgram["e2eventstart"],$lProgram["e2eventduration"],$lProgram["e2eventtitle"],$lProgram["e2eventdescription"],$lProgram["e2eventdescriptionextended"]));
- }
- }
- break;
- default:
- return false;
- break;
- }
- }
- $this->lProgramsCount = sizeof($this->lPrograms);
- $this->resetProgramsCounter();
- }
- /**
- * Sort the programs based in start time
- * @todo Make sorting based in start time
- */
- private function sortOnStartTime() {
- }
- /**
- * Add a program to a channel. Every channel has its own programs array.
- * @param string $pChannelID
- * @param Program $pProgramObj
- */
- public function addProgram($pChannelID,Program $pProgramObj) {
- $this->lPrograms["$this->lChannelID"][] = $pProgramObj;
- }
- /**
- * Get the total programs inside a program guide.
- * @return int
- */
- public function getProgramsCount() {
- return $this->lProgramsCount;
- }
- /**
- * Reset the internal program counter.
- */
- public function resetProgramsCounter() {
- $this->lProgramsQueueCounter = -1;
- }
- /**
- * Get the next program from the program guide.
- * @return Channel
- */
- public function getNextProgram() {
- $this->lProgramsQueueCounter++;
- if (isset($this->lPrograms["$this->lChannelID"][$this->lProgramsQueueCounter])) {
- return $this->lPrograms["$this->lChannelID"][$this->lProgramsQueueCounter];
- }
- return false;
- }
- /**
- * Get the current program based on current time.
- * @return Channel
- */
- public function getCurrentProgram() {
- foreach ($this->lPrograms["$this->lChannelID"] as $lProgram) {
- if ($lProgram->getStartTime() < time()) {
- return $lProgram;
- }
- }
- return false;
- }
- public function searchProgram($pProgramID) {
- foreach ($this->lPrograms["$this->lChannelID"] as $lProgram) {
- if ($lProgram->getID() == $pProgramID) {
- return $lProgram;
- }
- }
- }
- }
- ?>
Documentation generated on Sat, 19 Jan 2008 12:56:18 +0100 by phpDocumentor 1.3.0RC3