5 require_once 'include/probe.php';
6 require_once 'include/follow.php';
7 require_once 'include/Contact.php';
8 require_once 'include/contact_selectors.php';
10 function follow_content(App $a) {
13 notice( t('Permission denied.') . EOL);
14 goaway($_SESSION['return_url']);
19 $url = notags(trim($_REQUEST['url']));
21 $submit = t('Submit Request');
23 // There is a current issue. It seems as if you can't start following a Friendica that is following you
24 // With Diaspora this works - but Friendica is special, it seems ...
25 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
26 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
27 `network` != '%s' LIMIT 1",
28 intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
29 dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
32 notice(t('You already added this contact.').EOL);
34 //goaway($_SESSION['return_url']);
38 $ret = probe_url($url);
40 if (($ret["network"] == NETWORK_DIASPORA) && !get_config('system','diaspora_enabled')) {
41 notice( t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
43 //goaway($_SESSION['return_url']);
47 if (($ret["network"] == NETWORK_OSTATUS) && get_config('system','ostatus_disabled')) {
48 notice( t("OStatus support is disabled. Contact can't be added.") . EOL);
50 //goaway($_SESSION['return_url']);
54 if ($ret["network"] == NETWORK_PHANTOM) {
55 notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
57 //goaway($_SESSION['return_url']);
61 if ($ret["network"] == NETWORK_MAIL) {
62 $ret["url"] = $ret["addr"];
65 if ($ret['network'] === NETWORK_DFRN) {
66 $request = $ret["request"];
67 $tpl = get_markup_template('dfrn_request.tpl');
69 $request = App::get_baseurl()."/follow";
70 $tpl = get_markup_template('auto_request.tpl');
73 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
76 notice( t('Permission denied.') . EOL);
77 goaway($_SESSION['return_url']);
81 $myaddr = $r[0]["url"];
84 // Makes the connection request for friendica contacts easier
85 $_SESSION["fastlane"] = $ret["url"];
87 $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
88 normalise_link($ret["url"]));
91 $r = array(array("location" => "", "about" => "", "keywords" => ""));
93 $gcontact_id = $r[0]["id"];
96 if ($ret['network'] === NETWORK_DIASPORA) {
97 $r[0]["location"] = "";
101 $header = $ret["name"];
103 if ($ret["addr"] != "") {
104 $header .= " <".$ret["addr"].">";
107 //$header .= " (".network_to_name($ret['network'], $ret['url']).")";
108 $header = t("Connect/Follow");
110 $o = replace_macros($tpl,array(
111 '$header' => htmlentities($header),
112 //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
114 '$pls_answer' => t('Please answer the following:'),
115 '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'), t('Yes'))),
116 '$add_note' => t('Add a personal note:'),
122 '$your_address' => t('Your Identity Address:'),
123 '$invite_desc' => "",
125 '$submit' => $submit,
126 '$cancel' => t('Cancel'),
128 '$name' => $ret["name"],
129 '$url' => $ret["url"],
130 '$zrl' => zrl($ret["url"]),
131 '$url_label' => t("Profile URL"),
132 '$myaddr' => $myaddr,
133 '$request' => $request,
134 /*'$location' => bbcode($r[0]["location"]),
135 '$location_label' => t("Location:"),
136 '$about' => bbcode($r[0]["about"], false, false),
137 '$about_label' => t("About:"), */
138 '$keywords' => $r[0]["keywords"],
139 '$keywords_label' => t("Tags:")
142 $a->page['aside'] = "";
143 profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
145 if ($gcontact_id <> 0) {
146 $o .= replace_macros(get_markup_template('section_title.tpl'),
147 array('$title' => t('Status Messages and Posts')
150 // Show last public posts
151 $o .= posts_from_contact_url($a, $ret["url"]);
157 function follow_post(App $a) {
159 if (! local_user()) {
160 notice( t('Permission denied.') . EOL);
161 goaway($_SESSION['return_url']);
165 if ($_REQUEST['cancel']) {
166 goaway($_SESSION['return_url']);
170 $url = notags(trim($_REQUEST['url']));
171 $return_url = $_SESSION['return_url'];
173 // Makes the connection request for friendica contacts easier
174 // This is just a precaution if maybe this page is called somewhere directly via POST
175 $_SESSION["fastlane"] = $url;
177 $result = new_contact($uid,$url,true);
179 if ($result['success'] == false) {
180 if ($result['message']) {
181 notice($result['message']);
184 } elseif ($result['cid']) {
185 goaway(App::get_baseurl().'/contacts/'.$result['cid']);
188 info( t('Contact added').EOL);
190 if (strstr($return_url,'contacts')) {
191 goaway(App::get_baseurl().'/contacts/'.$contact_id);