aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2018-05-10 17:11:03 -0700
committerzotlabs <mike@macgirvin.com>2018-05-10 17:11:03 -0700
commit721496f9220fa59059f90d16d3b3fb19337b2f16 (patch)
tree34e5a739486320a7095146f2c383f80003dd7f92
parentbe225164ebdde1b76a376fade83b93697507264e (diff)
downloadvolse-hubzilla-721496f9220fa59059f90d16d3b3fb19337b2f16.tar.gz
volse-hubzilla-721496f9220fa59059f90d16d3b3fb19337b2f16.tar.bz2
volse-hubzilla-721496f9220fa59059f90d16d3b3fb19337b2f16.zip
hubzilla issue #1169
-rw-r--r--Zotlabs/Lib/MessageFilter.php79
-rw-r--r--Zotlabs/Module/Admin/Site.php10
-rw-r--r--include/feedutils.php12
-rwxr-xr-xinclude/items.php63
-rw-r--r--include/zot.php5
-rwxr-xr-xview/tpl/admin_site.tpl2
6 files changed, 108 insertions, 63 deletions
diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php
new file mode 100644
index 000000000..df59aa57e
--- /dev/null
+++ b/Zotlabs/Lib/MessageFilter.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+
+
+class MessageFilter {
+
+
+ static public function evaluate($item,$incl,$excl) {
+
+ require_once('include/html2plain.php');
+
+ unobscure($item);
+
+ $text = prepare_text($item['body'],$item['mimetype']);
+ $text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
+
+
+ $lang = null;
+
+ if((strpos($incl,'lang=') !== false) || (strpos($excl,'lang=') !== false)) {
+ $lang = detect_language($text);
+ }
+
+ $tags = ((count($item['term'])) ? $item['term'] : false);
+
+ // exclude always has priority
+
+ $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((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(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((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(stristr($text,$word) !== false)
+ return true;
+ }
+ }
+ else {
+ return true;
+ }
+
+ return false;
+ }
+
+
+} \ No newline at end of file
diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php
index 5c35e4a9d..ff4f56ac8 100644
--- a/Zotlabs/Module/Admin/Site.php
+++ b/Zotlabs/Module/Admin/Site.php
@@ -76,6 +76,8 @@ class Site {
$imagick_path = ((x($_POST,'imagick_path')) ? trim($_POST['imagick_path']) : '');
$thumbnail_security = ((x($_POST,'thumbnail_security')) ? intval($_POST['thumbnail_security']) : 0);
$force_queue = ((intval($_POST['force_queue']) > 0) ? intval($_POST['force_queue']) : 3000);
+ $pub_incl = escape_tags(trim($_POST['pub_incl']));
+ $pub_excl = escape_tags(trim($_POST['pub_excl']));
$permissions_role = escape_tags(trim($_POST['permissions_role']));
@@ -105,6 +107,8 @@ class Site {
set_config('system', 'imagick_convert_path' , $imagick_path);
set_config('system', 'thumbnail_security' , $thumbnail_security);
set_config('system', 'default_permissions_role', $permissions_role);
+ set_config('system', 'pubstream_incl',$pub_incl);
+ set_config('system', 'pubstream_excl',$pub_excl);
set_config('system', 'techlevel_lock', $techlevel_lock);
@@ -340,6 +344,10 @@ class Site {
'$disable_discover_tab' => array('disable_discover_tab', t('Import Public Streams'), $discover_tab, t('Import and allow access to public content pulled from other sites. Warning: this content is unmoderated.')),
'$site_firehose' => array('site_firehose', t('Site only Public Streams'), get_config('system','site_firehose'), t('Allow access to public content originating only from this site if Imported Public Streams are disabled.')),
'$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the Public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing. Warning: this content is unmoderated.')),
+ '$incl' => array('pub_incl',t('Only import Public stream posts with this text'), $contact['abook_incl'],t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')),
+ '$excl' => array('pub_excl',t('Do not import Public stream posts with this text'), $contact['abook_excl'],t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')),
+
+
'$login_on_homepage' => array('login_on_homepage', t("Login on Homepage"),((intval($homelogin) || $homelogin === false) ? 1 : '') , t("Present a login box to visitors on the home page if no other content has been configured.")),
'$enable_context_help' => array('enable_context_help', t("Enable context help"),((intval($enable_context_help) === 1 || $enable_context_help === false) ? 1 : 0) , t("Display contextual help for the current page when the help button is pressed.")),
@@ -363,7 +371,7 @@ class Site {
'$active_expire_days' => array('active_expire_days', t('Do not expire any posts which have comments less than this many days ago'), intval(get_config('system','active_expire_days',7)), ''),
'$sellpage' => array('site_sellpage', t('Public servers: Optional landing (marketing) webpage for new registrants'), get_config('system','sellpage',''), sprintf( t('Create this page first. Default is %s/register'),z_root())),
- '$first_page' => array('first_page', t('Page to display after creating a new channel'), get_config('system','workflow_channel_next','profiles'), t('Recommend: profiles, go, or settings')),
+ '$first_page' => array('first_page', t('Page to display after creating a new channel'), get_config('system','workflow_channel_next','profiles'), t('Default: profiles')),
'$location' => array('site_location', t('Optional: site location'), get_config('system','site_location',''), t('Region or country')),
diff --git a/include/feedutils.php b/include/feedutils.php
index 023caaad6..afbe4229e 100644
--- a/include/feedutils.php
+++ b/include/feedutils.php
@@ -1332,6 +1332,12 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
// immediate parent wasn't found. Turn into a top-level post if permissions allow
// but save the thread_parent in case we need to refer to it later.
+ if($importer['channel_system']) {
+ if( ! \Zotlabs\Lib\MessageFilter::evaluate($datarray,get_config('system','pubstream_incl'),get_config('system','pubstream_excl'))) {
+ continue;
+ }
+ }
+
if(! post_is_importable($datarray, $contact))
continue;
@@ -1482,6 +1488,12 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
$author['owner_avatar'] = $contact['thumb'];
}
+ if($importer['channel_system']) {
+ if( ! \Zotlabs\Lib\MessageFilter::evaluate($datarray,get_config('system','pubstream_incl'),get_config('system','pubstream_excl'))) {
+ continue;
+ }
+ }
+
if(! post_is_importable($datarray, $contact))
continue;
diff --git a/include/items.php b/include/items.php
index d7cf9c558..1c0ef418a 100755
--- a/include/items.php
+++ b/include/items.php
@@ -3129,69 +3129,8 @@ function post_is_importable($item,$abook) {
if(! ($abook['abook_incl'] || $abook['abook_excl']))
return true;
- require_once('include/html2plain.php');
-
- unobscure($item);
-
- $text = prepare_text($item['body'],$item['mimetype']);
- $text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
-
-
- $lang = null;
-
- if((strpos($abook['abook_incl'],'lang=') !== false) || (strpos($abook['abook_excl'],'lang=') !== false)) {
- $lang = detect_language($text);
- }
- $tags = ((count($item['term'])) ? $item['term'] : false);
-
- // exclude always has priority
-
- $exclude = (($abook['abook_excl']) ? explode("\n",$abook['abook_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((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(stristr($text,$word) !== false)
- return false;
- }
- }
-
- $include = (($abook['abook_incl']) ? explode("\n",$abook['abook_incl']) : null);
+ return \Zotlabs\Lib\MessageFilter::evaluate($item,$abook['abook_incl'],$abook['abook_excl']);
- 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((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(stristr($text,$word) !== false)
- return true;
- }
- }
- else {
- return true;
- }
-
- return false;
}
diff --git a/include/zot.php b/include/zot.php
index 0343f4464..14c9f6ae5 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -1787,6 +1787,10 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
$local_public = false;
continue;
}
+ if(! \Zotlabs\Lib\MessageFilter::evaluate($arr,get_config('system','pubstream_incl'),get_config('system','pubstream_excl'))) {
+ $local_public = false;
+ continue;
+ }
}
$tag_delivery = tgroup_check($channel['channel_id'],$arr);
@@ -1923,6 +1927,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
continue;
}
+
$r = q("select * from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['mid']),
intval($channel['channel_id'])
diff --git a/view/tpl/admin_site.tpl b/view/tpl/admin_site.tpl
index ed85bd6b2..3288c2988 100755
--- a/view/tpl/admin_site.tpl
+++ b/view/tpl/admin_site.tpl
@@ -86,6 +86,8 @@
{{include file="field_checkbox.tpl" field=$disable_discover_tab}}
{{include file="field_checkbox.tpl" field=$site_firehose}}
{{include file="field_checkbox.tpl" field=$open_pubstream}}
+ {{include file="field_textarea.tpl" field=$incl}}
+ {{include file="field_textarea.tpl" field=$excl}}
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>