streams/mod/home.php

286 lines
7.3 KiB
PHP
Raw Normal View History

2010-07-01 23:48:07 +00:00
<?php
require_once('include/items.php');
require_once('include/conversation.php');
2010-07-01 23:48:07 +00:00
function home_init(&$a) {
2011-12-15 09:09:38 +00:00
$ret = array();
2011-12-15 09:09:38 +00:00
call_hooks('home_init',$ret);
2011-12-15 09:08:19 +00:00
$splash = ((argc() > 1 && argv(1) === 'splash') ? true : false);
$channel = $a->get_channel();
2015-01-29 04:56:04 +00:00
if(local_channel() && $channel && $channel['xchan_url'] && ! $splash) {
2014-05-22 04:33:31 +00:00
$dest = $channel['channel_startpage'];
if(! $dest)
2015-01-29 04:56:04 +00:00
$dest = get_pconfig(local_channel(),'system','startpage');
if(! $dest)
$dest = get_config('system','startpage');
2014-05-22 04:33:31 +00:00
if(! $dest)
$dest = z_root() . '/apps';
2013-05-18 09:03:59 +00:00
goaway($dest);
}
2010-09-17 12:19:56 +00:00
if(get_account_id() && ! $splash) {
goaway(z_root() . '/new_channel');
}
}
2010-07-01 23:48:07 +00:00
2014-11-21 01:38:41 +00:00
function home_content(&$a, $update = 0, $load = false) {
2013-05-31 02:38:37 +00:00
2010-10-31 23:38:22 +00:00
$o = '';
if($load)
$_SESSION['loadtime'] = datetime_convert();
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('$Projectname');
return $o;
}
// Deprecated
$channel_address = get_config("system", "site_channel" );
// See if the sys channel set a homepage
if (! $channel_address) {
2014-11-23 22:51:04 +00:00
require_once('include/identity.php');
$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';
$randpage_id = 'home-%';
$u = q("select channel_id from channel where channel_address = '%s' limit 1",
dbesc($channel_address)
);
$randfunc = db_getfunc('RAND');
$r = q("select item.* from item left join item_id on item.id = item_id.iid
where item.uid = %d and ( sid = '%s' or sid like '%s' ) and service = 'WEBPAGE' and
item_restrict = %d ORDER BY $randfunc limit 1",
intval($u[0]['channel_id']),
dbesc($page_id),
dbesc($randpage_id),
intval(ITEM_WEBPAGE)
);
if($r) {
xchan_query($r);
$r = fetch_post_tags($r,true);
if($r[0]['layout_mid']) {
$l = q("select body from item where mid = '%s' and uid = %d limit 1",
dbesc($r[0]['layout_mid']),
intval($u[0]['channel_id'])
);
if($l) {
require_once('include/comanche.php');
comanche_parser($a,$l[0]['body']);
$a->pdl = $l[0]['body'];
}
}
$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 {
$sitename = get_config('system','sitename');
if($sitename)
$o .= '<h1>' . sprintf( t("Welcome to %s") ,$sitename) . '</h1>';
2014-11-21 01:38:41 +00:00
2015-01-29 04:58:59 +00:00
if(intval(get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
2014-11-21 01:38:41 +00:00
// If there's nothing special happening, just spit out a login box
if (! $a->config['system']['no_login_on_homepage'])
$o .= login(($a->config['system']['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
return $o;
}
else {
if(get_config('system','disable_discover_tab')) {
call_hooks('home_content',$o);
return $o;
}
2014-11-21 01:38:41 +00:00
if(! $update) {
$maxheight = get_config('system','home_divmore_height');
if(! $maxheight)
$maxheight = 75;
$o .= '<div id="live-home"></div>' . "\r\n";
2015-01-29 04:56:04 +00:00
$o .= "<script> var profile_uid = " . ((intval(local_channel())) ? local_channel() : (-1))
2014-11-21 01:38:41 +00:00
. "; var profile_page = " . $a->pager['page']
. "; divmore_height = " . intval($maxheight) . "; </script>\r\n";
$a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array(
'$baseurl' => z_root(),
'$pgtype' => 'home',
2015-01-29 04:56:04 +00:00
'$uid' => ((local_channel()) ? local_channel() : '0'),
2014-11-21 01:38:41 +00:00
'$gid' => '0',
'$cid' => '0',
'$cmin' => '0',
'$cmax' => '99',
'$star' => '0',
'$liked' => '0',
'$conv' => '0',
'$spam' => '0',
'$fh' => '1',
'$nouveau' => '0',
'$wall' => '0',
'$list' => '0',
'$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1),
'$search' => '',
'$order' => 'comment',
'$file' => '',
'$cats' => '',
2014-12-15 22:37:31 +00:00
'$tags' => '',
2014-11-21 01:38:41 +00:00
'$dend' => '',
'$mid' => '',
'$verb' => '',
2014-11-21 01:38:41 +00:00
'$dbegin' => ''
));
}
if($update && ! $load) {
// only setup pagination on initial page view
$pager_sql = '';
}
else {
$a->set_pager_itemspage(20);
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
}
require_once('include/identity.php');
2015-02-16 04:20:23 +00:00
if(get_config('system','site_firehose')) {
require_once('include/security.php');
$uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and (item_flags & " . intval(ITEM_WALL) . " ) > 0 ";
}
else {
$sys = get_sys_channel();
$uids = " and item.uid = " . intval($sys['channel_id']) . " ";
$a->data['firehose'] = intval($sys['channel_id']);
}
2014-11-21 01:38:41 +00:00
$page_mode = 'list';
$simple_update = (($update) ? " and item.item_unseen = 1 " : '');
2014-11-21 01:38:41 +00:00
if($update && $_SESSION['loadtime'])
$simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) OR item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) ";
2014-11-21 01:38:41 +00:00
if($load)
$simple_update = '';
//logger('update: ' . $update . ' load: ' . $load);
if($update) {
$ordering = "commented";
if($load) {
// Fetch a page full of parent items for this page
$r = q("SELECT distinct item.id AS item_id, $ordering FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE true $uids AND item.item_restrict = 0
AND item.parent = item.id
and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)
$sql_extra3 $sql_extra $sql_nets
ORDER BY $ordering DESC $pager_sql ",
intval(ABOOK_FLAG_BLOCKED)
);
2015-02-16 04:20:23 +00:00
2014-11-21 01:38:41 +00:00
}
elseif($update) {
2014-11-21 01:38:41 +00:00
$r = q("SELECT distinct item.id AS item_id, $ordering FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE true $uids AND item.item_restrict = 0
AND item.parent = item.id $simple_update
and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)
$sql_extra3 $sql_extra $sql_nets",
intval(ABOOK_FLAG_BLOCKED)
);
$_SESSION['loadtime'] = datetime_convert();
}
2014-11-21 01:38:41 +00:00
// Then fetch all the children of the parents that are on this page
$parents_str = '';
$update_unseen = '';
if($r) {
$parents_str = ids_to_querystr($r,'item_id');
$items = q("SELECT item.*, item.id AS item_id FROM item
WHERE true $uids AND item.item_restrict = 0
AND item.parent IN ( %s )
$sql_extra ",
dbesc($parents_str)
);
xchan_query($items,true,(-1));
$items = fetch_post_tags($items,true);
$items = conv_sort($items,$ordering);
}
else {
$items = array();
}
}
// fake it
$mode = ('network');
$o .= conversation($a,$items,$mode,$update,$page_mode);
if(($items) && (! $update))
$o .= alt_pager($a,count($items));
return $o;
}
call_hooks('home_content',$o);
return $o;
2013-12-15 01:06:50 +00:00
}
2014-11-21 01:38:41 +00:00
2014-11-23 22:51:04 +00:00
return $o;
2014-11-21 01:38:41 +00:00
}