Merge pull request #1423 from annando/1503-faster-tags

Improved search speed (for tags)
This commit is contained in:
fabrixxm 2015-03-09 08:52:37 +01:00
commit 35f623ae4f
18 changed files with 519 additions and 422 deletions

View File

@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Ginger'); define ( 'FRIENDICA_CODENAME', 'Ginger');
define ( 'FRIENDICA_VERSION', '3.3.3' ); define ( 'FRIENDICA_VERSION', '3.3.3' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1180 ); define ( 'DB_UPDATE_VERSION', 1181 );
define ( 'EOL', "<br />\r\n" ); define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View File

@ -516,7 +516,12 @@ class Photo {
return FALSE; return FALSE;
$string = $this->imageString(); $string = $this->imageString();
$a = get_app();
$stamp1 = microtime(true);
file_put_contents($path, $string); file_put_contents($path, $string);
$a->save_timestamp($stamp1, "file");
} }
public function imageString() { public function imageString() {
@ -767,7 +772,12 @@ function get_photo_info($url) {
$filesize = strlen($img_str); $filesize = strlen($img_str);
$tempfile = tempnam(get_temppath(), "cache"); $tempfile = tempnam(get_temppath(), "cache");
$a = get_app();
$stamp1 = microtime(true);
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);
$a->save_timestamp($stamp1, "file");
$data = getimagesize($tempfile); $data = getimagesize($tempfile);
unlink($tempfile); unlink($tempfile);
@ -851,7 +861,10 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
return(array()); return(array());
} elseif (strlen($imagedata) == 0) { } elseif (strlen($imagedata) == 0) {
logger("Uploading picture from ".$url, LOGGER_DEBUG); logger("Uploading picture from ".$url, LOGGER_DEBUG);
$stamp1 = microtime(true);
$imagedata = @file_get_contents($url); $imagedata = @file_get_contents($url);
$a->save_timestamp($stamp1, "file");
} }
$maximagesize = get_config('system','maximagesize'); $maximagesize = get_config('system','maximagesize');
@ -875,7 +888,11 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
*/ */
$tempfile = tempnam(get_temppath(), "cache"); $tempfile = tempnam(get_temppath(), "cache");
$stamp1 = microtime(true);
file_put_contents($tempfile, $imagedata); file_put_contents($tempfile, $imagedata);
$a->save_timestamp($stamp1, "file");
$data = getimagesize($tempfile); $data = getimagesize($tempfile);
if (!isset($data["mime"])) { if (!isset($data["mime"])) {

View File

@ -681,6 +681,8 @@ function bb_RemovePictureLinks($match) {
if(is_null($text)){ if(is_null($text)){
$a = get_app(); $a = get_app();
$stamp1 = microtime(true);
$ch = @curl_init($match[1]); $ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true); @curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -688,6 +690,8 @@ function bb_RemovePictureLinks($match) {
@curl_exec($ch); @curl_exec($ch);
$curl_info = @curl_getinfo($ch); $curl_info = @curl_getinfo($ch);
$a->save_timestamp($stamp1, "network");
if (substr($curl_info["content_type"], 0, 6) == "image/") if (substr($curl_info["content_type"], 0, 6) == "image/")
$text = "[url=".$match[1]."]".$match[1]."[/url]"; $text = "[url=".$match[1]."]".$match[1]."[/url]";
else { else {
@ -731,6 +735,8 @@ function bb_CleanPictureLinksSub($match) {
if(is_null($text)){ if(is_null($text)){
$a = get_app(); $a = get_app();
$stamp1 = microtime(true);
$ch = @curl_init($match[1]); $ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true); @curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@ -738,6 +744,8 @@ function bb_CleanPictureLinksSub($match) {
@curl_exec($ch); @curl_exec($ch);
$curl_info = @curl_getinfo($ch); $curl_info = @curl_getinfo($ch);
$a->save_timestamp($stamp1, "network");
// if its a link to a picture then embed this picture // if its a link to a picture then embed this picture
if (substr($curl_info["content_type"], 0, 6) == "image/") if (substr($curl_info["content_type"], 0, 6) == "image/")
$text = "[img]".$match[1]."[/img]"; $text = "[img]".$match[1]."[/img]";
@ -779,8 +787,6 @@ function bb_CleanPictureLinks($text) {
function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = false, $forplaintext = false) { function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = false, $forplaintext = false) {
$stamp1 = microtime(true);
$a = get_app(); $a = get_app();
// Hide all [noparse] contained bbtags by spacefying them // Hide all [noparse] contained bbtags by spacefying them
@ -1128,7 +1134,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text); // $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
// oembed tag // oembed tag
$Text = oembed_bbcode2html($Text); $Text = oembed_bbcode2html($Text);
@ -1200,8 +1205,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
call_hooks('bbcode',$Text); call_hooks('bbcode',$Text);
$a->save_timestamp($stamp1, "parser");
return trim($Text); return trim($Text);
} }
?> ?>

View File

@ -776,6 +776,9 @@ function db_definition() {
"last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"), "last-child" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "1"),
"mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "mention" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""), "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"rendered-html" => array("type" => "mediumtext", "not null" => "1"),
"global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -1188,6 +1191,10 @@ function db_definition() {
"type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"), "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
"received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
"global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
), ),
@ -1196,8 +1203,9 @@ function db_definition() {
"oid_otype_type_term" => array("oid","otype","type","term"), "oid_otype_type_term" => array("oid","otype","type","term"),
"uid_term_tid" => array("uid","term","tid"), "uid_term_tid" => array("uid","term","tid"),
"type_term" => array("type","term"), "type_term" => array("type","term"),
"uid_otype_type_term_tid" => array("uid","otype","type","term","tid"), "uid_otype_type_term_created" => array("uid","otype","type","term","created"),
"otype_type_term_tid" => array("otype","type","term","tid"), "otype_type_term_tid" => array("otype","type","term","tid"),
"guid" => array("guid"),
) )
); );
$database["thread"] = array( $database["thread"] = array(

View File

@ -1167,6 +1167,8 @@ function diaspora_reshare($importer,$xml,$msg) {
$prefix = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$person['name']). $prefix = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$person['name']).
"' profile='".$person['url']. "' profile='".$person['url'].
"' avatar='".((x($person,'thumb')) ? $person['thumb'] : $person['photo']). "' avatar='".((x($person,'thumb')) ? $person['thumb'] : $person['photo']).
"' guid='".$orig_guid.
"' posted='".$orig_created.
"' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$orig_url)."']"; "' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$orig_url)."']";
$datarray['author-name'] = $contact['name']; $datarray['author-name'] = $contact['name'];
$datarray['author-link'] = $contact['url']; $datarray['author-link'] = $contact['url'];

View File

@ -88,9 +88,6 @@ function deletenode(&$doc, $node)
function html2bbcode($message) function html2bbcode($message)
{ {
//$file = tempnam("/tmp/", "html");
//file_put_contents($file, $message);
$message = str_replace("\r", "", $message); $message = str_replace("\r", "", $message);
$message = str_replace(array( $message = str_replace(array(

View File

@ -1346,6 +1346,20 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
return 0; return 0;
} }
// Is this item available in the global items (with uid=0)?
if ($arr["uid"] == 0) {
$arr["global"] = true;
q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($arr["guid"]));
} else {
$isglobal = q("SELECT `global` FROM `item` WHERE `uid` = 0 AND `guid` = '%s'", dbesc($arr["guid"]));
$arr["global"] = (count($isglobal) > 0);
}
// Fill the cache field
put_item_in_cache($arr);
call_hooks('post_remote',$arr); call_hooks('post_remote',$arr);
if(x($arr,'cancel')) { if(x($arr,'cancel')) {
@ -1478,9 +1492,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
// in it. // in it.
if (!$deleted AND !$dontcache) { if (!$deleted AND !$dontcache) {
// Store the fresh generated item into the cache
put_item_in_cache($arr);
$r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post)); $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
if (count($r) == 1) { if (count($r) == 1) {
call_hooks('post_remote_end', $r[0]); call_hooks('post_remote_end', $r[0]);

View File

@ -870,13 +870,6 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
if(! $i) if(! $i)
return $srctext; return $srctext;
$cachefile = get_cachefile(hash("md5", $scaled));
if ($cachefile != '') {
$stamp1 = microtime(true);
file_put_contents($cachefile, $i);
$a->save_timestamp($stamp1, "file");
}
// guess mimetype from headers or filename // guess mimetype from headers or filename
$type = guess_image_type($mtch[1],true); $type = guess_image_type($mtch[1],true);
@ -1158,6 +1151,8 @@ function original_url($url, $depth=1, $fetchbody = false) {
$url = trim($url, "'"); $url = trim($url, "'");
$stamp1 = microtime(true);
$siteinfo = array(); $siteinfo = array();
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
@ -1172,6 +1167,8 @@ function original_url($url, $depth=1, $fetchbody = false) {
$http_code = $curl_info['http_code']; $http_code = $curl_info['http_code'];
curl_close($ch); curl_close($ch);
$a->save_timestamp($stamp1, "network");
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302")) if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) { AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "") if ($curl_info['redirect_url'] != "")
@ -1192,6 +1189,8 @@ function original_url($url, $depth=1, $fetchbody = false) {
if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html")) if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html"))
return($url); return($url);
$stamp1 = microtime(true);
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
@ -1203,6 +1202,8 @@ function original_url($url, $depth=1, $fetchbody = false) {
$body = curl_exec($ch); $body = curl_exec($ch);
curl_close($ch); curl_close($ch);
$a->save_timestamp($stamp1, "network");
if (trim($body) == "") if (trim($body) == "")
return($url); return($url);

View File

@ -11,7 +11,6 @@ function oembed_replacecb($matches){
function oembed_fetch_url($embedurl, $no_rich_type = false){ function oembed_fetch_url($embedurl, $no_rich_type = false){
$embedurl = trim($embedurl, "'"); $embedurl = trim($embedurl, "'");
$embedurl = trim($embedurl, '"'); $embedurl = trim($embedurl, '"');

View File

@ -52,7 +52,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
$a->last_ostatus_conversation_url = $conversation_url; $a->last_ostatus_conversation_url = $conversation_url;
$messages = q("SELECT `uid`, `parent`, `created` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); $messages = q("SELECT `uid`, `parent`, `created`, `received`, `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
if (!$messages) if (!$messages)
return; return;
$message = $messages[0]; $message = $messages[0];
@ -62,8 +62,9 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION)); intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION));
if (!$conversation) { if (!$conversation) {
$r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')", $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `created`, `received`, `guid`) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')",
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($message["created"]), dbesc($conversation_url)); intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION),
dbesc($message["created"]), dbesc($conversation_url), dbesc($message["created"]), dbesc($message["received"]), dbesc($message["guid"]));
logger('complete_conversation: Storing conversation url '.$conversation_url.' for id '.$itemid); logger('complete_conversation: Storing conversation url '.$conversation_url.' for id '.$itemid);
} }

View File

@ -9,7 +9,7 @@ function create_tags_from_item($itemid) {
$searchpath = $a->get_baseurl()."/search?tag="; $searchpath = $a->get_baseurl()."/search?tag=";
$messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `created`, `received`, `title`, `body`, `tag`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
if (!$messages) if (!$messages)
return; return;
@ -69,8 +69,22 @@ function create_tags_from_item($itemid) {
$term = $tag; $term = $tag;
} }
$r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')", if ($message["uid"] == 0) {
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term), dbesc($link)); $global = true;
q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
intval(TERM_OBJ_POST), dbesc($message["guid"]));
} else {
$isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
intval(TERM_OBJ_POST), dbesc($message["guid"]));
$global = (count($isglobal) > 0);
}
$r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `guid`, `created`, `received`, `global`)
VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d)",
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term),
dbesc($link), dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]), intval($global));
// Search for mentions // Search for mentions
if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) { if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) {
@ -96,10 +110,39 @@ function create_tags_from_itemuri($itemuri, $uid) {
} }
function update_items() { function update_items() {
//$messages = q("SELECT `id` FROM `item` where tag !='' ORDER BY `created` DESC limit 10"); global $db;
$messages = q("SELECT `id` FROM `item` where tag !=''");
foreach ($messages as $message) $messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''", true);
create_tags_from_item($message["id"]);
logger("fetched messages: ".count($messages));
while ($message = $db->qfetch()) {
if ($message["uid"] == 0) {
$global = true;
q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
intval(TERM_OBJ_POST), dbesc($message["guid"]));
} else {
$isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
intval(TERM_OBJ_POST), dbesc($message["guid"]));
$global = (count($isglobal) > 0);
}
q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s', `global` = %d WHERE `otype` = %d AND `oid` = %d",
dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]),
intval($global), intval(TERM_OBJ_POST), intval($message["oid"]));
}
$db->qclose();
$messages = $db->q("SELECT `guid` FROM `item` WHERE `uid` = 0", true);
logger("fetched messages: ".count($messages));
while ($message = $db->qfetch()) {
q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message["guid"]));
}
$db->qclose();
} }
?> ?>

22
include/tagupdate.php Normal file
View File

@ -0,0 +1,22 @@
<?php
require_once("boot.php");
require_once("include/tags.php");
global $a, $db;
if(is_null($a))
$a = new App;
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
load_config('config');
load_config('system');
update_items();
killme();
?>

View File

@ -1296,16 +1296,26 @@ function redir_private_images($a, &$item) {
}} }}
function put_item_in_cache($item) { function put_item_in_cache(&$item, $update = false) {
$cachefile = get_cachefile(urlencode($item["guid"])."-".hash("md5", $item['body']));
if (($item["rendered-hash"] != hash("md5", $item["body"])) OR ($item["rendered-hash"] == "") OR
($item["rendered-html"] == "") OR get_config("system", "ignore_cache")) {
// The function "redir_private_images" changes the body.
// I'm not sure if we should store it permanently, so we save the old value.
$body = $item["body"];
if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($item['body']);
$a = get_app(); $a = get_app();
$stamp1 = microtime(true); redir_private_images($a, $item);
file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file"); $item["rendered-html"] = prepare_text($item["body"]);
logger('put item '.$item["guid"].' into cachefile '.$cachefile); $item["rendered-hash"] = hash("md5", $item["body"]);
$item["body"] = $body;
if ($update AND ($item["id"] != 0)) {
q("UPDATE `item` SET `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
dbesc($item["rendered-html"]), dbesc($item["rendered-hash"]), intval($item["id"]));
}
} }
} }
@ -1359,28 +1369,8 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$item['hashtags'] = $hashtags; $item['hashtags'] = $hashtags;
$item['mentions'] = $mentions; $item['mentions'] = $mentions;
put_item_in_cache($item, true);
$cachefile = get_cachefile(urlencode($item["guid"])."-".hash("md5", $item['body'])); $s = $item["rendered-html"];
if (($cachefile != '')) {
if (file_exists($cachefile)) {
$stamp1 = microtime(true);
$s = file_get_contents($cachefile);
$a->save_timestamp($stamp1, "file");
} else {
redir_private_images($a, $item);
$s = prepare_text($item['body']);
$stamp1 = microtime(true);
file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
}
} else {
redir_private_images($a, $item);
$s = prepare_text($item['body']);
}
require_once("mod/proxy.php"); require_once("mod/proxy.php");
$s = proxy_parse_html($s); $s = proxy_parse_html($s);

View File

@ -746,14 +746,18 @@ function item_post(&$a) {
killme(); killme();
} }
// Fill the cache field
put_item_in_cache($datarray);
if($orig_post) { if($orig_post) {
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($datarray['title']), dbesc($datarray['title']),
dbesc($datarray['body']), dbesc($datarray['body']),
dbesc($datarray['tag']), dbesc($datarray['tag']),
dbesc($datarray['attach']), dbesc($datarray['attach']),
dbesc($datarray['file']), dbesc($datarray['file']),
dbesc($datarray['rendered-html']),
dbesc($datarray['rendered-hash']),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($post_id), intval($post_id),
@ -778,10 +782,10 @@ function item_post(&$a) {
$post_id = 0; $post_id = 0;
$r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `author-name`, `author-link`, `author-avatar`,
`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, `tag`, `inform`, `verb`, `object-type`, `postopts`,
`tag`, `inform`, `verb`, `object-type`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file` ) `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file`, `rendered-html`, `rendered-hash`)
VALUES( '%s', '%s', %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s' )", VALUES( '%s', '%s', %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s')",
dbesc($datarray['guid']), dbesc($datarray['guid']),
dbesc($datarray['extid']), dbesc($datarray['extid']),
intval($datarray['uid']), intval($datarray['uid']),
@ -823,21 +827,29 @@ function item_post(&$a) {
intval($datarray['bookmark']), intval($datarray['bookmark']),
intval($datarray['origin']), intval($datarray['origin']),
intval($datarray['moderated']), intval($datarray['moderated']),
dbesc($datarray['file']) dbesc($datarray['file']),
dbesc($datarray['rendered-html']),
dbesc($datarray['rendered-hash'])
); );
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($datarray['uri'])); dbesc($datarray['uri']));
if(count($r)) { if(!count($r)) {
logger('mod_item: unable to retrieve post that was just stored.');
notice( t('System error. Post not saved.') . EOL);
goaway($a->get_baseurl() . "/" . $return_path );
// NOTREACHED
}
$post_id = $r[0]['id']; $post_id = $r[0]['id'];
logger('mod_item: saved item ' . $post_id); logger('mod_item: saved item ' . $post_id);
$datarray["id"] = $post_id;
$datarray["plink"] = $a->get_baseurl().'/display/'.urlencode($datarray["guid"]);
// update filetags in pconfig // update filetags in pconfig
file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
// Store the fresh generated item into the cache
put_item_in_cache($datarray);
if($parent) { if($parent) {
// This item is the last leaf and gets the comment box, clear any ancestors // This item is the last leaf and gets the comment box, clear any ancestors
@ -930,13 +942,6 @@ function item_post(&$a) {
); );
update_thread($parent_item['id']); update_thread($parent_item['id']);
} }
}
else {
logger('mod_item: unable to retrieve post that was just stored.');
notice( t('System error. Post not saved.') . EOL);
goaway($a->get_baseurl() . "/" . $return_path );
// NOTREACHED
}
// update the commented timestamp on the parent // update the commented timestamp on the parent
@ -948,9 +953,6 @@ function item_post(&$a) {
if ($post_id != $parent) if ($post_id != $parent)
update_thread($parent); update_thread($parent);
$datarray['id'] = $post_id;
$datarray['plink'] = $a->get_baseurl().'/display/'.urlencode($datarray['guid']);
call_hooks('post_local_end', $datarray); call_hooks('post_local_end', $datarray);
if(strlen($emailcc) && $profile_uid == local_user()) { if(strlen($emailcc) && $profile_uid == local_user()) {

View File

@ -70,6 +70,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
$siteinfo["url"] = $url; $siteinfo["url"] = $url;
$siteinfo["type"] = "link"; $siteinfo["type"] = "link";
$stamp1 = microtime(true);
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HEADER, 1);
@ -84,6 +86,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
$http_code = $curl_info['http_code']; $http_code = $curl_info['http_code'];
curl_close($ch); curl_close($ch);
$a->save_timestamp($stamp1, "network");
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302") OR ($curl_info['http_code'] == "303") OR ($curl_info['http_code'] == "307")) if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302") OR ($curl_info['http_code'] == "303") OR ($curl_info['http_code'] == "307"))
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) { AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "") if ($curl_info['redirect_url'] != "")
@ -110,6 +114,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html")) if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html"))
return($siteinfo); return($siteinfo);
$stamp1 = microtime(true);
// Now fetch the body as well // Now fetch the body as well
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
@ -124,6 +130,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
$http_code = $curl_info['http_code']; $http_code = $curl_info['http_code'];
curl_close($ch); curl_close($ch);
$a->save_timestamp($stamp1, "network");
// Fetch the first mentioned charset. Can be in body or header // Fetch the first mentioned charset. Can be in body or header
$charset = ""; $charset = "";
if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches)) if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches))

