Merge remote-tracking branch 'upstream/develop' into 1601-api-statuses-lookup
This commit is contained in:
@@ -132,8 +132,8 @@ function terminate_friendship($user,$self,$contact) {
|
||||
diaspora_unshare($user,$contact);
|
||||
}
|
||||
elseif($contact['network'] === NETWORK_DFRN) {
|
||||
require_once('include/items.php');
|
||||
dfrn_deliver($user,$contact,'placeholder', 1);
|
||||
require_once('include/dfrn.php');
|
||||
dfrn::deliver($user,$contact,'placeholder', 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -205,60 +205,49 @@ function get_contact_details_by_url($url, $uid = -1) {
|
||||
if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND
|
||||
in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
|
||||
proc_run('php',"include/update_gcontact.php", $profile["gid"]);
|
||||
|
||||
} else {
|
||||
$r = q("SELECT `url`, `name`, `nick`, `avatar` AS `photo`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'",
|
||||
dbesc(normalise_link($url)));
|
||||
|
||||
if (count($r)) {
|
||||
$profile = $r[0];
|
||||
$profile["keywords"] = "";
|
||||
$profile["gender"] = "";
|
||||
$profile["community"] = false;
|
||||
$profile["network"] = "";
|
||||
$profile["addr"] = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Fetching further contact data from the contact table
|
||||
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
|
||||
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `thumb`, `addr`, `forum`, `prv`, `bd`, `self` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` IN ('%s', '')",
|
||||
dbesc(normalise_link($url)), intval($uid), dbesc($profile["network"]));
|
||||
|
||||
if (!count($r))
|
||||
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
|
||||
if (!count($r) AND !isset($profile))
|
||||
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `thumb`, `addr`, `forum`, `prv`, `bd`, `self` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
|
||||
dbesc(normalise_link($url)), intval($uid));
|
||||
|
||||
if (!count($r))
|
||||
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
|
||||
if (!count($r) AND !isset($profile))
|
||||
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `thumb`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
|
||||
dbesc(normalise_link($url)));
|
||||
|
||||
if ($r) {
|
||||
if (isset($r[0]["url"]) AND $r[0]["url"])
|
||||
if (!isset($profile["url"]) AND $r[0]["url"])
|
||||
$profile["url"] = $r[0]["url"];
|
||||
if (isset($r[0]["name"]) AND $r[0]["name"])
|
||||
if (!isset($profile["name"]) AND $r[0]["name"])
|
||||
$profile["name"] = $r[0]["name"];
|
||||
if (isset($r[0]["nick"]) AND $r[0]["nick"] AND ($profile["nick"] == ""))
|
||||
if (!isset($profile["nick"]) AND $r[0]["nick"])
|
||||
$profile["nick"] = $r[0]["nick"];
|
||||
if (isset($r[0]["addr"]) AND $r[0]["addr"] AND ($profile["addr"] == ""))
|
||||
if (!isset($profile["addr"]) AND $r[0]["addr"])
|
||||
$profile["addr"] = $r[0]["addr"];
|
||||
if (isset($r[0]["photo"]) AND $r[0]["photo"])
|
||||
if ((!isset($profile["photo"]) OR $r[0]["self"]) AND $r[0]["photo"])
|
||||
$profile["photo"] = $r[0]["photo"];
|
||||
if (isset($r[0]["location"]) AND $r[0]["location"])
|
||||
if (!isset($profile["location"]) AND $r[0]["location"])
|
||||
$profile["location"] = $r[0]["location"];
|
||||
if (isset($r[0]["about"]) AND $r[0]["about"])
|
||||
if (!isset($profile["about"]) AND $r[0]["about"])
|
||||
$profile["about"] = $r[0]["about"];
|
||||
if (isset($r[0]["keywords"]) AND $r[0]["keywords"])
|
||||
if (!isset($profile["keywords"]) AND $r[0]["keywords"])
|
||||
$profile["keywords"] = $r[0]["keywords"];
|
||||
if (isset($r[0]["gender"]) AND $r[0]["gender"])
|
||||
if (!isset($profile["gender"]) AND $r[0]["gender"])
|
||||
$profile["gender"] = $r[0]["gender"];
|
||||
if (isset($r[0]["forum"]) OR isset($r[0]["prv"]))
|
||||
$profile["community"] = ($r[0]["forum"] OR $r[0]["prv"]);
|
||||
if (isset($r[0]["network"]) AND $r[0]["network"])
|
||||
if (!isset($profile["network"]) AND $r[0]["network"])
|
||||
$profile["network"] = $r[0]["network"];
|
||||
if (isset($r[0]["addr"]) AND $r[0]["addr"])
|
||||
if (!isset($profile["addr"]) AND $r[0]["addr"])
|
||||
$profile["addr"] = $r[0]["addr"];
|
||||
if (isset($r[0]["bd"]) AND $r[0]["bd"])
|
||||
if (!isset($profile["bd"]) AND $r[0]["bd"])
|
||||
$profile["bd"] = $r[0]["bd"];
|
||||
if (isset($r[0]["thumb"]))
|
||||
$profile["thumb"] = $r[0]["thumb"];
|
||||
if ($r[0]["uid"] == 0)
|
||||
$profile["cid"] = 0;
|
||||
else
|
||||
@@ -415,6 +404,7 @@ function get_contact($url, $uid = 0) {
|
||||
$contactid = 0;
|
||||
|
||||
// is it an address in the format user@server.tld?
|
||||
/// @todo use gcontact and/or the addr field for a lookup
|
||||
if (!strstr($url, "http") OR strstr($url, "@")) {
|
||||
$data = probe_url($url);
|
||||
$url = $data["url"];
|
||||
@@ -422,12 +412,12 @@ function get_contact($url, $uid = 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
|
||||
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
|
||||
dbesc(normalise_link($url)),
|
||||
intval($uid));
|
||||
|
||||
if (!$contact)
|
||||
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d",
|
||||
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d ORDER BY `id` LIMIT 1",
|
||||
dbesc($url),
|
||||
dbesc(normalise_link($url)),
|
||||
intval($uid));
|
||||
@@ -451,9 +441,7 @@ function get_contact($url, $uid = 0) {
|
||||
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
|
||||
return 0;
|
||||
|
||||
// tempory programming. Can be deleted after 2015-02-07
|
||||
if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
|
||||
$data["alias"] = normalise_link($url);
|
||||
$url = $data["url"];
|
||||
|
||||
if ($contactid == 0) {
|
||||
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
|
||||
@@ -482,7 +470,7 @@ function get_contact($url, $uid = 0) {
|
||||
dbesc($data["poco"])
|
||||
);
|
||||
|
||||
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
|
||||
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
|
||||
dbesc(normalise_link($data["url"])),
|
||||
intval($uid));
|
||||
if (!$contact)
|
||||
@@ -491,25 +479,217 @@ function get_contact($url, $uid = 0) {
|
||||
$contactid = $contact[0]["id"];
|
||||
}
|
||||
|
||||
if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))
|
||||
q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d",
|
||||
dbesc(normalise_link($url)),
|
||||
intval($contactid));
|
||||
|
||||
require_once("Photo.php");
|
||||
|
||||
$photos = import_profile_photo($data["photo"],$uid,$contactid);
|
||||
update_contact_avatar($data["photo"],$uid,$contactid);
|
||||
|
||||
q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s',
|
||||
`addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
|
||||
`name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
|
||||
`name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
|
||||
dbesc($data["addr"]),
|
||||
dbesc($data["alias"]),
|
||||
dbesc($data["name"]),
|
||||
dbesc($data["nick"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval($contactid)
|
||||
);
|
||||
|
||||
return $contactid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns posts from a given gcontact
|
||||
*
|
||||
* @param App $a argv application class
|
||||
* @param int $gcontact_id Global contact
|
||||
*
|
||||
* @return string posts in HTML
|
||||
*/
|
||||
function posts_from_gcontact($a, $gcontact_id) {
|
||||
|
||||
require_once('include/conversation.php');
|
||||
|
||||
// There are no posts with "uid = 0" with connector networks
|
||||
// This speeds up the query a lot
|
||||
$r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id));
|
||||
if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
|
||||
$sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
|
||||
else
|
||||
$sql = "`item`.`uid` = %d";
|
||||
|
||||
if(get_config('system', 'old_pager')) {
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `item`
|
||||
WHERE `gcontact-id` = %d and $sql",
|
||||
intval($gcontact_id),
|
||||
intval(local_user()));
|
||||
|
||||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
|
||||
$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`)
|
||||
WHERE `gcontact-id` = %d AND $sql AND
|
||||
NOT `deleted` AND NOT `moderated` AND `visible`
|
||||
ORDER BY `item`.`created` DESC LIMIT %d, %d",
|
||||
intval($gcontact_id),
|
||||
intval(local_user()),
|
||||
intval($a->pager['start']),
|
||||
intval($a->pager['itemspage'])
|
||||
);
|
||||
|
||||
$o = conversation($a,$r,'community',false);
|
||||
|
||||
if(!get_config('system', 'old_pager')) {
|
||||
$o .= alt_pager($a,count($r));
|
||||
} else {
|
||||
$o .= paginate($a);
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the gcontact-id in all item entries
|
||||
*
|
||||
* This job has to be started multiple times until all entries are set.
|
||||
* It isn't started in the update function since it would consume too much time and can be done in the background.
|
||||
*/
|
||||
function item_set_gcontact() {
|
||||
define ('POST_UPDATE_VERSION', 1192);
|
||||
|
||||
// Was the script completed?
|
||||
if (get_config("system", "post_update_version") >= POST_UPDATE_VERSION)
|
||||
return;
|
||||
|
||||
// Check if the first step is done (Setting "gcontact-id" in the item table)
|
||||
$r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
|
||||
if (!$r) {
|
||||
// Are there unfinished entries in the thread table?
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `thread`
|
||||
INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
|
||||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
if ($r AND ($r[0]["total"] == 0)) {
|
||||
set_config("system", "post_update_version", POST_UPDATE_VERSION);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update the thread table from the item table
|
||||
q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
|
||||
SET `thread`.`gcontact-id` = `item`.`gcontact-id`
|
||||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$item_arr = array();
|
||||
foreach ($r AS $item) {
|
||||
$index = $item["author-link"]."-".$item["uid"];
|
||||
$item_arr[$index] = array("author-link" => $item["author-link"],
|
||||
"uid" => $item["uid"],
|
||||
"network" => $item["network"]);
|
||||
}
|
||||
|
||||
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
|
||||
foreach($item_arr AS $item) {
|
||||
$gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
|
||||
"photo" => $item['author-avatar'], "name" => $item['author-name']));
|
||||
q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
|
||||
intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns posts from a given contact
|
||||
*
|
||||
* @param App $a argv application class
|
||||
* @param int $contact_id contact
|
||||
*
|
||||
* @return string posts in HTML
|
||||
*/
|
||||
function posts_from_contact($a, $contact_id) {
|
||||
|
||||
require_once('include/conversation.php');
|
||||
|
||||
$r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$contact = $r[0];
|
||||
|
||||
if(get_config('system', 'old_pager')) {
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `item`
|
||||
WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
|
||||
intval(local_user()),
|
||||
dbesc(str_replace("https://", "http://", $contact["url"])),
|
||||
dbesc(str_replace("http://", "https://", $contact["url"])));
|
||||
|
||||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
|
||||
$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 (`uid_contactid_created`)
|
||||
WHERE `item`.`uid` = %d AND `contact-id` = %d
|
||||
AND `author-link` IN ('%s', '%s')
|
||||
AND NOT `deleted` AND NOT `moderated` AND `visible`
|
||||
ORDER BY `item`.`created` DESC LIMIT %d, %d",
|
||||
intval(local_user()),
|
||||
intval($contact_id),
|
||||
dbesc(str_replace("https://", "http://", $contact["url"])),
|
||||
dbesc(str_replace("http://", "https://", $contact["url"])),
|
||||
intval($a->pager['start']),
|
||||
intval($a->pager['itemspage'])
|
||||
);
|
||||
|
||||
$o .= conversation($a,$r,'community',false);
|
||||
|
||||
if(!get_config('system', 'old_pager'))
|
||||
$o .= alt_pager($a,count($r));
|
||||
else
|
||||
$o .= paginate($a);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a formatted location string from the given profile array
|
||||
*
|
||||
* @param array $profile Profile array (Generated from the "profile" table)
|
||||
*
|
||||
* @return string Location string
|
||||
*/
|
||||
function formatted_location($profile) {
|
||||
$location = '';
|
||||
|
||||
if($profile['locality'])
|
||||
$location .= $profile['locality'];
|
||||
|
||||
if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
|
||||
if($location)
|
||||
$location .= ', ';
|
||||
|
||||
$location .= $profile['region'];
|
||||
}
|
||||
|
||||
if($profile['country-name']) {
|
||||
if($location)
|
||||
$location .= ', ';
|
||||
|
||||
$location .= $profile['country-name'];
|
||||
}
|
||||
|
||||
return $location;
|
||||
}
|
||||
?>
|
||||
|
||||
190
include/ForumManager.php
Normal file
190
include/ForumManager.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file include/forum.php
|
||||
* @brief Functions related to forum functionality *
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This class handles functions related to the forum functionality
|
||||
*/
|
||||
class ForumManager {
|
||||
|
||||
/**
|
||||
* @brief Function to list all forums a user is connected with
|
||||
*
|
||||
* @param int $uid of the profile owner
|
||||
* @param boolean $showhidden
|
||||
* Show frorums which are not hidden
|
||||
* @param boolean $lastitem
|
||||
* Sort by lastitem
|
||||
* @param boolean $showprivate
|
||||
* Show private groups
|
||||
*
|
||||
* @returns array
|
||||
* 'url' => forum url
|
||||
* 'name' => forum name
|
||||
* 'id' => number of the key from the array
|
||||
* 'micro' => contact photo in format micro
|
||||
*/
|
||||
public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
|
||||
|
||||
$forumlist = array();
|
||||
|
||||
$order = (($showhidden) ? '' : ' AND NOT `hidden` ');
|
||||
$order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
|
||||
$select = '`forum` ';
|
||||
if ($showprivate) {
|
||||
$select = '(`forum` OR `prv`)';
|
||||
}
|
||||
|
||||
$contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
|
||||
WHERE `network`= 'dfrn' AND $select AND `uid` = %d
|
||||
AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
|
||||
AND `success_update` > `failure_update`
|
||||
$order ",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if (!$contacts)
|
||||
return($forumlist);
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist[] = array(
|
||||
'url' => $contact['url'],
|
||||
'name' => $contact['name'],
|
||||
'id' => $contact['id'],
|
||||
'micro' => $contact['micro'],
|
||||
);
|
||||
}
|
||||
return($forumlist);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Forumlist widget
|
||||
*
|
||||
* Sidebar widget to show subcribed friendica forums. If activated
|
||||
* in the settings, it appears at the notwork page sidebar
|
||||
*
|
||||
* @param int $uid The ID of the User
|
||||
* @param int $cid
|
||||
* The contact id which is used to mark a forum as "selected"
|
||||
* @return string
|
||||
*/
|
||||
public static function widget($uid,$cid = 0) {
|
||||
|
||||
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
//sort by last updated item
|
||||
$lastitem = true;
|
||||
|
||||
$contacts = self::get_list($uid,true,$lastitem, true);
|
||||
$total = count($contacts);
|
||||
$visible_forums = 10;
|
||||
|
||||
if(count($contacts)) {
|
||||
|
||||
$id = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
|
||||
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
|
||||
|
||||
$entry = array(
|
||||
'url' => z_root() . '/network?f=&cid=' . $contact['id'],
|
||||
'external_url' => z_root() . '/redir/' . $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'cid' => $contact['id'],
|
||||
'selected' => $selected,
|
||||
'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
|
||||
'id' => ++$id,
|
||||
);
|
||||
$entries[] = $entry;
|
||||
}
|
||||
|
||||
$tpl = get_markup_template('widget_forumlist.tpl');
|
||||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$title' => t('Forums'),
|
||||
'$forums' => $entries,
|
||||
'$link_desc' => t('External link to forum'),
|
||||
'$total' => $total,
|
||||
'$visible_forums' => $visible_forums,
|
||||
'$showmore' => t('show more'),
|
||||
));
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format forumlist as contact block
|
||||
*
|
||||
* This function is used to show the forumlist in
|
||||
* the advanced profile.
|
||||
*
|
||||
* @param int $uid The ID of the User
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public static function profile_advanced($uid) {
|
||||
|
||||
$profile = intval(feature_enabled($uid,'forumlist_profile'));
|
||||
if(! $profile)
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
// place holder in case somebody wants configurability
|
||||
$show_total = 9999;
|
||||
|
||||
//don't sort by last updated item
|
||||
$lastitem = false;
|
||||
|
||||
$contacts = self::get_list($uid,false,$lastitem,false);
|
||||
|
||||
$total_shown = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
|
||||
$total_shown ++;
|
||||
if($total_shown == $show_total)
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($contacts) > 0)
|
||||
$o .= $forumlist;
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief count unread forum items
|
||||
*
|
||||
* Count unread items of connected forums and private groups
|
||||
*
|
||||
* @return array
|
||||
* 'id' => contact id
|
||||
* 'name' => contact/forum name
|
||||
* 'count' => counted unseen forum items
|
||||
*
|
||||
*/
|
||||
public static function count_unseen_items() {
|
||||
$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
|
||||
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
|
||||
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
|
||||
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
|
||||
AND NOT `contact`.`pending` AND NOT `contact`.`archive`
|
||||
AND `contact`.`success_update` > `failure_update`
|
||||
GROUP BY `contact`.`id` ",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
||||
136
include/NotificationsManager.php
Normal file
136
include/NotificationsManager.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/NotificationsManager.php
|
||||
*/
|
||||
require_once('include/html2plain.php');
|
||||
require_once("include/datetime.php");
|
||||
require_once("include/bbcode.php");
|
||||
|
||||
/**
|
||||
* @brief Read and write notifications from/to database
|
||||
*/
|
||||
class NotificationsManager {
|
||||
private $a;
|
||||
|
||||
public function __construct() {
|
||||
$this->a = get_app();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set some extra note properties
|
||||
*
|
||||
* @param array $notes array of note arrays from db
|
||||
* @return array Copy of input array with added properties
|
||||
*
|
||||
* Set some extra properties to note array from db:
|
||||
* - timestamp as int in default TZ
|
||||
* - date_rel : relative date string
|
||||
* - msg_html: message as html string
|
||||
* - msg_plain: message as plain text string
|
||||
*/
|
||||
private function _set_extra($notes) {
|
||||
$rets = array();
|
||||
foreach($notes as $n) {
|
||||
$local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']);
|
||||
$n['timestamp'] = strtotime($local_time);
|
||||
$n['date_rel'] = relative_date($n['date']);
|
||||
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
|
||||
$n['msg_plain'] = explode("\n",trim(html2plain($n['msg_html'], 0)))[0];
|
||||
|
||||
$rets[] = $n;
|
||||
}
|
||||
return $rets;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get all notifications for local_user()
|
||||
*
|
||||
* @param array $filter optional Array "column name"=>value: filter query by columns values
|
||||
* @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date"
|
||||
* @param string $limit optional Query limits
|
||||
*
|
||||
* @return array of results or false on errors
|
||||
*/
|
||||
public function getAll($filter = array(), $order="-date", $limit="") {
|
||||
$filter_str = array();
|
||||
$filter_sql = "";
|
||||
foreach($filter as $column => $value) {
|
||||
$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
|
||||
}
|
||||
if (count($filter_str)>0) {
|
||||
$filter_sql = "AND ".implode(" AND ", $filter_str);
|
||||
}
|
||||
|
||||
$aOrder = explode(" ", $order);
|
||||
$asOrder = array();
|
||||
foreach($aOrder as $o) {
|
||||
$dir = "asc";
|
||||
if ($o[0]==="-") {
|
||||
$dir = "desc";
|
||||
$o = substr($o,1);
|
||||
}
|
||||
if ($o[0]==="+") {
|
||||
$dir = "asc";
|
||||
$o = substr($o,1);
|
||||
}
|
||||
$asOrder[] = "$o $dir";
|
||||
}
|
||||
$order_sql = implode(", ", $asOrder);
|
||||
|
||||
if ($limit!="") $limit = " LIMIT ".$limit;
|
||||
|
||||
$r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
|
||||
intval(local_user())
|
||||
);
|
||||
if ($r!==false && count($r)>0) return $this->_set_extra($r);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get one note for local_user() by $id value
|
||||
*
|
||||
* @param int $id
|
||||
* @return array note values or null if not found
|
||||
*/
|
||||
public function getByID($id) {
|
||||
$r = q("SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($id),
|
||||
intval(local_user())
|
||||
);
|
||||
if($r!==false && count($r)>0) {
|
||||
return $this->_set_extra($r)[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of $note of local_user()
|
||||
*
|
||||
* @param array $note
|
||||
* @param bool $seen optional true or false, default true
|
||||
* @return bool true on success, false on errors
|
||||
*/
|
||||
public function setSeen($note, $seen = true) {
|
||||
return q("UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d",
|
||||
intval($seen),
|
||||
dbesc($note['link']),
|
||||
intval($note['parent']),
|
||||
dbesc($note['otype']),
|
||||
intval(local_user())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of all notifications of local_user()
|
||||
*
|
||||
* @param bool $seen optional true or false. default true
|
||||
* @return bool true on success, false on error
|
||||
*/
|
||||
public function setAllSeen($seen = true) {
|
||||
return q("UPDATE `notify` SET `seen` = %d WHERE `uid` = %d",
|
||||
intval($seen),
|
||||
intval(local_user())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -720,65 +720,101 @@ function guess_image_type($filename, $fromcurl=false) {
|
||||
|
||||
}
|
||||
|
||||
function import_profile_photo($photo,$uid,$cid) {
|
||||
/**
|
||||
* @brief Updates the avatar links in a contact only if needed
|
||||
*
|
||||
* @param string $avatar Link to avatar picture
|
||||
* @param int $uid User id of contact owner
|
||||
* @param int $cid Contact id
|
||||
* @param bool $force force picture update
|
||||
*
|
||||
* @return array Returns array of the different avatar sizes
|
||||
*/
|
||||
function update_contact_avatar($avatar,$uid,$cid, $force = false) {
|
||||
|
||||
$a = get_app();
|
||||
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
|
||||
if (!$r)
|
||||
return false;
|
||||
else
|
||||
$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
|
||||
|
||||
$r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1",
|
||||
intval($uid),
|
||||
intval($cid)
|
||||
);
|
||||
if(count($r) && strlen($r[0]['resource-id'])) {
|
||||
$hash = $r[0]['resource-id'];
|
||||
}
|
||||
else {
|
||||
$hash = photo_new_resource();
|
||||
}
|
||||
if (($r[0]["avatar"] != $avatar) OR $force) {
|
||||
$photos = import_profile_photo($avatar,$uid,$cid, true);
|
||||
|
||||
$photo_failure = false;
|
||||
if ($photos) {
|
||||
q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
|
||||
dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
|
||||
dbesc(datetime_convert()), intval($cid));
|
||||
return $photos;
|
||||
}
|
||||
}
|
||||
|
||||
$filename = basename($photo);
|
||||
$img_str = fetch_url($photo,true);
|
||||
return $data;
|
||||
}
|
||||
|
||||
$type = guess_image_type($photo,true);
|
||||
$img = new Photo($img_str, $type);
|
||||
if($img->is_valid()) {
|
||||
function import_profile_photo($photo,$uid,$cid, $quit_on_error = false) {
|
||||
|
||||
$img->scaleImageSquare(175);
|
||||
$a = get_app();
|
||||
|
||||
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 );
|
||||
$r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1",
|
||||
intval($uid),
|
||||
intval($cid)
|
||||
);
|
||||
if(count($r) && strlen($r[0]['resource-id'])) {
|
||||
$hash = $r[0]['resource-id'];
|
||||
} else {
|
||||
$hash = photo_new_resource();
|
||||
}
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
$photo_failure = false;
|
||||
|
||||
$img->scaleImage(80);
|
||||
$filename = basename($photo);
|
||||
$img_str = fetch_url($photo,true);
|
||||
|
||||
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 );
|
||||
if ($quit_on_error AND ($img_str == ""))
|
||||
return false;
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
$type = guess_image_type($photo,true);
|
||||
$img = new Photo($img_str, $type);
|
||||
if($img->is_valid()) {
|
||||
|
||||
$img->scaleImage(48);
|
||||
$img->scaleImageSquare(175);
|
||||
|
||||
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 );
|
||||
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 );
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
|
||||
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
|
||||
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
|
||||
}
|
||||
else
|
||||
$photo_failure = true;
|
||||
$img->scaleImage(80);
|
||||
|
||||
if($photo_failure) {
|
||||
$photo = $a->get_baseurl() . '/images/person-175.jpg';
|
||||
$thumb = $a->get_baseurl() . '/images/person-80.jpg';
|
||||
$micro = $a->get_baseurl() . '/images/person-48.jpg';
|
||||
}
|
||||
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 );
|
||||
|
||||
return(array($photo,$thumb,$micro));
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(48);
|
||||
|
||||
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 );
|
||||
|
||||
if($r === false)
|
||||
$photo_failure = true;
|
||||
|
||||
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
|
||||
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
|
||||
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
|
||||
} else
|
||||
$photo_failure = true;
|
||||
|
||||
if($photo_failure AND $quit_on_error)
|
||||
return false;
|
||||
|
||||
if($photo_failure) {
|
||||
$photo = $a->get_baseurl() . '/images/person-175.jpg';
|
||||
$thumb = $a->get_baseurl() . '/images/person-80.jpg';
|
||||
$micro = $a->get_baseurl() . '/images/person-48.jpg';
|
||||
}
|
||||
|
||||
return(array($photo,$thumb,$micro));
|
||||
|
||||
}
|
||||
|
||||
@@ -792,15 +828,19 @@ function get_photo_info($url) {
|
||||
|
||||
$filesize = strlen($img_str);
|
||||
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
if (function_exists("getimagesizefromstring"))
|
||||
$data = getimagesizefromstring($img_str);
|
||||
else {
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
|
||||
$a = get_app();
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
$a = get_app();
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
|
||||
$data = getimagesize($tempfile);
|
||||
unlink($tempfile);
|
||||
$data = getimagesize($tempfile);
|
||||
unlink($tempfile);
|
||||
}
|
||||
|
||||
if ($data)
|
||||
$data["size"] = $filesize;
|
||||
|
||||
@@ -235,7 +235,9 @@ function scrape_feed($url) {
|
||||
$a = get_app();
|
||||
|
||||
$ret = array();
|
||||
$s = fetch_url($url);
|
||||
$cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
|
||||
$s = fetch_url($url, false, $redirects, 0, Null, $cookiejar);
|
||||
unlink($cookiejar);
|
||||
|
||||
$headers = $a->get_curl_headers();
|
||||
$code = $a->get_curl_code();
|
||||
@@ -559,10 +561,11 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
||||
$pubkey = $hcard_key;
|
||||
}
|
||||
}
|
||||
|
||||
if($diaspora && $diaspora_base && $diaspora_guid) {
|
||||
if($mode == PROBE_DIASPORA || ! $notify) {
|
||||
$notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
|
||||
$diaspora_notify = $diaspora_base.'receive/users/'.$diaspora_guid;
|
||||
|
||||
if($mode == PROBE_DIASPORA || ! $notify || ($notify == $diaspora_notify)) {
|
||||
$notify = $diaspora_notify;
|
||||
$batch = $diaspora_base . 'receive/public' ;
|
||||
}
|
||||
if(strpos($url,'@'))
|
||||
@@ -661,7 +664,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
||||
$vcard['photo'] = $feedret['photo'];
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
$feed = new SimplePie();
|
||||
$xml = fetch_url($poll);
|
||||
$cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
|
||||
$xml = fetch_url($poll, false, $redirects, 0, Null, $cookiejar);
|
||||
unlink($cookiejar);
|
||||
|
||||
logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
|
||||
$a = get_app();
|
||||
|
||||
@@ -20,7 +20,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
|
||||
|
||||
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
|
||||
|
||||
$r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
|
||||
$r = q("SELECT `id`, `name` FROM `group` WHERE NOT `deleted` AND `uid` = %d ORDER BY `name` ASC",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
@@ -309,7 +309,7 @@ function populate_acl($user = null, $show_jotnets = false) {
|
||||
$pubmail_enabled = false;
|
||||
|
||||
if(! $mail_disabled) {
|
||||
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
|
||||
$r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
|
||||
intval(local_user())
|
||||
);
|
||||
if(count($r)) {
|
||||
@@ -407,7 +407,7 @@ function acl_lookup(&$a, $out_type = 'json') {
|
||||
$search = $_REQUEST['query'];
|
||||
}
|
||||
|
||||
// logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG);
|
||||
logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG);
|
||||
|
||||
if ($search!=""){
|
||||
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
|
||||
@@ -503,7 +503,7 @@ function acl_lookup(&$a, $out_type = 'json') {
|
||||
}
|
||||
}
|
||||
|
||||
if ($type=='' || $type=='c'){
|
||||
if ($type==''){
|
||||
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact`
|
||||
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
|
||||
@@ -514,6 +514,17 @@ function acl_lookup(&$a, $out_type = 'json') {
|
||||
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
}
|
||||
elseif ($type=='c'){
|
||||
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact`
|
||||
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
|
||||
AND NOT (`network` IN ('%s'))
|
||||
$sql_extra2
|
||||
ORDER BY `name` ASC ",
|
||||
intval(local_user()),
|
||||
dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
}
|
||||
elseif($type == 'm') {
|
||||
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
|
||||
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
|
||||
|
||||
211
include/api.php
211
include/api.php
@@ -23,6 +23,7 @@
|
||||
require_once('include/message.php');
|
||||
require_once('include/group.php');
|
||||
require_once('include/like.php');
|
||||
require_once('include/NotificationsManager.php');
|
||||
|
||||
|
||||
define('API_METHOD_ANY','*');
|
||||
@@ -250,7 +251,7 @@
|
||||
*/
|
||||
function api_call(&$a){
|
||||
GLOBAL $API, $called_api;
|
||||
|
||||
|
||||
$type="json";
|
||||
if (strpos($a->query_string, ".xml")>0) $type="xml";
|
||||
if (strpos($a->query_string, ".json")>0) $type="json";
|
||||
@@ -394,7 +395,7 @@
|
||||
* Contact url or False if contact id is unknown
|
||||
*/
|
||||
function api_unique_id_to_url($id){
|
||||
$r = q("SELECT `url` FROM `unique_contacts` WHERE `id`=%d LIMIT 1",
|
||||
$r = q("SELECT `url` FROM `gcontact` WHERE `id`=%d LIMIT 1",
|
||||
intval($id));
|
||||
if ($r)
|
||||
return ($r[0]["url"]);
|
||||
@@ -504,9 +505,7 @@
|
||||
$r = array();
|
||||
|
||||
if ($url != "")
|
||||
$r = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", $url);
|
||||
elseif ($nick != "")
|
||||
$r = q("SELECT * FROM `unique_contacts` WHERE `nick`='%s' LIMIT 1", $nick);
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($url)));
|
||||
|
||||
if ($r) {
|
||||
// If no nick where given, extract it from the address
|
||||
@@ -518,14 +517,14 @@
|
||||
'id_str' => (string) $r[0]["id"],
|
||||
'name' => $r[0]["name"],
|
||||
'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']),
|
||||
'location' => NULL,
|
||||
'description' => NULL,
|
||||
'location' => $r[0]["location"],
|
||||
'description' => $r[0]["about"],
|
||||
'url' => $r[0]["url"],
|
||||
'protected' => false,
|
||||
'followers_count' => 0,
|
||||
'friends_count' => 0,
|
||||
'listed_count' => 0,
|
||||
'created_at' => api_date(0),
|
||||
'created_at' => api_date($r[0]["created"]),
|
||||
'favourites_count' => 0,
|
||||
'utc_offset' => 0,
|
||||
'time_zone' => 'UTC',
|
||||
@@ -536,8 +535,8 @@
|
||||
'contributors_enabled' => false,
|
||||
'is_translator' => false,
|
||||
'is_translation_enabled' => false,
|
||||
'profile_image_url' => $r[0]["avatar"],
|
||||
'profile_image_url_https' => $r[0]["avatar"],
|
||||
'profile_image_url' => $r[0]["photo"],
|
||||
'profile_image_url_https' => $r[0]["photo"],
|
||||
'following' => false,
|
||||
'follow_request_sent' => false,
|
||||
'notifications' => false,
|
||||
@@ -547,7 +546,7 @@
|
||||
'uid' => 0,
|
||||
'cid' => 0,
|
||||
'self' => 0,
|
||||
'network' => '',
|
||||
'network' => $r[0]["network"],
|
||||
);
|
||||
|
||||
return $ret;
|
||||
@@ -618,22 +617,14 @@
|
||||
$uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
|
||||
}
|
||||
|
||||
// Fetching unique id
|
||||
$r = q("SELECT id FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
|
||||
|
||||
// If not there, then add it
|
||||
if (count($r) == 0) {
|
||||
q("INSERT INTO `unique_contacts` (`url`, `name`, `nick`, `avatar`) VALUES ('%s', '%s', '%s', '%s')",
|
||||
dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']),dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro']));
|
||||
|
||||
$r = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
|
||||
}
|
||||
|
||||
$network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
|
||||
|
||||
$gcontact_id = get_gcontact_id(array("url" => $uinfo[0]['url'], "network" => $uinfo[0]['network'],
|
||||
"photo" => $uinfo[0]['micro'], "name" => $uinfo[0]['name']));
|
||||
|
||||
$ret = Array(
|
||||
'id' => intval($r[0]['id']),
|
||||
'id_str' => (string) intval($r[0]['id']),
|
||||
'id' => intval($gcontact_id),
|
||||
'id_str' => (string) intval($gcontact_id),
|
||||
'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
|
||||
'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
|
||||
'location' => ($usr) ? $usr[0]['default-location'] : $network_name,
|
||||
@@ -667,45 +658,12 @@
|
||||
|
||||
function api_item_get_user(&$a, $item) {
|
||||
|
||||
$author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
|
||||
dbesc(normalise_link($item['author-link'])));
|
||||
// Make sure that there is an entry in the global contacts for author and owner
|
||||
get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
|
||||
"photo" => $item['author-avatar'], "name" => $item['author-name']));
|
||||
|
||||
if (count($author) == 0) {
|
||||
q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')",
|
||||
dbesc(normalise_link($item["author-link"])), dbesc($item["author-name"]), dbesc($item["author-avatar"]));
|
||||
|
||||
$author = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
|
||||
dbesc(normalise_link($item['author-link'])));
|
||||
} else if ($item["author-link"].$item["author-name"] != $author[0]["url"].$author[0]["name"]) {
|
||||
$r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'",
|
||||
dbesc($item["author-name"]), dbesc($item["author-avatar"]),
|
||||
dbesc(normalise_link($item["author-link"])));
|
||||
|
||||
if (!$r)
|
||||
q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'",
|
||||
dbesc($item["author-name"]), dbesc($item["author-avatar"]),
|
||||
dbesc(normalise_link($item["author-link"])));
|
||||
}
|
||||
|
||||
$owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
|
||||
dbesc(normalise_link($item['owner-link'])));
|
||||
|
||||
if (count($owner) == 0) {
|
||||
q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')",
|
||||
dbesc(normalise_link($item["owner-link"])), dbesc($item["owner-name"]), dbesc($item["owner-avatar"]));
|
||||
|
||||
$owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
|
||||
dbesc(normalise_link($item['owner-link'])));
|
||||
} else if ($item["owner-link"].$item["owner-name"] != $owner[0]["url"].$owner[0]["name"]) {
|
||||
$r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'",
|
||||
dbesc($item["owner-name"]), dbesc($item["owner-avatar"]),
|
||||
dbesc(normalise_link($item["owner-link"])));
|
||||
|
||||
if (!$r)
|
||||
q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'",
|
||||
dbesc($item["owner-name"]), dbesc($item["owner-avatar"]),
|
||||
dbesc(normalise_link($item["owner-link"])));
|
||||
}
|
||||
get_gcontact_id(array("url" => $item['owner-link'], "network" => $item['network'],
|
||||
"photo" => $item['owner-avatar'], "name" => $item['owner-name']));
|
||||
|
||||
// Comments in threads may appear as wall-to-wall postings.
|
||||
// So only take the owner at the top posting.
|
||||
@@ -724,6 +682,34 @@
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief transform $data array in xml without a template
|
||||
*
|
||||
* @param array $data
|
||||
* @return string xml string
|
||||
*/
|
||||
function api_array_to_xml($data, $ename="") {
|
||||
$attrs="";
|
||||
$childs="";
|
||||
if (count($data)==1 && !is_array($data[0])) {
|
||||
$ename = array_keys($data)[0];
|
||||
$v = $data[$ename];
|
||||
return "<$ename>$v</$ename>";
|
||||
}
|
||||
foreach($data as $k=>$v) {
|
||||
$k=trim($k,'$');
|
||||
if (!is_array($v)) {
|
||||
$attrs .= sprintf('%s="%s" ', $k, $v);
|
||||
} else {
|
||||
if (is_numeric($k)) $k=trim($ename,'s');
|
||||
$childs.=api_array_to_xml($v, $k);
|
||||
}
|
||||
}
|
||||
$res = $childs;
|
||||
if ($ename!="") $res = "<$ename $attrs>$res</$ename>";
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* load api $templatename for $type and replace $data array
|
||||
*/
|
||||
@@ -736,13 +722,17 @@
|
||||
case "rss":
|
||||
case "xml":
|
||||
$data = array_xmlify($data);
|
||||
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
|
||||
if(! $tpl) {
|
||||
header ("Content-Type: text/xml");
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
|
||||
killme();
|
||||
if ($templatename==="<auto>") {
|
||||
$ret = api_array_to_xml($data);
|
||||
} else {
|
||||
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
|
||||
if(! $tpl) {
|
||||
header ("Content-Type: text/xml");
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
|
||||
killme();
|
||||
}
|
||||
$ret = replace_macros($tpl, $data);
|
||||
}
|
||||
$ret = replace_macros($tpl, $data);
|
||||
break;
|
||||
case "json":
|
||||
$ret = $data;
|
||||
@@ -825,8 +815,6 @@
|
||||
|
||||
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
|
||||
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
|
||||
$txt = html2bb_video($txt);
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('Cache.DefinitionImpl', null);
|
||||
@@ -866,9 +854,6 @@
|
||||
if(requestdata('htmlstatus')) {
|
||||
$txt = requestdata('htmlstatus');
|
||||
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
|
||||
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
|
||||
$txt = html2bb_video($txt);
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
@@ -1074,7 +1059,7 @@
|
||||
$in_reply_to_status_id= intval($lastwall['parent']);
|
||||
$in_reply_to_status_id_str = (string) intval($lastwall['parent']);
|
||||
|
||||
$r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
|
||||
if ($r) {
|
||||
if ($r[0]['nick'] == "")
|
||||
$r[0]['nick'] = api_get_nick($r[0]["url"]);
|
||||
@@ -1196,7 +1181,7 @@
|
||||
$in_reply_to_status_id = intval($lastwall['parent']);
|
||||
$in_reply_to_status_id_str = (string) intval($lastwall['parent']);
|
||||
|
||||
$r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
|
||||
if ($r) {
|
||||
if ($r[0]['nick'] == "")
|
||||
$r[0]['nick'] = api_get_nick($r[0]["url"]);
|
||||
@@ -1257,9 +1242,9 @@
|
||||
$userlist = array();
|
||||
|
||||
if (isset($_GET["q"])) {
|
||||
$r = q("SELECT id FROM `unique_contacts` WHERE `name`='%s'", dbesc($_GET["q"]));
|
||||
$r = q("SELECT id FROM `gcontact` WHERE `name`='%s'", dbesc($_GET["q"]));
|
||||
if (!count($r))
|
||||
$r = q("SELECT `id` FROM `unique_contacts` WHERE `nick`='%s'", dbesc($_GET["q"]));
|
||||
$r = q("SELECT `id` FROM `gcontact` WHERE `nick`='%s'", dbesc($_GET["q"]));
|
||||
|
||||
if (count($r)) {
|
||||
foreach ($r AS $user) {
|
||||
@@ -1595,6 +1580,8 @@
|
||||
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `contact`.`id` = `item`.`contact-id`
|
||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||
AND NOT `item`.`private` AND `item`.`allow_cid` = '' AND `item`.`allow`.`gid` = ''
|
||||
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
|
||||
$sql_extra
|
||||
AND `item`.`id`=%d",
|
||||
intval($id)
|
||||
@@ -1623,7 +1610,8 @@
|
||||
$_REQUEST["source"] = api_source();
|
||||
|
||||
item_post($a);
|
||||
}
|
||||
} else
|
||||
throw new ForbiddenException();
|
||||
|
||||
// this should output the last post (the one we just posted).
|
||||
$called_api = null;
|
||||
@@ -2342,7 +2330,7 @@
|
||||
intval(api_user()),
|
||||
intval($in_reply_to_status_id));
|
||||
if ($r) {
|
||||
$r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
|
||||
|
||||
if ($r) {
|
||||
if ($r[0]['nick'] == "")
|
||||
@@ -2598,7 +2586,7 @@
|
||||
|
||||
$stringify_ids = (x($_REQUEST,'stringify_ids')?$_REQUEST['stringify_ids']:false);
|
||||
|
||||
$r = q("SELECT `unique_contacts`.`id` FROM `contact`, `unique_contacts` WHERE `contact`.`nurl` = `unique_contacts`.`url` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra",
|
||||
$r = q("SELECT `gcontact`.`id` FROM `contact`, `gcontact` WHERE `contact`.`nurl` = `gcontact`.`nurl` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra",
|
||||
intval(api_user())
|
||||
);
|
||||
|
||||
@@ -3096,11 +3084,8 @@
|
||||
|
||||
//}
|
||||
|
||||
if ($nick != "") {
|
||||
q("UPDATE `unique_contacts` SET `nick` = '%s' WHERE `nick` != '%s' AND url = '%s'",
|
||||
dbesc($nick), dbesc($nick), dbesc(normalise_link($profile)));
|
||||
if ($nick != "")
|
||||
return($nick);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
@@ -3431,6 +3416,64 @@
|
||||
api_register_func('api/friendica/activity/unattendno', 'api_friendica_activity', true, API_METHOD_POST);
|
||||
api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activity', true, API_METHOD_POST);
|
||||
|
||||
/**
|
||||
* @brief Returns notifications
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
|
||||
* @return string
|
||||
*/
|
||||
function api_friendica_notification(&$a, $type) {
|
||||
if (api_user()===false) throw new ForbiddenException();
|
||||
if ($a->argc!==3) throw new BadRequestException("Invalid argument count");
|
||||
$nm = new NotificationsManager();
|
||||
|
||||
$notes = $nm->getAll(array(), "+seen -date", 50);
|
||||
return api_apply_template("<auto>", $type, array('$notes' => $notes));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set notification as seen and returns associated item (if possible)
|
||||
*
|
||||
* POST request with 'id' param as notification id
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
|
||||
* @return string
|
||||
*/
|
||||
function api_friendica_notification_seen(&$a, $type){
|
||||
if (api_user()===false) throw new ForbiddenException();
|
||||
if ($a->argc!==4) throw new BadRequestException("Invalid argument count");
|
||||
|
||||
$id = (x($_REQUEST, 'id') ? intval($_REQUEST['id']) : 0);
|
||||
|
||||
$nm = new NotificationsManager();
|
||||
$note = $nm->getByID($id);
|
||||
if (is_null($note)) throw new BadRequestException("Invalid argument");
|
||||
|
||||
$nm->setSeen($note);
|
||||
if ($note['otype']=='item') {
|
||||
// would be really better with an ItemsManager and $im->getByID() :-P
|
||||
$r = q("SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d",
|
||||
intval($note['iid']),
|
||||
intval(local_user())
|
||||
);
|
||||
if ($r!==false) {
|
||||
// we found the item, return it to the user
|
||||
$user_info = api_get_user($a);
|
||||
$ret = api_format_items($r,$user_info);
|
||||
$data = array('$statuses' => $ret);
|
||||
return api_apply_template("timeline", $type, $data);
|
||||
}
|
||||
// the item can't be found, but we set the note as seen, so we count this as a success
|
||||
}
|
||||
return api_apply_template('<auto>', $type, array('status' => "success"));
|
||||
}
|
||||
|
||||
api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST);
|
||||
api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET);
|
||||
|
||||
|
||||
/*
|
||||
To.Do:
|
||||
[pagename] => api/1.1/statuses/lookup.json
|
||||
|
||||
69
include/autoloader.php
Normal file
69
include/autoloader.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/autoloader.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief composer-derived autoloader init
|
||||
**/
|
||||
class FriendicaAutoloaderInit
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/autoloader/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('FriendicaAutoloaderInit', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('FriendicaAutoloaderInit', 'loadClassLoader'));
|
||||
|
||||
// library
|
||||
$map = require __DIR__ . '/autoloader/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoloader/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoloader/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = require __DIR__ . '/autoloader/autoload_files.php';
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
friendicaRequire($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function friendicaRequire($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return FriendicaAutoloaderInit::getLoader();
|
||||
413
include/autoloader/ClassLoader.php
Normal file
413
include/autoloader/ClassLoader.php
Normal file
@@ -0,0 +1,413 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE.composer
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0 class loader
|
||||
*
|
||||
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
// PSR-4
|
||||
private $prefixLengthsPsr4 = array();
|
||||
private $prefixDirsPsr4 = array();
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
private $prefixesPsr0 = array();
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', $this->prefixesPsr0);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classMap Class to filename map
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return bool|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
|
||||
if ('\\' == $class[0]) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if ($file === null && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
// Remember that this class does not exist.
|
||||
return $this->classMap[$class] = false;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
||||
19
include/autoloader/LICENSE.composer
Normal file
19
include/autoloader/LICENSE.composer
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the Software), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, andor sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
9
include/autoloader/autoload_classmap.php
Normal file
9
include/autoloader/autoload_classmap.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
||||
10
include/autoloader/autoload_files.php
Normal file
10
include/autoloader/autoload_files.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// autoload_files.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
|
||||
);
|
||||
10
include/autoloader/autoload_namespaces.php
Normal file
10
include/autoloader/autoload_namespaces.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
|
||||
);
|
||||
9
include/autoloader/autoload_psr4.php
Normal file
9
include/autoloader/autoload_psr4.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
||||
@@ -3,6 +3,7 @@ require_once("include/oembed.php");
|
||||
require_once('include/event.php');
|
||||
require_once('include/map.php');
|
||||
require_once('mod/proxy.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
function bb_PictureCacheExt($matches) {
|
||||
if (strpos($matches[3], "data:image/") === 0)
|
||||
@@ -541,8 +542,23 @@ function bb_ShareAttributes($share, $simplehtml) {
|
||||
$reldate = (($posted) ? " " . relative_date($posted) : '');
|
||||
}
|
||||
|
||||
$userid = GetProfileUsername($profile,$author, false);
|
||||
$userid_compact = GetProfileUsername($profile,$author, true);
|
||||
$data = get_contact_details_by_url($profile);
|
||||
|
||||
if (isset($data["name"]) AND isset($data["addr"]))
|
||||
$userid_compact = $data["name"]." (".$data["addr"].")";
|
||||
else
|
||||
$userid_compact = GetProfileUsername($profile,$author, true);
|
||||
|
||||
if (isset($data["addr"]))
|
||||
$userid = $data["addr"];
|
||||
else
|
||||
$userid = GetProfileUsername($profile,$author, false);
|
||||
|
||||
if (isset($data["name"]))
|
||||
$author = $data["name"];
|
||||
|
||||
if (isset($data["photo"]))
|
||||
$avatar = $data["photo"];
|
||||
|
||||
$preshare = trim($share[1]);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ if(! function_exists('load_config')) {
|
||||
function load_config($family) {
|
||||
global $a;
|
||||
|
||||
$r = q("SELECT * FROM `config` WHERE `cat` = '%s'", dbesc($family));
|
||||
$r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s'", dbesc($family));
|
||||
if(count($r)) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
@@ -170,7 +170,7 @@ function set_config($family,$key,$value) {
|
||||
if(! function_exists('load_pconfig')) {
|
||||
function load_pconfig($uid,$family) {
|
||||
global $a;
|
||||
$r = q("SELECT * FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d",
|
||||
$r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d",
|
||||
dbesc($family),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
@@ -811,16 +811,16 @@ function best_link_url($item,&$sparkle,$ssl_state = false) {
|
||||
if((local_user()) && (local_user() == $item['uid'])) {
|
||||
if(isset($a->contacts) && x($a->contacts,$clean_url)) {
|
||||
if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
|
||||
$best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
|
||||
$best_url = 'redir/'.$a->contacts[$clean_url]['id'];
|
||||
$sparkle = true;
|
||||
} else
|
||||
$best_url = $a->contacts[$clean_url]['url'];
|
||||
}
|
||||
} elseif (local_user()) {
|
||||
$r = q("SELECT `id`, `network` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s'",
|
||||
$r = q("SELECT `id` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s' LIMIT 1",
|
||||
dbesc(NETWORK_DFRN), intval(local_user()), dbesc(normalise_link($clean_url)));
|
||||
if ($r) {
|
||||
$best_url = $a->get_baseurl($ssl_state).'/redir/'.$r[0]['id'];
|
||||
$best_url = 'redir/'.$r[0]['id'];
|
||||
$sparkle = true;
|
||||
}
|
||||
}
|
||||
@@ -876,7 +876,7 @@ function item_photo_menu($item){
|
||||
if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
|
||||
$cid = $item['contact-id'];
|
||||
} else {
|
||||
$r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' ORDER BY `uid` DESC LIMIT 1",
|
||||
$r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
|
||||
intval(local_user()), dbesc(normalise_link($item['author-link'])));
|
||||
if ($r) {
|
||||
$cid = $r[0]["id"];
|
||||
|
||||
205
include/cron.php
205
include/cron.php
@@ -30,7 +30,6 @@ function cron_run(&$argv, &$argc){
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
@@ -133,9 +132,8 @@ function cron_run(&$argv, &$argc){
|
||||
// Check every conversation
|
||||
check_conversations(false);
|
||||
|
||||
// Follow your friends from your legacy OStatus account
|
||||
// Doesn't work
|
||||
// ostatus_check_follow_friends();
|
||||
// Set the gcontact-id in the item table if missing
|
||||
item_set_gcontact();
|
||||
|
||||
// update nodeinfo data
|
||||
nodeinfo_cron();
|
||||
@@ -159,75 +157,14 @@ function cron_run(&$argv, &$argc){
|
||||
proc_run('php','include/expire.php');
|
||||
}
|
||||
|
||||
$last = get_config('system','cache_last_cleared');
|
||||
// Clear cache entries
|
||||
cron_clear_cache($a);
|
||||
|
||||
if($last) {
|
||||
$next = $last + (3600); // Once per hour
|
||||
$clear_cache = ($next <= time());
|
||||
} else
|
||||
$clear_cache = true;
|
||||
// Repair missing Diaspora values in contacts
|
||||
cron_repair_diaspora($a);
|
||||
|
||||
if ($clear_cache) {
|
||||
// clear old cache
|
||||
Cache::clear();
|
||||
|
||||
// clear old item cache files
|
||||
clear_cache();
|
||||
|
||||
// clear cache for photos
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/photo");
|
||||
|
||||
// clear smarty cache
|
||||
clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled");
|
||||
|
||||
// clear cache for image proxy
|
||||
if (!get_config("system", "proxy_disabled")) {
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
|
||||
|
||||
$cachetime = get_config('system','proxy_cache_time');
|
||||
if (!$cachetime) $cachetime = PROXY_DEFAULT_TIME;
|
||||
|
||||
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
|
||||
}
|
||||
|
||||
// Maximum table size in megabyte
|
||||
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
|
||||
if ($max_tablesize == 0)
|
||||
$max_tablesize = 100 * 1000000; // Default are 100 MB
|
||||
|
||||
// Minimum fragmentation level in percent
|
||||
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
|
||||
if ($fragmentation_level == 0)
|
||||
$fragmentation_level = 0.3; // Default value is 30%
|
||||
|
||||
// Optimize some tables that need to be optimized
|
||||
$r = q("SHOW TABLE STATUS");
|
||||
foreach($r as $table) {
|
||||
|
||||
// Don't optimize tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize)
|
||||
continue;
|
||||
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / $table["Data_length"];
|
||||
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
|
||||
// Don't optimize tables that needn't to be optimized
|
||||
if ($fragmentation < $fragmentation_level)
|
||||
continue;
|
||||
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
}
|
||||
|
||||
set_config('system','cache_last_cleared', time());
|
||||
}
|
||||
// Repair entries in the database
|
||||
cron_repair_database();
|
||||
|
||||
$manual_id = 0;
|
||||
$generation = 0;
|
||||
@@ -373,6 +310,132 @@ function cron_run(&$argv, &$argc){
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear cache entries
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
function cron_clear_cache(&$a) {
|
||||
|
||||
$last = get_config('system','cache_last_cleared');
|
||||
|
||||
if($last) {
|
||||
$next = $last + (3600); // Once per hour
|
||||
$clear_cache = ($next <= time());
|
||||
} else
|
||||
$clear_cache = true;
|
||||
|
||||
if (!$clear_cache)
|
||||
return;
|
||||
|
||||
// clear old cache
|
||||
Cache::clear();
|
||||
|
||||
// clear old item cache files
|
||||
clear_cache();
|
||||
|
||||
// clear cache for photos
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/photo");
|
||||
|
||||
// clear smarty cache
|
||||
clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled");
|
||||
|
||||
// clear cache for image proxy
|
||||
if (!get_config("system", "proxy_disabled")) {
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
|
||||
|
||||
$cachetime = get_config('system','proxy_cache_time');
|
||||
if (!$cachetime) $cachetime = PROXY_DEFAULT_TIME;
|
||||
|
||||
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
|
||||
}
|
||||
|
||||
// Delete the cached OEmbed entries that are older than one year
|
||||
q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 1 YEAR");
|
||||
|
||||
// Delete the cached "parse_url" entries that are older than one year
|
||||
q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 1 YEAR");
|
||||
|
||||
// Maximum table size in megabyte
|
||||
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
|
||||
if ($max_tablesize == 0)
|
||||
$max_tablesize = 100 * 1000000; // Default are 100 MB
|
||||
|
||||
// Minimum fragmentation level in percent
|
||||
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
|
||||
if ($fragmentation_level == 0)
|
||||
$fragmentation_level = 0.3; // Default value is 30%
|
||||
|
||||
// Optimize some tables that need to be optimized
|
||||
$r = q("SHOW TABLE STATUS");
|
||||
foreach($r as $table) {
|
||||
|
||||
// Don't optimize tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize)
|
||||
continue;
|
||||
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / $table["Data_length"];
|
||||
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
|
||||
// Don't optimize tables that needn't to be optimized
|
||||
if ($fragmentation < $fragmentation_level)
|
||||
continue;
|
||||
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
}
|
||||
|
||||
set_config('system','cache_last_cleared', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Repair missing values in Diaspora contacts
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
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) {
|
||||
foreach ($r AS $contact) {
|
||||
if (poco_reachable($contact["url"])) {
|
||||
$data = probe_url($contact["url"]);
|
||||
if ($data["network"] == NETWORK_DIASPORA) {
|
||||
logger("Repair contact ".$contact["id"]." ".$contact["url"], LOGGER_DEBUG);
|
||||
q("UPDATE `contact` SET `batch` = '%s', `notify` = '%s', `poll` = '%s', pubkey = '%s' WHERE `id` = %d",
|
||||
dbesc($data["batch"]), dbesc($data["notify"]), dbesc($data["poll"]), dbesc($data["pubkey"]),
|
||||
intval($contact["id"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Do some repairs in database entries
|
||||
*
|
||||
*/
|
||||
function cron_repair_database() {
|
||||
|
||||
// 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");
|
||||
|
||||
/// @todo
|
||||
/// - remove thread entries without item
|
||||
/// - remove sign entries without item
|
||||
/// - remove children when parent got lost
|
||||
/// - set contact-id in item when not present
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
cron_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/datetime.php
|
||||
* @brief Some functions for date and time related tasks.
|
||||
*/
|
||||
|
||||
// two-level sort for timezones.
|
||||
|
||||
if(! function_exists('timezone_cmp')) {
|
||||
/**
|
||||
* @brief Two-level sort for timezones.
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return int
|
||||
*/
|
||||
function timezone_cmp($a, $b) {
|
||||
if(strstr($a,'/') && strstr($b,'/')) {
|
||||
if ( t($a) == t($b)) return 0;
|
||||
@@ -11,11 +20,16 @@ function timezone_cmp($a, $b) {
|
||||
if(strstr($a,'/')) return -1;
|
||||
if(strstr($b,'/')) return 1;
|
||||
if ( t($a) == t($b)) return 0;
|
||||
return ( t($a) < t($b)) ? -1 : 1;
|
||||
}}
|
||||
|
||||
// emit a timezone selector grouped (primarily) by continent
|
||||
if(! function_exists('select_timezone')) {
|
||||
return ( t($a) < t($b)) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Emit a timezone selector grouped (primarily) by continent
|
||||
*
|
||||
* @param string $current Timezone
|
||||
* @return string Parsed HTML output
|
||||
*/
|
||||
function select_timezone($current = 'America/Los_Angeles') {
|
||||
|
||||
$timezone_identifiers = DateTimeZone::listIdentifiers();
|
||||
@@ -52,13 +66,25 @@ function select_timezone($current = 'America/Los_Angeles') {
|
||||
}
|
||||
$o .= '</optgroup></select>';
|
||||
return $o;
|
||||
}}
|
||||
}
|
||||
|
||||
// return a select using 'field_select_raw' template, with timezones
|
||||
// groupped (primarily) by continent
|
||||
// arguments follow convetion as other field_* template array:
|
||||
// 'name', 'label', $value, 'help'
|
||||
if (!function_exists('field_timezone')){
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generating a Timezone selector
|
||||
*
|
||||
* Return a select using 'field_select_raw' template, with timezones
|
||||
* groupped (primarily) by continent
|
||||
* arguments follow convetion as other field_* template array:
|
||||
* 'name', 'label', $value, 'help'
|
||||
*
|
||||
* @param string $name Name of the selector
|
||||
* @param string $label Label for the selector
|
||||
* @param string $current Timezone
|
||||
* @param string $help Help text
|
||||
*
|
||||
* @return string Parsed HTML
|
||||
*/
|
||||
function field_timezone($name='timezone', $label='', $current = 'America/Los_Angeles', $help){
|
||||
$options = select_timezone($current);
|
||||
$options = str_replace('<select id="timezone_select" name="timezone">','', $options);
|
||||
@@ -69,15 +95,19 @@ function field_timezone($name='timezone', $label='', $current = 'America/Los_Ang
|
||||
'$field' => array($name, $label, $current, $help, $options),
|
||||
));
|
||||
|
||||
}}
|
||||
}
|
||||
|
||||
// General purpose date parse/convert function.
|
||||
// $from = source timezone
|
||||
// $to = dest timezone
|
||||
// $s = some parseable date/time string
|
||||
// $fmt = output format
|
||||
|
||||
if(! function_exists('datetime_convert')) {
|
||||
/**
|
||||
* @brief General purpose date parse/convert function.
|
||||
*
|
||||
* @param string $from Source timezone
|
||||
* @param string $to Dest timezone
|
||||
* @param string $s Some parseable date/time string
|
||||
* @param string $fmt Output format recognised from php's DateTime class
|
||||
* http://www.php.net/manual/en/datetime.format.php
|
||||
*
|
||||
* @return string Formatted date according to given format
|
||||
*/
|
||||
function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") {
|
||||
|
||||
// Defaults to UTC if nothing is set, but throws an exception if set to empty string.
|
||||
@@ -123,14 +153,20 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
|
||||
}
|
||||
|
||||
$d->setTimeZone($to_obj);
|
||||
|
||||
return($d->format($fmt));
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
// wrapper for date selector, tailored for use in birthday fields
|
||||
|
||||
/**
|
||||
* @brief Wrapper for date selector, tailored for use in birthday fields.
|
||||
*
|
||||
* @param string $dob Date of Birth
|
||||
* @return string
|
||||
*/
|
||||
function dob($dob) {
|
||||
list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d');
|
||||
|
||||
$f = get_config('system','birthday_input_format');
|
||||
if(! $f)
|
||||
$f = 'ymd';
|
||||
@@ -138,62 +174,69 @@ function dob($dob) {
|
||||
$value = '';
|
||||
else
|
||||
$value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d'));
|
||||
|
||||
$o = '<input type="text" name="dob" value="' . $value . '" placeholder="' . t('YYYY-MM-DD or MM-DD') . '" />';
|
||||
|
||||
// if ($dob && $dob != '0000-00-00')
|
||||
// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob');
|
||||
// else
|
||||
// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),false,'dob');
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a date selector
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $min
|
||||
* unix timestamp of minimum date
|
||||
* @param $max
|
||||
* unix timestap of maximum date
|
||||
* @param $default
|
||||
* unix timestamp of default date
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "datetimepicker")
|
||||
* @brief Returns a date selector
|
||||
*
|
||||
* @param string $format
|
||||
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param string $min
|
||||
* Unix timestamp of minimum date
|
||||
* @param string $max
|
||||
* Unix timestap of maximum date
|
||||
* @param string $default
|
||||
* Unix timestamp of default date
|
||||
* @param string $id
|
||||
* ID and name of datetimepicker (defaults to "datetimepicker")
|
||||
*
|
||||
* @return string Parsed HTML output.
|
||||
*/
|
||||
if(! function_exists('datesel')) {
|
||||
function datesel($format, $min, $max, $default, $id = 'datepicker') {
|
||||
return datetimesel($format,$min,$max,$default,$id,true,false, '','');
|
||||
}}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a time selector
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @brief Returns a time selector
|
||||
*
|
||||
* @param string $format
|
||||
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $h
|
||||
* already selected hour
|
||||
* Already selected hour
|
||||
* @param $m
|
||||
* already selected minute
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "timepicker")
|
||||
* Already selected minute
|
||||
* @param string $id
|
||||
* ID and name of datetimepicker (defaults to "timepicker")
|
||||
*
|
||||
* @return string Parsed HTML output.
|
||||
*/
|
||||
if(! function_exists('timesel')) {
|
||||
function timesel($format, $h, $m, $id='timepicker') {
|
||||
return datetimesel($format,new DateTime(),new DateTime(),new DateTime("$h:$m"),$id,false,true);
|
||||
}}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a datetime selector.
|
||||
*
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $min
|
||||
* @param string $min
|
||||
* unix timestamp of minimum date
|
||||
* @param $max
|
||||
* @param string $max
|
||||
* unix timestap of maximum date
|
||||
* @param $default
|
||||
* @param string $default
|
||||
* unix timestamp of default date
|
||||
* @param string $id
|
||||
* id and name of datetimepicker (defaults to "datetimepicker")
|
||||
* @param boolean $pickdate
|
||||
* @param bool $pickdate
|
||||
* true to show date picker (default)
|
||||
* @param boolean $picktime
|
||||
* true to show time picker (default)
|
||||
@@ -201,17 +244,15 @@ function timesel($format, $h, $m, $id='timepicker') {
|
||||
* set minimum date from picker with id $minfrom (none by default)
|
||||
* @param $maxfrom
|
||||
* set maximum date from picker with id $maxfrom (none by default)
|
||||
* @param boolean $required default false
|
||||
* @param bool $required default false
|
||||
*
|
||||
* @return string Parsed HTML output.
|
||||
*
|
||||
* @todo Once browser support is better this could probably be replaced with
|
||||
* native HTML5 date picker.
|
||||
*/
|
||||
if(! function_exists('datetimesel')) {
|
||||
function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '', $required = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
// First day of the week (0 = Sunday)
|
||||
$firstDay = get_pconfig(local_user(),'system','first_day_of_week');
|
||||
if ($firstDay === false) $firstDay=0;
|
||||
@@ -224,43 +265,58 @@ function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pic
|
||||
|
||||
$o = '';
|
||||
$dateformat = '';
|
||||
|
||||
if($pickdate) $dateformat .= 'Y-m-d';
|
||||
if($pickdate && $picktime) $dateformat .= ' ';
|
||||
if($picktime) $dateformat .= 'H:i';
|
||||
|
||||
$minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : '';
|
||||
$maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : '';
|
||||
|
||||
$input_text = $default ? 'value="' . date($dateformat, $default->getTimestamp()) . '"' : '';
|
||||
$defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : '';
|
||||
|
||||
$pickers = '';
|
||||
if(!$pickdate) $pickers .= ',datepicker: false';
|
||||
if(!$picktime) $pickers .= ',timepicker: false';
|
||||
|
||||
$extra_js = '';
|
||||
$pickers .= ",dayOfWeekStart: ".$firstDay.",lang:'".$lang."'";
|
||||
if($minfrom != '')
|
||||
$extra_js .= "\$('#$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})";
|
||||
if($maxfrom != '')
|
||||
$extra_js .= "\$('#$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})";
|
||||
|
||||
$readable_format = $dateformat;
|
||||
$readable_format = str_replace('Y','yyyy',$readable_format);
|
||||
$readable_format = str_replace('m','mm',$readable_format);
|
||||
$readable_format = str_replace('d','dd',$readable_format);
|
||||
$readable_format = str_replace('H','HH',$readable_format);
|
||||
$readable_format = str_replace('i','MM',$readable_format);
|
||||
|
||||
$o .= "<div class='date'><input type='text' placeholder='$readable_format' name='$id' id='$id' $input_text />";
|
||||
$o .= '</div>';
|
||||
$o .= "<script type='text/javascript'>";
|
||||
$o .= "\$(function () {var picker = \$('#$id').datetimepicker({step:5,format:'$dateformat' $minjs $maxjs $pickers $defaultdatejs}); $extra_js})";
|
||||
$o .= "</script>";
|
||||
|
||||
return $o;
|
||||
}}
|
||||
}
|
||||
|
||||
// implements "3 seconds ago" etc.
|
||||
// based on $posted_date, (UTC).
|
||||
// Results relative to current timezone
|
||||
// Limited to range of timestamps
|
||||
|
||||
if(! function_exists('relative_date')) {
|
||||
/**
|
||||
* @brief Returns a relative date string.
|
||||
*
|
||||
* Implements "3 seconds ago" etc.
|
||||
* Based on $posted_date, (UTC).
|
||||
* Results relative to current timezone.
|
||||
* Limited to range of timestamps.
|
||||
*
|
||||
* @param string $posted_date
|
||||
* @param string $format (optional) Parsed with sprintf()
|
||||
* <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
|
||||
*
|
||||
* @return string with relative date
|
||||
*/
|
||||
function relative_date($posted_date,$format = null) {
|
||||
|
||||
$localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
|
||||
@@ -300,23 +356,33 @@ function relative_date($posted_date,$format = null) {
|
||||
// translators - e.g. 22 hours ago, 1 minute ago
|
||||
if(! $format)
|
||||
$format = t('%1$d %2$s ago');
|
||||
|
||||
return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1]));
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
|
||||
// Returns age in years, given a date of birth,
|
||||
// the timezone of the person whose date of birth is provided,
|
||||
// and the timezone of the person viewing the result.
|
||||
// Why? Bear with me. Let's say I live in Mittagong, Australia, and my
|
||||
// birthday is on New Year's. You live in San Bruno, California.
|
||||
// When exactly are you going to see my age increase?
|
||||
// A: 5:00 AM Dec 31 San Bruno time. That's precisely when I start
|
||||
// celebrating and become a year older. If you wish me happy birthday
|
||||
// on January 1 (San Bruno time), you'll be a day late.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns timezone correct age in years.
|
||||
*
|
||||
* Returns the age in years, given a date of birth, the timezone of the person
|
||||
* whose date of birth is provided, and the timezone of the person viewing the
|
||||
* result.
|
||||
*
|
||||
* Why? Bear with me. Let's say I live in Mittagong, Australia, and my birthday
|
||||
* is on New Year's. You live in San Bruno, California.
|
||||
* When exactly are you going to see my age increase?
|
||||
*
|
||||
* A: 5:00 AM Dec 31 San Bruno time. That's precisely when I start celebrating
|
||||
* and become a year older. If you wish me happy birthday on January 1
|
||||
* (San Bruno time), you'll be a day late.
|
||||
*
|
||||
* @param string $dob Date of Birth
|
||||
* @param string $owner_tz (optional) Timezone of the person of interest
|
||||
* @param string $viewer_tz (optional) Timezone of the person viewing
|
||||
*
|
||||
* @return int Age in years
|
||||
*/
|
||||
function age($dob,$owner_tz = '',$viewer_tz = '') {
|
||||
if(! intval($dob))
|
||||
return 0;
|
||||
@@ -333,64 +399,79 @@ function age($dob,$owner_tz = '',$viewer_tz = '') {
|
||||
|
||||
if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day)))
|
||||
$year_diff--;
|
||||
|
||||
return $year_diff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get days in month
|
||||
// get_dim($year, $month);
|
||||
// returns number of days.
|
||||
// $month[1] = 'January';
|
||||
// to match human usage.
|
||||
|
||||
if(! function_exists('get_dim')) {
|
||||
/**
|
||||
* @brief Get days of a month in a given year.
|
||||
*
|
||||
* Returns number of days in the month of the given year.
|
||||
* $m = 1 is 'January' to match human usage.
|
||||
*
|
||||
* @param int $y Year
|
||||
* @param int $m Month (1=January, 12=December)
|
||||
*
|
||||
* @return int Number of days in the given month
|
||||
*/
|
||||
function get_dim($y,$m) {
|
||||
|
||||
$dim = array( 0,
|
||||
31, 28, 31, 30, 31, 30,
|
||||
31, 31, 30, 31, 30, 31);
|
||||
|
||||
if($m != 2)
|
||||
return $dim[$m];
|
||||
if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0))
|
||||
return 29;
|
||||
return $dim[2];
|
||||
}}
|
||||
$dim = array( 0,
|
||||
31, 28, 31, 30, 31, 30,
|
||||
31, 31, 30, 31, 30, 31);
|
||||
|
||||
if($m != 2)
|
||||
return $dim[$m];
|
||||
|
||||
// Returns the first day in month for a given month, year
|
||||
// get_first_dim($year,$month)
|
||||
// returns 0 = Sunday through 6 = Saturday
|
||||
// Months start at 1.
|
||||
if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0))
|
||||
return 29;
|
||||
|
||||
if(! function_exists('get_first_dim')) {
|
||||
return $dim[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the first day in month for a given month, year.
|
||||
*
|
||||
* Months start at 1.
|
||||
*
|
||||
* @param int $y Year
|
||||
* @param int $m Month (1=January, 12=December)
|
||||
*
|
||||
* @return string day 0 = Sunday through 6 = Saturday
|
||||
*/
|
||||
function get_first_dim($y,$m) {
|
||||
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
|
||||
return datetime_convert('UTC','UTC',$d,'w');
|
||||
}}
|
||||
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
|
||||
|
||||
// output a calendar for the given month, year.
|
||||
// if $links are provided (array), e.g. $links[12] => 'http://mylink' ,
|
||||
// date 12 will be linked appropriately. Today's date is also noted by
|
||||
// altering td class.
|
||||
// Months count from 1.
|
||||
return datetime_convert('UTC','UTC',$d,'w');
|
||||
}
|
||||
|
||||
|
||||
/// @TODO Provide (prev,next) links, define class variations for different size calendars
|
||||
|
||||
|
||||
if(! function_exists('cal')) {
|
||||
/**
|
||||
* @brief Output a calendar for the given month, year.
|
||||
*
|
||||
* If $links are provided (array), e.g. $links[12] => 'http://mylink' ,
|
||||
* date 12 will be linked appropriately. Today's date is also noted by
|
||||
* altering td class.
|
||||
* Months count from 1.
|
||||
*
|
||||
* @param int $y Year
|
||||
* @param int $m Month
|
||||
* @param bool $links (default false)
|
||||
* @param string $class
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @todo Provide (prev,next) links, define class variations for different size calendars
|
||||
*/
|
||||
function cal($y = 0,$m = 0, $links = false, $class='') {
|
||||
|
||||
|
||||
// month table - start at 1 to match human usage.
|
||||
|
||||
$mtab = array(' ',
|
||||
'January','February','March',
|
||||
'April','May','June',
|
||||
'July','August','September',
|
||||
'October','November','December'
|
||||
'January','February','March',
|
||||
'April','May','June',
|
||||
'July','August','September',
|
||||
'October','November','December'
|
||||
);
|
||||
|
||||
$thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
|
||||
@@ -400,54 +481,63 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
|
||||
if(! $m)
|
||||
$m = intval($thismonth);
|
||||
|
||||
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
|
||||
$f = get_first_dim($y,$m);
|
||||
$l = get_dim($y,$m);
|
||||
$d = 1;
|
||||
$dow = 0;
|
||||
$started = false;
|
||||
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
|
||||
$f = get_first_dim($y,$m);
|
||||
$l = get_dim($y,$m);
|
||||
$d = 1;
|
||||
$dow = 0;
|
||||
$started = false;
|
||||
|
||||
if(($y == $thisyear) && ($m == $thismonth))
|
||||
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
|
||||
if(($y == $thisyear) && ($m == $thismonth))
|
||||
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
|
||||
|
||||
$str_month = day_translate($mtab[$m]);
|
||||
$o = '<table class="calendar' . $class . '">';
|
||||
$o .= "<caption>$str_month $y</caption><tr>";
|
||||
for($a = 0; $a < 7; $a ++)
|
||||
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
|
||||
$o .= '</tr><tr>';
|
||||
$o = '<table class="calendar' . $class . '">';
|
||||
$o .= "<caption>$str_month $y</caption><tr>";
|
||||
for($a = 0; $a < 7; $a ++)
|
||||
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
|
||||
|
||||
while($d <= $l) {
|
||||
if(($dow == $f) && (! $started))
|
||||
$started = true;
|
||||
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
|
||||
$o .= "<td $today>";
|
||||
$day = str_replace(' ',' ',sprintf('%2.2d', $d));
|
||||
if($started) {
|
||||
if(is_array($links) && isset($links[$d]))
|
||||
$o .= "<a href=\"{$links[$d]}\">$day</a>";
|
||||
else
|
||||
$o .= $day;
|
||||
$d ++;
|
||||
}
|
||||
else
|
||||
$o .= ' ';
|
||||
$o .= '</td>';
|
||||
$dow ++;
|
||||
if(($dow == 7) && ($d <= $l)) {
|
||||
$dow = 0;
|
||||
$o .= '</tr><tr>';
|
||||
}
|
||||
}
|
||||
if($dow)
|
||||
for($a = $dow; $a < 7; $a ++)
|
||||
$o .= '<td> </td>';
|
||||
$o .= '</tr></table>'."\r\n";
|
||||
$o .= '</tr><tr>';
|
||||
|
||||
return $o;
|
||||
}}
|
||||
while($d <= $l) {
|
||||
if(($dow == $f) && (! $started))
|
||||
$started = true;
|
||||
|
||||
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
|
||||
$o .= "<td $today>";
|
||||
$day = str_replace(' ',' ',sprintf('%2.2d', $d));
|
||||
if($started) {
|
||||
if(is_array($links) && isset($links[$d]))
|
||||
$o .= "<a href=\"{$links[$d]}\">$day</a>";
|
||||
else
|
||||
$o .= $day;
|
||||
|
||||
$d ++;
|
||||
} else {
|
||||
$o .= ' ';
|
||||
}
|
||||
|
||||
$o .= '</td>';
|
||||
$dow ++;
|
||||
if(($dow == 7) && ($d <= $l)) {
|
||||
$dow = 0;
|
||||
$o .= '</tr><tr>';
|
||||
}
|
||||
}
|
||||
if($dow)
|
||||
for($a = $dow; $a < 7; $a ++)
|
||||
$o .= '<td> </td>';
|
||||
|
||||
$o .= '</tr></table>'."\r\n";
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a birthday event.
|
||||
*
|
||||
* Update the year and the birthday.
|
||||
*/
|
||||
function update_contact_birthdays() {
|
||||
|
||||
// This only handles foreign or alien networks where a birthday has been provided.
|
||||
@@ -474,8 +564,6 @@ function update_contact_birthdays() {
|
||||
$bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
|
||||
$bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
|
||||
|
||||
|
||||
|
||||
$r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ",
|
||||
intval($rr['uid']),
|
||||
|
||||
@@ -453,6 +453,7 @@ function db_definition() {
|
||||
"keywords" => array("type" => "text", "not null" => "1"),
|
||||
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
|
||||
"attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"photo" => array("type" => "text", "not null" => "1"),
|
||||
"thumb" => array("type" => "text", "not null" => "1"),
|
||||
"micro" => array("type" => "text", "not null" => "1"),
|
||||
@@ -666,9 +667,14 @@ function db_definition() {
|
||||
"about" => array("type" => "text", "not null" => "1"),
|
||||
"keywords" => array("type" => "text", "not null" => "1"),
|
||||
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
|
||||
"birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
|
||||
"community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"notify" => array("type" => "text", "not null" => "1"),
|
||||
"alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
|
||||
"server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
),
|
||||
@@ -742,21 +748,6 @@ function db_definition() {
|
||||
"nurl" => array("nurl"),
|
||||
)
|
||||
);
|
||||
$database["guid"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"guid" => array("guid"),
|
||||
"plink" => array("plink"),
|
||||
"uri" => array("uri"),
|
||||
)
|
||||
);
|
||||
$database["hook"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
@@ -795,6 +786,7 @@ function db_definition() {
|
||||
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
|
||||
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
|
||||
"type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
@@ -871,6 +863,7 @@ function db_definition() {
|
||||
"uid_thrparent" => array("uid","thr-parent"),
|
||||
"uid_parenturi" => array("uid","parent-uri"),
|
||||
"uid_contactid_created" => array("uid","contact-id","created"),
|
||||
"gcontactid_uid_created" => array("gcontact-id","uid","created"),
|
||||
"wall_body" => array("wall","body(6)"),
|
||||
"uid_visible_moderated_created" => array("uid","visible","moderated","created"),
|
||||
"uid_uri" => array("uid","uri"),
|
||||
@@ -1014,6 +1007,30 @@ function db_definition() {
|
||||
"receiver-uid" => array("receiver-uid"),
|
||||
)
|
||||
);
|
||||
$database["oembed"] = array(
|
||||
"fields" => array(
|
||||
"url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
|
||||
"content" => array("type" => "text", "not null" => "1"),
|
||||
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("url"),
|
||||
"created" => array("created"),
|
||||
)
|
||||
);
|
||||
$database["parsed_url"] = array(
|
||||
"fields" => array(
|
||||
"url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
|
||||
"guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
|
||||
"oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
|
||||
"content" => array("type" => "text", "not null" => "1"),
|
||||
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("url", "guessing", "oembed"),
|
||||
"created" => array("created"),
|
||||
)
|
||||
);
|
||||
$database["pconfig"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
@@ -1287,6 +1304,7 @@ function db_definition() {
|
||||
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
|
||||
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
"contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
|
||||
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
|
||||
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
|
||||
"edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
|
||||
"commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
|
||||
@@ -1316,6 +1334,8 @@ function db_definition() {
|
||||
"uid_network_created" => array("uid","network","created"),
|
||||
"uid_contactid_commented" => array("uid","contact-id","commented"),
|
||||
"uid_contactid_created" => array("uid","contact-id","created"),
|
||||
"uid_gcontactid_commented" => array("uid","gcontact-id","commented"),
|
||||
"uid_gcontactid_created" => array("uid","gcontact-id","created"),
|
||||
"wall_private_received" => array("wall","private","received"),
|
||||
"uid_created" => array("uid","created"),
|
||||
"uid_commented" => array("uid","commented"),
|
||||
@@ -1334,21 +1354,6 @@ function db_definition() {
|
||||
"PRIMARY" => array("id"),
|
||||
)
|
||||
);
|
||||
$database["unique_contacts"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"about" => array("type" => "text", "not null" => "1"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"url" => array("url"),
|
||||
)
|
||||
);
|
||||
$database["user"] = array(
|
||||
"fields" => array(
|
||||
"uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
|
||||
@@ -5,6 +5,7 @@ require_once('include/html2plain.php');
|
||||
require_once("include/Scrape.php");
|
||||
require_once('include/diaspora.php');
|
||||
require_once("include/ostatus.php");
|
||||
require_once("include/dfrn.php");
|
||||
|
||||
function delivery_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
@@ -264,8 +265,6 @@ function delivery_run(&$argv, &$argc){
|
||||
if(count($r))
|
||||
$contact = $r[0];
|
||||
|
||||
$hubxml = feed_hublinks();
|
||||
|
||||
if($contact['self'])
|
||||
continue;
|
||||
|
||||
@@ -278,138 +277,54 @@ function delivery_run(&$argv, &$argc){
|
||||
case NETWORK_DFRN:
|
||||
logger('notifier: '.$target_item["guid"].' dfrndelivery: ' . $contact['name']);
|
||||
|
||||
$feed_template = get_markup_template('atom_feed.tpl');
|
||||
$mail_template = get_markup_template('atom_mail.tpl');
|
||||
|
||||
$atom = '';
|
||||
|
||||
|
||||
$birthday = feed_birthday($owner['uid'],$owner['timezone']);
|
||||
|
||||
if(strlen($birthday))
|
||||
$birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>';
|
||||
|
||||
$atom .= replace_macros($feed_template, array(
|
||||
'$version' => xmlify(FRIENDICA_VERSION),
|
||||
'$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
|
||||
'$feed_title' => xmlify($owner['name']),
|
||||
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
|
||||
'$hub' => $hubxml,
|
||||
'$salmon' => '', // private feed, we don't use salmon here
|
||||
'$name' => xmlify($owner['name']),
|
||||
'$profile_page' => xmlify($owner['url']),
|
||||
'$photo' => xmlify($owner['photo']),
|
||||
'$thumb' => xmlify($owner['thumb']),
|
||||
'$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
|
||||
'$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
|
||||
'$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) ,
|
||||
'$birthday' => $birthday,
|
||||
'$community' => (($owner['page-flags'] == PAGE_COMMUNITY) ? '<dfrn:community>1</dfrn:community>' : '')
|
||||
));
|
||||
|
||||
if($mail) {
|
||||
$public_message = false; // mail is not public
|
||||
|
||||
$body = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
|
||||
|
||||
$atom .= replace_macros($mail_template, array(
|
||||
'$name' => xmlify($owner['name']),
|
||||
'$profile_page' => xmlify($owner['url']),
|
||||
'$thumb' => xmlify($owner['thumb']),
|
||||
'$item_id' => xmlify($item['uri']),
|
||||
'$subject' => xmlify($item['title']),
|
||||
'$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
|
||||
'$content' => xmlify($body),
|
||||
'$parent_id' => xmlify($item['parent-uri'])
|
||||
));
|
||||
} elseif($fsuggest) {
|
||||
$public_message = false; // suggestions are not public
|
||||
|
||||
$sugg_template = get_markup_template('atom_suggest.tpl');
|
||||
|
||||
$atom .= replace_macros($sugg_template, array(
|
||||
'$name' => xmlify($item['name']),
|
||||
'$url' => xmlify($item['url']),
|
||||
'$photo' => xmlify($item['photo']),
|
||||
'$request' => xmlify($item['request']),
|
||||
'$note' => xmlify($item['note'])
|
||||
));
|
||||
|
||||
// We don't need this any more
|
||||
|
||||
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1",
|
||||
intval($item['id'])
|
||||
);
|
||||
} elseif($relocate) {
|
||||
$public_message = false; // suggestions are not public
|
||||
|
||||
$sugg_template = get_markup_template('atom_relocate.tpl');
|
||||
|
||||
/* get site pubkey. this could be a new installation with no site keys*/
|
||||
$pubkey = get_config('system','site_pubkey');
|
||||
if(! $pubkey) {
|
||||
$res = new_keypair(1024);
|
||||
set_config('system','site_prvkey', $res['prvkey']);
|
||||
set_config('system','site_pubkey', $res['pubkey']);
|
||||
}
|
||||
|
||||
$rp = q("SELECT `resource-id` , `scale`, type FROM `photo`
|
||||
WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
|
||||
$photos = array();
|
||||
$ext = Photo::supportedTypes();
|
||||
foreach($rp as $p){
|
||||
$photos[$p['scale']] = $a->get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
|
||||
}
|
||||
unset($rp, $ext);
|
||||
|
||||
$atom .= replace_macros($sugg_template, array(
|
||||
'$name' => xmlify($owner['name']),
|
||||
'$photo' => xmlify($photos[4]),
|
||||
'$thumb' => xmlify($photos[5]),
|
||||
'$micro' => xmlify($photos[6]),
|
||||
'$url' => xmlify($owner['url']),
|
||||
'$request' => xmlify($owner['request']),
|
||||
'$confirm' => xmlify($owner['confirm']),
|
||||
'$notify' => xmlify($owner['notify']),
|
||||
'$poll' => xmlify($owner['poll']),
|
||||
'$sitepubkey' => xmlify(get_config('system','site_pubkey')),
|
||||
//'$pubkey' => xmlify($owner['pubkey']),
|
||||
//'$prvkey' => xmlify($owner['prvkey']),
|
||||
));
|
||||
unset($photos);
|
||||
} elseif($followup) {
|
||||
if ($mail) {
|
||||
$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
|
||||
$atom = dfrn::mail($item, $owner);
|
||||
} elseif ($fsuggest) {
|
||||
$atom = dfrn::fsuggest($item, $owner);
|
||||
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
|
||||
} elseif ($relocate)
|
||||
$atom = dfrn::relocate($owner, $uid);
|
||||
elseif($followup) {
|
||||
$msgitems = array();
|
||||
foreach($items as $item) { // there is only one item
|
||||
if(! $item['parent'])
|
||||
if(!$item['parent'])
|
||||
continue;
|
||||
if($item['id'] == $item_id) {
|
||||
logger('followup: item: ' . print_r($item,true), LOGGER_DATA);
|
||||
$atom .= atom_entry($item,'text',null,$owner,false);
|
||||
$msgitems[] = $item;
|
||||
}
|
||||
}
|
||||
$atom = dfrn::entries($msgitems,$owner);
|
||||
} else {
|
||||
$msgitems = array();
|
||||
foreach($items as $item) {
|
||||
if(! $item['parent'])
|
||||
if(!$item['parent'])
|
||||
continue;
|
||||
|
||||
// private emails may be in included in public conversations. Filter them.
|
||||
if(($public_message) && $item['private'] == 1)
|
||||
if(($public_message) && $item['private'])
|
||||
continue;
|
||||
|
||||
$item_contact = get_item_contact($item,$icontacts);
|
||||
if(! $item_contact)
|
||||
if(!$item_contact)
|
||||
continue;
|
||||
|
||||
if($normal_mode) {
|
||||
if($item_id == $item['id'] || $item['id'] == $item['parent'])
|
||||
$atom .= atom_entry($item,'text',null,$owner,true,(($top_level) ? $contact['id'] : 0));
|
||||
} else
|
||||
$atom .= atom_entry($item,'text',null,$owner,true);
|
||||
if($item_id == $item['id'] || $item['id'] == $item['parent']) {
|
||||
$item["entry:comment-allow"] = true;
|
||||
$item["entry:cid"] = (($top_level) ? $contact['id'] : 0);
|
||||
$msgitems[] = $item;
|
||||
}
|
||||
} else {
|
||||
$item["entry:comment-allow"] = true;
|
||||
$msgitems[] = $item;
|
||||
}
|
||||
}
|
||||
$atom = dfrn::entries($msgitems,$owner);
|
||||
}
|
||||
|
||||
$atom .= '</feed>' . "\r\n";
|
||||
|
||||
logger('notifier: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
|
||||
logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
|
||||
|
||||
logger('notifier: ' . $atom, LOGGER_DATA);
|
||||
$basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
|
||||
@@ -458,15 +373,14 @@ function delivery_run(&$argv, &$argc){
|
||||
if (($x[0]['page-flags'] == PAGE_SOAPBOX) AND $top_level)
|
||||
break;
|
||||
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
logger('mod-delivery: local delivery');
|
||||
local_delivery($x[0],$atom);
|
||||
dfrn::import($atom, $x[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(! was_recently_delayed($contact['id']))
|
||||
$deliver_status = dfrn_deliver($owner,$contact,$atom);
|
||||
$deliver_status = dfrn::deliver($owner,$contact,$atom);
|
||||
else
|
||||
$deliver_status = (-1);
|
||||
|
||||
|
||||
2422
include/dfrn.php
Normal file
2422
include/dfrn.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ require_once('include/queue_fn.php');
|
||||
require_once('include/lock.php');
|
||||
require_once('include/threads.php');
|
||||
require_once('mod/share.php');
|
||||
require_once('include/enotify.php');
|
||||
|
||||
function diaspora_dispatch_public($msg) {
|
||||
|
||||
@@ -728,7 +729,7 @@ function diaspora_request($importer,$xml) {
|
||||
|
||||
require_once('include/Photo.php');
|
||||
|
||||
$photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']);
|
||||
update_contact_avatar($contact_record['photo'],$importer['uid'],$contact_record['id']);
|
||||
|
||||
// technically they are sharing with us (CONTACT_IS_SHARING),
|
||||
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
|
||||
@@ -739,26 +740,17 @@ function diaspora_request($importer,$xml) {
|
||||
else
|
||||
$new_relation = CONTACT_IS_FOLLOWER;
|
||||
|
||||
$r = q("UPDATE `contact` SET
|
||||
`photo` = '%s',
|
||||
`thumb` = '%s',
|
||||
`micro` = '%s',
|
||||
`rel` = %d,
|
||||
$r = q("UPDATE `contact` SET `rel` = %d,
|
||||
`name-date` = '%s',
|
||||
`uri-date` = '%s',
|
||||
`avatar-date` = '%s',
|
||||
`blocked` = 0,
|
||||
`pending` = 0,
|
||||
`writable` = 1
|
||||
WHERE `id` = %d
|
||||
",
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
intval($new_relation),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact_record['id'])
|
||||
);
|
||||
|
||||
@@ -826,6 +818,23 @@ function diaspora_plink($addr, $guid) {
|
||||
return 'https://'.substr($addr,strpos($addr,'@')+1).'/posts/'.$guid;
|
||||
}
|
||||
|
||||
function diaspora_repair_signature($signature, $handle = "", $level = 1) {
|
||||
|
||||
if ($signature == "")
|
||||
return($signature);
|
||||
|
||||
if (base64_encode(base64_decode(base64_decode($signature))) == base64_decode($signature)) {
|
||||
$signature = base64_decode($signature);
|
||||
logger("Repaired double encoded signature from Diaspora/Hubzilla handle ".$handle." - level ".$level, LOGGER_DEBUG);
|
||||
|
||||
// Do a recursive call to be able to fix even multiple levels
|
||||
if ($level < 10)
|
||||
$signature = diaspora_repair_signature($signature, $handle, ++$level);
|
||||
}
|
||||
|
||||
return($signature);
|
||||
}
|
||||
|
||||
function diaspora_post($importer,$xml,$msg) {
|
||||
|
||||
$a = get_app();
|
||||
@@ -1565,62 +1574,22 @@ function diaspora_comment($importer,$xml,$msg) {
|
||||
//);
|
||||
//}
|
||||
|
||||
if(($parent_item['origin']) && (! $parent_author_signature)) {
|
||||
// If we are the origin of the parent we store the original signature and notify our followers
|
||||
if($parent_item['origin']) {
|
||||
$author_signature_base64 = base64_encode($author_signature);
|
||||
$author_signature_base64 = diaspora_repair_signature($author_signature_base64, $diaspora_handle);
|
||||
|
||||
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
intval($message_id),
|
||||
dbesc($signed_data),
|
||||
dbesc(base64_encode($author_signature)),
|
||||
dbesc($author_signature_base64),
|
||||
dbesc($diaspora_handle)
|
||||
);
|
||||
|
||||
// if the message isn't already being relayed, notify others
|
||||
// the existence of parent_author_signature means the parent_author or owner
|
||||
// is already relaying.
|
||||
|
||||
// notify others
|
||||
proc_run('php','include/notifier.php','comment-import',$message_id);
|
||||
}
|
||||
|
||||
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0 ",
|
||||
dbesc($parent_item['uri']),
|
||||
intval($importer['uid'])
|
||||
);
|
||||
|
||||
if(count($myconv)) {
|
||||
$importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
|
||||
|
||||
foreach($myconv as $conv) {
|
||||
|
||||
// now if we find a match, it means we're in this conversation
|
||||
|
||||
if(! link_compare($conv['author-link'],$importer_url))
|
||||
continue;
|
||||
|
||||
require_once('include/enotify.php');
|
||||
|
||||
$conv_parent = $conv['parent'];
|
||||
|
||||
notification(array(
|
||||
'type' => NOTIFY_COMMENT,
|
||||
'notify_flags' => $importer['notify-flags'],
|
||||
'language' => $importer['language'],
|
||||
'to_name' => $importer['username'],
|
||||
'to_email' => $importer['email'],
|
||||
'uid' => $importer['uid'],
|
||||
'item' => $datarray,
|
||||
'link' => $a->get_baseurl().'/display/'.urlencode($datarray['guid']),
|
||||
'source_name' => $datarray['author-name'],
|
||||
'source_link' => $datarray['author-link'],
|
||||
'source_photo' => $datarray['author-avatar'],
|
||||
'verb' => ACTIVITY_POST,
|
||||
'otype' => 'item',
|
||||
'parent' => $conv_parent,
|
||||
'parent_uri' => $parent_uri
|
||||
));
|
||||
|
||||
// only send one notification
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1775,7 +1744,6 @@ function diaspora_conversation($importer,$xml,$msg) {
|
||||
intval($conversation['id'])
|
||||
);
|
||||
|
||||
require_once('include/enotify.php');
|
||||
notification(array(
|
||||
'type' => NOTIFY_MAIL,
|
||||
'notify_flags' => $importer['notify-flags'],
|
||||
@@ -1973,11 +1941,15 @@ function diaspora_photo($importer,$xml,$msg,$attempt=1) {
|
||||
array($remote_photo_name, 'scaled_full_' . $remote_photo_name));
|
||||
|
||||
if(strpos($parent_item['body'],$link_text) === false) {
|
||||
|
||||
$parent_item['body'] = $link_text . $parent_item['body'];
|
||||
|
||||
$r = q("UPDATE `item` SET `body` = '%s', `visible` = 1 WHERE `id` = %d AND `uid` = %d",
|
||||
dbesc($link_text . $parent_item['body']),
|
||||
dbesc($parent_item['body']),
|
||||
intval($parent_item['id']),
|
||||
intval($parent_item['uid'])
|
||||
);
|
||||
put_item_in_cache($parent_item, true);
|
||||
update_thread($parent_item['id']);
|
||||
}
|
||||
|
||||
@@ -2222,21 +2194,21 @@ EOT;
|
||||
// );
|
||||
//}
|
||||
|
||||
if(! $parent_author_signature) {
|
||||
// If we are the origin of the parent we store the original signature and notify our followers
|
||||
if($parent_item['origin']) {
|
||||
$author_signature_base64 = base64_encode($author_signature);
|
||||
$author_signature_base64 = diaspora_repair_signature($author_signature_base64, $diaspora_handle);
|
||||
|
||||
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
intval($message_id),
|
||||
dbesc($signed_data),
|
||||
dbesc(base64_encode($author_signature)),
|
||||
dbesc($author_signature_base64),
|
||||
dbesc($diaspora_handle)
|
||||
);
|
||||
}
|
||||
|
||||
// if the message isn't already being relayed, notify others
|
||||
// the existence of parent_author_signature means the parent_author or owner
|
||||
// is already relaying. The parent_item['origin'] indicates the message was created on our system
|
||||
|
||||
if(($parent_item['origin']) && (! $parent_author_signature))
|
||||
// notify others
|
||||
proc_run('php','include/notifier.php','comment-import',$message_id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -2332,8 +2304,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
$sig_decode = base64_decode($sig);
|
||||
|
||||
@@ -2367,7 +2338,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
|
||||
intval($r[0]['parent'])
|
||||
);
|
||||
if(count($p)) {
|
||||
if(($p[0]['origin']) && (! $parent_author_signature)) {
|
||||
if($p[0]['origin']) {
|
||||
q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
$r[0]['id'],
|
||||
dbesc($signed_data),
|
||||
@@ -2407,10 +2378,10 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
if(! $contact)
|
||||
return;
|
||||
|
||||
if($contact['blocked']) {
|
||||
logger('diaspora_post: Ignoring this author.');
|
||||
return 202;
|
||||
}
|
||||
//if($contact['blocked']) {
|
||||
// logger('diaspora_post: Ignoring this author.');
|
||||
// return 202;
|
||||
//}
|
||||
|
||||
$name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : '');
|
||||
$image_url = unxmlify($xml->image_url);
|
||||
@@ -2418,6 +2389,8 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
$location = diaspora2bb(unxmlify($xml->location));
|
||||
$about = diaspora2bb(unxmlify($xml->bio));
|
||||
$gender = unxmlify($xml->gender);
|
||||
$searchable = (unxmlify($xml->searchable) == "true");
|
||||
$nsfw = (unxmlify($xml->nsfw) == "true");
|
||||
$tags = unxmlify($xml->tag_string);
|
||||
|
||||
$tags = explode("#", $tags);
|
||||
@@ -2432,6 +2405,8 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
$keywords = implode(", ", $keywords);
|
||||
|
||||
$handle_parts = explode("@", $diaspora_handle);
|
||||
$nick = $handle_parts[0];
|
||||
|
||||
if($name === '') {
|
||||
$name = $handle_parts[0];
|
||||
}
|
||||
@@ -2448,7 +2423,7 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
|
||||
require_once('include/Photo.php');
|
||||
|
||||
$images = import_profile_photo($image_url,$importer['uid'],$contact['id']);
|
||||
update_contact_avatar($image_url,$importer['uid'],$contact['id']);
|
||||
|
||||
// Generic birthday. We don't know the timezone. The year is irrelevant.
|
||||
|
||||
@@ -2466,12 +2441,11 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
/// @TODO Update name on item['author-name'] if the name changed. See consume_feed()
|
||||
/// (Not doing this currently because D* protocol is scheduled for revision soon).
|
||||
|
||||
$r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
|
||||
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s',
|
||||
`location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
|
||||
dbesc($name),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($images[0]),
|
||||
dbesc($images[1]),
|
||||
dbesc($images[2]),
|
||||
dbesc($nick),
|
||||
dbesc($diaspora_handle),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($birthday),
|
||||
dbesc($location),
|
||||
@@ -2482,26 +2456,17 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
intval($importer['uid'])
|
||||
);
|
||||
|
||||
if (unxmlify($xml->searchable) == "true") {
|
||||
if ($searchable) {
|
||||
require_once('include/socgraph.php');
|
||||
poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "",
|
||||
poco_check($contact['url'], $name, NETWORK_DIASPORA, $image_url, $about, $location, $gender, $keywords, "",
|
||||
datetime_convert(), 2, $contact['id'], $importer['uid']);
|
||||
}
|
||||
|
||||
$profileurl = "";
|
||||
$author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
|
||||
dbesc(normalise_link($contact['url'])));
|
||||
|
||||
if (count($author) == 0) {
|
||||
q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`, `location`, `about`) VALUES ('%s', '%s', '%s', '%s', '%s')",
|
||||
dbesc(normalise_link($contact['url'])), dbesc($name), dbesc($location), dbesc($about), dbesc($images[0]));
|
||||
|
||||
$author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
|
||||
dbesc(normalise_link($contact['url'])));
|
||||
} else if (normalise_link($contact['url']).$name.$location.$about != normalise_link($author[0]["url"]).$author[0]["name"].$author[0]["location"].$author[0]["about"]) {
|
||||
q("UPDATE unique_contacts SET name = '%s', avatar = '%s', `location` = '%s', `about` = '%s' WHERE url = '%s'",
|
||||
dbesc($name), dbesc($images[0]), dbesc($location), dbesc($about), dbesc(normalise_link($contact['url'])));
|
||||
}
|
||||
update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2,
|
||||
"photo" => $image_url, "name" => $name, "location" => $location,
|
||||
"about" => $about, "birthday" => $birthday, "gender" => $gender,
|
||||
"addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords,
|
||||
"hide" => !$searchable, "nsfw" => $nsfw));
|
||||
|
||||
/* if($r) {
|
||||
if($oldphotos) {
|
||||
@@ -2643,11 +2608,12 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
|
||||
}
|
||||
|
||||
logger('diaspora_send_status: '.$owner['username'].' -> '.$contact['name'].' base message: '.$msg, LOGGER_DATA);
|
||||
logger('send guid '.$item['guid'], LOGGER_DEBUG);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
$return_code = diaspora_transmit($owner,$contact,$slap,$public_batch);
|
||||
$return_code = diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']);
|
||||
|
||||
logger('diaspora_send_status: guid: '.$item['guid'].' result '.$return_code, LOGGER_DEBUG);
|
||||
|
||||
@@ -2758,10 +2724,12 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals
|
||||
|
||||
|
||||
logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
|
||||
logger('send guid '.$r[0]['guid'], LOGGER_DEBUG);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
diaspora_transmit($owner,$contact,$slap,$public_batch);
|
||||
diaspora_transmit($owner,$contact,$slap,$public_batch,false,$r[0]['guid']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2815,7 +2783,7 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
|
||||
// sign it
|
||||
|
||||
if($like)
|
||||
$signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $myaddr;
|
||||
$signed_text = $positive . ';' . $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $myaddr;
|
||||
else
|
||||
$signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $myaddr;
|
||||
|
||||
@@ -2832,11 +2800,12 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
|
||||
));
|
||||
|
||||
logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA);
|
||||
logger('send guid '.$item['guid'], LOGGER_DEBUG);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']));
|
||||
}
|
||||
|
||||
|
||||
@@ -2847,9 +2816,6 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
|
||||
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
|
||||
// $theiraddr = $contact['addr'];
|
||||
|
||||
$body = $item['body'];
|
||||
$text = html_entity_decode(bb2diaspora($body));
|
||||
|
||||
// Diaspora doesn't support threaded comments, but some
|
||||
// versions of Diaspora (i.e. Diaspora-pistos) support
|
||||
// likes on comments
|
||||
@@ -2900,61 +2866,53 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
|
||||
// fetch the original signature if the relayable was created by a Diaspora
|
||||
// or DFRN user. Relayables for other networks are not supported.
|
||||
|
||||
/* $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1",
|
||||
$r = q("SELECT `signed_text`, `signature`, `signer` FROM `sign` WHERE " . $sql_sign_id . " = %d LIMIT 1",
|
||||
intval($item['id'])
|
||||
);
|
||||
if(count($r)) {
|
||||
if(count($r)) {
|
||||
$orig_sign = $r[0];
|
||||
$signed_text = $orig_sign['signed_text'];
|
||||
$authorsig = $orig_sign['signature'];
|
||||
$handle = $orig_sign['signer'];
|
||||
|
||||
// Split the signed text
|
||||
$signed_parts = explode(";", $signed_text);
|
||||
|
||||
// Remove the parent guid
|
||||
array_shift($signed_parts);
|
||||
|
||||
// Remove the comment guid
|
||||
array_shift($signed_parts);
|
||||
|
||||
// Remove the handle
|
||||
array_pop($signed_parts);
|
||||
|
||||
// Glue the parts together
|
||||
$text = implode(";", $signed_parts);
|
||||
}
|
||||
else {
|
||||
// This part is meant for cases where we don't have the signatur. (Which shouldn't happen with posts from Diaspora and Friendica)
|
||||
// This means that the comment won't be accepted by newer Diaspora servers
|
||||
|
||||
// Author signature information (for likes, comments, and retractions of likes or comments,
|
||||
// whether from Diaspora or Friendica) must be placed in the `sign` table before this
|
||||
// function is called
|
||||
logger('diaspora_send_relay: original author signature not found, cannot send relayable');
|
||||
return;
|
||||
}*/
|
||||
$body = $item['body'];
|
||||
$text = html_entity_decode(bb2diaspora($body));
|
||||
|
||||
/* Since the author signature is only checked by the parent, not by the relay recipients,
|
||||
* I think it may not be necessary for us to do so much work to preserve all the original
|
||||
* signatures. The important thing that Diaspora DOES need is the original creator's handle.
|
||||
* Let's just generate that and forget about all the original author signature stuff.
|
||||
*
|
||||
* Note: this might be more of an problem if we want to support likes on comments for older
|
||||
* versions of Diaspora (diaspora-pistos), but since there are a number of problems with
|
||||
* doing that, let's ignore it for now.
|
||||
*
|
||||
* Currently, only DFRN contacts are supported. StatusNet shouldn't be hard, but it hasn't
|
||||
* been done yet
|
||||
*/
|
||||
$handle = diaspora_handle_from_contact($item['contact-id']);
|
||||
if(! $handle)
|
||||
return;
|
||||
|
||||
$handle = diaspora_handle_from_contact($item['contact-id']);
|
||||
if(! $handle)
|
||||
return;
|
||||
if($relay_retract)
|
||||
$signed_text = $item['guid'] . ';' . $target_type;
|
||||
elseif($like)
|
||||
$signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle;
|
||||
else
|
||||
$signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle;
|
||||
|
||||
|
||||
if($relay_retract)
|
||||
$sender_signed_text = $item['guid'] . ';' . $target_type;
|
||||
elseif($like)
|
||||
$sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle;
|
||||
else
|
||||
$sender_signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle;
|
||||
$authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
|
||||
}
|
||||
|
||||
// Sign the relayable with the top-level owner's signature
|
||||
//
|
||||
// We'll use the $sender_signed_text that we just created, instead of the $signed_text
|
||||
// stored in the database, because that provides the best chance that Diaspora will
|
||||
// be able to reconstruct the signed text the same way we did. This is particularly a
|
||||
// concern for the comment, whose signed text includes the text of the comment. The
|
||||
// smallest change in the text of the comment, including removing whitespace, will
|
||||
// make the signature verification fail. Since we translate from BB code to Diaspora's
|
||||
// markup at the top of this function, which is AFTER we placed the original $signed_text
|
||||
// in the database, it's hazardous to trust the original $signed_text.
|
||||
|
||||
$parentauthorsig = base64_encode(rsa_sign($sender_signed_text,$owner['uprvkey'],'sha256'));
|
||||
$parentauthorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
|
||||
|
||||
$msg = replace_macros($tpl,array(
|
||||
'$guid' => xmlify($item['guid']),
|
||||
@@ -2968,12 +2926,12 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
|
||||
));
|
||||
|
||||
logger('diaspora_send_relay: base message: ' . $msg, LOGGER_DATA);
|
||||
|
||||
logger('send guid '.$item['guid'], LOGGER_DEBUG);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']));
|
||||
|
||||
}
|
||||
|
||||
@@ -3005,10 +2963,12 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) {
|
||||
'$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256')))
|
||||
));
|
||||
|
||||
logger('send guid '.$item['guid'], LOGGER_DEBUG);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']));
|
||||
}
|
||||
|
||||
function diaspora_send_mail($item,$owner,$contact) {
|
||||
@@ -3065,16 +3025,17 @@ function diaspora_send_mail($item,$owner,$contact) {
|
||||
}
|
||||
|
||||
logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA);
|
||||
logger('send guid '.$item['guid'], LOGGER_DEBUG);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,false));
|
||||
return(diaspora_transmit($owner,$contact,$slap,false,false,$item['guid']));
|
||||
|
||||
|
||||
}
|
||||
|
||||
function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) {
|
||||
function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false,$guid = "") {
|
||||
|
||||
$enabled = intval(get_config('system','diaspora_enabled'));
|
||||
if(! $enabled) {
|
||||
@@ -3087,9 +3048,9 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false)
|
||||
if(! $dest_url) {
|
||||
logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
|
||||
logger('diaspora_transmit: '.$logid.'-'.$guid.' '.$dest_url);
|
||||
|
||||
if( (! $queue_run) && (was_recently_delayed($contact['id'])) ) {
|
||||
$return_code = 0;
|
||||
@@ -3104,7 +3065,7 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false)
|
||||
}
|
||||
}
|
||||
|
||||
logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code);
|
||||
logger('diaspora_transmit: '.$logid.'-'.$guid.' returns: '.$return_code);
|
||||
|
||||
if((! $return_code) || (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))) {
|
||||
logger('diaspora_transmit: queue message');
|
||||
|
||||
@@ -76,11 +76,18 @@ function discover_poco_run(&$argv, &$argc){
|
||||
update_suggestions();
|
||||
elseif (($mode == 2) AND get_config('system','poco_completion'))
|
||||
discover_users();
|
||||
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search'))
|
||||
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
|
||||
discover_directory($search);
|
||||
elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0))
|
||||
gs_search_user($search);
|
||||
} elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0)) {
|
||||
// Query Friendica and Hubzilla servers for their users
|
||||
poco_discover();
|
||||
|
||||
// Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
|
||||
if (!get_config('system','ostatus_disabled'))
|
||||
gs_discover();
|
||||
}
|
||||
|
||||
logger('end '.$search);
|
||||
|
||||
return;
|
||||
@@ -128,7 +135,7 @@ function discover_users() {
|
||||
else
|
||||
$server_url = poco_detect_server($user["url"]);
|
||||
|
||||
if (poco_check_server($server_url, $gcontacts[0]["network"])) {
|
||||
if (($server_url == "") OR poco_check_server($server_url, $gcontacts[0]["network"])) {
|
||||
logger('Check user '.$user["url"]);
|
||||
poco_last_updated($user["url"], true);
|
||||
|
||||
@@ -191,6 +198,36 @@ function discover_directory($search) {
|
||||
Cache::set("dirsearch:".$search, time(), CACHE_DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Search for GNU Social user with gstools.org
|
||||
*
|
||||
* @param str $search User name
|
||||
*/
|
||||
function gs_search_user($search) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$url = "http://gstools.org/api/users_search/".urlencode($search);
|
||||
|
||||
$result = z_fetch_url($url);
|
||||
if (!$result["success"])
|
||||
return false;
|
||||
|
||||
$contacts = json_decode($result["body"]);
|
||||
|
||||
if ($contacts->status == 'ERROR')
|
||||
return false;
|
||||
|
||||
foreach($contacts->data AS $user) {
|
||||
$contact = probe_url($user->site_address."/".$user->name);
|
||||
if ($contact["network"] != NETWORK_PHANTOM) {
|
||||
$contact["about"] = $user->description;
|
||||
update_gcontact($contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
discover_poco_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
|
||||
@@ -633,4 +633,129 @@ function notification($params) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks for item related notifications and sends them
|
||||
*
|
||||
* @param int $itemid ID of the item for which the check should be done
|
||||
* @param int $uid User ID
|
||||
* @param str $defaulttype (Optional) Forces a notification with this type.
|
||||
*/
|
||||
function check_item_notification($itemid, $uid, $defaulttype = "") {
|
||||
|
||||
$notification_data = array("uid" => $uid, "profiles" => array());
|
||||
call_hooks('check_item_notification', $notification_data);
|
||||
|
||||
$profiles = $notification_data["profiles"];
|
||||
|
||||
$user = q("SELECT `notify-flags`, `language`, `username`, `email` FROM `user` WHERE `uid` = %d", intval($uid));
|
||||
if (!$user)
|
||||
return false;
|
||||
|
||||
$owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid));
|
||||
if (!$owner)
|
||||
return false;
|
||||
|
||||
$profiles[] = $owner[0]["url"];
|
||||
|
||||
$profiles2 = array();
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
$profiles2[] = normalise_link($profile);
|
||||
$profiles2[] = str_replace("http://", "https://", normalise_link($profile));
|
||||
}
|
||||
|
||||
$profiles = $profiles2;
|
||||
|
||||
$profile_list = "";
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
if ($profile_list != "")
|
||||
$profile_list .= "', '";
|
||||
|
||||
$profile_list .= dbesc($profile);
|
||||
}
|
||||
|
||||
$profile_list = "'".$profile_list."'";
|
||||
|
||||
// Only act if it is a "real" post
|
||||
// We need the additional check for the "local_profile" because of mixed situations on connector networks
|
||||
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`,
|
||||
`parent-uri`, `uri`, `contact-id`
|
||||
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
|
||||
NOT (`author-link` IN ($profile_list)) LIMIT 1",
|
||||
intval($itemid), dbesc(ACTIVITY_POST));
|
||||
if (!$item)
|
||||
return false;
|
||||
|
||||
// Generate the notification array
|
||||
$params = array();
|
||||
$params["uid"] = $uid;
|
||||
$params["notify_flags"] = $user[0]["notify-flags"];
|
||||
$params["language"] = $user[0]["language"];
|
||||
$params["to_name"] = $user[0]["username"];
|
||||
$params["to_email"] = $user[0]["email"];
|
||||
$params["item"] = $item[0];
|
||||
$params["parent"] = $item[0]["parent"];
|
||||
$params["link"] = App::get_baseurl().'/display/'.urlencode($item[0]["guid"]);
|
||||
$params["otype"] = 'item';
|
||||
$params["source_name"] = $item[0]["author-name"];
|
||||
$params["source_link"] = $item[0]["author-link"];
|
||||
$params["source_photo"] = $item[0]["author-avatar"];
|
||||
|
||||
if ($item[0]["parent-uri"] === $item[0]["uri"]) {
|
||||
// Send a notification for every new post?
|
||||
$r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1",
|
||||
intval($item[0]['contact-id']),
|
||||
intval($uid)
|
||||
);
|
||||
$send_notification = count($r);
|
||||
|
||||
if (!$send_notification) {
|
||||
$tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d",
|
||||
intval(TERM_OBJ_POST), intval($itemid), intval(TERM_MENTION), intval($uid));
|
||||
|
||||
if (count($tags)) {
|
||||
foreach ($tags AS $tag) {
|
||||
$r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `notify_new_posts`",
|
||||
normalise_link($tag["url"]), intval($uid));
|
||||
if (count($r))
|
||||
$send_notification = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($send_notification) {
|
||||
$params["type"] = NOTIFY_SHARE;
|
||||
$params["verb"] = ACTIVITY_TAG;
|
||||
}
|
||||
}
|
||||
|
||||
// Is the user mentioned in this post?
|
||||
$tagged = false;
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]"))
|
||||
$tagged = true;
|
||||
}
|
||||
|
||||
if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) {
|
||||
$params["type"] = NOTIFY_TAGSELF;
|
||||
$params["verb"] = ACTIVITY_TAG;
|
||||
}
|
||||
|
||||
// Is it a post that the user had started or where he interacted?
|
||||
$parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid`
|
||||
WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND
|
||||
(`thread`.`mention` OR `item`.`author-link` IN ($profile_list))
|
||||
LIMIT 1",
|
||||
intval($item[0]["parent"]), intval($uid));
|
||||
|
||||
if ($parent AND !isset($params["type"])) {
|
||||
$params["type"] = NOTIFY_COMMENT;
|
||||
$params["verb"] = ACTIVITY_POST;
|
||||
}
|
||||
|
||||
if (isset($params["type"]))
|
||||
notification($params);
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -61,7 +61,7 @@ function format_event_html($ev, $simple = false) {
|
||||
. bbcode($ev['location'])
|
||||
. '</span></p>' . "\r\n";
|
||||
|
||||
if (strpos($ev['location'], "[map")===False) {
|
||||
if (strpos($ev['location'], "[map") !== False) {
|
||||
$map = generate_named_map($ev['location']);
|
||||
if ($map!==$ev['location']) $o.=$map;
|
||||
}
|
||||
@@ -76,7 +76,6 @@ function format_event_html($ev, $simple = false) {
|
||||
function parse_event($h) {
|
||||
|
||||
require_once('include/Scrape.php');
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
require_once('include/html2bbcode');
|
||||
|
||||
$h = '<html><body>' . $h . '</body></html>';
|
||||
|
||||
@@ -18,7 +18,6 @@ function expire_run(&$argv, &$argc){
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file include/features.php *
|
||||
* @file include/features.php
|
||||
* @brief Features management
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief check if feature is enabled
|
||||
*
|
||||
* return boolean
|
||||
* @return boolean
|
||||
*/
|
||||
function feature_enabled($uid,$feature) {
|
||||
//return true;
|
||||
|
||||
$x = get_pconfig($uid,'feature',$feature);
|
||||
$x = get_config('feature_lock',$feature);
|
||||
if($x === false) {
|
||||
$x = get_config('feature',$feature);
|
||||
if($x === false)
|
||||
$x = get_feature_default($feature);
|
||||
$x = get_pconfig($uid,'feature',$feature);
|
||||
if($x === false) {
|
||||
$x = get_config('feature',$feature);
|
||||
if($x === false)
|
||||
$x = get_feature_default($feature);
|
||||
}
|
||||
}
|
||||
$arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x);
|
||||
call_hooks('feature_enabled',$arr);
|
||||
@@ -42,14 +44,17 @@ function get_feature_default($feature) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @ brief get a list of all available features
|
||||
* @brief Get a list of all available features
|
||||
*
|
||||
* The array includes the setting group, the setting name,
|
||||
* explainations for the setting and if it's enabled or disabled
|
||||
* by default
|
||||
*
|
||||
* @param bool $filtered True removes any locked features
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_features() {
|
||||
function get_features($filtered = true) {
|
||||
|
||||
$arr = array(
|
||||
|
||||
@@ -57,56 +62,78 @@ function get_features() {
|
||||
'general' => array(
|
||||
t('General Features'),
|
||||
//array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')),
|
||||
array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'),false),
|
||||
array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'),false),
|
||||
array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'), false, get_config('feature_lock','multi_profiles')),
|
||||
array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, get_config('feature_lock','photo_location')),
|
||||
),
|
||||
|
||||
// Post composition
|
||||
'composition' => array(
|
||||
t('Post Composition Features'),
|
||||
array('richtext', t('Richtext Editor'), t('Enable richtext editor'),false),
|
||||
array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'),false),
|
||||
array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a fourm page is selected/deselected in ACL window.'),false),
|
||||
array('richtext', t('Richtext Editor'), t('Enable richtext editor'), false, get_config('feature_lock','richtext')),
|
||||
array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'), false, get_config('feature_lock','preview')),
|
||||
array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a fourm page is selected/deselected in ACL window.'), false, get_config('feature_lock','aclautomention')),
|
||||
),
|
||||
|
||||
// Network sidebar widgets
|
||||
'widgets' => array(
|
||||
t('Network Sidebar Widgets'),
|
||||
array('archives', t('Search by Date'), t('Ability to select posts by date ranges'),false),
|
||||
array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'),true),
|
||||
array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'),false),
|
||||
array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'),false),
|
||||
array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'),false),
|
||||
array('archives', t('Search by Date'), t('Ability to select posts by date ranges'), false, get_config('feature_lock','archives')),
|
||||
array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'), true, get_config('feature_lock','forumlist_widget')),
|
||||
array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'), false, get_config('feature_lock','groups')),
|
||||
array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'), false, get_config('feature_lock','networks')),
|
||||
array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'), false, get_config('feature_lock','savedsearch')),
|
||||
),
|
||||
|
||||
// Network tabs
|
||||
'net_tabs' => array(
|
||||
t('Network Tabs'),
|
||||
array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'),false),
|
||||
array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'),false),
|
||||
array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'),false),
|
||||
array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'), false, get_config('feature_lock','personal_tab')),
|
||||
array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'), false, get_config('feature_lock','new_tab')),
|
||||
array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'), false, get_config('feature_lock','link_tab')),
|
||||
),
|
||||
|
||||
// Item tools
|
||||
'tools' => array(
|
||||
t('Post/Comment Tools'),
|
||||
array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'),false),
|
||||
array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'),false),
|
||||
array('commtag', t('Tagging'), t('Ability to tag existing posts'),false),
|
||||
array('categories', t('Post Categories'), t('Add categories to your posts'),false),
|
||||
array('filing', t('Saved Folders'), t('Ability to file posts under folders'),false),
|
||||
array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments')),
|
||||
array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'),false),
|
||||
array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'),false),
|
||||
array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'), false, get_config('feature_lock','multi_delete')),
|
||||
array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'), false, get_config('feature_lock','edit_posts')),
|
||||
array('commtag', t('Tagging'), t('Ability to tag existing posts'), false, get_config('feature_lock','commtag')),
|
||||
array('categories', t('Post Categories'), t('Add categories to your posts'), false, get_config('feature_lock','categories')),
|
||||
array('filing', t('Saved Folders'), t('Ability to file posts under folders'), false, get_config('feature_lock','filing')),
|
||||
array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'), false, get_config('feature_lock','dislike')),
|
||||
array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'), false, get_config('feature_lock','star_posts')),
|
||||
array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'), false, get_config('feature_lock','ignore_posts')),
|
||||
),
|
||||
|
||||
// Advanced Profile Settings
|
||||
'advanced_profile' => array(
|
||||
t('Advanced Profile Settings'),
|
||||
array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'),false),
|
||||
array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'), false, get_config('feature_lock','forumlist_profile')),
|
||||
),
|
||||
);
|
||||
|
||||
// removed any locked features and remove the entire category if this makes it empty
|
||||
|
||||
if($filtered) {
|
||||
foreach($arr as $k => $x) {
|
||||
$has_items = false;
|
||||
$kquantity = count($arr[$k]);
|
||||
for($y = 0; $y < $kquantity; $y ++) {
|
||||
if(is_array($arr[$k][$y])) {
|
||||
if($arr[$k][$y][4] === false) {
|
||||
$has_items = true;
|
||||
}
|
||||
else {
|
||||
unset($arr[$k][$y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(! $has_items) {
|
||||
unset($arr[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
call_hooks('get_features',$arr);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
@@ -264,24 +264,8 @@ function new_contact($uid,$url,$interactive = false) {
|
||||
|
||||
require_once("include/Photo.php");
|
||||
|
||||
$photos = import_profile_photo($ret['photo'],$uid,$contact_id);
|
||||
|
||||
$r = q("UPDATE `contact` SET `photo` = '%s',
|
||||
`thumb` = '%s',
|
||||
`micro` = '%s',
|
||||
`name-date` = '%s',
|
||||
`uri-date` = '%s',
|
||||
`avatar-date` = '%s'
|
||||
WHERE `id` = %d",
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact_id)
|
||||
);
|
||||
|
||||
// Update the avatar
|
||||
update_contact_avatar($ret['photo'],$uid,$contact_id);
|
||||
|
||||
// pull feed and consume it, which should subscribe to the hub.
|
||||
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file include/forums.php
|
||||
* @brief Functions related to forum functionality *
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function to list all forums a user is connected with
|
||||
*
|
||||
* @param int $uid of the profile owner
|
||||
* @param boolean $showhidden
|
||||
* Show frorums which are not hidden
|
||||
* @param boolean $lastitem
|
||||
* Sort by lastitem
|
||||
* @param boolean $showprivate
|
||||
* Show private groups
|
||||
*
|
||||
* @returns array
|
||||
* 'url' => forum url
|
||||
* 'name' => forum name
|
||||
* 'id' => number of the key from the array
|
||||
* 'micro' => contact photo in format micro
|
||||
*/
|
||||
function get_forumlist($uid, $showhidden = true, $lastitem, $showprivate = false) {
|
||||
|
||||
$forumlist = array();
|
||||
|
||||
$order = (($showhidden) ? '' : ' AND NOT `hidden` ');
|
||||
$order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
|
||||
$select = '`forum` ';
|
||||
if ($showprivate) {
|
||||
$select = '(`forum` OR `prv`)';
|
||||
}
|
||||
|
||||
$contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
|
||||
WHERE `network`= 'dfrn' AND $select AND `uid` = %d
|
||||
AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
|
||||
AND `success_update` > `failure_update`
|
||||
$order ",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist[] = array(
|
||||
'url' => $contact['url'],
|
||||
'name' => $contact['name'],
|
||||
'id' => $contact['id'],
|
||||
'micro' => $contact['micro'],
|
||||
);
|
||||
}
|
||||
return($forumlist);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Forumlist widget
|
||||
*
|
||||
* Sidebar widget to show subcribed friendica forums. If activated
|
||||
* in the settings, it appears at the notwork page sidebar
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* The contact id which is used to mark a forum as "selected"
|
||||
* @return string
|
||||
*/
|
||||
function widget_forumlist($uid,$cid = 0) {
|
||||
|
||||
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
//sort by last updated item
|
||||
$lastitem = true;
|
||||
|
||||
$contacts = get_forumlist($uid,true,$lastitem, true);
|
||||
$total = count($contacts);
|
||||
$visible_forums = 10;
|
||||
|
||||
if(count($contacts)) {
|
||||
|
||||
$id = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
|
||||
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
|
||||
|
||||
$entry = array(
|
||||
'url' => z_root() . '/network?f=&cid=' . $contact['id'],
|
||||
'external_url' => z_root() . '/redir/' . $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'cid' => $contact['id'],
|
||||
'selected' => $selected,
|
||||
'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
|
||||
'id' => ++$id,
|
||||
);
|
||||
$entries[] = $entry;
|
||||
}
|
||||
|
||||
$tpl = get_markup_template('widget_forumlist.tpl');
|
||||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$title' => t('Forums'),
|
||||
'$forums' => $entries,
|
||||
'$link_desc' => t('External link to forum'),
|
||||
'$total' => $total,
|
||||
'$visible_forums' => $visible_forums,
|
||||
'$showmore' => t('show more'),
|
||||
));
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format forumlist as contact block
|
||||
*
|
||||
* This function is used to show the forumlist in
|
||||
* the advanced profile.
|
||||
*
|
||||
* @param int $uid
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function forumlist_profile_advanced($uid) {
|
||||
|
||||
$profile = intval(feature_enabled($uid,'forumlist_profile'));
|
||||
if(! $profile)
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
// place holder in case somebody wants configurability
|
||||
$show_total = 9999;
|
||||
|
||||
//don't sort by last updated item
|
||||
$lastitem = false;
|
||||
|
||||
$contacts = get_forumlist($uid,false,$lastitem,false);
|
||||
|
||||
$total_shown = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
|
||||
$total_shown ++;
|
||||
if($total_shown == $show_total)
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($contacts) > 0)
|
||||
$o .= $forumlist;
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief count unread forum items
|
||||
*
|
||||
* Count unread items of connected forums and private groups
|
||||
*
|
||||
* @return array
|
||||
* 'id' => contact id
|
||||
* 'name' => contact/forum name
|
||||
* 'count' => counted unseen forum items
|
||||
*
|
||||
*/
|
||||
|
||||
function forums_count_unseen() {
|
||||
$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
|
||||
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
|
||||
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
|
||||
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
|
||||
AND NOT `contact`.`pending` AND NOT `contact`.`archive`
|
||||
AND `contact`.`success_update` > `failure_update`
|
||||
GROUP BY `contact`.`id` ",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
@@ -60,6 +60,8 @@ class FriendicaSmartyEngine implements ITemplateEngine {
|
||||
$template = $s;
|
||||
$s = new FriendicaSmarty();
|
||||
}
|
||||
|
||||
$r['$APP'] = get_app();
|
||||
|
||||
// "middleware": inject variables into templates
|
||||
$arr = array(
|
||||
|
||||
@@ -33,7 +33,7 @@ function gprobe_run(&$argv, &$argc){
|
||||
|
||||
$url = hex2bin($argv[1]);
|
||||
|
||||
$r = q("select * from gcontact where nurl = '%s' limit 1",
|
||||
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($url))
|
||||
);
|
||||
|
||||
@@ -58,21 +58,16 @@ function gprobe_run(&$argv, &$argc){
|
||||
if (is_null($result))
|
||||
Cache::set("gprobe:".$urlparts["host"],serialize($arr));
|
||||
|
||||
if(count($arr) && x($arr,'network') && $arr['network'] === NETWORK_DFRN) {
|
||||
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`)
|
||||
values ( '%s', '%s', '%s', '%s') ",
|
||||
dbesc($arr['name']),
|
||||
dbesc($arr['url']),
|
||||
dbesc(normalise_link($arr['url'])),
|
||||
dbesc($arr['photo'])
|
||||
);
|
||||
}
|
||||
$r = q("select * from gcontact where nurl = '%s' limit 1",
|
||||
if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))
|
||||
update_gcontact($arr);
|
||||
|
||||
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($url))
|
||||
);
|
||||
}
|
||||
if(count($r))
|
||||
poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
|
||||
if ($r[0]["network"] == NETWORK_DFRN)
|
||||
poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
|
||||
|
||||
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
|
||||
return;
|
||||
|
||||
@@ -215,7 +215,7 @@ function mini_group_select($uid,$gid = 0) {
|
||||
|
||||
/**
|
||||
* @brief Create group sidebar widget
|
||||
*
|
||||
*
|
||||
* @param string $every
|
||||
* @param string $each
|
||||
* @param string $editmode
|
||||
@@ -234,7 +234,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||
return '';
|
||||
|
||||
$groups = array();
|
||||
|
||||
|
||||
$groups[] = array(
|
||||
'text' => t('Everybody'),
|
||||
'id' => 0,
|
||||
@@ -255,7 +255,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||
if(count($r)) {
|
||||
foreach($r as $rr) {
|
||||
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
|
||||
|
||||
|
||||
if ($editmode == "full") {
|
||||
$groupedit = array(
|
||||
'href' => "group/".$rr['id'],
|
||||
@@ -264,7 +264,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||
} else {
|
||||
$groupedit = null;
|
||||
}
|
||||
|
||||
|
||||
$groups[] = array(
|
||||
'id' => $rr['id'],
|
||||
'cid' => $cid,
|
||||
@@ -297,17 +297,26 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||
return $o;
|
||||
}
|
||||
|
||||
function expand_groups($a,$check_dead = false) {
|
||||
function expand_groups($a,$check_dead = false, $use_gcontact = false) {
|
||||
if(! (is_array($a) && count($a)))
|
||||
return array();
|
||||
$groups = implode(',', $a);
|
||||
$groups = dbesc($groups);
|
||||
$r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
|
||||
|
||||
if ($use_gcontact)
|
||||
$r = q("SELECT `gcontact`.`id` AS `contact-id` FROM `group_member`
|
||||
INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
|
||||
INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
|
||||
WHERE `gid` IN ($groups)");
|
||||
else
|
||||
$r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
|
||||
|
||||
|
||||
$ret = array();
|
||||
if(count($r))
|
||||
foreach($r as $rr)
|
||||
$ret[] = $rr['contact-id'];
|
||||
if($check_dead) {
|
||||
if($check_dead AND !$use_gcontact) {
|
||||
require_once('include/acl_selectors.php');
|
||||
$ret = prune_deadguys($ret);
|
||||
}
|
||||
@@ -353,17 +362,16 @@ function groups_containing($uid,$c) {
|
||||
*/
|
||||
function groups_count_unseen() {
|
||||
|
||||
$r = q("SELECT `group`.`id`, `group`.`name`, COUNT(`item`.`id`) AS `count` FROM `group`, `group_member`, `item`
|
||||
WHERE `group`.`uid` = %d
|
||||
AND `item`.`uid` = %d
|
||||
AND `item`.`unseen` AND `item`.`visible`
|
||||
AND NOT `item`.`deleted`
|
||||
AND `item`.`contact-id` = `group_member`.`contact-id`
|
||||
AND `group_member`.`gid` = `group`.`id`
|
||||
GROUP BY `group`.`id` ",
|
||||
$r = q("SELECT `group`.`id`, `group`.`name`,
|
||||
(SELECT COUNT(*) FROM `item`
|
||||
WHERE `uid` = %d AND `unseen` AND
|
||||
`contact-id` IN (SELECT `contact-id` FROM `group_member`
|
||||
WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count`
|
||||
FROM `group` WHERE `group`.`uid` = %d;",
|
||||
intval(local_user()),
|
||||
intval(local_user()),
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @file include/identity.php
|
||||
*/
|
||||
|
||||
require_once('include/forums.php');
|
||||
require_once('include/ForumManager.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once("mod/proxy.php");
|
||||
|
||||
@@ -300,6 +300,7 @@ function profile_sidebar($profile, $block = 0) {
|
||||
$account_type = "";
|
||||
|
||||
if((x($profile,'address') == 1)
|
||||
|| (x($profile,'location') == 1)
|
||||
|| (x($profile,'locality') == 1)
|
||||
|| (x($profile,'region') == 1)
|
||||
|| (x($profile,'postal-code') == 1)
|
||||
@@ -368,6 +369,8 @@ function profile_sidebar($profile, $block = 0) {
|
||||
|
||||
if (isset($p["address"]))
|
||||
$p["address"] = bbcode($p["address"]);
|
||||
else
|
||||
$p["address"] = bbcode($p["location"]);
|
||||
|
||||
if (isset($p["photo"]))
|
||||
$p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
|
||||
@@ -652,7 +655,7 @@ function advanced_profile(&$a) {
|
||||
|
||||
//show subcribed forum if it is enabled in the usersettings
|
||||
if (feature_enabled($uid,'forumlist_profile')) {
|
||||
$profile['forumlist'] = array( t('Forums:'), forumlist_profile_advanced($uid));
|
||||
$profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
|
||||
}
|
||||
|
||||
if ($a->profile['uid'] == local_user())
|
||||
|
||||
3278
include/items.php
3278
include/items.php
File diff suppressed because it is too large
Load Diff
@@ -279,6 +279,9 @@ function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact)
|
||||
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
|
||||
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
|
||||
|
||||
// This code could never had worked (the return values form the queries were used in a wrong way.
|
||||
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
|
||||
/*
|
||||
// Get contact's private key if he's a user of the local Friendica server
|
||||
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
|
||||
dbesc($contact['url'])
|
||||
@@ -289,9 +292,15 @@ function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact)
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact_uid)
|
||||
);
|
||||
*/
|
||||
// Is the contact the owner? Then fetch the private key
|
||||
if ($contact['self'] AND ($contact['uid'] > 0)) {
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact['uid'])
|
||||
);
|
||||
|
||||
if( $r)
|
||||
$authorsig = base64_encode(rsa_sign($signed_text,$r['prvkey'],'sha256'));
|
||||
if($r)
|
||||
$authorsig = base64_encode(rsa_sign($signed_text,$r[0]['prvkey'],'sha256'));
|
||||
}
|
||||
|
||||
if(! isset($authorsig))
|
||||
@@ -329,6 +338,10 @@ function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
|
||||
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
|
||||
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
|
||||
|
||||
|
||||
// This code could never had worked (the return values form the queries were used in a wrong way.
|
||||
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
|
||||
/*
|
||||
// Get contact's private key if he's a user of the local Friendica server
|
||||
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
|
||||
dbesc($contact['url'])
|
||||
@@ -343,6 +356,17 @@ function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
|
||||
if( $r)
|
||||
$contact_uprvkey = $r['prvkey'];
|
||||
}
|
||||
*/
|
||||
|
||||
// Is the contact the owner? Then fetch the private key
|
||||
if ($contact['self'] AND ($contact['uid'] > 0)) {
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact['uid'])
|
||||
);
|
||||
|
||||
if($r)
|
||||
$contact_uprvkey = $r[0]['prvkey'];
|
||||
}
|
||||
|
||||
$r = q("SELECT guid, parent FROM `item` WHERE id = %d LIMIT 1",
|
||||
intval($post_id)
|
||||
@@ -353,7 +377,7 @@ function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
|
||||
intval($r[0]['parent'])
|
||||
);
|
||||
if( $p) {
|
||||
$signed_text = $r[0]['guid'] . ';Post;' . $p[0]['guid'] . ';true;' . $diaspora_handle;
|
||||
$signed_text = 'true;'.$r[0]['guid'].';Post;'.$p[0]['guid'].';'.$diaspora_handle;
|
||||
|
||||
if(isset($contact_uprvkey))
|
||||
$authorsig = base64_encode(rsa_sign($signed_text,$contact_uprvkey,'sha256'));
|
||||
|
||||
@@ -42,6 +42,7 @@ if(!function_exists('z_fetch_url')){
|
||||
* @return array an assoziative array with:
|
||||
* * \e int \b return_code => HTTP return code or 0 if timeout or failure
|
||||
* * \e boolean \b success => boolean true (if HTTP 2xx result) or false
|
||||
* * \e string \b redirect_url => in case of redirect, content was finally retrieved from this URL
|
||||
* * \e string \b header => HTTP headers
|
||||
* * \e string \b body => fetched content
|
||||
*/
|
||||
@@ -116,6 +117,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
|
||||
// if it throws any errors.
|
||||
|
||||
$s = @curl_exec($ch);
|
||||
if (curl_errno($ch) !== CURLE_OK) {
|
||||
logger('fetch_url error fetching '.$url.': '.curl_error($ch), LOGGER_NORMAL);
|
||||
}
|
||||
|
||||
$base = $s;
|
||||
$curl_info = @curl_getinfo($ch);
|
||||
@@ -133,6 +137,10 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
|
||||
$base = substr($base,strlen($chunk));
|
||||
}
|
||||
|
||||
$a->set_curl_code($http_code);
|
||||
$a->set_curl_content_type($curl_info['content_type']);
|
||||
$a->set_curl_headers($header);
|
||||
|
||||
if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
|
||||
$new_location_info = @parse_url($curl_info["redirect_url"]);
|
||||
$old_location_info = @parse_url($curl_info["url"]);
|
||||
@@ -160,13 +168,13 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
|
||||
$a->set_curl_content_type($curl_info['content_type']);
|
||||
|
||||
$body = substr($s,strlen($header));
|
||||
$a->set_curl_headers($header);
|
||||
|
||||
|
||||
|
||||
$rc = intval($http_code);
|
||||
$ret['return_code'] = $rc;
|
||||
$ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
|
||||
$ret['redirect_url'] = $url;
|
||||
if(! $ret['success']) {
|
||||
$ret['error'] = curl_error($ch);
|
||||
$ret['debug'] = $curl_info;
|
||||
@@ -1246,6 +1254,9 @@ function original_url($url, $depth=1, $fetchbody = false) {
|
||||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
if ($http_code == 0)
|
||||
return($url);
|
||||
|
||||
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
|
||||
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
|
||||
if ($curl_info['redirect_url'] != "")
|
||||
|
||||
@@ -535,7 +535,7 @@ function notifier_run(&$argv, &$argc){
|
||||
|
||||
if($public_message) {
|
||||
|
||||
if (!$followup)
|
||||
if (!$followup AND $top_level)
|
||||
$r0 = diaspora_fetch_relay();
|
||||
else
|
||||
$r0 = array();
|
||||
|
||||
@@ -13,7 +13,13 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$txt = Cache::get($a->videowidth . $embedurl);
|
||||
$r = q("SELECT * FROM `oembed` WHERE `url` = '%s'",
|
||||
dbesc(normalise_link($embedurl)));
|
||||
|
||||
if ($r)
|
||||
$txt = $r[0]["content"];
|
||||
else
|
||||
$txt = Cache::get($a->videowidth . $embedurl);
|
||||
|
||||
// These media files should now be caught in bbcode.php
|
||||
// left here as a fallback in case this is called from another source
|
||||
@@ -66,8 +72,14 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
|
||||
|
||||
if ($txt[0]!="{")
|
||||
$txt='{"type":"error"}';
|
||||
else //save in cache
|
||||
else { //save in cache
|
||||
$j = json_decode($txt);
|
||||
if ($j->type != "error")
|
||||
q("INSERT INTO `oembed` (`url`, `content`, `created`) VALUES ('%s', '%s', '%s')",
|
||||
dbesc(normalise_link($embedurl)), dbesc($txt), dbesc(datetime_convert()));
|
||||
|
||||
Cache::set($a->videowidth . $embedurl,$txt, CACHE_DAY);
|
||||
}
|
||||
}
|
||||
|
||||
$j = json_decode($txt);
|
||||
@@ -85,7 +97,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
|
||||
// If fetching information doesn't work, then improve via internal functions
|
||||
if (($j->type == "error") OR ($no_rich_type AND ($j->type == "rich"))) {
|
||||
require_once("mod/parse_url.php");
|
||||
$data = parseurl_getsiteinfo($embedurl, true, false);
|
||||
$data = parseurl_getsiteinfo_cached($embedurl, true, false);
|
||||
$j->type = $data["type"];
|
||||
|
||||
if ($j->type == "photo") {
|
||||
|
||||
@@ -27,7 +27,6 @@ function onepoll_run(&$argv, &$argc){
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
@@ -335,7 +334,9 @@ function onepoll_run(&$argv, &$argc){
|
||||
if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly'])
|
||||
return;
|
||||
|
||||
$xml = fetch_url($contact['poll']);
|
||||
$cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
|
||||
$xml = fetch_url($contact['poll'], false, $redirects, 0, Null, $cookiejar);
|
||||
unlink($cookiejar);
|
||||
}
|
||||
elseif($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) {
|
||||
|
||||
|
||||
@@ -17,15 +17,6 @@ define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
|
||||
define('OSTATUS_DEFAULT_POLL_TIMEFRAME', 1440); // given in minutes
|
||||
define('OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS', 14400); // given in minutes
|
||||
|
||||
define("NS_ATOM", "http://www.w3.org/2005/Atom");
|
||||
define("NS_THR", "http://purl.org/syndication/thread/1.0");
|
||||
define("NS_GEORSS", "http://www.georss.org/georss");
|
||||
define("NS_ACTIVITY", "http://activitystrea.ms/spec/1.0/");
|
||||
define("NS_MEDIA", "http://purl.org/syndication/atommedia");
|
||||
define("NS_POCO", "http://portablecontacts.net/spec/1.0");
|
||||
define("NS_OSTATUS", "http://ostatus.org/schema/1.0");
|
||||
define("NS_STATUSNET", "http://status.net/schema/api/1/");
|
||||
|
||||
function ostatus_check_follow_friends() {
|
||||
$r = q("SELECT `uid`,`v` FROM `pconfig` WHERE `cat`='system' AND `k`='ostatus_legacy_contact' AND `v` != ''");
|
||||
|
||||
@@ -127,47 +118,57 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
|
||||
$author["owner-link"] = $author["author-link"];
|
||||
$author["owner-avatar"] = $author["author-avatar"];
|
||||
|
||||
if ($r AND !$onlyfetch) {
|
||||
// Only update the contacts if it is an OStatus contact
|
||||
if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) {
|
||||
// Update contact data
|
||||
$update_contact = ($r[0]['name-date'] < datetime_convert('','','now -12 hours'));
|
||||
if ($update_contact) {
|
||||
|
||||
$value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["notify"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/uri/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["alias"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["name"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["nick"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["about"] = html2bbcode($value);
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["location"] = $value;
|
||||
|
||||
if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["location"] != $r[0]["location"])) {
|
||||
|
||||
logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["name"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["nick"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["about"] = html2bbcode($value);
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$contact["location"] = $value;
|
||||
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d",
|
||||
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]),
|
||||
dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
|
||||
dbesc(datetime_convert()), intval($contact["id"]));
|
||||
|
||||
poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"],
|
||||
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
|
||||
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
|
||||
}
|
||||
|
||||
$update_photo = ($r[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
|
||||
|
||||
if ($update_photo AND isset($author["author-avatar"])) {
|
||||
if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) {
|
||||
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
|
||||
|
||||
$photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]);
|
||||
|
||||
q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
|
||||
dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
|
||||
dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
|
||||
update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
|
||||
}
|
||||
|
||||
|
||||
/// @todo Add the "addr" field
|
||||
$contact["generation"] = 2;
|
||||
$contact["photo"] = $author["author-avatar"];
|
||||
update_gcontact($contact);
|
||||
}
|
||||
|
||||
return($author);
|
||||
@@ -183,14 +184,14 @@ function ostatus_salmon_author($xml, $importer) {
|
||||
@$doc->loadXML($xml);
|
||||
|
||||
$xpath = new DomXPath($doc);
|
||||
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
|
||||
$xpath->registerNamespace('thr', "http://purl.org/syndication/thread/1.0");
|
||||
$xpath->registerNamespace('georss', "http://www.georss.org/georss");
|
||||
$xpath->registerNamespace('activity', "http://activitystrea.ms/spec/1.0/");
|
||||
$xpath->registerNamespace('media', "http://purl.org/syndication/atommedia");
|
||||
$xpath->registerNamespace('poco', "http://portablecontacts.net/spec/1.0");
|
||||
$xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0");
|
||||
$xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/");
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
|
||||
$xpath->registerNamespace('georss', NAMESPACE_GEORSS);
|
||||
$xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
|
||||
$xpath->registerNamespace('media', NAMESPACE_MEDIA);
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
|
||||
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
|
||||
|
||||
$entries = $xpath->query('/atom:entry');
|
||||
|
||||
@@ -214,14 +215,14 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
|
||||
@$doc->loadXML($xml);
|
||||
|
||||
$xpath = new DomXPath($doc);
|
||||
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
|
||||
$xpath->registerNamespace('thr', "http://purl.org/syndication/thread/1.0");
|
||||
$xpath->registerNamespace('georss', "http://www.georss.org/georss");
|
||||
$xpath->registerNamespace('activity', "http://activitystrea.ms/spec/1.0/");
|
||||
$xpath->registerNamespace('media', "http://purl.org/syndication/atommedia");
|
||||
$xpath->registerNamespace('poco', "http://portablecontacts.net/spec/1.0");
|
||||
$xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0");
|
||||
$xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/");
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
|
||||
$xpath->registerNamespace('georss', NAMESPACE_GEORSS);
|
||||
$xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
|
||||
$xpath->registerNamespace('media', NAMESPACE_MEDIA);
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
|
||||
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
|
||||
|
||||
$gub = "";
|
||||
$hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes;
|
||||
@@ -546,29 +547,6 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
|
||||
}
|
||||
|
||||
logger("Item was stored with id ".$item_id, LOGGER_DEBUG);
|
||||
$item["id"] = $item_id;
|
||||
|
||||
if ($mention) {
|
||||
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid']));
|
||||
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($item_id));
|
||||
|
||||
notification(array(
|
||||
'type' => NOTIFY_TAGSELF,
|
||||
'notify_flags' => $u[0]["notify-flags"],
|
||||
'language' => $u[0]["language"],
|
||||
'to_name' => $u[0]["username"],
|
||||
'to_email' => $u[0]["email"],
|
||||
'uid' => $item["uid"],
|
||||
'item' => $item,
|
||||
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item_id)),
|
||||
'source_name' => $item["author-name"],
|
||||
'source_link' => $item["author-link"],
|
||||
'source_photo' => $item["author-avatar"],
|
||||
'verb' => ACTIVITY_TAG,
|
||||
'otype' => 'item',
|
||||
'parent' => $r[0]["parent"]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1013,28 +991,6 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
|
||||
// Add the conversation entry (but don't fetch the whole conversation)
|
||||
ostatus_store_conversation($newitem, $conversation_url);
|
||||
|
||||
if ($mention) {
|
||||
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($uid));
|
||||
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($newitem));
|
||||
|
||||
notification(array(
|
||||
'type' => NOTIFY_TAGSELF,
|
||||
'notify_flags' => $u[0]["notify-flags"],
|
||||
'language' => $u[0]["language"],
|
||||
'to_name' => $u[0]["username"],
|
||||
'to_email' => $u[0]["email"],
|
||||
'uid' => $uid,
|
||||
'item' => $arr,
|
||||
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($newitem)),
|
||||
'source_name' => $arr["author-name"],
|
||||
'source_link' => $arr["author-link"],
|
||||
'source_photo' => $arr["author-avatar"],
|
||||
'verb' => ACTIVITY_TAG,
|
||||
'otype' => 'item',
|
||||
'parent' => $r[0]["parent"]
|
||||
));
|
||||
}
|
||||
|
||||
// If the newly created item is the top item then change the parent settings of the thread
|
||||
// This shouldn't happen anymore. This is supposed to be absolote.
|
||||
if ($arr["uri"] == $first_id) {
|
||||
@@ -1109,7 +1065,7 @@ function get_reshared_guid($item) {
|
||||
return $guid;
|
||||
}
|
||||
|
||||
function xml_add_element($doc, $parent, $element, $value = "", $attributes = array()) {
|
||||
function xml_create_element($doc, $element, $value = "", $attributes = array()) {
|
||||
$element = $doc->createElement($element, xmlify($value));
|
||||
|
||||
foreach ($attributes AS $key => $value) {
|
||||
@@ -1117,7 +1073,11 @@ function xml_add_element($doc, $parent, $element, $value = "", $attributes = arr
|
||||
$attribute->value = xmlify($value);
|
||||
$element->appendChild($attribute);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
function xml_add_element($doc, $parent, $element, $value = "", $attributes = array()) {
|
||||
$element = xml_create_element($doc, $element, $value, $attributes);
|
||||
$parent->appendChild($element);
|
||||
}
|
||||
|
||||
@@ -1151,16 +1111,16 @@ function ostatus_format_picture_post($body) {
|
||||
function ostatus_add_header($doc, $owner) {
|
||||
$a = get_app();
|
||||
|
||||
$root = $doc->createElementNS(NS_ATOM, 'feed');
|
||||
$root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
|
||||
$doc->appendChild($root);
|
||||
|
||||
$root->setAttribute("xmlns:thr", NS_THR);
|
||||
$root->setAttribute("xmlns:georss", NS_GEORSS);
|
||||
$root->setAttribute("xmlns:activity", NS_ACTIVITY);
|
||||
$root->setAttribute("xmlns:media", NS_MEDIA);
|
||||
$root->setAttribute("xmlns:poco", NS_POCO);
|
||||
$root->setAttribute("xmlns:ostatus", NS_OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", NS_STATUSNET);
|
||||
$root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
|
||||
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
|
||||
xml_add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
|
||||
@@ -1352,6 +1312,10 @@ function ostatus_add_author($doc, $owner) {
|
||||
function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false) {
|
||||
$a = get_app();
|
||||
|
||||
if (($item["id"] != $item["parent"]) AND (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
$is_repeat = false;
|
||||
|
||||
/* if (!$repeat) {
|
||||
@@ -1374,15 +1338,15 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false)
|
||||
$entry = $doc->createElement("activity:object");
|
||||
$title = sprintf("New note by %s", $owner["nick"]);
|
||||
} else {
|
||||
$entry = $doc->createElementNS(NS_ATOM, "entry");
|
||||
$entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
|
||||
|
||||
$entry->setAttribute("xmlns:thr", NS_THR);
|
||||
$entry->setAttribute("xmlns:georss", NS_GEORSS);
|
||||
$entry->setAttribute("xmlns:activity", NS_ACTIVITY);
|
||||
$entry->setAttribute("xmlns:media", NS_MEDIA);
|
||||
$entry->setAttribute("xmlns:poco", NS_POCO);
|
||||
$entry->setAttribute("xmlns:ostatus", NS_OSTATUS);
|
||||
$entry->setAttribute("xmlns:statusnet", NS_STATUSNET);
|
||||
$entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
|
||||
$author = ostatus_add_author($doc, $owner);
|
||||
$entry->appendChild($author);
|
||||
@@ -1447,9 +1411,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false)
|
||||
$repeated_owner["about"] = "";
|
||||
$repeated_owner["uid"] = 0;
|
||||
|
||||
$r =q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($repeated_item["author-link"]));
|
||||
// Fetch the missing data from the global contacts
|
||||
$r =q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($repeated_item["author-link"]));
|
||||
if ($r) {
|
||||
$repeated_owner["nick"] = $r[0]["nick"];
|
||||
if ($r[0]["nick"] != "")
|
||||
$repeated_owner["nick"] = $r[0]["nick"];
|
||||
|
||||
$repeated_owner["location"] = $r[0]["location"];
|
||||
$repeated_owner["about"] = $r[0]["about"];
|
||||
}
|
||||
|
||||
@@ -90,6 +90,14 @@ function get_attached_data($body) {
|
||||
$post["text"] = $body;
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match_all("(\[url\]([$URLSearchString]*)\[\/url\])ism", $body, $links, PREG_SET_ORDER)) {
|
||||
if (count($links) == 1) {
|
||||
$post["type"] = "text";
|
||||
$post["url"] = $links[0][1];
|
||||
$post["text"] = $body;
|
||||
}
|
||||
}
|
||||
if (!isset($post["type"])) {
|
||||
$post["type"] = "text";
|
||||
$post["text"] = trim($body);
|
||||
@@ -129,9 +137,17 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
||||
require_once("include/html2plain.php");
|
||||
require_once("include/network.php");
|
||||
|
||||
// Remove the hash tags
|
||||
$URLSearchString = "^\[\]";
|
||||
$body = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $b["body"]);
|
||||
|
||||
// Add an URL element if the text contains a raw link
|
||||
$body = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2[/url]', $body);
|
||||
|
||||
// At first look at data that is attached via "type-..." stuff
|
||||
// This will hopefully replaced with a dedicated bbcode later
|
||||
$post = get_attached_data($b["body"]);
|
||||
//$post = get_attached_data($b["body"]);
|
||||
$post = get_attached_data($body);
|
||||
|
||||
if (($b["title"] != "") AND ($post["text"] != ""))
|
||||
$post["text"] = trim($b["title"]."\n\n".$post["text"]);
|
||||
@@ -146,6 +162,8 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
||||
if ($includedlinks) {
|
||||
if ($post["type"] == "link")
|
||||
$link = $post["url"];
|
||||
elseif ($post["type"] == "text")
|
||||
$link = $post["url"];
|
||||
elseif ($post["type"] == "video")
|
||||
$link = $post["url"];
|
||||
elseif ($post["type"] == "photo")
|
||||
@@ -161,8 +179,22 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
||||
// But: if the link is beyond the limit, then it has to be added.
|
||||
if (($link != "") AND strstr($msg, $link)) {
|
||||
$pos = strpos($msg, $link);
|
||||
if (($limit == 0) OR ($pos < $limit))
|
||||
|
||||
// Will the text be shortened in the link?
|
||||
// Or is the link the last item in the post?
|
||||
if (($limit > 0) AND ($pos < $limit) AND (($pos + 23 > $limit) OR ($pos + strlen($link) == strlen($msg))))
|
||||
$msg = trim(str_replace($link, "", $msg));
|
||||
elseif (($limit == 0) OR ($pos < $limit)) {
|
||||
// The limit has to be increased since it will be shortened - but not now
|
||||
// Only do it with Twitter (htmlmode = 8)
|
||||
if (($limit > 0) AND (strlen($link) > 23) AND ($htmlmode == 8))
|
||||
$limit = $limit - 23 + strlen($link);
|
||||
|
||||
$link = "";
|
||||
|
||||
if ($post["type"] == "text")
|
||||
unset($post["url"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +210,9 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
||||
|
||||
if (iconv_strlen($msg, "UTF-8") > $limit) {
|
||||
|
||||
if (!isset($post["url"])) {
|
||||
if (($post["type"] == "text") AND isset($post["url"]))
|
||||
$post["url"] = $b["plink"];
|
||||
elseif (!isset($post["url"])) {
|
||||
$limit = $limit - 23;
|
||||
$post["url"] = $b["plink"];
|
||||
} elseif (strpos($b["body"], "[share") !== false)
|
||||
|
||||
@@ -26,6 +26,9 @@ function poller_run(&$argv, &$argc){
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
if (poller_max_connections_reached())
|
||||
return;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
@@ -39,8 +42,10 @@ function poller_run(&$argv, &$argc){
|
||||
}
|
||||
|
||||
// Checking the number of workers
|
||||
if (poller_too_much_workers(1))
|
||||
if (poller_too_much_workers(1)) {
|
||||
poller_kill_stale_workers();
|
||||
return;
|
||||
}
|
||||
|
||||
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
|
||||
// Run the cron job that calls all other jobs
|
||||
@@ -50,16 +55,7 @@ function poller_run(&$argv, &$argc){
|
||||
proc_run("php","include/cronhooks.php");
|
||||
|
||||
// Cleaning dead processes
|
||||
$r = q("SELECT DISTINCT(`pid`) FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
|
||||
foreach($r AS $pid)
|
||||
if (!posix_kill($pid["pid"], 0))
|
||||
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
|
||||
intval($pid["pid"]));
|
||||
else {
|
||||
/// @TODO Kill long running processes
|
||||
/// But: Update processes (like the database update) mustn't be killed
|
||||
}
|
||||
|
||||
poller_kill_stale_workers();
|
||||
} else
|
||||
// Sleep four seconds before checking for running processes again to avoid having too many workers
|
||||
sleep(4);
|
||||
@@ -72,6 +68,10 @@ function poller_run(&$argv, &$argc){
|
||||
|
||||
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) {
|
||||
|
||||
// Constantly check the number of available database connections to let the frontend be accessible at any time
|
||||
if (poller_max_connections_reached())
|
||||
return;
|
||||
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (poller_too_much_workers(3))
|
||||
return;
|
||||
@@ -124,6 +124,107 @@ function poller_run(&$argv, &$argc){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the number of database connections has reached a critical limit.
|
||||
*
|
||||
* @return bool Are more than 3/4 of the maximum connections used?
|
||||
*/
|
||||
function poller_max_connections_reached() {
|
||||
|
||||
// Fetch the max value from the config. This is needed when the system cannot detect the correct value by itself.
|
||||
$max = get_config("system", "max_connections");
|
||||
|
||||
if ($max == 0) {
|
||||
// the maximum number of possible user connections can be a system variable
|
||||
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
|
||||
if ($r)
|
||||
$max = $r[0]["Value"];
|
||||
|
||||
// Or it can be granted. This overrides the system variable
|
||||
$r = q("SHOW GRANTS");
|
||||
if ($r)
|
||||
foreach ($r AS $grants) {
|
||||
$grant = array_pop($grants);
|
||||
if (stristr($grant, "GRANT USAGE ON"))
|
||||
if (preg_match("/WITH MAX_USER_CONNECTIONS (\d*)/", $grant, $match))
|
||||
$max = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// If $max is set we will use the processlist to determine the current number of connections
|
||||
// The processlist only shows entries of the current user
|
||||
if ($max != 0) {
|
||||
$r = q("SHOW PROCESSLIST");
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$used = count($r);
|
||||
|
||||
logger("Connection usage (user values): ".$used."/".$max, LOGGER_DEBUG);
|
||||
|
||||
$level = $used / $max;
|
||||
|
||||
if ($level >= (3/4)) {
|
||||
logger("Maximum level (3/4) of user connections reached: ".$used."/".$max);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// We will now check for the system values.
|
||||
// This limit could be reached although the user limits are fine.
|
||||
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$max = intval($r[0]["Value"]);
|
||||
if ($max == 0)
|
||||
return false;
|
||||
|
||||
$r = q("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$used = intval($r[0]["Value"]);
|
||||
if ($used == 0)
|
||||
return false;
|
||||
|
||||
logger("Connection usage (system values): ".$used."/".$max, LOGGER_DEBUG);
|
||||
|
||||
$level = $used / $max;
|
||||
|
||||
if ($level < (3/4))
|
||||
return false;
|
||||
|
||||
logger("Maximum level (3/4) of system connections reached: ".$used."/".$max);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fix the queue entry if the worker process died
|
||||
*
|
||||
*/
|
||||
function poller_kill_stale_workers() {
|
||||
$r = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
|
||||
foreach($r AS $pid)
|
||||
if (!posix_kill($pid["pid"], 0))
|
||||
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
|
||||
intval($pid["pid"]));
|
||||
else {
|
||||
// Kill long running processes
|
||||
$duration = (time() - strtotime($pid["executed"])) / 60;
|
||||
if ($duration > 180) {
|
||||
logger("Worker process ".$pid["pid"]." took more than 3 hours. It will be killed now.");
|
||||
posix_kill($pid["pid"], SIGTERM);
|
||||
|
||||
// Question: If a process is stale: Should we remove it or should we reschedule it?
|
||||
// By now we rescheduling it. It's maybe not the wisest decision?
|
||||
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
|
||||
intval($pid["pid"]));
|
||||
} else
|
||||
logger("Worker process ".$pid["pid"]." now runs for ".round($duration)." minutes. That's okay.", LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
function poller_too_much_workers($stage) {
|
||||
|
||||
$queues = get_config("system", "worker_queues");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/diaspora.php');
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
function profile_change() {
|
||||
|
||||
@@ -53,19 +54,7 @@ function profile_change() {
|
||||
$about = xmlify($profile['about']);
|
||||
require_once('include/bbcode.php');
|
||||
$about = xmlify(strip_tags(bbcode($about)));
|
||||
$location = '';
|
||||
if($profile['locality'])
|
||||
$location .= $profile['locality'];
|
||||
if($profile['region']) {
|
||||
if($location)
|
||||
$location .= ', ';
|
||||
$location .= $profile['region'];
|
||||
}
|
||||
if($profile['country-name']) {
|
||||
if($location)
|
||||
$location .= ', ';
|
||||
$location .= $profile['country-name'];
|
||||
}
|
||||
$location = formatted_location($profile);
|
||||
$location = xmlify($location);
|
||||
$tags = '';
|
||||
if($profile['pub_keywords']) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/dfrn.php');
|
||||
|
||||
function queue_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
@@ -52,6 +53,8 @@ function queue_run(&$argv, &$argc){
|
||||
$queue_id = 0;
|
||||
|
||||
$deadguys = array();
|
||||
$deadservers = array();
|
||||
$serverlist = array();
|
||||
|
||||
logger('queue: start');
|
||||
|
||||
@@ -95,7 +98,7 @@ function queue_run(&$argv, &$argc){
|
||||
// For the first 12 hours we'll try to deliver every 15 minutes
|
||||
// After that, we'll only attempt delivery once per hour.
|
||||
|
||||
$r = q("SELECT `id` FROM `queue` WHERE (( `created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( `last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR ))");
|
||||
$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
|
||||
}
|
||||
if(! $r){
|
||||
return;
|
||||
@@ -116,7 +119,7 @@ function queue_run(&$argv, &$argc){
|
||||
// so check again if this entry still needs processing
|
||||
|
||||
if($queue_id) {
|
||||
$qi = q("select * from queue where `id` = %d limit 1",
|
||||
$qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id)
|
||||
);
|
||||
}
|
||||
@@ -142,8 +145,18 @@ function queue_run(&$argv, &$argc){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!poco_reachable($c[0]['url'])) {
|
||||
logger('queue: skipping probably dead url: ' . $c[0]['url']);
|
||||
$server = poco_detect_server($c[0]['url']);
|
||||
|
||||
if (($server != "") AND !in_array($server, $serverlist)) {
|
||||
logger("Check server ".$server." (".$c[0]["network"].")");
|
||||
if (!poco_check_server($server, $c[0]["network"], true))
|
||||
$deadservers[] = $server;
|
||||
|
||||
$serverlist[] = $server;
|
||||
}
|
||||
|
||||
if (($server != "") AND in_array($server, $deadservers)) {
|
||||
logger('queue: skipping known dead server: '.$server);
|
||||
update_queue_time($q_item['id']);
|
||||
continue;
|
||||
}
|
||||
@@ -166,37 +179,39 @@ function queue_run(&$argv, &$argc){
|
||||
|
||||
switch($contact['network']) {
|
||||
case NETWORK_DFRN:
|
||||
logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
|
||||
$deliver_status = dfrn_deliver($owner,$contact,$data);
|
||||
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = dfrn::deliver($owner,$contact,$data);
|
||||
|
||||
if($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
$deadguys[] = $contact['notify'];
|
||||
}
|
||||
else {
|
||||
} else
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
|
||||
break;
|
||||
case NETWORK_OSTATUS:
|
||||
if($contact['notify']) {
|
||||
logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
|
||||
logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = slapper($owner,$contact['notify'],$data);
|
||||
|
||||
if($deliver_status == (-1))
|
||||
if($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
else
|
||||
$deadguys[] = $contact['notify'];
|
||||
} else
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
break;
|
||||
case NETWORK_DIASPORA:
|
||||
if($contact['notify']) {
|
||||
logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
|
||||
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = diaspora_transmit($owner,$contact,$data,$public,true);
|
||||
|
||||
if($deliver_status == (-1))
|
||||
if($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
else
|
||||
$deadguys[] = $contact['notify'];
|
||||
} else
|
||||
remove_queue_item($q_item['id']);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -212,6 +227,7 @@ function queue_run(&$argv, &$argc){
|
||||
break;
|
||||
|
||||
}
|
||||
logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
<?php
|
||||
/* update friendica */
|
||||
define('APIBASE', 'http://github.com/api/v2/');
|
||||
define('F9KREPO', 'friendica/friendica');
|
||||
|
||||
$up_totalfiles = 0;
|
||||
$up_countfiles = 0;
|
||||
$up_lastp = -1;
|
||||
|
||||
function checkUpdate(){
|
||||
$r = fetch_url( APIBASE."json/repos/show/".F9KREPO."/tags" );
|
||||
$tags = json_decode($r);
|
||||
|
||||
$tag = 0.0;
|
||||
foreach ($tags->tags as $i=>$v){
|
||||
$i = (float)$i;
|
||||
if ($i>$tag) $tag=$i;
|
||||
}
|
||||
|
||||
if ($tag==0.0) return false;
|
||||
$f = fetch_url("https://raw.github.com/".F9KREPO."/".$tag."/boot.php","r");
|
||||
preg_match("|'FRIENDICA_VERSION', *'([^']*)'|", $f, $m);
|
||||
$version = $m[1];
|
||||
|
||||
$lv = explode(".", FRIENDICA_VERSION);
|
||||
$rv = explode(".",$version);
|
||||
foreach($lv as $i=>$v){
|
||||
if ((int)$lv[$i] < (int)$rv[$i]) {
|
||||
return array($tag, $version, "https://github.com/friendica/friendica/zipball/".$tag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function canWeWrite(){
|
||||
$bd = dirname(dirname(__file__));
|
||||
return is_writable( $bd."/boot.php" );
|
||||
}
|
||||
|
||||
function out($txt){ echo "§".$txt."§"; ob_end_flush(); flush();}
|
||||
|
||||
function up_count($path){
|
||||
|
||||
$file_count = 0;
|
||||
|
||||
$dir_handle = opendir($path);
|
||||
|
||||
if (!$dir_handle) return -1;
|
||||
|
||||
while ($file = readdir($dir_handle)) {
|
||||
|
||||
if ($file == '.' || $file == '..') continue;
|
||||
$file_count++;
|
||||
|
||||
if (is_dir($path . $file)){
|
||||
$file_count += up_count($path . $file . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
closedir($dir_handle);
|
||||
|
||||
return $file_count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function up_unzip($file, $folder="/tmp"){
|
||||
$folder.="/";
|
||||
$zip = zip_open($file);
|
||||
if ($zip) {
|
||||
while ($zip_entry = zip_read($zip)) {
|
||||
$zip_entry_name = zip_entry_name($zip_entry);
|
||||
if (substr($zip_entry_name,strlen($zip_entry_name)-1,1)=="/"){
|
||||
mkdir($folder.$zip_entry_name,0777, true);
|
||||
} else {
|
||||
$fp = fopen($folder.$zip_entry_name, "w");
|
||||
if (zip_entry_open($zip, $zip_entry, "r")) {
|
||||
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
|
||||
fwrite($fp,"$buf");
|
||||
zip_entry_close($zip_entry);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
zip_close($zip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk recoursively in a folder and call a callback function on every
|
||||
* dir entry.
|
||||
* args:
|
||||
* $dir string base dir to walk
|
||||
* $callback function callback function
|
||||
* $sort int 0: ascending, 1: descending
|
||||
* $cb_argv any extra value passed to callback
|
||||
*
|
||||
* callback signature:
|
||||
* function name($fn, $dir [, $argv])
|
||||
* $fn string full dir entry name
|
||||
* $dir string start dir path
|
||||
* $argv any user value to callback
|
||||
*
|
||||
*/
|
||||
function up_walktree($dir, $callback=Null, $sort=0, $cb_argv=Null , $startdir=Null){
|
||||
if (is_null($callback)) return;
|
||||
if (is_null($startdir)) $startdir = $dir;
|
||||
$res = scandir($dir, $sort);
|
||||
foreach($res as $i=>$v){
|
||||
if ($v!="." && $v!=".."){
|
||||
$fn = $dir."/".$v;
|
||||
if ($sort==0) $callback($fn, $startdir, $cb_argv);
|
||||
if (is_dir($fn)) up_walktree($fn, $callback, $sort, $cb_argv, $startdir);
|
||||
if ($sort==1) $callback($fn, $startdir, $cb_argv);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function up_copy($fn, $dir){
|
||||
global $up_countfiles, $up_totalfiles, $up_lastp;
|
||||
$up_countfiles++; $prc=(int)(((float)$up_countfiles/(float)$up_totalfiles)*100);
|
||||
|
||||
if (strpos($fn, ".gitignore")>-1 || strpos($fn, ".htaccess")>-1) return;
|
||||
$ddest = dirname(dirname(__file__));
|
||||
$fd = str_replace($dir, $ddest, $fn);
|
||||
|
||||
if (is_dir($fn) && !is_dir($fd)) {
|
||||
$re=mkdir($fd,0777,true);
|
||||
}
|
||||
if (!is_dir($fn)){
|
||||
$re=copy($fn, $fd);
|
||||
}
|
||||
|
||||
if ($re===false) {
|
||||
out("ERROR. Abort.");
|
||||
killme();
|
||||
}
|
||||
out("copy@Copy@$prc%");
|
||||
}
|
||||
|
||||
function up_ftp($fn, $dir, $argv){
|
||||
global $up_countfiles, $up_totalfiles, $up_lastp;
|
||||
$up_countfiles++; $prc=(int)(((float)$up_countfiles/(float)$up_totalfiles)*100);
|
||||
|
||||
if (strpos($fn, ".gitignore")>-1 || strpos($fn, ".htaccess")>-1) return;
|
||||
|
||||
list($ddest, $conn_id) = $argv;
|
||||
$l = strlen($ddest)-1;
|
||||
if (substr($ddest,$l,1)=="/") $ddest = substr($ddest,0,$l);
|
||||
$fd = str_replace($dir, $ddest, $fn);
|
||||
|
||||
if (is_dir($fn)){
|
||||
if (ftp_nlist($conn_id, $fd)===false) {
|
||||
$ret = ftp_mkdir($conn_id, $fd);
|
||||
} else {
|
||||
$ret=true;
|
||||
}
|
||||
} else {
|
||||
$ret = ftp_put($conn_id, $fd, $fn, FTP_BINARY);
|
||||
}
|
||||
if (!$ret) {
|
||||
out("ERROR. Abort.");
|
||||
killme();
|
||||
}
|
||||
out("copy@Copy@$prc%");
|
||||
}
|
||||
|
||||
function up_rm($fn, $dir){
|
||||
if (is_dir($fn)){
|
||||
rmdir($fn);
|
||||
} else {
|
||||
unlink($fn);
|
||||
}
|
||||
}
|
||||
|
||||
function up_dlfile($url, $file) {
|
||||
$in = fopen ($url, "r");
|
||||
$out = fopen ($file, "w");
|
||||
|
||||
$fs = filesize($url);
|
||||
|
||||
|
||||
if (!$in || !$out) return false;
|
||||
|
||||
$s=0; $count=0;
|
||||
while (!feof ($in)) {
|
||||
$line = fgets ($in, 1024);
|
||||
fwrite( $out, $line);
|
||||
|
||||
$count++; $s += strlen($line);
|
||||
if ($count==50){
|
||||
$count=0;
|
||||
$sp=$s/1024.0; $ex="Kb";
|
||||
if ($sp>1024) { $sp=$sp/1024; $ex="Mb"; }
|
||||
if ($sp>1024) { $sp=$sp/1024; $ex="Gb"; }
|
||||
$sp = ((int)($sp*100))/100;
|
||||
out("dwl@Download@".$sp.$ex);
|
||||
}
|
||||
}
|
||||
fclose($in);
|
||||
return true;
|
||||
}
|
||||
|
||||
function doUpdate($remotefile, $ftpdata=false){
|
||||
global $up_totalfiles;
|
||||
|
||||
|
||||
$localtmpfile = tempnam("/tmp", "fk");
|
||||
out("dwl@Download@starting...");
|
||||
$rt= up_dlfile($remotefile, $localtmpfile);
|
||||
if ($rt==false || filesize($localtmpfile)==0){
|
||||
out("dwl@Download@ERROR.");
|
||||
unlink($localtmpfile);
|
||||
return;
|
||||
}
|
||||
out("dwl@Download@Ok.");
|
||||
|
||||
out("unzip@Unzip@");
|
||||
$tmpdirname = $localfile."ex";
|
||||
mkdir($tmpdirname);
|
||||
up_unzip($localtmpfile, $tmpdirname);
|
||||
$basedir = glob($tmpdirname."/*"); $basedir=$basedir[0];
|
||||
out ("unzip@Unzip@Ok.");
|
||||
|
||||
$up_totalfiles = up_count($basedir."/");
|
||||
|
||||
if (canWeWrite()){
|
||||
out("copy@Copy@");
|
||||
up_walktree($basedir, 'up_copy');
|
||||
}
|
||||
if ($ftpdata!==false && is_array($ftpdata) && $ftpdata['ftphost']!="" ){
|
||||
out("ftpcon@Connect to FTP@");
|
||||
$conn_id = ftp_connect($ftpdata['ftphost']);
|
||||
$login_result = ftp_login($conn_id, $ftpdata['ftpuser'], $ftpdata['ftppwd']);
|
||||
|
||||
if ((!$conn_id) || (!$login_result)) {
|
||||
out("ftpcon@Connect to FTP@FAILED");
|
||||
up_clean($tmpdirname, $localtmpfile);
|
||||
return;
|
||||
} else {
|
||||
out("ftpcon@Connect to FTP@Ok.");
|
||||
}
|
||||
out("copy@Copy@");
|
||||
up_walktree($basedir, 'up_ftp', 0, array( $ftpdata['ftppath'], $conn_id));
|
||||
|
||||
ftp_close($conn_id);
|
||||
}
|
||||
|
||||
up_clean($tmpdirname, $localtmpfile);
|
||||
|
||||
}
|
||||
|
||||
function up_clean($tmpdirname, $localtmpfile){
|
||||
out("clean@Clean up@");
|
||||
unlink($localtmpfile);
|
||||
up_walktree($tmpdirname, 'up_rm', 1);
|
||||
rmdir($tmpdirname);
|
||||
out("clean@Clean up@Ok.");
|
||||
}
|
||||
@@ -139,15 +139,16 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
||||
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid, $uid, $zcid);
|
||||
|
||||
// Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
|
||||
if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
|
||||
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
|
||||
WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
|
||||
dbesc($location),
|
||||
dbesc($about),
|
||||
dbesc($keywords),
|
||||
dbesc($gender),
|
||||
dbesc(normalise_link($profile_url)),
|
||||
dbesc(NETWORK_DFRN));
|
||||
// Deactivated because we now update Friendica contacts in dfrn.php
|
||||
//if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
|
||||
// q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
|
||||
// WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
|
||||
// dbesc($location),
|
||||
// dbesc($about),
|
||||
// dbesc($keywords),
|
||||
// dbesc($gender),
|
||||
// dbesc(normalise_link($profile_url)),
|
||||
// dbesc(NETWORK_DFRN));
|
||||
}
|
||||
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
|
||||
|
||||
@@ -227,6 +228,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
$server_url = $x[0]["server_url"];
|
||||
$nick = $x[0]["nick"];
|
||||
$addr = $x[0]["addr"];
|
||||
$alias = $x[0]["alias"];
|
||||
$notify = $x[0]["notify"];
|
||||
} else {
|
||||
$created = "0000-00-00 00:00:00";
|
||||
$server_url = "";
|
||||
@@ -234,6 +237,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
$urlparts = parse_url($profile_url);
|
||||
$nick = end(explode("/", $urlparts["path"]));
|
||||
$addr = "";
|
||||
$alias = "";
|
||||
$notify = "";
|
||||
}
|
||||
|
||||
if ((($network == "") OR ($name == "") OR ($addr == "") OR ($profile_photo == "") OR ($server_url == "") OR $alternate)
|
||||
@@ -246,6 +251,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
$name = $data["name"];
|
||||
$nick = $data["nick"];
|
||||
$addr = $data["addr"];
|
||||
$alias = $data["alias"];
|
||||
$notify = $data["notify"];
|
||||
$profile_url = $data["url"];
|
||||
$profile_photo = $data["photo"];
|
||||
$server_url = $data["baseurl"];
|
||||
@@ -283,76 +290,25 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
|
||||
poco_check_server($server_url, $network);
|
||||
|
||||
if(count($x)) {
|
||||
$gcid = $x[0]['id'];
|
||||
$gcontact = array("url" => $profile_url,
|
||||
"addr" => $addr,
|
||||
"alias" => $alias,
|
||||
"name" => $name,
|
||||
"network" => $network,
|
||||
"photo" => $profile_photo,
|
||||
"about" => $about,
|
||||
"location" => $location,
|
||||
"gender" => $gender,
|
||||
"keywords" => $keywords,
|
||||
"server_url" => $server_url,
|
||||
"connect" => $connect_url,
|
||||
"notify" => $notify,
|
||||
"updated" => $updated,
|
||||
"generation" => $generation);
|
||||
|
||||
if (($location == "") AND ($x[0]['location'] != ""))
|
||||
$location = $x[0]['location'];
|
||||
$gcid = update_gcontact($gcontact);
|
||||
|
||||
if (($about == "") AND ($x[0]['about'] != ""))
|
||||
$about = $x[0]['about'];
|
||||
|
||||
if (($gender == "") AND ($x[0]['gender'] != ""))
|
||||
$gender = $x[0]['gender'];
|
||||
|
||||
if (($keywords == "") AND ($x[0]['keywords'] != ""))
|
||||
$keywords = $x[0]['keywords'];
|
||||
|
||||
if (($addr == "") AND ($x[0]['addr'] != ""))
|
||||
$addr = $x[0]['addr'];
|
||||
|
||||
if (($generation == 0) AND ($x[0]['generation'] > 0))
|
||||
$generation = $x[0]['generation'];
|
||||
|
||||
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
|
||||
q("UPDATE `gcontact` SET `name` = '%s', `addr` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `server_url` = '%s',
|
||||
`updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s', `generation` = %d
|
||||
WHERE (`generation` >= %d OR `generation` = 0) AND `nurl` = '%s'",
|
||||
dbesc($name),
|
||||
dbesc($addr),
|
||||
dbesc($network),
|
||||
dbesc($profile_photo),
|
||||
dbesc($connect_url),
|
||||
dbesc($profile_url),
|
||||
dbesc($server_url),
|
||||
dbesc($updated),
|
||||
dbesc($location),
|
||||
dbesc($about),
|
||||
dbesc($keywords),
|
||||
dbesc($gender),
|
||||
intval($generation),
|
||||
intval($generation),
|
||||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `generation`)
|
||||
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
|
||||
dbesc($name),
|
||||
dbesc($nick),
|
||||
dbesc($addr),
|
||||
dbesc($network),
|
||||
dbesc($profile_url),
|
||||
dbesc(normalise_link($profile_url)),
|
||||
dbesc($profile_photo),
|
||||
dbesc($connect_url),
|
||||
dbesc($server_url),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($updated),
|
||||
dbesc($location),
|
||||
dbesc($about),
|
||||
dbesc($keywords),
|
||||
dbesc($gender),
|
||||
intval($generation)
|
||||
);
|
||||
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
if(count($x))
|
||||
$gcid = $x[0]['id'];
|
||||
}
|
||||
|
||||
if(! $gcid)
|
||||
if(!$gcid)
|
||||
return $gcid;
|
||||
|
||||
$r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1",
|
||||
@@ -379,13 +335,6 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
);
|
||||
}
|
||||
|
||||
// For unknown reasons there are sometimes duplicates
|
||||
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND
|
||||
NOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)",
|
||||
dbesc(normalise_link($profile_url)),
|
||||
intval($gcid)
|
||||
);
|
||||
|
||||
return $gcid;
|
||||
}
|
||||
|
||||
@@ -698,6 +647,10 @@ function poco_to_boolean($val) {
|
||||
|
||||
function poco_check_server($server_url, $network = "", $force = false) {
|
||||
|
||||
// Unify the server address
|
||||
$server_url = trim($server_url, "/");
|
||||
$server_url = str_replace("/index.php", "", $server_url);
|
||||
|
||||
if ($server_url == "")
|
||||
return false;
|
||||
|
||||
@@ -769,17 +722,23 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
||||
// Test for Diaspora
|
||||
$serverret = z_fetch_url($server_url);
|
||||
|
||||
$lines = explode("\n",$serverret["header"]);
|
||||
if(count($lines))
|
||||
foreach($lines as $line) {
|
||||
$line = trim($line);
|
||||
if(stristr($line,'X-Diaspora-Version:')) {
|
||||
$platform = "Diaspora";
|
||||
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
|
||||
$version = trim(str_replace("x-diaspora-version:", "", $version));
|
||||
$network = NETWORK_DIASPORA;
|
||||
if (!$serverret["success"] OR ($serverret["body"] == ""))
|
||||
$failure = true;
|
||||
else {
|
||||
$lines = explode("\n",$serverret["header"]);
|
||||
if(count($lines))
|
||||
foreach($lines as $line) {
|
||||
$line = trim($line);
|
||||
if(stristr($line,'X-Diaspora-Version:')) {
|
||||
$platform = "Diaspora";
|
||||
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
|
||||
$version = trim(str_replace("x-diaspora-version:", "", $version));
|
||||
$network = NETWORK_DIASPORA;
|
||||
$versionparts = explode("-", $version);
|
||||
$version = $versionparts[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$failure) {
|
||||
@@ -1290,18 +1249,30 @@ function poco_discover_federation() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Discover Friendica, Hubzilla and Diaspora servers
|
||||
$serverdata = fetch_url("http://the-federation.info/pods.json");
|
||||
|
||||
if (!$serverdata)
|
||||
return;
|
||||
if ($serverdata) {
|
||||
$servers = json_decode($serverdata);
|
||||
|
||||
$servers = json_decode($serverdata);
|
||||
foreach($servers->pods AS $server)
|
||||
poco_check_server("https://".$server->host);
|
||||
}
|
||||
|
||||
foreach($servers->pods AS $server)
|
||||
poco_check_server("https://".$server->host);
|
||||
// Discover GNU Social Servers
|
||||
if (!get_config('system','ostatus_disabled')) {
|
||||
$serverdata = "http://gstools.org/api/get_open_instances/";
|
||||
|
||||
$result = z_fetch_url($serverdata);
|
||||
if ($result["success"]) {
|
||||
$servers = json_decode($result["body"]);
|
||||
|
||||
foreach($servers->data AS $server)
|
||||
poco_check_server($server->instance_address);
|
||||
}
|
||||
}
|
||||
|
||||
set_config('poco','last_federation_discovery', time());
|
||||
|
||||
}
|
||||
|
||||
function poco_discover($complete = false) {
|
||||
@@ -1481,4 +1452,214 @@ function poco_discover_server($data, $default_generation = 0) {
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fetch the gcontact id, add an entry if not existed
|
||||
*
|
||||
* @param arr $contact contact array
|
||||
* @return bool|int Returns false if not found, integer if contact was found
|
||||
*/
|
||||
function get_gcontact_id($contact) {
|
||||
|
||||
$gcontact_id = 0;
|
||||
|
||||
if ($contact["network"] == NETWORK_STATUSNET)
|
||||
$contact["network"] = NETWORK_OSTATUS;
|
||||
|
||||
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 2",
|
||||
dbesc(normalise_link($contact["url"])));
|
||||
|
||||
if ($r)
|
||||
$gcontact_id = $r[0]["id"];
|
||||
else {
|
||||
q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `generation`)
|
||||
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
|
||||
dbesc($contact["name"]),
|
||||
dbesc($contact["nick"]),
|
||||
dbesc($contact["addr"]),
|
||||
dbesc($contact["network"]),
|
||||
dbesc($contact["url"]),
|
||||
dbesc(normalise_link($contact["url"])),
|
||||
dbesc($contact["photo"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($contact["location"]),
|
||||
dbesc($contact["about"]),
|
||||
intval($contact["generation"])
|
||||
);
|
||||
|
||||
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 2",
|
||||
dbesc(normalise_link($contact["url"])));
|
||||
|
||||
if ($r)
|
||||
$gcontact_id = $r[0]["id"];
|
||||
}
|
||||
|
||||
if ((count($r) > 1) AND ($gcontact_id > 0) AND ($contact["url"] != ""))
|
||||
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d",
|
||||
dbesc(normalise_link($contact["url"])),
|
||||
intval($gcontact_id));
|
||||
|
||||
return $gcontact_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the gcontact table from a given array
|
||||
*
|
||||
* @param arr $contact contact array
|
||||
* @return bool|int Returns false if not found, integer if contact was found
|
||||
*/
|
||||
function update_gcontact($contact) {
|
||||
|
||||
/// @todo update contact table as well
|
||||
|
||||
$gcontact_id = get_gcontact_id($contact);
|
||||
|
||||
if (!$gcontact_id)
|
||||
return false;
|
||||
|
||||
$r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`,
|
||||
`hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url`
|
||||
FROM `gcontact` WHERE `id` = %d LIMIT 1",
|
||||
intval($gcontact_id));
|
||||
|
||||
// Get all field names
|
||||
$fields = array();
|
||||
foreach ($r[0] AS $field => $data)
|
||||
$fields[$field] = $data;
|
||||
|
||||
unset($fields["url"]);
|
||||
unset($fields["updated"]);
|
||||
|
||||
// assign all unassigned fields from the database entry
|
||||
foreach ($fields AS $field => $data)
|
||||
if (!isset($contact[$field]))
|
||||
$contact[$field] = $r[0][$field];
|
||||
|
||||
if ($contact["network"] == NETWORK_STATUSNET)
|
||||
$contact["network"] = NETWORK_OSTATUS;
|
||||
|
||||
if (!isset($contact["updated"]))
|
||||
$contact["updated"] = datetime_convert();
|
||||
|
||||
// Check if any field changed
|
||||
$update = false;
|
||||
unset($fields["generation"]);
|
||||
|
||||
foreach ($fields AS $field => $data)
|
||||
if ($contact[$field] != $r[0][$field])
|
||||
$update = true;
|
||||
|
||||
if ($contact["generation"] < $r[0]["generation"])
|
||||
$update = true;
|
||||
|
||||
if ($update) {
|
||||
q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s',
|
||||
`birthday` = '%s', `gender` = '%s', `keywords` = '%s', `hide` = %d, `nsfw` = %d,
|
||||
`alias` = '%s', `notify` = '%s', `url` = '%s',
|
||||
`location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s',
|
||||
`server_url` = '%s', `connect` = '%s'
|
||||
WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)",
|
||||
dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]),
|
||||
dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]),
|
||||
dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]),
|
||||
intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]),
|
||||
dbesc($contact["url"]), dbesc($contact["location"]), dbesc($contact["about"]),
|
||||
intval($contact["generation"]), dbesc($contact["updated"]),
|
||||
dbesc($contact["server_url"]), dbesc($contact["connect"]),
|
||||
dbesc(normalise_link($contact["url"])), intval($contact["generation"]));
|
||||
}
|
||||
|
||||
return $gcontact_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the gcontact entry from probe
|
||||
*
|
||||
* @param str $url profile link
|
||||
*/
|
||||
function update_gcontact_from_probe($url) {
|
||||
$data = probe_url($url);
|
||||
|
||||
if ($data["network"] != NETWORK_PHANTOM)
|
||||
update_gcontact($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fetches users of given GNU Social server
|
||||
*
|
||||
* If the "Statistics" plugin is enabled (See http://gstools.org/ for details) we query user data with this.
|
||||
*
|
||||
* @param str $server Server address
|
||||
*/
|
||||
function gs_fetch_users($server) {
|
||||
|
||||
logger("Fetching users from GNU Social server ".$server, LOGGER_DEBUG);
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$url = $server."/main/statistics";
|
||||
|
||||
$result = z_fetch_url($url);
|
||||
if (!$result["success"])
|
||||
return false;
|
||||
|
||||
$statistics = json_decode($result["body"]);
|
||||
|
||||
if (is_object($statistics->config)) {
|
||||
if ($statistics->config->instance_with_ssl)
|
||||
$server = "https://";
|
||||
else
|
||||
$server = "http://";
|
||||
|
||||
$server .= $statistics->config->instance_address;
|
||||
|
||||
$hostname = $statistics->config->instance_address;
|
||||
} else {
|
||||
if ($statistics->instance_with_ssl)
|
||||
$server = "https://";
|
||||
else
|
||||
$server = "http://";
|
||||
|
||||
$server .= $statistics->instance_address;
|
||||
|
||||
$hostname = $statistics->instance_address;
|
||||
}
|
||||
|
||||
if (is_object($statistics->users))
|
||||
foreach ($statistics->users AS $nick => $user) {
|
||||
$profile_url = $server."/".$user->nickname;
|
||||
|
||||
$contact = array("url" => $profile_url,
|
||||
"name" => $user->fullname,
|
||||
"addr" => $user->nickname."@".$hostname,
|
||||
"nick" => $user->nickname,
|
||||
"about" => $user->bio,
|
||||
"network" => NETWORK_OSTATUS,
|
||||
"photo" => $a->get_baseurl()."/images/person-175.jpg");
|
||||
get_gcontact_id($contact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Asking GNU Social server on a regular base for their user data
|
||||
*
|
||||
*/
|
||||
function gs_discover() {
|
||||
|
||||
$requery_days = intval(get_config("system", "poco_requery_days"));
|
||||
|
||||
$last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
|
||||
|
||||
$r = q("SELECT `nurl`, `url` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `network` = '%s' AND `last_poco_query` < '%s' ORDER BY RAND() LIMIT 5",
|
||||
dbesc(NETWORK_OSTATUS), dbesc($last_update));
|
||||
|
||||
if (!$r)
|
||||
return;
|
||||
|
||||
foreach ($r AS $server) {
|
||||
gs_fetch_users($server["url"]);
|
||||
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
102
include/text.php
102
include/text.php
@@ -20,10 +20,10 @@ function replace_macros($s,$r) {
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
||||
// pass $baseurl to all templates
|
||||
$r['$baseurl'] = z_root();
|
||||
|
||||
$r['$baseurl'] = $a->get_baseurl();
|
||||
|
||||
|
||||
$t = $a->template_engine();
|
||||
try {
|
||||
@@ -829,35 +829,6 @@ function qp($s) {
|
||||
return str_replace ("%","=",rawurlencode($s));
|
||||
}}
|
||||
|
||||
|
||||
|
||||
if(! function_exists('get_mentions')) {
|
||||
/**
|
||||
* @param array $item
|
||||
* @return string html for mentions #FIXME: remove html
|
||||
*/
|
||||
function get_mentions($item) {
|
||||
$o = '';
|
||||
if(! strlen($item['tag']))
|
||||
return $o;
|
||||
|
||||
$arr = explode(',',$item['tag']);
|
||||
foreach($arr as $x) {
|
||||
$matches = null;
|
||||
if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
|
||||
$o .= "\t\t" . '<link rel="ostatus:attention" href="' . $matches[1] . '" />' . "\r\n";
|
||||
$o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$item['private']) {
|
||||
$o .= "\t\t".'<link rel="ostatus:attention" href="http://activityschema.org/collection/public"/>'."\r\n";
|
||||
$o .= "\t\t".'<link rel="mentioned" href="http://activityschema.org/collection/public"/>'."\r\n";
|
||||
}
|
||||
|
||||
return $o;
|
||||
}}
|
||||
|
||||
if(! function_exists('contact_block')) {
|
||||
/**
|
||||
* Get html for contact block.
|
||||
@@ -895,9 +866,9 @@ function contact_block() {
|
||||
$micropro = Null;
|
||||
|
||||
} else {
|
||||
$r = q("SELECT * FROM `contact`
|
||||
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0
|
||||
AND `hidden` = 0 AND `archive` = 0
|
||||
$r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `micro`, `network` FROM `contact`
|
||||
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending`
|
||||
AND NOT `hidden` AND NOT `archive`
|
||||
AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d",
|
||||
intval($a->profile['uid']),
|
||||
dbesc(NETWORK_DFRN),
|
||||
@@ -1415,7 +1386,14 @@ function prepare_body(&$item,$attach = false, $preview = false) {
|
||||
$item['hashtags'] = $hashtags;
|
||||
$item['mentions'] = $mentions;
|
||||
|
||||
put_item_in_cache($item, true);
|
||||
// Update the cached values if there is no "zrl=..." on the links
|
||||
$update = (!local_user() and !remote_user() and ($item["uid"] == 0));
|
||||
|
||||
// Or update it if the current viewer is the intented viewer
|
||||
if (($item["uid"] == local_user()) AND ($item["uid"] != 0))
|
||||
$update = true;
|
||||
|
||||
put_item_in_cache($item, $update);
|
||||
$s = $item["rendered-html"];
|
||||
|
||||
$prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview);
|
||||
@@ -1526,7 +1504,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
|
||||
|
||||
$pos = strpos($s, $spoilersearch);
|
||||
$rnd = random_string(8);
|
||||
$spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
|
||||
$spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" class="spoiler-wrap fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
|
||||
'<blockquote class="spoiler" id="spoiler-'.$rnd.'" style="display: none;">';
|
||||
$s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
|
||||
}
|
||||
@@ -1538,7 +1516,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
|
||||
|
||||
$pos = strpos($s, $authorsearch);
|
||||
$rnd = random_string(8);
|
||||
$authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
|
||||
$authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" class="author-wrap fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
|
||||
'<blockquote class="author" id="author-'.$rnd.'" style="display: block;">';
|
||||
$s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
|
||||
}
|
||||
@@ -1650,54 +1628,6 @@ function get_cats_and_terms($item) {
|
||||
return array($categories, $folders);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(! function_exists('feed_hublinks')) {
|
||||
/**
|
||||
* return atom link elements for all of our hubs
|
||||
* @return string hub link xml elements
|
||||
*/
|
||||
function feed_hublinks() {
|
||||
$a = get_app();
|
||||
$hub = get_config('system','huburl');
|
||||
|
||||
$hubxml = '';
|
||||
if(strlen($hub)) {
|
||||
$hubs = explode(',', $hub);
|
||||
if(count($hubs)) {
|
||||
foreach($hubs as $h) {
|
||||
$h = trim($h);
|
||||
if(! strlen($h))
|
||||
continue;
|
||||
if ($h === '[internal]')
|
||||
$h = z_root() . '/pubsubhubbub';
|
||||
$hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $hubxml;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('feed_salmonlinks')) {
|
||||
/**
|
||||
* return atom link elements for salmon endpoints
|
||||
* @param string $nick user nickname
|
||||
* @return string salmon link xml elements
|
||||
*/
|
||||
function feed_salmonlinks($nick) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$salmon = '<link rel="salmon" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
|
||||
|
||||
// old style links that status.net still needed as of 12/2010
|
||||
|
||||
$salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
|
||||
$salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
|
||||
return $salmon;
|
||||
}}
|
||||
|
||||
if(! function_exists('get_plink')) {
|
||||
/**
|
||||
* get private link for item
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
function add_thread($itemid, $onlyshadow = false) {
|
||||
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`,
|
||||
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
||||
`deleted`, `origin`, `forum_mode`, `mention`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
|
||||
|
||||
if (!$items)
|
||||
@@ -66,6 +66,7 @@ function add_thread($itemid, $onlyshadow = false) {
|
||||
|
||||
unset($item[0]['id']);
|
||||
$item[0]['uid'] = 0;
|
||||
$item[0]['origin'] = 0;
|
||||
$item[0]['contact-id'] = get_contact($item[0]['author-link'], 0);
|
||||
$public_shadow = item_store($item[0], false, false, true);
|
||||
|
||||
@@ -111,8 +112,8 @@ function update_thread_uri($itemuri, $uid) {
|
||||
}
|
||||
|
||||
function update_thread($itemid, $setmention = false) {
|
||||
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`,
|
||||
`deleted`, `origin`, `forum_mode`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
|
||||
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
||||
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
|
||||
|
||||
if (!$items)
|
||||
return;
|
||||
@@ -125,7 +126,7 @@ function update_thread($itemid, $setmention = false) {
|
||||
$sql = "";
|
||||
|
||||
foreach ($item AS $field => $data)
|
||||
if (!in_array($field, array("guid", "title", "body"))) {
|
||||
if (!in_array($field, array("guid", "title", "body", "rendered-html", "rendered-hash"))) {
|
||||
if ($sql != "")
|
||||
$sql .= ", ";
|
||||
|
||||
@@ -142,9 +143,11 @@ function update_thread($itemid, $setmention = false) {
|
||||
if (!$items)
|
||||
return;
|
||||
|
||||
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s' WHERE `id` = %d",
|
||||
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
|
||||
dbesc($item["title"]),
|
||||
dbesc($item["body"]),
|
||||
dbesc($item["rendered-html"]),
|
||||
dbesc($item["rendered-hash"]),
|
||||
intval($items[0]["id"])
|
||||
);
|
||||
logger("Updating public shadow for post ".$items[0]["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
|
||||
|
||||
Reference in New Issue
Block a user