Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Microblog Facebook initial support

  • Loading branch information...
commit 77827c39bc9470f2e502dbdd6ecb7c1c8e442968 1 parent 43edee9
Dan Dart authored
Showing with 96 additions and 2 deletions.
  1. +30 −1 apps/internet/microblog/app.php
  2. +66 −1 apps/internet/microblog/mb.php
View
31 apps/internet/microblog/app.php
@@ -16,6 +16,25 @@ function mbsend() {
}
}
+if (document.getElementById('facebook').value=="on") {
+fbemail=document.getElementById('fbemail').value;
+fbpassword=document.getElementById('fbpassword').value;
+statustext=document.getElementById('status').value;
+fbstatus=doAjaxSynchronous("apps/internet/microblog/mb.php?service=facebook&email="+fbemail+"&pass="+fbpassword+"&status="+statustext);
+if (fbstatus.indexOf("FB OK") != -1) {
+ alert ("Debug: Facebook success");
+}
+/*if (twstatus.indexOf("Could not authenticate you") != -1) {
+ alert ("I could not authenticate your Twitter account");
+}*/
+/*if (twstatus.indexOf("twimg") != -1) {
+ alert ("Debug: Twitter success");
+}
+*/
+}
+
+
+
if (document.getElementById('identica').value=="on") {
idusername=document.getElementById('idusername').value;
idpassword=document.getElementById('idpassword').value;
@@ -29,6 +48,10 @@ function mbsend() {
}
}
+
+
+
+
if (document.getElementById('custom').value=="on") {
cuusername=document.getElementById('cuusername').value;
cupassword=document.getElementById('cupassword').value;
@@ -59,6 +82,12 @@ function mbsend() {
Password: <input type="password" id="twpassword" name="twpassword" style="width:190px;" />
</div>
<br />
+<div id="facebookbox" style="font-size:14pt;padding-left:30px;">
+ Facebook &nbsp;<input type="checkbox" id="facebook" name="facebook" />
+ Email: <input type="text" id="fbemail" name="fbemail" style="width:190px;" />&nbsp;&nbsp;
+ Password: <input type="password" id="fbpassword" name="fbpassword" style="width:190px;" />
+</div>
+<br />
<div id="identicabox" style="font-size:14pt;padding-left:30px;">
Identica <input type="checkbox" id="identica" name="identica" />
Username: <input type="text" id="idusername" name="idusername" style="width:190px;" />&nbsp;&nbsp;
@@ -74,4 +103,4 @@ function mbsend() {
Password: <input type="password" id="cupassword" name="cupassword" style="width:190px;" />
</span>
</div>
-</div>
+</div>
View
67 apps/internet/microblog/mb.php
@@ -1,6 +1,70 @@
<?php
// Give it some SSL, man.
+function setFacebookStatus($status, $login_email, $login_pass, $debug=false) {
+ //CURL stuff
+ //This executes the login procedure
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&amp;next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
+ curl_setopt($ch, CURLOPT_POSTFIELDS, 'email=' . urlencode($login_email) . '&pass=' . urlencode($login_pass) . '&login=' . urlencode("Log in"));
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
+ curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ //make sure you put a popular web browser here (signature for your web browser can be retrieved with 'echo $_SERVER['HTTP_USER_AGENT'];'
+ curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8");
+ curl_exec($ch);
+
+ //This executes the status update
+ curl_setopt($ch, CURLOPT_POST, 0);
+ curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
+ $page = curl_exec($ch);
+
+ //echo htmlspecialchars($page);
+
+ curl_setopt($ch, CURLOPT_POST, 1);
+ //this gets the post_form_id value
+ preg_match("/input type=\"hidden\" name=\"post_form_id\" value=\"(.*?)\"/", $page, $form_id);
+ preg_match("/input type=\"hidden\" name=\"fb_dtsg\" value=\"(.*?)\"/", $page, $fb_dtsg);
+ preg_match("/input type=\"hidden\" name=\"charset_test\" value=\"(.*?)\"/", $page, $charset_test);
+ preg_match("/input type=\"submit\" class=\"button\" name=\"update\" value=\"(.*?)\"/", $page, $update);
+
+ //we'll also need the exact name of the form processor page
+ //preg_match("/form action=\"(.*?)\"/", $page, $form_num);
+ //sometimes doesn't work so we search the correct form action to use
+ //since there could be more than one form in the page.
+ preg_match_all("#<form([^>]*)>(.*)</form>#Ui", $page, $form_ar);
+ for($i=0;$i<count($form_ar[0]);$i++)
+ if(stristr($form_ar[0][$i],"post_form_id")) preg_match("/form action=\"(.*?)\"/", $page, $form_num);
+
+ $strpost = 'post_form_id=' . $form_id[1] . '&status=' . urlencode($status) . '&update=' . urlencode($update[1]) . '&charset_test=' . urlencode($charset_test[1]) . '&fb_dtsg=' . urlencode($fb_dtsg[1]);
+ if($debug) {
+ echo "Parameters sent: ".$strpost."<hr>";
+ }
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
+
+ //set url to form processor page
+ curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com' . $form_num[1]);
+ curl_exec($ch);
+
+ if ($debug) {
+ //show information regarding the request
+ print_r(curl_getinfo($ch));
+ echo curl_errno($ch) . '-' . curl_error($ch);
+ echo "FB OK";
+ }
+ //close the connection
+ curl_close($ch);
+ }
+
+
$ch = curl_init();
+if ($_GET['service']=="facebook") {
+ setFacebookStatus($_GET['status'], $_GET['email'], $_GET['pass'], false);
+}
+else {
if ($_GET['service']=="identica") {
curl_setopt($ch, CURLOPT_URL, "http://identi.ca/api/statuses/update.xml");
}
@@ -13,10 +77,11 @@
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "source=bibud&status=".$_GET['status']);
-curl_setopt($ch, CURLOPT_USERAGENT, "Bibud a4");
+curl_setopt($ch, CURLOPT_USERAGENT, "Bibud a6");
curl_setopt($ch, CURLOPT_USERPWD, $_GET['user'].":".$_GET['pass']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
+}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.