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.

This commit is contained in:
friendica 2014-05-20 18:08:49 -07:00
parent 8333f9fe20
commit fc0967b84b
8 changed files with 121 additions and 17 deletions

View File

@ -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); 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) { 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(); $ret = array();
@ -285,7 +322,16 @@ function app_encode($app) {
if($app['app_page']) if($app['app_page'])
$ret['page'] = $app['app_page']; $ret['page'] = $app['app_page'];
if(! $embed)
return $ret;
$j = json_encode($ret); $j = json_encode($ret);
return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]'; return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]';
} }
function papp_encode($papp) {
return chunk_split(base64_encode(json_encode($papp)),72,"\n");
}

View File

@ -78,9 +78,9 @@ function widget_appselect($arr) {
return replace_macros(get_markup_template('app_select.tpl'),array( return replace_macros(get_markup_template('app_select.tpl'),array(
'$title' => t('App Category'), '$title' => t('App Category'),
'$system' => t('System'), '$system' => t('System'),
'$personal' => t('Personal'), '$personal' => t('Personal')
'$featured' => t('Featured'), // '$featured' => t('Featured'),
'$new' => t('New') // '$new' => t('New')
)); ));
} }

26
mod/appman.php Normal file
View File

@ -0,0 +1,26 @@
<?php /** @file */
require_once('include/apps.php');
function appman_post(&$a) {
if(! local_user())
return;
$papp = app_decode($_POST['papp']);
if(! is_array($papp)) {
notice( t('Malformed app.') . EOL);
return;
}
if($_POST['install']) {
app_install(local_user(),$papp);
}
if($_POST['delete']) {
app_destroy(local_user(),$papp);
}
}

View File

@ -5,17 +5,35 @@ require_once('include/apps.php');
function apps_content(&$a) { function apps_content(&$a) {
if(argc() == 1 || (! local_user())) {
$apps = get_system_apps(); $apps = get_system_apps();
// $o .= print_r($apps,true); // $o .= print_r($apps,true);
// return $o;
// return $o;
return replace_macros(get_markup_template('apps.tpl'), array( return replace_macros(get_markup_template('apps.tpl'), array(
'$title' => t('Apps'), '$title' => t('Apps'),
'$apps' => $apps, '$apps' => $apps,
)); ));
}
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,
));
} }

View File

@ -1 +1 @@
2014-05-19.680 2014-05-20.681

View File

@ -1,6 +1,13 @@
<div class="app-container"> <div class="app-container">
<a href="{{$ap.url}}" {{if $ap.hover}}title="{{$ap.hover}}"{{/if}}><img src="{{$ap.photo}}" width="80" height="80" /> <a href="{{$app.url}}" {{if $app.hover}}title="{{$app.hover}}"{{/if}}><img src="{{$app.photo}}" width="80" height="80" />
<div class="app-name">{{$ap.name}}</div> <div class="app-name">{{$app.name}}</div>
</a> </a>
{{if $install || $update || $delete }}
<form action="appman" method="post">
<input type="hidden" name="papp" value="{{$app.papp}}" />
{{if $install}}<button type="submit" name="install" value="{{$install}}" class="btn btn-default" title="{{$install}}" /><i class="icon-download-alt" ></i></button>{{/if}}
{{if $delete}}<button type="submit" name="delete" value="{{$delete}}" class="btn btn-default" title="{{$delete}}" /><i class="icon-remove drop-icons"></i></button>{{/if}}
</form>
{{/if}}
</div> </div>

View File

@ -1,10 +1,8 @@
<div class="widget"> <div class="widget">
<h3>{{$title}}</h3> <h3>{{$title}}</h3>
<ul> <ul>
<li><a href="apps/system">{{$system}}</a></li> <li><a href="apps">{{$system}}</a></li>
<li><a href="apps/personal">{{$personal}}</a></li> <li><a href="apps/personal">{{$personal}}</a></li>
<li><a href="apps/featured">{{$featured}}</a></li>
<li><a href="apps/new">{{$new}}</a></li>
</ul> </ul>
</div> </div>

9
view/tpl/myapps.tpl Executable file
View File

@ -0,0 +1,9 @@
<h3>{{$title}}</h3>
{{foreach $apps as $ap}}
<div class="app-container">
{{$ap}}
</div>
{{/foreach}}
<div class="clear"></div>