]> git.mxchange.org Git - friendica.git/blobdiff - mod/contacts.php
Merge pull request #3985 from hoergen/develop
[friendica.git] / mod / contacts.php
index ee501fb9dd63f34a92afa820c280976c36f7bd2a..35be8e79e3f21efaad3494b98f569a0baf6c68eb 100644 (file)
@@ -1,13 +1,16 @@
 <?php
 
 use Friendica\App;
+use Friendica\Core\System;
+use Friendica\Core\Worker;
+use Friendica\Database\DBM;
+use Friendica\Model\GlobalContact;
+use Friendica\Network\Probe;
+use Friendica\Object\Contact;
 
-require_once('include/Contact.php');
-require_once('include/socgraph.php');
-require_once('include/contact_selectors.php');
-require_once('include/Scrape.php');
-require_once('mod/proxy.php');
-require_once('include/Photo.php');
+require_once 'include/contact_selectors.php';
+require_once 'mod/proxy.php';
+require_once 'include/Photo.php';
 
 function contacts_init(App $a) {
        if (! local_user()) {
@@ -16,19 +19,19 @@ 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()),
                        intval($contact_id)
                );
-               if (! dbm::is_result($r)) {
+               if (! DBM::is_result($r)) {
                        $contact_id = 0;
                }
        }
 
-       require_once('include/group.php');
-       require_once('include/contact_widgets.php');
+       require_once 'include/group.php';
+       require_once 'include/contact_widgets.php';
 
        if ($_GET['nets'] == "all") {
                $_GET['nets'] = "";
@@ -41,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 = '';
@@ -55,7 +58,7 @@ function contacts_init(App $a) {
                        '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
                        '$network_name' => $networkname,
                        '$network' => t('Network:'),
-                       '$account_type' => account_type($a->data['contact'])
+                       '$account_type' => Contact::getAccountType($a->data['contact'])
                ));
 
                $finpeople_widget = '';
@@ -83,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
        ));
 
@@ -128,7 +131,7 @@ function contacts_batch_actions(App $a) {
                        if ($r) $count_actions++;
                }
                if (x($_POST, 'contacts_batch_drop')) {
-                       _contact_drop($contact_id, $orig_record);
+                       _contact_drop($orig_record);
                        $count_actions++;
                }
        }
@@ -181,7 +184,7 @@ function contacts_post(App $a) {
                        intval($profile_id),
                        intval(local_user())
                );
-               if (! dbm::is_result($r)) {
+               if (! DBM::is_result($r)) {
                        notice( t('Could not locate selected profile.') . EOL);
                        return;
                }
@@ -223,7 +226,7 @@ function contacts_post(App $a) {
                intval($contact_id),
                intval(local_user())
        );
-       if($r && dbm::is_result($r))
+       if($r && DBM::is_result($r))
                $a->data['contact'] = $r[0];
 
        return;
@@ -242,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) {
@@ -262,10 +265,10 @@ function _contact_update_profile($contact_id) {
        if ($uid != local_user())
                return;
 
-       $data = probe_url($r[0]["url"]);
+       $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",
@@ -280,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) {
@@ -306,10 +309,10 @@ function _contact_update_profile($contact_id) {
        );
 
        // Update the entry in the contact table
-       update_contact_avatar($data['photo'], local_user(), $contact_id);
+       update_contact_avatar($data['photo'], local_user(), $contact_id, true);
 
        // Update the entry in the gcontact table
-       update_gcontact_from_probe($data["url"]);
+       GlobalContact::updateFromProbe($data["url"]);
 }
 
 function _contact_block($contact_id, $orig_record) {
@@ -343,11 +346,21 @@ function _contact_archive($contact_id, $orig_record) {
        }
        return $r;
 }
-function _contact_drop($contact_id, $orig_record) {
+
+function _contact_drop($orig_record)
+{
        $a = get_app();
 
-       terminate_friendship($a->user,$a->contact,$orig_record);
-       contact_remove($orig_record['id']);
+       $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;
+       }
+
+       Contact::terminateFriendship($r[0], $orig_record);
+       Contact::remove($orig_record['id']);
 }
 
 
@@ -467,7 +480,7 @@ function contacts_content(App $a) {
                                }
                        }
 
