Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. 1 <?php
  2. 2 require_once('libmenu.php');
  3. 3
  4. 4 /* function make_me_example()
  5. 5 * doda example elemente na vsako podstran
  6. 6 * to so:
  7. 7 * -
  8. 8 * -
  9. 9 * -
  10. 10 */
  11. 11 function make_me_example() {
  12. 12 global $EXAMPLE_ENABLED;
  13. 13
  14. 14 if ($EXAMPLE_ENABLED === false) { return; } // a.k.a. LEAVE ME ALONE
  15. 15
  16. 16 ob_start("parse_and_include_stuff");
  17. 17 }
  18. 18
  19. 19 /* function parse_and_include_stuff(): funkcija dobi html v stringu,
  20. 20 * ki mu doda example elemente. parsa po zančkah <head> in <body>
  21. 21 * je case insensitive.
  22. 22 * pri bodyu podpira atribute
  23. 23 * @return nov html
  24. 24 * funkcija se uporablja kot callbakc pri ob_start()
  25. 25 */
  26. 26 function parse_and_include_stuff($html) {
  27. 27 $add_to_head = <<<EOHTML
  28. 28
  29. 29 <meta name='description' content='' />
  30. 30 <meta name='author' content='' />
  31. 31 <meta name='keywords' content='' />
  32. 32 <meta name='robots' content='index, follow' />
  33. 33 <meta http-equiv='content-type' content='text/html; charset=utf-8' />
  34. 34 <meta http-equiv="content-style-type" content="text/css" />
  35. 35 <meta http-equiv='content-language' content='' />
  36. 36 <link type="text/css" rel="stylesheet" href="" />
  37. 37 <link rel='shortcut icon' href='' />
  38. 38
  39. 39 EOHTML;
  40. 40
  41. 41 $add_to_body = "\n\n".get_navbar_html()."\n";
  42. 42
  43. 43 $broken = preg_split("/(<head>)/i", $html, null, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);
  44. 44 if (count($broken) != 3) {
  45. 45 throw new Exception("HTML file for parsing is highly malformed! It has none or too many head tags! Cannot parse!");
  46. 46 }
  47. 47 $html = $broken[0][0] . $broken[1][0] . $add_to_head . $broken[2][0];
  48. 48 $broken = preg_split("/(<body[^>]*>)/i", $html, null, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);
  49. 49 var_dump($broken);
  50. 50 if (count($broken) != 3) {
  51. 51 throw new Exception("HTML file for parsing is highly malformed! It has none or too many body tags! Cannot parse!");
  52. 52 }
  53. 53
  54. 54 $html = $broken[0][0] . $broken[1][0] . $add_to_body . $broken[2][0];
  55. 55
  56. 56 return $html;
  57. 57 }
  58. 58
  59. 59 ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement