4 use Friendica\Core\System;
6 require_once 'include/probe.php';
7 require_once 'include/follow.php';
8 require_once 'include/Contact.php';
9 require_once 'include/contact_selectors.php';
11 function follow_content(App $a) {
14 notice( t('Permission denied.') . EOL);
15 goaway($_SESSION['return_url']);
20 $url = notags(trim($_REQUEST['url']));
22 $submit = t('Submit Request');
24 // There is a current issue. It seems as if you can't start following a Friendica that is following you
25 // With Diaspora this works - but Friendica is special, it seems ...
26 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
27 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
28 `network` != '%s' LIMIT 1",
29 intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
30 dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
33 notice(t('You already added this contact.').EOL);
35 //goaway($_SESSION['return_url']);
39 $ret = probe_url($url);
41 if (($ret["network"] == NETWORK_DIASPORA) && !get_config('system','diaspora_enabled')) {
42 notice( t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
44 //goaway($_SESSION['return_url']);
48 if (($ret["network"] == NETWORK_OSTATUS) && get_config('system','ostatus_disabled')) {
49 notice( t("OStatus support is disabled. Contact can't be added.") . EOL);
51 //goaway($_SESSION['return_url']);
55 if ($ret["network"] == NETWORK_PHANTOM) {
56 notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
58 //goaway($_SESSION['return_url']);
62 if ($ret["network"] == NETWORK_MAIL) {
63 $ret["url"] = $ret["addr"];
66 if ($ret['network'] === NETWORK_DFRN) {
67 $request = $ret["request"];
68 $tpl = get_markup_template('dfrn_request.tpl');
70 $request = System::baseUrl()."/follow";
71 $tpl = get_markup_template('auto_request.tpl');
74 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
77 notice( t('Permission denied.') . EOL);
78 goaway($_SESSION['return_url']);
82 $myaddr = $r[0]["url"];
85 // Makes the connection request for friendica contacts easier
86 $_SESSION["fastlane"] = $ret["url"];
88 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
89 normalise_link($ret["url"]));
92 $r = array(array("location" => "", "about" => "", "keywords" => ""));
94 $gcontact_id = $r[0]["id"];
97 if ($ret['network'] === NETWORK_DIASPORA) {
98 $r[0]["location"] = "";
102 $header = $ret["name"];
104 if ($ret["addr"] != "") {
105 $header .= " <".$ret["addr"].">";
108 //$header .= " (".network_to_name($ret['network'], $ret['url']).")";
109 $header = t("Connect/Follow");
111 $o = replace_macros($tpl,array(
112 '$header' => htmlentities($header),
113 //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
115 '$pls_answer' => t('Please answer the following:'),
116 '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'), t('Yes'))),
117 '$add_note' => t('Add a personal note:'),
123 '$your_address' => t('Your Identity Address:'),
124 '$invite_desc' => "",
126 '$submit' => $submit,
127 '$cancel' => t('Cancel'),
129 '$name' => $ret["name"],
130 '$url' => $ret["url"],
131 '$zrl' => zrl($ret["url"]),
132 '$url_label' => t("Profile URL"),
133 '$myaddr' => $myaddr,
134 '$request' => $request,
135 /*'$location' => bbcode($r[0]["location"]),
136 '$location_label' => t("Location:"),
137 '$about' => bbcode($r[0]["about"], false, false),
138 '$about_label' => t("About:"), */
139 '$keywords' => $r[0]["keywords"],
140 '$keywords_label' => t("Tags:")
143 $a->page['aside'] = "";
144 profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
146 if ($gcontact_id <> 0) {
147 $o .= replace_macros(get_markup_template('section_title.tpl'),
148 array('$title' => t('Status Messages and Posts')
151 // Show last public posts
152 $o .= posts_from_contact_url($a, $ret["url"]);
158 function follow_post(App $a) {
160 if (! local_user()) {
161 notice( t('Permission denied.') . EOL);
162 goaway($_SESSION['return_url']);
166 if ($_REQUEST['cancel']) {
167 goaway($_SESSION['return_url']);
171 $url = notags(trim($_REQUEST['url']));
172 $return_url = $_SESSION['return_url'];
174 // Makes the connection request for friendica contacts easier
175 // This is just a precaution if maybe this page is called somewhere directly via POST
176 $_SESSION["fastlane"] = $url;
178 $result = new_contact($uid,$url,true);
180 if ($result['success'] == false) {
181 if ($result['message']) {
182 notice($result['message']);
185 } elseif ($result['cid']) {
186 goaway(System::baseUrl().'/contacts/'.$result['cid']);
189 info( t('Contact added').EOL);
191 if (strstr($return_url,'contacts')) {
192 goaway(System::baseUrl().'/contacts/'.$contact_id);