View File

@ -127,66 +127,48 @@ function search_content(&$a) {
if (get_config('system','only_tag_search')) if (get_config('system','only_tag_search'))
$tag = true; $tag = true;
if($tag) {
$sql_extra = "";
$sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` IN (%d, 0)) AS `term` ON `item`.`id` = `term`.`oid` ",
dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
$sql_order = "`item`.`id`";
} else {
if (get_config('system','use_fulltext_engine')) {
$sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
} else {
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
}
$sql_table = "`item`";
$sql_order = "`item`.`id`";
//$sql_order = "`item`.`received`";
}
// Here is the way permissions work in the search module... // Here is the way permissions work in the search module...
// Only public posts can be shown // Only public posts can be shown
// OR your own posts if you are a logged in member // OR your own posts if you are a logged in member
// No items will be shown if the member has a blocked profile wall. // No items will be shown if the member has a blocked profile wall.
if(get_config('system', 'old_pager')) { if($tag) {
$r = q("SELECT distinct(`item`.`uri`) as `total` logger("Start tag search for '".$search."'", LOGGER_DEBUG);
FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
AND ((`item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `item`.`uid` = 0)
OR (`item`.`uid` = %d))
$sql_extra ",
intval(local_user())
);
if(count($r)) $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
$a->set_pager_total(count($r)); `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `term`
INNER JOIN `item` ON `item`.`id`=`term`.`oid`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s'
ORDER BY term.created DESC LIMIT %d , %d ",
intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)),
intval($a->pager['start']), intval($a->pager['itemspage']));
} else {
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
if(! count($r)) { if (get_config('system','use_fulltext_engine')) {
info( t('No results.') . EOL); $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
return $o; } else {
} $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
} }
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND ((`item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `item`.`uid`=0) AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND (`item`.`private` OR NOT `item`.`network` IN ('%s', '%s', '%s'))))
OR `item`.`uid` = %d)
$sql_extra $sql_extra
GROUP BY `item`.`uri` GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d ",
ORDER BY $sql_order DESC LIMIT %d , %d ", intval(local_user()), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']));
intval($a->pager['start']), }
intval($a->pager['itemspage'])
);
if(! count($r)) { if(! count($r)) {
info( t('No results.') . EOL); info( t('No results.') . EOL);
@ -199,13 +181,12 @@ function search_content(&$a) {
else else
$o .= '<h2>Search results for: ' . $search . '</h2>'; $o .= '<h2>Search results for: ' . $search . '</h2>';
logger("Start Conversation for '".$search."'", LOGGER_DEBUG);
$o .= conversation($a,$r,'search',false); $o .= conversation($a,$r,'search',false);
if(!get_config('system', 'old_pager')) {
$o .= alt_pager($a,count($r)); $o .= alt_pager($a,count($r));
} else {
$o .= paginate($a); logger("Done '".$search."'", LOGGER_DEBUG);
}
return $o; return $o;
} }

View File

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1180 ); define( 'UPDATE_VERSION' , 1181 );
/** /**
* *
@ -1640,3 +1640,11 @@ function update_1178() {
return UPDATE_SUCCESS; return UPDATE_SUCCESS;
} }
function update_1180() {
// Fill the new fields in the term table.
proc_run('php',"include/tagupdate.php");
return UPDATE_SUCCESS;
}

View File

@ -129,7 +129,7 @@ blockquote.shared_content {
/* headers */ /* headers */
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
margin: 0px 0px 5px 0px; margin: 5px 0px 5px 0px;
font-weight: normal; font-weight: normal;
line-height: normal; line-height: normal;
text-rendering: optimizelegibility; text-rendering: optimizelegibility;
@ -158,3 +158,7 @@ h5 {
h6 { h6 {
font-size: 14.95px; font-size: 14.95px;
} }
span.oembed, h4 {
margin: 0px 0px 0px 0px;
}