mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-21 19:35:24 +00:00
add categories to apps (wip)
This commit is contained in:
parent
7c57da3a28
commit
50fb525b28
5 changed files with 187 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php /** @file */
|
||||||
namespace Zotlabs\Module; /** @file */
|
|
||||||
|
namespace Zotlabs\Module;
|
||||||
|
|
||||||
require_once('include/apps.php');
|
require_once('include/apps.php');
|
||||||
|
|
||||||
|
@ -25,7 +26,8 @@ class Appman extends \Zotlabs\Web\Controller {
|
||||||
'price' => escape_tags($_REQUEST['price']),
|
'price' => escape_tags($_REQUEST['price']),
|
||||||
'requires' => escape_tags($_REQUEST['requires']),
|
'requires' => escape_tags($_REQUEST['requires']),
|
||||||
'system' => intval($_REQUEST['system']),
|
'system' => intval($_REQUEST['system']),
|
||||||
'sig' => escape_tags($_REQUEST['sig'])
|
'sig' => escape_tags($_REQUEST['sig']),
|
||||||
|
'categories' => escape_tags($_REQUEST['categories'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$_REQUEST['appid'] = app_install(local_channel(),$arr);
|
$_REQUEST['appid'] = app_install(local_channel(),$arr);
|
||||||
|
@ -81,8 +83,23 @@ class Appman extends \Zotlabs\Web\Controller {
|
||||||
dbesc($_REQUEST['appid']),
|
dbesc($_REQUEST['appid']),
|
||||||
dbesc(local_channel())
|
dbesc(local_channel())
|
||||||
);
|
);
|
||||||
if($r)
|
if($r) {
|
||||||
$app = $r[0];
|
$app = $r[0];
|
||||||
|
|
||||||
|
$term = q("select * from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($r[0]['id'])
|
||||||
|
);
|
||||||
|
if($term) {
|
||||||
|
$app['categories'] = '';
|
||||||
|
foreach($term as $t) {
|
||||||
|
if($app['categories'])
|
||||||
|
$app['categories'] .= ',';
|
||||||
|
$app['categories'] .= $t['term'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$embed = array('embed', t('Embed code'), app_encode($app,true),'', 'onclick="this.select();"');
|
$embed = array('embed', t('Embed code'), app_encode($app,true),'', 'onclick="this.select();"');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -98,6 +115,7 @@ class Appman extends \Zotlabs\Web\Controller {
|
||||||
'$url' => array('url', t('Location (URL) of app'),(($app) ? $app['app_url'] : ''), t('Required')),
|
'$url' => array('url', t('Location (URL) of app'),(($app) ? $app['app_url'] : ''), t('Required')),
|
||||||
'$desc' => array('desc', t('Description'),(($app) ? $app['app_desc'] : ''), ''),
|
'$desc' => array('desc', t('Description'),(($app) ? $app['app_desc'] : ''), ''),
|
||||||
'$photo' => array('photo', t('Photo icon URL'),(($app) ? $app['app_photo'] : ''), t('80 x 80 pixels - optional')),
|
'$photo' => array('photo', t('Photo icon URL'),(($app) ? $app['app_photo'] : ''), t('80 x 80 pixels - optional')),
|
||||||
|
'$categories' => array('categories',t('Categories (optional, comma separated list)'),(($app) ? $app['categories'] : ''),''),
|
||||||
'$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'] : ''), ''),
|
||||||
|
|
|
@ -69,6 +69,7 @@ function app_name_compare($a,$b) {
|
||||||
return strcmp($a['name'],$b['name']);
|
return strcmp($a['name'],$b['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function parse_app_description($f,$translate = true) {
|
function parse_app_description($f,$translate = true) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
|
@ -295,6 +296,7 @@ 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))
|
||||||
$x = app_update($app);
|
$x = app_update($app);
|
||||||
else
|
else
|
||||||
|
@ -305,9 +307,17 @@ function app_install($uid,$app) {
|
||||||
dbesc($x['app_id']),
|
dbesc($x['app_id']),
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
if($r)
|
if($r) {
|
||||||
|
if(! $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),
|
||||||
|
intval($r[0]['id'])
|
||||||
|
);
|
||||||
build_sync_packet($uid,array('app' => $r[0]));
|
build_sync_packet($uid,array('app' => $r[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return $x['app_id'];
|
return $x['app_id'];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -322,8 +332,12 @@ function app_destroy($uid,$app) {
|
||||||
dbesc($app['guid']),
|
dbesc($app['guid']),
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
|
if($x) {
|
||||||
$x[0]['app_deleted'] = 1;
|
$x[0]['app_deleted'] = 1;
|
||||||
|
q("delete from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($x[0]['id'])
|
||||||
|
);
|
||||||
if($x[0]['app_system']) {
|
if($x[0]['app_system']) {
|
||||||
$r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
|
$r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
|
||||||
dbesc($app['guid']),
|
dbesc($app['guid']),
|
||||||
|
@ -335,11 +349,13 @@ function app_destroy($uid,$app) {
|
||||||
dbesc($app['guid']),
|
dbesc($app['guid']),
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
|
// we don't sync system apps - they may be completely different on the other system
|
||||||
build_sync_packet($uid,array('app' => $x));
|
build_sync_packet($uid,array('app' => $x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function app_installed($uid,$app) {
|
function app_installed($uid,$app) {
|
||||||
|
@ -365,7 +381,12 @@ function app_list($uid, $deleted = false) {
|
||||||
);
|
);
|
||||||
if($r) {
|
if($r) {
|
||||||
for($x = 0; $x < count($r); $x ++) {
|
for($x = 0; $x < count($r); $x ++) {
|
||||||
|
if(! $r[$x]['app_system'])
|
||||||
$r[$x]['type'] = 'personal';
|
$r[$x]['type'] = 'personal';
|
||||||
|
$r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($r[$x]['id'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return($r);
|
return($r);
|
||||||
|
@ -436,6 +457,22 @@ function app_store($arr) {
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
$ret['app_id'] = $darray['app_id'];
|
$ret['app_id'] = $darray['app_id'];
|
||||||
}
|
}
|
||||||
|
if($arr['categories']) {
|
||||||
|
$x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||||
|
dbesc($darray['app_id']),
|
||||||
|
intval($darray['app_channel'])
|
||||||
|
);
|
||||||
|
$y = explode(',',$arr['categories']);
|
||||||
|
if($y) {
|
||||||
|
foreach($y as $t) {
|
||||||
|
$t = trim($t);
|
||||||
|
if($t) {
|
||||||
|
store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,6 +532,28 @@ function app_update($arr) {
|
||||||
$ret['app_id'] = $darray['app_id'];
|
$ret['app_id'] = $darray['app_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||||
|
dbesc($darray['app_id']),
|
||||||
|
intval($darray['app_channel'])
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
q("delete from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($x[0]['id'])
|
||||||
|
);
|
||||||
|
if($arr['categories']) {
|
||||||
|
$y = explode(',',$arr['categories']);
|
||||||
|
if($y) {
|
||||||
|
foreach($y as $t) {
|
||||||
|
$t = trim($t);
|
||||||
|
if($t) {
|
||||||
|
store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -551,9 +610,23 @@ function app_encode($app,$embed = false) {
|
||||||
if($app['app_deleted'])
|
if($app['app_deleted'])
|
||||||
$ret['deleted'] = $app['app_deleted'];
|
$ret['deleted'] = $app['app_deleted'];
|
||||||
|
|
||||||
|
if($app['term']) {
|
||||||
|
$s = '';
|
||||||
|
foreach($app['term'] as $t) {
|
||||||
|
if($s)
|
||||||
|
$s .= ',';
|
||||||
|
$s .= $t['term'];
|
||||||
|
}
|
||||||
|
$ret['categories'] = $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(! $embed)
|
if(! $embed)
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
|
if(array_key_exists('categories',$ret))
|
||||||
|
unset($ret['categories']);
|
||||||
|
|
||||||
$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]';
|
||||||
|
|
||||||
|
|
|
@ -580,11 +580,18 @@ function identity_basic_export($channel_id, $items = false) {
|
||||||
if($r)
|
if($r)
|
||||||
$ret['obj'] = $r;
|
$ret['obj'] = $r;
|
||||||
|
|
||||||
$r = q("select * from app where app_channel = %d",
|
$r = q("select * from app where app_channel = %d and app_system = 0",
|
||||||
intval($channel_id)
|
intval($channel_id)
|
||||||
);
|
);
|
||||||
if($r)
|
if($r) {
|
||||||
|
for($x = 0; $x < count($r); $x ++) {
|
||||||
|
$r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($r[$x]['id'])
|
||||||
|
);
|
||||||
|
}
|
||||||
$ret['app'] = $r;
|
$ret['app'] = $r;
|
||||||
|
}
|
||||||
|
|
||||||
$r = q("select * from chatroom where cr_uid = %d",
|
$r = q("select * from chatroom where cr_uid = %d",
|
||||||
intval($channel_id)
|
intval($channel_id)
|
||||||
|
|
|
@ -297,8 +297,11 @@ function import_apps($channel,$apps) {
|
||||||
if($channel && $apps) {
|
if($channel && $apps) {
|
||||||
foreach($apps as $app) {
|
foreach($apps as $app) {
|
||||||
|
|
||||||
|
$term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null);
|
||||||
|
|
||||||
unset($app['id']);
|
unset($app['id']);
|
||||||
unset($app['app_channel']);
|
unset($app['app_channel']);
|
||||||
|
unset($app['term']);
|
||||||
|
|
||||||
$app['app_channel'] = $channel['channel_id'];
|
$app['app_channel'] = $channel['channel_id'];
|
||||||
|
|
||||||
|
@ -307,6 +310,8 @@ function import_apps($channel,$apps) {
|
||||||
$app['app_photo'] = $x[0];
|
$app['app_photo'] = $x[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hash = $app['app_id'];
|
||||||
|
|
||||||
dbesc_array($app);
|
dbesc_array($app);
|
||||||
$r = dbq("INSERT INTO app (`"
|
$r = dbq("INSERT INTO app (`"
|
||||||
. implode("`, `", array_keys($app))
|
. implode("`, `", array_keys($app))
|
||||||
|
@ -314,6 +319,21 @@ function import_apps($channel,$apps) {
|
||||||
. implode("', '", array_values($app))
|
. implode("', '", array_values($app))
|
||||||
. "')"
|
. "')"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if($term) {
|
||||||
|
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||||
|
dbesc($hash),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
foreach($term as $t) {
|
||||||
|
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,16 +345,41 @@ function sync_apps($channel,$apps) {
|
||||||
if($channel && $apps) {
|
if($channel && $apps) {
|
||||||
foreach($apps as $app) {
|
foreach($apps as $app) {
|
||||||
|
|
||||||
|
$exists = false;
|
||||||
|
$term = ((array_key_exists('term',$app)) ? $app['term'] : null);
|
||||||
|
|
||||||
|
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||||
|
dbesc($app['app_id']),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
$exists = $x[0];
|
||||||
|
}
|
||||||
|
|
||||||
if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
|
if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
|
||||||
q("delete from app where app_id = '%s' and app_channel = %d limit 1",
|
q("delete from app where app_id = '%s' and app_channel = %d limit 1",
|
||||||
dbesc($app['app_id']),
|
dbesc($app['app_id']),
|
||||||
intval($channel['channel_id'])
|
intval($channel['channel_id'])
|
||||||
);
|
);
|
||||||
|
if($exists) {
|
||||||
|
q("delete from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($exists['id'])
|
||||||
|
);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($app['id']);
|
unset($app['id']);
|
||||||
unset($app['app_channel']);
|
unset($app['app_channel']);
|
||||||
|
unset($app['term']);
|
||||||
|
|
||||||
|
if($exists) {
|
||||||
|
q("delete from term where otype = %d and oid = %d",
|
||||||
|
intval(TERM_OBJ_APP),
|
||||||
|
intval($exists['id'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if(! $app['app_created'] || $app['app_created'] === NULL_DATE)
|
if(! $app['app_created'] || $app['app_created'] === NULL_DATE)
|
||||||
$app['app_created'] = datetime_convert();
|
$app['app_created'] = datetime_convert();
|
||||||
|
@ -348,16 +393,15 @@ function sync_apps($channel,$apps) {
|
||||||
$app['app_photo'] = $x[0];
|
$app['app_photo'] = $x[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$exists = false;
|
if($exists && $term) {
|
||||||
|
foreach($term as $t) {
|
||||||
|
store_item_tag($channel['channel_id'],$exists['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
if($exists) {
|
||||||
dbesc($app['app_id']),
|
if($exists['app_edited'] >= $app['app_edited'])
|
||||||
intval($channel['channel_id'])
|
|
||||||
);
|
|
||||||
if($x) {
|
|
||||||
if($x[0]['app_edited'] >= $app['app_edited'])
|
|
||||||
continue;
|
continue;
|
||||||
$exists = true;
|
|
||||||
}
|
}
|
||||||
$hash = $app['app_id'];
|
$hash = $app['app_id'];
|
||||||
|
|
||||||
|
@ -380,6 +424,17 @@ function sync_apps($channel,$apps) {
|
||||||
. implode("', '", array_values($app))
|
. implode("', '", array_values($app))
|
||||||
. "')"
|
. "')"
|
||||||
);
|
);
|
||||||
|
if($term) {
|
||||||
|
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||||
|
dbesc($hash),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
foreach($term as $t) {
|
||||||
|
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
|
|
||||||
{{include file="field_input.tpl" field=$name}}
|
{{include file="field_input.tpl" field=$name}}
|
||||||
|
{{include file="field_input.tpl" field=$categories}}
|
||||||
{{include file="field_input.tpl" field=$url}}
|
{{include file="field_input.tpl" field=$url}}
|
||||||
{{include file="field_textarea.tpl" field=$desc}}
|
{{include file="field_textarea.tpl" field=$desc}}
|
||||||
{{include file="field_input.tpl" field=$photo}}
|
{{include file="field_input.tpl" field=$photo}}
|
||||||
|
|
Loading…
Reference in a new issue