From f20e46c79bd1c13b6a79e1b20902bb8b37a926b2 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Fri, 18 Aug 2023 12:02:10 +0300 Subject: [PATCH] Add random quotes from ipfw.ru/bash and ibash.org.ru, move it to footer --- assets/css/style.css | 1 + index.php | 17 +++++++++------- parse.php | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 parse.php diff --git a/assets/css/style.css b/assets/css/style.css index 0e7df62..82e70d8 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -216,6 +216,7 @@ button:hover { } #header-quote { margin: 1rem 0; + text-align: left; } /* SEARCH */ diff --git a/index.php b/index.php index d082143..6147da0 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ +
+ +
+ - \ No newline at end of file + diff --git a/parse.php b/parse.php new file mode 100644 index 0000000..e246919 --- /dev/null +++ b/parse.php @@ -0,0 +1,48 @@ +loadHTML($html); + + $xpath = new DOMXpath($dom); + $nodes = $xpath->query('//div[@class="' . $classname . '"]'); + + $tmp_dom = new DOMDocument(); + foreach ($nodes as $node) { + $tmp_dom->appendChild($tmp_dom->importNode($node, true)); + } + + return trim($tmp_dom->saveHTML()); +} +$quote = ""; +$random = rand()&1; +if ($random == 0){ + $file=file_get_contents("http://ipfw.ru/bash/fortune"); + $file = mb_convert_encoding($file, 'UTF-8', 'KOI8-R'); + $arr = explode ('%', $file); + array_splice($arr,0,3); + shuffle($arr); +//foreach ($arr as $fortune){ +// $fortune=nl2br($fortune); +//echo $fortune; +//echo "


"; +//} + $quote = "from ipfw.ru/bash:

".nl2br(htmlentities($arr[0])); + $quote = str_replace ("

","
", $quote); +}else{ + $data = ""; + $curl = curl_init(); +// Set some options - we are passing in a useragent too here + curl_setopt_array($curl, array( + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_URL => 'http://ibash.org.ru/random.php', + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' + )); +// Send the request & save response to $resp + $data = curl_exec($curl); +// Close request to clear up some resources + curl_close($curl); +//$data = mb_convert_encoding($data, 'UTF-8', 'windows-1251'); + $quote = "from iBASH:

".getElementByClassname($data, "quotbody"); +} +//print_r ($arr); +?>