-function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0, $pass = 0)
-{
- if ($contact['network'] === Protocol::OSTATUS) {
- if ($pass < 2) {
- // Test - remove before flight
- //$tempfile = tempnam(get_temppath(), "ostatus2");
- //file_put_contents($tempfile, $xml);
- Logger::log("Consume OStatus messages ", Logger::DEBUG);
- OStatus::import($xml, $importer, $contact, $hub);
- }
-
- return;
- }
-
- if ($contact['network'] === Protocol::FEED) {
- if ($pass < 2) {
- Logger::log("Consume feeds", Logger::DEBUG);
- Feed::import($xml, $importer, $contact, $hub);
- }
-
- return;
- }
-
- if ($contact['network'] === Protocol::DFRN) {
- Logger::log("Consume DFRN messages", Logger::DEBUG);
- $dfrn_importer = DFRN::getImporter($contact["id"], $importer["uid"]);
- if (!empty($dfrn_importer)) {
- Logger::log("Now import the DFRN feed");
- DFRN::import($xml, $dfrn_importer, true);
- return;
- }
- }
-}
-
-function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'subscribe')
-{
- /*
- * Diaspora has different message-ids in feeds than they do
- * through the direct Diaspora protocol. If we try and use
- * the feed, we'll get duplicates. So don't.
- */
- if ($contact['network'] === Protocol::DIASPORA) {
- return;
- }
-
- // Without an importer we don't have a user id - so we quit
- if (empty($importer)) {
- return;
- }
-
- $a = BaseObject::getApp();
-
- $user = DBA::selectFirst('user', ['nickname'], ['uid' => $importer['uid']]);
-
- // No user, no nickname, we quit
- if (!DBA::isResult($user)) {
- return;
- }
-
- $push_url = System::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
-
- // Use a single verify token, even if multiple hubs
- $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : Strings::getRandomHex());
-
- $params= 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
-
- Logger::log('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
-
- if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
- DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
- }
-
- $postResult = Network::post($url, $params);
-
- Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG);
-
- return;
-
-}
-
-function drop_items(array $items)
-{
- $uid = 0;
-
- if (!local_user() && !remote_user()) {
- return;
- }
-
- if (!empty($items)) {
- foreach ($items as $item) {
- $owner = Item::deleteForUser(['id' => $item], local_user());
-
- if ($owner && !$uid) {
- $uid = $owner;
- }
- }
- }
-}
-
-function drop_item($id, $return = '')
-{
- $a = BaseObject::getApp();
-
- // locate item to be deleted
-
- $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'];
- $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]);
-
- if (!DBA::isResult($item)) {
- notice(L10n::t('Item not found.') . EOL);
- $a->internalRedirect('network');
- }
-
- if ($item['deleted']) {
- return 0;
- }
-
- $contact_id = 0;
-
- // check if logged in user is either the author or owner of this item
-
- if (!empty($_SESSION['remote'])) {
- foreach ($_SESSION['remote'] as $visitor) {
- if ($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) {
- $contact_id = $visitor['cid'];
- break;
- }
- }
- }
-
- if ((local_user() == $item['uid']) || $contact_id) {
- // Check if we should do HTML-based delete confirmation
- if (!empty($_REQUEST['confirm'])) {
- // <form> can't take arguments in its "action" parameter
- // so add any arguments as hidden inputs
- $query = explode_querystring($a->query_string);
- $inputs = [];
-
- foreach ($query['args'] as $arg) {
- if (strpos($arg, 'confirm=') === false) {
- $arg_parts = explode('=', $arg);
- $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
- }
- }
-
- return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
- '$method' => 'get',
- '$message' => L10n::t('Do you really want to delete this item?'),
- '$extra_inputs' => $inputs,
- '$confirm' => L10n::t('Yes'),
- '$confirm_url' => $query['base'],
- '$confirm_name' => 'confirmed',
- '$cancel' => L10n::t('Cancel'),
- ]);
- }
- // Now check how the user responded to the confirmation query
- if (!empty($_REQUEST['canceled'])) {
- $a->internalRedirect('display/' . $item['guid']);
- }
-
- $is_comment = ($item['gravity'] == GRAVITY_COMMENT) ? true : false;
- $parentitem = null;
- if (!empty($item['parent'])){
- $fields = ['guid'];
- $parentitem = Item::selectFirstForUser(local_user(), $fields, ['id' => $item['parent']]);
- }
-
- // delete the item
- Item::deleteForUser(['id' => $item['id']], local_user());
-
- $return_url = hex2bin($return);
-
- // removes update_* from return_url to ignore Ajax refresh
- $return_url = str_replace("update_", "", $return_url);
-
- // Check if delete a comment
- if ($is_comment) {
- // Return to parent guid
- if (!empty($parentitem)) {
- $a->internalRedirect('display/' . $parentitem['guid']);
- //NOTREACHED
- }
- // In case something goes wrong
- else {
- $a->internalRedirect('network');
- //NOTREACHED
- }
- }
- else {
- // if unknown location or deleting top level post called from display
- if (empty($return_url) || strpos($return_url, 'display') !== false) {
- $a->internalRedirect('network');
- //NOTREACHED
- } else {
- $a->internalRedirect($return_url);
- //NOTREACHED
- }
- }
- } else {
- notice(L10n::t('Permission denied.') . EOL);
- $a->internalRedirect('display/' . $item['guid']);
- //NOTREACHED
- }
-}
-
-/* arrange the list in years */
-function list_post_dates($uid, $wall)