appstore changes
This commit is contained in:
parent
51a2e64a89
commit
f6e8ce5516
@ -13,7 +13,12 @@ require_once('include/channel.php');
|
|||||||
|
|
||||||
class Apps {
|
class Apps {
|
||||||
|
|
||||||
static public $installed_system_apps = null;
|
static public $available_apps = null;
|
||||||
|
static public $installed_apps = null;
|
||||||
|
|
||||||
|
static public $base_apps = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static public function get_system_apps($translate = true) {
|
static public function get_system_apps($translate = true) {
|
||||||
|
|
||||||
@ -55,22 +60,52 @@ class Apps {
|
|||||||
static public function import_system_apps() {
|
static public function import_system_apps() {
|
||||||
if(! local_channel())
|
if(! local_channel())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
self::$base_apps = get_config('system','base_apps',[
|
||||||
|
'Connections',
|
||||||
|
'Suggest Channels',
|
||||||
|
'Grid',
|
||||||
|
'Settings',
|
||||||
|
'Files',
|
||||||
|
'Channel Home',
|
||||||
|
'View Profile',
|
||||||
|
'Photos',
|
||||||
|
'Events',
|
||||||
|
'Directory',
|
||||||
|
'Search',
|
||||||
|
'Help',
|
||||||
|
'Mail',
|
||||||
|
'Profile Photo'
|
||||||
|
]);
|
||||||
|
|
||||||
$apps = self::get_system_apps(false);
|
$apps = self::get_system_apps(false);
|
||||||
|
|
||||||
self::$installed_system_apps = q("select * from app where app_system = 1 and app_channel = %d",
|
self::$available_apps = q("select * from app where app_channel = 0");
|
||||||
|
|
||||||
|
self::$installed_apps = q("select * from app where app_channel = %d",
|
||||||
intval(local_channel())
|
intval(local_channel())
|
||||||
);
|
);
|
||||||
|
|
||||||
if($apps) {
|
if($apps) {
|
||||||
foreach($apps as $app) {
|
foreach($apps as $app) {
|
||||||
$id = self::check_install_system_app($app);
|
$id = self::check_install_system_app($app);
|
||||||
|
|
||||||
|
// $id will be boolean true or false to install an app, or an integer id to update an existing app
|
||||||
|
if($id !== false) {
|
||||||
|
$app['uid'] = 0;
|
||||||
|
$app['guid'] = hash('whirlpool',$app['name']);
|
||||||
|
$app['system'] = 1;
|
||||||
|
self::app_install(0,$app);
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = self::check_install_personal_app($app);
|
||||||
// $id will be boolean true or false to install an app, or an integer id to update an existing app
|
// $id will be boolean true or false to install an app, or an integer id to update an existing app
|
||||||
if($id === false)
|
if($id === false)
|
||||||
continue;
|
continue;
|
||||||
if($id !== true) {
|
if($id !== true) {
|
||||||
// if we already installed this app, but it changed, preserve any categories we created
|
// if we already installed this app, but it changed, preserve any categories we created
|
||||||
$s = '';
|
$s = EMPTY_STR;
|
||||||
$r = q("select * from term where otype = %d and oid = %d",
|
$r = q("select term from term where otype = %d and oid = %d",
|
||||||
intval(TERM_OBJ_APP),
|
intval(TERM_OBJ_APP),
|
||||||
intval($id)
|
intval($id)
|
||||||
);
|
);
|
||||||
@ -87,6 +122,7 @@ class Apps {
|
|||||||
$app['guid'] = hash('whirlpool',$app['name']);
|
$app['guid'] = hash('whirlpool',$app['name']);
|
||||||
$app['system'] = 1;
|
$app['system'] = 1;
|
||||||
self::app_install(local_channel(),$app);
|
self::app_install(local_channel(),$app);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,11 +133,11 @@ class Apps {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static public function check_install_system_app($app) {
|
static public function check_install_system_app($app) {
|
||||||
if((! is_array(self::$installed_system_apps)) || (! count(self::$installed_system_apps))) {
|
if((! is_array(self::$available_apps)) || (! count(self::$available_apps))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$notfound = true;
|
$notfound = true;
|
||||||
foreach(self::$installed_system_apps as $iapp) {
|
foreach(self::$available_apps as $iapp) {
|
||||||
if($iapp['app_id'] == hash('whirlpool',$app['name'])) {
|
if($iapp['app_id'] == hash('whirlpool',$app['name'])) {
|
||||||
$notfound = false;
|
$notfound = false;
|
||||||
if(($iapp['app_version'] != $app['version'])
|
if(($iapp['app_version'] != $app['version'])
|
||||||
@ -115,6 +151,28 @@ class Apps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install the system app if no system apps have been installed, or if a new system app
|
||||||
|
* is discovered, or if the version of a system app changes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public function check_install_personal_app($app) {
|
||||||
|
foreach(self::$installed_apps as $iapp) {
|
||||||
|
$install = false;
|
||||||
|
if($iapp['app_id'] == hash('whirlpool',$app['name'])) {
|
||||||
|
if(($iapp['app_version'] != $app['version'])
|
||||||
|
|| ($app['plugin'] && (! $iapp['app_plugin']))) {
|
||||||
|
return intval($iapp['app_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(in_array($app['name'],self::$base_apps)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static public function app_name_compare($a,$b) {
|
static public function app_name_compare($a,$b) {
|
||||||
return strcasecmp($a['name'],$b['name']);
|
return strcasecmp($a['name'],$b['name']);
|
||||||
}
|
}
|
||||||
@ -235,7 +293,6 @@ class Apps {
|
|||||||
'View Bookmarks' => t('View Bookmarks'),
|
'View Bookmarks' => t('View Bookmarks'),
|
||||||
'My Chatrooms' => t('My Chatrooms'),
|
'My Chatrooms' => t('My Chatrooms'),
|
||||||
'Connections' => t('Connections'),
|
'Connections' => t('Connections'),
|
||||||
'Firefox Share' => t('Firefox Share'),
|
|
||||||
'Remote Diagnostics' => t('Remote Diagnostics'),
|
'Remote Diagnostics' => t('Remote Diagnostics'),
|
||||||
'Suggest Channels' => t('Suggest Channels'),
|
'Suggest Channels' => t('Suggest Channels'),
|
||||||
'Login' => t('Login'),
|
'Login' => t('Login'),
|
||||||
@ -290,6 +347,7 @@ class Apps {
|
|||||||
* modes:
|
* modes:
|
||||||
* view: normal mode for viewing an app via bbcode from a conversation or page
|
* view: normal mode for viewing an app via bbcode from a conversation or page
|
||||||
* provides install/update button if you're logged in locally
|
* provides install/update button if you're logged in locally
|
||||||
|
* install: like view but does not display app-bin options if they are present
|
||||||
* list: normal mode for viewing an app on the app page
|
* list: normal mode for viewing an app on the app page
|
||||||
* no buttons are shown
|
* no buttons are shown
|
||||||
* edit: viewing the app page in editing mode provides a delete button
|
* edit: viewing the app page in editing mode provides a delete button
|
||||||
@ -302,7 +360,7 @@ class Apps {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(! $papp['photo'])
|
if(! $papp['photo'])
|
||||||
$papp['photo'] = z_root() . '/' . get_default_profile_photo(80);
|
$papp['photo'] = 'icon:gear';
|
||||||
|
|
||||||
self::translate_system_apps($papp);
|
self::translate_system_apps($papp);
|
||||||
|
|
||||||
@ -402,12 +460,15 @@ class Apps {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($mode === 'install') {
|
||||||
|
$papp['embed'] = true;
|
||||||
|
}
|
||||||
return replace_macros(get_markup_template('app.tpl'),array(
|
return replace_macros(get_markup_template('app.tpl'),array(
|
||||||
'$app' => $papp,
|
'$app' => $papp,
|
||||||
'$icon' => $icon,
|
'$icon' => $icon,
|
||||||
'$hosturl' => $hosturl,
|
'$hosturl' => $hosturl,
|
||||||
'$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''),
|
'$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''),
|
||||||
'$install' => (($hosturl && $mode == 'view') ? $install_action : ''),
|
'$install' => (($hosturl && in_array($mode, ['view','install'])) ? $install_action : ''),
|
||||||
'$edit' => ((local_channel() && $installed && $mode == 'edit') ? t('Edit') : ''),
|
'$edit' => ((local_channel() && $installed && $mode == 'edit') ? t('Edit') : ''),
|
||||||
'$delete' => ((local_channel() && $installed && $mode == 'edit') ? t('Delete') : ''),
|
'$delete' => ((local_channel() && $installed && $mode == 'edit') ? t('Delete') : ''),
|
||||||
'$undelete' => ((local_channel() && $installed && $mode == 'edit') ? t('Undelete') : ''),
|
'$undelete' => ((local_channel() && $installed && $mode == 'edit') ? t('Undelete') : ''),
|
||||||
@ -738,12 +799,19 @@ class Apps {
|
|||||||
$darray = array();
|
$darray = array();
|
||||||
$ret = array('success' => false);
|
$ret = array('success' => false);
|
||||||
|
|
||||||
|
$sys = get_sys_channel();
|
||||||
|
|
||||||
|
|
||||||
$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['app_url']) || (! $darray['app_channel']))
|
if(! $darray['app_url'])
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
|
if((! $arr['uid']) && (! $arr['author'])) {
|
||||||
|
$arr['author'] = $sys['channel_hash'];
|
||||||
|
}
|
||||||
|
|
||||||
if($arr['photo'] && (strpos($arr['photo'],'icon:') !== 0) && (! strstr($arr['photo'],z_root()))) {
|
if($arr['photo'] && (strpos($arr['photo'],'icon:') !== 0) && (! strstr($arr['photo'],z_root()))) {
|
||||||
$x = import_xchan_photo($arr['photo'],get_observer_hash(),true);
|
$x = import_xchan_photo($arr['photo'],get_observer_hash(),true);
|
||||||
$arr['photo'] = $x[1];
|
$arr['photo'] = $x[1];
|
||||||
|
@ -15,6 +15,8 @@ class Apps extends \Zotlabs\Web\Controller {
|
|||||||
else
|
else
|
||||||
$mode = 'list';
|
$mode = 'list';
|
||||||
|
|
||||||
|
$available = ((argc() == 2 && argv(1) === 'available') ? true : false);
|
||||||
|
|
||||||
$_SESSION['return_url'] = \App::$query_string;
|
$_SESSION['return_url'] = \App::$query_string;
|
||||||
|
|
||||||
$apps = array();
|
$apps = array();
|
||||||
@ -23,7 +25,7 @@ class Apps extends \Zotlabs\Web\Controller {
|
|||||||
Zlib\Apps::import_system_apps();
|
Zlib\Apps::import_system_apps();
|
||||||
$syslist = array();
|
$syslist = array();
|
||||||
$cat = ((array_key_exists('cat',$_GET) && $_GET['cat']) ? [ escape_tags($_GET['cat']) ] : '');
|
$cat = ((array_key_exists('cat',$_GET) && $_GET['cat']) ? [ escape_tags($_GET['cat']) ] : '');
|
||||||
$list = Zlib\Apps::app_list(local_channel(), (($mode == 'edit') ? true : false), $cat);
|
$list = Zlib\Apps::app_list((($available) ? 0 : local_channel()), (($mode == 'edit') ? true : false), $cat);
|
||||||
if($list) {
|
if($list) {
|
||||||
foreach($list as $x) {
|
foreach($list as $x) {
|
||||||
$syslist[] = Zlib\Apps::app_encode($x);
|
$syslist[] = Zlib\Apps::app_encode($x);
|
||||||
@ -39,7 +41,7 @@ class Apps extends \Zotlabs\Web\Controller {
|
|||||||
// logger('apps: ' . print_r($syslist,true));
|
// logger('apps: ' . print_r($syslist,true));
|
||||||
|
|
||||||
foreach($syslist as $app) {
|
foreach($syslist as $app) {
|
||||||
$apps[] = Zlib\Apps::app_render($app,$mode);
|
$apps[] = Zlib\Apps::app_render($app,(($available) ? 'install' : $mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
return replace_macros(get_markup_template('myapps.tpl'), array(
|
return replace_macros(get_markup_template('myapps.tpl'), array(
|
||||||
|
@ -17,6 +17,9 @@ class Appcategories {
|
|||||||
|
|
||||||
// Leaving this line which negates the effect of the two invalid lines prior
|
// Leaving this line which negates the effect of the two invalid lines prior
|
||||||
$srchurl = z_root() . '/apps';
|
$srchurl = z_root() . '/apps';
|
||||||
|
if(argc() > 1 && argv(1) === 'available')
|
||||||
|
$srchurl .= '/available';
|
||||||
|
|
||||||
|
|
||||||
$terms = array();
|
$terms = array();
|
||||||
|
|
||||||
|
18
Zotlabs/Widget/Appstore.php
Normal file
18
Zotlabs/Widget/Appstore.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Widget;
|
||||||
|
|
||||||
|
|
||||||
|
class Appstore {
|
||||||
|
|
||||||
|
function widget($arr) {
|
||||||
|
$store = ((argc() > 1 && argv(1) === 'available') ? 1 : 0);
|
||||||
|
return replace_macros(get_markup_template('appstore.tpl'), [
|
||||||
|
'$title' => t('App Collections'),
|
||||||
|
'$options' => [
|
||||||
|
[ z_root() . '/apps/available', t('Available Apps'), $store ],
|
||||||
|
[ z_root() . '/apps', t('Installed apps'), 1 - $store ]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
[region=aside]
|
[region=aside]
|
||||||
|
[widget=appstore][/widget]
|
||||||
[widget=appcategories][/widget]
|
[widget=appcategories][/widget]
|
||||||
[/region]
|
[/region]
|
||||||
[region=right_aside]
|
[region=right_aside]
|
||||||
|
8
view/tpl/appstore.tpl
Normal file
8
view/tpl/appstore.tpl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<div class="widget">
|
||||||
|
<h3>{{$title}}</h3>
|
||||||
|
<ul class="nav nav-pills flex-column">
|
||||||
|
{{foreach $options as $x}}
|
||||||
|
<li class="nav-item"><a href="{{$x.0}}" class="nav-link{{if $x.2}} active{{/if}}">{{$x.1}}</a></li>
|
||||||
|
{{/foreach}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
Reference in New Issue
Block a user