Relocate class files from /include to /src/
dbm, Diaspora, dfrn, and NotificationsManager moved to namespace. Includes and references in files updated.
This commit is contained in:
parent
6feec66979
commit
f234691216
31 changed files with 7965 additions and 67 deletions
|
@ -5,6 +5,8 @@ use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
|
|
||||||
// Included here for completeness, but this is a very dangerous operation.
|
// Included here for completeness, but this is a very dangerous operation.
|
||||||
// It is the caller's responsibility to confirm the requestor's intent and
|
// It is the caller's responsibility to confirm the requestor's intent and
|
||||||
|
@ -90,11 +92,9 @@ function terminate_friendship($user,$self,$contact) {
|
||||||
slapper($user,$contact['notify'],$slap);
|
slapper($user,$contact['notify'],$slap);
|
||||||
}
|
}
|
||||||
} elseif ($contact['network'] === NETWORK_DIASPORA) {
|
} elseif ($contact['network'] === NETWORK_DIASPORA) {
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
Diaspora::send_unshare($user,$contact);
|
Diaspora::send_unshare($user,$contact);
|
||||||
} elseif ($contact['network'] === NETWORK_DFRN) {
|
} elseif ($contact['network'] === NETWORK_DFRN) {
|
||||||
require_once 'include/dfrn.php';
|
Dfrn::deliver($user,$contact,'placeholder', 1);
|
||||||
dfrn::deliver($user,$contact,'placeholder', 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Core\NotificationsManager;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
|
||||||
require_once 'include/HTTPExceptions.php';
|
require_once 'include/HTTPExceptions.php';
|
||||||
|
@ -28,7 +29,6 @@ require_once 'mod/proxy.php';
|
||||||
require_once 'include/message.php';
|
require_once 'include/message.php';
|
||||||
require_once 'include/group.php';
|
require_once 'include/group.php';
|
||||||
require_once 'include/like.php';
|
require_once 'include/like.php';
|
||||||
require_once 'include/NotificationsManager.php';
|
|
||||||
require_once 'include/plaintext.php';
|
require_once 'include/plaintext.php';
|
||||||
require_once 'include/xml.php';
|
require_once 'include/xml.php';
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
require_once('include/diaspora.php');
|
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
function contact_profile_assign($current,$foreign_net) {
|
function contact_profile_assign($current,$foreign_net) {
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
|
|
||||||
require_once 'include/queue_fn.php';
|
require_once 'include/queue_fn.php';
|
||||||
require_once 'include/html2plain.php';
|
require_once 'include/html2plain.php';
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
require_once 'include/ostatus.php';
|
require_once 'include/ostatus.php';
|
||||||
require_once 'include/dfrn.php';
|
|
||||||
|
|
||||||
function delivery_run(&$argv, &$argc){
|
function delivery_run(&$argv, &$argc){
|
||||||
global $a;
|
global $a;
|
||||||
|
@ -243,12 +243,12 @@ function delivery_run(&$argv, &$argc){
|
||||||
|
|
||||||
if ($mail) {
|
if ($mail) {
|
||||||
$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
|
$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
|
||||||
$atom = dfrn::mail($item, $owner);
|
$atom = Dfrn::mail($item, $owner);
|
||||||
} elseif ($fsuggest) {
|
} elseif ($fsuggest) {
|
||||||
$atom = dfrn::fsuggest($item, $owner);
|
$atom = Dfrn::fsuggest($item, $owner);
|
||||||
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
|
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
|
||||||
} elseif ($relocate) {
|
} elseif ($relocate) {
|
||||||
$atom = dfrn::relocate($owner, $uid);
|
$atom = Dfrn::relocate($owner, $uid);
|
||||||
} elseif ($followup) {
|
} elseif ($followup) {
|
||||||
$msgitems = array();
|
$msgitems = array();
|
||||||
foreach ($items as $item) { // there is only one item
|
foreach ($items as $item) { // there is only one item
|
||||||
|
@ -260,7 +260,7 @@ function delivery_run(&$argv, &$argc){
|
||||||
$msgitems[] = $item;
|
$msgitems[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$atom = dfrn::entries($msgitems,$owner);
|
$atom = Dfrn::entries($msgitems,$owner);
|
||||||
} else {
|
} else {
|
||||||
$msgitems = array();
|
$msgitems = array();
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
@ -289,7 +289,7 @@ function delivery_run(&$argv, &$argc){
|
||||||
$msgitems[] = $item;
|
$msgitems[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$atom = dfrn::entries($msgitems,$owner);
|
$atom = Dfrn::entries($msgitems,$owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
|
logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
|
||||||
|
@ -343,13 +343,13 @@ function delivery_run(&$argv, &$argc){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
logger('mod-delivery: local delivery');
|
logger('mod-delivery: local delivery');
|
||||||
dfrn::import($atom, $x[0]);
|
Dfrn::import($atom, $x[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!was_recently_delayed($contact['id'])) {
|
if (!was_recently_delayed($contact['id'])) {
|
||||||
$deliver_status = dfrn::deliver($owner,$contact,$atom);
|
$deliver_status = Dfrn::deliver($owner,$contact,$atom);
|
||||||
} else {
|
} else {
|
||||||
$deliver_status = (-1);
|
$deliver_status = (-1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ use Friendica\Core\Config;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once 'include/socgraph.php';
|
require_once 'include/socgraph.php';
|
||||||
require_once 'include/group.php';
|
require_once 'include/group.php';
|
||||||
require_once 'include/salmon.php';
|
require_once 'include/salmon.php';
|
||||||
require_once 'include/ostatus.php';
|
require_once 'include/ostatus.php';
|
||||||
require_once 'include/Photo.php';
|
require_once 'include/Photo.php';
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
|
|
||||||
function update_contact($id) {
|
function update_contact($id) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Friendica\Util\Lock;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
|
|
||||||
require_once 'include/bbcode.php';
|
require_once 'include/bbcode.php';
|
||||||
require_once 'include/oembed.php';
|
require_once 'include/oembed.php';
|
||||||
|
@ -29,7 +30,6 @@ require_once 'include/feed.php';
|
||||||
require_once 'include/Contact.php';
|
require_once 'include/Contact.php';
|
||||||
require_once 'mod/share.php';
|
require_once 'mod/share.php';
|
||||||
require_once 'include/enotify.php';
|
require_once 'include/enotify.php';
|
||||||
require_once 'include/dfrn.php';
|
|
||||||
require_once 'include/group.php';
|
require_once 'include/group.php';
|
||||||
|
|
||||||
/// @TODO one day with composer autoloader no more needed
|
/// @TODO one day with composer autoloader no more needed
|
||||||
|
@ -1564,7 +1564,7 @@ function consume_feed($xml, $importer, &$contact, &$hub, $datedir = 0, $pass = 0
|
||||||
);
|
);
|
||||||
if (dbm::is_result($r)) {
|
if (dbm::is_result($r)) {
|
||||||
logger("Now import the DFRN feed");
|
logger("Now import the DFRN feed");
|
||||||
dfrn::import($xml, $r[0], true);
|
Dfrn::import($xml, $r[0], true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
require_once("include/diaspora.php");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief add/remove activity to an item
|
* @brief add/remove activity to an item
|
||||||
|
|
|
@ -4,10 +4,10 @@ use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once 'include/queue_fn.php';
|
require_once 'include/queue_fn.php';
|
||||||
require_once 'include/html2plain.php';
|
require_once 'include/html2plain.php';
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
require_once 'include/ostatus.php';
|
require_once 'include/ostatus.php';
|
||||||
require_once 'include/salmon.php';
|
require_once 'include/salmon.php';
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
require_once('include/diaspora.php');
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
function profile_update_run(&$argv, &$argc) {
|
function profile_update_run(&$argv, &$argc) {
|
||||||
if ($argc != 2) {
|
if ($argc != 2) {
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
|
|
||||||
require_once 'include/queue_fn.php';
|
require_once 'include/queue_fn.php';
|
||||||
require_once 'include/dfrn.php';
|
|
||||||
require_once 'include/datetime.php';
|
require_once 'include/datetime.php';
|
||||||
require_once 'include/items.php';
|
require_once 'include/items.php';
|
||||||
require_once 'include/bbcode.php';
|
require_once 'include/bbcode.php';
|
||||||
|
@ -63,7 +64,6 @@ function queue_run(&$argv, &$argc) {
|
||||||
// delivering
|
// delivering
|
||||||
|
|
||||||
require_once 'include/salmon.php';
|
require_once 'include/salmon.php';
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
|
|
||||||
$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||||
intval($queue_id));
|
intval($queue_id));
|
||||||
|
@ -129,7 +129,7 @@ function queue_run(&$argv, &$argc) {
|
||||||
switch ($contact['network']) {
|
switch ($contact['network']) {
|
||||||
case NETWORK_DFRN:
|
case NETWORK_DFRN:
|
||||||
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||||
$deliver_status = dfrn::deliver($owner, $contact, $data);
|
$deliver_status = Dfrn::deliver($owner, $contact, $data);
|
||||||
|
|
||||||
if ($deliver_status == (-1)) {
|
if ($deliver_status == (-1)) {
|
||||||
update_queue_time($q_item['id']);
|
update_queue_time($q_item['id']);
|
||||||
|
|
|
@ -24,6 +24,7 @@ use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once 'include/enotify.php';
|
require_once 'include/enotify.php';
|
||||||
require_once 'include/group.php';
|
require_once 'include/group.php';
|
||||||
|
@ -438,7 +439,6 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
|
||||||
if ((isset($new_relation) && $new_relation == CONTACT_IS_FRIEND)) {
|
if ((isset($new_relation) && $new_relation == CONTACT_IS_FRIEND)) {
|
||||||
|
|
||||||
if (($contact) && ($contact['network'] === NETWORK_DIASPORA)) {
|
if (($contact) && ($contact['network'] === NETWORK_DIASPORA)) {
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
$ret = Diaspora::send_share($user[0],$r[0]);
|
$ret = Diaspora::send_share($user[0],$r[0]);
|
||||||
logger('share returns: ' . $ret);
|
logger('share returns: ' . $ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
|
|
||||||
require_once('include/items.php');
|
require_once('include/items.php');
|
||||||
require_once('include/dfrn.php');
|
|
||||||
require_once('include/event.php');
|
require_once('include/event.php');
|
||||||
|
|
||||||
require_once('library/defuse/php-encryption-1.2.1/Crypto.php');
|
require_once('library/defuse/php-encryption-1.2.1/Crypto.php');
|
||||||
|
@ -180,7 +180,7 @@ function dfrn_notify_post(App $a) {
|
||||||
*we got a key. old code send only the key, without RINO version.
|
*we got a key. old code send only the key, without RINO version.
|
||||||
* we assume RINO 1 if key and no RINO version
|
* we assume RINO 1 if key and no RINO version
|
||||||
*/
|
*/
|
||||||
$data = dfrn::aes_decrypt(hex2bin($data), $final_key);
|
$data = Dfrn::aes_decrypt(hex2bin($data), $final_key);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
try {
|
try {
|
||||||
|
@ -212,7 +212,7 @@ function dfrn_notify_post(App $a) {
|
||||||
logger('rino: decrypted data: ' . $data, LOGGER_DATA);
|
logger('rino: decrypted data: ' . $data, LOGGER_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = dfrn::import($data, $importer);
|
$ret = Dfrn::import($data, $importer);
|
||||||
xml_status($ret, 'Processed');
|
xml_status($ret, 'Processed');
|
||||||
|
|
||||||
// NOTREACHED
|
// NOTREACHED
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
|
|
||||||
require_once('include/items.php');
|
require_once('include/items.php');
|
||||||
require_once('include/auth.php');
|
require_once('include/auth.php');
|
||||||
require_once('include/dfrn.php');
|
|
||||||
require_once('include/ostatus.php');
|
require_once('include/ostatus.php');
|
||||||
|
|
||||||
function dfrn_poll_init(App $a) {
|
function dfrn_poll_init(App $a) {
|
||||||
|
@ -58,7 +58,7 @@ function dfrn_poll_init(App $a) {
|
||||||
|
|
||||||
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
|
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
|
||||||
header("Content-type: application/atom+xml");
|
header("Content-type: application/atom+xml");
|
||||||
echo dfrn::feed('', $user,$last_update, 0, $hidewall);
|
echo Dfrn::feed('', $user,$last_update, 0, $hidewall);
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ function dfrn_poll_post(App $a) {
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Content-type: application/atom+xml");
|
header("Content-type: application/atom+xml");
|
||||||
$o = dfrn::feed($dfrn_id, $a->argv[1], $last_update, $direction);
|
$o = Dfrn::feed($dfrn_id, $a->argv[1], $last_update, $direction);
|
||||||
echo $o;
|
echo $o;
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Protocol\Dfrn;
|
||||||
require_once('include/dfrn.php');
|
|
||||||
|
|
||||||
function display_init(App $a) {
|
function display_init(App $a) {
|
||||||
|
|
||||||
|
@ -492,7 +491,7 @@ function display_content(App $a, $update = 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayShowFeed($item_id, $conversation) {
|
function displayShowFeed($item_id, $conversation) {
|
||||||
$xml = dfrn::itemFeed($item_id, $conversation);
|
$xml = Dfrn::itemFeed($item_id, $conversation);
|
||||||
if ($xml == '') {
|
if ($xml == '') {
|
||||||
http_status_exit(500);
|
http_status_exit(500);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ This file is part of the Diaspora protocol. It is used for fetching single publi
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once("include/crypto.php");
|
require_once("include/crypto.php");
|
||||||
require_once("include/diaspora.php");
|
|
||||||
require_once("include/xml.php");
|
require_once("include/xml.php");
|
||||||
|
|
||||||
function fetch_init(App $a) {
|
function fetch_init(App $a) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Friendica\Core\Config;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once 'include/crypto.php';
|
require_once 'include/crypto.php';
|
||||||
require_once 'include/enotify.php';
|
require_once 'include/enotify.php';
|
||||||
|
@ -29,7 +30,6 @@ require_once 'include/files.php';
|
||||||
require_once 'include/threads.php';
|
require_once 'include/threads.php';
|
||||||
require_once 'include/text.php';
|
require_once 'include/text.php';
|
||||||
require_once 'include/items.php';
|
require_once 'include/items.php';
|
||||||
require_once 'include/diaspora.php';
|
|
||||||
require_once 'include/Contact.php';
|
require_once 'include/Contact.php';
|
||||||
|
|
||||||
function item_post(App $a) {
|
function item_post(App $a) {
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
|
use Friendica\Core\NotificationsManager;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
|
||||||
require_once("include/NotificationsManager.php");
|
|
||||||
require_once("include/contact_selectors.php");
|
require_once("include/contact_selectors.php");
|
||||||
require_once("include/network.php");
|
require_once("include/network.php");
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
|
use Friendica\Core\NotificationsManager;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
|
||||||
require_once('include/NotificationsManager.php');
|
|
||||||
|
|
||||||
function notify_init(App $a) {
|
function notify_init(App $a) {
|
||||||
if (! local_user()) {
|
if (! local_user()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -5,8 +5,7 @@ This file is part of the Diaspora protocol. It is used for fetching single publi
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
require_once("include/diaspora.php");
|
|
||||||
|
|
||||||
function p_init($a){
|
function p_init($a){
|
||||||
if ($a->argc != 2) {
|
if ($a->argc != 2) {
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once('include/salmon.php');
|
require_once('include/salmon.php');
|
||||||
require_once('include/crypto.php');
|
require_once('include/crypto.php');
|
||||||
require_once('include/diaspora.php');
|
|
||||||
|
|
||||||
function receive_post(App $a) {
|
function receive_post(App $a) {
|
||||||
$enabled = intval(Config::get('system', 'diaspora_enabled'));
|
$enabled = intval(Config::get('system', 'diaspora_enabled'));
|
||||||
|
|
|
@ -4,10 +4,10 @@ if(class_exists('Item'))
|
||||||
|
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
|
|
||||||
require_once('object/BaseObject.php');
|
require_once('object/BaseObject.php');
|
||||||
require_once('include/text.php');
|
require_once('include/text.php');
|
||||||
require_once('include/diaspora.php');
|
|
||||||
require_once('boot.php');
|
require_once('boot.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,10 +5,10 @@ namespace Friendica;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
|
|
||||||
use Cache;
|
use Cache;
|
||||||
use dba;
|
use dba;
|
||||||
use dbm;
|
|
||||||
|
|
||||||
use Detection\MobileDetect;
|
use Detection\MobileDetect;
|
||||||
|
|
||||||
|
@ -706,7 +706,7 @@ class App {
|
||||||
dba::transaction();
|
dba::transaction();
|
||||||
|
|
||||||
$r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
|
$r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
|
||||||
if (!dbm::is_result($r)) {
|
if (!Dbm::is_result($r)) {
|
||||||
dba::insert('process', array('pid' => getmypid(), 'command' => $command, 'created' => datetime_convert()));
|
dba::insert('process', array('pid' => getmypid(), 'command' => $command, 'created' => datetime_convert()));
|
||||||
}
|
}
|
||||||
dba::commit();
|
dba::commit();
|
||||||
|
@ -719,7 +719,7 @@ class App {
|
||||||
dba::transaction();
|
dba::transaction();
|
||||||
|
|
||||||
$r = q('SELECT `pid` FROM `process`');
|
$r = q('SELECT `pid` FROM `process`');
|
||||||
if (dbm::is_result($r)) {
|
if (Dbm::is_result($r)) {
|
||||||
foreach ($r AS $process) {
|
foreach ($r AS $process) {
|
||||||
if (!posix_kill($process['pid'], 0)) {
|
if (!posix_kill($process['pid'], 0)) {
|
||||||
q('DELETE FROM `process` WHERE `pid` = %d', intval($process['pid']));
|
q('DELETE FROM `process` WHERE `pid` = %d', intval($process['pid']));
|
||||||
|
@ -806,7 +806,7 @@ class App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$processlist = dbm::processlist();
|
$processlist = Dbm::processlist();
|
||||||
if ($processlist['list'] != '') {
|
if ($processlist['list'] != '') {
|
||||||
logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
|
logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
use dba;
|
use dba;
|
||||||
use dbm;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file include/Core/Config.php
|
* @file include/Core/Config.php
|
||||||
|
@ -99,7 +99,7 @@ class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = dba::select('config', array('v'), array('cat' => $family, 'k' => $key), array('limit' => 1));
|
$ret = dba::select('config', array('v'), array('cat' => $family, 'k' => $key), array('limit' => 1));
|
||||||
if (dbm::is_result($ret)) {
|
if (Dbm::is_result($ret)) {
|
||||||
// manage array value
|
// manage array value
|
||||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
|
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
|
||||||
|
|
||||||
|
|
868
src/Core/NotificationsManager.php
Normal file
868
src/Core/NotificationsManager.php
Normal file
|
@ -0,0 +1,868 @@
|
||||||
|
<?php
|
||||||
|
namespace Friendica\Core;
|
||||||
|
/**
|
||||||
|
* @file src/Core/NotificationsManager.php
|
||||||
|
* @brief Methods for read and write notifications from/to database
|
||||||
|
* or for formatting notifications
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Friendica\Core\Pconfig;
|
||||||
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
|
|
||||||
|
require_once 'include/html2plain.php';
|
||||||
|
require_once 'include/datetime.php';
|
||||||
|
require_once 'include/bbcode.php';
|
||||||
|
require_once 'include/Contact.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Methods for read and write notifications from/to database
|
||||||
|
* or for formatting notifications
|
||||||
|
*/
|
||||||
|
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 (Dbm::is_result($r))
|
||||||
|
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 (Dbm::is_result($r)) {
|
||||||
|
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())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief List of pages for the Notifications TabBar
|
||||||
|
*
|
||||||
|
* @return array with with notifications TabBar data
|
||||||
|
*/
|
||||||
|
public function getTabs() {
|
||||||
|
$tabs = array(
|
||||||
|
array(
|
||||||
|
'label' => t('System'),
|
||||||
|
'url'=>'notifications/system',
|
||||||
|
'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''),
|
||||||
|
'id' => 'system-tab',
|
||||||
|
'accesskey' => 'y',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'label' => t('Network'),
|
||||||
|
'url'=>'notifications/network',
|
||||||
|
'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''),
|
||||||
|
'id' => 'network-tab',
|
||||||
|
'accesskey' => 'w',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'label' => t('Personal'),
|
||||||
|
'url'=>'notifications/personal',
|
||||||
|
'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''),
|
||||||
|
'id' => 'personal-tab',
|
||||||
|
'accesskey' => 'r',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'label' => t('Home'),
|
||||||
|
'url' => 'notifications/home',
|
||||||
|
'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''),
|
||||||
|
'id' => 'home-tab',
|
||||||
|
'accesskey' => 'h',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'label' => t('Introductions'),
|
||||||
|
'url' => 'notifications/intros',
|
||||||
|
'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''),
|
||||||
|
'id' => 'intro-tab',
|
||||||
|
'accesskey' => 'i',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Format the notification query in an usable array
|
||||||
|
*
|
||||||
|
* @param array $notifs The array from the db query
|
||||||
|
* @param string $ident The notifications identifier (e.g. network)
|
||||||
|
* @return array
|
||||||
|
* string 'label' => The type of the notification
|
||||||
|
* string 'link' => URL to the source
|
||||||
|
* string 'image' => The avatar image
|
||||||
|
* string 'url' => The profile url of the contact
|
||||||
|
* string 'text' => The notification text
|
||||||
|
* string 'when' => The date of the notification
|
||||||
|
* string 'ago' => T relative date of the notification
|
||||||
|
* bool 'seen' => Is the notification marked as "seen"
|
||||||
|
*/
|
||||||
|
private function formatNotifs($notifs, $ident = "") {
|
||||||
|
|
||||||
|
$notif = array();
|
||||||
|
$arr = array();
|
||||||
|
|
||||||
|
if (Dbm::is_result($notifs)) {
|
||||||
|
|
||||||
|
foreach ($notifs as $it) {
|
||||||
|
// Because we use different db tables for the notification query
|
||||||
|
// we have sometimes $it['unseen'] and sometimes $it['seen].
|
||||||
|
// So we will have to transform $it['unseen']
|
||||||
|
if (array_key_exists('unseen', $it)) {
|
||||||
|
$it['seen'] = ($it['unseen'] > 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Depending on the identifier of the notification we need to use different defaults
|
||||||
|
switch ($ident) {
|
||||||
|
case 'system':
|
||||||
|
$default_item_label = 'notify';
|
||||||
|
$default_item_link = System::baseUrl(true).'/notify/view/'. $it['id'];
|
||||||
|
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
|
||||||
|
$default_item_url = $it['url'];
|
||||||
|
$default_item_text = strip_tags(bbcode($it['msg']));
|
||||||
|
$default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['date'], 'r');
|
||||||
|
$default_item_ago = relative_date($it['date']);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'home':
|
||||||
|
$default_item_label = 'comment';
|
||||||
|
$default_item_link = System::baseUrl(true).'/display/'.$it['pguid'];
|
||||||
|
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
|
||||||
|
$default_item_url = $it['author-link'];
|
||||||
|
$default_item_text = sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
|
||||||
|
$default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['created'], 'r');
|
||||||
|
$default_item_ago = relative_date($it['created']);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
|
||||||
|
$default_item_link = System::baseUrl(true).'/display/'.$it['pguid'];
|
||||||
|
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
|
||||||
|
$default_item_url = $it['author-link'];
|
||||||
|
$default_item_text = (($it['id'] == $it['parent'])
|
||||||
|
? sprintf(t("%s created a new post"), $it['author-name'])
|
||||||
|
: sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']));
|
||||||
|
$default_item_when = datetime_convert('UTC', date_default_timezone_get(), $it['created'], 'r');
|
||||||
|
$default_item_ago = relative_date($it['created']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transform the different types of notification in an usable array
|
||||||
|
switch ($it['verb']){
|
||||||
|
case ACTIVITY_LIKE:
|
||||||
|
$notif = array(
|
||||||
|
'label' => 'like',
|
||||||
|
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
||||||
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
|
'url' => $it['author-link'],
|
||||||
|
'text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']),
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_DISLIKE:
|
||||||
|
$notif = array(
|
||||||
|
'label' => 'dislike',
|
||||||
|
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
||||||
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
|
'url' => $it['author-link'],
|
||||||
|
'text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']),
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_ATTEND:
|
||||||
|
$notif = array(
|
||||||
|
'label' => 'attend',
|
||||||
|
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
||||||
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
|
'url' => $it['author-link'],
|
||||||
|
'text' => sprintf(t("%s is attending %s's event"), $it['author-name'], $it['pname']),
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_ATTENDNO:
|
||||||
|
$notif = array(
|
||||||
|
'label' => 'attendno',
|
||||||
|
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
||||||
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
|
'url' => $it['author-link'],
|
||||||
|
'text' => sprintf( t("%s is not attending %s's event"), $it['author-name'], $it['pname']),
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_ATTENDMAYBE:
|
||||||
|
$notif = array(
|
||||||
|
'label' => 'attendmaybe',
|
||||||
|
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
||||||
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
|
'url' => $it['author-link'],
|
||||||
|
'text' => sprintf(t("%s may attend %s's event"), $it['author-name'], $it['pname']),
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_FRIEND:
|
||||||
|
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
|
||||||
|
$obj = parse_xml_string($xmlhead.$it['object']);
|
||||||
|
$it['fname'] = $obj->title;
|
||||||
|
|
||||||
|
$notif = array(
|
||||||
|
'label' => 'friend',
|
||||||
|
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
||||||
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
|
'url' => $it['author-link'],
|
||||||
|
'text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']),
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$notif = array(
|
||||||
|
'label' => $default_item_label,
|
||||||
|
'link' => $default_item_link,
|
||||||
|
'image' => $default_item_image,
|
||||||
|
'url' => $default_item_url,
|
||||||
|
'text' => $default_item_text,
|
||||||
|
'when' => $default_item_when,
|
||||||
|
'ago' => $default_item_ago,
|
||||||
|
'seen' => $it['seen']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr[] = $notif;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Total number of network notifications
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @return int Number of network notifications
|
||||||
|
*/
|
||||||
|
private function networkTotal($seen = 0) {
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
|
|
||||||
|
$r = q("SELECT COUNT(*) AS `total`
|
||||||
|
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
|
||||||
|
WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
|
||||||
|
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
|
||||||
|
$sql_seen",
|
||||||
|
intval(local_user())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
return $r[0]['total'];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get network notifications
|
||||||
|
*
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @param int $start Start the query at this point
|
||||||
|
* @param int $limit Maximum number of query results
|
||||||
|
*
|
||||||
|
* @return array with
|
||||||
|
* string 'ident' => Notification identifier
|
||||||
|
* int 'total' => Total number of available network notifications
|
||||||
|
* array 'notifications' => Network notifications
|
||||||
|
*/
|
||||||
|
public function networkNotifs($seen = 0, $start = 0, $limit = 80) {
|
||||||
|
$ident = 'network';
|
||||||
|
$total = $this->networkTotal($seen);
|
||||||
|
$notifs = array();
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
|
|
||||||
|
|
||||||
|
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
|
||||||
|
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
|
||||||
|
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
|
||||||
|
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
|
||||||
|
WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
|
||||||
|
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
|
||||||
|
$sql_seen
|
||||||
|
ORDER BY `item`.`created` DESC LIMIT %d, %d ",
|
||||||
|
intval(local_user()),
|
||||||
|
intval($start),
|
||||||
|
intval($limit)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
|
|
||||||
|
$arr = array (
|
||||||
|
'notifications' => $notifs,
|
||||||
|
'ident' => $ident,
|
||||||
|
'total' => $total,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Total number of system notifications
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @return int Number of system notifications
|
||||||
|
*/
|
||||||
|
private function systemTotal($seen = 0) {
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `seen` = 0 ";
|
||||||
|
|
||||||
|
$r = q("SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
|
||||||
|
intval(local_user())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
return $r[0]['total'];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get system notifications
|
||||||
|
*
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @param int $start Start the query at this point
|
||||||
|
* @param int $limit Maximum number of query results
|
||||||
|
*
|
||||||
|
* @return array with
|
||||||
|
* string 'ident' => Notification identifier
|
||||||
|
* int 'total' => Total number of available system notifications
|
||||||
|
* array 'notifications' => System notifications
|
||||||
|
*/
|
||||||
|
public function systemNotifs($seen = 0, $start = 0, $limit = 80) {
|
||||||
|
$ident = 'system';
|
||||||
|
$total = $this->systemTotal($seen);
|
||||||
|
$notifs = array();
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `seen` = 0 ";
|
||||||
|
|
||||||
|
$r = q("SELECT `id`, `url`, `photo`, `msg`, `date`, `seen` FROM `notify`
|
||||||
|
WHERE `uid` = %d $sql_seen ORDER BY `date` DESC LIMIT %d, %d ",
|
||||||
|
intval(local_user()),
|
||||||
|
intval($start),
|
||||||
|
intval($limit)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
|
|
||||||
|
$arr = array (
|
||||||
|
'notifications' => $notifs,
|
||||||
|
'ident' => $ident,
|
||||||
|
'total' => $total,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Addional SQL query string for the personal notifications
|
||||||
|
*
|
||||||
|
* @return string The additional sql query
|
||||||
|
*/
|
||||||
|
private function _personal_sql_extra() {
|
||||||
|
$myurl = System::baseUrl(true) . '/profile/'. $this->a->user['nickname'];
|
||||||
|
$myurl = substr($myurl,strpos($myurl,'://')+3);
|
||||||
|
$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
|
||||||
|
$diasp_url = str_replace('/profile/','/u/',$myurl);
|
||||||
|
$sql_extra = sprintf(" AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
|
||||||
|
dbesc($myurl . '$'),
|
||||||
|
dbesc($myurl . '\\]'),
|
||||||
|
dbesc($diasp_url . '\\]')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $sql_extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Total number of personal notifications
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @return int Number of personal notifications
|
||||||
|
*/
|
||||||
|
private function personalTotal($seen = 0) {
|
||||||
|
$sql_seen = "";
|
||||||
|
$sql_extra = $this->_personal_sql_extra();
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
|
|
||||||
|
$r = q("SELECT COUNT(*) AS `total`
|
||||||
|
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
|
||||||
|
WHERE `item`.`visible` = 1
|
||||||
|
$sql_extra
|
||||||
|
$sql_seen
|
||||||
|
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 " ,
|
||||||
|
intval(local_user())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
return $r[0]['total'];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get personal notifications
|
||||||
|
*
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @param int $start Start the query at this point
|
||||||
|
* @param int $limit Maximum number of query results
|
||||||
|
*
|
||||||
|
* @return array with
|
||||||
|
* string 'ident' => Notification identifier
|
||||||
|
* int 'total' => Total number of available personal notifications
|
||||||
|
* array 'notifications' => Personal notifications
|
||||||
|
*/
|
||||||
|
public function personalNotifs($seen = 0, $start = 0, $limit = 80) {
|
||||||
|
$ident = 'personal';
|
||||||
|
$total = $this->personalTotal($seen);
|
||||||
|
$sql_extra = $this->_personal_sql_extra();
|
||||||
|
$notifs = array();
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
|
|
||||||
|
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
|
||||||
|
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
|
||||||
|
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
|
||||||
|
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
|
||||||
|
WHERE `item`.`visible` = 1
|
||||||
|
$sql_extra
|
||||||
|
$sql_seen
|
||||||
|
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
|
||||||
|
ORDER BY `item`.`created` DESC LIMIT %d, %d " ,
|
||||||
|
intval(local_user()),
|
||||||
|
intval($start),
|
||||||
|
intval($limit)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
|
|
||||||
|
$arr = array (
|
||||||
|
'notifications' => $notifs,
|
||||||
|
'ident' => $ident,
|
||||||
|
'total' => $total,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Total number of home notifications
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @return int Number of home notifications
|
||||||
|
*/
|
||||||
|
private function homeTotal($seen = 0) {
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
|
|
||||||
|
$r = q("SELECT COUNT(*) AS `total` FROM `item`
|
||||||
|
WHERE `item`.`visible` = 1 AND
|
||||||
|
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
|
||||||
|
$sql_seen",
|
||||||
|
intval(local_user())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
return $r[0]['total'];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get home notifications
|
||||||
|
*
|
||||||
|
* @param int|string $seen
|
||||||
|
* If 0 only include notifications into the query
|
||||||
|
* which aren't marked as "seen"
|
||||||
|
* @param int $start Start the query at this point
|
||||||
|
* @param int $limit Maximum number of query results
|
||||||
|
*
|
||||||
|
* @return array with
|
||||||
|
* string 'ident' => Notification identifier
|
||||||
|
* int 'total' => Total number of available home notifications
|
||||||
|
* array 'notifications' => Home notifications
|
||||||
|
*/
|
||||||
|
public function homeNotifs($seen = 0, $start = 0, $limit = 80) {
|
||||||
|
$ident = 'home';
|
||||||
|
$total = $this->homeTotal($seen);
|
||||||
|
$notifs = array();
|
||||||
|
$sql_seen = "";
|
||||||
|
|
||||||
|
if($seen === 0)
|
||||||
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
|
|
||||||
|
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
|
||||||
|
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
|
||||||
|
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
|
||||||
|
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
|
||||||
|
WHERE `item`.`visible` = 1 AND
|
||||||
|
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
|
||||||
|
$sql_seen
|
||||||
|
ORDER BY `item`.`created` DESC LIMIT %d, %d ",
|
||||||
|
intval(local_user()),
|
||||||
|
intval($start),
|
||||||
|
intval($limit)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
|
|
||||||
|
$arr = array (
|
||||||
|
'notifications' => $notifs,
|
||||||
|
'ident' => $ident,
|
||||||
|
'total' => $total,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Total number of introductions
|
||||||
|
* @param bool $all
|
||||||
|
* If false only include introductions into the query
|
||||||
|
* which aren't marked as ignored
|
||||||
|
* @return int Number of introductions
|
||||||
|
*/
|
||||||
|
private function introTotal($all = false) {
|
||||||
|
$sql_extra = "";
|
||||||
|
|
||||||
|
if(!$all)
|
||||||
|
$sql_extra = " AND `ignore` = 0 ";
|
||||||
|
|
||||||
|
$r = q("SELECT COUNT(*) AS `total` FROM `intro`
|
||||||
|
WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
|
||||||
|
intval($_SESSION['uid'])
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
return $r[0]['total'];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get introductions
|
||||||
|
*
|
||||||
|
* @param bool $all
|
||||||
|
* If false only include introductions into the query
|
||||||
|
* which aren't marked as ignored
|
||||||
|
* @param int $start Start the query at this point
|
||||||
|
* @param int $limit Maximum number of query results
|
||||||
|
*
|
||||||
|
* @return array with
|
||||||
|
* string 'ident' => Notification identifier
|
||||||
|
* int 'total' => Total number of available introductions
|
||||||
|
* array 'notifications' => Introductions
|
||||||
|
*/
|
||||||
|
public function introNotifs($all = false, $start = 0, $limit = 80) {
|
||||||
|
$ident = 'introductions';
|
||||||
|
$total = $this->introTotal($seen);
|
||||||
|
$notifs = array();
|
||||||
|
$sql_extra = "";
|
||||||
|
|
||||||
|
if(!$all)
|
||||||
|
$sql_extra = " AND `ignore` = 0 ";
|
||||||
|
|
||||||
|
/// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
|
||||||
|
$r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
|
||||||
|
`fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`,
|
||||||
|
`fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
|
||||||
|
`gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
|
||||||
|
`gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
|
||||||
|
`gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
|
||||||
|
FROM `intro`
|
||||||
|
LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
|
||||||
|
LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
|
||||||
|
LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
|
||||||
|
WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0
|
||||||
|
LIMIT %d, %d",
|
||||||
|
intval($_SESSION['uid']),
|
||||||
|
intval($start),
|
||||||
|
intval($limit)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Dbm::is_result($r))
|
||||||
|
$notifs = $this->formatIntros($r);
|
||||||
|
|
||||||
|
$arr = array (
|
||||||
|
'ident' => $ident,
|
||||||
|
'total' => $total,
|
||||||
|
'notifications' => $notifs,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Format the notification query in an usable array
|
||||||
|
*
|
||||||
|
* @param array $intros The array from the db query
|
||||||
|
* @return array with the introductions
|
||||||
|
*/
|
||||||
|
private function formatIntros($intros) {
|
||||||
|
$knowyou = '';
|
||||||
|
|
||||||
|
foreach($intros as $it) {
|
||||||
|
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
|
||||||
|
// We have to distinguish between these two because they use different data.
|
||||||
|
|
||||||
|
// Contact suggestions
|
||||||
|
if($it['fid']) {
|
||||||
|
|
||||||
|
$return_addr = bin2hex($this->a->user['nickname'] . '@' . $this->a->get_hostname() . (($this->a->path) ? '/' . $this->a->path : ''));
|
||||||
|
|
||||||
|
$intro = array(
|
||||||
|
'label' => 'friend_suggestion',
|
||||||
|
'notify_type' => t('Friend Suggestion'),
|
||||||
|
'intro_id' => $it['intro_id'],
|
||||||
|
'madeby' => $it['name'],
|
||||||
|
'contact_id' => $it['contact-id'],
|
||||||
|
'photo' => ((x($it,'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
|
||||||
|
'name' => $it['fname'],
|
||||||
|
'url' => zrl($it['furl']),
|
||||||
|
'hidden' => $it['hidden'] == 1,
|
||||||
|
'post_newfriend' => (intval(PConfig::get(local_user(),'system','post_newfriend')) ? '1' : 0),
|
||||||
|
|
||||||
|
'knowyou' => $knowyou,
|
||||||
|
'note' => $it['note'],
|
||||||
|
'request' => $it['frequest'] . '?addr=' . $return_addr,
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
// Normal connection requests
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$it = $this->getMissingIntroData($it);
|
||||||
|
|
||||||
|
// Don't show these data until you are connected. Diaspora is doing the same.
|
||||||
|
if($it['gnetwork'] === NETWORK_DIASPORA) {
|
||||||
|
$it['glocation'] = "";
|
||||||
|
$it['gabout'] = "";
|
||||||
|
$it['ggender'] = "";
|
||||||
|
}
|
||||||
|
$intro = array(
|
||||||
|
'label' => (($it['network'] !== NETWORK_OSTATUS) ? 'friend_request' : 'follower'),
|
||||||
|
'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
|
||||||
|
'dfrn_id' => $it['issued-id'],
|
||||||
|
'uid' => $_SESSION['uid'],
|
||||||
|
'intro_id' => $it['intro_id'],
|
||||||
|
'contact_id' => $it['contact-id'],
|
||||||
|
'photo' => ((x($it,'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
|
||||||
|
'name' => $it['name'],
|
||||||
|
'location' => bbcode($it['glocation'], false, false),
|
||||||
|
'about' => bbcode($it['gabout'], false, false),
|
||||||
|
'keywords' => $it['gkeywords'],
|
||||||
|
'gender' => $it['ggender'],
|
||||||
|
'hidden' => $it['hidden'] == 1,
|
||||||
|
'post_newfriend' => (intval(PConfig::get(local_user(),'system','post_newfriend')) ? '1' : 0),
|
||||||
|
'url' => $it['url'],
|
||||||
|
'zrl' => zrl($it['url']),
|
||||||
|
'addr' => $it['gaddr'],
|
||||||
|
'network' => $it['gnetwork'],
|
||||||
|
'knowyou' => $it['knowyou'],
|
||||||
|
'note' => $it['note'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr[] = $intro;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check for missing contact data and try to fetch the data from
|
||||||
|
* from other sources
|
||||||
|
*
|
||||||
|
* @param array $arr The input array with the intro data
|
||||||
|
*
|
||||||
|
* @return array The array with the intro data
|
||||||
|
*/
|
||||||
|
private function getMissingIntroData($arr) {
|
||||||
|
// If the network and the addr isn't available from the gcontact
|
||||||
|
// table entry, take the one of the contact table entry
|
||||||
|
if ($arr['gnetwork'] == "") {
|
||||||
|
$arr['gnetwork'] = $arr['network'];
|
||||||
|
}
|
||||||
|
if ($arr['gaddr'] == "") {
|
||||||
|
$arr['gaddr'] = $arr['addr'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the network and addr is still not available
|
||||||
|
// get the missing data data from other sources
|
||||||
|
if ($arr['gnetwork'] == "" || $arr['gaddr'] == "") {
|
||||||
|
$ret = get_contact_details_by_url($arr['url']);
|
||||||
|
|
||||||
|
if ($arr['gnetwork'] == "" && $ret['network'] != "") {
|
||||||
|
$arr['gnetwork'] = $ret['network'];
|
||||||
|
}
|
||||||
|
if ($arr['gaddr'] == "" && $ret['addr'] != "") {
|
||||||
|
$arr['gaddr'] = $ret['addr'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
use dba;
|
use dba;
|
||||||
use dbm;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file include/Core/PConfig.php
|
* @file include/Core/PConfig.php
|
||||||
|
@ -37,7 +37,7 @@ class PConfig {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
$r = dba::select('pconfig', array('v', 'k'), array('cat' => $family, 'uid' => $uid));
|
$r = dba::select('pconfig', array('v', 'k'), array('cat' => $family, 'uid' => $uid));
|
||||||
if (dbm::is_result($r)) {
|
if (Dbm::is_result($r)) {
|
||||||
while ($rr = dba::fetch($r)) {
|
while ($rr = dba::fetch($r)) {
|
||||||
$k = $rr['k'];
|
$k = $rr['k'];
|
||||||
$a->config[$uid][$family][$k] = $rr['v'];
|
$a->config[$uid][$family][$k] = $rr['v'];
|
||||||
|
@ -90,7 +90,7 @@ class PConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = dba::select('pconfig', array('v'), array('uid' => $uid, 'cat' => $family, 'k' => $key), array('limit' => 1));
|
$ret = dba::select('pconfig', array('v'), array('uid' => $uid, 'cat' => $family, 'k' => $key), array('limit' => 1));
|
||||||
if (dbm::is_result($ret)) {
|
if (Dbm::is_result($ret)) {
|
||||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
|
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
|
||||||
$a->config[$uid][$family][$key] = $val;
|
$a->config[$uid][$family][$key] = $val;
|
||||||
self::$in_db[$uid][$family][$key] = true;
|
self::$in_db[$uid][$family][$key] = true;
|
||||||
|
|
|
@ -5,10 +5,10 @@ use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
use Friendica\Util\Lock;
|
use Friendica\Util\Lock;
|
||||||
|
|
||||||
use dba;
|
use dba;
|
||||||
use dbm;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file src/Core/Worker.php
|
* @file src/Core/Worker.php
|
||||||
|
@ -142,7 +142,7 @@ class Worker {
|
||||||
*/
|
*/
|
||||||
private static function totalEntries() {
|
private static function totalEntries() {
|
||||||
$s = dba::fetch_first("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done`", NULL_DATE);
|
$s = dba::fetch_first("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done`", NULL_DATE);
|
||||||
if (dbm::is_result($s)) {
|
if (Dbm::is_result($s)) {
|
||||||
return $s["total"];
|
return $s["total"];
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -157,7 +157,7 @@ class Worker {
|
||||||
private static function highestPriority() {
|
private static function highestPriority() {
|
||||||
$condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
|
$condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
|
||||||
$s = dba::select('workerqueue', array('priority'), $condition, array('limit' => 1, 'order' => array('priority')));
|
$s = dba::select('workerqueue', array('priority'), $condition, array('limit' => 1, 'order' => array('priority')));
|
||||||
if (dbm::is_result($s)) {
|
if (Dbm::is_result($s)) {
|
||||||
return $s["priority"];
|
return $s["priority"];
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -405,7 +405,7 @@ class Worker {
|
||||||
if ($max == 0) {
|
if ($max == 0) {
|
||||||
// the maximum number of possible user connections can be a system variable
|
// the maximum number of possible user connections can be a system variable
|
||||||
$r = dba::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
|
$r = dba::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
|
||||||
if (dbm::is_result($r)) {
|
if (Dbm::is_result($r)) {
|
||||||
$max = $r["Value"];
|
$max = $r["Value"];
|
||||||
}
|
}
|
||||||
// Or it can be granted. This overrides the system variable
|
// Or it can be granted. This overrides the system variable
|
||||||
|
@ -441,7 +441,7 @@ class Worker {
|
||||||
// We will now check for the system values.
|
// We will now check for the system values.
|
||||||
// This limit could be reached although the user limits are fine.
|
// This limit could be reached although the user limits are fine.
|
||||||
$r = dba::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
|
$r = dba::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
|
||||||
if (!dbm::is_result($r)) {
|
if (!Dbm::is_result($r)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$max = intval($r["Value"]);
|
$max = intval($r["Value"]);
|
||||||
|
@ -449,7 +449,7 @@ class Worker {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$r = dba::fetch_first("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
|
$r = dba::fetch_first("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
|
||||||
if (!dbm::is_result($r)) {
|
if (!Dbm::is_result($r)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$used = intval($r["Value"]);
|
$used = intval($r["Value"]);
|
||||||
|
@ -631,7 +631,7 @@ class Worker {
|
||||||
INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done`");
|
INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done`");
|
||||||
|
|
||||||
// No active processes at all? Fine
|
// No active processes at all? Fine
|
||||||
if (!dbm::is_result($r)) {
|
if (!Dbm::is_result($r)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$priorities = array();
|
$priorities = array();
|
||||||
|
@ -754,7 +754,7 @@ class Worker {
|
||||||
|
|
||||||
// There can already be jobs for us in the queue.
|
// There can already be jobs for us in the queue.
|
||||||
$r = dba::select('workerqueue', array(), array('pid' => getmypid(), 'done' => false));
|
$r = dba::select('workerqueue', array(), array('pid' => getmypid(), 'done' => false));
|
||||||
if (dbm::is_result($r)) {
|
if (Dbm::is_result($r)) {
|
||||||
self::$db_duration += (microtime(true) - $stamp);
|
self::$db_duration += (microtime(true) - $stamp);
|
||||||
return dba::inArray($r);
|
return dba::inArray($r);
|
||||||
}
|
}
|
||||||
|
|
115
src/Database/Dbm.php
Normal file
115
src/Database/Dbm.php
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
namespace Friendica\Database;
|
||||||
|
|
||||||
|
use dba;
|
||||||
|
/**
|
||||||
|
* @brief This class contain functions for the database management
|
||||||
|
*
|
||||||
|
* This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
|
||||||
|
*/
|
||||||
|
class Dbm {
|
||||||
|
/**
|
||||||
|
* @brief Return a list of database processes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* 'list' => List of processes, separated in their different states
|
||||||
|
* 'amount' => Number of concurrent database processes
|
||||||
|
*/
|
||||||
|
public static function processlist() {
|
||||||
|
$r = q("SHOW PROCESSLIST");
|
||||||
|
$s = array();
|
||||||
|
|
||||||
|
$processes = 0;
|
||||||
|
$states = array();
|
||||||
|
foreach ($r AS $process) {
|
||||||
|
$state = trim($process["State"]);
|
||||||
|
|
||||||
|
// Filter out all non blocking processes
|
||||||
|
if (!in_array($state, array("", "init", "statistics", "updating"))) {
|
||||||
|
++$states[$state];
|
||||||
|
++$processes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$statelist = "";
|
||||||
|
foreach ($states AS $state => $usage) {
|
||||||
|
if ($statelist != "")
|
||||||
|
$statelist .= ", ";
|
||||||
|
$statelist .= $state.": ".$usage;
|
||||||
|
}
|
||||||
|
return(array("list" => $statelist, "amount" => $processes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if $array is a filled array with at least one entry.
|
||||||
|
*
|
||||||
|
* @param $array mixed A filled array with at least one entry
|
||||||
|
* @return Whether $array is a filled array or an object with rows
|
||||||
|
*/
|
||||||
|
public static function is_result($array) {
|
||||||
|
// It could be a return value from an update statement
|
||||||
|
if (is_bool($array)) {
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_object($array)) {
|
||||||
|
return dba::num_rows($array) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (is_array($array) && (count($array) > 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Callback function for "esc_array"
|
||||||
|
*
|
||||||
|
* @param mixed $value Array value
|
||||||
|
* @param string $key Array key
|
||||||
|
* @param boolean $add_quotation add quotation marks for string values
|
||||||
|
*/
|
||||||
|
private static function esc_array_callback(&$value, $key, $add_quotation) {
|
||||||
|
|
||||||
|
if (!$add_quotation) {
|
||||||
|
if (is_bool($value)) {
|
||||||
|
$value = ($value ? '1' : '0');
|
||||||
|
} else {
|
||||||
|
$value = dbesc($value);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_bool($value)) {
|
||||||
|
$value = ($value ? 'true' : 'false');
|
||||||
|
} elseif (is_float($value) || is_integer($value)) {
|
||||||
|
$value = (string)$value;
|
||||||
|
} else {
|
||||||
|
$value = "'".dbesc($value)."'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Escapes a whole array
|
||||||
|
*
|
||||||
|
* @param mixed $arr Array with values to be escaped
|
||||||
|
* @param boolean $add_quotation add quotation marks for string values
|
||||||
|
*/
|
||||||
|
public static function esc_array(&$arr, $add_quotation = false) {
|
||||||
|
array_walk($arr, 'self::esc_array_callback', $add_quotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks Converts any date string into a SQL compatible date string
|
||||||
|
*
|
||||||
|
* @param string $date a date string in any format
|
||||||
|
* @return string SQL style date string
|
||||||
|
*/
|
||||||
|
public static function date($date = 'now') {
|
||||||
|
$timestamp = strtotime($date);
|
||||||
|
|
||||||
|
// Don't allow lower date strings as '0001-01-01 00:00:00'
|
||||||
|
if ($timestamp < -62135596800) {
|
||||||
|
$timestamp = -62135596800;
|
||||||
|
}
|
||||||
|
|
||||||
|
return date('Y-m-d H:i:s', (int)$timestamp);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,9 +11,9 @@ namespace Friendica\Network;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
|
|
||||||
use dba;
|
use dba;
|
||||||
use dbm;
|
|
||||||
use Cache;
|
use Cache;
|
||||||
use xml;
|
use xml;
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ class Probe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields['updated'] = dbm::date();
|
$fields['updated'] = Dbm::date();
|
||||||
|
|
||||||
$condition = array('nurl' => normalise_link($data["url"]));
|
$condition = array('nurl' => normalise_link($data["url"]));
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ class Probe {
|
||||||
'confirm' => $data['confirm'],
|
'confirm' => $data['confirm'],
|
||||||
'poco' => $data['poco'],
|
'poco' => $data['poco'],
|
||||||
'network' => $data['network'],
|
'network' => $data['network'],
|
||||||
'success_update' => dbm::date());
|
'success_update' => Dbm::date());
|
||||||
|
|
||||||
$fieldnames = array();
|
$fieldnames = array();
|
||||||
|
|
||||||
|
@ -1501,7 +1501,7 @@ class Probe {
|
||||||
|
|
||||||
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
|
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
|
||||||
|
|
||||||
if (dbm::is_result($x) && dbm::is_result($r)) {
|
if (Dbm::is_result($x) && Dbm::is_result($r)) {
|
||||||
$mailbox = construct_mailbox_name($r[0]);
|
$mailbox = construct_mailbox_name($r[0]);
|
||||||
$password = '';
|
$password = '';
|
||||||
openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
|
openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
|
||||||
|
|
2970
src/Protocol/Dfrn.php
Normal file
2970
src/Protocol/Dfrn.php
Normal file
File diff suppressed because it is too large
Load diff
3948
src/Protocol/Diaspora.php
Normal file
3948
src/Protocol/Diaspora.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -9,9 +9,9 @@ namespace Friendica\Util;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Database\Dbm;
|
||||||
use Memcache;
|
use Memcache;
|
||||||
use dba;
|
use dba;
|
||||||
use dbm;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class contain Functions for preventing parallel execution of functions
|
* @brief This class contain Functions for preventing parallel execution of functions
|
||||||
|
@ -121,7 +121,7 @@ class Lock {
|
||||||
dba::lock('locks');
|
dba::lock('locks');
|
||||||
$lock = dba::select('locks', array('locked', 'pid'), array('name' => $fn_name), array('limit' => 1));
|
$lock = dba::select('locks', array('locked', 'pid'), array('name' => $fn_name), array('limit' => 1));
|
||||||
|
|
||||||
if (dbm::is_result($lock)) {
|
if (Dbm::is_result($lock)) {
|
||||||
if ($lock['locked']) {
|
if ($lock['locked']) {
|
||||||
// When the process id isn't used anymore, we can safely claim the lock for us.
|
// When the process id isn't used anymore, we can safely claim the lock for us.
|
||||||
if (!posix_kill($lock['pid'], 0)) {
|
if (!posix_kill($lock['pid'], 0)) {
|
||||||
|
@ -136,7 +136,7 @@ class Lock {
|
||||||
dba::update('locks', array('locked' => true, 'pid' => getmypid()), array('name' => $fn_name));
|
dba::update('locks', array('locked' => true, 'pid' => getmypid()), array('name' => $fn_name));
|
||||||
$got_lock = true;
|
$got_lock = true;
|
||||||
}
|
}
|
||||||
} elseif (!dbm::is_result($lock)) {
|
} elseif (!Dbm::is_result($lock)) {
|
||||||
dba::insert('locks', array('name' => $fn_name, 'locked' => true, 'pid' => getmypid()));
|
dba::insert('locks', array('name' => $fn_name, 'locked' => true, 'pid' => getmypid()));
|
||||||
$got_lock = true;
|
$got_lock = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue