From e28dab17d6b958d6ef76181d23f784d17bc70b5e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 27 Jul 2018 13:59:27 -0700 Subject: app update and ownership issues --- Zotlabs/Lib/Apps.php | 57 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 82f0b57b8..b337a3bcd 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -140,10 +140,15 @@ class Apps { foreach(self::$available_apps as $iapp) { if($iapp['app_id'] == hash('whirlpool',$app['name'])) { $notfound = false; - if(($iapp['app_version'] != $app['version']) + if(($iapp['app_version'] !== $app['version']) || ($app['plugin'] && (! $iapp['app_plugin']))) { return intval($iapp['app_id']); } + + if(($iapp['app_url'] !== $app['url']) + || ($iapp['app_photo'] !== $app['photo'])) { + return intval($iapp['app_id']); + } } } @@ -198,12 +203,11 @@ class Apps { if($lines) { foreach($lines as $x) { if(preg_match('/^([a-zA-Z].*?):(.*?)$/ism',$x,$matches)) { - $ret[$matches[1]] = trim(str_replace(array('$baseurl','$nick'),array($baseurl,$address),$matches[2])); + $ret[$matches[1]] = trim($matches[2]); } } } - if(! $ret['photo']) $ret['photo'] = $baseurl . '/' . get_default_profile_photo(80); @@ -372,9 +376,24 @@ class Apps { $papp['papp'] = self::papp_encode($papp); + // This will catch somebody clicking on a system "available" app that hasn't had the path macros replaced + // and they are allowed to see the app + + + if(strstr($papp['url'],'$baseurl') || strstr($papp['url'],'$nick') || strstr($papp['photo'],'$baseurl') || strstr($pap['photo'],'$nick')) { + $view_channel = local_channel(); + if(! $view_channel) { + $sys = get_sys_channel(); + $view_channel = $sys['channel_id']; + } + self::app_macros($view_channel,$papp); + } + if(! strstr($papp['url'],'://')) $papp['url'] = z_root() . ((strpos($papp['url'],'/') === 0) ? '' : '/') . $papp['url']; + + foreach($papp as $k => $v) { if(strpos($v,'http') === 0 && $k != 'papp') { if(! (local_channel() && strpos($v,z_root()) === 0)) { @@ -811,6 +830,29 @@ class Apps { } + static public function app_macros($uid,&$arr) { + + if(! intval($uid)) + return; + + $baseurl = z_root(); + $channel = channelx_by_n($uid); + $address = (($channel) ? $channel['channel_address'] : ''); + + //future expansion + + $observer = \App::get_observer(); + + $arr['url'] = str_replace(array('$baseurl','$nick'),array($baseurl,$address),$arr['url']); + $arr['photo'] = str_replace(array('$baseurl','$nick'),array($baseurl,$address),$arr['photo']); + + } + + + + + + static public function app_store($arr) { //logger('app_store: ' . print_r($arr,true)); @@ -820,6 +862,7 @@ class Apps { $sys = get_sys_channel(); + self::app_macros($arr['uid'],$arr); $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); @@ -905,11 +948,14 @@ class Apps { $darray = array(); $ret = array('success' => false); + self::app_macros($arr['uid'],$arr); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0); - if((! $darray['app_url']) || (! $darray['app_channel']) || (! $darray['app_id'])) + if((! $darray['app_url']) || (! $darray['app_id'])) return $ret; if($arr['photo'] && (strpos($arr['photo'],'icon:') !== 0) && (! strstr($arr['photo'],z_root()))) { @@ -996,9 +1042,6 @@ class Apps { $ret['type'] = 'personal'; - if($app['app_id']) - $ret['guid'] = $app['app_id']; - if($app['app_id']) $ret['guid'] = $app['app_id']; -- cgit v1.2.3 From e25d205a7f1428588edd431002a2e10833c8f76e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 27 Jul 2018 14:36:06 -0700 Subject: app delete issue with base installed apps and app photo being reloaded uneccessarily --- Zotlabs/Lib/Apps.php | 66 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index b337a3bcd..841fffd39 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -56,12 +56,8 @@ class Apps { } - - static public function import_system_apps() { - if(! local_channel()) - return; - - self::$base_apps = get_config('system','base_apps',[ + static public function get_base_apps() { + return get_config('system','base_apps',[ 'Connections', 'Suggest Channels', 'Grid', @@ -77,7 +73,16 @@ class Apps { 'Mail', 'Profile Photo' ]); + } + + + static public function import_system_apps() { + if(! local_channel()) + return; + + self::$base_apps = self::get_base_apps(); + $apps = self::get_system_apps(false); self::$available_apps = q("select * from app where app_channel = 0"); @@ -537,9 +542,26 @@ class Apps { return false; } - static public function app_destroy($uid,$app) { + + static public function can_delete($uid,$app) { + if(! $uid) { + return false; + } + + $base_apps = self::get_base_apps(); + if($base_apps) { + foreach($base_apps as $b) { + if($app['guid'] === hash('whirlpool',$b)) { + return false; + } + } + } + return true; + } + static public function app_destroy($uid,$app) { + if($uid && $app['guid']) { $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", @@ -549,25 +571,31 @@ class Apps { if($x) { if(! intval($x[0]['app_deleted'])) { $x[0]['app_deleted'] = 1; - q("delete from term where otype = %d and oid = %d", - intval(TERM_OBJ_APP), - intval($x[0]['id']) - ); - if ($uid) { + if(self::can_delete($uid,$app)) { $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)); + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + } + else { + $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); } + + build_sync_packet($uid,array('app' => $x)); } else { self::app_undestroy($uid,$app); } } } + } static public function app_undestroy($uid,$app) { @@ -874,8 +902,8 @@ class Apps { $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); + if($arr['photo'] && (strpos($arr['photo'],'icon:') === false) && (! strstr($arr['photo'],z_root()))) { + $x = import_xchan_photo(str_replace('$baseurl',z_root(),$arr['photo']),get_observer_hash(),true); $arr['photo'] = $x[1]; } @@ -958,8 +986,8 @@ class Apps { if((! $darray['app_url']) || (! $darray['app_id'])) return $ret; - if($arr['photo'] && (strpos($arr['photo'],'icon:') !== 0) && (! strstr($arr['photo'],z_root()))) { - $x = import_xchan_photo($arr['photo'],get_observer_hash(),true); + if($arr['photo'] && (strpos($arr['photo'],'icon:') === false) && (! strstr($arr['photo'],z_root()))) { + $x = import_xchan_photo(str_replace('$baseurl',z_root(),$arr['photo']),get_observer_hash(),true); $arr['photo'] = $x[1]; } -- cgit v1.2.3 From a0f28708ab125e953157299d13d8ebbea8b77396 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 27 Jul 2018 15:05:29 -0700 Subject: don't sync system apps --- Zotlabs/Lib/Apps.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 841fffd39..ddaf8c44d 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -527,7 +527,7 @@ class Apps { intval($uid) ); if($r) { - if(! $r[0]['app_system']) { + 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", intval(TERM_OBJ_APP), @@ -587,8 +587,9 @@ class Apps { intval($uid) ); } - - build_sync_packet($uid,array('app' => $x)); + if(! intval($x[0]['app_system'])) { + build_sync_packet($uid,array('app' => $x)); + } } else { self::app_undestroy($uid,$app); -- cgit v1.2.3