streams/Zotlabs/Module/Home.php

152 lines
4 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
namespace Zotlabs\Module;
2019-12-03 05:23:02 +00:00
use App;
2018-06-01 02:42:13 +00:00
use Zotlabs\Lib\Libzot;
2021-08-25 05:59:48 +00:00
use Zotlabs\Lib\ActivityStreams;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\LDSignatures;
2018-06-20 02:33:50 +00:00
use Zotlabs\Web\HTTPSig;
2019-12-03 05:23:02 +00:00
use Zotlabs\Web\Controller;
2016-04-19 03:38:38 +00:00
2018-06-01 04:05:09 +00:00
require_once('include/conversation.php');
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
class Home extends Controller {
2016-04-19 03:38:38 +00:00
function init() {
2021-08-25 05:59:48 +00:00
2019-12-03 05:23:02 +00:00
$ret = [];
2016-04-19 03:38:38 +00:00
call_hooks('home_init',$ret);
2021-08-25 05:59:48 +00:00
if (ActivityStreams::is_as_request()) {
$x = array_merge(['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1',
Activity::ap_schema()
]], Activity::encode_site() );
$headers = [];
$headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
$x['signature'] = LDSignatures::sign($x,[ 'channel_address' => z_root(), 'channel_prvkey' => get_config('system','prvkey') ]);
$ret = json_encode($x, JSON_UNESCAPED_SLASHES);
logger('data: ' . jindent($ret), LOGGER_DATA);
$headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
$headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
$h = HTTPSig::create_sig($headers,get_config('system','prvkey'),z_root());
HTTPSig::set_headers($h);
echo $ret;
killme();
}
2019-12-03 05:23:02 +00:00
if (Libzot::is_zot_request()) {
2018-04-23 04:30:14 +00:00
2018-06-20 02:33:50 +00:00
$key = get_config('system','prvkey');
$ret = json_encode(Libzot::site_info());
2018-04-23 04:30:14 +00:00
2018-06-20 02:33:50 +00:00
$headers = [ 'Content-Type' => 'application/x-zot+json', 'Digest' => HTTPSig::generate_digest_header($ret) ];
2018-10-11 00:58:51 +00:00
$headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
2018-06-20 05:09:49 +00:00
$h = HTTPSig::create_sig($headers, $key, z_root());
2018-06-20 02:33:50 +00:00
HTTPSig::set_headers($h);
2018-04-23 04:30:14 +00:00
echo $ret;
killme();
}
2016-04-19 03:38:38 +00:00
$splash = ((argc() > 1 && argv(1) === 'splash') ? true : false);
2019-12-03 05:23:02 +00:00
$channel = App::get_channel();
if (local_channel() && $channel && $channel['xchan_url'] && ! $splash) {
2016-04-19 03:38:38 +00:00
$dest = $channel['channel_startpage'];
2019-12-03 05:23:02 +00:00
if (! $dest) {
2016-04-19 03:38:38 +00:00
$dest = get_pconfig(local_channel(),'system','startpage');
2019-12-03 05:23:02 +00:00
}
if (! $dest) {
2016-04-19 03:38:38 +00:00
$dest = get_config('system','startpage');
2019-12-03 05:23:02 +00:00
}
if (! $dest) {
2020-02-13 05:36:21 +00:00
$dest = z_root() . '/stream';
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
goaway($dest);
}
2019-12-03 05:23:02 +00:00
if (remote_channel() && (! $splash) && $_SESSION['atoken']) {
$r = q("select * from atoken where atoken_id = %d",
intval($_SESSION['atoken'])
);
2019-12-03 05:23:02 +00:00
if ($r) {
$x = channelx_by_n($r[0]['atoken_uid']);
2019-12-03 05:23:02 +00:00
if ($x) {
goaway(z_root() . '/channel/' . $x['channel_address']);
}
}
}
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
if (get_account_id() && ! $splash) {
2016-04-19 03:38:38 +00:00
goaway(z_root() . '/new_channel');
}
}
function get($update = 0, $load = false) {
2019-12-03 05:23:02 +00:00
$o = EMPTY_STR;
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
if (x($_SESSION,'theme')) {
2016-04-19 03:38:38 +00:00
unset($_SESSION['theme']);
2019-12-03 05:23:02 +00:00
}
if (x($_SESSION,'mobile_theme')) {
2016-04-19 03:38:38 +00:00
unset($_SESSION['mobile_theme']);
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
$splash = ((argc() > 1 && argv(1) === 'splash') ? true : false);
call_hooks('home_content',$o);
2019-12-03 05:23:02 +00:00
if ($o) {
2016-04-19 03:38:38 +00:00
return $o;
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
$frontpage = get_config('system','frontpage');
2019-12-03 05:23:02 +00:00
if ($frontpage) {
if (strpos($frontpage,'include:') !== false) {
2016-04-19 03:38:38 +00:00
$file = trim(str_replace('include:' , '', $frontpage));
2019-12-03 05:23:02 +00:00
if (file_exists($file)) {
App::$page['template'] = 'full';
App::$page['title'] = t('$Projectname');
2016-04-19 03:38:38 +00:00
$o .= file_get_contents($file);
return $o;
}
}
2019-12-03 05:23:02 +00:00
if (strpos($frontpage,'http') !== 0) {
2016-04-19 03:38:38 +00:00
$frontpage = z_root() . '/' . $frontpage;
2019-12-03 05:23:02 +00:00
}
if (intval(get_config('system','mirror_frontpage'))) {
2016-04-19 03:38:38 +00:00
$o = '<html><head><title>' . t('$Projectname') . '</title></head><body style="margin: 0; padding: 0; border: none;" ><iframe src="' . $frontpage . '" width="100%" height="100%" style="margin: 0; padding: 0; border: none;" ></iframe></body></html>';
echo $o;
killme();
}
goaway($frontpage);
}
$sitename = get_config('system','sitename');
2019-12-03 05:23:02 +00:00
if ($sitename) {
$o .= '<h1 class="home-welcome">' . sprintf( t('Welcome to %s') ,$sitename) . '</h1>';
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
$loginbox = get_config('system','login_on_homepage');
2019-12-03 05:23:02 +00:00
if (intval($loginbox) || $loginbox === false) {
$o .= login(true);
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
return $o;
}
}