aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Apps.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/Apps.php')
-rw-r--r--Zotlabs/Lib/Apps.php224
1 files changed, 179 insertions, 45 deletions
diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php
index a966842ae..b13658be2 100644
--- a/Zotlabs/Lib/Apps.php
+++ b/Zotlabs/Lib/Apps.php
@@ -56,15 +56,10 @@ 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',
+ 'Network',
'Settings',
'Files',
'Channel Home',
@@ -77,7 +72,14 @@ 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");
@@ -266,6 +268,10 @@ class Apps {
if(! can_view_public_stream())
unset($ret);
break;
+ case 'custom_role':
+ if(get_pconfig(local_channel(),'system','permissions_role') !== 'custom')
+ unset($ret);
+ break;
case 'observer':
if(! $observer)
unset($ret);
@@ -297,14 +303,14 @@ class Apps {
'Cards' => t('Cards'),
'Admin' => t('Site Admin'),
'Report Bug' => t('Report Bug'),
- 'View Bookmarks' => t('View Bookmarks'),
- 'My Chatrooms' => t('My Chatrooms'),
+ 'Bookmarks' => t('Bookmarks'),
+ 'Chatrooms' => t('Chatrooms'),
'Connections' => t('Connections'),
'Remote Diagnostics' => t('Remote Diagnostics'),
'Suggest Channels' => t('Suggest Channels'),
'Login' => t('Login'),
'Channel Manager' => t('Channel Manager'),
- 'Grid' => t('Activity'),
+ 'Network' => t('Stream'),
'Settings' => t('Settings'),
'Files' => t('Files'),
'Webpages' => t('Webpages'),
@@ -332,7 +338,20 @@ class Apps {
'Profiles' => t('Profiles'),
'Privacy Groups' => t('Privacy Groups'),
'Notifications' => t('Notifications'),
- 'Order Apps' => t('Order Apps')
+ 'Order Apps' => t('Order Apps'),
+ 'CalDAV' => t('CalDAV'),
+ 'CardDAV' => t('CardDAV'),
+ 'Channel Sources' => t('Channel Sources'),
+ 'Guest Access' => t('Guest Access'),
+ 'Notes' => t('Notes'),
+ 'OAuth Apps Manager' => t('OAuth Apps Manager'),
+ 'OAuth2 Apps Manager' => t('OAuth2 Apps Manager'),
+ 'PDL Editor' => t('PDL Editor'),
+ 'Permission Categories' => t('Permission Categories'),
+ 'Premium Channel' => t('Premium Channel'),
+ 'Public Stream' => t('Public Stream'),
+ 'My Chatrooms' => t('My Chatrooms'),
+ 'Channel Export' => t('Channel Export')
);
if(array_key_exists('name',$arr)) {
@@ -344,6 +363,9 @@ class Apps {
for($x = 0; $x < count($arr); $x++) {
if(array_key_exists($arr[$x]['name'],$apps)) {
$arr[$x]['name'] = $apps[$arr[$x]['name']];
+ } else {
+ // Try to guess by app name if not in list
+ $arr[$x]['name'] = t(trim($arr[$x]['name']));
}
}
}
@@ -383,18 +405,23 @@ class Apps {
// 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')) {
+ if(strpos($papp['url'],'$baseurl') !== false || strpos($papp['url'],'$nick') !== false || strpos($papp['photo'],'$baseurl') !== false || strpos($papp['photo'],'$nick') !== false) {
$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'],'://'))
+ if(strpos($papp['url'], ',')) {
+ $urls = explode(',', $papp['url']);
+ $papp['url'] = trim($urls[0]);
+ $papp['settings_url'] = trim($urls[1]);
+ }
+
+ if(! strpos($papp['url'],'://'))
$papp['url'] = z_root() . ((strpos($papp['url'],'/') === 0) ? '' : '/') . $papp['url'];
@@ -442,6 +469,10 @@ class Apps {
if(! can_view_public_stream())
return '';
break;
+ case 'custom_role':
+ if(get_pconfig(local_channel(),'system','permissions_role') != 'custom')
+ return '';
+ break;
case 'observer':
$observer = \App::get_observer();
if(! $observer)
@@ -463,7 +494,9 @@ class Apps {
$hosturl = '';
if(local_channel()) {
- $installed = self::app_installed(local_channel(),$papp);
+ if(self::app_installed(local_channel(),$papp) && !$papp['deleted'])
+ $installed = true;
+
$hosturl = z_root() . '/';
}
elseif(remote_channel()) {
@@ -490,18 +523,21 @@ 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 && in_array($mode, ['view','install'])) ? $install_action : ''),
+ '$installed' => $installed,
+ '$action_label' => (($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') : ''),
+ '$delete' => ((local_channel() && $mode == 'edit') ? t('Delete') : ''),
+ '$undelete' => ((local_channel() && $mode == 'edit') ? t('Undelete') : ''),
+ '$settings_url' => ((local_channel() && $installed && $mode == 'list') ? $papp['settings_url'] : ''),
'$deleted' => $papp['deleted'],
- '$feature' => (($papp['embed']) ? false : true),
- '$pin' => (($papp['embed']) ? false : true),
+ '$feature' => (($papp['embed'] || $mode == 'edit') ? false : true),
+ '$pin' => (($papp['embed'] || $mode == 'edit') ? false : true),
'$featured' => ((strpos($papp['categories'], 'nav_featured_app') === false) ? false : true),
'$pinned' => ((strpos($papp['categories'], 'nav_pinned_app') === false) ? false : true),
'$navapps' => (($mode == 'nav') ? true : false),
@@ -509,14 +545,26 @@ class Apps {
'$add' => t('Add to app-tray'),
'$remove' => t('Remove from app-tray'),
'$add_nav' => t('Pin to navbar'),
- '$remove_nav' => t('Unpin from navbar')
+ '$remove_nav' => t('Unpin from navbar'),
+ '$rpath' => z_root() . '/apps'
));
}
static public function app_install($uid,$app) {
+
+ if(! is_array($app)) {
+ $r = q("select * from app where app_name = '%s' and app_channel = 0",
+ dbesc($app)
+ );
+ if(! $r)
+ return false;
+
+ $app = self::app_encode($r[0]);
+ }
+
$app['uid'] = $uid;
- if(self::app_installed($uid,$app))
+ if(self::app_installed($uid,$app,true))
$x = self::app_update($app);
else
$x = self::app_store($app);
@@ -527,7 +575,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),
@@ -542,9 +590,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",
@@ -554,23 +619,33 @@ 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'])
- );
- $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));
+ if(self::can_delete($uid,$app)) {
+ $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",
+ 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",
+ dbesc($app['guid']),
+ intval($uid)
+ );
+ }
+ if(! intval($x[0]['app_system'])) {
+ build_sync_packet($uid,array('app' => $x));
+ }
}
else {
self::app_undestroy($uid,$app);
}
}
}
+
}
static public function app_undestroy($uid,$app) {
@@ -618,16 +693,65 @@ class Apps {
}
}
- static public function app_installed($uid,$app) {
+ static public function app_installed($uid,$app,$bypass_filter=false) {
$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)
);
+ if (!$bypass_filter) {
+ $filter_arr = [
+ 'uid'=>$uid,
+ 'app'=>$app,
+ 'installed'=>$r
+ ];
+ call_hooks('app_installed_filter',$filter_arr);
+ $r = $filter_arr['installed'];
+ }
+ return(($r) ? true : false);
+
+ }
+
+
+ static public 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",
+ dbesc($app),
+ intval($uid)
+ );
+ if (!$bypass_filter) {
+ $filter_arr = [
+ 'uid'=>$uid,
+ 'app'=>$app,
+ 'installed'=>$r
+ ];
+ call_hooks('addon_app_installed_filter',$filter_arr);
+ $r = $filter_arr['installed'];
+ }
return(($r) ? true : false);
}
+ static public function system_app_installed($uid,$app,$bypass_filter=false) {
+
+ $r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
+ dbesc(hash('whirlpool',$app)),
+ intval($uid)
+ );
+ if (!$bypass_filter) {
+ $filter_arr = [
+ 'uid'=>$uid,
+ 'app'=>$app,
+ 'installed'=>$r
+ ];
+ call_hooks('system_app_installed_filter',$filter_arr);
+ $r = $filter_arr['installed'];
+ }
+ return(($r) ? true : false);
+
+ }
+
+
static public function app_list($uid, $deleted = false, $cats = []) {
if($deleted)
@@ -668,6 +792,9 @@ class Apps {
);
if($r) {
+ $hookinfo = Array('uid'=>$uid,'deleted'=>$deleted,'cats'=>$cats,'apps'=>$r);
+ call_hooks('app_list',$hookinfo);
+ $r = $hookinfo['apps'];
for($x = 0; $x < count($r); $x ++) {
if(! $r[$x]['app_system'])
$r[$x]['type'] = 'personal';
@@ -855,8 +982,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) && (strpos($arr['photo'],z_root()) !== false)) {
+ $x = import_xchan_photo(str_replace('$baseurl',z_root(),$arr['photo']),get_observer_hash(),true);
$arr['photo'] = $x[1];
}
@@ -875,10 +1002,11 @@ class Apps {
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
$darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0);
$darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0);
+ $darray['app_options'] = ((x($arr,'options')) ? intval($arr['options']) : 0);
$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 ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %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']),
@@ -896,7 +1024,8 @@ class Apps {
dbesc($created),
intval($darray['app_system']),
dbesc($darray['app_plugin']),
- intval($darray['app_deleted'])
+ intval($darray['app_deleted']),
+ intval($darray['app_options'])
);
if($r) {
@@ -939,8 +1068,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) && (strpos($arr['photo'],z_root()) !== false)) {
+ $x = import_xchan_photo(str_replace('$baseurl',z_root(),$arr['photo']),get_observer_hash(),true);
$arr['photo'] = $x[1];
}
@@ -957,10 +1086,11 @@ class Apps {
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
$darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0);
$darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0);
+ $darray['app_options'] = ((x($arr,'options')) ? intval($arr['options']) : 0);
$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 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']),
@@ -976,6 +1106,7 @@ class Apps {
intval($darray['app_system']),
dbesc($darray['app_plugin']),
intval($darray['app_deleted']),
+ intval($darray['app_options']),
dbesc($darray['app_id']),
intval($darray['app_channel'])
);
@@ -1065,6 +1196,9 @@ class Apps {
if($app['app_system'])
$ret['system'] = $app['app_system'];
+ if($app['app_options'])
+ $ret['options'] = $app['app_options'];
+
if($app['app_plugin'])
$ret['plugin'] = trim($app['app_plugin']);