]> git.mxchange.org Git - friendica.git/blob - util/fpostit/fpostit.php
Merge pull request #4193 from annando/item-unification
[friendica.git] / util / fpostit / fpostit.php
1 <?php
2
3 if (($_POST["friendica_acct_name"] != '') && ($_POST["friendica_password"] != '')) {
4         setcookie("username", $_POST["friendica_acct_name"], time()+60*60*24*300);
5         setcookie("password", $_POST["friendica_password"], time()+60*60*24*300);
6 }
7
8 ?>
9 <html>
10 <head>
11         <style>
12                 body {
13                         font-family: arial, Helvetica,sans-serif;
14                         margin: 0px;
15                 }
16                 .wrap1 {
17                         padding: 2px 5px;
18                         background-color: #729FCF;
19                         margin-bottom: 10px;
20                 }
21                 .wrap2 {
22                         margin-left: 10px;
23                         font-size: 12px;
24                 }
25                 .logo {
26                         margin-left: 3px;
27                         margin-right: 5px;
28                         float: left;
29                 }
30                 h2 {
31                         color: #ffffff;
32                 }
33                 .error {
34                         background-color: #FFFF66;
35                         font-size: 12px;
36                         margin-left: 10px;
37                 }
38         </style>
39 </head>
40
41 <body>
42 <?php
43
44 if (isset($_GET['title'])) {
45         $title = $_GET['title'];
46 }
47 if (isset($_GET['text'])) {
48         $text = $_GET['text'];
49 }
50 if (isset($_GET['url'])) {
51         $url = $_GET['url'];
52 }
53
54 if ((isset($title)) && (isset($text)) && (isset($url))) {
55         $content = "$title\nsource:$url\n\n$text";
56 } else {
57         $content = $_POST['content'];
58 }
59
60 if (isset($_POST['submit'])) {
61         
62         if (($_POST["friendica_acct_name"] != '') && ($_POST["friendica_password"] != '')) {
63                 $acctname = $_POST["friendica_acct_name"];
64                 $tmp_account_array = explode("@", $acctname);
65                 if (isset($tmp_account_array[1])) {
66                         $username = $tmp_account_array[0];
67                         $hostname = $tmp_account_array[1];
68                 }
69                 $password = $_POST["friendica_password"];
70                 $content = $_POST["content"];
71
72                 $url = "http://" . $hostname . '/api/statuses/update';
73                 $data = array('status' => $content);
74                 
75                 // echo "posting to: $url<br/>";
76
77                 $c = curl_init();
78                 curl_setopt($c, CURLOPT_URL, $url); 
79                 curl_setopt($c, CURLOPT_USERPWD, "$username:$password");
80                 curl_setopt($c, CURLOPT_POSTFIELDS, $data); 
81                 curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
82                 curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
83                 $c_result = curl_exec($c); 
84                 if(curl_errno($c)){ 
85                         $error = curl_error($c);
86                         showForm($error, $content);
87                 }
88                 
89                 curl_close($c);
90                 if (!isset($error)) {
91                         echo '<script language="javascript" type="text/javascript">window.close();</script>';
92                 }
93                 
94         } else {
95                 $error = "Missing account name and/or password...try again please";
96                 showForm($error, $content);
97         }
98         
99 } else {
100         showForm(null, $content);
101 }
102
103 function showForm($error, $content) {
104         $username_cookie = $_COOKIE['username'];
105         $password_cookie = $_COOKIE['password'];
106         
107         echo <<<EOF
108         <div class='wrap1'>
109                 <h2><img class='logo' src='friendica-32.png' align='middle';/>
110                 Friendica Bookmarklet</h2>
111         </div>
112
113         <div class="wrap2">
114                 <form method="post" action="{$_SERVER['PHP_SELF']}">
115                         Enter the email address of the Friendica Account that you want to cross-post to:(example: user@friendica.org)<br /><br />
116                         Account ID: <input type="text" name="friendica_acct_name" value="{$username_cookie}" size="50"/><br />
117                         Password: <input type="password" name="friendica_password" value="{$password_cookie}" size="50"/><br />
118                         <textarea name="content" id="content" rows="6" cols="70">{$content}</textarea><br />
119                         <input type="submit" value="PostIt!" name="submit" />&nbsp;&nbsp;<span class='error'>$error</span>
120                 </form>
121                 <p></p>
122         </div>
123 EOF;
124         
125 }
126 ?>
127
128 </body>
129 </html>