namespace Friendica\Protocol;
use Friendica\App;
+use Friendica\Content\OEmbed;
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
-use Friendica\Model\GlobalContact;
-use Friendica\Object\Contact;
-use Friendica\Object\Profile;
+use Friendica\Model\Contact;
+use Friendica\Model\GContact;
+use Friendica\Model\Group;
+use Friendica\Model\Profile;
+use Friendica\Model\Term;
+use Friendica\Model\User;
+use Friendica\Object\Image;
use Friendica\Protocol\OStatus;
use Friendica\Util\XML;
use dba;
use DOMDocument;
-use DomXPath;
+use DOMXPath;
+require_once 'boot.php';
+require_once 'include/dba.php';
require_once "include/enotify.php";
require_once "include/threads.php";
require_once "include/items.php";
require_once "include/tags.php";
-require_once "include/files.php";
require_once "include/event.php";
require_once "include/text.php";
-require_once "include/oembed.php";
require_once "include/html2bbcode.php";
require_once "include/bbcode.php";
$contact = $r[0];
include_once 'include/security.php';
- $groups = init_groups_visitor($contact['id']);
+ $groups = Group::getIdsByContactId($contact['id']);
if (count($groups)) {
for ($x = 0; $x < count($groups); $x ++)
$items = $r;
$item = $r[0];
- $r = q(
- "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
- FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `contact`.`self` AND `user`.`uid` = %d LIMIT 1",
- intval($item['uid'])
- );
-
- if (!DBM::is_result($r)) {
- killme();
+ if ($item['uid'] != 0) {
+ $owner = User::getOwnerDataById($item['uid']);
+ if (!$owner) {
+ killme();
+ }
+ } else {
+ $owner = ['uid' => 0, 'nick' => 'feed-item'];
}
- $owner = $r[0];
-
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$type = 'html';
/* get site pubkey. this could be a new installation with no site keys*/
$pubkey = Config::get('system', 'site_pubkey');
if (! $pubkey) {
- $res = new_keypair(1024);
+ $res = Crypto::newKeypair(1024);
Config::set('system', 'site_prvkey', $res['prvkey']);
Config::set('system', 'site_pubkey', $res['pubkey']);
}
$uid
);
$photos = array();
- $ext = Photo::supportedTypes();
+ $ext = Image::supportedTypes();
foreach ($rp as $p) {
$photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
case 2:
// RINO 2 based on php-encryption
try {
- $key = \Crypto::createNewRandomKey();
+ $key = \Crypto::CreateNewRandomKey();
} catch (\CryptoTestFailedException $ex) {
logger('Cannot safely create a key');
return -4;
return -5;
}
try {
- $data = \Crypto::encrypt($postvars['data'], $key);
+ $data = \Crypto::Encrypt($postvars['data'], $key);
} catch (\CryptoTestFailedException $ex) {
logger('Cannot safely perform encryption');
return -6;
* @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well
* @param string $xml optional, default empty
*
- * @return Returns an array with relevant data of the author
+ * @return array Relevant data of the author
* @todo Find good type-hints for all parameter
*/
private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "")
);
}
- update_contact_avatar(
+ Contact::updateAvatar(
$author["avatar"],
$importer["uid"],
$contact["id"],
$poco["photo"] = $author["avatar"];
$poco["hide"] = $hide;
$poco["contact-type"] = $contact["contact-type"];
- $gcid = GlobalContact::update($poco);
+ $gcid = GContact::update($poco);
- GlobalContact::link($gcid, $importer["uid"], $contact["id"]);
+ GContact::link($gcid, $importer["uid"], $contact["id"]);
}
return($author);
*
* @param object $xpath XPath object
* @param object $activity Activity object
- * @param text $element element name
+ * @param string $element element name
*
* @return string XML string
* @todo Find good type-hints for all parameter
dbesc(normalise_link($old["url"]))
);
- update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
+ Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
if ($x === false) {
return false;
/// @todo Do we really need this check for HTML elements? (It was copied from the old function)
if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) {
+ $base_url = get_app()->get_baseurl();
$item['body'] = reltoabs($item['body'], $base_url);
$item['body'] = html2bb_video($item['body']);
- $item['body'] = oembed_html2bbcode($item['body']);
+ $item['body'] = OEmbed::HTML2BBCode($item['body']);
- $config = HTMLPurifier_Config::createDefault();
+ $config = \HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
// we shouldn't need a whitelist, because the bbcode converter
// will strip out any unsupported tags.
- $purifier = new HTMLPurifier($config);
+ $purifier = new \HTMLPurifier($config);
$item['body'] = $purifier->purify($item['body']);
$item['body'] = @html2bbcode($item['body']);
intval($importer["uid"])
);
create_tags_from_itemuri($uri, $importer["uid"]);
- create_files_from_itemuri($uri, $importer["uid"]);
+ Term::createFromItemURI($uri, $importer["uid"]);
update_thread_uri($uri, $importer["uid"]);
} else {
$r = q(
intval($importer["uid"])
);
create_tags_from_itemuri($uri, $importer["uid"]);
- create_files_from_itemuri($uri, $importer["uid"]);
+ Term::createFromItemURI($uri, $importer["uid"]);
update_thread_uri($uri, $importer["importer_uid"]);
if ($item["last-child"]) {
// ensure that last-child is set in case the comment that had it just got wiped.
/**
* @brief Imports a DFRN message
*
- * @param text $xml The DFRN message
- * @param array $importer Record of the importer user mixed with contact of the content
- * @param bool $sort_by_date Is used when feeds are polled
+ * @param string $xml The DFRN message
+ * @param array $importer Record of the importer user mixed with contact of the content
+ * @param bool $sort_by_date Is used when feeds are polled
* @return integer Import status
* @todo set proper type-hints
*/
$doc = new DOMDocument();
@$doc->loadXML($xml);
- $xpath = new DomXPath($doc);
+ $xpath = new DOMXPath($doc);
$xpath->registerNamespace("atom", NAMESPACE_ATOM1);
$xpath->registerNamespace("thr", NAMESPACE_THREAD);
$xpath->registerNamespace("at", NAMESPACE_TOMB);
// The account type is new since 3.5.1
if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) {
- $accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()", $context)->item(0)->nodeValue);
+ $accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()")->item(0)->nodeValue);
if ($accounttype != $importer["contact-type"]) {
dba::update('contact', array('contact-type' => $accounttype), array('id' => $importer["id"]));
// is it a public forum? Private forums aren't supported with this method
// This is deprecated since 3.5.1
- $forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()", $context)->item(0)->nodeValue);
+ $forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()")->item(0)->nodeValue);
if ($forum != $importer["forum"]) {
$condition = array('`forum` != ? AND `id` = ?', $forum, $importer["id"]);
logger("Import done for user " . $importer["uid"] . " from contact " . $importer["id"], LOGGER_DEBUG);
return 200;
}
+
+ /**
+ * @param App $a App
+ * @param string $contact_nick contact nickname
+ */
+ public static function autoRedir(App $a, $contact_nick)
+ {
+ // prevent looping
+ if (x($_REQUEST, 'redir') && intval($_REQUEST['redir'])) {
+ return;
+ }
+
+ if ((! $contact_nick) || ($contact_nick === $a->user['nickname'])) {
+ return;
+ }
+
+ if (local_user()) {
+ // We need to find out if $contact_nick is a user on this hub, and if so, if I
+ // am a contact of that user. However, that user may have other contacts with the
+ // same nickname as me on other hubs or other networks. Exclude these by requiring
+ // that the contact have a local URL. I will be the only person with my nickname at
+ // this URL, so if a result is found, then I am a contact of the $contact_nick user.
+ //
+ // We also have to make sure that I'm a legitimate contact--I'm not blocked or pending.
+
+ $baseurl = System::baseUrl();
+ $domain_st = strpos($baseurl, "://");
+ if ($domain_st === false) {
+ return;
+ }
+ $baseurl = substr($baseurl, $domain_st + 3);
+ $nurl = normalise_link($baseurl);
+
+ /// @todo Why is there a query for "url" *and* "nurl"? Especially this normalising is strange.
+ $r = q("SELECT `id` FROM `contact` WHERE `uid` = (SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1)
+ AND `nick` = '%s' AND NOT `self` AND (`url` LIKE '%%%s%%' OR `nurl` LIKE '%%%s%%') AND NOT `blocked` AND NOT `pending` LIMIT 1",
+ dbesc($contact_nick),
+ dbesc($a->user['nickname']),
+ dbesc($baseurl),
+ dbesc($nurl)
+ );
+ if ((! DBM::is_result($r)) || $r[0]['id'] == remote_user()) {
+ return;
+ }
+
+ $r = q("SELECT * FROM contact WHERE nick = '%s'
+ AND network = '%s' AND uid = %d AND url LIKE '%%%s%%' LIMIT 1",
+ dbesc($contact_nick),
+ dbesc(NETWORK_DFRN),
+ intval(local_user()),
+ dbesc($baseurl)
+ );
+ if (! DBM::is_result($r)) {
+ return;
+ }
+
+ $cid = $r[0]['id'];
+
+ $dfrn_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
+
+ if ($r[0]['duplex'] && $r[0]['issued-id']) {
+ $orig_id = $r[0]['issued-id'];
+ $dfrn_id = '1:' . $orig_id;
+ }
+ if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
+ $orig_id = $r[0]['dfrn-id'];
+ $dfrn_id = '0:' . $orig_id;
+ }
+
+ // ensure that we've got a valid ID. There may be some edge cases with forums and non-duplex mode
+ // that may have triggered some of the "went to {profile/intro} and got an RSS feed" issues
+
+ if (strlen($dfrn_id) < 3) {
+ return;
+ }
+
+ $sec = random_string();
+
+ dba::insert('profile_check', ['uid' => local_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id, 'sec' => $sec, 'expire' => time() + 45]);
+
+ $url = curPageURL();
+
+ logger('auto_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
+ $dest = (($url) ? '&destination_url=' . $url : '');
+ goaway($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
+ . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest);
+ }
+
+ return;
+ }
}