/**
  * Send notice to FetLife after it's saved.
  *
  * @param Notice $notice Notice that was saved
  *
  * @return boolean hook value
  */
 function onEndNoticeSave($notice)
 {
     // TODO: Oh my god, refactor this.
     if (empty($this->fl_nick) || empty($this->fl_pw)) {
         return true;
         // bail out and give other plugins a chance
     }
     $FL = new FetLifeUser($this->fl_nick, $this->fl_pw);
     $FL->logIn();
     // If we still don't have an ID, no point in failing to send a status.
     if (!$FL->id) {
         common_log(1, "Failed to get correct FetLife ID for FetLife nickname '{$this->fl_nick}'. Make sure your FetLife settings are correct?");
         return true;
     }
     $post_data = $this->prepareForFetLife($notice);
     // "Cross-post" notice to FetLife.
     $r = $this->sendToFetLife($post_data, $FL);
     // Make a note of HTTP failure, if we encounter it.
     // TODO: Flesh out this error handling, eventually.
     if (302 === $r['status']) {
         common_log(1, "Attempted to send notice to FetLife, but encountered HTTP error: {$r['status']}.");
     } else {
         if (200 !== $r['status']) {
             common_log(1, "Attempted to send notice to FetLife, but encountered HTTP error: {$r['status']}");
         }
     }
     // Uncomment to debug result.
     //        common_log(1, $r);
     //        $this->logme($r);
     return true;
 }
Example #2
0
$export_dir = $username . @date('-Y-m-d');
$zip_dir = dirname(basename(__FILE__)) . "/{$export_dir}";
$zip_url = dirname($_SERVER['PHP_SELF']) . "{$export_dir}.zip";
if ($username && (int) $_REQUEST['download_archive']) {
    exec(escapeshellcmd('zip -r ' . escapeshellarg($zip_dir) . '.zip ' . escapeshellarg($zip_dir)));
    header('Content-Type: application/zip');
    header('Content-Length: ' . filesize("{$zip_dir}.zip"));
    header("Content-Location: {$zip_url}");
    header("Content-Disposition: attachment; filename=\"{$export_dir}.zip\"");
    readfile("{$zip_dir}.zip");
    ob_end_flush();
    ob_flush();
    flush();
}
if ($username && $password && (int) $_REQUEST['delete_archive']) {
    $fetlife = new FetLifeUser($username, $password);
    if ($fetlife->logIn()) {
        // If a user wants to delete their archive from this server, delete ALL archives.
        exec(escapeshellcmd('rm -rf ' . escapeshellarg(substr($export_dir, 0, -11))) . '*', $output);
        exec(escapeshellcmd('rm -f ' . escapeshellarg("{$zip_dir}.zip")), $output);
    }
    header("Location: {$SERVER_['PHP_SELF']}");
    exit(0);
}
// TODO: Make this work regardless of the current position of this script.
//       Right now, it only functions correctly if this file is placed in
//       the DOCUMENT_ROOT.
$robotstxt = realpath(dirname(basename($_SERVER['SCRIPT_NAME']))) . '/robots.txt';
define('FLEXPORT_ROBOTS_TXT', $robotstxt);
if (!file_exists(FLEXPORT_ROBOTS_TXT)) {
    if ($fh = fopen(FLEXPORT_ROBOTS_TXT, 'w')) {
 private function loginToFetLife()
 {
     $cnf = dirname(__FILE__) . '/fl-mt-config.ini.php';
     $this->fl_mt_config = parse_ini_file($cnf);
     $this->mt->debug("Loaded configuration file: {$cnf}");
     $FL = new FetLifeUser($this->fl_mt_config['username'], $this->fl_mt_config['password']);
     if (!empty($this->fl_mt_config['proxy'])) {
         if ('auto' === $this->fl_mt_config['proxy']) {
             $FL->connection->setProxy('auto');
         } else {
             $p = parse_url($this->fl_mt_config['proxy']);
             $FL->connection->setProxy("{$p['host']}:{$p['port']}", 'socks' === $p['scheme'] ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP);
         }
         $proxy_type = CURLPROXY_SOCKS5 ? 'SOCKS5' : 'HTTP';
         $this->mt->debug("Using {$proxy_type} proxy at {$FL->connection->proxy_url}");
     }
     if (!$FL->logIn()) {
         $this->mt->addUIMessage("Failed to login to FetLife.com. Have you checked your username and password?", 'FatalError');
         $this->mt->debug('Failed to login to FetLife.com');
         $this->mt->debug("Last HTML received:\n{$FL->connection->cur_page}");
         die;
     } else {
         $this->mt->debug("Logged in to FetLife as {$FL->nickname} with ID {$FL->id}");
     }
     return $FL;
 }