aboutsummaryrefslogtreecommitdiffstats
path: root/mod/home.php
blob: a1a68710f48b9c8227e5e87c26516688b752c806 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php

require_once('include/items.php');
require_once('include/conversation.php');


function home_init(&$a) {

	$ret = array();
	call_hooks('home_init',$ret);

	$splash = ((argc() > 1 && argv(1) === 'splash') ? true : false);

	$channel = $a->get_channel();
	if(local_user() && $channel && $channel['xchan_url'] && ! $splash) {
		$dest = $channel['channel_startpage'];
		if(! $dest)
			$dest = get_pconfig(local_user(),'system','startpage');
		if(! $dest)
			$dest = get_config('system','startpage');
		if(! $dest)
			$dest = z_root() . '/apps';

		goaway($dest);
	}

	if(get_account_id() && ! $splash) {
		goaway(z_root() . '/new_channel');
	}

}


function home_content(&$a) {

	$o = '';

	if(x($_SESSION,'theme'))
		unset($_SESSION['theme']);
	if(x($_SESSION,'mobile_theme'))
		unset($_SESSION['mobile_theme']);

	$splash = ((argc() > 1 && argv(1) === 'splash') ? true : false);

	if(get_config('system','projecthome')) {
		$o .= file_get_contents('assets/home.html');
		$a->page['template'] = 'full';
		$a->page['title'] = t('Red Matrix - &quot;The Network&quot;');
		return $o;
	}


	// Deprecated
	$channel_address = get_config("system", "site_channel" );
	
	// See if the sys channel set a homepage
	if (! $channel_address) {
		$u = get_sys_channel();
		if ($u) {
			$u = array($u);
			// change to channel_id when below deprecated and skip the $u=...
			$channel_address = $u[0]['channel_address'];
		}
	}

	if($channel_address) {

		$page_id = 'home';

		$u = q("select channel_id from channel where channel_address = '%s' limit 1",
			dbesc($channel_address)
		);

		$r = q("select item.* from item left join item_id on item.id = item_id.iid
			where item.uid = %d and sid = '%s' and service = 'WEBPAGE' and 
			item_restrict = %d limit 1",
			intval($u[0]['channel_id']),
			dbesc($page_id),
			intval(ITEM_WEBPAGE)
		);

		if($r) {
			xchan_query($r);
			$r = fetch_post_tags($r,true);
			$a->profile = array('profile_uid' => $u[0]['channel_id']);
			$a->profile_uid = $u[0]['channel_id'];
			$o .= prepare_page($r[0]);
			return $o;
		}
	}

	// Nope, we didn't find an item.  Let's see if there's any html

	if(file_exists('home.html')) {
		$o .= file_get_contents('home.html');
	}
	else {

		// If there's nothing special happening, just spit out a login box

		$sitename = get_config('system','sitename');
		if($sitename) 
			$o .= '<h1>' . sprintf( t("Welcome to %s") ,$sitename) . '</h1>';
		if (! $a->config['system']['no_login_on_homepage'])
			$o .= login(($a->config['system']['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
	}
	
	call_hooks('home_content',$o);
	return $o;	
}