TRUE)); // Store a hash of the arguments in the cache, which will be checked by // _echo_access() to ensure that the request originated from this function // and not from an external source. $key = sha1($title . $content . $theme); // Thirty seconds ought to be enough for anyone. $expiration = REQUEST_TIME + max(ini_get('max_execution_time'), 30); cache_set($key, $key, 'cache', $expiration); $options = array( 'method' => 'POST', 'data' => 'title=' . rawurlencode($title) . '&content=' . rawurlencode($content) . '&theme=' . rawurlencode($theme), 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), ); $return = ''; // Turn off maintenance mode so that anonymous page views work. if ($maintenance_mode = variable_get('maintenance_mode', 0)) { variable_set('maintenance_mode', 0); } if ( ($response = drupal_http_request($url, $options)) && isset($response->data) ) { $return = $response->data; } if ($maintenance_mode) { variable_set('maintenance_mode', $maintenance_mode); } return $return; } /** * Implements hook_menu(). */ function echo_menu() { return array( 'echo' => array( 'title callback' => '_echo_request', 'title arguments' => array('title'), 'page callback' => '_echo_request', 'page arguments' => array('content'), 'theme callback' => '_echo_request', 'theme arguments' => array('theme'), 'access callback' => '_echo_access', 'type' => MENU_CALLBACK, ) ); } /** * Returns the contents of a _REQUEST variable. */ function _echo_request($key) { return isset($_REQUEST[$key]) ? $_REQUEST[$key] : ''; } /** * Returns TRUE if this request originated from the echo_themed_page() function; * FALSE otherwise. */ function _echo_access() { if (isset($_REQUEST['title'])) { if (isset($_REQUEST['content'])) { if (isset($_REQUEST['theme'])) { $key = sha1( $_REQUEST['title'] . $_REQUEST['content'] . $_REQUEST['theme'] ); if ($access = cache_get($key)) { if ($access->data == $key) { return TRUE; } } } } } return FALSE; }