예제 #1
0
 static function create($url, $title)
 {
     global $db;
     $db->beginTransaction();
     $new = new Thrash($title, $url);
     $new->blocked_domain = false;
     //Temporariamente desabilitado pois voltaram a funcionar os dominios - preg_match(Thrash::$blocked_domains_regex, $url) ? 1 : 0;
     $old = $new->blocked_domain ? null : Thrash::get_by_url($url);
     try {
         $new->save();
     } catch (PDOExecption $e) {
         print "Error!: " . $e->getMessage() . "</br>";
     }
     if ($old) {
         $date = DateTime::createFromFormat('Y-m-d H:i:s', $old->date_created);
         $today = new DateTime();
     }
     if ($old && $today->diff($date)->days <= 1) {
         $db->prepare("update thrash set image_owner_id={$old->id} where id={$new->id}")->execute();
     } else {
         if (!$new->blocked_domain) {
             $basePath = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/';
             $path = $basePath . Thrash::$image_storage_base;
             $return = shell_exec($basePath . "capture.sh \"{$url}\" {$path}{$new->code}.png");
             $sliceHeight = 768;
             $info = getimagesize("{$path}{$new->code}.png");
             if (!$info) {
                 $db->rollBack();
                 shell_exec("rm {$path}{$new->code}.png");
                 header("Location: ./?error=load&url={$url}");
                 die;
             } else {
                 if ($info[1] > $sliceHeight) {
                     $slices = ceil($info[1] / $sliceHeight);
                     shell_exec($basePath . "slice.sh {$path}{$new->code} {$slices}");
                     $db->prepare("update thrash set slices={$slices} where id={$new->id}")->execute();
                 }
             }
             shell_exec($basePath . "optimize.sh {$path}{$new->code}.png");
         }
     }
     $db->commit();
     return $new;
 }
예제 #2
0
if ($code) {
    include_once "lib/Thrash.class.php";
    if ($thrash = Thrash::get_by_code($code)) {
        $title = "<strong>naofo.de</strong> | {$thrash->title}";
    } else {
        die('codigo invalido');
    }
} else {
    $test = strpos($_SERVER['HTTP_HOST'], 'localhost') === 0;
    if (isset($_POST['url']) && ($test || isset($_POST["recaptcha_response_field"]))) {
        if (!$test) {
            $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], @$_POST["recaptcha_challenge_field"], @$_POST["recaptcha_response_field"]);
        }
        if ($test || $resp->is_valid) {
            include_once "lib/Thrash.class.php";
            $thrash = Thrash::create($_POST['url'], $_POST['title']);
            $redirect_url = $thrash->get_url();
            if ($thrash->blocked_domain) {
                $redirect_url .= "?created=1";
            }
            header("Location: " . $redirect_url);
            die;
        } else {
            $error = $resp->error;
        }
    }
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->