PageRenderTime 48ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/view.php

http://github.com/highslide-software/highcharts.com
PHP | 140 lines | 109 code | 27 blank | 4 comment | 12 complexity | f72ccf1d912bed3bf326829f8bb4a24b MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0
  1. <?php
  2. $path = $_GET['path'];
  3. if (!preg_match('/^[a-z]+\/[a-z]+\/[a-z0-9\-,]+$/', $path)) {
  4. die ('Invalid sample path input');
  5. }
  6. $i = (int)$_GET['i'];
  7. $next = $i + 1;
  8. function getResources() {
  9. global $path;
  10. // No idea why file_get_contents doesn't work here...
  11. ob_start();
  12. include("$path/demo.details");
  13. $s = ob_get_clean();
  14. $html = '';
  15. if ($s) {
  16. $lines = explode("\n", $s);
  17. $run = false;
  18. foreach ($lines as $line) {
  19. if ($run && substr(trim($line), 0, 1) != '-') {
  20. $run = false;
  21. }
  22. if ($run) {
  23. $url = trim($line, " -\r");
  24. if (preg_match('/\.js$/', $url)) {
  25. $html .= "<script src='$url'></script>\n";
  26. } elseif (preg_match('/\.css$/', $url)) {
  27. $html .= "<link rel='stylesheet' href='$url'></script>\n";
  28. }
  29. }
  30. if (trim($line) === 'resources:') {
  31. $run = true;
  32. }
  33. }
  34. }
  35. return $html;
  36. }
  37. ?><!DOCTYPE HTML>
  38. <html>
  39. <head>
  40. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  41. <title>Highstock Example</title>
  42. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
  43. <?php echo getResources(); ?>
  44. <script type="text/javascript">
  45. <?php @include("$path/demo.js"); ?>
  46. </script>
  47. <style type="text/css">
  48. <?php @include("$path/demo.css"); ?>
  49. </style>
  50. <script type="text/javascript">
  51. $(function() {
  52. if (window.parent.frames[0]) {
  53. var contentDoc = window.parent.frames[0].document;
  54. // Highlight the current sample in the left
  55. var li = contentDoc.getElementById('li<?php echo $i ?>');
  56. if (li) {
  57. // previous
  58. if (contentDoc.currentLi) {
  59. $(contentDoc.currentLi).removeClass('hilighted');
  60. $(contentDoc.currentLi).addClass('visited');
  61. }
  62. $(li).addClass('hilighted');
  63. $(contentDoc.body).animate({
  64. scrollTop: $(li).offset().top - 70
  65. },'slow');
  66. contentDoc.currentLi = li;
  67. }
  68. // add the next button
  69. if (contentDoc.getElementById('i<?php echo $next ?>')) {
  70. function goNext () {
  71. window.location.href =
  72. window.parent.frames[0].document.getElementById('i<?php echo $next ?>').href;
  73. }
  74. $('#next').click(function() {
  75. goNext();
  76. });
  77. $('#next')[0].disabled = false;
  78. }
  79. }
  80. });
  81. </script>
  82. <style type="text/css">
  83. .top-bar {
  84. color: white;
  85. font-family: Arial, sans-serif;
  86. font-size: 0.8em;
  87. padding: 0.5em;
  88. height: 3.5em;
  89. background: #57544A;
  90. background: -webkit-linear-gradient(top, #57544A, #37342A);
  91. background: -moz-linear-gradient(top, #57544A, #37342A);
  92. box-shadow: 0px 0px 8px #888;
  93. }
  94. </style>
  95. </head>
  96. <body style="margin: 0">
  97. <div class="top-bar">
  98. <h2 style="margin: 0"><?php echo ($next - 1) ?>. <?php echo $path ?></h2>
  99. <div style="text-align: center">
  100. <button id="next" disabled="disabled">Next</button>
  101. <button id="reload" style="margin-left: 1em" onclick="location.reload()">Reload</button>
  102. <a style="color: white; font-weight: bold; text-decoration: none; margin-left: 1em"
  103. href="../compare-svg/view.php?path=<?php echo $path ?>&amp;i=<?php echo $i ?>">Compare</a>
  104. <a style="color: white; font-weight: bold; text-decoration: none; margin-left: 1em"
  105. href="http://jsfiddle.net/gh/get/jquery/1.7.1/highslide-software/highcharts.com/tree/master/samples/<?php echo $path ?>/"
  106. target="_blank">Â? jsFiddle</a>
  107. </div>
  108. </div>
  109. <div style="margin: 1em">
  110. <?php @include("$path/demo.html"); ?>
  111. </div>
  112. </body>
  113. </html>