<?php
/**
* @name Auto Posting MWB
* @author Achunk JealousMan
* @link http://facebook.com/achunks
* @since 28 Nov 2015
*/
class autoPostMwb
{
protected $login_url =
'http://www.mywapblog.com/en/login.php?action=login&redir=aHR0cDovL3d3dy5teXdhcGJsb2cuY29tL2VuL3Bvc3QucGhwPw==&lkey=4e5ce687c622baab5b2f818f260a665b';
protected $post_url = 'http://www.mywapblog.com/en/post.php?';
protected $error = true;
public $error_message = '';
public $cookie_dir;
public $cookie_file = null;
public $content;
public $session_id;
public $key;
public $username;
public $password;
public $domain_id;
/**
* autoPostMwb::__construct()
*
* @string $username
* @string $password
* @integer $domain_id
*
* Pilihan ID Domain:
* 0 = mywapblog.com
* 1 = heck.in
* 2 = pun.bz
* 3 = faa.im
* 4 = mwb.im
* 5 = yu.tl
* 6 = mwb-id.com
* 7 = indonesiaz.com
* @return
*/
public function __construct($username, $password, $domain_id, $cookie_dir = './')
{
$this->username = $username;
$this->password = base64_encode($password);
$this->domain_id = $domain_id;
$this->cookie_dir = $cookie_dir;
}
/**
* autoPostMwb::callMwb()
*
* @return
*/
protected function callMwb($data = array(), $logged_in = false)
{
$fields_string = http_build_query($data) . '&';
if (!$logged_in)
$url = $this->login_url;
else
$url = $this->post_url;
$ch = curl_init($url);
if ($this->cookie_file == null)
{
$this->cookie_file = $cookie_file = tempnam($this->cookie_dir, "MWB");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
}
else
{
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
}
curl_setopt($ch, CURLOPT_REFERER, "http://www.mywapblog.com");
curl_setopt($ch, CURLOPT_USERAGENT,
"Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; " .
"U; en) Presto/2.5.25 Version/10.54");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (count($data) > 0)
{
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
}
$request = curl_exec($ch);
if (!$request)
{
$this->error_message = 'CURL ERROR: ' . curl_error($ch);
curl_close($ch);
return false;
}
curl_close($ch);
$this->content = $request;
return true;
}
/**
* autoPostMwb::login()
*
* @return
*/
public function login()
{
$data = array(
'username' => $this->username,
'password' => $this->password,
'domain_id' => $this->domain_id,
'remember' => 'yes',
'ask_domain_id' => 'true',
'login' => 'Masuk',
);
if (!$this->callMwb($data))
return false;
$this->callMwb(array(), true);
preg_match('/name\=\"PHPSESSID\" value\=\"([a-z0-9]{32})\"/i', $this->content, $matches);
preg_match('/name\=\"key\" value\=\"([a-z0-9\.]{23})\"/i', $this->content, $matches2);
if (!$matches || !$matches2)
{
$this->error_message = 'Login gagal';
return false;
}
$this->session_id = $matches[1];
$this->key = $matches2[1];
$this->error = false;
return true;
}
/**
* autoPostMwb::post()
*
* @string $title
* @string $body
* @array $category
*
* @return
*/
public function post($title, $body, $category = null)
{
if ($this->error)
return false;
$data = array(
'PHPSESSID' => $this->session_id,
'key' => $this->key,
'html_mode' => '1',
'title' => $title,
'body' => $body,
'category' => $category,
'publish' => 'Publish',
);
$this->callMwb($data, true);
if (strpos($this->content, 'Post published successfully') !== false)
return true;
elseif (strpos($this->content, 'Please verify') !== false)
{
$this->error_message = 'Verifikasi dibutuhkan';
return false;
}
$this->error_message = 'Posting gagal';
return false;
}
public function deleteCookie()
{
if ($this->cookie_file != null)
@unlink($this->cookie_file);
}
}
/**
* $mwb = new autoPostMwb('usernem', 'paspor', 1);
* if ($mwb->login())
* {
* if ($mwb->post('Judul', 'Teks', array('1423415')))
* echo 'Posting Sukses!';
* else
* echo $mwb->error_message;
* }
* else
* {
* echo $mwb->error_message;
* }
* $mwb->deleteCookie();
*/
?>