diff options
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r-- | Zotlabs/Lib/ActivityStreams.php | 5 | ||||
-rw-r--r-- | Zotlabs/Lib/Apps.php | 115 | ||||
-rw-r--r-- | Zotlabs/Lib/MessageFilter.php | 79 | ||||
-rw-r--r-- | Zotlabs/Lib/ThreadItem.php | 21 |
4 files changed, 186 insertions, 34 deletions
diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 2e9bb0703..37e717f58 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -9,6 +9,7 @@ namespace Zotlabs\Lib; */ class ActivityStreams { + public $raw = null; public $data; public $valid = false; public $id = ''; @@ -33,7 +34,9 @@ class ActivityStreams { */ function __construct($string) { + $this->raw = $string; $this->data = json_decode($string, true); + if($this->data) { $this->valid = true; } @@ -204,7 +207,7 @@ class ActivityStreams { } $x = z_fetch_url($url, true, $redirects, - ['headers' => [ 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/activity+json' ]]); + ['headers' => [ 'Accept: application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ]]); if($x['success']) return json_decode($x['body'], true); diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 24cb4a626..c2ec5c967 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -13,7 +13,12 @@ require_once('include/channel.php'); class Apps { - static public $installed_system_apps = null; + static public $available_apps = null; + static public $installed_apps = null; + + static public $base_apps = null; + + static public function get_system_apps($translate = true) { @@ -45,6 +50,8 @@ class Apps { } } + call_hooks('get_system_apps',$ret); + return $ret; } @@ -53,22 +60,52 @@ class Apps { static public function import_system_apps() { if(! local_channel()) return; + + self::$base_apps = get_config('system','base_apps',[ + 'Connections', + 'Suggest Channels', + 'Grid', + 'Settings', + 'Files', + 'Channel Home', + 'View Profile', + 'Photos', + 'Events', + 'Directory', + 'Search', + 'Help', + 'Mail', + 'Profile Photo' + ]); + $apps = self::get_system_apps(false); - self::$installed_system_apps = q("select * from app where app_system = 1 and app_channel = %d", + self::$available_apps = q("select * from app where app_channel = 0"); + + self::$installed_apps = q("select * from app where app_channel = %d", intval(local_channel()) ); if($apps) { foreach($apps as $app) { $id = self::check_install_system_app($app); + + // $id will be boolean true or false to install an app, or an integer id to update an existing app + if($id !== false) { + $app['uid'] = 0; + $app['guid'] = hash('whirlpool',$app['name']); + $app['system'] = 1; + self::app_install(0,$app); + } + + $id = self::check_install_personal_app($app); // $id will be boolean true or false to install an app, or an integer id to update an existing app if($id === false) continue; if($id !== true) { // if we already installed this app, but it changed, preserve any categories we created - $s = ''; - $r = q("select * from term where otype = %d and oid = %d", + $s = EMPTY_STR; + $r = q("select term from term where otype = %d and oid = %d", intval(TERM_OBJ_APP), intval($id) ); @@ -85,6 +122,7 @@ class Apps { $app['guid'] = hash('whirlpool',$app['name']); $app['system'] = 1; self::app_install(local_channel(),$app); + } } } @@ -95,11 +133,11 @@ class Apps { */ static public function check_install_system_app($app) { - if((! is_array(self::$installed_system_apps)) || (! count(self::$installed_system_apps))) { + if((! is_array(self::$available_apps)) || (! count(self::$available_apps))) { return true; } $notfound = true; - foreach(self::$installed_system_apps as $iapp) { + foreach(self::$available_apps as $iapp) { if($iapp['app_id'] == hash('whirlpool',$app['name'])) { $notfound = false; if(($iapp['app_version'] != $app['version']) @@ -113,6 +151,31 @@ class Apps { } + /** + * Install the system app if no system apps have been installed, or if a new system app + * is discovered, or if the version of a system app changes. + */ + + + + static public function check_install_personal_app($app) { + $installed = false; + foreach(self::$installed_apps as $iapp) { + if($iapp['app_id'] == hash('whirlpool',$app['name'])) { + $installed = true; + if(($iapp['app_version'] != $app['version']) + || ($app['plugin'] && (! $iapp['app_plugin']))) { + return intval($iapp['app_id']); + } + } + } + if(! $installed && in_array($app['name'],self::$base_apps)) { + return true; + } + return false; + } + + static public function app_name_compare($a,$b) { return strcasecmp($a['name'],$b['name']); } @@ -233,7 +296,6 @@ class Apps { 'View Bookmarks' => t('View Bookmarks'), 'My Chatrooms' => t('My Chatrooms'), 'Connections' => t('Connections'), - 'Firefox Share' => t('Firefox Share'), 'Remote Diagnostics' => t('Remote Diagnostics'), 'Suggest Channels' => t('Suggest Channels'), 'Login' => t('Login'), @@ -288,6 +350,7 @@ class Apps { * modes: * view: normal mode for viewing an app via bbcode from a conversation or page * provides install/update button if you're logged in locally + * install: like view but does not display app-bin options if they are present * list: normal mode for viewing an app on the app page * no buttons are shown * edit: viewing the app page in editing mode provides a delete button @@ -300,7 +363,7 @@ class Apps { return; if(! $papp['photo']) - $papp['photo'] = z_root() . '/' . get_default_profile_photo(80); + $papp['photo'] = 'icon:gear'; self::translate_system_apps($papp); @@ -400,12 +463,15 @@ class Apps { )); } + if($mode === 'install') { + $papp['embed'] = true; + } return replace_macros(get_markup_template('app.tpl'),array( '$app' => $papp, '$icon' => $icon, '$hosturl' => $hosturl, '$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''), - '$install' => (($hosturl && $mode == 'view') ? $install_action : ''), + '$install' => (($hosturl && in_array($mode, ['view','install'])) ? $install_action : ''), '$edit' => ((local_channel() && $installed && $mode == 'edit') ? t('Edit') : ''), '$delete' => ((local_channel() && $installed && $mode == 'edit') ? t('Delete') : ''), '$undelete' => ((local_channel() && $installed && $mode == 'edit') ? t('Undelete') : ''), @@ -468,21 +534,13 @@ class Apps { intval(TERM_OBJ_APP), intval($x[0]['id']) ); - if($x[0]['app_system']) { - $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", - dbesc($app['guid']), - intval($uid) - ); - } - else { - $r = q("delete from app where app_id = '%s' and app_channel = %d", - dbesc($app['guid']), - intval($uid) - ); + $r = q("delete from app where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); - // we don't sync system apps - they may be completely different on the other system - build_sync_packet($uid,array('app' => $x)); - } + // we don't sync system apps - they may be completely different on the other system + build_sync_packet($uid,array('app' => $x)); } else { self::app_undestroy($uid,$app); @@ -736,12 +794,19 @@ class Apps { $darray = array(); $ret = array('success' => false); + $sys = get_sys_channel(); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); - if((! $darray['app_url']) || (! $darray['app_channel'])) + if(! $darray['app_url']) return $ret; + if((! $arr['uid']) && (! $arr['author'])) { + $arr['author'] = $sys['channel_hash']; + } + if($arr['photo'] && (strpos($arr['photo'],'icon:') !== 0) && (! strstr($arr['photo'],z_root()))) { $x = import_xchan_photo($arr['photo'],get_observer_hash(),true); $arr['photo'] = $x[1]; @@ -875,7 +940,7 @@ class Apps { // if updating an embed app, don't mess with any existing categories. - if(array_key_exists('embed',$arr) && intval($arr['embed'])) + if(array_key_exists('embed',$arr) && intval($arr['embed']) && (intval($darray['app_channel']))) return $ret; if($x) { diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php new file mode 100644 index 000000000..eb0fc3d2c --- /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 = ((is_array($item['term']) && 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; + } + + +} diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 61a012f9d..ed78ae00b 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -102,6 +102,13 @@ class ThreadItem { if($item['author']['xchan_network'] === 'rss') $shareable = true; + $privacy_warning = false; + if(($item['item_private'] == 1) && ($item['owner']['xchan_network'] === 'activitypub')) { + $recips = get_iconfig($item['parent'], 'activitypub', 'recips'); + + if(! in_array($observer['xchan_url'], $recips['to'])) + $privacy_warning = true; + } $mode = $conv->get_mode(); @@ -141,6 +148,10 @@ class ThreadItem { 'delete' => t('Delete'), ); } + elseif(is_site_admin()) { + $drop = [ 'dropping' => true, 'delete' => t('Admin Delete') ]; + } + // FIXME if($observer_is_pageowner) { $multidrop = array( @@ -232,16 +243,9 @@ class ThreadItem { // FIXME check this permission if(($conv->get_profile_owner() == local_channel()) && (! array_key_exists('real_uid',$item))) { -// FIXME we don't need all this stuff, some can be done in the template - $star = array( - 'do' => t("Add Star"), - 'undo' => t("Remove Star"), 'toggle' => t("Toggle Star Status"), - 'classdo' => ((intval($item['item_starred'])) ? "hidden" : ""), - 'classundo' => ((intval($item['item_starred'])) ? "" : "hidden"), 'isstarred' => ((intval($item['item_starred'])) ? true : false), - 'starred' => t('starred'), ); } @@ -366,6 +370,7 @@ class ThreadItem { 'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''), 'lock' => $lock, + 'privacy_warning' => $privacy_warning, 'verified' => $verified, 'unverified' => $unverified, 'forged' => $forged, @@ -756,7 +761,7 @@ class ThreadItem { '$edquote' => t('Quote'), '$edcode' => t('Code'), '$edimg' => t('Image'), - '$edatt' => t('Attach File'), + '$edatt' => t('Attach/Upload file'), '$edurl' => t('Insert Link'), '$edvideo' => t('Video'), '$preview' => t('Preview'), // ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''), |