new function absolutely_no_comments() and some text cleanup in daemon/thumbnail

This commit is contained in:
zotlabs 2020-06-17 20:30:18 -07:00
parent f612dfa3f8
commit 232422f5dd
5 changed files with 42 additions and 14 deletions

View file

@ -7,15 +7,17 @@ class Thumbnail {
static public function run($argc,$argv) {
if(! $argc == 2)
if (! ($argc == 2)) {
return;
}
$c = q("select * from attach where hash = '%s' ",
dbesc($argv[1])
);
if(! $c)
if (! $c) {
return;
}
$attach = $c[0];
@ -41,35 +43,34 @@ class Thumbnail {
*/
call_hooks('thumbnail',$p);
if($p['thumbnail']) {
if ($p['thumbnail']) {
return;
}
$default_controller = null;
$files = glob('Zotlabs/Thumbs/*.php');
if($files) {
foreach($files as $f) {
if ($files) {
foreach ($files as $f) {
$clsname = '\\Zotlabs\\Thumbs\\' . ucfirst(basename($f,'.php'));
if(class_exists($clsname)) {
if (class_exists($clsname)) {
$x = new $clsname();
if(method_exists($x,'Match')) {
if (method_exists($x,'Match')) {
$matched = $x->Match($attach['filetype']);
if($matched) {
if ($matched) {
$x->Thumb($attach,$preview_style,$preview_width,$preview_height);
}
}
if(method_exists($x,'MatchDefault')) {
if (method_exists($x,'MatchDefault')) {
$default_matched = $x->MatchDefault(substr($attach['filetype'],0,strpos($attach['filetype'],'/')));
if($default_matched) {
if ($default_matched) {
$default_controller = $x;
}
}
}
}
}
if(($default_controller)
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);

View file

@ -2518,6 +2518,9 @@ class Activity {
if ((! $allowed) && PConfig::Get($channel['channel_id'], 'system','permit_all_mentions') && i_am_mentioned($channel,$item)) {
$allowed = true;
}
if (absolutely_no_comments($p[0])) {
$allowed = false;
}
if (! $allowed) {
logger('rejected comment from ' . $item['author_xchan'] . ' for ' . $channel['channel_address']);

View file

@ -520,7 +520,7 @@ class Enotify {
}
if (is_array($datarray['parent_item'])) {
if (LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['owner_xchan']) || LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['owner_xchan'])) {
if (LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['author_xchan']) || LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['owner_xchan'])) {
pop_lang();
return;
}

View file

@ -1790,7 +1790,11 @@ class Libzot {
$allowed = can_comment_on_post($sender,$parent[0]);
}
if ((! $allowed) && PConfig::Get($channel['channel_id'], 'system','permit_all_mentions') && i_am_mentioned($channel,$arr)) {
$allowed = true;
// permit_all_mentions bypasses some comment protections, but if comments are disallowed completely
// honour this setting.
if (! absolutely_no_comments($arr)) {
$allowed = true;
}
}
}

View file

@ -345,6 +345,26 @@ function can_comment_on_post($observer_xchan, $item) {
return false;
}
function absolutely_no_comments($item) {
if($item['comment_policy'] === 'none') {
return true;
}
if (intval($item['item_nocomment'])) {
return true;
}
if(comments_are_now_closed($item)) {
return true;
}
return false;
}
/**
* @brief Adds $hash to the item source route specified by $iid.
*