]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into rewrites/mixed-static-object...
authorRoland Häder <roland@mxchange.org>
Mon, 19 Dec 2016 08:40:34 +0000 (09:40 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 19 Dec 2016 08:40:34 +0000 (09:40 +0100)
Signed-off-by: Roland Häder <roland@mxchange.org>
Conflicts:
include/follow.php

1  2 
include/Contact.php
include/cron.php
include/follow.php
include/user.php
mod/install.php

diff --combined include/Contact.php
index 871418bf57600d34f6fbd46a67228161f805b5c9,58748e289a70717b3cdbe35f0a2aad65cb2e8c1b..7ca45a21bd01e32baee60d3e235faa49afc76cb1
@@@ -64,7 -64,7 +64,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');
@@@ -93,20 -93,13 +93,13 @@@ function terminate_friendship($user,$se
  
        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"
-               ));
+               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');
@@@ -249,7 -242,7 +242,7 @@@ function get_contact_details_by_url($ur
                        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) {
@@@ -435,7 -428,7 +428,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 '';
  }
diff --combined include/cron.php
index d7771c08b8dee6b2cca2a0a50ad1dd9c52c095cf,730325ba8c0ccb95cc2ab786a4e6f0741178c193..77332dcec6c2daa300b2222b496dfd2fee0cdbc8
@@@ -12,6 -12,7 +12,7 @@@ if (!file_exists("boot.php") AND (sizeo
  
  require_once("boot.php");
  require_once("include/photos.php");
+ require_once("include/user.php");
  
  
  function cron_run(&$argv, &$argc){
@@@ -42,7 -43,7 +43,7 @@@
  
        // Don't check this stuff if the function is called by the poller
        if (App::callstack() != "poller_run") {
 -              if (App::maxload_reached())
 +              if ($a->maxload_reached())
                        return;
                if (App::is_already_running('cron', 'include/cron.php', 540))
                        return;
@@@ -433,7 -434,7 +434,7 @@@ function cron_repair_diaspora(&$a) 
        $r = q("SELECT `id`, `url` FROM `contact`
                WHERE `network` = '%s' AND (`batch` = '' OR `notify` = '' OR `poll` = '' OR pubkey = '')
                        ORDER BY RAND() LIMIT 50", dbesc(NETWORK_DIASPORA));
 -      if ($r) {
 +      if (dbm::is_result($r)) {
                foreach ($r AS $contact) {
                        if (poco_reachable($contact["url"])) {
                                $data = probe_url($contact["url"]);
   */
  function cron_repair_database() {
  
+       // Sometimes there seem to be issues where the "self" contact vanishes.
+       // We haven't found the origin of the problem by now.
+       $r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)");
+       if (dbm::is_result($r)) {
+               foreach ($r AS $user) {
+                       logger('Create missing self contact for user '.$user['uid']);
+                       user_create_self_contact($user['uid']);
+               }
+       }
        // Set the parent if it wasn't set. (Shouldn't happen - but does sometimes)
        // This call is very "cheap" so we can do it at any time without a problem
        q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
  
        // Update the global contacts for local users
        $r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
 -      if ($r)
 +      if (dbm::is_result($r))
                foreach ($r AS $user)
                        update_gcontact_for_user($user["uid"]);
  
diff --combined include/follow.php
index f753206efcde106f36f06bb48d60bccbf0c1d174,77f0bbe2f102f246e8abab9cf68dc311207d8684..7a3514b3a73aa4942ca00f009cc6128361782461
@@@ -2,6 -2,10 +2,10 @@@
  require_once("include/Scrape.php");
  require_once("include/socgraph.php");
  require_once('include/group.php');
+ require_once('include/salmon.php');
+ require_once('include/ostatus.php');
+ require_once("include/Photo.php");
+ require_once('include/diaspora.php');
  
  function update_contact($id) {
        /*
@@@ -173,12 -177,12 +177,12 @@@ function new_contact($uid,$url,$interac
                dbesc($ret['network'])
        );
  
 -      if(!count($r))
 +      if (!dbm::is_result($r))
                $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` = '%s' LIMIT 1",
                        intval($uid), dbesc(normalise_link($url)), dbesc($ret['network'])
        );
  
 -      if(count($r)) {
 +      if (dbm::is_result($r)) {
                // update contact
                if($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) {
                        q("UPDATE `contact` SET `rel` = %d , `subhub` = %d, `readonly` = 0 WHERE `id` = %d AND `uid` = %d",
                $r = q("select count(*) as total from contact where uid = %d and pending = 0 and self = 0",
                        intval($uid)
                );
 -              if(count($r))
 +              if (dbm::is_result($r))
                        $total_contacts = $r[0]['total'];
  
                if(! service_class_allows($uid,'total_contacts',$total_contacts)) {
                        intval($uid),
                        dbesc($network)
                );
 -              if(count($r))
 +              if (dbm::is_result($r))
                        $total_network = $r[0]['total'];
  
                if(! service_class_allows($uid,'total_contacts_' . $network,$total_network)) {
                intval($uid)
        );
  
 -      if(! count($r)) {
 +      if(! dbm::is_result($r)) {
                $result['message'] .=  t('Unable to retrieve contact information.') . EOL;
                return $result;
        }
        if (intval($def_gid))
                group_add_member($uid, '', $contact_id, $def_gid);
  
-       require_once("include/Photo.php");
        // Update the avatar
        update_contact_avatar($ret['photo'],$uid,$contact_id);
  
  
        proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
  
-       // create a follow slap
-       $tpl = get_markup_template('follow_slap.tpl');
-       $slap = replace_macros($tpl, array(
-               '$name' => $a->user['username'],
-               '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
-               '$photo' => $a->contact['photo'],
-               '$thumb' => $a->contact['thumb'],
-               '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
-               '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . get_guid(32),
-               '$title' => '',
-               '$type' => 'text',
-               '$content' => t('following'),
-               '$nick' => $a->user['nickname'],
-               '$verb' => ACTIVITY_FOLLOW,
-               '$ostat_follow' => ''
-       ));
        $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
-                       WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
+                       WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
                        intval($uid)
        );
  
        if (dbm::is_result($r)) {
-               if(($contact['network'] == NETWORK_OSTATUS) && (strlen($contact['notify']))) {
-                       require_once('include/salmon.php');
-                       slapper($r[0],$contact['notify'],$slap);
+               if (($contact['network'] == NETWORK_OSTATUS) && (strlen($contact['notify']))) {
+                       // create a follow slap
+                       $item = array();
+                       $item['verb'] = ACTIVITY_FOLLOW;
+                       $item['follow'] = $contact["url"];
+                       $slap = ostatus::salmon($item, $r[0]);
+                       slapper($r[0], $contact['notify'], $slap);
                }
-               if($contact['network'] == NETWORK_DIASPORA) {
-                       require_once('include/diaspora.php');
+               if ($contact['network'] == NETWORK_DIASPORA) {
                        $ret = diaspora::send_share($a->user,$contact);
                        logger('share returns: '.$ret);
                }
diff --combined include/user.php
index 7e97a1ddf2ff9d72ee6c0685bdd7a1f84ced9d9a,989c8b0e049fdb983639cf62c8ce523c81199cbe..ec15d5b1340f722c0e0de3d2910012ec04855e75
@@@ -130,7 -130,7 +130,7 @@@ function create_user($arr) 
                $r = q("SELECT * FROM `user` WHERE `email` = '%s' LIMIT 1",
                        dbesc($email)
                );
 -              if(count($r))
 +              if (dbm::is_result($r))
                        $result['message'] .= t('Cannot use that email.') . EOL;
        }
  
                WHERE `nickname` = '%s' LIMIT 1",
                dbesc($nickname)
        );
 -      if(count($r))
 +      if (dbm::is_result($r))
                $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL;
  
        // Check deleted accounts that had this nickname. Doesn't matter to us,
                WHERE `username` = '%s' LIMIT 1",
                dbesc($nickname)
        );
 -      if(count($r))
 +      if (dbm::is_result($r))
                $result['message'] .= t('Nickname was once registered here and may not be re-used. Please choose another.') . EOL;
  
        if(strlen($result['message'])) {
                        dbesc($username),
                        dbesc($new_password_encoded)
                );
 -              if($r !== false && count($r)) {
 +              if (dbm::is_result($r)) {
                        $u = $r[0];
                        $newuid = intval($r[0]['uid']);
                }
                                intval($newuid));
                        return $result;
                }
-               $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`,
-                       `addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness` )
-                       VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0 ) ",
-                       intval($newuid),
-                       datetime_convert(),
-                       dbesc($username),
-                       dbesc($nickname),
-                       dbesc(z_root() . "/photo/profile/{$newuid}.jpg"),
-                       dbesc(z_root() . "/photo/avatar/{$newuid}.jpg"),
-                       dbesc(z_root() . "/photo/micro/{$newuid}.jpg"),
-                       dbesc(z_root() . "/profile/$nickname"),
-                       dbesc(normalise_link(z_root() . "/profile/$nickname")),
-                       dbesc($nickname . '@' . substr(z_root(), strpos(z_root(),'://') + 3 )),
-                       dbesc(z_root() . "/dfrn_request/$nickname"),
-                       dbesc(z_root() . "/dfrn_notify/$nickname"),
-                       dbesc(z_root() . "/dfrn_poll/$nickname"),
-                       dbesc(z_root() . "/dfrn_confirm/$nickname"),
-                       dbesc(z_root() . "/poco/$nickname"),
-                       dbesc(datetime_convert()),
-                       dbesc(datetime_convert()),
-                       dbesc(datetime_convert())
-               );
+               // Create the self contact
+               user_create_self_contact($newuid);
  
                // Create a group with no members. This allows somebody to use it
                // right away as a default group for new contacts.
                        intval($newuid),
                        dbesc(t('Friends'))
                );
 -              if($r && count($r)) {
 +              if (dbm::is_result($r)) {
                        $def_gid = $r[0]['id'];
  
                        q("UPDATE `user` SET `def_gid` = %d WHERE `uid` = %d",
  
  }
  
+ /**
+  * @brief create the "self" contact from data from the user table
+  *
+  * @param integer $uid
+  */
+ function user_create_self_contact($uid) {
+       // Only create the entry if it doesn't exist yet
+       $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid));
+       if (dbm::is_result($r)) {
+               return;
+       }
+       $r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `uid` = %d", intval($uid));
+       if (!dbm::is_result($r)) {
+               return;
+       }
+       $user = $r[0];
+       q("INSERT INTO `contact` (`uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`,
+               `addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness`)
+               VALUES (%d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0)",
+               intval($user['uid']),
+               datetime_convert(),
+               dbesc($user['username']),
+               dbesc($user['nickname']),
+               dbesc(z_root()."/photo/profile/".$user['uid'].".jpg"),
+               dbesc(z_root()."/photo/avatar/".$user['uid'].".jpg"),
+               dbesc(z_root()."/photo/micro/".$user['uid'].".jpg"),
+               dbesc(z_root()."/profile/".$user['nickname']),
+               dbesc(normalise_link(z_root()."/profile/".$user['nickname'])),
+               dbesc($user['nickname'].'@'.substr(z_root(), strpos(z_root(),'://') + 3)),
+               dbesc(z_root()."/dfrn_request/".$user['nickname']),
+               dbesc(z_root()."/dfrn_notify/".$user['nickname']),
+               dbesc(z_root()."/dfrn_poll/".$user['nickname']),
+               dbesc(z_root()."/dfrn_confirm/".$user['nickname']),
+               dbesc(z_root()."/poco/".$user['nickname']),
+               dbesc(datetime_convert()),
+               dbesc(datetime_convert()),
+               dbesc(datetime_convert())
+       );
+ }
  
  /**
   * @brief send registration confiŕmation with the intormation that reg is pending
diff --combined mod/install.php
index f9dec01f16e8f83c0c84af0f2d72a8f7c6530896,97092c140f2f58ef9bd035d1008e5123a0be1f4f..b5af1373a443703b7ec35b862cc4cf84fdbc5c66
@@@ -165,7 -165,7 +165,7 @@@ function install_content(&$a) 
  
        if($db && $db->connected) {
                $r = q("SELECT COUNT(*) as `total` FROM `user`");
 -              if($r && count($r) && $r[0]['total']) {
 +              if (dbm::is_result($r) && $r[0]['total']) {
                        $tpl = get_markup_template('install.tpl');
                        return replace_macros($tpl, array(
                                '$title' => $install_title,
@@@ -548,9 -548,14 +548,14 @@@ function check_imagik(&$checks) 
                        $gif = true;
                }
        }
-       check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
-       if ($imagick) {
-               check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
+       if ($imagick == false) {
+               check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, "");
+               }
+       else {
+               check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
+               if ($imagick) {
+                       check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
+               }
        }
  }