]> git.mxchange.org Git - friendica.git/blobdiff - include/Contact.php
Rearranged the logging
[friendica.git] / include / Contact.php
index 6b969de1fe3a1fb0d2fc6e8e3b80d5048f0e04eb..15b6813714f2bff59863bb98256c4c39def94956 100644 (file)
@@ -8,7 +8,6 @@
 function user_remove($uid) {
        if(! $uid)
                return;
-       $a = get_app();
        logger('Removing user: ' . $uid);
 
        $r = q("select * from user where uid = %d limit 1", intval($uid));
@@ -54,7 +53,7 @@ function user_remove($uid) {
        if($uid == local_user()) {
                unset($_SESSION['authenticated']);
                unset($_SESSION['uid']);
-               goaway($a->get_baseurl());
+               goaway(App::get_baseurl());
        }
 }
 
@@ -64,7 +63,7 @@ function contact_remove($id) {
        $r = q("select uid from contact where id = %d limit 1",
                intval($id)
        );
-       if((! count($r)) || (! intval($r[0]['uid'])))
+       if((! dbm::is_result($r)) || (! intval($r[0]['uid'])))
                return;
 
        $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
@@ -86,38 +85,29 @@ function contact_remove($id) {
 
 function terminate_friendship($user,$self,$contact) {
 
-
+       /// @TODO Get rid of this, include/datetime.php should care about it by itself
        $a = get_app();
 
        require_once('include/datetime.php');
 
-       if($contact['network'] === NETWORK_OSTATUS) {
-
-               $slap = replace_macros(get_markup_template('follow_slap.tpl'), array(
-                       '$name' => $user['username'],
-                       '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'],
-                       '$photo' => $self['photo'],
-                       '$thumb' => $self['thumb'],
-                       '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
-                       '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . get_guid(32),
-                       '$title' => '',
-                       '$type' => 'text',
-                       '$content' => t('stopped following'),
-                       '$nick' => $user['nickname'],
-                       '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
-                       '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
-               ));
-
-               if((x($contact,'notify')) && (strlen($contact['notify']))) {
+       if ($contact['network'] === NETWORK_OSTATUS) {
+
+               require_once('include/ostatus.php');
+
+               // create an unfollow slap
+               $item = array();
+               $item['verb'] = NAMESPACE_OSTATUS."/unfollow";
+               $item['follow'] = $contact["url"];
+               $slap = ostatus::salmon($item, $user);
+
+               if ((x($contact,'notify')) && (strlen($contact['notify']))) {
                        require_once('include/salmon.php');
                        slapper($user,$contact['notify'],$slap);
                }
-       }
-       elseif($contact['network'] === NETWORK_DIASPORA) {
+       } elseif ($contact['network'] === NETWORK_DIASPORA) {
                require_once('include/diaspora.php');
-               diaspora::send_unshare($user,$contact);
-       }
-       elseif($contact['network'] === NETWORK_DFRN) {
+               Diaspora::send_unshare($user,$contact);
+       } elseif ($contact['network'] === NETWORK_DFRN) {
                require_once('include/dfrn.php');
                dfrn::deliver($user,$contact,'placeholder', 1);
        }
@@ -236,20 +226,20 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
                        dbesc(normalise_link($url)), intval($uid));
 
        // Fetch the data from the contact table with "uid=0" (which is filled automatically)
-       if (!$r)
+       if (!dbm::is_result($r))
                $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
                        `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
                        FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
                                dbesc(normalise_link($url)));
 
        // Fetch the data from the gcontact table
-       if (!$r)
+       if (!dbm::is_result($r))
                $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
                        `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
                        FROM `gcontact` WHERE `nurl` = '%s'",
                                dbesc(normalise_link($url)));
 
-       if ($r) {
+       if (dbm::is_result($r)) {
                // If there is more than one entry we filter out the connector networks
                if (count($r) > 1) {
                        foreach ($r AS $id => $result) {
@@ -368,7 +358,7 @@ function contact_photo_menu($contact, $uid = 0)
        $sparkle = false;
        if ($contact['network'] === NETWORK_DFRN) {
                $sparkle = true;
-               $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
+               $profile_link = App::get_baseurl() . '/redir/' . $contact['id'];
        } else {
                $profile_link = $contact['url'];
        }
@@ -384,17 +374,17 @@ function contact_photo_menu($contact, $uid = 0)
        }
 
        if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DIASPORA))) {
-               $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
+               $pm_url = App::get_baseurl() . '/message/new/' . $contact['id'];
        }
 
        if ($contact['network'] == NETWORK_DFRN) {
-               $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id'];
+               $poke_link = App::get_baseurl() . '/poke/?f=&c=' . $contact['id'];
        }
 
-       $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
+       $contact_url = App::get_baseurl() . '/contacts/' . $contact['id'];
 
-       $posts_link = $a->get_baseurl() . '/contacts/' . $contact['id'] . '/posts';
-       $contact_drop_link = $a->get_baseurl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
+       $posts_link = App::get_baseurl() . '/contacts/' . $contact['id'] . '/posts';
+       $contact_drop_link = App::get_baseurl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
 
        /**
         * menu array:
@@ -435,7 +425,7 @@ function random_profile() {
                        ORDER BY rand() LIMIT 1",
                dbesc(NETWORK_DFRN));
 
-       if(count($r))
+       if (dbm::is_result($r))
                return dirname($r[0]['url']);
        return '';
 }
@@ -622,7 +612,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
  *
  * @return string posts in HTML
  */
-function posts_from_gcontact($a, $gcontact_id) {
+function posts_from_gcontact(App $a, $gcontact_id) {
 
        require_once('include/conversation.php');
 
@@ -646,7 +636,7 @@ function posts_from_gcontact($a, $gcontact_id) {
        $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
                        `author-name` AS `name`, `owner-avatar` AS `photo`,
                        `owner-link` AS `url`, `owner-avatar` AS `thumb`
-               FROM `item` FORCE INDEX (`gcontactid_uid_created`)
+               FROM `item`
                WHERE `gcontact-id` = %d AND $sql AND
                        NOT `deleted` AND NOT `moderated` AND `visible`
                ORDER BY `item`.`created` DESC LIMIT %d, %d",
@@ -670,11 +660,11 @@ function posts_from_gcontact($a, $gcontact_id) {
  * @brief Returns posts from a given contact url
  *
  * @param App $a argv application class
- * @param int $contact_url Contact URL
+ * @param string $contact_url Contact URL
  *
  * @return string posts in HTML
  */
-function posts_from_contact_url($a, $contact_url) {
+function posts_from_contact_url(App $a, $contact_url) {
 
        require_once('include/conversation.php');