*/
namespace Friendica\Protocol;
-use Friendica\App;
-use Friendica\Core\System;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
+use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Group;
+use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Model\Queue;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Util\Crypto;
+use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\XML;
use dba;
require_once 'include/dba.php';
require_once 'include/items.php';
require_once 'include/bb2diaspora.php';
-require_once 'include/datetime.php';
/**
* @brief This class contain functions to create and send Diaspora XML files
$r = q(
"INSERT INTO `contact` (`uid`, `created`, `name`, `nick`, `addr`, `url`, `nurl`, `batch`, `network`, `rel`, `blocked`, `pending`, `writable`, `name-date`, `uri-date`, `avatar-date`)
VALUES (0, '%s', '%s', 'relay', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, '%s', '%s', '%s')",
- datetime_convert(),
+ DateTimeFormat::utcNow(),
dbesc($addr),
dbesc($addr),
dbesc($server),
dbesc($batch),
dbesc(NETWORK_DIASPORA),
intval(CONTACT_IS_FOLLOWER),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc(datetime_convert())
+ dbesc(DateTimeFormat::utcNow()),
+ dbesc(DateTimeFormat::utcNow()),
+ dbesc(DateTimeFormat::utcNow())
);
$relais = q("SELECT `batch`, `id`, `name`,`network` FROM `contact` WHERE `uid` = 0 AND `batch` = '%s' LIMIT 1", dbesc($batch));
*/
private static function verifyMagicEnvelope($envelope)
{
- $basedom = Network::parseXmlString($envelope);
+ $basedom = XML::parseString($envelope);
if (!is_object($basedom)) {
logger("Envelope is no XML file");
if (!is_object($j_outer_key_bundle)) {
logger('Outer Salmon did not verify. Discarding.');
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
$outer_iv = base64_decode($j_outer_key_bundle->iv);
$xml = $raw;
}
- $basedom = Network::parseXmlString($xml);
+ $basedom = XML::parseString($xml);
if (!is_object($basedom)) {
logger('Received data does not seem to be an XML. Discarding. '.$xml);
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
$base = $basedom->children(NAMESPACE_SALMON_ME);
$verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) {
logger('Message did not verify. Discarding.');
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
return ['message' => (string)base64url_decode($base->data),
public static function decode($importer, $xml)
{
$public = false;
- $basedom = Network::parseXmlString($xml);
+ $basedom = XML::parseString($xml);
if (!is_object($basedom)) {
logger("XML is not parseable.");
$decrypted = self::aesDecrypt($outer_key, $outer_iv, $ciphertext);
logger('decrypted: '.$decrypted, LOGGER_DEBUG);
- $idom = Network::parseXmlString($decrypted);
+ $idom = XML::parseString($decrypted);
$inner_iv = base64_decode($idom->iv);
$inner_aes_key = base64_decode($idom->aes_key);
if (!$base) {
logger('unable to locate salmon data in xml');
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
if (!$author_link) {
logger('Could not retrieve author URI.');
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
// Once we have the author URI, go to the web and try to find their public key
// (first this will look it up locally if it is in the fcontact cache)
if (!$key) {
logger('Could not retrieve author key.');
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
$verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) {
logger('Message did not verify. Discarding.');
- Network::httpStatusExit(400);
+ System::httpExit(400);
}
logger('Message verified.');
*/
private static function validPosting($msg)
{
- $data = Network::parseXmlString($msg["message"]);
+ $data = XML::parseString($msg["message"]);
if (!is_object($data)) {
logger("No valid XML ".$msg["message"], LOGGER_DEBUG);
dbesc($arr["confirm"]),
dbesc($arr["alias"]),
dbesc($arr["pubkey"]),
- dbesc(datetime_convert()),
+ dbesc(DateTimeFormat::utcNow()),
dbesc($arr["url"]),
dbesc($arr["network"])
);
dbesc($arr["network"]),
dbesc($arr["alias"]),
dbesc($arr["pubkey"]),
- dbesc(datetime_convert())
+ dbesc(DateTimeFormat::utcNow())
);
}
logger("Fetch post from ".$source_url, LOGGER_DEBUG);
- $envelope = Network::fetchURL($source_url);
+ $envelope = Network::fetchUrl($source_url);
if ($envelope) {
logger("Envelope was fetched.", LOGGER_DEBUG);
$x = self::verifyMagicEnvelope($envelope);
$source_url = $server."/p/".urlencode($guid).".xml";
logger("Fetch post from ".$source_url, LOGGER_DEBUG);
- $x = Network::fetchURL($source_url);
+ $x = Network::fetchUrl($source_url);
if (!$x) {
return false;
}
}
- $source_xml = Network::parseXmlString($x);
+ $source_xml = XML::parseString($x);
if (!is_object($source_xml)) {
return false;
$text = unxmlify($data->text);
if (isset($data->created_at)) {
- $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
+ $created_at = DateTimeFormat::utc(notags(unxmlify($data->created_at)));
} else {
- $created_at = datetime_convert();
+ $created_at = DateTimeFormat::utcNow();
}
if (isset($data->thread_parent_guid)) {
self::fetchGuid($datarray);
- $message_id = item_store($datarray);
+ $message_id = Item::insert($datarray);
if ($message_id <= 0) {
return false;
$msg_guid = notags(unxmlify($mesg->guid));
$msg_conversation_guid = notags(unxmlify($mesg->conversation_guid));
$msg_text = unxmlify($mesg->text);
- $msg_created_at = datetime_convert("UTC", "UTC", notags(unxmlify($mesg->created_at)));
+ $msg_created_at = DateTimeFormat::utc(notags(unxmlify($mesg->created_at)));
if ($msg_conversation_guid != $guid) {
logger("message conversation guid does not belong to the current conversation.");
dba::unlock();
- dba::update('conv', ['updated' => datetime_convert()], ['id' => $conversation["id"]]);
+ dba::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
notification(
[
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$subject = notags(unxmlify($data->subject));
- $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
+ $created_at = DateTimeFormat::utc(notags(unxmlify($data->created_at)));
$participants = notags(unxmlify($data->participants));
$messages = $data->message;
dbesc($guid),
dbesc($author),
dbesc($created_at),
- dbesc(datetime_convert()),
+ dbesc(DateTimeFormat::utcNow()),
dbesc($subject),
dbesc($participants)
);
$datarray["body"] = self::constructLikeBody($contact, $parent_item, $guid);
- $message_id = item_store($datarray);
+ $message_id = Item::insert($datarray);
if ($message_id <= 0) {
return false;
$guid = notags(unxmlify($data->guid));
$conversation_guid = notags(unxmlify($data->conversation_guid));
$text = unxmlify($data->text);
- $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
+ $created_at = DateTimeFormat::utc(notags(unxmlify($data->created_at)));
$contact = self::allowedContactByHandle($importer, $author, true);
if (!$contact) {
dba::unlock();
- dba::update('conv', ['updated' => datetime_convert()], ['id' => $conversation["id"]]);
+ dba::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
return true;
}
$birthday = str_replace("1000", "1901", $birthday);
if ($birthday != "") {
- $birthday = datetime_convert("UTC", "UTC", $birthday, "Y-m-d");
+ $birthday = DateTimeFormat::utc($birthday, "Y-m-d");
}
// this is to prevent multiple birthday notifications in a single year
dbesc($name),
dbesc($nick),
dbesc($author),
- dbesc(datetime_convert()),
+ dbesc(DateTimeFormat::utcNow()),
dbesc($birthday),
dbesc($location),
dbesc($about),
$arr["deny_cid"] = $user["deny_cid"];
$arr["deny_gid"] = $user["deny_gid"];
- $i = item_store($arr);
+ $i = Item::insert($arr);
if ($i) {
Worker::add(PRIORITY_HIGH, "Notifier", "activity", $i);
}
return true;
} else {
logger("Author ".$author." doesn't want to follow us anymore.", LOGGER_DEBUG);
- lose_follower($importer, $contact);
+ Contact::removeFollower($importer, $contact);
return true;
}
}
intval($importer["uid"]),
dbesc($ret["network"]),
dbesc($ret["addr"]),
- datetime_convert(),
+ DateTimeFormat::utcNow(),
dbesc($ret["url"]),
dbesc(normalise_link($ret["url"])),
dbesc($batch),
0,
dbesc(L10n::t("Sharing notification from Diaspora network")),
dbesc($hash),
- dbesc(datetime_convert())
+ dbesc(DateTimeFormat::utcNow())
);
} else {
// automatic friend approval
WHERE `id` = %d
",
intval($new_relation),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
+ dbesc(DateTimeFormat::utcNow()),
+ dbesc(DateTimeFormat::utcNow()),
intval($contact_record["id"])
);
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
- $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
+ $created_at = DateTimeFormat::utc(notags(unxmlify($data->created_at)));
$root_author = notags(unxmlify($data->root_author));
$root_guid = notags(unxmlify($data->root_guid));
/// @todo handle unprocessed property "provider_display_name"
$datarray["object-type"] = $original_item["object-type"];
self::fetchGuid($datarray);
- $message_id = item_store($datarray);
+ $message_id = Item::insert($datarray);
self::sendParticipation($contact, $datarray);
'deleted' => true,
'title' => '',
'body' => '',
- 'edited' => datetime_convert(),
- 'changed' => datetime_convert()],
+ 'edited' => DateTimeFormat::utcNow(),
+ 'changed' => DateTimeFormat::utcNow()],
['id' => $item["id"]]
);
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
- $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
+ $created_at = DateTimeFormat::utc(notags(unxmlify($data->created_at)));
$public = notags(unxmlify($data->public));
$text = unxmlify($data->text);
$provider_display_name = notags(unxmlify($data->provider_display_name));
}
self::fetchGuid($datarray);
- $message_id = item_store($datarray);
+ $message_id = Item::insert($datarray);
self::sendParticipation($contact, $datarray);
if (!intval(Config::get("system", "diaspora_test"))) {
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
- Network::postURL($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
+ Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
$return_code = $a->get_curl_code();
} else {
logger("test_mode");
$eventdata['guid'] = $event['guid'];
}
- $mask = 'Y-m-d\TH:i:s\Z';
+ $mask = DateTimeFormat::ATOM;
/// @todo - establish "all day" events in Friendica
$eventdata["all_day"] = "false";
}
if ($event['start']) {
- $eventdata['start'] = datetime_convert($eventdata['timezone'], "UTC", $event['start'], $mask);
+ $eventdata['start'] = DateTimeFormat::convert($event['start'], "UTC", $eventdata['timezone'], $mask);
}
if ($event['finish'] && !$event['nofinish']) {
- $eventdata['end'] = datetime_convert($eventdata['timezone'], "UTC", $event['finish'], $mask);
+ $eventdata['end'] = DateTimeFormat::convert($event['finish'], "UTC", $eventdata['timezone'], $mask);
}
if ($event['summary']) {
$eventdata['summary'] = html_entity_decode(bb2diaspora($event['summary']));
$public = (($item["private"]) ? "false" : "true");
- $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
+ $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
// Detect a share element and do a reshare
if (!$item['private'] && ($ret = self::isReshare($item["body"]))) {
$parent = $p[0];
$text = html_entity_decode(bb2diaspora($item["body"]));
- $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
+ $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
$comment = ["author" => self::myHandle($owner),
"guid" => $item["guid"],
"author" => $cnv["creator"],
"guid" => $cnv["guid"],
"subject" => $cnv["subject"],
- "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
+ "created_at" => DateTimeFormat::utc($cnv['created'], DateTimeFormat::ATOM),
"participants" => $cnv["recips"]
];
$body = bb2diaspora($item["body"]);
- $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
+ $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
$msg = [
"author" => $myaddr,
"author" => $cnv["creator"],
"guid" => $cnv["guid"],
"subject" => $cnv["subject"],
- "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
+ "created_at" => DateTimeFormat::utc($cnv['created'], DateTimeFormat::ATOM),
"participants" => $cnv["recips"],
"message" => $msg];
if ($year < 1004) {
$year = 1004;
}
- $dob = datetime_convert('UTC', 'UTC', $year . '-' . $month . '-'. $day, 'Y-m-d');
+ $dob = DateTimeFormat::utc($year . '-' . $month . '-'. $day, 'Y-m-d');
}
$about = $profile['about'];