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