mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 16:55:18 +00:00
psr12 rewrites, continued
This commit is contained in:
parent
f602a393a5
commit
d46dd6aeb8
712 changed files with 47242 additions and 43902 deletions
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Addon
|
||||
{
|
||||
|
||||
class Addon {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
|
||||
call_hooks('daemon_addon',$argv);
|
||||
|
||||
}
|
||||
call_hooks('daemon_addon', $argv);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,50 +1,54 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
require_once('include/photos.php');
|
||||
|
||||
class CacheThumb {
|
||||
class CacheThumb
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
if (! $argc == 2) {
|
||||
return;
|
||||
}
|
||||
if (! $argc == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = 'cache/img/' . substr($argv[1],0,2) . '/' . $argv[1];
|
||||
$path = 'cache/img/' . substr($argv[1], 0, 2) . '/' . $argv[1];
|
||||
|
||||
$is = getimagesize($path);
|
||||
$is = getimagesize($path);
|
||||
|
||||
if (! $is) {
|
||||
return;
|
||||
}
|
||||
|
||||
$width = $is[0];
|
||||
$height = $is[1];
|
||||
if (! $is) {
|
||||
return;
|
||||
}
|
||||
|
||||
$max_thumb = get_config('system','max_cache_thumbnail',1024);
|
||||
$width = $is[0];
|
||||
$height = $is[1];
|
||||
|
||||
if ($width > $max_thumb || $height > $max_thumb) {
|
||||
$imagick_path = get_config('system','imagick_convert_path');
|
||||
if ($imagick_path && @file_exists($imagick_path)) {
|
||||
$tmp_name = $path . '-001';
|
||||
$newsize = photo_calculate_scale(array_merge($is,['max' => $max_thumb]));
|
||||
$cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $path) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name);
|
||||
$max_thumb = get_config('system', 'max_cache_thumbnail', 1024);
|
||||
|
||||
for ($x = 0; $x < 4; $x ++) {
|
||||
exec($cmd);
|
||||
if (file_exists($tmp_name)) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! file_exists($tmp_name)) {
|
||||
return;
|
||||
}
|
||||
@rename($tmp_name,$path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($width > $max_thumb || $height > $max_thumb) {
|
||||
$imagick_path = get_config('system', 'imagick_convert_path');
|
||||
if ($imagick_path && @file_exists($imagick_path)) {
|
||||
$tmp_name = $path . '-001';
|
||||
$newsize = photo_calculate_scale(array_merge($is, ['max' => $max_thumb]));
|
||||
$cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $path) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name);
|
||||
|
||||
for ($x = 0; $x < 4; $x++) {
|
||||
exec($cmd);
|
||||
if (file_exists($tmp_name)) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! file_exists($tmp_name)) {
|
||||
return;
|
||||
}
|
||||
@rename($tmp_name, $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,33 +2,34 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Cache_embeds
|
||||
{
|
||||
|
||||
class Cache_embeds {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
if (! $argc == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $argc == 2) {
|
||||
return;
|
||||
}
|
||||
$c = q(
|
||||
"select body, html, created from item where id = %d ",
|
||||
dbesc(intval($argv[1]))
|
||||
);
|
||||
|
||||
$c = q("select body, html, created from item where id = %d ",
|
||||
dbesc(intval($argv[1]))
|
||||
);
|
||||
if (! $c) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $c) {
|
||||
return;
|
||||
}
|
||||
$item = array_shift($c);
|
||||
|
||||
$item = array_shift($c);
|
||||
$cache_expire = intval(get_config('system', 'default_expire_days'));
|
||||
if ($cache_expire <= 0) {
|
||||
$cache_expire = 60;
|
||||
}
|
||||
$cache_enable = ((($cache_expire) && ($item['created'] < datetime_convert('UTC', 'UTC', 'now - ' . $cache_expire . ' days'))) ? false : true);
|
||||
|
||||
$cache_expire = intval(get_config('system', 'default_expire_days'));
|
||||
if ($cache_expire <= 0) {
|
||||
$cache_expire = 60;
|
||||
}
|
||||
$cache_enable = ((($cache_expire) && ($item['created'] < datetime_convert('UTC','UTC', 'now - ' . $cache_expire . ' days'))) ? false : true);
|
||||
|
||||
$s = bbcode($item['body']);
|
||||
$s = sslify($s, $cache_enable);
|
||||
|
||||
}
|
||||
$s = bbcode($item['body']);
|
||||
$s = sslify($s, $cache_enable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,16 @@ namespace Zotlabs\Daemon;
|
|||
|
||||
use Zotlabs\Lib\Img_cache;
|
||||
|
||||
class Cache_image {
|
||||
class Cache_image
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
cli_startup();
|
||||
logger('caching: ' . $argv[1] . ' to ' . $argv[2]);
|
||||
if ($argc === 3) {
|
||||
Img_cache::url_to_cache($argv[1],$argv[2]);
|
||||
}
|
||||
|
||||
}
|
||||
cli_startup();
|
||||
logger('caching: ' . $argv[1] . ' to ' . $argv[2]);
|
||||
if ($argc === 3) {
|
||||
Img_cache::url_to_cache($argv[1], $argv[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,32 +2,35 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Channel_purge
|
||||
{
|
||||
|
||||
class Channel_purge {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
cli_startup();
|
||||
|
||||
cli_startup();
|
||||
$channel_id = intval($argv[1]);
|
||||
|
||||
$channel_id = intval($argv[1]);
|
||||
$channel = q(
|
||||
"select * from channel where channel_id = %d and channel_removed = 1",
|
||||
intval($channel_id)
|
||||
);
|
||||
|
||||
$channel = q("select * from channel where channel_id = %d and channel_removed = 1",
|
||||
intval($channel_id)
|
||||
);
|
||||
if (! $channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
$r = q("select id from item where uid = %d and item_deleted = 0 limit 1000",
|
||||
intval($channel_id)
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
drop_item($rv['id'],false);
|
||||
}
|
||||
}
|
||||
} while ($r);
|
||||
}
|
||||
do {
|
||||
$r = q(
|
||||
"select id from item where uid = %d and item_deleted = 0 limit 1000",
|
||||
intval($channel_id)
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
drop_item($rv['id'], false);
|
||||
}
|
||||
}
|
||||
} while ($r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +1,66 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
require_once('include/hubloc.php');
|
||||
|
||||
|
||||
class Checksites {
|
||||
class Checksites
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
logger('checksites: start');
|
||||
|
||||
if(($argc > 1) && ($argv[1]))
|
||||
$site_id = $argv[1];
|
||||
logger('checksites: start');
|
||||
|
||||
if($site_id)
|
||||
$sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
|
||||
if (($argc > 1) && ($argv[1])) {
|
||||
$site_id = $argv[1];
|
||||
}
|
||||
|
||||
$days = intval(get_config('system','sitecheckdays'));
|
||||
if($days < 1)
|
||||
$days = 30;
|
||||
if ($site_id) {
|
||||
$sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
|
||||
}
|
||||
|
||||
$r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d $sql_options ",
|
||||
db_utcnow(), db_quoteinterval($days . ' DAY'),
|
||||
intval(SITE_TYPE_ZOT)
|
||||
);
|
||||
$days = intval(get_config('system', 'sitecheckdays'));
|
||||
if ($days < 1) {
|
||||
$days = 30;
|
||||
}
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
$r = q(
|
||||
"select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d $sql_options ",
|
||||
db_utcnow(),
|
||||
db_quoteinterval($days . ' DAY'),
|
||||
intval(SITE_TYPE_ZOT)
|
||||
);
|
||||
|
||||
foreach($r as $rr) {
|
||||
if(! strcasecmp($rr['site_url'],z_root()))
|
||||
continue;
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
|
||||
$x = ping_site($rr['site_url']);
|
||||
if($x['success']) {
|
||||
logger('checksites: ' . $rr['site_url']);
|
||||
q("update site set site_update = '%s' where site_url = '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($rr['site_url'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
logger('marking dead site: ' . $x['message']);
|
||||
q("update site set site_dead = 1 where site_url = '%s' ",
|
||||
dbesc($rr['site_url'])
|
||||
);
|
||||
}
|
||||
}
|
||||
foreach ($r as $rr) {
|
||||
if (! strcasecmp($rr['site_url'], z_root())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$x = ping_site($rr['site_url']);
|
||||
if ($x['success']) {
|
||||
logger('checksites: ' . $rr['site_url']);
|
||||
q(
|
||||
"update site set site_update = '%s' where site_url = '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($rr['site_url'])
|
||||
);
|
||||
} else {
|
||||
logger('marking dead site: ' . $x['message']);
|
||||
q(
|
||||
"update site set site_dead = 1 where site_url = '%s' ",
|
||||
dbesc($rr['site_url'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,52 +8,55 @@ require_once('include/cli_startup.php');
|
|||
require_once('include/attach.php');
|
||||
require_once('include/import.php');
|
||||
|
||||
class Content_importer {
|
||||
class Content_importer
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
cli_startup();
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
cli_startup();
|
||||
|
||||
$page = $argv[1];
|
||||
$since = $argv[2];
|
||||
$until = $argv[3];
|
||||
$channel_address = $argv[4];
|
||||
$hz_server = urldecode($argv[5]);
|
||||
$page = $argv[1];
|
||||
$since = $argv[2];
|
||||
$until = $argv[3];
|
||||
$channel_address = $argv[4];
|
||||
$hz_server = urldecode($argv[5]);
|
||||
|
||||
$m = parse_url($hz_server);
|
||||
$m = parse_url($hz_server);
|
||||
|
||||
$channel = channelx_by_nick($channel_address);
|
||||
if(! $channel) {
|
||||
logger('itemhelper: channel not found');
|
||||
killme();
|
||||
}
|
||||
$channel = channelx_by_nick($channel_address);
|
||||
if (! $channel) {
|
||||
logger('itemhelper: channel not found');
|
||||
killme();
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'X-API-Token' => random_string(),
|
||||
'X-API-Request' => $hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
|
||||
'Host' => $m['host'],
|
||||
'(request-target)' => 'get /api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
|
||||
];
|
||||
$headers = [
|
||||
'X-API-Token' => random_string(),
|
||||
'X-API-Request' => $hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
|
||||
'Host' => $m['host'],
|
||||
'(request-target)' => 'get /api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
|
||||
];
|
||||
|
||||
$headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel),true,'sha512');
|
||||
$headers = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), true, 'sha512');
|
||||
|
||||
$x = z_fetch_url($hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page,false,$redirects,[ 'headers' => $headers ]);
|
||||
$x = z_fetch_url($hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page, false, $redirects, [ 'headers' => $headers ]);
|
||||
|
||||
if(! $x['success']) {
|
||||
logger('no API response',LOGGER_DEBUG);
|
||||
killme();
|
||||
}
|
||||
if (! $x['success']) {
|
||||
logger('no API response', LOGGER_DEBUG);
|
||||
killme();
|
||||
}
|
||||
|
||||
$j = json_decode($x['body'],true);
|
||||
$j = json_decode($x['body'], true);
|
||||
|
||||
if (! $j) {
|
||||
killme();
|
||||
}
|
||||
if (! $j) {
|
||||
killme();
|
||||
}
|
||||
|
||||
if(! ($j['item'] || count($j['item'])))
|
||||
killme();
|
||||
if (! ($j['item'] || count($j['item']))) {
|
||||
killme();
|
||||
}
|
||||
|
||||
import_items($channel,$j['item'],false,((array_key_exists('relocate',$j)) ? $j['relocate'] : null));
|
||||
import_items($channel, $j['item'], false, ((array_key_exists('relocate', $j)) ? $j['relocate'] : null));
|
||||
|
||||
killme();
|
||||
}
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
|
@ -6,53 +6,56 @@ use Zotlabs\Lib\Activity;
|
|||
use Zotlabs\Lib\ActivityStreams;
|
||||
use Zotlabs\Lib\ASCollection;
|
||||
|
||||
class Convo {
|
||||
class Convo
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
logger('convo invoked: ' . print_r($argv,true));
|
||||
logger('convo invoked: ' . print_r($argv, true));
|
||||
|
||||
if($argc != 4) {
|
||||
killme();
|
||||
}
|
||||
if ($argc != 4) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$id = $argv[1];
|
||||
$channel_id = intval($argv[2]);
|
||||
$contact_hash = $argv[3];
|
||||
|
||||
$channel = channelx_by_n($channel_id);
|
||||
if (! $channel) {
|
||||
killme();
|
||||
}
|
||||
$id = $argv[1];
|
||||
$channel_id = intval($argv[2]);
|
||||
$contact_hash = $argv[3];
|
||||
|
||||
$r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
$channel = channelx_by_n($channel_id);
|
||||
if (! $channel) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$r = q(
|
||||
"SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE abook_channel = %d and abook_xchan = '%s' LIMIT 1",
|
||||
intval($channel_id),
|
||||
dbesc($contact_hash)
|
||||
);
|
||||
if (! $r) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$contact = array_shift($r);
|
||||
intval($channel_id),
|
||||
dbesc($contact_hash)
|
||||
);
|
||||
if (! $r) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$obj = new ASCollection($id, $channel);
|
||||
$contact = array_shift($r);
|
||||
|
||||
$messages = $obj->get();
|
||||
$obj = new ASCollection($id, $channel);
|
||||
|
||||
if ($messages) {
|
||||
foreach ($messages as $message) {
|
||||
if (is_string($message)) {
|
||||
$message = Activity::fetch($message,$channel);
|
||||
}
|
||||
// set client flag because comments will probably just be objects and not full blown activities
|
||||
// and that lets us use implied_create
|
||||
$AS = new ActivityStreams($message, null, true);
|
||||
if ($AS->is_valid() && is_array($AS->obj)) {
|
||||
$item = Activity::decode_note($AS,true);
|
||||
Activity::store($channel,$contact['abook_xchan'],$AS,$item,true,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$messages = $obj->get();
|
||||
|
||||
if ($messages) {
|
||||
foreach ($messages as $message) {
|
||||
if (is_string($message)) {
|
||||
$message = Activity::fetch($message, $channel);
|
||||
}
|
||||
// set client flag because comments will probably just be objects and not full blown activities
|
||||
// and that lets us use implied_create
|
||||
$AS = new ActivityStreams($message, null, true);
|
||||
if ($AS->is_valid() && is_array($AS->obj)) {
|
||||
$item = Activity::decode_note($AS, true);
|
||||
Activity::store($channel, $contact['abook_xchan'], $AS, $item, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,201 +1,221 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib\Libsync;
|
||||
|
||||
class Cron {
|
||||
class Cron
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
if(function_exists('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
if(intval($load[0]) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Cron deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$maxsysload = intval(get_config('system', 'maxloadavg'));
|
||||
if ($maxsysload < 1) {
|
||||
$maxsysload = 50;
|
||||
}
|
||||
if (function_exists('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
if (intval($load[0]) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Cron deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
|
||||
$lockfile = 'cache/cron';
|
||||
if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
|
||||
&& (! get_config('system','override_cron_lockfile'))) {
|
||||
logger("cron: Already running");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a lockfile. Needs two vars, but $x doesn't need to contain anything.
|
||||
file_put_contents($lockfile, $x);
|
||||
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
|
||||
$lockfile = 'cache/cron';
|
||||
if (
|
||||
(file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
|
||||
&& (! get_config('system', 'override_cron_lockfile'))
|
||||
) {
|
||||
logger("cron: Already running");
|
||||
return;
|
||||
}
|
||||
|
||||
logger('cron: start');
|
||||
|
||||
// run queue delivery process in the background
|
||||
// Create a lockfile. Needs two vars, but $x doesn't need to contain anything.
|
||||
file_put_contents($lockfile, $x);
|
||||
|
||||
Run::Summon( [ 'Queue' ] );
|
||||
logger('cron: start');
|
||||
|
||||
Run::Summon( [ 'Poller' ] );
|
||||
// run queue delivery process in the background
|
||||
|
||||
// maintenance for mod sharedwithme - check for updated items and remove them
|
||||
Run::Summon([ 'Queue' ]);
|
||||
|
||||
require_once('include/sharedwithme.php');
|
||||
apply_updates();
|
||||
|
||||
// expire any expired items
|
||||
Run::Summon([ 'Poller' ]);
|
||||
|
||||
$r = q("select id,item_wall from item where expires > '2001-01-01 00:00:00' and expires < %s
|
||||
// maintenance for mod sharedwithme - check for updated items and remove them
|
||||
|
||||
require_once('include/sharedwithme.php');
|
||||
apply_updates();
|
||||
|
||||
// expire any expired items
|
||||
|
||||
$r = q(
|
||||
"select id,item_wall from item where expires > '2001-01-01 00:00:00' and expires < %s
|
||||
and item_deleted = 0 ",
|
||||
db_utcnow()
|
||||
);
|
||||
if($r) {
|
||||
require_once('include/items.php');
|
||||
foreach($r as $rr) {
|
||||
drop_item($rr['id'],false,(($rr['item_wall']) ? DROPITEM_PHASE1 : DROPITEM_NORMAL));
|
||||
if($rr['item_wall']) {
|
||||
// The notifier isn't normally invoked unless item_drop is interactive.
|
||||
Run::Summon( [ 'Notifier', 'drop', $rr['id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
db_utcnow()
|
||||
);
|
||||
if ($r) {
|
||||
require_once('include/items.php');
|
||||
foreach ($r as $rr) {
|
||||
drop_item($rr['id'], false, (($rr['item_wall']) ? DROPITEM_PHASE1 : DROPITEM_NORMAL));
|
||||
if ($rr['item_wall']) {
|
||||
// The notifier isn't normally invoked unless item_drop is interactive.
|
||||
Run::Summon([ 'Notifier', 'drop', $rr['id'] ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// delete expired access tokens
|
||||
// delete expired access tokens
|
||||
|
||||
$r = q("select atoken_id from atoken where atoken_expires > '%s' and atoken_expires < %s",
|
||||
dbesc(NULL_DATE),
|
||||
db_utcnow()
|
||||
);
|
||||
if($r) {
|
||||
require_once('include/security.php');
|
||||
foreach($r as $rr) {
|
||||
atoken_delete($rr['atoken_id']);
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"select atoken_id from atoken where atoken_expires > '%s' and atoken_expires < %s",
|
||||
dbesc(NULL_DATE),
|
||||
db_utcnow()
|
||||
);
|
||||
if ($r) {
|
||||
require_once('include/security.php');
|
||||
foreach ($r as $rr) {
|
||||
atoken_delete($rr['atoken_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that every channel pings their directory occasionally.
|
||||
// Ensure that every channel pings their directory occasionally.
|
||||
|
||||
$r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s and channel_removed = 0",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('7 DAY')
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
Run::Summon( [ 'Directory', $rr['channel_id'], 'force' ] );
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"select channel_id from channel where channel_dirdate < %s - INTERVAL %s and channel_removed = 0",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('7 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
Run::Summon([ 'Directory', $rr['channel_id'], 'force' ]);
|
||||
if ($interval) {
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// publish any applicable items that were set to be published in the future
|
||||
// (time travel posts). Restrict to items that have come of age in the last
|
||||
// couple of days to limit the query to something reasonable.
|
||||
// publish any applicable items that were set to be published in the future
|
||||
// (time travel posts). Restrict to items that have come of age in the last
|
||||
// couple of days to limit the query to something reasonable.
|
||||
|
||||
$r = q("select id from item where item_delayed = 1 and created <= %s and created > '%s' ",
|
||||
db_utcnow(),
|
||||
dbesc(datetime_convert('UTC','UTC','now - 2 days'))
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$x = q("update item set item_delayed = 0 where id = %d",
|
||||
intval($rr['id'])
|
||||
);
|
||||
if($x) {
|
||||
$z = q("select * from item where id = %d",
|
||||
intval($message_id)
|
||||
);
|
||||
if($z) {
|
||||
xchan_query($z);
|
||||
$sync_item = fetch_post_tags($z);
|
||||
Libsync::build_sync_packet($sync_item[0]['uid'],
|
||||
[
|
||||
'item' => [ encode_item($sync_item[0],true) ]
|
||||
]
|
||||
);
|
||||
}
|
||||
Run::Summon( [ 'Notifier','wall-new',$rr['id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"select id from item where item_delayed = 1 and created <= %s and created > '%s' ",
|
||||
db_utcnow(),
|
||||
dbesc(datetime_convert('UTC', 'UTC', 'now - 2 days'))
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$x = q(
|
||||
"update item set item_delayed = 0 where id = %d",
|
||||
intval($rr['id'])
|
||||
);
|
||||
if ($x) {
|
||||
$z = q(
|
||||
"select * from item where id = %d",
|
||||
intval($message_id)
|
||||
);
|
||||
if ($z) {
|
||||
xchan_query($z);
|
||||
$sync_item = fetch_post_tags($z);
|
||||
Libsync::build_sync_packet(
|
||||
$sync_item[0]['uid'],
|
||||
[
|
||||
'item' => [ encode_item($sync_item[0], true) ]
|
||||
]
|
||||
);
|
||||
}
|
||||
Run::Summon([ 'Notifier','wall-new',$rr['id'] ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once('include/attach.php');
|
||||
attach_upgrade();
|
||||
require_once('include/attach.php');
|
||||
attach_upgrade();
|
||||
|
||||
$abandon_days = intval(get_config('system','account_abandon_days'));
|
||||
if($abandon_days < 1)
|
||||
$abandon_days = 0;
|
||||
|
||||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
|
||||
// FIXME: add birthday updates, both locally and for xprof for use
|
||||
// by directory servers
|
||||
|
||||
$d1 = intval(get_config('system','last_expire_day'));
|
||||
$d2 = intval(datetime_convert('UTC','UTC','now','d'));
|
||||
|
||||
// Allow somebody to staggger daily activities if they have more than one site on their server,
|
||||
// or if it happens at an inconvenient (busy) hour.
|
||||
|
||||
$h1 = intval(get_config('system','cron_hour'));
|
||||
$h2 = intval(datetime_convert('UTC','UTC','now','G'));
|
||||
$abandon_days = intval(get_config('system', 'account_abandon_days'));
|
||||
if ($abandon_days < 1) {
|
||||
$abandon_days = 0;
|
||||
}
|
||||
|
||||
|
||||
if(($d2 != $d1) && ($h1 == $h2)) {
|
||||
Run::Summon( [ 'Cron_daily' ] );
|
||||
}
|
||||
// once daily run birthday_updates and then expire in background
|
||||
|
||||
// update any photos which didn't get imported properly
|
||||
// This should be rare
|
||||
// FIXME: add birthday updates, both locally and for xprof for use
|
||||
// by directory servers
|
||||
|
||||
$r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = ''
|
||||
$d1 = intval(get_config('system', 'last_expire_day'));
|
||||
$d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd'));
|
||||
|
||||
// Allow somebody to staggger daily activities if they have more than one site on their server,
|
||||
// or if it happens at an inconvenient (busy) hour.
|
||||
|
||||
$h1 = intval(get_config('system', 'cron_hour'));
|
||||
$h2 = intval(datetime_convert('UTC', 'UTC', 'now', 'G'));
|
||||
|
||||
|
||||
if (($d2 != $d1) && ($h1 == $h2)) {
|
||||
Run::Summon([ 'Cron_daily' ]);
|
||||
}
|
||||
|
||||
// update any photos which didn't get imported properly
|
||||
// This should be rare
|
||||
|
||||
$r = q(
|
||||
"select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = ''
|
||||
and xchan_photo_date < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('1 DAY')
|
||||
);
|
||||
if($r) {
|
||||
require_once('include/photo_factory.php');
|
||||
foreach($r as $rr) {
|
||||
$photos = import_remote_xchan_photo($rr['xchan_photo_l'],$rr['xchan_hash']);
|
||||
if ($photos) {
|
||||
$x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
|
||||
db_utcnow(),
|
||||
db_quoteinterval('1 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
require_once('include/photo_factory.php');
|
||||
foreach ($r as $rr) {
|
||||
$photos = import_remote_xchan_photo($rr['xchan_photo_l'], $rr['xchan_hash']);
|
||||
if ($photos) {
|
||||
$x = q(
|
||||
"update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
|
||||
where xchan_hash = '%s'",
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
dbesc($photos[3]),
|
||||
dbesc($rr['xchan_hash'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
dbesc($photos[3]),
|
||||
dbesc($rr['xchan_hash'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$generation = 0;
|
||||
$generation = 0;
|
||||
|
||||
$restart = false;
|
||||
$restart = false;
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if(! $generation)
|
||||
return;
|
||||
}
|
||||
if (($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if (! $generation) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reload_plugins();
|
||||
reload_plugins();
|
||||
|
||||
$d = datetime_convert();
|
||||
$d = datetime_convert();
|
||||
|
||||
// TODO check to see if there are any cronhooks before wasting a process
|
||||
// TODO check to see if there are any cronhooks before wasting a process
|
||||
|
||||
if(! $restart)
|
||||
Run::Summon( [ 'Cronhooks' ] );
|
||||
if (! $restart) {
|
||||
Run::Summon([ 'Cronhooks' ]);
|
||||
}
|
||||
|
||||
set_config('system','lastcron',datetime_convert());
|
||||
set_config('system', 'lastcron', datetime_convert());
|
||||
|
||||
//All done - clear the lockfile
|
||||
@unlink($lockfile);
|
||||
//All done - clear the lockfile
|
||||
@unlink($lockfile);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,110 +1,122 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib\Libzotdir;
|
||||
use Zotlabs\Lib\Libzot;
|
||||
|
||||
class Cron_daily {
|
||||
class Cron_daily
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
logger('cron_daily: start');
|
||||
logger('cron_daily: start');
|
||||
|
||||
/**
|
||||
* Cron Daily
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Cron Daily
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// make sure our own site record is up to date
|
||||
Libzot::import_site(Libzot::site_info(true));
|
||||
// make sure our own site record is up to date
|
||||
Libzot::import_site(Libzot::site_info(true));
|
||||
|
||||
|
||||
// Fire off the Cron_weekly process if it's the correct day.
|
||||
|
||||
$d3 = intval(datetime_convert('UTC','UTC','now','N'));
|
||||
if ($d3 == 7) {
|
||||
Run::Summon( [ 'Cron_weekly' ] );
|
||||
}
|
||||
// Fire off the Cron_weekly process if it's the correct day.
|
||||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
$d3 = intval(datetime_convert('UTC', 'UTC', 'now', 'N'));
|
||||
if ($d3 == 7) {
|
||||
Run::Summon([ 'Cron_weekly' ]);
|
||||
}
|
||||
|
||||
// FIXME: add birthday updates, both locally and for xprof for use
|
||||
// by directory servers
|
||||
// once daily run birthday_updates and then expire in background
|
||||
|
||||
update_birthdays();
|
||||
// FIXME: add birthday updates, both locally and for xprof for use
|
||||
// by directory servers
|
||||
|
||||
// expire any read notifications over a month old
|
||||
update_birthdays();
|
||||
|
||||
q("delete from notify where seen = 1 and created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('60 DAY')
|
||||
);
|
||||
// expire any read notifications over a month old
|
||||
|
||||
// expire any unread notifications over a year old
|
||||
q(
|
||||
"delete from notify where seen = 1 and created < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('60 DAY')
|
||||
);
|
||||
|
||||
q("delete from notify where seen = 0 and created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('1 YEAR')
|
||||
);
|
||||
// expire any unread notifications over a year old
|
||||
|
||||
q(
|
||||
"delete from notify where seen = 0 and created < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('1 YEAR')
|
||||
);
|
||||
|
||||
|
||||
//update statistics in config
|
||||
require_once('include/statistics_fns.php');
|
||||
update_channels_total_stat();
|
||||
update_channels_active_halfyear_stat();
|
||||
update_channels_active_monthly_stat();
|
||||
update_local_posts_stat();
|
||||
update_local_comments_stat();
|
||||
//update statistics in config
|
||||
require_once('include/statistics_fns.php');
|
||||
update_channels_total_stat();
|
||||
update_channels_active_halfyear_stat();
|
||||
update_channels_active_monthly_stat();
|
||||
update_local_posts_stat();
|
||||
update_local_comments_stat();
|
||||
|
||||
|
||||
// expire old delivery reports
|
||||
// expire old delivery reports
|
||||
|
||||
$keep_reports = intval(get_config('system','expire_delivery_reports'));
|
||||
if($keep_reports === 0)
|
||||
$keep_reports = 10;
|
||||
$keep_reports = intval(get_config('system', 'expire_delivery_reports'));
|
||||
if ($keep_reports === 0) {
|
||||
$keep_reports = 10;
|
||||
}
|
||||
|
||||
q("delete from dreport where dreport_time < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval($keep_reports . ' DAY')
|
||||
);
|
||||
q(
|
||||
"delete from dreport where dreport_time < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval($keep_reports . ' DAY')
|
||||
);
|
||||
|
||||
// delete accounts that did not submit email verification within 3 days
|
||||
// delete accounts that did not submit email verification within 3 days
|
||||
|
||||
$r = q("select * from register where password = 'verify' and created < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('3 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
q("DELETE FROM account WHERE account_id = %d",
|
||||
intval($rv['uid'])
|
||||
);
|
||||
$r = q(
|
||||
"select * from register where password = 'verify' and created < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('3 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
q(
|
||||
"DELETE FROM account WHERE account_id = %d",
|
||||
intval($rv['uid'])
|
||||
);
|
||||
|
||||
q("DELETE FROM register WHERE id = %d",
|
||||
intval($rv['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
q(
|
||||
"DELETE FROM register WHERE id = %d",
|
||||
intval($rv['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// expire any expired accounts
|
||||
downgrade_accounts();
|
||||
// expire any expired accounts
|
||||
downgrade_accounts();
|
||||
|
||||
Run::Summon( [ 'Expire' ] );
|
||||
Run::Summon([ 'Expire' ]);
|
||||
|
||||
|
||||
// remove xchan photos that were stored in the DB ine earlier versions
|
||||
// and were migrated to filesystem storage.
|
||||
// eventually this will do nothing but waste cpu cycles checking to see if anything remains.
|
||||
|
||||
cleanup_xchan_photos();
|
||||
// remove xchan photos that were stored in the DB ine earlier versions
|
||||
// and were migrated to filesystem storage.
|
||||
// eventually this will do nothing but waste cpu cycles checking to see if anything remains.
|
||||
|
||||
remove_obsolete_hublocs();
|
||||
cleanup_xchan_photos();
|
||||
|
||||
call_hooks('cron_daily',datetime_convert());
|
||||
remove_obsolete_hublocs();
|
||||
|
||||
set_config('system','last_expire_day',intval(datetime_convert('UTC','UTC','now','d')));
|
||||
call_hooks('cron_daily', datetime_convert());
|
||||
|
||||
/**
|
||||
* End Cron Daily
|
||||
*/
|
||||
}
|
||||
set_config('system', 'last_expire_day', intval(datetime_convert('UTC', 'UTC', 'now', 'd')));
|
||||
|
||||
/**
|
||||
* End Cron Daily
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,77 +2,83 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Cron_weekly {
|
||||
class Cron_weekly
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
/**
|
||||
* Cron Weekly
|
||||
*
|
||||
* Actions in the following block are executed once per day only on Sunday (once per week).
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Cron Weekly
|
||||
*
|
||||
* Actions in the following block are executed once per day only on Sunday (once per week).
|
||||
*
|
||||
*/
|
||||
|
||||
call_hooks('cron_weekly',datetime_convert());
|
||||
call_hooks('cron_weekly', datetime_convert());
|
||||
|
||||
z_check_cert();
|
||||
z_check_cert();
|
||||
|
||||
prune_hub_reinstalls();
|
||||
|
||||
mark_orphan_hubsxchans();
|
||||
prune_hub_reinstalls();
|
||||
|
||||
// Find channels that were removed in the last three weeks, but
|
||||
// haven't been finally cleaned up. These should be older than 10
|
||||
// days to ensure that "purgeall" messages have gone out or bounced
|
||||
// or timed out.
|
||||
mark_orphan_hubsxchans();
|
||||
|
||||
$r = q("select channel_id from channel where channel_removed = 1 and
|
||||
// Find channels that were removed in the last three weeks, but
|
||||
// haven't been finally cleaned up. These should be older than 10
|
||||
// days to ensure that "purgeall" messages have gone out or bounced
|
||||
// or timed out.
|
||||
|
||||
$r = q(
|
||||
"select channel_id from channel where channel_removed = 1 and
|
||||
channel_deleted > %s - INTERVAL %s and channel_deleted < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('21 DAY'),
|
||||
db_utcnow(), db_quoteinterval('10 DAY')
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rv) {
|
||||
channel_remove_final($rv['channel_id']);
|
||||
}
|
||||
}
|
||||
db_utcnow(),
|
||||
db_quoteinterval('21 DAY'),
|
||||
db_utcnow(),
|
||||
db_quoteinterval('10 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
channel_remove_final($rv['channel_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// get rid of really old poco records
|
||||
// get rid of really old poco records
|
||||
|
||||
q("delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ",
|
||||
db_utcnow(), db_quoteinterval('14 DAY')
|
||||
);
|
||||
q(
|
||||
"delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('14 DAY')
|
||||
);
|
||||
|
||||
// Check for dead sites
|
||||
Run::Summon( ['Checksites' ] );
|
||||
// Check for dead sites
|
||||
Run::Summon(['Checksites' ]);
|
||||
|
||||
|
||||
// clean up image cache - use site expiration or 60 days if not set or zero
|
||||
|
||||
$files = glob('cache/img/*/*');
|
||||
$expire_days = intval(get_config('system','default_expire_days'));
|
||||
if ($expire_days <= 0) {
|
||||
$expire_days = 60;
|
||||
}
|
||||
$now = time();
|
||||
$maxage = 86400 * $expire_days;
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
if ($now - filemtime($file) >= $maxage) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up image cache - use site expiration or 60 days if not set or zero
|
||||
|
||||
// update searchable doc indexes
|
||||
$files = glob('cache/img/*/*');
|
||||
$expire_days = intval(get_config('system', 'default_expire_days'));
|
||||
if ($expire_days <= 0) {
|
||||
$expire_days = 60;
|
||||
}
|
||||
$now = time();
|
||||
$maxage = 86400 * $expire_days;
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
if ($now - filemtime($file) >= $maxage) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Run::Summon( [ 'Importdoc'] );
|
||||
// update searchable doc indexes
|
||||
|
||||
/**
|
||||
* End Cron Weekly
|
||||
*/
|
||||
Run::Summon([ 'Importdoc']);
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* End Cron Weekly
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Cronhooks {
|
||||
class Cronhooks
|
||||
{
|
||||
|
||||
public static function run($argc, $argv){
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
logger('cronhooks: start');
|
||||
|
||||
$d = datetime_convert();
|
||||
logger('cronhooks: start');
|
||||
|
||||
call_hooks('cron', $d);
|
||||
$d = datetime_convert();
|
||||
|
||||
return;
|
||||
}
|
||||
call_hooks('cron', $d);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,56 +2,59 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
// generate a curl compatible cookie file with an authenticated session for the given channel_id.
|
||||
// If this file is then used with curl and the destination url is sent through zid() or manually
|
||||
// generate a curl compatible cookie file with an authenticated session for the given channel_id.
|
||||
// If this file is then used with curl and the destination url is sent through zid() or manually
|
||||
// manipulated to add a zid, it should allow curl to provide zot magic-auth across domains.
|
||||
|
||||
// Handles expiration of stale cookies currently by deleting them and rewriting the file.
|
||||
// Handles expiration of stale cookies currently by deleting them and rewriting the file.
|
||||
|
||||
use App;
|
||||
|
||||
class CurlAuth {
|
||||
class CurlAuth
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
if($argc != 2)
|
||||
return;
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
App::$session->start();
|
||||
App::$session->start();
|
||||
|
||||
$_SESSION['authenticated'] = 1;
|
||||
$_SESSION['uid'] = $argv[1];
|
||||
$_SESSION['authenticated'] = 1;
|
||||
$_SESSION['uid'] = $argv[1];
|
||||
|
||||
$x = session_id();
|
||||
$x = session_id();
|
||||
|
||||
$f = 'cache/cookie_' . $argv[1];
|
||||
$c = 'cache/cookien_' . $argv[1];
|
||||
$f = 'cache/cookie_' . $argv[1];
|
||||
$c = 'cache/cookien_' . $argv[1];
|
||||
|
||||
$e = file_exists($f);
|
||||
$e = file_exists($f);
|
||||
|
||||
$output = '';
|
||||
$output = '';
|
||||
|
||||
if($e) {
|
||||
$lines = file($f);
|
||||
if($lines) {
|
||||
foreach($lines as $line) {
|
||||
if(strlen($line) > 0 && $line[0] != '#' && substr_count($line, "\t") == 6) {
|
||||
$tokens = explode("\t", $line);
|
||||
$tokens = array_map('trim', $tokens);
|
||||
if($tokens[4] > time()) {
|
||||
$output .= $line . "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
$t = time() + (24 * 3600);
|
||||
file_put_contents($f, $output . 'HttpOnly_' . App::get_hostname() . "\tFALSE\t/\tTRUE\t$t\tPHPSESSID\t" . $x, (($e) ? FILE_APPEND : 0));
|
||||
if ($e) {
|
||||
$lines = file($f);
|
||||
if ($lines) {
|
||||
foreach ($lines as $line) {
|
||||
if (strlen($line) > 0 && $line[0] != '#' && substr_count($line, "\t") == 6) {
|
||||
$tokens = explode("\t", $line);
|
||||
$tokens = array_map('trim', $tokens);
|
||||
if ($tokens[4] > time()) {
|
||||
$output .= $line . "\n";
|
||||
}
|
||||
} else {
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$t = time() + (24 * 3600);
|
||||
file_put_contents($f, $output . 'HttpOnly_' . App::get_hostname() . "\tFALSE\t/\tTRUE\t$t\tPHPSESSID\t" . $x, (($e) ? FILE_APPEND : 0));
|
||||
|
||||
file_put_contents($c,$x);
|
||||
file_put_contents($c, $x);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,36 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib\Libzot;
|
||||
use Zotlabs\Lib\Queue;
|
||||
|
||||
class Deliver
|
||||
{
|
||||
|
||||
class Deliver {
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
if($argc < 2)
|
||||
return;
|
||||
if ($argc < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
|
||||
logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
|
||||
|
||||
for($x = 1; $x < $argc; $x ++) {
|
||||
for ($x = 1; $x < $argc; $x++) {
|
||||
if (! $argv[$x]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! $argv[$x])
|
||||
continue;
|
||||
|
||||
$r = q("select * from outq where outq_hash = '%s' limit 1",
|
||||
dbesc($argv[$x])
|
||||
);
|
||||
if($r) {
|
||||
Queue::deliver($r[0],true);
|
||||
}
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"select * from outq where outq_hash = '%s' limit 1",
|
||||
dbesc($argv[$x])
|
||||
);
|
||||
if ($r) {
|
||||
Queue::deliver($r[0], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,23 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Deliver_hooks
|
||||
{
|
||||
|
||||
class Deliver_hooks {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
|
||||
if($argc < 2)
|
||||
return;
|
||||
if ($argc < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$r = q("select * from item where id = '%d'",
|
||||
intval($argv[1])
|
||||
);
|
||||
if($r)
|
||||
call_hooks('notifier_normal',$r[0]);
|
||||
|
||||
}
|
||||
$r = q(
|
||||
"select * from item where id = '%d'",
|
||||
intval($argv[1])
|
||||
);
|
||||
if ($r) {
|
||||
call_hooks('notifier_normal', $r[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,18 +6,20 @@ namespace Zotlabs\Daemon;
|
|||
* Daemon to remove 'item' resources in the background from a removed connection
|
||||
*/
|
||||
|
||||
class Delxitems {
|
||||
class Delxitems
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
cli_startup();
|
||||
cli_startup();
|
||||
|
||||
if($argc != 3) {
|
||||
return;
|
||||
}
|
||||
if ($argc != 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove_abook_items($argv[1],$argv[2]);
|
||||
remove_abook_items($argv[1], $argv[2]);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,52 +2,52 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
|
||||
use Zotlabs\Lib\Libzot;
|
||||
use Zotlabs\Lib\Libzotdir;
|
||||
use Zotlabs\Lib\Queue;
|
||||
|
||||
class Directory
|
||||
{
|
||||
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
class Directory {
|
||||
if ($argc < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
$force = false;
|
||||
$pushall = true;
|
||||
|
||||
if ($argc < 2) {
|
||||
return;
|
||||
}
|
||||
if ($argc > 2) {
|
||||
if ($argv[2] === 'force') {
|
||||
$force = true;
|
||||
}
|
||||
if ($argv[2] === 'nopush') {
|
||||
$pushall = false;
|
||||
}
|
||||
}
|
||||
|
||||
$force = false;
|
||||
$pushall = true;
|
||||
|
||||
if ($argc > 2) {
|
||||
if ($argv[2] === 'force') {
|
||||
$force = true;
|
||||
}
|
||||
if ($argv[2] === 'nopush') {
|
||||
$pushall = false;
|
||||
}
|
||||
}
|
||||
logger('directory update', LOGGER_DEBUG);
|
||||
|
||||
logger('directory update', LOGGER_DEBUG);
|
||||
$channel = channelx_by_n($argv[1]);
|
||||
if (! $channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
$channel = channelx_by_n($argv[1]);
|
||||
if (! $channel) {
|
||||
return;
|
||||
}
|
||||
// update the local directory - was optional, but now done regardless
|
||||
|
||||
// update the local directory - was optional, but now done regardless
|
||||
|
||||
Libzotdir::local_dir_update($argv[1],$force);
|
||||
Libzotdir::local_dir_update($argv[1], $force);
|
||||
|
||||
q("update channel set channel_dirdate = '%s' where channel_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
q(
|
||||
"update channel set channel_dirdate = '%s' where channel_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
// Now update all the connections
|
||||
if ($pushall) {
|
||||
Run::Summon( [ 'Notifier','refresh_all',$channel['channel_id'] ] );
|
||||
}
|
||||
}
|
||||
// Now update all the connections
|
||||
if ($pushall) {
|
||||
Run::Summon([ 'Notifier','refresh_all',$channel['channel_id'] ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,90 +2,94 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Expire
|
||||
{
|
||||
|
||||
class Expire {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv){
|
||||
cli_startup();
|
||||
|
||||
cli_startup();
|
||||
// perform final cleanup on previously delete items
|
||||
|
||||
// perform final cleanup on previously delete items
|
||||
$r = q(
|
||||
"select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('10 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
drop_item($rr['id'], false, DROPITEM_PHASE2);
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('10 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
drop_item($rr['id'], false, DROPITEM_PHASE2);
|
||||
}
|
||||
}
|
||||
// physically remove anything that has been deleted for more than two months
|
||||
/** @FIXME - this is a wretchedly inefficient query */
|
||||
|
||||
// physically remove anything that has been deleted for more than two months
|
||||
/** @FIXME - this is a wretchedly inefficient query */
|
||||
$r = q(
|
||||
"delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('36 DAY')
|
||||
);
|
||||
|
||||
$r = q("delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('36 DAY')
|
||||
);
|
||||
logger('expire: start', LOGGER_DEBUG);
|
||||
|
||||
logger('expire: start', LOGGER_DEBUG);
|
||||
$site_expire = intval(get_config('system', 'default_expire_days'));
|
||||
$commented_days = intval(get_config('system', 'active_expire_days'));
|
||||
|
||||
$site_expire = intval(get_config('system', 'default_expire_days'));
|
||||
$commented_days = intval(get_config('system','active_expire_days'));
|
||||
logger('site_expire: ' . $site_expire);
|
||||
|
||||
logger('site_expire: ' . $site_expire);
|
||||
$r = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
|
||||
|
||||
$r = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
// expire the sys channel separately
|
||||
if (intval($rr['channel_system'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
// service class default (if non-zero) over-rides the site default
|
||||
|
||||
// expire the sys channel separately
|
||||
if (intval($rr['channel_system']))
|
||||
continue;
|
||||
$service_class_expire = service_class_fetch($rr['channel_id'], 'expire_days');
|
||||
if (intval($service_class_expire)) {
|
||||
$channel_expire = $service_class_expire;
|
||||
} else {
|
||||
$channel_expire = $site_expire;
|
||||
}
|
||||
|
||||
// service class default (if non-zero) over-rides the site default
|
||||
if (
|
||||
intval($channel_expire) && (intval($channel_expire) < intval($rr['channel_expire_days'])) ||
|
||||
intval($rr['channel_expire_days'] == 0)
|
||||
) {
|
||||
$expire_days = $channel_expire;
|
||||
} else {
|
||||
$expire_days = $rr['channel_expire_days'];
|
||||
}
|
||||
|
||||
$service_class_expire = service_class_fetch($rr['channel_id'], 'expire_days');
|
||||
if (intval($service_class_expire)) {
|
||||
$channel_expire = $service_class_expire;
|
||||
}
|
||||
else {
|
||||
$channel_expire = $site_expire;
|
||||
}
|
||||
|
||||
if (intval($channel_expire) && (intval($channel_expire) < intval($rr['channel_expire_days'])) ||
|
||||
intval($rr['channel_expire_days'] == 0)) {
|
||||
$expire_days = $channel_expire;
|
||||
}
|
||||
else {
|
||||
$expire_days = $rr['channel_expire_days'];
|
||||
}
|
||||
// if the site or service class expiration is non-zero and less than person expiration, use that
|
||||
logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG);
|
||||
item_expire($rr['channel_id'], $expire_days, $commented_days);
|
||||
}
|
||||
}
|
||||
|
||||
// if the site or service class expiration is non-zero and less than person expiration, use that
|
||||
logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG);
|
||||
item_expire($rr['channel_id'], $expire_days, $commented_days);
|
||||
}
|
||||
}
|
||||
$x = get_sys_channel();
|
||||
if ($x) {
|
||||
// this should probably just fetch the channel_expire_days from the sys channel,
|
||||
// but there's no convenient way to set it.
|
||||
|
||||
$x = get_sys_channel();
|
||||
if ($x) {
|
||||
$expire_days = get_config('system', 'sys_expire_days', 30);
|
||||
|
||||
// this should probably just fetch the channel_expire_days from the sys channel,
|
||||
// but there's no convenient way to set it.
|
||||
if (intval($site_expire) && (intval($site_expire) < intval($expire_days))) {
|
||||
$expire_days = $site_expire;
|
||||
}
|
||||
|
||||
$expire_days = get_config('system', 'sys_expire_days',30);
|
||||
logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
|
||||
|
||||
if (intval($site_expire) && (intval($site_expire) < intval($expire_days))) {
|
||||
$expire_days = $site_expire;
|
||||
}
|
||||
if ($expire_days) {
|
||||
item_expire($x['channel_id'], $expire_days, $commented_days);
|
||||
}
|
||||
|
||||
logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
|
||||
|
||||
if ($expire_days) {
|
||||
item_expire($x['channel_id'], $expire_days, $commented_days);
|
||||
}
|
||||
|
||||
logger('Expire: sys: done', LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
logger('Expire: sys: done', LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,43 +8,45 @@ require_once('include/cli_startup.php');
|
|||
require_once('include/attach.php');
|
||||
require_once('include/import.php');
|
||||
|
||||
class File_importer {
|
||||
class File_importer
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
cli_startup();
|
||||
cli_startup();
|
||||
|
||||
$attach_id = $argv[1];
|
||||
$channel_address = $argv[2];
|
||||
$hz_server = urldecode($argv[3]);
|
||||
$attach_id = $argv[1];
|
||||
$channel_address = $argv[2];
|
||||
$hz_server = urldecode($argv[3]);
|
||||
|
||||
$m = parse_url($hz_server);
|
||||
$m = parse_url($hz_server);
|
||||
|
||||
$channel = channelx_by_nick($channel_address);
|
||||
if(! $channel) {
|
||||
logger('filehelper: channel not found');
|
||||
killme();
|
||||
}
|
||||
$channel = channelx_by_nick($channel_address);
|
||||
if (! $channel) {
|
||||
logger('filehelper: channel not found');
|
||||
killme();
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'X-API-Token' => random_string(),
|
||||
'X-API-Request' => $hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
|
||||
'Host' => $m['host'],
|
||||
'(request-target)' => 'get /api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
|
||||
];
|
||||
$headers = [
|
||||
'X-API-Token' => random_string(),
|
||||
'X-API-Request' => $hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
|
||||
'Host' => $m['host'],
|
||||
'(request-target)' => 'get /api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
|
||||
];
|
||||
|
||||
$headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),true,'sha512');
|
||||
$x = z_fetch_url($hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,false,$redirects,[ 'headers' => $headers ]);
|
||||
$headers = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), true, 'sha512');
|
||||
$x = z_fetch_url($hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id, false, $redirects, [ 'headers' => $headers ]);
|
||||
|
||||
if(! $x['success']) {
|
||||
logger('no API response',LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
if (! $x['success']) {
|
||||
logger('no API response', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
$j = json_decode($x['body'],true);
|
||||
$j = json_decode($x['body'], true);
|
||||
|
||||
$r = sync_files($channel,[$j]);
|
||||
$r = sync_files($channel, [$j]);
|
||||
|
||||
killme();
|
||||
}
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
|
@ -8,49 +10,52 @@ use Zotlabs\Lib\Zotfinger;
|
|||
|
||||
// performs zot_finger on $argv[1], which is a hex_encoded webbie/reddress
|
||||
|
||||
class Gprobe {
|
||||
class Gprobe
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = hex2bin($argv[1]);
|
||||
$protocols = [];
|
||||
|
||||
if (! strpos($url,'@')) {
|
||||
return;
|
||||
}
|
||||
$url = hex2bin($argv[1]);
|
||||
$protocols = [];
|
||||
|
||||
$r = q("select * from hubloc where hubloc_addr = '%s'",
|
||||
dbesc($url)
|
||||
);
|
||||
if (! strpos($url, '@')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
if ($rv['hubloc_network'] === 'activitypub') {
|
||||
$protocols[] = 'activitypub';
|
||||
continue;
|
||||
}
|
||||
if ($rv['hubloc_network'] === 'zot6') {
|
||||
$protocols[] = 'zot6';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"select * from hubloc where hubloc_addr = '%s'",
|
||||
dbesc($url)
|
||||
);
|
||||
|
||||
if (! in_array('zot6',$protocols)) {
|
||||
$href = Webfinger::zot_url(punify($url));
|
||||
if ($href) {
|
||||
$zf = Zotfinger::exec($href,$channel);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
if ($rv['hubloc_network'] === 'activitypub') {
|
||||
$protocols[] = 'activitypub';
|
||||
continue;
|
||||
}
|
||||
if ($rv['hubloc_network'] === 'zot6') {
|
||||
$protocols[] = 'zot6';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (is_array($zf) && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid']) && isset($zf['data']) && $zf['data']) {
|
||||
$xc = Libzot::import_xchan($zf['data']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (! in_array('zot6', $protocols)) {
|
||||
$href = Webfinger::zot_url(punify($url));
|
||||
if ($href) {
|
||||
$zf = Zotfinger::exec($href, $channel);
|
||||
}
|
||||
if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid']) && isset($zf['data']) && $zf['data']) {
|
||||
$xc = Libzot::import_xchan($zf['data']);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,50 +2,50 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Importdoc
|
||||
{
|
||||
|
||||
class Importdoc {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
require_once('include/help.php');
|
||||
|
||||
require_once('include/help.php');
|
||||
self::update_docs_dir('doc/*');
|
||||
}
|
||||
|
||||
self::update_docs_dir('doc/*');
|
||||
|
||||
}
|
||||
|
||||
public static function update_docs_dir($s) {
|
||||
$f = basename($s);
|
||||
$d = dirname($s);
|
||||
if($s === 'doc/html')
|
||||
return;
|
||||
$files = glob("$d/$f");
|
||||
if($files) {
|
||||
foreach($files as $fi) {
|
||||
if($fi === 'doc/html') {
|
||||
continue;
|
||||
}
|
||||
if(is_dir($fi)) {
|
||||
self::update_docs_dir("$fi/*");
|
||||
}
|
||||
else {
|
||||
// don't update media content
|
||||
if(strpos(z_mime_content_type($fi),'text') === 0) {
|
||||
store_doc_file($fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove old files that weren't updated (indicates they were most likely deleted).
|
||||
$i = q("select * from item where item_type = 5 and edited < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('14 DAY')
|
||||
);
|
||||
if ($i) {
|
||||
foreach ($i as $iv) {
|
||||
drop_item($iv['id'],false,DROPITEM_NORMAL,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function update_docs_dir($s)
|
||||
{
|
||||
$f = basename($s);
|
||||
$d = dirname($s);
|
||||
if ($s === 'doc/html') {
|
||||
return;
|
||||
}
|
||||
$files = glob("$d/$f");
|
||||
if ($files) {
|
||||
foreach ($files as $fi) {
|
||||
if ($fi === 'doc/html') {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($fi)) {
|
||||
self::update_docs_dir("$fi/*");
|
||||
} else {
|
||||
// don't update media content
|
||||
if (strpos(z_mime_content_type($fi), 'text') === 0) {
|
||||
store_doc_file($fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove old files that weren't updated (indicates they were most likely deleted).
|
||||
$i = q(
|
||||
"select * from item where item_type = 5 and edited < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('14 DAY')
|
||||
);
|
||||
if ($i) {
|
||||
foreach ($i as $iv) {
|
||||
drop_item($iv['id'], false, DROPITEM_NORMAL, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,49 +1,57 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib\Libsync;
|
||||
|
||||
class Importfile {
|
||||
class Importfile
|
||||
{
|
||||
|
||||
public static function run($argc, $argv){
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
logger('Importfile: ' . print_r($argv,true));
|
||||
logger('Importfile: ' . print_r($argv, true));
|
||||
|
||||
if($argc < 3)
|
||||
return;
|
||||
if ($argc < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
$channel = channelx_by_n($argv[1]);
|
||||
if(! $channel)
|
||||
return;
|
||||
$channel = channelx_by_n($argv[1]);
|
||||
if (! $channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
$srcfile = $argv[2];
|
||||
$folder = (($argc > 3) ? $argv[3] : '');
|
||||
$dstname = (($argc > 4) ? $argv[4] : '');
|
||||
$srcfile = $argv[2];
|
||||
$folder = (($argc > 3) ? $argv[3] : '');
|
||||
$dstname = (($argc > 4) ? $argv[4] : '');
|
||||
|
||||
$hash = random_string();
|
||||
$hash = random_string();
|
||||
|
||||
$arr = [
|
||||
'src' => $srcfile,
|
||||
'filename' => (($dstname) ? $dstname : basename($srcfile)),
|
||||
'hash' => $hash,
|
||||
'allow_cid' => $channel['channel_allow_cid'],
|
||||
'allow_gid' => $channel['channel_allow_gid'],
|
||||
'deny_cid' => $channel['channel_deny_cid'],
|
||||
'deny_gid' => $channel['channel_deny_gid'],
|
||||
'preserve_original' => true,
|
||||
'replace' => true
|
||||
];
|
||||
$arr = [
|
||||
'src' => $srcfile,
|
||||
'filename' => (($dstname) ? $dstname : basename($srcfile)),
|
||||
'hash' => $hash,
|
||||
'allow_cid' => $channel['channel_allow_cid'],
|
||||
'allow_gid' => $channel['channel_allow_gid'],
|
||||
'deny_cid' => $channel['channel_deny_cid'],
|
||||
'deny_gid' => $channel['channel_deny_gid'],
|
||||
'preserve_original' => true,
|
||||
'replace' => true
|
||||
];
|
||||
|
||||
if($folder)
|
||||
$arr['folder'] = $folder;
|
||||
if ($folder) {
|
||||
$arr['folder'] = $folder;
|
||||
}
|
||||
|
||||
attach_store($channel,$channel['channel_hash'],'import',$arr);
|
||||
attach_store($channel, $channel['channel_hash'], 'import', $arr);
|
||||
|
||||
$sync = attach_export_data($channel,$hash);
|
||||
if($sync)
|
||||
Libsync::build_sync_packet($channel['channel_id'],array('file' => array($sync)));
|
||||
|
||||
return;
|
||||
}
|
||||
$sync = attach_export_data($channel, $hash);
|
||||
if ($sync) {
|
||||
Libsync::build_sync_packet($channel['channel_id'], array('file' => array($sync)));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,75 +1,87 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib\Libzotdir;
|
||||
|
||||
class Onedirsync
|
||||
{
|
||||
|
||||
class Onedirsync {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
logger('onedirsync: start ' . intval($argv[1]));
|
||||
|
||||
logger('onedirsync: start ' . intval($argv[1]));
|
||||
|
||||
if(($argc > 1) && (intval($argv[1])))
|
||||
$update_id = intval($argv[1]);
|
||||
if (($argc > 1) && (intval($argv[1]))) {
|
||||
$update_id = intval($argv[1]);
|
||||
}
|
||||
|
||||
if(! $update_id) {
|
||||
logger('onedirsync: no update');
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from updates where ud_id = %d limit 1",
|
||||
intval($update_id)
|
||||
);
|
||||
if (! $update_id) {
|
||||
logger('onedirsync: no update');
|
||||
return;
|
||||
}
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
if(($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr']))
|
||||
return;
|
||||
$r = q(
|
||||
"select * from updates where ud_id = %d limit 1",
|
||||
intval($update_id)
|
||||
);
|
||||
|
||||
// Have we probed this channel more recently than the other directory server
|
||||
// (where we received this update from) ?
|
||||
// If we have, we don't need to do anything except mark any older entries updated
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
if (($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1",
|
||||
dbesc($r[0]['ud_addr']),
|
||||
dbesc($r[0]['ud_date']),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
if($x) {
|
||||
$y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($r[0]['ud_addr']),
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($x[0]['ud_date'])
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Have we probed this channel more recently than the other directory server
|
||||
// (where we received this update from) ?
|
||||
// If we have, we don't need to do anything except mark any older entries updated
|
||||
|
||||
// ignore doing an update if this ud_addr refers to a known dead hubloc
|
||||
$x = q(
|
||||
"select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1",
|
||||
dbesc($r[0]['ud_addr']),
|
||||
dbesc($r[0]['ud_date']),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
if ($x) {
|
||||
$y = q(
|
||||
"update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($r[0]['ud_addr']),
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($x[0]['ud_date'])
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$h = q("select * from hubloc where hubloc_addr = '%s' limit 1",
|
||||
dbesc($r[0]['ud_addr'])
|
||||
);
|
||||
if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) {
|
||||
$y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($r[0]['ud_addr']),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
// ignore doing an update if this ud_addr refers to a known dead hubloc
|
||||
|
||||
return;
|
||||
}
|
||||
$h = q(
|
||||
"select * from hubloc where hubloc_addr = '%s' limit 1",
|
||||
dbesc($r[0]['ud_addr'])
|
||||
);
|
||||
if (($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) {
|
||||
$y = q(
|
||||
"update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($r[0]['ud_addr']),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
|
||||
// we might have to pull this out some day, but for now update_directory_entry()
|
||||
// runs zot_finger() and is kind of zot specific
|
||||
return;
|
||||
}
|
||||
|
||||
if($h && $h[0]['hubloc_network'] !== 'zot6')
|
||||
return;
|
||||
// we might have to pull this out some day, but for now update_directory_entry()
|
||||
// runs zot_finger() and is kind of zot specific
|
||||
|
||||
Libzotdir::update_directory_entry($r[0]);
|
||||
if ($h && $h[0]['hubloc_network'] !== 'zot6') {
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
Libzotdir::update_directory_entry($r[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
|
@ -7,164 +9,171 @@ use Zotlabs\Lib\ActivityStreams;
|
|||
use Zotlabs\Lib\Activity;
|
||||
use Zotlabs\Lib\ASCollection;
|
||||
|
||||
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
|
||||
class Onepoll {
|
||||
class Onepoll
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
logger('onepoll: start');
|
||||
|
||||
if(($argc > 1) && (intval($argv[1])))
|
||||
$contact_id = intval($argv[1]);
|
||||
logger('onepoll: start');
|
||||
|
||||
if(! $contact_id) {
|
||||
logger('onepoll: no contact');
|
||||
return;
|
||||
}
|
||||
if (($argc > 1) && (intval($argv[1]))) {
|
||||
$contact_id = intval($argv[1]);
|
||||
}
|
||||
|
||||
$d = datetime_convert();
|
||||
if (! $contact_id) {
|
||||
logger('onepoll: no contact');
|
||||
return;
|
||||
}
|
||||
|
||||
$contacts = q("SELECT abook.*, xchan.*, account.*
|
||||
$d = datetime_convert();
|
||||
|
||||
$contacts = q(
|
||||
"SELECT abook.*, xchan.*, account.*
|
||||
FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan
|
||||
where abook_id = %d
|
||||
and abook_pending = 0 and abook_archived = 0 and abook_blocked = 0 and abook_ignored = 0
|
||||
AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1",
|
||||
intval($contact_id),
|
||||
intval(ACCOUNT_OK),
|
||||
intval(ACCOUNT_UNVERIFIED)
|
||||
);
|
||||
intval($contact_id),
|
||||
intval(ACCOUNT_OK),
|
||||
intval(ACCOUNT_UNVERIFIED)
|
||||
);
|
||||
|
||||
if(! $contacts) {
|
||||
logger('onepoll: abook_id not found: ' . $contact_id);
|
||||
return;
|
||||
}
|
||||
if (! $contacts) {
|
||||
logger('onepoll: abook_id not found: ' . $contact_id);
|
||||
return;
|
||||
}
|
||||
|
||||
$contact = array_shift($contacts);
|
||||
$contact = array_shift($contacts);
|
||||
|
||||
$t = $contact['abook_updated'];
|
||||
$t = $contact['abook_updated'];
|
||||
|
||||
$importer_uid = $contact['abook_channel'];
|
||||
|
||||
$r = q("SELECT * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
|
||||
intval($importer_uid)
|
||||
);
|
||||
$importer_uid = $contact['abook_channel'];
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
$r = q(
|
||||
"SELECT * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
|
||||
intval($importer_uid)
|
||||
);
|
||||
|
||||
$importer = $r[0];
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
|
||||
$importer = $r[0];
|
||||
|
||||
$last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] <= NULL_DATE))
|
||||
? datetime_convert('UTC','UTC','now - 7 days')
|
||||
: datetime_convert('UTC','UTC',$contact['abook_updated'] . ' - 2 days')
|
||||
);
|
||||
logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
|
||||
|
||||
if($contact['xchan_network'] === 'zot6') {
|
||||
$last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] <= NULL_DATE))
|
||||
? datetime_convert('UTC', 'UTC', 'now - 7 days')
|
||||
: datetime_convert('UTC', 'UTC', $contact['abook_updated'] . ' - 2 days')
|
||||
);
|
||||
|
||||
// update permissions
|
||||
if ($contact['xchan_network'] === 'zot6') {
|
||||
// update permissions
|
||||
|
||||
$x = Libzot::refresh($contact,$importer);
|
||||
$x = Libzot::refresh($contact, $importer);
|
||||
|
||||
$responded = false;
|
||||
$updated = datetime_convert();
|
||||
$connected = datetime_convert();
|
||||
if(! $x) {
|
||||
// mark for death by not updating abook_connected, this is caught in include/poller.php
|
||||
q("update abook set abook_updated = '%s' where abook_id = %d",
|
||||
dbesc($updated),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
q("update abook set abook_updated = '%s', abook_connected = '%s' where abook_id = %d",
|
||||
dbesc($updated),
|
||||
dbesc($connected),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$responded = true;
|
||||
}
|
||||
$responded = false;
|
||||
$updated = datetime_convert();
|
||||
$connected = datetime_convert();
|
||||
if (! $x) {
|
||||
// mark for death by not updating abook_connected, this is caught in include/poller.php
|
||||
q(
|
||||
"update abook set abook_updated = '%s' where abook_id = %d",
|
||||
dbesc($updated),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
} else {
|
||||
q(
|
||||
"update abook set abook_updated = '%s', abook_connected = '%s' where abook_id = %d",
|
||||
dbesc($updated),
|
||||
dbesc($connected),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$responded = true;
|
||||
}
|
||||
|
||||
if (! $responded) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$fetch_feed = true;
|
||||
if (! $responded) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// They haven't given us permission to see their stream
|
||||
$fetch_feed = true;
|
||||
|
||||
$can_view_stream = intval(get_abconfig($importer_uid,$contact['abook_xchan'],'their_perms','view_stream'));
|
||||
// They haven't given us permission to see their stream
|
||||
|
||||
if (! $can_view_stream) {
|
||||
$fetch_feed = false;
|
||||
}
|
||||
$can_view_stream = intval(get_abconfig($importer_uid, $contact['abook_xchan'], 'their_perms', 'view_stream'));
|
||||
|
||||
// we haven't given them permission to send us their stream
|
||||
if (! $can_view_stream) {
|
||||
$fetch_feed = false;
|
||||
}
|
||||
|
||||
$can_send_stream = intval(get_abconfig($importer_uid,$contact['abook_xchan'],'my_perms','send_stream'));
|
||||
|
||||
if (! $can_send_stream) {
|
||||
$fetch_feed = false;
|
||||
}
|
||||
// we haven't given them permission to send us their stream
|
||||
|
||||
if ($contact['abook_created'] < datetime_convert('UTC','UTC', 'now - 1 week')) {
|
||||
$fetch_feed = false;
|
||||
}
|
||||
$can_send_stream = intval(get_abconfig($importer_uid, $contact['abook_xchan'], 'my_perms', 'send_stream'));
|
||||
|
||||
// In previous releases there was a mechanism to fetch 'external' or public stream posts from a site
|
||||
// (as opposed to a channel). This mechanism was deprecated as there is no reliable/scalable method
|
||||
// for informing downstream publishers when/if the content has expired or been deleted.
|
||||
// We can use the ThreadListener interface to implement this on the owner's outbox, however this is still a
|
||||
// work in progress and may present scaling issues. Making this work correctly with third-party fetches is
|
||||
// prohibitive as deletion requests would need to be relayed over potentially hostile networks.
|
||||
if (! $can_send_stream) {
|
||||
$fetch_feed = false;
|
||||
}
|
||||
|
||||
if($fetch_feed) {
|
||||
$max = intval(get_config('system','max_imported_posts',20));
|
||||
if (intval($max)) {
|
||||
$cl = get_xconfig($xchan,'activitypub','collections');
|
||||
if (is_array($cl) && $cl) {
|
||||
$url = ((array_key_exists('outbox',$cl)) ? $cl['outbox'] : '');
|
||||
if ($url) {
|
||||
logger('fetching outbox');
|
||||
$url = $url . '?date_begin=' . urlencode($last_update);
|
||||
$obj = new ASCollection($url, $importer, 0, $max);
|
||||
$messages = $obj->get();
|
||||
if ($messages) {
|
||||
foreach($messages as $message) {
|
||||
if (is_string($message)) {
|
||||
$message = Activity::fetch($message,$importer);
|
||||
}
|
||||
if (is_array($message)) {
|
||||
$AS = new ActivityStreams($message,null,true);
|
||||
if ($AS->is_valid() && is_array($AS->obj)) {
|
||||
$item = Activity::decode_note($AS,true);
|
||||
if ($item) {
|
||||
Activity::store($importer,$contact['abook_xchan'],$AS, $item, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($contact['abook_created'] < datetime_convert('UTC', 'UTC', 'now - 1 week')) {
|
||||
$fetch_feed = false;
|
||||
}
|
||||
|
||||
// update the poco details for this connection
|
||||
// In previous releases there was a mechanism to fetch 'external' or public stream posts from a site
|
||||
// (as opposed to a channel). This mechanism was deprecated as there is no reliable/scalable method
|
||||
// for informing downstream publishers when/if the content has expired or been deleted.
|
||||
// We can use the ThreadListener interface to implement this on the owner's outbox, however this is still a
|
||||
// work in progress and may present scaling issues. Making this work correctly with third-party fetches is
|
||||
// prohibitive as deletion requests would need to be relayed over potentially hostile networks.
|
||||
|
||||
$r = q("SELECT xlink_id from xlink
|
||||
if ($fetch_feed) {
|
||||
$max = intval(get_config('system', 'max_imported_posts', 20));
|
||||
if (intval($max)) {
|
||||
$cl = get_xconfig($xchan, 'activitypub', 'collections');
|
||||
if (is_array($cl) && $cl) {
|
||||
$url = ((array_key_exists('outbox', $cl)) ? $cl['outbox'] : '');
|
||||
if ($url) {
|
||||
logger('fetching outbox');
|
||||
$url = $url . '?date_begin=' . urlencode($last_update);
|
||||
$obj = new ASCollection($url, $importer, 0, $max);
|
||||
$messages = $obj->get();
|
||||
if ($messages) {
|
||||
foreach ($messages as $message) {
|
||||
if (is_string($message)) {
|
||||
$message = Activity::fetch($message, $importer);
|
||||
}
|
||||
if (is_array($message)) {
|
||||
$AS = new ActivityStreams($message, null, true);
|
||||
if ($AS->is_valid() && is_array($AS->obj)) {
|
||||
$item = Activity::decode_note($AS, true);
|
||||
if ($item) {
|
||||
Activity::store($importer, $contact['abook_xchan'], $AS, $item, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the poco details for this connection
|
||||
|
||||
$r = q(
|
||||
"SELECT xlink_id from xlink
|
||||
where xlink_xchan = '%s' and xlink_updated > %s - INTERVAL %s and xlink_static = 0 limit 1",
|
||||
intval($contact['xchan_hash']),
|
||||
db_utcnow(), db_quoteinterval('7 DAY')
|
||||
);
|
||||
if(! $r) {
|
||||
poco_load($contact['xchan_hash'],$contact['xchan_connurl']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
intval($contact['xchan_hash']),
|
||||
db_utcnow(),
|
||||
db_quoteinterval('7 DAY')
|
||||
);
|
||||
if (! $r) {
|
||||
poco_load($contact['xchan_hash'], $contact['xchan_connurl']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +1,90 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Poller {
|
||||
class Poller
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
if(function_exists('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
if(intval($load[0]) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$maxsysload = intval(get_config('system', 'maxloadavg'));
|
||||
if ($maxsysload < 1) {
|
||||
$maxsysload = 50;
|
||||
}
|
||||
if (function_exists('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
if (intval($load[0]) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$interval = intval(get_config('system','poll_interval'));
|
||||
if(! $interval)
|
||||
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
|
||||
$interval = intval(get_config('system', 'poll_interval'));
|
||||
if (! $interval) {
|
||||
$interval = ((get_config('system', 'delivery_interval') === false) ? 3 : intval(get_config('system', 'delivery_interval')));
|
||||
}
|
||||
|
||||
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
|
||||
$lockfile = 'cache/poller';
|
||||
if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
|
||||
&& (! get_config('system','override_poll_lockfile'))) {
|
||||
logger("poller: Already running");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a lockfile.
|
||||
file_put_contents($lockfile, EMPTY_STR);
|
||||
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
|
||||
$lockfile = 'cache/poller';
|
||||
if (
|
||||
(file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
|
||||
&& (! get_config('system', 'override_poll_lockfile'))
|
||||
) {
|
||||
logger("poller: Already running");
|
||||
return;
|
||||
}
|
||||
|
||||
logger('poller: start');
|
||||
|
||||
$manual_id = 0;
|
||||
$generation = 0;
|
||||
// Create a lockfile.
|
||||
file_put_contents($lockfile, EMPTY_STR);
|
||||
|
||||
$force = false;
|
||||
$restart = false;
|
||||
logger('poller: start');
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'force'))
|
||||
$force = true;
|
||||
$manual_id = 0;
|
||||
$generation = 0;
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if(! $generation)
|
||||
return;
|
||||
}
|
||||
$force = false;
|
||||
$restart = false;
|
||||
|
||||
if(($argc > 1) && intval($argv[1])) {
|
||||
$manual_id = intval($argv[1]);
|
||||
$force = true;
|
||||
}
|
||||
if (($argc > 1) && ($argv[1] == 'force')) {
|
||||
$force = true;
|
||||
}
|
||||
|
||||
if (($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if (! $generation) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (($argc > 1) && intval($argv[1])) {
|
||||
$manual_id = intval($argv[1]);
|
||||
$force = true;
|
||||
}
|
||||
|
||||
|
||||
$sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : "");
|
||||
$sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : "");
|
||||
|
||||
reload_plugins();
|
||||
reload_plugins();
|
||||
|
||||
$d = datetime_convert();
|
||||
$d = datetime_convert();
|
||||
|
||||
// Only poll from those with suitable relationships
|
||||
// Only poll from those with suitable relationships
|
||||
|
||||
// $abandon_sql = (($abandon_days)
|
||||
// ? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days).' DAY'))
|
||||
// : ''
|
||||
// );
|
||||
// $abandon_sql = (($abandon_days)
|
||||
// ? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days).' DAY'))
|
||||
// : ''
|
||||
// );
|
||||
|
||||
$abandon_sql = EMPTY_STR;
|
||||
|
||||
$randfunc = db_getfunc('RAND');
|
||||
|
||||
$contacts = q("SELECT abook.abook_updated, abook.abook_connected, abook.abook_feed,
|
||||
$abandon_sql = EMPTY_STR;
|
||||
|
||||
$randfunc = db_getfunc('RAND');
|
||||
|
||||
$contacts = q(
|
||||
"SELECT abook.abook_updated, abook.abook_connected, abook.abook_feed,
|
||||
abook.abook_channel, abook.abook_id, abook.abook_archived, abook.abook_pending,
|
||||
abook.abook_ignored, abook.abook_blocked,
|
||||
xchan.xchan_network,
|
||||
|
@ -83,109 +94,116 @@ class Poller {
|
|||
where abook_self = 0
|
||||
$sql_extra
|
||||
AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY $randfunc",
|
||||
intval(ACCOUNT_OK),
|
||||
intval(ACCOUNT_UNVERIFIED) // FIXME
|
||||
);
|
||||
intval(ACCOUNT_OK),
|
||||
intval(ACCOUNT_UNVERIFIED) // FIXME
|
||||
);
|
||||
|
||||
if($contacts) {
|
||||
if ($contacts) {
|
||||
foreach ($contacts as $contact) {
|
||||
$update = false;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$t = $contact['abook_updated'];
|
||||
$c = $contact['abook_connected'];
|
||||
|
||||
$update = false;
|
||||
|
||||
$t = $contact['abook_updated'];
|
||||
$c = $contact['abook_connected'];
|
||||
|
||||
if(intval($contact['abook_feed'])) {
|
||||
$min = service_class_fetch($contact['abook_channel'],'minimum_feedcheck_minutes');
|
||||
if(! $min)
|
||||
$min = intval(get_config('system','minimum_feedcheck_minutes'));
|
||||
if(! $min)
|
||||
$min = 60;
|
||||
$x = datetime_convert('UTC','UTC',"now - $min minutes");
|
||||
if($c < $x) {
|
||||
Run::Summon( [ 'Onepoll', $contact['abook_id'] ] );
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (intval($contact['abook_feed'])) {
|
||||
$min = service_class_fetch($contact['abook_channel'], 'minimum_feedcheck_minutes');
|
||||
if (! $min) {
|
||||
$min = intval(get_config('system', 'minimum_feedcheck_minutes'));
|
||||
}
|
||||
if (! $min) {
|
||||
$min = 60;
|
||||
}
|
||||
$x = datetime_convert('UTC', 'UTC', "now - $min minutes");
|
||||
if ($c < $x) {
|
||||
Run::Summon([ 'Onepoll', $contact['abook_id'] ]);
|
||||
if ($interval) {
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if($contact['xchan_network'] !== 'zot6')
|
||||
continue;
|
||||
if ($contact['xchan_network'] !== 'zot6') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($c == $t) {
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
|
||||
$update = true;
|
||||
}
|
||||
else {
|
||||
|
||||
// if we've never connected with them, start the mark for death countdown from now
|
||||
|
||||
if($c <= NULL_DATE) {
|
||||
$r = q("update abook set abook_connected = '%s' where abook_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$c = datetime_convert();
|
||||
$update = true;
|
||||
}
|
||||
if ($c == $t) {
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
|
||||
$update = true;
|
||||
}
|
||||
} else {
|
||||
// if we've never connected with them, start the mark for death countdown from now
|
||||
|
||||
// He's dead, Jim
|
||||
if ($c <= NULL_DATE) {
|
||||
$r = q(
|
||||
"update abook set abook_connected = '%s' where abook_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$c = datetime_convert();
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) {
|
||||
$r = q("update abook set abook_archived = 1 where abook_id = %d",
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$update = false;
|
||||
continue;
|
||||
}
|
||||
// He's dead, Jim
|
||||
|
||||
if(intval($contact['abook_archived'])) {
|
||||
$update = false;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 30 day")) > 0) {
|
||||
$r = q(
|
||||
"update abook set abook_archived = 1 where abook_id = %d",
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$update = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// might be dead, so maybe don't poll quite so often
|
||||
|
||||
// recently deceased, so keep up the regular schedule for 3 days
|
||||
|
||||
if((strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 3 day")) > 0)
|
||||
&& (strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 1 day")) > 0))
|
||||
$update = true;
|
||||
if (intval($contact['abook_archived'])) {
|
||||
$update = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// After that back off and put them on a morphine drip
|
||||
// might be dead, so maybe don't poll quite so often
|
||||
|
||||
if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) {
|
||||
$update = true;
|
||||
}
|
||||
// recently deceased, so keep up the regular schedule for 3 days
|
||||
|
||||
}
|
||||
if (
|
||||
(strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 3 day")) > 0)
|
||||
&& (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 1 day")) > 0)
|
||||
) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if(intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked']))
|
||||
continue;
|
||||
// After that back off and put them on a morphine drip
|
||||
|
||||
if((! $update) && (! $force))
|
||||
continue;
|
||||
if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 2 day")) > 0) {
|
||||
$update = true;
|
||||
}
|
||||
}
|
||||
|
||||
Run::Summon( [ 'Onepoll',$contact['abook_id'] ] );
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
if (intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if ((! $update) && (! $force)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// migrate a few photos - eventually we'll migrate them all but without killing somebody's site
|
||||
// trying to do them all at once
|
||||
|
||||
migrate_xchan_photos(5);
|
||||
Run::Summon([ 'Onepoll',$contact['abook_id'] ]);
|
||||
if ($interval) {
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_config('system','lastpoll',datetime_convert());
|
||||
// migrate a few photos - eventually we'll migrate them all but without killing somebody's site
|
||||
// trying to do them all at once
|
||||
|
||||
//All done - clear the lockfile
|
||||
@unlink($lockfile);
|
||||
migrate_xchan_photos(5);
|
||||
|
||||
return;
|
||||
}
|
||||
set_config('system', 'lastpoll', datetime_convert());
|
||||
|
||||
//All done - clear the lockfile
|
||||
@unlink($lockfile);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,82 +1,94 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib as Zlib;
|
||||
|
||||
class Queue
|
||||
{
|
||||
|
||||
class Queue {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
if ($argc > 1) {
|
||||
$queue_id = $argv[1];
|
||||
} else {
|
||||
$queue_id = EMPTY_STR;
|
||||
}
|
||||
|
||||
if($argc > 1)
|
||||
$queue_id = $argv[1];
|
||||
else
|
||||
$queue_id = EMPTY_STR;
|
||||
logger('queue: start');
|
||||
|
||||
logger('queue: start');
|
||||
// delete all queue items more than 3 days old
|
||||
// but first mark these sites dead if we haven't heard from them in a month
|
||||
|
||||
// delete all queue items more than 3 days old
|
||||
// but first mark these sites dead if we haven't heard from them in a month
|
||||
$r = q(
|
||||
"select outq_posturl from outq where outq_created < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('3 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$site_url = '';
|
||||
$h = parse_url($rr['outq_posturl']);
|
||||
$desturl = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
|
||||
q(
|
||||
"update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s",
|
||||
dbesc($desturl),
|
||||
db_utcnow(),
|
||||
db_quoteinterval('1 MONTH')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('3 DAY')
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$site_url = '';
|
||||
$h = parse_url($rr['outq_posturl']);
|
||||
$desturl = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
|
||||
q("update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s",
|
||||
dbesc($desturl),
|
||||
db_utcnow(), db_quoteinterval('1 MONTH')
|
||||
);
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('3 DAY')
|
||||
);
|
||||
|
||||
$r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('3 DAY')
|
||||
);
|
||||
if ($queue_id) {
|
||||
$r = q(
|
||||
"SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
|
||||
dbesc($queue_id)
|
||||
);
|
||||
} else {
|
||||
// For the first 12 hours we'll try to deliver every 15 minutes
|
||||
// After that, we'll only attempt delivery once per hour.
|
||||
// This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
|
||||
// so that we don't start off a thousand deliveries for a couple of dead hubs.
|
||||
// The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
|
||||
// Other drivers will have to do something different here and may need their own query.
|
||||
|
||||
if($queue_id) {
|
||||
$r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
|
||||
dbesc($queue_id)
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
// For the first 12 hours we'll try to deliver every 15 minutes
|
||||
// After that, we'll only attempt delivery once per hour.
|
||||
// This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
|
||||
// so that we don't start off a thousand deliveries for a couple of dead hubs.
|
||||
// The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
|
||||
// Other drivers will have to do something different here and may need their own query.
|
||||
|
||||
// Note: this requires some tweaking as new posts to long dead hubs once a day will keep them in the
|
||||
// "every 15 minutes" category. We probably need to prioritise them when inserted into the queue
|
||||
// or just prior to this query based on recent and long-term delivery history. If we have good reason to believe
|
||||
// the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
|
||||
// or twice a day.
|
||||
// Note: this requires some tweaking as new posts to long dead hubs once a day will keep them in the
|
||||
// "every 15 minutes" category. We probably need to prioritise them when inserted into the queue
|
||||
// or just prior to this query based on recent and long-term delivery history. If we have good reason to believe
|
||||
// the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
|
||||
// or twice a day.
|
||||
|
||||
$sqlrandfunc = db_getfunc('rand');
|
||||
|
||||
$r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
|
||||
db_utcnow()
|
||||
);
|
||||
while ($r) {
|
||||
foreach($r as $rv) {
|
||||
Zlib\Queue::deliver($rv);
|
||||
}
|
||||
$r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
|
||||
db_utcnow()
|
||||
);
|
||||
}
|
||||
}
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
foreach($r as $rv) {
|
||||
Zlib\Queue::deliver($rv);
|
||||
}
|
||||
}
|
||||
$r = q(
|
||||
"SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
|
||||
db_utcnow()
|
||||
);
|
||||
while ($r) {
|
||||
foreach ($r as $rv) {
|
||||
Zlib\Queue::deliver($rv);
|
||||
}
|
||||
$r = q(
|
||||
"SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
|
||||
db_utcnow()
|
||||
);
|
||||
}
|
||||
}
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r as $rv) {
|
||||
Zlib\Queue::deliver($rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,74 +2,76 @@
|
|||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
if (array_search( __file__ , get_included_files()) === 0) {
|
||||
if (array_search(__file__, get_included_files()) === 0) {
|
||||
require_once('include/cli_startup.php');
|
||||
array_shift($argv);
|
||||
$argc = count($argv);
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
array_shift($argv);
|
||||
$argc = count($argv);
|
||||
|
||||
if ($argc) {
|
||||
Run::Release($argc,$argv);
|
||||
}
|
||||
return;
|
||||
if ($argc) {
|
||||
Run::Release($argc, $argv);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Run {
|
||||
class Run
|
||||
{
|
||||
|
||||
// These processes should be ignored by addons which enforce timeouts (e.g. queueworker)
|
||||
// as it could result in corrupt data. Please add additional long running tasks to this list as they arise.
|
||||
// Ideally the queueworker should probably be provided an allow list rather than a deny list as it will be easier
|
||||
// to maintain. This was a quick hack to fix truncation of very large synced files when the queueworker addon is installed.
|
||||
|
||||
public static $long_running = [ 'Addon', 'Channel_purge', 'Checksites', 'Content_importer', 'Convo',
|
||||
'Cron', 'Cron_daily', 'Cron_weekly', 'Delxitems', 'Expire', 'File_importer', 'Importfile'
|
||||
];
|
||||
// These processes should be ignored by addons which enforce timeouts (e.g. queueworker)
|
||||
// as it could result in corrupt data. Please add additional long running tasks to this list as they arise.
|
||||
// Ideally the queueworker should probably be provided an allow list rather than a deny list as it will be easier
|
||||
// to maintain. This was a quick hack to fix truncation of very large synced files when the queueworker addon is installed.
|
||||
|
||||
public static function Summon($arr) {
|
||||
if (file_exists('maintenance_lock') || file_exists('cache/maintenance_lock')) {
|
||||
return;
|
||||
}
|
||||
public static $long_running = [ 'Addon', 'Channel_purge', 'Checksites', 'Content_importer', 'Convo',
|
||||
'Cron', 'Cron_daily', 'Cron_weekly', 'Delxitems', 'Expire', 'File_importer', 'Importfile'
|
||||
];
|
||||
|
||||
$hookinfo = [
|
||||
'argv' => $arr,
|
||||
'long_running' => self::$long_running
|
||||
];
|
||||
public static function Summon($arr)
|
||||
{
|
||||
if (file_exists('maintenance_lock') || file_exists('cache/maintenance_lock')) {
|
||||
return;
|
||||
}
|
||||
|
||||
call_hooks('daemon_summon', $hookinfo);
|
||||
$hookinfo = [
|
||||
'argv' => $arr,
|
||||
'long_running' => self::$long_running
|
||||
];
|
||||
|
||||
$arr = $hookinfo['argv'];
|
||||
$argc = count($arr);
|
||||
call_hooks('daemon_summon', $hookinfo);
|
||||
|
||||
if ((! is_array($arr) || ($argc < 1))) {
|
||||
logger("Summon handled by hook.", LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
$arr = $hookinfo['argv'];
|
||||
$argc = count($arr);
|
||||
|
||||
proc_run('php','Zotlabs/Daemon/Run.php',$arr);
|
||||
}
|
||||
if ((! is_array($arr) || ($argc < 1))) {
|
||||
logger("Summon handled by hook.", LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
public static function Release($argc, $argv) {
|
||||
cli_startup();
|
||||
proc_run('php', 'Zotlabs/Daemon/Run.php', $arr);
|
||||
}
|
||||
|
||||
$hookinfo = [
|
||||
'argv' => $argv,
|
||||
'long_running' => self::$long_running
|
||||
];
|
||||
public static function Release($argc, $argv)
|
||||
{
|
||||
cli_startup();
|
||||
|
||||
call_hooks('daemon_release', $hookinfo);
|
||||
$hookinfo = [
|
||||
'argv' => $argv,
|
||||
'long_running' => self::$long_running
|
||||
];
|
||||
|
||||
$argv = $hookinfo['argv'];
|
||||
$argc = count($argv);
|
||||
call_hooks('daemon_release', $hookinfo);
|
||||
|
||||
if ((! is_array($argv) || ($argc < 1))) {
|
||||
logger("Release handled by hook.", LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
$argv = $hookinfo['argv'];
|
||||
$argc = count($argv);
|
||||
|
||||
logger('Run: release: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
|
||||
$cls = '\\Zotlabs\\Daemon\\' . $argv[0];
|
||||
$cls::run($argc,$argv);
|
||||
}
|
||||
if ((! is_array($argv) || ($argc < 1))) {
|
||||
logger("Release handled by hook.", LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
logger('Run: release: ' . print_r($argv, true), LOGGER_ALL, LOG_DEBUG);
|
||||
$cls = '\\Zotlabs\\Daemon\\' . $argv[0];
|
||||
$cls::run($argc, $argv);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +1,85 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Thumbnail
|
||||
{
|
||||
|
||||
class Thumbnail {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
if (! ($argc == 2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! ($argc == 2)) {
|
||||
return;
|
||||
}
|
||||
$c = q(
|
||||
"select * from attach where hash = '%s' ",
|
||||
dbesc($argv[1])
|
||||
);
|
||||
|
||||
$c = q("select * from attach where hash = '%s' ",
|
||||
dbesc($argv[1])
|
||||
);
|
||||
if (! $c) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $c) {
|
||||
return;
|
||||
}
|
||||
$attach = $c[0];
|
||||
|
||||
$attach = $c[0];
|
||||
$preview_style = intval(get_config('system', 'thumbnail_security', 0));
|
||||
$preview_width = intval(get_config('system', 'thumbnail_width', 300));
|
||||
$preview_height = intval(get_config('system', 'thumbnail_height', 300));
|
||||
|
||||
$preview_style = intval(get_config('system','thumbnail_security',0));
|
||||
$preview_width = intval(get_config('system','thumbnail_width',300));
|
||||
$preview_height = intval(get_config('system','thumbnail_height',300));
|
||||
$p = [
|
||||
'attach' => $attach,
|
||||
'preview_style' => $preview_style,
|
||||
'preview_width' => $preview_width,
|
||||
'preview_height' => $preview_height,
|
||||
'thumbnail' => null
|
||||
];
|
||||
|
||||
$p = [
|
||||
'attach' => $attach,
|
||||
'preview_style' => $preview_style,
|
||||
'preview_width' => $preview_width,
|
||||
'preview_height' => $preview_height,
|
||||
'thumbnail' => null
|
||||
];
|
||||
/**
|
||||
* @hooks thumbnail
|
||||
* * \e array \b attach
|
||||
* * \e int \b preview_style
|
||||
* * \e int \b preview_width
|
||||
* * \e int \b preview_height
|
||||
* * \e string \b thumbnail
|
||||
*/
|
||||
|
||||
/**
|
||||
* @hooks thumbnail
|
||||
* * \e array \b attach
|
||||
* * \e int \b preview_style
|
||||
* * \e int \b preview_width
|
||||
* * \e int \b preview_height
|
||||
* * \e string \b thumbnail
|
||||
*/
|
||||
call_hooks('thumbnail', $p);
|
||||
if ($p['thumbnail']) {
|
||||
return;
|
||||
}
|
||||
|
||||
call_hooks('thumbnail',$p);
|
||||
if ($p['thumbnail']) {
|
||||
return;
|
||||
}
|
||||
$default_controller = null;
|
||||
|
||||
$default_controller = null;
|
||||
|
||||
$files = glob('Zotlabs/Thumbs/*.php');
|
||||
if ($files) {
|
||||
foreach ($files as $f) {
|
||||
$clsname = '\\Zotlabs\\Thumbs\\' . ucfirst(basename($f,'.php'));
|
||||
if (class_exists($clsname)) {
|
||||
$x = new $clsname();
|
||||
if (method_exists($x,'Match')) {
|
||||
$matched = $x->Match($attach['filetype']);
|
||||
if ($matched) {
|
||||
$x->Thumb($attach,$preview_style,$preview_width,$preview_height);
|
||||
}
|
||||
}
|
||||
if (method_exists($x,'MatchDefault')) {
|
||||
$default_matched = $x->MatchDefault(substr($attach['filetype'],0,strpos($attach['filetype'],'/')));
|
||||
if ($default_matched) {
|
||||
$default_controller = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (($default_controller)
|
||||
&& ((! file_exists(dbunescbin($attach['content']) . '.thumb'))
|
||||
|| (filectime(dbunescbin($attach['content']) . 'thumb') < (time() - 60)))) {
|
||||
$default_controller->Thumb($attach,$preview_style,$preview_width,$preview_height);
|
||||
}
|
||||
}
|
||||
$files = glob('Zotlabs/Thumbs/*.php');
|
||||
if ($files) {
|
||||
foreach ($files as $f) {
|
||||
$clsname = '\\Zotlabs\\Thumbs\\' . ucfirst(basename($f, '.php'));
|
||||
if (class_exists($clsname)) {
|
||||
$x = new $clsname();
|
||||
if (method_exists($x, 'Match')) {
|
||||
$matched = $x->Match($attach['filetype']);
|
||||
if ($matched) {
|
||||
$x->Thumb($attach, $preview_style, $preview_width, $preview_height);
|
||||
}
|
||||
}
|
||||
if (method_exists($x, 'MatchDefault')) {
|
||||
$default_matched = $x->MatchDefault(substr($attach['filetype'], 0, strpos($attach['filetype'], '/')));
|
||||
if ($default_matched) {
|
||||
$default_controller = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
($default_controller)
|
||||
&& ((! file_exists(dbunescbin($attach['content']) . '.thumb'))
|
||||
|| (filectime(dbunescbin($attach['content']) . 'thumb') < (time() - 60)))
|
||||
) {
|
||||
$default_controller->Thumb($attach, $preview_style, $preview_width, $preview_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,39 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
class Xchan_photo
|
||||
{
|
||||
|
||||
class Xchan_photo {
|
||||
public static function run($argc, $argv)
|
||||
{
|
||||
|
||||
public static function run($argc, $argv) {
|
||||
if ($argc != 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($argc != 3) {
|
||||
return;
|
||||
}
|
||||
$url = hex2bin($argv[1]);
|
||||
$xchan = hex2bin($argv[2]);
|
||||
|
||||
$url = hex2bin($argv[1]);
|
||||
$xchan = hex2bin($argv[2]);
|
||||
// Some photo sources hang after connect and aren't caught by curl timeout
|
||||
|
||||
// Some photo sources hang after connect and aren't caught by curl timeout
|
||||
set_time_limit(90);
|
||||
|
||||
set_time_limit(90);
|
||||
$photos = import_remote_xchan_photo($url, $xchan);
|
||||
if ($photos) {
|
||||
$r = q(
|
||||
"update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
|
||||
dbescdate(datetime_convert()),
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
dbesc($photos[3]),
|
||||
dbesc($xchan)
|
||||
);
|
||||
}
|
||||
|
||||
$photos = import_remote_xchan_photo($url,$xchan);
|
||||
if ($photos) {
|
||||
$r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
|
||||
dbescdate(datetime_convert()),
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
dbesc($photos[3]),
|
||||
dbesc($xchan)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,118 +8,129 @@ use App;
|
|||
* @brief Hook class.
|
||||
*
|
||||
*/
|
||||
class Hook {
|
||||
class Hook
|
||||
{
|
||||
|
||||
public static function register($hook, $file, $function, $version = 1, $priority = 0) {
|
||||
if (is_array($function)) {
|
||||
$function = serialize($function);
|
||||
}
|
||||
public static function register($hook, $file, $function, $version = 1, $priority = 0)
|
||||
{
|
||||
if (is_array($function)) {
|
||||
$function = serialize($function);
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s' and priority = %d and hook_version = %d LIMIT 1",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
intval($priority),
|
||||
intval($version)
|
||||
);
|
||||
if ($r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// To aid in upgrade and transition, remove old settings for any registered hooks that match in all respects except
|
||||
// for priority or hook_version
|
||||
$r = q(
|
||||
"SELECT * FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s' and priority = %d and hook_version = %d LIMIT 1",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
intval($priority),
|
||||
intval($version)
|
||||
);
|
||||
if ($r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$r = q("DELETE FROM hook where hook = '%s' and file = '%s' and fn = '%s'",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function)
|
||||
);
|
||||
// To aid in upgrade and transition, remove old settings for any registered hooks that match in all respects except
|
||||
// for priority or hook_version
|
||||
|
||||
$r = q("INSERT INTO hook (hook, file, fn, priority, hook_version) VALUES ( '%s', '%s', '%s', %d, %d )",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
intval($priority),
|
||||
intval($version)
|
||||
);
|
||||
$r = q(
|
||||
"DELETE FROM hook where hook = '%s' and file = '%s' and fn = '%s'",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
$r = q(
|
||||
"INSERT INTO hook (hook, file, fn, priority, hook_version) VALUES ( '%s', '%s', '%s', %d, %d )",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
intval($priority),
|
||||
intval($version)
|
||||
);
|
||||
|
||||
public static function register_array($file, $arr) {
|
||||
if ($arr) {
|
||||
foreach ($arr as $k => $v) {
|
||||
self::register($k,$file,$v);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
public static function register_array($file, $arr)
|
||||
{
|
||||
if ($arr) {
|
||||
foreach ($arr as $k => $v) {
|
||||
self::register($k, $file, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function unregister($hook, $file, $function, $version = 1, $priority = 0) {
|
||||
if (is_array($function)) {
|
||||
$function = serialize($function);
|
||||
}
|
||||
$r = q("DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s' and priority = %d and hook_version = %d",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
intval($priority),
|
||||
intval($version)
|
||||
);
|
||||
public static function unregister($hook, $file, $function, $version = 1, $priority = 0)
|
||||
{
|
||||
if (is_array($function)) {
|
||||
$function = serialize($function);
|
||||
}
|
||||
$r = q(
|
||||
"DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s' and priority = %d and hook_version = %d",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
intval($priority),
|
||||
intval($version)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister all hooks with this file component.
|
||||
*
|
||||
* Useful for addon upgrades where you want to clean out old interfaces.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
|
||||
public static function unregister_by_file($file) {
|
||||
$r = q("DELETE FROM hook WHERE file = '%s' ",
|
||||
dbesc($file)
|
||||
);
|
||||
/**
|
||||
* @brief Unregister all hooks with this file component.
|
||||
*
|
||||
* Useful for addon upgrades where you want to clean out old interfaces.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
|
||||
return $r;
|
||||
}
|
||||
public static function unregister_by_file($file)
|
||||
{
|
||||
$r = q(
|
||||
"DELETE FROM hook WHERE file = '%s' ",
|
||||
dbesc($file)
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Inserts a hook into a page request.
|
||||
*
|
||||
* Insert a short-lived hook into the running page request.
|
||||
* Hooks are normally persistent so that they can be called
|
||||
* across asynchronous processes such as delivery and poll
|
||||
* processes.
|
||||
*
|
||||
* insert_hook lets you attach a hook callback immediately
|
||||
* which will not persist beyond the life of this page request
|
||||
* or the current process.
|
||||
*
|
||||
* @param string $hook
|
||||
* name of hook to attach callback
|
||||
* @param string $fn
|
||||
* function name of callback handler
|
||||
* @param int $version
|
||||
* hook interface version, 0 uses two callback params, 1 uses one callback param
|
||||
* @param int $priority
|
||||
* currently not implemented in this function, would require the hook array to be resorted
|
||||
*/
|
||||
public static function insert($hook, $fn, $version = 0, $priority = 0) {
|
||||
if (is_array($fn)) {
|
||||
$fn = serialize($fn);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
if (! is_array(App::$hooks)) {
|
||||
App::$hooks = [];
|
||||
}
|
||||
/**
|
||||
* @brief Inserts a hook into a page request.
|
||||
*
|
||||
* Insert a short-lived hook into the running page request.
|
||||
* Hooks are normally persistent so that they can be called
|
||||
* across asynchronous processes such as delivery and poll
|
||||
* processes.
|
||||
*
|
||||
* insert_hook lets you attach a hook callback immediately
|
||||
* which will not persist beyond the life of this page request
|
||||
* or the current process.
|
||||
*
|
||||
* @param string $hook
|
||||
* name of hook to attach callback
|
||||
* @param string $fn
|
||||
* function name of callback handler
|
||||
* @param int $version
|
||||
* hook interface version, 0 uses two callback params, 1 uses one callback param
|
||||
* @param int $priority
|
||||
* currently not implemented in this function, would require the hook array to be resorted
|
||||
*/
|
||||
public static function insert($hook, $fn, $version = 0, $priority = 0)
|
||||
{
|
||||
if (is_array($fn)) {
|
||||
$fn = serialize($fn);
|
||||
}
|
||||
|
||||
if (! array_key_exists($hook, App::$hooks)) {
|
||||
App::$hooks[$hook] = [];
|
||||
}
|
||||
if (! is_array(App::$hooks)) {
|
||||
App::$hooks = [];
|
||||
}
|
||||
|
||||
App::$hooks[$hook][] = [ '', $fn, $priority, $version ];
|
||||
}
|
||||
}
|
||||
if (! array_key_exists($hook, App::$hooks)) {
|
||||
App::$hooks[$hook] = [];
|
||||
}
|
||||
|
||||
App::$hooks[$hook][] = [ '', $fn, $priority, $version ];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Extend;
|
||||
|
||||
|
||||
class Route
|
||||
{
|
||||
|
||||
|
@ -51,4 +50,3 @@ class Route
|
|||
return set_config('system', 'routes', $r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Extend;
|
||||
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
||||
|
|
|
@ -8,37 +8,38 @@ use OAuth2\Storage\Memory;
|
|||
use OAuth2\GrantType\ClientCredentials;
|
||||
use OAuth2\OpenID\GrantType\AuthorizationCode;
|
||||
|
||||
class OAuth2Server extends Server {
|
||||
class OAuth2Server extends Server
|
||||
{
|
||||
|
||||
public function __construct(OAuth2Storage $storage, $config = null) {
|
||||
public function __construct(OAuth2Storage $storage, $config = null)
|
||||
{
|
||||
|
||||
if (! is_array($config)) {
|
||||
$config = [
|
||||
// 'use_openid_connect' => true,
|
||||
'issuer' => System::get_site_name(),
|
||||
// 'use_jwt_access_tokens' => true,
|
||||
// 'enforce_state' => false
|
||||
];
|
||||
}
|
||||
if (! is_array($config)) {
|
||||
$config = [
|
||||
// 'use_openid_connect' => true,
|
||||
'issuer' => System::get_site_name(),
|
||||
// 'use_jwt_access_tokens' => true,
|
||||
// 'enforce_state' => false
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct($storage, $config);
|
||||
parent::__construct($storage, $config);
|
||||
|
||||
// Add the "Client Credentials" grant type (it is the simplest of the grant types)
|
||||
$this->addGrantType(new ClientCredentials($storage));
|
||||
// Add the "Client Credentials" grant type (it is the simplest of the grant types)
|
||||
$this->addGrantType(new ClientCredentials($storage));
|
||||
|
||||
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
|
||||
// Need to use OpenID\GrantType to return id_token
|
||||
// (see:https://github.com/bshaffer/oauth2-server-php/issues/443)
|
||||
$this->addGrantType(new AuthorizationCode($storage));
|
||||
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
|
||||
// Need to use OpenID\GrantType to return id_token
|
||||
// (see:https://github.com/bshaffer/oauth2-server-php/issues/443)
|
||||
$this->addGrantType(new AuthorizationCode($storage));
|
||||
|
||||
$keyStorage = new Memory( [
|
||||
'keys' => [
|
||||
'public_key' => get_config('system', 'pubkey'),
|
||||
'private_key' => get_config('system', 'prvkey')
|
||||
]
|
||||
]);
|
||||
|
||||
$this->addStorage($keyStorage, 'public_key');
|
||||
}
|
||||
$keyStorage = new Memory([
|
||||
'keys' => [
|
||||
'public_key' => get_config('system', 'pubkey'),
|
||||
'private_key' => get_config('system', 'prvkey')
|
||||
]
|
||||
]);
|
||||
|
||||
$this->addStorage($keyStorage, 'public_key');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace Zotlabs\Identity;
|
||||
|
||||
|
||||
use OAuth2\Storage\Pdo;
|
||||
|
||||
class OAuth2Storage extends Pdo {
|
||||
class OAuth2Storage extends Pdo
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
|
@ -40,9 +40,8 @@ class OAuth2Storage extends Pdo {
|
|||
protected function checkPassword($user, $password)
|
||||
{
|
||||
|
||||
$x = account_verify_password($user,$password);
|
||||
return((array_key_exists('channel',$x) && ! empty($x['channel'])) ? true : false);
|
||||
|
||||
$x = account_verify_password($user, $password);
|
||||
return((array_key_exists('channel', $x) && ! empty($x['channel'])) ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,77 +51,80 @@ class OAuth2Storage extends Pdo {
|
|||
public function getUser($username)
|
||||
{
|
||||
|
||||
$x = channelx_by_n($username);
|
||||
if (! $x) {
|
||||
return false;
|
||||
}
|
||||
$x = channelx_by_n($username);
|
||||
if (! $x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$a = q("select * from account where account_id = %d",
|
||||
intval($x['channel_account_id'])
|
||||
);
|
||||
$a = q(
|
||||
"select * from account where account_id = %d",
|
||||
intval($x['channel_account_id'])
|
||||
);
|
||||
|
||||
$n = explode(' ', $x['channel_name']);
|
||||
$n = explode(' ', $x['channel_name']);
|
||||
|
||||
return( [
|
||||
'webfinger' => channel_reddress($x),
|
||||
'portable_id' => $x['channel_hash'],
|
||||
'email' => $a[0]['account_email'],
|
||||
'username' => $x['channel_address'],
|
||||
'user_id' => $x['channel_id'],
|
||||
'name' => $x['channel_name'],
|
||||
'firstName' => ((count($n) > 1) ? $n[1] : $n[0]),
|
||||
'lastName' => ((count($n) > 2) ? $n[count($n) - 1] : ''),
|
||||
'picture' => $x['xchan_photo_l']
|
||||
] );
|
||||
return( [
|
||||
'webfinger' => channel_reddress($x),
|
||||
'portable_id' => $x['channel_hash'],
|
||||
'email' => $a[0]['account_email'],
|
||||
'username' => $x['channel_address'],
|
||||
'user_id' => $x['channel_id'],
|
||||
'name' => $x['channel_name'],
|
||||
'firstName' => ((count($n) > 1) ? $n[1] : $n[0]),
|
||||
'lastName' => ((count($n) > 2) ? $n[count($n) - 1] : ''),
|
||||
'picture' => $x['xchan_photo_l']
|
||||
] );
|
||||
}
|
||||
|
||||
public function scopeExists($scope) {
|
||||
public function scopeExists($scope)
|
||||
{
|
||||
// Report that the scope is valid even if it's not.
|
||||
// We will only return a very small subset no matter what.
|
||||
// @TODO: Truly validate the scope
|
||||
// see vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/ScopeInterface.php and
|
||||
// vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/Pdo.php
|
||||
// for more info.
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDefaultScope($client_id=null) {
|
||||
public function getDefaultScope($client_id = null)
|
||||
{
|
||||
// Do not REQUIRE a scope
|
||||
// see vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/ScopeInterface.php and
|
||||
// for more info.
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getUserClaims ($user_id, $claims) {
|
||||
// Populate the CLAIMS requested (if any).
|
||||
// @TODO: create a more reasonable/comprehensive list.
|
||||
// @TODO: present claims on the AUTHORIZATION screen
|
||||
public function getUserClaims($user_id, $claims)
|
||||
{
|
||||
// Populate the CLAIMS requested (if any).
|
||||
// @TODO: create a more reasonable/comprehensive list.
|
||||
// @TODO: present claims on the AUTHORIZATION screen
|
||||
|
||||
$userClaims = [];
|
||||
$claims = explode (' ', trim($claims));
|
||||
$claims = explode(' ', trim($claims));
|
||||
$validclaims = [ "name", "preferred_username", "webfinger", "portable_id", "email", "picture", "firstName", "lastName" ];
|
||||
$claimsmap = [
|
||||
"webfinger" => 'webfinger',
|
||||
"portable_id" => 'portable_id',
|
||||
"name" => 'name',
|
||||
"email" => 'email',
|
||||
"preferred_username" => 'username',
|
||||
"picture" => 'picture',
|
||||
"given_name" => 'firstName',
|
||||
"family_name" => 'lastName'
|
||||
];
|
||||
"webfinger" => 'webfinger',
|
||||
"portable_id" => 'portable_id',
|
||||
"name" => 'name',
|
||||
"email" => 'email',
|
||||
"preferred_username" => 'username',
|
||||
"picture" => 'picture',
|
||||
"given_name" => 'firstName',
|
||||
"family_name" => 'lastName'
|
||||
];
|
||||
$userinfo = $this->getUser($user_id);
|
||||
foreach ($validclaims as $validclaim) {
|
||||
if (in_array($validclaim,$claims)) {
|
||||
$claimkey = $claimsmap[$validclaim];
|
||||
$userClaims[$validclaim] = $userinfo[$claimkey];
|
||||
}
|
||||
else {
|
||||
$userClaims[$validclaim] = $validclaim;
|
||||
if (in_array($validclaim, $claims)) {
|
||||
$claimkey = $claimsmap[$validclaim];
|
||||
$userClaims[$validclaim] = $userinfo[$claimkey];
|
||||
} else {
|
||||
$userClaims[$validclaim] = $validclaim;
|
||||
}
|
||||
}
|
||||
$userClaims["sub"]=$user_id;
|
||||
return $userClaims;
|
||||
$userClaims["sub"] = $user_id;
|
||||
return $userClaims;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,5 +167,4 @@ class OAuth2Storage extends Pdo {
|
|||
// if grant_types are not defined, then none are restricted
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Import;
|
||||
|
||||
use App;
|
||||
|
@ -11,7 +12,6 @@ use Zotlabs\Access\PermissionRoles;
|
|||
use Zotlabs\Access\Permissions;
|
||||
use Zotlabs\Daemon\Run;
|
||||
|
||||
|
||||
class Friendica
|
||||
{
|
||||
|
||||
|
@ -56,7 +56,8 @@ class Friendica
|
|||
$max_identities = account_service_class_fetch($account_id, 'total_identities');
|
||||
|
||||
if ($max_identities !== false) {
|
||||
$r = q("select channel_id from channel where channel_account_id = %d and channel_removed = 0 ",
|
||||
$r = q(
|
||||
"select channel_id from channel where channel_account_id = %d and channel_removed = 0 ",
|
||||
intval($account_id)
|
||||
);
|
||||
if ($r && count($r) > $max_identities) {
|
||||
|
@ -225,12 +226,12 @@ class Friendica
|
|||
set_abconfig($newuid, $channel['channel_hash'], 'system', 'my_perms', $x);
|
||||
|
||||
if (intval($channel['channel_account_id'])) {
|
||||
|
||||
// Save our permissions role so we can perhaps call it up and modify it later.
|
||||
|
||||
if ($role_permissions) {
|
||||
if (array_key_exists('online', $role_permissions))
|
||||
if (array_key_exists('online', $role_permissions)) {
|
||||
set_pconfig($newuid, 'system', 'hide_presence', 1 - intval($role_permissions['online']));
|
||||
}
|
||||
if (array_key_exists('perms_auto', $role_permissions)) {
|
||||
$autoperms = intval($role_permissions['perms_auto']);
|
||||
set_pconfig($newuid, 'system', 'autoperms', $autoperms);
|
||||
|
@ -246,12 +247,14 @@ class Friendica
|
|||
// if our role_permissions indicate that we're using a default collection ACL, add it.
|
||||
|
||||
if (is_array($role_permissions) && $role_permissions['default_collection']) {
|
||||
$r = q("select hash from pgrp where uid = %d and gname = '%s' limit 1",
|
||||
$r = q(
|
||||
"select hash from pgrp where uid = %d and gname = '%s' limit 1",
|
||||
intval($newuid),
|
||||
dbesc(t('Friends'))
|
||||
);
|
||||
if ($r) {
|
||||
q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d",
|
||||
q(
|
||||
"update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d",
|
||||
dbesc($r[0]['hash']),
|
||||
dbesc('<' . $r[0]['hash'] . '>'),
|
||||
intval($newuid)
|
||||
|
@ -270,14 +273,14 @@ class Friendica
|
|||
|
||||
$accts = get_config('system', 'auto_follow');
|
||||
if (($accts) && (!$total_identities)) {
|
||||
if (!is_array($accts))
|
||||
if (!is_array($accts)) {
|
||||
$accts = array($accts);
|
||||
}
|
||||
|
||||
foreach ($accts as $acct) {
|
||||
if (trim($acct)) {
|
||||
$f = connect_and_sync($channel, trim($acct));
|
||||
if ($f['success']) {
|
||||
|
||||
$can_view_stream = their_perms_contains($channel['channel_id'], $f['abook']['abook_xchan'], 'view_stream');
|
||||
|
||||
// If we can view their stream, pull in some posts
|
||||
|
@ -357,8 +360,5 @@ class Friendica
|
|||
notice(t('Import complete.') . EOL);
|
||||
|
||||
goaway(z_root() . '/stream');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,22 +4,26 @@ namespace Zotlabs\Lib;
|
|||
|
||||
// account configuration storage is built on top of the under-utilised xconfig
|
||||
|
||||
class AConfig {
|
||||
class AConfig
|
||||
{
|
||||
|
||||
public static function Load($account_id) {
|
||||
return XConfig::Load('a_' . $account_id);
|
||||
}
|
||||
public static function Load($account_id)
|
||||
{
|
||||
return XConfig::Load('a_' . $account_id);
|
||||
}
|
||||
|
||||
public static function Get($account_id, $family, $key, $default = false) {
|
||||
return XConfig::Get('a_' . $account_id,$family,$key, $default);
|
||||
}
|
||||
public static function Get($account_id, $family, $key, $default = false)
|
||||
{
|
||||
return XConfig::Get('a_' . $account_id, $family, $key, $default);
|
||||
}
|
||||
|
||||
public static function Set($account_id, $family, $key, $value) {
|
||||
return XConfig::Set('a_' . $account_id,$family,$key,$value);
|
||||
}
|
||||
|
||||
public static function Delete($account_id, $family, $key) {
|
||||
return XConfig::Delete('a_' . $account_id,$family,$key);
|
||||
}
|
||||
public static function Set($account_id, $family, $key, $value)
|
||||
{
|
||||
return XConfig::Set('a_' . $account_id, $family, $key, $value);
|
||||
}
|
||||
|
||||
public static function Delete($account_id, $family, $key)
|
||||
{
|
||||
return XConfig::Delete('a_' . $account_id, $family, $key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use Zotlabs\Lib\Activity;
|
|||
* Class for dealing with fetching ActivityStreams collections (ordered or unordered, normal or paged).
|
||||
* Construct with either an existing object or url and an optional channel to sign requests.
|
||||
* $direction is 0 (default) to fetch from the beginning, and 1 to fetch from the end and reverse order the resultant array.
|
||||
* An optional limit to the number of records returned may also be specified.
|
||||
* An optional limit to the number of records returned may also be specified.
|
||||
* Use $class->get() to return an array of collection members.
|
||||
*/
|
||||
class ASCollection
|
||||
|
|
|
@ -2,74 +2,83 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
class AbConfig
|
||||
{
|
||||
|
||||
class AbConfig {
|
||||
|
||||
public static function Load($chan, $xhash, $family = '') {
|
||||
if($family)
|
||||
$where = sprintf(" and cat = '%s' ",dbesc($family));
|
||||
$r = q("select * from abconfig where chan = %d and xchan = '%s' $where",
|
||||
intval($chan),
|
||||
dbesc($xhash)
|
||||
);
|
||||
return $r;
|
||||
}
|
||||
public static function Load($chan, $xhash, $family = '')
|
||||
{
|
||||
if ($family) {
|
||||
$where = sprintf(" and cat = '%s' ", dbesc($family));
|
||||
}
|
||||
$r = q(
|
||||
"select * from abconfig where chan = %d and xchan = '%s' $where",
|
||||
intval($chan),
|
||||
dbesc($xhash)
|
||||
);
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
public static function Get($chan, $xhash, $family, $key, $default = false) {
|
||||
$r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
|
||||
intval($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if($r) {
|
||||
return unserialise($r[0]['v']);
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
public static function Get($chan, $xhash, $family, $key, $default = false)
|
||||
{
|
||||
$r = q(
|
||||
"select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
|
||||
intval($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if ($r) {
|
||||
return unserialise($r[0]['v']);
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
||||
public static function Set($chan, $xhash, $family, $key, $value) {
|
||||
public static function Set($chan, $xhash, $family, $key, $value)
|
||||
{
|
||||
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(self::Get($chan,$xhash,$family,$key) === false) {
|
||||
$r = q("insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
|
||||
intval($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
||||
dbesc($dbvalue),
|
||||
dbesc($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
if($r)
|
||||
return $value;
|
||||
return false;
|
||||
}
|
||||
if (self::Get($chan, $xhash, $family, $key) === false) {
|
||||
$r = q(
|
||||
"insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
|
||||
intval($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
} else {
|
||||
$r = q(
|
||||
"update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
||||
dbesc($dbvalue),
|
||||
dbesc($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
if ($r) {
|
||||
return $value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function Delete($chan, $xhash, $family, $key) {
|
||||
public static function Delete($chan, $xhash, $family, $key)
|
||||
{
|
||||
|
||||
$r = q("delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
||||
intval($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
$r = q(
|
||||
"delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
|
||||
intval($chan),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
use Zotlabs\Lib\Libsync;
|
||||
|
||||
|
||||
class AccessList
|
||||
{
|
||||
|
||||
|
@ -15,14 +14,14 @@ class AccessList
|
|||
if ($uid && $name) {
|
||||
$r = self::byname($uid, $name); // check for dups
|
||||
if ($r !== false) {
|
||||
|
||||
// This could be a problem.
|
||||
// Let's assume we've just created a list which we once deleted
|
||||
// all the old members are gone, but the list remains so we don't break any security
|
||||
// access lists. What we're doing here is reviving the dead list, but old content which
|
||||
// was restricted to this list may now be seen by the new list members.
|
||||
|
||||
$z = q("SELECT * FROM pgrp WHERE id = %d LIMIT 1",
|
||||
$z = q(
|
||||
"SELECT * FROM pgrp WHERE id = %d LIMIT 1",
|
||||
intval($r)
|
||||
);
|
||||
if (($z) && $z[0]['deleted']) {
|
||||
|
@ -35,7 +34,8 @@ class AccessList
|
|||
|
||||
$hash = new_uuid();
|
||||
|
||||
$r = q("INSERT INTO pgrp ( hash, uid, visible, gname, rule )
|
||||
$r = q(
|
||||
"INSERT INTO pgrp ( hash, uid, visible, gname, rule )
|
||||
VALUES( '%s', %d, %d, '%s', '' ) ",
|
||||
dbesc($hash),
|
||||
intval($uid),
|
||||
|
@ -55,7 +55,8 @@ class AccessList
|
|||
{
|
||||
$ret = false;
|
||||
if ($uid && $name) {
|
||||
$r = q("SELECT id, hash FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT id, hash FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
|
@ -67,7 +68,8 @@ class AccessList
|
|||
}
|
||||
|
||||
// remove group from default posting lists
|
||||
$r = q("SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if ($r) {
|
||||
|
@ -88,7 +90,8 @@ class AccessList
|
|||
}
|
||||
|
||||
if ($change) {
|
||||
q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s'
|
||||
q(
|
||||
"UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s'
|
||||
WHERE channel_id = %d",
|
||||
intval($user_info['channel_default_group']),
|
||||
dbesc($user_info['channel_allow_gid']),
|
||||
|
@ -99,19 +102,20 @@ class AccessList
|
|||
}
|
||||
|
||||
// remove all members
|
||||
$r = q("DELETE FROM pgrp_member WHERE uid = %d AND gid = %d ",
|
||||
$r = q(
|
||||
"DELETE FROM pgrp_member WHERE uid = %d AND gid = %d ",
|
||||
intval($uid),
|
||||
intval($group_id)
|
||||
);
|
||||
|
||||
// remove group
|
||||
$r = q("UPDATE pgrp SET deleted = 1 WHERE uid = %d AND gname = '%s'",
|
||||
$r = q(
|
||||
"UPDATE pgrp SET deleted = 1 WHERE uid = %d AND gname = '%s'",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
|
||||
$ret = $r;
|
||||
|
||||
}
|
||||
|
||||
Libsync::build_sync_packet($uid, null, true);
|
||||
|
@ -127,7 +131,8 @@ class AccessList
|
|||
if (!($uid && $name)) {
|
||||
return false;
|
||||
}
|
||||
$r = q("SELECT id FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT id FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
|
@ -143,7 +148,8 @@ class AccessList
|
|||
return false;
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM pgrp WHERE uid = %d AND id = %d and deleted = 0",
|
||||
$r = q(
|
||||
"SELECT * FROM pgrp WHERE uid = %d AND id = %d and deleted = 0",
|
||||
intval($uid),
|
||||
intval($id)
|
||||
);
|
||||
|
@ -159,7 +165,8 @@ class AccessList
|
|||
if (!($uid && $hash)) {
|
||||
return false;
|
||||
}
|
||||
$r = q("SELECT * FROM pgrp WHERE uid = %d AND hash = '%s' LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT * FROM pgrp WHERE uid = %d AND hash = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($hash)
|
||||
);
|
||||
|
@ -179,7 +186,8 @@ class AccessList
|
|||
if (!($uid && $gid && $member)) {
|
||||
return false;
|
||||
}
|
||||
$r = q("DELETE FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' ",
|
||||
$r = q(
|
||||
"DELETE FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' ",
|
||||
intval($uid),
|
||||
intval($gid),
|
||||
dbesc($member)
|
||||
|
@ -200,7 +208,8 @@ class AccessList
|
|||
return false;
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT * FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
intval($gid),
|
||||
dbesc($member)
|
||||
|
@ -210,7 +219,8 @@ class AccessList
|
|||
// we indicate success because the group member was in fact created
|
||||
// -- It was just created at another time
|
||||
} else {
|
||||
$r = q("INSERT INTO pgrp_member (uid, gid, xchan)
|
||||
$r = q(
|
||||
"INSERT INTO pgrp_member (uid, gid, xchan)
|
||||
VALUES( %d, %d, '%s' ) ",
|
||||
intval($uid),
|
||||
intval($gid),
|
||||
|
@ -246,13 +256,15 @@ class AccessList
|
|||
break;
|
||||
}
|
||||
if ($total) {
|
||||
$r = q("SELECT count(*) FROM abook left join xchan on xchan_hash = abook_xchan WHERE abook_channel = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 $sql_extra ORDER BY xchan_name ASC $pager_sql",
|
||||
$r = q(
|
||||
"SELECT count(*) FROM abook left join xchan on xchan_hash = abook_xchan WHERE abook_channel = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 $sql_extra ORDER BY xchan_name ASC $pager_sql",
|
||||
intval($uid)
|
||||
);
|
||||
return ($r) ? $r[0]['total'] : false;
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM abook left join xchan on xchan_hash = abook_xchan
|
||||
$r = q(
|
||||
"SELECT * FROM abook left join xchan on xchan_hash = abook_xchan
|
||||
WHERE abook_channel = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 $sql_extra ORDER BY xchan_name ASC $pager_sql",
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -266,7 +278,8 @@ class AccessList
|
|||
|
||||
if (intval($gid)) {
|
||||
if ($total) {
|
||||
$r = q("SELECT count(xchan) as total FROM pgrp_member
|
||||
$r = q(
|
||||
"SELECT count(xchan) as total FROM pgrp_member
|
||||
LEFT JOIN abook ON abook_xchan = pgrp_member.xchan left join xchan on xchan_hash = abook_xchan
|
||||
WHERE gid = %d AND abook_channel = %d and pgrp_member.uid = %d and xchan_deleted = 0 and abook_self = 0
|
||||
and abook_blocked = 0 and abook_pending = 0",
|
||||
|
@ -279,7 +292,8 @@ class AccessList
|
|||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM pgrp_member
|
||||
$r = q(
|
||||
"SELECT * FROM pgrp_member
|
||||
LEFT JOIN abook ON abook_xchan = pgrp_member.xchan left join xchan on xchan_hash = abook_xchan
|
||||
WHERE gid = %d AND abook_channel = %d and pgrp_member.uid = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 ORDER BY xchan_name ASC $pager_sql",
|
||||
intval($gid),
|
||||
|
@ -297,7 +311,8 @@ class AccessList
|
|||
{
|
||||
$ret = [];
|
||||
if (intval($gid)) {
|
||||
$r = q("SELECT xchan FROM pgrp_member WHERE gid = %d AND uid = %d",
|
||||
$r = q(
|
||||
"SELECT xchan FROM pgrp_member WHERE gid = %d AND uid = %d",
|
||||
intval($gid),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -315,7 +330,8 @@ class AccessList
|
|||
|
||||
$grps = [];
|
||||
|
||||
$r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
|
||||
$r = q(
|
||||
"SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
|
||||
intval($uid)
|
||||
);
|
||||
$grps[] = ['name' => '', 'hash' => '0', 'selected' => ''];
|
||||
|
@ -323,7 +339,6 @@ class AccessList
|
|||
foreach ($r as $rr) {
|
||||
$grps[] = ['name' => $rr['gname'], 'id' => $rr['hash'], 'selected' => (($group == $rr['hash']) ? 'true' : '')];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return replace_macros(get_markup_template('group_selection.tpl'), [
|
||||
|
@ -340,7 +355,8 @@ class AccessList
|
|||
|
||||
$groups = [];
|
||||
|
||||
$r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
|
||||
$r = q(
|
||||
"SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
|
||||
intval($_SESSION['uid'])
|
||||
);
|
||||
$member_of = [];
|
||||
|
@ -379,7 +395,6 @@ class AccessList
|
|||
'$groups' => $groups,
|
||||
'$add' => t('add'),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -393,7 +408,6 @@ class AccessList
|
|||
$x = [];
|
||||
|
||||
foreach ($g as $gv) {
|
||||
|
||||
// virtual access lists
|
||||
// connections:abc is all the connection sof the channel with channel_hash abc
|
||||
// zot:abc is all of abc's zot6 connections
|
||||
|
@ -408,12 +422,14 @@ class AccessList
|
|||
if (strpos($gv, 'activitypub:') === 0) {
|
||||
$sql_extra = " and xchan_network = 'activitypub' ";
|
||||
}
|
||||
$r = q("select channel_id from channel where channel_hash = '%s' ",
|
||||
$r = q(
|
||||
"select channel_id from channel where channel_hash = '%s' ",
|
||||
dbesc($channel_hash)
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
$y = q("select abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 $sql_extra",
|
||||
$y = q(
|
||||
"select abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 $sql_extra",
|
||||
intval($rv['channel_id'])
|
||||
);
|
||||
if ($y) {
|
||||
|
@ -438,7 +454,6 @@ class AccessList
|
|||
$ret[] = $rv['xchan'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
|
@ -447,7 +462,8 @@ class AccessList
|
|||
|
||||
public static function member_of($c)
|
||||
{
|
||||
$r = q("SELECT pgrp.gname, pgrp.id FROM pgrp LEFT JOIN pgrp_member ON pgrp_member.gid = pgrp.id
|
||||
$r = q(
|
||||
"SELECT pgrp.gname, pgrp.id FROM pgrp LEFT JOIN pgrp_member ON pgrp_member.gid = pgrp.id
|
||||
WHERE pgrp_member.xchan = '%s' AND pgrp.deleted = 0 ORDER BY pgrp.gname ASC ",
|
||||
dbesc($c)
|
||||
);
|
||||
|
@ -458,17 +474,19 @@ class AccessList
|
|||
public static function containing($uid, $c)
|
||||
{
|
||||
|
||||
$r = q("SELECT gid FROM pgrp_member WHERE uid = %d AND pgrp_member.xchan = '%s' ",
|
||||
$r = q(
|
||||
"SELECT gid FROM pgrp_member WHERE uid = %d AND pgrp_member.xchan = '%s' ",
|
||||
intval($uid),
|
||||
dbesc($c)
|
||||
);
|
||||
|
||||
$ret = [];
|
||||
if ($r) {
|
||||
foreach ($r as $rv)
|
||||
foreach ($r as $rv) {
|
||||
$ret[] = $rv['gid'];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
use Zotlabs\Lib\LDSignatures;
|
||||
|
@ -28,7 +29,6 @@ class ActivityPub
|
|||
$signed_msg = null;
|
||||
|
||||
if (array_key_exists('target_item', $arr) && is_array($arr['target_item'])) {
|
||||
|
||||
if (intval($arr['target_item']['item_obscured'])) {
|
||||
logger('Cannot send raw data as an activitypub activity.');
|
||||
return;
|
||||
|
@ -47,11 +47,9 @@ class ActivityPub
|
|||
logger('relayed post with no signed message');
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($purge_all) {
|
||||
|
||||
$ti = [
|
||||
'id' => channel_url($arr['channel']) . '?operation=delete',
|
||||
'actor' => channel_url($arr['channel']),
|
||||
|
@ -71,7 +69,6 @@ class ActivityPub
|
|||
logger('ActivityPub_encoded (purge_all): ' . json_encode($msg, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||
|
||||
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
} else {
|
||||
$target_item = $arr['target_item'];
|
||||
|
||||
|
@ -85,7 +82,6 @@ class ActivityPub
|
|||
if ($signed_msg) {
|
||||
$jmsg = $signed_msg;
|
||||
} else {
|
||||
|
||||
// Rewrite outbound mentions so they match the ActivityPub convention, which
|
||||
// is to pretend that the preferred display name doesn't exist and instead use
|
||||
// the username or webfinger address when displaying names. This is likely to
|
||||
|
@ -101,18 +97,18 @@ class ActivityPub
|
|||
return;
|
||||
}
|
||||
|
||||
// $token = IConfig::get($target_item['id'],'ocap','relay');
|
||||
// if ($token) {
|
||||
// if (defined('USE_BEARCAPS')) {
|
||||
// $ti['id'] = 'bear:?u=' . $ti['id'] . '&t=' . $token;
|
||||
// }
|
||||
// else {
|
||||
// $ti['id'] = $ti['id'] . '?token=' . $token;
|
||||
// }
|
||||
// if ($ti['url'] && is_string($ti['url'])) {
|
||||
// $ti['url'] .= '?token=' . $token;
|
||||
// }
|
||||
// }
|
||||
// $token = IConfig::get($target_item['id'],'ocap','relay');
|
||||
// if ($token) {
|
||||
// if (defined('USE_BEARCAPS')) {
|
||||
// $ti['id'] = 'bear:?u=' . $ti['id'] . '&t=' . $token;
|
||||
// }
|
||||
// else {
|
||||
// $ti['id'] = $ti['id'] . '?token=' . $token;
|
||||
// }
|
||||
// if ($ti['url'] && is_string($ti['url'])) {
|
||||
// $ti['url'] .= '?token=' . $token;
|
||||
// }
|
||||
// }
|
||||
|
||||
$msg = array_merge(['@context' => [
|
||||
ACTIVITYSTREAMS_JSONLD_REV,
|
||||
|
@ -136,7 +132,8 @@ class ActivityPub
|
|||
$hashes[] = "'" . $recip . "'";
|
||||
}
|
||||
|
||||
$r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s'
|
||||
$r = q(
|
||||
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s'
|
||||
and xchan_hash in (" . implode(',', $hashes) . ") and xchan_network = 'activitypub' ",
|
||||
dbesc($arr['hub']['hubloc_url'])
|
||||
);
|
||||
|
@ -147,7 +144,6 @@ class ActivityPub
|
|||
}
|
||||
|
||||
foreach ($r as $contact) {
|
||||
|
||||
// is $contact connected with this channel - and if the channel is cloned, also on this hub?
|
||||
// 2018-10-19 this probably doesn't apply to activitypub anymore, just send the thing.
|
||||
// They'll reject it if they don't like it.
|
||||
|
@ -163,9 +159,7 @@ class ActivityPub
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// public message
|
||||
|
||||
// See if we can deliver all of them at once
|
||||
|
@ -179,8 +173,8 @@ class ActivityPub
|
|||
$arr['queued'][] = $qi;
|
||||
}
|
||||
} else {
|
||||
|
||||
$r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' and xchan_network = 'activitypub' ",
|
||||
$r = q(
|
||||
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' and xchan_network = 'activitypub' ",
|
||||
dbesc($arr['hub']['hubloc_url'])
|
||||
);
|
||||
|
||||
|
@ -190,7 +184,6 @@ class ActivityPub
|
|||
}
|
||||
|
||||
foreach ($r as $contact) {
|
||||
|
||||
// $single = deliverable_singleton($arr['channel']['channel_id'],$contact);
|
||||
|
||||
$qi = self::queue_message($jmsg, $arr['channel'], $contact, $target_item['mid']);
|
||||
|
@ -202,7 +195,6 @@ class ActivityPub
|
|||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -233,7 +225,8 @@ class ActivityPub
|
|||
]);
|
||||
|
||||
if ($message_id && (!get_config('system', 'disable_dreport'))) {
|
||||
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue, dreport_log ) values ( '%s','%s','%s','%s','%s','%s','%s','%s' ) ",
|
||||
q(
|
||||
"insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue, dreport_log ) values ( '%s','%s','%s','%s','%s','%s','%s','%s' ) ",
|
||||
dbesc($message_id),
|
||||
dbesc($dest_url),
|
||||
dbesc($dest_url),
|
||||
|
@ -277,18 +270,20 @@ class ActivityPub
|
|||
$orig_follow = get_abconfig($x['sender']['channel_id'], $x['recipient']['xchan_hash'], 'activitypub', 'their_follow_id');
|
||||
$orig_follow_type = get_abconfig($x['sender']['channel_id'], $x['recipient']['xchan_hash'], 'activitypub', 'their_follow_type');
|
||||
|
||||
$msg = array_merge(['@context' => [
|
||||
$msg = array_merge(
|
||||
['@context' => [
|
||||
ACTIVITYSTREAMS_JSONLD_REV,
|
||||
'https://w3id.org/security/v1',
|
||||
Activity::ap_schema()
|
||||
]],
|
||||
]],
|
||||
[
|
||||
'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR),
|
||||
'type' => (($orig_follow_type) ? $orig_follow_type : 'Follow'),
|
||||
'actor' => $p,
|
||||
'object' => $x['recipient']['xchan_hash'],
|
||||
'to' => [$x['recipient']['xchan_hash']]
|
||||
]);
|
||||
]
|
||||
);
|
||||
|
||||
// for Group actors, send both a Follow and a Join because some platforms only support one and there's
|
||||
// no way of discovering/knowing in advance which type they support
|
||||
|
@ -305,7 +300,8 @@ class ActivityPub
|
|||
$msg['signature'] = LDSignatures::sign($msg, $x['sender']);
|
||||
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
|
||||
$h = q(
|
||||
"select * from hubloc where hubloc_hash = '%s' limit 1",
|
||||
dbesc($x['recipient']['xchan_hash'])
|
||||
);
|
||||
|
||||
|
@ -348,11 +344,12 @@ class ActivityPub
|
|||
return;
|
||||
}
|
||||
|
||||
$msg = array_merge(['@context' => [
|
||||
$msg = array_merge(
|
||||
['@context' => [
|
||||
ACTIVITYSTREAMS_JSONLD_REV,
|
||||
'https://w3id.org/security/v1',
|
||||
Activity::ap_schema()
|
||||
]],
|
||||
]],
|
||||
[
|
||||
'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . '/' . md5($accept),
|
||||
'type' => 'Accept',
|
||||
|
@ -364,13 +361,15 @@ class ActivityPub
|
|||
'object' => z_root() . '/channel/' . $x['sender']['channel_address']
|
||||
],
|
||||
'to' => [$x['recipient']['xchan_hash']]
|
||||
]);
|
||||
]
|
||||
);
|
||||
|
||||
$msg['signature'] = LDSignatures::sign($msg, $x['sender']);
|
||||
|
||||
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
|
||||
$h = q(
|
||||
"select * from hubloc where hubloc_hash = '%s' limit 1",
|
||||
dbesc($x['recipient']['xchan_hash'])
|
||||
);
|
||||
|
||||
|
@ -382,18 +381,19 @@ class ActivityPub
|
|||
}
|
||||
|
||||
$x['success'] = true;
|
||||
|
||||
}
|
||||
|
||||
public static function contact_remove($channel_id, $abook)
|
||||
{
|
||||
|
||||
$recip = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d",
|
||||
$recip = q(
|
||||
"select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d",
|
||||
intval($abook['abook_id'])
|
||||
);
|
||||
|
||||
if ((!$recip) || $recip[0]['xchan_network'] !== 'activitypub')
|
||||
if ((!$recip) || $recip[0]['xchan_network'] !== 'activitypub') {
|
||||
return;
|
||||
}
|
||||
|
||||
$channel = channelx_by_n($recip[0]['abook_channel']);
|
||||
if (!$channel) {
|
||||
|
@ -410,14 +410,14 @@ class ActivityPub
|
|||
$orig_activity = get_abconfig($recip[0]['abook_channel'], $recip[0]['xchan_hash'], 'activitypub', 'follow_id');
|
||||
|
||||
if ($orig_activity && $recip[0]['abook_pending']) {
|
||||
|
||||
// was never approved
|
||||
|
||||
$msg = array_merge(['@context' => [
|
||||
$msg = array_merge(
|
||||
['@context' => [
|
||||
ACTIVITYSTREAMS_JSONLD_REV,
|
||||
'https://w3id.org/security/v1',
|
||||
Activity::ap_schema()
|
||||
]],
|
||||
]],
|
||||
[
|
||||
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . '/' . md5($orig_activity) . '?operation=reject',
|
||||
'type' => 'Reject',
|
||||
|
@ -429,18 +429,18 @@ class ActivityPub
|
|||
'object' => $p
|
||||
],
|
||||
'to' => [$recip[0]['xchan_hash']]
|
||||
]);
|
||||
]
|
||||
);
|
||||
del_abconfig($recip[0]['abook_channel'], $recip[0]['xchan_hash'], 'activitypub', 'follow_id');
|
||||
|
||||
} else {
|
||||
|
||||
// send an unfollow
|
||||
|
||||
$msg = array_merge(['@context' => [
|
||||
$msg = array_merge(
|
||||
['@context' => [
|
||||
ACTIVITYSTREAMS_JSONLD_REV,
|
||||
'https://w3id.org/security/v1',
|
||||
Activity::ap_schema()
|
||||
]],
|
||||
]],
|
||||
[
|
||||
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR) . '?operation=unfollow',
|
||||
'type' => 'Undo',
|
||||
|
@ -452,14 +452,16 @@ class ActivityPub
|
|||
'object' => $recip[0]['xchan_hash']
|
||||
],
|
||||
'to' => [$recip[0]['xchan_hash']]
|
||||
]);
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$msg['signature'] = LDSignatures::sign($msg, $channel);
|
||||
|
||||
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
|
||||
$h = q(
|
||||
"select * from hubloc where hubloc_hash = '%s' limit 1",
|
||||
dbesc($recip[0]['xchan_hash'])
|
||||
);
|
||||
|
||||
|
@ -488,7 +490,6 @@ class ActivityPub
|
|||
}
|
||||
|
||||
if (isset($person_obj)) {
|
||||
|
||||
Activity::actor_store($person_obj['id'], $person_obj, $force);
|
||||
return $person_obj['id'];
|
||||
}
|
||||
|
@ -531,13 +532,15 @@ class ActivityPub
|
|||
if ($approvals) {
|
||||
foreach ($approvals as $approval) {
|
||||
if ($approval === $src_xchan) {
|
||||
$abooks = q("select abook_channel from abook where abook_xchan = '%s'",
|
||||
$abooks = q(
|
||||
"select abook_channel from abook where abook_xchan = '%s'",
|
||||
dbesc($src_xchan)
|
||||
);
|
||||
if ($abooks) {
|
||||
foreach ($abooks as $abook) {
|
||||
// check to see if we already performed this action
|
||||
$x = q("select * from abook where abook_xchan = '%s' and abook_channel = %d",
|
||||
$x = q(
|
||||
"select * from abook where abook_xchan = '%s' and abook_channel = %d",
|
||||
dbesc($dst_xchan),
|
||||
intval($abook['abook_channel'])
|
||||
);
|
||||
|
@ -545,23 +548,27 @@ class ActivityPub
|
|||
continue;
|
||||
}
|
||||
// update the local abook
|
||||
q("update abconfig set xchan = '%s' where chan = %d and xchan = '%s'",
|
||||
q(
|
||||
"update abconfig set xchan = '%s' where chan = %d and xchan = '%s'",
|
||||
dbesc($dst_xchan),
|
||||
intval($abook['abook_channel']),
|
||||
dbesc($src_xchan)
|
||||
);
|
||||
q("update pgrp_member set xchan = '%s' where uid = %d and xchan = '%s'",
|
||||
q(
|
||||
"update pgrp_member set xchan = '%s' where uid = %d and xchan = '%s'",
|
||||
dbesc($dst_xchan),
|
||||
intval($abook['abook_channel']),
|
||||
dbesc($src_xchan)
|
||||
);
|
||||
$r = q("update abook set abook_xchan = '%s' where abook_xchan = '%s' and abook_channel = %d ",
|
||||
$r = q(
|
||||
"update abook set abook_xchan = '%s' where abook_xchan = '%s' and abook_channel = %d ",
|
||||
dbesc($dst_xchan),
|
||||
dbesc($src_xchan),
|
||||
intval($abook['abook_channel'])
|
||||
);
|
||||
|
||||
$r = q("SELECT abook.*, xchan.*
|
||||
$r = q(
|
||||
"SELECT abook.*, xchan.*
|
||||
FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE abook_channel = %d and abook_id = %d LIMIT 1",
|
||||
intval(abook['abook_channel']),
|
||||
|
@ -584,5 +591,4 @@ class ActivityPub
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Zotlabs\Lib;
|
|||
|
||||
use Zotlabs\Web\HTTPSig;
|
||||
|
||||
|
||||
/**
|
||||
* @brief ActivityStreams class.
|
||||
*
|
||||
|
@ -57,7 +56,6 @@ class ActivityStreams
|
|||
}
|
||||
|
||||
if ($this->data) {
|
||||
|
||||
// verify and unpack JSalmon signature if present
|
||||
// This will only be the case for Zot6 packets
|
||||
|
||||
|
@ -90,7 +88,6 @@ class ActivityStreams
|
|||
$this->valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Attempt to assemble an Activity from what we were given.
|
||||
|
@ -108,8 +105,10 @@ class ActivityStreams
|
|||
$this->ldsig = $this->get_compound_property('signature');
|
||||
if ($this->ldsig) {
|
||||
$this->signer = $this->get_compound_property('creator', $this->ldsig);
|
||||
if ($this->signer && is_array($this->signer) && array_key_exists('publicKey', $this->signer)
|
||||
&& is_array($this->signer['publicKey']) && $this->signer['publicKey']['publicKeyPem']) {
|
||||
if (
|
||||
$this->signer && is_array($this->signer) && array_key_exists('publicKey', $this->signer)
|
||||
&& is_array($this->signer['publicKey']) && $this->signer['publicKey']['publicKeyPem']
|
||||
) {
|
||||
$this->sigok = LDSignatures::verify($this->data, $this->signer['publicKey']['publicKeyPem']);
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +198,7 @@ class ActivityStreams
|
|||
}
|
||||
|
||||
// not yet ready for prime time
|
||||
// $x = $this->expand($x,$base,$namespace);
|
||||
// $x = $this->expand($x,$base,$namespace);
|
||||
return $x;
|
||||
}
|
||||
|
||||
|
@ -472,4 +471,4 @@ class ActivityStreams
|
|||
|
||||
return (($x) ? true : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
||||
class Api_router
|
||||
{
|
||||
|
||||
|
@ -32,5 +31,4 @@ class Api_router
|
|||
{
|
||||
return self::$routes;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ class Apps
|
|||
call_hooks('get_system_apps', $ret);
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
public static function get_base_apps()
|
||||
|
@ -107,7 +106,8 @@ class Apps
|
|||
|
||||
self::$available_apps = q("select * from app where app_channel = 0");
|
||||
|
||||
self::$installed_apps = q("select * from app where app_channel = %d",
|
||||
self::$installed_apps = q(
|
||||
"select * from app where app_channel = %d",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
|
@ -130,7 +130,8 @@ class Apps
|
|||
}
|
||||
if ($id !== true) {
|
||||
// if we already installed this app, but it changed, preserve any categories we created
|
||||
$r = q("select term from term where otype = %d and oid = %d",
|
||||
$r = q(
|
||||
"select term from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($id)
|
||||
);
|
||||
|
@ -142,7 +143,6 @@ class Apps
|
|||
$app['guid'] = hash('whirlpool', $app['name']);
|
||||
$app['system'] = 1;
|
||||
self::app_install(local_channel(), $app);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,13 +161,17 @@ class Apps
|
|||
foreach (self::$available_apps as $iapp) {
|
||||
if ($iapp['app_id'] == hash('whirlpool', $app['name'])) {
|
||||
$notfound = false;
|
||||
if ((isset($app['version']) && $iapp['app_version'] !== $app['version'])
|
||||
|| ((isset($app['plugin']) && $app['plugin']) && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))) {
|
||||
if (
|
||||
(isset($app['version']) && $iapp['app_version'] !== $app['version'])
|
||||
|| ((isset($app['plugin']) && $app['plugin']) && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))
|
||||
) {
|
||||
return intval($iapp['app_id']);
|
||||
}
|
||||
|
||||
if (($iapp['app_url'] !== $app['url'])
|
||||
|| ($iapp['app_photo'] !== $app['photo'])) {
|
||||
if (
|
||||
($iapp['app_url'] !== $app['url'])
|
||||
|| ($iapp['app_photo'] !== $app['photo'])
|
||||
) {
|
||||
return intval($iapp['app_id']);
|
||||
}
|
||||
}
|
||||
|
@ -188,8 +192,10 @@ class Apps
|
|||
foreach (self::$installed_apps as $iapp) {
|
||||
if ($iapp['app_id'] == hash('whirlpool', $app['name'])) {
|
||||
$installed = true;
|
||||
if (($iapp['app_version'] != $app['version'])
|
||||
|| (isset($app['plugin']) && $app['plugin'] && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))) {
|
||||
if (
|
||||
($iapp['app_version'] != $app['version'])
|
||||
|| (isset($app['plugin']) && $app['plugin'] && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))
|
||||
) {
|
||||
return intval($iapp['app_id']);
|
||||
}
|
||||
}
|
||||
|
@ -629,7 +635,8 @@ class Apps
|
|||
{
|
||||
|
||||
if (!is_array($app)) {
|
||||
$r = q("select * from app where app_name = '%s' and app_channel = 0",
|
||||
$r = q(
|
||||
"select * from app where app_name = '%s' and app_channel = 0",
|
||||
dbesc($app)
|
||||
);
|
||||
if (!$r) {
|
||||
|
@ -648,14 +655,16 @@ class Apps
|
|||
}
|
||||
|
||||
if ($x['success']) {
|
||||
$r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$r = q(
|
||||
"select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($x['app_id']),
|
||||
intval($uid)
|
||||
);
|
||||
if ($r) {
|
||||
if (($app['uid']) && (!$r[0]['app_system'])) {
|
||||
if ($app['categories'] && (!$app['term'])) {
|
||||
$r[0]['term'] = q("select * from term where otype = %d and oid = %d",
|
||||
$r[0]['term'] = q(
|
||||
"select * from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($r[0]['id'])
|
||||
);
|
||||
|
@ -695,8 +704,8 @@ class Apps
|
|||
{
|
||||
|
||||
if ($uid && $app['guid']) {
|
||||
|
||||
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$x = q(
|
||||
"select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -704,17 +713,20 @@ class Apps
|
|||
if (!intval($x[0]['app_deleted'])) {
|
||||
$x[0]['app_deleted'] = 1;
|
||||
if (self::can_delete($uid, $app)) {
|
||||
$r = q("delete from app where app_id = '%s' and app_channel = %d",
|
||||
$r = q(
|
||||
"delete from app where app_id = '%s' and app_channel = %d",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
q("delete from term where otype = %d and oid = %d",
|
||||
q(
|
||||
"delete from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
call_hooks('app_destroy', $x[0]);
|
||||
} else {
|
||||
$r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
|
||||
$r = q(
|
||||
"update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -729,7 +741,6 @@ class Apps
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function app_undestroy($uid, $app)
|
||||
|
@ -738,14 +749,15 @@ class Apps
|
|||
// undelete a system app
|
||||
|
||||
if ($uid && $app['guid']) {
|
||||
|
||||
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$x = q(
|
||||
"select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
if ($x) {
|
||||
if ($x[0]['app_system']) {
|
||||
$r = q("update app set app_deleted = 0 where app_id = '%s' and app_channel = %d",
|
||||
$r = q(
|
||||
"update app set app_deleted = 0 where app_id = '%s' and app_channel = %d",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -756,19 +768,22 @@ class Apps
|
|||
|
||||
public static function app_feature($uid, $app, $term)
|
||||
{
|
||||
$r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$r = q(
|
||||
"select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
$x = q("select * from term where otype = %d and oid = %d and term = '%s' limit 1",
|
||||
$x = q(
|
||||
"select * from term where otype = %d and oid = %d and term = '%s' limit 1",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($r[0]['id']),
|
||||
dbesc($term)
|
||||
);
|
||||
|
||||
if ($x) {
|
||||
q("delete from term where otype = %d and oid = %d and term = '%s'",
|
||||
q(
|
||||
"delete from term where otype = %d and oid = %d and term = '%s'",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($x[0]['oid']),
|
||||
dbesc($term)
|
||||
|
@ -781,7 +796,8 @@ class Apps
|
|||
public static function app_installed($uid, $app, $bypass_filter = false)
|
||||
{
|
||||
|
||||
$r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$r = q(
|
||||
"select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc((array_key_exists('guid', $app)) ? $app['guid'] : ''),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -796,13 +812,13 @@ class Apps
|
|||
}
|
||||
|
||||
return (($r) ? true : false);
|
||||
|
||||
}
|
||||
|
||||
public static function addon_app_installed($uid, $app, $bypass_filter = false)
|
||||
{
|
||||
|
||||
$r = q("select id from app where app_plugin = '%s' and app_channel = %d limit 1",
|
||||
$r = q(
|
||||
"select id from app where app_plugin = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -817,13 +833,13 @@ class Apps
|
|||
}
|
||||
|
||||
return (($r) ? true : false);
|
||||
|
||||
}
|
||||
|
||||
public static function system_app_installed($uid, $app, $bypass_filter = false)
|
||||
{
|
||||
|
||||
$r = q("select id from app where app_id = '%s' and app_channel = %d and app_deleted = 0 limit 1",
|
||||
$r = q(
|
||||
"select id from app where app_id = '%s' and app_channel = %d and app_deleted = 0 limit 1",
|
||||
dbesc(hash('whirlpool', $app)),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -848,19 +864,20 @@ class Apps
|
|||
$sql_extra = " and app_deleted = 0 ";
|
||||
}
|
||||
if ($cats) {
|
||||
|
||||
$cat_sql_extra = " and ( ";
|
||||
|
||||
foreach ($cats as $cat) {
|
||||
if (strpos($cat_sql_extra, 'term'))
|
||||
if (strpos($cat_sql_extra, 'term')) {
|
||||
$cat_sql_extra .= "or ";
|
||||
}
|
||||
|
||||
$cat_sql_extra .= "term = '" . dbesc($cat) . "' ";
|
||||
}
|
||||
|
||||
$cat_sql_extra .= ") ";
|
||||
|
||||
$r = q("select oid from term where otype = %d $cat_sql_extra",
|
||||
$r = q(
|
||||
"select oid from term where otype = %d $cat_sql_extra",
|
||||
intval(TERM_OBJ_APP)
|
||||
);
|
||||
if (!$r) {
|
||||
|
@ -869,7 +886,8 @@ class Apps
|
|||
$sql_extra .= " and app.id in ( " . array_elm_to_str($r, 'oid') . ') ';
|
||||
}
|
||||
|
||||
$r = q("select * from app where app_channel = %d $sql_extra order by app_name asc",
|
||||
$r = q(
|
||||
"select * from app where app_channel = %d $sql_extra order by app_name asc",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -881,7 +899,8 @@ class Apps
|
|||
if (!$r[$x]['app_system']) {
|
||||
$r[$x]['type'] = 'personal';
|
||||
}
|
||||
$r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
|
||||
$r[$x]['term'] = q(
|
||||
"select * from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($r[$x]['id'])
|
||||
);
|
||||
|
@ -898,7 +917,8 @@ class Apps
|
|||
// not yet finished
|
||||
// somehow need to account for translations
|
||||
|
||||
$r = q("select * from app where app_channel = 0 $sql_extra order by app_name asc",
|
||||
$r = q(
|
||||
"select * from app where app_channel = 0 $sql_extra order by app_name asc",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -909,8 +929,9 @@ class Apps
|
|||
public static function app_order($uid, $apps, $menu)
|
||||
{
|
||||
|
||||
if (!$apps)
|
||||
if (!$apps) {
|
||||
return $apps;
|
||||
}
|
||||
|
||||
$conf = (($menu === 'nav_featured_app') ? 'app_order' : 'app_pin_order');
|
||||
|
||||
|
@ -938,7 +959,6 @@ class Apps
|
|||
}
|
||||
}
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
public static function find_app_in_array($name, $arr)
|
||||
|
@ -999,7 +1019,6 @@ class Apps
|
|||
}
|
||||
|
||||
set_pconfig($uid, 'system', $conf, implode(',', $narr));
|
||||
|
||||
}
|
||||
|
||||
public static function movedown($uid, $guid, $menu)
|
||||
|
@ -1047,7 +1066,6 @@ class Apps
|
|||
}
|
||||
|
||||
set_pconfig($uid, 'system', $conf, implode(',', $narr));
|
||||
|
||||
}
|
||||
|
||||
public static function app_decode($s)
|
||||
|
@ -1074,7 +1092,6 @@ class Apps
|
|||
|
||||
$arr['url'] = str_replace(array('$baseurl', '$nick'), array($baseurl, $address), $arr['url']);
|
||||
$arr['photo'] = str_replace(array('$baseurl', '$nick'), array($baseurl, $address), $arr['photo']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1128,7 +1145,8 @@ class Apps
|
|||
|
||||
$created = datetime_convert();
|
||||
|
||||
$r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_plugin, app_deleted, app_options ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )",
|
||||
$r = q(
|
||||
"insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_plugin, app_deleted, app_options ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )",
|
||||
dbesc($darray['app_id']),
|
||||
dbesc($darray['app_sig']),
|
||||
dbesc($darray['app_author']),
|
||||
|
@ -1156,7 +1174,8 @@ class Apps
|
|||
}
|
||||
|
||||
if ($arr['categories']) {
|
||||
$x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$x = q(
|
||||
"select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($darray['app_id']),
|
||||
intval($darray['app_channel'])
|
||||
);
|
||||
|
@ -1218,7 +1237,8 @@ class Apps
|
|||
|
||||
$edited = datetime_convert();
|
||||
|
||||
$r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_plugin = '%s', app_deleted = %d, app_options = %d where app_id = '%s' and app_channel = %d",
|
||||
$r = q(
|
||||
"update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_plugin = '%s', app_deleted = %d, app_options = %d where app_id = '%s' and app_channel = %d",
|
||||
dbesc($darray['app_sig']),
|
||||
dbesc($darray['app_author']),
|
||||
dbesc($darray['app_name']),
|
||||
|
@ -1243,18 +1263,21 @@ class Apps
|
|||
$ret['app_id'] = $darray['app_id'];
|
||||
}
|
||||
|
||||
$x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
$x = q(
|
||||
"select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($darray['app_id']),
|
||||
intval($darray['app_channel'])
|
||||
);
|
||||
|
||||
// if updating an embed app and we don't have a 0 channel_id don't mess with any existing categories
|
||||
|
||||
if (array_key_exists('embed', $arr) && intval($arr['embed']) && (intval($darray['app_channel'])))
|
||||
if (array_key_exists('embed', $arr) && intval($arr['embed']) && (intval($darray['app_channel']))) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if ($x) {
|
||||
q("delete from term where otype = %d and oid = %d",
|
||||
q(
|
||||
"delete from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
|
@ -1272,7 +1295,6 @@ class Apps
|
|||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1350,7 +1372,6 @@ class Apps
|
|||
|
||||
$j = json_encode($ret);
|
||||
return '[app]' . chunk_split(base64_encode($j), 72, "\n") . '[/app]';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1358,7 +1379,4 @@ class Apps
|
|||
{
|
||||
return chunk_split(base64_encode(json_encode($papp)), 72, "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,51 +1,63 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
/**
|
||||
* cache api
|
||||
*/
|
||||
|
||||
class Cache {
|
||||
public static function get($key) {
|
||||
/**
|
||||
* cache api
|
||||
*/
|
||||
|
||||
$hash = hash('whirlpool',$key);
|
||||
class Cache
|
||||
{
|
||||
public static function get($key)
|
||||
{
|
||||
|
||||
$r = q("SELECT v FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
|
||||
if ($r)
|
||||
return $r[0]['v'];
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function set($key,$value) {
|
||||
$hash = hash('whirlpool', $key);
|
||||
|
||||
$hash = hash('whirlpool',$key);
|
||||
$r = q(
|
||||
"SELECT v FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
|
||||
$r = q("SELECT * FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
if($r) {
|
||||
q("UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'",
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($hash));
|
||||
}
|
||||
else {
|
||||
q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')",
|
||||
dbesc($hash),
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()));
|
||||
}
|
||||
}
|
||||
if ($r) {
|
||||
return $r[0]['v'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function clear() {
|
||||
q("DELETE FROM cache WHERE updated < '%s'",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
|
||||
}
|
||||
|
||||
public static function set($key, $value)
|
||||
{
|
||||
|
||||
$hash = hash('whirlpool', $key);
|
||||
|
||||
$r = q(
|
||||
"SELECT * FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
if ($r) {
|
||||
q(
|
||||
"UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'",
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($hash)
|
||||
);
|
||||
} else {
|
||||
q(
|
||||
"INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')",
|
||||
dbesc($hash),
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function clear()
|
||||
{
|
||||
q(
|
||||
"DELETE FROM cache WHERE updated < '%s'",
|
||||
dbesc(datetime_convert('UTC', 'UTC', "now - 30 days"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
use Zotlabs\Lib\Libsync;
|
||||
|
@ -28,7 +29,8 @@ class Chatroom
|
|||
return $ret;
|
||||
}
|
||||
|
||||
$r = q("select cr_id from chatroom where cr_uid = %d and cr_name = '%s' limit 1",
|
||||
$r = q(
|
||||
"select cr_id from chatroom where cr_uid = %d and cr_name = '%s' limit 1",
|
||||
intval($channel['channel_id']),
|
||||
dbesc($name)
|
||||
);
|
||||
|
@ -37,23 +39,27 @@ class Chatroom
|
|||
return $ret;
|
||||
}
|
||||
|
||||
$r = q("select count(cr_id) as total from chatroom where cr_aid = %d",
|
||||
$r = q(
|
||||
"select count(cr_id) as total from chatroom where cr_aid = %d",
|
||||
intval($channel['channel_account_id'])
|
||||
);
|
||||
if ($r)
|
||||
if ($r) {
|
||||
$limit = service_class_fetch($channel['channel_id'], 'chatrooms');
|
||||
}
|
||||
|
||||
if (($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) {
|
||||
$ret['message'] = upgrade_message();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if (!array_key_exists('expire', $arr))
|
||||
if (!array_key_exists('expire', $arr)) {
|
||||
$arr['expire'] = 120; // minutes, e.g. 2 hours
|
||||
}
|
||||
|
||||
$created = datetime_convert();
|
||||
|
||||
$x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
$x = q(
|
||||
"insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
values ( %d, %d , '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s' ) ",
|
||||
intval($channel['channel_account_id']),
|
||||
intval($channel['channel_id']),
|
||||
|
@ -67,8 +73,9 @@ class Chatroom
|
|||
dbesc($arr['deny_gid'])
|
||||
);
|
||||
|
||||
if ($x)
|
||||
if ($x) {
|
||||
$ret['success'] = true;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
@ -79,16 +86,17 @@ class Chatroom
|
|||
|
||||
$ret = array('success' => false);
|
||||
|
||||
if (intval($arr['cr_id']))
|
||||
if (intval($arr['cr_id'])) {
|
||||
$sql_extra = " and cr_id = " . intval($arr['cr_id']) . " ";
|
||||
elseif (trim($arr['cr_name']))
|
||||
} elseif (trim($arr['cr_name'])) {
|
||||
$sql_extra = " and cr_name = '" . protect_sprintf(dbesc(trim($arr['cr_name']))) . "' ";
|
||||
else {
|
||||
} else {
|
||||
$ret['message'] = t('Invalid room specifier.');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1",
|
||||
$r = q(
|
||||
"select * from chatroom where cr_uid = %d $sql_extra limit 1",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if (!$r) {
|
||||
|
@ -98,14 +106,17 @@ class Chatroom
|
|||
|
||||
Libsync::build_sync_packet($channel['channel_id'], array('chatroom' => $r));
|
||||
|
||||
q("delete from chatroom where cr_id = %d",
|
||||
q(
|
||||
"delete from chatroom where cr_id = %d",
|
||||
intval($r[0]['cr_id'])
|
||||
);
|
||||
if ($r[0]['cr_id']) {
|
||||
q("delete from chatpresence where cp_room = %d",
|
||||
q(
|
||||
"delete from chatpresence where cp_room = %d",
|
||||
intval($r[0]['cr_id'])
|
||||
);
|
||||
q("delete from chat where chat_room = %d",
|
||||
q(
|
||||
"delete from chat where chat_room = %d",
|
||||
intval($r[0]['cr_id'])
|
||||
);
|
||||
}
|
||||
|
@ -118,10 +129,12 @@ class Chatroom
|
|||
public static function enter($observer_xchan, $room_id, $status, $client)
|
||||
{
|
||||
|
||||
if (!$room_id || !$observer_xchan)
|
||||
if (!$room_id || !$observer_xchan) {
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from chatroom where cr_id = %d limit 1",
|
||||
$r = q(
|
||||
"select * from chatroom where cr_id = %d limit 1",
|
||||
intval($room_id)
|
||||
);
|
||||
if (!$r) {
|
||||
|
@ -131,7 +144,8 @@ class Chatroom
|
|||
require_once('include/security.php');
|
||||
$sql_extra = permissions_sql($r[0]['cr_uid']);
|
||||
|
||||
$x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1",
|
||||
$x = q(
|
||||
"select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1",
|
||||
intval($room_id),
|
||||
intval($r[0]['cr_uid'])
|
||||
);
|
||||
|
@ -142,7 +156,8 @@ class Chatroom
|
|||
|
||||
$limit = service_class_fetch($r[0]['cr_uid'], 'chatters_inroom');
|
||||
if ($limit !== false) {
|
||||
$y = q("select count(*) as total from chatpresence where cp_room = %d",
|
||||
$y = q(
|
||||
"select count(*) as total from chatpresence where cp_room = %d",
|
||||
intval($room_id)
|
||||
);
|
||||
if ($y && $y[0]['total'] > $limit) {
|
||||
|
@ -152,19 +167,22 @@ class Chatroom
|
|||
}
|
||||
|
||||
if (intval($x[0]['cr_expire'])) {
|
||||
$r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d",
|
||||
$r = q(
|
||||
"delete from chat where created < %s - INTERVAL %s and chat_room = %d",
|
||||
db_utcnow(),
|
||||
db_quoteinterval(intval($x[0]['cr_expire']) . ' MINUTE'),
|
||||
intval($x[0]['cr_id'])
|
||||
);
|
||||
}
|
||||
|
||||
$r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
|
||||
$r = q(
|
||||
"select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
|
||||
dbesc($observer_xchan),
|
||||
intval($room_id)
|
||||
);
|
||||
if ($r) {
|
||||
q("update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'",
|
||||
q(
|
||||
"update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['cp_id']),
|
||||
dbesc($client)
|
||||
|
@ -172,7 +190,8 @@ class Chatroom
|
|||
return true;
|
||||
}
|
||||
|
||||
$r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client )
|
||||
$r = q(
|
||||
"insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client )
|
||||
values ( %d, '%s', '%s', '%s', '%s' )",
|
||||
intval($room_id),
|
||||
dbesc($observer_xchan),
|
||||
|
@ -187,16 +206,19 @@ class Chatroom
|
|||
|
||||
public function leave($observer_xchan, $room_id, $client)
|
||||
{
|
||||
if (!$room_id || !$observer_xchan)
|
||||
if (!$room_id || !$observer_xchan) {
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1",
|
||||
$r = q(
|
||||
"select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1",
|
||||
dbesc($observer_xchan),
|
||||
intval($room_id),
|
||||
dbesc($client)
|
||||
);
|
||||
if ($r) {
|
||||
q("delete from chatpresence where cp_id = %d",
|
||||
q(
|
||||
"delete from chatpresence where cp_id = %d",
|
||||
intval($r[0]['cp_id'])
|
||||
);
|
||||
}
|
||||
|
@ -210,7 +232,8 @@ class Chatroom
|
|||
require_once('include/security.php');
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name",
|
||||
$r = q(
|
||||
"select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -222,7 +245,8 @@ class Chatroom
|
|||
require_once('include/security.php');
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select count(*) as total from chatroom where cr_uid = %d $sql_extra",
|
||||
$r = q(
|
||||
"select count(*) as total from chatroom where cr_uid = %d $sql_extra",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -245,17 +269,20 @@ class Chatroom
|
|||
|
||||
$ret = array('success' => false);
|
||||
|
||||
if (!$text)
|
||||
if (!$text) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
|
||||
$r = q(
|
||||
"select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
|
||||
intval($uid),
|
||||
intval($room_id)
|
||||
);
|
||||
if (!$r)
|
||||
if (!$r) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'chat_room' => $room_id,
|
||||
|
@ -271,7 +298,8 @@ class Chatroom
|
|||
*/
|
||||
call_hooks('chat_message', $arr);
|
||||
|
||||
$x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
|
||||
$x = q(
|
||||
"insert into chat ( chat_room, chat_xchan, created, chat_text )
|
||||
values( %d, '%s', '%s', '%s' )",
|
||||
intval($room_id),
|
||||
dbesc($xchan),
|
||||
|
|
|
@ -2,163 +2,174 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
||||
use App;
|
||||
|
||||
class Config {
|
||||
class Config
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Loads the hub's configuration from database to a cached storage.
|
||||
*
|
||||
* Retrieve a category ($family) of config variables from database to a cached
|
||||
* storage in the global App::$config[$family].
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
*/
|
||||
public static function Load($family) {
|
||||
if(! array_key_exists($family, App::$config))
|
||||
App::$config[$family] = [];
|
||||
/**
|
||||
* @brief Loads the hub's configuration from database to a cached storage.
|
||||
*
|
||||
* Retrieve a category ($family) of config variables from database to a cached
|
||||
* storage in the global App::$config[$family].
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
*/
|
||||
public static function Load($family)
|
||||
{
|
||||
if (! array_key_exists($family, App::$config)) {
|
||||
App::$config[$family] = [];
|
||||
}
|
||||
|
||||
if(! array_key_exists('config_loaded', App::$config[$family])) {
|
||||
$r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
|
||||
if($r !== false) {
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
App::$config[$family][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
App::$config[$family]['config_loaded'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! array_key_exists('config_loaded', App::$config[$family])) {
|
||||
$r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
|
||||
if ($r !== false) {
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
App::$config[$family][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
App::$config[$family]['config_loaded'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for the hub.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key).
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param mixed $value
|
||||
* The value to store in the configuration
|
||||
* @return mixed
|
||||
* Return the set value, or false if the database update failed
|
||||
*/
|
||||
public static function Set($family, $key, $value) {
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
/**
|
||||
* @brief Sets a configuration value for the hub.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key).
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param mixed $value
|
||||
* The value to store in the configuration
|
||||
* @return mixed
|
||||
* Return the set value, or false if the database update failed
|
||||
*/
|
||||
public static function Set($family, $key, $value)
|
||||
{
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(self::Get($family, $key) === false || (! self::get_from_storage($family, $key))) {
|
||||
$ret = q("INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ",
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
if($ret) {
|
||||
App::$config[$family][$key] = $value;
|
||||
$ret = $value;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
if (self::Get($family, $key) === false || (! self::get_from_storage($family, $key))) {
|
||||
$ret = q(
|
||||
"INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ",
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
if ($ret) {
|
||||
App::$config[$family][$key] = $value;
|
||||
$ret = $value;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret = q("UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
$ret = q(
|
||||
"UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
if($ret) {
|
||||
App::$config[$family][$key] = $value;
|
||||
$ret = $value;
|
||||
}
|
||||
if ($ret) {
|
||||
App::$config[$family][$key] = $value;
|
||||
$ret = $value;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular config variable given the category name ($family)
|
||||
* and a key.
|
||||
*
|
||||
* Get a particular config variable from the given category ($family) and the
|
||||
* $key from a cached storage in App::$config[$family]. If a key is found in the
|
||||
* DB but does not exist in local config cache, pull it into the cache so we
|
||||
* do not have to hit the DB again for this item.
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param string $default (optional) default false
|
||||
* @return mixed Return value or false on error or if not set
|
||||
*/
|
||||
public static function Get($family, $key, $default = false) {
|
||||
if((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family])))
|
||||
self::Load($family);
|
||||
/**
|
||||
* @brief Get a particular config variable given the category name ($family)
|
||||
* and a key.
|
||||
*
|
||||
* Get a particular config variable from the given category ($family) and the
|
||||
* $key from a cached storage in App::$config[$family]. If a key is found in the
|
||||
* DB but does not exist in local config cache, pull it into the cache so we
|
||||
* do not have to hit the DB again for this item.
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param string $default (optional) default false
|
||||
* @return mixed Return value or false on error or if not set
|
||||
*/
|
||||
public static function Get($family, $key, $default = false)
|
||||
{
|
||||
if ((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family]))) {
|
||||
self::Load($family);
|
||||
}
|
||||
|
||||
if(array_key_exists('config_loaded', App::$config[$family])) {
|
||||
if(! array_key_exists($key, App::$config[$family])) {
|
||||
return $default;
|
||||
}
|
||||
return unserialise(App::$config[$family][$key]);
|
||||
}
|
||||
if (array_key_exists('config_loaded', App::$config[$family])) {
|
||||
if (! array_key_exists($key, App::$config[$family])) {
|
||||
return $default;
|
||||
}
|
||||
return unserialise(App::$config[$family][$key]);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the hub's configuration database.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$family]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function Delete($family, $key) {
|
||||
/**
|
||||
* @brief Deletes the given key from the hub's configuration database.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$family]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function Delete($family, $key)
|
||||
{
|
||||
|
||||
$ret = false;
|
||||
$ret = false;
|
||||
|
||||
if(array_key_exists($family, App::$config) && array_key_exists($key, App::$config[$family]))
|
||||
unset(App::$config[$family][$key]);
|
||||
if (array_key_exists($family, App::$config) && array_key_exists($key, App::$config[$family])) {
|
||||
unset(App::$config[$family][$key]);
|
||||
}
|
||||
|
||||
$ret = q("DELETE FROM config WHERE cat = '%s' AND k = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
$ret = q(
|
||||
"DELETE FROM config WHERE cat = '%s' AND k = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns a record directly from the database configuration storage.
|
||||
*
|
||||
* This function queries directly the database and bypasses the cached storage
|
||||
* from get_config($family, $key).
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @return mixed
|
||||
*/
|
||||
private static function get_from_storage($family, $key) {
|
||||
$ret = q("SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* @brief Returns a record directly from the database configuration storage.
|
||||
*
|
||||
* This function queries directly the database and bypasses the cached storage
|
||||
* from get_config($family, $key).
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @return mixed
|
||||
*/
|
||||
private static function get_from_storage($family, $key)
|
||||
{
|
||||
$ret = q(
|
||||
"SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
@ -6,7 +8,6 @@ use App;
|
|||
use Zotlabs\Access\Permissions;
|
||||
use Zotlabs\Daemon\Run;
|
||||
|
||||
|
||||
class Connect
|
||||
{
|
||||
|
||||
|
@ -57,7 +58,8 @@ class Connect
|
|||
|
||||
// check service class limits
|
||||
|
||||
$r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ",
|
||||
$r = q(
|
||||
"select count(*) as total from abook where abook_channel = %d and abook_self = 0 ",
|
||||
intval($uid)
|
||||
);
|
||||
if ($r) {
|
||||
|
@ -72,14 +74,14 @@ class Connect
|
|||
$xchan_hash = '';
|
||||
$sql_options = (($protocol) ? " and xchan_network = '" . dbesc($protocol) . "' " : '');
|
||||
|
||||
$r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s') $sql_options ",
|
||||
$r = q(
|
||||
"select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s') $sql_options ",
|
||||
dbesc($url),
|
||||
dbesc($url),
|
||||
dbesc($url)
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
|
||||
// reset results to the best record or the first if we don't have the best
|
||||
// note: this returns a single record and not an array of records
|
||||
|
||||
|
@ -88,7 +90,8 @@ class Connect
|
|||
// ensure there's a valid hubloc for this xchan before proceeding - you cannot connect without it
|
||||
|
||||
if (in_array($r['xchan_network'], ['zot6', 'activitypub'])) {
|
||||
$h = q("select * from hubloc where hubloc_hash = '%s'",
|
||||
$h = q(
|
||||
"select * from hubloc where hubloc_hash = '%s'",
|
||||
dbesc($r['xchan_hash'])
|
||||
);
|
||||
if (!$h) {
|
||||
|
@ -99,7 +102,6 @@ class Connect
|
|||
// we may have nulled out this record so check again
|
||||
|
||||
if ($r) {
|
||||
|
||||
// Check the site table to see if we should have a zot6 hubloc,
|
||||
// If so, clear the xchan and start fresh
|
||||
|
||||
|
@ -107,7 +109,8 @@ class Connect
|
|||
$m = parse_url($r['xchan_hash']);
|
||||
unset($m['path']);
|
||||
$h = unparse_url($m);
|
||||
$s = q("select * from site where site_url = '%s'",
|
||||
$s = q(
|
||||
"select * from site where site_url = '%s'",
|
||||
dbesc($h)
|
||||
);
|
||||
if (intval($s['site_type']) === SITE_TYPE_ZOT) {
|
||||
|
@ -122,7 +125,6 @@ class Connect
|
|||
$singleton = false;
|
||||
|
||||
if (!$r) {
|
||||
|
||||
// not in cache - try discovery
|
||||
|
||||
$wf = discover_by_webbie($url, $protocol, false);
|
||||
|
@ -134,10 +136,10 @@ class Connect
|
|||
}
|
||||
|
||||
if ($wf) {
|
||||
|
||||
// something was discovered - find the record which was just created.
|
||||
|
||||
$r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' ) $sql_options",
|
||||
$r = q(
|
||||
"select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' ) $sql_options",
|
||||
dbesc(($wf) ? $wf : $url),
|
||||
dbesc($url),
|
||||
dbesc($url)
|
||||
|
@ -170,7 +172,6 @@ class Connect
|
|||
$result['message'] = t('Channel is blocked on this site.');
|
||||
logger('follow: ' . $result['message']);
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,14 +213,14 @@ class Connect
|
|||
|
||||
// See if we are already connected by virtue of having an abook record
|
||||
|
||||
$r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook
|
||||
$r = q(
|
||||
"select abook_id, abook_xchan, abook_pending, abook_instance from abook
|
||||
where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
dbesc($xchan_hash),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
|
||||
$abook_instance = $r[0]['abook_instance'];
|
||||
|
||||
// If they are on a non-nomadic network, add them to this location
|
||||
|
@ -230,7 +231,8 @@ class Connect
|
|||
}
|
||||
$abook_instance .= z_root();
|
||||
|
||||
$x = q("update abook set abook_instance = '%s', abook_not_here = 0 where abook_id = %d",
|
||||
$x = q(
|
||||
"update abook set abook_instance = '%s', abook_not_here = 0 where abook_id = %d",
|
||||
dbesc($abook_instance),
|
||||
intval($r[0]['abook_id'])
|
||||
);
|
||||
|
@ -239,12 +241,12 @@ class Connect
|
|||
// if they have a pending connection, we just followed them so approve the connection request
|
||||
|
||||
if (intval($r[0]['abook_pending'])) {
|
||||
$x = q("update abook set abook_pending = 0 where abook_id = %d",
|
||||
$x = q(
|
||||
"update abook set abook_pending = 0 where abook_id = %d",
|
||||
intval($r[0]['abook_id'])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
// create a new abook record
|
||||
|
||||
$closeness = get_pconfig($uid, 'system', 'new_abook_closeness', 80);
|
||||
|
@ -278,7 +280,8 @@ class Connect
|
|||
|
||||
// fetch the entire record
|
||||
|
||||
$r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash
|
||||
$r = q(
|
||||
"select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash
|
||||
where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
dbesc($xchan_hash),
|
||||
intval($uid)
|
||||
|
@ -305,4 +308,4 @@ class Connect
|
|||
$result['success'] = true;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,210 +1,213 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
use Exception;
|
||||
|
||||
class Crypto {
|
||||
class Crypto
|
||||
{
|
||||
|
||||
public static $openssl_algorithms = [
|
||||
public static $openssl_algorithms = [
|
||||
|
||||
// zot6 nickname, opensslname, keylength, ivlength
|
||||
// zot6 nickname, opensslname, keylength, ivlength
|
||||
|
||||
[ 'aes256ctr', 'aes-256-ctr', 32, 16 ],
|
||||
[ 'camellia256cfb', 'camellia-256-cfb', 32, 16 ],
|
||||
[ 'cast5cfb', 'cast5-cfb', 16, 8 ]
|
||||
[ 'aes256ctr', 'aes-256-ctr', 32, 16 ],
|
||||
[ 'camellia256cfb', 'camellia-256-cfb', 32, 16 ],
|
||||
[ 'cast5cfb', 'cast5-cfb', 16, 8 ]
|
||||
|
||||
];
|
||||
];
|
||||
|
||||
|
||||
public static function methods() {
|
||||
$ret = [];
|
||||
public static function methods()
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
foreach(self::$openssl_algorithms as $ossl) {
|
||||
$ret[] = $ossl[0] . '.oaep';
|
||||
}
|
||||
foreach (self::$openssl_algorithms as $ossl) {
|
||||
$ret[] = $ossl[0] . '.oaep';
|
||||
}
|
||||
|
||||
call_hooks('crypto_methods',$ret);
|
||||
return $ret;
|
||||
}
|
||||
call_hooks('crypto_methods', $ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public static function signing_methods() {
|
||||
public static function signing_methods()
|
||||
{
|
||||
|
||||
$ret = [ 'sha256' ];
|
||||
call_hooks('signing_methods',$ret);
|
||||
return $ret;
|
||||
|
||||
}
|
||||
$ret = [ 'sha256' ];
|
||||
call_hooks('signing_methods', $ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public static function new_keypair($bits) {
|
||||
public static function new_keypair($bits)
|
||||
{
|
||||
|
||||
$openssl_options = [
|
||||
'digest_alg' => 'sha1',
|
||||
'private_key_bits' => $bits,
|
||||
'encrypt_key' => false
|
||||
];
|
||||
$openssl_options = [
|
||||
'digest_alg' => 'sha1',
|
||||
'private_key_bits' => $bits,
|
||||
'encrypt_key' => false
|
||||
];
|
||||
|
||||
$conf = get_config('system','openssl_conf_file');
|
||||
|
||||
if ($conf) {
|
||||
$openssl_options['config'] = $conf;
|
||||
}
|
||||
$conf = get_config('system', 'openssl_conf_file');
|
||||
|
||||
$result = openssl_pkey_new($openssl_options);
|
||||
if ($conf) {
|
||||
$openssl_options['config'] = $conf;
|
||||
}
|
||||
|
||||
if (empty($result)) {
|
||||
return false;
|
||||
}
|
||||
$result = openssl_pkey_new($openssl_options);
|
||||
|
||||
// Get private key
|
||||
if (empty($result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = [ 'prvkey' => '', 'pubkey' => '' ];
|
||||
// Get private key
|
||||
|
||||
openssl_pkey_export($result, $response['prvkey']);
|
||||
$response = [ 'prvkey' => '', 'pubkey' => '' ];
|
||||
|
||||
// Get public key
|
||||
$pkey = openssl_pkey_get_details($result);
|
||||
$response['pubkey'] = $pkey["key"];
|
||||
openssl_pkey_export($result, $response['prvkey']);
|
||||
|
||||
return $response;
|
||||
// Get public key
|
||||
$pkey = openssl_pkey_get_details($result);
|
||||
$response['pubkey'] = $pkey["key"];
|
||||
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public static function sign($data, $key, $alg = 'sha256') {
|
||||
public static function sign($data, $key, $alg = 'sha256')
|
||||
{
|
||||
|
||||
if (! $key) {
|
||||
return false;
|
||||
}
|
||||
if (! $key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sig = '';
|
||||
openssl_sign($data,$sig,$key,$alg);
|
||||
return $sig;
|
||||
}
|
||||
$sig = '';
|
||||
openssl_sign($data, $sig, $key, $alg);
|
||||
return $sig;
|
||||
}
|
||||
|
||||
|
||||
public static function verify($data, $sig, $key, $alg = 'sha256') {
|
||||
public static function verify($data, $sig, $key, $alg = 'sha256')
|
||||
{
|
||||
|
||||
if (! $key) {
|
||||
return false;
|
||||
}
|
||||
if (! $key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$verify = openssl_verify($data,$sig,$key,$alg);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$verify = (-1);
|
||||
}
|
||||
try {
|
||||
$verify = openssl_verify($data, $sig, $key, $alg);
|
||||
} catch (Exception $e) {
|
||||
$verify = (-1);
|
||||
}
|
||||
|
||||
if ($verify === (-1)) {
|
||||
while ($msg = openssl_error_string()) {
|
||||
logger('openssl_verify: ' . $msg,LOGGER_NORMAL,LOG_ERR);
|
||||
}
|
||||
btlogger('openssl_verify: key: ' . $key, LOGGER_DEBUG, LOG_ERR);
|
||||
}
|
||||
if ($verify === (-1)) {
|
||||
while ($msg = openssl_error_string()) {
|
||||
logger('openssl_verify: ' . $msg, LOGGER_NORMAL, LOG_ERR);
|
||||
}
|
||||
btlogger('openssl_verify: key: ' . $key, LOGGER_DEBUG, LOG_ERR);
|
||||
}
|
||||
|
||||
return (($verify > 0) ? true : false);
|
||||
}
|
||||
return (($verify > 0) ? true : false);
|
||||
}
|
||||
|
||||
public static function encapsulate($data, $pubkey, $alg) {
|
||||
public static function encapsulate($data, $pubkey, $alg)
|
||||
{
|
||||
|
||||
if (! ($alg && $pubkey)) {
|
||||
return $data;
|
||||
}
|
||||
if (! ($alg && $pubkey)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$alg_base = $alg;
|
||||
$padding = OPENSSL_PKCS1_PADDING;
|
||||
$alg_base = $alg;
|
||||
$padding = OPENSSL_PKCS1_PADDING;
|
||||
|
||||
$exts = explode('.',$alg);
|
||||
if (count($exts) > 1) {
|
||||
switch ($exts[1]) {
|
||||
case 'oaep':
|
||||
$padding = OPENSSL_PKCS1_OAEP_PADDING;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$alg_base = $exts[0];
|
||||
}
|
||||
$exts = explode('.', $alg);
|
||||
if (count($exts) > 1) {
|
||||
switch ($exts[1]) {
|
||||
case 'oaep':
|
||||
$padding = OPENSSL_PKCS1_OAEP_PADDING;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$alg_base = $exts[0];
|
||||
}
|
||||
|
||||
$method = null;
|
||||
$method = null;
|
||||
|
||||
foreach (self::$openssl_algorithms as $ossl) {
|
||||
if ($ossl[0] === $alg_base) {
|
||||
$method = $ossl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (self::$openssl_algorithms as $ossl) {
|
||||
if ($ossl[0] === $alg_base) {
|
||||
$method = $ossl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($method) {
|
||||
$result = [ 'encrypted' => true ];
|
||||
if ($method) {
|
||||
$result = [ 'encrypted' => true ];
|
||||
|
||||
$key = openssl_random_pseudo_bytes(256);
|
||||
$iv = openssl_random_pseudo_bytes(256);
|
||||
$key = openssl_random_pseudo_bytes(256);
|
||||
$iv = openssl_random_pseudo_bytes(256);
|
||||
|
||||
$key1 = substr($key, 0, $method[2]);
|
||||
$iv1 = substr($iv, 0, $method[3]);
|
||||
$key1 = substr($key, 0, $method[2]);
|
||||
$iv1 = substr($iv, 0, $method[3]);
|
||||
|
||||
$result['data'] = base64url_encode(openssl_encrypt($data,$method[1],$key1,OPENSSL_RAW_DATA,$iv1),true);
|
||||
$result['data'] = base64url_encode(openssl_encrypt($data, $method[1], $key1, OPENSSL_RAW_DATA, $iv1), true);
|
||||
|
||||
openssl_public_encrypt($key, $k, $pubkey, $padding);
|
||||
openssl_public_encrypt($iv, $i, $pubkey, $padding);
|
||||
openssl_public_encrypt($key, $k, $pubkey, $padding);
|
||||
openssl_public_encrypt($iv, $i, $pubkey, $padding);
|
||||
|
||||
$result['alg'] = $alg;
|
||||
$result['key'] = base64url_encode($k,true);
|
||||
$result['iv'] = base64url_encode($i,true);
|
||||
return $result;
|
||||
$result['alg'] = $alg;
|
||||
$result['key'] = base64url_encode($k, true);
|
||||
$result['iv'] = base64url_encode($i, true);
|
||||
return $result;
|
||||
} else {
|
||||
$x = [ 'data' => $data, 'pubkey' => $pubkey, 'alg' => $alg, 'result' => $data ];
|
||||
call_hooks('crypto_encapsulate', $x);
|
||||
return $x['result'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$x = [ 'data' => $data, 'pubkey' => $pubkey, 'alg' => $alg, 'result' => $data ];
|
||||
call_hooks('crypto_encapsulate', $x);
|
||||
return $x['result'];
|
||||
}
|
||||
}
|
||||
public static function unencapsulate($data, $prvkey)
|
||||
{
|
||||
|
||||
public static function unencapsulate($data, $prvkey) {
|
||||
if (! (is_array($data) && array_key_exists('encrypted', $data) && array_key_exists('alg', $data) && $data['alg'])) {
|
||||
logger('not encrypted');
|
||||
|
||||
if (! (is_array($data) && array_key_exists('encrypted',$data) && array_key_exists('alg',$data) && $data['alg'])) {
|
||||
logger('not encrypted');
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
$alg_base = $data['alg'];
|
||||
$padding = OPENSSL_PKCS1_PADDING;
|
||||
|
||||
$alg_base = $data['alg'];
|
||||
$padding = OPENSSL_PKCS1_PADDING;
|
||||
$exts = explode('.', $data['alg']);
|
||||
if (count($exts) > 1) {
|
||||
switch ($exts[1]) {
|
||||
case 'oaep':
|
||||
$padding = OPENSSL_PKCS1_OAEP_PADDING;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$alg_base = $exts[0];
|
||||
}
|
||||
|
||||
$exts = explode('.',$data['alg']);
|
||||
if (count($exts) > 1) {
|
||||
switch ($exts[1]) {
|
||||
case 'oaep':
|
||||
$padding = OPENSSL_PKCS1_OAEP_PADDING;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$alg_base = $exts[0];
|
||||
}
|
||||
$method = null;
|
||||
|
||||
$method = null;
|
||||
foreach (self::$openssl_algorithms as $ossl) {
|
||||
if ($ossl[0] === $alg_base) {
|
||||
$method = $ossl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (self::$openssl_algorithms as $ossl) {
|
||||
if ($ossl[0] === $alg_base) {
|
||||
$method = $ossl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($method) {
|
||||
openssl_private_decrypt(base64url_decode($data['key']),$k,$prvkey,$padding);
|
||||
openssl_private_decrypt(base64url_decode($data['iv']), $i,$prvkey,$padding);
|
||||
return openssl_decrypt(base64url_decode($data['data']),$method[1],substr($k,0,$method[2]),OPENSSL_RAW_DATA,substr($i,0,$method[3]));
|
||||
}
|
||||
else {
|
||||
$x = [ 'data' => $data, 'prvkey' => $prvkey, 'alg' => $data['alg'], 'result' => $data ];
|
||||
call_hooks('crypto_unencapsulate',$x);
|
||||
return $x['result'];
|
||||
}
|
||||
}
|
||||
if ($method) {
|
||||
openssl_private_decrypt(base64url_decode($data['key']), $k, $prvkey, $padding);
|
||||
openssl_private_decrypt(base64url_decode($data['iv']), $i, $prvkey, $padding);
|
||||
return openssl_decrypt(base64url_decode($data['data']), $method[1], substr($k, 0, $method[2]), OPENSSL_RAW_DATA, substr($i, 0, $method[3]));
|
||||
} else {
|
||||
$x = [ 'data' => $data, 'prvkey' => $prvkey, 'alg' => $data['alg'], 'result' => $data ];
|
||||
call_hooks('crypto_unencapsulate', $x);
|
||||
return $x['result'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
||||
use App;
|
||||
|
||||
class DB_Upgrade
|
||||
|
@ -18,8 +17,9 @@ class DB_Upgrade
|
|||
$this->func_prefix = '_';
|
||||
|
||||
$build = get_config('system', 'db_version', 0);
|
||||
if (!intval($build))
|
||||
if (!intval($build)) {
|
||||
$build = set_config('system', 'db_version', $db_revision);
|
||||
}
|
||||
|
||||
if ($build == $db_revision) {
|
||||
// Nothing to be done.
|
||||
|
@ -34,7 +34,6 @@ class DB_Upgrade
|
|||
$current = intval($db_revision);
|
||||
|
||||
if ($stored < $current) {
|
||||
|
||||
// The last update we performed was $stored.
|
||||
// Start at $stored + 1 and continue until we have completed $current
|
||||
|
||||
|
@ -55,8 +54,9 @@ class DB_Upgrade
|
|||
|
||||
Config::Load('database');
|
||||
|
||||
if (get_config('database', $s))
|
||||
if (get_config('database', $s)) {
|
||||
break;
|
||||
}
|
||||
set_config('database', $s, '1');
|
||||
|
||||
|
||||
|
@ -65,8 +65,6 @@ class DB_Upgrade
|
|||
$retval = $c->run();
|
||||
|
||||
if ($retval != UPDATE_SUCCESS) {
|
||||
|
||||
|
||||
$source = t('Source code of failed update: ') . "\n\n" . @file_get_contents('Zotlabs/Update/' . $s . '.php');
|
||||
|
||||
|
||||
|
@ -75,13 +73,15 @@ class DB_Upgrade
|
|||
|
||||
$lockfile = 'cache/mailsent';
|
||||
|
||||
if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400)))
|
||||
if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400))) {
|
||||
return;
|
||||
}
|
||||
@unlink($lockfile);
|
||||
//send the administrator an e-mail
|
||||
file_put_contents($lockfile, $x);
|
||||
|
||||
$r = q("select account_language from account where account_email = '%s' limit 1",
|
||||
$r = q(
|
||||
"select account_language from account where account_email = '%s' limit 1",
|
||||
dbesc(App::$config['system']['admin_email'])
|
||||
);
|
||||
push_lang(($r) ? $r[0]['account_language'] : 'en');
|
||||
|
@ -89,7 +89,8 @@ class DB_Upgrade
|
|||
[
|
||||
'toEmail' => App::$config['system']['admin_email'],
|
||||
'messageSubject' => sprintf(t('Update Error at %s'), z_root()),
|
||||
'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
|
||||
'textVersion' => replace_macros(
|
||||
get_intltext_template('update_fail_eml.tpl'),
|
||||
[
|
||||
'$sitename' => App::$config['system']['sitename'],
|
||||
'$siteurl' => z_root(),
|
||||
|
@ -113,4 +114,4 @@ class DB_Upgrade
|
|||
set_config('system', 'db_version', $db_revision);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
class DReport
|
||||
|
@ -73,8 +74,9 @@ class DReport
|
|||
public static function is_storable($dr)
|
||||
{
|
||||
|
||||
if (get_config('system', 'disable_dreport'))
|
||||
if (get_config('system', 'disable_dreport')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hooks dreport_is_storable
|
||||
|
@ -85,21 +87,26 @@ class DReport
|
|||
call_hooks('dreport_is_storable', $dr);
|
||||
|
||||
// let plugins accept or reject - if neither, continue on
|
||||
if (array_key_exists('accept', $dr) && intval($dr['accept']))
|
||||
if (array_key_exists('accept', $dr) && intval($dr['accept'])) {
|
||||
return true;
|
||||
if (array_key_exists('reject', $dr) && intval($dr['reject']))
|
||||
}
|
||||
if (array_key_exists('reject', $dr) && intval($dr['reject'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($dr['sender']))
|
||||
if (!($dr['sender'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the sender one of our channels?
|
||||
|
||||
$c = q("select channel_id from channel where channel_hash = '%s' limit 1",
|
||||
$c = q(
|
||||
"select channel_id from channel where channel_hash = '%s' limit 1",
|
||||
dbesc($dr['sender'])
|
||||
);
|
||||
if (!$c)
|
||||
if (!$c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// is the recipient one of our connections, or do we want to store every report?
|
||||
|
@ -107,37 +114,41 @@ class DReport
|
|||
|
||||
$rxchan = $dr['recipient'];
|
||||
$pcf = get_pconfig($c[0]['channel_id'], 'system', 'dreport_store_all');
|
||||
if ($pcf)
|
||||
if ($pcf) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We always add ourself as a recipient to private and relayed posts
|
||||
// So if a remote site says they can't find us, that's no big surprise
|
||||
// and just creates a lot of extra report noise
|
||||
|
||||
if (($dr['location'] !== z_root()) && ($dr['sender'] === $rxchan) && ($dr['status'] === 'recipient not found'))
|
||||
if (($dr['location'] !== z_root()) && ($dr['sender'] === $rxchan) && ($dr['status'] === 'recipient not found')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If you have a private post with a recipient list, every single site is going to report
|
||||
// back a failed delivery for anybody on that list that isn't local to them. We're only
|
||||
// concerned about this if we have a local hubloc record which says we expected them to
|
||||
// have a channel on that site.
|
||||
|
||||
$r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_url = '%s'",
|
||||
$r = q(
|
||||
"select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_url = '%s'",
|
||||
dbesc($rxchan),
|
||||
dbesc($dr['location'])
|
||||
);
|
||||
if ((!$r) && ($dr['status'] === 'recipient not found'))
|
||||
if ((!$r) && ($dr['status'] === 'recipient not found')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
$r = q(
|
||||
"select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
dbesc($rxchan),
|
||||
intval($c[0]['channel_id'])
|
||||
);
|
||||
if ($r)
|
||||
if ($r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,45 +15,49 @@ use ZipArchive;
|
|||
*
|
||||
* @author andrew
|
||||
*/
|
||||
class ExtendedZip extends ZipArchive {
|
||||
|
||||
// Member function to add a whole file system subtree to the archive
|
||||
public function addTree($dirname, $localname = '') {
|
||||
if ($localname)
|
||||
$this->addEmptyDir($localname);
|
||||
$this->_addTree($dirname, $localname);
|
||||
}
|
||||
class ExtendedZip extends ZipArchive
|
||||
{
|
||||
|
||||
// Internal function, to recurse
|
||||
protected function _addTree($dirname, $localname) {
|
||||
$dir = opendir($dirname);
|
||||
while ($filename = readdir($dir)) {
|
||||
// Discard . and ..
|
||||
if ($filename == '.' || $filename == '..')
|
||||
continue;
|
||||
// Member function to add a whole file system subtree to the archive
|
||||
public function addTree($dirname, $localname = '')
|
||||
{
|
||||
if ($localname) {
|
||||
$this->addEmptyDir($localname);
|
||||
}
|
||||
$this->_addTree($dirname, $localname);
|
||||
}
|
||||
|
||||
// Proceed according to type
|
||||
$path = $dirname . '/' . $filename;
|
||||
$localpath = $localname ? ($localname . '/' . $filename) : $filename;
|
||||
if (is_dir($path)) {
|
||||
// Directory: add & recurse
|
||||
$this->addEmptyDir($localpath);
|
||||
$this->_addTree($path, $localpath);
|
||||
}
|
||||
else if (is_file($path)) {
|
||||
// File: just add
|
||||
$this->addFile($path, $localpath);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
// Internal function, to recurse
|
||||
protected function _addTree($dirname, $localname)
|
||||
{
|
||||
$dir = opendir($dirname);
|
||||
while ($filename = readdir($dir)) {
|
||||
// Discard . and ..
|
||||
if ($filename == '.' || $filename == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Helper function
|
||||
public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '') {
|
||||
$zip = new self();
|
||||
$zip->open($zipFilename, $flags);
|
||||
$zip->addTree($dirname, $localname);
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
// Proceed according to type
|
||||
$path = $dirname . '/' . $filename;
|
||||
$localpath = $localname ? ($localname . '/' . $filename) : $filename;
|
||||
if (is_dir($path)) {
|
||||
// Directory: add & recurse
|
||||
$this->addEmptyDir($localpath);
|
||||
$this->_addTree($path, $localpath);
|
||||
} elseif (is_file($path)) {
|
||||
// File: just add
|
||||
$this->addFile($path, $localpath);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
// Helper function
|
||||
public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '')
|
||||
{
|
||||
$zip = new self();
|
||||
$zip->open($zipFilename, $flags);
|
||||
$zip->addTree($dirname, $localname);
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
/*
|
||||
* Zotlabs\Lib\Hashpath
|
||||
|
@ -17,14 +17,14 @@ namespace Zotlabs\Lib;
|
|||
* ...
|
||||
* The total number of records anticipated divided by the number of hash directories should generally be kept to
|
||||
* less than 1500 entries for optimum performance though this varies by operating system and filesystem type.
|
||||
* ext4 uses 32 bit inode numbers (~4B record limit) so use caution or alternative filesystem types with $depth above 3.
|
||||
* ext4 uses 32 bit inode numbers (~4B record limit) so use caution or alternative filesystem types with $depth above 3.
|
||||
* an optional $mkdir (boolean) to recursively create the directory (ignoring errors) before returning
|
||||
*
|
||||
* examples: for a $url of 'abcdefg' and prefix of 'path' the following paths are returned for $depth = 1 and $depth = 3
|
||||
* path/7d/7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a
|
||||
* path/7d/1a/54/7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4da9a
|
||||
*
|
||||
* see also: boot.php:os_mkdir() - here we provide the equivalent of mkdir -p with permissions of 770.
|
||||
* see also: boot.php:os_mkdir() - here we provide the equivalent of mkdir -p with permissions of 770.
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,173 +2,181 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
class IConfig
|
||||
{
|
||||
|
||||
public static function Load(&$item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public static function Get(&$item, $family, $key, $default = false)
|
||||
{
|
||||
|
||||
$is_item = false;
|
||||
|
||||
if (is_array($item)) {
|
||||
$is_item = true;
|
||||
|
||||
if ((! array_key_exists('iconfig', $item)) || (! is_array($item['iconfig']))) {
|
||||
$item['iconfig'] = [];
|
||||
}
|
||||
|
||||
if (array_key_exists('item_id', $item)) {
|
||||
$iid = $item['item_id'];
|
||||
} else {
|
||||
$iid = ((isset($item['id'])) ? $item['id'] : 0);
|
||||
}
|
||||
|
||||
if (array_key_exists('iconfig', $item) && is_array($item['iconfig'])) {
|
||||
foreach ($item['iconfig'] as $c) {
|
||||
if ($c['cat'] == $family && $c['k'] == $key) {
|
||||
return $c['v'];
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (intval($item)) {
|
||||
$iid = $item;
|
||||
}
|
||||
|
||||
if (! $iid) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$r = q(
|
||||
"select * from iconfig where iid = %d and cat = '%s' and k = '%s' limit 1",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if ($r) {
|
||||
$r[0]['v'] = unserialise($r[0]['v']);
|
||||
if ($is_item) {
|
||||
$item['iconfig'][] = $r[0];
|
||||
}
|
||||
return $r[0]['v'];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* IConfig::Set(&$item, $family, $key, $value, $sharing = false);
|
||||
*
|
||||
* $item - item array or item id. If passed an array the iconfig meta information is
|
||||
* added to the item structure (which will need to be saved with item_store eventually).
|
||||
* If passed an id, the DB is updated, but may not be federated and/or cloned.
|
||||
* $family - namespace of meta variable
|
||||
* $key - key of meta variable
|
||||
* $value - value of meta variable
|
||||
* $sharing - boolean (default false); if true the meta information is propagated with the item
|
||||
* to other sites/channels, mostly useful when $item is an array and has not yet been stored/delivered.
|
||||
* If the meta information is added after delivery and you wish it to be shared, it may be necessary to
|
||||
* alter the item edited timestamp and invoke the delivery process on the updated item. The edited
|
||||
* timestamp needs to be altered in order to trigger an item_store_update() at the receiving end.
|
||||
*/
|
||||
|
||||
|
||||
class IConfig {
|
||||
public static function Set(&$item, $family, $key, $value, $sharing = false)
|
||||
{
|
||||
|
||||
public static function Load(&$item) {
|
||||
return;
|
||||
}
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
public static function Get(&$item, $family, $key, $default = false) {
|
||||
$is_item = false;
|
||||
$idx = null;
|
||||
|
||||
$is_item = false;
|
||||
|
||||
if (is_array($item)) {
|
||||
$is_item = true;
|
||||
if (is_array($item)) {
|
||||
$is_item = true;
|
||||
if ((! array_key_exists('iconfig', $item)) || (! is_array($item['iconfig']))) {
|
||||
$item['iconfig'] = [];
|
||||
} elseif ($item['iconfig']) {
|
||||
for ($x = 0; $x < count($item['iconfig']); $x++) {
|
||||
if ($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
|
||||
$idx = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
$entry = array('cat' => $family, 'k' => $key, 'v' => $value, 'sharing' => $sharing);
|
||||
|
||||
if ((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig']))) {
|
||||
$item['iconfig'] = [];
|
||||
}
|
||||
if (is_null($idx)) {
|
||||
$item['iconfig'][] = $entry;
|
||||
} else {
|
||||
$item['iconfig'][$idx] = $entry;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (array_key_exists('item_id',$item)) {
|
||||
$iid = $item['item_id'];
|
||||
}
|
||||
else {
|
||||
$iid = ((isset($item['id'])) ? $item['id'] : 0);
|
||||
}
|
||||
|
||||
if (array_key_exists('iconfig',$item) && is_array($item['iconfig'])) {
|
||||
foreach ($item['iconfig'] as $c) {
|
||||
if ($c['cat'] == $family && $c['k'] == $key) {
|
||||
return $c['v'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (intval($item)) {
|
||||
$iid = $item;
|
||||
}
|
||||
if (intval($item)) {
|
||||
$iid = intval($item);
|
||||
}
|
||||
|
||||
if (! $iid) {
|
||||
return $default;
|
||||
}
|
||||
if (! $iid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = q("select * from iconfig where iid = %d and cat = '%s' and k = '%s' limit 1",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if ($r) {
|
||||
$r[0]['v'] = unserialise($r[0]['v']);
|
||||
if ($is_item) {
|
||||
$item['iconfig'][] = $r[0];
|
||||
}
|
||||
return $r[0]['v'];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
if (self::Get($item, $family, $key) === false) {
|
||||
$r = q(
|
||||
"insert into iconfig( iid, cat, k, v, sharing ) values ( %d, '%s', '%s', '%s', %d ) ",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue),
|
||||
intval($sharing)
|
||||
);
|
||||
} else {
|
||||
$r = q(
|
||||
"update iconfig set v = '%s', sharing = %d where iid = %d and cat = '%s' and k = '%s' ",
|
||||
dbesc($dbvalue),
|
||||
intval($sharing),
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* IConfig::Set(&$item, $family, $key, $value, $sharing = false);
|
||||
*
|
||||
* $item - item array or item id. If passed an array the iconfig meta information is
|
||||
* added to the item structure (which will need to be saved with item_store eventually).
|
||||
* If passed an id, the DB is updated, but may not be federated and/or cloned.
|
||||
* $family - namespace of meta variable
|
||||
* $key - key of meta variable
|
||||
* $value - value of meta variable
|
||||
* $sharing - boolean (default false); if true the meta information is propagated with the item
|
||||
* to other sites/channels, mostly useful when $item is an array and has not yet been stored/delivered.
|
||||
* If the meta information is added after delivery and you wish it to be shared, it may be necessary to
|
||||
* alter the item edited timestamp and invoke the delivery process on the updated item. The edited
|
||||
* timestamp needs to be altered in order to trigger an item_store_update() at the receiving end.
|
||||
*/
|
||||
|
||||
if (! $r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function Set(&$item, $family, $key, $value, $sharing = false) {
|
||||
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
$is_item = false;
|
||||
$idx = null;
|
||||
|
||||
if(is_array($item)) {
|
||||
$is_item = true;
|
||||
if((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig'])))
|
||||
$item['iconfig'] = [];
|
||||
elseif($item['iconfig']) {
|
||||
for($x = 0; $x < count($item['iconfig']); $x ++) {
|
||||
if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
|
||||
$idx = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
$entry = array('cat' => $family, 'k' => $key, 'v' => $value, 'sharing' => $sharing);
|
||||
|
||||
if(is_null($idx))
|
||||
$item['iconfig'][] = $entry;
|
||||
else
|
||||
$item['iconfig'][$idx] = $entry;
|
||||
return $value;
|
||||
}
|
||||
|
||||
if(intval($item))
|
||||
$iid = intval($item);
|
||||
|
||||
if(! $iid)
|
||||
return false;
|
||||
|
||||
if(self::Get($item, $family, $key) === false) {
|
||||
$r = q("insert into iconfig( iid, cat, k, v, sharing ) values ( %d, '%s', '%s', '%s', %d ) ",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue),
|
||||
intval($sharing)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("update iconfig set v = '%s', sharing = %d where iid = %d and cat = '%s' and k = '%s' ",
|
||||
dbesc($dbvalue),
|
||||
intval($sharing),
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
if(! $r)
|
||||
return false;
|
||||
|
||||
return $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function Delete(&$item, $family, $key) {
|
||||
public static function Delete(&$item, $family, $key)
|
||||
{
|
||||
|
||||
|
||||
$is_item = false;
|
||||
$idx = null;
|
||||
$is_item = false;
|
||||
$idx = null;
|
||||
|
||||
if(is_array($item)) {
|
||||
$is_item = true;
|
||||
if(is_array($item['iconfig'])) {
|
||||
for($x = 0; $x < count($item['iconfig']); $x ++) {
|
||||
if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
|
||||
unset($item['iconfig'][$x]);
|
||||
}
|
||||
}
|
||||
// re-order the array index
|
||||
$item['iconfig'] = array_values($item['iconfig']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (is_array($item)) {
|
||||
$is_item = true;
|
||||
if (is_array($item['iconfig'])) {
|
||||
for ($x = 0; $x < count($item['iconfig']); $x++) {
|
||||
if ($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
|
||||
unset($item['iconfig'][$x]);
|
||||
}
|
||||
}
|
||||
// re-order the array index
|
||||
$item['iconfig'] = array_values($item['iconfig']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(intval($item))
|
||||
$iid = intval($item);
|
||||
if (intval($item)) {
|
||||
$iid = intval($item);
|
||||
}
|
||||
|
||||
if(! $iid)
|
||||
return false;
|
||||
if (! $iid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return q("delete from iconfig where iid = %d and cat = '%s' and k = '%s' ",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return q(
|
||||
"delete from iconfig where iid = %d and cat = '%s' and k = '%s' ",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
use Zotlabs\Lib\Hashpath;
|
||||
|
@ -7,7 +8,7 @@ use Zotlabs\Daemon\Run;
|
|||
class Img_cache
|
||||
{
|
||||
|
||||
static public $cache_life = 18600 * 7;
|
||||
public static $cache_life = 18600 * 7;
|
||||
|
||||
public static function get_filename($url, $prefix = '.')
|
||||
{
|
||||
|
@ -79,12 +80,4 @@ class Img_cache
|
|||
logger('cache failed from ' . $url);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,15 +33,17 @@ class Img_filesize
|
|||
$fname = basename($url);
|
||||
$resolution = 0;
|
||||
|
||||
if (strpos($fname, '.') !== false)
|
||||
if (strpos($fname, '.') !== false) {
|
||||
$fname = substr($fname, 0, strpos($fname, '.'));
|
||||
}
|
||||
|
||||
if (substr($fname, -2, 1) == '-') {
|
||||
$resolution = intval(substr($fname, -1, 1));
|
||||
$fname = substr($fname, 0, -2);
|
||||
}
|
||||
|
||||
$r = q("SELECT filesize FROM photo WHERE resource_id = '%s' AND imgscale = %d LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT filesize FROM photo WHERE resource_id = '%s' AND imgscale = %d LIMIT 1",
|
||||
dbesc($fname),
|
||||
intval($resolution)
|
||||
);
|
||||
|
@ -50,7 +52,6 @@ class Img_filesize
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +83,7 @@ function getRemoteFileSize($url)
|
|||
curl_setopt($ch, CURLOPT_VERBOSE, 0); // set to 1 to debug
|
||||
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'r'));
|
||||
|
||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $line) use (&$in_headers, &$size) {
|
||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $line) use (&$in_headers, &$size) {
|
||||
$length = strlen($line);
|
||||
|
||||
if (trim($line) == '') {
|
||||
|
@ -97,7 +98,7 @@ function getRemoteFileSize($url)
|
|||
list($rng, $s) = explode('/', $content, 2);
|
||||
$size = (int)$s;
|
||||
return 0; // aborts transfer
|
||||
} else if ($header == 'content-length' && 206 != curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
|
||||
} elseif ($header == 'content-length' && 206 != curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
|
||||
// found content-length header and this is not a 206 Partial Content response (range response)
|
||||
$size = (int)$content;
|
||||
return 0;
|
||||
|
@ -107,7 +108,7 @@ function getRemoteFileSize($url)
|
|||
}
|
||||
});
|
||||
|
||||
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) use ($in_headers) {
|
||||
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($curl, $data) use ($in_headers) {
|
||||
if (!$in_headers) {
|
||||
// shouldn't be here unless we couldn't determine file size
|
||||
// abort transfer
|
||||
|
@ -120,7 +121,7 @@ function getRemoteFileSize($url)
|
|||
|
||||
curl_exec($ch);
|
||||
curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $size;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ class JSalmon
|
|||
'key_id' => base64url_encode($key_id, true)
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public static function verify($x)
|
||||
|
@ -64,13 +63,10 @@ class JSalmon
|
|||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
public static function unpack($data)
|
||||
{
|
||||
return json_decode(base64url_decode($data), true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,91 +9,94 @@ use phpseclib\Math\BigInteger;
|
|||
* Keyutils
|
||||
* Convert RSA keys between various formats
|
||||
*/
|
||||
class Keyutils {
|
||||
class Keyutils
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $m modulo
|
||||
* @param string $e exponent
|
||||
* @return string
|
||||
*/
|
||||
public static function meToPem($m, $e) {
|
||||
/**
|
||||
* @param string $m modulo
|
||||
* @param string $e exponent
|
||||
* @return string
|
||||
*/
|
||||
public static function meToPem($m, $e)
|
||||
{
|
||||
|
||||
$rsa = new RSA();
|
||||
$rsa->loadKey([
|
||||
'e' => new BigInteger($e, 256),
|
||||
'n' => new BigInteger($m, 256)
|
||||
]);
|
||||
return $rsa->getPublicKey();
|
||||
$rsa = new RSA();
|
||||
$rsa->loadKey([
|
||||
'e' => new BigInteger($e, 256),
|
||||
'n' => new BigInteger($m, 256)
|
||||
]);
|
||||
return $rsa->getPublicKey();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param string key
|
||||
* @return string
|
||||
*/
|
||||
public static function rsaToPem($key)
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string key
|
||||
* @return string
|
||||
*/
|
||||
public static function rsaToPem($key) {
|
||||
$rsa = new RSA();
|
||||
$rsa->setPublicKey($key);
|
||||
|
||||
$rsa = new RSA();
|
||||
$rsa->setPublicKey($key);
|
||||
return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8);
|
||||
}
|
||||
|
||||
return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8);
|
||||
/**
|
||||
* @param string key
|
||||
* @return string
|
||||
*/
|
||||
public static function pemToRsa($key)
|
||||
{
|
||||
|
||||
}
|
||||
$rsa = new RSA();
|
||||
$rsa->setPublicKey($key);
|
||||
|
||||
/**
|
||||
* @param string key
|
||||
* @return string
|
||||
*/
|
||||
public static function pemToRsa($key) {
|
||||
return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1);
|
||||
}
|
||||
|
||||
$rsa = new RSA();
|
||||
$rsa->setPublicKey($key);
|
||||
/**
|
||||
* @param string $key key
|
||||
* @param string $m reference modulo
|
||||
* @param string $e reference exponent
|
||||
*/
|
||||
public static function pemToMe($key, &$m, &$e)
|
||||
{
|
||||
|
||||
return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1);
|
||||
$rsa = new RSA();
|
||||
$rsa->loadKey($key);
|
||||
$rsa->setPublicKey();
|
||||
|
||||
}
|
||||
$m = $rsa->modulus->toBytes();
|
||||
$e = $rsa->exponent->toBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key key
|
||||
* @param string $m reference modulo
|
||||
* @param string $e reference exponent
|
||||
*/
|
||||
public static function pemToMe($key, &$m, &$e) {
|
||||
/**
|
||||
* @param string $pubkey
|
||||
* @return string
|
||||
*/
|
||||
public static function salmonKey($pubkey)
|
||||
{
|
||||
self::pemToMe($pubkey, $m, $e);
|
||||
return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true);
|
||||
}
|
||||
|
||||
$rsa = new RSA();
|
||||
$rsa->loadKey($key);
|
||||
$rsa->setPublicKey();
|
||||
/**
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public static function convertSalmonKey($key)
|
||||
{
|
||||
if (strstr($key, ',')) {
|
||||
$rawkey = substr($key, strpos($key, ',') + 1);
|
||||
} else {
|
||||
$rawkey = substr($key, 5);
|
||||
}
|
||||
|
||||
$m = $rsa->modulus->toBytes();
|
||||
$e = $rsa->exponent->toBytes();
|
||||
$key_info = explode('.', $rawkey);
|
||||
|
||||
}
|
||||
$m = base64url_decode($key_info[1]);
|
||||
$e = base64url_decode($key_info[2]);
|
||||
|
||||
/**
|
||||
* @param string $pubkey
|
||||
* @return string
|
||||
*/
|
||||
public static function salmonKey($pubkey) {
|
||||
self::pemToMe($pubkey, $m, $e);
|
||||
return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public static function convertSalmonKey($key) {
|
||||
if (strstr($key, ','))
|
||||
$rawkey = substr($key, strpos($key, ',') + 1);
|
||||
else
|
||||
$rawkey = substr($key, 5);
|
||||
|
||||
$key_info = explode('.', $rawkey);
|
||||
|
||||
$m = base64url_decode($key_info[1]);
|
||||
$e = base64url_decode($key_info[2]);
|
||||
|
||||
return self::meToPem($m, $e);
|
||||
}
|
||||
|
||||
}
|
||||
return self::meToPem($m, $e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class LDSignatures
|
|||
public static function dopplesign(&$data, $channel)
|
||||
{
|
||||
// remove for the time being - performance issues
|
||||
// $data['magicEnv'] = self::salmon_sign($data,$channel);
|
||||
// $data['magicEnv'] = self::salmon_sign($data,$channel);
|
||||
return self::sign($data, $channel);
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,9 @@ class LDSignatures
|
|||
$data = json_decode($data);
|
||||
}
|
||||
|
||||
if (!is_object($data))
|
||||
if (!is_object($data)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
jsonld_set_document_loader('jsonld_document_loader');
|
||||
|
||||
|
@ -133,8 +134,5 @@ class LDSignatures
|
|||
'meCreator' => channel_url($channel),
|
||||
'meSignatureValue' => $signature
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
||||
class LibBlock
|
||||
{
|
||||
|
||||
static public $cache = [];
|
||||
static public $empty = [];
|
||||
public static $cache = [];
|
||||
public static $empty = [];
|
||||
|
||||
// This limits the number of DB queries for fetch_by_entity to once per page load.
|
||||
|
||||
|
@ -46,7 +45,8 @@ class LibBlock
|
|||
$arr['block_comment'] = ((array_key_exists('block_comment', $arr)) ? escape_tags(trim($arr['block_comment'])) : EMPTY_STR);
|
||||
|
||||
if (!intval($arr['block_id'])) {
|
||||
$r = q("select * from block where block_channel_id = %d and block_entity = '%s' and block_type = %d limit 1",
|
||||
$r = q(
|
||||
"select * from block where block_channel_id = %d and block_entity = '%s' and block_type = %d limit 1",
|
||||
intval($arr['block_channel_id']),
|
||||
dbesc($arr['block_entity']),
|
||||
intval($arr['block_type'])
|
||||
|
@ -57,7 +57,8 @@ class LibBlock
|
|||
}
|
||||
|
||||
if (intval($arr['block_id'])) {
|
||||
return q("UPDATE block set block_channel_id = %d, block_entity = '%s', block_type = %d, block_comment = '%s' where block_id = %d",
|
||||
return q(
|
||||
"UPDATE block set block_channel_id = %d, block_entity = '%s', block_type = %d, block_comment = '%s' where block_id = %d",
|
||||
intval($arr['block_channel_id']),
|
||||
dbesc($arr['block_entity']),
|
||||
intval($arr['block_type']),
|
||||
|
@ -71,7 +72,8 @@ class LibBlock
|
|||
|
||||
public static function remove($channel_id, $entity)
|
||||
{
|
||||
return q("delete from block where block_channel_id = %d and block_entity = '%s'",
|
||||
return q(
|
||||
"delete from block where block_channel_id = %d and block_entity = '%s'",
|
||||
intval($channel_id),
|
||||
dbesc($entity)
|
||||
);
|
||||
|
@ -82,7 +84,8 @@ class LibBlock
|
|||
if (!intval($channel_id)) {
|
||||
return false;
|
||||
}
|
||||
$r = q("select * from block where block_channel_id = %d and block_id = %d ",
|
||||
$r = q(
|
||||
"select * from block where block_channel_id = %d and block_id = %d ",
|
||||
intval($channel_id)
|
||||
);
|
||||
return (($r) ? array_shift($r) : $r);
|
||||
|
@ -96,7 +99,6 @@ class LibBlock
|
|||
}
|
||||
|
||||
return self::fetch_from_cache($channel_id, $entity);
|
||||
|
||||
}
|
||||
|
||||
public static function fetch($channel_id, $type = false)
|
||||
|
@ -107,10 +109,10 @@ class LibBlock
|
|||
|
||||
$sql_extra = (($type === false) ? EMPTY_STR : " and block_type = " . intval($type));
|
||||
|
||||
$r = q("select * from block where block_channel_id = %d $sql_extra",
|
||||
$r = q(
|
||||
"select * from block where block_channel_id = %d $sql_extra",
|
||||
intval($channel_id)
|
||||
);
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class Libprofile
|
|||
public static function load($nickname, $profile = '')
|
||||
{
|
||||
|
||||
// logger('Libprofile::load: ' . $nickname . (($profile) ? ' profile: ' . $profile : ''));
|
||||
// logger('Libprofile::load: ' . $nickname . (($profile) ? ' profile: ' . $profile : ''));
|
||||
|
||||
$channel = channelx_by_nick($nickname);
|
||||
|
||||
|
@ -50,25 +50,29 @@ class Libprofile
|
|||
}
|
||||
|
||||
if (!$profile) {
|
||||
$r = q("SELECT abook_profile FROM abook WHERE abook_xchan = '%s' and abook_channel = '%d' limit 1",
|
||||
$r = q(
|
||||
"SELECT abook_profile FROM abook WHERE abook_xchan = '%s' and abook_channel = '%d' limit 1",
|
||||
dbesc(($observer) ? $observer['xchan_hash'] : ''),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if ($r)
|
||||
if ($r) {
|
||||
$profile = $r[0]['abook_profile'];
|
||||
}
|
||||
}
|
||||
|
||||
$p = null;
|
||||
|
||||
if ($profile) {
|
||||
$p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
|
||||
$p = q(
|
||||
"SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
|
||||
LEFT JOIN channel ON profile.uid = channel.channel_id
|
||||
WHERE channel.channel_address = '%s' AND profile.profile_guid = '%s' LIMIT 1",
|
||||
dbesc($nickname),
|
||||
dbesc($profile)
|
||||
);
|
||||
if (!$p) {
|
||||
$p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
|
||||
$p = q(
|
||||
"SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
|
||||
LEFT JOIN channel ON profile.uid = channel.channel_id
|
||||
WHERE channel.channel_address = '%s' AND profile.id = %d LIMIT 1",
|
||||
dbesc($nickname),
|
||||
|
@ -78,7 +82,8 @@ class Libprofile
|
|||
}
|
||||
|
||||
if (!$p) {
|
||||
$p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
|
||||
$p = q(
|
||||
"SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
|
||||
LEFT JOIN channel ON profile.uid = channel.channel_id
|
||||
WHERE channel.channel_address = '%s' and channel_removed = 0
|
||||
AND profile.is_default = 1 LIMIT 1",
|
||||
|
@ -93,22 +98,23 @@ class Libprofile
|
|||
return;
|
||||
}
|
||||
|
||||
$q = q("select * from profext where hash = '%s' and channel_id = %d",
|
||||
$q = q(
|
||||
"select * from profext where hash = '%s' and channel_id = %d",
|
||||
dbesc($p[0]['profile_guid']),
|
||||
intval($p[0]['profile_uid'])
|
||||
);
|
||||
if ($q) {
|
||||
|
||||
$extra_fields = [];
|
||||
|
||||
$profile_fields_basic = get_profile_fields_basic();
|
||||
$profile_fields_advanced = get_profile_fields_advanced();
|
||||
|
||||
$advanced = ((feature_enabled(local_channel(), 'advanced_profiles')) ? true : false);
|
||||
if ($advanced)
|
||||
if ($advanced) {
|
||||
$fields = $profile_fields_advanced;
|
||||
else
|
||||
} else {
|
||||
$fields = $profile_fields_basic;
|
||||
}
|
||||
|
||||
foreach ($q as $qq) {
|
||||
foreach ($fields as $k => $f) {
|
||||
|
@ -123,7 +129,8 @@ class Libprofile
|
|||
|
||||
$p[0]['extra_fields'] = ((isset($extra_fields)) ? $extra_fields : []);
|
||||
|
||||
$z = q("select xchan_photo_date, xchan_addr from xchan where xchan_hash = '%s' limit 1",
|
||||
$z = q(
|
||||
"select xchan_photo_date, xchan_addr from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($p[0]['channel_hash'])
|
||||
);
|
||||
if ($z) {
|
||||
|
@ -134,11 +141,13 @@ class Libprofile
|
|||
// fetch user tags if this isn't the default profile
|
||||
|
||||
if (!$p[0]['is_default']) {
|
||||
$x = q("select keywords from profile where uid = %d and is_default = 1 limit 1",
|
||||
$x = q(
|
||||
"select keywords from profile where uid = %d and is_default = 1 limit 1",
|
||||
intval($p[0]['profile_uid'])
|
||||
);
|
||||
if ($x && $can_view_profile)
|
||||
if ($x && $can_view_profile) {
|
||||
$p[0]['keywords'] = $x[0]['keywords'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($p[0]['keywords']) {
|
||||
|
@ -171,8 +180,7 @@ class Libprofile
|
|||
* load/reload current theme info
|
||||
*/
|
||||
|
||||
// $_SESSION['theme'] = $p[0]['channel_theme'];
|
||||
|
||||
// $_SESSION['theme'] = $p[0]['channel_theme'];
|
||||
}
|
||||
|
||||
public static function edit_menu($uid)
|
||||
|
@ -198,14 +206,16 @@ class Libprofile
|
|||
$ret['edit'] = [z_root() . '/profiles/' . $uid, t('Edit Profile'), '', t('Edit')];
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM profile WHERE uid = %d",
|
||||
$r = q(
|
||||
"SELECT * FROM profile WHERE uid = %d",
|
||||
local_channel()
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
if (!($multi_profiles || $rr['is_default']))
|
||||
if (!($multi_profiles || $rr['is_default'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ret['menu']['entries'][] = [
|
||||
'photo' => $rr['thumb'],
|
||||
|
@ -252,13 +262,15 @@ class Libprofile
|
|||
$block = true;
|
||||
}
|
||||
|
||||
if ((!is_array($profile)) && (!count($profile)))
|
||||
if ((!is_array($profile)) && (!count($profile))) {
|
||||
return $o;
|
||||
}
|
||||
|
||||
head_set_icon($profile['thumb']);
|
||||
|
||||
if (is_sys_channel($profile['uid']))
|
||||
if (is_sys_channel($profile['uid'])) {
|
||||
$show_connect = false;
|
||||
}
|
||||
|
||||
$profile['picdate'] = urlencode($profile['picdate']);
|
||||
|
||||
|
@ -269,42 +281,46 @@ class Libprofile
|
|||
call_hooks('profile_sidebar_enter', $profile);
|
||||
|
||||
if ($show_connect) {
|
||||
|
||||
// This will return an empty string if we're already connected.
|
||||
|
||||
$connect_url = rconnect_url($profile['uid'], get_observer_hash());
|
||||
$connect = (($connect_url) ? t('Connect') : '');
|
||||
if ($connect_url)
|
||||
if ($connect_url) {
|
||||
$connect_url = sprintf($connect_url, urlencode(channel_reddress($profile)));
|
||||
}
|
||||
|
||||
// premium channel - over-ride
|
||||
|
||||
if ($profile['channel_pageflags'] & PAGE_PREMIUM)
|
||||
if ($profile['channel_pageflags'] & PAGE_PREMIUM) {
|
||||
$connect_url = z_root() . '/connect/' . $profile['channel_address'];
|
||||
}
|
||||
}
|
||||
|
||||
if ((x($profile, 'address') == 1)
|
||||
if (
|
||||
(x($profile, 'address') == 1)
|
||||
|| (x($profile, 'locality') == 1)
|
||||
|| (x($profile, 'region') == 1)
|
||||
|| (x($profile, 'postal_code') == 1)
|
||||
|| (x($profile, 'country_name') == 1))
|
||||
|| (x($profile, 'country_name') == 1)
|
||||
) {
|
||||
$location = t('Location:');
|
||||
}
|
||||
|
||||
$profile['homepage'] = linkify($profile['homepage'], true);
|
||||
|
||||
$gender = ((x($profile, 'gender') == 1) ? t('Gender:') : False);
|
||||
$marital = ((x($profile, 'marital') == 1) ? t('Status:') : False);
|
||||
$homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : False);
|
||||
$pronouns = ((x($profile, 'pronouns') == 1) ? t('Pronouns:') : False);
|
||||
$gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
|
||||
$marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
|
||||
$homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
|
||||
$pronouns = ((x($profile, 'pronouns') == 1) ? t('Pronouns:') : false);
|
||||
|
||||
// zap/osada do not have a realtime chat system at this time so don't show online state
|
||||
// $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False);
|
||||
// logger('online: ' . $profile['online']);
|
||||
// $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False);
|
||||
// logger('online: ' . $profile['online']);
|
||||
|
||||
$profile['online'] = false;
|
||||
|
||||
if (($profile['hidewall'] && (!local_channel()) && (!remote_channel())) || $block) {
|
||||
$location = $reddress = $pdesc = $gender = $marital = $homepage = False;
|
||||
$location = $reddress = $pdesc = $gender = $marital = $homepage = false;
|
||||
}
|
||||
|
||||
if ($profile['gender']) {
|
||||
|
@ -327,8 +343,9 @@ class Libprofile
|
|||
if ($menu && !$block) {
|
||||
require_once('include/menu.php');
|
||||
$m = menu_fetch($menu, $profile['uid'], $observer['xchan_hash']);
|
||||
if ($m)
|
||||
if ($m) {
|
||||
$channel_menu = menu_render($m);
|
||||
}
|
||||
}
|
||||
$menublock = get_pconfig($profile['uid'], 'system', 'channel_menublock');
|
||||
if ($menublock && (!$block)) {
|
||||
|
@ -336,10 +353,11 @@ class Libprofile
|
|||
$channel_menu .= $comanche->block($menublock);
|
||||
}
|
||||
|
||||
if ($zcard)
|
||||
if ($zcard) {
|
||||
$tpl = get_markup_template('profile_vcard_short.tpl');
|
||||
else
|
||||
} else {
|
||||
$tpl = get_markup_template('profile_vcard.tpl');
|
||||
}
|
||||
|
||||
$o .= replace_macros($tpl, array(
|
||||
'$zcard' => $zcard,
|
||||
|
@ -383,23 +401,29 @@ class Libprofile
|
|||
public static function gender_icon($gender)
|
||||
{
|
||||
|
||||
// logger('gender: ' . $gender);
|
||||
// logger('gender: ' . $gender);
|
||||
|
||||
// This can easily get throw off if the observer language is different
|
||||
// than the channel owner language.
|
||||
|
||||
if (strpos(strtolower($gender), strtolower(t('Female'))) !== false)
|
||||
if (strpos(strtolower($gender), strtolower(t('Female'))) !== false) {
|
||||
return 'venus';
|
||||
if (strpos(strtolower($gender), strtolower(t('Male'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($gender), strtolower(t('Male'))) !== false) {
|
||||
return 'mars';
|
||||
if (strpos(strtolower($gender), strtolower(t('Trans'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($gender), strtolower(t('Trans'))) !== false) {
|
||||
return 'transgender';
|
||||
if (strpos(strtolower($gender), strtolower(t('Inter'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($gender), strtolower(t('Inter'))) !== false) {
|
||||
return 'transgender';
|
||||
if (strpos(strtolower($gender), strtolower(t('Neuter'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($gender), strtolower(t('Neuter'))) !== false) {
|
||||
return 'neuter';
|
||||
if (strpos(strtolower($gender), strtolower(t('Non-specific'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($gender), strtolower(t('Non-specific'))) !== false) {
|
||||
return 'genderless';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
@ -411,12 +435,15 @@ class Libprofile
|
|||
// This can easily get throw off if the observer language is different
|
||||
// than the channel owner language.
|
||||
|
||||
if (strpos(strtolower($pronouns), strtolower(t('She'))) !== false)
|
||||
if (strpos(strtolower($pronouns), strtolower(t('She'))) !== false) {
|
||||
return 'venus';
|
||||
if (strpos(strtolower($pronouns), strtolower(t('Him'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($pronouns), strtolower(t('Him'))) !== false) {
|
||||
return 'mars';
|
||||
if (strpos(strtolower($pronouns), strtolower(t('Them'))) !== false)
|
||||
}
|
||||
if (strpos(strtolower($pronouns), strtolower(t('Them'))) !== false) {
|
||||
return 'users';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
@ -425,19 +452,20 @@ class Libprofile
|
|||
public static function advanced()
|
||||
{
|
||||
|
||||
if (!perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_profile'))
|
||||
if (!perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_profile')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (App::$profile['fullname']) {
|
||||
|
||||
$profile_fields_basic = get_profile_fields_basic();
|
||||
$profile_fields_advanced = get_profile_fields_advanced();
|
||||
|
||||
$advanced = ((feature_enabled(App::$profile['profile_uid'], 'advanced_profiles')) ? true : false);
|
||||
if ($advanced)
|
||||
if ($advanced) {
|
||||
$fields = $profile_fields_advanced;
|
||||
else
|
||||
} else {
|
||||
$fields = $profile_fields_basic;
|
||||
}
|
||||
|
||||
$clean_fields = [];
|
||||
if ($fields) {
|
||||
|
@ -453,38 +481,40 @@ class Libprofile
|
|||
|
||||
$profile['fullname'] = array(t('Full Name:'), App::$profile['fullname']);
|
||||
|
||||
if (App::$profile['gender']) $profile['gender'] = array(t('Gender:'), App::$profile['gender']);
|
||||
if (App::$profile['gender']) {
|
||||
$profile['gender'] = array(t('Gender:'), App::$profile['gender']);
|
||||
}
|
||||
|
||||
|
||||
$ob_hash = get_observer_hash();
|
||||
// this may not work at all any more, but definitely won't work correctly if the liked profile belongs to a group
|
||||
// comment out until we are able to look at it much closer
|
||||
// if($ob_hash && perm_is_allowed(App::$profile['profile_uid'],$ob_hash,'post_like')) {
|
||||
// $profile['canlike'] = true;
|
||||
// $profile['likethis'] = t('Like this channel');
|
||||
// $profile['profile_guid'] = App::$profile['profile_guid'];
|
||||
// }
|
||||
// if($ob_hash && perm_is_allowed(App::$profile['profile_uid'],$ob_hash,'post_like')) {
|
||||
// $profile['canlike'] = true;
|
||||
// $profile['likethis'] = t('Like this channel');
|
||||
// $profile['profile_guid'] = App::$profile['profile_guid'];
|
||||
// }
|
||||
|
||||
// $likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'",
|
||||
// intval(App::$profile['profile_uid']),
|
||||
// dbesc(ACTIVITY_OBJ_PROFILE),
|
||||
// dbesc(ACTIVITY_LIKE)
|
||||
// );
|
||||
// $profile['likers'] = [];
|
||||
// $profile['like_count'] = count($likers);
|
||||
// $profile['like_button_label'] = tt('Like','Likes',$profile['like_count'],'noun');
|
||||
// $likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'",
|
||||
// intval(App::$profile['profile_uid']),
|
||||
// dbesc(ACTIVITY_OBJ_PROFILE),
|
||||
// dbesc(ACTIVITY_LIKE)
|
||||
// );
|
||||
// $profile['likers'] = [];
|
||||
// $profile['like_count'] = count($likers);
|
||||
// $profile['like_button_label'] = tt('Like','Likes',$profile['like_count'],'noun');
|
||||
|
||||
// if($likers) {
|
||||
// foreach($likers as $l)
|
||||
// $profile['likers'][] = array('name' => $l['xchan_name'],'photo' => zid($l['xchan_photo_s']), 'url' => zid($l['xchan_url']));
|
||||
// }
|
||||
// if($likers) {
|
||||
// foreach($likers as $l)
|
||||
// $profile['likers'][] = array('name' => $l['xchan_name'],'photo' => zid($l['xchan_photo_s']), 'url' => zid($l['xchan_url']));
|
||||
// }
|
||||
|
||||
if ((App::$profile['dob']) && (App::$profile['dob'] != '0000-00-00')) {
|
||||
|
||||
$val = '';
|
||||
|
||||
if ((substr(App::$profile['dob'], 5, 2) === '00') || (substr(App::$profile['dob'], 8, 2) === '00'))
|
||||
if ((substr(App::$profile['dob'], 5, 2) === '00') || (substr(App::$profile['dob'], 8, 2) === '00')) {
|
||||
$val = substr(App::$profile['dob'], 0, 4);
|
||||
}
|
||||
|
||||
$year_bd_format = t('j F, Y');
|
||||
$short_bd_format = t('j F');
|
||||
|
@ -497,14 +527,17 @@ class Libprofile
|
|||
$profile['birthday'] = array(t('Birthday:'), $val);
|
||||
}
|
||||
|
||||
if ($age = age(App::$profile['dob'], App::$profile['timezone'], ''))
|
||||
if ($age = age(App::$profile['dob'], App::$profile['timezone'], '')) {
|
||||
$profile['age'] = array(t('Age:'), $age);
|
||||
}
|
||||
|
||||
if (App::$profile['marital'])
|
||||
if (App::$profile['marital']) {
|
||||
$profile['marital'] = array(t('Status:'), App::$profile['marital']);
|
||||
}
|
||||
|
||||
if (App::$profile['partner'])
|
||||
if (App::$profile['partner']) {
|
||||
$profile['marital']['partner'] = zidify_links(bbcode(App::$profile['partner']));
|
||||
}
|
||||
|
||||
if (strlen(App::$profile['howlong']) && App::$profile['howlong'] > NULL_DATE) {
|
||||
$profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s'));
|
||||
|
@ -523,51 +556,91 @@ class Libprofile
|
|||
}
|
||||
|
||||
|
||||
if (App::$profile['sexual']) $profile['sexual'] = array(t('Sexual Preference:'), App::$profile['sexual']);
|
||||
if (App::$profile['sexual']) {
|
||||
$profile['sexual'] = array(t('Sexual Preference:'), App::$profile['sexual']);
|
||||
}
|
||||
|
||||
if (App::$profile['pronouns']) $profile['pronouns'] = array(t('Pronouns:'), App::$profile['pronouns']);
|
||||
if (App::$profile['pronouns']) {
|
||||
$profile['pronouns'] = array(t('Pronouns:'), App::$profile['pronouns']);
|
||||
}
|
||||
|
||||
if (App::$profile['homepage']) $profile['homepage'] = array(t('Homepage:'), linkify(App::$profile['homepage']));
|
||||
if (App::$profile['homepage']) {
|
||||
$profile['homepage'] = array(t('Homepage:'), linkify(App::$profile['homepage']));
|
||||
}
|
||||
|
||||
if (App::$profile['hometown']) $profile['hometown'] = array(t('Hometown:'), linkify(App::$profile['hometown']));
|
||||
if (App::$profile['hometown']) {
|
||||
$profile['hometown'] = array(t('Hometown:'), linkify(App::$profile['hometown']));
|
||||
}
|
||||
|
||||
if (App::$profile['politic']) $profile['politic'] = array(t('Political Views:'), App::$profile['politic']);
|
||||
if (App::$profile['politic']) {
|
||||
$profile['politic'] = array(t('Political Views:'), App::$profile['politic']);
|
||||
}
|
||||
|
||||
if (App::$profile['religion']) $profile['religion'] = array(t('Religion:'), App::$profile['religion']);
|
||||
if (App::$profile['religion']) {
|
||||
$profile['religion'] = array(t('Religion:'), App::$profile['religion']);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['about'])) $profile['about'] = array(t('About:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['about'])) {
|
||||
$profile['about'] = array(t('About:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['interest'])) $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['interest'])) {
|
||||
$profile['interest'] = array(t('Hobbies/Interests:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['likes'])) $profile['likes'] = array(t('Likes:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['likes'])) {
|
||||
$profile['likes'] = array(t('Likes:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['dislikes'])) $profile['dislikes'] = array(t('Dislikes:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['dislikes'])) {
|
||||
$profile['dislikes'] = array(t('Dislikes:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['contact'])) $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['contact'])) {
|
||||
$profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['channels'])) $profile['channels'] = array(t('My other channels:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['channels'])) {
|
||||
$profile['channels'] = array(t('My other channels:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['music'])) $profile['music'] = array(t('Musical interests:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['music'])) {
|
||||
$profile['music'] = array(t('Musical interests:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['book'])) $profile['book'] = array(t('Books, literature:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['book'])) {
|
||||
$profile['book'] = array(t('Books, literature:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['tv'])) $profile['tv'] = array(t('Television:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['tv'])) {
|
||||
$profile['tv'] = array(t('Television:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['film'])) $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['film'])) {
|
||||
$profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['romance'])) $profile['romance'] = array(t('Love/Romance:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['romance'])) {
|
||||
$profile['romance'] = array(t('Love/Romance:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['employment'])) $profile['employment'] = array(t('Work/employment:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['employment'])) {
|
||||
$profile['employment'] = array(t('Work/employment:'), $txt);
|
||||
}
|
||||
|
||||
if ($txt = prepare_text(App::$profile['education'])) $profile['education'] = array(t('School/education:'), $txt);
|
||||
if ($txt = prepare_text(App::$profile['education'])) {
|
||||
$profile['education'] = array(t('School/education:'), $txt);
|
||||
}
|
||||
|
||||
if (App::$profile['extra_fields']) {
|
||||
foreach (App::$profile['extra_fields'] as $f) {
|
||||
$x = q("select * from profdef where field_name = '%s' limit 1",
|
||||
$x = q(
|
||||
"select * from profdef where field_name = '%s' limit 1",
|
||||
dbesc($f)
|
||||
);
|
||||
if ($x && $txt = prepare_text(App::$profile[$f]))
|
||||
if ($x && $txt = prepare_text(App::$profile[$f])) {
|
||||
$profile[$f] = array($x[0]['field_desc'] . ':', $txt);
|
||||
}
|
||||
}
|
||||
$profile['extra_fields'] = App::$profile['extra_fields'];
|
||||
}
|
||||
|
@ -575,9 +648,9 @@ class Libprofile
|
|||
$things = get_things(App::$profile['profile_guid'], App::$profile['profile_uid']);
|
||||
|
||||
|
||||
// logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
|
||||
// logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
|
||||
|
||||
// $exportlink = ((App::$profile['profile_vcard']) ? zid(z_root() . '/profile/' . App::$profile['channel_address'] . '/vcard') : '');
|
||||
// $exportlink = ((App::$profile['profile_vcard']) ? zid(z_root() . '/profile/' . App::$profile['channel_address'] . '/vcard') : '');
|
||||
|
||||
return replace_macros($tpl, array(
|
||||
'$title' => t('Profile'),
|
||||
|
@ -594,6 +667,4 @@ class Libprofile
|
|||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ class Libsync
|
|||
unset($channel['channel_password']);
|
||||
unset($channel['channel_salt']);
|
||||
|
||||
$h = q("select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url
|
||||
$h = q(
|
||||
"select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url
|
||||
where hubloc_hash = '%s' and hubloc_network = 'zot6' and hubloc_deleted = 0",
|
||||
dbesc(($keychange) ? $packet['keychange']['old_hash'] : $channel['channel_hash'])
|
||||
);
|
||||
|
@ -72,7 +73,8 @@ class Libsync
|
|||
continue;
|
||||
}
|
||||
|
||||
$y = q("select site_dead from site where site_url = '%s' limit 1",
|
||||
$y = q(
|
||||
"select site_dead from site where site_url = '%s' limit 1",
|
||||
dbesc($x['hubloc_url'])
|
||||
);
|
||||
|
||||
|
@ -106,7 +108,6 @@ class Libsync
|
|||
if ($channel) {
|
||||
$info['channel'] = [];
|
||||
foreach ($channel as $k => $v) {
|
||||
|
||||
// filter out any joined tables like xchan
|
||||
|
||||
if (strpos($k, 'channel_') !== 0) {
|
||||
|
@ -132,14 +133,16 @@ class Libsync
|
|||
}
|
||||
|
||||
if ($groups_changed) {
|
||||
$r = q("select hash as collection, visible, deleted, rule, gname as name from pgrp where uid = %d ",
|
||||
$r = q(
|
||||
"select hash as collection, visible, deleted, rule, gname as name from pgrp where uid = %d ",
|
||||
intval($uid)
|
||||
);
|
||||
if ($r) {
|
||||
$info['collections'] = $r;
|
||||
}
|
||||
|
||||
$r = q("select pgrp.hash as collection, pgrp_member.xchan as member from pgrp left join pgrp_member on pgrp.id = pgrp_member.gid
|
||||
$r = q(
|
||||
"select pgrp.hash as collection, pgrp_member.xchan as member from pgrp left join pgrp_member on pgrp.id = pgrp_member.gid
|
||||
where pgrp_member.uid = %d ",
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -203,7 +206,8 @@ class Libsync
|
|||
return;
|
||||
}
|
||||
|
||||
$l = q("select link from linkid where ident = '%s' and sigtype = 2",
|
||||
$l = q(
|
||||
"select link from linkid where ident = '%s' and sigtype = 2",
|
||||
dbesc($channel['channel_hash'])
|
||||
);
|
||||
|
||||
|
@ -227,7 +231,8 @@ class Libsync
|
|||
continue;
|
||||
}
|
||||
|
||||
$y = q("select site_dead from site where site_url = '%s' limit 1",
|
||||
$y = q(
|
||||
"select site_dead from site where site_url = '%s' limit 1",
|
||||
dbesc($x['hubloc_url'])
|
||||
);
|
||||
|
||||
|
@ -296,19 +301,22 @@ class Libsync
|
|||
foreach ($deliveries as $d) {
|
||||
$linked_channel = false;
|
||||
|
||||
$r = q("select * from channel where channel_hash = '%s' limit 1",
|
||||
$r = q(
|
||||
"select * from channel where channel_hash = '%s' limit 1",
|
||||
dbesc($sender)
|
||||
);
|
||||
|
||||
$DR = new DReport(z_root(), $sender, $d, 'sync');
|
||||
|
||||
if (!$r) {
|
||||
$l = q("select ident from linkid where link = '%s' and sigtype = 2 limit 1",
|
||||
$l = q(
|
||||
"select ident from linkid where link = '%s' and sigtype = 2 limit 1",
|
||||
dbesc($sender)
|
||||
);
|
||||
if ($l) {
|
||||
$linked_channel = true;
|
||||
$r = q("select * from channel where channel_hash = '%s' limit 1",
|
||||
$r = q(
|
||||
"select * from channel where channel_hash = '%s' limit 1",
|
||||
dbesc($l[0]['ident'])
|
||||
);
|
||||
}
|
||||
|
@ -342,7 +350,8 @@ class Libsync
|
|||
// if the clone is active, so are we
|
||||
|
||||
if (substr($channel['channel_active'], 0, 10) !== substr(datetime_convert(), 0, 10)) {
|
||||
q("UPDATE channel set channel_active = '%s' where channel_id = %d",
|
||||
q(
|
||||
"UPDATE channel set channel_active = '%s' where channel_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -421,19 +430,16 @@ class Libsync
|
|||
}
|
||||
|
||||
if (array_key_exists('channel', $arr) && is_array($arr['channel']) && count($arr['channel'])) {
|
||||
|
||||
$remote_channel = $arr['channel'];
|
||||
$remote_channel['channel_id'] = $channel['channel_id'];
|
||||
|
||||
if (array_key_exists('channel_pageflags', $arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
|
||||
|
||||
// Several pageflags are site-specific and cannot be sync'd.
|
||||
// Only allow those bits which are shareable from the remote and then
|
||||
// logically OR with the local flags
|
||||
|
||||
$arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] & (PAGE_HIDDEN | PAGE_AUTOCONNECT | PAGE_APPLICATION | PAGE_PREMIUM | PAGE_ADULT);
|
||||
$arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] | $channel['channel_pageflags'];
|
||||
|
||||
}
|
||||
|
||||
$columns = db_columns('channel');
|
||||
|
@ -461,11 +467,11 @@ class Libsync
|
|||
}
|
||||
|
||||
if (array_key_exists('abook', $arr) && is_array($arr['abook']) && count($arr['abook'])) {
|
||||
|
||||
$total_friends = 0;
|
||||
$total_feeds = 0;
|
||||
|
||||
$r = q("select abook_id, abook_feed from abook where abook_channel = %d",
|
||||
$r = q(
|
||||
"select abook_id, abook_feed from abook where abook_channel = %d",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if ($r) {
|
||||
|
@ -484,7 +490,6 @@ class Libsync
|
|||
$fields = db_columns('abook');
|
||||
|
||||
foreach ($arr['abook'] as $abook) {
|
||||
|
||||
// this is here for debugging so we can find the issue source
|
||||
|
||||
if (!is_array($abook)) {
|
||||
|
@ -503,7 +508,8 @@ class Libsync
|
|||
if ($abook['abook_xchan'] && $abook['entry_deleted']) {
|
||||
logger('Removing abook entry for ' . $abook['abook_xchan']);
|
||||
|
||||
$r = q("select abook_id, abook_feed from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
|
||||
$r = q(
|
||||
"select abook_id, abook_feed from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
|
||||
dbesc($abook['abook_xchan']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -546,7 +552,8 @@ class Libsync
|
|||
$xc[$k] = $v;
|
||||
}
|
||||
}
|
||||
$r = q("select * from xchan where xchan_hash = '%s'",
|
||||
$r = q(
|
||||
"select * from xchan where xchan_hash = '%s'",
|
||||
dbesc($xc['xchan_hash'])
|
||||
);
|
||||
if (!$r) {
|
||||
|
@ -584,7 +591,8 @@ class Libsync
|
|||
}
|
||||
}
|
||||
|
||||
$r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
$r = q(
|
||||
"select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
dbesc($clean['abook_xchan']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -621,7 +629,6 @@ class Libsync
|
|||
|
||||
$r = dbq("UPDATE abook set " . dbesc($k) . " = '" . dbesc($v)
|
||||
. "' where abook_xchan = '" . dbesc($clean['abook_xchan']) . "' and abook_channel = " . intval($channel['channel_id']));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,7 +653,8 @@ class Libsync
|
|||
// sync collections (privacy groups) oh joy...
|
||||
|
||||
if (array_key_exists('collections', $arr) && is_array($arr['collections']) && count($arr['collections'])) {
|
||||
$x = q("select * from pgrp where uid = %d ",
|
||||
$x = q(
|
||||
"select * from pgrp where uid = %d ",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
foreach ($arr['collections'] as $cl) {
|
||||
|
@ -659,10 +667,13 @@ class Libsync
|
|||
}
|
||||
}
|
||||
if ($found) {
|
||||
if (($y['gname'] != $cl['name'])
|
||||
if (
|
||||
($y['gname'] != $cl['name'])
|
||||
|| ($y['visible'] != $cl['visible'])
|
||||
|| ($y['deleted'] != $cl['deleted'])) {
|
||||
q("update pgrp set gname = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d",
|
||||
|| ($y['deleted'] != $cl['deleted'])
|
||||
) {
|
||||
q(
|
||||
"update pgrp set gname = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d",
|
||||
dbesc($cl['name']),
|
||||
intval($cl['visible']),
|
||||
intval($cl['deleted']),
|
||||
|
@ -671,14 +682,16 @@ class Libsync
|
|||
);
|
||||
}
|
||||
if (intval($cl['deleted']) && (!intval($y['deleted']))) {
|
||||
q("delete from pgrp_member where gid = %d",
|
||||
q(
|
||||
"delete from pgrp_member where gid = %d",
|
||||
intval($y['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$r = q("INSERT INTO pgrp ( hash, uid, visible, deleted, gname, rule )
|
||||
$r = q(
|
||||
"INSERT INTO pgrp ( hash, uid, visible, deleted, gname, rule )
|
||||
VALUES( '%s', %d, %d, %d, '%s', '%s' ) ",
|
||||
dbesc($cl['collection']),
|
||||
intval($channel['channel_id']),
|
||||
|
@ -703,10 +716,12 @@ class Libsync
|
|||
}
|
||||
}
|
||||
if (!$found_local) {
|
||||
q("delete from pgrp_member where gid = %d",
|
||||
q(
|
||||
"delete from pgrp_member where gid = %d",
|
||||
intval($y['id'])
|
||||
);
|
||||
q("update pgrp set deleted = 1 where id = %d and uid = %d",
|
||||
q(
|
||||
"update pgrp set deleted = 1 where id = %d and uid = %d",
|
||||
intval($y['id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -716,16 +731,18 @@ class Libsync
|
|||
}
|
||||
|
||||
// reload the group list with any updates
|
||||
$x = q("select * from pgrp where uid = %d",
|
||||
$x = q(
|
||||
"select * from pgrp where uid = %d",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
// now sync the members
|
||||
|
||||
if (array_key_exists('collection_members', $arr)
|
||||
if (
|
||||
array_key_exists('collection_members', $arr)
|
||||
&& is_array($arr['collection_members'])
|
||||
&& count($arr['collection_members'])) {
|
||||
|
||||
&& count($arr['collection_members'])
|
||||
) {
|
||||
// first sort into groups keyed by the group hash
|
||||
$members = [];
|
||||
foreach ($arr['collection_members'] as $cm) {
|
||||
|
@ -739,12 +756,12 @@ class Libsync
|
|||
// our group list is already synchronised
|
||||
if ($x) {
|
||||
foreach ($x as $y) {
|
||||
|
||||
// for each group, loop on members list we just received
|
||||
if (isset($y['hash']) && isset($members[$y['hash']])) {
|
||||
foreach ($members[$y['hash']] as $member) {
|
||||
$found = false;
|
||||
$z = q("select xchan from pgrp_member where gid = %d and uid = %d and xchan = '%s' limit 1",
|
||||
$z = q(
|
||||
"select xchan from pgrp_member where gid = %d and uid = %d and xchan = '%s' limit 1",
|
||||
intval($y['id']),
|
||||
intval($channel['channel_id']),
|
||||
dbesc($member)
|
||||
|
@ -756,7 +773,8 @@ class Libsync
|
|||
// if somebody is in the group that wasn't before - add them
|
||||
|
||||
if (!$found) {
|
||||
q("INSERT INTO pgrp_member (uid, gid, xchan)
|
||||
q(
|
||||
"INSERT INTO pgrp_member (uid, gid, xchan)
|
||||
VALUES( %d, %d, '%s' ) ",
|
||||
intval($channel['channel_id']),
|
||||
intval($y['id']),
|
||||
|
@ -767,7 +785,8 @@ class Libsync
|
|||
}
|
||||
|
||||
// now retrieve a list of members we have on this site
|
||||
$m = q("select xchan from pgrp_member where gid = %d and uid = %d",
|
||||
$m = q(
|
||||
"select xchan from pgrp_member where gid = %d and uid = %d",
|
||||
intval($y['id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -775,7 +794,8 @@ class Libsync
|
|||
foreach ($m as $mm) {
|
||||
// if the local existing member isn't in the list we just received - remove them
|
||||
if (!in_array($mm['xchan'], $members[$y['hash']])) {
|
||||
q("delete from pgrp_member where xchan = '%s' and gid = %d and uid = %d",
|
||||
q(
|
||||
"delete from pgrp_member where xchan = '%s' and gid = %d and uid = %d",
|
||||
dbesc($mm['xchan']),
|
||||
intval($y['id']),
|
||||
intval($channel['channel_id'])
|
||||
|
@ -789,12 +809,11 @@ class Libsync
|
|||
}
|
||||
|
||||
if (array_key_exists('profile', $arr) && is_array($arr['profile']) && count($arr['profile'])) {
|
||||
|
||||
$disallowed = array('id', 'aid', 'uid', 'guid');
|
||||
|
||||
foreach ($arr['profile'] as $profile) {
|
||||
|
||||
$x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
|
||||
$x = q(
|
||||
"select * from profile where profile_guid = '%s' and uid = %d limit 1",
|
||||
dbesc($profile['profile_guid']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -807,7 +826,8 @@ class Libsync
|
|||
]
|
||||
);
|
||||
|
||||
$x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
|
||||
$x = q(
|
||||
"select * from profile where profile_guid = '%s' and uid = %d limit 1",
|
||||
dbesc($profile['profile_guid']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -897,7 +917,8 @@ class Libsync
|
|||
// If a sender reports that the channel has been deleted, delete its hubloc
|
||||
|
||||
if (isset($arr['deleted_locally']) && intval($arr['deleted_locally'])) {
|
||||
q("UPDATE hubloc SET hubloc_deleted = 1, hubloc_updated = '%s' WHERE hubloc_hash = '%s' AND hubloc_url = '%s'",
|
||||
q(
|
||||
"UPDATE hubloc SET hubloc_deleted = 1, hubloc_updated = '%s' WHERE hubloc_hash = '%s' AND hubloc_url = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($sender['hash']),
|
||||
dbesc($sender['site']['url'])
|
||||
|
@ -905,8 +926,8 @@ class Libsync
|
|||
}
|
||||
|
||||
if ($arr['locations']) {
|
||||
|
||||
$x = q("select * from xchan where xchan_hash = '%s'",
|
||||
$x = q(
|
||||
"select * from xchan where xchan_hash = '%s'",
|
||||
dbesc($sender['hash'])
|
||||
);
|
||||
if ($x) {
|
||||
|
@ -917,7 +938,8 @@ class Libsync
|
|||
Libzot::check_location_move($sender['hash'], $arr['locations']);
|
||||
}
|
||||
|
||||
$xisting = q("select * from hubloc where hubloc_hash = '%s'",
|
||||
$xisting = q(
|
||||
"select * from hubloc where hubloc_hash = '%s'",
|
||||
dbesc($sender['hash'])
|
||||
);
|
||||
|
||||
|
@ -937,8 +959,9 @@ class Libsync
|
|||
|
||||
// Ensure that they have one primary hub
|
||||
|
||||
if (!$has_primary)
|
||||
if (!$has_primary) {
|
||||
$arr['locations'][0]['primary'] = true;
|
||||
}
|
||||
|
||||
foreach ($arr['locations'] as $location) {
|
||||
if (!Libzot::verify($location['url'], $location['url_sig'], $sender['public_key'])) {
|
||||
|
@ -948,8 +971,10 @@ class Libsync
|
|||
}
|
||||
|
||||
for ($x = 0; $x < count($xisting); $x++) {
|
||||
if (($xisting[$x]['hubloc_url'] === $location['url'])
|
||||
&& ($xisting[$x]['hubloc_sitekey'] === $location['sitekey'])) {
|
||||
if (
|
||||
($xisting[$x]['hubloc_url'] === $location['url'])
|
||||
&& ($xisting[$x]['hubloc_sitekey'] === $location['sitekey'])
|
||||
) {
|
||||
$xisting[$x]['updated'] = true;
|
||||
}
|
||||
}
|
||||
|
@ -961,7 +986,8 @@ class Libsync
|
|||
|
||||
// match as many fields as possible in case anything at all changed.
|
||||
|
||||
$r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
|
||||
$r = q(
|
||||
"select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
|
||||
dbesc($sender['hash']),
|
||||
dbesc($sender['id']),
|
||||
dbesc($sender['id_sig']),
|
||||
|
@ -979,7 +1005,8 @@ class Libsync
|
|||
// generate a new hubloc_site_id if it's wrong due to historical bugs 2021-11-30
|
||||
|
||||
if ($r[0]['hubloc_site_id'] !== $location['site_id']) {
|
||||
q("update hubloc set hubloc_site_id = '%s' where hubloc_id = %d",
|
||||
q(
|
||||
"update hubloc set hubloc_site_id = '%s' where hubloc_id = %d",
|
||||
dbesc(Libzot::make_xchan_hash($location['url'], $location['sitekey'])),
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
|
@ -993,7 +1020,8 @@ class Libsync
|
|||
$t = datetime_convert('UTC', 'UTC', 'now - 15 minutes');
|
||||
|
||||
if (array_key_exists('site', $arr) && $location['url'] == $arr['site']['url']) {
|
||||
q("update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d and hubloc_updated < '%s'",
|
||||
q(
|
||||
"update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d and hubloc_updated < '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['hubloc_id']),
|
||||
|
@ -1003,15 +1031,18 @@ class Libsync
|
|||
}
|
||||
|
||||
if ($current_site && (intval($r[0]['hubloc_error']) || intval($r[0]['hubloc_deleted']))) {
|
||||
q("update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d",
|
||||
q(
|
||||
"update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d",
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
if (intval($r[0]['hubloc_orphancheck'])) {
|
||||
q("update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d",
|
||||
q(
|
||||
"update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d",
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
}
|
||||
q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
|
||||
q(
|
||||
"update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
|
||||
dbesc($sender['hash'])
|
||||
);
|
||||
}
|
||||
|
@ -1019,7 +1050,8 @@ class Libsync
|
|||
// Remove pure duplicates
|
||||
if (count($r) > 1) {
|
||||
for ($h = 1; $h < count($r); $h++) {
|
||||
q("delete from hubloc where hubloc_id = %d",
|
||||
q(
|
||||
"delete from hubloc where hubloc_id = %d",
|
||||
intval($r[$h]['hubloc_id'])
|
||||
);
|
||||
$what .= 'duplicate_hubloc_removed ';
|
||||
|
@ -1028,7 +1060,8 @@ class Libsync
|
|||
}
|
||||
|
||||
if (intval($r[0]['hubloc_primary']) && (!$location['primary'])) {
|
||||
$m = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
$m = q(
|
||||
"update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
|
@ -1037,7 +1070,8 @@ class Libsync
|
|||
$what .= 'primary_hub ';
|
||||
$changed = true;
|
||||
} elseif ((!intval($r[0]['hubloc_primary'])) && ($location['primary'])) {
|
||||
$m = q("update hubloc set hubloc_primary = 1, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
$m = q(
|
||||
"update hubloc set hubloc_primary = 1, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
|
@ -1062,7 +1096,8 @@ class Libsync
|
|||
}
|
||||
|
||||
if (intval($r[0]['hubloc_deleted']) && (!intval($location['deleted']))) {
|
||||
$n = q("update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
$n = q(
|
||||
"update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
|
@ -1070,7 +1105,8 @@ class Libsync
|
|||
$changed = true;
|
||||
} elseif ((!intval($r[0]['hubloc_deleted'])) && (intval($location['deleted']))) {
|
||||
logger('deleting hubloc: ' . $r[0]['hubloc_addr']);
|
||||
$n = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
$n = q(
|
||||
"update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['hubloc_id'])
|
||||
);
|
||||
|
@ -1084,7 +1120,8 @@ class Libsync
|
|||
// New hub claiming to be primary. Make it so by removing any existing primaries.
|
||||
|
||||
if (intval($location['primary'])) {
|
||||
$r = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1",
|
||||
$r = q(
|
||||
"update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($sender['hash'])
|
||||
);
|
||||
|
@ -1116,12 +1153,14 @@ class Libsync
|
|||
$changed = true;
|
||||
|
||||
if ($location['primary']) {
|
||||
$r = q("select * from hubloc where hubloc_addr = '%s' and hubloc_sitekey = '%s' limit 1",
|
||||
$r = q(
|
||||
"select * from hubloc where hubloc_addr = '%s' and hubloc_sitekey = '%s' limit 1",
|
||||
dbesc($location['address']),
|
||||
dbesc($location['sitekey'])
|
||||
);
|
||||
if ($r)
|
||||
if ($r) {
|
||||
hubloc_change_primary($r[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1131,7 +1170,8 @@ class Libsync
|
|||
foreach ($xisting as $x) {
|
||||
if (!array_key_exists('updated', $x)) {
|
||||
logger('Deleting unreferenced hub location ' . $x['hubloc_addr']);
|
||||
$r = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
$r = q(
|
||||
"update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($x['hubloc_id'])
|
||||
);
|
||||
|
@ -1164,7 +1204,8 @@ class Libsync
|
|||
$hash = Libzot::make_xchan_hash($channel['channel_guid'], $arr['channel']['channel_pubkey']);
|
||||
|
||||
|
||||
$r = q("update channel set channel_prvkey = '%s', channel_pubkey = '%s', channel_guid_sig = '%s',
|
||||
$r = q(
|
||||
"update channel set channel_prvkey = '%s', channel_pubkey = '%s', channel_guid_sig = '%s',
|
||||
channel_hash = '%s' where channel_id = %d",
|
||||
dbesc($arr['channel']['channel_prvkey']),
|
||||
dbesc($arr['channel']['channel_pubkey']),
|
||||
|
@ -1177,7 +1218,8 @@ class Libsync
|
|||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from channel where channel_id = %d",
|
||||
$r = q(
|
||||
"select * from channel where channel_id = %d",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
|
@ -1188,7 +1230,8 @@ class Libsync
|
|||
|
||||
$channel = $r[0];
|
||||
|
||||
$h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
|
||||
$h = q(
|
||||
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
|
||||
dbesc($arr['keychange']['old_hash']),
|
||||
dbesc(z_root())
|
||||
);
|
||||
|
@ -1202,11 +1245,13 @@ class Libsync
|
|||
}
|
||||
}
|
||||
|
||||
$x = q("select * from xchan where xchan_hash = '%s' ",
|
||||
$x = q(
|
||||
"select * from xchan where xchan_hash = '%s' ",
|
||||
dbesc($arr['keychange']['old_hash'])
|
||||
);
|
||||
|
||||
$check = q("select * from xchan where xchan_hash = '%s'",
|
||||
$check = q(
|
||||
"select * from xchan where xchan_hash = '%s'",
|
||||
dbesc($hash)
|
||||
);
|
||||
|
||||
|
@ -1222,19 +1267,19 @@ class Libsync
|
|||
}
|
||||
}
|
||||
|
||||
$a = q("select * from abook where abook_xchan = '%s' and abook_self = 1",
|
||||
$a = q(
|
||||
"select * from abook where abook_xchan = '%s' and abook_self = 1",
|
||||
dbesc($arr['keychange']['old_hash'])
|
||||
);
|
||||
|
||||
if ($a) {
|
||||
q("update abook set abook_xchan = '%s' where abook_id = %d",
|
||||
q(
|
||||
"update abook set abook_xchan = '%s' where abook_id = %d",
|
||||
dbesc($hash),
|
||||
intval($a[0]['abook_id'])
|
||||
);
|
||||
}
|
||||
|
||||
xchan_change_key($oldxchan, $newxchan, $arr['keychange']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,8 +39,9 @@ class Libzotdir
|
|||
}
|
||||
}
|
||||
|
||||
if (!$isadir)
|
||||
if (!$isadir) {
|
||||
set_config('system', 'directory_server', '');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,10 +49,11 @@ class Libzotdir
|
|||
{
|
||||
|
||||
|
||||
if ($observer)
|
||||
if ($observer) {
|
||||
$ret = get_xconfig($observer, 'directory', $setting);
|
||||
else
|
||||
} else {
|
||||
$ret = ((array_key_exists($setting, $_SESSION)) ? intval($_SESSION[$setting]) : false);
|
||||
}
|
||||
|
||||
if ($ret === false) {
|
||||
$ret = get_config('directory', $setting);
|
||||
|
@ -60,8 +62,9 @@ class Libzotdir
|
|||
}
|
||||
}
|
||||
|
||||
if ($setting === 'globaldir' && intval(get_config('system', 'localdir_hide')))
|
||||
if ($setting === 'globaldir' && intval(get_config('system', 'localdir_hide'))) {
|
||||
$ret = 1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
@ -116,7 +119,7 @@ class Libzotdir
|
|||
'$forumsurl' => $forumsurl,
|
||||
'$safemode' => array('safemode', t('Safe Mode'), $safe_mode, '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&safe="+(this.checked ? 1 : 0)\''),
|
||||
'$pubforums' => array('pubforums', t('Groups Only'), (($pubforums == 1) ? true : false), '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 1 : 0)\''),
|
||||
// '$collections' => array('collections', t('Collections Only'),(($pubforums == 2) ? true : false),'',array(t('No'), t('Yes')),' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 2 : 0)\''),
|
||||
// '$collections' => array('collections', t('Collections Only'),(($pubforums == 2) ? true : false),'',array(t('No'), t('Yes')),' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 2 : 0)\''),
|
||||
'$hide_local' => $hide_local,
|
||||
'$globaldir' => array('globaldir', t('This Website Only'), 1 - intval($globaldir), '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&global="+(this.checked ? 0 : 1)\''),
|
||||
'$activedir' => array('activedir', t('Recently Updated'), intval($activedir), '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&active="+(this.checked ? 1 : 0)\''),
|
||||
|
@ -153,7 +156,8 @@ class Libzotdir
|
|||
if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) {
|
||||
$xc = Libzot::import_xchan($zf['data'], 0, $ud);
|
||||
} else {
|
||||
q("update updates set ud_last = '%s' where ud_addr = '%s'",
|
||||
q(
|
||||
"update updates set ud_last = '%s' where ud_addr = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($ud['ud_addr'])
|
||||
);
|
||||
|
@ -178,7 +182,8 @@ class Libzotdir
|
|||
|
||||
logger('local_dir_update: uid: ' . $uid, LOGGER_DEBUG);
|
||||
|
||||
$p = q("select channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
|
||||
$p = q(
|
||||
"select channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -190,8 +195,9 @@ class Libzotdir
|
|||
|
||||
$profile['description'] = $p[0]['pdesc'];
|
||||
$profile['birthday'] = $p[0]['dob'];
|
||||
if ($age = age($p[0]['dob'], $p[0]['channel_timezone'], ''))
|
||||
if ($age = age($p[0]['dob'], $p[0]['channel_timezone'], '')) {
|
||||
$profile['age'] = $age;
|
||||
}
|
||||
|
||||
$profile['gender'] = $p[0]['gender'];
|
||||
$profile['marital'] = $p[0]['marital'];
|
||||
|
@ -207,25 +213,31 @@ class Libzotdir
|
|||
if ($p[0]['keywords']) {
|
||||
$tags = [];
|
||||
$k = explode(' ', $p[0]['keywords']);
|
||||
if ($k)
|
||||
foreach ($k as $kk)
|
||||
if (trim($kk))
|
||||
if ($k) {
|
||||
foreach ($k as $kk) {
|
||||
if (trim($kk)) {
|
||||
$tags[] = trim($kk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($tags)
|
||||
if ($tags) {
|
||||
$profile['keywords'] = $tags;
|
||||
}
|
||||
}
|
||||
|
||||
$hidden = (1 - intval($p[0]['publish']));
|
||||
|
||||
// logger('hidden: ' . $hidden);
|
||||
|
||||
$r = q("select xchan_hidden from xchan where xchan_hash = '%s' limit 1",
|
||||
$r = q(
|
||||
"select xchan_hidden from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($p[0]['channel_hash'])
|
||||
);
|
||||
|
||||
if (intval($r[0]['xchan_hidden']) != $hidden) {
|
||||
$r = q("update xchan set xchan_hidden = %d where xchan_hash = '%s'",
|
||||
$r = q(
|
||||
"update xchan set xchan_hidden = %d where xchan_hash = '%s'",
|
||||
intval($hidden),
|
||||
dbesc($p[0]['channel_hash'])
|
||||
);
|
||||
|
@ -240,14 +252,15 @@ class Libzotdir
|
|||
self::import_directory_profile($hash, $arr['profile'], $address, 0);
|
||||
} else {
|
||||
// they may have made it private
|
||||
$r = q("delete from xprof where xprof_hash = '%s'",
|
||||
$r = q(
|
||||
"delete from xprof where xprof_hash = '%s'",
|
||||
dbesc($hash)
|
||||
);
|
||||
$r = q("delete from xtag where xtag_hash = '%s'",
|
||||
$r = q(
|
||||
"delete from xtag where xtag_hash = '%s'",
|
||||
dbesc($hash)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$ud_hash = random_string() . '@' . App::get_hostname();
|
||||
|
@ -270,8 +283,9 @@ class Libzotdir
|
|||
{
|
||||
|
||||
logger('import_directory_profile', LOGGER_DEBUG);
|
||||
if (!$hash)
|
||||
if (!$hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$maxlen = get_max_import_size();
|
||||
|
@ -315,19 +329,23 @@ class Libzotdir
|
|||
|
||||
|
||||
if (in_arrayi('nsfw', $clean) || in_arrayi('adult', $clean)) {
|
||||
q("update xchan set xchan_selfcensored = 1 where xchan_hash = '%s'",
|
||||
q(
|
||||
"update xchan set xchan_selfcensored = 1 where xchan_hash = '%s'",
|
||||
dbesc($hash)
|
||||
);
|
||||
}
|
||||
|
||||
$r = q("select * from xprof where xprof_hash = '%s' limit 1",
|
||||
$r = q(
|
||||
"select * from xprof where xprof_hash = '%s' limit 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
|
||||
if ($arr['xprof_age'] > 150)
|
||||
if ($arr['xprof_age'] > 150) {
|
||||
$arr['xprof_age'] = 150;
|
||||
if ($arr['xprof_age'] < 0)
|
||||
}
|
||||
if ($arr['xprof_age'] < 0) {
|
||||
$arr['xprof_age'] = 0;
|
||||
}
|
||||
|
||||
if ($r) {
|
||||
$update = false;
|
||||
|
@ -339,7 +357,8 @@ class Libzotdir
|
|||
}
|
||||
}
|
||||
if ($update) {
|
||||
q("update xprof set
|
||||
q(
|
||||
"update xprof set
|
||||
xprof_desc = '%s',
|
||||
xprof_dob = '%s',
|
||||
xprof_age = %d,
|
||||
|
@ -377,7 +396,8 @@ class Libzotdir
|
|||
} else {
|
||||
$update = true;
|
||||
logger('New profile');
|
||||
q("insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_age, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_about, xprof_homepage, xprof_hometown, xprof_keywords, xprof_pronouns) values ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||
q(
|
||||
"insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_age, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_about, xprof_homepage, xprof_hometown, xprof_keywords, xprof_pronouns) values ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||
dbesc($arr['xprof_hash']),
|
||||
dbesc($arr['xprof_desc']),
|
||||
dbesc($arr['xprof_dob']),
|
||||
|
@ -417,7 +437,8 @@ class Libzotdir
|
|||
self::update_modtime($arr['xprof_hash'], new_uuid(), $addr, $ud_flags);
|
||||
}
|
||||
|
||||
q("update xchan set xchan_updated = '%s' where xchan_hash = '%s'",
|
||||
q(
|
||||
"update xchan set xchan_updated = '%s' where xchan_hash = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($arr['xprof_hash'])
|
||||
);
|
||||
|
@ -436,13 +457,15 @@ class Libzotdir
|
|||
{
|
||||
|
||||
$existing = [];
|
||||
$r = q("select * from xtag where xtag_hash = '%s' and xtag_flags = 0",
|
||||
$r = q(
|
||||
"select * from xtag where xtag_hash = '%s' and xtag_flags = 0",
|
||||
dbesc($hash)
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
foreach ($r as $rr)
|
||||
foreach ($r as $rr) {
|
||||
$existing[] = $rr['xtag_term'];
|
||||
}
|
||||
}
|
||||
|
||||
$clean = [];
|
||||
|
@ -453,15 +476,18 @@ class Libzotdir
|
|||
}
|
||||
|
||||
foreach ($existing as $x) {
|
||||
if (!in_array($x, $clean))
|
||||
$r = q("delete from xtag where xtag_hash = '%s' and xtag_term = '%s' and xtag_flags = 0",
|
||||
if (!in_array($x, $clean)) {
|
||||
$r = q(
|
||||
"delete from xtag where xtag_hash = '%s' and xtag_term = '%s' and xtag_flags = 0",
|
||||
dbesc($hash),
|
||||
dbesc($x)
|
||||
);
|
||||
}
|
||||
}
|
||||
foreach ($clean as $x) {
|
||||
if (!in_array($x, $existing)) {
|
||||
$r = q("insert into xtag ( xtag_hash, xtag_term, xtag_flags) values ( '%s' ,'%s', 0 )",
|
||||
$r = q(
|
||||
"insert into xtag ( xtag_hash, xtag_term, xtag_flags) values ( '%s' ,'%s', 0 )",
|
||||
dbesc($hash),
|
||||
dbesc($x)
|
||||
);
|
||||
|
@ -484,11 +510,13 @@ class Libzotdir
|
|||
|
||||
$dirmode = intval(get_config('system', 'directory_mode'));
|
||||
|
||||
if ($dirmode == DIRECTORY_MODE_NORMAL)
|
||||
if ($dirmode == DIRECTORY_MODE_NORMAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($flags) {
|
||||
q("insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' )",
|
||||
q(
|
||||
"insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' )",
|
||||
dbesc($hash),
|
||||
dbesc($guid),
|
||||
dbesc(datetime_convert()),
|
||||
|
@ -496,13 +524,12 @@ class Libzotdir
|
|||
dbesc($addr)
|
||||
);
|
||||
} else {
|
||||
q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ",
|
||||
q(
|
||||
"update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($addr),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
/**
|
||||
|
@ -6,7 +7,6 @@ namespace Zotlabs\Lib;
|
|||
*/
|
||||
|
||||
use Michelf\MarkdownExtra;
|
||||
|
||||
use League\HTMLToMarkdown\HtmlConverter;
|
||||
use League\HTMLToMarkdown\Environment;
|
||||
use League\HTMLToMarkdown\Converter\ConverterInterface;
|
||||
|
@ -110,10 +110,11 @@ class Markdown
|
|||
$res = '';
|
||||
$is_zid = is_matrix_url(trim($match[0]));
|
||||
|
||||
if ($is_zid)
|
||||
if ($is_zid) {
|
||||
$res = $match[1] . '[zrl=' . $match[2] . $match[3] . ']' . $match[2] . $match[3] . '[/zrl]';
|
||||
else
|
||||
} else {
|
||||
$res = $match[1] . '[url=' . $match[2] . $match[3] . ']' . $match[2] . $match[3] . '[/url]';
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -123,10 +124,11 @@ class Markdown
|
|||
$res = '';
|
||||
$is_zid = is_matrix_url(trim($match[1]));
|
||||
|
||||
if ($is_zid)
|
||||
if ($is_zid) {
|
||||
$res = '[zmg]' . $match[1] . '[/zmg]';
|
||||
else
|
||||
} else {
|
||||
$res = $match[0];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -136,10 +138,11 @@ class Markdown
|
|||
$res = '';
|
||||
$is_zid = is_matrix_url(trim($match[3]));
|
||||
|
||||
if ($is_zid)
|
||||
if ($is_zid) {
|
||||
$res = '[zmg=' . $match[1] . 'x' . $match[2] . ']' . $match[3] . '[/zmg]';
|
||||
else
|
||||
} else {
|
||||
$res = $match[0];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
@ -159,39 +162,46 @@ class Markdown
|
|||
|
||||
$author = "";
|
||||
preg_match("/author='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$author = urldecode($matches[1]);
|
||||
}
|
||||
|
||||
$link = "";
|
||||
preg_match("/link='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$link = $matches[1];
|
||||
}
|
||||
|
||||
$avatar = "";
|
||||
preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$avatar = $matches[1];
|
||||
}
|
||||
|
||||
$profile = "";
|
||||
preg_match("/profile='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$profile = $matches[1];
|
||||
}
|
||||
|
||||
$posted = "";
|
||||
preg_match("/posted='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$posted = $matches[1];
|
||||
}
|
||||
|
||||
// message_id is never used, do we still need it?
|
||||
$message_id = "";
|
||||
preg_match("/message_id='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$message_id = $matches[1];
|
||||
}
|
||||
|
||||
if (!$message_id) {
|
||||
preg_match("/guid='(.*?)'/ism", $attributes, $matches);
|
||||
if ($matches[1] != "")
|
||||
if ($matches[1] != "") {
|
||||
$message_id = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,12 +209,14 @@ class Markdown
|
|||
|
||||
$headline = '';
|
||||
|
||||
if ($avatar != "")
|
||||
if ($avatar != "") {
|
||||
$headline .= '[url=' . zid($profile) . '][img]' . $avatar . '[/img][/url]';
|
||||
}
|
||||
|
||||
// Bob Smith wrote the following post 2 hours ago
|
||||
|
||||
$fmt = sprintf(t('%1$s wrote the following %2$s %3$s'),
|
||||
$fmt = sprintf(
|
||||
t('%1$s wrote the following %2$s %3$s'),
|
||||
'[url=' . zid($profile) . ']' . $author . '[/url]',
|
||||
'[url=' . zid($link) . ']' . t('post') . '[/url]',
|
||||
$reldate
|
||||
|
@ -233,8 +245,11 @@ class Markdown
|
|||
* Transform #tags, strip off the [url] and replace spaces with underscore
|
||||
*/
|
||||
|
||||
$Text = preg_replace_callback('/#\[([zu])rl\=(.*?)\](.*?)\[\/[(zu)]rl\]/i',
|
||||
create_function('$match', 'return \'#\'. str_replace(\' \', \'_\', $match[3]);'), $Text);
|
||||
$Text = preg_replace_callback(
|
||||
'/#\[([zu])rl\=(.*?)\](.*?)\[\/[(zu)]rl\]/i',
|
||||
create_function('$match', 'return \'#\'. str_replace(\' \', \'_\', $match[3]);'),
|
||||
$Text
|
||||
);
|
||||
|
||||
$Text = preg_replace('/#\^\[([zu])rl\=(.*?)\](.*?)\[\/([zu])rl\]/i', '[$1rl=$2]$3[/$4rl]', $Text);
|
||||
|
||||
|
@ -336,64 +351,64 @@ class Markdown
|
|||
|
||||
class TableConverter implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(ElementInterface $element)
|
||||
{
|
||||
switch ($element->getTagName()) {
|
||||
case 'tr':
|
||||
$line = [];
|
||||
$i = 1;
|
||||
foreach ($element->getChildren() as $td) {
|
||||
$i++;
|
||||
$v = $td->getValue();
|
||||
$v = trim($v);
|
||||
if ($i % 2 === 0 || $v !== '') {
|
||||
$line[] = $v;
|
||||
}
|
||||
}
|
||||
return '| ' . implode(' | ', $line) . " |\n";
|
||||
case 'td':
|
||||
case 'th':
|
||||
return trim($element->getValue());
|
||||
case 'tbody':
|
||||
return trim($element->getValue());
|
||||
case 'thead':
|
||||
$headerLine = reset($element->getChildren())->getValue();
|
||||
$headers = explode(' | ', trim(trim($headerLine, "\n"), '|'));
|
||||
$hr = [];
|
||||
foreach ($headers as $td) {
|
||||
$length = strlen(trim($td)) + 2;
|
||||
$hr[] = str_repeat('-', $length > 3 ? $length : 3);
|
||||
}
|
||||
$hr = '|' . implode('|', $hr) . '|';
|
||||
return $headerLine . $hr . "\n";
|
||||
case 'table':
|
||||
$inner = $element->getValue();
|
||||
if (strpos($inner, '-----') === false) {
|
||||
$inner = explode("\n", $inner);
|
||||
$single = explode(' | ', trim($inner[0], '|'));
|
||||
$hr = [];
|
||||
foreach ($single as $td) {
|
||||
$length = strlen(trim($td)) + 2;
|
||||
$hr[] = str_repeat('-', $length > 3 ? $length : 3);
|
||||
}
|
||||
$hr = '|' . implode('|', $hr) . '|';
|
||||
array_splice($inner, 1, 0, $hr);
|
||||
$inner = implode("\n", $inner);
|
||||
}
|
||||
return trim($inner) . "\n\n";
|
||||
}
|
||||
return $element->getValue();
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedTags()
|
||||
{
|
||||
return array('table', 'tr', 'thead', 'td', 'tbody');
|
||||
}
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convert(ElementInterface $element)
|
||||
{
|
||||
switch ($element->getTagName()) {
|
||||
case 'tr':
|
||||
$line = [];
|
||||
$i = 1;
|
||||
foreach ($element->getChildren() as $td) {
|
||||
$i++;
|
||||
$v = $td->getValue();
|
||||
$v = trim($v);
|
||||
if ($i % 2 === 0 || $v !== '') {
|
||||
$line[] = $v;
|
||||
}
|
||||
}
|
||||
return '| ' . implode(' | ', $line) . " |\n";
|
||||
case 'td':
|
||||
case 'th':
|
||||
return trim($element->getValue());
|
||||
case 'tbody':
|
||||
return trim($element->getValue());
|
||||
case 'thead':
|
||||
$headerLine = reset($element->getChildren())->getValue();
|
||||
$headers = explode(' | ', trim(trim($headerLine, "\n"), '|'));
|
||||
$hr = [];
|
||||
foreach ($headers as $td) {
|
||||
$length = strlen(trim($td)) + 2;
|
||||
$hr[] = str_repeat('-', $length > 3 ? $length : 3);
|
||||
}
|
||||
$hr = '|' . implode('|', $hr) . '|';
|
||||
return $headerLine . $hr . "\n";
|
||||
case 'table':
|
||||
$inner = $element->getValue();
|
||||
if (strpos($inner, '-----') === false) {
|
||||
$inner = explode("\n", $inner);
|
||||
$single = explode(' | ', trim($inner[0], '|'));
|
||||
$hr = [];
|
||||
foreach ($single as $td) {
|
||||
$length = strlen(trim($td)) + 2;
|
||||
$hr[] = str_repeat('-', $length > 3 ? $length : 3);
|
||||
}
|
||||
$hr = '|' . implode('|', $hr) . '|';
|
||||
array_splice($inner, 1, 0, $hr);
|
||||
$inner = implode("\n", $inner);
|
||||
}
|
||||
return trim($inner) . "\n\n";
|
||||
}
|
||||
return $element->getValue();
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedTags()
|
||||
{
|
||||
return array('table', 'tr', 'thead', 'td', 'tbody');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@ class MarkdownSoap
|
|||
public function extract_code($s)
|
||||
{
|
||||
|
||||
$text = preg_replace_callback('{
|
||||
$text = preg_replace_callback(
|
||||
'{
|
||||
(?:\n\n|\A\n?)
|
||||
( # $1 = the code block -- one or more lines, starting with a space/tab
|
||||
(?>
|
||||
|
@ -77,7 +78,9 @@ class MarkdownSoap
|
|||
)
|
||||
((?=^[ ]{0,' . '4' . '}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
|
||||
}xm',
|
||||
[$this, 'encode_code'], $s);
|
||||
[$this, 'encode_code'],
|
||||
$s
|
||||
);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
|
|
@ -5,27 +5,30 @@ namespace Zotlabs\Lib;
|
|||
use App;
|
||||
use Zotlabs\Lib\PConfig;
|
||||
|
||||
|
||||
class MastAPI
|
||||
{
|
||||
|
||||
public static function format_channel($channel)
|
||||
{
|
||||
$p = q("select * from profile where uid = %d and is_default = 1",
|
||||
$p = q(
|
||||
"select * from profile where uid = %d and is_default = 1",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
$a = q("select * from account where account_id = %d",
|
||||
$a = q(
|
||||
"select * from account where account_id = %d",
|
||||
intval($channel['channel_account_id'])
|
||||
);
|
||||
|
||||
$followers = q("select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 ",
|
||||
$followers = q(
|
||||
"select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 ",
|
||||
intval($channel['channel_id']),
|
||||
intval($channel['channel_id']),
|
||||
dbesc($channel['channel_hash'])
|
||||
);
|
||||
|
||||
$following = q("select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'my_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0",
|
||||
$following = q(
|
||||
"select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'my_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0",
|
||||
intval($channel['channel_id']),
|
||||
intval($channel['channel_id']),
|
||||
dbesc($channel['channel_hash'])
|
||||
|
@ -36,7 +39,8 @@ class MastAPI
|
|||
$item_normal = item_normal();
|
||||
|
||||
// count posts/comments
|
||||
$statuses = q("SELECT COUNT(id) as total FROM item
|
||||
$statuses = q(
|
||||
"SELECT COUNT(id) as total FROM item
|
||||
WHERE uid = %d
|
||||
AND author_xchan = '%s' $item_normal ",
|
||||
intval($channel['channel_id']),
|
||||
|
@ -100,7 +104,5 @@ class MastAPI
|
|||
$ret['contact_account'] = self::format_channel($adminsx);
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,89 +2,94 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
class MessageFilter
|
||||
{
|
||||
|
||||
|
||||
class MessageFilter {
|
||||
public static function evaluate($item, $incl, $excl)
|
||||
{
|
||||
|
||||
require_once('include/html2plain.php');
|
||||
|
||||
public static function evaluate($item, $incl, $excl) {
|
||||
$text = prepare_text($item['body'], ((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode'));
|
||||
$text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
|
||||
|
||||
require_once('include/html2plain.php');
|
||||
$lang = null;
|
||||
|
||||
$text = prepare_text($item['body'],((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode'));
|
||||
$text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
|
||||
if ((strpos($incl, 'lang=') !== false) || (strpos($excl, 'lang=') !== false) || (strpos($incl, 'lang!=') !== false) || (strpos($excl, 'lang!=') !== false)) {
|
||||
$lang = detect_language($text);
|
||||
}
|
||||
|
||||
$lang = null;
|
||||
$tags = ((isset($item['term']) && is_array($item['term']) && count($item['term'])) ? $item['term'] : false);
|
||||
|
||||
if((strpos($incl,'lang=') !== false) || (strpos($excl,'lang=') !== false) || (strpos($incl,'lang!=') !== false) || (strpos($excl,'lang!=') !== false)) {
|
||||
$lang = detect_language($text);
|
||||
}
|
||||
// exclude always has priority
|
||||
|
||||
$tags = ((isset($item['term']) && is_array($item['term']) && count($item['term'])) ? $item['term'] : false);
|
||||
$exclude = (($excl) ? explode("\n", $excl) : null);
|
||||
|
||||
// exclude always has priority
|
||||
if ($exclude) {
|
||||
foreach ($exclude as $word) {
|
||||
$word = trim($word);
|
||||
if (! $word) {
|
||||
continue;
|
||||
}
|
||||
if (substr($word, 0, 1) === '#' && $tags) {
|
||||
foreach ($tags as $t) {
|
||||
if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} elseif (substr($word, 0, 1) === '$' && $tags) {
|
||||
foreach ($tags as $t) {
|
||||
if (($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) {
|
||||
return false;
|
||||
} elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) {
|
||||
return false;
|
||||
} elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) {
|
||||
return false;
|
||||
} elseif (stristr($text, $word) !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$exclude = (($excl) ? explode("\n",$excl) : null);
|
||||
|
||||
if($exclude) {
|
||||
foreach($exclude as $word) {
|
||||
$word = trim($word);
|
||||
if(! $word)
|
||||
continue;
|
||||
if(substr($word,0,1) === '#' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return false;
|
||||
}
|
||||
elseif(substr($word,0,1) === '$' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if(($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return false;
|
||||
}
|
||||
elseif((strpos($word,'/') === 0) && preg_match($word,$text))
|
||||
return false;
|
||||
elseif((strpos($word,'lang=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,5))) == 0))
|
||||
return false;
|
||||
elseif((strpos($word,'lang!=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,6))) != 0))
|
||||
return false;
|
||||
elseif(stristr($text,$word) !== false)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$include = (($incl) ? explode("\n",$incl) : null);
|
||||
|
||||
if($include) {
|
||||
foreach($include as $word) {
|
||||
$word = trim($word);
|
||||
if(! $word)
|
||||
continue;
|
||||
if(substr($word,0,1) === '#' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return true;
|
||||
}
|
||||
elseif(substr($word,0,1) === '$' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if(($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return true;
|
||||
}
|
||||
elseif((strpos($word,'/') === 0) && preg_match($word,$text))
|
||||
return true;
|
||||
elseif((strpos($word,'lang=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,5))) == 0))
|
||||
return true;
|
||||
elseif((strpos($word,'lang!=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,6))) != 0))
|
||||
return true;
|
||||
elseif(stristr($text,$word) !== false)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
$include = (($incl) ? explode("\n", $incl) : null);
|
||||
|
||||
if ($include) {
|
||||
foreach ($include as $word) {
|
||||
$word = trim($word);
|
||||
if (! $word) {
|
||||
continue;
|
||||
}
|
||||
if (substr($word, 0, 1) === '#' && $tags) {
|
||||
foreach ($tags as $t) {
|
||||
if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} elseif (substr($word, 0, 1) === '$' && $tags) {
|
||||
foreach ($tags as $t) {
|
||||
if (($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) {
|
||||
return true;
|
||||
} elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) {
|
||||
return true;
|
||||
} elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) {
|
||||
return true;
|
||||
} elseif (stristr($text, $word) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,43 +2,40 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
class Nodeinfo
|
||||
{
|
||||
|
||||
|
||||
class Nodeinfo {
|
||||
|
||||
public static function fetch($url) {
|
||||
$href = EMPTY_STR;
|
||||
$m = parse_url($url);
|
||||
if ($m['scheme'] && $m['host']) {
|
||||
$s = $m['scheme'] . '://' . $m['host'] . '/.well-known/nodeinfo';
|
||||
$n = z_fetch_url($s);
|
||||
if ($n['success']) {
|
||||
$j = json_decode($n['body'], true);
|
||||
if ($j && $j['links']) {
|
||||
// lemmy just sends one result
|
||||
if (isset($j['links']['rel'])) {
|
||||
if ($j['links']['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($j['links']['href'])) {
|
||||
$href = $j['links']['href'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($j['links'] as $l) {
|
||||
if (isset($l['rel']) && $l['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($l['href'])) {
|
||||
$href = $l['href'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($href) {
|
||||
$n = z_fetch_url($href);
|
||||
if ($n['success']) {
|
||||
return json_decode($n['body'],true);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static function fetch($url)
|
||||
{
|
||||
$href = EMPTY_STR;
|
||||
$m = parse_url($url);
|
||||
if ($m['scheme'] && $m['host']) {
|
||||
$s = $m['scheme'] . '://' . $m['host'] . '/.well-known/nodeinfo';
|
||||
$n = z_fetch_url($s);
|
||||
if ($n['success']) {
|
||||
$j = json_decode($n['body'], true);
|
||||
if ($j && $j['links']) {
|
||||
// lemmy just sends one result
|
||||
if (isset($j['links']['rel'])) {
|
||||
if ($j['links']['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($j['links']['href'])) {
|
||||
$href = $j['links']['href'];
|
||||
}
|
||||
} else {
|
||||
foreach ($j['links'] as $l) {
|
||||
if (isset($l['rel']) && $l['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($l['href'])) {
|
||||
$href = $l['href'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($href) {
|
||||
$n = z_fetch_url($href);
|
||||
if ($n['success']) {
|
||||
return json_decode($n['body'], true);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,193 +18,212 @@ use App;
|
|||
* The old (deprecated?) way to access a PConfig value is:
|
||||
* @code{.php}$var = get_pconfig(local_channel(), 'category', 'key');@endcode
|
||||
*/
|
||||
class PConfig {
|
||||
class PConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Loads all configuration values of a channel into a cached storage.
|
||||
*
|
||||
* All configuration values of the given channel are stored in global cache
|
||||
* which is available under the global variable App::$config[$uid].
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @return void|false Nothing or false if $uid is null or false
|
||||
*/
|
||||
public static function Load($uid) {
|
||||
if(is_null($uid) || $uid === false)
|
||||
return false;
|
||||
/**
|
||||
* @brief Loads all configuration values of a channel into a cached storage.
|
||||
*
|
||||
* All configuration values of the given channel are stored in global cache
|
||||
* which is available under the global variable App::$config[$uid].
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @return void|false Nothing or false if $uid is null or false
|
||||
*/
|
||||
public static function Load($uid)
|
||||
{
|
||||
if (is_null($uid) || $uid === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(! is_array(App::$config)) {
|
||||
btlogger('App::$config not an array');
|
||||
}
|
||||
if (! is_array(App::$config)) {
|
||||
btlogger('App::$config not an array');
|
||||
}
|
||||
|
||||
if(! array_key_exists($uid, App::$config)) {
|
||||
App::$config[$uid] = [];
|
||||
}
|
||||
if (! array_key_exists($uid, App::$config)) {
|
||||
App::$config[$uid] = [];
|
||||
}
|
||||
|
||||
if(! is_array(App::$config[$uid])) {
|
||||
btlogger('App::$config[$uid] not an array: ' . $uid);
|
||||
}
|
||||
if (! is_array(App::$config[$uid])) {
|
||||
btlogger('App::$config[$uid] not an array: ' . $uid);
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM pconfig WHERE uid = %d",
|
||||
intval($uid)
|
||||
);
|
||||
$r = q(
|
||||
"SELECT * FROM pconfig WHERE uid = %d",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$c = $rr['cat'];
|
||||
if(! array_key_exists($c, App::$config[$uid])) {
|
||||
App::$config[$uid][$c] = [];
|
||||
App::$config[$uid][$c]['config_loaded'] = true;
|
||||
}
|
||||
App::$config[$uid][$c][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$c = $rr['cat'];
|
||||
if (! array_key_exists($c, App::$config[$uid])) {
|
||||
App::$config[$uid][$c] = [];
|
||||
App::$config[$uid][$c]['config_loaded'] = true;
|
||||
}
|
||||
App::$config[$uid][$c][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular channel's config variable given the category name
|
||||
* ($family) and a key.
|
||||
*
|
||||
* Get a particular channel's config value from the given category ($family)
|
||||
* and the $key from a cached storage in App::$config[$uid].
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param mixed $default (optional, default false)
|
||||
* Default value to return if key does not exist
|
||||
* @return mixed Stored value or false if it does not exist
|
||||
*/
|
||||
public static function Get($uid, $family, $key, $default = false) {
|
||||
/**
|
||||
* @brief Get a particular channel's config variable given the category name
|
||||
* ($family) and a key.
|
||||
*
|
||||
* Get a particular channel's config value from the given category ($family)
|
||||
* and the $key from a cached storage in App::$config[$uid].
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param mixed $default (optional, default false)
|
||||
* Default value to return if key does not exist
|
||||
* @return mixed Stored value or false if it does not exist
|
||||
*/
|
||||
public static function Get($uid, $family, $key, $default = false)
|
||||
{
|
||||
|
||||
if(is_null($uid) || $uid === false)
|
||||
return $default;
|
||||
if (is_null($uid) || $uid === false) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if(! array_key_exists($uid, App::$config))
|
||||
self::Load($uid);
|
||||
if (! array_key_exists($uid, App::$config)) {
|
||||
self::Load($uid);
|
||||
}
|
||||
|
||||
if((! array_key_exists($family, App::$config[$uid])) || (! array_key_exists($key, App::$config[$uid][$family])))
|
||||
return $default;
|
||||
if ((! array_key_exists($family, App::$config[$uid])) || (! array_key_exists($key, App::$config[$uid][$family]))) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return unserialise(App::$config[$uid][$family][$key]);
|
||||
}
|
||||
return unserialise(App::$config[$uid][$family][$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for a channel.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the channel_id $uid.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
public static function Set($uid, $family, $key, $value) {
|
||||
/**
|
||||
* @brief Sets a configuration value for a channel.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the channel_id $uid.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
public static function Set($uid, $family, $key, $value)
|
||||
{
|
||||
|
||||
// this catches subtle errors where this function has been called
|
||||
// with local_channel() when not logged in (which returns false)
|
||||
// and throws an error in array_key_exists below.
|
||||
// we provide a function backtrace in the logs so that we can find
|
||||
// and fix the calling function.
|
||||
// this catches subtle errors where this function has been called
|
||||
// with local_channel() when not logged in (which returns false)
|
||||
// and throws an error in array_key_exists below.
|
||||
// we provide a function backtrace in the logs so that we can find
|
||||
// and fix the calling function.
|
||||
|
||||
if(is_null($uid) || $uid === false) {
|
||||
btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR);
|
||||
return;
|
||||
}
|
||||
if (is_null($uid) || $uid === false) {
|
||||
btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(self::Get($uid, $family, $key) === false) {
|
||||
if(! array_key_exists($uid, App::$config))
|
||||
App::$config[$uid] = [];
|
||||
if(! array_key_exists($family, App::$config[$uid]))
|
||||
App::$config[$uid][$family] = [];
|
||||
if (self::Get($uid, $family, $key) === false) {
|
||||
if (! array_key_exists($uid, App::$config)) {
|
||||
App::$config[$uid] = [];
|
||||
}
|
||||
if (! array_key_exists($family, App::$config[$uid])) {
|
||||
App::$config[$uid][$family] = [];
|
||||
}
|
||||
|
||||
$ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$ret = q(
|
||||
"INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
} else {
|
||||
$ret = q(
|
||||
"UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
$ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
// keep a separate copy for all variables which were
|
||||
// set in the life of this page. We need this to
|
||||
// synchronise channel clones.
|
||||
|
||||
// keep a separate copy for all variables which were
|
||||
// set in the life of this page. We need this to
|
||||
// synchronise channel clones.
|
||||
if (! array_key_exists('transient', App::$config[$uid])) {
|
||||
App::$config[$uid]['transient'] = [];
|
||||
}
|
||||
if (! array_key_exists($family, App::$config[$uid]['transient'])) {
|
||||
App::$config[$uid]['transient'][$family] = [];
|
||||
}
|
||||
|
||||
if(! array_key_exists('transient', App::$config[$uid]))
|
||||
App::$config[$uid]['transient'] = [];
|
||||
if(! array_key_exists($family, App::$config[$uid]['transient']))
|
||||
App::$config[$uid]['transient'][$family] = [];
|
||||
App::$config[$uid][$family][$key] = $value;
|
||||
App::$config[$uid]['transient'][$family][$key] = $value;
|
||||
|
||||
App::$config[$uid][$family][$key] = $value;
|
||||
App::$config[$uid]['transient'][$family][$key] = $value;
|
||||
if ($ret) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if($ret)
|
||||
return $value;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the channel's configuration.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$uid]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function Delete($uid, $family, $key) {
|
||||
/**
|
||||
* @brief Deletes the given key from the channel's configuration.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$uid]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function Delete($uid, $family, $key)
|
||||
{
|
||||
|
||||
if(is_null($uid) || $uid === false)
|
||||
return false;
|
||||
if (is_null($uid) || $uid === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ret = false;
|
||||
$ret = false;
|
||||
|
||||
if(array_key_exists($uid, App::$config)
|
||||
&& is_array(App::$config['uid'])
|
||||
&& array_key_exists($family, App::$config['uid'])
|
||||
&& array_key_exists($key, App::$config[$uid][$family]))
|
||||
unset(App::$config[$uid][$family][$key]);
|
||||
if (
|
||||
array_key_exists($uid, App::$config)
|
||||
&& is_array(App::$config['uid'])
|
||||
&& array_key_exists($family, App::$config['uid'])
|
||||
&& array_key_exists($key, App::$config[$uid][$family])
|
||||
) {
|
||||
unset(App::$config[$uid][$family][$key]);
|
||||
}
|
||||
|
||||
$ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
$ret = q(
|
||||
"DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,157 +21,168 @@ use Zotlabs\Access\Permissions;
|
|||
* These answer the question "Can Joe view *this* album/photo?".
|
||||
*/
|
||||
|
||||
class Permcat {
|
||||
class Permcat
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $permcats = [];
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $permcats = [];
|
||||
|
||||
/**
|
||||
* @brief Permcat constructor.
|
||||
*
|
||||
* @param int $channel_id
|
||||
*/
|
||||
public function __construct($channel_id) {
|
||||
/**
|
||||
* @brief Permcat constructor.
|
||||
*
|
||||
* @param int $channel_id
|
||||
*/
|
||||
public function __construct($channel_id)
|
||||
{
|
||||
|
||||
$perms = [];
|
||||
$perms = [];
|
||||
|
||||
// first check role perms for a perms_connect setting
|
||||
// first check role perms for a perms_connect setting
|
||||
|
||||
$role = get_pconfig($channel_id,'system','permissions_role');
|
||||
if($role) {
|
||||
$x = PermissionRoles::role_perms($role);
|
||||
if($x['perms_connect']) {
|
||||
$perms = Permissions::FilledPerms($x['perms_connect']);
|
||||
}
|
||||
}
|
||||
$role = get_pconfig($channel_id, 'system', 'permissions_role');
|
||||
if ($role) {
|
||||
$x = PermissionRoles::role_perms($role);
|
||||
if ($x['perms_connect']) {
|
||||
$perms = Permissions::FilledPerms($x['perms_connect']);
|
||||
}
|
||||
}
|
||||
|
||||
// if no role perms it may be a custom role, see if there any autoperms
|
||||
// if no role perms it may be a custom role, see if there any autoperms
|
||||
|
||||
if(! $perms) {
|
||||
$perms = Permissions::FilledAutoPerms($channel_id);
|
||||
}
|
||||
if (! $perms) {
|
||||
$perms = Permissions::FilledAutoPerms($channel_id);
|
||||
}
|
||||
|
||||
// if no autoperms it may be a custom role with manual perms
|
||||
// if no autoperms it may be a custom role with manual perms
|
||||
|
||||
if(! $perms) {
|
||||
$c = channelx_by_n($channel_id);
|
||||
if($c) {
|
||||
$perms = Permissions::FilledPerms(get_abconfig($channel_id,$c['channel_hash'],'system','my_perms',EMPTY_STR));
|
||||
}
|
||||
}
|
||||
if (! $perms) {
|
||||
$c = channelx_by_n($channel_id);
|
||||
if ($c) {
|
||||
$perms = Permissions::FilledPerms(get_abconfig($channel_id, $c['channel_hash'], 'system', 'my_perms', EMPTY_STR));
|
||||
}
|
||||
}
|
||||
|
||||
// nothing was found - create a filled permission array where all permissions are 0
|
||||
// nothing was found - create a filled permission array where all permissions are 0
|
||||
|
||||
if(! $perms) {
|
||||
$perms = Permissions::FilledPerms([]);
|
||||
}
|
||||
if (! $perms) {
|
||||
$perms = Permissions::FilledPerms([]);
|
||||
}
|
||||
|
||||
$this->permcats[] = [
|
||||
'name' => 'default',
|
||||
'localname' => t('default','permcat'),
|
||||
'perms' => Permissions::Operms($perms),
|
||||
'system' => 1
|
||||
];
|
||||
$this->permcats[] = [
|
||||
'name' => 'default',
|
||||
'localname' => t('default', 'permcat'),
|
||||
'perms' => Permissions::Operms($perms),
|
||||
'system' => 1
|
||||
];
|
||||
|
||||
|
||||
$p = $this->load_permcats($channel_id);
|
||||
if($p) {
|
||||
for($x = 0; $x < count($p); $x++) {
|
||||
$this->permcats[] = [
|
||||
'name' => $p[$x][0],
|
||||
'localname' => $p[$x][1],
|
||||
'perms' => Permissions::Operms(Permissions::FilledPerms($p[$x][2])),
|
||||
'system' => intval($p[$x][3])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$p = $this->load_permcats($channel_id);
|
||||
if ($p) {
|
||||
for ($x = 0; $x < count($p); $x++) {
|
||||
$this->permcats[] = [
|
||||
'name' => $p[$x][0],
|
||||
'localname' => $p[$x][1],
|
||||
'perms' => Permissions::Operms(Permissions::FilledPerms($p[$x][2])),
|
||||
'system' => intval($p[$x][3])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return array with permcats.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listing() {
|
||||
return $this->permcats;
|
||||
}
|
||||
/**
|
||||
* @brief Return array with permcats.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listing()
|
||||
{
|
||||
return $this->permcats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
* * \e array with permcats
|
||||
* * \e bool \b error if $name not found in permcats true
|
||||
*/
|
||||
public function fetch($name) {
|
||||
if($name && $this->permcats) {
|
||||
foreach($this->permcats as $permcat) {
|
||||
if(strcasecmp($permcat['name'], $name) === 0) {
|
||||
return $permcat;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
* * \e array with permcats
|
||||
* * \e bool \b error if $name not found in permcats true
|
||||
*/
|
||||
public function fetch($name)
|
||||
{
|
||||
if ($name && $this->permcats) {
|
||||
foreach ($this->permcats as $permcat) {
|
||||
if (strcasecmp($permcat['name'], $name) === 0) {
|
||||
return $permcat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['error' => true];
|
||||
}
|
||||
return ['error' => true];
|
||||
}
|
||||
|
||||
public function load_permcats($uid) {
|
||||
public function load_permcats($uid)
|
||||
{
|
||||
|
||||
$permcats = [
|
||||
[ 'follower', t('follower','permcat'),
|
||||
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
|
||||
'post_like' ], 1
|
||||
],
|
||||
[ 'contributor', t('contributor','permcat'),
|
||||
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
|
||||
'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
|
||||
],
|
||||
[ 'publisher', t('publisher','permcat'),
|
||||
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
|
||||
'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
|
||||
'chat', 'republish' ], 1
|
||||
]
|
||||
];
|
||||
$permcats = [
|
||||
[ 'follower', t('follower', 'permcat'),
|
||||
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
|
||||
'post_like' ], 1
|
||||
],
|
||||
[ 'contributor', t('contributor', 'permcat'),
|
||||
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
|
||||
'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
|
||||
],
|
||||
[ 'publisher', t('publisher', 'permcat'),
|
||||
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
|
||||
'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
|
||||
'chat', 'republish' ], 1
|
||||
]
|
||||
];
|
||||
|
||||
if($uid) {
|
||||
$x = q("select * from pconfig where uid = %d and cat = 'permcat'",
|
||||
intval($uid)
|
||||
);
|
||||
if($x) {
|
||||
foreach($x as $xv) {
|
||||
$value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
|
||||
$permcats[] = [ $xv['k'], $xv['k'], $value, 0 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($uid) {
|
||||
$x = q(
|
||||
"select * from pconfig where uid = %d and cat = 'permcat'",
|
||||
intval($uid)
|
||||
);
|
||||
if ($x) {
|
||||
foreach ($x as $xv) {
|
||||
$value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
|
||||
$permcats[] = [ $xv['k'], $xv['k'], $value, 0 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hooks permcats
|
||||
* * \e array
|
||||
*/
|
||||
call_hooks('permcats', $permcats);
|
||||
/**
|
||||
* @hooks permcats
|
||||
* * \e array
|
||||
*/
|
||||
call_hooks('permcats', $permcats);
|
||||
|
||||
return $permcats;
|
||||
}
|
||||
return $permcats;
|
||||
}
|
||||
|
||||
public static function find_permcat($arr, $name) {
|
||||
if((! $arr) || (! $name))
|
||||
return false;
|
||||
public static function find_permcat($arr, $name)
|
||||
{
|
||||
if ((! $arr) || (! $name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($arr as $p)
|
||||
if($p['name'] == $name)
|
||||
return $p['value'];
|
||||
}
|
||||
foreach ($arr as $p) {
|
||||
if ($p['name'] == $name) {
|
||||
return $p['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function update($channel_id, $name, $permarr) {
|
||||
PConfig::Set($channel_id, 'permcat', $name, $permarr);
|
||||
}
|
||||
public static function update($channel_id, $name, $permarr)
|
||||
{
|
||||
PConfig::Set($channel_id, 'permcat', $name, $permarr);
|
||||
}
|
||||
|
||||
public static function delete($channel_id, $name) {
|
||||
PConfig::Delete($channel_id, 'permcat', $name);
|
||||
}
|
||||
|
||||
}
|
||||
public static function delete($channel_id, $name)
|
||||
{
|
||||
PConfig::Delete($channel_id, 'permcat', $name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,148 +16,178 @@ require_once("include/text.php");
|
|||
* permission settings for an item with an empty ACL.
|
||||
* i.e the caption, icon, and tooltip for the no-ACL option in the ACL dialog.
|
||||
*/
|
||||
class PermissionDescription {
|
||||
class PermissionDescription
|
||||
{
|
||||
|
||||
private $global_perm;
|
||||
private $channel_perm;
|
||||
private $fallback_description;
|
||||
private $global_perm;
|
||||
private $channel_perm;
|
||||
private $fallback_description;
|
||||
|
||||
/**
|
||||
* Constructor is private.
|
||||
* Use static methods fromGlobalPermission(), fromStandalonePermission(),
|
||||
* or fromDescription() to create instances.
|
||||
*
|
||||
* @internal
|
||||
* @param int $global_perm
|
||||
* @param int $channel_perm
|
||||
* @param string $description (optional) default empty
|
||||
*/
|
||||
private function __construct($global_perm, $channel_perm, $description = '') {
|
||||
$this->global_perm = $global_perm;
|
||||
$this->channel_perm = $channel_perm;
|
||||
$this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description;
|
||||
}
|
||||
/**
|
||||
* Constructor is private.
|
||||
* Use static methods fromGlobalPermission(), fromStandalonePermission(),
|
||||
* or fromDescription() to create instances.
|
||||
*
|
||||
* @internal
|
||||
* @param int $global_perm
|
||||
* @param int $channel_perm
|
||||
* @param string $description (optional) default empty
|
||||
*/
|
||||
private function __construct($global_perm, $channel_perm, $description = '')
|
||||
{
|
||||
$this->global_perm = $global_perm;
|
||||
$this->channel_perm = $channel_perm;
|
||||
$this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the interpretation of an empty ACL can't be summarised with a global default permission
|
||||
* or a specific permission setting then use this method and describe what it means instead.
|
||||
* Remember to localize the description first.
|
||||
*
|
||||
* @param string $description - the localized caption for the no-ACL option in the ACL dialog.
|
||||
* @return a new instance of PermissionDescription
|
||||
*/
|
||||
public static function fromDescription($description) {
|
||||
return new PermissionDescription('', 0x80000, $description);
|
||||
}
|
||||
/**
|
||||
* If the interpretation of an empty ACL can't be summarised with a global default permission
|
||||
* or a specific permission setting then use this method and describe what it means instead.
|
||||
* Remember to localize the description first.
|
||||
*
|
||||
* @param string $description - the localized caption for the no-ACL option in the ACL dialog.
|
||||
* @return a new instance of PermissionDescription
|
||||
*/
|
||||
public static function fromDescription($description)
|
||||
{
|
||||
return new PermissionDescription('', 0x80000, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method only if the interpretation of an empty ACL doesn't fall back to a global
|
||||
* default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC,
|
||||
* PERMS_NETWORK etc.
|
||||
*
|
||||
* @param int $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc.
|
||||
* @return a new instance of PermissionDescription
|
||||
*/
|
||||
public static function fromStandalonePermission($perm) {
|
||||
/**
|
||||
* Use this method only if the interpretation of an empty ACL doesn't fall back to a global
|
||||
* default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC,
|
||||
* PERMS_NETWORK etc.
|
||||
*
|
||||
* @param int $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc.
|
||||
* @return a new instance of PermissionDescription
|
||||
*/
|
||||
public static function fromStandalonePermission($perm)
|
||||
{
|
||||
|
||||
$result = new PermissionDescription('', $perm);
|
||||
$result = new PermissionDescription('', $perm);
|
||||
|
||||
$checkPerm = $result->get_permission_description();
|
||||
if($checkPerm == $result->fallback_description) {
|
||||
$result = null;
|
||||
logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR);
|
||||
}
|
||||
$checkPerm = $result->get_permission_description();
|
||||
if ($checkPerm == $result->fallback_description) {
|
||||
$result = null;
|
||||
logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the preferred way to create a PermissionDescription, as it provides the most details.
|
||||
* Use this method if you know an empty ACL will result in one of the global default permissions
|
||||
* being used, such as channel_r_stream (for which you would pass 'view_stream').
|
||||
*
|
||||
* @param string $permname - a key for the global perms array from get_perms() in permissions.php,
|
||||
* e.g. 'view_stream', 'view_profile', etc.
|
||||
* @return a new instance of PermissionDescription
|
||||
*/
|
||||
public static function fromGlobalPermission($permname) {
|
||||
/**
|
||||
* This is the preferred way to create a PermissionDescription, as it provides the most details.
|
||||
* Use this method if you know an empty ACL will result in one of the global default permissions
|
||||
* being used, such as channel_r_stream (for which you would pass 'view_stream').
|
||||
*
|
||||
* @param string $permname - a key for the global perms array from get_perms() in permissions.php,
|
||||
* e.g. 'view_stream', 'view_profile', etc.
|
||||
* @return a new instance of PermissionDescription
|
||||
*/
|
||||
public static function fromGlobalPermission($permname)
|
||||
{
|
||||
|
||||
$result = null;
|
||||
$result = null;
|
||||
|
||||
$global_perms = Permissions::Perms();
|
||||
$global_perms = Permissions::Perms();
|
||||
|
||||
if(array_key_exists($permname, $global_perms)) {
|
||||
if (array_key_exists($permname, $global_perms)) {
|
||||
$channelPerm = PermissionLimits::Get(App::$channel['channel_id'], $permname);
|
||||
|
||||
$channelPerm = PermissionLimits::Get(App::$channel['channel_id'], $permname);
|
||||
$result = new PermissionDescription('', $channelPerm);
|
||||
} else {
|
||||
// The acl dialog can handle null arguments, but it shouldn't happen
|
||||
logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR);
|
||||
}
|
||||
|
||||
$result = new PermissionDescription('', $channelPerm);
|
||||
} else {
|
||||
// The acl dialog can handle null arguments, but it shouldn't happen
|
||||
logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Gets a localized description of the permission, or a generic message if the permission
|
||||
* is unknown.
|
||||
*
|
||||
* @return string description
|
||||
*/
|
||||
public function get_permission_description()
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets a localized description of the permission, or a generic message if the permission
|
||||
* is unknown.
|
||||
*
|
||||
* @return string description
|
||||
*/
|
||||
public function get_permission_description() {
|
||||
switch ($this->channel_perm) {
|
||||
case 0:
|
||||
return t('Only me');
|
||||
case PERMS_PUBLIC:
|
||||
return t('Public');
|
||||
case PERMS_NETWORK:
|
||||
return t('Anybody in the $Projectname network');
|
||||
case PERMS_SITE:
|
||||
return sprintf(t('Any account on %s'), App::get_hostname());
|
||||
case PERMS_CONTACTS:
|
||||
return t('Any of my connections');
|
||||
case PERMS_SPECIFIC:
|
||||
return t('Only connections I specifically allow');
|
||||
case PERMS_AUTHED:
|
||||
return t('Anybody authenticated (could include visitors from other networks)');
|
||||
case PERMS_PENDING:
|
||||
return t('Any connections including those who haven\'t yet been approved');
|
||||
default:
|
||||
return $this->fallback_description;
|
||||
}
|
||||
}
|
||||
|
||||
switch($this->channel_perm) {
|
||||
case 0: return t('Only me');
|
||||
case PERMS_PUBLIC: return t('Public');
|
||||
case PERMS_NETWORK: return t('Anybody in the $Projectname network');
|
||||
case PERMS_SITE: return sprintf(t('Any account on %s'), App::get_hostname());
|
||||
case PERMS_CONTACTS: return t('Any of my connections');
|
||||
case PERMS_SPECIFIC: return t('Only connections I specifically allow');
|
||||
case PERMS_AUTHED: return t('Anybody authenticated (could include visitors from other networks)');
|
||||
case PERMS_PENDING: return t('Any connections including those who haven\'t yet been approved');
|
||||
default: return $this->fallback_description;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public,
|
||||
* otherwise returns empty string.
|
||||
*
|
||||
* @return string icon css class name (often FontAwesome)
|
||||
*/
|
||||
public function get_permission_icon()
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public,
|
||||
* otherwise returns empty string.
|
||||
*
|
||||
* @return string icon css class name (often FontAwesome)
|
||||
*/
|
||||
public function get_permission_icon() {
|
||||
switch ($this->channel_perm) {
|
||||
case 0:
|
||||
return 'fa-eye-slash';
|
||||
case PERMS_PUBLIC:
|
||||
return 'fa-globe';
|
||||
case PERMS_NETWORK:
|
||||
return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use
|
||||
case PERMS_SITE:
|
||||
return 'fa-sitemap';
|
||||
case PERMS_CONTACTS:
|
||||
return 'fa-group';
|
||||
case PERMS_SPECIFIC:
|
||||
return 'fa-list';
|
||||
case PERMS_AUTHED:
|
||||
return '';
|
||||
case PERMS_PENDING:
|
||||
return '';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
switch($this->channel_perm) {
|
||||
case 0:/* only me */ return 'fa-eye-slash';
|
||||
case PERMS_PUBLIC: return 'fa-globe';
|
||||
case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use
|
||||
case PERMS_SITE: return 'fa-sitemap';
|
||||
case PERMS_CONTACTS: return 'fa-group';
|
||||
case PERMS_SPECIFIC: return 'fa-list';
|
||||
case PERMS_AUTHED: return '';
|
||||
case PERMS_PENDING: return '';
|
||||
default: return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a localized description of where the permission came from, if this is known.
|
||||
* If it's not know, or if the permission is standalone and didn't come from a default
|
||||
* permission setting, then empty string is returned.
|
||||
*
|
||||
* @return string description or empty string
|
||||
*/
|
||||
public function get_permission_origin_description() {
|
||||
|
||||
switch($this->global_perm) {
|
||||
case PERMS_R_STREAM: return t('This is your default setting for the audience of your normal stream, and posts.');
|
||||
case PERMS_R_PROFILE: return t('This is your default setting for who can view your default channel profile');
|
||||
case PERMS_R_ABOOK: return t('This is your default setting for who can view your connections');
|
||||
case PERMS_R_STORAGE: return t('This is your default setting for who can view your file storage and photos');
|
||||
case PERMS_R_PAGES: return t('This is your default setting for the audience of your webpages');
|
||||
default: return '';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a localized description of where the permission came from, if this is known.
|
||||
* If it's not know, or if the permission is standalone and didn't come from a default
|
||||
* permission setting, then empty string is returned.
|
||||
*
|
||||
* @return string description or empty string
|
||||
*/
|
||||
public function get_permission_origin_description()
|
||||
{
|
||||
|
||||
switch ($this->global_perm) {
|
||||
case PERMS_R_STREAM:
|
||||
return t('This is your default setting for the audience of your normal stream, and posts.');
|
||||
case PERMS_R_PROFILE:
|
||||
return t('This is your default setting for who can view your default channel profile');
|
||||
case PERMS_R_ABOOK:
|
||||
return t('This is your default setting for who can view your connections');
|
||||
case PERMS_R_STORAGE:
|
||||
return t('This is your default setting for who can view your file storage and photos');
|
||||
case PERMS_R_PAGES:
|
||||
return t('This is your default setting for the audience of your webpages');
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
@ -23,14 +25,16 @@ class Queue
|
|||
// getting stuck on a particular message when another one with different content
|
||||
// might actually succeed.
|
||||
|
||||
$x = q("select outq_created, outq_hash, outq_posturl from outq where outq_hash = '%s' limit 1",
|
||||
$x = q(
|
||||
"select outq_created, outq_hash, outq_posturl from outq where outq_hash = '%s' limit 1",
|
||||
dbesc($id)
|
||||
);
|
||||
if (!$x) {
|
||||
return;
|
||||
}
|
||||
|
||||
$g = q("select outq_created, outq_hash, outq_posturl from outq where outq_posturl = '%s' and outq_hash != '%s' limit 1",
|
||||
$g = q(
|
||||
"select outq_created, outq_hash, outq_posturl from outq where outq_posturl = '%s' and outq_hash != '%s' limit 1",
|
||||
dbesc($x[0]['outq_posturl']),
|
||||
dbesc($id)
|
||||
);
|
||||
|
@ -42,7 +46,8 @@ class Queue
|
|||
}
|
||||
|
||||
|
||||
$y = q("select min(outq_created) as earliest from outq where outq_posturl = '%s'",
|
||||
$y = q(
|
||||
"select min(outq_created) as earliest from outq where outq_posturl = '%s'",
|
||||
dbesc($x[0]['outq_posturl'])
|
||||
);
|
||||
|
||||
|
@ -52,8 +57,9 @@ class Queue
|
|||
|
||||
$might_be_down = false;
|
||||
|
||||
if ($y)
|
||||
if ($y) {
|
||||
$might_be_down = ((datetime_convert('UTC', 'UTC', $y[0]['earliest']) < datetime_convert('UTC', 'UTC', 'now - 2 days')) ? true : false);
|
||||
}
|
||||
|
||||
|
||||
// Set all other records for this destination way into the future.
|
||||
|
@ -64,7 +70,8 @@ class Queue
|
|||
// queue item is less than 12 hours old, we'll schedule for fifteen
|
||||
// minutes.
|
||||
|
||||
$r = q("UPDATE outq SET outq_scheduled = '%s' WHERE outq_posturl = '%s'",
|
||||
$r = q(
|
||||
"UPDATE outq SET outq_scheduled = '%s' WHERE outq_posturl = '%s'",
|
||||
dbesc(datetime_convert('UTC', 'UTC', 'now + 5 days')),
|
||||
dbesc($x[0]['outq_posturl'])
|
||||
);
|
||||
|
@ -77,11 +84,11 @@ class Queue
|
|||
$next = datetime_convert('UTC', 'UTC', 'now + ' . intval($add_priority) . ' minutes');
|
||||
}
|
||||
|
||||
q("UPDATE outq SET outq_updated = '%s',
|
||||
q(
|
||||
"UPDATE outq SET outq_updated = '%s',
|
||||
outq_priority = outq_priority + %d,
|
||||
outq_scheduled = '%s'
|
||||
WHERE outq_hash = '%s'",
|
||||
|
||||
dbesc(datetime_convert()),
|
||||
intval($add_priority),
|
||||
dbesc($next),
|
||||
|
@ -95,7 +102,8 @@ class Queue
|
|||
logger('queue: remove queue item ' . $id, LOGGER_DEBUG);
|
||||
$sql_extra = (($channel_id) ? " and outq_channel = " . intval($channel_id) . " " : '');
|
||||
|
||||
q("DELETE FROM outq WHERE outq_hash = '%s' $sql_extra",
|
||||
q(
|
||||
"DELETE FROM outq WHERE outq_hash = '%s' $sql_extra",
|
||||
dbesc($id)
|
||||
);
|
||||
}
|
||||
|
@ -105,7 +113,8 @@ class Queue
|
|||
{
|
||||
logger('queue: remove queue posturl ' . $posturl, LOGGER_DEBUG);
|
||||
|
||||
q("DELETE FROM outq WHERE outq_posturl = '%s' ",
|
||||
q(
|
||||
"DELETE FROM outq WHERE outq_posturl = '%s' ",
|
||||
dbesc($posturl)
|
||||
);
|
||||
}
|
||||
|
@ -119,7 +128,8 @@ class Queue
|
|||
// Set the next scheduled run date so far in the future that it will be expired
|
||||
// long before it ever makes it back into the delivery chain.
|
||||
|
||||
q("update outq set outq_delivered = 1, outq_updated = '%s', outq_scheduled = '%s' where outq_hash = '%s' $sql_extra ",
|
||||
q(
|
||||
"update outq set outq_delivered = 1, outq_updated = '%s', outq_scheduled = '%s' where outq_hash = '%s' $sql_extra ",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert('UTC', 'UTC', 'now + 5 days')),
|
||||
dbesc($id)
|
||||
|
@ -140,7 +150,8 @@ class Queue
|
|||
}
|
||||
|
||||
|
||||
$x = q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_priority,
|
||||
$x = q(
|
||||
"insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_priority,
|
||||
outq_created, outq_updated, outq_scheduled, outq_notify, outq_msg )
|
||||
values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s' )",
|
||||
dbesc($arr['hash']),
|
||||
|
@ -157,7 +168,6 @@ class Queue
|
|||
dbesc(($arr['msg']) ? $arr['msg'] : '')
|
||||
);
|
||||
return $x;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,12 +181,14 @@ class Queue
|
|||
}
|
||||
|
||||
if (($base) && ($base !== z_root()) && ($immediate)) {
|
||||
$y = q("select site_update, site_dead from site where site_url = '%s' ",
|
||||
$y = q(
|
||||
"select site_update, site_dead from site where site_url = '%s' ",
|
||||
dbesc($base)
|
||||
);
|
||||
if ($y) {
|
||||
if (intval($y[0]['site_dead'])) {
|
||||
q("update dreport set dreport_result = '%s' where dreport_queue = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_result = '%s' where dreport_queue = '%s'",
|
||||
dbesc('site dead'),
|
||||
dbesc($outq['outq_hash'])
|
||||
);
|
||||
|
@ -186,7 +198,8 @@ class Queue
|
|||
return;
|
||||
}
|
||||
if ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
|
||||
q("update dreport set dreport_log = '%s' where dreport_queue = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_log = '%s' where dreport_queue = '%s'",
|
||||
dbesc('site deferred'),
|
||||
dbesc($outq['outq_hash'])
|
||||
);
|
||||
|
@ -195,7 +208,6 @@ class Queue
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
// zot sites should all have a site record, unless they've been dead for as long as
|
||||
// your site has existed. Since we don't know for sure what these sites are,
|
||||
// call them unknown
|
||||
|
@ -214,8 +226,9 @@ class Queue
|
|||
|
||||
$arr = array('outq' => $outq, 'base' => $base, 'handled' => false, 'immediate' => $immediate);
|
||||
call_hooks('queue_deliver', $arr);
|
||||
if ($arr['handled'])
|
||||
if ($arr['handled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
// "post" queue driver - used for diaspora and friendica-over-diaspora communications.
|
||||
|
||||
|
@ -224,12 +237,14 @@ class Queue
|
|||
if ($result['success'] && $result['return_code'] < 300) {
|
||||
logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG);
|
||||
if ($base) {
|
||||
q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
|
||||
q(
|
||||
"update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($base)
|
||||
);
|
||||
}
|
||||
q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
|
||||
dbesc('accepted for delivery'),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($outq['outq_hash'])
|
||||
|
@ -241,7 +256,8 @@ class Queue
|
|||
// immediate delivery otherwise we could get into a queue loop.
|
||||
|
||||
if (!$immediate) {
|
||||
$x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
|
||||
$x = q(
|
||||
"select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
|
||||
dbesc($outq['outq_posturl'])
|
||||
);
|
||||
|
||||
|
@ -265,7 +281,6 @@ class Queue
|
|||
}
|
||||
|
||||
if ($outq['outq_driver'] === 'asfetch') {
|
||||
|
||||
$channel = channelx_by_n($outq['outq_channel']);
|
||||
if (!$channel) {
|
||||
logger('missing channel: ' . $outq['outq_channel']);
|
||||
|
@ -303,7 +318,8 @@ class Queue
|
|||
// immediate delivery otherwise we could get into a queue loop.
|
||||
|
||||
if (!$immediate) {
|
||||
$x = q("select outq_hash from outq where outq_driver = 'asfetch' and outq_channel = %d and outq_delivered = 0",
|
||||
$x = q(
|
||||
"select outq_hash from outq where outq_driver = 'asfetch' and outq_channel = %d and outq_delivered = 0",
|
||||
dbesc($outq['outq_channel'])
|
||||
);
|
||||
|
||||
|
@ -325,7 +341,6 @@ class Queue
|
|||
}
|
||||
|
||||
if ($outq['outq_driver'] === 'activitypub') {
|
||||
|
||||
$channel = channelx_by_n($outq['outq_channel']);
|
||||
if (!$channel) {
|
||||
logger('missing channel: ' . $outq['outq_channel']);
|
||||
|
@ -356,12 +371,14 @@ class Queue
|
|||
if ($result['success'] && $result['return_code'] < 300) {
|
||||
logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG);
|
||||
if ($base) {
|
||||
q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
|
||||
q(
|
||||
"update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($base)
|
||||
);
|
||||
}
|
||||
q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
|
||||
dbesc('accepted for delivery'),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($outq['outq_hash'])
|
||||
|
@ -373,7 +390,8 @@ class Queue
|
|||
// immediate delivery otherwise we could get into a queue loop.
|
||||
|
||||
if (!$immediate) {
|
||||
$x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
|
||||
$x = q(
|
||||
"select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
|
||||
dbesc($outq['outq_posturl'])
|
||||
);
|
||||
|
||||
|
@ -389,18 +407,21 @@ class Queue
|
|||
}
|
||||
} else {
|
||||
if ($result['return_code'] >= 300) {
|
||||
q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
|
||||
dbesc('delivery rejected' . ' ' . $result['return_code']),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($outq['outq_hash'])
|
||||
);
|
||||
} else {
|
||||
$dr = q("select * from dreport where dreport_queue = '%s'",
|
||||
$dr = q(
|
||||
"select * from dreport where dreport_queue = '%s'",
|
||||
dbesc($outq['outq_hash'])
|
||||
);
|
||||
if ($dr) {
|
||||
// update every queue entry going to this site with the most recent communication error
|
||||
q("update dreport set dreport_log = '%s' where dreport_site = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_log = '%s' where dreport_site = '%s'",
|
||||
dbesc(z_curl_error($result)),
|
||||
dbesc($dr[0]['dreport_site'])
|
||||
);
|
||||
|
@ -426,7 +447,8 @@ class Queue
|
|||
Libzot::process_response($outq['outq_posturl'], ['success' => true, 'body' => json_encode($result)], $outq);
|
||||
|
||||
if (!$immediate) {
|
||||
$x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
|
||||
$x = q(
|
||||
"select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
|
||||
dbesc($outq['outq_posturl'])
|
||||
);
|
||||
|
||||
|
@ -451,7 +473,8 @@ class Queue
|
|||
$host_crypto = null;
|
||||
|
||||
if ($channel && $base) {
|
||||
$h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1",
|
||||
$h = q(
|
||||
"select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1",
|
||||
dbesc($base)
|
||||
);
|
||||
if ($h) {
|
||||
|
@ -467,12 +490,14 @@ class Queue
|
|||
logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']);
|
||||
Libzot::process_response($outq['outq_posturl'], $result, $outq);
|
||||
} else {
|
||||
$dr = q("select * from dreport where dreport_queue = '%s'",
|
||||
$dr = q(
|
||||
"select * from dreport where dreport_queue = '%s'",
|
||||
dbesc($outq['outq_hash'])
|
||||
);
|
||||
|
||||
// update every queue entry going to this site with the most recent communication error
|
||||
q("update dreport set dreport_log = '%s' where dreport_site = '%s'",
|
||||
q(
|
||||
"update dreport set dreport_log = '%s' where dreport_site = '%s'",
|
||||
dbesc(z_curl_error($result)),
|
||||
dbesc($dr[0]['dreport_site'])
|
||||
);
|
||||
|
@ -485,4 +510,3 @@ class Queue
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,23 +7,27 @@ namespace Zotlabs\Lib;
|
|||
*
|
||||
* @see XConfig
|
||||
*/
|
||||
|
||||
class SConfig {
|
||||
|
||||
public static function Load($server_id) {
|
||||
return XConfig::Load('s_' . $server_id);
|
||||
}
|
||||
class SConfig
|
||||
{
|
||||
|
||||
public static function Get($server_id, $family, $key, $default = false) {
|
||||
return XConfig::Get('s_' . $server_id,$family,$key, $default);
|
||||
}
|
||||
public static function Load($server_id)
|
||||
{
|
||||
return XConfig::Load('s_' . $server_id);
|
||||
}
|
||||
|
||||
public static function Set($server_id, $family, $key, $value) {
|
||||
return XConfig::Set('s_' . $server_id,$family,$key,$value);
|
||||
}
|
||||
public static function Get($server_id, $family, $key, $default = false)
|
||||
{
|
||||
return XConfig::Get('s_' . $server_id, $family, $key, $default);
|
||||
}
|
||||
|
||||
public static function Delete($server_id, $family, $key) {
|
||||
return XConfig::Delete('s_' . $server_id,$family,$key);
|
||||
}
|
||||
public static function Set($server_id, $family, $key, $value)
|
||||
{
|
||||
return XConfig::Set('s_' . $server_id, $family, $key, $value);
|
||||
}
|
||||
|
||||
public static function Delete($server_id, $family, $key)
|
||||
{
|
||||
return XConfig::Delete('s_' . $server_id, $family, $key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,222 +6,227 @@ use App;
|
|||
use Zotlabs\Daemon\Run;
|
||||
use Zotlabs\Lib\Libsync;
|
||||
|
||||
class Share {
|
||||
class Share
|
||||
{
|
||||
|
||||
private $item = null;
|
||||
private $item = null;
|
||||
|
||||
|
||||
public function __construct($post_id) {
|
||||
|
||||
if (! $post_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_array($post_id)) {
|
||||
$this->item = $post_id;
|
||||
return;
|
||||
}
|
||||
|
||||
if (! (local_channel() || remote_channel())) {
|
||||
return;
|
||||
}
|
||||
public function __construct($post_id)
|
||||
{
|
||||
|
||||
$r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
|
||||
intval($post_id)
|
||||
);
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
if (! $post_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql_extra = item_permissions_sql($r[0]['uid']);
|
||||
|
||||
$r = q("select * from item where id = %d $sql_extra",
|
||||
intval($post_id)
|
||||
);
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array($r[0]['mimetype'], [ 'text/bbcode', 'text/x-multicode' ])) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @FIXME eventually we want to post remotely via rpost on your home site */
|
||||
// When that works remove this next bit:
|
||||
|
||||
if (! local_channel()) {
|
||||
return;
|
||||
}
|
||||
if (is_array($post_id)) {
|
||||
$this->item = $post_id;
|
||||
return;
|
||||
}
|
||||
|
||||
xchan_query($r);
|
||||
|
||||
$this->item = array_shift($r);
|
||||
if (! (local_channel() || remote_channel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$arr = [];
|
||||
$r = q(
|
||||
"SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
|
||||
intval($post_id)
|
||||
);
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
|
||||
$owner_uid = $this->item['uid'];
|
||||
$owner_aid = $this->item['aid'];
|
||||
if (($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$channel = channelx_by_n($this->item['uid']);
|
||||
$observer = App::get_observer();
|
||||
$sql_extra = item_permissions_sql($r[0]['uid']);
|
||||
|
||||
$can_comment = false;
|
||||
if ((array_key_exists('owner',$this->item)) && intval($this->item['owner']['abook_self'])) {
|
||||
$can_comment = perm_is_allowed($this->item['uid'],$observer['xchan_hash'],'post_comments');
|
||||
}
|
||||
else {
|
||||
$can_comment = can_comment_on_post($observer['xchan_hash'],$this->item);
|
||||
}
|
||||
$r = q(
|
||||
"select * from item where id = %d $sql_extra",
|
||||
intval($post_id)
|
||||
);
|
||||
if (! $r) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $can_comment) {
|
||||
return;
|
||||
}
|
||||
if (! in_array($r[0]['mimetype'], [ 'text/bbcode', 'text/x-multicode' ])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($this->item['owner_xchan'])
|
||||
);
|
||||
/** @FIXME eventually we want to post remotely via rpost on your home site */
|
||||
// When that works remove this next bit:
|
||||
|
||||
if ($r) {
|
||||
$thread_owner = array_shift($r);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($this->item['author_xchan'])
|
||||
);
|
||||
if ($r) {
|
||||
$item_author = array_shift($r);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
if (! local_channel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($item_author['network'] === 'activitypub') {
|
||||
xchan_query($r);
|
||||
|
||||
// for Mastodon compatibility, send back an ActivityPub Announce activity.
|
||||
// We don't need or want these on our own network as there is no mechanism for providing
|
||||
// a fair-use defense to copyright claims and frivolous lawsuits.
|
||||
|
||||
$arr['aid'] = $owner_aid;
|
||||
$arr['uid'] = $owner_uid;
|
||||
$this->item = array_shift($r);
|
||||
|
||||
$arr['item_origin'] = 1;
|
||||
$arr['item_wall'] = $this->item['item_wall'];
|
||||
$arr['uuid'] = new_uuid();
|
||||
$arr['mid'] = z_root() . '/item/' . $arr['uuid'];
|
||||
$arr['mid'] = str_replace('/item/','/activity/',$arr['mid']);
|
||||
$arr['parent_mid'] = $this->item['mid'];
|
||||
$arr = [];
|
||||
|
||||
$mention = '@[zrl=' . $this->item['author']['xchan_url'] . ']' . $this->item['author']['xchan_name'] . '[/zrl]';
|
||||
$arr['body'] = sprintf( t('🔁 Repeated %1$s\'s %2$s'), $mention, $this->item['obj_type']);
|
||||
$owner_uid = $this->item['uid'];
|
||||
$owner_aid = $this->item['aid'];
|
||||
|
||||
$arr['author_xchan'] = $observer['xchan_hash'];
|
||||
$arr['owner_xchan'] = $this->item['author_xchan'];
|
||||
$arr['obj'] = $this->item['obj'];
|
||||
$arr['obj_type'] = $this->item['obj_type'];
|
||||
$arr['verb'] = 'Announce';
|
||||
$channel = channelx_by_n($this->item['uid']);
|
||||
$observer = App::get_observer();
|
||||
|
||||
$post = item_store($arr);
|
||||
$can_comment = false;
|
||||
if ((array_key_exists('owner', $this->item)) && intval($this->item['owner']['abook_self'])) {
|
||||
$can_comment = perm_is_allowed($this->item['uid'], $observer['xchan_hash'], 'post_comments');
|
||||
} else {
|
||||
$can_comment = can_comment_on_post($observer['xchan_hash'], $this->item);
|
||||
}
|
||||
|
||||
$post_id = $post['item_id'];
|
||||
if (! $can_comment) {
|
||||
return;
|
||||
}
|
||||
|
||||
$arr['id'] = $post_id;
|
||||
|
||||
call_hooks('post_local_end', $arr);
|
||||
$r = q(
|
||||
"select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($this->item['owner_xchan'])
|
||||
);
|
||||
|
||||
$r = q("select * from item where id = %d",
|
||||
intval($post_id)
|
||||
);
|
||||
if ($r) {
|
||||
xchan_query($r);
|
||||
$sync_item = fetch_post_tags($r);
|
||||
Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0],true) ] ]);
|
||||
}
|
||||
if ($r) {
|
||||
$thread_owner = array_shift($r);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
Run::Summon([ 'Notifier','like',$post_id ]);
|
||||
}
|
||||
|
||||
return;
|
||||
$r = q(
|
||||
"select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($this->item['author_xchan'])
|
||||
);
|
||||
if ($r) {
|
||||
$item_author = array_shift($r);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if ($item_author['network'] === 'activitypub') {
|
||||
// for Mastodon compatibility, send back an ActivityPub Announce activity.
|
||||
// We don't need or want these on our own network as there is no mechanism for providing
|
||||
// a fair-use defense to copyright claims and frivolous lawsuits.
|
||||
|
||||
public function obj() {
|
||||
$obj = [];
|
||||
$arr['aid'] = $owner_aid;
|
||||
$arr['uid'] = $owner_uid;
|
||||
|
||||
if(! $this->item)
|
||||
return $obj;
|
||||
$arr['item_origin'] = 1;
|
||||
$arr['item_wall'] = $this->item['item_wall'];
|
||||
$arr['uuid'] = new_uuid();
|
||||
$arr['mid'] = z_root() . '/item/' . $arr['uuid'];
|
||||
$arr['mid'] = str_replace('/item/', '/activity/', $arr['mid']);
|
||||
$arr['parent_mid'] = $this->item['mid'];
|
||||
|
||||
$obj['type'] = $this->item['obj_type'];
|
||||
$obj['id'] = $this->item['mid'];
|
||||
$obj['content'] = bbcode($this->item['body']);
|
||||
$obj['source'] = [
|
||||
'mediaType' => $this->item['mimetype'],
|
||||
'content' => $this->item['body']
|
||||
];
|
||||
$mention = '@[zrl=' . $this->item['author']['xchan_url'] . ']' . $this->item['author']['xchan_name'] . '[/zrl]';
|
||||
$arr['body'] = sprintf(t('🔁 Repeated %1$s\'s %2$s'), $mention, $this->item['obj_type']);
|
||||
|
||||
$obj['name'] = $this->item['title'];
|
||||
$obj['published'] = $this->item['created'];
|
||||
$obj['updated'] = $this->item['edited'];
|
||||
$obj['attributedTo'] = ((strpos($this->item['author']['xchan_hash'],'http') === 0)
|
||||
? $this->item['author']['xchan_hash']
|
||||
: $this->item['author']['xchan_url']);
|
||||
$arr['author_xchan'] = $observer['xchan_hash'];
|
||||
$arr['owner_xchan'] = $this->item['author_xchan'];
|
||||
$arr['obj'] = $this->item['obj'];
|
||||
$arr['obj_type'] = $this->item['obj_type'];
|
||||
$arr['verb'] = 'Announce';
|
||||
|
||||
return $obj;
|
||||
}
|
||||
$post = item_store($arr);
|
||||
|
||||
public function bbcode() {
|
||||
$bb = EMPTY_STR;
|
||||
$post_id = $post['item_id'];
|
||||
|
||||
if (! $this->item)
|
||||
return $bb;
|
||||
$arr['id'] = $post_id;
|
||||
|
||||
if (! $this->item['author']) {
|
||||
$author = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($this->item['author_xchan'])
|
||||
);
|
||||
if ($author) {
|
||||
$this->item['author'] = array_shift($author);
|
||||
}
|
||||
}
|
||||
call_hooks('post_local_end', $arr);
|
||||
|
||||
$special_object = (in_array($this->item['obj_type'], [ ACTIVITY_OBJ_PHOTO, 'Event', 'Question' ]) ? true : false);
|
||||
if($special_object) {
|
||||
$object = json_decode($this->item['obj'],true);
|
||||
$special = (($object['source']) ? $object['source']['content'] : $object['body']);
|
||||
}
|
||||
|
||||
if (strpos($this->item['body'], "[/share]") !== false) {
|
||||
$pos = strpos($this->item['body'], "[share");
|
||||
$bb = substr($this->item['body'], $pos);
|
||||
} else {
|
||||
$bb = "[share author='" . urlencode($this->item['author']['xchan_name']).
|
||||
"' profile='" . $this->item['author']['xchan_url'] .
|
||||
"' portable_id='" . $this->item['author']['xchan_hash'] .
|
||||
"' avatar='" . $this->item['author']['xchan_photo_s'] .
|
||||
"' link='" . $this->item['plink'] .
|
||||
"' auth='" . (($this->item['author']['network'] === 'zot6') ? 'true' : 'false') .
|
||||
"' posted='" . $this->item['created'] .
|
||||
"' message_id='" . $this->item['mid'] .
|
||||
"']";
|
||||
if ($this->item['title']) {
|
||||
$bb .= '[b]'.$this->item['title'].'[/b]'."\r\n";
|
||||
}
|
||||
if ($this->item['summary']) {
|
||||
$bb .= $this->item['summary'] . "\r\n";
|
||||
}
|
||||
|
||||
$bb .= (($special_object) ? $special . "\r\n" . $this->item['body'] : $this->item['body']);
|
||||
$bb .= "[/share]";
|
||||
}
|
||||
$r = q(
|
||||
"select * from item where id = %d",
|
||||
intval($post_id)
|
||||
);
|
||||
if ($r) {
|
||||
xchan_query($r);
|
||||
$sync_item = fetch_post_tags($r);
|
||||
Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0], true) ] ]);
|
||||
}
|
||||
|
||||
return $bb;
|
||||
Run::Summon([ 'Notifier','like',$post_id ]);
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public function obj()
|
||||
{
|
||||
$obj = [];
|
||||
|
||||
if (! $this->item) {
|
||||
return $obj;
|
||||
}
|
||||
|
||||
$obj['type'] = $this->item['obj_type'];
|
||||
$obj['id'] = $this->item['mid'];
|
||||
$obj['content'] = bbcode($this->item['body']);
|
||||
$obj['source'] = [
|
||||
'mediaType' => $this->item['mimetype'],
|
||||
'content' => $this->item['body']
|
||||
];
|
||||
|
||||
$obj['name'] = $this->item['title'];
|
||||
$obj['published'] = $this->item['created'];
|
||||
$obj['updated'] = $this->item['edited'];
|
||||
$obj['attributedTo'] = ((strpos($this->item['author']['xchan_hash'], 'http') === 0)
|
||||
? $this->item['author']['xchan_hash']
|
||||
: $this->item['author']['xchan_url']);
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function bbcode()
|
||||
{
|
||||
$bb = EMPTY_STR;
|
||||
|
||||
if (! $this->item) {
|
||||
return $bb;
|
||||
}
|
||||
|
||||
if (! $this->item['author']) {
|
||||
$author = q(
|
||||
"select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($this->item['author_xchan'])
|
||||
);
|
||||
if ($author) {
|
||||
$this->item['author'] = array_shift($author);
|
||||
}
|
||||
}
|
||||
|
||||
$special_object = (in_array($this->item['obj_type'], [ ACTIVITY_OBJ_PHOTO, 'Event', 'Question' ]) ? true : false);
|
||||
if ($special_object) {
|
||||
$object = json_decode($this->item['obj'], true);
|
||||
$special = (($object['source']) ? $object['source']['content'] : $object['body']);
|
||||
}
|
||||
|
||||
if (strpos($this->item['body'], "[/share]") !== false) {
|
||||
$pos = strpos($this->item['body'], "[share");
|
||||
$bb = substr($this->item['body'], $pos);
|
||||
} else {
|
||||
$bb = "[share author='" . urlencode($this->item['author']['xchan_name']) .
|
||||
"' profile='" . $this->item['author']['xchan_url'] .
|
||||
"' portable_id='" . $this->item['author']['xchan_hash'] .
|
||||
"' avatar='" . $this->item['author']['xchan_photo_s'] .
|
||||
"' link='" . $this->item['plink'] .
|
||||
"' auth='" . (($this->item['author']['network'] === 'zot6') ? 'true' : 'false') .
|
||||
"' posted='" . $this->item['created'] .
|
||||
"' message_id='" . $this->item['mid'] .
|
||||
"']";
|
||||
if ($this->item['title']) {
|
||||
$bb .= '[b]' . $this->item['title'] . '[/b]' . "\r\n";
|
||||
}
|
||||
if ($this->item['summary']) {
|
||||
$bb .= $this->item['summary'] . "\r\n";
|
||||
}
|
||||
|
||||
$bb .= (($special_object) ? $special . "\r\n" . $this->item['body'] : $this->item['body']);
|
||||
$bb .= "[/share]";
|
||||
}
|
||||
|
||||
return $bb;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ use Zotlabs\Lib\Config;
|
|||
|
||||
/**
|
||||
* SVGSantiizer
|
||||
*
|
||||
*
|
||||
* Allowlist-based PHP SVG sanitizer.
|
||||
*
|
||||
*
|
||||
* @link https://github.com/alister-/SVG-Sanitizer}
|
||||
* @author Alister Norris
|
||||
* @copyright Copyright (c) 2013 Alister Norris
|
||||
|
@ -108,7 +108,6 @@ class SvgSanitizer
|
|||
$total = $currentNode->attributes->length;
|
||||
|
||||
for ($x = 0; $x < $total; $x++) {
|
||||
|
||||
// get attributes name
|
||||
$attrName = $currentNode->attributes->item($x)->nodeName;
|
||||
|
||||
|
@ -119,8 +118,14 @@ class SvgSanitizer
|
|||
if (!in_array($attrName, $allowlist_attr_arr)) {
|
||||
$this->removedattrs[] = $attrName;
|
||||
} // check for disallowed functions
|
||||
elseif (preg_match_all('/([a-zA-Z0-9]+)[\s]*\(/',
|
||||
$currentNode->attributes->item($x)->textContent, $matches, PREG_SET_ORDER)) {
|
||||
elseif (
|
||||
preg_match_all(
|
||||
'/([a-zA-Z0-9]+)[\s]*\(/',
|
||||
$currentNode->attributes->item($x)->textContent,
|
||||
$matches,
|
||||
PREG_SET_ORDER
|
||||
)
|
||||
) {
|
||||
if ($attrName === 'text') {
|
||||
continue;
|
||||
}
|
||||
|
@ -138,7 +143,6 @@ class SvgSanitizer
|
|||
logger('removed: ' . $attr, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
} // else remove element
|
||||
else {
|
||||
logger('remove_node: ' . print_r($currentNode, true));
|
||||
|
|
|
@ -4,113 +4,141 @@ namespace Zotlabs\Lib;
|
|||
|
||||
use App;
|
||||
|
||||
class System {
|
||||
class System
|
||||
{
|
||||
|
||||
public static function get_platform_name() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('platform_name',App::$config['system']))
|
||||
return App::$config['system']['platform_name'];
|
||||
return PLATFORM_NAME;
|
||||
}
|
||||
public static function get_platform_name()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('platform_name', App::$config['system'])) {
|
||||
return App::$config['system']['platform_name'];
|
||||
}
|
||||
return PLATFORM_NAME;
|
||||
}
|
||||
|
||||
public static function get_site_name() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['sitename'])
|
||||
return App::$config['system']['sitename'];
|
||||
return '';
|
||||
}
|
||||
public static function get_site_name()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['sitename']) {
|
||||
return App::$config['system']['sitename'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function get_banner() {
|
||||
public static function get_banner()
|
||||
{
|
||||
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('banner',App::$config['system']) && App::$config['system']['banner']) {
|
||||
return App::$config['system']['banner'];
|
||||
}
|
||||
return self::get_site_name();
|
||||
}
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('banner', App::$config['system']) && App::$config['system']['banner']) {
|
||||
return App::$config['system']['banner'];
|
||||
}
|
||||
return self::get_site_name();
|
||||
}
|
||||
|
||||
public static function get_project_icon() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('icon',App::$config['system'])) {
|
||||
return App::$config['system']['icon'];
|
||||
}
|
||||
return z_root() . '/images/' . PLATFORM_NAME . '-64.png';
|
||||
}
|
||||
public static function get_project_icon()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('icon', App::$config['system'])) {
|
||||
return App::$config['system']['icon'];
|
||||
}
|
||||
return z_root() . '/images/' . PLATFORM_NAME . '-64.png';
|
||||
}
|
||||
|
||||
public static function get_project_favicon() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('favicon',App::$config['system'])) {
|
||||
return App::$config['system']['favicon'];
|
||||
}
|
||||
return z_root() . '/images/' . PLATFORM_NAME . '.ico';
|
||||
}
|
||||
public static function get_project_favicon()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('favicon', App::$config['system'])) {
|
||||
return App::$config['system']['favicon'];
|
||||
}
|
||||
return z_root() . '/images/' . PLATFORM_NAME . '.ico';
|
||||
}
|
||||
|
||||
|
||||
public static function get_project_version() {
|
||||
if(array_path_exists('system/hide_version', App::$config) && intval(App::$config['system']['hide_version']))
|
||||
return '';
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('std_version',App::$config['system']))
|
||||
return App::$config['system']['std_version'];
|
||||
public static function get_project_version()
|
||||
{
|
||||
if (array_path_exists('system/hide_version', App::$config) && intval(App::$config['system']['hide_version'])) {
|
||||
return '';
|
||||
}
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('std_version', App::$config['system'])) {
|
||||
return App::$config['system']['std_version'];
|
||||
}
|
||||
|
||||
return self::get_std_version();
|
||||
}
|
||||
return self::get_std_version();
|
||||
}
|
||||
|
||||
public static function get_update_version() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['hide_version'])
|
||||
return EMPTY_STR;
|
||||
return DB_UPDATE_VERSION;
|
||||
}
|
||||
public static function get_update_version()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['hide_version']) {
|
||||
return EMPTY_STR;
|
||||
}
|
||||
return DB_UPDATE_VERSION;
|
||||
}
|
||||
|
||||
|
||||
public static function get_notify_icon() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['email_notify_icon_url'])
|
||||
return App::$config['system']['email_notify_icon_url'];
|
||||
return self::get_project_icon();
|
||||
}
|
||||
public static function get_notify_icon()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['email_notify_icon_url']) {
|
||||
return App::$config['system']['email_notify_icon_url'];
|
||||
}
|
||||
return self::get_project_icon();
|
||||
}
|
||||
|
||||
public static function get_site_icon() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && isset(App::$config['system']['site_icon_url']) && App::$config['system']['site_icon_url'])
|
||||
return App::$config['system']['site_icon_url'];
|
||||
return self::get_project_icon();
|
||||
}
|
||||
public static function get_site_icon()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && isset(App::$config['system']['site_icon_url']) && App::$config['system']['site_icon_url']) {
|
||||
return App::$config['system']['site_icon_url'];
|
||||
}
|
||||
return self::get_project_icon();
|
||||
}
|
||||
|
||||
public static function get_site_favicon() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['site_favicon_url'])
|
||||
return App::$config['system']['site_favicon_url'];
|
||||
return self::get_project_favicon();
|
||||
}
|
||||
public static function get_site_favicon()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['site_favicon_url']) {
|
||||
return App::$config['system']['site_favicon_url'];
|
||||
}
|
||||
return self::get_project_favicon();
|
||||
}
|
||||
|
||||
public static function get_project_link() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_link'])
|
||||
return App::$config['system']['project_link'];
|
||||
return 'https://zotlabs.com/' . PLATFORM_NAME;
|
||||
}
|
||||
public static function get_project_link()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_link']) {
|
||||
return App::$config['system']['project_link'];
|
||||
}
|
||||
return 'https://zotlabs.com/' . PLATFORM_NAME;
|
||||
}
|
||||
|
||||
public static function get_project_srclink() {
|
||||
if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_srclink'])
|
||||
return App::$config['system']['project_srclink'];
|
||||
return 'https://codeberg.org/zot/' . PLATFORM_NAME;
|
||||
}
|
||||
public static function get_project_srclink()
|
||||
{
|
||||
if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_srclink']) {
|
||||
return App::$config['system']['project_srclink'];
|
||||
}
|
||||
return 'https://codeberg.org/zot/' . PLATFORM_NAME;
|
||||
}
|
||||
|
||||
public static function ebs() {
|
||||
if(defined('EBSSTATE')) {
|
||||
return EBSSTATE;
|
||||
}
|
||||
return 'armed';
|
||||
}
|
||||
public static function ebs()
|
||||
{
|
||||
if (defined('EBSSTATE')) {
|
||||
return EBSSTATE;
|
||||
}
|
||||
return 'armed';
|
||||
}
|
||||
|
||||
public static function get_zot_revision() {
|
||||
$x = [ 'revision' => ZOT_REVISION ];
|
||||
call_hooks('zot_revision',$x);
|
||||
return $x['revision'];
|
||||
}
|
||||
public static function get_zot_revision()
|
||||
{
|
||||
$x = [ 'revision' => ZOT_REVISION ];
|
||||
call_hooks('zot_revision', $x);
|
||||
return $x['revision'];
|
||||
}
|
||||
|
||||
public static function get_std_version() {
|
||||
if(defined('STD_VERSION'))
|
||||
return STD_VERSION;
|
||||
return '0.0.0';
|
||||
}
|
||||
public static function get_std_version()
|
||||
{
|
||||
if (defined('STD_VERSION')) {
|
||||
return STD_VERSION;
|
||||
}
|
||||
return '0.0.0';
|
||||
}
|
||||
|
||||
public static function compatible_project($p) {
|
||||
public static function compatible_project($p)
|
||||
{
|
||||
|
||||
if (in_array(strtolower($p),['hubzilla', 'zap', 'red', 'misty', 'mistpark', 'redmatrix', 'osada', 'roadhouse'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (in_array(strtolower($p), ['hubzilla', 'zap', 'red', 'misty', 'mistpark', 'redmatrix', 'osada', 'roadhouse'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,52 +2,62 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
class ThreadListener {
|
||||
class ThreadListener
|
||||
{
|
||||
|
||||
public static function store($target_id, $portable_id, $ltype = 0) {
|
||||
$x = self::fetch($target_id,$portable_id,$ltype = 0);
|
||||
if(! $x) {
|
||||
$r = q("insert into listeners ( target_id, portable_id, ltype ) values ( '%s', '%s' , %d ) ",
|
||||
dbesc($target_id),
|
||||
dbesc($portable_id),
|
||||
intval($ltype)
|
||||
);
|
||||
}
|
||||
}
|
||||
public static function store($target_id, $portable_id, $ltype = 0)
|
||||
{
|
||||
$x = self::fetch($target_id, $portable_id, $ltype = 0);
|
||||
if (! $x) {
|
||||
$r = q(
|
||||
"insert into listeners ( target_id, portable_id, ltype ) values ( '%s', '%s' , %d ) ",
|
||||
dbesc($target_id),
|
||||
dbesc($portable_id),
|
||||
intval($ltype)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static function fetch($target_id, $portable_id, $ltype = 0) {
|
||||
$x = q("select * from listeners where target_id = '%s' and portable_id = '%s' and ltype = %d limit 1",
|
||||
dbesc($target_id),
|
||||
dbesc($portable_id),
|
||||
intval($ltype)
|
||||
);
|
||||
if($x) {
|
||||
return $x[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static function fetch($target_id, $portable_id, $ltype = 0)
|
||||
{
|
||||
$x = q(
|
||||
"select * from listeners where target_id = '%s' and portable_id = '%s' and ltype = %d limit 1",
|
||||
dbesc($target_id),
|
||||
dbesc($portable_id),
|
||||
intval($ltype)
|
||||
);
|
||||
if ($x) {
|
||||
return $x[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function fetch_by_target($target_id, $ltype = 0) {
|
||||
$x = q("select * from listeners where target_id = '%s' and ltype = %d",
|
||||
dbesc($target_id),
|
||||
intval($ltype)
|
||||
);
|
||||
public static function fetch_by_target($target_id, $ltype = 0)
|
||||
{
|
||||
$x = q(
|
||||
"select * from listeners where target_id = '%s' and ltype = %d",
|
||||
dbesc($target_id),
|
||||
intval($ltype)
|
||||
);
|
||||
|
||||
return $x;
|
||||
}
|
||||
return $x;
|
||||
}
|
||||
|
||||
public static function delete_by_target($target_id, $ltype = 0) {
|
||||
return q("delete from listeners where target_id = '%s' and ltype = %d",
|
||||
dbesc($target_id),
|
||||
intval($ltype)
|
||||
);
|
||||
}
|
||||
|
||||
public static function delete_by_pid($portable_id, $ltype = 0) {
|
||||
return q("delete from listeners where portable_id = '%s' and ltype = %d",
|
||||
dbesc($portable_id),
|
||||
intval($ltype)
|
||||
);
|
||||
}
|
||||
public static function delete_by_target($target_id, $ltype = 0)
|
||||
{
|
||||
return q(
|
||||
"delete from listeners where target_id = '%s' and ltype = %d",
|
||||
dbesc($target_id),
|
||||
intval($ltype)
|
||||
);
|
||||
}
|
||||
|
||||
public static function delete_by_pid($portable_id, $ltype = 0)
|
||||
{
|
||||
return q(
|
||||
"delete from listeners where portable_id = '%s' and ltype = %d",
|
||||
dbesc($portable_id),
|
||||
intval($ltype)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php /** @file */
|
||||
<?php
|
||||
|
||||
/** @file */
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
@ -12,240 +14,257 @@ require_once('include/text.php');
|
|||
*
|
||||
*/
|
||||
|
||||
class ThreadStream {
|
||||
class ThreadStream
|
||||
{
|
||||
|
||||
private $threads = [];
|
||||
private $mode = null;
|
||||
private $observer = null;
|
||||
private $writable = false;
|
||||
private $commentable = false;
|
||||
private $uploadable = false;
|
||||
private $profile_owner = 0;
|
||||
private $preview = false;
|
||||
private $prepared_item = '';
|
||||
public $reload = '';
|
||||
private $cipher = 'AES-128-CCM';
|
||||
private $threads = [];
|
||||
private $mode = null;
|
||||
private $observer = null;
|
||||
private $writable = false;
|
||||
private $commentable = false;
|
||||
private $uploadable = false;
|
||||
private $profile_owner = 0;
|
||||
private $preview = false;
|
||||
private $prepared_item = '';
|
||||
public $reload = '';
|
||||
private $cipher = 'AES-128-CCM';
|
||||
|
||||
// $prepared_item is for use by alternate conversation structures such as photos
|
||||
// wherein we've already prepared a top level item which doesn't look anything like
|
||||
// a normal "post" item
|
||||
// $prepared_item is for use by alternate conversation structures such as photos
|
||||
// wherein we've already prepared a top level item which doesn't look anything like
|
||||
// a normal "post" item
|
||||
|
||||
public function __construct($mode, $preview, $uploadable, $prepared_item = '') {
|
||||
$this->set_mode($mode);
|
||||
$this->preview = $preview;
|
||||
$this->uploadable = $uploadable;
|
||||
$this->prepared_item = $prepared_item;
|
||||
$c = ((local_channel()) ? get_pconfig(local_channel(),'system','default_cipher') : '');
|
||||
if($c)
|
||||
$this->cipher = $c;
|
||||
}
|
||||
public function __construct($mode, $preview, $uploadable, $prepared_item = '')
|
||||
{
|
||||
$this->set_mode($mode);
|
||||
$this->preview = $preview;
|
||||
$this->uploadable = $uploadable;
|
||||
$this->prepared_item = $prepared_item;
|
||||
$c = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'default_cipher') : '');
|
||||
if ($c) {
|
||||
$this->cipher = $c;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mode we'll be displayed on
|
||||
*/
|
||||
private function set_mode($mode) {
|
||||
if($this->get_mode() == $mode)
|
||||
return;
|
||||
/**
|
||||
* Set the mode we'll be displayed on
|
||||
*/
|
||||
private function set_mode($mode)
|
||||
{
|
||||
if ($this->get_mode() == $mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->observer = App::get_observer();
|
||||
$ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
|
||||
$this->observer = App::get_observer();
|
||||
$ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
|
||||
|
||||
switch($mode) {
|
||||
case 'stream':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = true;
|
||||
break;
|
||||
case 'pubstream':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = ((local_channel()) ? true : false);
|
||||
break;
|
||||
case 'hq':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = true;
|
||||
break;
|
||||
case 'channel':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
break;
|
||||
case 'cards':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
$this->reload = $_SESSION['return_url'];
|
||||
break;
|
||||
case 'articles':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
$this->reload = $_SESSION['return_url'];
|
||||
break;
|
||||
case 'display':
|
||||
// in this mode we set profile_owner after initialisation (from conversation()) and then
|
||||
// pull some trickery which allows us to re-invoke this function afterward
|
||||
// it's an ugly hack so @FIXME
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
$this->uploadable = perm_is_allowed($this->profile_owner,$ob_hash,'write_storage');
|
||||
break;
|
||||
case 'page':
|
||||
$this->profile_owner = App::$profile['uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
break;
|
||||
default:
|
||||
logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
$this->mode = $mode;
|
||||
}
|
||||
switch ($mode) {
|
||||
case 'stream':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = true;
|
||||
break;
|
||||
case 'pubstream':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = ((local_channel()) ? true : false);
|
||||
break;
|
||||
case 'hq':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = true;
|
||||
break;
|
||||
case 'channel':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
|
||||
break;
|
||||
case 'cards':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
|
||||
$this->reload = $_SESSION['return_url'];
|
||||
break;
|
||||
case 'articles':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
|
||||
$this->reload = $_SESSION['return_url'];
|
||||
break;
|
||||
case 'display':
|
||||
// in this mode we set profile_owner after initialisation (from conversation()) and then
|
||||
// pull some trickery which allows us to re-invoke this function afterward
|
||||
// it's an ugly hack so @FIXME
|
||||
$this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
|
||||
$this->uploadable = perm_is_allowed($this->profile_owner, $ob_hash, 'write_storage');
|
||||
break;
|
||||
case 'page':
|
||||
$this->profile_owner = App::$profile['uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
|
||||
break;
|
||||
default:
|
||||
logger('[ERROR] Conversation::set_mode : Unhandled mode (' . $mode . ').', LOGGER_DEBUG);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode
|
||||
*/
|
||||
public function get_mode() {
|
||||
return $this->mode;
|
||||
}
|
||||
/**
|
||||
* Get mode
|
||||
*/
|
||||
public function get_mode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if page is writable
|
||||
*/
|
||||
public function is_writable() {
|
||||
return $this->writable;
|
||||
}
|
||||
/**
|
||||
* Check if page is writable
|
||||
*/
|
||||
public function is_writable()
|
||||
{
|
||||
return $this->writable;
|
||||
}
|
||||
|
||||
public function is_commentable() {
|
||||
return $this->commentable;
|
||||
}
|
||||
public function is_commentable()
|
||||
{
|
||||
return $this->commentable;
|
||||
}
|
||||
|
||||
public function is_uploadable() {
|
||||
return $this->uploadable;
|
||||
}
|
||||
public function is_uploadable()
|
||||
{
|
||||
return $this->uploadable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if page is a preview
|
||||
*/
|
||||
public function is_preview() {
|
||||
return $this->preview;
|
||||
}
|
||||
/**
|
||||
* Check if page is a preview
|
||||
*/
|
||||
public function is_preview()
|
||||
{
|
||||
return $this->preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile owner
|
||||
*/
|
||||
public function get_profile_owner() {
|
||||
return $this->profile_owner;
|
||||
}
|
||||
/**
|
||||
* Get profile owner
|
||||
*/
|
||||
public function get_profile_owner()
|
||||
{
|
||||
return $this->profile_owner;
|
||||
}
|
||||
|
||||
public function set_profile_owner($uid) {
|
||||
$this->profile_owner = $uid;
|
||||
$mode = $this->get_mode();
|
||||
$this->mode = null;
|
||||
$this->set_mode($mode);
|
||||
}
|
||||
public function set_profile_owner($uid)
|
||||
{
|
||||
$this->profile_owner = $uid;
|
||||
$mode = $this->get_mode();
|
||||
$this->mode = null;
|
||||
$this->set_mode($mode);
|
||||
}
|
||||
|
||||
public function get_observer() {
|
||||
return $this->observer;
|
||||
}
|
||||
public function get_observer()
|
||||
{
|
||||
return $this->observer;
|
||||
}
|
||||
|
||||
public function get_cipher() {
|
||||
return $this->cipher;
|
||||
}
|
||||
public function get_cipher()
|
||||
{
|
||||
return $this->cipher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a thread to the conversation
|
||||
*
|
||||
* Returns:
|
||||
* _ The inserted item on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function add_thread($item) {
|
||||
$item_id = $item->get_id();
|
||||
if(!$item_id) {
|
||||
logger('Item has no ID!!', LOGGER_DEBUG, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
if($this->get_thread($item->get_id())) {
|
||||
logger('Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG, LOG_WARNING);
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Add a thread to the conversation
|
||||
*
|
||||
* Returns:
|
||||
* _ The inserted item on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function add_thread($item)
|
||||
{
|
||||
$item_id = $item->get_id();
|
||||
if (!$item_id) {
|
||||
logger('Item has no ID!!', LOGGER_DEBUG, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
if ($this->get_thread($item->get_id())) {
|
||||
logger('Thread already exists (' . $item->get_id() . ').', LOGGER_DEBUG, LOG_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only add things that will be displayed
|
||||
*/
|
||||
|
||||
|
||||
if(($item->get_data_value('id') != $item->get_data_value('parent')) && (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$item->set_commentable(false);
|
||||
$ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
|
||||
|
||||
if(! comments_are_now_closed($item->get_data())) {
|
||||
if(($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash))
|
||||
$item->set_commentable(true);
|
||||
|
||||
if(intval($item->get_data_value('item_nocomment'))) {
|
||||
$item->set_commentable(false);
|
||||
}
|
||||
elseif(! $item->is_commentable()) {
|
||||
if((array_key_exists('owner',$item->data)) && intval($item->data['owner']['abook_self']))
|
||||
$item->set_commentable(perm_is_allowed($this->profile_owner,$ob_hash,'post_comments'));
|
||||
else
|
||||
$item->set_commentable(can_comment_on_post($ob_hash,$item->data));
|
||||
}
|
||||
}
|
||||
if($this->mode === 'pubstream' && (! local_channel())) {
|
||||
$item->set_commentable(false);
|
||||
}
|
||||
/*
|
||||
* Only add things that will be displayed
|
||||
*/
|
||||
|
||||
|
||||
$item->set_conversation($this);
|
||||
$this->threads[] = $item;
|
||||
return end($this->threads);
|
||||
}
|
||||
if (($item->get_data_value('id') != $item->get_data_value('parent')) && (activity_match($item->get_data_value('verb'), ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'), ACTIVITY_DISLIKE))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data in a form usable by a conversation template
|
||||
*
|
||||
* We should find a way to avoid using those arguments (at least most of them)
|
||||
*
|
||||
* Returns:
|
||||
* _ The data requested on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function get_template_data($conv_responses) {
|
||||
$result = [];
|
||||
$item->set_commentable(false);
|
||||
$ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
|
||||
|
||||
foreach($this->threads as $item) {
|
||||
if (! comments_are_now_closed($item->get_data())) {
|
||||
if (($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash)) {
|
||||
$item->set_commentable(true);
|
||||
}
|
||||
|
||||
if(($item->get_data_value('id') == $item->get_data_value('parent')) && $this->prepared_item) {
|
||||
$item_data = $this->prepared_item;
|
||||
}
|
||||
else {
|
||||
$item_data = $item->get_template_data($conv_responses);
|
||||
}
|
||||
if(!$item_data) {
|
||||
logger('Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
$result[] = $item_data;
|
||||
}
|
||||
if (intval($item->get_data_value('item_nocomment'))) {
|
||||
$item->set_commentable(false);
|
||||
} elseif (! $item->is_commentable()) {
|
||||
if ((array_key_exists('owner', $item->data)) && intval($item->data['owner']['abook_self'])) {
|
||||
$item->set_commentable(perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments'));
|
||||
} else {
|
||||
$item->set_commentable(can_comment_on_post($ob_hash, $item->data));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->mode === 'pubstream' && (! local_channel())) {
|
||||
$item->set_commentable(false);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a thread based on its item id
|
||||
*
|
||||
* Returns:
|
||||
* _ The found item on success
|
||||
* _ false on failure
|
||||
*/
|
||||
private function get_thread($id) {
|
||||
foreach($this->threads as $item) {
|
||||
if($item->get_id() == $id)
|
||||
return $item;
|
||||
}
|
||||
$item->set_conversation($this);
|
||||
$this->threads[] = $item;
|
||||
return end($this->threads);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Get data in a form usable by a conversation template
|
||||
*
|
||||
* We should find a way to avoid using those arguments (at least most of them)
|
||||
*
|
||||
* Returns:
|
||||
* _ The data requested on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function get_template_data($conv_responses)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($this->threads as $item) {
|
||||
if (($item->get_data_value('id') == $item->get_data_value('parent')) && $this->prepared_item) {
|
||||
$item_data = $this->prepared_item;
|
||||
} else {
|
||||
$item_data = $item->get_template_data($conv_responses);
|
||||
}
|
||||
if (!$item_data) {
|
||||
logger('Failed to get item template data (' . $item->get_id() . ').', LOGGER_DEBUG, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
$result[] = $item_data;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a thread based on its item id
|
||||
*
|
||||
* Returns:
|
||||
* _ The found item on success
|
||||
* _ false on failure
|
||||
*/
|
||||
private function get_thread($id)
|
||||
{
|
||||
foreach ($this->threads as $item) {
|
||||
if ($item->get_id() == $id) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
||||
class Verify
|
||||
{
|
||||
|
||||
public static function create($type, $channel_id, $token, $meta)
|
||||
{
|
||||
return q("insert into verify ( vtype, channel, token, meta, created ) values ( '%s', %d, '%s', '%s', '%s' )",
|
||||
return q(
|
||||
"insert into verify ( vtype, channel, token, meta, created ) values ( '%s', %d, '%s', '%s', '%s' )",
|
||||
dbesc($type),
|
||||
intval($channel_id),
|
||||
dbesc($token),
|
||||
|
@ -19,14 +19,16 @@ class Verify
|
|||
|
||||
public static function match($type, $channel_id, $token, $meta)
|
||||
{
|
||||
$r = q("select id from verify where vtype = '%s' and channel = %d and token = '%s' and meta = '%s' limit 1",
|
||||
$r = q(
|
||||
"select id from verify where vtype = '%s' and channel = %d and token = '%s' and meta = '%s' limit 1",
|
||||
dbesc($type),
|
||||
intval($channel_id),
|
||||
dbesc($token),
|
||||
dbesc($meta)
|
||||
);
|
||||
if ($r) {
|
||||
q("delete from verify where id = %d",
|
||||
q(
|
||||
"delete from verify where id = %d",
|
||||
intval($r[0]['id'])
|
||||
);
|
||||
return true;
|
||||
|
@ -36,13 +38,15 @@ class Verify
|
|||
|
||||
public static function get_meta($type, $channel_id, $token)
|
||||
{
|
||||
$r = q("select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1",
|
||||
$r = q(
|
||||
"select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1",
|
||||
dbesc($type),
|
||||
intval($channel_id),
|
||||
dbesc($token)
|
||||
);
|
||||
if ($r) {
|
||||
q("delete from verify where id = %d",
|
||||
q(
|
||||
"delete from verify where id = %d",
|
||||
intval($r[0]['id'])
|
||||
);
|
||||
return $r[0]['meta'];
|
||||
|
@ -58,11 +62,11 @@ class Verify
|
|||
*/
|
||||
public static function purge($type, $interval)
|
||||
{
|
||||
q("delete from verify where vtype = '%s' and created < ( %s - INTERVAL %s )",
|
||||
q(
|
||||
"delete from verify where vtype = '%s' and created < ( %s - INTERVAL %s )",
|
||||
dbesc($type),
|
||||
db_utcnow(),
|
||||
db_quoteinterval($interval)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,4 +105,4 @@ class Webfinger
|
|||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,153 +24,169 @@ use App;
|
|||
* $var = get_xconfig($observer, 'category', 'key');
|
||||
* }@endcode
|
||||
*/
|
||||
class XConfig {
|
||||
class XConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Loads a full xchan's configuration into a cached storage.
|
||||
*
|
||||
* All configuration values of the given observer hash are stored in global
|
||||
* cache which is available under the global variable App::$config[$xchan].
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @return void|false Returns false if xchan is not set
|
||||
*/
|
||||
public static function Load($xchan) {
|
||||
/**
|
||||
* @brief Loads a full xchan's configuration into a cached storage.
|
||||
*
|
||||
* All configuration values of the given observer hash are stored in global
|
||||
* cache which is available under the global variable App::$config[$xchan].
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @return void|false Returns false if xchan is not set
|
||||
*/
|
||||
public static function Load($xchan)
|
||||
{
|
||||
|
||||
if(! $xchan)
|
||||
return false;
|
||||
if (! $xchan) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(! array_key_exists($xchan, App::$config))
|
||||
App::$config[$xchan] = [];
|
||||
if (! array_key_exists($xchan, App::$config)) {
|
||||
App::$config[$xchan] = [];
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM xconfig WHERE xchan = '%s'",
|
||||
dbesc($xchan)
|
||||
);
|
||||
$r = q(
|
||||
"SELECT * FROM xconfig WHERE xchan = '%s'",
|
||||
dbesc($xchan)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$c = $rr['cat'];
|
||||
if(! array_key_exists($c, App::$config[$xchan])) {
|
||||
App::$config[$xchan][$c] = [];
|
||||
App::$config[$xchan][$c]['config_loaded'] = true;
|
||||
}
|
||||
App::$config[$xchan][$c][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$c = $rr['cat'];
|
||||
if (! array_key_exists($c, App::$config[$xchan])) {
|
||||
App::$config[$xchan][$c] = [];
|
||||
App::$config[$xchan][$c]['config_loaded'] = true;
|
||||
}
|
||||
App::$config[$xchan][$c][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular observer's config variable given the category
|
||||
* name ($family) and a key.
|
||||
*
|
||||
* Get a particular observer's config value from the given category ($family)
|
||||
* and the $key from a cached storage in App::$config[$xchan].
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param bool $default (optional) default false
|
||||
* @return mixed Stored $value or false if it does not exist
|
||||
*/
|
||||
public static function Get($xchan, $family, $key, $default = false) {
|
||||
/**
|
||||
* @brief Get a particular observer's config variable given the category
|
||||
* name ($family) and a key.
|
||||
*
|
||||
* Get a particular observer's config value from the given category ($family)
|
||||
* and the $key from a cached storage in App::$config[$xchan].
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param bool $default (optional) default false
|
||||
* @return mixed Stored $value or false if it does not exist
|
||||
*/
|
||||
public static function Get($xchan, $family, $key, $default = false)
|
||||
{
|
||||
|
||||
if(! $xchan)
|
||||
return $default;
|
||||
if (! $xchan) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if(! array_key_exists($xchan, App::$config))
|
||||
load_xconfig($xchan);
|
||||
if (! array_key_exists($xchan, App::$config)) {
|
||||
load_xconfig($xchan);
|
||||
}
|
||||
|
||||
if((! array_key_exists($family, App::$config[$xchan])) || (! array_key_exists($key, App::$config[$xchan][$family])))
|
||||
return $default;
|
||||
if ((! array_key_exists($family, App::$config[$xchan])) || (! array_key_exists($key, App::$config[$xchan][$family]))) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return unserialise(App::$config[$xchan][$family][$key]);
|
||||
}
|
||||
return unserialise(App::$config[$xchan][$family][$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for an observer.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the observer's $xchan hash.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
public static function Set($xchan, $family, $key, $value) {
|
||||
/**
|
||||
* @brief Sets a configuration value for an observer.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the observer's $xchan hash.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
public static function Set($xchan, $family, $key, $value)
|
||||
{
|
||||
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialise($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(self::Get($xchan, $family, $key) === false) {
|
||||
if(! array_key_exists($xchan, App::$config))
|
||||
App::$config[$xchan] = [];
|
||||
if(! array_key_exists($family, App::$config[$xchan]))
|
||||
App::$config[$xchan][$family] = [];
|
||||
if (self::Get($xchan, $family, $key) === false) {
|
||||
if (! array_key_exists($xchan, App::$config)) {
|
||||
App::$config[$xchan] = [];
|
||||
}
|
||||
if (! array_key_exists($family, App::$config[$xchan])) {
|
||||
App::$config[$xchan][$family] = [];
|
||||
}
|
||||
|
||||
$ret = q("INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' )",
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$ret = q("UPDATE xconfig SET v = '%s' WHERE xchan = '%s' and cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
$ret = q(
|
||||
"INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' )",
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
} else {
|
||||
$ret = q(
|
||||
"UPDATE xconfig SET v = '%s' WHERE xchan = '%s' and cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
App::$config[$xchan][$family][$key] = $value;
|
||||
App::$config[$xchan][$family][$key] = $value;
|
||||
|
||||
if($ret)
|
||||
return $value;
|
||||
if ($ret) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the observer's config.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$xchan]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function Delete($xchan, $family, $key) {
|
||||
/**
|
||||
* @brief Deletes the given key from the observer's config.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$xchan]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
public static function Delete($xchan, $family, $key)
|
||||
{
|
||||
|
||||
if(isset(App::$config[$xchan]) && isset(App::$config[$xchan][$family]) && isset(App::$config[$xchan][$family][$key]))
|
||||
unset(App::$config[$xchan][$family][$key]);
|
||||
if (isset(App::$config[$xchan]) && isset(App::$config[$xchan][$family]) && isset(App::$config[$xchan][$family][$key])) {
|
||||
unset(App::$config[$xchan][$family][$key]);
|
||||
}
|
||||
|
||||
$ret = q("DELETE FROM xconfig WHERE xchan = '%s' AND cat = '%s' AND k = '%s'",
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
$ret = q(
|
||||
"DELETE FROM xconfig WHERE xchan = '%s' AND cat = '%s' AND k = '%s'",
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,123 +4,123 @@ namespace Zotlabs\Lib;
|
|||
|
||||
use Zotlabs\Web\HTTPSig;
|
||||
|
||||
class ZotURL
|
||||
{
|
||||
|
||||
class ZotURL {
|
||||
public static function fetch($url, $channel, $hub = null)
|
||||
{
|
||||
|
||||
public static function fetch($url, $channel, $hub = null) {
|
||||
$ret = [ 'success' => false ];
|
||||
|
||||
$ret = [ 'success' => false ];
|
||||
|
||||
if(strpos($url,'x-zot:') !== 0) {
|
||||
return $ret;
|
||||
}
|
||||
if (strpos($url, 'x-zot:') !== 0) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
if(! $url) {
|
||||
return $ret;
|
||||
}
|
||||
if (! $url) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$portable_url = substr($url,6);
|
||||
$u = explode('/',$portable_url);
|
||||
$portable_id = $u[0];
|
||||
$portable_url = substr($url, 6);
|
||||
$u = explode('/', $portable_url);
|
||||
$portable_id = $u[0];
|
||||
|
||||
$hosts = self::lookup($portable_id,$hub);
|
||||
$hosts = self::lookup($portable_id, $hub);
|
||||
|
||||
if(! $hosts) {
|
||||
return $ret;
|
||||
}
|
||||
if (! $hosts) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
foreach($hosts as $h) {
|
||||
$newurl = $h . '/id/' . $portable_url;
|
||||
foreach ($hosts as $h) {
|
||||
$newurl = $h . '/id/' . $portable_url;
|
||||
|
||||
$m = parse_url($newurl);
|
||||
$m = parse_url($newurl);
|
||||
|
||||
$data = json_encode([ 'zot_token' => random_string() ]);
|
||||
$data = json_encode([ 'zot_token' => random_string() ]);
|
||||
|
||||
if($channel && $m) {
|
||||
if ($channel && $m) {
|
||||
$headers = [
|
||||
'Accept' => 'application/x-zot+json',
|
||||
'Content-Type' => 'application/x-zot+json',
|
||||
'X-Zot-Token' => random_string(),
|
||||
'Digest' => HTTPSig::generate_digest_header($data),
|
||||
'Host' => $m['host'],
|
||||
'(request-target)' => 'post ' . get_request_string($newurl)
|
||||
];
|
||||
$h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), false);
|
||||
} else {
|
||||
$h = [ 'Accept: application/x-zot+json' ];
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Accept' => 'application/x-zot+json',
|
||||
'Content-Type' => 'application/x-zot+json',
|
||||
'X-Zot-Token' => random_string(),
|
||||
'Digest' => HTTPSig::generate_digest_header($data),
|
||||
'Host' => $m['host'],
|
||||
'(request-target)' => 'post ' . get_request_string($newurl)
|
||||
];
|
||||
$h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),false);
|
||||
}
|
||||
else {
|
||||
$h = [ 'Accept: application/x-zot+json' ];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$result = [];
|
||||
|
||||
$redirects = 0;
|
||||
$x = z_post_url($newurl,$data,$redirects, [ 'headers' => $h ] );
|
||||
if($x['success']) {
|
||||
return $x;
|
||||
}
|
||||
}
|
||||
$redirects = 0;
|
||||
$x = z_post_url($newurl, $data, $redirects, [ 'headers' => $h ]);
|
||||
if ($x['success']) {
|
||||
return $x;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
public static function is_zoturl($s)
|
||||
{
|
||||
|
||||
public static function is_zoturl($s) {
|
||||
|
||||
if(strpos($url,'x-zot:') === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (strpos($url, 'x-zot:') === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function lookup($portable_id, $hub) {
|
||||
public static function lookup($portable_id, $hub)
|
||||
{
|
||||
|
||||
$r = q("select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc",
|
||||
dbesc($portable_id)
|
||||
);
|
||||
$r = q(
|
||||
"select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc",
|
||||
dbesc($portable_id)
|
||||
);
|
||||
|
||||
if(! $r) {
|
||||
if (! $r) {
|
||||
// extend to network lookup
|
||||
|
||||
// extend to network lookup
|
||||
$path = '/q/' . $portable_id;
|
||||
|
||||
$path = '/q/' . $portable_id;
|
||||
// first check sending hub since they have recently communicated with this object
|
||||
|
||||
// first check sending hub since they have recently communicated with this object
|
||||
$redirects = 0;
|
||||
|
||||
$redirects = 0;
|
||||
if ($hub) {
|
||||
$x = z_fetch_url($hub['hubloc_url'] . $path, false, $redirects);
|
||||
$u = self::parse_response($x);
|
||||
if ($u) {
|
||||
return $u;
|
||||
}
|
||||
}
|
||||
|
||||
if($hub) {
|
||||
$x = z_fetch_url($hub['hubloc_url'] . $path, false, $redirects);
|
||||
$u = self::parse_response($x);
|
||||
if($u) {
|
||||
return $u;
|
||||
}
|
||||
}
|
||||
// If this fails, fallback on directory servers
|
||||
|
||||
// If this fails, fallback on directory servers
|
||||
|
||||
return false;
|
||||
}
|
||||
return ids_to_array($r,'hubloc_url');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return ids_to_array($r, 'hubloc_url');
|
||||
}
|
||||
|
||||
|
||||
public static function parse_response($arr) {
|
||||
if(! $arr['success']) {
|
||||
return false;
|
||||
}
|
||||
$a = json_decode($arr['body'],true);
|
||||
if($a['success'] && array_key_exists('results', $a) && is_array($a['results']) && count($a['results'])) {
|
||||
foreach($a['results'] as $b) {
|
||||
$m = discover_by_webbie($b);
|
||||
if($m) {
|
||||
return([ $b ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public static function parse_response($arr)
|
||||
{
|
||||
if (! $arr['success']) {
|
||||
return false;
|
||||
}
|
||||
$a = json_decode($arr['body'], true);
|
||||
if ($a['success'] && array_key_exists('results', $a) && is_array($a['results']) && count($a['results'])) {
|
||||
foreach ($a['results'] as $b) {
|
||||
$m = discover_by_webbie($b);
|
||||
if ($m) {
|
||||
return([ $b ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ class Zotfinger
|
|||
$data = json_encode(['zot_token' => random_string()]);
|
||||
|
||||
if ($channel && $m) {
|
||||
|
||||
$headers = [
|
||||
'Accept' => 'application/x-zot+json',
|
||||
'Content-Type' => 'application/x-zot+json',
|
||||
|
@ -44,7 +43,6 @@ class Zotfinger
|
|||
$x = z_post_url($resource, $data, $redirects, ['headers' => $h]);
|
||||
|
||||
if ($x['success']) {
|
||||
|
||||
if ($verify) {
|
||||
$result['signature'] = HTTPSig::verify($x, EMPTY_STR, 'zot6');
|
||||
}
|
||||
|
@ -60,5 +58,4 @@ class Zotfinger
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,11 +70,11 @@ class Acl extends Controller
|
|||
$permitted = [];
|
||||
|
||||
if (in_array($type, ['m', 'a', 'f'])) {
|
||||
|
||||
// These queries require permission checking. We'll create a simple array of xchan_hash for those with
|
||||
// the requisite permissions which we can check against.
|
||||
|
||||
$x = q("select xchan from abconfig where chan = %d and cat = 'system' and k = 'their_perms' and v like '%s'",
|
||||
$x = q(
|
||||
"select xchan from abconfig where chan = %d and cat = 'system' and k = 'their_perms' and v like '%s'",
|
||||
intval(local_channel()),
|
||||
dbesc(($type === 'm') ? '%post_mail%' : '%tag_deliver%')
|
||||
);
|
||||
|
@ -102,8 +102,6 @@ class Acl extends Controller
|
|||
$sql_extra3 = "AND ( xchan_addr like " . protect_sprintf("'%" . dbesc(punify($search)) . "%'") . " OR xchan_name like " . protect_sprintf("'%" . dbesc($search) . "%'") . " OR abook_alias like " . protect_sprintf("'%" . dbesc($search) . "%'") . " ) ";
|
||||
|
||||
$sql_extra4 = "AND ( xchan_name LIKE " . protect_sprintf("'%" . dbesc($search) . "%'") . " OR xchan_addr LIKE " . protect_sprintf("'%" . dbesc(punify($search)) . ((strpos($search, '@') === false) ? "%@%'" : "%'")) . " OR abook_alias LIKE " . protect_sprintf("'%" . dbesc($search) . "%'") . ") ";
|
||||
|
||||
|
||||
} else {
|
||||
$sql_extra = $sql_extra2 = $sql_extra3 = $sql_extra4 = "";
|
||||
}
|
||||
|
@ -113,10 +111,10 @@ class Acl extends Controller
|
|||
$contacts = [];
|
||||
|
||||
if ($type == '' || $type == 'g') {
|
||||
|
||||
// Normal privacy groups
|
||||
|
||||
$r = q("SELECT pgrp.id, pgrp.hash, pgrp.gname
|
||||
$r = q(
|
||||
"SELECT pgrp.id, pgrp.hash, pgrp.gname
|
||||
FROM pgrp, pgrp_member
|
||||
WHERE pgrp.deleted = 0 AND pgrp.uid = %d
|
||||
AND pgrp_member.gid = pgrp.id
|
||||
|
@ -131,7 +129,7 @@ class Acl extends Controller
|
|||
|
||||
if ($r) {
|
||||
foreach ($r as $g) {
|
||||
// logger('acl: group: ' . $g['gname'] . ' members: ' . AccessList::members_xchan(local_channel(),$g['id']));
|
||||
// logger('acl: group: ' . $g['gname'] . ' members: ' . AccessList::members_xchan(local_channel(),$g['id']));
|
||||
$groups[] = [
|
||||
"type" => "g",
|
||||
"photo" => "images/twopeople.png",
|
||||
|
@ -146,40 +144,36 @@ class Acl extends Controller
|
|||
}
|
||||
|
||||
if ($type == '' || $type == 'c' || $type === 'f') {
|
||||
|
||||
// Getting info from the abook is better for local users because it contains info about permissions
|
||||
if (local_channel()) {
|
||||
|
||||
// add connections
|
||||
|
||||
$r = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, xchan_type, abook_flags, abook_self
|
||||
$r = q(
|
||||
"SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, xchan_type, abook_flags, abook_self
|
||||
FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE abook_channel = %d AND abook_blocked = 0 and abook_pending = 0 and xchan_deleted = 0 $sql_extra4 order by xchan_name asc limit $count",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
} else { // Visitors
|
||||
$r = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_flags, 0 as abook_self
|
||||
$r = q(
|
||||
"SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_flags, 0 as abook_self
|
||||
FROM xchan left join xlink on xlink_link = xchan_hash
|
||||
WHERE xlink_xchan = '%s' AND xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc limit $count",
|
||||
dbesc(get_observer_hash())
|
||||
);
|
||||
|
||||
}
|
||||
if ((count($r) < 100) && $type == 'c') {
|
||||
$r2 = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_flags, 0 as abook_self
|
||||
FROM xchan WHERE xchan_deleted = 0 and xchan_network != 'unknown' $sql_extra2 order by $order_extra2 xchan_name asc limit $count"
|
||||
);
|
||||
FROM xchan WHERE xchan_deleted = 0 and xchan_network != 'unknown' $sql_extra2 order by $order_extra2 xchan_name asc limit $count");
|
||||
if ($r2) {
|
||||
$r = array_merge($r, $r2);
|
||||
$r = unique_multidim_array($r, 'hash');
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($type == 'm') {
|
||||
|
||||
$r = [];
|
||||
$z = q("SELECT xchan_hash as hash, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url
|
||||
$z = q(
|
||||
"SELECT xchan_hash as hash, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url
|
||||
FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE abook_channel = %d
|
||||
and xchan_deleted = 0
|
||||
|
@ -194,19 +188,18 @@ class Acl extends Controller
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($type == 'a') {
|
||||
|
||||
$r = q("SELECT abook_id as id, xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
$r = q(
|
||||
"SELECT abook_id as id, xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE abook_channel = %d
|
||||
and xchan_deleted = 0
|
||||
$sql_extra3
|
||||
ORDER BY xchan_name ASC ",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
} elseif ($type == 'z') {
|
||||
$r = q("SELECT xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM xchan left join abook on xchan_hash = abook_xchan
|
||||
$r = q(
|
||||
"SELECT xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM xchan left join abook on xchan_hash = abook_xchan
|
||||
WHERE ( abook_channel = %d OR abook_channel IS NULL )
|
||||
and xchan_deleted = 0
|
||||
$sql_extra3
|
||||
|
@ -240,7 +233,6 @@ class Acl extends Controller
|
|||
|
||||
if ($r) {
|
||||
foreach ($r as $g) {
|
||||
|
||||
if (isset($g['network']) && in_array($g['network'], ['rss', 'anon', 'unknown']) && ($type != 'a')) {
|
||||
continue;
|
||||
}
|
||||
|
@ -301,7 +293,7 @@ class Acl extends Controller
|
|||
public function navbar_complete()
|
||||
{
|
||||
|
||||
// logger('navbar_complete');
|
||||
// logger('navbar_complete');
|
||||
|
||||
if (observer_prohibited()) {
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Module;
|
||||
|
||||
use Zotlabs\Web\Controller;
|
||||
|
@ -30,7 +31,8 @@ class Activity extends Controller
|
|||
$bear = ZlibActivity::token_from_request();
|
||||
if ($bear) {
|
||||
logger('bear: ' . $bear, LOGGER_DEBUG);
|
||||
$t = q("select item.uid, iconfig.v from iconfig left join item on iid = item.id where cat = 'ocap' and item.uuid = '%s'",
|
||||
$t = q(
|
||||
"select item.uid, iconfig.v from iconfig left join item on iid = item.id where cat = 'ocap' and item.uuid = '%s'",
|
||||
dbesc($item_id)
|
||||
);
|
||||
if ($t) {
|
||||
|
@ -68,14 +70,16 @@ class Activity extends Controller
|
|||
$sql_extra = item_permissions_sql(0);
|
||||
}
|
||||
|
||||
$r = q("select * from item where ( uuid = '%s' or mid = '%s' or mid = '%s' ) $item_normal $sql_extra limit 1",
|
||||
$r = q(
|
||||
"select * from item where ( uuid = '%s' or mid = '%s' or mid = '%s' ) $item_normal $sql_extra limit 1",
|
||||
dbesc($item_id),
|
||||
dbesc(z_root() . '/activity/' . $item_id),
|
||||
dbesc(z_root() . '/item/' . $item_id)
|
||||
);
|
||||
|
||||
if (!$r) {
|
||||
$r = q("select * from item where ( uuid = '%s' or mid = '%s' or mid = '%s' ) $item_normal limit 1",
|
||||
$r = q(
|
||||
"select * from item where ( uuid = '%s' or mid = '%s' or mid = '%s' ) $item_normal limit 1",
|
||||
dbesc($item_id),
|
||||
dbesc(z_root() . '/activity/' . $item_id),
|
||||
dbesc(z_root() . '/item/' . $item_id)
|
||||
|
@ -91,7 +95,8 @@ class Activity extends Controller
|
|||
$items = fetch_post_tags($r, false);
|
||||
|
||||
if ($portable_id && (!intval($items[0]['item_private']))) {
|
||||
$c = q("select abook_id from abook where abook_channel = %d and abook_xchan = '%s'",
|
||||
$c = q(
|
||||
"select abook_id from abook where abook_channel = %d and abook_xchan = '%s'",
|
||||
intval($items[0]['uid']),
|
||||
dbesc($portable_id)
|
||||
);
|
||||
|
@ -103,11 +108,9 @@ class Activity extends Controller
|
|||
$channel = channelx_by_n($items[0]['uid']);
|
||||
|
||||
as_return_and_die(ZlibActivity::encode_activity($items[0], true), $channel);
|
||||
|
||||
}
|
||||
|
||||
if (Libzot::is_zot_request()) {
|
||||
|
||||
$item_id = argv(1);
|
||||
|
||||
if (!$item_id) {
|
||||
|
@ -122,12 +125,14 @@ class Activity extends Controller
|
|||
|
||||
// do we have the item (at all)?
|
||||
|
||||
$r = q("select * from item where mid = '%s' $item_normal limit 1",
|
||||
$r = q(
|
||||
"select * from item where mid = '%s' $item_normal limit 1",
|
||||
dbesc(z_root() . '/activity/' . $item_id)
|
||||
);
|
||||
|
||||
if (!$r) {
|
||||
$r = q("select * from item where mid = '%s' $item_normal limit 1",
|
||||
$r = q(
|
||||
"select * from item where mid = '%s' $item_normal limit 1",
|
||||
dbesc(z_root() . '/item/' . $item_id)
|
||||
);
|
||||
if ($r) {
|
||||
|
@ -146,12 +151,14 @@ class Activity extends Controller
|
|||
// first see if we have a copy of this item's parent owned by the current signer
|
||||
// include xchans for all zot-like networks - these will have the same guid and public key
|
||||
|
||||
$x = q("select * from xchan where xchan_hash = '%s'",
|
||||
$x = q(
|
||||
"select * from xchan where xchan_hash = '%s'",
|
||||
dbesc($sigdata['portable_id'])
|
||||
);
|
||||
|
||||
if ($x) {
|
||||
$xchans = q("select xchan_hash from xchan where xchan_hash = '%s' OR ( xchan_guid = '%s' AND xchan_pubkey = '%s' ) ",
|
||||
$xchans = q(
|
||||
"select xchan_hash from xchan where xchan_hash = '%s' OR ( xchan_guid = '%s' AND xchan_pubkey = '%s' ) ",
|
||||
dbesc($sigdata['portable_id']),
|
||||
dbesc($x[0]['xchan_guid']),
|
||||
dbesc($x[0]['xchan_pubkey'])
|
||||
|
@ -159,7 +166,8 @@ class Activity extends Controller
|
|||
|
||||
if ($xchans) {
|
||||
$hashes = ids_to_querystr($xchans, 'xchan_hash', true);
|
||||
$i = q("select id as item_id from item where mid = '%s' $item_normal and owner_xchan in ( " . protect_sprintf($hashes) . " ) limit 1",
|
||||
$i = q(
|
||||
"select id as item_id from item where mid = '%s' $item_normal and owner_xchan in ( " . protect_sprintf($hashes) . " ) limit 1",
|
||||
dbesc($r[0]['parent_mid'])
|
||||
);
|
||||
}
|
||||
|
@ -172,7 +180,8 @@ class Activity extends Controller
|
|||
$sql_extra = item_permissions_sql(0);
|
||||
|
||||
if (!$i) {
|
||||
$i = q("select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1",
|
||||
$i = q(
|
||||
"select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1",
|
||||
dbesc($r[0]['parent_mid'])
|
||||
);
|
||||
}
|
||||
|
@ -181,11 +190,13 @@ class Activity extends Controller
|
|||
if ($bear) {
|
||||
logger('bear: ' . $bear, LOGGER_DEBUG);
|
||||
if (!$i) {
|
||||
$t = q("select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'",
|
||||
$t = q(
|
||||
"select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'",
|
||||
dbesc($bear)
|
||||
);
|
||||
if ($t) {
|
||||
$i = q("select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1",
|
||||
$i = q(
|
||||
"select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1",
|
||||
dbesc($item_id),
|
||||
intval($t[0]['iid'])
|
||||
);
|
||||
|
@ -200,7 +211,8 @@ class Activity extends Controller
|
|||
|
||||
$parents_str = ids_to_querystr($i, 'item_id');
|
||||
|
||||
$items = q("SELECT item.*, item.id AS item_id FROM item WHERE item.parent IN ( %s ) $item_normal ",
|
||||
$items = q(
|
||||
"SELECT item.*, item.id AS item_id FROM item WHERE item.parent IN ( %s ) $item_normal ",
|
||||
dbesc($parents_str)
|
||||
);
|
||||
|
||||
|
@ -217,7 +229,6 @@ class Activity extends Controller
|
|||
$to = (($recips && array_key_exists('to', $recips) && is_array($recips['to'])) ? $recips['to'] : null);
|
||||
$nitems = [];
|
||||
foreach ($items as $i) {
|
||||
|
||||
$mids = [];
|
||||
|
||||
if (intval($i['item_private'])) {
|
||||
|
@ -239,29 +250,32 @@ class Activity extends Controller
|
|||
if ((!$to) || (!in_array($observer['xchan_url'], $to))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
$nitems[] = $i;
|
||||
}
|
||||
|
||||
if (!$nitems)
|
||||
if (!$nitems) {
|
||||
http_status_exit(404, 'Not found');
|
||||
}
|
||||
|
||||
$chan = channelx_by_n($nitems[0]['uid']);
|
||||
|
||||
if (!$chan)
|
||||
if (!$chan) {
|
||||
http_status_exit(404, 'Not found');
|
||||
}
|
||||
|
||||
if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream'))
|
||||
if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream')) {
|
||||
http_status_exit(403, 'Forbidden');
|
||||
}
|
||||
|
||||
$i = ZlibActivity::encode_item_collection($nitems, 'conversation/' . $item_id, 'OrderedCollection', true, count($nitems));
|
||||
if ($portable_id && (!intval($items[0]['item_private']))) {
|
||||
ThreadListener::store(z_root() . '/activity/' . $item_id, $portable_id);
|
||||
}
|
||||
|
||||
if (!$i)
|
||||
if (!$i) {
|
||||
http_status_exit(404, 'Not found');
|
||||
}
|
||||
|
||||
$x = array_merge(['@context' => [
|
||||
ACTIVITYSTREAMS_JSONLD_REV,
|
||||
|
@ -279,11 +293,9 @@ class Activity extends Controller
|
|||
HTTPSig::set_headers($h);
|
||||
echo $ret;
|
||||
killme();
|
||||
|
||||
}
|
||||
|
||||
|
||||
goaway(z_root() . '/item/' . argv(1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file Zotlabs/Module/Admin.php
|
||||
* @brief Hubzilla's admin controller.
|
||||
|
@ -13,7 +14,6 @@ use Zotlabs\Web\Controller;
|
|||
use Zotlabs\Web\SubModule;
|
||||
use Zotlabs\Lib\Config;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Admin area.
|
||||
*
|
||||
|
@ -112,7 +112,8 @@ class Admin extends Controller
|
|||
|
||||
// list total user accounts, expirations etc.
|
||||
$accounts = [];
|
||||
$r = q("SELECT COUNT(CASE WHEN account_id > 0 THEN 1 ELSE NULL END) AS total, COUNT(CASE WHEN account_expires > %s THEN 1 ELSE NULL END) AS expiring, COUNT(CASE WHEN account_expires < %s AND account_expires > '%s' THEN 1 ELSE NULL END) AS expired, COUNT(CASE WHEN (account_flags & %d)>0 THEN 1 ELSE NULL END) AS blocked FROM account",
|
||||
$r = q(
|
||||
"SELECT COUNT(CASE WHEN account_id > 0 THEN 1 ELSE NULL END) AS total, COUNT(CASE WHEN account_expires > %s THEN 1 ELSE NULL END) AS expiring, COUNT(CASE WHEN account_expires < %s AND account_expires > '%s' THEN 1 ELSE NULL END) AS expired, COUNT(CASE WHEN (account_flags & %d)>0 THEN 1 ELSE NULL END) AS blocked FROM account",
|
||||
db_utcnow(),
|
||||
db_utcnow(),
|
||||
dbesc(NULL_DATE),
|
||||
|
@ -127,7 +128,8 @@ class Admin extends Controller
|
|||
|
||||
// pending registrations
|
||||
|
||||
$pdg = q("SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) > 0 ",
|
||||
$pdg = q(
|
||||
"SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) > 0 ",
|
||||
intval(ACCOUNT_PENDING)
|
||||
);
|
||||
|
||||
|
@ -189,5 +191,4 @@ class Admin extends Controller
|
|||
'$build' => Config::Get('system', 'db_version')
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Module\Admin;
|
||||
|
||||
|
||||
class Account_edit
|
||||
{
|
||||
|
||||
|
@ -11,38 +10,42 @@ class Account_edit
|
|||
|
||||
$account_id = $_REQUEST['aid'];
|
||||
|
||||
if (!$account_id)
|
||||
if (!$account_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pass1 = trim($_REQUEST['pass1']);
|
||||
$pass2 = trim($_REQUEST['pass2']);
|
||||
if ($pass1 && $pass2 && ($pass1 === $pass2)) {
|
||||
$salt = random_string(32);
|
||||
$password_encoded = hash('whirlpool', $salt . $pass1);
|
||||
$r = q("update account set account_salt = '%s', account_password = '%s',
|
||||
$r = q(
|
||||
"update account set account_salt = '%s', account_password = '%s',
|
||||
account_password_changed = '%s' where account_id = %d",
|
||||
dbesc($salt),
|
||||
dbesc($password_encoded),
|
||||
dbesc(datetime_convert()),
|
||||
intval($account_id)
|
||||
);
|
||||
if ($r)
|
||||
if ($r) {
|
||||
info(sprintf(t('Password changed for account %d.'), $account_id) . EOL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$service_class = trim($_REQUEST['service_class']);
|
||||
$account_language = trim($_REQUEST['account_language']);
|
||||
|
||||
$r = q("update account set account_service_class = '%s', account_language = '%s'
|
||||
$r = q(
|
||||
"update account set account_service_class = '%s', account_language = '%s'
|
||||
where account_id = %d",
|
||||
dbesc($service_class),
|
||||
dbesc($account_language),
|
||||
intval($account_id)
|
||||
);
|
||||
|
||||
if ($r)
|
||||
if ($r) {
|
||||
info(t('Account settings updated.') . EOL);
|
||||
}
|
||||
|
||||
goaway(z_root() . '/admin/accounts');
|
||||
}
|
||||
|
@ -50,10 +53,12 @@ class Account_edit
|
|||
|
||||
public function get()
|
||||
{
|
||||
if (argc() > 2)
|
||||
if (argc() > 2) {
|
||||
$account_id = argv(2);
|
||||
}
|
||||
|
||||
$x = q("select * from account where account_id = %d limit 1",
|
||||
$x = q(
|
||||
"select * from account where account_id = %d limit 1",
|
||||
intval($account_id)
|
||||
);
|
||||
|
||||
|
@ -71,13 +76,8 @@ class Account_edit
|
|||
'$account_language' => ['account_language', t('Account language (for emails)'), $x[0]['account_language'], '', language_list()],
|
||||
'$service_class' => ['service_class', t('Service class'), $x[0]['account_service_class'], ''],
|
||||
'$submit' => t('Submit'),
|
||||
]
|
||||
);
|
||||
]);
|
||||
|
||||
return $a;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ class Accounts
|
|||
for ($i = 0; $i < count($users); $i++) {
|
||||
// if account is blocked remove blocked bit-flag, otherwise add blocked bit-flag
|
||||
$op = ($blocked[$i]) ? '& ~' : '| ';
|
||||
q("UPDATE account SET account_flags = (account_flags $op %d) WHERE account_id = %d",
|
||||
q(
|
||||
"UPDATE account SET account_flags = (account_flags $op %d) WHERE account_id = %d",
|
||||
intval(ACCOUNT_BLOCKED),
|
||||
intval($users[$i])
|
||||
);
|
||||
|
@ -78,7 +79,8 @@ class Accounts
|
|||
{
|
||||
if (argc() > 2) {
|
||||
$uid = argv(3);
|
||||
$account = q("SELECT * FROM account WHERE account_id = %d",
|
||||
$account = q(
|
||||
"SELECT * FROM account WHERE account_id = %d",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -97,7 +99,8 @@ class Accounts
|
|||
notice(sprintf(t("Account '%s' deleted"), $account[0]['account_email']) . EOL);
|
||||
break;
|
||||
case 'block':
|
||||
q("UPDATE account SET account_flags = ( account_flags | %d ) WHERE account_id = %d",
|
||||
q(
|
||||
"UPDATE account SET account_flags = ( account_flags | %d ) WHERE account_id = %d",
|
||||
intval(ACCOUNT_BLOCKED),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -105,7 +108,8 @@ class Accounts
|
|||
notice(sprintf(t("Account '%s' blocked"), $account[0]['account_email']) . EOL);
|
||||
break;
|
||||
case 'unblock':
|
||||
q("UPDATE account SET account_flags = ( account_flags & ~ %d ) WHERE account_id = %d",
|
||||
q(
|
||||
"UPDATE account SET account_flags = ( account_flags & ~ %d ) WHERE account_id = %d",
|
||||
intval(ACCOUNT_BLOCKED),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -118,7 +122,8 @@ class Accounts
|
|||
}
|
||||
|
||||
/* get pending */
|
||||
$pending = q("SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) != 0 ",
|
||||
$pending = q(
|
||||
"SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) != 0 ",
|
||||
intval(ACCOUNT_PENDING)
|
||||
);
|
||||
|
||||
|
@ -141,7 +146,8 @@ class Accounts
|
|||
$base = z_root() . '/admin/accounts?f=';
|
||||
$odir = (($dir === 'asc') ? '0' : '1');
|
||||
|
||||
$users = q("SELECT account_id , account_email, account_lastlog, account_created, account_expires, account_service_class, ( account_flags & %d ) > 0 as blocked,
|
||||
$users = q(
|
||||
"SELECT account_id , account_email, account_lastlog, account_created, account_expires, account_service_class, ( account_flags & %d ) > 0 as blocked,
|
||||
(SELECT %s FROM channel as ch WHERE ch.channel_account_id = ac.account_id and ch.channel_removed = 0 ) as channels FROM account as ac
|
||||
where true $serviceclass and account_flags != %d order by $key $dir limit %d offset %d ",
|
||||
intval(ACCOUNT_BLOCKED),
|
||||
|
|
|
@ -226,7 +226,7 @@ class Addons
|
|||
foreach ($git->git->tree('master') as $object) {
|
||||
if ($object['type'] == 'blob' && (strtolower($object['file']) === 'readme.md' || strtolower($object['file']) === 'readme')) {
|
||||
$repo['readme'] = MarkdownExtra::defaultTransform($git->git->cat->blob($object['hash']));
|
||||
} else if ($object['type'] == 'blob' && strtolower($object['file']) === 'manifest.json') {
|
||||
} elseif ($object['type'] == 'blob' && strtolower($object['file']) === 'manifest.json') {
|
||||
$repo['manifest'] = $git->git->cat->blob($object['hash']);
|
||||
}
|
||||
}
|
||||
|
@ -297,8 +297,9 @@ class Addons
|
|||
|
||||
if ($pinstalled) {
|
||||
@require_once("addon/$plugin/$plugin.php");
|
||||
if (function_exists($plugin . '_plugin_admin'))
|
||||
if (function_exists($plugin . '_plugin_admin')) {
|
||||
goaway(z_root() . '/admin/addons/' . $plugin);
|
||||
}
|
||||
}
|
||||
goaway(z_root() . '/admin/addons');
|
||||
}
|
||||
|
@ -317,13 +318,14 @@ class Addons
|
|||
if (is_file("addon/$plugin/README.md")) {
|
||||
$readme = file_get_contents("addon/$plugin/README.md");
|
||||
$readme = MarkdownExtra::defaultTransform($readme);
|
||||
} else if (is_file("addon/$plugin/README")) {
|
||||
} elseif (is_file("addon/$plugin/README")) {
|
||||
$readme = "<pre>" . file_get_contents("addon/$plugin/README") . "</pre>";
|
||||
}
|
||||
|
||||
$admin_form = '';
|
||||
|
||||
$r = q("select * from addon where plugin_admin = 1 and aname = '%s' limit 1",
|
||||
$r = q(
|
||||
"select * from addon where plugin_admin = 1 and aname = '%s' limit 1",
|
||||
dbesc($plugin)
|
||||
);
|
||||
|
||||
|
@ -409,7 +411,8 @@ class Addons
|
|||
}
|
||||
|
||||
$admin_plugins_add_repo_form = replace_macros(
|
||||
get_markup_template('admin_plugins_addrepo.tpl'), array(
|
||||
get_markup_template('admin_plugins_addrepo.tpl'),
|
||||
array(
|
||||
'$post' => 'admin/addons/addrepo',
|
||||
'$desc' => t('Enter the public git repository URL of the addon repo.'),
|
||||
'$repoURL' => array('repoURL', t('Addon repo git URL'), '', ''),
|
||||
|
@ -419,7 +422,8 @@ class Addons
|
|||
);
|
||||
$newRepoModalID = random_string(3);
|
||||
$newRepoModal = replace_macros(
|
||||
get_markup_template('generic_modal.tpl'), array(
|
||||
get_markup_template('generic_modal.tpl'),
|
||||
array(
|
||||
'$id' => $newRepoModalID,
|
||||
'$title' => t('Install new repo'),
|
||||
'$ok' => t('Install'),
|
||||
|
@ -480,5 +484,4 @@ class Addons
|
|||
{
|
||||
return (strcmp(strtolower($a[2]['name']), strtolower($b[2]['name'])));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ class Channels
|
|||
|
||||
if (x($_POST, 'page_channels_block')) {
|
||||
foreach ($channels as $uid) {
|
||||
q("UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d",
|
||||
q(
|
||||
"UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d",
|
||||
intval(PAGE_CENSORED),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -37,7 +38,8 @@ class Channels
|
|||
}
|
||||
if (x($_POST, 'page_channels_code')) {
|
||||
foreach ($channels as $uid) {
|
||||
q("UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d",
|
||||
q(
|
||||
"UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d",
|
||||
intval(PAGE_ALLOWCODE),
|
||||
intval($uid)
|
||||
);
|
||||
|
@ -63,7 +65,8 @@ class Channels
|
|||
{
|
||||
if (argc() > 2) {
|
||||
$uid = argv(3);
|
||||
$channel = q("SELECT * FROM channel WHERE channel_id = %d",
|
||||
$channel = q(
|
||||
"SELECT * FROM channel WHERE channel_id = %d",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
|
@ -80,34 +83,36 @@ class Channels
|
|||
channel_remove($uid, true);
|
||||
|
||||
notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "block":
|
||||
{
|
||||
check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
|
||||
$pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED;
|
||||
q("UPDATE channel SET channel_pageflags = %d where channel_id = %d",
|
||||
q(
|
||||
"UPDATE channel SET channel_pageflags = %d where channel_id = %d",
|
||||
intval($pflags),
|
||||
intval($uid)
|
||||
);
|
||||
Run::Summon(['Directory', $uid, 'nopush']);
|
||||
|
||||
notice(sprintf((($pflags & PAGE_CENSORED) ? t("Channel '%s' censored") : t("Channel '%s' uncensored")), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "code":
|
||||
{
|
||||
check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
|
||||
$pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE;
|
||||
q("UPDATE channel SET channel_pageflags = %d where channel_id = %d",
|
||||
q(
|
||||
"UPDATE channel SET channel_pageflags = %d where channel_id = %d",
|
||||
intval($pflags),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
notice(sprintf((($pflags & PAGE_ALLOWCODE) ? t("Channel '%s' code allowed") : t("Channel '%s' code disallowed")), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -118,8 +123,9 @@ class Channels
|
|||
|
||||
$key = (($_REQUEST['key']) ? dbesc($_REQUEST['key']) : 'channel_id');
|
||||
$dir = 'asc';
|
||||
if (array_key_exists('dir', $_REQUEST))
|
||||
if (array_key_exists('dir', $_REQUEST)) {
|
||||
$dir = ((intval($_REQUEST['dir'])) ? 'asc' : 'desc');
|
||||
}
|
||||
|
||||
$base = z_root() . '/admin/channels?f=';
|
||||
$odir = (($dir === 'asc') ? '0' : '1');
|
||||
|
@ -132,22 +138,25 @@ class Channels
|
|||
App::set_pager_itemspage(100);
|
||||
}
|
||||
|
||||
$channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 order by $key $dir limit %d offset %d ",
|
||||
$channels = q(
|
||||
"SELECT * from channel where channel_removed = 0 and channel_system = 0 order by $key $dir limit %d offset %d ",
|
||||
intval(App::$pager['itemspage']),
|
||||
intval(App::$pager['start'])
|
||||
);
|
||||
|
||||
if ($channels) {
|
||||
for ($x = 0; $x < count($channels); $x++) {
|
||||
if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED)
|
||||
if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
|
||||
$channels[$x]['blocked'] = true;
|
||||
else
|
||||
} else {
|
||||
$channels[$x]['blocked'] = false;
|
||||
}
|
||||
|
||||
if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE)
|
||||
if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) {
|
||||
$channels[$x]['allowcode'] = true;
|
||||
else
|
||||
} else {
|
||||
$channels[$x]['allowcode'] = false;
|
||||
}
|
||||
|
||||
$channels[$x]['channel_link'] = z_root() . '/channel/' . $channels[$x]['channel_address'];
|
||||
}
|
||||
|
@ -187,5 +196,4 @@ class Channels
|
|||
|
||||
return $o;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Module\Admin;
|
||||
|
||||
use App;
|
||||
|
@ -7,7 +8,7 @@ use Zotlabs\Lib\Libprofile;
|
|||
use Zotlabs\Access\AccessControl;
|
||||
use Zotlabs\Web\Controller;
|
||||
|
||||
/*
|
||||
/*
|
||||
@file cover_photo.php
|
||||
@brief Module-file with functions for handling of cover-photos
|
||||
|
||||
|
@ -57,7 +58,6 @@ class Cover_photo
|
|||
check_form_security_token_redirectOnErr('/admin/cover_photo', 'cover_photo');
|
||||
|
||||
if ((array_key_exists('cropfinal', $_POST)) && ($_POST['cropfinal'] == 1)) {
|
||||
|
||||
// phase 2 - we have finished cropping
|
||||
|
||||
if (argc() != 3) {
|
||||
|
@ -78,31 +78,31 @@ class Cover_photo
|
|||
$srcW = intval($_POST['xfinal']) - $srcX;
|
||||
$srcH = intval($_POST['yfinal']) - $srcY;
|
||||
|
||||
$r = q("select gender from profile where uid = %d and is_default = 1 limit 1",
|
||||
$r = q(
|
||||
"select gender from profile where uid = %d and is_default = 1 limit 1",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if ($r) {
|
||||
$profile = array_shift($r);
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND imgscale > 0 order by imgscale asc LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND imgscale > 0 order by imgscale asc LIMIT 1",
|
||||
dbesc($image_id),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
|
||||
$max_thumb = intval(get_config('system', 'max_thumbnail', 1600));
|
||||
$iscaled = false;
|
||||
if (intval($r[0]['height']) > $max_thumb || intval($r[0]['width']) > $max_thumb) {
|
||||
$imagick_path = get_config('system', 'imagick_convert_path');
|
||||
if ($imagick_path && @file_exists($imagick_path) && intval($r[0]['os_storage'])) {
|
||||
|
||||
$fname = dbunescbin($r[0]['content']);
|
||||
$tmp_name = $fname . '-001';
|
||||
$newsize = photo_calculate_scale(array_merge(getimagesize($fname), ['max' => $max_thumb]));
|
||||
$cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $fname) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name);
|
||||
// logger('imagick thumbnail command: ' . $cmd);
|
||||
// logger('imagick thumbnail command: ' . $cmd);
|
||||
for ($x = 0; $x < 4; $x++) {
|
||||
exec($cmd);
|
||||
if (file_exists($tmp_name)) {
|
||||
|
@ -128,14 +128,14 @@ class Cover_photo
|
|||
|
||||
$im = photo_factory($base_image['content'], $base_image['mimetype']);
|
||||
if ($im->is_valid()) {
|
||||
|
||||
// We are scaling and cropping the relative pixel locations to the original photo instead of the
|
||||
// scaled photo we operated on.
|
||||
|
||||
// First load the scaled photo to check its size. (Should probably pass this in the post form and save
|
||||
// a query.)
|
||||
|
||||
$g = q("select width, height from photo where resource_id = '%s' and uid = %d and imgscale = 3",
|
||||
$g = q(
|
||||
"select width, height from photo where resource_id = '%s' and uid = %d and imgscale = 3",
|
||||
dbesc($image_id),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -151,7 +151,8 @@ class Cover_photo
|
|||
|
||||
// unset all other cover photos
|
||||
|
||||
q("update photo set photo_usage = %d where photo_usage = %d and uid = %d",
|
||||
q(
|
||||
"update photo set photo_usage = %d where photo_usage = %d and uid = %d",
|
||||
intval(PHOTO_NORMAL),
|
||||
intval(PHOTO_COVER),
|
||||
intval($channel['channel_id'])
|
||||
|
@ -196,19 +197,19 @@ class Cover_photo
|
|||
if ($r1 === false || $r2 === false || $r3 === false) {
|
||||
// if one failed, delete them all so we can start over.
|
||||
notice(t('Image resize failed.') . EOL);
|
||||
$x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale >= 7 ",
|
||||
$x = q(
|
||||
"delete from photo where resource_id = '%s' and uid = %d and imgscale >= 7 ",
|
||||
dbesc($base_image['resource_id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
} else
|
||||
} else {
|
||||
notice(t('Unable to process image') . EOL);
|
||||
}
|
||||
}
|
||||
|
||||
goaway(z_root() . '/admin');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -260,7 +261,6 @@ class Cover_photo
|
|||
logger('attach_store: ' . print_r($res, true), LOGGER_DEBUG);
|
||||
|
||||
json_return_and_die(['message' => $hash]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -284,12 +284,14 @@ class Cover_photo
|
|||
|
||||
$newuser = false;
|
||||
|
||||
if (argc() == 3 && argv(1) === 'new')
|
||||
if (argc() == 3 && argv(1) === 'new') {
|
||||
$newuser = true;
|
||||
}
|
||||
|
||||
|
||||
if (argv(2) === 'reset') {
|
||||
q("update photo set photo_usage = %d where photo_usage = %d and uid = %d",
|
||||
q(
|
||||
"update photo set photo_usage = %d where photo_usage = %d and uid = %d",
|
||||
intval(PHOTO_NORMAL),
|
||||
intval(PHOTO_COVER),
|
||||
intval($channel['channel_id'])
|
||||
|
@ -302,11 +304,12 @@ class Cover_photo
|
|||
return;
|
||||
}
|
||||
|
||||
// check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo');
|
||||
// check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo');
|
||||
|
||||
$resource_id = argv(3);
|
||||
|
||||
$r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 ORDER BY imgscale ASC",
|
||||
$r = q(
|
||||
"SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 ORDER BY imgscale ASC",
|
||||
intval($channel['channel_id']),
|
||||
dbesc($resource_id)
|
||||
);
|
||||
|
@ -321,10 +324,10 @@ class Cover_photo
|
|||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1",
|
||||
$r = q(
|
||||
"SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1",
|
||||
intval($r[0]['id']),
|
||||
intval($channel['channel_id'])
|
||||
|
||||
);
|
||||
if (!$r) {
|
||||
notice(t('Photo not available.') . EOL);
|
||||
|
@ -341,7 +344,8 @@ class Cover_photo
|
|||
$smallest = 0;
|
||||
if ($ph->is_valid()) {
|
||||
// go ahead as if we have just uploaded a new photo to crop
|
||||
$i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d and imgscale = 0",
|
||||
$i = q(
|
||||
"select resource_id, imgscale from photo where resource_id = '%s' and uid = %d and imgscale = 0",
|
||||
dbesc($r[0]['resource_id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -359,7 +363,6 @@ class Cover_photo
|
|||
|
||||
|
||||
if (!array_key_exists('imagecrop', App::$data)) {
|
||||
|
||||
$o .= replace_macros(get_markup_template('admin_cover_photo.tpl'), [
|
||||
'$user' => $channel['channel_address'],
|
||||
'$channel_id' => $channel['channel_id'],
|
||||
|
@ -438,6 +441,4 @@ class Cover_photo
|
|||
App::$page['htmlhead'] .= replace_macros(get_markup_template('crophead.tpl'), []);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Module\Admin;
|
||||
|
||||
|
||||
class Dbsync
|
||||
{
|
||||
|
||||
|
@ -15,14 +14,14 @@ class Dbsync
|
|||
// remove the old style config if it exists
|
||||
del_config('database', 'update_r' . intval(argv(3)));
|
||||
set_config('database', '_' . intval(argv(3)), 'success');
|
||||
if (intval(get_config('system', 'db_version')) < intval(argv(3)))
|
||||
if (intval(get_config('system', 'db_version')) < intval(argv(3))) {
|
||||
set_config('system', 'db_version', intval(argv(3)));
|
||||
}
|
||||
info(t('Update has been marked successful') . EOL);
|
||||
goaway(z_root() . '/admin/dbsync');
|
||||
}
|
||||
|
||||
if (argc() > 3 && intval(argv(3)) && argv(2) === 'verify') {
|
||||
|
||||
$s = '_' . intval(argv(3));
|
||||
$cls = '\\Zotlabs\Update\\' . $s;
|
||||
if (class_exists($cls)) {
|
||||
|
@ -34,13 +33,15 @@ class Dbsync
|
|||
} elseif ($retval === UPDATE_SUCCESS) {
|
||||
$o .= sprintf(t('Update %s was successfully applied.'), $s);
|
||||
set_config('database', $s, 'success');
|
||||
} else
|
||||
} else {
|
||||
$o .= sprintf(t('Verifying update %s did not return a status. Unknown if it succeeded.'), $s);
|
||||
}
|
||||
} else {
|
||||
$o .= sprintf(t('Update %s does not contain a verification function.'), $s);
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
$o .= sprintf(t('Update function %s could not be found.'), $s);
|
||||
}
|
||||
|
||||
return $o;
|
||||
|
||||
|
@ -48,8 +49,9 @@ class Dbsync
|
|||
// remove the old style config if it exists
|
||||
del_config('database', 'update_r' . intval(argv(3)));
|
||||
set_config('database', '_' . intval(argv(3)), 'success');
|
||||
if (intval(get_config('system', 'db_version')) < intval(argv(3)))
|
||||
if (intval(get_config('system', 'db_version')) < intval(argv(3))) {
|
||||
set_config('system', 'db_version', intval(argv(3)));
|
||||
}
|
||||
info(t('Update has been marked successful') . EOL);
|
||||
goaway(z_root() . '/admin/dbsync');
|
||||
}
|
||||
|
@ -66,10 +68,12 @@ class Dbsync
|
|||
} elseif ($retval === UPDATE_SUCCESS) {
|
||||
$o .= sprintf(t('Update %s was successfully applied.'), $s);
|
||||
set_config('database', $s, 'success');
|
||||
} else
|
||||
} else {
|
||||
$o .= sprintf(t('Update %s did not return a status. It cannot be determined if it was successful.'), $s);
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
$o .= sprintf(t('Update function %s could not be found.'), $s);
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
@ -79,8 +83,9 @@ class Dbsync
|
|||
if (count($r)) {
|
||||
foreach ($r as $rr) {
|
||||
$upd = intval(substr($rr['k'], -4));
|
||||
if ($rr['v'] === 'success')
|
||||
if ($rr['v'] === 'success') {
|
||||
continue;
|
||||
}
|
||||
$failed[] = $upd;
|
||||
}
|
||||
}
|
||||
|
@ -100,4 +105,4 @@ class Dbsync
|
|||
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Module\Admin;
|
||||
|
||||
|
||||
class Logs
|
||||
{
|
||||
|
||||
|
@ -64,13 +63,15 @@ class Logs
|
|||
$fstat = fstat($fp);
|
||||
$size = $fstat['size'];
|
||||
if ($size != 0) {
|
||||
if ($size > 5000000 || $size < 0)
|
||||
if ($size > 5000000 || $size < 0) {
|
||||
$size = 5000000;
|
||||
}
|
||||
$seek = fseek($fp, 0 - $size, SEEK_END);
|
||||
if ($seek === 0) {
|
||||
$data = escape_tags(fread($fp, $size));
|
||||
while (!feof($fp))
|
||||
while (!feof($fp)) {
|
||||
$data .= escape_tags(fread($fp, 4096));
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
@ -94,6 +95,4 @@ class Logs
|
|||
'$form_security_token' => get_form_security_token('admin_logs'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Module\Admin;
|
||||
|
||||
/*
|
||||
|
@ -14,7 +15,6 @@ use Zotlabs\Lib\Libprofile;
|
|||
use Zotlabs\Lib\Config;
|
||||
use Zotlabs\Daemon\Run;
|
||||
|
||||
|
||||
require_once('include/photo_factory.php');
|
||||
require_once('include/photos.php');
|
||||
|
||||
|
@ -38,7 +38,6 @@ class Profile_photo
|
|||
|
||||
$channel = get_sys_channel();
|
||||
Libprofile::load($channel['channel_address']);
|
||||
|
||||
}
|
||||
|
||||
/* @brief Evaluate posted values
|
||||
|
@ -60,7 +59,6 @@ class Profile_photo
|
|||
check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
|
||||
|
||||
if ((array_key_exists('cropfinal', $_POST)) && (intval($_POST['cropfinal']) == 1)) {
|
||||
|
||||
// logger('crop: ' . print_r($_POST,true));
|
||||
|
||||
// phase 2 - we have finished cropping
|
||||
|
@ -81,7 +79,8 @@ class Profile_photo
|
|||
$is_default_profile = 1;
|
||||
|
||||
if ($_REQUEST['profile']) {
|
||||
$r = q("select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1",
|
||||
$r = q(
|
||||
"select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1",
|
||||
intval($_REQUEST['profile']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -98,18 +97,18 @@ class Profile_photo
|
|||
$srcW = intval($_POST['xfinal']) - $srcX;
|
||||
$srcH = intval($_POST['yfinal']) - $srcY;
|
||||
|
||||
$r = q("SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND imgscale = %d LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND imgscale = %d LIMIT 1",
|
||||
dbesc($image_id),
|
||||
dbesc($channel['channel_id']),
|
||||
intval($scale));
|
||||
intval($scale)
|
||||
);
|
||||
if ($r) {
|
||||
|
||||
$base_image = array_shift($r);
|
||||
$base_image['content'] = (($base_image['os_storage']) ? @file_get_contents(dbunescbin($base_image['content'])) : dbunescbin($base_image['content']));
|
||||
|
||||
$im = photo_factory($base_image['content'], $base_image['mimetype']);
|
||||
if ($im->is_valid()) {
|
||||
|
||||
$im->cropImage(300, $srcX, $srcY, $srcW, $srcH);
|
||||
|
||||
$aid = 0;
|
||||
|
@ -144,7 +143,8 @@ class Profile_photo
|
|||
if ($r1 === false || $r2 === false || $r3 === false) {
|
||||
// if one failed, delete them all so we can start over.
|
||||
notice(t('Image resize failed.') . EOL);
|
||||
$x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale in ( %d, %d, %d ) ",
|
||||
$x = q(
|
||||
"delete from photo where resource_id = '%s' and uid = %d and imgscale in ( %d, %d, %d ) ",
|
||||
dbesc($base_image['resource_id']),
|
||||
$channel['channel_id'],
|
||||
intval(PHOTO_RES_PROFILE_300),
|
||||
|
@ -155,7 +155,8 @@ class Profile_photo
|
|||
}
|
||||
|
||||
|
||||
$r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d
|
||||
$r = q(
|
||||
"UPDATE photo SET photo_usage = %d WHERE photo_usage = %d
|
||||
AND resource_id != '%s' AND uid = %d",
|
||||
intval(PHOTO_NORMAL),
|
||||
intval(PHOTO_PROFILE),
|
||||
|
@ -169,7 +170,8 @@ class Profile_photo
|
|||
// changed to a generic URL by a clone operation. Otherwise the new photo may
|
||||
// not get pushed to other sites correctly.
|
||||
|
||||
$r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s'
|
||||
$r = q(
|
||||
"UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s'
|
||||
where xchan_hash = '%s'",
|
||||
dbesc($im->getType()),
|
||||
dbesc(datetime_convert()),
|
||||
|
@ -185,7 +187,6 @@ class Profile_photo
|
|||
Config::Set('system', 'site_icon_url', z_root() . '/photo/profile/m/' . $channel['channel_id']);
|
||||
|
||||
info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
|
||||
|
||||
} else {
|
||||
notice(t('Unable to process image') . EOL);
|
||||
}
|
||||
|
@ -207,7 +208,6 @@ class Profile_photo
|
|||
$hash = $_REQUEST['importfile'];
|
||||
$importing = true;
|
||||
} else {
|
||||
|
||||
$matches = [];
|
||||
$partial = false;
|
||||
|
||||
|
@ -256,7 +256,8 @@ class Profile_photo
|
|||
}
|
||||
|
||||
if (($res && intval($res['data']['is_photo'])) || $importing) {
|
||||
$i = q("select * from photo where resource_id = '%s' and uid = %d order by imgscale",
|
||||
$i = q(
|
||||
"select * from photo where resource_id = '%s' and uid = %d order by imgscale",
|
||||
dbesc($hash),
|
||||
intval($channel['channel_hash'])
|
||||
);
|
||||
|
@ -330,7 +331,8 @@ class Profile_photo
|
|||
|
||||
$pf = (($_REQUEST['pf']) ? intval($_REQUEST['pf']) : 0);
|
||||
|
||||
$c = q("select id, is_default from profile where uid = %d",
|
||||
$c = q(
|
||||
"select id, is_default from profile where uid = %d",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
|
@ -343,7 +345,8 @@ class Profile_photo
|
|||
$_REQUEST['profile'] = $pf;
|
||||
}
|
||||
|
||||
$r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC",
|
||||
$r = q(
|
||||
"SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC",
|
||||
intval($channel['channel_id']),
|
||||
dbesc($resource_id)
|
||||
);
|
||||
|
@ -362,19 +365,22 @@ class Profile_photo
|
|||
|
||||
if ($havescale) {
|
||||
// unset any existing profile photos
|
||||
$r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d",
|
||||
$r = q(
|
||||
"UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d",
|
||||
intval(PHOTO_NORMAL),
|
||||
intval(PHOTO_PROFILE),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
$r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'",
|
||||
$r = q(
|
||||
"UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'",
|
||||
intval(PHOTO_PROFILE),
|
||||
intval($channel['channel_id']),
|
||||
dbesc($resource_id)
|
||||
);
|
||||
|
||||
$r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'",
|
||||
$r = q(
|
||||
"UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($channel['xchan_hash'])
|
||||
);
|
||||
|
@ -382,10 +388,10 @@ class Profile_photo
|
|||
goaway(z_root() . '/admin');
|
||||
}
|
||||
|
||||
$r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1",
|
||||
$r = q(
|
||||
"SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1",
|
||||
intval($r[0]['id']),
|
||||
intval($channel['channel_id'])
|
||||
|
||||
);
|
||||
if (!$r) {
|
||||
notice(t('Photo not available.') . EOL);
|
||||
|
@ -402,7 +408,8 @@ class Profile_photo
|
|||
$smallest = 0;
|
||||
if ($ph->is_valid()) {
|
||||
// go ahead as if we have just uploaded a new photo to crop
|
||||
$i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d order by imgscale",
|
||||
$i = q(
|
||||
"select resource_id, imgscale from photo where resource_id = '%s' and uid = %d order by imgscale",
|
||||
dbesc($r[0]['resource_id']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
@ -424,12 +431,12 @@ class Profile_photo
|
|||
}
|
||||
|
||||
// falls through with App::$data['imagecrop'] set so we go straight to the cropping section
|
||||
|
||||
}
|
||||
|
||||
// present an upload form
|
||||
|
||||
$profiles = q("select id, profile_name as name, is_default from profile where uid = %d order by id asc",
|
||||
$profiles = q(
|
||||
"select id, profile_name as name, is_default from profile where uid = %d order by id asc",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
|
@ -448,7 +455,6 @@ class Profile_photo
|
|||
$importing = ((array_key_exists('importfile', App::$data)) ? true : false);
|
||||
|
||||
if (!array_key_exists('imagecrop', App::$data)) {
|
||||
|
||||
$tpl = get_markup_template('admin_profile_photo.tpl');
|
||||
|
||||
$o .= replace_macros($tpl, [
|
||||
|
@ -480,7 +486,6 @@ class Profile_photo
|
|||
call_hooks('profile_photo_content_end', $o);
|
||||
return $o;
|
||||
} else {
|
||||
|
||||
// present a cropping form
|
||||
|
||||
$filename = App::$data['imagecrop'] . '-' . App::$data['imagecrop_resolution'];
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Zotlabs\Module\Admin;
|
||||
|
||||
|
||||
class Profs
|
||||
{
|
||||
|
||||
|
@ -20,10 +19,11 @@ class Profs
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!$narr)
|
||||
if (!$narr) {
|
||||
del_config('system', 'profile_fields_basic');
|
||||
else
|
||||
} else {
|
||||
set_config('system', 'profile_fields_basic', $narr);
|
||||
}
|
||||
|
||||
|
||||
if (array_key_exists('advanced', $_REQUEST)) {
|
||||
|
@ -37,11 +37,11 @@ class Profs
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!$narr)
|
||||
if (!$narr) {
|
||||
del_config('system', 'profile_fields_advanced');
|
||||
else
|
||||
} else {
|
||||
set_config('system', 'profile_fields_advanced', $narr);
|
||||
|
||||
}
|
||||
}
|
||||
goaway(z_root() . '/admin/profs');
|
||||
}
|
||||
|
@ -49,7 +49,8 @@ class Profs
|
|||
|
||||
if (array_key_exists('field_name', $_REQUEST)) {
|
||||
if ($_REQUEST['id']) {
|
||||
$r = q("update profdef set field_name = '%s', field_type = '%s', field_desc = '%s' field_help = '%s', field_inputs = '%s' where id = %d",
|
||||
$r = q(
|
||||
"update profdef set field_name = '%s', field_type = '%s', field_desc = '%s' field_help = '%s', field_inputs = '%s' where id = %d",
|
||||
dbesc($_REQUEST['field_name']),
|
||||
dbesc($_REQUEST['field_type']),
|
||||
dbesc($_REQUEST['field_desc']),
|
||||
|
@ -58,7 +59,8 @@ class Profs
|
|||
intval($_REQUEST['id'])
|
||||
);
|
||||
} else {
|
||||
$r = q("insert into profdef ( field_name, field_type, field_desc, field_help, field_inputs ) values ( '%s' , '%s', '%s', '%s', '%s' )",
|
||||
$r = q(
|
||||
"insert into profdef ( field_name, field_type, field_desc, field_help, field_inputs ) values ( '%s' , '%s', '%s', '%s', '%s' )",
|
||||
dbesc($_REQUEST['field_name']),
|
||||
dbesc($_REQUEST['field_type']),
|
||||
dbesc($_REQUEST['field_desc']),
|
||||
|
@ -78,7 +80,8 @@ class Profs
|
|||
{
|
||||
|
||||
if ((argc() > 3) && argv(2) == 'drop' && intval(argv(3))) {
|
||||
$r = q("delete from profdef where id = %d",
|
||||
$r = q(
|
||||
"delete from profdef where id = %d",
|
||||
intval(argv(3))
|
||||
);
|
||||
// remove from allowed fields
|
||||
|
@ -98,7 +101,8 @@ class Profs
|
|||
}
|
||||
|
||||
if ((argc() > 2) && intval(argv(2))) {
|
||||
$r = q("select * from profdef where id = %d limit 1",
|
||||
$r = q(
|
||||
"select * from profdef where id = %d limit 1",
|
||||
intval(argv(2))
|
||||
);
|
||||
if (!$r) {
|
||||
|
@ -121,12 +125,14 @@ class Profs
|
|||
$barr = [];
|
||||
$fields = get_profile_fields_basic();
|
||||
|
||||
if (!$fields)
|
||||
if (!$fields) {
|
||||
$fields = get_profile_fields_basic(1);
|
||||
}
|
||||
if ($fields) {
|
||||
foreach ($fields as $k => $v) {
|
||||
if ($basic)
|
||||
if ($basic) {
|
||||
$basic .= ', ';
|
||||
}
|
||||
$basic .= trim($k);
|
||||
$barr[] = trim($k);
|
||||
}
|
||||
|
@ -134,14 +140,17 @@ class Profs
|
|||
|
||||
$advanced = '';
|
||||
$fields = get_profile_fields_advanced();
|
||||
if (!$fields)
|
||||
if (!$fields) {
|
||||
$fields = get_profile_fields_advanced(1);
|
||||
}
|
||||
if ($fields) {
|
||||
foreach ($fields as $k => $v) {
|
||||
if (in_array(trim($k), $barr))
|
||||
if (in_array(trim($k), $barr)) {
|
||||
continue;
|
||||
if ($advanced)
|
||||
}
|
||||
if ($advanced) {
|
||||
$advanced .= ', ';
|
||||
}
|
||||
$advanced .= trim($k);
|
||||
}
|
||||
}
|
||||
|
@ -150,8 +159,9 @@ class Profs
|
|||
$fields = get_profile_fields_advanced(1);
|
||||
if ($fields) {
|
||||
foreach ($fields as $k => $v) {
|
||||
if ($all)
|
||||
if ($all) {
|
||||
$all .= ', ';
|
||||
}
|
||||
$all .= trim($k);
|
||||
}
|
||||
}
|
||||
|
@ -159,8 +169,9 @@ class Profs
|
|||
$r = q("select * from profdef where true");
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
if ($all)
|
||||
if ($all) {
|
||||
$all .= ', ';
|
||||
}
|
||||
$all .= $rr['field_name'];
|
||||
}
|
||||
}
|
||||
|
@ -181,9 +192,5 @@ class Profs
|
|||
));
|
||||
|
||||
return $o;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,4 @@ class Queue
|
|||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue