From db5ff22285cb517b781c779015730f59d271c6d0 Mon Sep 17 00:00:00 2001 From: surya432 Date: Mon, 20 Apr 2020 01:33:55 +0700 Subject: [PATCH] modif player --- app/GoogleDrivePlayer.php | 12 + .../GoogleDrivePlayerController.php | 93 ++ composer.json | 1 + composer.lock | 97 +- ...1459_create_google_drive_players_table.php | 34 + public/cookies/cookies1.txt | 5 - public/cookies/cookies2.txt | 5 - public/cookies/cookies3.txt | 5 - public/cookies/cookies4.txt | 5 - public/cookies/cookies5.txt | 5 - public/curl_gd.php | 282 ++-- public/embed.php | 7 +- public/google.mp3 | 2 +- public/player/curl_gd.php | 1394 ----------------- public/player/embed.php | 41 - public/player/google.mp3 | 34 - public/player/index.php | 69 - public/player/json.php | 93 -- .../views/googledrivePlayer/create.blade.php | 32 + .../views/googledrivePlayer/edit.blade.php | 34 + .../views/googledrivePlayer/index.blade.php | 197 +++ resources/views/parts/sidebar.blade.php | 11 +- routes/web.php | 2 + 23 files changed, 696 insertions(+), 1764 deletions(-) create mode 100644 app/GoogleDrivePlayer.php create mode 100644 app/Http/Controllers/GoogleDrivePlayerController.php create mode 100644 database/migrations/2020_04_20_011459_create_google_drive_players_table.php delete mode 100644 public/cookies/cookies1.txt delete mode 100644 public/cookies/cookies2.txt delete mode 100644 public/cookies/cookies3.txt delete mode 100644 public/cookies/cookies4.txt delete mode 100644 public/cookies/cookies5.txt delete mode 100644 public/player/curl_gd.php delete mode 100644 public/player/embed.php delete mode 100644 public/player/google.mp3 delete mode 100644 public/player/index.php delete mode 100644 public/player/json.php create mode 100644 resources/views/googledrivePlayer/create.blade.php create mode 100644 resources/views/googledrivePlayer/edit.blade.php create mode 100644 resources/views/googledrivePlayer/index.blade.php diff --git a/app/GoogleDrivePlayer.php b/app/GoogleDrivePlayer.php new file mode 100644 index 00000000..2f9bddd6 --- /dev/null +++ b/app/GoogleDrivePlayer.php @@ -0,0 +1,12 @@ +delete(); + return $this->sendResponse($googleDrivePlayer->toArray(), 'googleDrivePlayer deleted successfully.'); + } + public function getlist(){ + $data = GoogleDrivePlayer::where('status','active')->random(1)->first(); + return response()->json($data); + } +} diff --git a/composer.json b/composer.json index e5da70d9..796dcbb4 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "laravelcollective/html": "^5.2.0", "maatwebsite/excel": "^3.1", "nesbot/carbon": "^1.0", + "sunra/php-simple-html-dom-parser": "^1.5", "torann/geoip": "^1.0", "weidner/goutte": "^1.3", "yajra/laravel-datatables": "^1.0" diff --git a/composer.lock b/composer.lock index 6ab05f57..c073008e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "edd0b0bfcf7c872b67f1a97154bc1f40", + "content-hash": "c36830bde693eee7276818d3d1301dc1", "packages": [ { "name": "cartalyst/sentinel", @@ -1140,6 +1140,7 @@ "email": "jakub.onderka@gmail.com" } ], + "abandoned": "php-parallel-lint/php-console-color", "time": "2018-09-29T17:23:10+00:00" }, { @@ -1186,6 +1187,7 @@ } ], "description": "Highlight PHP code in terminal", + "abandoned": "php-parallel-lint/php-console-highlighter", "time": "2018-09-29T18:48:56+00:00" }, { @@ -3217,6 +3219,54 @@ ], "time": "2019-12-01T04:55:27+00:00" }, + { + "name": "sunra/php-simple-html-dom-parser", + "version": "v1.5.2", + "source": { + "type": "git", + "url": "https://github.com/sunra/php-simple-html-dom-parser.git", + "reference": "75b9b1cb64502d8f8c04dc11b5906b969af247c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sunra/php-simple-html-dom-parser/zipball/75b9b1cb64502d8f8c04dc11b5906b969af247c6", + "reference": "75b9b1cb64502d8f8c04dc11b5906b969af247c6", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.3.2" + }, + "type": "library", + "autoload": { + "psr-0": { + "Sunra\\PhpSimple\\HtmlDomParser": "Src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sunra", + "email": "sunra@yandex.ru", + "homepage": "https://github.com/sunra" + }, + { + "name": "S.C. Chen", + "homepage": "http://sourceforge.net/projects/simplehtmldom/" + } + ], + "description": "Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.", + "homepage": "https://github.com/sunra/php-simple-html-dom-parser", + "keywords": [ + "dom", + "html", + "parser" + ], + "time": "2016-11-22T22:57:47+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.2.3", @@ -4201,6 +4251,20 @@ "portable", "shim" ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-03-09T19:04:49+00:00" }, { @@ -4260,6 +4324,20 @@ "portable", "shim" ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-03-09T19:04:49+00:00" }, { @@ -4315,6 +4393,20 @@ "portable", "shim" ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-02-27T09:26:54+00:00" }, { @@ -7137,5 +7229,6 @@ "platform": { "php": "^7.1.3" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/database/migrations/2020_04_20_011459_create_google_drive_players_table.php b/database/migrations/2020_04_20_011459_create_google_drive_players_table.php new file mode 100644 index 00000000..733d620a --- /dev/null +++ b/database/migrations/2020_04_20_011459_create_google_drive_players_table.php @@ -0,0 +1,34 @@ +bigIncrements('id'); + $table->string('email'); + $table->text('cookiestext'); + $table->string('status'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('google_drive_players'); + } +} diff --git a/public/cookies/cookies1.txt b/public/cookies/cookies1.txt deleted file mode 100644 index f3ee7fd0..00000000 --- a/public/cookies/cookies1.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.haxx.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_.google.com TRUE / FALSE 1602431775 NID 202=U8r8fn3W5zP8eXzUlTho1973-jK7uvrmX97RrHxJSEfOBsaQ4EuAZJB1XtYYSD3xakqmW-CRzdkhrBTBylt1NvzzuNJjj_Ywr1JOVDna0Bf0gJKeqeObhTiRaOlvMNDkjSI4FBytBY1n5WeOn6GuNb9BUVGWYrW_1hw2Vqgg8ck diff --git a/public/cookies/cookies2.txt b/public/cookies/cookies2.txt deleted file mode 100644 index f3ee7fd0..00000000 --- a/public/cookies/cookies2.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.haxx.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_.google.com TRUE / FALSE 1602431775 NID 202=U8r8fn3W5zP8eXzUlTho1973-jK7uvrmX97RrHxJSEfOBsaQ4EuAZJB1XtYYSD3xakqmW-CRzdkhrBTBylt1NvzzuNJjj_Ywr1JOVDna0Bf0gJKeqeObhTiRaOlvMNDkjSI4FBytBY1n5WeOn6GuNb9BUVGWYrW_1hw2Vqgg8ck diff --git a/public/cookies/cookies3.txt b/public/cookies/cookies3.txt deleted file mode 100644 index f3ee7fd0..00000000 --- a/public/cookies/cookies3.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.haxx.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_.google.com TRUE / FALSE 1602431775 NID 202=U8r8fn3W5zP8eXzUlTho1973-jK7uvrmX97RrHxJSEfOBsaQ4EuAZJB1XtYYSD3xakqmW-CRzdkhrBTBylt1NvzzuNJjj_Ywr1JOVDna0Bf0gJKeqeObhTiRaOlvMNDkjSI4FBytBY1n5WeOn6GuNb9BUVGWYrW_1hw2Vqgg8ck diff --git a/public/cookies/cookies4.txt b/public/cookies/cookies4.txt deleted file mode 100644 index f3ee7fd0..00000000 --- a/public/cookies/cookies4.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.haxx.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_.google.com TRUE / FALSE 1602431775 NID 202=U8r8fn3W5zP8eXzUlTho1973-jK7uvrmX97RrHxJSEfOBsaQ4EuAZJB1XtYYSD3xakqmW-CRzdkhrBTBylt1NvzzuNJjj_Ywr1JOVDna0Bf0gJKeqeObhTiRaOlvMNDkjSI4FBytBY1n5WeOn6GuNb9BUVGWYrW_1hw2Vqgg8ck diff --git a/public/cookies/cookies5.txt b/public/cookies/cookies5.txt deleted file mode 100644 index f3ee7fd0..00000000 --- a/public/cookies/cookies5.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.haxx.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_.google.com TRUE / FALSE 1602431775 NID 202=U8r8fn3W5zP8eXzUlTho1973-jK7uvrmX97RrHxJSEfOBsaQ4EuAZJB1XtYYSD3xakqmW-CRzdkhrBTBylt1NvzzuNJjj_Ywr1JOVDna0Bf0gJKeqeObhTiRaOlvMNDkjSI4FBytBY1n5WeOn6GuNb9BUVGWYrW_1hw2Vqgg8ck diff --git a/public/curl_gd.php b/public/curl_gd.php index 5afe7762..afae3558 100644 --- a/public/curl_gd.php +++ b/public/curl_gd.php @@ -12,10 +12,11 @@ function GoogleDrive($gid) //$title = gdTitle($gid); //$img = gdImg($gdurl); $streaming_vid = Drive($gid, "1"); + if (empty($streaming_vid) || is_null($streaming_vid) || $streaming_vid == "Error") { $streaming_vid = Drive($gid, "2"); if (empty($streaming_vid) || is_null($streaming_vid) || $streaming_vid == "Error") { - $keys = array('AIzaSyCNxXAnWvUkdi0m7XTkC-EFHb2z2MQMtRo', 'AIzaSyCSqEAuMN_6svup7oZc_v9JRq1PHOQ_2dE', 'AIzaSyD7jsVh3vlw-xhJcklRTugVDSwdnfxMma4', 'AIzaSyDVP1vHDb9fP2fNAhd4GSRRspLMFyVt_X0', 'AIzaSyAFin5-mcY0LhVmjZ56jnVkuUyomb8qf6E', 'AIzaSyACZPjRqcxAS4q_J-MP-dAfMzZVUKqh-2Y','AIzaSyBnkAWXQIDhSTXuCpsmh5bfBgvgm_XdXG0','AIzaSyBWcqH-i6qgdTXjK34jADTgm_NgaJegb2c'); + $keys = array('AIzaSyCNxXAnWvUkdi0m7XTkC-EFHb2z2MQMtRo', 'AIzaSyCSqEAuMN_6svup7oZc_v9JRq1PHOQ_2dE', 'AIzaSyD7jsVh3vlw-xhJcklRTugVDSwdnfxMma4', 'AIzaSyDVP1vHDb9fP2fNAhd4GSRRspLMFyVt_X0', 'AIzaSyAFin5-mcY0LhVmjZ56jnVkuUyomb8qf6E', 'AIzaSyACZPjRqcxAS4q_J-MP-dAfMzZVUKqh-2Y', 'AIzaSyBnkAWXQIDhSTXuCpsmh5bfBgvgm_XdXG0', 'AIzaSyBWcqH-i6qgdTXjK34jADTgm_NgaJegb2c'); $output = ['label' => 'auto', 'file' => 'https://www.googleapis.com/drive/v3/files/' . $gid . '?alt=media&key=' . $keys[array_rand($keys)], 'type' => 'video/mp4']; $output = json_encode($output, JSON_PRETTY_PRINT); return $output; @@ -31,6 +32,7 @@ function Drive($gid, $try) { $timeout = 900; $file_name = md5('GD' . $gid . 'player' . $try); + // return $file_name; if (file_exists('cache/' . $file_name . '.cache')) { $fopen = file_get_contents('cache/' . $file_name . '.cache'); $data = explode('@@', $fopen); @@ -38,17 +40,19 @@ function Drive($gid, $try) $times = strtotime($now) - $data[0]; if ($times >= $timeout) { $linkdown = trim(getlink($gid, $try)); - $create_cache = gd_cache($gid . $try, $linkdown); + $create_cache = gd_cache($file_name, $linkdown); $arrays = explode('|', $create_cache); $cache = $arrays[0]; + $cache = $linkdown; + } else { $cache = $data[1]; } } else { - $linkdown = trim(getlink($gid,$try)); - $create_cache = gd_cache($gid, $linkdown); + $linkdown = trim(getlink($gid, $try)); + $create_cache = gd_cache($file_name, $linkdown); $arrays = explode('|', $create_cache); - $cache = $arrays[0]; + $cache = $linkdown; } return $cache; } @@ -56,11 +60,11 @@ function Drive($gid, $try) //New cache function gd_cache($gid, $source) { - if ($source == '404') { - return 'Error|a'; + if ($source == '404' || is_null($source) || empty($source)) { + return 'Error'; } $time = gmdate('Y-m-d H:i:s', time() + 3600 * (+7 + date('I'))); - $file_name = md5('GD' . $gid . 'player'); + $file_name = $gid; $string = strtotime($time) . '@@' . $source; $file = fopen("cache/" . $file_name . ".cache", 'w'); fwrite($file, $string); @@ -72,20 +76,24 @@ function gd_cache($gid, $source) } return $msn; } - +function getCookies(){ + return ""; +} function getlink($id, $try) { $link = "https://drive.google.com/uc?export=download&id=$id"; $ch = curl_init(); + $cookies = "cookies" . rand(1, 5); + $jsoncookies = getCookies(); curl_setopt($ch, CURLOPT_URL, $link); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 300); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 10); + // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); if ($try == "2") { - curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookies/cookies" . rand(1, 5) . ".txt"); - curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookies/cookies" . rand(1, 5) . ".txt"); + curl_setopt($ch, CURLOPT_COOKIE, $jsoncookies); } else { curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/google.mp3"); curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/google.mp3"); @@ -94,14 +102,12 @@ function getlink($id, $try) $get = locheader($page); if (strpos($page, "Can't")) { //'Sorry, the owner hasn\'t given you permission to download this file.'; - $get = '404'; + $get = ''; } elseif (strpos($page, "Error 404")) { //Error 404. We\'re sorry. You can\'t access this item because it is in violation of our Terms of Service. - $get = '404'; + $get = ''; } else { - if ($get != "") { - $get = '404'; - } else { + if ($get != "") { } else { $html = str_get_html($page); $link = urldecode(trim($html->find('a[id=uc-download-link]', 0)->href)); $tmp = explode("confirm=", $link); @@ -115,14 +121,11 @@ function getlink($id, $try) curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 600); if ($try == "2") { - curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookies/cookies" . rand(1, 5) . ".txt"); - curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookies/cookies" . rand(1, 5) . ".txt"); + curl_setopt($ch, CURLOPT_COOKIE, $jsoncookies); } else { curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/google.mp3"); curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/google.mp3"); } - - // Getting binary data $page = curl_exec($ch); $get = locheader($page); } @@ -237,10 +240,19 @@ function locheader($page) $temp = explode("\r\n", $page); foreach ($temp as $item) { $temp2 = explode(": ", $item); - $infoheader[$temp2[0]] = $temp2[1]; + if (isset($temp2[1])) { + $infoheader[$temp2[0]] = $temp2[1]; + } + } + if (isset($infoheader['location'])) { + $location = $infoheader['location']; + return $location; + } + if (isset($infoheader['Location'])) { + $location = $infoheader['Location']; + return $location; } - $location = $infoheader['Location']; - return $location; + return ""; } function file_get_html() @@ -277,7 +289,6 @@ function dump_html_tree($node, $show_attr = true, $deep = 0) foreach ($node->nodes as $c) { dump_html_tree($c, $show_attr, $deep + 1); } - } // simple html dom node @@ -453,7 +464,6 @@ public function outertext() foreach ($this->nodes as $n) { $ret .= $n->outertext(); } - } // render end tag @@ -472,9 +482,12 @@ public function text() } switch ($this->nodetype) { - case HDOM_TYPE_TEXT:return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - case HDOM_TYPE_COMMENT:return ''; - case HDOM_TYPE_UNKNOWN:return ''; + case HDOM_TYPE_TEXT: + return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); + case HDOM_TYPE_COMMENT: + return ''; + case HDOM_TYPE_UNKNOWN: + return ''; } if (strcasecmp($this->tag, 'script') === 0) { return ''; @@ -525,11 +538,14 @@ public function makeup() $ret .= $key; } else { switch ($this->_[HDOM_INFO_QUOTE][$i]) { - case HDOM_QUOTE_DOUBLE:$quote = '"'; + case HDOM_QUOTE_DOUBLE: + $quote = '"'; break; - case HDOM_QUOTE_SINGLE:$quote = '\''; + case HDOM_QUOTE_SINGLE: + $quote = '\''; break; - default:$quote = ''; + default: + $quote = ''; } $ret .= $key . $this->_[HDOM_INFO_SPACE][$i][1] . '=' . $this->_[HDOM_INFO_SPACE][$i][2] . $quote . $val . $quote; } @@ -574,7 +590,6 @@ public function find($selector, $idx = null) if (!isset($found_keys[$k])) { $found_keys[$k] = 1; } - } } @@ -638,18 +653,18 @@ protected function seek($selector, &$ret) } // compare tag - if ($tag && $tag != $node->tag && $tag !== '*') {$pass = false;} + if ($tag && $tag != $node->tag && $tag !== '*') { + $pass = false; + } // compare key if ($pass && $key) { if ($no_key) { if (isset($node->attr[$key])) { $pass = false; } - } else if (!isset($node->attr[$key])) { $pass = false; } - } // compare value if ($pass && $key && $val && $val !== '*') { @@ -661,13 +676,11 @@ protected function seek($selector, &$ret) if ($check) { break; } - } } if (!$check) { $pass = false; } - } if ($pass) { $ret[$i] = 1; @@ -719,20 +732,34 @@ protected function parse_selector($selector_string) } list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); - if (!empty($m[2])) {$key = 'id'; - $val = $m[2];} - if (!empty($m[3])) {$key = 'class'; - $val = $m[3];} - if (!empty($m[4])) {$key = $m[4];} - if (!empty($m[5])) {$exp = $m[5];} - if (!empty($m[6])) {$val = $m[6];} + if (!empty($m[2])) { + $key = 'id'; + $val = $m[2]; + } + if (!empty($m[3])) { + $key = 'class'; + $val = $m[3]; + } + if (!empty($m[4])) { + $key = $m[4]; + } + if (!empty($m[5])) { + $exp = $m[5]; + } + if (!empty($m[6])) { + $val = $m[6]; + } // convert to lowercase - if ($this->dom->lowercase) {$tag = strtolower($tag); - $key = strtolower($key);} + if ($this->dom->lowercase) { + $tag = strtolower($tag); + $key = strtolower($key); + } //elements that do NOT have the specified attribute - if (isset($key[0]) && $key[0] === '!') {$key = substr($key, 1); - $no_key = true;} + if (isset($key[0]) && $key[0] === '!') { + $key = substr($key, 1); + $no_key = true; + } $result[] = array($tag, $key, $val, $exp, $no_key); if (trim($m[7]) === ',') { @@ -754,18 +781,24 @@ public function __get($name) } switch ($name) { - case 'outertext':return $this->outertext(); - case 'innertext':return $this->innertext(); - case 'plaintext':return $this->text(); - case 'xmltext':return $this->xmltext(); - default:return array_key_exists($name, $this->attr); + case 'outertext': + return $this->outertext(); + case 'innertext': + return $this->innertext(); + case 'plaintext': + return $this->text(); + case 'xmltext': + return $this->xmltext(); + default: + return array_key_exists($name, $this->attr); } } public function __set($name, $value) { switch ($name) { - case 'outertext':return $this->_[HDOM_INFO_OUTER] = $value; + case 'outertext': + return $this->_[HDOM_INFO_OUTER] = $value; case 'innertext': if (isset($this->_[HDOM_INFO_TEXT])) { return $this->_[HDOM_INFO_TEXT] = $value; @@ -783,9 +816,12 @@ public function __set($name, $value) public function __isset($name) { switch ($name) { - case 'outertext':return true; - case 'innertext':return true; - case 'plaintext':return true; + case 'outertext': + return true; + case 'innertext': + return true; + case 'plaintext': + return true; } //no value attr: nowrap, checked selected... return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]); @@ -796,40 +832,69 @@ public function __unset($name) if (isset($this->attr[$name])) { unset($this->attr[$name]); } - } // camel naming conventions public function getAllAttributes() - {return $this->attr;} + { + return $this->attr; + } public function getAttribute($name) - {return $this->__get($name);} + { + return $this->__get($name); + } public function setAttribute($name, $value) - {$this->__set($name, $value);} + { + $this->__set($name, $value); + } public function hasAttribute($name) - {return $this->__isset($name);} + { + return $this->__isset($name); + } public function removeAttribute($name) - {$this->__set($name, null);} + { + $this->__set($name, null); + } public function getElementById($id) - {return $this->find("#$id", 0);} + { + return $this->find("#$id", 0); + } public function getElementsById($id, $idx = null) - {return $this->find("#$id", $idx);} + { + return $this->find("#$id", $idx); + } public function getElementByTagName($name) - {return $this->find($name, 0);} + { + return $this->find($name, 0); + } public function getElementsByTagName($name, $idx = null) - {return $this->find($name, $idx);} + { + return $this->find($name, $idx); + } public function parentNode() - {return $this->parent();} + { + return $this->parent(); + } public function childNodes($idx = -1) - {return $this->children($idx);} + { + return $this->children($idx); + } public function firstChild() - {return $this->first_child();} + { + return $this->first_child(); + } public function lastChild() - {return $this->last_child();} + { + return $this->last_child(); + } public function nextSibling() - {return $this->next_sibling();} + { + return $this->next_sibling(); + } public function previousSibling() - {return $this->prev_sibling();} + { + return $this->prev_sibling(); + } } // simple html dom parser @@ -874,7 +939,6 @@ public function __construct($str = null) } else { $this->load($str); } - } } @@ -950,10 +1014,18 @@ public function find($selector, $idx = null) // clean up memory due to php5 circular references memory leak... public function clear() { - foreach ($this->nodes as $n) {$n->clear(); - $n = null;} - if (isset($this->parent)) {$this->parent->clear();unset($this->parent);} - if (isset($this->root)) {$this->root->clear();unset($this->root);} + foreach ($this->nodes as $n) { + $n->clear(); + $n = null; + } + if (isset($this->parent)) { + $this->parent->clear(); + unset($this->parent); + } + if (isset($this->root)) { + $this->root->clear(); + unset($this->root); + } unset($this->doc); unset($this->noise); } @@ -983,7 +1055,6 @@ protected function prepare($str, $lowercase = true) if ($this->size > 0) { $this->char = $this->doc[0]; } - } // parse html content @@ -1062,7 +1133,6 @@ protected function read_tag() } else { return $this->as_text_node($tag); } - } $this->parent->_[HDOM_INFO_END] = $this->cursor; @@ -1202,7 +1272,6 @@ protected function read_tag() } else { break; } - } while ($this->char !== '>' && $this->char !== '/'); $this->link_nodes($node, true); @@ -1217,7 +1286,6 @@ protected function read_tag() if (!isset($this->self_closing_tags[strtolower($node->tag)])) { $this->parent = $node; } - } $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next return true; @@ -1254,7 +1322,6 @@ protected function link_nodes(&$node, $is_child) if ($is_child) { $this->parent->children[] = $node; } - } // as a text node @@ -1367,7 +1434,6 @@ protected function remove_noise($pattern, $remove_tag = false) if ($this->size > 0) { $this->char = $this->doc[0]; } - } // restore noise to html content @@ -1378,7 +1444,6 @@ public function restore_noise($text) if (isset($this->noise[$key])) { $text = substr($text, 0, $pos) . $this->noise[$key] . substr($text, $pos + 14); } - } return $text; } @@ -1391,28 +1456,47 @@ public function __toString() public function __get($name) { switch ($name) { - case 'outertext':return $this->root->innertext(); - case 'innertext':return $this->root->innertext(); - case 'plaintext':return $this->root->text(); + case 'outertext': + return $this->root->innertext(); + case 'innertext': + return $this->root->innertext(); + case 'plaintext': + return $this->root->text(); } } // camel naming conventions public function childNodes($idx = -1) - {return $this->root->childNodes($idx);} + { + return $this->root->childNodes($idx); + } public function firstChild() - {return $this->root->first_child();} + { + return $this->root->first_child(); + } public function lastChild() - {return $this->root->last_child();} + { + return $this->root->last_child(); + } public function getElementById($id) - {return $this->find("#$id", 0);} + { + return $this->find("#$id", 0); + } public function getElementsById($id, $idx = null) - {return $this->find("#$id", $idx);} + { + return $this->find("#$id", $idx); + } public function getElementByTagName($name) - {return $this->find($name, 0);} + { + return $this->find($name, 0); + } public function getElementsByTagName($name, $idx = -1) - {return $this->find($name, $idx);} + { + return $this->find($name, $idx); + } public function loadFile() - {$args = func_get_args(); - $this->load(call_user_func_array('file_get_contents', $args), true);} + { + $args = func_get_args(); + $this->load(call_user_func_array('file_get_contents', $args), true); + } } diff --git a/public/embed.php b/public/embed.php index 4fd93a47..452dd8be 100644 --- a/public/embed.php +++ b/public/embed.php @@ -51,9 +51,8 @@ function url() return $protocol . "://gd." . $_SERVER['HTTP_HOST']; } if (isset($_GET['id'])) { - $eid = htmlspecialchars($_GET['id']); - $gid = my_simple_crypt($eid, 'd'); - // url() . + $gid = htmlspecialchars($_GET['id']); + $gid = my_simple_crypt($gid, 'd'); // $results = file_get_contents('https://gd.nontonindrama.com/Player-Script/json.php?url=https://drive.google.com/file/d/' . $gid . '/preview'); $gid = get_drive_id("https://drive.google.com/file/d/$gid/view"); $sourcesvideo = GoogleDrive($gid); @@ -147,6 +146,8 @@ function() { if (isset($results)) { echo $results; } + }else{ + echo "nothing"; } ?> diff --git a/public/google.mp3 b/public/google.mp3 index 81f46e2d..eedf1a1c 100644 --- a/public/google.mp3 +++ b/public/google.mp3 @@ -2,4 +2,4 @@ # https://curl.haxx.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. -#HttpOnly_.google.com TRUE / FALSE 1589468793 NID 191=OfR8FXLJ51jG1z_k_VKeTAgNBkh9J_nXPkpaUoLAa__pLAWuPTpZRgHW0ovOl9Ui9KrlVu91ubOUlNSDKGmTTmMZ6K2DbceYF2Rw14ZBNzWAcVSzYnYMKSeqDCXW6BT2gYAcgKUzaYwUIAJVAWdq6rEvkJK6qnGY1t6nhjilgOo +#HttpOnly_.google.com TRUE / FALSE 1603124248 NID 202=ZbLiAEc3dh3UA9Pl8M0SGht6yCGruXR_2u36_EthXjRFs4JkgKGMGYIT9AcSpVcU7fTHMPyNw0f8JSjT0RNfKJJBVO6DIgxa2E9tGP-A_6PR8c60SnorgLAddA-r8Tk1lHT1pjdHHlLOQeeWYcEMlBluS6KN9YccFRLTkLETCtI diff --git a/public/player/curl_gd.php b/public/player/curl_gd.php deleted file mode 100644 index 783d6ccc..00000000 --- a/public/player/curl_gd.php +++ /dev/null @@ -1,1394 +0,0 @@ - 'auto', 'file' => $streaming_vid, 'type' => 'video/mp4']; - $output = json_encode($output, JSON_PRETTY_PRINT); - return $output; -} - -//Check cache -function Drive($gid) -{ - $timeout = 900; - $file_name = md5('GD' . $gid . 'player'); - if (file_exists('cache/' . $file_name . '.cache')) { - $fopen = file_get_contents('cache/' . $file_name . '.cache'); - $data = explode('@@', $fopen); - $now = gmdate('Y-m-d H:i:s', time() + 3600 * (+7 + date('I'))); - $times = strtotime($now) - $data[0]; - if ($times >= $timeout) { - $linkdown = trim(getlink($gid)); - $create_cache = gd_cache($gid, $linkdown); - $arrays = explode('|', $create_cache); - $cache = $arrays[0]; - } else { - $cache = $data[1]; - } - } else { - $linkdown = trim(getlink($gid)); - $create_cache = gd_cache($gid, $linkdown); - $arrays = explode('|', $create_cache); - $cache = $arrays[0]; - } - return $cache; -} - -//New cache -function gd_cache($gid, $source) -{ - $time = gmdate('Y-m-d H:i:s', time() + 3600 * (+7 + date('I'))); - $file_name = md5('GD' . $gid . 'player'); - $string = strtotime($time) . '@@' . $source; - $file = fopen("cache/" . $file_name . ".cache", 'w'); - fwrite($file, $string); - fclose($file); - if (file_exists('cache/' . $file_name . '.cache')) { - $msn = $source; - } else { - $msn = $source; - } - return $msn; -} - -function getlink($id) -{ - $link = "https://drive.google.com/uc?export=download&id=$id"; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $link); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/google.mp3"); - curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/google.mp3"); - $page = curl_exec($ch); - $get = locheader($page); - if (strpos($page, "Can't")) { - //'Sorry, the owner hasn\'t given you permission to download this file.'; - $get = '1'; - } elseif (strpos($page, "Error 404")) { - //Error 404. We\'re sorry. You can\'t access this item because it is in violation of our Terms of Service. - $get = '2'; - } else { - if ($get != "") { - - } else { - $html = str_get_html($page); - $link = urldecode(trim($html->find('a[id=uc-download-link]', 0)->href)); - $tmp = explode("confirm=", $link); - $tmp2 = explode("&", $tmp[1]); - $confirm = $tmp2[0]; - $linkdowngoc = "https://drive.google.com/uc?export=download&id=$id&confirm=$confirm"; - curl_setopt($ch, CURLOPT_URL, $linkdowngoc); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/google.mp3"); - curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/google.mp3"); - - // Getting binary data - $page = curl_exec($ch); - $get = locheader($page); - } - curl_close($ch); - } - return $get; -} - -function gdTitle($gid) -{ - $title = fetch_value(file_get_contents('https://drive.google.com/get_video_info?docid=' . $gid), "title=", "&"); - return $title; -} - -function gdImg($url) -{ - $html = new simple_html_dom(); - $html->load_file($url); - return $html->find('meta[property=og:image]', 0)->attr['content']; -} - -function get_drive_id($string) -{ - if (strpos($string, "/edit")) { - $string = str_replace("/edit", "/view", $string); - } else if (strpos($string, "?id=")) { - $parts = parse_url($string); - parse_str($parts['query'], $query); - return $query['id']; - } else if (!strpos($string, "/view")) { - $string = $string . "/view"; - } - $start = "file/d/"; - - if (strpos($string, "/preview")) { - $end = "/preview"; - } elseif (strpos($string, "/view")) { - $end = "/view"; - } - $string = " " . $string; - $ini = strpos($string, $start); - if ($ini == 0) { - return null; - } - $ini += strlen($start); - $len = strpos($string, $end, $ini) - $ini; - return substr($string, $ini, $len); -} - -function my_simple_crypt($string, $action = 'e') -{ - $secret_key = 'GReg7rNx2z[2'; - $secret_iv = 'C0?s9rh4'; - $output = false; - $encrypt_method = "AES-256-CBC"; - $key = hash('sha256', $secret_key); - $iv = substr(hash('sha256', $secret_iv), 0, 16); - if ($action == 'e') { - $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv)); - } else if ($action == 'd') { - $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); - } - return $output; -} - -function fetch_value($str, $find_start = '', $find_end = '') -{ - if ($find_start == '') { - return ''; - } - $start = strpos($str, $find_start); - if ($start === false) { - return ''; - } - $length = strlen($find_start); - $substr = substr($str, $start + $length); - if ($find_end == '') { - return $substr; - } - $end = strpos($substr, $find_end); - if ($end === false) { - return $substr; - } - - return substr($substr, 0, $end); -} - -// helper functions -// ----------------------------------------------------------------------------- -// get html dom form file - -define('HDOM_TYPE_ELEMENT', 1); -define('HDOM_TYPE_COMMENT', 2); -define('HDOM_TYPE_TEXT', 3); -define('HDOM_TYPE_ENDTAG', 4); -define('HDOM_TYPE_ROOT', 5); -define('HDOM_TYPE_UNKNOWN', 6); -define('HDOM_QUOTE_DOUBLE', 0); -define('HDOM_QUOTE_SINGLE', 1); -define('HDOM_QUOTE_NO', 3); -define('HDOM_INFO_BEGIN', 0); -define('HDOM_INFO_END', 1); -define('HDOM_INFO_QUOTE', 2); -define('HDOM_INFO_SPACE', 3); -define('HDOM_INFO_TEXT', 4); -define('HDOM_INFO_INNER', 5); -define('HDOM_INFO_OUTER', 6); -define('HDOM_INFO_ENDSPACE', 7); - -function locheader($page) -{ - $temp = explode("\r\n", $page); - foreach ($temp as $item) { - $temp2 = explode(": ", $item); - $infoheader[$temp2[0]] = $temp2[1]; - } - $location = $infoheader['Location']; - return $location; -} - -function file_get_html() -{ - $dom = new simple_html_dom; - $args = func_get_args(); - $dom->load(call_user_func_array('file_get_contents', $args), true); - return $dom; -} - -// get html dom form string -function str_get_html($str, $lowercase = true) -{ - $dom = new simple_html_dom; - $dom->load($str, $lowercase); - return $dom; -} - -// dump html dom tree -function dump_html_tree($node, $show_attr = true, $deep = 0) -{ - $lead = str_repeat(' ', $deep); - echo $lead . $node->tag; - if ($show_attr && count($node->attr) > 0) { - echo '('; - foreach ($node->attr as $k => $v) { - echo "[$k]=>\"" . $node->$k . '", '; - } - - echo ')'; - } - echo "\n"; - - foreach ($node->nodes as $c) { - dump_html_tree($c, $show_attr, $deep + 1); - } - -} - -// simple html dom node -// ----------------------------------------------------------------------------- -class simple_html_dom_node -{ - public $nodetype = HDOM_TYPE_TEXT; - public $tag = 'text'; - public $attr = array(); - public $children = array(); - public $nodes = array(); - public $parent = null; - public $_ = array(); - private $dom = null; - - public function __construct($dom) - { - $this->dom = $dom; - $dom->nodes[] = $this; - } - - public function __destruct() - { - $this->clear(); - } - - public function __toString() - { - return $this->outertext(); - } - - // clean up memory due to php5 circular references memory leak... - public function clear() - { - $this->dom = null; - $this->nodes = null; - $this->parent = null; - $this->children = null; - } - - // dump node's tree - public function dump($show_attr = true) - { - dump_html_tree($this, $show_attr); - } - - // returns the parent of node - public function parent() - { - return $this->parent; - } - - // returns children of node - public function children($idx = -1) - { - if ($idx === -1) { - return $this->children; - } - - if (isset($this->children[$idx])) { - return $this->children[$idx]; - } - - return null; - } - - // returns the first child of node - public function first_child() - { - if (count($this->children) > 0) { - return $this->children[0]; - } - - return null; - } - - // returns the last child of node - public function last_child() - { - if (($count = count($this->children)) > 0) { - return $this->children[$count - 1]; - } - - return null; - } - - // returns the next sibling of node - public function next_sibling() - { - if ($this->parent === null) { - return null; - } - - $idx = 0; - $count = count($this->parent->children); - while ($idx < $count && $this !== $this->parent->children[$idx]) { - ++$idx; - } - - if (++$idx >= $count) { - return null; - } - - return $this->parent->children[$idx]; - } - - // returns the previous sibling of node - public function prev_sibling() - { - if ($this->parent === null) { - return null; - } - - $idx = 0; - $count = count($this->parent->children); - while ($idx < $count && $this !== $this->parent->children[$idx]) { - ++$idx; - } - - if (--$idx < 0) { - return null; - } - - return $this->parent->children[$idx]; - } - - // get dom node's inner html - public function innertext() - { - if (isset($this->_[HDOM_INFO_INNER])) { - return $this->_[HDOM_INFO_INNER]; - } - - if (isset($this->_[HDOM_INFO_TEXT])) { - return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - } - - $ret = ''; - foreach ($this->nodes as $n) { - $ret .= $n->outertext(); - } - - return $ret; - } - - // get dom node's outer text (with tag) - public function outertext() - { - if ($this->tag === 'root') { - return $this->innertext(); - } - - // trigger callback - if ($this->dom->callback !== null) { - call_user_func_array($this->dom->callback, array($this)); - } - - if (isset($this->_[HDOM_INFO_OUTER])) { - return $this->_[HDOM_INFO_OUTER]; - } - - if (isset($this->_[HDOM_INFO_TEXT])) { - return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - } - - // render begin tag - $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup(); - - // render inner text - if (isset($this->_[HDOM_INFO_INNER])) { - $ret .= $this->_[HDOM_INFO_INNER]; - } else { - foreach ($this->nodes as $n) { - $ret .= $n->outertext(); - } - - } - - // render end tag - if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END] != 0) { - $ret .= 'tag . '>'; - } - - return $ret; - } - - // get dom node's plain text - public function text() - { - if (isset($this->_[HDOM_INFO_INNER])) { - return $this->_[HDOM_INFO_INNER]; - } - - switch ($this->nodetype) { - case HDOM_TYPE_TEXT:return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - case HDOM_TYPE_COMMENT:return ''; - case HDOM_TYPE_UNKNOWN:return ''; - } - if (strcasecmp($this->tag, 'script') === 0) { - return ''; - } - - if (strcasecmp($this->tag, 'style') === 0) { - return ''; - } - - $ret = ''; - foreach ($this->nodes as $n) { - $ret .= $n->text(); - } - - return $ret; - } - - public function xmltext() - { - $ret = $this->innertext(); - $ret = str_ireplace('', '', $ret); - return $ret; - } - - // build node's text with tag - public function makeup() - { - // text, comment, unknown - if (isset($this->_[HDOM_INFO_TEXT])) { - return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); - } - - $ret = '<' . $this->tag; - $i = -1; - - foreach ($this->attr as $key => $val) { - ++$i; - - // skip removed attribute - if ($val === null || $val === false) { - continue; - } - - $ret .= $this->_[HDOM_INFO_SPACE][$i][0]; - //no value attr: nowrap, checked selected... - if ($val === true) { - $ret .= $key; - } else { - switch ($this->_[HDOM_INFO_QUOTE][$i]) { - case HDOM_QUOTE_DOUBLE:$quote = '"'; - break; - case HDOM_QUOTE_SINGLE:$quote = '\''; - break; - default:$quote = ''; - } - $ret .= $key . $this->_[HDOM_INFO_SPACE][$i][1] . '=' . $this->_[HDOM_INFO_SPACE][$i][2] . $quote . $val . $quote; - } - } - $ret = $this->dom->restore_noise($ret); - return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>'; - } - - // find elements by css selector - public function find($selector, $idx = null) - { - $selectors = $this->parse_selector($selector); - if (($count = count($selectors)) === 0) { - return array(); - } - - $found_keys = array(); - - // find each selector - for ($c = 0; $c < $count; ++$c) { - if (($levle = count($selectors[0])) === 0) { - return array(); - } - - if (!isset($this->_[HDOM_INFO_BEGIN])) { - return array(); - } - - $head = array($this->_[HDOM_INFO_BEGIN] => 1); - - // handle descendant selectors, no recursive! - for ($l = 0; $l < $levle; ++$l) { - $ret = array(); - foreach ($head as $k => $v) { - $n = ($k === -1) ? $this->dom->root : $this->dom->nodes[$k]; - $n->seek($selectors[$c][$l], $ret); - } - $head = $ret; - } - - foreach ($head as $k => $v) { - if (!isset($found_keys[$k])) { - $found_keys[$k] = 1; - } - - } - } - - // sort keys - ksort($found_keys); - - $found = array(); - foreach ($found_keys as $k => $v) { - $found[] = $this->dom->nodes[$k]; - } - - // return nth-element or array - if (is_null($idx)) { - return $found; - } else if ($idx < 0) { - $idx = count($found) + $idx; - } - - return (isset($found[$idx])) ? $found[$idx] : null; - } - - // seek for given conditions - protected function seek($selector, &$ret) - { - list($tag, $key, $val, $exp, $no_key) = $selector; - - // xpath index - if ($tag && $key && is_numeric($key)) { - $count = 0; - foreach ($this->children as $c) { - if ($tag === '*' || $tag === $c->tag) { - if (++$count == $key) { - $ret[$c->_[HDOM_INFO_BEGIN]] = 1; - return; - } - } - } - return; - } - - $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0; - if ($end == 0) { - $parent = $this->parent; - while (!isset($parent->_[HDOM_INFO_END]) && $parent !== null) { - $end -= 1; - $parent = $parent->parent; - } - $end += $parent->_[HDOM_INFO_END]; - } - - for ($i = $this->_[HDOM_INFO_BEGIN] + 1; $i < $end; ++$i) { - $node = $this->dom->nodes[$i]; - $pass = true; - - if ($tag === '*' && !$key) { - if (in_array($node, $this->children, true)) { - $ret[$i] = 1; - } - - continue; - } - - // compare tag - if ($tag && $tag != $node->tag && $tag !== '*') {$pass = false;} - // compare key - if ($pass && $key) { - if ($no_key) { - if (isset($node->attr[$key])) { - $pass = false; - } - - } else if (!isset($node->attr[$key])) { - $pass = false; - } - - } - // compare value - if ($pass && $key && $val && $val !== '*') { - $check = $this->match($exp, $val, $node->attr[$key]); - // handle multiple class - if (!$check && strcasecmp($key, 'class') === 0) { - foreach (explode(' ', $node->attr[$key]) as $k) { - $check = $this->match($exp, $val, $k); - if ($check) { - break; - } - - } - } - if (!$check) { - $pass = false; - } - - } - if ($pass) { - $ret[$i] = 1; - } - - unset($node); - } - } - - protected function match($exp, $pattern, $value) - { - switch ($exp) { - case '=': - return ($value === $pattern); - case '!=': - return ($value !== $pattern); - case '^=': - return preg_match("/^" . preg_quote($pattern, '/') . "/", $value); - case '$=': - return preg_match("/" . preg_quote($pattern, '/') . "$/", $value); - case '*=': - if ($pattern[0] == '/') { - return preg_match($pattern, $value); - } - - return preg_match("/" . $pattern . "/i", $value); - } - return false; - } - - protected function parse_selector($selector_string) - { - // pattern of CSS selectors, modified from mootools - $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; - preg_match_all($pattern, trim($selector_string) . ' ', $matches, PREG_SET_ORDER); - $selectors = array(); - $result = array(); - //print_r($matches); - - foreach ($matches as $m) { - $m[0] = trim($m[0]); - if ($m[0] === '' || $m[0] === '/' || $m[0] === '//') { - continue; - } - - // for borwser grnreated xpath - if ($m[1] === 'tbody') { - continue; - } - - list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); - if (!empty($m[2])) {$key = 'id'; - $val = $m[2];} - if (!empty($m[3])) {$key = 'class'; - $val = $m[3];} - if (!empty($m[4])) {$key = $m[4];} - if (!empty($m[5])) {$exp = $m[5];} - if (!empty($m[6])) {$val = $m[6];} - - // convert to lowercase - if ($this->dom->lowercase) {$tag = strtolower($tag); - $key = strtolower($key);} - //elements that do NOT have the specified attribute - if (isset($key[0]) && $key[0] === '!') {$key = substr($key, 1); - $no_key = true;} - - $result[] = array($tag, $key, $val, $exp, $no_key); - if (trim($m[7]) === ',') { - $selectors[] = $result; - $result = array(); - } - } - if (count($result) > 0) { - $selectors[] = $result; - } - - return $selectors; - } - - public function __get($name) - { - if (isset($this->attr[$name])) { - return $this->attr[$name]; - } - - switch ($name) { - case 'outertext':return $this->outertext(); - case 'innertext':return $this->innertext(); - case 'plaintext':return $this->text(); - case 'xmltext':return $this->xmltext(); - default:return array_key_exists($name, $this->attr); - } - } - - public function __set($name, $value) - { - switch ($name) { - case 'outertext':return $this->_[HDOM_INFO_OUTER] = $value; - case 'innertext': - if (isset($this->_[HDOM_INFO_TEXT])) { - return $this->_[HDOM_INFO_TEXT] = $value; - } - - return $this->_[HDOM_INFO_INNER] = $value; - } - if (!isset($this->attr[$name])) { - $this->_[HDOM_INFO_SPACE][] = array(' ', '', ''); - $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE; - } - $this->attr[$name] = $value; - } - - public function __isset($name) - { - switch ($name) { - case 'outertext':return true; - case 'innertext':return true; - case 'plaintext':return true; - } - //no value attr: nowrap, checked selected... - return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]); - } - - public function __unset($name) - { - if (isset($this->attr[$name])) { - unset($this->attr[$name]); - } - - } - - // camel naming conventions - public function getAllAttributes() - {return $this->attr;} - public function getAttribute($name) - {return $this->__get($name);} - public function setAttribute($name, $value) - {$this->__set($name, $value);} - public function hasAttribute($name) - {return $this->__isset($name);} - public function removeAttribute($name) - {$this->__set($name, null);} - public function getElementById($id) - {return $this->find("#$id", 0);} - public function getElementsById($id, $idx = null) - {return $this->find("#$id", $idx);} - public function getElementByTagName($name) - {return $this->find($name, 0);} - public function getElementsByTagName($name, $idx = null) - {return $this->find($name, $idx);} - public function parentNode() - {return $this->parent();} - public function childNodes($idx = -1) - {return $this->children($idx);} - public function firstChild() - {return $this->first_child();} - public function lastChild() - {return $this->last_child();} - public function nextSibling() - {return $this->next_sibling();} - public function previousSibling() - {return $this->prev_sibling();} -} - -// simple html dom parser -// ----------------------------------------------------------------------------- -class simple_html_dom -{ - public $root = null; - public $nodes = array(); - public $callback = null; - public $lowercase = false; - protected $pos; - protected $doc; - protected $char; - protected $size; - protected $cursor; - protected $parent; - protected $noise = array(); - protected $token_blank = " \t\r\n"; - protected $token_equal = ' =/>'; - protected $token_slash = " />\r\n\t"; - protected $token_attr = ' >'; - // use isset instead of in_array, performance boost about 30%... - protected $self_closing_tags = array('img' => 1, 'br' => 1, 'input' => 1, 'meta' => 1, 'link' => 1, 'hr' => 1, 'base' => 1, 'embed' => 1, 'spacer' => 1); - protected $block_tags = array('root' => 1, 'body' => 1, 'form' => 1, 'div' => 1, 'span' => 1, 'table' => 1); - protected $optional_closing_tags = array( - 'tr' => array('tr' => 1, 'td' => 1, 'th' => 1), - 'th' => array('th' => 1), - 'td' => array('td' => 1), - 'li' => array('li' => 1), - 'dt' => array('dt' => 1, 'dd' => 1), - 'dd' => array('dd' => 1, 'dt' => 1), - 'dl' => array('dd' => 1, 'dt' => 1), - 'p' => array('p' => 1), - 'nobr' => array('nobr' => 1), - ); - - public function __construct($str = null) - { - if ($str) { - if (preg_match("/^http:\/\//i", $str) || is_file($str)) { - $this->load_file($str); - } else { - $this->load($str); - } - - } - } - - public function __destruct() - { - $this->clear(); - } - - // load html from string - public function load($str, $lowercase = true) - { - // prepare - $this->prepare($str, $lowercase); - // strip out comments - $this->remove_noise("''is"); - // strip out cdata - $this->remove_noise("''is", true); - // strip out