$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');
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');
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) {
ORDER BY rand() LIMIT 1",
dbesc(NETWORK_DFRN));
- if(count($r))
+ if (dbm::is_result($r))
return dirname($r[0]['url']);
return '';
}
require_once("boot.php");
require_once("include/photos.php");
+ require_once("include/user.php");
function cron_run(&$argv, &$argc){
// 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;
$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"]);
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) {
/*
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);
}
$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
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,
$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, "");
+ }
}
}