3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
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);
32 font-family: arial, Helvetica,sans-serif;
37 background-color: #729FCF;
53 background-color: #FFFF66;
63 if (isset($_GET['title'])) {
64 $title = $_GET['title'];
66 if (isset($_GET['text'])) {
67 $text = $_GET['text'];
69 if (isset($_GET['url'])) {
73 if ((isset($title)) && (isset($text)) && (isset($url))) {
74 $content = "$title\nsource:$url\n\n$text";
76 $content = $_POST['content'];
79 if (isset($_POST['submit'])) {
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];
88 $password = $_POST["friendica_password"];
89 $content = $_POST["content"];
91 $url = "http://" . $hostname . '/api/statuses/update';
92 $data = ['status' => $content];
94 // echo "posting to: $url<br/>";
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);
104 $error = curl_error($c);
105 showForm($error, $content);
109 if (!isset($error)) {
110 echo '<script language="javascript" type="text/javascript">window.close();</script>';
114 $error = "Missing account name and/or password...try again please";
115 showForm($error, $content);
119 showForm(null, $content);
122 function showForm($error, $content) {
123 $username_cookie = $_COOKIE['username'];
124 $password_cookie = $_COOKIE['password'];
128 <h2><img class='logo' width="32" height="32" src='friendica.svg' align='middle';/>
129 Friendica Bookmarklet</h2>
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" /> <span class='error'>$error</span>