webmaster@1: #!/usr/bin/php webmaster@1: " webmaster@1: Example: {$script} "http://mysite.org/node" webmaster@1: webmaster@1: All arguments are long options. webmaster@1: webmaster@1: --help This page. webmaster@1: webmaster@1: --root Set the working directory for the script to the specified path. webmaster@1: To execute Drupal this has to be the root directory of your webmaster@1: Drupal installation, f.e. /home/www/foo/drupal (assuming Drupal webmaster@1: running on Unix). Current directory is not required. webmaster@1: Use surrounding quotation marks on Windows. webmaster@1: webmaster@1: --verbose This option displays the options as they are set, but will webmaster@1: produce errors from setting the session. webmaster@1: webmaster@1: URI The URI to execute, i.e. http://default/foo/bar for executing webmaster@1: the path '/foo/bar' in your site 'default'. URI has to be webmaster@1: enclosed by quotation marks if there are ampersands in it webmaster@1: (f.e. index.php?q=node&foo=bar). Prefix 'http://' is required, webmaster@1: and the domain must exist in Drupal's sites-directory. webmaster@1: webmaster@1: If the given path and file exists it will be executed directly, webmaster@1: i.e. if URI is set to http://default/bar/foo.php webmaster@1: and bar/foo.php exists, this script will be executed without webmaster@1: bootstrapping Drupal. To execute Drupal's cron.php, specify webmaster@1: http://default/cron.php as the URI. webmaster@1: webmaster@1: webmaster@1: To run this script without --root argument invoke it from the root directory webmaster@1: of your Drupal installation with webmaster@1: webmaster@1: ./scripts/{$script} webmaster@1: \n webmaster@1: EOF; webmaster@1: exit; webmaster@1: } webmaster@1: webmaster@1: // define default settings webmaster@1: $cmd = 'index.php'; webmaster@1: $_SERVER['HTTP_HOST'] = 'default'; webmaster@1: $_SERVER['PHP_SELF'] = '/index.php'; webmaster@1: $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; webmaster@1: $_SERVER['SERVER_SOFTWARE'] = 'PHP CLI'; webmaster@1: $_SERVER['REQUEST_METHOD'] = 'GET'; webmaster@1: $_SERVER['QUERY_STRING'] = ''; webmaster@1: $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/'; webmaster@1: webmaster@1: // toggle verbose mode webmaster@1: if (in_array('--verbose', $_SERVER['argv'])) { webmaster@1: $_verbose_mode = true; webmaster@1: } webmaster@1: else { webmaster@1: $_verbose_mode = false; webmaster@1: } webmaster@1: webmaster@1: // parse invocation arguments webmaster@1: while ($param = array_shift($_SERVER['argv'])) { webmaster@1: switch ($param) { webmaster@1: case '--root': webmaster@1: // change working directory webmaster@1: $path = array_shift($_SERVER['argv']); webmaster@1: if (is_dir($path)) { webmaster@1: chdir($path); webmaster@1: if ($_verbose_mode) { webmaster@1: echo "cwd changed to: {$path}\n"; webmaster@1: } webmaster@1: } webmaster@1: else { webmaster@1: echo "\nERROR: {$path} not found.\n\n"; webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: default: webmaster@1: if (substr($param, 0, 2) == '--') { webmaster@1: // ignore unknown options webmaster@1: break; webmaster@1: } webmaster@1: else { webmaster@1: // parse the URI webmaster@1: $path = parse_url($param); webmaster@1: webmaster@1: // set site name webmaster@1: if (isset($path['host'])) { webmaster@1: $_SERVER['HTTP_HOST'] = $path['host']; webmaster@1: } webmaster@1: webmaster@1: // set query string webmaster@1: if (isset($path['query'])) { webmaster@1: $_SERVER['QUERY_STRING'] = $path['query']; webmaster@1: parse_str($path['query'], $_GET); webmaster@1: $_REQUEST = $_GET; webmaster@1: } webmaster@1: webmaster@1: // set file to execute or Drupal path (clean urls enabled) webmaster@1: if (isset($path['path']) && file_exists(substr($path['path'], 1))) { webmaster@1: $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = $path['path']; webmaster@1: $cmd = substr($path['path'], 1); webmaster@1: } webmaster@1: else if (isset($path['path'])) { webmaster@1: if (!isset($_GET['q'])) { webmaster@1: $_REQUEST['q'] = $_GET['q'] = $path['path']; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: // display setup in verbose mode webmaster@1: if ($_verbose_mode) { webmaster@1: echo "Hostname set to: {$_SERVER['HTTP_HOST']}\n"; webmaster@1: echo "Script name set to: {$cmd}\n"; webmaster@1: echo "Path set to: {$_GET['q']}\n"; webmaster@1: } webmaster@1: } webmaster@1: break; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: if (file_exists($cmd)) { webmaster@1: include $cmd; webmaster@1: } webmaster@1: else { webmaster@1: echo "\nERROR: {$cmd} not found.\n\n"; webmaster@1: } webmaster@1: exit();