mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-16 20:05:14 +02:00
Merge remote-tracking branch 'upstream/develop' into 1702-null-date
This commit is contained in:
commit
e301fa0832
64 changed files with 1826 additions and 2335 deletions
|
@ -702,15 +702,6 @@ function posts_from_gcontact(App $a, $gcontact_id) {
|
|||
else
|
||||
$sql = "`item`.`uid` = %d";
|
||||
|
||||
if(get_config('system', 'old_pager')) {
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `item`
|
||||
WHERE `gcontact-id` = %d and $sql",
|
||||
intval($gcontact_id),
|
||||
intval(local_user()));
|
||||
|
||||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
|
||||
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
|
||||
`author-name` AS `name`, `owner-avatar` AS `photo`,
|
||||
`owner-link` AS `url`, `owner-avatar` AS `thumb`
|
||||
|
@ -724,13 +715,9 @@ function posts_from_gcontact(App $a, $gcontact_id) {
|
|||
intval($a->pager['itemspage'])
|
||||
);
|
||||
|
||||
$o = conversation($a,$r,'community',false);
|
||||
$o = conversation($a, $r, 'community', false);
|
||||
|
||||
if(!get_config('system', 'old_pager')) {
|
||||
$o .= alt_pager($a,count($r));
|
||||
} else {
|
||||
$o .= paginate($a);
|
||||
}
|
||||
$o .= alt_pager($a, count($r));
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
@ -763,15 +750,6 @@ function posts_from_contact_url(App $a, $contact_url) {
|
|||
|
||||
$author_id = intval($r[0]["author-id"]);
|
||||
|
||||
if (get_config('system', 'old_pager')) {
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `item`
|
||||
WHERE `author-id` = %d and $sql",
|
||||
intval($author_id),
|
||||
intval(local_user()));
|
||||
|
||||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
|
||||
$r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
|
||||
" ORDER BY `item`.`created` DESC LIMIT %d, %d",
|
||||
intval($author_id),
|
||||
|
@ -780,13 +758,9 @@ function posts_from_contact_url(App $a, $contact_url) {
|
|||
intval($a->pager['itemspage'])
|
||||
);
|
||||
|
||||
$o = conversation($a,$r,'community',false);
|
||||
$o = conversation($a, $r, 'community', false);
|
||||
|
||||
if (!get_config('system', 'old_pager')) {
|
||||
$o .= alt_pager($a,count($r));
|
||||
} else {
|
||||
$o .= paginate($a);
|
||||
}
|
||||
$o .= alt_pager($a, count($r));
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
|
|
@ -1686,20 +1686,16 @@ use \Friendica\Core\Config;
|
|||
);
|
||||
|
||||
if ($r[0]['body'] != "") {
|
||||
if (!intval(get_config('system','old_share'))) {
|
||||
if (strpos($r[0]['body'], "[/share]") !== false) {
|
||||
$pos = strpos($r[0]['body'], "[share");
|
||||
$post = substr($r[0]['body'], $pos);
|
||||
} else {
|
||||
$post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
|
||||
|
||||
$post .= $r[0]['body'];
|
||||
$post .= "[/share]";
|
||||
}
|
||||
$_REQUEST['body'] = $post;
|
||||
} else
|
||||
$_REQUEST['body'] = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
|
||||
if (strpos($r[0]['body'], "[/share]") !== false) {
|
||||
$pos = strpos($r[0]['body'], "[share");
|
||||
$post = substr($r[0]['body'], $pos);
|
||||
} else {
|
||||
$post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
|
||||
|
||||
$post .= $r[0]['body'];
|
||||
$post .= "[/share]";
|
||||
}
|
||||
$_REQUEST['body'] = $post;
|
||||
$_REQUEST['profile_uid'] = api_user();
|
||||
$_REQUEST['type'] = 'wall';
|
||||
$_REQUEST['api_source'] = true;
|
||||
|
|
|
@ -125,6 +125,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
|
|||
$openid = new LightOpenID;
|
||||
$openid->identity = $openid_url;
|
||||
$_SESSION['openid'] = $openid_url;
|
||||
$_SESSION['remember'] = $_POST['remember'];
|
||||
$openid->returnUrl = App::get_baseurl(true).'/openid';
|
||||
goaway($openid->authUrl());
|
||||
} catch (Exception $e) {
|
||||
|
@ -178,17 +179,12 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
|
|||
goaway(z_root());
|
||||
}
|
||||
|
||||
// If the user specified to remember the authentication, then set a cookie
|
||||
// that expires after one week (the default is when the browser is closed).
|
||||
// The cookie will be renewed automatically.
|
||||
// The week ensures that sessions will expire after some inactivity.
|
||||
if ($_POST['remember'])
|
||||
new_cookie(604800, $r[0]);
|
||||
else
|
||||
if (! $_POST['remember']) {
|
||||
new_cookie(0); // 0 means delete on browser exit
|
||||
}
|
||||
|
||||
// if we haven't failed up this point, log them in.
|
||||
|
||||
$_SESSION['remember'] = $_POST['remember'];
|
||||
$_SESSION['last_login_date'] = datetime_convert('UTC','UTC');
|
||||
authenticate_success($record, true, true);
|
||||
}
|
||||
|
@ -203,39 +199,3 @@ function nuke_session() {
|
|||
session_unset();
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the hash that is needed for the "Friendica" cookie
|
||||
*
|
||||
* @param array $user Record from "user" table
|
||||
*
|
||||
* @return string Hashed data
|
||||
*/
|
||||
function cookie_hash($user) {
|
||||
return(hash("sha256", get_config("system", "site_prvkey").
|
||||
$user["uprvkey"].
|
||||
$user["password"]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the "Friendica" cookie
|
||||
*
|
||||
* @param int $time
|
||||
* @param array $user Record from "user" table
|
||||
*/
|
||||
function new_cookie($time, $user = array()) {
|
||||
|
||||
if ($time != 0)
|
||||
$time = $time + time();
|
||||
|
||||
if ($user)
|
||||
$value = json_encode(array("uid" => $user["uid"],
|
||||
"hash" => cookie_hash($user),
|
||||
"ip" => $_SERVER['REMOTE_ADDR']));
|
||||
else
|
||||
$value = "";
|
||||
|
||||
setcookie("Friendica", $value, $time, "/", "",
|
||||
(get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true);
|
||||
|
||||
}
|
||||
|
|
|
@ -416,8 +416,8 @@ These Fields are not added below (yet). They are here to for bug search.
|
|||
`item`.`shadow`,
|
||||
*/
|
||||
|
||||
return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
|
||||
`item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
|
||||
return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
|
||||
`item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
|
||||
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
|
||||
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
|
||||
`item`.`commented`, `item`.`created`, `item`.`edited`,
|
||||
|
@ -1066,8 +1066,9 @@ function builtin_activity_puller($item, &$conv_responses) {
|
|||
else
|
||||
$conv_responses[$mode][$item['thr-parent']] ++;
|
||||
|
||||
if((local_user()) && (local_user() == $item['uid']) && ($item['self']))
|
||||
if (public_contact() == $item['author-id']) {
|
||||
$conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
|
||||
}
|
||||
|
||||
$conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
|
||||
|
||||
|
|
|
@ -6,26 +6,9 @@
|
|||
* This script is started from mod/item.php to save some time when doing a post.
|
||||
*/
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/threads.php");
|
||||
|
||||
function create_shadowentry_run($argv, $argc) {
|
||||
global $a, $db;
|
||||
|
||||
if (is_null($a))
|
||||
$a = new App;
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
|
@ -34,9 +17,4 @@ function create_shadowentry_run($argv, $argc) {
|
|||
|
||||
add_shadow_entry($message_id);
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
create_shadowentry_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,35 +1,11 @@
|
|||
<?php
|
||||
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
|
||||
$directory = dirname($_SERVER["argv"][0]);
|
||||
|
||||
if (substr($directory, 0, 1) != "/")
|
||||
$directory = $_SERVER["PWD"]."/".$directory;
|
||||
|
||||
$directory = realpath($directory."/..");
|
||||
|
||||
chdir($directory);
|
||||
}
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/photos.php");
|
||||
require_once("include/user.php");
|
||||
|
||||
require_once('include/photos.php');
|
||||
require_once('include/user.php');
|
||||
|
||||
function cron_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
global $a;
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
@ -40,16 +16,6 @@ function cron_run(&$argv, &$argc){
|
|||
require_once('mod/nodeinfo.php');
|
||||
require_once('include/post_update.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if ($a->maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('cron', 'include/cron.php', 540))
|
||||
return;
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cron');
|
||||
|
||||
$poll_interval = intval(get_config('system','cron_interval'));
|
||||
|
@ -64,10 +30,6 @@ function cron_run(&$argv, &$argc){
|
|||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
logger('cron: start');
|
||||
|
||||
// run queue delivery process in the background
|
||||
|
@ -85,34 +47,17 @@ function cron_run(&$argv, &$argc){
|
|||
// Expire and remove user entries
|
||||
cron_expire_and_remove_users();
|
||||
|
||||
// If the worker is active, split the jobs in several sub processes
|
||||
if (get_config("system", "worker")) {
|
||||
// Check OStatus conversations
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
|
||||
// Check OStatus conversations
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
|
||||
|
||||
// Check every conversation
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
|
||||
// Check every conversation
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
|
||||
|
||||
// Call possible post update functions
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
|
||||
// Call possible post update functions
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
|
||||
|
||||
// update nodeinfo data
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
|
||||
} else {
|
||||
// Check OStatus conversations
|
||||
// Check only conversations with mentions (for a longer time)
|
||||
ostatus::check_conversations(true);
|
||||
|
||||
// Check every conversation
|
||||
ostatus::check_conversations(false);
|
||||
|
||||
// Call possible post update functions
|
||||
// see include/post_update.php for more details
|
||||
post_update();
|
||||
|
||||
// update nodeinfo data
|
||||
nodeinfo_cron();
|
||||
}
|
||||
// update nodeinfo data
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
|
||||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
|
||||
|
@ -123,6 +68,8 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
update_contact_birthdays();
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
|
||||
|
||||
set_config('system','last_expire_day',$d2);
|
||||
|
@ -213,14 +160,6 @@ function cron_poll_contacts($argc, $argv) {
|
|||
$force = true;
|
||||
}
|
||||
|
||||
$interval = intval(get_config('system','poll_interval'));
|
||||
if (!$interval)
|
||||
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
|
||||
|
||||
// If we are using the worker we don't need a delivery interval
|
||||
if (get_config("system", "worker"))
|
||||
$interval = false;
|
||||
|
||||
$sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
|
||||
|
||||
reload_plugins();
|
||||
|
@ -335,9 +274,6 @@ function cron_poll_contacts($argc, $argv) {
|
|||
} else {
|
||||
proc_run(PRIORITY_LOW, 'include/onepoll.php', $contact['id']);
|
||||
}
|
||||
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -488,8 +424,3 @@ function cron_repair_database() {
|
|||
/// - remove children when parent got lost
|
||||
/// - set contact-id in item when not present
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
cron_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -2,37 +2,11 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function cronhooks_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if ($a->maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
|
||||
return;
|
||||
}
|
||||
|
||||
load_hooks();
|
||||
|
||||
if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $hook)
|
||||
if ($hook[1] == $argv[1]) {
|
||||
|
@ -42,7 +16,7 @@ function cronhooks_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cronhook');
|
||||
$last = get_config('system', 'last_cronhook');
|
||||
|
||||
$poll_interval = intval(get_config('system','cronhook_interval'));
|
||||
if(! $poll_interval)
|
||||
|
@ -62,22 +36,16 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
$d = datetime_convert();
|
||||
|
||||
if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||
if (is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $hook) {
|
||||
logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
|
||||
}
|
||||
} else
|
||||
call_hooks('cron', $d);
|
||||
}
|
||||
|
||||
logger('cronhooks: end');
|
||||
|
||||
set_config('system','last_cronhook', time());
|
||||
set_config('system', 'last_cronhook', time());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
cronhooks_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -1,44 +1,14 @@
|
|||
<?php
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
|
||||
$directory = dirname($_SERVER["argv"][0]);
|
||||
|
||||
if (substr($directory, 0, 1) != "/")
|
||||
$directory = $_SERVER["PWD"]."/".$directory;
|
||||
|
||||
$directory = realpath($directory."/..");
|
||||
|
||||
chdir($directory);
|
||||
}
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
|
||||
function cronjobs_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/ostatus.php');
|
||||
require_once('include/post_update.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
// No parameter set? So return
|
||||
if ($argc <= 1)
|
||||
return;
|
||||
|
@ -71,8 +41,3 @@ function cronjobs_run(&$argv, &$argc){
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
cronjobs_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
320
include/dba.php
320
include/dba.php
|
@ -1,17 +1,5 @@
|
|||
<?php
|
||||
require_once("dbm.php");
|
||||
|
||||
# if PDO is avaible for mysql, use the new database abstraction
|
||||
# TODO: PDO is disabled for release 3.3. We need to investigate why
|
||||
# the update from 3.2 fails with pdo
|
||||
/*
|
||||
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
|
||||
require_once("library/dddbl2/dddbl.php");
|
||||
require_once("include/dba_pdo.php");
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
require_once('include/datetime.php');
|
||||
|
||||
/**
|
||||
|
@ -24,13 +12,12 @@ require_once('include/datetime.php');
|
|||
*
|
||||
*/
|
||||
|
||||
if (! class_exists('dba')) {
|
||||
class dba {
|
||||
|
||||
private $debug = 0;
|
||||
private $db;
|
||||
private $result;
|
||||
public $mysqli = true;
|
||||
private $driver;
|
||||
public $connected = false;
|
||||
public $error = false;
|
||||
|
||||
|
@ -53,7 +40,7 @@ class dba {
|
|||
if ($install) {
|
||||
if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
|
||||
if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
|
||||
$this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server);
|
||||
$this->error = sprintf(t('Cannot locate DNS info for database server \'%s\''), $server);
|
||||
$this->connected = false;
|
||||
$this->db = null;
|
||||
return;
|
||||
|
@ -61,37 +48,52 @@ class dba {
|
|||
}
|
||||
}
|
||||
|
||||
if (class_exists('mysqli')) {
|
||||
$this->db = @new mysqli($server,$user,$pass,$db);
|
||||
if (! mysqli_connect_errno()) {
|
||||
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
|
||||
$this->driver = 'pdo';
|
||||
$connect = "mysql:host=".$server.";dbname=".$db;
|
||||
if (isset($a->config["system"]["db_charset"])) {
|
||||
$connect .= ";charset=".$a->config["system"]["db_charset"];
|
||||
}
|
||||
$this->db = @new PDO($connect, $user, $pass);
|
||||
if (!$this->db->errorCode()) {
|
||||
$this->connected = true;
|
||||
}
|
||||
if (isset($a->config["system"]["db_charset"])) {
|
||||
$this->db->set_charset($a->config["system"]["db_charset"]);
|
||||
} elseif (class_exists('mysqli')) {
|
||||
$this->driver = 'mysqli';
|
||||
$this->db = @new mysqli($server,$user,$pass,$db);
|
||||
if (!mysqli_connect_errno()) {
|
||||
$this->connected = true;
|
||||
|
||||
if (isset($a->config["system"]["db_charset"])) {
|
||||
$this->db->set_charset($a->config["system"]["db_charset"]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->mysqli = false;
|
||||
} elseif (function_exists('mysql_connect')) {
|
||||
$this->driver = 'mysql';
|
||||
$this->db = mysql_connect($server,$user,$pass);
|
||||
if ($this->db && mysql_select_db($db,$this->db)) {
|
||||
$this->connected = true;
|
||||
|
||||
if (isset($a->config["system"]["db_charset"])) {
|
||||
mysql_set_charset($a->config["system"]["db_charset"], $this->db);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No suitable SQL driver was found.
|
||||
if (!$install) {
|
||||
system_unavailable();
|
||||
}
|
||||
if (isset($a->config["system"]["db_charset"]))
|
||||
mysql_set_charset($a->config["system"]["db_charset"], $this->db);
|
||||
}
|
||||
|
||||
if (!$this->connected) {
|
||||
$this->db = null;
|
||||
if (!$install) {
|
||||
system_unavailable();
|
||||
}
|
||||
}
|
||||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
}
|
||||
|
||||
public function getdb() {
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the MySQL server version string
|
||||
*
|
||||
|
@ -101,12 +103,18 @@ class dba {
|
|||
* @return string
|
||||
*/
|
||||
public function server_info() {
|
||||
if ($this->mysqli) {
|
||||
$return = $this->db->server_info;
|
||||
} else {
|
||||
$return = mysql_get_server_info($this->db);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$version = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
break;
|
||||
case 'mysqli':
|
||||
$version = $this->db->server_info;
|
||||
break;
|
||||
case 'mysql':
|
||||
$version = mysql_get_server_info($this->db);
|
||||
break;
|
||||
}
|
||||
return $return;
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,12 +138,18 @@ class dba {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if ($this->mysqli) {
|
||||
$return = $this->result->num_rows;
|
||||
} else {
|
||||
$return = mysql_num_rows($this->result);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$rows = $this->result->rowCount();
|
||||
break;
|
||||
case 'mysqli':
|
||||
$rows = $this->result->num_rows;
|
||||
break;
|
||||
case 'mysql':
|
||||
$rows = mysql_num_rows($this->result);
|
||||
break;
|
||||
}
|
||||
return $return;
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,8 +186,9 @@ class dba {
|
|||
if ((intval($a->config["system"]["db_loglimit_index"]) > 0)) {
|
||||
$log = (in_array($row['key'], $watchlist) AND
|
||||
($row['rows'] >= intval($a->config["system"]["db_loglimit_index"])));
|
||||
} else
|
||||
} else {
|
||||
$log = false;
|
||||
}
|
||||
|
||||
if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) AND ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) {
|
||||
$log = true;
|
||||
|
@ -203,13 +218,7 @@ class dba {
|
|||
|
||||
$this->error = '';
|
||||
|
||||
// Check the connection (This can reconnect the connection - if configured)
|
||||
if ($this->mysqli) {
|
||||
$connected = $this->db->ping();
|
||||
} else {
|
||||
$connected = mysql_ping($this->db);
|
||||
}
|
||||
$connstr = ($connected ? "Connected" : "Disonnected");
|
||||
$connstr = ($this->connected() ? "Connected" : "Disonnected");
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
|
@ -219,10 +228,22 @@ class dba {
|
|||
$sql = "/*".$a->callstack()." */ ".$sql;
|
||||
}
|
||||
|
||||
if ($this->mysqli) {
|
||||
$result = @$this->db->query($sql);
|
||||
} else {
|
||||
$result = @mysql_query($sql,$this->db);
|
||||
$columns = 0;
|
||||
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$result = @$this->db->query($sql);
|
||||
// Is used to separate between queries that returning data - or not
|
||||
if (!is_bool($result)) {
|
||||
$columns = $result->columnCount();
|
||||
}
|
||||
break;
|
||||
case 'mysqli':
|
||||
$result = @$this->db->query($sql);
|
||||
break;
|
||||
case 'mysql':
|
||||
$result = @mysql_query($sql,$this->db);
|
||||
break;
|
||||
}
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
|
@ -243,16 +264,27 @@ class dba {
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->mysqli) {
|
||||
if ($this->db->errno) {
|
||||
$this->error = $this->db->error;
|
||||
$this->errorno = $this->db->errno;
|
||||
}
|
||||
} elseif (mysql_errno($this->db)) {
|
||||
$this->error = mysql_error($this->db);
|
||||
$this->errorno = mysql_errno($this->db);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$errorInfo = $this->db->errorInfo();
|
||||
if ($errorInfo) {
|
||||
$this->error = $errorInfo[2];
|
||||
$this->errorno = $errorInfo[1];
|
||||
}
|
||||
break;
|
||||
case 'mysqli':
|
||||
if ($this->db->errno) {
|
||||
$this->error = $this->db->error;
|
||||
$this->errorno = $this->db->errno;
|
||||
}
|
||||
break;
|
||||
case 'mysql':
|
||||
if (mysql_errno($this->db)) {
|
||||
$this->error = mysql_error($this->db);
|
||||
$this->errorno = mysql_errno($this->db);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (strlen($this->error)) {
|
||||
logger('DB Error ('.$connstr.') '.$this->errorno.': '.$this->error);
|
||||
}
|
||||
|
@ -266,10 +298,16 @@ class dba {
|
|||
} elseif ($result === true) {
|
||||
$mesg = 'true';
|
||||
} else {
|
||||
if ($this->mysqli) {
|
||||
$mesg = $result->num_rows . ' results' . EOL;
|
||||
} else {
|
||||
$mesg = mysql_num_rows($result) . ' results' . EOL;
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$mesg = $result->rowCount().' results'.EOL;
|
||||
break;
|
||||
case 'mysqli':
|
||||
$mesg = $result->num_rows.' results'.EOL;
|
||||
break;
|
||||
case 'mysql':
|
||||
$mesg = mysql_num_rows($result).' results'.EOL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,7 +331,7 @@ class dba {
|
|||
}
|
||||
}
|
||||
|
||||
if (($result === true) || ($result === false)) {
|
||||
if (is_bool($result)) {
|
||||
return $result;
|
||||
}
|
||||
if ($onlyquery) {
|
||||
|
@ -302,18 +340,32 @@ class dba {
|
|||
}
|
||||
|
||||
$r = array();
|
||||
if ($this->mysqli) {
|
||||
if ($result->num_rows) {
|
||||
while($x = $result->fetch_array(MYSQLI_ASSOC))
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
while ($x = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
$r[] = $x;
|
||||
}
|
||||
$result->closeCursor();
|
||||
break;
|
||||
case 'mysqli':
|
||||
while ($x = $result->fetch_array(MYSQLI_ASSOC)) {
|
||||
$r[] = $x;
|
||||
}
|
||||
$result->free_result();
|
||||
}
|
||||
} else {
|
||||
if (mysql_num_rows($result)) {
|
||||
while($x = mysql_fetch_array($result, MYSQL_ASSOC))
|
||||
break;
|
||||
case 'mysql':
|
||||
while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) {
|
||||
$r[] = $x;
|
||||
}
|
||||
mysql_free_result($result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// PDO doesn't return "true" on successful operations - like mysqli does
|
||||
// Emulate this behaviour by checking if the query returned data and had columns
|
||||
// This should be reliable enough
|
||||
if (($this->driver == 'pdo') AND (count($r) == 0) AND ($columns == 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//$a->save_timestamp($stamp1, "database");
|
||||
|
@ -328,12 +380,16 @@ class dba {
|
|||
$x = false;
|
||||
|
||||
if ($this->result) {
|
||||
if ($this->mysqli) {
|
||||
if ($this->result->num_rows)
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$x = $this->result->fetch(PDO::FETCH_ASSOC);
|
||||
break;
|
||||
case 'mysqli':
|
||||
$x = $this->result->fetch_array(MYSQLI_ASSOC);
|
||||
} else {
|
||||
if (mysql_num_rows($this->result))
|
||||
break;
|
||||
case 'mysql':
|
||||
$x = mysql_fetch_array($this->result, MYSQL_ASSOC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return($x);
|
||||
|
@ -341,10 +397,16 @@ class dba {
|
|||
|
||||
public function qclose() {
|
||||
if ($this->result) {
|
||||
if ($this->mysqli) {
|
||||
$this->result->free_result();
|
||||
} else {
|
||||
mysql_free_result($this->result);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$this->result->closeCursor();
|
||||
break;
|
||||
case 'mysqli':
|
||||
$this->result->free_result();
|
||||
break;
|
||||
case 'mysql':
|
||||
mysql_free_result($this->result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -355,35 +417,65 @@ class dba {
|
|||
|
||||
public function escape($str) {
|
||||
if ($this->db && $this->connected) {
|
||||
if ($this->mysqli) {
|
||||
return @$this->db->real_escape_string($str);
|
||||
} else {
|
||||
return @mysql_real_escape_string($str,$this->db);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
return substr(@$this->db->quote($str, PDO::PARAM_STR), 1, -1);
|
||||
case 'mysqli':
|
||||
return @$this->db->real_escape_string($str);
|
||||
case 'mysql':
|
||||
return @mysql_real_escape_string($str,$this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function connected() {
|
||||
if ($this->mysqli) {
|
||||
$connected = $this->db->ping();
|
||||
} else {
|
||||
$connected = mysql_ping($this->db);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
// Not sure if this really is working like expected
|
||||
$connected = ($this->db->getAttribute(PDO::ATTR_CONNECTION_STATUS) != "");
|
||||
break;
|
||||
case 'mysqli':
|
||||
$connected = $this->db->ping();
|
||||
break;
|
||||
case 'mysql':
|
||||
$connected = mysql_ping($this->db);
|
||||
break;
|
||||
}
|
||||
return $connected;
|
||||
}
|
||||
|
||||
function insert_id() {
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$id = $this->db->lastInsertId();
|
||||
break;
|
||||
case 'mysqli':
|
||||
$id = $this->db->insert_id;
|
||||
break;
|
||||
case 'mysql':
|
||||
$id = mysql_insert_id($this->db);
|
||||
break;
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
if ($this->db) {
|
||||
if ($this->mysqli) {
|
||||
$this->db->close();
|
||||
} else {
|
||||
mysql_close($this->db);
|
||||
switch ($this->driver) {
|
||||
case 'pdo':
|
||||
$this->db = null;
|
||||
break;
|
||||
case 'mysqli':
|
||||
$this->db->close();
|
||||
break;
|
||||
case 'mysql':
|
||||
mysql_close($this->db);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
if (! function_exists('printable')) {
|
||||
function printable($s) {
|
||||
$s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s);
|
||||
$s = str_replace("\x00",'.',$s);
|
||||
|
@ -391,37 +483,32 @@ function printable($s) {
|
|||
$s = escape_tags($s);
|
||||
}
|
||||
return $s;
|
||||
}}
|
||||
}
|
||||
|
||||
// Procedural functions
|
||||
if (! function_exists('dbg')) {
|
||||
function dbg($state) {
|
||||
global $db;
|
||||
|
||||
if ($db) {
|
||||
$db->dbg($state);
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
if (! function_exists('dbesc')) {
|
||||
function dbesc($str) {
|
||||
global $db;
|
||||
|
||||
if ($db && $db->connected) {
|
||||
return($db->escape($str));
|
||||
} else {
|
||||
return(str_replace("'","\\'",$str));
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Function: q($sql,$args);
|
||||
// Description: execute SQL query with printf style args.
|
||||
// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
|
||||
// 'user', 1);
|
||||
|
||||
if (! function_exists('q')) {
|
||||
function q($sql) {
|
||||
|
||||
global $db;
|
||||
$args = func_get_args();
|
||||
unset($args[0]);
|
||||
|
@ -445,8 +532,7 @@ function q($sql) {
|
|||
*/
|
||||
logger('dba: no database: ' . print_r($args,true));
|
||||
return false;
|
||||
|
||||
}}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Performs a query with "dirty reads"
|
||||
|
@ -458,8 +544,8 @@ function q($sql) {
|
|||
* @return array Query array
|
||||
*/
|
||||
function qu($sql) {
|
||||
|
||||
global $db;
|
||||
|
||||
$args = func_get_args();
|
||||
unset($args[0]);
|
||||
|
||||
|
@ -484,7 +570,6 @@ function qu($sql) {
|
|||
*/
|
||||
logger('dba: no database: ' . print_r($args,true));
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -492,40 +577,31 @@ function qu($sql) {
|
|||
* Raw db query, no arguments
|
||||
*
|
||||
*/
|
||||
|
||||
if (! function_exists('dbq')) {
|
||||
function dbq($sql) {
|
||||
|
||||
global $db;
|
||||
|
||||
if ($db && $db->connected) {
|
||||
$ret = $db->q($sql);
|
||||
} else {
|
||||
$ret = false;
|
||||
}
|
||||
return $ret;
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
// Caller is responsible for ensuring that any integer arguments to
|
||||
// dbesc_array are actually integers and not malformed strings containing
|
||||
// SQL injection vectors. All integer array elements should be specifically
|
||||
// cast to int to avoid trouble.
|
||||
|
||||
|
||||
if (! function_exists('dbesc_array_cb')) {
|
||||
function dbesc_array_cb(&$item, $key) {
|
||||
if (is_string($item))
|
||||
$item = dbesc($item);
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
if (! function_exists('dbesc_array')) {
|
||||
function dbesc_array(&$arr) {
|
||||
if (is_array($arr) && count($arr)) {
|
||||
array_walk($arr,'dbesc_array_cb');
|
||||
}
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
function dba_timer() {
|
||||
return microtime(true);
|
||||
|
|
|
@ -5,26 +5,8 @@
|
|||
*/
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
use \Friendica\Core\PConfig;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function dbclean_run(&$argv, &$argc) {
|
||||
global $a, $db;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
if (!Config::get('system', 'dbclean', false)) {
|
||||
return;
|
||||
}
|
||||
|
@ -35,7 +17,7 @@ function dbclean_run(&$argv, &$argc) {
|
|||
$stage = 0;
|
||||
}
|
||||
|
||||
if (Config::get("system", "worker") AND ($stage == 0)) {
|
||||
if ($stage == 0) {
|
||||
proc_run(PRIORITY_LOW, 'include/dbclean.php', 1);
|
||||
proc_run(PRIORITY_LOW, 'include/dbclean.php', 2);
|
||||
proc_run(PRIORITY_LOW, 'include/dbclean.php', 3);
|
||||
|
@ -56,12 +38,8 @@ function remove_orphans($stage = 0) {
|
|||
|
||||
$count = 0;
|
||||
|
||||
// With activated worker we split the deletion in many small tasks
|
||||
if (Config::get("system", "worker")) {
|
||||
$limit = 1000;
|
||||
} else {
|
||||
$limit = 10000;
|
||||
}
|
||||
// We split the deletion in many small tasks
|
||||
$limit = 1000;
|
||||
|
||||
if (($stage == 1) OR ($stage == 0)) {
|
||||
logger("Deleting old global item entries from item table without user copy");
|
||||
|
@ -159,14 +137,9 @@ function remove_orphans($stage = 0) {
|
|||
}
|
||||
|
||||
// Call it again if not all entries were purged
|
||||
if (($stage != 0) AND ($count > 0) AND Config::get("system", "worker")) {
|
||||
if (($stage != 0) AND ($count > 0)) {
|
||||
proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
dbclean_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -712,18 +712,6 @@ function db_definition($charset) {
|
|||
"uid" => array("uid"),
|
||||
)
|
||||
);
|
||||
$database["deliverq"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"cmd" => array("type" => "varbinary(32)", "not null" => "1", "default" => ""),
|
||||
"item" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
|
||||
"contact" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"cmd_item_contact" => array("UNIQUE", "cmd", "item", "contact"),
|
||||
)
|
||||
);
|
||||
$database["event"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
|
|
|
@ -2,32 +2,12 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function dbupdate_run(&$argv, &$argc) {
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load();
|
||||
global $a;
|
||||
|
||||
// We are deleting the latest dbupdate entry.
|
||||
// This is done to avoid endless loops because the update was interupted.
|
||||
Config::delete('database','dbupdate_'.DB_UPDATE_VERSION);
|
||||
Config::delete('database', 'dbupdate_'.DB_UPDATE_VERSION);
|
||||
|
||||
update_db($a);
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
dbupdate_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -2,44 +2,25 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/html2plain.php');
|
||||
require_once("include/Scrape.php");
|
||||
require_once('include/Scrape.php');
|
||||
require_once('include/diaspora.php');
|
||||
require_once("include/ostatus.php");
|
||||
require_once("include/dfrn.php");
|
||||
require_once('include/ostatus.php');
|
||||
require_once('include/dfrn.php');
|
||||
|
||||
function delivery_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
require_once("include/session.php");
|
||||
require_once("include/datetime.php");
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/email.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
load_hooks();
|
||||
|
||||
if ($argc < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
logger('delivery: invoked: '. print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
|
@ -49,30 +30,6 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$contact_id = intval($argv[$x]);
|
||||
|
||||
/// @todo When switching completely to the worker we won't need this anymore
|
||||
// Some other process may have delivered this item already.
|
||||
|
||||
$r = q("SELECT * FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d LIMIT 1",
|
||||
dbesc($cmd),
|
||||
dbesc($item_id),
|
||||
dbesc($contact_id)
|
||||
);
|
||||
if (!dbm::is_result($r)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($a->maxload_reached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// It's ours to deliver. Remove it from the queue.
|
||||
|
||||
q("DELETE FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d",
|
||||
dbesc($cmd),
|
||||
dbesc($item_id),
|
||||
dbesc($contact_id)
|
||||
);
|
||||
|
||||
if (!$item_id || !$contact_id) {
|
||||
continue;
|
||||
}
|
||||
|
@ -577,8 +534,3 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
delivery_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -1,36 +1,16 @@
|
|||
<?php
|
||||
require_once("boot.php");
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
function directory_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
$dir = get_config('system', 'directory');
|
||||
|
||||
Config::load();
|
||||
|
||||
if($argc != 2)
|
||||
return;
|
||||
|
||||
load_hooks();
|
||||
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
$dir = get_config('system','directory');
|
||||
|
||||
if(! strlen($dir))
|
||||
if (!strlen($dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dir .= "/submit";
|
||||
|
||||
|
@ -39,13 +19,8 @@ function directory_run(&$argv, &$argc){
|
|||
call_hooks('globaldir_update', $arr);
|
||||
|
||||
logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG);
|
||||
if(strlen($arr['url']))
|
||||
if (strlen($arr['url'])) {
|
||||
fetch_url($dir . '?url=' . bin2hex($arr['url']));
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
directory_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -2,62 +2,64 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/socgraph.php");
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
function discover_poco_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
function discover_poco_run(&$argv, &$argc) {
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
/*
|
||||
This function can be called in these ways:
|
||||
- dirsearch <search pattern>: Searches for "search pattern" in the directory. "search pattern" is url encoded.
|
||||
- checkcontact: Updates gcontact entries
|
||||
- suggestions: Discover other servers for their contacts.
|
||||
- server <poco url>: Searches for the poco server list. "poco url" is base64 encoded.
|
||||
- update_server: Frequently check the first 250 servers for vitality.
|
||||
*/
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if ($a->maxload_reached())
|
||||
return;
|
||||
|
||||
if(($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
if (($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
$search = urldecode($argv[2]);
|
||||
$mode = 1;
|
||||
} elseif(($argc == 2) && ($argv[1] == "checkcontact")) {
|
||||
} elseif (($argc == 2) && ($argv[1] == "checkcontact")) {
|
||||
$mode = 2;
|
||||
} elseif(($argc == 2) && ($argv[1] == "suggestions")) {
|
||||
} elseif (($argc == 2) && ($argv[1] == "suggestions")) {
|
||||
$mode = 3;
|
||||
} elseif (($argc == 3) && ($argv[1] == "server")) {
|
||||
$mode = 4;
|
||||
} elseif (($argc == 2) && ($argv[1] == "update_server")) {
|
||||
$mode = 5;
|
||||
} elseif ($argc == 1) {
|
||||
$search = "";
|
||||
$mode = 0;
|
||||
} else
|
||||
} else {
|
||||
die("Unknown or missing parameter ".$argv[1]."\n");
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('discover_poco'.$mode.urlencode($search), 'include/discover_poco.php', 1140))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
}
|
||||
|
||||
logger('start '.$search);
|
||||
|
||||
if ($mode==3)
|
||||
if ($mode == 5) {
|
||||
update_server();
|
||||
} elseif ($mode == 4) {
|
||||
$server_url = base64_decode($argv[2]);
|
||||
if ($server_url == "") {
|
||||
return;
|
||||
}
|
||||
$server_url = filter_var($server_url, FILTER_SANITIZE_URL);
|
||||
if (substr(normalise_link($server_url), 0, 7) != "http://") {
|
||||
return;
|
||||
}
|
||||
$result = "Checking server ".$server_url." - ";
|
||||
$ret = poco_check_server($server_url);
|
||||
if ($ret) {
|
||||
$result .= "success";
|
||||
} else {
|
||||
$result .= "failed";
|
||||
}
|
||||
logger($result, LOGGER_DEBUG);
|
||||
} elseif ($mode == 3) {
|
||||
update_suggestions();
|
||||
elseif (($mode == 2) AND get_config('system','poco_completion'))
|
||||
} elseif (($mode == 2) AND get_config('system','poco_completion')) {
|
||||
discover_users();
|
||||
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
|
||||
} elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
|
||||
discover_directory($search);
|
||||
gs_search_user($search);
|
||||
} elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0)) {
|
||||
|
@ -74,6 +76,33 @@ function discover_poco_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the first 250 servers
|
||||
*
|
||||
*/
|
||||
function update_server() {
|
||||
$r = q("SELECT `url`, `created`, `last_failure`, `last_contact` FROM `gserver` ORDER BY rand()");
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$updated = 0;
|
||||
|
||||
foreach ($r AS $server) {
|
||||
if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) {
|
||||
continue;
|
||||
}
|
||||
logger('Update server status for server '.$server["url"], LOGGER_DEBUG);
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server["url"]));
|
||||
|
||||
if (++$updated > 250) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function discover_users() {
|
||||
logger("Discover users", LOGGER_DEBUG);
|
||||
|
||||
|
@ -84,9 +113,9 @@ function discover_users() {
|
|||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_FEED));
|
||||
|
||||
if (!$users)
|
||||
if (!$users) {
|
||||
return;
|
||||
|
||||
}
|
||||
$checked = 0;
|
||||
|
||||
foreach ($users AS $user) {
|
||||
|
@ -111,27 +140,29 @@ function discover_users() {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($user["server_url"] != "")
|
||||
if ($user["server_url"] != "") {
|
||||
$server_url = $user["server_url"];
|
||||
else
|
||||
} else {
|
||||
$server_url = poco_detect_server($user["url"]);
|
||||
|
||||
}
|
||||
if (($server_url == "") OR poco_check_server($server_url, $gcontacts[0]["network"])) {
|
||||
logger('Check user '.$user["url"]);
|
||||
poco_last_updated($user["url"], true);
|
||||
|
||||
if (++$checked > 100)
|
||||
if (++$checked > 100) {
|
||||
return;
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($user["url"])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function discover_directory($search) {
|
||||
|
||||
$data = Cache::get("dirsearch:".$search);
|
||||
if (!is_null($data)){
|
||||
if (!is_null($data)) {
|
||||
// Only search for the same item every 24 hours
|
||||
if (time() < $data + (60 * 60 * 24)) {
|
||||
logger("Already searched for ".$search." in the last 24 hours", LOGGER_DEBUG);
|
||||
|
@ -142,7 +173,7 @@ function discover_directory($search) {
|
|||
$x = fetch_url(get_server()."/lsearch?p=1&n=500&search=".urlencode($search));
|
||||
$j = json_decode($x);
|
||||
|
||||
if(count($j->results))
|
||||
if (count($j->results)) {
|
||||
foreach($j->results as $jj) {
|
||||
// Check if the contact already exists
|
||||
$exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($jj->url));
|
||||
|
@ -150,32 +181,33 @@ function discover_directory($search) {
|
|||
logger("Profile ".$jj->url." already exists (".$search.")", LOGGER_DEBUG);
|
||||
|
||||
if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND
|
||||
($exists[0]["updated"] < $exists[0]["last_failure"]))
|
||||
($exists[0]["updated"] < $exists[0]["last_failure"])) {
|
||||
continue;
|
||||
|
||||
}
|
||||
// Update the contact
|
||||
poco_last_updated($jj->url);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Harcoded paths aren't so good. But in this case it is okay.
|
||||
// First: We only will get Friendica contacts (which always are using this url schema)
|
||||
// Second: There will be no further problems if we are doing a mistake
|
||||
$server_url = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $jj->url);
|
||||
if ($server_url != $jj->url)
|
||||
$server_url = poco_detect_server($jj->url);
|
||||
if ($server_url != '') {
|
||||
if (!poco_check_server($server_url)) {
|
||||
logger("Friendica server ".$server_url." doesn't answer.", LOGGER_DEBUG);
|
||||
continue;
|
||||
}
|
||||
logger("Friendica server ".$server_url." seems to be okay.", LOGGER_DEBUG);
|
||||
logger("Friendica server ".$server_url." seems to be okay.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
logger("Check if profile ".$jj->url." is reachable (".$search.")", LOGGER_DEBUG);
|
||||
$data = probe_url($jj->url);
|
||||
if ($data["network"] == NETWORK_DFRN) {
|
||||
logger("Profile ".$jj->url." is reachable (".$search.")", LOGGER_DEBUG);
|
||||
logger("Add profile ".$jj->url." to local directory (".$search.")", LOGGER_DEBUG);
|
||||
poco_check($data["url"], $data["name"], $data["network"], $data["photo"], "", "", "", $jj->tags, $data["addr"], "", 0);
|
||||
} else {
|
||||
logger("Profile ".$jj->url." is not responding or no Friendica contact - but network ".$data["network"], LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
Cache::set("dirsearch:".$search, time(), CACHE_DAY);
|
||||
}
|
||||
|
||||
|
@ -195,14 +227,14 @@ function gs_search_user($search) {
|
|||
$url = "http://gstools.org/api/users_search/".urlencode($search);
|
||||
|
||||
$result = z_fetch_url($url);
|
||||
if (!$result["success"])
|
||||
if (!$result["success"]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
$contacts = json_decode($result["body"]);
|
||||
|
||||
if ($contacts->status == 'ERROR')
|
||||
if ($contacts->status == 'ERROR') {
|
||||
return false;
|
||||
|
||||
}
|
||||
foreach($contacts->data AS $user) {
|
||||
$contact = probe_url($user->site_address."/".$user->name);
|
||||
if ($contact["network"] != NETWORK_PHANTOM) {
|
||||
|
@ -211,9 +243,3 @@ function gs_search_user($search) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
discover_poco_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -2,32 +2,13 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function expire_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
||||
// physically remove anything that has been deleted for more than two months
|
||||
|
||||
$r = q("delete from item where deleted = 1 and changed < UTC_TIMESTAMP() - INTERVAL 60 DAY");
|
||||
|
@ -53,8 +34,3 @@ function expire_run(&$argv, &$argc){
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
expire_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
207
include/feed.php
207
include/feed.php
|
@ -17,11 +17,11 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
|
||||
$a = get_app();
|
||||
|
||||
if (!$simulate)
|
||||
if (!$simulate) {
|
||||
logger("Import Atom/RSS feed '".$contact["name"]."' (Contact ".$contact["id"].") for user ".$importer["uid"], LOGGER_DEBUG);
|
||||
else
|
||||
} else {
|
||||
logger("Test Atom/RSS feed", LOGGER_DEBUG);
|
||||
|
||||
}
|
||||
if ($xml == "") {
|
||||
logger('XML is empty.', LOGGER_DEBUG);
|
||||
return;
|
||||
|
@ -45,63 +45,69 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
$author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue;
|
||||
$author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:title/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
if ($author["author-name"] == "") {
|
||||
$author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:description/text()')->item(0)->nodeValue;
|
||||
|
||||
}
|
||||
$entries = $xpath->query('/rdf:RDF/rss:item');
|
||||
}
|
||||
|
||||
// Is it Atom?
|
||||
if ($xpath->query('/atom:feed')->length > 0) {
|
||||
$alternate = $xpath->query("atom:link[@rel='alternate']")->item(0)->attributes;
|
||||
if (is_object($alternate))
|
||||
foreach($alternate AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
if (is_object($alternate)) {
|
||||
foreach($alternate AS $attributes) {
|
||||
if ($attributes->name == "href") {
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
|
||||
if ($author["author-link"] == "")
|
||||
$author["author-link"] = $author["author-id"];
|
||||
|
||||
if ($author["author-link"] == "") {
|
||||
$self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
|
||||
if (is_object($self))
|
||||
foreach($self AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($author["author-link"] == "")
|
||||
$author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue;
|
||||
if ($author["author-link"] == "") {
|
||||
$author["author-link"] = $author["author-id"];
|
||||
}
|
||||
if ($author["author-link"] == "") {
|
||||
$self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
|
||||
if (is_object($self)) {
|
||||
foreach($self AS $attributes) {
|
||||
if ($attributes->name == "href") {
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($author["author-link"] == "") {
|
||||
$author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue;
|
||||
}
|
||||
$author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:title/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
if ($author["author-name"] == "") {
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:subtitle/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
}
|
||||
if ($author["author-name"] == "") {
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:author/atom:name/text()')->item(0)->nodeValue;
|
||||
|
||||
}
|
||||
$value = $xpath->evaluate('atom:author/poco:displayName/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$author["author-name"] = $value;
|
||||
|
||||
}
|
||||
if ($simulate) {
|
||||
$author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$author["author-nick"] = $value;
|
||||
|
||||
}
|
||||
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$author["author-location"] = $value;
|
||||
|
||||
}
|
||||
$value = $xpath->evaluate('atom:author/poco:note/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
if ($value != "") {
|
||||
$author["author-about"] = $value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
|
||||
|
@ -118,12 +124,12 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
$author["author-name"] = $xpath->evaluate('/rss/channel/title/text()')->item(0)->nodeValue;
|
||||
$author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
if ($author["author-name"] == "") {
|
||||
$author["author-name"] = $xpath->evaluate('/rss/channel/copyright/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
}
|
||||
if ($author["author-name"] == "") {
|
||||
$author["author-name"] = $xpath->evaluate('/rss/channel/description/text()')->item(0)->nodeValue;
|
||||
|
||||
}
|
||||
$author["edited"] = $author["created"] = $xpath->query('/rss/channel/pubDate/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["app"] = $xpath->evaluate('/rss/channel/generator/text()')->item(0)->nodeValue;
|
||||
|
@ -134,9 +140,9 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
if (!$simulate) {
|
||||
$author["author-link"] = $contact["url"];
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
if ($author["author-name"] == "") {
|
||||
$author["author-name"] = $contact["name"];
|
||||
|
||||
}
|
||||
$author["author-avatar"] = $contact["thumb"];
|
||||
|
||||
$author["owner-link"] = $contact["url"];
|
||||
|
@ -171,33 +177,39 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
|
||||
$entrylist = array();
|
||||
|
||||
foreach ($entries AS $entry)
|
||||
foreach ($entries AS $entry) {
|
||||
$entrylist[] = $entry;
|
||||
|
||||
}
|
||||
foreach (array_reverse($entrylist) AS $entry) {
|
||||
$item = array_merge($header, $author);
|
||||
|
||||
if (is_object($alternate))
|
||||
foreach($alternate AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
$alternate = $xpath->query("atom:link[@rel='alternate']", $entry)->item(0)->attributes;
|
||||
if (!is_object($alternate)) {
|
||||
$alternate = $xpath->query("atom:link", $entry)->item(0)->attributes;
|
||||
}
|
||||
if (is_object($alternate)) {
|
||||
foreach($alternate AS $attributes) {
|
||||
if ($attributes->name == "href") {
|
||||
$item["plink"] = $attributes->textContent;
|
||||
|
||||
if ($item["plink"] == "")
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($item["plink"] == "") {
|
||||
$item["plink"] = $xpath->evaluate('link/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($item["plink"] == "")
|
||||
}
|
||||
if ($item["plink"] == "") {
|
||||
$item["plink"] = $xpath->evaluate('rss:link/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
}
|
||||
$item["plink"] = original_url($item["plink"]);
|
||||
|
||||
$item["uri"] = $xpath->evaluate('atom:id/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($item["uri"] == "")
|
||||
if ($item["uri"] == "") {
|
||||
$item["uri"] = $xpath->evaluate('guid/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($item["uri"] == "")
|
||||
}
|
||||
if ($item["uri"] == "") {
|
||||
$item["uri"] = $item["plink"];
|
||||
|
||||
}
|
||||
$item["parent-uri"] = $item["uri"];
|
||||
|
||||
if (!$simulate) {
|
||||
|
@ -211,54 +223,50 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
|
||||
$item["title"] = $xpath->evaluate('atom:title/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($item["title"] == "")
|
||||
if ($item["title"] == "") {
|
||||
$item["title"] = $xpath->evaluate('title/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($item["title"] == "")
|
||||
}
|
||||
if ($item["title"] == "") {
|
||||
$item["title"] = $xpath->evaluate('rss:title/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
$alternate = $xpath->query("atom:link[@rel='alternate']", $entry)->item(0)->attributes;
|
||||
if (!is_object($alternate))
|
||||
$alternate = $xpath->query("atom:link", $entry)->item(0)->attributes;
|
||||
|
||||
}
|
||||
$published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($published == "")
|
||||
if ($published == "") {
|
||||
$published = $xpath->query('pubDate/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($published == "")
|
||||
}
|
||||
if ($published == "") {
|
||||
$published = $xpath->query('dc:date/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
}
|
||||
$updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($updated == "")
|
||||
if ($updated == "") {
|
||||
$updated = $published;
|
||||
|
||||
if ($published != "")
|
||||
}
|
||||
if ($published != "") {
|
||||
$item["created"] = $published;
|
||||
|
||||
if ($updated != "")
|
||||
}
|
||||
if ($updated != "") {
|
||||
$item["edited"] = $updated;
|
||||
|
||||
}
|
||||
$creator = $xpath->query('author/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($creator == "")
|
||||
if ($creator == "") {
|
||||
$creator = $xpath->query('atom:author/atom:name/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($creator == "")
|
||||
}
|
||||
if ($creator == "") {
|
||||
$creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($creator != "")
|
||||
}
|
||||
if ($creator != "") {
|
||||
$item["author-name"] = $creator;
|
||||
|
||||
if ($pubDate != "")
|
||||
}
|
||||
if ($pubDate != "") {
|
||||
$item["edited"] = $item["created"] = $pubDate;
|
||||
|
||||
}
|
||||
$creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
if ($creator != "")
|
||||
if ($creator != "") {
|
||||
$item["author-name"] = $creator;
|
||||
|
||||
}
|
||||
/// @TODO ?
|
||||
// <category>Ausland</category>
|
||||
// <media:thumbnail width="152" height="76" url="http://www.taz.de/picture/667875/192/14388767.jpg"/>
|
||||
|
@ -273,12 +281,13 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
$title = "";
|
||||
|
||||
foreach($enclosure->attributes AS $attributes) {
|
||||
if ($attributes->name == "url")
|
||||
if ($attributes->name == "url") {
|
||||
$href = $attributes->textContent;
|
||||
elseif ($attributes->name == "length")
|
||||
} elseif ($attributes->name == "length") {
|
||||
$length = $attributes->textContent;
|
||||
elseif ($attributes->name == "type")
|
||||
} elseif ($attributes->name == "type") {
|
||||
$type = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
if(strlen($item["attach"]))
|
||||
$item["attach"] .= ',';
|
||||
|
@ -292,9 +301,11 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
$preview = "";
|
||||
|
||||
// Handle enclosures and treat them as preview picture
|
||||
foreach ($attachments AS $attachment)
|
||||
if ($attachment["type"] == "image/jpeg")
|
||||
foreach ($attachments AS $attachment) {
|
||||
if ($attachment["type"] == "image/jpeg") {
|
||||
$preview = $attachment["link"];
|
||||
}
|
||||
}
|
||||
|
||||
$item["body"] = $item["title"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
|
||||
$item["tag"] = add_page_keywords($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
|
||||
|
@ -304,20 +315,20 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
} else {
|
||||
$body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue);
|
||||
|
||||
if ($body == "")
|
||||
if ($body == "") {
|
||||
$body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue);
|
||||
|
||||
if ($body == "")
|
||||
}
|
||||
if ($body == "") {
|
||||
$body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue);
|
||||
|
||||
if ($body == "")
|
||||
}
|
||||
if ($body == "") {
|
||||
$body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue);
|
||||
|
||||
}
|
||||
// remove the content of the title if it is identically to the body
|
||||
// This helps with auto generated titles e.g. from tumblr
|
||||
if (title_is_body($item["title"], $body))
|
||||
if (title_is_body($item["title"], $body)) {
|
||||
$item["title"] = "";
|
||||
|
||||
}
|
||||
$item["body"] = html2bbcode($body);
|
||||
}
|
||||
|
||||
|
@ -336,14 +347,16 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
|||
$id = item_store($item, false, $notify);
|
||||
|
||||
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
||||
} else
|
||||
} else {
|
||||
$items[] = $item;
|
||||
|
||||
if ($simulate)
|
||||
}
|
||||
if ($simulate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($simulate)
|
||||
if ($simulate) {
|
||||
return array("header" => $author, "items" => $items);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2,36 +2,14 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/Scrape.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
function gprobe_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
if($argc != 2)
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
|
||||
}
|
||||
$url = hex2bin($argv[1]);
|
||||
|
||||
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
|
@ -74,8 +52,3 @@ function gprobe_run(&$argv, &$argc){
|
|||
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
gprobe_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
264
include/like.php
264
include/like.php
|
@ -18,155 +18,169 @@ require_once("include/diaspora.php");
|
|||
function do_like($item_id, $verb) {
|
||||
$a = get_app();
|
||||
|
||||
if(! local_user() && ! remote_user()) {
|
||||
if (! local_user() && ! remote_user()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch($verb) {
|
||||
switch ($verb) {
|
||||
case 'like':
|
||||
$bodyverb = t('%1$s likes %2$s\'s %3$s');
|
||||
$activity = ACTIVITY_LIKE;
|
||||
break;
|
||||
case 'unlike':
|
||||
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
|
||||
$activity = ACTIVITY_LIKE;
|
||||
break;
|
||||
case 'dislike':
|
||||
case 'undislike':
|
||||
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
|
||||
$activity = ACTIVITY_DISLIKE;
|
||||
break;
|
||||
case 'attendyes':
|
||||
case 'unattendyes':
|
||||
$bodyverb = t('%1$s is attending %2$s\'s %3$s');
|
||||
$activity = ACTIVITY_ATTEND;
|
||||
break;
|
||||
case 'attendno':
|
||||
case 'unattendno':
|
||||
$bodyverb = t('%1$s is not attending %2$s\'s %3$s');
|
||||
$activity = ACTIVITY_ATTENDNO;
|
||||
break;
|
||||
case 'attendmaybe':
|
||||
case 'unattendmaybe':
|
||||
$bodyverb = t('%1$s may attend %2$s\'s %3$s');
|
||||
$activity = ACTIVITY_ATTENDMAYBE;
|
||||
break;
|
||||
default:
|
||||
logger('like: unknown verb ' . $verb . ' for item ' . $item_id);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Enable activity toggling instead of on/off
|
||||
$event_verb_flag = $activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE;
|
||||
|
||||
logger('like: verb ' . $verb . ' item ' . $item_id);
|
||||
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
|
||||
// Retrieve item
|
||||
$items = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
|
||||
dbesc($item_id),
|
||||
dbesc($item_id)
|
||||
);
|
||||
|
||||
if(! $item_id || (! dbm::is_result($r))) {
|
||||
logger('like: no item ' . $item_id);
|
||||
if (! $item_id || ! dbm::is_result($items)) {
|
||||
logger('like: unknown item ' . $item_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
$item = $r[0];
|
||||
$item = $items[0];
|
||||
|
||||
$owner_uid = $item['uid'];
|
||||
|
||||
if (! can_write_wall($a,$owner_uid)) {
|
||||
if (! can_write_wall($a, $item['uid'])) {
|
||||
logger('like: unable to write on wall ' . $item['uid']);
|
||||
return false;
|
||||
}
|
||||
|
||||
$remote_owner = null;
|
||||
// Retrieves the local post owner
|
||||
$owners = q("SELECT `contact`.* FROM `contact`
|
||||
WHERE `contact`.`self` = 1
|
||||
AND `contact`.`uid` = %d",
|
||||
intval($item['uid'])
|
||||
);
|
||||
if (dbm::is_result($owners)) {
|
||||
$owner_self_contact = $owners[0];
|
||||
} else {
|
||||
logger('like: unknown owner ' . $item['uid']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(! $item['wall']) {
|
||||
// The top level post may have been written by somebody on another system
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($item['contact-id']),
|
||||
intval($item['uid'])
|
||||
// Retrieve the current logged in user's public contact
|
||||
$author_id = public_contact();
|
||||
|
||||
$contacts = q("SELECT * FROM `contact` WHERE `id` = %d",
|
||||
intval($author_id)
|
||||
);
|
||||
if (dbm::is_result($contacts)) {
|
||||
$author_contact = $contacts[0];
|
||||
} else {
|
||||
logger('like: unknown author ' . $author_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Contact-id is the uid-dependant author contact
|
||||
if (local_user() == $item['uid']) {
|
||||
$item_contact_id = $owner_self_contact['id'];
|
||||
$item_contact = $owner_self_contact;
|
||||
} else {
|
||||
$item_contact_id = get_contact($author_contact['url'], $item['uid']);
|
||||
|
||||
$contacts = q("SELECT * FROM `contact` WHERE `id` = %d",
|
||||
intval($item_contact_id)
|
||||
);
|
||||
if (! dbm::is_result($r)) {
|
||||
if (dbm::is_result($contacts)) {
|
||||
$item_contact = $contacts[0];
|
||||
} else {
|
||||
logger('like: unknown item contact ' . $item_contact_id);
|
||||
return false;
|
||||
}
|
||||
if (! $r[0]['self']) {
|
||||
$remote_owner = $r[0];
|
||||
}
|
||||
}
|
||||
|
||||
// this represents the post owner on this system.
|
||||
|
||||
$r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
|
||||
WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
|
||||
intval($owner_uid)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
$owner = $r[0];
|
||||
}
|
||||
|
||||
if (! $owner) {
|
||||
logger('like: no owner');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $remote_owner) {
|
||||
$remote_owner = $owner;
|
||||
}
|
||||
|
||||
// This represents the person posting
|
||||
|
||||
if ((local_user()) && (local_user() == $owner_uid)) {
|
||||
$contact = $owner;
|
||||
} else {
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($_SESSION['visitor_id']),
|
||||
intval($owner_uid)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
$contact = $r[0];
|
||||
}
|
||||
}
|
||||
if (! $contact) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$verbs = " '".dbesc($activity)."' ";
|
||||
|
||||
// Look for an existing verb row
|
||||
// event participation are essentially radio toggles. If you make a subsequent choice,
|
||||
// we need to eradicate your first choice.
|
||||
if ($activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE) {
|
||||
$verbs = " '" . dbesc(ACTIVITY_ATTEND) . "','" . dbesc(ACTIVITY_ATTENDNO) . "','" . dbesc(ACTIVITY_ATTENDMAYBE) . "' ";
|
||||
if ($event_verb_flag) {
|
||||
$verbs = "'" . dbesc(ACTIVITY_ATTEND) . "', '" . dbesc(ACTIVITY_ATTENDNO) . "', '" . dbesc(ACTIVITY_ATTENDMAYBE) . "'";
|
||||
} else {
|
||||
$verbs = "'".dbesc($activity)."'";
|
||||
}
|
||||
|
||||
$r = q("SELECT `id`, `guid` FROM `item` WHERE `verb` IN ( $verbs ) AND `deleted` = 0
|
||||
AND `contact-id` = %d AND `uid` = %d
|
||||
AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s') LIMIT 1",
|
||||
intval($contact['id']), intval($owner_uid),
|
||||
$existing_like = q("SELECT `id`, `guid`, `verb` FROM `item`
|
||||
WHERE `verb` IN ($verbs)
|
||||
AND `deleted` = 0
|
||||
AND `author-id` = %d
|
||||
AND `uid` = %d
|
||||
AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s')
|
||||
LIMIT 1",
|
||||
intval($author_contact['id']),
|
||||
intval($item['uid']),
|
||||
dbesc($item_id), dbesc($item_id), dbesc($item['uri'])
|
||||
);
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
$like_item = $r[0];
|
||||
// If it exists, mark it as deleted
|
||||
if (dbm::is_result($existing_like)) {
|
||||
$like_item = $existing_like[0];
|
||||
|
||||
// Already voted, undo it
|
||||
$r = q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `id` = %d",
|
||||
q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `id` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($like_item['id'])
|
||||
);
|
||||
|
||||
|
||||
// Clean up the Diaspora signatures for this like
|
||||
// Go ahead and do it even if Diaspora support is disabled. We still want to clean up
|
||||
// if it had been enabled in the past
|
||||
$r = q("DELETE FROM `sign` WHERE `iid` = %d",
|
||||
q("DELETE FROM `sign` WHERE `iid` = %d",
|
||||
intval($like_item['id'])
|
||||
);
|
||||
|
||||
$like_item_id = $like_item['id'];
|
||||
proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $like_item_id);
|
||||
|
||||
if (!$event_verb_flag || $like_item['verb'] == $activity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Verb is "un-something", just trying to delete existing entries
|
||||
if (strpos($verb, 'un') === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$uri = item_new_uri($a->get_hostname(),$owner_uid);
|
||||
|
||||
// Else or if event verb different from existing row, create a new item row
|
||||
$post_type = (($item['resource-id']) ? t('photo') : t('status'));
|
||||
if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
|
||||
$post_type = t('event');
|
||||
}
|
||||
$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
|
||||
$link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
|
||||
$objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ;
|
||||
$link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . '" />' . "\n") ;
|
||||
$body = $item['body'];
|
||||
|
||||
$obj = <<< EOT
|
||||
|
@ -180,80 +194,62 @@ function do_like($item_id, $verb) {
|
|||
<content>$body</content>
|
||||
</object>
|
||||
EOT;
|
||||
if ($verb === 'like') {
|
||||
$bodyverb = t('%1$s likes %2$s\'s %3$s');
|
||||
}
|
||||
if ($verb === 'dislike') {
|
||||
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
|
||||
}
|
||||
if ($verb === 'attendyes') {
|
||||
$bodyverb = t('%1$s is attending %2$s\'s %3$s');
|
||||
}
|
||||
if ($verb === 'attendno') {
|
||||
$bodyverb = t('%1$s is not attending %2$s\'s %3$s');
|
||||
}
|
||||
if ($verb === 'attendmaybe') {
|
||||
$bodyverb = t('%1$s may attend %2$s\'s %3$s');
|
||||
}
|
||||
|
||||
if (! isset($bodyverb)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
|
||||
$ulink = '[url=' . $author_contact['url'] . ']' . $author_contact['name'] . '[/url]';
|
||||
$alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
|
||||
$plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
|
||||
$plink = '[url=' . App::get_baseurl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
|
||||
|
||||
/// @TODO Or rewrite this to multi-line initialization of the array?
|
||||
$arr = array();
|
||||
$new_item = array(
|
||||
'guid' => get_guid(32),
|
||||
'uri' => item_new_uri($a->get_hostname(), $item['uid']),
|
||||
'uid' => $item['uid'],
|
||||
'contact-id' => $item_contact_id,
|
||||
'type' => 'activity',
|
||||
'wall' => $item['wall'],
|
||||
'origin' => 1,
|
||||
'gravity' => GRAVITY_LIKE,
|
||||
'parent' => $item['id'],
|
||||
'parent-uri' => $item['uri'],
|
||||
'thr-parent' => $item['uri'],
|
||||
'owner-id' => $item['owner-id'],
|
||||
'owner-name' => $item['owner-name'],
|
||||
'owner-link' => $item['owner-link'],
|
||||
'owner-avatar' => $item['owner-avatar'],
|
||||
'author-id' => $author_contact['id'],
|
||||
'author-name' => $author_contact['name'],
|
||||
'author-link' => $author_contact['url'],
|
||||
'author-avatar' => $author_contact['thumb'],
|
||||
'body' => sprintf($bodyverb, $ulink, $alink, $plink),
|
||||
'verb' => $activity,
|
||||
'object-type' => $objtype,
|
||||
'object' => $obj,
|
||||
'allow_cid' => $item['allow_cid'],
|
||||
'allow_gid' => $item['allow_gid'],
|
||||
'deny_cid' => $item['deny_cid'],
|
||||
'deny_gid' => $item['deny_gid'],
|
||||
'visible' => 1,
|
||||
'unseen' => 1,
|
||||
'last-child' => 0
|
||||
);
|
||||
|
||||
$arr['guid'] = get_guid(32);
|
||||
$arr['uri'] = $uri;
|
||||
$arr['uid'] = $owner_uid;
|
||||
$arr['contact-id'] = $contact['id'];
|
||||
$arr['type'] = 'activity';
|
||||
$arr['wall'] = $item['wall'];
|
||||
$arr['origin'] = 1;
|
||||
$arr['gravity'] = GRAVITY_LIKE;
|
||||
$arr['parent'] = $item['id'];
|
||||
$arr['parent-uri'] = $item['uri'];
|
||||
$arr['thr-parent'] = $item['uri'];
|
||||
$arr['owner-name'] = $remote_owner['name'];
|
||||
$arr['owner-link'] = $remote_owner['url'];
|
||||
$arr['owner-avatar'] = $remote_owner['thumb'];
|
||||
$arr['author-name'] = $contact['name'];
|
||||
$arr['author-link'] = $contact['url'];
|
||||
$arr['author-avatar'] = $contact['thumb'];
|
||||
$arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
|
||||
$arr['verb'] = $activity;
|
||||
$arr['object-type'] = $objtype;
|
||||
$arr['object'] = $obj;
|
||||
$arr['allow_cid'] = $item['allow_cid'];
|
||||
$arr['allow_gid'] = $item['allow_gid'];
|
||||
$arr['deny_cid'] = $item['deny_cid'];
|
||||
$arr['deny_gid'] = $item['deny_gid'];
|
||||
$arr['visible'] = 1;
|
||||
$arr['unseen'] = 1;
|
||||
$arr['last-child'] = 0;
|
||||
|
||||
$post_id = item_store($arr);
|
||||
$new_item_id = item_store($new_item);
|
||||
|
||||
// @todo: Explain this block
|
||||
if (! $item['visible']) {
|
||||
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
|
||||
q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
|
||||
intval($item['id']),
|
||||
intval($owner_uid)
|
||||
intval($item['uid'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Save the author information for the like in case we need to relay to Diaspora
|
||||
Diaspora::store_like_signature($contact, $post_id);
|
||||
Diaspora::store_like_signature($item_contact, $new_item_id);
|
||||
|
||||
$arr['id'] = $post_id;
|
||||
$new_item['id'] = $new_item_id;
|
||||
|
||||
call_hooks('post_local_end', $arr);
|
||||
call_hooks('post_local_end', $new_item);
|
||||
|
||||
proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $post_id);
|
||||
proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $new_item_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -72,8 +72,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
|
|||
$a = get_app();
|
||||
|
||||
$ch = @curl_init($url);
|
||||
if(($redirects > 8) || (! $ch))
|
||||
return false;
|
||||
if(($redirects > 8) || (! $ch)) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/html2plain.php');
|
||||
require_once("include/Scrape.php");
|
||||
require_once('include/Scrape.php');
|
||||
require_once('include/diaspora.php');
|
||||
require_once("include/ostatus.php");
|
||||
require_once('include/ostatus.php');
|
||||
require_once('include/salmon.php');
|
||||
|
||||
/*
|
||||
|
@ -44,35 +43,17 @@ require_once('include/salmon.php');
|
|||
|
||||
|
||||
function notifier_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
require_once("include/session.php");
|
||||
require_once("include/datetime.php");
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/email.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
load_hooks();
|
||||
|
||||
if ($argc < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
|
@ -490,79 +471,22 @@ function notifier_run(&$argv, &$argc){
|
|||
if ($relocate) {
|
||||
$r = $recipients_relocate;
|
||||
} else {
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra,
|
||||
$r = q("SELECT `id`, `url`, `network`, `self` FROM `contact`
|
||||
WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra,
|
||||
dbesc($recip_str)
|
||||
);
|
||||
}
|
||||
|
||||
$interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
|
||||
|
||||
// If we are using the worker we don't need a delivery interval
|
||||
if (get_config("system", "worker")) {
|
||||
$interval = false;
|
||||
}
|
||||
// delivery loop
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $contact) {
|
||||
if (!$contact['self']) {
|
||||
if (($contact['network'] === NETWORK_DIASPORA) && ($public_message)) {
|
||||
continue;
|
||||
}
|
||||
q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)",
|
||||
dbesc($cmd),
|
||||
intval($item_id),
|
||||
intval($contact['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This controls the number of deliveries to execute with each separate delivery process.
|
||||
// By default we'll perform one delivery per process. Assuming a hostile shared hosting
|
||||
// provider, this provides the greatest chance of deliveries if processes start getting
|
||||
// killed. We can also space them out with the delivery_interval to also help avoid them
|
||||
// getting whacked.
|
||||
|
||||
// If $deliveries_per_process > 1, we will chain this number of multiple deliveries
|
||||
// together into a single process. This will reduce the overall number of processes
|
||||
// spawned for each delivery, but they will run longer.
|
||||
|
||||
// When using the workerqueue, we don't need this functionality.
|
||||
|
||||
$deliveries_per_process = intval(get_config('system','delivery_batch_count'));
|
||||
if (($deliveries_per_process <= 0) OR get_config("system", "worker")) {
|
||||
$deliveries_per_process = 1;
|
||||
}
|
||||
|
||||
$this_batch = array();
|
||||
|
||||
for ($x = 0; $x < count($r); $x ++) {
|
||||
$contact = $r[$x];
|
||||
|
||||
if ($contact['self']) {
|
||||
continue;
|
||||
}
|
||||
logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
|
||||
|
||||
// potentially more than one recipient. Start a new process and space them out a bit.
|
||||
// we will deliver single recipient types of message and email recipients here.
|
||||
|
||||
$this_batch[] = $contact['id'];
|
||||
|
||||
if (count($this_batch) >= $deliveries_per_process) {
|
||||
proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch);
|
||||
$this_batch = array();
|
||||
if ($interval) {
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// be sure to pick up any stragglers
|
||||
if (count($this_batch)) {
|
||||
proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch);
|
||||
proc_run(PRIORITY_HIGH,'include/delivery.php', $cmd, $item_id, $contact['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -614,18 +538,6 @@ function notifier_run(&$argv, &$argc){
|
|||
if (dbm::is_result($r)) {
|
||||
logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);
|
||||
|
||||
// throw everything into the queue in case we get killed
|
||||
|
||||
foreach ($r as $rr) {
|
||||
if ((! $mail) && (! $fsuggest) && (! $followup)) {
|
||||
q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)
|
||||
ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d",
|
||||
dbesc($cmd), intval($item_id), intval($rr['id']),
|
||||
dbesc($cmd), intval($item_id), intval($rr['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($r as $rr) {
|
||||
|
||||
// except for Diaspora batch jobs
|
||||
|
@ -639,9 +551,6 @@ function notifier_run(&$argv, &$argc){
|
|||
if ((! $mail) && (! $fsuggest) && (! $followup)) {
|
||||
logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]);
|
||||
proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$rr['id']);
|
||||
if ($interval) {
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -694,9 +603,3 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
notifier_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/follow.php");
|
||||
require_once('include/follow.php');
|
||||
|
||||
function RemoveReply($subject) {
|
||||
while (in_array(strtolower(substr($subject, 0, 3)), array("re:", "aw:")))
|
||||
|
@ -13,20 +12,8 @@ function RemoveReply($subject) {
|
|||
}
|
||||
|
||||
function onepoll_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
|
@ -34,12 +21,6 @@ function onepoll_run(&$argv, &$argc){
|
|||
require_once('include/socgraph.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
logger('onepoll: start');
|
||||
|
||||
$manual_id = 0;
|
||||
|
@ -61,13 +42,6 @@ function onepoll_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::is_already_running('onepoll'.$contact_id, '', 540)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
// Only poll from those with suitable relationships,
|
||||
|
@ -697,8 +671,3 @@ function onepoll_run(&$argv, &$argc){
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0) {
|
||||
onepoll_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ function poller_run($argv, $argc){
|
|||
return;
|
||||
}
|
||||
|
||||
$a->set_baseurl(Config::get('system', 'url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
$a->start_process();
|
||||
|
||||
if (poller_max_connections_reached()) {
|
||||
|
@ -465,7 +469,7 @@ function poller_too_much_workers() {
|
|||
// Are there fewer workers running as possible? Then fork a new one.
|
||||
if (!Config::get("system", "worker_dont_fork") AND ($queues > ($active + 1)) AND ($entries > 1)) {
|
||||
logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG);
|
||||
$args = array("php", "include/poller.php", "no_cron");
|
||||
$args = array("include/poller.php", "no_cron");
|
||||
$a = get_app();
|
||||
$a->proc_run($args);
|
||||
}
|
||||
|
@ -576,7 +580,7 @@ function poller_worker_process() {
|
|||
* @brief Call the front end worker
|
||||
*/
|
||||
function call_worker() {
|
||||
if (!Config::get("system", "frontend_worker") OR !Config::get("system", "worker")) {
|
||||
if (!Config::get("system", "frontend_worker")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -588,7 +592,7 @@ function call_worker() {
|
|||
* @brief Call the front end worker if there aren't any active
|
||||
*/
|
||||
function call_worker_if_idle() {
|
||||
if (!Config::get("system", "frontend_worker") OR !Config::get("system", "worker")) {
|
||||
if (!Config::get("system", "frontend_worker")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -615,7 +619,7 @@ function call_worker_if_idle() {
|
|||
|
||||
logger('Call poller', LOGGER_DEBUG);
|
||||
|
||||
$args = array("php", "include/poller.php", "no_cron");
|
||||
$args = array("include/poller.php", "no_cron");
|
||||
$a = get_app();
|
||||
$a->proc_run($args);
|
||||
return;
|
||||
|
|
|
@ -1,12 +1,31 @@
|
|||
<?php
|
||||
require_once("boot.php");
|
||||
require_once("include/ostatus.php");
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
use \Friendica\Core\PConfig;
|
||||
|
||||
require_once('include/items.php');
|
||||
require_once('include/ostatus.php');
|
||||
|
||||
function pubsubpublish_run(&$argv, &$argc){
|
||||
|
||||
if ($argc > 1) {
|
||||
$pubsubpublish_id = intval($argv[1]);
|
||||
} else {
|
||||
// We'll push to each subscriber that has push > 0,
|
||||
// i.e. there has been an update (set in notifier.php).
|
||||
$r = q("SELECT `id`, `callback_url` FROM `push_subscriber` WHERE `push` > 0");
|
||||
|
||||
foreach ($r as $rr) {
|
||||
logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]);
|
||||
}
|
||||
}
|
||||
|
||||
handle_pubsubhubbub($pubsubpublish_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function handle_pubsubhubbub($id) {
|
||||
global $a, $db;
|
||||
global $a;
|
||||
|
||||
$r = q("SELECT * FROM `push_subscriber` WHERE `id` = %d", intval($id));
|
||||
if (!$r)
|
||||
|
@ -54,70 +73,3 @@ function handle_pubsubhubbub($id) {
|
|||
intval($rr['id']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function pubsubpublish_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)){
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/items.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
if ($argc > 1) {
|
||||
$pubsubpublish_id = intval($argv[1]);
|
||||
}
|
||||
else {
|
||||
// We'll push to each subscriber that has push > 0,
|
||||
// i.e. there has been an update (set in notifier.php).
|
||||
$r = q("SELECT `id`, `callback_url` FROM `push_subscriber` WHERE `push` > 0");
|
||||
|
||||
// Use the delivery interval that is also used for the notifier
|
||||
$interval = Config::get("system", "delivery_interval", 2);
|
||||
|
||||
// If we are using the worker we don't need a delivery interval
|
||||
if (get_config("system", "worker")) {
|
||||
$interval = false;
|
||||
}
|
||||
|
||||
foreach ($r as $rr) {
|
||||
logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]);
|
||||
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
|
||||
handle_pubsubhubbub($pubsubpublish_id);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
pubsubpublish_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,41 +2,16 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/dfrn.php');
|
||||
require_once("include/datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/cache.php');
|
||||
|
||||
function queue_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if (is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)){
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once("include/session.php");
|
||||
require_once("include/datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
Config::load();
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('queue', 'include/queue.php', 540))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
global $a;
|
||||
|
||||
if ($argc > 1) {
|
||||
$queue_id = intval($argv[1]);
|
||||
|
@ -54,30 +29,13 @@ function queue_run(&$argv, &$argc){
|
|||
// Handling the pubsubhubbub requests
|
||||
proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');
|
||||
|
||||
$interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
|
||||
|
||||
// If we are using the worker we don't need a delivery interval
|
||||
if (get_config("system", "worker"))
|
||||
$interval = false;
|
||||
|
||||
$r = q("select * from deliverq where 1");
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
logger('queue: deliverq');
|
||||
proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']);
|
||||
if ($interval) {
|
||||
time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
|
||||
INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
|
||||
WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
|
||||
logger('Expired queue data :' . $rr['content'], LOGGER_DATA);
|
||||
logger('Expired queue data: ' . $rr['content'], LOGGER_DATA);
|
||||
}
|
||||
q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
}
|
||||
|
@ -86,158 +44,137 @@ function queue_run(&$argv, &$argc){
|
|||
// After that, we'll only attempt delivery once per hour.
|
||||
|
||||
$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
|
||||
} else {
|
||||
logger('queue: start for id '.$queue_id);
|
||||
|
||||
$r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id)
|
||||
);
|
||||
}
|
||||
call_hooks('queue_predeliver', $a, $r);
|
||||
|
||||
if (!$r){
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $q_item) {
|
||||
logger('Call queue for id '.$q_item['id']);
|
||||
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$queue_id)
|
||||
call_hooks('queue_predeliver', $a, $r);
|
||||
|
||||
|
||||
// delivery loop
|
||||
// delivering
|
||||
|
||||
require_once('include/salmon.php');
|
||||
require_once('include/diaspora.php');
|
||||
|
||||
foreach($r as $q_item) {
|
||||
$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id));
|
||||
|
||||
// queue_predeliver hooks may have changed the queue db details,
|
||||
// so check again if this entry still needs processing
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($queue_id) {
|
||||
$qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id));
|
||||
} elseif (get_config("system", "worker")) {
|
||||
logger('Call queue for id '.$q_item['id']);
|
||||
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
|
||||
continue;
|
||||
} else
|
||||
$qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
|
||||
intval($q_item['id']));
|
||||
$q_item = $r[0];
|
||||
|
||||
if (!dbm::is_result($qi)) {
|
||||
continue;
|
||||
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
|
||||
intval($q_item['cid'])
|
||||
);
|
||||
|
||||
if (!dbm::is_result($c)) {
|
||||
remove_queue_item($q_item['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
$dead = Cache::get($cachekey_deadguy.$c[0]['notify']);
|
||||
|
||||
if (!is_null($dead) AND $dead) {
|
||||
logger('queue: skipping known dead url: '.$c[0]['notify']);
|
||||
update_queue_time($q_item['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
$server = poco_detect_server($c[0]['url']);
|
||||
|
||||
if ($server != "") {
|
||||
$vital = Cache::get($cachekey_server.$server);
|
||||
|
||||
if (is_null($vital)) {
|
||||
logger("Check server ".$server." (".$c[0]["network"].")");
|
||||
|
||||
$vital = poco_check_server($server, $c[0]["network"], true);
|
||||
Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR);
|
||||
}
|
||||
|
||||
|
||||
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
|
||||
intval($qi[0]['cid'])
|
||||
);
|
||||
if (! dbm::is_result($c)) {
|
||||
remove_queue_item($q_item['id']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$dead = Cache::get($cachekey_deadguy.$c[0]['notify']);
|
||||
|
||||
if (!is_null($dead) AND $dead) {
|
||||
logger('queue: skipping known dead url: '.$c[0]['notify']);
|
||||
if (!is_null($vital) AND !$vital) {
|
||||
logger('queue: skipping dead server: '.$server);
|
||||
update_queue_time($q_item['id']);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$server = poco_detect_server($c[0]['url']);
|
||||
$u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
|
||||
FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval($c[0]['uid'])
|
||||
);
|
||||
if (!dbm::is_result($u)) {
|
||||
remove_queue_item($q_item['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($server != "") {
|
||||
$vital = Cache::get($cachekey_server.$server);
|
||||
$data = $q_item['content'];
|
||||
$public = $q_item['batch'];
|
||||
$contact = $c[0];
|
||||
$owner = $u[0];
|
||||
|
||||
if (is_null($vital)) {
|
||||
logger("Check server ".$server." (".$c[0]["network"].")");
|
||||
$deliver_status = 0;
|
||||
|
||||
$vital = poco_check_server($server, $c[0]["network"], true);
|
||||
Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR);
|
||||
}
|
||||
switch ($contact['network']) {
|
||||
case NETWORK_DFRN:
|
||||
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = dfrn::deliver($owner, $contact, $data);
|
||||
|
||||
if (!is_null($vital) AND !$vital) {
|
||||
logger('queue: skipping dead server: '.$server);
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
continue;
|
||||
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NETWORK_OSTATUS:
|
||||
if ($contact['notify']) {
|
||||
logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = slapper($owner, $contact['notify'], $data);
|
||||
|
||||
$u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
|
||||
FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval($c[0]['uid'])
|
||||
);
|
||||
if (! dbm::is_result($u)) {
|
||||
remove_queue_item($q_item['id']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $qi[0]['content'];
|
||||
$public = $qi[0]['batch'];
|
||||
$contact = $c[0];
|
||||
$owner = $u[0];
|
||||
|
||||
$deliver_status = 0;
|
||||
|
||||
switch($contact['network']) {
|
||||
case NETWORK_DFRN:
|
||||
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = dfrn::deliver($owner,$contact,$data);
|
||||
|
||||
if ($deliver_status < 0) {
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
break;
|
||||
case NETWORK_OSTATUS:
|
||||
if ($contact['notify']) {
|
||||
logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = slapper($owner,$contact['notify'],$data);
|
||||
}
|
||||
break;
|
||||
case NETWORK_DIASPORA:
|
||||
if ($contact['notify']) {
|
||||
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true);
|
||||
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NETWORK_DIASPORA:
|
||||
if ($contact['notify']) {
|
||||
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = Diaspora::transmit($owner,$contact,$data,$public,true);
|
||||
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
|
||||
call_hooks('queue_deliver', $a, $params);
|
||||
|
||||
if ($params['result']) {
|
||||
remove_queue_item($q_item['id']);
|
||||
} else {
|
||||
if ($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR);
|
||||
} else {
|
||||
remove_queue_item($q_item['id']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
|
||||
call_hooks('queue_deliver', $a, $params);
|
||||
|
||||
if ($params['result']) {
|
||||
remove_queue_item($q_item['id']);
|
||||
} else {
|
||||
update_queue_time($q_item['id']);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
logger('Deliver status '.(int)$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
|
||||
}
|
||||
logger('Deliver status '.(int)$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
queue_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -6,24 +6,7 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function remove_contact_run($argv, $argc) {
|
||||
global $a, $db;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
|
@ -46,9 +29,4 @@ function remove_contact_run($argv, $argc) {
|
|||
|
||||
q("DELETE FROM `queue` WHERE `cid` = %d", intval($id));
|
||||
}
|
||||
|
||||
if (array_search(__file__, get_included_files()) === 0) {
|
||||
remove_contact_run($_SERVER["argv"], $_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @brief Calculate the hash that is needed for the "Friendica" cookie
|
||||
*
|
||||
* @param array $user Record from "user" table
|
||||
*
|
||||
* @return string Hashed data
|
||||
*/
|
||||
function cookie_hash($user) {
|
||||
return(hash("sha256", get_config("system", "site_prvkey").
|
||||
$user["uprvkey"].
|
||||
$user["password"]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the "Friendica" cookie
|
||||
*
|
||||
* @param int $time
|
||||
* @param array $user Record from "user" table
|
||||
*/
|
||||
function new_cookie($time, $user = array()) {
|
||||
|
||||
if ($time != 0) {
|
||||
$time = $time + time();
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$value = json_encode(array("uid" => $user["uid"],
|
||||
"hash" => cookie_hash($user),
|
||||
"ip" => $_SERVER['REMOTE_ADDR']));
|
||||
}
|
||||
else {
|
||||
$value = "";
|
||||
}
|
||||
|
||||
setcookie("Friendica", $value, $time, "/", "",
|
||||
(get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true);
|
||||
|
||||
}
|
||||
|
||||
function authenticate_success($user_record, $login_initial = false, $interactive = false, $login_refresh = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
@ -94,6 +133,21 @@ function authenticate_success($user_record, $login_initial = false, $interactive
|
|||
|
||||
|
||||
}
|
||||
|
||||
if ($login_initial) {
|
||||
// If the user specified to remember the authentication, then set a cookie
|
||||
// that expires after one week (the default is when the browser is closed).
|
||||
// The cookie will be renewed automatically.
|
||||
// The week ensures that sessions will expire after some inactivity.
|
||||
if ($_SESSION['remember']) {
|
||||
logger('Injecting cookie for remembered user '. $_SESSION['remember_user']['nickname']);
|
||||
new_cookie(604800, $user_record);
|
||||
unset($_SESSION['remember']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($login_initial) {
|
||||
call_hooks('logged_in', $a->user);
|
||||
|
||||
|
|
|
@ -5,20 +5,26 @@ use \Friendica\Core\Config;
|
|||
require_once("boot.php");
|
||||
require_once("include/threads.php");
|
||||
|
||||
global $a, $db;
|
||||
function shadowupdate_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a))
|
||||
$a = new App;
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
update_shadow_copy();
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
update_shadow_copy();
|
||||
killme();
|
||||
?>
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
shadowupdate_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -309,7 +309,18 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
|||
|
||||
logger("profile-check generation: ".$generation." Network: ".$network." URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG);
|
||||
|
||||
poco_check_server($server_url, $network);
|
||||
// We check the server url to be sure that it is a real one
|
||||
$server_url2 = poco_detect_server($profile_url);
|
||||
|
||||
// We are no sure that it is a correct URL. So we use it in the future
|
||||
if ($server_url2 != "") {
|
||||
$server_url = $server_url2;
|
||||
}
|
||||
|
||||
// The server URL doesn't seem to be valid, so we don't store it.
|
||||
if (!poco_check_server($server_url, $network)) {
|
||||
$server_url = "";
|
||||
}
|
||||
|
||||
$gcontact = array("url" => $profile_url,
|
||||
"addr" => $addr,
|
||||
|
@ -401,13 +412,47 @@ function poco_detect_server($profile) {
|
|||
|
||||
// Mastodon
|
||||
if ($server_url == "") {
|
||||
$red = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile);
|
||||
if ($red != $profile) {
|
||||
$server_url = $red;
|
||||
$mastodon = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile);
|
||||
if ($mastodon != $profile) {
|
||||
$server_url = $mastodon;
|
||||
$network = NETWORK_OSTATUS;
|
||||
}
|
||||
}
|
||||
|
||||
// Numeric OStatus variant
|
||||
if ($server_url == "") {
|
||||
$ostatus = preg_replace("=(https?://)(.*)/user/(.*)=ism", "$1$2", $profile);
|
||||
if ($ostatus != $profile) {
|
||||
$server_url = $ostatus;
|
||||
$network = NETWORK_OSTATUS;
|
||||
}
|
||||
}
|
||||
|
||||
// Wild guess
|
||||
if ($server_url == "") {
|
||||
$base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile);
|
||||
if ($base != $profile) {
|
||||
$server_url = $base;
|
||||
$network = NETWORK_PHANTOM;
|
||||
}
|
||||
}
|
||||
|
||||
if ($server_url == "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
$r = q("SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`",
|
||||
dbesc(normalise_link($server_url)));
|
||||
if (dbm::is_result($r)) {
|
||||
return $server_url;
|
||||
}
|
||||
|
||||
// Fetch the host-meta to check if this really is a server
|
||||
$serverret = z_fetch_url($server_url."/.well-known/host-meta");
|
||||
if (!$serverret["success"]) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return $server_url;
|
||||
}
|
||||
|
||||
|
@ -424,10 +469,12 @@ function poco_last_updated($profile, $force = false) {
|
|||
q("UPDATE `gcontact` SET `created` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($profile)));
|
||||
|
||||
if ($gcontacts[0]["server_url"] != "")
|
||||
if ($gcontacts[0]["server_url"] != "") {
|
||||
$server_url = $gcontacts[0]["server_url"];
|
||||
else
|
||||
}
|
||||
if (($server_url == '') OR ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"])) {
|
||||
$server_url = poco_detect_server($profile);
|
||||
}
|
||||
|
||||
if (!in_array($gcontacts[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_FEED, NETWORK_OSTATUS, ""))) {
|
||||
logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
|
||||
|
@ -680,6 +727,213 @@ function poco_to_boolean($val) {
|
|||
return ($val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detect server type (Hubzilla or Friendica) via the poco data
|
||||
*
|
||||
* @param object $data POCO data
|
||||
* @return array Server data
|
||||
*/
|
||||
function poco_detect_poco_data($data) {
|
||||
$server = false;
|
||||
|
||||
if (!isset($data->entry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($data->entry) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($data->entry[0]->urls)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($data->entry[0]->urls) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data->entry[0]->urls AS $url) {
|
||||
if ($url->type == 'zot') {
|
||||
$server = array();
|
||||
$server["platform"] = 'Hubzilla';
|
||||
$server["network"] = NETWORK_DIASPORA;
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detect server type by using the nodeinfo data
|
||||
*
|
||||
* @param string $server_url address of the server
|
||||
* @return array Server data
|
||||
*/
|
||||
function poco_fetch_nodeinfo($server_url) {
|
||||
$serverret = z_fetch_url($server_url."/.well-known/nodeinfo");
|
||||
if (!$serverret["success"]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$nodeinfo = json_decode($serverret['body']);
|
||||
|
||||
if (!is_object($nodeinfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($nodeinfo->links)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$nodeinfo_url = '';
|
||||
|
||||
foreach ($nodeinfo->links AS $link) {
|
||||
if ($link->rel == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
|
||||
$nodeinfo_url = $link->href;
|
||||
}
|
||||
}
|
||||
|
||||
if ($nodeinfo_url == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$serverret = z_fetch_url($nodeinfo_url);
|
||||
if (!$serverret["success"]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$nodeinfo = json_decode($serverret['body']);
|
||||
|
||||
if (!is_object($nodeinfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$server = array();
|
||||
|
||||
$server['register_policy'] = REGISTER_CLOSED;
|
||||
|
||||
if (is_bool($nodeinfo->openRegistrations) AND $nodeinfo->openRegistrations) {
|
||||
$server['register_policy'] = REGISTER_OPEN;
|
||||
}
|
||||
|
||||
if (is_object($nodeinfo->software)) {
|
||||
if (isset($nodeinfo->software->name)) {
|
||||
$server['platform'] = $nodeinfo->software->name;
|
||||
}
|
||||
|
||||
if (isset($nodeinfo->software->version)) {
|
||||
$server['version'] = $nodeinfo->software->version;
|
||||
// Version numbers on Nodeinfo are presented with additional info, e.g.:
|
||||
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
|
||||
$server['version'] = preg_replace("=(.+)-(.{4,})=ism", "$1", $server['version']);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($nodeinfo->metadata)) {
|
||||
if (isset($nodeinfo->metadata->nodeName)) {
|
||||
$server['site_name'] = $nodeinfo->metadata->nodeName;
|
||||
}
|
||||
}
|
||||
|
||||
$diaspora = false;
|
||||
$friendica = false;
|
||||
$gnusocial = false;
|
||||
|
||||
if (is_array($nodeinfo->protocols->inbound)) {
|
||||
foreach ($nodeinfo->protocols->inbound AS $inbound) {
|
||||
if ($inbound == 'diaspora') {
|
||||
$diaspora = true;
|
||||
}
|
||||
if ($inbound == 'friendica') {
|
||||
$friendica = true;
|
||||
}
|
||||
if ($inbound == 'gnusocial') {
|
||||
$gnusocial = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($gnusocial) {
|
||||
$server['network'] = NETWORK_OSTATUS;
|
||||
}
|
||||
if ($diaspora) {
|
||||
$server['network'] = NETWORK_DIASPORA;
|
||||
}
|
||||
if ($friendica) {
|
||||
$server['network'] = NETWORK_DFRN;
|
||||
}
|
||||
|
||||
if (!$server) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detect server type (Hubzilla or Friendica) via the front page body
|
||||
*
|
||||
* @param string $body Front page of the server
|
||||
* @return array Server data
|
||||
*/
|
||||
function poco_detect_server_type($body) {
|
||||
$server = false;
|
||||
|
||||
$doc = new \DOMDocument();
|
||||
@$doc->loadHTML($body);
|
||||
$xpath = new \DomXPath($doc);
|
||||
|
||||
$list = $xpath->query("//meta[@name]");
|
||||
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
if ($attr['name'] == 'generator') {
|
||||
$version_part = explode(" ", $attr['content']);
|
||||
if (count($version_part) == 2) {
|
||||
if (in_array($version_part[0], array("Friendika", "Friendica"))) {
|
||||
$server = array();
|
||||
$server["platform"] = $version_part[0];
|
||||
$server["version"] = $version_part[1];
|
||||
$server["network"] = NETWORK_DFRN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$server) {
|
||||
$list = $xpath->query("//meta[@property]");
|
||||
|
||||
foreach ($list as $node) {
|
||||
$attr = array();
|
||||
if ($node->attributes->length) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$attr[$attribute->name] = $attribute->value;
|
||||
}
|
||||
}
|
||||
if ($attr['property'] == 'generator') {
|
||||
if (in_array($attr['content'], array("hubzilla", "BlaBlaNet"))) {
|
||||
$server = array();
|
||||
$server["platform"] = $attr['content'];
|
||||
$server["version"] = "";
|
||||
$server["network"] = NETWORK_DIASPORA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$server) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$server["site_name"] = $xpath->evaluate($element."//head/title/text()", $context)->item(0)->nodeValue;
|
||||
return $server;
|
||||
}
|
||||
|
||||
function poco_check_server($server_url, $network = "", $force = false) {
|
||||
|
||||
// Unify the server address
|
||||
|
@ -729,7 +983,9 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$servers[0]["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
|
||||
|
||||
$failure = false;
|
||||
$possible_failure = false;
|
||||
$orig_last_failure = $last_failure;
|
||||
$orig_last_contact = $last_contact;
|
||||
|
||||
// Check if the page is accessible via SSL.
|
||||
$orig_server_url = $server_url;
|
||||
|
@ -769,18 +1025,58 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
$last_failure = datetime_convert();
|
||||
$failure = true;
|
||||
}
|
||||
$possible_failure = true;
|
||||
} elseif ($network == NETWORK_DIASPORA)
|
||||
$last_contact = datetime_convert();
|
||||
|
||||
// If the server has no possible failure we reset the cached data
|
||||
if (!$possible_failure) {
|
||||
$version = "";
|
||||
$platform = "";
|
||||
$site_name = "";
|
||||
$info = "";
|
||||
$register_policy = -1;
|
||||
}
|
||||
|
||||
// Look for poco
|
||||
if (!$failure) {
|
||||
// Test for Diaspora
|
||||
$serverret = z_fetch_url($server_url."/poco");
|
||||
if ($serverret["success"]) {
|
||||
$data = json_decode($serverret["body"]);
|
||||
if (isset($data->totalResults)) {
|
||||
$poco = $server_url."/poco";
|
||||
$last_contact = datetime_convert();
|
||||
|
||||
$server = poco_detect_poco_data($data);
|
||||
if ($server) {
|
||||
$platform = $server['platform'];
|
||||
$network = $server['network'];
|
||||
$version = '';
|
||||
$site_name = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$failure) {
|
||||
// Test for Diaspora, Hubzilla, Mastodon or older Friendica servers
|
||||
$serverret = z_fetch_url($server_url);
|
||||
|
||||
if (!$serverret["success"] OR ($serverret["body"] == ""))
|
||||
if (!$serverret["success"] OR ($serverret["body"] == "")) {
|
||||
$last_failure = datetime_convert();
|
||||
$failure = true;
|
||||
else {
|
||||
} else {
|
||||
$server = poco_detect_server_type($serverret["body"]);
|
||||
if ($server) {
|
||||
$platform = $server['platform'];
|
||||
$network = $server['network'];
|
||||
$version = $server['version'];
|
||||
$site_name = $server['site_name'];
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
|
||||
$lines = explode("\n",$serverret["header"]);
|
||||
if(count($lines))
|
||||
if(count($lines)) {
|
||||
foreach($lines as $line) {
|
||||
$line = trim($line);
|
||||
if(stristr($line,'X-Diaspora-Version:')) {
|
||||
|
@ -790,6 +1086,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
$network = NETWORK_DIASPORA;
|
||||
$versionparts = explode("-", $version);
|
||||
$version = $versionparts[0];
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
|
||||
if(stristr($line,'Server: Mastodon')) {
|
||||
|
@ -797,12 +1094,14 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
$network = NETWORK_OSTATUS;
|
||||
// Mastodon doesn't reveal version numbers
|
||||
$version = "";
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$failure) {
|
||||
if (!$failure AND ($poco == "")) {
|
||||
// Test for Statusnet
|
||||
// Will also return data for Friendica and GNU Social - but it will be overwritten later
|
||||
// The "not implemented" is a special treatment for really, really old Friendica versions
|
||||
|
@ -810,8 +1109,11 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
|
||||
($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
|
||||
$platform = "StatusNet";
|
||||
$version = trim($serverret["body"], '"');
|
||||
// Remove junk that some GNU Social servers return
|
||||
$version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
|
||||
$version = trim($version, '"');
|
||||
$network = NETWORK_OSTATUS;
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
|
||||
// Test for GNU Social
|
||||
|
@ -819,17 +1121,32 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
|
||||
($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
|
||||
$platform = "GNU Social";
|
||||
$version = trim($serverret["body"], '"');
|
||||
// Remove junk that some GNU Social servers return
|
||||
$version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
|
||||
$version = trim($version, '"');
|
||||
$network = NETWORK_OSTATUS;
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$failure) {
|
||||
// Test for Hubzilla, Redmatrix or Friendica
|
||||
$serverret = z_fetch_url($server_url."/api/statusnet/config.json");
|
||||
if ($serverret["success"]) {
|
||||
$data = json_decode($serverret["body"]);
|
||||
|
||||
if (isset($data->site->server)) {
|
||||
$last_contact = datetime_convert();
|
||||
|
||||
if (isset($data->site->platform)) {
|
||||
$platform = $data->site->platform->PLATFORM_NAME;
|
||||
$version = $data->site->platform->STD_VERSION;
|
||||
$network = NETWORK_DIASPORA;
|
||||
}
|
||||
if (isset($data->site->BlaBlaNet)) {
|
||||
$platform = $data->site->BlaBlaNet->PLATFORM_NAME;
|
||||
$version = $data->site->BlaBlaNet->STD_VERSION;
|
||||
$network = NETWORK_DIASPORA;
|
||||
}
|
||||
if (isset($data->site->hubzilla)) {
|
||||
$platform = $data->site->hubzilla->PLATFORM_NAME;
|
||||
$version = $data->site->hubzilla->RED_VERSION;
|
||||
|
@ -866,32 +1183,66 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
|
||||
if (!$failure) {
|
||||
$serverret = z_fetch_url($server_url."/statistics.json");
|
||||
if ($serverret["success"]) {
|
||||
$data = json_decode($serverret["body"]);
|
||||
if ($version == "")
|
||||
if (isset($data->version)) {
|
||||
$version = $data->version;
|
||||
// Version numbers on statistics.json are presented with additional info, e.g.:
|
||||
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
|
||||
$version = preg_replace("=(.+)-(.{4,})=ism", "$1", $version);
|
||||
}
|
||||
|
||||
$site_name = $data->name;
|
||||
|
||||
if (isset($data->network) AND ($platform == ""))
|
||||
if (isset($data->network)) {
|
||||
$platform = $data->network;
|
||||
}
|
||||
|
||||
if ($platform == "Diaspora")
|
||||
if ($platform == "Diaspora") {
|
||||
$network = NETWORK_DIASPORA;
|
||||
}
|
||||
|
||||
if ($data->registrations_open)
|
||||
if ($data->registrations_open) {
|
||||
$register_policy = REGISTER_OPEN;
|
||||
else
|
||||
} else {
|
||||
$register_policy = REGISTER_CLOSED;
|
||||
}
|
||||
|
||||
if (isset($data->version))
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
}
|
||||
|
||||
// Query nodeinfo. Working for (at least) Diaspora and Friendica.
|
||||
if (!$failure) {
|
||||
$server = poco_fetch_nodeinfo($server_url);
|
||||
if ($server) {
|
||||
$register_policy = $server['register_policy'];
|
||||
|
||||
if (isset($server['platform'])) {
|
||||
$platform = $server['platform'];
|
||||
}
|
||||
|
||||
if (isset($server['network'])) {
|
||||
$network = $server['network'];
|
||||
}
|
||||
|
||||
if (isset($server['version'])) {
|
||||
$version = $server['version'];
|
||||
}
|
||||
|
||||
if (isset($server['site_name'])) {
|
||||
$site_name = $server['site_name'];
|
||||
}
|
||||
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
}
|
||||
|
||||
// Check for noscrape
|
||||
// Friendica servers could be detected as OStatus servers
|
||||
if (!$failure AND in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS))) {
|
||||
|
@ -929,16 +1280,21 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
}
|
||||
}
|
||||
|
||||
// Look for poco
|
||||
if (!$failure) {
|
||||
$serverret = z_fetch_url($server_url."/poco");
|
||||
if ($serverret["success"]) {
|
||||
$data = json_decode($serverret["body"]);
|
||||
if (isset($data->totalResults)) {
|
||||
$poco = $server_url."/poco";
|
||||
$last_contact = datetime_convert();
|
||||
}
|
||||
}
|
||||
if ($possible_failure AND !$failure) {
|
||||
$last_failure = datetime_convert();
|
||||
$failure = true;
|
||||
}
|
||||
|
||||
if ($failure) {
|
||||
$last_contact = $orig_last_contact;
|
||||
} else {
|
||||
$last_failure = $orig_last_failure;
|
||||
}
|
||||
|
||||
if (($last_contact <= $last_failure) AND !$failure) {
|
||||
logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
|
||||
} else if (($last_contact >= $last_failure) AND $failure) {
|
||||
logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
// Check again if the server exists
|
||||
|
@ -949,7 +1305,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
$info = strip_tags($info);
|
||||
$platform = strip_tags($platform);
|
||||
|
||||
if ($servers)
|
||||
if ($servers) {
|
||||
q("UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
|
||||
`network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($server_url),
|
||||
|
@ -965,7 +1321,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
dbesc($last_failure),
|
||||
dbesc(normalise_link($server_url))
|
||||
);
|
||||
else
|
||||
} elseif (!$failure) {
|
||||
q("INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`)
|
||||
VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
|
||||
dbesc($server_url),
|
||||
|
@ -983,7 +1339,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
dbesc($last_failure),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
|
||||
}
|
||||
logger("End discovery for server ".$server_url, LOGGER_DEBUG);
|
||||
|
||||
return !$failure;
|
||||
|
@ -1246,6 +1602,33 @@ function update_suggestions() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fetch server list from remote servers and adds them when they are new.
|
||||
*
|
||||
* @param string $poco URL to the POCO endpoint
|
||||
*/
|
||||
function poco_fetch_serverlist($poco) {
|
||||
$serverret = z_fetch_url($poco."/@server");
|
||||
if (!$serverret["success"]) {
|
||||
return;
|
||||
}
|
||||
$serverlist = json_decode($serverret['body']);
|
||||
|
||||
if (!is_array($serverlist)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($serverlist AS $server) {
|
||||
$server_url = str_replace("/index.php", "", $server->url);
|
||||
|
||||
$r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
|
||||
if (!dbm::is_result($r)) {
|
||||
logger("Call server check for server ".$server_url, LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server_url));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function poco_discover_federation() {
|
||||
$last = get_config('poco','last_federation_discovery');
|
||||
|
||||
|
@ -1261,8 +1644,9 @@ function poco_discover_federation() {
|
|||
if ($serverdata) {
|
||||
$servers = json_decode($serverdata);
|
||||
|
||||
foreach($servers->pods AS $server)
|
||||
poco_check_server("https://".$server->host);
|
||||
foreach ($servers->pods AS $server) {
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode("https://".$server->host));
|
||||
}
|
||||
}
|
||||
|
||||
// Currently disabled, since the service isn't available anymore.
|
||||
|
@ -1307,6 +1691,9 @@ function poco_discover($complete = false) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Discover new servers out there
|
||||
poco_fetch_serverlist($server["poco"]);
|
||||
|
||||
// Fetch all users from the other server
|
||||
$url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
|
||||
|
||||
|
@ -1881,4 +2268,20 @@ function gs_discover() {
|
|||
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a list of all known servers
|
||||
* @return array List of server urls
|
||||
*/
|
||||
function poco_serverlist() {
|
||||
$r = q("SELECT `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver`
|
||||
WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure`
|
||||
ORDER BY `last_contact`
|
||||
LIMIT 1000",
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
if (!dbm::is_result($r)) {
|
||||
return false;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -6,24 +6,10 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/items.php");
|
||||
|
||||
function spool_post_run($argv, $argc) {
|
||||
global $a, $db;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
Config::load();
|
||||
global $a;
|
||||
|
||||
$path = get_spoolpath();
|
||||
|
||||
|
@ -69,9 +55,4 @@ function spool_post_run($argv, $argc) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_search(__file__, get_included_files()) === 0) {
|
||||
spool_post_run($_SERVER["argv"], $_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,24 +1,6 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/tags.php");
|
||||
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a))
|
||||
$a = new App;
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
function tagupdate_run(&$argv, &$argc){
|
||||
update_items();
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
update_items();
|
||||
killme();
|
||||
?>
|
||||
|
|
106
include/text.php
106
include/text.php
|
@ -268,90 +268,90 @@ function hex2bin($s) {
|
|||
}}
|
||||
|
||||
|
||||
if(! function_exists('paginate_data')) {
|
||||
/**
|
||||
* Automatica pagination data.
|
||||
* @brief Paginator function. Pushes relevant links in a pager array structure.
|
||||
*
|
||||
* Links are generated depending on the current page and the total number of items.
|
||||
* Inactive links (like "first" and "prev" on page 1) are given the "disabled" class.
|
||||
* Current page link is given the "active" CSS class
|
||||
*
|
||||
* @param App $a App instance
|
||||
* @param int $count [optional] item count (used with alt pager)
|
||||
* @param int $count [optional] item count (used with minimal pager)
|
||||
* @return Array data for pagination template
|
||||
*/
|
||||
function paginate_data(App $a, $count=null) {
|
||||
$stripped = preg_replace('/([&?]page=[0-9]*)/','',$a->query_string);
|
||||
function paginate_data(App $a, $count = null) {
|
||||
$stripped = preg_replace('/([&?]page=[0-9]*)/', '', $a->query_string);
|
||||
|
||||
$stripped = str_replace('q=','',$stripped);
|
||||
$stripped = trim($stripped,'/');
|
||||
$stripped = str_replace('q=', '', $stripped);
|
||||
$stripped = trim($stripped, '/');
|
||||
$pagenum = $a->pager['page'];
|
||||
|
||||
if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped))
|
||||
$stripped .= "&offset=".urlencode($a->page_offset);
|
||||
|
||||
$url = $stripped;
|
||||
|
||||
$data = array();
|
||||
function _l(&$d, $name, $url, $text, $class="") {
|
||||
if (!strpos($url, "?")) {
|
||||
if ($pos = strpos($url, "&"))
|
||||
$url = substr($url, 0, $pos)."?".substr($url, $pos + 1);
|
||||
}
|
||||
|
||||
$d[$name] = array('url'=>$url, 'text'=>$text, 'class'=>$class);
|
||||
if (($a->page_offset != '') AND !preg_match('/[?&].offset=/', $stripped)) {
|
||||
$stripped .= '&offset=' . urlencode($a->page_offset);
|
||||
}
|
||||
|
||||
if (!is_null($count)){
|
||||
// alt pager
|
||||
if($a->pager['page']>1)
|
||||
_l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('newer'));
|
||||
if($count>0)
|
||||
_l($data, "next", $url.'&page='.($a->pager['page'] + 1), t('older'));
|
||||
$url = $stripped;
|
||||
$data = array();
|
||||
|
||||
function _l(&$d, $name, $url, $text, $class = '') {
|
||||
if (strpos($url, '?') === false && ($pos = strpos($url, '&')) !== false) {
|
||||
$url = substr($url, 0, $pos) . '?' . substr($url, $pos + 1);
|
||||
}
|
||||
|
||||
$d[$name] = array('url' => $url, 'text' => $text, 'class' => $class);
|
||||
}
|
||||
|
||||
if (!is_null($count)) {
|
||||
// minimal pager (newer / older)
|
||||
$data['class'] = 'pager';
|
||||
_l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('newer'), 'previous' . ($a->pager['page'] == 1 ? ' disabled' : ''));
|
||||
_l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('older'), 'next' . ($count <= 0 ? ' disabled' : ''));
|
||||
} else {
|
||||
// full pager
|
||||
if($a->pager['total'] > $a->pager['itemspage']) {
|
||||
if($a->pager['page'] != 1)
|
||||
_l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('prev'));
|
||||
|
||||
_l($data, "first", $url."&page=1", t('first'));
|
||||
|
||||
// full pager (first / prev / 1 / 2 / ... / 14 / 15 / next / last)
|
||||
$data['class'] = 'pagination';
|
||||
if ($a->pager['total'] > $a->pager['itemspage']) {
|
||||
_l($data, 'first', $url . '&page=1', t('first'), $a->pager['page'] == 1 ? 'disabled' : '');
|
||||
_l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('prev'), $a->pager['page'] == 1 ? 'disabled' : '');
|
||||
|
||||
$numpages = $a->pager['total'] / $a->pager['itemspage'];
|
||||
|
||||
$numstart = 1;
|
||||
$numstop = $numpages;
|
||||
|
||||
if($numpages > 14) {
|
||||
$numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
|
||||
$numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
|
||||
// Limit the number of displayed page number buttons.
|
||||
if ($numpages > 8) {
|
||||
$numstart = (($pagenum > 4) ? ($pagenum - 4) : 1);
|
||||
$numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 8));
|
||||
}
|
||||
|
||||
$pages = array();
|
||||
|
||||
for($i = $numstart; $i <= $numstop; $i++){
|
||||
if($i == $a->pager['page'])
|
||||
_l($pages, $i, "#", $i, "current");
|
||||
else
|
||||
_l($pages, $i, $url."&page=$i", $i, "n");
|
||||
for ($i = $numstart; $i <= $numstop; $i++) {
|
||||
if ($i == $a->pager['page']) {
|
||||
_l($pages, $i, '#', $i, 'current active');
|
||||
} else {
|
||||
_l($pages, $i, $url . '&page='. $i, $i, 'n');
|
||||
}
|
||||
}
|
||||
|
||||
if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
|
||||
if($i == $a->pager['page'])
|
||||
_l($pages, $i, "#", $i, "current");
|
||||
else
|
||||
_l($pages, $i, $url."&page=$i", $i, "n");
|
||||
if (($a->pager['total'] % $a->pager['itemspage']) != 0) {
|
||||
if ($i == $a->pager['page']) {
|
||||
_l($pages, $i, '#', $i, 'current active');
|
||||
} else {
|
||||
_l($pages, $i, $url . '&page=' . $i, $i, 'n');
|
||||
}
|
||||
}
|
||||
|
||||
$data['pages'] = $pages;
|
||||
|
||||
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
|
||||
_l($data, "last", $url."&page=$lastpage", t('last'));
|
||||
|
||||
if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
|
||||
_l($data, "next", $url."&page=".($a->pager['page'] + 1), t('next'));
|
||||
|
||||
_l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('next'), $a->pager['page'] == $lastpage ? 'disabled' : '');
|
||||
_l($data, 'last', $url . '&page=' . $lastpage, t('last'), $a->pager['page'] == $lastpage ? 'disabled' : '');
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
|
||||
}}
|
||||
return $data;
|
||||
}
|
||||
|
||||
if(! function_exists('paginate')) {
|
||||
/**
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
<?php
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
require_once("include/threads.php");
|
||||
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a))
|
||||
$a = new App;
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
function threadupdate_run(&$argv, &$argc){
|
||||
update_threads();
|
||||
update_threads_mention();
|
||||
}
|
||||
|
||||
Config::load();
|
||||
|
||||
update_threads();
|
||||
update_threads_mention();
|
||||
killme();
|
||||
?>
|
||||
|
|
|
@ -11,14 +11,11 @@ define("IMPORT_DEBUG", False);
|
|||
|
||||
function last_insert_id() {
|
||||
global $db;
|
||||
|
||||
if (IMPORT_DEBUG)
|
||||
return 1;
|
||||
if ($db->mysqli) {
|
||||
$thedb = $db->getdb();
|
||||
return $thedb->insert_id;
|
||||
} else {
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
return $db->insert_id();
|
||||
}
|
||||
|
||||
function last_error() {
|
||||
|
|
|
@ -2,46 +2,23 @@
|
|||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("boot.php");
|
||||
|
||||
function update_gcontact_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
global $a;
|
||||
|
||||
require_once('include/Scrape.php');
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
Config::load();
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
logger('update_gcontact: start');
|
||||
|
||||
if(($argc > 1) && (intval($argv[1])))
|
||||
if (($argc > 1) && (intval($argv[1]))) {
|
||||
$contact_id = intval($argv[1]);
|
||||
}
|
||||
|
||||
if(!$contact_id) {
|
||||
if (!$contact_id) {
|
||||
logger('update_gcontact: no contact');
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('update_gcontact'.$contact_id, '', 540))
|
||||
return;
|
||||
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
|
||||
|
||||
if (!$r)
|
||||
|
@ -98,8 +75,3 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
dbesc(normalise_link($data["url"]))
|
||||
);
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue