more app work

This commit is contained in:
friendica 2014-05-20 22:25:36 -07:00
parent cad481d94f
commit 5d9f924642
4 changed files with 77 additions and 28 deletions

View File

@ -93,7 +93,7 @@ function parse_app_description($f) {
break; break;
} }
logger('require: ' . print_r($ret,true)); // logger('require: ' . print_r($ret,true));
} }
if($ret) { if($ret) {
translate_system_apps($ret); translate_system_apps($ret);
@ -156,9 +156,14 @@ function app_render($papp,$mode = 'view') {
function app_install($uid,$app) { function app_install($uid,$app) {
$app['uid'] = $uid; $app['uid'] = $uid;
if(app_installed($uid,$app)) if(app_installed($uid,$app))
app_update($app); $x = app_update($app);
else else
app_store($app); $x = app_store($app);
if($x['success'])
return $x['app_id'];
return false;
} }
function app_destroy($uid,$app) { function app_destroy($uid,$app) {
@ -199,14 +204,22 @@ function app_decode($s) {
function app_store($arr) { function app_store($arr) {
// logger('app_store: ' . print_r($arr,true));
$darray = array(); $darray = array();
$ret = array('success' => false); $ret = array('success' => false);
$darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : '');
$darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0);
if((! $darray['url']) || (! $darray['app_channel'])) if((! $darray['app_url']) || (! $darray['app_channel']))
return $ret; return $ret;
if($arr['photo'] && ! strstr($arr['photo'],z_root())) {
$x = import_profile_photo($arr['photo'],get_observer_hash(),true);
$arr['photo'] = $x[1];
}
$darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . get_app()->get_hostname()); $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . get_app()->get_hostname());
$darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : '');
$darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash());
@ -232,9 +245,10 @@ function app_store($arr) {
dbesc($darray['app_price']), dbesc($darray['app_price']),
dbesc($darray['app_page']) dbesc($darray['app_page'])
); );
if($r) if($r) {
$ret['success'] = true; $ret['success'] = true;
$ret['app_id'] = $darray['app_id'];
}
return $ret; return $ret;
} }
@ -247,9 +261,14 @@ function app_update($arr) {
$darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : '');
$darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0);
$darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0); $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0);
if((! $darray['url']) || (! $darray['app_channel']) || (! $darray['app_id'])) if((! $darray['app_url']) || (! $darray['app_channel']) || (! $darray['app_id']))
return $ret; return $ret;
if($arr['photo'] && ! strstr($arr['photo'],z_root())) {
$x = import_profile_photo($arr['photo'],get_observer_hash(),true);
$arr['photo'] = $x[1];
}
$darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : '');
$darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash());
$darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown'));
@ -274,8 +293,10 @@ function app_update($arr) {
dbesc($darray['app_id']), dbesc($darray['app_id']),
intval($darray['app_channel']) intval($darray['app_channel'])
); );
if($r) if($r) {
$ret['success'] = true; $ret['success'] = true;
$ret['app_id'] = $darray['app_id'];
}
return $ret; return $ret;

View File

@ -7,6 +7,28 @@ function appman_post(&$a) {
if(! local_user()) if(! local_user())
return; return;
if($_POST['url']) {
$arr = array(
'uid' => intval($_REQUEST['uid']),
'url' => escape_tags($_REQUEST['url']),
'guid' => escape_tags($_REQUEST['guid']),
'author' => escape_tags($_REQUEST['author']),
'addr' => escape_tags($_REQUEST['addr']),
'name' => escape_tags($_REQUEST['name']),
'desc' => escape_tags($_REQUEST['desc']),
'photo' => escape_tags($_REQUEST['photo']),
'version' => escape_tags($_REQUEST['version']),
'price' => escape_tags($_REQUEST['price']),
'sig' => escape_tags($_REQUEST['sig'])
);
$_REQUEST['appid'] = app_install(local_user(),$arr);
if(app_installed(local_user(),$app))
info( t('App installed.') . EOL);
return;
}
$papp = app_decode($_POST['papp']); $papp = app_decode($_POST['papp']);
if(! is_array($papp)) { if(! is_array($papp)) {
@ -39,7 +61,7 @@ function appman_content(&$a) {
$channel = $a->get_channel(); $channel = $a->get_channel();
$app = null; $app = null;
$embed = null;
if($_REQUEST['appid']) { if($_REQUEST['appid']) {
$r = q("select * from app where app_id = '%s' and app_channel = %d limit 1", $r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($_REQUEST['appid']), dbesc($_REQUEST['appid']),
@ -47,6 +69,8 @@ function appman_content(&$a) {
); );
if($r) if($r)
$app = $r[0]; $app = $r[0];
$embed = array('embed', t('Embed code'), app_encode($app,true),'');
} }
return replace_macros(get_markup_template('app_create.tpl'), array( return replace_macros(get_markup_template('app_create.tpl'), array(
@ -63,8 +87,8 @@ function appman_content(&$a) {
'$version' => array('version', t('Version ID'),(($app) ? $app['app_version'] : ''), ''), '$version' => array('version', t('Version ID'),(($app) ? $app['app_version'] : ''), ''),
'$price' => array('price', t('Price of app'),(($app) ? $app['app_price'] : ''), ''), '$price' => array('price', t('Price of app'),(($app) ? $app['app_price'] : ''), ''),
'$page' => array('page', t('Location (URL) to purchase app'),(($app) ? $app['app_page'] : ''), ''), '$page' => array('page', t('Location (URL) to purchase app'),(($app) ? $app['app_page'] : ''), ''),
'$embed' => $embed,
'$submit' => t('Submit') '$submit' => t('Submit')
)); ));
} }

View File

@ -5,8 +5,8 @@
{{if $install || $update || $delete }} {{if $install || $update || $delete }}
<form action="appman" method="post"> <form action="appman" method="post">
<input type="hidden" name="papp" value="{{$app.papp}}" /> <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 $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}} {{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> </form>
{{/if}} {{/if}}
</div> </div>

View File

@ -14,12 +14,16 @@
{{include file="field_input.tpl" field=$name}} {{include file="field_input.tpl" field=$name}}
{{include file="field_input.tpl" field=$url}} {{include file="field_input.tpl" field=$url}}
{{include file="field_input.tpl" field=$desc}} {{include file="field_textarea.tpl" field=$desc}}
{{include file="field_input.tpl" field=$photo}} {{include file="field_input.tpl" field=$photo}}
{{include file="field_input.tpl" field=$version}} {{include file="field_input.tpl" field=$version}}
{{include file="field_input.tpl" field=$price}} {{include file="field_input.tpl" field=$price}}
{{include file="field_input.tpl" field=$page}} {{include file="field_input.tpl" field=$page}}
{{if $embed}}
{{include file="field_textarea.tpl" field=$embed}}
{{/if}}
<input type="submit" name="submit" value="{{$submit}}" /> <input type="submit" name="submit" value="{{$submit}}" />
</form> </form>