From fc0967b84b5e1301c0ce3a9a41c00985ce16bc82 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 20 May 2014 18:08:49 -0700 Subject: most of the remaining apps basic infrastructure except a form to create the things. Don't let this fool you - there is still a lot of work, but there isn't a whole lot of work to create a demo; in fact you can demo it now. --- include/apps.php | 54 +++++++++++++++++++++++++++++++++++++++++++++---- include/widgets.php | 6 +++--- mod/appman.php | 26 ++++++++++++++++++++++++ mod/apps.php | 26 ++++++++++++++++++++---- version.inc | 2 +- view/tpl/app.tpl | 11 ++++++++-- view/tpl/app_select.tpl | 4 +--- view/tpl/myapps.tpl | 9 +++++++++ 8 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 mod/appman.php create mode 100755 view/tpl/myapps.tpl diff --git a/include/apps.php b/include/apps.php index a1469b400..536a40f01 100644 --- a/include/apps.php +++ b/include/apps.php @@ -118,10 +118,38 @@ function translate_system_apps(&$arr) { } -function app_render($app) { -//debugging - return print_r($app,true); +// papp is a portable app + +function app_render($papp,$mode = 'view') { + + /** + * 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 + * 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 + */ + + $installed = false; + + if(! $papp['photo']) + $papp['photo'] = z_root() . '/' . get_default_profile_photo(80); + + $papp['papp'] = papp_encode($papp); + + if(local_user()) { + $installed = app_installed(local_user(),$papp); + } + + $install_action = (($installed) ? t('Update') : t('Install')); + + return replace_macros(get_markup_template('app.tpl'),array( + '$app' => $papp, + '$install' => ((local_user() && $mode == 'view') ? $install_action : ''), + '$delete' => ((local_user() && $installed && $mode == 'edit') ? t('Delete') : '') + )); } @@ -133,6 +161,15 @@ function app_install($uid,$app) { app_store($app); } +function app_destroy($uid,$app) { + if($uid && $app['guid']) { + $r = q("delete from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($app['guid']), + intval($uid) + ); + } +} + function app_installed($uid,$app) { @@ -245,7 +282,7 @@ function app_update($arr) { } -function app_encode($app) { +function app_encode($app,$embed = false) { $ret = array(); @@ -285,7 +322,16 @@ function app_encode($app) { if($app['app_page']) $ret['page'] = $app['app_page']; + if(! $embed) + return $ret; + $j = json_encode($ret); return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]'; +} + + +function papp_encode($papp) { + return chunk_split(base64_encode(json_encode($papp)),72,"\n"); + } \ No newline at end of file diff --git a/include/widgets.php b/include/widgets.php index 37a079bc7..8cd2287a7 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -78,9 +78,9 @@ function widget_appselect($arr) { return replace_macros(get_markup_template('app_select.tpl'),array( '$title' => t('App Category'), '$system' => t('System'), - '$personal' => t('Personal'), - '$featured' => t('Featured'), - '$new' => t('New') + '$personal' => t('Personal') +// '$featured' => t('Featured'), +// '$new' => t('New') )); } diff --git a/mod/appman.php b/mod/appman.php new file mode 100644 index 000000000..48389a637 --- /dev/null +++ b/mod/appman.php @@ -0,0 +1,26 @@ + t('Apps'), + '$apps' => $apps, + )); + } - return replace_macros(get_markup_template('apps.tpl'), array( + if(argc() == 3 && argv(2) == 'edit') + $mode = 'edit'; + else + $mode = 'list'; + + $apps = array(); + $list = app_list(local_user()); + if($list) { + foreach($list as $app) + $apps[] = app_render(app_encode($app),$mode); + } + + return replace_macros(get_markup_template('myapps.tpl'), array( '$title' => t('Apps'), '$apps' => $apps, )); diff --git a/version.inc b/version.inc index 396a326bd..6b7ff2f87 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-05-19.680 +2014-05-20.681 diff --git a/view/tpl/app.tpl b/view/tpl/app.tpl index 30287b044..323dfbe63 100644 --- a/view/tpl/app.tpl +++ b/view/tpl/app.tpl @@ -1,6 +1,13 @@
- -
{{$ap.name}}
+
+
{{$app.name}}
+{{if $install || $update || $delete }} +
+ +{{if $install}}{{/if}} +{{if $delete}}{{/if}} +
+{{/if}}
diff --git a/view/tpl/app_select.tpl b/view/tpl/app_select.tpl index 9613b4976..d6eb2c31a 100644 --- a/view/tpl/app_select.tpl +++ b/view/tpl/app_select.tpl @@ -1,10 +1,8 @@

{{$title}}

diff --git a/view/tpl/myapps.tpl b/view/tpl/myapps.tpl new file mode 100755 index 000000000..1a591f9f8 --- /dev/null +++ b/view/tpl/myapps.tpl @@ -0,0 +1,9 @@ +

{{$title}}

+ +{{foreach $apps as $ap}} +
+{{$ap}} +
+{{/foreach}} +
+ -- cgit v1.2.3