-                       _contact_drop($contact_id, $orig_record[0]);
+                       _contact_drop($orig_record[0]);
                        info( t('Contact has been removed.') . EOL );
                        if (x($_SESSION,'return_url')) {
                                goaway('' . $_SESSION['return_url']);
@@ -492,13 +505,13 @@ 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');
+               require_once 'include/contact_selectors.php';
 
                $tpl = get_markup_template("contact_edit.tpl");
 
@@ -549,12 +562,12 @@ function contacts_content(App $a) {
 
                $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
 
-               //$common = count_common_friends(local_user(),$contact['id']);
+               //$common = GlobalContact::countCommonFriends(local_user(),$contact['id']);
                //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
 
                $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
 
-               //$x = count_all_friends(local_user(), $contact['id']);
+               //$x = GlobalContact::countAllFriends(local_user(), $contact['id']);
                //$all_friends = (($x) ? t('View all contacts') : '');
 
                // tabs
@@ -563,8 +576,14 @@ function contacts_content(App $a) {
                $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
 
                if ($contact['network'] == NETWORK_FEED) {
-                       $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
-                                                                       array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
+                       $fetch_further_information = array('fetch_further_information',
+                                                       t('Fetch further information for feeds'),
+                                                       $contact['fetch_further_information'],
+                                                       t("Fetch information like preview pictures, title and teaser from the feed item. You can activate this if the feed doesn't contain much text. Keywords are taken from the meta header in the feed item and are posted as hash tags."),
+                                                               array('0' => t('Disabled'),
+                                                                       '1' => t('Fetch information'),
+                                                                       '3' => t('Fetch keywords'),
+                                                                       '2' => t('Fetch information and keywords')));
                }
                if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
                        $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
@@ -572,9 +591,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);
@@ -588,6 +613,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'],
@@ -609,7 +636,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') ),
@@ -620,6 +647,7 @@ function contacts_content(App $a) {
                        '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
                        '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
                        '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
+                       '$pending' => (($contact['pending']) ? t('Awaiting connection acknowledge') : ''),
                        '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
                        '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
                        '$fetch_further_information' => $fetch_further_information,
@@ -633,7 +661,7 @@ function contacts_content(App $a) {
                        '$url' => $url,
                        '$profileurllabel' => t('Profile URL'),
                        '$profileurl' => $contact['url'],
-                       '$account_type' => account_type($contact),
+                       '$account_type' => Contact::getAccountType($contact),
                        '$location' => bbcode($contact["location"]),
                        '$location_label' => t("Location:"),
                        '$xmpp' => bbcode($contact["xmpp"]),
@@ -775,7 +803,7 @@ function contacts_content(App $a) {
        $r = q("SELECT COUNT(*) AS `total` FROM `contact`
                WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
                intval($_SESSION['uid']));
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                $a->set_pager_total($r[0]['total']);
                $total = $r[0]['total'];
        }
@@ -790,7 +818,7 @@ function contacts_content(App $a) {
 
        $contacts = array();
 
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                foreach ($r as $rr) {
                        $contacts[] = _contact_detail_for_template($rr);
                }
@@ -798,7 +826,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,
@@ -830,7 +858,7 @@ function contacts_content(App $a) {
  *
  * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
  *
- * @param app $a
+ * @param App $a
  * @param int $contact_id The ID of the contact
  * @param int $active_tab 1 if tab should be marked as active
  *
@@ -852,13 +880,13 @@ 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',
                )
        );
 
        // Show this tab only if there is visible friend list
-       $x = count_all_friends(local_user(), $contact_id);
+       $x = GlobalContact::countAllFriends(local_user(), $contact_id);
        if ($x)
                $tabs[] = array('label'=>t('Contacts'),
                                'url' => "allfriends/".$contact_id,
@@ -868,7 +896,7 @@ function contacts_tab($a, $contact_id, $active_tab) {
                                'accesskey' => 't');
 
        // Show this tab only if there is visible common friend list
-       $common = count_common_friends(local_user(),$contact_id);
+       $common = GlobalContact::countCommonFriends(local_user(), $contact_id);
        if ($common)
                $tabs[] = array('label'=>t('Common Friends'),
                                'url' => "common/loc/".local_user()."/".$contact_id,
@@ -896,7 +924,7 @@ function contact_posts($a, $contact_id) {
        if ($r) {
                $contact = $r[0];
                $a->page['aside'] = "";
-               profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
+               profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
        } else
                $profile = "";
 
@@ -904,7 +932,7 @@ function contact_posts($a, $contact_id) {
 
        $o .= $tab_str;
 
-       $o .= posts_from_contact_url($a, $contact["url"]);
+       $o .= Contact::getPostsFromUrl($contact["url"]);
 
        return $o;
 }
@@ -939,14 +967,14 @@ function _contact_detail_for_template($rr){
        return array(
                'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
                'edit_hover' => t('Edit contact'),
-               'photo_menu' => contact_photo_menu($rr),
+               'photo_menu' => Contact::photoMenu($rr),
                'id' => $rr['id'],
                'alt_text' => $alt_text,
                'dir_icon' => $dir_icon,
                'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
                'name' => htmlentities($rr['name']),
                'username' => htmlentities($rr['name']),
-               'account_type' => account_type($rr),
+               'account_type' => Contact::getAccountType($rr),
                'sparkle' => $sparkle,
                'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
                'url' => $url,