loggingaggregator.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * This test class pretends to be an RSS aggregator. It logs notifications
  4. * from the cloud.
  5. *
  6. * PHP version 5
  7. *
  8. * @category Plugin
  9. * @package StatusNet
  10. * @author Zach Copley <zach@status.net>
  11. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  12. * @link http://status.net/
  13. *
  14. * StatusNet - the distributed open-source microblogging tool
  15. * Copyright (C) 2009, StatusNet, Inc.
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. */
  30. if (!defined('STATUSNET')) {
  31. exit(1);
  32. }
  33. /**
  34. * Dummy aggregator that acts as a proper notification handler. It
  35. * doesn't do anything but respond correctly when notified via
  36. * REST. Mostly, this is just and action I used to develop the plugin
  37. * and easily test things end-to-end. I'm leaving it in here as it
  38. * may be useful for developing the plugin further.
  39. *
  40. * @category Plugin
  41. * @package StatusNet
  42. * @author Zach Copley <zach@status.net>
  43. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  44. * @link http://status.net/
  45. */
  46. class LoggingAggregatorAction extends Action
  47. {
  48. var $challenge = null;
  49. var $url = null;
  50. /**
  51. * Initialization.
  52. *
  53. * @param array $args Web and URL arguments
  54. *
  55. * @return boolean false if user doesn't exist
  56. */
  57. function prepare(array $args = array())
  58. {
  59. parent::prepare($args);
  60. $this->url = $this->arg('url');
  61. $this->challenge = $this->arg('challenge');
  62. common_debug("args = " . var_export($this->args, true));
  63. common_debug('url = ' . $this->url . ' challenge = ' . $this->challenge);
  64. return true;
  65. }
  66. /**
  67. * Handle the request
  68. *
  69. * @param array $args $_REQUEST data (unused)
  70. *
  71. * @return void
  72. */
  73. function handle()
  74. {
  75. parent::handle();
  76. if (empty($this->url)) {
  77. // TRANS: Form validation error displayed when a URL parameter is missing.
  78. $this->showError(_m('A URL parameter is required.'));
  79. return;
  80. }
  81. if (!empty($this->challenge)) {
  82. // must be a GET
  83. if ($_SERVER['REQUEST_METHOD'] != 'GET') {
  84. // TRANS: Form validation error displayed when HTTP GET is not used.
  85. $this->showError(_m('This resource requires an HTTP GET.'));
  86. return;
  87. }
  88. header('Content-Type: text/xml');
  89. echo $this->challenge;
  90. } else {
  91. // must be a POST
  92. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  93. // TRANS: Form validation error displayed when HTTP POST is not used.
  94. $this->showError(_m('This resource requires an HTTP POST.'));
  95. return;
  96. }
  97. header('Content-Type: text/xml');
  98. Echo "<notifyResult success='true' msg='Thanks for the update.' />\n";
  99. }
  100. $this->ip = $_SERVER['REMOTE_ADDR'];
  101. common_log(LOG_INFO, 'RSSCloud Logging Aggregator - ' .
  102. $this->ip . ' claims the feed at ' .
  103. $this->url . ' has been updated.');
  104. }
  105. /**
  106. * Show an XML error when things go badly
  107. *
  108. * @param string $msg the error message
  109. *
  110. * @return void
  111. */
  112. function showError($msg)
  113. {
  114. header('HTTP/1.1 400 Bad Request');
  115. header('Content-Type: text/xml');
  116. echo "<?xml version='1.0'?>\n";
  117. echo "<notifyResult success='false' msg='$msg' />\n";
  118. }
  119. }