Add random quotes from ipfw.ru/bash and ibash.org.ru, move it to footer
This commit is contained in:
parent
565c02c3b0
commit
f20e46c79b
|
@ -216,6 +216,7 @@ button:hover {
|
|||
}
|
||||
#header-quote {
|
||||
margin: 1rem 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* SEARCH */
|
||||
|
|
17
index.php
17
index.php
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
include "vars.php";
|
||||
include "quotes.php";
|
||||
include "parse.php";
|
||||
?>
|
||||
<!doctype html>
|
||||
<!--
|
||||
|
@ -27,12 +28,6 @@ include "quotes.php";
|
|||
<section id="header">
|
||||
<h1 id="header-time">00:00</h1>
|
||||
<h2 id="header-date">Date</h2>
|
||||
<div id="header-quote">
|
||||
<?php
|
||||
shuffle($quotes);
|
||||
echo $quotes[0];
|
||||
?>
|
||||
</div>
|
||||
<!--<div class="randompic"> </div>-->
|
||||
<div id="search" class="searchbar">
|
||||
<input type="text" class="searchbox" name="q" title="Search Google"
|
||||
|
@ -77,7 +72,15 @@ include "quotes.php";
|
|||
?>
|
||||
</div>
|
||||
</section>
|
||||
<div id="header-quote">
|
||||
<?php
|
||||
//shuffle($quotes);
|
||||
//echo $quotes[0];
|
||||
echo $quote;
|
||||
?>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
<script src="./assets/js/script.js" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
function getElementByClassname ($html, $classname) {
|
||||
$dom = new DOMDocument();
|
||||
$dom->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 "<br><hr><br>";
|
||||
//}
|
||||
$quote = "from ipfw.ru/bash:<br><hr style='width: 33%;'>".nl2br(htmlentities($arr[0]));
|
||||
$quote = str_replace ("<br><br>","<br>", $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:<br><hr style='width: 33%;'>".getElementByClassname($data, "quotbody");
|
||||
}
|
||||
//print_r ($arr);
|
||||
?>
|
Loading…
Reference in New Issue