]> git.mxchange.org Git - friendica.git/blobdiff - include/Contact.php
opps, re-introduced this out-dated code by mistake
[friendica.git] / include / Contact.php
index dc29d38257a38a6cca4f0ae60c7f0df152215661..bb6d8c198178a9002ee0ade07daff13c0ba94d49 100644 (file)
@@ -1,11 +1,14 @@
 <?php
 
+use Friendica\App;
+use Friendica\Network\Probe;
+
 // Included here for completeness, but this is a very dangerous operation.
 // It is the caller's responsibility to confirm the requestor's intent and
 // authorisation to do this.
 
 function user_remove($uid) {
-       if (! $uid)
+       if(! $uid)
                return;
        logger('Removing user: ' . $uid);
 
@@ -20,36 +23,14 @@ function user_remove($uid) {
                $r[0]['nickname']
        );
 
-       /// @todo Should be done in a background job since this likely will run into a time out
-       // don't delete yet, will be done later when contacts have deleted my stuff
-       // q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
-       q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
-       // don't delete yet, will be done later when contacts have deleted my stuff
-       // q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
+       // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
        q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
        proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid);
 
        // Send an update to the directory
        proc_run(PRIORITY_LOW, "include/directory.php", $r[0]['url']);
 
-       if ($uid == local_user()) {
+       if($uid == local_user()) {
                unset($_SESSION['authenticated']);
                unset($_SESSION['uid']);
                goaway(App::get_baseurl());
@@ -89,11 +70,11 @@ 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');
+       require_once 'include/datetime.php';
 
        if ($contact['network'] === NETWORK_OSTATUS) {
 
-               require_once('include/ostatus.php');
+               require_once 'include/ostatus.php';
 
                // create an unfollow slap
                $item = array();
@@ -102,14 +83,14 @@ function terminate_friendship($user,$self,$contact) {
                $slap = ostatus::salmon($item, $user);
 
                if ((x($contact,'notify')) && (strlen($contact['notify']))) {
-                       require_once('include/salmon.php');
+                       require_once 'include/salmon.php';
                        slapper($user,$contact['notify'],$slap);
                }
        } elseif ($contact['network'] === NETWORK_DIASPORA) {
-               require_once('include/diaspora.php');
+               require_once 'include/diaspora.php';
                Diaspora::send_unshare($user,$contact);
        } elseif ($contact['network'] === NETWORK_DFRN) {
-               require_once('include/dfrn.php');
+               require_once 'include/dfrn.php';
                dfrn::deliver($user,$contact,'placeholder', 1);
        }
 
@@ -122,13 +103,11 @@ function terminate_friendship($user,$self,$contact) {
 // This provides for the possibility that their database is temporarily messed
 // up or some other transient event and that there's a possibility we could recover from it.
 
-function mark_for_death(array $contact) {
+function mark_for_death($contact) {
 
-       if ($contact['archive']) {
+       if($contact['archive'])
                return;
-       }
 
-       /// @TODO Comparison of strings this way may lead to bugs/incompatibility, better switch to DateTime
        if ($contact['term-date'] <= NULL_DATE) {
                q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
                                dbesc(datetime_convert()),
@@ -153,7 +132,7 @@ function mark_for_death(array $contact) {
                /// Check for contact vitality via probing
 
                $expiry = $contact['term-date'] . ' + 32 days ';
-               if (datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
+               if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
 
                        // relationship is really truly dead.
                        // archive them rather than delete
@@ -214,6 +193,10 @@ function unmark_for_death($contact) {
 function get_contact_details_by_url($url, $uid = -1, $default = array()) {
        static $cache = array();
 
+       if ($url == '') {
+               return $default;
+       }
+
        if ($uid == -1) {
                $uid = local_user();
        }
@@ -256,7 +239,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
 
                // "bd" always contains the upcoming birthday of a contact.
                // "birthday" might contain the birthday including the year of birth.
-               if ($profile["birthday"] != "0000-00-00") {
+               if ($profile["birthday"] > '0001-01-01') {
                        $bd_timestamp = strtotime($profile["birthday"]);
                        $month = date("m", $bd_timestamp);
                        $day = date("d", $bd_timestamp);
@@ -273,7 +256,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
                                $profile["bd"] = (++$current_year)."-".$month."-".$day;
                        }
                } else {
-                       $profile["bd"] = "0000-00-00";
+                       $profile["bd"] = '0001-01-01';
                }
        } else {
                $profile = $default;
@@ -309,7 +292,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
                $profile["location"] = "";
                $profile["about"] = "";
                $profile["gender"] = "";
-               $profile["birthday"] = "0000-00-00";
+               $profile["birthday"] = '0001-01-01';
        }
 
        $cache[$url][$uid] = $profile;
@@ -330,6 +313,10 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
 function get_contact_details_by_addr($addr, $uid = -1) {
        static $cache = array();
 
+       if ($addr == '') {
+               return array();
+       }
+
        if ($uid == -1) {
                $uid = local_user();
        }
@@ -355,7 +342,6 @@ function get_contact_details_by_addr($addr, $uid = -1) {
                                dbesc($addr));
 
        if (!dbm::is_result($r)) {
-               require_once('include/Probe.php');
                $data = Probe::uri($addr);
 
                $profile = get_contact_details_by_url($data['url'], $uid);
@@ -485,7 +471,7 @@ function random_profile() {
 
 function contacts_not_grouped($uid,$start = 0,$count = 0) {
 
-       if (! $count) {
+       if(! $count) {
                $r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
                        intval($uid),
                        intval($uid)
@@ -536,6 +522,10 @@ function get_contact($url, $uid = 0, $no_update = false) {
        $data = array();
        $contact_id = 0;
 
+       if ($url == '') {
+               return 0;
+       }
+
        // We first try the nurl (http://server.tld/nick), most common case
        $contacts = q("SELECT `id`, `avatar-date` FROM `contact`
                                        WHERE `nurl` = '%s'
@@ -577,7 +567,6 @@ function get_contact($url, $uid = 0, $no_update = false) {
                return 0;
        }
 
-       require_once('include/Probe.php');
        $data = Probe::uri($url);
 
        // Last try in gcontact for unsupported networks
@@ -694,7 +683,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
  */
 function posts_from_gcontact(App $a, $gcontact_id) {
 
-       require_once('include/conversation.php');
+       require_once 'include/conversation.php';
 
        // There are no posts with "uid = 0" with connector networks
        // This speeds up the query a lot
@@ -733,7 +722,7 @@ function posts_from_gcontact(App $a, $gcontact_id) {
  */
 function posts_from_contact_url(App $a, $contact_url) {
 
-       require_once('include/conversation.php');
+       require_once 'include/conversation.php';
 
        // There are no posts with "uid = 0" with connector networks
        // This speeds up the query a lot
@@ -777,18 +766,18 @@ function posts_from_contact_url(App $a, $contact_url) {
 function formatted_location($profile) {
        $location = '';
 
-       if ($profile['locality'])
+       if($profile['locality'])
                $location .= $profile['locality'];
 
-       if ($profile['region'] AND ($profile['locality'] != $profile['region'])) {
-               if ($location)
+       if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
+               if($location)
                        $location .= ', ';
 
                $location .= $profile['region'];
        }
 
-       if ($profile['country-name']) {
-               if ($location)
+       if($profile['country-name']) {
+               if($location)
                        $location .= ', ';
 
                $location .= $profile['country-name'];
@@ -810,7 +799,7 @@ function account_type($contact) {
        // "page-flags" is a field in the user table,
        // "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP.
        // "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP.
-       if ((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
+       if((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
                || (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP))
                || (isset($contact['forum']) && intval($contact['forum']))
                || (isset($contact['prv']) && intval($contact['prv']))
@@ -842,4 +831,3 @@ function account_type($contact) {
 
        return $account_type;
 }
-?>