SHARE
TWEET

Auto Post MWB

achunk17 Nov 28th, 2015 (edited) 307 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * @name    Auto Posting MWB
  5.  * @author  Achunk JealousMan
  6.  * @link    http://facebook.com/achunks
  7.  * @since   28 Nov 2015
  8.  */
  9.  
  10. class autoPostMwb
  11. {
  12.     protected $login_url =
  13.         'http://www.mywapblog.com/en/login.php?action=login&redir=aHR0cDovL3d3dy5teXdhcGJsb2cuY29tL2VuL3Bvc3QucGhwPw==&lkey=4e5ce687c622baab5b2f818f260a665b';
  14.     protected $post_url = 'http://www.mywapblog.com/en/post.php?';
  15.     protected $error = true;
  16.  
  17.     public $error_message = '';
  18.     public $cookie_dir;
  19.     public $cookie_file = null;
  20.     public $content;
  21.     public $session_id;
  22.     public $key;
  23.     public $username;
  24.     public $password;
  25.     public $domain_id;
  26.  
  27.     /**
  28.      * autoPostMwb::__construct()
  29.      *
  30.      * @string          $username
  31.      * @string          $password
  32.      * @integer         $domain_id
  33.      *
  34.      * Pilihan ID Domain:
  35.      * 0 = mywapblog.com
  36.      * 1 = heck.in
  37.      * 2 = pun.bz
  38.      * 3 = faa.im
  39.      * 4 = mwb.im
  40.      * 5 = yu.tl
  41.      * 6 = mwb-id.com
  42.      * 7 = indonesiaz.com
  43.      * @return
  44.      */
  45.     public function __construct($username, $password, $domain_id, $cookie_dir = './')
  46.     {
  47.         $this->username = $username;
  48.         $this->password = base64_encode($password);
  49.         $this->domain_id = $domain_id;
  50.         $this->cookie_dir = $cookie_dir;
  51.     }
  52.  
  53.     /**
  54.      * autoPostMwb::callMwb()
  55.      *
  56.      * @return
  57.      */
  58.     protected function callMwb($data = array(), $logged_in = false)
  59.     {
  60.         $fields_string = http_build_query($data) . '&';
  61.         if (!$logged_in)
  62.             $url = $this->login_url;
  63.         else
  64.             $url = $this->post_url;
  65.         $ch = curl_init($url);
  66.         if ($this->cookie_file == null)
  67.         {
  68.             $this->cookie_file = $cookie_file = tempnam($this->cookie_dir, "MWB");
  69.             curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
  70.         }
  71.         else
  72.         {
  73.             curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
  74.         }
  75.         curl_setopt($ch, CURLOPT_REFERER, "http://www.mywapblog.com");
  76.         curl_setopt($ch, CURLOPT_USERAGENT,
  77.             "Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; " .
  78.             "U; en) Presto/2.5.25 Version/10.54");
  79.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  80.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  81.         if (count($data) > 0)
  82.         {
  83.             curl_setopt($ch, CURLOPT_POST, count($data));
  84.             curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  85.         }
  86.         $request = curl_exec($ch);
  87.         if (!$request)
  88.         {
  89.             $this->error_message = 'CURL ERROR: ' . curl_error($ch);
  90.             curl_close($ch);
  91.             return false;
  92.         }
  93.         curl_close($ch);
  94.         $this->content = $request;
  95.         return true;
  96.     }
  97.  
  98.     /**
  99.      * autoPostMwb::login()
  100.      *
  101.      * @return
  102.      */
  103.     public function login()
  104.     {
  105.         $data = array(
  106.             'username' => $this->username,
  107.             'password' => $this->password,
  108.             'domain_id' => $this->domain_id,
  109.             'remember' => 'yes',
  110.             'ask_domain_id' => 'true',
  111.             'login' => 'Masuk',
  112.             );
  113.         if (!$this->callMwb($data))
  114.             return false;
  115.         $this->callMwb(array(), true);
  116.         preg_match('/name\=\"PHPSESSID\" value\=\"([a-z0-9]{32})\"/i', $this->content, $matches);
  117.         preg_match('/name\=\"key\" value\=\"([a-z0-9\.]{23})\"/i', $this->content, $matches2);
  118.         if (!$matches || !$matches2)
  119.         {
  120.             $this->error_message = 'Login gagal';
  121.             return false;
  122.         }
  123.         $this->session_id = $matches[1];
  124.         $this->key = $matches2[1];
  125.         $this->error = false;
  126.  
  127.         return true;
  128.     }
  129.  
  130.     /**
  131.      * autoPostMwb::post()
  132.      *
  133.      * @string  $title
  134.      * @string  $body
  135.      * @array   $category
  136.      *
  137.      * @return
  138.      */
  139.     public function post($title, $body, $category = null)
  140.     {
  141.         if ($this->error)
  142.             return false;
  143.  
  144.         $data = array(
  145.             'PHPSESSID' => $this->session_id,
  146.             'key' => $this->key,
  147.             'html_mode' => '1',
  148.             'title' => $title,
  149.             'body' => $body,
  150.             'category' => $category,
  151.             'publish' => 'Publish',
  152.             );
  153.         $this->callMwb($data, true);
  154.         if (strpos($this->content, 'Post published successfully') !== false)
  155.             return true;
  156.         elseif (strpos($this->content, 'Please verify') !== false)
  157.         {
  158.             $this->error_message = 'Verifikasi dibutuhkan';
  159.             return false;
  160.         }
  161.         $this->error_message = 'Posting gagal';
  162.         return false;
  163.     }
  164.  
  165.     public function deleteCookie()
  166.     {
  167.         if ($this->cookie_file != null)
  168.             @unlink($this->cookie_file);
  169.     }
  170. }
  171.  
  172. /**
  173.  
  174.  * $mwb = new autoPostMwb('usernem', 'paspor', 1);
  175.  * if ($mwb->login())
  176.  * {
  177.  *              if ($mwb->post('Judul', 'Teks', array('1423415')))
  178.  *                              echo 'Posting Sukses!';
  179.  *              else
  180.  *                              echo $mwb->error_message;
  181.  * }
  182.  * else
  183.  * {
  184.  *              echo $mwb->error_message;
  185.  * }
  186.  * $mwb->deleteCookie();
  187.  
  188.  */
  189. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top