Last active
October 20, 2015 10:51
-
-
Save mt3o/1c4a6e0a1e5debbbed28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // do pobrania z https://code.google.com/p/phpquery/ | |
| // do pobrania z rashell.pl/clearsense/phpQuery-onefile.phps | |
| require 'phpQuery-onefile.php'; | |
| $server = 'http://rashell.pl'; | |
| $results=array(); | |
| header('Content-Type: application/csv'); | |
| header('Content-Disposition: attachment; filename=skaner.csv'); | |
| header('Pragma: no-cache'); | |
| //echo '<pre>'; | |
| chdir('..'); | |
| /* | |
| //TODO: dodac, że kontekst jest dla HTTP/fopen | |
| // działa bez tej sekcji | |
| // jeśli potrzebne jest cookie, referer czy coś to ta część się przyda | |
| $opts = array( | |
| 'ignore_errors'=>true, | |
| 'http'=>array( | |
| 'method'=>"GET", | |
| 'header'=> | |
| "User-agent: Mozilla/4.0 (compatible; MSIE 8.0)\r\n". | |
| "Accept-language: en\r\n" . | |
| //"Cookie: foo=bar\r\n". | |
| '' | |
| ) | |
| ); | |
| stream_context_set_default($opts); | |
| */ | |
| $omit=array( | |
| 'aida', | |
| "wp-admin","wp-includes","wp-content" , | |
| "bin", "tmp", | |
| "cache", | |
| "components", "modules","plugins", | |
| "administrator", | |
| "installation" , | |
| "libraries", | |
| "layouts" , | |
| "templates", | |
| "language", | |
| "media", "images", | |
| "logs", | |
| "includes", | |
| "workflow" | |
| ); | |
| $DIRECTORY = new RecursiveDirectoryIterator('.'); | |
| $RECURSIVE = new RecursiveIteratorIterator($DIRECTORY, RecursiveIteratorIterator::SELF_FIRST); | |
| $REGEX = new RegexIterator($RECURSIVE, '/((\/\.)|(index\.(php|html)))$/i'); | |
| $objects = $REGEX; | |
| foreach($objects as $name=>$object){ //lista wszystkich plików i katalogów | |
| $nameRelative = preg_replace('/^\./','',$name); | |
| //echo "$nameRelative \n"; | |
| $is_file = is_file($name); | |
| $is_dir = is_dir($name); | |
| $is_html = preg_match('/\.html$/',$name); | |
| $is_php = preg_match('/\.php$/',$name); | |
| if($is_html){ | |
| $html = phpQuery::newDocumentFile( $name ); | |
| $answer = 'Local static file'; | |
| } | |
| else if($is_php || $is_dir){ | |
| $contents=@file_get_contents($server.$nameRelative, false, $context); | |
| $answer = $http_response_header[0]; | |
| $html = phpQuery::newDocument(); | |
| }else{ | |
| //echo "File $name is not HTML nor PHP, omitting\n"; | |
| continue; | |
| } | |
| $title = $html->find('title')->text(); | |
| $published = substr_count ( $title, 'Nothing found' ); | |
| array_push($results,array( | |
| 'file'=>$name, | |
| 'url'=>"$server$nameRelative", | |
| 'title'=>$title, | |
| 'status'=> $published ? 'nieopublikowany' : 'opublikowany', | |
| 'answer'=>$answer, | |
| )); | |
| } | |
| foreach($results as $result) | |
| echo arrayToCsv($result)."\r\n"; | |
| function arrayToCsv( array &$fields, $delimiter = ';', $enclosure = '"', $encloseAll = false, $nullToMysqlNull = false ) { | |
| $delimiter_esc = preg_quote($delimiter, '/'); | |
| $enclosure_esc = preg_quote($enclosure, '/'); | |
| $output = array(); | |
| foreach ( $fields as $field ) { | |
| if ($field === null && $nullToMysqlNull) { | |
| $output[] = 'NULL'; | |
| continue; | |
| } | |
| // Enclose fields containing $delimiter, $enclosure or whitespace | |
| if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field ) ) { | |
| $output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure; | |
| } | |
| else { | |
| $output[] = $field; | |
| } | |
| } | |
| return implode( $delimiter, $output ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment