streams/Zotlabs/Module/Appman.php

160 lines
4.4 KiB
PHP
Raw Normal View History

2016-05-05 00:35:27 +00:00
<?php /** @file */
namespace Zotlabs\Module;
2016-04-19 03:38:38 +00:00
2016-05-23 02:25:27 +00:00
//require_once('include/apps.php');
2016-04-19 03:38:38 +00:00
2016-05-23 02:25:27 +00:00
use \Zotlabs\Lib as Zlib;
2016-04-19 03:38:38 +00:00
class Appman extends \Zotlabs\Web\Controller {
function post() {
if(! local_channel())
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']),
2018-03-24 22:13:19 +00:00
'page' => escape_tags($_REQUEST['page']),
'requires' => escape_tags($_REQUEST['requires']),
'system' => intval($_REQUEST['system']),
2017-01-13 21:22:36 +00:00
'plugin' => escape_tags($_REQUEST['plugin']),
2016-05-05 00:35:27 +00:00
'sig' => escape_tags($_REQUEST['sig']),
'categories' => escape_tags($_REQUEST['categories'])
2016-04-19 03:38:38 +00:00
);
2016-05-23 02:25:27 +00:00
$_REQUEST['appid'] = Zlib\Apps::app_install(local_channel(),$arr);
2016-04-19 03:38:38 +00:00
2016-05-23 02:25:27 +00:00
if(Zlib\Apps::app_installed(local_channel(),$arr))
2016-04-19 03:38:38 +00:00
info( t('App installed.') . EOL);
2017-02-22 10:22:43 +00:00
goaway(z_root() . '/apps');
return; //not reached
2016-04-19 03:38:38 +00:00
}
2016-05-23 02:25:27 +00:00
$papp = Zlib\Apps::app_decode($_POST['papp']);
2016-04-19 03:38:38 +00:00
if(! is_array($papp)) {
notice( t('Malformed app.') . EOL);
return;
}
if($_POST['install']) {
2016-05-23 02:25:27 +00:00
Zlib\Apps::app_install(local_channel(),$papp);
if(Zlib\Apps::app_installed(local_channel(),$papp))
2016-04-19 03:38:38 +00:00
info( t('App installed.') . EOL);
}
if($_POST['delete']) {
2016-05-23 02:25:27 +00:00
Zlib\Apps::app_destroy(local_channel(),$papp);
2016-04-19 03:38:38 +00:00
}
2016-04-19 03:38:38 +00:00
if($_POST['edit']) {
return;
}
2017-01-13 21:22:36 +00:00
2017-01-30 14:17:46 +00:00
if($_POST['feature']) {
Zlib\Apps::app_feature(local_channel(), $papp, $_POST['feature']);
}
if($_POST['pin']) {
Zlib\Apps::app_feature(local_channel(), $papp, $_POST['pin']);
2017-01-30 14:17:46 +00:00
}
2016-04-19 03:38:38 +00:00
if($_SESSION['return_url'])
goaway(z_root() . '/' . $_SESSION['return_url']);
2017-01-13 21:22:36 +00:00
2016-04-19 03:38:38 +00:00
goaway(z_root() . '/apps');
}
function get() {
2016-04-19 03:38:38 +00:00
if(! local_channel()) {
notice( t('Permission denied.') . EOL);
return;
}
2017-01-13 21:22:36 +00:00
2016-04-19 03:38:38 +00:00
$channel = \App::get_channel();
2018-12-13 03:04:14 +00:00
if(argc() > 3) {
if(argv(2) === 'moveup') {
2018-12-13 03:04:14 +00:00
Zlib\Apps::moveup(local_channel(),argv(1),argv(3));
}
if(argv(2) === 'movedown') {
2018-12-13 03:04:14 +00:00
Zlib\Apps::movedown(local_channel(),argv(1),argv(3));
}
goaway(z_root() . '/apporder');
}
2016-04-19 03:38:38 +00:00
$app = null;
$embed = null;
if($_REQUEST['appid']) {
$r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($_REQUEST['appid']),
dbesc(local_channel())
);
2016-05-05 00:35:27 +00:00
if($r) {
2016-04-19 03:38:38 +00:00
$app = $r[0];
2016-05-05 00:35:27 +00:00
2018-10-05 03:29:41 +00:00
$term = q("select * from term where otype = %d and oid = %d and uid = %d",
2016-05-05 00:35:27 +00:00
intval(TERM_OBJ_APP),
2018-10-05 03:29:41 +00:00
intval($r[0]['id']),
intval(local_channel())
2016-05-05 00:35:27 +00:00
);
if($term) {
$app['categories'] = '';
foreach($term as $t) {
if($app['categories'])
$app['categories'] .= ',';
$app['categories'] .= $t['term'];
}
}
}
2016-05-23 02:25:27 +00:00
$embed = array('embed', t('Embed code'), Zlib\Apps::app_encode($app,true),'', 'onclick="this.select();"');
2016-04-19 03:38:38 +00:00
}
return replace_macros(get_markup_template('app_create.tpl'), array(
'$banner' => (($app) ? t('Edit App') : t('Create App')),
'$app' => $app,
'$guid' => (($app) ? $app['app_id'] : ''),
'$author' => (($app) ? $app['app_author'] : $channel['channel_hash']),
'$addr' => (($app) ? $app['app_addr'] : $channel['xchan_addr']),
'$name' => array('name', t('Name of app'),(($app) ? $app['app_name'] : ''), 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'] : ''), ''),
'$photo' => array('photo', t('Photo icon URL'),(($app) ? $app['app_photo'] : ''), t('80 x 80 pixels - optional')),
2016-05-05 00:35:27 +00:00
'$categories' => array('categories',t('Categories (optional, comma separated list)'),(($app) ? $app['categories'] : ''),''),
2016-04-19 03:38:38 +00:00
'$version' => array('version', t('Version ID'),(($app) ? $app['app_version'] : ''), ''),
'$price' => array('price', t('Price of app'),(($app) ? $app['app_price'] : ''), ''),
'$page' => array('page', t('Location (URL) to purchase app'),(($app) ? $app['app_page'] : ''), ''),
'$system' => (($app) ? intval($app['app_system']) : 0),
2017-01-13 21:22:36 +00:00
'$plugin' => (($app) ? $app['app_plugin'] : ''),
'$requires' => (($app) ? $app['app_requires'] : ''),
2016-04-19 03:38:38 +00:00
'$embed' => $embed,
'$submit' => t('Submit')
));
}
}