Enforcing standards ahead of moving App to src
This commit is contained in:
parent
0747ce0e6e
commit
68c1939d12
24
boot.php
24
boot.php
|
@ -26,14 +26,12 @@ define('NAMESPACE_DFRN', 'http://purl.org/macgirvin/dfrn/1.0');
|
|||
/**
|
||||
* log levels
|
||||
*/
|
||||
|
||||
define('LOGGER_NORMAL', 0);
|
||||
define('LOGGER_TRACE', 1);
|
||||
define('LOGGER_DEBUG', 2);
|
||||
define('LOGGER_DATA', 3);
|
||||
define('LOGGER_ALL', 4);
|
||||
|
||||
|
||||
class App
|
||||
{
|
||||
public $module_loaded = false;
|
||||
|
@ -66,10 +64,8 @@ class App
|
|||
$this->page = array();
|
||||
$this->pager = array();
|
||||
|
||||
$this->scheme = ((isset($_SERVER['HTTPS'])
|
||||
&& ($_SERVER['HTTPS'])) ? 'https' : 'http');
|
||||
$this->hostname = str_replace('www.', '',
|
||||
$_SERVER['SERVER_NAME']);
|
||||
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http');
|
||||
$this->hostname = str_replace('www.', '', $_SERVER['SERVER_NAME']);
|
||||
set_include_path("include/$this->hostname"
|
||||
. PATH_SEPARATOR . 'include'
|
||||
. PATH_SEPARATOR . '.');
|
||||
|
@ -104,8 +100,7 @@ class App
|
|||
}
|
||||
|
||||
$this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
|
||||
. ((isset($this->path) && strlen($this->path))
|
||||
? '/' . $this->path : '');
|
||||
. ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '');
|
||||
return $this->baseurl;
|
||||
}
|
||||
|
||||
|
@ -157,7 +152,6 @@ class App
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('x')) {
|
||||
function x($s, $k = null)
|
||||
{
|
||||
|
@ -243,9 +237,6 @@ if (! function_exists('t')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!function_exists('fetch_url')) {
|
||||
function fetch_url($url, $binary = false, $timeout = 20)
|
||||
{
|
||||
|
@ -269,7 +260,6 @@ if (! function_exists('fetch_url')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('post_url')) {
|
||||
function post_url($url, $params)
|
||||
{
|
||||
|
@ -290,7 +280,6 @@ if (! function_exists('post_url')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('random_string')) {
|
||||
function random_string()
|
||||
{
|
||||
|
@ -331,7 +320,6 @@ if (! function_exists('login')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('killme')) {
|
||||
function killme()
|
||||
{
|
||||
|
@ -376,10 +364,6 @@ if (! function_exists('hex2bin')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!function_exists('paginate')) {
|
||||
function paginate(&$a)
|
||||
{
|
||||
|
@ -390,7 +374,6 @@ if (! function_exists('paginate')) {
|
|||
$pagenum = $a->pager['page'];
|
||||
$url = $a->get_baseurl() . '/' . $stripped;
|
||||
|
||||
|
||||
if ($a->pager['total'] > $a->pager['itemspage']) {
|
||||
$o .= '<div class="pager">';
|
||||
if ($a->pager['page'] != 1) {
|
||||
|
@ -439,7 +422,6 @@ if (! function_exists('paginate')) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function get_my_url()
|
||||
{
|
||||
if (x($_SESSION, 'my_url')) {
|
||||
|
|
|
@ -10,18 +10,22 @@
|
|||
$verbose = $argv[1] === 'verbose';
|
||||
|
||||
//Startup.
|
||||
require_once('boot.php');
|
||||
require_once 'boot.php';
|
||||
|
||||
$a = new App;
|
||||
|
||||
//Config and DB.
|
||||
require_once(".htconfig.php");
|
||||
require_once("dba.php");
|
||||
require_once '.htconfig.php';
|
||||
require_once 'dba.php';
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
|
||||
|
||||
//Get our set of items. Youngest items first, after the threshold.
|
||||
//This may be counter-intuitive, but is to prevent items that fail to update from blocking the rest.
|
||||
$res = q(
|
||||
"SELECT `id`, `homepage`, `censored` FROM `profile` WHERE `updated` < '%s' ORDER BY `updated` DESC LIMIT %u",
|
||||
$res = q("SELECT `id`, `homepage`, `censored`
|
||||
FROM `profile`
|
||||
WHERE `updated` < '%s'
|
||||
ORDER BY `updated` DESC
|
||||
LIMIT %u",
|
||||
dbesc(date('Y-m-d H:i:s', time() - $a->config['maintenance']['min_scrape_delay'])),
|
||||
intval($a->config['maintenance']['max_scrapes'])
|
||||
);
|
||||
|
@ -35,7 +39,7 @@
|
|||
$db->getdb()->close();
|
||||
|
||||
//We need the scraper.
|
||||
require_once('include/submit.php');
|
||||
require_once 'include/submit.php';
|
||||
|
||||
//POSIX threads only.
|
||||
if (!function_exists('pcntl_fork')) {
|
||||
|
@ -49,24 +53,31 @@
|
|||
$threads = array();
|
||||
|
||||
//Debug...
|
||||
if($verbose) echo("Creating $threadc maintainer threads for $items profiles.".PHP_EOL);
|
||||
if ($verbose) {
|
||||
echo "Creating $threadc maintainer threads for $items profiles." . PHP_EOL;
|
||||
}
|
||||
logger("Creating $threadc maintainer threads for $items profiles.");
|
||||
|
||||
for ($i = 0; $i < $threadc; $i++) {
|
||||
|
||||
$pid = pcntl_fork();
|
||||
if ($pid === -1) {
|
||||
if($verbose) echo('Error: something went wrong with the fork. '.pcntl_strerror());
|
||||
if ($verbose) {
|
||||
echo('Error: something went wrong with the fork. ' . pcntl_strerror());
|
||||
}
|
||||
logger('Error: something went wrong with the fork. ' . pcntl_strerror());
|
||||
die('Error: something went wrong with the fork. ' . pcntl_strerror());
|
||||
}
|
||||
|
||||
//You're a child, go do some labor!
|
||||
if($pid === 0) break;
|
||||
if ($pid === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
//Store the list of PID's.
|
||||
if($pid > 0) $threads[] = $pid;
|
||||
|
||||
if ($pid > 0) {
|
||||
$threads[] = $pid;
|
||||
}
|
||||
}
|
||||
|
||||
//The work for child processes.
|
||||
|
@ -91,24 +102,27 @@
|
|||
while (count($workload)) {
|
||||
$entry = array_pop($workload);
|
||||
set_time_limit(20); //This should work for 1 submit.
|
||||
if($verbose) echo "Submitting ".$entry['homepage'].PHP_EOL;
|
||||
if ($verbose) {
|
||||
echo "Submitting " . $entry['homepage'] . PHP_EOL;
|
||||
}
|
||||
run_submit($entry['homepage']);
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
//The main process.
|
||||
else{
|
||||
foreach ($threads as $pid) {
|
||||
pcntl_waitpid($pid, $status);
|
||||
if ($status !== 0) {
|
||||
if($verbose) echo "Bad process return value $pid:$status".PHP_EOL;
|
||||
if ($verbose) {
|
||||
echo "Bad process return value $pid:$status" . PHP_EOL;
|
||||
}
|
||||
logger("Bad process return value $pid:$status");
|
||||
}
|
||||
}
|
||||
$time = time() - $start_maintain;
|
||||
if($verbose) echo("Maintenance completed. Took $time seconds.".PHP_EOL);
|
||||
if ($verbose) {
|
||||
echo("Maintenance completed. Took $time seconds." . PHP_EOL);
|
||||
}
|
||||
logger("Maintenance completed. Took $time seconds.");
|
||||
}
|
||||
|
|
|
@ -48,29 +48,34 @@ error_reporting(E_ALL^E_NOTICE);
|
|||
$start_syncing = time();
|
||||
|
||||
//Startup.
|
||||
require_once('boot.php');
|
||||
require_once 'boot.php';
|
||||
$a = new App;
|
||||
|
||||
//Create a simple log function for CLI use.
|
||||
global $verbose;
|
||||
$verbose = $argv[1] === 'verbose';
|
||||
|
||||
function msg($message, $fatal=false){
|
||||
function msg($message, $fatal = false)
|
||||
{
|
||||
global $verbose;
|
||||
if($verbose || $fatal) echo($message.PHP_EOL);
|
||||
if ($verbose || $fatal)
|
||||
echo($message . PHP_EOL);
|
||||
logger($message);
|
||||
if($fatal) exit(1);
|
||||
};
|
||||
if ($fatal) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//Config.
|
||||
require_once(".htconfig.php");
|
||||
require_once '.htconfig.php';
|
||||
|
||||
//Connect the DB.
|
||||
require_once("dba.php");
|
||||
require_once 'dba.php';
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
|
||||
|
||||
//Import syncing functions.
|
||||
require_once('sync.php');
|
||||
require_once 'sync.php';
|
||||
|
||||
//Get work for pulling.
|
||||
$pull_batch = get_pulling_job($a);
|
||||
|
@ -81,12 +86,14 @@ list($push_targets, $push_batch) = get_pushing_job($a);
|
|||
//Close the connection for now. Process forking and DB connections are not the best of friends.
|
||||
$db->getdb()->close();
|
||||
|
||||
if(count($pull_batch))
|
||||
if (count($pull_batch)) {
|
||||
run_pulling_job($a, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install);
|
||||
}
|
||||
|
||||
//Do our multi-fork job, if we have a batch and targets.
|
||||
if(count($push_targets) && count($push_batch))
|
||||
if (count($push_targets) && count($push_batch)) {
|
||||
run_pushing_job($push_targets, $push_batch, $db_host, $db_user, $db_pass, $db_data, $install);
|
||||
}
|
||||
|
||||
//Log the time it took.
|
||||
$time = time() - $start_syncing;
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
<?php
|
||||
|
||||
require_once("boot.php");
|
||||
require_once 'boot.php';
|
||||
|
||||
$a = new App;
|
||||
|
||||
@include(".htconfig.php");
|
||||
require_once("dba.php");
|
||||
@include '.htconfig.php';
|
||||
|
||||
require_once 'dba.php';
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
|
||||
if($argc != 2)
|
||||
if ($argc != 2) {
|
||||
exit;
|
||||
}
|
||||
|
||||
load_config('system');
|
||||
|
||||
|
@ -19,8 +22,9 @@
|
|||
|
||||
$dir = get_config('system', 'directory_submit_url');
|
||||
|
||||
if(! strlen($dir))
|
||||
if (!strlen($dir)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
fetch_url($dir . '?url=' . bin2hex($argv[1]));
|
||||
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
<?php
|
||||
|
||||
|
||||
require_once("boot.php");
|
||||
require_once 'boot.php';
|
||||
|
||||
$a = new App;
|
||||
|
||||
@include(".htconfig.php");
|
||||
require_once("dba.php");
|
||||
@include '.htconfig.php';
|
||||
|
||||
require_once 'dba.php';
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
require_once("session.php");
|
||||
require_once("datetime.php");
|
||||
require_once 'session.php';
|
||||
require_once 'datetime.php';
|
||||
|
||||
if($argc < 3)
|
||||
if ($argc < 3) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system', 'url'));
|
||||
|
||||
|
@ -24,55 +27,51 @@
|
|||
case 'mail':
|
||||
default:
|
||||
$item_id = intval($argv[2]);
|
||||
if(! $item_id)
|
||||
if (!$item_id) {
|
||||
killme();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$recipients = array();
|
||||
|
||||
if ($cmd == 'mail') {
|
||||
|
||||
$message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! count($message))
|
||||
$message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1", intval($item_id));
|
||||
if (!count($message)) {
|
||||
killme();
|
||||
}
|
||||
$recipients[] = $message[0]['contact-id'];
|
||||
$item = $message[0];
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// find ancestors
|
||||
|
||||
$r = q("SELECT `parent`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! count($r))
|
||||
$r = q("SELECT `parent`, `edited` FROM `item` WHERE `id` = %d LIMIT 1", intval($item_id));
|
||||
if (!count($r)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$parent = $r[0]['parent'];
|
||||
$updated = $r[0]['edited'];
|
||||
|
||||
$items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
|
||||
intval($parent)
|
||||
);
|
||||
$items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC", intval($parent));
|
||||
|
||||
if(! count($items))
|
||||
if (!count($items)) {
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 LIMIT 1");
|
||||
|
||||
if(count($r))
|
||||
if (count($r)) {
|
||||
$owner = $r[0];
|
||||
else
|
||||
} else {
|
||||
killme();
|
||||
}
|
||||
|
||||
if ($cmd != 'mail') {
|
||||
|
||||
require_once('include/group.php');
|
||||
require_once 'include/group.php';
|
||||
|
||||
$parent = $items[0];
|
||||
|
||||
|
@ -80,8 +79,7 @@
|
|||
// local followup to remote post
|
||||
$followup = true;
|
||||
$conversant_str = dbesc($parent['contact-id']);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$followup = false;
|
||||
|
||||
$allow_people = expand_acl($parent['allow_cid']);
|
||||
|
@ -98,7 +96,6 @@
|
|||
|
||||
$conversants = array_unique($conversants, SORT_NUMERIC);
|
||||
|
||||
|
||||
$recipients = array_unique(array_merge($recipients, $allow_people, $allow_groups), SORT_NUMERIC);
|
||||
$deny = array_unique(array_merge($deny_people, $deny_groups), SORT_NUMERIC);
|
||||
$recipients = array_diff($recipients, $deny);
|
||||
|
@ -108,8 +105,9 @@
|
|||
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
|
||||
|
||||
if( ! count($r))
|
||||
if (!count($r)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$contacts = $r;
|
||||
|
||||
|
@ -123,12 +121,10 @@
|
|||
|
||||
$atom = '';
|
||||
|
||||
|
||||
$atom .= replace_macros($feed_template, array(
|
||||
'$feed_id' => xmlify($a->get_baseurl()),
|
||||
'$feed_title' => xmlify($owner['name']),
|
||||
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
|
||||
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$name' => xmlify($owner['name']),
|
||||
'$profile_page' => xmlify($owner['url']),
|
||||
'$photo' => xmlify($owner['photo']),
|
||||
|
@ -145,15 +141,11 @@
|
|||
'$thumb' => xmlify($owner['thumb']),
|
||||
'$item_id' => xmlify($item['uri']),
|
||||
'$subject' => xmlify($item['title']),
|
||||
'$created' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$content' => xmlify($item['body']),
|
||||
'$parent_id' => xmlify($item['parent-uri'])
|
||||
|
||||
));
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
if ($followup) {
|
||||
foreach ($items as $item) {
|
||||
if ($item['id'] == $item_id) {
|
||||
|
@ -163,27 +155,22 @@
|
|||
'$thumb' => xmlify($owner['thumb']),
|
||||
'$item_id' => xmlify($item['uri']),
|
||||
'$title' => xmlify($item['title']),
|
||||
'$published' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$content' => xmlify($item['body']),
|
||||
'$parent_id' => xmlify($item['parent-uri']),
|
||||
'$comment_allow' => 0
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
foreach ($items as $item) {
|
||||
if ($item['deleted']) {
|
||||
$atom .= replace_macros($tomb_template, array(
|
||||
'$id' => xmlify($item['uri']),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\TH:i:s\Z'))
|
||||
));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
foreach ($contacts as $contact) {
|
||||
if ($item['contact-id'] == $contact['id']) {
|
||||
if ($item['parent'] == $item['id']) {
|
||||
|
@ -196,25 +183,20 @@
|
|||
'$owner_thumb' => xmlify($item['owner-avatar']),
|
||||
'$item_id' => xmlify($item['uri']),
|
||||
'$title' => xmlify($item['title']),
|
||||
'$published' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$content' => xmlify($item['body']),
|
||||
'$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
|
||||
));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$atom .= replace_macros($cmnt_template, array(
|
||||
'$name' => xmlify($contact['name']),
|
||||
'$profile_page' => xmlify($contact['url']),
|
||||
'$thumb' => xmlify($contact['thumb']),
|
||||
'$item_id' => xmlify($item['uri']),
|
||||
'$title' => xmlify($item['title']),
|
||||
'$published' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC',
|
||||
$item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
|
||||
'$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', 'Y-m-d\TH:i:s\Z')),
|
||||
'$content' => xmlify($item['body']),
|
||||
'$parent_id' => xmlify($item['parent-uri']),
|
||||
'$comment_allow' => (($item['last-child']) ? 1 : 0)
|
||||
|
@ -232,39 +214,42 @@
|
|||
|
||||
$atom_nowrite = str_replace('<dfrn:comment-allow>1', '<dfrn:comment-allow>0', $atom);
|
||||
|
||||
if($followup)
|
||||
if ($followup) {
|
||||
$recip_str = $parent['contact-id'];
|
||||
else
|
||||
} else {
|
||||
$recip_str = implode(', ', $recipients);
|
||||
}
|
||||
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
|
||||
dbesc($recip_str)
|
||||
);
|
||||
if(! count($r))
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ", dbesc($recip_str));
|
||||
if (!count($r)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
// delivery loop
|
||||
|
||||
foreach ($r as $rr) {
|
||||
if($rr['self'])
|
||||
if ($rr['self']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! strlen($rr['dfrn-id']))
|
||||
if (!strlen($rr['dfrn-id'])) {
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
$url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
|
||||
|
||||
$xml = fetch_url($url);
|
||||
|
||||
if(! $xml)
|
||||
if (!$xml) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$res = simplexml_load_string($xml);
|
||||
|
||||
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
|
||||
if ((intval($res->status) != 0) || (!strlen($res->challenge)) || (!strlen($res->dfrn_id))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$postvars = array();
|
||||
$sent_dfrn_id = hex2bin($res->dfrn_id);
|
||||
|
@ -285,11 +270,9 @@
|
|||
|
||||
if ($cmd == 'mail') {
|
||||
$postvars['data'] = $atom;
|
||||
}
|
||||
elseif(strlen($rr['dfrn-id']) && (! ($rr['blocked']) || ($rr['readonly']))) {
|
||||
} elseif (strlen($rr['dfrn-id']) && (!($rr['blocked']) || ($rr['readonly']))) {
|
||||
$postvars['data'] = $atom;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$postvars['data'] = $atom_nowrite;
|
||||
}
|
||||
|
||||
|
@ -301,10 +284,7 @@
|
|||
// We need to handle this in the UI, report the non-deliverables and try again
|
||||
|
||||
if (($cmd == 'mail') && (intval($res->status) == 0)) {
|
||||
|
||||
$r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
$r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1", intval($item_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
<?php
|
||||
|
||||
|
||||
require_once('boot.php');
|
||||
require_once 'boot.php';
|
||||
|
||||
$a = new App;
|
||||
|
||||
@include('.htconfig.php');
|
||||
require_once('dba.php');
|
||||
|
||||
require_once 'dba.php';
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
require_once('session.php');
|
||||
require_once('datetime.php');
|
||||
require_once('simplepie/simplepie.inc');
|
||||
require_once('include/items.php');
|
||||
require_once 'session.php';
|
||||
require_once 'datetime.php';
|
||||
require_once 'simplepie/simplepie.inc';
|
||||
require_once 'include/items.php';
|
||||
|
||||
$a->set_baseurl(get_config('system', 'url'));
|
||||
|
||||
|
@ -21,13 +23,12 @@
|
|||
WHERE `dfrn-id` != '' AND `self` = 0 AND `blocked` = 0
|
||||
AND `readonly` = 0 ORDER BY RAND()");
|
||||
|
||||
if(! count($contacts))
|
||||
if (!count($contacts)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
|
||||
if ($contact['priority']) {
|
||||
|
||||
$update = false;
|
||||
$t = $contact['last-update'];
|
||||
|
||||
|
@ -54,31 +55,32 @@
|
|||
$update = true;
|
||||
break;
|
||||
}
|
||||
if(! $update)
|
||||
if (!$update) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 LIMIT 1");
|
||||
if (!count($r)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 LIMIT 1");
|
||||
if(! count($r))
|
||||
continue;
|
||||
|
||||
$importer = $r[0];
|
||||
|
||||
$last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
|
||||
? datetime_convert('UTC','UTC','now - 30 days','Y-m-d\TH:i:s\Z')
|
||||
: datetime_convert('UTC','UTC',$contact['last-update'],'Y-m-d\TH:i:s\Z'));
|
||||
$last_update = (($contact['last-update'] == '0000-00-00 00:00:00') ? datetime_convert('UTC', 'UTC', 'now - 30 days', 'Y-m-d\TH:i:s\Z') : datetime_convert('UTC', 'UTC', $contact['last-update'], 'Y-m-d\TH:i:s\Z'));
|
||||
|
||||
$url = $contact['poll'] . '?dfrn_id=' . $contact['dfrn-id'] . '&type=data&last_update=' . $last_update;
|
||||
|
||||
$xml = fetch_url($url);
|
||||
if(! $xml)
|
||||
if (!$xml) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$res = simplexml_load_string($xml);
|
||||
|
||||
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
|
||||
if ((intval($res->status) != 0) || (!strlen($res->challenge)) || (!strlen($res->dfrn_id))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$postvars = array();
|
||||
|
||||
|
@ -101,7 +103,8 @@
|
|||
|
||||
if (!strlen($xml)) {
|
||||
// an empty response may mean there's nothing new - record the fact that we checked
|
||||
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
|
||||
$r = q(
|
||||
"UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['id'])
|
||||
);
|
||||
|
@ -114,22 +117,23 @@
|
|||
$feed->init();
|
||||
|
||||
$photo_rawupdate = $feed->get_feed_tags(NAMESPACE_DFRN, 'icon-updated');
|
||||
|
||||
if ($photo_rawupdate) {
|
||||
$photo_timestamp = datetime_convert('UTC', 'UTC', $photo_rawupdate[0]['data']);
|
||||
$photo_url = $feed->get_image_url();
|
||||
if(strlen($photo_url) && $photo_timestamp > $contact['avatar-date']) {
|
||||
|
||||
require_once("Photo.php");
|
||||
if (strlen($photo_url) && $photo_timestamp > $contact['avatar-date']) {
|
||||
require_once 'Photo.php';
|
||||
|
||||
$photo_failure = false;
|
||||
|
||||
$r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d LIMIT 1",
|
||||
intval($contact['id'])
|
||||
);
|
||||
$r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d LIMIT 1", intval($contact['id']));
|
||||
|
||||
if (count($r)) {
|
||||
$resource_id = $r[0]['resource-id'];
|
||||
$img_str = fetch_url($photo_url, true);
|
||||
$img = new Photo($img_str);
|
||||
|
||||
if ($img) {
|
||||
q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND contact-id` = %d ",
|
||||
dbesc($resource_id),
|
||||
|
@ -144,7 +148,7 @@
|
|||
|
||||
$img->scaleImage(80);
|
||||
$r = $img->store($contact['id'], $hash, basename($photo_url), t('Contact Photos'), 5);
|
||||
if($r)
|
||||
if ($r) {
|
||||
q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `id` = %d LIMIT 1",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['id'])
|
||||
|
@ -153,27 +157,27 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ($feed->get_items() as $item) {
|
||||
|
||||
$deleted = false;
|
||||
|
||||
$rawdelete = $item->get_item_tags("http://purl.org/atompub/tombstones/1.0", 'deleted-entry');
|
||||
|
||||
if (isset($rawdelete[0]['attribs']['']['ref'])) {
|
||||
$uri = $rawthread[0]['attribs']['']['ref'];
|
||||
$deleted = true;
|
||||
|
||||
if (isset($rawdelete[0]['attribs']['']['when'])) {
|
||||
$when = $rawthread[0]['attribs']['']['when'];
|
||||
$when = datetime_convert('UTC', 'UTC', $when, 'Y-m-d H:i:s');
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$when = datetime_convert('UTC', 'UTC', 'now', 'Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' LIMIT 1",
|
||||
dbesc($uri)
|
||||
);
|
||||
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($uri));
|
||||
if (count($r)) {
|
||||
if ($r[0]['uri'] == $r[0]['parent-uri']) {
|
||||
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s',
|
||||
|
@ -182,8 +186,7 @@
|
|||
dbesc($when),
|
||||
dbesc($r[0]['uri'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s',
|
||||
`body` = '', `title` = ''
|
||||
WHERE `uri` = '%s' LIMIT 1",
|
||||
|
@ -195,25 +198,21 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
$is_reply = false;
|
||||
$item_id = $item->get_id();
|
||||
$rawthread = $item->get_item_tags("http://purl.org/syndication/thread/1.0", 'in-reply-to');
|
||||
|
||||
if (isset($rawthread[0]['attribs']['']['ref'])) {
|
||||
$is_reply = true;
|
||||
$parent_uri = $rawthread[0]['attribs']['']['ref'];
|
||||
}
|
||||
|
||||
|
||||
if ($is_reply) {
|
||||
|
||||
// Have we seen it? If not, import it.
|
||||
|
||||
$item_id = $item->get_id();
|
||||
|
||||
$r = q("SELECT `last-child`, `edited` FROM `item` WHERE `uri` = '%s' LIMIT 1",
|
||||
dbesc($item_id)
|
||||
);
|
||||
$r = q("SELECT `last-child`, `edited` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($item_id));
|
||||
|
||||
// FIXME update content if 'updated' changes
|
||||
if (count($r)) {
|
||||
$allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
|
||||
|
@ -225,20 +224,19 @@
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$datarray = get_atom_elements($item);
|
||||
$datarray['parent-uri'] = $parent_uri;
|
||||
$datarray['contact-id'] = $contact['id'];
|
||||
$r = post_remote($a, $datarray);
|
||||
continue;
|
||||
}
|
||||
|
||||
else {
|
||||
continue;
|
||||
} else {
|
||||
// Head post of a conversation. Have we seen it? If not, import it.
|
||||
|
||||
$item_id = $item->get_id();
|
||||
$r = q("SELECT `last-child`, `edited` FROM `item` WHERE `uri` = '%s' LIMIT 1",
|
||||
dbesc($item_id)
|
||||
);
|
||||
$r = q("SELECT `last-child`, `edited` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($item_id));
|
||||
|
||||
if (count($r)) {
|
||||
$allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
|
||||
if ($allow && $allow[0]['data'] != $r[0]['last-child']) {
|
||||
|
@ -254,17 +252,15 @@
|
|||
$datarray['parent-uri'] = $item_id;
|
||||
$datarray['contact-id'] = $contact['id'];
|
||||
$r = post_remote($a, $datarray);
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['id'])
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
killme();
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
<?php
|
||||
|
||||
require_once("boot.php");
|
||||
require_once 'boot.php';
|
||||
|
||||
$a = new App;
|
||||
|
||||
@include(".htconfig.php");
|
||||
require_once("dba.php");
|
||||
require_once 'dba.php';
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
|
||||
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
require_once("session.php");
|
||||
require_once("datetime.php");
|
||||
require_once 'session.php';
|
||||
require_once 'datetime.php';
|
||||
|
||||
$a->set_baseurl(get_config('system', 'url'));
|
||||
|
||||
$u = q("SELECT * FROM `user` WHERE 1 LIMIT 1");
|
||||
if(! count($u))
|
||||
|
||||
if (!count($u)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$uid = $u[0]['uid'];
|
||||
$nickname = $u[0]['nickname'];
|
||||
|
@ -25,12 +29,11 @@
|
|||
FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
|
||||
WHERE `intro`.`blocked` = 0 AND `intro`.`ignore` = 0");
|
||||
|
||||
if(! count($intros))
|
||||
if (!count($intros)) {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
foreach ($intros as $intro) {
|
||||
|
||||
$intro_id = intval($intro['intro_id']);
|
||||
|
||||
$dfrn_id = $intro['issued-id'];
|
||||
|
@ -86,7 +89,6 @@
|
|||
break;
|
||||
case 1:
|
||||
// birthday paradox - generate new dfrn-id and fall through.
|
||||
|
||||
$new_dfrn_id = random_string();
|
||||
$r = q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d LIMIT 1",
|
||||
dbesc($new_dfrn_id),
|
||||
|
@ -101,45 +103,44 @@
|
|||
}
|
||||
|
||||
if (($status == 0 || $status == 3) && ($intro_id)) {
|
||||
|
||||
// delete the notification
|
||||
|
||||
$r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1",
|
||||
intval($intro_id)
|
||||
);
|
||||
$r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1", intval($intro_id));
|
||||
}
|
||||
if($status != 0)
|
||||
killme();
|
||||
|
||||
require_once("Photo.php");
|
||||
if ($status != 0) {
|
||||
killme();
|
||||
}
|
||||
|
||||
require_once 'Photo.php';
|
||||
|
||||
$photo_failure = false;
|
||||
|
||||
|
||||
$filename = basename($intro['photo']);
|
||||
$img_str = fetch_url($intro['photo'], true);
|
||||
$img = new Photo($img_str);
|
||||
if($img) {
|
||||
|
||||
if ($img) {
|
||||
$img->scaleImageSquare(175);
|
||||
$hash = hash('md5', uniqid(mt_rand(), true));
|
||||
|
||||
$r = $img->store($contact_id, $hash, $filename, t('Contact Photos'), 4);
|
||||
|
||||
if($r === false)
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
$img->scaleImage(80);
|
||||
|
||||
$r = $img->store($contact_id, $hash, $filename, t('Contact Photos'), 5);
|
||||
|
||||
if($r === false)
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
|
||||
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
if ($photo_failure) {
|
||||
$photo = $a->get_baseurl() . '/images/default-profile.jpg';
|
||||
|
@ -160,6 +161,5 @@
|
|||
intval((x($a->config, 'rockstar-profile')) ? $a->config['rockstar-profile'] : 0),
|
||||
intval($contact_id)
|
||||
);
|
||||
|
||||
}
|
||||
killme();
|
||||
|
|
128
include/sync.php
128
include/sync.php
|
@ -7,14 +7,12 @@
|
|||
*/
|
||||
function sync_pull($url)
|
||||
{
|
||||
|
||||
global $a;
|
||||
|
||||
//If we support it that is.
|
||||
if ($a->config['syncing']['enable_pulling']) {
|
||||
q("INSERT INTO `sync-pull-queue` (`url`) VALUES ('%s')", dbesc($url));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +22,6 @@ function sync_pull($url)
|
|||
*/
|
||||
function sync_push($url)
|
||||
{
|
||||
|
||||
global $a;
|
||||
|
||||
//If we support it that is.
|
||||
|
@ -33,7 +30,6 @@ function sync_push($url)
|
|||
}
|
||||
|
||||
sync_mark($url);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +40,6 @@ function sync_push($url)
|
|||
*/
|
||||
function sync_mark($url)
|
||||
{
|
||||
|
||||
global $a;
|
||||
|
||||
//If we support it that is.
|
||||
|
@ -54,11 +49,11 @@ function sync_mark($url)
|
|||
|
||||
$exists = count(q("SELECT * FROM `sync-timestamps` WHERE `url`='%s'", dbesc($url)));
|
||||
|
||||
if(!$exists)
|
||||
if (!$exists) {
|
||||
q("INSERT INTO `sync-timestamps` (`url`, `modified`) VALUES ('%s', NOW())", dbesc($url));
|
||||
else
|
||||
} else {
|
||||
q("UPDATE `sync-timestamps` SET `modified`=NOW() WHERE `url`='%s'", dbesc($url));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +65,6 @@ function sync_mark($url)
|
|||
*/
|
||||
function push_worker($target, $batch)
|
||||
{
|
||||
|
||||
//Lets be nice, we're only doing a background job here...
|
||||
pcntl_setpriority(5);
|
||||
|
||||
|
@ -82,14 +76,14 @@ function push_worker($target, $batch)
|
|||
msg("Submitting {$item['url']} to $submit");
|
||||
fetch_url($submit . '?url=' . bin2hex($item['url']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of push targets.
|
||||
* @return array Push targets.
|
||||
*/
|
||||
function get_push_targets(){
|
||||
function get_push_targets()
|
||||
{
|
||||
return q("SELECT * FROM `sync-targets` WHERE `push`=b'1'");
|
||||
}
|
||||
|
||||
|
@ -98,7 +92,8 @@ function get_push_targets(){
|
|||
* @param object $a The App instance.
|
||||
* @return array Batch of URL's.
|
||||
*/
|
||||
function get_push_batch($a){
|
||||
function get_push_batch($a)
|
||||
{
|
||||
return q("SELECT * FROM `sync-push-queue` LIMIT %u", intval($a->config['syncing']['max_push_items']));
|
||||
}
|
||||
|
||||
|
@ -109,7 +104,6 @@ function get_push_batch($a){
|
|||
*/
|
||||
function get_pushing_job($a)
|
||||
{
|
||||
|
||||
//When pushing is requested...
|
||||
if (!!$a->config['syncing']['enable_pushing']) {
|
||||
|
||||
|
@ -125,19 +119,16 @@ function get_pushing_job($a)
|
|||
//If we have targets, get our batch.
|
||||
else {
|
||||
$batch = get_push_batch($a);
|
||||
if(!count($batch)) msg('Empty pushing queue.'); //No batch, means no work.
|
||||
if (!count($batch))
|
||||
msg('Empty pushing queue.'); //No batch, means no work.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
//No pushing if it's disabled.
|
||||
else{
|
||||
$targets = array();
|
||||
$batch = array();
|
||||
}
|
||||
|
||||
return array($targets, $batch);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,7 +144,6 @@ function get_pushing_job($a)
|
|||
*/
|
||||
function run_pushing_job($targets, $batch, $db_host, $db_user, $db_pass, $db_data, $install)
|
||||
{
|
||||
|
||||
//Create a thread for each target we want to serve push messages to.
|
||||
//Not good creating more, because it would stress their server too much.
|
||||
$threadc = count($targets);
|
||||
|
@ -163,10 +153,8 @@ function run_pushing_job($targets, $batch, $db_host, $db_user, $db_pass, $db_dat
|
|||
if ($threadc === 1) {
|
||||
msg('No threads needed. Only one pushing target.');
|
||||
push_worker($targets[0], $batch);
|
||||
}
|
||||
|
||||
} elseif ($threadc > 1) {
|
||||
//When we need threads.
|
||||
elseif($threadc > 1){
|
||||
|
||||
//POSIX threads only.
|
||||
if (!function_exists('pcntl_fork')) {
|
||||
|
@ -179,24 +167,29 @@ function run_pushing_job($targets, $batch, $db_host, $db_user, $db_pass, $db_dat
|
|||
|
||||
//Loop while we need more threads.
|
||||
for ($i = 0; $i < $threadc; $i++) {
|
||||
|
||||
$pid = pcntl_fork();
|
||||
if($pid === -1) msg('Error: something went wrong with the fork. '.pcntl_strerror(), true);
|
||||
if ($pid === -1)
|
||||
msg('Error: something went wrong with the fork. ' . pcntl_strerror(), true);
|
||||
|
||||
//You're a child, go do some labor!
|
||||
if($pid === 0){push_worker($targets[$i], $batch); exit;}
|
||||
|
||||
//Store the list of PID's.
|
||||
if($pid > 0) $threads[] = $pid;
|
||||
|
||||
if ($pid === 0) {
|
||||
push_worker($targets[$i], $batch);
|
||||
exit;
|
||||
}
|
||||
|
||||
//Store the list of PID's.
|
||||
if ($pid > 0) {
|
||||
$threads[] = $pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Wait for all child processes.
|
||||
$theading_problems = false;
|
||||
|
||||
foreach ($threads as $pid) {
|
||||
pcntl_waitpid($pid, $status);
|
||||
|
||||
if ($status !== 0) {
|
||||
$theading_problems = true;
|
||||
msg("Bad process return value $pid:$status");
|
||||
|
@ -205,22 +198,22 @@ function run_pushing_job($targets, $batch, $db_host, $db_user, $db_pass, $db_dat
|
|||
|
||||
//If we did not have any "threading" problems.
|
||||
if (!$theading_problems) {
|
||||
|
||||
//Reconnect
|
||||
global $db;
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
|
||||
|
||||
//Create a query for deleting this queue.
|
||||
$where = array();
|
||||
foreach($batch as $item) $where[] = dbesc($item['url']);
|
||||
foreach ($batch as $item) {
|
||||
$where[] = dbesc($item['url']);
|
||||
}
|
||||
$where = "WHERE `url` IN ('" . implode("', '", $where) . "')";
|
||||
|
||||
//Remove the items from queue.
|
||||
q("DELETE FROM `sync-push-queue` $where LIMIT %u", count($batch));
|
||||
msg('Removed items from push queue.');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,7 +221,8 @@ function run_pushing_job($targets, $batch, $db_host, $db_user, $db_pass, $db_dat
|
|||
* @param object $a The App instance.
|
||||
* @return array Batch of URL's.
|
||||
*/
|
||||
function get_queued_pull_batch($a){
|
||||
function get_queued_pull_batch($a)
|
||||
{
|
||||
//Randomize this, to prevent scraping the same servers too much or dead URL's.
|
||||
$batch = q("SELECT * FROM `sync-pull-queue` ORDER BY RAND() LIMIT %u", intval($a->config['syncing']['max_pull_items']));
|
||||
msg(sprintf('Pulling %u items from queue.', count($batch)));
|
||||
|
@ -239,7 +233,8 @@ function get_queued_pull_batch($a){
|
|||
* Gets an array of pull targets.
|
||||
* @return array Pull targets.
|
||||
*/
|
||||
function get_pull_targets(){
|
||||
function get_pull_targets()
|
||||
{
|
||||
return q("SELECT * FROM `sync-targets` WHERE `pull`=b'1'");
|
||||
}
|
||||
|
||||
|
@ -250,25 +245,26 @@ function get_pull_targets(){
|
|||
*/
|
||||
function get_remote_pull_batch($a)
|
||||
{
|
||||
|
||||
//Find our targets.
|
||||
$targets = get_pull_targets();
|
||||
|
||||
msg(sprintf('Pulling from %u remote targets.', count($targets)));
|
||||
|
||||
//No targets, means no batch.
|
||||
if(!count($targets))
|
||||
if (!count($targets)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
//Pull a list of URL's from each target.
|
||||
$urls = array();
|
||||
foreach($targets as $i => $target){
|
||||
|
||||
foreach ($targets as $i => $target) {
|
||||
//First pull, or an update?
|
||||
if(!$target['dt_last_pull'])
|
||||
if (!$target['dt_last_pull']) {
|
||||
$url = $target['base_url'] . '/sync/pull/all';
|
||||
else
|
||||
} else {
|
||||
$url = $target['base_url'] . '/sync/pull/since/' . intval($target['dt_last_pull']);
|
||||
}
|
||||
|
||||
//Go for it :D
|
||||
$targets[$i]['pull_data'] = json_decode(fetch_url($url), true);
|
||||
|
@ -280,14 +276,16 @@ function get_remote_pull_batch($a)
|
|||
}
|
||||
|
||||
//Add all entries as keys, to remove duplicates.
|
||||
foreach($targets[$i]['pull_data']['results'] as $url)
|
||||
foreach ($targets[$i]['pull_data']['results'] as $url) {
|
||||
$urls[$url] = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Now that we have our URL's. Store them in the queue.
|
||||
foreach ($urls as $url => $bool) {
|
||||
if($url) sync_pull($url);
|
||||
if ($url) {
|
||||
sync_pull($url);
|
||||
}
|
||||
}
|
||||
|
||||
//Since this all worked out, mark each source with the timestamp of pulling.
|
||||
|
@ -300,7 +298,6 @@ function get_remote_pull_batch($a)
|
|||
|
||||
//Finally, return a batch of this.
|
||||
return get_queued_pull_batch($a);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -310,19 +307,22 @@ function get_remote_pull_batch($a)
|
|||
*/
|
||||
function get_pulling_job($a)
|
||||
{
|
||||
|
||||
//No pulling today...
|
||||
if(!$a->config['syncing']['enable_pulling'])
|
||||
if (!$a->config['syncing']['enable_pulling']) {
|
||||
return array();
|
||||
}
|
||||
|
||||
//Firstly, finish the items from our queue.
|
||||
$batch = get_queued_pull_batch($a);
|
||||
if(count($batch)) return $batch;
|
||||
if (count($batch)) {
|
||||
return $batch;
|
||||
}
|
||||
|
||||
//If that is empty, fill the queue with remote items and return a batch of that.
|
||||
$batch = get_remote_pull_batch($a);
|
||||
if(count($batch)) return $batch;
|
||||
|
||||
if (count($batch)) {
|
||||
return $batch;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,7 +340,6 @@ function get_pulling_job($a)
|
|||
*/
|
||||
function pull_worker($i, $threadc, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install)
|
||||
{
|
||||
|
||||
//Lets be nice, we're only doing maintenance here...
|
||||
pcntl_setpriority(5);
|
||||
|
||||
|
@ -363,7 +362,6 @@ function pull_worker($i, $threadc, $pull_batch, $db_host, $db_user, $db_pass, $d
|
|||
msg("Submitting " . $entry['url']);
|
||||
run_submit($entry['url']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -379,9 +377,8 @@ function pull_worker($i, $threadc, $pull_batch, $db_host, $db_user, $db_pass, $d
|
|||
*/
|
||||
function run_pulling_job($a, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install)
|
||||
{
|
||||
|
||||
//We need the scraper.
|
||||
require_once('include/submit.php');
|
||||
require_once 'include/submit.php';
|
||||
|
||||
//POSIX threads only.
|
||||
if (!function_exists('pcntl_fork')) {
|
||||
|
@ -397,16 +394,21 @@ function run_pulling_job($a, $pull_batch, $db_host, $db_user, $db_pass, $db_data
|
|||
|
||||
//Build the threads.
|
||||
for ($i = 0; $i < $threadc; $i++) {
|
||||
|
||||
$pid = pcntl_fork();
|
||||
if($pid === -1) msg('Error: something went wrong with the fork. '.pcntl_strerror(), true);
|
||||
if ($pid === -1) {
|
||||
msg('Error: something went wrong with the fork. ' . pcntl_strerror(), true);
|
||||
}
|
||||
|
||||
//You're a child, go do some labor!
|
||||
if($pid === 0){pull_worker($i, $threadc, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install); exit;}
|
||||
if ($pid === 0) {
|
||||
pull_worker($i, $threadc, $pull_batch, $db_host, $db_user, $db_pass, $db_data, $install);
|
||||
exit;
|
||||
}
|
||||
|
||||
//Store the list of PID's.
|
||||
if($pid > 0) $threads[] = $pid;
|
||||
|
||||
if ($pid > 0) {
|
||||
$threads[] = $pid;
|
||||
}
|
||||
}
|
||||
|
||||
//Wait for all child processes.
|
||||
|
@ -421,20 +423,20 @@ function run_pulling_job($a, $pull_batch, $db_host, $db_user, $db_pass, $db_data
|
|||
|
||||
//If we did not have any "threading" problems.
|
||||
if (!$theading_problems) {
|
||||
|
||||
//Reconnect
|
||||
global $db;
|
||||
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
|
||||
|
||||
//Create a query for deleting this queue.
|
||||
$where = array();
|
||||
foreach($pull_batch as $item) $where[] = dbesc($item['url']);
|
||||
foreach ($pull_batch as $item) {
|
||||
$where[] = dbesc($item['url']);
|
||||
}
|
||||
$where = "WHERE `url` IN ('" . implode("', '", $where) . "')";
|
||||
|
||||
//Remove the items from queue.
|
||||
q("DELETE FROM `sync-pull-queue` $where LIMIT %u", count($pull_batch));
|
||||
msg('Removed items from pull queue.');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
12
index.php
12
index.php
|
@ -43,6 +43,7 @@ if (strlen($a->module)) {
|
|||
include("mod/{$a->module}.php");
|
||||
$a->module_loaded = true;
|
||||
}
|
||||
|
||||
if (!$a->module_loaded) {
|
||||
if ((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
|
||||
goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
|
||||
|
@ -54,14 +55,13 @@ if (strlen($a->module)) {
|
|||
|
||||
if ($a->module_loaded) {
|
||||
$a->page['page_title'] = $a->module;
|
||||
|
||||
if (function_exists($a->module . '_init')) {
|
||||
$func = $a->module . '_init';
|
||||
$func($a);
|
||||
}
|
||||
|
||||
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (! $a->error)
|
||||
&& (function_exists($a->module . '_post'))
|
||||
&& (! x($_POST, 'auth-params'))) {
|
||||
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!$a->error) && (function_exists($a->module . '_post')) && (!x($_POST, 'auth-params'))) {
|
||||
$func = $a->module . '_post';
|
||||
$func($a);
|
||||
}
|
||||
|
@ -83,9 +83,11 @@ if (x($_SESSION, 'sysmsg')) {
|
|||
if (stristr($_SESSION['sysmsg'], t('Permission denied'))) {
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
|
||||
}
|
||||
|
||||
if (!isset($a->page['content'])) {
|
||||
$a->page['content'] = '';
|
||||
}
|
||||
|
||||
$a->page['content'] = '<div id="sysmsg" class="error-message">' . $_SESSION['sysmsg'] . '</div>' . PHP_EOL
|
||||
. $a->page['content'];
|
||||
unset($_SESSION['sysmsg']);
|
||||
|
@ -103,11 +105,15 @@ $page = $a->page;
|
|||
$profile = $a->profile;
|
||||
|
||||
header('Content-type: text/html; charset=utf-8');
|
||||
|
||||
$template = 'view/'
|
||||
. ((x($a->page, 'template')) ? $a->page['template'] : 'default' )
|
||||
. '.php';
|
||||
|
||||
require_once $template;
|
||||
|
||||
session_write_close();
|
||||
|
||||
closedb();
|
||||
|
||||
exit;
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
require_once 'datetime.php';
|
||||
|
||||
function photo_init(App $a) {
|
||||
function photo_init(App $a)
|
||||
{
|
||||
switch ($a->argc) {
|
||||
case 2:
|
||||
$photo = $a->argv[1];
|
||||
|
@ -14,12 +15,12 @@ function photo_init(App $a) {
|
|||
|
||||
$profile_id = str_replace('.jpg', '', $photo);
|
||||
|
||||
$r = q('SELECT * FROM `photo` WHERE `profile-id` = %d LIMIT 1',
|
||||
intval($profile_id)
|
||||
);
|
||||
$r = q('SELECT * FROM `photo` WHERE `profile-id` = %d LIMIT 1', intval($profile_id));
|
||||
|
||||
if (count($r)) {
|
||||
$data = $r[0]['data'];
|
||||
}
|
||||
|
||||
if (x($data) === false || (!strlen($data))) {
|
||||
$data = file_get_contents('images/default-profile-sm.jpg');
|
||||
}
|
||||
|
@ -32,6 +33,7 @@ function photo_init(App $a) {
|
|||
header('Etag: ' . $etag);
|
||||
header('Expires: ' . datetime_convert('UTC', 'UTC', 'now + 1 week', 'D, d M Y H:i:s' . ' GMT'));
|
||||
header('Cache-Control: max-age=' . intval(7 * 24 * 3600));
|
||||
|
||||
if (function_exists('header_remove')) {
|
||||
header_remove('Pragma');
|
||||
header_remove('pragma');
|
||||
|
|
|
@ -4,13 +4,13 @@ use Friendica\Directory\Rendering\View;
|
|||
use Friendica\Directory\Helper\Search as SearchHelper;
|
||||
use Friendica\Directory\Helper\Profile as ProfileHelper;
|
||||
|
||||
function search_content(&$a) {
|
||||
|
||||
function search_content(App $a)
|
||||
{
|
||||
//Filters
|
||||
$community = null;
|
||||
$filter = null;
|
||||
if($a->argc >= 2){
|
||||
|
||||
if ($a->argc >= 2) {
|
||||
$filter = $a->argv[1];
|
||||
switch ($filter) {
|
||||
|
||||
|
@ -26,9 +26,7 @@ function search_content(&$a) {
|
|||
$community = null;
|
||||
$filter = null;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$alpha = false;
|
||||
|
@ -42,17 +40,21 @@ function search_content(&$a) {
|
|||
goaway('/home');
|
||||
}
|
||||
|
||||
if($search)
|
||||
if ($search) {
|
||||
$alpha = true;
|
||||
}
|
||||
|
||||
//Run our query.
|
||||
if($search)
|
||||
if ($search) {
|
||||
$search = dbesc($search . '*');
|
||||
}
|
||||
|
||||
$sql_extra = ((strlen($search)) ? " AND MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` )
|
||||
AGAINST ('$search' IN BOOLEAN MODE) " : "");
|
||||
|
||||
if(!is_null($community))
|
||||
if (!is_null($community)) {
|
||||
$sql_extra .= " and comm=" . intval($community) . " ";
|
||||
}
|
||||
|
||||
$sql_extra = str_replace('%', '%%', $sql_extra);
|
||||
|
||||
|
@ -63,11 +65,11 @@ function search_content(&$a) {
|
|||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
|
||||
if($alpha)
|
||||
if ($alpha) {
|
||||
$order = " order by name asc ";
|
||||
else
|
||||
} else {
|
||||
$order = " order by updated desc, id desc ";
|
||||
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM `profile` WHERE `censored` = 0 $sql_extra $order LIMIT %d , %d ",
|
||||
intval($a->pager['start']),
|
||||
|
@ -77,7 +79,9 @@ function search_content(&$a) {
|
|||
//Show results.
|
||||
$view = new View('search');
|
||||
|
||||
$view->addHelper('paginate', function()use($a){return paginate($a);});
|
||||
$view->addHelper('paginate', function() use ($a) {
|
||||
return paginate($a);
|
||||
});
|
||||
$view->addHelper('photoUrl', ProfileHelper::get('photoUrl'));
|
||||
$view->addHelper('filterAllUrl', SearchHelper::get('filterAllUrl'));
|
||||
$view->addHelper('filterPeopleUrl', SearchHelper::get('filterPeopleUrl'));
|
||||
|
@ -89,5 +93,4 @@ function search_content(&$a) {
|
|||
'filter' => $filter,
|
||||
'query' => x($_GET, 'query') ? $_GET['query'] : ''
|
||||
));
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use Friendica\Directory\Rendering\View;
|
||||
|
||||
require_once('include/site-health.php');
|
||||
require_once 'include/site-health.php';
|
||||
|
||||
function servers_content(&$a) {
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php namespace Friendica\Directory\Helper;
|
||||
<?php
|
||||
|
||||
namespace Friendica\Directory\Helper;
|
||||
|
||||
use \OutOfBoundsException;
|
||||
use \ReflectionMethod;
|
||||
|
@ -8,6 +10,11 @@ use \ReflectionMethod;
|
|||
*/
|
||||
abstract class BaseHelper
|
||||
{
|
||||
/**
|
||||
* A reference to the global App.
|
||||
* @var \App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
public static function get($name)
|
||||
{
|
||||
|
@ -15,12 +22,6 @@ abstract class BaseHelper
|
|||
return $helper->{$name};
|
||||
}
|
||||
|
||||
/**
|
||||
* A reference to the global App.
|
||||
* @var \App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $a;
|
||||
|
@ -30,7 +31,6 @@ abstract class BaseHelper
|
|||
//Provides access to a wrapper for your helper functions.
|
||||
public function __get($name)
|
||||
{
|
||||
|
||||
if (!method_exists($this, $name)) {
|
||||
throw new OutOfBoundsException("Helper method '$name' does not exist on " . get_class($this));
|
||||
}
|
||||
|
@ -41,7 +41,5 @@ abstract class BaseHelper
|
|||
$arguments = func_get_args();
|
||||
return $method->invokeArgs($helper, $arguments);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue