Merge branch 'dev' of ../p3 into dev

This commit is contained in:
nobody 2020-12-21 14:43:19 -08:00
commit cdd077714a
3 changed files with 4 additions and 162 deletions

View file

@ -90,13 +90,13 @@ class PermissionLimits {
call_hooks('permission_limits_get',$a);
return intval($a['value']);
}
return $x;
return intval($x);
}
PConfig::Load($channel_id);
if(array_key_exists($channel_id, App::$config)
&& array_key_exists('perm_limits', App::$config[$channel_id]))
return App::$config[$channel_id]['perm_limits'];
if(array_key_exists($channel_id, App::$config) && array_key_exists('perm_limits', App::$config[$channel_id])) {
return intval(App::$config[$channel_id]['perm_limits']);
}
return false;
}

View file

@ -1,113 +0,0 @@
<?php
namespace Zotlabs\Daemon;
use Zotlabs\Lib\Libzot;
/*
This file is being kept for archival reference at this time.
It is not currently referenced elsewhere. Its purpose is to grab
some public posts from random zot sites by polling occasionally
and asking for a 'zotfeed'. This is generally stored in the
'public stream' which is owned by the system channel on this site.
If somebody wishes to bring back this functionality, it should be
modified to read public outboxes in ActivityStreams format.
*/
class Externals {
static public function run($argc, $argv){
$total = 0;
$attempts = 0;
$sys = get_sys_channel();
logger('externals: startup', LOGGER_DEBUG);
// pull in some public posts
while ($total == 0 && $attempts < 3) {
$arr = [ 'url' => EMPTY_STR ];
call_hooks('externals_url_select',$arr);
if ($arr['url']) {
$url = $arr['url'];
}
else {
$randfunc = db_getfunc('RAND');
// fixme this query does not deal with directory realms.
$r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d and site_dead = 0 order by $randfunc limit 1",
dbesc(z_root()),
intval(DIRECTORY_MODE_STANDALONE),
intval(SITE_TYPE_ZOT)
);
if ($r) {
$url = $r[0]['site_url'];
}
}
$denied = false;
if (! check_siteallowed($url)) {
logger('denied site: ' . $url);
$denied = true;
}
$attempts ++;
// make sure we can eventually break out if somebody blacklists all known sites
if ($denied) {
if ($attempts > 20) {
break;
}
$attempts --;
continue;
}
if ($url) {
if ($r[0]['site_pull'] > NULL_DATE) {
$mindate = urlencode(datetime_convert('','',$r[0]['site_pull'] . ' - 1 day'));
}
else {
$days = get_config('externals','since_days',15);
$mindate = urlencode(datetime_convert('','','now - ' . intval($days) . ' days'));
}
$feedurl = $url . '/zotfeed?f=&mindate=' . $mindate;
logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG);
$x = z_fetch_url($feedurl);
if (($x) && ($x['success'])) {
q("update site set site_pull = '%s' where site_url = '%s'",
dbesc(datetime_convert()),
dbesc($url)
);
$j = json_decode($x['body'],true);
if($j['success'] && $j['messages']) {
foreach($j['messages'] as $message) {
// on these posts, clear any route info.
$message['route'] = EMPTY_STR;
$results = Libzot::process_delivery('undefined', null, get_item_elements($message), [ $sys['xchan_hash'] ], false, true);
$total ++;
}
logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
}
}
}
}
}
}

View file

@ -1,45 +0,0 @@
<?php
namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
class Zotfeed extends Controller {
function init() {
$result = [ 'success' => false ];
$mindate = (($_REQUEST['mindate']) ? datetime_convert('UTC','UTC',$_REQUEST['mindate']) : '');
if (! $mindate) {
$mindate = datetime_convert('UTC','UTC', 'now - 14 days');
}
if (observer_prohibited()) {
$result['message'] = 'Public access denied';
json_return_and_die($result);
}
$channel_address = ((argc() > 1) ? argv(1) : '');
if ($channel_address) {
$channel = channelx_by_nick($channel_address);
}
else {
$channel = get_sys_channel();
$mindate = datetime_convert('UTC','UTC', 'now - 14 days');
}
if (! $channel) {
$result['message'] = 'Channel not found.';
json_return_and_die($result);
}
logger('zotfeed request: ' . $channel['channel_name'], LOGGER_DEBUG);
$result['project'] = 'Zap';
$result['messages'] = zot_feed($channel['channel_id'],get_observer_hash(), [ 'mindate' => $mindate ]);
$result['success'] = true;
json_return_and_die($result);
}
}