tools.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. function get_base_url($url)
  3. {
  4. $split_url = explode("/", $url);
  5. $base_url = $split_url[0] . "//" . $split_url[2] . "/";
  6. return $base_url;
  7. }
  8. function get_xpath($response)
  9. {
  10. $htmlDom = new DOMDocument;
  11. @$htmlDom->loadHTML($response);
  12. $xpath = new DOMXPath($htmlDom);
  13. return $xpath;
  14. }
  15. function request($url)
  16. {
  17. require "config.php";
  18. $ch = curl_init($url);
  19. curl_setopt_array($ch, $config_curl_settings);
  20. $response = curl_exec($ch);
  21. return $response;
  22. }
  23. function human_filesize($bytes, $dec = 2)
  24. {
  25. $size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  26. $factor = floor((strlen($bytes) - 1) / 3);
  27. return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
  28. }
  29. function print_next_page_button($text, $page, $query, $type)
  30. {
  31. echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
  32. echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
  33. echo "<input type=\"hidden\" name=\"q\" value=\"$query\" />";
  34. echo "<input type=\"hidden\" name=\"type\" value=\"$type\" />";
  35. echo "<button type=\"submit\">$text</button>";
  36. echo "</form>";
  37. }
  38. ?>