]> git.mxchange.org Git - friendica.git/blob - mods/fpostit/fpostit.php
Merge pull request #8302 from annando/allowed-chars
[friendica.git] / mods / fpostit / fpostit.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 if (($_POST["friendica_acct_name"] != '') && ($_POST["friendica_password"] != '')) {
23         setcookie("username", $_POST["friendica_acct_name"], time()+60*60*24*300);
24         setcookie("password", $_POST["friendica_password"], time()+60*60*24*300);
25 }
26
27 ?>
28 <html>
29 <head>
30         <style>
31                 body {
32                         font-family: arial, Helvetica,sans-serif;
33                         margin: 0px;
34                 }
35                 .wrap1 {
36                         padding: 2px 5px;
37                         background-color: #729FCF;
38                         margin-bottom: 10px;
39                 }
40                 .wrap2 {
41                         margin-left: 10px;
42                         font-size: 12px;
43                 }
44                 .logo {
45                         margin-left: 3px;
46                         margin-right: 5px;
47                         float: left;
48                 }
49                 h2 {
50                         color: #ffffff;
51                 }
52                 .error {
53                         background-color: #FFFF66;
54                         font-size: 12px;
55                         margin-left: 10px;
56                 }
57         </style>
58 </head>
59
60 <body>
61 <?php
62
63 if (isset($_GET['title'])) {
64         $title = $_GET['title'];
65 }
66 if (isset($_GET['text'])) {
67         $text = $_GET['text'];
68 }
69 if (isset($_GET['url'])) {
70         $url = $_GET['url'];
71 }
72
73 if ((isset($title)) && (isset($text)) && (isset($url))) {
74         $content = "$title\nsource:$url\n\n$text";
75 } else {
76         $content = $_POST['content'];
77 }
78
79 if (isset($_POST['submit'])) {
80
81         if (($_POST["friendica_acct_name"] != '') && ($_POST["friendica_password"] != '')) {
82                 $acctname = $_POST["friendica_acct_name"];
83                 $tmp_account_array = explode("@", $acctname);
84                 if (isset($tmp_account_array[1])) {
85                         $username = $tmp_account_array[0];
86                         $hostname = $tmp_account_array[1];
87                 }
88                 $password = $_POST["friendica_password"];
89                 $content = $_POST["content"];
90
91                 $url = "http://" . $hostname . '/api/statuses/update';
92                 $data = ['status' => $content];
93
94                 // echo "posting to: $url<br/>";
95
96                 $c = curl_init();
97                 curl_setopt($c, CURLOPT_URL, $url);
98                 curl_setopt($c, CURLOPT_USERPWD, "$username:$password");
99                 curl_setopt($c, CURLOPT_POSTFIELDS, $data);
100                 curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
101                 curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
102                 $c_result = curl_exec($c);
103                 if(curl_errno($c)){
104                         $error = curl_error($c);
105                         showForm($error, $content);
106                 }
107
108                 curl_close($c);
109                 if (!isset($error)) {
110                         echo '<script language="javascript" type="text/javascript">window.close();</script>';
111                 }
112
113         } else {
114                 $error = "Missing account name and/or password...try again please";
115                 showForm($error, $content);
116         }
117
118 } else {
119         showForm(null, $content);
120 }
121
122 function showForm($error, $content) {
123         $username_cookie = $_COOKIE['username'];
124         $password_cookie = $_COOKIE['password'];
125
126         echo <<<EOF
127         <div class='wrap1'>
128                 <h2><img class='logo' src='friendica-32.png' align='middle';/>
129                 Friendica Bookmarklet</h2>
130         </div>
131
132         <div class="wrap2">
133                 <form method="post" action="{$_SERVER['PHP_SELF']}">
134                         Enter the email address of the Friendica Account that you want to cross-post to:(example: user@friendica.org)<br /><br />
135                         Account ID: <input type="text" name="friendica_acct_name" value="{$username_cookie}" size="50"/><br />
136                         Password: <input type="password" name="friendica_password" value="{$password_cookie}" size="50"/><br />
137                         <textarea name="content" id="content" rows="6" cols="70">{$content}</textarea><br />
138                         <input type="submit" value="PostIt!" name="submit" />&nbsp;&nbsp;<span class='error'>$error</span>
139                 </form>
140                 <p></p>
141         </div>
142 EOF;
143
144 }
145 ?>
146
147 </body>
148 </html>