2019-04-29 04:17:04 +00:00
|
|
|
<?php
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
namespace Zotlabs\Lib;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
use App;
|
2018-06-05 01:40:11 +00:00
|
|
|
use Zotlabs\Lib\Libsync;
|
2018-06-01 04:05:09 +00:00
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
/**
|
|
|
|
* Apps
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Apps {
|
|
|
|
|
2018-07-05 05:56:43 +00:00
|
|
|
static public $available_apps = null;
|
|
|
|
static public $installed_apps = null;
|
|
|
|
|
|
|
|
static public $base_apps = null;
|
|
|
|
|
2020-11-25 03:22:59 +00:00
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
static public function get_system_apps($translate = true) {
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
$ret = [];
|
|
|
|
if (is_dir('apps')) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$files = glob('apps/*.apd');
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-05-23 02:26:21 +00:00
|
|
|
$files = glob('app/*.apd');
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if ($files) {
|
|
|
|
foreach ($files as $f) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$x = self::parse_app_description($f,$translate);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret[] = $x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$files = glob('addon/*/*.apd');
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($files) {
|
|
|
|
foreach ($files as $f) {
|
2016-07-01 09:16:23 +00:00
|
|
|
$path = explode('/',$f);
|
2017-05-15 01:02:22 +00:00
|
|
|
$plugin = trim($path[1]);
|
2020-09-24 01:02:29 +00:00
|
|
|
if (addon_is_installed($plugin)) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$x = self::parse_app_description($f,$translate);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
2016-12-15 03:11:01 +00:00
|
|
|
$x['plugin'] = $plugin;
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret[] = $x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-21 23:19:17 +00:00
|
|
|
call_hooks('get_system_apps',$ret);
|
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
return $ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-27 21:36:06 +00:00
|
|
|
static public function get_base_apps() {
|
2021-10-28 22:12:43 +00:00
|
|
|
|
2021-10-29 09:00:48 +00:00
|
|
|
// to add additional default "base" apps to your site, put their English name, one per line,
|
|
|
|
// into 'cache/default_apps'. This will be merged with the default project base apps.
|
|
|
|
|
2021-10-28 22:12:43 +00:00
|
|
|
if (file_exists('cache/default_apps')) {
|
2021-10-29 09:00:48 +00:00
|
|
|
$custom_apps = file('cache/default_apps', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
2021-10-28 22:12:43 +00:00
|
|
|
// do some cleanup in case the file was edited by hand and contains accidentally introduced whitespace
|
2021-10-29 09:00:48 +00:00
|
|
|
if (is_array($custom_apps) && $custom_apps) {
|
|
|
|
$custom_apps = array_map('trim', $custom_apps);
|
2021-10-28 22:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-29 09:00:48 +00:00
|
|
|
|
|
|
|
$default_apps = [
|
|
|
|
'Channel Home',
|
|
|
|
'Connections',
|
|
|
|
'Directory',
|
|
|
|
'Events',
|
|
|
|
'Files',
|
|
|
|
'Help',
|
|
|
|
'Lists',
|
|
|
|
'Photos',
|
|
|
|
'Profile Photo',
|
|
|
|
'Search',
|
|
|
|
'Settings',
|
|
|
|
'Stream',
|
|
|
|
'Suggest Channels',
|
|
|
|
'View Profile'
|
|
|
|
];
|
|
|
|
if (is_array($custom_apps)) {
|
|
|
|
$default_apps = array_values(array_unique(array_merge($default_apps,$custom_apps)));
|
2021-10-28 22:12:43 +00:00
|
|
|
}
|
2021-10-29 09:00:48 +00:00
|
|
|
|
2021-10-28 22:12:43 +00:00
|
|
|
$x = get_config('system','base_apps',$default_apps);
|
2019-01-09 04:34:39 +00:00
|
|
|
call_hooks('get_base_apps',$x);
|
|
|
|
return $x;
|
2018-07-27 21:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static public function import_system_apps() {
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! local_channel()) {
|
2018-07-27 21:36:06 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-07-05 05:56:43 +00:00
|
|
|
|
2018-07-27 21:36:06 +00:00
|
|
|
self::$base_apps = self::get_base_apps();
|
|
|
|
|
2016-06-02 23:38:15 +00:00
|
|
|
$apps = self::get_system_apps(false);
|
2020-11-25 03:22:59 +00:00
|
|
|
|
2018-07-05 05:56:43 +00:00
|
|
|
self::$available_apps = q("select * from app where app_channel = 0");
|
|
|
|
|
|
|
|
self::$installed_apps = q("select * from app where app_channel = %d",
|
2016-06-02 23:38:15 +00:00
|
|
|
intval(local_channel())
|
|
|
|
);
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($apps) {
|
|
|
|
foreach ($apps as $app) {
|
2016-06-03 00:08:47 +00:00
|
|
|
$id = self::check_install_system_app($app);
|
2018-07-05 06:20:35 +00:00
|
|
|
|
|
|
|
// $id will be boolean true or false to install an app, or an integer id to update an existing app
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($id !== false) {
|
2018-07-05 06:20:35 +00:00
|
|
|
$app['uid'] = 0;
|
|
|
|
$app['guid'] = hash('whirlpool',$app['name']);
|
|
|
|
$app['system'] = 1;
|
|
|
|
self::app_install(0,$app);
|
|
|
|
}
|
|
|
|
|
2018-07-05 05:56:43 +00:00
|
|
|
$id = self::check_install_personal_app($app);
|
2016-06-03 00:08:47 +00:00
|
|
|
// $id will be boolean true or false to install an app, or an integer id to update an existing app
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($id === false) {
|
2016-06-03 00:08:47 +00:00
|
|
|
continue;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if ($id !== true) {
|
2016-06-03 00:08:47 +00:00
|
|
|
// if we already installed this app, but it changed, preserve any categories we created
|
2018-07-05 05:56:43 +00:00
|
|
|
$r = q("select term from term where otype = %d and oid = %d",
|
2016-06-03 00:08:47 +00:00
|
|
|
intval(TERM_OBJ_APP),
|
|
|
|
intval($id)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($r) {
|
|
|
|
$app['categories'] = array_elm_to_str($r,'term');
|
2016-06-03 00:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
$app['uid'] = local_channel();
|
|
|
|
$app['guid'] = hash('whirlpool',$app['name']);
|
|
|
|
$app['system'] = 1;
|
2016-06-03 00:08:47 +00:00
|
|
|
self::app_install(local_channel(),$app);
|
2018-07-05 05:56:43 +00:00
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-02 23:38:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 23:45:00 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-06-02 23:38:15 +00:00
|
|
|
static public function check_install_system_app($app) {
|
2019-05-23 23:37:56 +00:00
|
|
|
if ((! is_array(self::$available_apps)) || (! count(self::$available_apps))) {
|
2016-06-02 23:38:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-06-02 23:45:00 +00:00
|
|
|
$notfound = true;
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach (self::$available_apps as $iapp) {
|
|
|
|
if ($iapp['app_id'] == hash('whirlpool',$app['name'])) {
|
2016-06-02 23:45:00 +00:00
|
|
|
$notfound = false;
|
2021-11-11 20:18:12 +00:00
|
|
|
if ((isset($app['version']) && $iapp['app_version'] !== $app['version'])
|
2021-03-09 01:51:41 +00:00
|
|
|
|| ((isset($app['plugin']) && $app['plugin']) && (! (isset($iapp['app_plugin']) && $iapp['app_plugin'])))) {
|
2016-06-03 00:08:47 +00:00
|
|
|
return intval($iapp['app_id']);
|
2016-06-02 23:45:00 +00:00
|
|
|
}
|
2018-07-27 20:59:27 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (($iapp['app_url'] !== $app['url'])
|
2018-07-27 20:59:27 +00:00
|
|
|
|| ($iapp['app_photo'] !== $app['photo'])) {
|
|
|
|
return intval($iapp['app_id']);
|
|
|
|
}
|
2016-06-02 23:38:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-13 21:22:36 +00:00
|
|
|
|
2016-06-02 23:45:00 +00:00
|
|
|
return $notfound;
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-05 05:56:43 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
2018-07-06 05:27:44 +00:00
|
|
|
$installed = false;
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach (self::$installed_apps as $iapp) {
|
|
|
|
if ($iapp['app_id'] == hash('whirlpool',$app['name'])) {
|
2018-07-06 05:27:44 +00:00
|
|
|
$installed = true;
|
2019-05-23 23:37:56 +00:00
|
|
|
if (($iapp['app_version'] != $app['version'])
|
2021-03-09 01:51:41 +00:00
|
|
|
|| (isset($app['plugin']) && $app['plugin'] && (! (isset($iapp['app_plugin']) && $iapp['app_plugin'])))) {
|
2018-07-05 05:56:43 +00:00
|
|
|
return intval($iapp['app_id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $installed && in_array($app['name'],self::$base_apps)) {
|
2018-07-05 05:56:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
static public function app_name_compare($a,$b) {
|
2016-08-30 01:06:39 +00:00
|
|
|
return strcasecmp($a['name'],$b['name']);
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public function parse_app_description($f,$translate = true) {
|
2018-02-14 23:32:33 +00:00
|
|
|
|
2021-03-15 05:10:44 +00:00
|
|
|
$ret = [];
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$baseurl = z_root();
|
2019-05-23 23:37:56 +00:00
|
|
|
$channel = App::get_channel();
|
2016-05-23 02:26:21 +00:00
|
|
|
$address = (($channel) ? $channel['channel_address'] : '');
|
|
|
|
|
|
|
|
//future expansion
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
$observer = App::get_observer();
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
$lines = @file($f);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($lines) {
|
|
|
|
foreach ($lines as $x) {
|
|
|
|
if (preg_match('/^([a-zA-Z].*?):(.*?)$/ism',$x,$matches)) {
|
2018-07-27 20:59:27 +00:00
|
|
|
$ret[$matches[1]] = trim($matches[2]);
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $ret['photo']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['photo'] = $baseurl . '/' . get_default_profile_photo(80);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$ret['type'] = 'system';
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($ret as $k => $v) {
|
|
|
|
if (strpos($v,'http') === 0) {
|
|
|
|
if (! (local_channel() && strpos($v,z_root()) === 0)) {
|
2017-02-06 22:10:54 +00:00
|
|
|
$ret[$k] = zid($v);
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (array_key_exists('desc',$ret)) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['desc']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if (array_key_exists('target',$ret)) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['target'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['target']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if (array_key_exists('version',$ret)) {
|
2016-06-02 23:38:15 +00:00
|
|
|
$ret['version'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['version']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if (array_key_exists('categories',$ret)) {
|
2017-02-02 22:49:51 +00:00
|
|
|
$ret['categories'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['categories']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if (array_key_exists('requires',$ret)) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$requires = explode(',',$ret['requires']);
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($requires as $require) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$require = trim(strtolower($require));
|
2017-08-01 01:38:41 +00:00
|
|
|
$config = false;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (substr($require, 0, 7) == 'config:') {
|
2017-08-01 01:38:41 +00:00
|
|
|
$config = true;
|
|
|
|
$require = ltrim($require, 'config:');
|
2017-08-06 21:20:24 +00:00
|
|
|
$require = explode('=', $require);
|
2017-08-01 01:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
switch ($require) {
|
2016-05-23 02:26:21 +00:00
|
|
|
case 'nologin':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (local_channel()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
case 'admin':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! is_site_admin()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
case 'local_channel':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! local_channel()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
case 'public_profile':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! is_public_profile()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
2018-02-14 23:32:33 +00:00
|
|
|
case 'public_stream':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! can_view_public_stream()) {
|
2018-02-14 23:32:33 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-02-14 23:32:33 +00:00
|
|
|
break;
|
2018-10-05 03:29:41 +00:00
|
|
|
case 'custom_role':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (get_pconfig(local_channel(),'system','permissions_role') !== 'custom') {
|
2018-10-05 03:29:41 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-10-05 03:29:41 +00:00
|
|
|
break;
|
2016-05-23 02:26:21 +00:00
|
|
|
case 'observer':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $observer) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($config) {
|
2017-08-06 21:20:24 +00:00
|
|
|
$unset = ((get_config('system', $require[0]) == $require[1]) ? false : true);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-08-01 01:38:41 +00:00
|
|
|
$unset = ((local_channel() && feature_enabled(local_channel(),$require)) ? false : true);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if ($unset) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($ret)) {
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($translate) {
|
2016-05-23 02:26:21 +00:00
|
|
|
self::translate_system_apps($ret);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public function translate_system_apps(&$arr) {
|
|
|
|
$apps = array(
|
2020-11-30 00:38:45 +00:00
|
|
|
'Admin' => t('Site Admin'),
|
2017-05-23 08:18:34 +00:00
|
|
|
'Apps' => t('Apps'),
|
2018-01-16 05:46:27 +00:00
|
|
|
'Articles' => t('Articles'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'CalDAV' => t('CalDAV'),
|
|
|
|
'CardDAV' => t('CardDAV'),
|
2017-08-23 07:01:02 +00:00
|
|
|
'Cards' => t('Cards'),
|
2019-05-13 01:20:37 +00:00
|
|
|
'Calendar' => t('Calendar'),
|
2019-03-25 03:18:13 +00:00
|
|
|
'Categories' => t('Categories'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Channel Home' => t('Channel Home'),
|
|
|
|
'Channel Manager' => t('Channel Manager'),
|
|
|
|
'Channel Sources' => t('Channel Sources'),
|
|
|
|
'Chat' => t('Chat'),
|
|
|
|
'Chatrooms' => t('Chatrooms'),
|
2019-10-10 05:51:48 +00:00
|
|
|
'Clients' => t('Clients'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Comment Control' => t('Comment Control'),
|
|
|
|
'Connections' => t('Connections'),
|
2019-01-23 03:11:53 +00:00
|
|
|
'Content Filter' => t('Content Filter'),
|
2019-03-08 04:13:33 +00:00
|
|
|
'Content Import' => t('Content Import'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Directory' => t('Directory'),
|
|
|
|
'Drafts' => t('Drafts'),
|
|
|
|
'Events' => t('Events'),
|
2019-03-25 05:46:31 +00:00
|
|
|
'Expire Posts' => t('Expire Posts'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Features' => t('Features'),
|
2016-05-23 02:26:21 +00:00
|
|
|
'Files' => t('Files'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Followlist' => t('Followlist'),
|
|
|
|
'Friend Zoom' => t('Friend Zoom'),
|
|
|
|
'Future Posting' => t('Future Posting'),
|
|
|
|
'Gallery' => t('Gallery'),
|
2021-04-11 06:39:04 +00:00
|
|
|
'Guest Pass' => t('Guest Pass'),
|
2016-05-23 02:26:21 +00:00
|
|
|
'Help' => t('Help'),
|
|
|
|
'Invite' => t('Invite'),
|
|
|
|
'Language' => t('Language'),
|
2019-10-02 00:44:58 +00:00
|
|
|
'Lists' => t('Lists'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Login' => t('Login'),
|
|
|
|
'Mail' => t('Mail'),
|
|
|
|
'Markup' => t('Markup'),
|
|
|
|
'Mood' => t('Mood'),
|
2020-11-30 00:42:30 +00:00
|
|
|
'My Chatrooms' => t('My Chatrooms'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'No Comment' => t('No Comment'),
|
2018-10-05 03:29:41 +00:00
|
|
|
'Notes' => t('Notes'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Notifications' => t('Notifications'),
|
2018-10-05 03:29:41 +00:00
|
|
|
'OAuth Apps Manager' => t('OAuth Apps Manager'),
|
|
|
|
'OAuth2 Apps Manager' => t('OAuth2 Apps Manager'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Order Apps' => t('Order Apps'),
|
2018-10-05 03:29:41 +00:00
|
|
|
'PDL Editor' => t('PDL Editor'),
|
|
|
|
'Permission Categories' => t('Permission Categories'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Photos' => t('Photos'),
|
|
|
|
'Photomap' => t('Photomap'),
|
|
|
|
'Poke' => t('Poke'),
|
|
|
|
'Post' => t('Post'),
|
2018-10-05 03:29:41 +00:00
|
|
|
'Premium Channel' => t('Premium Channel'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Probe' => t('Probe'),
|
|
|
|
'Profile' => t('Profile'),
|
|
|
|
'Profile Photo' => t('Profile Photo'),
|
|
|
|
'Profiles' => t('Profiles'),
|
2018-10-05 03:29:41 +00:00
|
|
|
'Public Stream' => t('Public Stream'),
|
2020-11-30 00:38:45 +00:00
|
|
|
'Random Channel' => t('Random Channel'),
|
|
|
|
'Remote Diagnostics' => t('Remote Diagnostics'),
|
|
|
|
'Report Bug' => t('Report Bug'),
|
|
|
|
'Search' => t('Search'),
|
|
|
|
'Secrets' => t('Secrets'),
|
|
|
|
'Settings' => t('Settings'),
|
|
|
|
'Sites' => t('Sites'),
|
|
|
|
'Stream' => t('Stream'),
|
|
|
|
'Stream Order' => t('Stream Order'),
|
|
|
|
'Suggest' => t('Suggest'),
|
|
|
|
'Suggest Channels' => t('Suggest Channels'),
|
|
|
|
'Tagadelic' => t('Tagadelic'),
|
|
|
|
'Tasks' => t('Tasks'),
|
|
|
|
'View Bookmarks' => t('View Bookmarks'),
|
|
|
|
'View Profile' => t('View Profile'),
|
|
|
|
'Virtual Lists' => t('Virtual Lists'),
|
|
|
|
'Webpages' => t('Webpages'),
|
|
|
|
'Wiki' => t('Wiki'),
|
|
|
|
'ZotPost' => t('ZotPost'),
|
2016-05-23 02:26:21 +00:00
|
|
|
);
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (array_key_exists('name',$arr)) {
|
|
|
|
if (array_key_exists($arr['name'],$apps)) {
|
2017-04-03 00:34:16 +00:00
|
|
|
$arr['name'] = $apps[$arr['name']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-05-23 23:37:56 +00:00
|
|
|
for ($x = 0; $x < count($arr); $x++) {
|
|
|
|
if (array_key_exists($arr[$x]['name'],$apps)) {
|
2017-04-03 00:34:16 +00:00
|
|
|
$arr[$x]['name'] = $apps[$arr[$x]['name']];
|
|
|
|
}
|
2018-10-05 03:29:41 +00:00
|
|
|
else {
|
|
|
|
// Try to guess by app name if not in list
|
|
|
|
$arr[$x]['name'] = t(trim($arr[$x]['name']));
|
|
|
|
}
|
2017-04-03 00:34:16 +00:00
|
|
|
}
|
2016-12-15 03:11:01 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// papp is a portable app
|
|
|
|
|
|
|
|
static public 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
|
2018-07-05 05:56:43 +00:00
|
|
|
* install: like view but does not display app-bin options if they are present
|
2016-05-23 02:26:21 +00:00
|
|
|
* 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
|
2017-02-08 10:17:09 +00:00
|
|
|
* nav: render apps for app-bin
|
2016-05-23 02:26:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
$installed = false;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $papp) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $papp['photo']) {
|
2018-07-05 05:56:43 +00:00
|
|
|
$papp['photo'] = 'icon:gear';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2016-06-15 23:24:45 +00:00
|
|
|
self::translate_system_apps($papp);
|
|
|
|
|
2021-03-11 03:30:25 +00:00
|
|
|
if (isset($papp['plugin']) && trim($papp['plugin']) && (! addon_is_installed(trim($papp['plugin'])))) {
|
2016-12-15 03:11:01 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-12-15 03:11:01 +00:00
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
$papp['papp'] = self::papp_encode($papp);
|
|
|
|
|
2018-07-27 20:59:27 +00:00
|
|
|
// This will catch somebody clicking on a system "available" app that hasn't had the path macros replaced
|
|
|
|
// and they are allowed to see the app
|
|
|
|
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (strpos($papp['url'],'$baseurl') !== false || strpos($papp['url'],'$nick') !== false || strpos($papp['photo'],'$baseurl') !== false || strpos($papp['photo'],'$nick') !== false) {
|
2018-07-27 20:59:27 +00:00
|
|
|
$view_channel = local_channel();
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $view_channel) {
|
2018-07-27 20:59:27 +00:00
|
|
|
$sys = get_sys_channel();
|
|
|
|
$view_channel = $sys['channel_id'];
|
|
|
|
}
|
|
|
|
self::app_macros($view_channel,$papp);
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (strpos($papp['url'], ',')) {
|
2018-10-05 03:29:41 +00:00
|
|
|
$urls = explode(',', $papp['url']);
|
|
|
|
$papp['url'] = trim($urls[0]);
|
|
|
|
$papp['settings_url'] = trim($urls[1]);
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! strstr($papp['url'],'://')) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$papp['url'] = z_root() . ((strpos($papp['url'],'/') === 0) ? '' : '/') . $papp['url'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2018-07-27 20:59:27 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($papp as $k => $v) {
|
|
|
|
if (strpos($v,'http') === 0 && $k != 'papp') {
|
|
|
|
if (! (local_channel() && strpos($v,z_root()) === 0)) {
|
2017-02-06 22:10:54 +00:00
|
|
|
$papp[$k] = zid($v);
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($k === 'desc') {
|
2016-05-23 02:26:21 +00:00
|
|
|
$papp['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$papp['desc']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($k === 'requires') {
|
2016-05-23 02:26:21 +00:00
|
|
|
$requires = explode(',',$v);
|
2017-08-01 01:38:41 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($requires as $require) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$require = trim(strtolower($require));
|
2017-08-01 01:38:41 +00:00
|
|
|
$config = false;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (substr($require, 0, 7) == 'config:') {
|
2017-08-01 01:38:41 +00:00
|
|
|
$config = true;
|
|
|
|
$require = ltrim($require, 'config:');
|
2017-08-06 21:20:24 +00:00
|
|
|
$require = explode('=', $require);
|
2017-08-01 01:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
switch ($require) {
|
2016-05-23 02:26:21 +00:00
|
|
|
case 'nologin':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (local_channel()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
case 'admin':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! is_site_admin()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
case 'local_channel':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! local_channel()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
case 'public_profile':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! is_public_profile()) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
2018-02-14 23:32:33 +00:00
|
|
|
case 'public_stream':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! can_view_public_stream()) {
|
2018-02-14 23:32:33 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-02-14 23:32:33 +00:00
|
|
|
break;
|
2018-10-05 03:29:41 +00:00
|
|
|
case 'custom_role':
|
2019-05-23 23:37:56 +00:00
|
|
|
if (get_pconfig(local_channel(),'system','permissions_role') != 'custom') {
|
2018-10-05 03:29:41 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-10-05 03:29:41 +00:00
|
|
|
break;
|
2016-05-23 02:26:21 +00:00
|
|
|
case 'observer':
|
2019-05-23 23:37:56 +00:00
|
|
|
$observer = App::get_observer();
|
|
|
|
if (! $observer) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($config) {
|
2017-12-03 11:31:41 +00:00
|
|
|
$unset = ((get_config('system', $require[0]) === $require[1]) ? false : true);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-08-01 01:38:41 +00:00
|
|
|
$unset = ((local_channel() && feature_enabled(local_channel(),$require)) ? false : true);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if ($unset) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return '';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$hosturl = '';
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (local_channel()) {
|
2021-03-11 03:30:25 +00:00
|
|
|
if (self::app_installed(local_channel(),$papp) && (! (isset($papp['deleted']) && intval($papp['deleted'])))) {
|
2018-10-05 03:29:41 +00:00
|
|
|
$installed = true;
|
2021-11-11 03:51:04 +00:00
|
|
|
if ($mode === 'install') {
|
|
|
|
return '';
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-10-05 03:29:41 +00:00
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
$hosturl = z_root() . '/';
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
elseif (remote_channel()) {
|
|
|
|
$observer = App::get_observer();
|
|
|
|
if ($observer && $observer['xchan_network'] === 'zot6') {
|
2016-05-23 02:26:21 +00:00
|
|
|
// some folks might have xchan_url redirected offsite, use the connurl
|
|
|
|
$x = parse_url($observer['xchan_connurl']);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$hosturl = $x['scheme'] . '://' . $x['host'] . '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 03:51:04 +00:00
|
|
|
$install_action = (($installed) ? t('Installed') : t('Install'));
|
2017-02-06 19:10:10 +00:00
|
|
|
$icon = ((strpos($papp['photo'],'icon:') === 0) ? substr($papp['photo'],5) : '');
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($mode === 'navbar') {
|
|
|
|
return replace_macros(get_markup_template('app_nav.tpl'), [
|
2017-10-09 02:43:03 +00:00
|
|
|
'$app' => $papp,
|
|
|
|
'$icon' => $icon,
|
2019-05-23 23:37:56 +00:00
|
|
|
]);
|
2017-10-09 02:43:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($mode === 'install') {
|
2018-07-05 05:56:43 +00:00
|
|
|
$papp['embed'] = true;
|
|
|
|
}
|
2021-09-12 21:09:11 +00:00
|
|
|
|
|
|
|
$featured = $pinned = false;
|
|
|
|
if (isset($papp['categories'])) {
|
|
|
|
$featured = ((strpos($papp['categories'],'nav_featured_app') !== false) ? true : false);
|
|
|
|
$pinned = ((strpos($papp['categories'],'nav_pinned_app') !== false) ? true : false);
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
return replace_macros(get_markup_template('app.tpl'), [
|
2016-05-23 02:26:21 +00:00
|
|
|
'$app' => $papp,
|
2017-02-06 19:10:10 +00:00
|
|
|
'$icon' => $icon,
|
2016-05-23 02:26:21 +00:00
|
|
|
'$hosturl' => $hosturl,
|
2021-03-11 03:30:25 +00:00
|
|
|
'$purchase' => ((isset($papp['page']) && $papp['page'] && (! $installed)) ? t('Purchase') : ''),
|
2018-09-07 08:39:15 +00:00
|
|
|
'$installed' => $installed,
|
|
|
|
'$action_label' => (($hosturl && in_array($mode, ['view','install'])) ? $install_action : ''),
|
2018-10-05 03:29:41 +00:00
|
|
|
'$edit' => ((local_channel() && $installed && $mode === 'edit') ? t('Edit') : ''),
|
|
|
|
'$delete' => ((local_channel() && $installed && $mode === 'edit') ? t('Delete') : ''),
|
|
|
|
'$undelete' => ((local_channel() && $installed && $mode === 'edit') ? t('Undelete') : ''),
|
2021-11-11 20:18:12 +00:00
|
|
|
'$settings_url' => ((local_channel() && $installed && $mode === 'list' && isset($papp['settings_url'])) ? $papp['settings_url'] : ''),
|
2021-03-11 03:46:10 +00:00
|
|
|
'$deleted' => ((isset($papp['deleted'])) ? intval($papp['deleted']) : false),
|
2021-03-11 03:30:25 +00:00
|
|
|
'$feature' => (((isset($papp['embed']) && $papp['embed']) || $mode === 'edit') ? false : true),
|
|
|
|
'$pin' => (((isset($papp['embed']) && $papp['embed']) || $mode === 'edit') ? false : true),
|
2021-09-12 21:09:11 +00:00
|
|
|
'$featured' => $featured,
|
|
|
|
'$pinned' => $pinned,
|
2018-10-05 03:29:41 +00:00
|
|
|
'$navapps' => (($mode === 'nav') ? true : false),
|
2019-10-03 04:38:32 +00:00
|
|
|
'$order' => (($mode === 'nav-order' || $mode === 'nav-order-pinned') ? true : false),
|
|
|
|
'$mode' => $mode,
|
2017-02-22 10:22:43 +00:00
|
|
|
'$add' => t('Add to app-tray'),
|
2017-11-16 10:11:06 +00:00
|
|
|
'$remove' => t('Remove from app-tray'),
|
2017-11-16 20:42:39 +00:00
|
|
|
'$add_nav' => t('Pin to navbar'),
|
|
|
|
'$remove_nav' => t('Unpin from navbar')
|
2019-05-23 23:37:56 +00:00
|
|
|
]);
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static public function app_install($uid,$app) {
|
2018-07-06 05:27:44 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! is_array($app)) {
|
2018-10-05 03:29:41 +00:00
|
|
|
$r = q("select * from app where app_name = '%s' and app_channel = 0",
|
|
|
|
dbesc($app)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $r) {
|
2018-10-05 03:29:41 +00:00
|
|
|
return false;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-10-05 03:29:41 +00:00
|
|
|
|
|
|
|
$app = self::app_encode($r[0]);
|
|
|
|
}
|
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
$app['uid'] = $uid;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (self::app_installed($uid,$app,true)) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$x = self::app_update($app);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-05-23 02:26:21 +00:00
|
|
|
$x = self::app_store($app);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x['success']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
|
|
|
dbesc($x['app_id']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($r) {
|
|
|
|
if (($app['uid']) && (! $r[0]['app_system'])) {
|
|
|
|
if ($app['categories'] && (! $app['term'])) {
|
2016-12-15 03:11:01 +00:00
|
|
|
$r[0]['term'] = q("select * from term where otype = %d and oid = %d",
|
2016-05-23 02:26:21 +00:00
|
|
|
intval(TERM_OBJ_APP),
|
|
|
|
intval($r[0]['id'])
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if (intval($r[0]['app_system'])) {
|
2019-03-22 04:57:43 +00:00
|
|
|
Libsync::build_sync_packet($uid,array('sysapp' => $r[0]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Libsync::build_sync_packet($uid,array('app' => $r[0]));
|
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $x['app_id'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 21:36:06 +00:00
|
|
|
static public function can_delete($uid,$app) {
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $uid) {
|
2018-07-27 21:36:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$base_apps = self::get_base_apps();
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($base_apps) {
|
|
|
|
foreach ($base_apps as $b) {
|
|
|
|
if ($app['guid'] === hash('whirlpool',$b)) {
|
2018-07-27 21:36:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
|
2018-07-27 21:36:06 +00:00
|
|
|
static public function app_destroy($uid,$app) {
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($uid && $app['guid']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
|
|
|
dbesc($app['guid']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
|
|
|
if (! intval($x[0]['app_deleted'])) {
|
2016-12-15 03:11:01 +00:00
|
|
|
$x[0]['app_deleted'] = 1;
|
2019-05-23 23:37:56 +00:00
|
|
|
if (self::can_delete($uid,$app)) {
|
2016-12-15 03:11:01 +00:00
|
|
|
$r = q("delete from app where app_id = '%s' and app_channel = %d",
|
|
|
|
dbesc($app['guid']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2018-07-27 21:36:06 +00:00
|
|
|
q("delete from term where otype = %d and oid = %d",
|
|
|
|
intval(TERM_OBJ_APP),
|
|
|
|
intval($x[0]['id'])
|
|
|
|
);
|
2018-10-05 03:29:41 +00:00
|
|
|
call_hooks('app_destroy',$x[0]);
|
2018-07-27 21:36:06 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
|
|
|
|
dbesc($app['guid']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2018-07-12 23:23:32 +00:00
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
if (intval($x[0]['app_system'])) {
|
2019-03-22 04:57:43 +00:00
|
|
|
Libsync::build_sync_packet($uid,array('sysapp' => $x));
|
|
|
|
}
|
|
|
|
else {
|
2018-06-05 01:40:11 +00:00
|
|
|
Libsync::build_sync_packet($uid,array('app' => $x));
|
2016-12-15 03:11:01 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-12-15 03:11:01 +00:00
|
|
|
self::app_undestroy($uid,$app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 21:36:06 +00:00
|
|
|
|
2016-12-15 03:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static public function app_undestroy($uid,$app) {
|
|
|
|
|
|
|
|
// undelete a system app
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($uid && $app['guid']) {
|
2016-12-15 03:11:01 +00:00
|
|
|
|
|
|
|
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
|
|
|
dbesc($app['guid']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
|
|
|
if ($x[0]['app_system']) {
|
2016-12-15 03:11:01 +00:00
|
|
|
$r = q("update app set app_deleted = 0 where app_id = '%s' and app_channel = %d",
|
2016-05-23 02:26:21 +00:00
|
|
|
dbesc($app['guid']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 10:11:06 +00:00
|
|
|
static public function app_feature($uid,$app,$term) {
|
2017-01-30 14:17:46 +00:00
|
|
|
$r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
|
|
|
dbesc($app['guid']),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2017-11-16 10:11:06 +00:00
|
|
|
$x = q("select * from term where otype = %d and oid = %d and term = '%s' limit 1",
|
2017-01-30 14:17:46 +00:00
|
|
|
intval(TERM_OBJ_APP),
|
2017-11-16 10:11:06 +00:00
|
|
|
intval($r[0]['id']),
|
|
|
|
dbesc($term)
|
2017-01-30 14:17:46 +00:00
|
|
|
);
|
2016-12-15 03:11:01 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
2017-11-16 10:11:06 +00:00
|
|
|
q("delete from term where otype = %d and oid = %d and term = '%s'",
|
2017-01-30 14:17:46 +00:00
|
|
|
intval(TERM_OBJ_APP),
|
2017-11-16 10:11:06 +00:00
|
|
|
intval($x[0]['oid']),
|
|
|
|
dbesc($term)
|
2017-01-30 14:17:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2017-11-16 10:11:06 +00:00
|
|
|
store_item_tag($uid, $r[0]['id'], TERM_OBJ_APP, TERM_CATEGORY, $term, escape_tags(z_root() . '/apps/?f=&cat=' . $term));
|
2017-01-30 14:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 03:11:01 +00:00
|
|
|
|
2018-10-05 03:29:41 +00:00
|
|
|
static public function app_installed($uid,$app,$bypass_filter = false) {
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2017-01-23 19:36:28 +00:00
|
|
|
$r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
2016-05-23 02:26:21 +00:00
|
|
|
dbesc((array_key_exists('guid',$app)) ? $app['guid'] : ''),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $bypass_filter) {
|
2018-10-05 03:29:41 +00:00
|
|
|
$filter_arr = [
|
|
|
|
'uid'=>$uid,
|
|
|
|
'app'=>$app,
|
|
|
|
'installed'=>$r
|
|
|
|
];
|
|
|
|
call_hooks('app_installed_filter',$filter_arr);
|
|
|
|
$r = $filter_arr['installed'];
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
return (($r) ? true : false);
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-05 03:29:41 +00:00
|
|
|
static public function addon_app_installed($uid,$app,$bypass_filter = false) {
|
2018-07-06 00:52:32 +00:00
|
|
|
|
|
|
|
$r = q("select id from app where app_plugin = '%s' and app_channel = %d limit 1",
|
|
|
|
dbesc($app),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $bypass_filter) {
|
2018-10-05 03:29:41 +00:00
|
|
|
$filter_arr = [
|
|
|
|
'uid'=>$uid,
|
|
|
|
'app'=>$app,
|
|
|
|
'installed'=>$r
|
|
|
|
];
|
|
|
|
call_hooks('addon_app_installed_filter',$filter_arr);
|
|
|
|
$r = $filter_arr['installed'];
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
return (($r) ? true : false);
|
2018-07-06 00:52:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-05 03:29:41 +00:00
|
|
|
static public function system_app_installed($uid,$app,$bypass_filter = false) {
|
2018-08-23 00:52:22 +00:00
|
|
|
|
2019-05-03 09:27:20 +00:00
|
|
|
$r = q("select id from app where app_id = '%s' and app_channel = %d and app_deleted = 0 limit 1",
|
2018-07-16 01:31:39 +00:00
|
|
|
dbesc(hash('whirlpool',$app)),
|
|
|
|
intval($uid)
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $bypass_filter) {
|
2018-10-05 03:29:41 +00:00
|
|
|
$filter_arr = [
|
|
|
|
'uid'=>$uid,
|
|
|
|
'app'=>$app,
|
|
|
|
'installed'=>$r
|
|
|
|
];
|
|
|
|
call_hooks('system_app_installed_filter',$filter_arr);
|
|
|
|
$r = $filter_arr['installed'];
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
return (($r) ? true : false);
|
2018-07-16 01:31:39 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2017-11-16 10:11:06 +00:00
|
|
|
static public function app_list($uid, $deleted = false, $cats = []) {
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($deleted) {
|
2016-12-15 03:11:01 +00:00
|
|
|
$sql_extra = "";
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-05-23 02:26:21 +00:00
|
|
|
$sql_extra = " and app_deleted = 0 ";
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
if ($cats) {
|
2017-11-16 10:11:06 +00:00
|
|
|
|
|
|
|
$cat_sql_extra = " and ( ";
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($cats as $cat) {
|
|
|
|
if (strpos($cat_sql_extra, 'term'))
|
2017-11-16 10:11:06 +00:00
|
|
|
$cat_sql_extra .= "or ";
|
|
|
|
|
|
|
|
$cat_sql_extra .= "term = '" . dbesc($cat) . "' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
$cat_sql_extra .= ") ";
|
|
|
|
|
|
|
|
$r = q("select oid from term where otype = %d $cat_sql_extra",
|
|
|
|
intval(TERM_OBJ_APP)
|
2016-05-23 02:26:21 +00:00
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $r) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return $r;
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
$sql_extra .= " and app.id in ( " . array_elm_to_str($r,'oid') . ') ';
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$r = q("select * from app where app_channel = %d $sql_extra order by app_name asc",
|
|
|
|
intval($uid)
|
|
|
|
);
|
2017-02-06 09:49:42 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($r) {
|
2018-12-29 23:40:07 +00:00
|
|
|
$hookinfo = [ 'uid' => $uid, 'deleted' => $deleted, 'cats' => $cats, 'apps' => $r ];
|
2018-09-17 03:01:17 +00:00
|
|
|
call_hooks('app_list',$hookinfo);
|
|
|
|
$r = $hookinfo['apps'];
|
2019-05-23 23:37:56 +00:00
|
|
|
for ($x = 0; $x < count($r); $x ++) {
|
|
|
|
if (! $r[$x]['app_system']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$r[$x]['type'] = 'personal';
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
$r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
|
|
|
|
intval(TERM_OBJ_APP),
|
|
|
|
intval($r[$x]['id'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-02-03 11:12:05 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
return ($r);
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 23:42:32 +00:00
|
|
|
|
|
|
|
static public function app_search_available($str) {
|
|
|
|
|
|
|
|
// not yet finished
|
|
|
|
// somehow need to account for translations
|
|
|
|
|
|
|
|
$r = q("select * from app where app_channel = 0 $sql_extra order by app_name asc",
|
|
|
|
intval($uid)
|
|
|
|
);
|
|
|
|
|
|
|
|
return ($r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
static public function app_order($uid,$apps,$menu) {
|
2017-05-17 05:57:34 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $apps)
|
2017-05-17 05:57:34 +00:00
|
|
|
return $apps;
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
$conf = (($menu === 'nav_featured_app') ? 'app_order' : 'app_pin_order');
|
|
|
|
|
|
|
|
$x = (($uid) ? get_pconfig($uid,'system',$conf) : get_config('system',$conf));
|
2019-05-23 23:37:56 +00:00
|
|
|
if (($x) && (! is_array($x))) {
|
2017-05-17 05:57:34 +00:00
|
|
|
$y = explode(',',$x);
|
|
|
|
$y = array_map('trim',$y);
|
|
|
|
$x = $y;
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! (is_array($x) && ($x))) {
|
2017-05-17 05:57:34 +00:00
|
|
|
return $apps;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2017-05-17 05:57:34 +00:00
|
|
|
|
|
|
|
$ret = [];
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($x as $xx) {
|
2017-05-17 05:57:34 +00:00
|
|
|
$y = self::find_app_in_array($xx,$apps);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($y) {
|
2017-05-17 05:57:34 +00:00
|
|
|
$ret[] = $y;
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($apps as $ap) {
|
|
|
|
if (! self::find_app_in_array($ap['name'],$ret)) {
|
2017-05-17 05:57:34 +00:00
|
|
|
$ret[] = $ap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static function find_app_in_array($name,$arr) {
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $arr) {
|
2017-05-17 05:57:34 +00:00
|
|
|
return false;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
|
|
|
foreach ($arr as $x) {
|
|
|
|
if ($x['name'] === $name) {
|
|
|
|
return $x;
|
2017-05-17 05:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
static function moveup($uid,$guid,$menu) {
|
2019-05-23 23:37:56 +00:00
|
|
|
$syslist = [];
|
2018-12-13 03:04:14 +00:00
|
|
|
|
|
|
|
$conf = (($menu === 'nav_featured_app') ? 'app_order' : 'app_pin_order');
|
|
|
|
|
|
|
|
$list = self::app_list($uid, false, [ $menu ]);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($list) {
|
|
|
|
foreach ($list as $li) {
|
2018-12-13 03:04:14 +00:00
|
|
|
$papp = self::app_encode($li);
|
|
|
|
$syslist[] = $papp;
|
2017-05-22 05:23:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
self::translate_system_apps($syslist);
|
|
|
|
|
|
|
|
usort($syslist,'self::app_name_compare');
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
$syslist = self::app_order($uid,$syslist,$menu);
|
2017-05-22 05:23:36 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $syslist) {
|
2017-05-22 05:23:36 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2017-05-22 05:23:36 +00:00
|
|
|
|
|
|
|
$newlist = [];
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($syslist as $k => $li) {
|
|
|
|
if ($li['guid'] === $guid) {
|
2017-05-22 05:23:36 +00:00
|
|
|
$position = $k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $position) {
|
2017-05-22 05:23:36 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2017-05-22 05:23:36 +00:00
|
|
|
$dest_position = $position - 1;
|
|
|
|
$saved = $syslist[$dest_position];
|
|
|
|
$syslist[$dest_position] = $syslist[$position];
|
|
|
|
$syslist[$position] = $saved;
|
|
|
|
|
|
|
|
$narr = [];
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($syslist as $x) {
|
2017-05-22 05:23:36 +00:00
|
|
|
$narr[] = $x['name'];
|
|
|
|
}
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
set_pconfig($uid,'system',$conf,implode(',',$narr));
|
2017-05-22 05:23:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
static function movedown($uid,$guid,$menu) {
|
2021-03-15 05:10:44 +00:00
|
|
|
$syslist = [];
|
2018-12-13 03:04:14 +00:00
|
|
|
|
|
|
|
$conf = (($menu === 'nav_featured_app') ? 'app_order' : 'app_pin_order');
|
|
|
|
|
|
|
|
$list = self::app_list($uid, false, [ $menu ]);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($list) {
|
|
|
|
foreach ($list as $li) {
|
2018-12-13 03:04:14 +00:00
|
|
|
$papp = self::app_encode($li);
|
|
|
|
$syslist[] = $papp;
|
2017-05-22 05:23:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
self::translate_system_apps($syslist);
|
|
|
|
|
|
|
|
usort($syslist,'self::app_name_compare');
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
$syslist = self::app_order($uid,$syslist,$menu);
|
2017-05-22 05:23:36 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $syslist) {
|
2017-05-22 05:23:36 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2017-05-22 05:23:36 +00:00
|
|
|
|
|
|
|
$newlist = [];
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($syslist as $k => $li) {
|
|
|
|
if ($li['guid'] === $guid) {
|
2017-05-22 05:23:36 +00:00
|
|
|
$position = $k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($position >= count($syslist) - 1) {
|
2017-05-22 05:23:36 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2017-05-22 05:23:36 +00:00
|
|
|
$dest_position = $position + 1;
|
|
|
|
$saved = $syslist[$dest_position];
|
|
|
|
$syslist[$dest_position] = $syslist[$position];
|
|
|
|
$syslist[$position] = $saved;
|
|
|
|
|
|
|
|
$narr = [];
|
2019-05-23 23:37:56 +00:00
|
|
|
foreach ($syslist as $x) {
|
2017-05-22 05:23:36 +00:00
|
|
|
$narr[] = $x['name'];
|
|
|
|
}
|
|
|
|
|
2018-12-13 03:04:14 +00:00
|
|
|
set_pconfig($uid,'system',$conf,implode(',',$narr));
|
2017-05-22 05:23:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
static public function app_decode($s) {
|
2019-11-21 10:32:22 +00:00
|
|
|
$x = base64_decode(str_replace(array('<br>',"\r","\n",' '),array('','','',''),$s));
|
2016-05-23 02:26:21 +00:00
|
|
|
return json_decode($x,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:59:27 +00:00
|
|
|
static public function app_macros($uid,&$arr) {
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! intval($uid)) {
|
2018-07-27 20:59:27 +00:00
|
|
|
return;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2018-07-27 20:59:27 +00:00
|
|
|
|
|
|
|
$baseurl = z_root();
|
|
|
|
$channel = channelx_by_n($uid);
|
|
|
|
$address = (($channel) ? $channel['channel_address'] : '');
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
// future expansion
|
2018-07-27 20:59:27 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
$observer = App::get_observer();
|
2018-07-27 20:59:27 +00:00
|
|
|
|
|
|
|
$arr['url'] = str_replace(array('$baseurl','$nick'),array($baseurl,$address),$arr['url']);
|
|
|
|
$arr['photo'] = str_replace(array('$baseurl','$nick'),array($baseurl,$address),$arr['photo']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
static public function app_store($arr) {
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
// logger('app_store: ' . print_r($arr,true));
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
$darray = [];
|
|
|
|
$ret = [ 'success' => false ];
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2018-07-05 05:56:43 +00:00
|
|
|
$sys = get_sys_channel();
|
|
|
|
|
2018-07-27 20:59:27 +00:00
|
|
|
self::app_macros($arr['uid'],$arr);
|
2018-07-05 05:56:43 +00:00
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
$darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : '');
|
|
|
|
$darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0);
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $darray['app_url']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return $ret;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ((! $arr['uid']) && (! $arr['author'])) {
|
2018-07-05 05:56:43 +00:00
|
|
|
$arr['author'] = $sys['channel_hash'];
|
|
|
|
}
|
|
|
|
|
2020-05-04 23:43:15 +00:00
|
|
|
if ($arr['photo'] && (strpos($arr['photo'],'icon:') === false) && (strpos($arr['photo'],z_root()) === false)) {
|
2020-08-25 04:36:56 +00:00
|
|
|
$x = import_remote_xchan_photo(str_replace('$baseurl',z_root(),$arr['photo']),get_observer_hash(),true);
|
2020-08-25 09:28:59 +00:00
|
|
|
if ((! $x) || ($x[4])) {
|
2020-05-04 23:43:15 +00:00
|
|
|
// $x[4] = true indicates storage failure of our cached/resized copy. If this failed, just keep the original url.
|
|
|
|
$arr['photo'] = $x[1];
|
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . \App::get_hostname());
|
|
|
|
$darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : '');
|
|
|
|
$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_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : '');
|
|
|
|
$darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80));
|
|
|
|
$darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : '');
|
|
|
|
$darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : '');
|
|
|
|
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
|
|
|
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
2017-05-15 01:02:22 +00:00
|
|
|
$darray['app_plugin'] = ((x($arr,'plugin')) ? escape_tags(trim($arr['plugin'])) : '');
|
2016-05-23 02:26:21 +00:00
|
|
|
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
|
|
|
|
$darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0);
|
|
|
|
$darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0);
|
2018-08-03 05:49:30 +00:00
|
|
|
$darray['app_options'] = ((x($arr,'options')) ? intval($arr['options']) : 0);
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$created = datetime_convert();
|
|
|
|
|
2018-08-03 05:49:30 +00:00
|
|
|
$r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_plugin, app_deleted, app_options ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )",
|
2016-05-23 02:26:21 +00:00
|
|
|
dbesc($darray['app_id']),
|
|
|
|
dbesc($darray['app_sig']),
|
|
|
|
dbesc($darray['app_author']),
|
|
|
|
dbesc($darray['app_name']),
|
|
|
|
dbesc($darray['app_desc']),
|
|
|
|
dbesc($darray['app_url']),
|
|
|
|
dbesc($darray['app_photo']),
|
|
|
|
dbesc($darray['app_version']),
|
|
|
|
intval($darray['app_channel']),
|
|
|
|
dbesc($darray['app_addr']),
|
|
|
|
dbesc($darray['app_price']),
|
|
|
|
dbesc($darray['app_page']),
|
|
|
|
dbesc($darray['app_requires']),
|
|
|
|
dbesc($created),
|
|
|
|
dbesc($created),
|
|
|
|
intval($darray['app_system']),
|
2016-12-15 03:11:01 +00:00
|
|
|
dbesc($darray['app_plugin']),
|
2018-08-03 05:49:30 +00:00
|
|
|
intval($darray['app_deleted']),
|
|
|
|
intval($darray['app_options'])
|
2016-05-23 02:26:21 +00:00
|
|
|
);
|
2018-03-24 22:13:19 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($r) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['success'] = true;
|
|
|
|
$ret['app_id'] = $darray['app_id'];
|
|
|
|
}
|
2018-07-06 05:27:44 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($arr['categories']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$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']);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($y) {
|
|
|
|
foreach ($y as $t) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$t = trim($t);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($t) {
|
2016-05-23 02:26:21 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public function app_update($arr) {
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
// logger('app_update: ' . print_r($arr,true));
|
|
|
|
$darray = [];
|
|
|
|
$ret = [ 'success' => false ];
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2018-07-27 20:59:27 +00:00
|
|
|
self::app_macros($arr['uid'],$arr);
|
|
|
|
|
|
|
|
|
2016-05-23 02:26:21 +00:00
|
|
|
$darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : '');
|
|
|
|
$darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0);
|
|
|
|
$darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0);
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ((! $darray['app_url']) || (! $darray['app_id'])) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return $ret;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
2020-05-04 23:43:15 +00:00
|
|
|
if ($arr['photo'] && (strpos($arr['photo'],'icon:') === false) && (strpos($arr['photo'],z_root()) === false)) {
|
2020-08-25 04:36:56 +00:00
|
|
|
$x = import_remote_xchan_photo(str_replace('$baseurl',z_root(),$arr['photo']),get_observer_hash(),true);
|
2020-08-25 09:28:59 +00:00
|
|
|
if ((! $x) || ($x[4])) {
|
2020-05-04 23:43:15 +00:00
|
|
|
// $x[4] = true indicates storage failure of our cached/resized copy. If this failed, just keep the original url.
|
|
|
|
$arr['photo'] = $x[1];
|
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : '');
|
|
|
|
$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_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : '');
|
|
|
|
$darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80));
|
|
|
|
$darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : '');
|
|
|
|
$darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : '');
|
|
|
|
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
|
|
|
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
2017-05-15 01:02:22 +00:00
|
|
|
$darray['app_plugin'] = ((x($arr,'plugin')) ? escape_tags(trim($arr['plugin'])) : '');
|
2016-05-23 02:26:21 +00:00
|
|
|
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
|
|
|
|
$darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0);
|
|
|
|
$darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0);
|
2018-08-03 05:49:30 +00:00
|
|
|
$darray['app_options'] = ((x($arr,'options')) ? intval($arr['options']) : 0);
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$edited = datetime_convert();
|
|
|
|
|
2018-08-03 05:49:30 +00:00
|
|
|
$r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_plugin = '%s', app_deleted = %d, app_options = %d where app_id = '%s' and app_channel = %d",
|
2016-05-23 02:26:21 +00:00
|
|
|
dbesc($darray['app_sig']),
|
|
|
|
dbesc($darray['app_author']),
|
|
|
|
dbesc($darray['app_name']),
|
|
|
|
dbesc($darray['app_desc']),
|
|
|
|
dbesc($darray['app_url']),
|
|
|
|
dbesc($darray['app_photo']),
|
|
|
|
dbesc($darray['app_version']),
|
|
|
|
dbesc($darray['app_addr']),
|
|
|
|
dbesc($darray['app_price']),
|
|
|
|
dbesc($darray['app_page']),
|
|
|
|
dbesc($darray['app_requires']),
|
|
|
|
dbesc($edited),
|
|
|
|
intval($darray['app_system']),
|
2016-12-15 03:11:01 +00:00
|
|
|
dbesc($darray['app_plugin']),
|
2016-05-23 02:26:21 +00:00
|
|
|
intval($darray['app_deleted']),
|
2018-08-03 05:49:30 +00:00
|
|
|
intval($darray['app_options']),
|
2016-05-23 02:26:21 +00:00
|
|
|
dbesc($darray['app_id']),
|
|
|
|
intval($darray['app_channel'])
|
|
|
|
);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($r) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['success'] = true;
|
|
|
|
$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'])
|
|
|
|
);
|
2018-03-25 04:17:15 +00:00
|
|
|
|
2018-07-06 05:27:44 +00:00
|
|
|
// if updating an embed app and we don't have a 0 channel_id don't mess with any existing categories
|
2018-03-25 04:17:15 +00:00
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (array_key_exists('embed',$arr) && intval($arr['embed']) && (intval($darray['app_channel'])))
|
2018-03-25 04:17:15 +00:00
|
|
|
return $ret;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($x) {
|
2016-05-23 02:26:21 +00:00
|
|
|
q("delete from term where otype = %d and oid = %d",
|
|
|
|
intval(TERM_OBJ_APP),
|
|
|
|
intval($x[0]['id'])
|
|
|
|
);
|
2021-07-18 21:17:42 +00:00
|
|
|
if (isset($arr['categories']) && $arr['categories']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$y = explode(',',$arr['categories']);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($y) {
|
|
|
|
foreach ($y as $t) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$t = trim($t);
|
2019-05-23 23:37:56 +00:00
|
|
|
if ($t) {
|
2016-05-23 02:26:21 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public function app_encode($app,$embed = false) {
|
|
|
|
|
2021-03-15 05:10:44 +00:00
|
|
|
$ret = [];
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$ret['type'] = 'personal';
|
|
|
|
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_id']) && $app['app_id']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['guid'] = $app['app_id'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_sig']) && $app['app_sig']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['sig'] = $app['app_sig'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_author']) && $app['app_author']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['author'] = $app['app_author'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_name']) && $app['app_name']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['name'] = $app['app_name'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_desc']) && $app['app_desc']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['desc'] = $app['app_desc'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_url']) && $app['app_url']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['url'] = $app['app_url'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_photo']) && $app['app_photo']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['photo'] = $app['app_photo'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_icon']) && $app['app_icon']) {
|
2017-02-03 11:12:05 +00:00
|
|
|
$ret['icon'] = $app['app_icon'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_version']) && $app['app_version']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['version'] = $app['app_version'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_addr']) && $app['app_addr']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['addr'] = $app['app_addr'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_price']) && $app['app_price']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['price'] = $app['app_price'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_page']) && $app['app_page']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['page'] = $app['app_page'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_requires']) && $app['app_requires']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['requires'] = $app['app_requires'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_system']) && $app['app_system']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['system'] = $app['app_system'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_options']) && $app['app_options']) {
|
2018-08-03 05:49:30 +00:00
|
|
|
$ret['options'] = $app['app_options'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_plugin']) && $app['app_plugin']) {
|
2017-05-15 01:02:22 +00:00
|
|
|
$ret['plugin'] = trim($app['app_plugin']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['app_deleted']) && $app['app_deleted']) {
|
2016-05-23 02:26:21 +00:00
|
|
|
$ret['deleted'] = $app['app_deleted'];
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2021-03-09 01:51:41 +00:00
|
|
|
if (isset($app['term']) && $app['term']) {
|
2019-05-23 23:37:56 +00:00
|
|
|
$ret['categories'] = array_elm_to_str($app['term'],'term');
|
2016-05-23 02:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (! $embed) {
|
2016-05-23 02:26:21 +00:00
|
|
|
return $ret;
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2017-02-08 10:17:09 +00:00
|
|
|
$ret['embed'] = true;
|
|
|
|
|
2019-05-23 23:37:56 +00:00
|
|
|
if (array_key_exists('categories',$ret)) {
|
2016-05-23 02:26:21 +00:00
|
|
|
unset($ret['categories']);
|
2019-05-23 23:37:56 +00:00
|
|
|
}
|
2016-05-23 02:26:21 +00:00
|
|
|
|
|
|
|
$j = json_encode($ret);
|
|
|
|
return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public function papp_encode($papp) {
|
|
|
|
return chunk_split(base64_encode(json_encode($papp)),72,"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|