trigger.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. require("user.inc.php");
  3. require("template.inc.php");
  4. list($status, $triggers) = $ctl->cmd("trigger_list");
  5. if (get('json')) {
  6. header("Content-type: text/plain; charset=UTF-8");
  7. print $triggers;
  8. exit;
  9. } elseif (get('tsv')) {
  10. header("Content-type: text/plain; charset=UTF-8");
  11. $triggers = json_decode($triggers, true);
  12. foreach ($triggers as $k => $v) {
  13. print "$k\t$v\n";
  14. }
  15. exit;
  16. }
  17. tpl_header();
  18. $triggers = json_decode($triggers, true);
  19. $aliases = array();
  20. $delete = array();
  21. foreach ($triggers as $k => $v) {
  22. if (!preg_match("/^@!([a-z0-9_.-]+)\$/i", $v, $m)) continue;
  23. $aliases[$m[1]][] = $k;
  24. $delete[] = $k;
  25. }
  26. foreach ($delete as $v) { unset($triggers[$v]); }
  27. function format_aliases($t)
  28. {
  29. global $aliases;
  30. if (!isset($aliases[$t])) return "";
  31. $res = $aliases[$t];
  32. for ($i = 0; $i < count($res); $i++) {
  33. $res[$i] = "<a href=\"trigger_detail.php?trigger=". urlencode($res[$i]). "\">!". htmlspecialchars($res[$i]) ."</a>";
  34. }
  35. return " (aliases: ". implode(", ", $res) .")";
  36. }
  37. print "<h2>Active triggers</h2>";
  38. if (!$triggers) {
  39. print "<p>No triggers defined.";
  40. tpl_footer();
  41. exit;
  42. }
  43. print "<p>Click on one of the triggers to get its edit history";
  44. if (logged_in()) print " or edit it";
  45. print ". <a href=\"trigger_recent.php\">Global list of recent changes</a><dl>";
  46. foreach ($triggers as $k => $v) {
  47. $t = htmlspecialchars($k);
  48. $tu = urlencode($k);
  49. $a_out = format_aliases($k);
  50. print "<dt><a href=\"trigger_detail.php?trigger=$tu\">!$t</a>$a_out</dt><dd>".format_plain_linked($v)."</dd>";
  51. }
  52. print "</dl>";
  53. print <<<EOM
  54. <h2>Raw data</h2>
  55. <p>You can get the raw data as <a href="trigger.php?json=1">JSON</a> or <a
  56. href="trigger.php?tsv=1">tab-separated values (TSV)</a>.
  57. EOM;
  58. tpl_footer();