firehose fixes and optimisations. In particular get rid of the unresponsive script warning when trying to load updates (sine they aren't our posts, we can't check for unseen, hence we can't really load updates). Also make the url selection pluggable.

This commit is contained in:
friendica 2014-03-27 15:35:29 -07:00
parent 7b24b78af9
commit a0674af416
6 changed files with 82 additions and 74 deletions

View File

@ -52,8 +52,14 @@ class Conversation extends BaseObject {
switch($mode) {
case 'network':
$this->profile_owner = local_user();
$this->writable = true;
if(array_key_exists('firehose',$a->data) && intval($a->data['firehose'])) {
$this->profile_owner = intval($a->data['firehose']);
$this->writable = false;
}
else {
$this->profile_owner = local_user();
$this->writable = true;
}
break;
case 'channel':
$this->profile_owner = $a->profile['profile_uid'];

View File

@ -1384,10 +1384,10 @@ function network_tabs() {
// tabs
$tabs = array(
array(
'label' => t('Public'),
'label' => t('External'),
'url'=>$a->get_baseurl(true) . '/' . $cmd . '?f=&fh=1' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') . ((x($_GET,'gid')) ? '&gid=' . $_GET['gid'] : ''),
'sel'=> $public_active,
'title'=> t('View Public Streams'),
'title'=> t('Imported public streams'),
),
array(

54
include/externals.php Normal file
View File

@ -0,0 +1,54 @@
<?php /** @file */
require_once('boot.php');
require_once('include/cli_startup.php');
require_once('include/zot.php');
require_once('include/identity.php');
function externals_run($argv, $argc){
cli_startup();
$a = get_app();
// pull in some public posts
$arr = array('url' => '');
call_hooks('externals_url_select',$arr);
if($arr['url']) {
$url = $arr['url'];
}
else {
$r = q("select site_url from site where site_url != '%s' order by rand() limit 1",
dbesc(z_root())
);
if($r)
$url = $r[0]['site_url'];
}
if($url) {
$feedurl = $url . '/zotfeed?f=&mindate=' . urlencode(datetime_convert('','','now - 15 days'));
$x = z_fetch_url($feedurl);
if(($x) && ($x['success'])) {
$total = 0;
$j = json_decode($x['body'],true);
if($j['success'] && $j['messages']) {
$sys = get_sys_channel();
foreach($j['messages'] as $message) {
$results = process_delivery(array('hash' => 'undefined'), get_item_elements($message),
array(array('hash' => $sys['xchan_hash'])), false, true);
$total ++;
}
logger('import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
}
}
}
}
if (array_search(__file__,get_included_files())===0){
externals_run($argv,$argc);
killme();
}

View File

@ -167,31 +167,10 @@ function poller_run($argv, $argc){
}
}
// pull in some public posts
proc_run('php','include/externals.php');
$r = q("select site_url from site where site_url != '%s' order by rand() limit 1",
dbesc(z_root())
);
if($r) {
$feedurl = $r[0]['site_url'] . '/zotfeed?f=&mindate=' . urlencode(datetime_convert('','','now - 15 days'));
$x = z_fetch_url($feedurl);
if(($x) && ($x['success'])) {
$total = 0;
$j = json_decode($x['body'],true);
if($j['success'] && $j['messages']) {
require_once('include/identity.php');
$sys = get_sys_channel();
foreach($j['messages'] as $message) {
$results = process_delivery(array('hash' => 'undefined'), get_item_elements($message),
array(array('hash' => $sys['xchan_hash'])), false, true);
$total ++;
}
logger('import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
}
}
}
$manual_id = 0;
$generation = 0;

View File

@ -322,7 +322,8 @@ function network_content(&$a, $update = 0, $load = false) {
if($firehose) {
require_once('include/identity.php');
$sys = get_sys_channel();
$uids = " and item.uid in ( " . intval(local_user()) . "," . intval($sys['channel_id']) . ") ";
$uids = " and item.uid = " . intval($sys['channel_id']) . " ";
$a->data['firehose'] = intval($sys['channel_id']);
}
else {
$uids = " and item.uid = " . local_user() . " ";
@ -341,7 +342,7 @@ function network_content(&$a, $update = 0, $load = false) {
$items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item`
WHERE true $uids AND item_restrict = 0
$simple_update
$sql_extra $sql_nets group by item.mid
$sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql "
);
@ -369,22 +370,23 @@ function network_content(&$a, $update = 0, $load = false) {
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 group by item.mid
$sql_extra3 $sql_extra $sql_nets
ORDER BY item.$ordering DESC $pager_sql ",
intval(ABOOK_FLAG_BLOCKED)
);
}
else {
// update
$r = q("SELECT item.parent AS item_id FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE true $uids AND item.item_restrict = 0 $simple_update
and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)
$sql_extra3 $sql_extra $sql_nets group by item.mid ",
intval(ABOOK_FLAG_BLOCKED)
);
if(! $firehose) {
// update
$r = q("SELECT item.parent AS item_id FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE true $uids AND item.item_restrict = 0 $simple_update
and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)
$sql_extra3 $sql_extra $sql_nets ",
intval(ABOOK_FLAG_BLOCKED)
);
}
}
$first = dba_timer();
@ -400,7 +402,7 @@ function network_content(&$a, $update = 0, $load = false) {
$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 group by item.mid",
$sql_extra ",
dbesc($parents_str)
);
@ -432,7 +434,7 @@ function network_content(&$a, $update = 0, $load = false) {
// logger('items: ' . count($items));
if($update_unseen)
if(($update_unseen) && (! $firehose))
$r = q("UPDATE `item` SET item_flags = ( item_flags ^ %d)
WHERE (item_flags & %d) AND `uid` = %d $update_unseen ",
intval(ITEM_UNSEEN),

View File

@ -1,33 +0,0 @@
<?php
// See update_profile.php for documentation
require_once('mod/community.php');
function update_community_content(&$a) {
header("Content-type: text/html");
echo "<!DOCTYPE html><html><body>\r\n";
echo (($_GET['msie'] == 1) ? '<div>' : '<section>');
$text = community_content($a,true);
$pattern = "/<img([^>]*) src=\"([^\"]*)\"/";
$replace = "<img\${1} dst=\"\${2}\"";
$text = preg_replace($pattern, $replace, $text);
$replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />';
$pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i";
$text = preg_replace($pattern, $replace, $text);
$pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i";
$text = preg_replace($pattern, $replace, $text);
$pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i";
$text = preg_replace($pattern, $replace, $text);
$pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i";
$text = preg_replace($pattern, $replace, $text);
echo str_replace("\t",' ',$text);
echo (($_GET['msie'] == 1) ? '</div>' : '</section>');
echo "</body></html>\r\n";
killme();
}