ammarfaizi2

facebook_class.php

Dec 14th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.04 KB | None | 0 0
  1. <?php
  2. defined("DATA") || exit("No Direct Script Access Allowed !");
  3. /**
  4. * @author Ammar F. https://www.facebook.com/ammarfaizi2 <ammarfaizi2@gmail.com>
  5. * @license RedAngel PHP Concept (c) 2016/2017
  6. */
  7. class Crayner_Machine{
  8.     protected static function curl($url,$cookies=null,$postfields=null,$return=null){
  9.         $ch = curl_init();
  10.         $options = array(
  11.             CURLOPT_URL=>$url,
  12.             CURLOPT_SSL_VERIFYPEER=>false,
  13.             CURLOPT_RETURNTRANSFER=>true,
  14.             CURLOPT_USERAGENT=>useragent,
  15.             CURLOPT_ENCODING=>"",
  16.             CURLOPT_FOLLOWLOCATION=>true,
  17.             CURLOPT_TIMEOUT=>15
  18.         );
  19.         if ($postfields!==null) {
  20.             $options[CURLOPT_POST] = true;
  21.             $options[CURLOPT_POSTFIELDS] = $postfields;
  22.         }
  23.         if ($cookies!==null) {
  24.             $options[CURLOPT_COOKIEFILE] = cookies."/".$cookies;
  25.             $options[CURLOPT_COOKIEJAR] = cookies."/".$cookies;
  26.         }
  27.         curl_setopt_array($ch,$options);
  28.         //return $options;
  29.         $ch_exec = curl_exec($ch);
  30.         if ($return!==null) {
  31.             if ($return=="curl_getinfo") {
  32.                 $return = curl_getinfo($ch);
  33.                 curl_close($ch);
  34.                 unset($ch,$options,$ch_exec);
  35.                 if($cookies!==null){unset($cookies);}
  36.                 if ($postfields!==null){unset($postfields);}
  37.                 return $return;
  38.             } else
  39.             if ($return=="curl_error") {
  40.                 $return = curl_error($ch);
  41.                 curl_close($ch);
  42.                 unset($ch,$options,$ch_exec);
  43.                 if($cookies!==null){unset($cookies);}
  44.                 if ($postfields!==null){unset($postfields);}
  45.                 return $return;
  46.             } else
  47.             if ($return=="curl_errno") {
  48.                 $return = curl_errno($ch);
  49.                 curl_close($ch);
  50.                 unset($ch,$options,$ch_exec);
  51.                 if($cookies!==null){unset($cookies);}
  52.                 if ($postfields!==null){unset($postfields);}
  53.                 return $return;
  54.             } else
  55.             if ($return=="all") {
  56.                 $return = array("curl_error"=>curl_error($ch),"curl_errno"=>curl_errno($ch),"curl_exec"=>$ch_exec,"curl_getinfo"=>curl_getinfo($ch));
  57.                 curl_close($ch);
  58.                 unset($ch,$options,$ch_exec);
  59.                 if($cookies!==null){unset($cookies);}
  60.                 if ($postfields!==null){unset($postfields);}
  61.                 return $return;
  62.             } else {
  63.                 $return = $ch_exec;
  64.                 curl_close($ch);
  65.                 unset($ch,$options,$ch_exec);
  66.                 if($cookies!==null){unset($cookies);}
  67.                 if ($postfields!==null){unset($postfields);}
  68.                 return $return;
  69.             }
  70.         } else {
  71.             $return = $ch_exec;
  72.             curl_close($ch);
  73.             unset($ch,$options,$ch_exec);
  74.             if ($cookies!==null) {
  75.                 unset($cookies);
  76.             }
  77.             if ($postfields!==null) {
  78.                 unset($postfields);
  79.             }
  80.             return $return;
  81.         }
  82.     }
  83. }
  84. /**
  85. * @author Ammar F. https://www.facebook.com/ammarfaizi2 <ammarfaizi2@gmail.com>
  86. * @license RedAngel PHP Concept (c) 2016/2017
  87. */
  88. class Facebook extends Crayner_Machine{
  89.     public $username;
  90.     public $email;
  91.     public $password;
  92.     public $access_token;
  93.     public function __construct($email,$password,$access_token=null,$username=null){
  94.         $this->email = $email;
  95.         $this->password = $password;
  96.         $this->access_token = $access_token;
  97.         $this->username = $username;
  98.     }
  99.     public function do_login(){
  100.         if (!isset($this->username)){
  101.             $explode = strpos($this->email,"@")!==false ? explode("@",$this->email) : array($this->email,null);
  102.         } else {
  103.             $explode = array($this->username);
  104.         }
  105.         $user = $explode[0];
  106.         $cookies = $user."_".md5($this->email."_".$this->password).".txt";
  107.         $postfields = "email=".urlencode($this->email)."&pass=".urlencode($this->password)."&login=Log+In";
  108.         $do_login[0] = $this->curl("https://m.facebook.com",$cookies);
  109.         $do_login[1] = $this->curl("https://m.facebook.com/login.php",$cookies,$postfields);
  110.         unset($explode,$user,$postfields,$do_login);
  111.         return strpos(file_get_contents(cookies."/".$cookies),"c_user")!==false ? true : false;
  112.     }
  113.     public function go_to($to,$type=null){
  114.         if (!isset($this->username)){
  115.             $explode = strpos($this->email,"@")!==false ? explode("@",$this->email) : array($this->email,null);
  116.         } else {
  117.             $explode = array($this->username);
  118.         }
  119.         $user = $explode[0];
  120.         $cookies = $user."_".md5($this->email."_".$this->password).".txt";
  121.         $url = $type!==null ? (strpos($type,"web") ? "https://www.facebook.com/" : "https://m.facebook.com/") : "https://m.facebook.com/";
  122.         $do_login[0] = $this->curl($url.$to,$cookies);
  123.         unset($explode,$user,$postfields,$url);
  124.         return strpos(file_get_contents(cookies."/".$cookies),"c_user")!==false ? $do_login[0] : false;
  125.     }
  126. }
  127. /**
  128. * @author Ammar F. https://www.facebook.com/ammarfaizi2 <ammarfaizi2@gmail.com>
  129. * @license RedAngel PHP Concept (c) 2016/2017
  130. */
  131. class Messenger extends Facebook{
  132.     public $messenger_postfields;
  133.     public $cookies;
  134.     public function __construct($cookies,$messenger_postfields){
  135.         $this->messenger_postfields = $messenger_postfields;
  136.         $this->cookies = $cookies;
  137.     }
  138.     /**
  139.     * @return (string)
  140.     */
  141.     public function change_color($color,$gcid){
  142.         $ch = curl_init();
  143.         $header[] = "Cookie: ".$this->cookies;
  144.         curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  145.         curl_setopt($ch,CURLOPT_URL,"https://www.messenger.com/messaging/save_thread_color/?source=thread_settings&dpr=1");
  146.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  147.         curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  148.         curl_setopt($ch,CURLOPT_USERAGENT,useragent);
  149.         curl_setopt($ch,CURLOPT_POST,true);
  150.         curl_setopt($ch,CURLOPT_POSTFIELDS,"color_choice=".urlencode($color)."&thread_or_other_fbid=".$gcid."&".$this->messenger_postfields);
  151.         //curl_setopt($ch,CURLOPT_COOKIEJAR,$cookies);
  152.         //curl_setopt($ch,CURLOPT_COOKIEFILE,$cookies);
  153.         curl_setopt($ch,CURLOPT_ENCODING,"");
  154.         curl_setopt($ch,CURLOPT_TIMEOUT,30);
  155.         $data = curl_exec($ch);
  156.         if ((bool)curl_errno($ch)!==false) {
  157.             $error = curl_error($ch);
  158.             curl_close($ch);
  159.             return $error;
  160.         } else {
  161.             curl_close($ch);
  162.             return $data;
  163.         }
  164.     }
  165.     /**
  166.     * @return (string)
  167.     */
  168.     public function remove_participant($participant_id,$gcid){
  169.         $ch = curl_init();
  170.         $header[] = "Cookie: ".$this->cookies;
  171.         curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  172.         curl_setopt($ch,CURLOPT_URL,"https://www.messenger.com/chat/remove_participants/?uid=".$participant_id."&tid=".$gcid."&dpr=1");
  173.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  174.         curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  175.         curl_setopt($ch,CURLOPT_USERAGENT,useragent);
  176.         curl_setopt($ch,CURLOPT_POST,true);
  177.         curl_setopt($ch,CURLOPT_POSTFIELDS,$this->messenger_postfields);
  178.         //curl_setopt($ch,CURLOPT_COOKIEJAR,$cookies);
  179.         //curl_setopt($ch,CURLOPT_COOKIEFILE,$cookies);
  180.         curl_setopt($ch,CURLOPT_ENCODING,"");
  181.         curl_setopt($ch,CURLOPT_TIMEOUT,30);
  182.         $data = curl_exec($ch);
  183.         if ((bool)curl_errno($ch)!==false) {
  184.             $error = curl_error($ch);
  185.             curl_close($ch);
  186.             return $error;
  187.         } else {
  188.             curl_close($ch);
  189.             return $data;
  190.         }
  191.     }
  192.     /**
  193.     * @return (string)
  194.     */
  195.     public function add_participant($participant_id,$gcid){
  196.         $ch = curl_init();
  197.         $header[] = "Cookie: ".$this->cookies;
  198.         curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  199.         curl_setopt($ch,CURLOPT_URL,"https://www.messenger.com/messaging/send/?dpr=1");
  200.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  201.         curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  202.         curl_setopt($ch,CURLOPT_USERAGENT,useragent);
  203.         curl_setopt($ch,CURLOPT_POST,true);
  204.         curl_setopt($ch,CURLOPT_POSTFIELDS,$this->messenger_postfields."&log_message_data[added_participants][0]=fbid%3A".$participant_id."&action_type=ma-type%3Alog-message&thread_fbid=".$gcid."&log_message_type=log%3Asubscribe");
  205.         //curl_setopt($ch,CURLOPT_COOKIEJAR,$cookies);
  206.         //curl_setopt($ch,CURLOPT_COOKIEFILE,$cookies);
  207.         curl_setopt($ch,CURLOPT_ENCODING,"");
  208.         curl_setopt($ch,CURLOPT_TIMEOUT,30);
  209.         $data = curl_exec($ch);
  210.         if ((bool)curl_errno($ch)!==false) {
  211.             $error = curl_error($ch);
  212.             curl_close($ch);
  213.             return $error;
  214.         } else {
  215.             curl_close($ch);
  216.             return $data;
  217.         }
  218.     }
  219.     public function change_thread_name($new_name,$gcid){
  220.         $ch = curl_init();
  221.         $header[] = "Cookie: ".$this->cookies;
  222.         curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  223.         curl_setopt($ch,CURLOPT_URL,"https://www.messenger.com/messaging/send/?dpr=1");
  224.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  225.         curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  226.         curl_setopt($ch,CURLOPT_USERAGENT,useragent);
  227.         curl_setopt($ch,CURLOPT_POST,true);
  228.         curl_setopt($ch,CURLOPT_POSTFIELDS,$this->messenger_postfields."&log_message_data[added_participants][0]=fbid%3A".$participant_id."&action_type=ma-type%3Alog-message&thread_fbid=".$gcid."&log_message_type=log%3Asubscribe");
  229.         //curl_setopt($ch,CURLOPT_COOKIEJAR,$cookies);
  230.         //curl_setopt($ch,CURLOPT_COOKIEFILE,$cookies);
  231.         curl_setopt($ch,CURLOPT_ENCODING,"");
  232.         curl_setopt($ch,CURLOPT_TIMEOUT,30);
  233.         $data = curl_exec($ch);
  234.         if ((bool)curl_errno($ch)!==false) {
  235.             $error = curl_error($ch);
  236.             curl_close($ch);
  237.             return $error;
  238.         } else {
  239.             curl_close($ch);
  240.             return $data;
  241.         }
  242.     }
  243. }
  244. /**
  245. * @author Ammar F. https://www.facebook.com/ammarfaizi2 <ammarfaizi2@gmail.com>
  246. * @license RedAngel PHP Concept (c) 2016/2017
  247. */
  248. class Graph extends Facebook{
  249.     public function get_user_info($user=null){
  250.         return $user===null ? json_decode($this->curl("https://graph.facebook.com/me/?fields=id&access_token=".$this->access_token),true) : json_decode($this->curl("https://graph.facebook.com/".$user."/?field=id&access_token=".$this->access_token),true);
  251.     }
  252.     public function do_like($fbid,$access_token=null){
  253.         $token = $access_token!==null ? $access_token : $this->access_token;
  254.         return $this->curl("https://graph.facebook.com/".$fbid."/likes?method=post&access_token=".$token);
  255.     }
  256.     public function get_newpost($userid="me"){
  257.         if ($userid=="me") {
  258.             $a = $this->get_user_info();
  259.             $b = json_decode($this->curl("https://graph.facebook.com/".$a['id']."/feed?fields=id&limit=1&access_token=".$this->access_token),true);
  260.             $c = explode("_",$b['data'][0]['id']);
  261.             unset($a,$b,$userid);
  262.             return end($c);
  263.         } else {
  264.             $a = json_decode($this->curl("https://graph.facebook.com/".$userid."/feed?fields=id&limit=1&access_token=".$this->access_token),true);
  265.             $b = explode("_",$a['data'][0]['id']);
  266.             unset($a,$userid);
  267.             return end($b);
  268.         }
  269.     }
  270.     public function like_my_newpost($access_token=null){
  271.         return $access_token!==null ? $this->do_like($this->get_newpost(),$access_token) : $this->do_like($this->get_newpost());
  272.     }  
  273. }
  274. ?>
Add Comment
Please, Sign In to add comment