PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/my.php

http://showslow.googlecode.com/
PHP | 250 lines | 213 code | 37 blank | 0 comment | 60 complexity | e1b96f08ff49d6adcda7961fbccd1043 MD5 | raw file
  1. <?php
  2. require_once(dirname(__FILE__).'/global.php');
  3. require_once(dirname(__FILE__).'/users/users.php');
  4. $current_user = User::require_login();
  5. if (array_key_exists('delete', $_POST) && is_array($_POST['delete'])) {
  6. $delete = array_keys($_POST['delete']);
  7. $first = true;
  8. $deleteids = '';
  9. foreach ($delete as $id) {
  10. if (!is_numeric($id)) {
  11. next;
  12. }
  13. if ($first) {
  14. $first = false;
  15. }
  16. else
  17. {
  18. $deleteids.=', ';
  19. }
  20. $deleteids.=$id;
  21. }
  22. if (!$first && $deleteids != '') {
  23. $query = sprintf("DELETE FROM user_urls WHERE user_id = %d AND url_id IN (%s)",
  24. $current_user->getID(),
  25. $deleteids
  26. );
  27. $result = mysql_query($query);
  28. if (!$result) {
  29. error_log(mysql_error());
  30. }
  31. }
  32. header('Location: '.$showslow_base.'my.php#deleted');
  33. exit;
  34. }
  35. if (in_array($current_user->getID(), $noMaxURLsForUsers)) {
  36. $maxURLsPerUser = false;
  37. }
  38. $noMoreURLs = false;
  39. if ($maxURLsPerUser)
  40. {
  41. $query = sprintf('SELECT count(*) AS cnt FROM user_urls WHERE user_urls.user_id = %d', $current_user->getID());
  42. $result = mysql_query($query);
  43. if (!$result) {
  44. error_log(mysql_error());
  45. }
  46. if ($cnt = mysql_fetch_row($result) && $cnt[0] >= $maxURLsPerUser)
  47. {
  48. $noMoreURLs = true;
  49. }
  50. mysql_free_result($result);
  51. }
  52. if (!$noMoreURLs && array_key_exists('url', $_REQUEST)) {
  53. $url_id = getUrlId(resolveRedirects($_REQUEST['url']), false);
  54. if (is_null($url_id)) {
  55. header('Location: '.$showslow_base.'my.php#invalid');
  56. exit;
  57. }
  58. $query = sprintf("INSERT IGNORE INTO user_urls (user_id, url_id) VALUES (%d, %d)",
  59. $current_user->getID(),
  60. $url_id
  61. );
  62. $result = mysql_query($query);
  63. if (!$result) {
  64. error_log(mysql_error());
  65. }
  66. $current_user->recordActivity(SHOWSLOW_ACTIVITY_ADD_URL);
  67. header('Location: '.$showslow_base.'my.php#added');
  68. exit;
  69. }
  70. $query = sprintf("SELECT urls.id as id, url, last_update,
  71. yslow2.o as o,
  72. pagespeed.o as ps_o,
  73. dynatrace.rank as dt_o
  74. FROM urls INNER JOIN user_urls ON urls.id = user_urls.url_id
  75. LEFT JOIN yslow2 ON urls.yslow2_last_id = yslow2.id
  76. LEFT JOIN pagespeed ON urls.pagespeed_last_id = pagespeed.id
  77. LEFT JOIN dynatrace ON urls.dynatrace_last_id = dynatrace.id
  78. WHERE user_urls.user_id = %d ORDER BY url", $current_user->getID());
  79. $result = mysql_query($query);
  80. if (!$result) {
  81. error_log(mysql_error());
  82. }
  83. $yslow = false;
  84. $pagespeed = false;
  85. $dynatrace = false;
  86. $rows = array();
  87. $cols = 0;
  88. while ($row = mysql_fetch_assoc($result)) {
  89. $rows[] = $row;
  90. if (!$yslow && !is_null($row['o'])) {
  91. $yslow = true;
  92. $cols += 1;
  93. }
  94. if (!$pagespeed && !is_null($row['ps_o'])) {
  95. $pagespeed = true;
  96. $cols += 1;
  97. }
  98. if (!$dynatrace && !is_null($row['dt_o'])) {
  99. $dynatrace = true;
  100. $cols += 1;
  101. }
  102. }
  103. $TITLE = 'My URLs';
  104. $SECTION = 'my';
  105. require_once(dirname(__FILE__).'/header.php');
  106. ?>
  107. <style>
  108. td, th { white-space: nowrap; }
  109. .score {
  110. text-align: right;
  111. padding: 0 10px 0 10px;
  112. }
  113. .url {
  114. padding-left:10px;
  115. }
  116. </style>
  117. <h1 style="margin-bottom: 0">Add URLs to monitor</h1>
  118. <div style="font-size: small; margin-bottom: 1em">User: <a href="users/edit.php"><?php echo $current_user->getName(); ?></a></div>
  119. <p>If you don't want to <a href="<?php echo $showslow_base; ?>configure.php">run YSlow, Page Speed and dynaTrace on your desktop</a>, you can add a URL to the list below and it'll be measured automatically every <?php echo $monitoringPeriod ?> hours.</p>
  120. <form action="" method="POST">
  121. <?php
  122. if ($noMoreURLs)
  123. {
  124. ?>
  125. <p><?php echo $maxURLsMessage; ?></p>
  126. <div title="<?php echo htmlentities(strip_tags($maxURLsMessage)); ?>">Add URL: <input type="text" size="80" name="url" disabled="disabled"/><input type="submit" name="add" value="add" disabled="disabled"/></div>
  127. <?php } else { ?>
  128. Add URL: <input type="text" size="80" name="url"/><input type="submit" name="add" value="add" title="add URL to be measured"/>
  129. <?php
  130. }
  131. if (count($rows))
  132. {
  133. ?>
  134. <div style="width: 100%; overflow: hidden">
  135. <table border="0" style="margin-top: 1em">
  136. <tr style="font-size: smaller; font-weight: bold">
  137. <td style="text-align: left; padding-right: 0.7em">Timestamp</td>
  138. <?php if ($yslow) { ?><th colspan="2">YSlow grade</th><?php } ?>
  139. <?php if ($pagespeed) { ?><th colspan="2">Page Speed score</th><?php } ?>
  140. <?php if ($dynatrace) { ?><th colspan="2">dynaTrace rank</th><?php } ?>
  141. <td style="text-align: center">Remove</td>
  142. <td style="padding-left: 1em">URL</td>
  143. </tr>
  144. <?php
  145. foreach ($rows as $row) {
  146. $link = true;
  147. ?><tr>
  148. <?php if (shouldBeIgnoredAsNonHTTP($row['url'])) {
  149. $link = false;
  150. ?>
  151. <td style="color: red; text-align: right; padding-right: 1em"><i title="This instance of Show Slow only allows HTTP(S) URLs">non-HTTP(s) URL</i></td>
  152. <td colspan="<?php echo $cols*2 ?>"/>
  153. <?php } else if (!isURLAllowed($row['url'])) {
  154. $link = false;
  155. ?>
  156. <td style="color: red; text-align: right; padding-right: 1em"><i title="URL is not allowed to be reported to this instance of Show Slow">not allowed</i></td>
  157. <td colspan="<?php echo $cols*2 ?>"/>
  158. <?php } else if (isURLIgnored($row['url'])) {
  159. $link = false;
  160. ?>
  161. <td style="color: red; text-align: right; padding-right: 1em"><i title="This URL is ignored by this instance of Show Slow">ignored</i></td>
  162. <td colspan="<?php echo $cols*2 ?>"/>
  163. <?php } else if (!is_null($row['o']) || !is_null($row['ps_o']) || !is_null($row['dt_o'])) { ?>
  164. <td style="text-align: right; padding-right: 1em"><a title="Time of last check for this URL" href="details/?url=<?php echo urlencode($row['url']); ?>"><?php echo htmlentities($row['last_update']); ?></a></td>
  165. <?php if (!$yslow) {?>
  166. <?php } else if (!is_null($row['o'])) {?>
  167. <td class="score" title="Current YSlow grade: <?php echo prettyScore($row['o'])?> (<?php echo $row['o']?>)"><?php echo prettyScore($row['o'])?> (<?php echo $row['o']?>)</td>
  168. <td title="Current YSlow grade: <?php echo prettyScore($row['o'])?> (<?php echo $row['o']?>)"><div class="gbox"><div style="width: <?php echo $row['o']+1?>px" class="bar c<?php echo scoreColorStep($row['o'])?>"/></div></td>
  169. <?php } else { ?>
  170. <td class="score" style="color: silver" title="No data collected">no data</td>
  171. <td><div class="gbox" title="No data collected"><div class="bar"/></div></td>
  172. <?php } ?>
  173. <?php if (!$pagespeed) {?>
  174. <?php } else if (!is_null($row['ps_o'])) {?>
  175. <td class="score" title="Current Page Speed score: <?php echo prettyScore($row['ps_o'])?> (<?php echo $row['ps_o']?>)"><?php echo prettyScore($row['ps_o'])?> (<?php echo $row['ps_o']?>)</td>
  176. <td title="Current Page Speed score: <?php echo prettyScore($row['ps_o'])?> (<?php echo $row['ps_o']?>)"><div class="gbox"><div style="width: <?php echo $row['ps_o']+1?>px" class="bar c<?php echo scoreColorStep($row['ps_o'])?>"/></div></td>
  177. <?php } else { ?>
  178. <td class="score" style="color: silver" title="No data collected">no data</td>
  179. <td><div class="gbox" title="No data collected"><div class="bar"/></div></td>
  180. <?php } ?>
  181. <?php if (!$dynatrace) {?>
  182. <?php } else if (!is_null($row['dt_o'])) {?>
  183. <td class="score" title="Current dynaTrace score: <?php echo prettyScore($row['dt_o'])?> (<?php echo $row['dt_o']?>)"><?php echo prettyScore($row['dt_o'])?> (<?php echo $row['dt_o']?>)</td>
  184. <td title="Current dynaTrace score: <?php echo prettyScore($row['dt_o'])?> (<?php echo $row['dt_o']?>)"><div class="gbox"><div style="width: <?php echo $row['dt_o']+1?>px" class="bar c<?php echo scoreColorStep($row['dt_o'])?>"/></div></td>
  185. <?php }else{?>
  186. <td class="score" style="color: silver" title="No data collected">no data</td>
  187. <td><div class="gbox" title="No data collected"><div class="bar"/></div></td>
  188. <?php } ?>
  189. <?php } else { ?>
  190. <td style="text-align: right; padding-right: 1em" title="Data for this URL is being collected"><i>collecting data</i></td>
  191. <?php for($i=0; $i<$cols; $i++) {?>
  192. <td class="score" style="color: silver" title="Collecting data"><img style="vertical-align: text-bottom" src="<?php echo assetURL('clock.png')?>"/></td>
  193. <td title="Collecting data"><div class="gbox"><div class="bar ccol"/></div></td>
  194. <?php } ?>
  195. <?php } ?>
  196. <td style="text-align: center"><input type="submit" name="delete[<?php echo htmlentities($row['id'])?>]" value="X" style="font-size: xx-small" title="Stop monitoring this URL" onclick="return confirm('Are you sure you want to remove this URL?')"/></td>
  197. <?php if ($link) {?>
  198. <td style="padding-left: 1em; overflow: hidden; white-space: nowrap;"><a href="details/?url=<?php echo urlencode($row['url'])?>"><?php echo htmlentities(substr($row['url'], 0, 100))?><?php if (strlen($row['url']) > 100) { ?>...<?php } ?></a></td>
  199. <?php } else { ?>
  200. <td style="padding-left: 1em; overflow: hidden; white-space: nowrap;"><i title="Time of last check for this URL"><?php echo htmlentities(substr($row['url'], 0, 100))?><?php if (strlen($row['url']) > 100) { ?>...<?php } ?></i></td>
  201. <?php } ?>
  202. </tr><?php
  203. }
  204. mysql_free_result($result);
  205. ?>
  206. </table>
  207. </div>
  208. <?php
  209. }
  210. ?>
  211. </form>
  212. <?php
  213. require_once(dirname(__FILE__).'/footer.php');