function from_tumblr() { global $sessionkey; $db = get_db_connectiuon(); list($sessionkey, $cookies, $u) = get_login_cookie($db); $page = getPage(); $agent = Net_UserAgent_Mobile::singleton(); // paging a page if ($agent->isDoCoMo()) { $page = ceil($page / 2); } //$postid = getPostId(); $url = 'http://www.tumblr.com/dashboard/'; if ($page > 1) { $url .= $page; } if ($postid > 1) { $url .= "/{$postid}"; } #print "<!--$url-->"; $retry = 2; while ($retry--) { $req =& new HTTP_Request($url); $req->setMethod(HTTP_REQUEST_METHOD_GET); foreach ($cookies as $v) { $req->addCookie($v['name'], $v['value']); } if (PEAR::isError($req->sendRequest())) { $err = 1; } $code = $req->getResponseCode(); if ($code == 302) { $err = true; if ($u['email']) { list($err, $cookies) = update_cookie_info($u['email'], $u['password'], true, $u['hash']); } if ($err) { $retry = 0; break; } } else { if ($code == 200) { return $req->getResponseBody(); } else { print '<html><body><pre>x_x'; print " {$code} "; print '</body></html>'; exit; } } } if ($retry == 0) { header('Location: /login'); } else { print '<html><body><pre>x_x'; print '</body></html>'; } exit; }
function __construct() { $post_id = $_REQUEST['id']; $this->db = $db = get_db_connectiuon(); list($sessionkey, $cookies) = get_login_cookie($db); $this->sessionkey = $sessionkey; $this->page = $page = getPage(); }
function __construct() { $post_id = $_REQUEST['id']; $this->db = $db = get_db_connectiuon(); list($sessionkey, $cookies) = get_login_cookie($db); $this->sessionkey = $sessionkey; $this->page = $page = getPage(); $pid = getmypid(); $this->postid = $postid = (int) $_REQUEST['postid']; if (preg_match('%^http://([a-z\\-_.]+\\.)+\\w{2,4}(/mobile)?/post/\\d+$%i', $link = (string) $_REQUEST['permalink'])) { $this->permalink = $link; } else { $link = ''; } $uniqkey = "{$pid}-{$postid}-{$sessionkey}"; $set = new Net_Gearman_Set(); $task = new Net_Gearman_Task('reblog', array(cookies => $cookies, postid => $postid, sessionkey => $sessionkey, permalink => $this->permalink, token => $_REQUEST['token'], uniqkey => $uniqkey), $uniqkey, Net_Gearman_Task::JOB_BACKGROUND); // $task->attachCallback('result'); $set->addTask($task); $client = new Net_Gearman_Client(array('localhost:37003')); $client->runSet($set); }
function update_cookie_info($email, $password, $persistent, &$hash = null) { $url = 'http://www.tumblr.com/login'; $err = false; $req =& new HTTP_Request($url); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addPostData("email", $email); $req->addPostData("password", $password); if (PEAR::isError($req->sendRequest())) { $err = 1; } else { $res = $req->getResponseBody(); if (strstr($res, '<meta http-equiv="Refresh" content="0;url=/dashboard">') === false) { $err = 1; } else { $cookies = $req->getResponseCookies(); $cookie_content = serialize($cookies); $k = calc_sha1($email, $password); if ($persistent == '') { $email = ''; $password = ''; } $db = get_db_connectiuon(); if ($hash) { $db->query('UPDATE auth SET cookie = ? WHERE hash = ?', array($cookie_content, $hash)); } else { $hash = $k; $db->query('INSERT auth (hash, cookie, email, password) VALUES (?,?,?,?)', array($k, $cookie_content, $email, $password)); } } } if ($err) { $err = 'login failed.'; } return array($err, $cookies); }