]> git.mxchange.org Git - friendica.git/blobdiff - mod/contacts.php
proc_run was replaced
[friendica.git] / mod / contacts.php
index 30b8dde20eccdaae6029f5560ae773b029daa0a9..216d2451eaaba34941b0ff95a87185490a627e58 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
 use Friendica\App;
+use Friendica\Core\System;
+use Friendica\Core\Worker;
 use Friendica\Network\Probe;
 
 require_once 'include/Contact.php';
@@ -17,7 +19,7 @@ function contacts_init(App $a) {
 
        $contact_id = 0;
 
-       if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
+       if((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
                $contact_id = intval($a->argv[1]);
                $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
                        intval(local_user()),
@@ -42,7 +44,7 @@ function contacts_init(App $a) {
        if ($contact_id) {
                $a->data['contact'] = $r[0];
 
-               if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
+               if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
                        $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
                } else {
                        $networkname = '';
@@ -84,16 +86,16 @@ function contacts_init(App $a) {
                '$networks_widget' => $networks_widget
        ));
 
-       $base = z_root();
+       $base = System::baseUrl();
        $tpl = get_markup_template("contacts-head.tpl");
        $a->page['htmlhead'] .= replace_macros($tpl,array(
-               '$baseurl' => App::get_baseurl(true),
+               '$baseurl' => System::baseUrl(true),
                '$base' => $base
        ));
 
        $tpl = get_markup_template("contacts-end.tpl");
        $a->page['end'] .= replace_macros($tpl,array(
-               '$baseurl' => App::get_baseurl(true),
+               '$baseurl' => System::baseUrl(true),
                '$base' => $base
        ));
 
@@ -243,14 +245,14 @@ function _contact_update($contact_id) {
                return;
 
        if ($r[0]["network"] == NETWORK_OSTATUS) {
-               $result = new_contact($uid, $r[0]["url"], false);
+               $result = new_contact($uid, $r[0]["url"], false, $r[0]["network"]);
 
                if ($result['success'])
                        $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
                                intval($contact_id));
        } else
                // pull feed and consume it, which should subscribe to the hub.
-               proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
+               Worker::add(PRIORITY_HIGH, "onepoll", $contact_id, "force");
 }
 
 function _contact_update_profile($contact_id) {
@@ -266,7 +268,7 @@ function _contact_update_profile($contact_id) {
        $data = Probe::uri($r[0]["url"], "", 0, false);
 
        // "Feed" or "Unknown" is mostly a sign of communication problems
-       if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
+       if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) && ($data["network"] != $r[0]["network"]))
                return;
 
        $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
@@ -281,14 +283,14 @@ function _contact_update_profile($contact_id) {
        }
 
        foreach($updatefields AS $field)
-               if (isset($data[$field]) AND ($data[$field] != ""))
+               if (isset($data[$field]) && ($data[$field] != ""))
                        $update[$field] = $data[$field];
 
        $update["nurl"] = normalise_link($data["url"]);
 
        $query = "";
 
-       if (isset($data["priority"]) AND ($data["priority"] != 0))
+       if (isset($data["priority"]) && ($data["priority"] != 0))
                $query = "`priority` = ".intval($data["priority"]);
 
        foreach($update AS $key => $value) {
@@ -347,7 +349,16 @@ function _contact_archive($contact_id, $orig_record) {
 function _contact_drop($contact_id, $orig_record) {
        $a = get_app();
 
-       terminate_friendship($a->user,$a->contact,$orig_record);
+       $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
+               WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
+               intval($a->user['uid'])
+       );
+       if (!dbm::is_result($r)) {
+               return;
+       }
+
+       $self = ""; // Unused parameter
+       terminate_friendship($r[0], $self, $orig_record);
        contact_remove($orig_record['id']);
 }
 
@@ -493,10 +504,10 @@ function contacts_content(App $a) {
                $contact = $a->data['contact'];
 
                $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
-                       '$baseurl' => App::get_baseurl(true),
+                       '$baseurl' => System::baseUrl(true),
                ));
                $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
-                       '$baseurl' => App::get_baseurl(true),
+                       '$baseurl' => System::baseUrl(true),
                ));
 
                require_once 'include/contact_selectors.php';
@@ -573,9 +584,15 @@ function contacts_content(App $a) {
                if ($contact['network'] == NETWORK_DFRN)
                        $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
 
-               if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
-                       ($contact['rel'] == CONTACT_IS_FOLLOWER))
-                       $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
+               if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
+                       if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
+                               $follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
+                               $follow_text = t("Connect/Follow");
+                       } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
+                               $follow = System::baseUrl(true)."/unfollow?url=".urlencode($contact["url"]);
+                               $follow_text = t("Disconnect/Unfollow");
+                       }
+               }
 
                // Load contactact related actions like hide, suggest, delete and others
                $contact_actions = contact_actions($contact);
@@ -589,6 +606,8 @@ function contacts_content(App $a) {
                        '$lbl_vis1' => t('Profile Visibility'),
                        '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
                        '$lbl_info1' => t('Contact Information / Notes'),
+                       '$lbl_info2' => t('Their personal note'),
+                       '$reason' => trim(notags($contact['reason'])),
                        '$infedit' => t('Edit contact notes'),
                        '$common_text' => $common_text,
                        '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
@@ -610,7 +629,7 @@ function contacts_content(App $a) {
                        '$last_update' => $last_update,
                        '$udnow' => t('Update now'),
                        '$follow' => $follow,
-                       '$follow_text' => t("Connect/Follow"),
+                       '$follow_text' => $follow_text,
                        '$profile_select' => $profile_select,
                        '$contact_id' => $contact['id'],
                        '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
@@ -799,7 +818,7 @@ function contacts_content(App $a) {
 
        $tpl = get_markup_template("contacts-template.tpl");
        $o .= replace_macros($tpl, array(
-               '$baseurl' => z_root(),
+               '$baseurl' => System::baseUrl(),
                '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
                '$tabs' => $t,
                '$total' => $total,
@@ -853,7 +872,7 @@ function contacts_tab($a, $contact_id, $active_tab) {
                        'url' => "contacts/".$contact_id,
                        'sel' => (($active_tab == 2)?'active':''),
                        'title' => t('Profile Details'),
-                       'id' => 'status-tab',
+                       'id' => 'profile-tab',
                        'accesskey' => 'o',
                )
        );