4  * Tweeper - a Twitter to RSS web scraper.
 
   6  * Copyright (C) 2013-2015  Antonio Ospite <ao2@ao2.it>
 
   8  * This program is free software: you can redistribute it and/or modify
 
   9  * it under the terms of the GNU General Public License as published by
 
  10  * the Free Software Foundation, either version 3 of the License, or
 
  11  * (at your option) any later version.
 
  13  * This program is distributed in the hope that it will be useful,
 
  14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  16  * GNU General Public License for more details.
 
  18  * You should have received a copy of the GNU General Public License
 
  19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
  22 require_once 'src/Tweeper.php';
 
  26 date_default_timezone_set('UTC');
 
  29  * Check if the script is being run from the command line.
 
  32   return (php_sapi_name() === "cli");
 
  36  * Show the script usage.
 
  38 function usage($argv) {
 
  40     $usage = "{$argv[0]} [-e|-h|--help] <src_url>\n";
 
  43     $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=<src_url>&generate_enclosure=<0|1>");
 
  46   return "usage: $usage";
 
  50  * Parse command line options.
 
  52 function parse_options_cli($argv, $argc) {
 
  54     'generate_enclosure' => FALSE,
 
  61   $cli_options = getopt("eh", array("help"));
 
  62   foreach ($cli_options as $opt => $val) {
 
  65         $options['generate_enclosure'] = TRUE;
 
  74         fwrite(STDERR, usage($argv));
 
  79   $options['src_url'] = $argv[count($cli_options) + 1];
 
  85  * Parse options passed from a query string.
 
  87 function parse_options_query_string() {
 
  89     'generate_enclosure' => FALSE,
 
  92   if (isset($_GET['src_url'])) {
 
  93     $options['src_url'] = $_GET['src_url'];
 
  96   if (isset($_GET['generate_enclosure'])) {
 
  97     $options['generate_enclosure'] = $_GET['generate_enclosure'] == 1;
 
 104   $options = parse_options_cli($argv, $argc);
 
 105   $error_stream = fopen('php://stderr', 'w');
 
 108   $options = parse_options_query_string();
 
 109   $error_stream = fopen('php://output', 'w');
 
 112 if (!isset($options['src_url'])) {
 
 113   fwrite($error_stream, usage(is_cli() ? $argv : NULL));
 
 117 $tweeper = new Tweeper($options['generate_enclosure']);
 
 118 $output = $tweeper->tweep($options['src_url']);
 
 119 if (is_null($output)) {