Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('max_execution_time', 300);
- $errmsg_arr = array();
- $errflag = false;
- $link;
- include ('simple_html_dom.php');
- function db_connect()
- {
- define('DB_HOST', 'localhost');
- define('DB_USER', 'root');
- define('DB_PASSWORD', 'root');
- define('DB_DATABASE', 'tv');
- $errmsg_arr = array();
- $errflag = false;
- $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
- if(!$link)
- {
- die('Failed to connect to server: ' . mysql_error());
- }
- $db = mysql_select_db(DB_DATABASE);
- if(!$db)
- {
- die("Unable to select database");
- }
- }
- function getUrlFriendlyString($str)
- {
- // convert spaces to '-', remove characters that are not alphanumeric
- // or a '-', combine multiple dashes (i.e., '---') into one dash '-'.
- $str = ereg_replace("[-]+", "-", ereg_replace("[^a-z0-9-]", "",
- strtolower( str_replace(" ", "-", $str) ) ) );
- return $str;
- }
- db_connect();
- function clean($var)
- {
- return mysql_real_escape_string(strip_tags($var));
- }
- $channels = "";
- $id = "";
- if(isset($_GET['channels'])){
- $channels = clean($_GET['channels']);
- }
- if(isset($_GET['id'])){
- $id = clean($_GET['id']);
- }
- if($errflag)
- {
- $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
- echo implode('<br />',$errmsg_arr);
- }
- else
- {
- $insert = array();
- if(isset($_GET['channels']))
- {
- $insert[] = 'channels = \'' . clean($_GET['channels']) .'\'';
- }
- if(isset($_GET['id']))
- {
- $insert[] = 'id = \'' . clean($_GET['id']) . '\'';
- }
- $base1 = "http://localhost/free/myscrip/get-listing.php";
- $html = file_get_html($base1);
- $countp = $html->find('p');
- header("Content-type: text/xml");
- echo "<?xml version='1.0' encoding='UTF-8'?>";
- echo '<tv generator-info-name="www.testbox.elementfx.com/xmltv">';
- for ($i=30 ;$i<count($countp) ; $i=$i+2)
- {
- echo '<channel id="'.$countp[$i]->innertext.'">' .'<display-name>'.$countp[$i]->innertext.'</display-name>';
- $htmlinner = file_get_html($countp[$i+1]->children(0)->innertext);
- $countpinner = $htmlinner->find('span');
- for ($iinner=0 ;$iinner<count($countpinner) ; $iinner = $iinner+2){
- $start_time_pr = date("Ymd");
- $end_time_pr = date("Ymd");
- $start_time_pr .= date("His", strtotime($countpinner[$iinner]->innertext) );
- if ($iinner +2 <count($countpinner) )
- $end_time_pr .= date("His", strtotime($countpinner[$iinner+2]->innertext ));
- else
- $end_time_pr .= "000000" ;
- echo '<programme channel="'.$countp[$i]->innertext.'" start="'.$start_time_pr.'" stop="'.$end_time_pr.'">';
- echo '<title lang="en"/>'.$countpinner[$iinner+1]->innertext.'';
- echo '<sub-title lang="en"></sub-title>';
- echo '<desc lang="en"/>';
- echo '<category lang="en"/>';
- echo '</programme>';
- }
- echo '</channel>';
- }
- echo "</tv>";
- exit;
- $curl1 = curl_init();
- curl_setopt($curl1, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl1, CURLOPT_HEADER, false);
- curl_setopt($curl1, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl1, CURLOPT_URL, $base1);
- curl_setopt($curl1, CURLOPT_REFERER, $base1);
- curl_setopt($curl1, CURLOPT_RETURNTRANSFER, TRUE);
- $str1 = curl_exec($curl1);
- curl_close($curl1);
- echo var_dump( $str1);
- exit;
- // Create a DOM object
- $html = new simple_html_dom();
- // Load HTML from a string
- $html->load($str1);
- //$html = file_get_html("http://localhost/free/myscrip/get-listing.php");
- // Find all images
- $program_list = array();
- $count = 0;
- echo $html;
- // echo var_dump( $html->find('nodetype'));
- exit;
- foreach($html->find('p[id=links]') as $element)
- {
- $program_list[ $count ] = array();
- $temp_arr = explode("?", $element->plaintext);
- $temp_arr = explode("&", $temp_arr[1]);
- $channels = explode("channels=",$temp_arr[0]);
- $channels = $channels[1];
- $id = explode("id=",$temp_arr[1]);
- $id = $id[1];
- echo $temp_arr;
- $program_list[ $count ]['channels'] = $channels;
- $program_list[ $count ]['id'] = $id;
- $html_two = "";
- //$tmp = explode("?", $element->plaintext);
- $tmp = explode("?", $element->plaintext);
- $tmp = explode("&", $tmp[1] );
- $tmpch = explode("channels=",$tmp[0]);
- $tmpch = $tmpch[1];
- $tmpid = explode("id=",$tmp[1]);
- $tmpid = $tmpid[1];
- $tempch = urlencode($tmpch);
- $tempid = urlencode($tmpid);
- /*$url = "http://localhost/free/myscrip/get-listing.php?channels=" . $tempch . "&id=" . $tmpid;
- $html_two = new simple_html_dom();
- $dom = $html_two->load_file($url);
- if(empty($dom))
- {
- continue;
- }*/
- /*$base2 = "http://localhost/free/myscrip/get-listing.php?channels=" . $tempch . "&id=" . $tmpid;
- $curl2 = curl_init();
- curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl2, CURLOPT_HEADER, false);
- curl_setopt($curl2, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl2, CURLOPT_URL, $base2);
- curl_setopt($curl2, CURLOPT_REFERER, $base2);
- curl_setopt($curl2, CURLOPT_RETURNTRANSFER, TRUE);
- $str2 = curl_exec($curl2);
- curl_close($curl2);
- // Create a DOM object
- $html_two = new simple_html_dom();
- // Load HTML from a string
- $html_two->load($str2);*/
- $html_two = file_get_html("http://localhost/free/myscrip/get-listing.php?channels=" . $tempch . "&id=" . $tmpid);
- $html_two_counter = count($html_two->find('span[id=time1]'));
- if($html_two_counter == 0)
- {
- continue;
- }
- //$html_two = file_get_html($url);
- $time1 = $html_two->find('span[id=time1]',0)->plaintext;
- $title1 = $html_two->find('span[id=title1]',0)->plaintext;
- $time1 = explode(" ", $time1);
- $hoursMinutes = explode(":", $time1[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time1[1] == "PM")
- {
- $time1[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time1[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['start_time1'] = $time1[0];
- $program_list[$count]['title1'] = $title1;
- //time2
- $time2 = $html_two->find('span[id=time2]', 0)->plaintext;
- $title2 = $html_two->find('span[id=title2]', 0)->plaintext;
- $time2 = explode(" ", $time2);
- $hoursMinutes = explode(":", $time2[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time2[1] == "PM")
- {
- $time2[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time2[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time1'] = $time2[0];
- $program_list[$count]['start_time2'] = $time2[0];
- $program_list[$count]['title2'] = $title2;
- //time3
- $time3 = $html_two->find('span[id=time3]', 0)->plaintext;
- $title3 = $html_two->find('span[id=title3]', 0)->plaintext;
- $time3 = explode(" ", $time3);
- $hoursMinutes = explode(":", $time3[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time3[1] == "PM")
- {
- $time3[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time3[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time2'] = $time3[0];
- $program_list[$count]['start_time3'] = $time3[0];
- $program_list[$count]['title3'] = $title3;
- //time4
- $time4 = $html_two->find('span[id=time4]', 0)->plaintext;
- $title4 = $html_two->find('span[id=title4]', 0)->plaintext;
- $time4 = explode(" ", $time4);
- $hoursMinutes = explode(":", $time4[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time4[1] == "PM")
- {
- $time4[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time4[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time3'] = $time4[0];
- $program_list[$count]['start_time4'] = $time4[0];
- $program_list[$count]['title4'] = $title4;
- //time5
- $time5 = $html_two->find('span[id=time5]', 0)->plaintext;
- $title5 = $html_two->find('span[id=title5]', 0)->plaintext;
- $time5 = explode(" ", $time5);
- $hoursMinutes = explode(":", $time5[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time5[1] == "PM")
- {
- $time5[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time5[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time4'] = $time5[0];
- $program_list[$count]['start_time5'] = $time5[0];
- $program_list[$count]['title5'] = $title5;
- //time6
- $time6 = $html_two->find('span[id=time6]', 0)->plaintext;
- $title6 = $html_two->find('span[id=title6]', 0)->plaintext;
- $time6 = explode(" ", $time6);
- $hoursMinutes = explode(":", $time6[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time6[1] == "PM")
- {
- $time6[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time6[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time5'] = $time6[0];
- $program_list[$count]['start_time6'] = $time6[0];
- $program_list[$count]['title6'] = $title6;
- //time7
- $time7 = $html_two->find('span[id=time7]', 0)->plaintext;
- $title7 = $html_two->find('span[id=title7]', 0)->plaintext;
- $time7 = explode(" ", $time7);
- $hoursMinutes = explode(":", $time7[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time7[1] == "PM")
- {
- $time7[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time7[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time6'] = $time7[0];
- $program_list[$count]['start_time7'] = $time7[0];
- $program_list[$count]['title7'] = $title7;
- //time8
- $time8 = $html_two->find('span[id=time8]', 0)->plaintext;
- $title8 = $html_two->find('span[id=title8]', 0)->plaintext;
- $time8 = explode(" ", $time8);
- $hoursMinutes = explode(":", $time8[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time8[1] == "PM")
- {
- $time8[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time8[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time7'] = $time8[0];
- $program_list[$count]['start_time8'] = $time8[0];
- $program_list[$count]['title8'] = $title8;
- //time9
- $time9 = $html_two->find('span[id=time9]', 0)->plaintext;
- $title9 = $html_two->find('span[id=title9]', 0)->plaintext;
- $time9 = explode(" ", $time9);
- $hoursMinutes = explode(":", $time9[0]);
- $hours = $hoursMinutes[0];
- $minutes = $hoursMinutes[1];
- if($time9[1] == "PM")
- {
- $time9[0] = date("Ymd") . ((int)($hours) + 12) . $minutes . "00";
- }
- else
- {
- $time9[0] = date("Ymd") . $hours . $minutes . "00";
- }
- $program_list[$count]['end_time8'] = $time9[0];
- $program_list[$count]['start_time9'] = $time9[0];
- $program_list[$count]['title9'] = $title9;
- $count++;
- }
- var_dump($program_list);
- $xml = "<?xml version='1.0' encoding='UTF-8' ?>
- <tv generator-info-name='www.testbox.elementfx.com/xmltv'>";
- for($i = 0; $i < count($program_list); $i++)
- {
- if(!isset($program_list[$i]['start_time1']))
- {
- continue;
- }
- $xml .= "<channel id='" . $program_list[$i]['channels'] . "'>";
- $xml .= "<display-name>" . $program_list[$i]['channels'] . "</display-name>";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time1'] . "' stop='" . $program_list[$i]['end_time1'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time2'] . "' stop='" . $program_list[$i]['end_time2'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time3'] . "' stop='" . $program_list[$i]['end_time3'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time4'] . "' stop='" . $program_list[$i]['end_time4'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time5'] . "' stop='" . $program_list[$i]['end_time5'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time6'] . "' stop='" . $program_list[$i]['end_time6'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time7'] . "' stop='" . $program_list[$i]['end_time7'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time8'] . "' stop='" . $program_list[$i]['end_time8'] . "'>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>\n";
- $xml .= "<programme channel='" . $program_list[$i]['channels'] . "' start='" . $program_list[$i]['start_time9'] . "' stop=''>";
- $xml .= "<title lang='en'></title>";
- $xml .= "<sub-title lang='en'></sub-title>";
- $xml .= "<desc lang='en'></desc>";
- $xml .= "<category lang='en'></category>";
- $xml .= "</programme>";
- $xml .= "</channel>\n";
- }
- $xml .= "</tv>";
- header("Content-Type: text/xml");
- echo $xml;
- $handle = fopen("myChannel.xml", "w");
- fwrite ($handle, $xml);
- exit;
- if(!$channels && ! $id)
- {
- $qrytable1="SELECT id, channels, links, streams FROM tvguide";
- $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
- while ($row = mysql_fetch_array($result1))
- {
- // fake some example data. the actual data would be retrieved from a database query
- $data[] = array('channel_id'=>$row['channels'],
- 'display_name'=>$row['channels'],
- 'program_id'=>123,'start'=>'s1','stop'=>'e1',
- 'title'=>'program title',
- 'sub_title'=>'sub title',
- 'description'=>'program description1',
- 'category'=>'some category');
- // build the xml
- $xml = '<?xml version="1.0" encoding="UTF-8" ?>
- <tv generator-info-name="www.testbox.elementfx.com/xmltv">';
- $last_channel = null; // used to detect when the channel changes
- foreach($data as $arr)
- {
- if($last_channel != $arr['channel_id'])
- {
- // the channel changed
- if($last_channel != null)
- {
- // not the first channel, close out the previous channel
- $xml .= "
- </channel> \n";
- }
- // start a new channel
- $xml .= "
- <channel id=\"{$arr['channel_id']}\">";
- $xml .= "
- <display-name>{$arr['display_name']}</display-name>";
- $last_channel = $arr['channel_id'];
- }
- // output the program info under each channel
- $xml .= "
- <programme channel=\"{$arr['channel_id']}\" start=\"{$arr['start']}\" stop=\"{$arr['stop']}\">";
- // i don't see a program id in this definition, but it likely needs one
- $xml .= "
- <title lang=\"en\">{$arr['title']}</title>";
- $xml .= "
- <sub-title lang=\"en\">{$arr['sub_title']}</sub-title>";
- $xml .= "
- <desc lang=\"en\">{$arr['description']}</desc>";
- $xml .= "
- <category lang=\"en\">{$arr['category']}</category>";
- $xml .= "
- </programme>";
- }
- if($last_channel != null)
- {
- // close out the previous channel if any
- $xml .= '
- </channel>';
- }
- }
- }
- $xml .= '
- </tv>';
- // output the xml to the browser in this example, write $xml to a file here...
- header("Content-Type: text/xml");
- echo $xml;
- ?>
- <!-- <html>
- <script>
- setTimeout(function(){location.href = "myChannel.xml";},1000){
- }
- </script>
- </html> -->
- <?php
- $handle = fopen("myChannel.xml", "w");
- fwrite ($handle, $xml);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement