more background work for app management - give every member a copy of all the system apps so that they can edit and delete them to taste/preference. This needs further work to pick up changes in system apps (additions, edits, deletions, etc.). Currently this is done once and never attempted again.
This commit is contained in:
parent
45c7a03a0d
commit
191298ec93
@ -17,16 +17,21 @@ class Apps extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
$apps = array();
|
$apps = array();
|
||||||
|
|
||||||
$syslist = get_system_apps();
|
|
||||||
|
|
||||||
if(local_channel()) {
|
if(local_channel()) {
|
||||||
|
import_system_apps();
|
||||||
|
$syslist = array();
|
||||||
$list = app_list(local_channel());
|
$list = app_list(local_channel());
|
||||||
if($list) {
|
if($list) {
|
||||||
foreach($list as $x) {
|
foreach($list as $x) {
|
||||||
$syslist[] = app_encode($x);
|
$syslist[] = app_encode($x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
translate_system_apps($syslist);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
$syslist = get_system_apps(true);
|
||||||
|
|
||||||
usort($syslist,'app_name_compare');
|
usort($syslist,'app_name_compare');
|
||||||
|
|
||||||
// logger('apps: ' . print_r($syslist,true));
|
// logger('apps: ' . print_r($syslist,true));
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
require_once('include/plugin.php');
|
require_once('include/plugin.php');
|
||||||
require_once('include/identity.php');
|
require_once('include/identity.php');
|
||||||
|
|
||||||
function get_system_apps() {
|
function get_system_apps($translate = true) {
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
if(is_dir('apps'))
|
if(is_dir('apps'))
|
||||||
@ -17,7 +17,7 @@ function get_system_apps() {
|
|||||||
$files = glob('app/*.apd');
|
$files = glob('app/*.apd');
|
||||||
if($files) {
|
if($files) {
|
||||||
foreach($files as $f) {
|
foreach($files as $f) {
|
||||||
$x = parse_app_description($f);
|
$x = parse_app_description($f,$translate);
|
||||||
if($x) {
|
if($x) {
|
||||||
$ret[] = $x;
|
$ret[] = $x;
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ function get_system_apps() {
|
|||||||
foreach($files as $f) {
|
foreach($files as $f) {
|
||||||
$n = basename($f,'.apd');
|
$n = basename($f,'.apd');
|
||||||
if(plugin_is_installed($n)) {
|
if(plugin_is_installed($n)) {
|
||||||
$x = parse_app_description($f);
|
$x = parse_app_description($f,$translate);
|
||||||
if($x) {
|
if($x) {
|
||||||
$ret[] = $x;
|
$ret[] = $x;
|
||||||
}
|
}
|
||||||
@ -40,11 +40,36 @@ function get_system_apps() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function import_system_apps() {
|
||||||
|
if(! local_channel())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Eventually we want to look at modification dates and update system apps.
|
||||||
|
|
||||||
|
$installed = get_pconfig(local_channel(),'system','apps_installed');
|
||||||
|
if($installed)
|
||||||
|
return;
|
||||||
|
$apps = get_system_apps(false);
|
||||||
|
if($apps) {
|
||||||
|
foreach($apps as $app) {
|
||||||
|
$app['uid'] = local_channel();
|
||||||
|
$app['guid'] = hash('whirlpool',$app['name']);
|
||||||
|
$app['system'] = 1;
|
||||||
|
app_install(local_channel(),$app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set_pconfig(local_channel(),'system','apps_installed',1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function app_name_compare($a,$b) {
|
function app_name_compare($a,$b) {
|
||||||
return strcmp($a['name'],$b['name']);
|
return strcmp($a['name'],$b['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_app_description($f) {
|
function parse_app_description($f,$translate = true) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
$baseurl = z_root();
|
$baseurl = z_root();
|
||||||
@ -116,6 +141,7 @@ function parse_app_description($f) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($ret) {
|
if($ret) {
|
||||||
|
if($translate)
|
||||||
translate_system_apps($ret);
|
translate_system_apps($ret);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
@ -293,11 +319,18 @@ function app_destroy($uid,$app) {
|
|||||||
);
|
);
|
||||||
$x[0]['app_deleted'] = 1;
|
$x[0]['app_deleted'] = 1;
|
||||||
|
|
||||||
|
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",
|
$r = q("delete from app where app_id = '%s' and app_channel = %d",
|
||||||
dbesc($app['guid']),
|
dbesc($app['guid']),
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
build_sync_packet($uid,array('app' => $x));
|
build_sync_packet($uid,array('app' => $x));
|
||||||
}
|
}
|
||||||
@ -370,10 +403,12 @@ function app_store($arr) {
|
|||||||
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
||||||
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
||||||
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
|
$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);
|
||||||
|
|
||||||
$created = datetime_convert();
|
$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 ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )",
|
$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_deleted ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
|
||||||
dbesc($darray['app_id']),
|
dbesc($darray['app_id']),
|
||||||
dbesc($darray['app_sig']),
|
dbesc($darray['app_sig']),
|
||||||
dbesc($darray['app_author']),
|
dbesc($darray['app_author']),
|
||||||
@ -388,7 +423,9 @@ function app_store($arr) {
|
|||||||
dbesc($darray['app_page']),
|
dbesc($darray['app_page']),
|
||||||
dbesc($darray['app_requires']),
|
dbesc($darray['app_requires']),
|
||||||
dbesc($created),
|
dbesc($created),
|
||||||
dbesc($created)
|
dbesc($created),
|
||||||
|
intval($darray['app_system']),
|
||||||
|
intval($darray['app_deleted'])
|
||||||
);
|
);
|
||||||
if($r) {
|
if($r) {
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
@ -425,10 +462,12 @@ function app_update($arr) {
|
|||||||
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
||||||
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
||||||
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
|
$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);
|
||||||
|
|
||||||
$edited = datetime_convert();
|
$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' 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_deleted = %d where app_id = '%s' and app_channel = %d",
|
||||||
dbesc($darray['app_sig']),
|
dbesc($darray['app_sig']),
|
||||||
dbesc($darray['app_author']),
|
dbesc($darray['app_author']),
|
||||||
dbesc($darray['app_name']),
|
dbesc($darray['app_name']),
|
||||||
@ -441,6 +480,8 @@ function app_update($arr) {
|
|||||||
dbesc($darray['app_page']),
|
dbesc($darray['app_page']),
|
||||||
dbesc($darray['app_requires']),
|
dbesc($darray['app_requires']),
|
||||||
dbesc($edited),
|
dbesc($edited),
|
||||||
|
intval($darray['app_system']),
|
||||||
|
intval($darray['app_deleted']),
|
||||||
dbesc($darray['app_id']),
|
dbesc($darray['app_id']),
|
||||||
intval($darray['app_channel'])
|
intval($darray['app_channel'])
|
||||||
);
|
);
|
||||||
@ -499,6 +540,12 @@ function app_encode($app,$embed = false) {
|
|||||||
if($app['app_requires'])
|
if($app['app_requires'])
|
||||||
$ret['requires'] = $app['app_requires'];
|
$ret['requires'] = $app['app_requires'];
|
||||||
|
|
||||||
|
if($app['app_system'])
|
||||||
|
$ret['system'] = $app['app_system'];
|
||||||
|
|
||||||
|
if($app['app_deleted'])
|
||||||
|
$ret['deleted'] = $app['app_deleted'];
|
||||||
|
|
||||||
if(! $embed)
|
if(! $embed)
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
|
@ -103,8 +103,8 @@ function widget_appselect($arr) {
|
|||||||
'$system' => t('System'),
|
'$system' => t('System'),
|
||||||
'$authed' => ((local_channel()) ? true : false),
|
'$authed' => ((local_channel()) ? true : false),
|
||||||
'$personal' => t('Personal'),
|
'$personal' => t('Personal'),
|
||||||
'$new' => t('Create Personal App'),
|
'$new' => t('New App'),
|
||||||
'$edit' => t('Edit Personal App')
|
'$edit' => t('Edit App')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<div class="widget">
|
<div class="widget">
|
||||||
<h3>{{$title}}</h3>
|
<h3>{{$title}}</h3>
|
||||||
<ul class="nav nav-pills nav-stacked">
|
<ul class="nav nav-pills nav-stacked">
|
||||||
<li><a href="appman">{{$new}}</a></li>
|
<li><a href="appman"><i class="fa fa-plus"></i> {{$new}}</a></li>
|
||||||
<li><a href="apps/edit">{{$edit}}</a></li>
|
<li><a href="apps/edit"><i class="fa fa-pencil"></i> {{$edit}}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Reference in New Issue
Block a user