From 82820d8e952dc648af572a55b6e205d448cfa138 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jan 2013 20:54:18 +0100 Subject: [PATCH 01/28] Now the third most likely languages are shown. In "vier" the tag line is now suppressed. It saves a little bit of space - and is redundant. --- include/items.php | 19 +++++++++++++++++-- mod/item.php | 18 ++++++++++++++++-- object/Item.php | 24 ++++++++++++++++++++++-- view/theme/vier/style.css | 3 +++ 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/include/items.php b/include/items.php index 7eb090136f..6e856f9602 100755 --- a/include/items.php +++ b/include/items.php @@ -898,8 +898,23 @@ function item_store($arr,$force_parent = false) { require_once('library/langdet/Text/LanguageDetect.php'); $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']); $l = new Text_LanguageDetect; - $lng = $l->detectConfidence($naked_body); - $arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); + //$lng = $l->detectConfidence($naked_body); + //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); + $lng = $l->detect($naked_body, 3); + + if (sizeof($lng) > 0) { + $postopts = ""; + + foreach ($lng as $language => $score) { + if ($postopts == "") + $postopts = "lang="; + else + $postopts .= ":"; + + $postopts .= $language.";".$score; + } + $arr['postopts'] = $postopts; + } } $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); diff --git a/mod/item.php b/mod/item.php index 2ed1b812a4..8399b796dc 100644 --- a/mod/item.php +++ b/mod/item.php @@ -236,9 +236,23 @@ function item_post(&$a) { if (version_compare(PHP_VERSION, '5.3.0', '>=')) { $l = new Text_LanguageDetect; - $lng = $l->detectConfidence($naked_body); + //$lng = $l->detectConfidence($naked_body); + //$postopts = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); - $postopts = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : ''); + $lng = $l->detect($naked_body, 3); + + if (sizeof($lng) > 0) { + $postopts = ""; + + foreach ($lng as $language => $score) { + if ($postopts == "") + $postopts = "lang="; + else + $postopts .= ":"; + + $postopts .= $language.";".$score; + } + } logger('mod_item: detect language' . print_r($lng,true) . $naked_body, LOGGER_DATA); } diff --git a/object/Item.php b/object/Item.php index 0ea9954b0a..e5aaecacd7 100644 --- a/object/Item.php +++ b/object/Item.php @@ -213,8 +213,28 @@ class Item extends BaseObject { localize_item($item); if ($item["postopts"]) { - $langdata = explode(";", $item["postopts"]); - $langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)"; + //$langdata = explode(";", $item["postopts"]); + //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)"; + $langstr = ""; + if (substr($item["postopts"], 0, 5) == "lang=") { + $postopts = substr($item["postopts"], 5); + + $languages = explode(":", $postopts); + + if (sizeof($languages) == 1) { + $languages = array(); + $languages[] = $postopts; + } + + foreach ($languages as $language) { + $langdata = explode(";", $language); + if ($langstr != "") + $langstr .= ", "; + + //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)"; + $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0]; + } + } } $body = prepare_body($item,true); diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index f97fc2f590..dcf8d34253 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -1091,6 +1091,7 @@ border-bottom: 1px solid #D2D2D2; max-width: 660px; word-wrap: break-word; line-height: 1.36; + padding-bottom: 6px; } .wall-item-container .wall-item-content img { @@ -1304,7 +1305,9 @@ border-bottom: 1px solid #D2D2D2; .wall-item-tags { padding-top: 1px; padding-bottom: 2px; + display: none; } + .tag { color: rgb(153,153,153); padding-left: 3px; From 61c78711dfa9744e01c3acc9a3c5643c6a18b5cb Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 11 Jan 2013 01:20:16 +0100 Subject: [PATCH 02/28] Preparations for a new tag structure. Tags are now stored in a dedicated table. --- boot.php | 2 +- database.sql | 14 +++ include/items.php | 150 +++++++++++++++++------------- include/tags.php | 82 ++++++++++++++++ object/Item.php | 18 +++- update.php | 15 ++- view/theme/vier/profile_vcard.tpl | 2 +- view/theme/vier/style.css | 8 +- 8 files changed, 214 insertions(+), 77 deletions(-) create mode 100644 include/tags.php diff --git a/boot.php b/boot.php index a9e5998055..bf0f86eaee 100644 --- a/boot.php +++ b/boot.php @@ -14,7 +14,7 @@ require_once('include/features.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_VERSION', '3.1.1572' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1157 ); +define ( 'DB_UPDATE_VERSION', 1158 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/database.sql b/database.sql index 369637fe60..bc3c1aabd1 100644 --- a/database.sql +++ b/database.sql @@ -1118,3 +1118,17 @@ CREATE TABLE IF NOT EXISTS `userd` ( `username` char(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `tag` +-- + +CREATE TABLE IF NOT EXISTS `tag` ( + `iid` int(11) NOT NULL, + `tag` char(255) NOT NULL, + `link` char(255) NOT NULL, + PRIMARY KEY (`iid`, `tag`), + KEY `tag` (`tag`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/include/items.php b/include/items.php index 6e856f9602..b93f56e179 100755 --- a/include/items.php +++ b/include/items.php @@ -5,7 +5,7 @@ require_once('include/oembed.php'); require_once('include/salmon.php'); require_once('include/crypto.php'); require_once('include/Photo.php'); - +require_once('include/tags.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) { @@ -26,7 +26,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) } } - + // default permissions - anonymous user @@ -670,7 +670,7 @@ function get_atom_elements($feed,$item) { } // translate OStatus unfollow to activity streams if it happened to get selected - + if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow')) $res['verb'] = ACTIVITY_UNFOLLOW; @@ -721,7 +721,7 @@ function get_atom_elements($feed,$item) { if($child[NAMESPACE_ACTIVITY]['object-type'][0]['data']) { $res['object-type'] = $child[NAMESPACE_ACTIVITY]['object-type'][0]['data']; $res['object'] .= '' . $child[NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '' . "\n"; - } + } if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) $res['object'] .= '' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) @@ -759,7 +759,7 @@ function get_atom_elements($feed,$item) { $child = $rawobj[0]['child']; if($child[NAMESPACE_ACTIVITY]['object-type'][0]['data']) { $res['target'] .= '' . $child[NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '' . "\n"; - } + } if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) $res['target'] .= '' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) @@ -1032,7 +1032,7 @@ function item_store($arr,$force_parent = false) { logger('item_store: item parent was not found - ignoring item'); return 0; } - + $parent_deleted = 0; } } @@ -1072,6 +1072,7 @@ function item_store($arr,$force_parent = false) { if(count($r)) { $current_post = $r[0]['id']; + create_tags_from_item($r[0]['id']); logger('item_store: created item ' . $current_post); } else { @@ -1087,7 +1088,7 @@ function item_store($arr,$force_parent = false) { ); } - if((! $parent_id) || ($arr['parent-uri'] === $arr['uri'])) + if((! $parent_id) || ($arr['parent-uri'] === $arr['uri'])) $parent_id = $current_post; if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid)) @@ -1108,6 +1109,7 @@ function item_store($arr,$force_parent = false) { intval($parent_deleted), intval($current_post) ); + create_tags_from_item($current_post); $arr['id'] = $current_post; $arr['parent'] = $parent_id; @@ -1287,7 +1289,7 @@ function tag_deliver($uid,$item_id) { intval($item_id) ); - proc_run('php','include/notifier.php','tgroup',$item_id); + proc_run('php','include/notifier.php','tgroup',$item_id); } @@ -1358,7 +1360,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { if($contact['duplex'] && $contact['dfrn-id']) $idtosend = '0:' . $orig_id; if($contact['duplex'] && $contact['issued-id']) - $idtosend = '1:' . $orig_id; + $idtosend = '1:' . $orig_id; $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0); @@ -1376,7 +1378,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { break; case SSL_POLICY_SELFSIGN: $ssl_policy = 'self'; - break; + break; case SSL_POLICY_NONE: default: $ssl_policy = 'none'; @@ -1429,7 +1431,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { intval(($perm == 'rw') ? 1 : 0), intval($contact['id']) ); - $contact['writable'] = (string) 1 - intval($contact['writable']); + $contact['writable'] = (string) 1 - intval($contact['writable']); } } @@ -1573,7 +1575,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) logger('consume_feed: empty input'); return; } - + $feed = new SimplePie(); $feed->set_raw_data($xml); if($datedir) @@ -1609,7 +1611,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) { $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']; $new_name = $elems['name'][0]['data']; - } + } if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) { $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']); $photo_url = $elems['link'][0]['attribs']['']['href']; @@ -1652,12 +1654,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($contact['uid']) ); } - + $img->scaleImageSquare(175); - + $hash = $resource_id; $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 4); - + $img->scaleImage(80); $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 5); @@ -1666,7 +1668,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $a = get_app(); - q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' + q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", dbesc(datetime_convert()), dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.'.$img->getExt()), @@ -1716,7 +1718,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) * to contain a sparkle link and perhaps a photo. * */ - + $bdtext = sprintf( t('%s\'s birthday'), $contact['name']); $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' ) ; @@ -1733,7 +1735,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($bdtext2), dbesc('birthday') ); - + // update bdyear @@ -1825,6 +1827,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc(implode(',',$newtags)), intval($i[0]['id']) ); + create_tags_from_item($i[0]['id']); } } } @@ -1839,6 +1842,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($item['uri']), intval($importer['uid']) ); + create_tags_from_itemuri($item['uri'], $importer['uid']); } else { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', @@ -1849,6 +1853,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($uri), intval($importer['uid']) ); + create_tags_from_itemuri($uri, $importer['uid']); if($item['last-child']) { // ensure that last-child is set in case the comment that had it just got wiped. q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", @@ -1962,6 +1967,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($item_id), intval($importer['uid']) ); + create_tags_from_itemuri($item_id, $importer['uid']); } // update last-child if it changes @@ -2003,7 +2009,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($parent_uri) ); if($r && count($r)) - continue; + continue; } if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) { @@ -2026,6 +2032,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag), intval($r[0]['id']) ); + create_tags_from_item($r[0]['id']); } } } @@ -2109,6 +2116,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($item_id), intval($importer['uid']) ); + create_tags_from_itemuri($item_id, $importer['uid']); } // update last-child if it changes @@ -2246,7 +2254,7 @@ function local_delivery($importer,$data) { if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) { $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']; $new_name = $elems['name'][0]['data']; - } + } if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) { $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']); $photo_url = $elems['link'][0]['attribs']['']['href']; @@ -2285,12 +2293,12 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']) ); } - + $img->scaleImageSquare(175); - + $hash = $resource_id; $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 4); - + $img->scaleImage(80); $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 5); @@ -2299,7 +2307,7 @@ function local_delivery($importer,$data) { $a = get_app(); - q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' + q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", dbesc(datetime_convert()), dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.'.$img->getExt()), @@ -2358,17 +2366,17 @@ function local_delivery($importer,$data) { /** relocated user must have original key pair */ /*$newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data'])); $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));*/ - + logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG); - + // update contact $r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;", intval($importer['id']), intval($importer['importer_uid'])); - if ($r === false) + if ($r === false) return 1; $old = $r[0]; - + $x = q("UPDATE contact SET name = '%s', photo = '%s', @@ -2411,7 +2419,7 @@ function local_delivery($importer,$data) { if ($x === false) return 1; } - + // TODO // merge with current record, current contents have priority // update record, set url-updated @@ -2485,7 +2493,7 @@ function local_delivery($importer,$data) { $hash = random_string(); - + $r = q("INSERT INTO `intro` ( `uid`, `fid`, `contact-id`, `note`, `hash`, `datetime`, `blocked` ) VALUES( %d, %d, %d, '%s', '%s', '%s', %d )", intval($fsugg['uid']), @@ -2539,7 +2547,7 @@ function local_delivery($importer,$data) { $msg['uri'] = notags(unxmlify($base['id'][0]['data'])); $msg['parent-uri'] = notags(unxmlify($base['in-reply-to'][0]['data'])); $msg['created'] = datetime_convert(notags(unxmlify('UTC','UTC',$base['sentdate'][0]['data']))); - + dbesc_array($msg); $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg)) @@ -2563,12 +2571,12 @@ function local_delivery($importer,$data) { 'verb' => ACTIVITY_POST, 'otype' => 'mail' ); - + notification($notif_params); return 0; // NOTREACHED - } + } $community_page = 0; $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'community'); @@ -2582,7 +2590,7 @@ function local_delivery($importer,$data) { ); $importer['forum'] = (string) $community_page; } - + logger('local_delivery: feed item count = ' . $feed->get_item_quantity()); // process any deleted entries @@ -2692,14 +2700,14 @@ function local_delivery($importer,$data) { if(count($i)) { // For tags, the owner cannot remove the tag on the author's copy of the post. - + $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false); $author_remove = (($item['origin'] && $item['self']) ? true : false); - $author_copy = (($item['origin']) ? true : false); + $author_copy = (($item['origin']) ? true : false); if($owner_remove && $author_copy) continue; - if($author_remove || $owner_remove) { + if($author_remove || $owner_remove) { $tags = explode(',',$i[0]['tag']); $newtags = array(); if(count($tags)) { @@ -2711,6 +2719,7 @@ function local_delivery($importer,$data) { dbesc(implode(',',$newtags)), intval($i[0]['id']) ); + create_tags_from_item($i[0]['id']); } } } @@ -2725,6 +2734,7 @@ function local_delivery($importer,$data) { dbesc($item['uri']), intval($importer['importer_uid']) ); + create_tags_from_itemuri($item['uri'], $importer['importer_uid']); } else { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', @@ -2735,6 +2745,7 @@ function local_delivery($importer,$data) { dbesc($uri), intval($importer['importer_uid']) ); + create_tags_from_itemuri($uri, $importer['importer_uid']); if($item['last-child']) { // ensure that last-child is set in case the comment that had it just got wiped. q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", @@ -2742,7 +2753,7 @@ function local_delivery($importer,$data) { dbesc($item['parent-uri']), intval($item['uid']) ); - // who is the last child now? + // who is the last child now? $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `created` DESC LIMIT 1", dbesc($item['parent-uri']), @@ -2752,7 +2763,7 @@ function local_delivery($importer,$data) { q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']) ); - } + } } // if this is a relayed delete, propagate it to other recipients @@ -2846,11 +2857,11 @@ function local_delivery($importer,$data) { if(count($r)) { $iid = $r[0]['id']; if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { - + // do not accept (ignore) an earlier edit than one we currently have. if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) continue; - + logger('received updated comment' , LOGGER_DEBUG); $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($datarray['title']), @@ -2860,6 +2871,7 @@ function local_delivery($importer,$data) { dbesc($item_id), intval($importer['importer_uid']) ); + create_tags_from_itemuri($item_id, $importer['importer_uid']); proc_run('php',"include/notifier.php","comment-import",$iid); @@ -2896,14 +2908,14 @@ function local_delivery($importer,$data) { dbesc($datarray['verb']), dbesc($datarray['parent-uri']), dbesc($datarray['parent-uri']) - + ); if($r && count($r)) - continue; + continue; } if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) { - + $xo = parse_xml_string($datarray['object'],false); $xt = parse_xml_string($datarray['target'],false); @@ -2916,9 +2928,9 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']) ); if(! count($tagp)) - continue; + continue; - // extract tag, if not duplicate, and this user allows tags, add to parent item + // extract tag, if not duplicate, and this user allows tags, add to parent item if($xo->id && $xo->content) { $newtag = '#[url=' . $xo->id . ']'. $xo->content . '[/url]'; @@ -2932,9 +2944,10 @@ function local_delivery($importer,$data) { intval($tagp[0]['id']), dbesc(datetime_convert()) ); + create_tags_from_item($tagp[0]['id']); } } - } + } } } @@ -2951,7 +2964,7 @@ function local_delivery($importer,$data) { $parent = $r[0]['parent']; $parent_uri = $r[0]['parent-uri']; } - + if(! $is_like) { $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d", dbesc(datetime_convert()), @@ -2969,7 +2982,7 @@ function local_delivery($importer,$data) { if($posted_id && $parent) { proc_run('php',"include/notifier.php","comment-import","$posted_id"); - + if((! $is_like) && (! $importer['self'])) { require_once('include/enotify.php'); @@ -3032,6 +3045,7 @@ function local_delivery($importer,$data) { dbesc($item_id), intval($importer['importer_uid']) ); + create_tags_from_itemuri($item_id, $importer['importer_uid']); } // update last-child if it changes @@ -3068,7 +3082,7 @@ function local_delivery($importer,$data) { dbesc($parent_uri) ); if($r && count($r)) - continue; + continue; } @@ -3083,24 +3097,25 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']) ); if(! count($r)) - continue; + continue; - // extract tag, if not duplicate, add to parent item + // extract tag, if not duplicate, add to parent item if($xo->content) { if(! (stristr($r[0]['tag'],trim($xo->content)))) { q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'), intval($r[0]['id']) ); + create_tags_from_item($r[0]['id']); } - } + } } } $posted_id = item_store($datarray); // find out if our user is involved in this conversation and wants to be notified. - + if(!x($datarray['type']) || $datarray['type'] != 'activity') { $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", @@ -3114,11 +3129,11 @@ function local_delivery($importer,$data) { // first make sure this isn't our own post coming back to us from a wall-to-wall event if(! link_compare($datarray['author-link'],$importer_url)) { - + foreach($myconv as $conv) { // now if we find a match, it means we're in this conversation - + if(! link_compare($conv['author-link'],$importer_url)) continue; @@ -3206,6 +3221,7 @@ function local_delivery($importer,$data) { dbesc($item_id), intval($importer['importer_uid']) ); + create_tags_from_itemuri($item_id, $importer['importer_uid']); } // update last-child if it changes @@ -3329,7 +3345,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { // send email notification to owner? } else { - + // create contact record $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`, @@ -3352,7 +3368,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { if(count($r)) $contact_record = $r[0]; - // create notification + // create notification $hash = random_string(); if(is_array($contact_record)) { @@ -3390,7 +3406,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit' ); - + } } } @@ -3460,7 +3476,7 @@ function subscribe_to_hub($url,$importer,$contact,$hubmode = 'subscribe') { post_url($url,$params); logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG); - + return; } @@ -3793,16 +3809,16 @@ function item_expire($uid,$days) { $expire_items = get_pconfig($uid, 'expire','items'); $expire_items = (($expire_items===false)?1:intval($expire_items)); // default if not set: 1 - + $expire_notes = get_pconfig($uid, 'expire','notes'); $expire_notes = (($expire_notes===false)?1:intval($expire_notes)); // default if not set: 1 $expire_starred = get_pconfig($uid, 'expire','starred'); $expire_starred = (($expire_starred===false)?1:intval($expire_starred)); // default if not set: 1 - + $expire_photos = get_pconfig($uid, 'expire','photos'); $expire_photos = (($expire_photos===false)?0:intval($expire_photos)); // default if not set: 0 - + logger('expire: # items=' . count($r). "; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos"); foreach($r as $item) { @@ -3897,6 +3913,7 @@ function drop_item($id,$interactive = true) { dbesc(datetime_convert()), intval($item['id']) ); + create_tags_from_item($item['id']); // clean up categories and tags so they don't end up as orphans @@ -3962,6 +3979,7 @@ function drop_item($id,$interactive = true) { dbesc($item['parent-uri']), intval($item['uid']) ); + create_tags_from_item($item['parent-uri'], $item['uid']); // ignore the result } else { @@ -3971,7 +3989,7 @@ function drop_item($id,$interactive = true) { dbesc($item['parent-uri']), intval($item['uid']) ); - // who is the last child now? + // who is the last child now? $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1", dbesc($item['parent-uri']), intval($item['uid']) @@ -4003,7 +4021,7 @@ function drop_item($id,$interactive = true) { goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); //NOTREACHED } - + } diff --git a/include/tags.php b/include/tags.php new file mode 100644 index 0000000000..384d6581fa --- /dev/null +++ b/include/tags.php @@ -0,0 +1,82 @@ +set_baseurl(get_config('system','url')); +*/ + +function create_tags_from_item($itemid) { + global $a; + + $searchpath = $a->get_baseurl()."/search?tag="; + + $messages = q("SELECT `uri`, `uid`, `id`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + + if (!$messages) + return; + + $message = $messages[0]; + + // Clean up all tags + q("DELETE FROM `tag` WHERE `iid` = %d", intval($itemid)); + + if ($message["deleted"]) + return; + + $taglist = explode(",", $message["tag"]); + + $tags = ""; + foreach ($taglist as $tag) + if ((substr(trim($tag), 0, 1) == "#") OR (substr(trim($tag), 0, 1) == "@")) + $tags .= " ".trim($tag); + else + $tags .= " #".trim($tag); + + $data = " ".$message["title"]." ".$message["body"]." ".$tags." "; + + $tags = array(); + + $pattern = "/\W\#([^\[].*?)[\s'\".,:;\?!\[\]\/]/ism"; + if (preg_match_all($pattern, $data, $matches)) + foreach ($matches[1] as $match) + $tags["#".strtolower($match)] = $searchpath.strtolower($match); + + $pattern = "/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism"; + if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) + $tags[$match[1].strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2]; + } + + foreach ($tags as $tag=>$link) + $r = q("INSERT INTO `tag` (`iid`, `tag`, `link`) VALUES (%d, '%s', '%s')", + intval($itemid), dbesc($tag), dbesc($link)); +} + +function create_tags_from_itemuri($itemuri, $uid) { + $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); + + foreach ($messages as $message) + create_tags_from_item($message["id"]); +} + +function update_items() { + $messages = q("SELECT `id` FROM `item` where tag !='' ORDER BY `created` DESC LIMIT 100"); + + foreach ($messages as $message) + create_tags_from_item($message["id"]); +} + +//update_items(); +//create_tags_from_item(265194); +//create_tags_from_itemuri("infoagent@diasp.org:cce94abd104c06e8", 2); +?> diff --git a/object/Item.php b/object/Item.php index e5aaecacd7..215c987b19 100644 --- a/object/Item.php +++ b/object/Item.php @@ -148,7 +148,18 @@ class Item extends BaseObject { $tags=array(); $hashtags = array(); $mentions = array(); - foreach(explode(',',$item['tag']) as $tag){ + + $taglist = q("select tag,link from tag where iid=%d", intval($item['id'])); + + foreach($taglist as $tag) { + $tags[] = substr($tag["tag"], 0, 1)."".substr($tag["tag"], 1).""; + if (substr($tag["tag"], 0, 1) == "#") + $hashtags[] = "#".substr($tag["tag"], 1).""; + elseif (substr($tag["tag"], 0, 1) == "@") + $mentions[] = "@".substr($tag["tag"], 1).""; + } + + /*foreach(explode(',',$item['tag']) as $tag){ $tag = trim($tag); if ($tag!="") { $t = bbcode($tag); @@ -158,8 +169,7 @@ class Item extends BaseObject { elseif($t[0] == '@') $mentions[] = $t; } - - } + }*/ $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); @@ -270,7 +280,7 @@ class Item extends BaseObject { 'has_cats' => ((count($categories)) ? 'true' : ''), 'has_folders' => ((count($folders)) ? 'true' : ''), 'categories' => $categories, - 'folders' => $folders, + 'folders' => $folders, 'body' => $body_e, 'text' => $text_e, 'id' => $this->get_id(), diff --git a/update.php b/update.php index b29afdb741..7308a6acf7 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ {{ else }} -
+ {{ endif }} diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index dcf8d34253..aa66769db2 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -1305,16 +1305,16 @@ border-bottom: 1px solid #D2D2D2; .wall-item-tags { padding-top: 1px; padding-bottom: 2px; - display: none; + /*display: none;*/ } .tag { color: rgb(153,153,153); - padding-left: 3px; - font-size: 10px; + /*padding-left: 3px; + font-size: 10px;*/ } .tag a { - padding-right: 8px; + /*padding-right: 8px;*/ color: rgb(153,153,153); } .wwto { From c26cf428a67de6b2c8f05eedc8ac6ac4886e4161 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 11 Jan 2013 08:51:58 +0100 Subject: [PATCH 03/28] The search now searches in the new tag table --- mod/search.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mod/search.php b/mod/search.php index 956816fed0..6694fbc780 100644 --- a/mod/search.php +++ b/mod/search.php @@ -136,6 +136,11 @@ function search_content(&$a) { $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); } + if($tag) { + $sql_extra = sprintf(" AND `tag`.`tag` = '%s' ", '#'.dbesc(protect_sprintf($search))); + $sql_table = "`tag` LEFT JOIN `item` ON `item`.`id` = `tag`.`iid`"; + } else + $sql_table = "`item`"; @@ -146,7 +151,7 @@ function search_content(&$a) { if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) { $r = q("SELECT distinct(`item`.`uri`) as `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` 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 `user`.`hidewall` = 0) OR `item`.`uid` = %d ) @@ -169,7 +174,7 @@ function search_content(&$a) { `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, `user`.`nickname` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` 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 `user`.`hidewall` = 0 ) From 8cef0fa80d63e72fe0adb14aaa43eb9c23702a49 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 13 Jan 2013 09:37:15 +0100 Subject: [PATCH 04/28] Mentions are now displayed much faster. Attention: The related database update can last more than one minute. bbcode: The generated HTML is now cleaned up every time (using the DOM) since it happened that bad html broke the network page. --- boot.php | 2 +- database.sql | 2 ++ include/api.php | 29 +++++++++++++++++------------ include/bbcode.php | 5 +++-- include/tags.php | 7 ++++--- mod/item.php | 3 +++ mod/network.php | 10 ++++++++-- mod/search.php | 3 +++ update.php | 8 +++++++- 9 files changed, 48 insertions(+), 21 deletions(-) diff --git a/boot.php b/boot.php index bf0f86eaee..7bd0fec4db 100644 --- a/boot.php +++ b/boot.php @@ -14,7 +14,7 @@ require_once('include/features.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_VERSION', '3.1.1572' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1158 ); +define ( 'DB_UPDATE_VERSION', 1159 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/database.sql b/database.sql index bc3c1aabd1..f7fdfa3d9e 100644 --- a/database.sql +++ b/database.sql @@ -546,6 +546,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `deleted` tinyint(1) NOT NULL DEFAULT '0', `origin` tinyint(1) NOT NULL DEFAULT '0', `forum_mode` tinyint(1) NOT NULL DEFAULT '0', + `mention` tinyint(1) NOT NULL DEFAULT '0', `last-child` tinyint(1) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `uri` (`uri`), @@ -575,6 +576,7 @@ CREATE TABLE IF NOT EXISTS `item` ( KEY `uid_commented` (`uid`, `commented`), KEY `uid_created` (`uid`, `created`), KEY `uid_unseen` (`uid`, `unseen`), + KEY `mention` (`mention`), FULLTEXT KEY `title` (`title`), FULLTEXT KEY `body` (`body`), FULLTEXT KEY `allow_cid` (`allow_cid`), diff --git a/include/api.php b/include/api.php index 2c5ddc626f..1b33378b0a 100644 --- a/include/api.php +++ b/include/api.php @@ -1040,18 +1040,23 @@ $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - if (get_config('system','use_fulltext_engine')) - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", - dbesc(protect_sprintf($myurl)), - dbesc(protect_sprintf($myurl)), - dbesc(protect_sprintf($diasp_url)) - ); - else - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", - dbesc(protect_sprintf('%' . $myurl)), - dbesc(protect_sprintf('%' . $myurl . ']%')), - dbesc(protect_sprintf('%' . $diasp_url . ']%')) - ); + /*if (get_config('system','use_fulltext_engine')) + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($diasp_url)) + ); + else + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", + dbesc(protect_sprintf('%' . $myurl)), + dbesc(protect_sprintf('%' . $myurl . ']%')), + dbesc(protect_sprintf('%' . $diasp_url . ']%')) + );*/ + + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($myurl)) + ); if ($max_id > 0) $sql_extra .= ' AND `item`.`id` <= '.intval($max_id); diff --git a/include/bbcode.php b/include/bbcode.php index 08edc19340..a7cfa079d1 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -603,7 +603,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Clean up the HTML by loading and saving the HTML with the DOM // Only do it when it has to be done - for performance reasons - if (!$tryoembed) { + // Update: Now it is done every time - since bad structured html can break a whole page + //if (!$tryoembed) { $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; @@ -618,7 +619,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace('
','', $Text); $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); - } + //} call_hooks('bbcode',$Text); diff --git a/include/tags.php b/include/tags.php index 384d6581fa..aabe40d1c6 100644 --- a/include/tags.php +++ b/include/tags.php @@ -20,7 +20,7 @@ function create_tags_from_item($itemid) { $searchpath = $a->get_baseurl()."/search?tag="; - $messages = q("SELECT `uri`, `uid`, `id`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + $messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); if (!$messages) return; @@ -58,8 +58,9 @@ function create_tags_from_item($itemid) { } foreach ($tags as $tag=>$link) - $r = q("INSERT INTO `tag` (`iid`, `tag`, `link`) VALUES (%d, '%s', '%s')", - intval($itemid), dbesc($tag), dbesc($link)); + $r = q("INSERT INTO `tag` (`iid`, `tag`, `link`, `created`, `edited`, `commented`, `received`, `changed`) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", + intval($itemid), dbesc($tag), dbesc($link), dbesc($message["created"]), + dbesc($message["edited"]), dbesc($message["commented"]), dbesc($message["received"]), dbesc($message["changed"])); } function create_tags_from_itemuri($itemuri, $uid) { diff --git a/mod/item.php b/mod/item.php index 8399b796dc..7096239b0f 100644 --- a/mod/item.php +++ b/mod/item.php @@ -19,6 +19,7 @@ require_once('include/crypto.php'); require_once('include/enotify.php'); require_once('include/email.php'); require_once('library/langdet/Text/LanguageDetect.php'); +require_once('include/tags.php'); function item_post(&$a) { @@ -685,6 +686,7 @@ function item_post(&$a) { intval($post_id), intval($profile_uid) ); + create_tags_from_itemuri($post_id, $profile_uid); // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); @@ -750,6 +752,7 @@ function item_post(&$a) { if(count($r)) { $post_id = $r[0]['id']; logger('mod_item: saved item ' . $post_id); + create_tags_from_item($post_id); // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); diff --git a/mod/network.php b/mod/network.php index 2524ae0634..ecef7c1dfb 100644 --- a/mod/network.php +++ b/mod/network.php @@ -674,8 +674,10 @@ function network_content(&$a, $update = 0) { $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace('www.','',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - if (get_config('system','use_fulltext_engine')) + /*if (get_config('system','use_fulltext_engine')) $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", + //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (`author-link` IN ('https://%s', 'http://%s') OR MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", + //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($diasp_url)) @@ -685,8 +687,12 @@ function network_content(&$a, $update = 0) { dbesc(protect_sprintf('%' . $myurl)), dbesc(protect_sprintf('%' . $myurl . ']%')), dbesc(protect_sprintf('%' . $diasp_url . ']%')) - ); + );*/ + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($myurl)) + ); } if($update) { diff --git a/mod/search.php b/mod/search.php index 6694fbc780..aedd639403 100644 --- a/mod/search.php +++ b/mod/search.php @@ -124,6 +124,9 @@ function search_content(&$a) { if(! $search) return $o; + if (get_config('system','only_tag_search')) + $tag = true; + if (get_config('system','use_fulltext_engine')) { if($tag) $sql_extra = sprintf(" AND MATCH (`item`.`tag`) AGAINST ('".'"%s"'."' in boolean mode) ", '#'.dbesc(protect_sprintf($search))); diff --git a/update.php b/update.php index 7308a6acf7..04ae451a1c 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Sun, 13 Jan 2013 14:50:55 +0100 Subject: [PATCH 05/28] Changing the tag system to the "term" table. --- boot.php | 3 ++- database.sql | 26 ++++++++++++++----------- include/api.php | 9 +++++---- include/tags.php | 50 ++++++++++++++++++++++++++++++++++++++++-------- mod/network.php | 4 +++- mod/search.php | 23 +++++++++++++--------- object/Item.php | 21 ++++++++++++++------ update.php | 11 ++++------- 8 files changed, 100 insertions(+), 47 deletions(-) diff --git a/boot.php b/boot.php index 7bd0fec4db..6864e533d8 100644 --- a/boot.php +++ b/boot.php @@ -204,10 +204,11 @@ define ( 'NOTIFY_SYSTEM', 0x8000 ); define ( 'TERM_UNKNOWN', 0 ); define ( 'TERM_HASHTAG', 1 ); -define ( 'TERM_MENTION', 2 ); +define ( 'TERM_MENTION', 2 ); define ( 'TERM_CATEGORY', 3 ); define ( 'TERM_PCATEGORY', 4 ); define ( 'TERM_FILE', 5 ); +define ( 'TERM_SAVEDSEARCH', 6 ); define ( 'TERM_OBJ_POST', 1 ); define ( 'TERM_OBJ_PHOTO', 2 ); diff --git a/database.sql b/database.sql index f7fdfa3d9e..99d60429ae 100644 --- a/database.sql +++ b/database.sql @@ -1017,18 +1017,22 @@ CREATE TABLE IF NOT EXISTS `spam` ( -- CREATE TABLE IF NOT EXISTS `term` ( - `tid` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `oid` INT UNSIGNED NOT NULL , - `otype` TINYINT( 3 ) UNSIGNED NOT NULL , - `type` TINYINT( 3 ) UNSIGNED NOT NULL , - `term` CHAR( 255 ) NOT NULL , - `url` CHAR( 255 ) NOT NULL, + `tid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `aid` int(10) unsigned NOT NULL DEFAULT '0', + `uid` int(10) unsigned NOT NULL DEFAULT '0', + `oid` int(10) unsigned NOT NULL, + `otype` tinyint(3) unsigned NOT NULL, + `type` tinyint(3) unsigned NOT NULL, + `term` char(255) NOT NULL, + `url` char(255) NOT NULL, PRIMARY KEY (`tid`), - KEY `oid` ( `oid` ), - KEY `otype` ( `otype` ), - KEY `type` ( `type` ), - KEY `term` ( `term` ) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; + KEY `oid` (`oid`), + KEY `otype` (`otype`), + KEY `type` (`type`), + KEY `term` (`term`), + KEY `uid` (`uid`), + KEY `aid` (`aid`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- diff --git a/include/api.php b/include/api.php index 1b33378b0a..4efb0c614a 100644 --- a/include/api.php +++ b/include/api.php @@ -1037,10 +1037,11 @@ $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname']; $myurl = substr($myurl,strpos($myurl,'://')+3); - $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); + //$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); + $myurl = str_replace('www.','',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - /*if (get_config('system','use_fulltext_engine')) +/* if (get_config('system','use_fulltext_engine')) $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($myurl)), @@ -1051,8 +1052,8 @@ dbesc(protect_sprintf('%' . $myurl)), dbesc(protect_sprintf('%' . $myurl . ']%')), dbesc(protect_sprintf('%' . $diasp_url . ']%')) - );*/ - + ); +*/ $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($myurl)) diff --git a/include/tags.php b/include/tags.php index aabe40d1c6..6a5728a9ba 100644 --- a/include/tags.php +++ b/include/tags.php @@ -12,12 +12,17 @@ if(is_null($db)) { unset($db_host, $db_user, $db_pass, $db_data); }; -$a->set_baseurl(get_config('system','url')); +$a->set_baseurl("https://pirati.ca"); */ function create_tags_from_item($itemid) { global $a; + $profile_base = $a->get_baseurl(); + $profile_data = parse_url($profile_base); + $profile_base_friendica = $profile_data['host'].$profile_data['path']."/profile/"; + $profile_base_diaspora = $profile_data['host'].$profile_data['path']."/u/"; + $searchpath = $a->get_baseurl()."/search?tag="; $messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); @@ -28,7 +33,11 @@ function create_tags_from_item($itemid) { $message = $messages[0]; // Clean up all tags - q("DELETE FROM `tag` WHERE `iid` = %d", intval($itemid)); + q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + intval(TERM_OBJ_POST), + intval($itemid), + intval(TERM_HASHTAG), + intval(TERM_MENTION)); if ($message["deleted"]) return; @@ -49,7 +58,7 @@ function create_tags_from_item($itemid) { $pattern = "/\W\#([^\[].*?)[\s'\".,:;\?!\[\]\/]/ism"; if (preg_match_all($pattern, $data, $matches)) foreach ($matches[1] as $match) - $tags["#".strtolower($match)] = $searchpath.strtolower($match); + $tags["#".strtolower($match)] = ""; // $searchpath.strtolower($match); $pattern = "/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism"; if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) { @@ -57,10 +66,31 @@ function create_tags_from_item($itemid) { $tags[$match[1].strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2]; } - foreach ($tags as $tag=>$link) - $r = q("INSERT INTO `tag` (`iid`, `tag`, `link`, `created`, `edited`, `commented`, `received`, `changed`) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", - intval($itemid), dbesc($tag), dbesc($link), dbesc($message["created"]), - dbesc($message["edited"]), dbesc($message["commented"]), dbesc($message["received"]), dbesc($message["changed"])); + foreach ($tags as $tag=>$link) { + + if (substr(trim($tag), 0, 1) == "#") { + $type = TERM_HASHTAG; + $term = substr($tag, 1); + } elseif (substr(trim($tag), 0, 1) == "@") { + $type = TERM_MENTION; + $term = substr($tag, 1); + } else { // This shouldn't happen + $type = TERM_HASHTAG; + $term = $tag; + } + + $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')", + intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term), dbesc($link)); + + // Search for mentions + if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) { + $users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link); + foreach ($users AS $user) { + if ($user["uid"] == $message["uid"]) + q("UPDATE `item` SET `mention` = 1 WHERE `id` = %d", intval($itemid)); + } + } + } } function create_tags_from_itemuri($itemuri, $uid) { @@ -71,12 +101,16 @@ function create_tags_from_itemuri($itemuri, $uid) { } function update_items() { - $messages = q("SELECT `id` FROM `item` where tag !='' ORDER BY `created` DESC LIMIT 100"); + //$messages = q("SELECT `id` FROM `item` where tag !='' ORDER BY `created` DESC limit 10"); + $messages = q("SELECT `id` FROM `item` where tag !=''"); foreach ($messages as $message) create_tags_from_item($message["id"]); } +//print_r($tags); +//print_r($hashtags); +//print_r($mentions); //update_items(); //create_tags_from_item(265194); //create_tags_from_itemuri("infoagent@diasp.org:cce94abd104c06e8", 2); diff --git a/mod/network.php b/mod/network.php index ecef7c1dfb..4a8b54762c 100644 --- a/mod/network.php +++ b/mod/network.php @@ -689,7 +689,9 @@ function network_content(&$a, $update = 0) { dbesc(protect_sprintf('%' . $diasp_url . ']%')) );*/ - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", + //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", + //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `mention`)", + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s'))", dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($myurl)) ); diff --git a/mod/search.php b/mod/search.php index aedd639403..c6d5989fb5 100644 --- a/mod/search.php +++ b/mod/search.php @@ -23,7 +23,7 @@ function search_saved_searches() { ); } - + $tpl = get_markup_template("saved_searches_aside.tpl"); $o .= replace_macros($tpl, array( @@ -32,7 +32,7 @@ function search_saved_searches() { '$searchbox' => '', '$saved' => $saved, )); - } + } return $o; @@ -127,7 +127,7 @@ function search_content(&$a) { if (get_config('system','only_tag_search')) $tag = true; - if (get_config('system','use_fulltext_engine')) { + /*if (get_config('system','use_fulltext_engine')) { if($tag) $sql_extra = sprintf(" AND MATCH (`item`.`tag`) AGAINST ('".'"%s"'."' in boolean mode) ", '#'.dbesc(protect_sprintf($search))); else @@ -137,15 +137,20 @@ function search_content(&$a) { $sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ", dbesc('\\]' . protect_sprintf(preg_quote($search)) . '\\[')); else $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); - } + }*/ if($tag) { - $sql_extra = sprintf(" AND `tag`.`tag` = '%s' ", '#'.dbesc(protect_sprintf($search))); - $sql_table = "`tag` LEFT JOIN `item` ON `item`.`id` = `tag`.`iid`"; - } else + $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d", + dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); + $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + } 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`"; - - + } // Here is the way permissions work in the search module... // Only public posts can be shown diff --git a/object/Item.php b/object/Item.php index 215c987b19..648b558071 100644 --- a/object/Item.php +++ b/object/Item.php @@ -145,18 +145,27 @@ class Item extends BaseObject { call_hooks('render_location',$locate); $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); + $searchpath = $a->get_baseurl()."/search?tag="; $tags=array(); $hashtags = array(); $mentions = array(); - $taglist = q("select tag,link from tag where iid=%d", intval($item['id'])); + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); foreach($taglist as $tag) { - $tags[] = substr($tag["tag"], 0, 1)."".substr($tag["tag"], 1).""; - if (substr($tag["tag"], 0, 1) == "#") - $hashtags[] = "#".substr($tag["tag"], 1).""; - elseif (substr($tag["tag"], 0, 1) == "@") - $mentions[] = "@".substr($tag["tag"], 1).""; + + if ($tag["url"] == "") + $tag["url"] = $searchpath.strtolower($tag["term"]); + + if ($tag["type"] == TERM_HASHTAG) { + $hashtags[] = "#".$tag["term"].""; + $prefix = "#"; + } elseif ($tag["type"] == TERM_MENTION) { + $mentions[] = "@".$tag["term"].""; + $prefix = "@"; + } + $tags[] = $prefix."".$tag["term"].""; } /*foreach(explode(',',$item['tag']) as $tag){ diff --git a/update.php b/update.php index 04ae451a1c..4bee3a3bc1 100644 --- a/update.php +++ b/update.php @@ -1371,13 +1371,10 @@ ADD INDEX ( `datasize` ) "); } function update_1157() { - $r = q("CREATE TABLE IF NOT EXISTS `tag` ( - `iid` int(11) NOT NULL, - `tag` char(255) NOT NULL, - `link` char(255) NOT NULL, - PRIMARY KEY (`iid`, `tag`), - KEY `tag` (`tag`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + $r = q("ALTER TABLE `term` ADD `aid` int(10) unsigned NOT NULL DEFAULT '0', + ADD `uid` int(10) unsigned NOT NULL DEFAULT '0', + ADD INDEX (`uid`), + ADD INDEX (`aid`)"); if(!$r) return UPDATE_FAILED; return UPDATE_SUCCESS; From 3dc615dd9ddbd068f83ced55138e0f4f7a882ebe Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 13 Jan 2013 15:05:24 +0100 Subject: [PATCH 06/28] Adding the tag creating function to the function when a photo is tagged --- mod/photos.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/photos.php b/mod/photos.php index 7035c66904..118149227e 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -5,7 +5,7 @@ require_once('include/acl_selectors.php'); require_once('include/bbcode.php'); require_once('include/security.php'); require_once('include/redir.php'); - +require_once('include/tags.php'); function photos_init(&$a) { @@ -559,6 +559,7 @@ function photos_post(&$a) { intval($item_id), intval($page_owner_uid) ); + create_tags_from_item($item_id); $best = 0; foreach($p as $scales) { From b9afb38f4d73c7a2c0e3c375a7a207fd6f6bfba7 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 13 Jan 2013 15:11:06 +0100 Subject: [PATCH 07/28] Some more function calls to ensure that the tags are deleted when an item is deleted --- mod/photos.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 118149227e..37aab7c1f2 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -228,6 +228,7 @@ function photos_post(&$a) { dbesc($rr['parent-uri']), intval($page_owner_uid) ); + create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid); $drop_id = intval($rr['id']); @@ -275,6 +276,7 @@ function photos_post(&$a) { dbesc($i[0]['uri']), intval($page_owner_uid) ); + create_tags_from_itemuri($i[0]['uri'], $page_owner_uid); $url = $a->get_baseurl(); $drop_id = intval($i[0]['id']); @@ -335,7 +337,7 @@ function photos_post(&$a) { $ph->scaleImage(640); $width = $ph->getWidth(); $height = $ph->getHeight(); - + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1 limit 1", dbesc($ph->imageString()), intval($height), @@ -357,7 +359,7 @@ function photos_post(&$a) { dbesc($resource_id), intval($page_owner_uid) ); - } + } } } } @@ -835,8 +837,8 @@ function photos_post(&$a) { intval($item_id) ); } - - if($visible) + + if($visible) proc_run('php', "include/notifier.php", 'wall-new', $item_id); call_hooks('photo_post_end',intval($item_id)); @@ -1341,7 +1343,7 @@ function photos_content(&$a) { intval($a->pager['itemspage']) ); - + if((local_user()) && (local_user() == $link_item['uid'])) { q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d", intval($link_item['parent']), From 5501dd0759cdec41f74b4bc104fca526ecbb0eef Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 13 Jan 2013 17:13:01 +0100 Subject: [PATCH 08/28] Searching for tags has been enabled in all places. The tag detection has been improved for imports with missing line feeds. --- include/conversation.php | 23 ++++++++++++++-- include/dba.php | 2 +- include/network.php | 18 ++++++------ include/text.php | 5 ++-- mod/content.php | 59 ++++++++++++++++++++++++++++------------ mod/network.php | 56 +++++++++++++++++++++++++------------- 6 files changed, 112 insertions(+), 51 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 9420d8b74a..7665342739 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -523,7 +523,26 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $tags=array(); $hashtags = array(); $mentions = array(); - foreach(explode(',',$item['tag']) as $tag){ + + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); + + foreach($taglist as $tag) { + + if ($tag["url"] == "") + $tag["url"] = $searchpath.strtolower($tag["term"]); + + if ($tag["type"] == TERM_HASHTAG) { + $hashtags[] = "#".$tag["term"].""; + $prefix = "#"; + } elseif ($tag["type"] == TERM_MENTION) { + $mentions[] = "@".$tag["term"].""; + $prefix = "@"; + } + $tags[] = $prefix."".$tag["term"].""; + } + + /*foreach(explode(',',$item['tag']) as $tag){ $tag = trim($tag); if ($tag!="") { $t = bbcode($tag); @@ -533,7 +552,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { elseif($t[0] == '@') $mentions[] = $t; } - } + }*/ $sp = false; $profile_link = best_link_url($item,$sp); diff --git a/include/dba.php b/include/dba.php index ad33705bf1..a9f70aa40d 100644 --- a/include/dba.php +++ b/include/dba.php @@ -89,7 +89,7 @@ class dba { if(x($a->config,'system') && x($a->config['system'],'db_log')) { $stamp2 = microtime(true); $duration = round($stamp2-$stamp1, 3); - if ($duration > $a->config["system"]["db_loglimit"]) { + if (($duration > $a->config["system"]["db_loglimit"])) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @file_put_contents($a->config["system"]["db_log"], $duration."\t". basename($backtrace[1]["file"])."\t". diff --git a/include/network.php b/include/network.php index f6e6cc2a30..1ecee598cf 100644 --- a/include/network.php +++ b/include/network.php @@ -918,7 +918,7 @@ function fix_contact_ssl_policy(&$contact,$new_policy) { * Return: The parsed XML in an array form. Use print_r() to see the resulting array structure. * Examples: $array = xml2array(file_get_contents('feed.xml')); * $array = xml2array(file_get_contents('feed.xml', true, 1, 'attribute')); - */ + */ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = 'attribute') { if(!$contents) return array(); @@ -976,7 +976,7 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = $result = array(); $attributes_data = array(); - + if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; // Put the value in a assoc array if we are in the 'Attribute' mode @@ -992,7 +992,7 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = // See tag status and do the needed. if($namespaces && strpos($tag,':')) { - $namespc = substr($tag,0,strrpos($tag,':')); + $namespc = substr($tag,0,strrpos($tag,':')); $tag = strtolower(substr($tag,strlen($namespc)+1)); $result['@namespace'] = $namespc; } @@ -1015,7 +1015,7 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = } else { // This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result); // This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; - + if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); @@ -1038,7 +1038,7 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; - + if($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } @@ -1049,11 +1049,11 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well - + $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } - + if($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } @@ -1066,6 +1066,6 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = $current = &$parent[$level-1]; } } - + return($xml_array); -} +} diff --git a/include/text.php b/include/text.php index 1d74d9cf5c..5b64ef2f94 100644 --- a/include/text.php +++ b/include/text.php @@ -562,11 +562,12 @@ function get_tags($s) { $ret = array(); // ignore anything in a code block - $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s); - // ignore anything in a bbtag + // Force line feeds at bbtags + $s = str_replace(array("[", "]"), array("\n[", "]\n"), $s); + // ignore anything in a bbtag $s = preg_replace('/\[(.*?)\]/sm','',$s); // Match full names against @tags including the space between first and last diff --git a/mod/content.php b/mod/content.php index 318c37233c..06f5d58b22 100644 --- a/mod/content.php +++ b/mod/content.php @@ -160,16 +160,26 @@ function content_content(&$a, $update = 0) { $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); $sql_extra3 = (($nouveau) ? '' : $sql_extra3); + $sql_table = "`item`"; if(x($_GET,'search')) { $search = escape_tags($_GET['search']); - if (get_config('system','use_fulltext_engine')) { + + if(strpos($search,'#') === 0) { + $tag = true; + $search = substr($search,1); + } + + if (get_config('system','only_tag_search')) + $tag = true; + + /*if (get_config('system','use_fulltext_engine')) { if(strpos($search,'#') === 0) - $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ", + $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('%s' in boolean mode)) ", dbesc(protect_sprintf($search)) ); else - $sql_extra .= sprintf(" AND (MATCH(`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ", + $sql_extra .= sprintf(" AND (MATCH(`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode)) ", dbesc(protect_sprintf($search)), dbesc(protect_sprintf($search)) ); @@ -178,7 +188,19 @@ function content_content(&$a, $update = 0) { dbesc(protect_sprintf('%' . $search . '%')), dbesc(protect_sprintf('%]' . $search . '[%')) ); + }*/ + + if($tag) { + $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", + dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); + $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + } 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)))); } + } if(strlen($file)) { $sql_extra .= file_tag_file_query('item',unxmlify($file)); @@ -189,38 +211,39 @@ function content_content(&$a, $update = 0) { $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace('www.','',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - if (get_config('system','use_fulltext_engine')) - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ", + /*if (get_config('system','use_fulltext_engine')) + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from $sql_table where (MATCH(`author-link`, `tag`) AGAINST ('%s' in boolean mode) or MATCH(tag) AGAINST ('%s' in boolean mode))) ", dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($diasp_url)) ); else - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from $sql_table where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", dbesc(protect_sprintf('%' . $myurl)), dbesc(protect_sprintf('%' . $myurl . ']%')), dbesc(protect_sprintf('%' . $diasp_url . ']%')) - ); + );*/ + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", + dbesc(protect_sprintf($myurl)), + dbesc(protect_sprintf($myurl)) + ); } $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - - if($nouveau) { // "New Item View" - show all items unthreaded in reverse created date order - $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, + $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item`, `contact` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 $simple_update - AND `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra $sql_nets ORDER BY `item`.`received` DESC $pager_sql ", @@ -241,7 +264,7 @@ function content_content(&$a, $update = 0) { $start = dba_timer(); $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = `item`.`id` @@ -268,9 +291,9 @@ function content_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item`, `contact` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 - AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id` + AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` IN ( %s ) $sql_extra ", @@ -287,7 +310,7 @@ function content_content(&$a, $update = 0) { } } - + logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start)); logger('child dba_timer: ' . sprintf('%01.4f',$second - $first)); @@ -298,7 +321,7 @@ function content_content(&$a, $update = 0) { $o = render_content($a,$items,$mode,false); - + header('Content-type: application/json'); echo json_encode($o); killme(); diff --git a/mod/network.php b/mod/network.php index 4a8b54762c..872c34da95 100644 --- a/mod/network.php +++ b/mod/network.php @@ -6,7 +6,7 @@ function network_init(&$a) { notice( t('Permission denied.') . EOL); return; } - + $is_a_date_query = false; if($a->argc > 1) { @@ -17,12 +17,12 @@ function network_init(&$a) { } } } - + // convert query string to array and remove first element (which is friendica args) $query_array = array(); parse_str($a->query_string, $query_array); array_shift($query_array); - + // fetch last used network view and redirect if needed if(! $is_a_date_query) { $sel_tabs = network_query_get_sel_tab($a); @@ -141,11 +141,11 @@ function network_init(&$a) { if(x($_GET['nets']) && $_GET['nets'] === 'all') unset($_GET['nets']); - + $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0); set_pconfig(local_user(), 'network.view', 'group.selected', $group_id); - + require_once('include/group.php'); require_once('include/contact_widgets.php'); require_once('include/items.php'); @@ -500,7 +500,7 @@ function network_content(&$a, $update = 0) { - + $contact_id = $a->cid; @@ -645,16 +645,26 @@ function network_content(&$a, $update = 0) { $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); $sql_extra3 = (($nouveau) ? '' : $sql_extra3); + $sql_table = "`item`"; if(x($_GET,'search')) { $search = escape_tags($_GET['search']); - if (get_config('system','use_fulltext_engine')) { + + if(strpos($search,'#') === 0) { + $tag = true; + $search = substr($search,1); + } + + if (get_config('system','only_tag_search')) + $tag = true; + + /*if (get_config('system','use_fulltext_engine')) { if(strpos($search,'#') === 0) $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ", dbesc(protect_sprintf($search)) ); else - $sql_extra .= sprintf(" AND (MATCH(`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ", + $sql_extra .= sprintf(" AND (MATCH(`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode)) ", dbesc(protect_sprintf($search)), dbesc(protect_sprintf($search)) ); @@ -663,6 +673,17 @@ function network_content(&$a, $update = 0) { dbesc(protect_sprintf('%' . $search . '%')), dbesc(protect_sprintf('%]' . $search . '[%')) ); + }*/ + + if($tag) { + $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", + dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); + $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + } 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)))); } } if(strlen($file)) { @@ -689,9 +710,7 @@ function network_content(&$a, $update = 0) { dbesc(protect_sprintf('%' . $diasp_url . ']%')) );*/ - //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", - //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `mention`)", - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s'))", + $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", dbesc(protect_sprintf($myurl)), dbesc(protect_sprintf($myurl)) ); @@ -706,7 +725,7 @@ function network_content(&$a, $update = 0) { else { if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) { $r = q("SELECT COUNT(*) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra2 $sql_extra3 @@ -737,11 +756,10 @@ function network_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item`, `contact` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 $simple_update - AND `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra $sql_nets ORDER BY `item`.`received` DESC $pager_sql ", @@ -764,7 +782,7 @@ function network_content(&$a, $update = 0) { if($update) { $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "') and `item`.`moderated` = 0 and `item`.`unseen` = 1 @@ -775,7 +793,7 @@ function network_content(&$a, $update = 0) { } else { $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = `item`.`id` @@ -800,9 +818,9 @@ function network_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item`, `contact` + FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 - AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id` + AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` IN ( %s ) $sql_extra ", @@ -824,7 +842,7 @@ function network_content(&$a, $update = 0) { // We aren't going to try and figure out at the item, group, and page // level which items you've seen and which you haven't. If you're looking // at the top level network page just mark everything seen. - + // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact - // and other feeds that bring in stuff from the past. One can't find it all. From 452ff19d7335906bdc7f2a921e77e3656ed11be9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 13 Jan 2013 18:51:48 +0100 Subject: [PATCH 09/28] Redirects sometimes only seems to send the hostname and no path. "fetch_url" respects this. --- include/network.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/network.php b/include/network.php index 1ecee598cf..df23c2549c 100644 --- a/include/network.php +++ b/include/network.php @@ -76,9 +76,17 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ } if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { - $matches = array(); - preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); - $newurl = trim(array_pop($matches)); + $new_location_info = @parse_url($curl_info["redirect_url"]); + $old_location_info = @parse_url($curl_info["url"]); + + $newurl = $curl_info["redirect_url"]; + + if (($new_location_info["path"] == "") AND ($new_location_info["host"] != "")) + $newurl = $new_location_info["scheme"]."://".$new_location_info["host"].$old_location_info["path"]; + + //$matches = array(); + //preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); + //$newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) $newurl = $url . $newurl; $url_parsed = @parse_url($newurl); From 82c00660e099070cf4dee8de82c2023d1232ef8d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 17 Jan 2013 23:20:40 +0100 Subject: [PATCH 10/28] Preloading of items in the cache when receiving them. --- include/conversation.php | 2 +- include/items.php | 21 +++++++++++++++------ include/tags.php | 10 +++++++++- include/text.php | 4 +++- mod/item.php | 9 +++++++++ object/Item.php | 2 +- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 7665342739..7c4e606a72 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -524,7 +524,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $hashtags = array(); $mentions = array(); - $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); foreach($taglist as $tag) { diff --git a/include/items.php b/include/items.php index b93f56e179..3779126840 100755 --- a/include/items.php +++ b/include/items.php @@ -6,6 +6,7 @@ require_once('include/salmon.php'); require_once('include/crypto.php'); require_once('include/Photo.php'); require_once('include/tags.php'); +require_once('include/text.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) { @@ -238,7 +239,7 @@ function construct_activity_object($item) { $r->link = str_replace('&','&', $r->link); $r->link = preg_replace('/\/','',$r->link); $o .= $r->link; - } + } else $o .= '' . "\r\n"; } @@ -270,7 +271,7 @@ function construct_activity_target($item) { $r->link = str_replace('&','&', $r->link); $r->link = preg_replace('/\/','',$r->link); $o .= $r->link; - } + } else $o .= '' . "\r\n"; } @@ -882,7 +883,7 @@ function item_store($arr,$force_parent = false) { $arr['gravity'] = 0; elseif(activity_match($arr['verb'],ACTIVITY_POST)) $arr['gravity'] = 6; - else + else $arr['gravity'] = 6; // extensible catchall if(! x($arr,'type')) @@ -1072,10 +1073,9 @@ function item_store($arr,$force_parent = false) { if(count($r)) { $current_post = $r[0]['id']; - create_tags_from_item($r[0]['id']); logger('item_store: created item ' . $current_post); - } - else { + create_tags_from_item($r[0]['id']); + } else { logger('item_store: could not locate created item'); return 0; } @@ -1153,6 +1153,15 @@ function item_store($arr,$force_parent = false) { tag_deliver($arr['uid'],$current_post); + // Store the fresh generated item into the cache + $cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body'])); + + if (($cachefile != '') AND !file_exists($cachefile)) { + $s = prepare_text($arr['body']); + file_put_contents($cachefile, $s); + logger('item_store: put item '.$current_post.' into cachefile '.$cachefile); + } + return $current_post; } diff --git a/include/tags.php b/include/tags.php index 6a5728a9ba..b02adc3d83 100644 --- a/include/tags.php +++ b/include/tags.php @@ -25,7 +25,7 @@ function create_tags_from_item($itemid) { $searchpath = $a->get_baseurl()."/search?tag="; - $messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); if (!$messages) return; @@ -42,6 +42,14 @@ function create_tags_from_item($itemid) { if ($message["deleted"]) return; + $cachefile = get_cachefile($message["guid"]."-".hash("md5", $message['body'])); + + if (($cachefile != '') AND !file_exists($cachefile)) { + $s = prepare_text($message['body']); + file_put_contents($cachefile, $s); + logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile); + } + $taglist = explode(",", $message["tag"]); $tags = ""; diff --git a/include/text.php b/include/text.php index 5b64ef2f94..54c9f39fa6 100644 --- a/include/text.php +++ b/include/text.php @@ -1019,7 +1019,8 @@ function prepare_body($item,$attach = false) { $a = get_app(); call_hooks('prepare_body_init', $item); - $cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); + //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); + $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body'])); if (($cachefile != '')) { if (file_exists($cachefile)) @@ -1027,6 +1028,7 @@ function prepare_body($item,$attach = false) { else { $s = prepare_text($item['body']); file_put_contents($cachefile, $s); + logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile); } } else $s = prepare_text($item['body']); diff --git a/mod/item.php b/mod/item.php index 7096239b0f..452ec8a36d 100644 --- a/mod/item.php +++ b/mod/item.php @@ -757,6 +757,15 @@ function item_post(&$a) { // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); + // Store the fresh generated item into the cache + $cachefile = get_cachefile($datarray["guid"]."-".hash("md5", $datarray['body'])); + + if (($cachefile != '') AND !file_exists($cachefile)) { + $s = prepare_text($datarray['body']); + file_put_contents($cachefile, $s); + logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile); + } + if($parent) { // This item is the last leaf and gets the comment box, clear any ancestors diff --git a/object/Item.php b/object/Item.php index 648b558071..de28da4642 100644 --- a/object/Item.php +++ b/object/Item.php @@ -150,7 +150,7 @@ class Item extends BaseObject { $hashtags = array(); $mentions = array(); - $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); foreach($taglist as $tag) { From 7ab335c9d620779c929d80cac3d083f183dba391 Mon Sep 17 00:00:00 2001 From: "Michael - piratica.eu" Date: Sun, 20 Jan 2013 14:08:28 +0100 Subject: [PATCH 11/28] Diaspora: Auto-adding users as friend who already sharing with us --- include/Scrape.php | 12 ++++++------ include/diaspora.php | 18 ++++++++++++++++-- include/follow.php | 6 +++--- include/network.php | 1 + include/poller.php | 12 ++++++------ view/theme/vier/profile_vcard.tpl | 2 +- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/include/Scrape.php b/include/Scrape.php index 611cbda886..7b72a199df 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -346,7 +346,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $network = null; $diaspora = false; $diaspora_base = ''; - $diaspora_guid = ''; + $diaspora_guid = ''; $diaspora_key = ''; $has_lrdd = false; $email_conversant = false; @@ -485,7 +485,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { } } } - } + } if($mode == PROBE_NORMAL) { if(strlen($zot)) { @@ -531,7 +531,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { } if(strpos($url,'@')) $addr = str_replace('acct:', '', $url); - } + } if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if($diaspora) @@ -544,13 +544,13 @@ function probe_url($url, $mode = PROBE_NORMAL) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos - + if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') { $h = @parse_url($hcard); if($h) $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo']; } - + logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA); } @@ -561,7 +561,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $vcard['nick'] = $addr_parts[0]; } - if($twitter) { + if($twitter) { logger('twitter: setup'); $tid = basename($url); $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; diff --git a/include/diaspora.php b/include/diaspora.php index 3b681e9918..8e77f03336 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -557,7 +557,7 @@ function diaspora_decode($importer,$xml) { } - + function diaspora_request($importer,$xml) { $a = get_app(); @@ -567,7 +567,7 @@ function diaspora_request($importer,$xml) { if(! $sender_handle || ! $recipient_handle) return; - + $contact = diaspora_get_contact_by_handle($importer['uid'],$sender_handle); if($contact) { @@ -752,6 +752,20 @@ function diaspora_request($importer,$xml) { } function diaspora_post_allow($importer,$contact) { + + // perhaps we were already sharing with this person. Now they're sharing with us. + // That makes us friends. + // Normally this should have handled by getting a request - but this could get lost + if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) { + q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval(CONTACT_IS_FRIEND), + intval($contact['id']), + intval($importer['uid']) + ); + $contact['rel'] = CONTACT_IS_FRIEND; + logger('diaspora_post_allow: defining user '.$contact["nick"].' as friend'); + } + if(($contact['blocked']) || ($contact['readonly']) || ($contact['archive'])) return false; if($contact['rel'] == CONTACT_IS_SHARING || $contact['rel'] == CONTACT_IS_FRIEND) diff --git a/include/follow.php b/include/follow.php index 59f3b1a5fc..fc167bb82b 100644 --- a/include/follow.php +++ b/include/follow.php @@ -48,9 +48,9 @@ function new_contact($uid,$url,$interactive = false) { $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']); else $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); - + goaway($ret['request'] . "&addr=$myaddr"); - + // NOTREACHED } } @@ -61,7 +61,7 @@ function new_contact($uid,$url,$interactive = false) { return $result; } } - + diff --git a/include/network.php b/include/network.php index df23c2549c..1de65c42cb 100644 --- a/include/network.php +++ b/include/network.php @@ -367,6 +367,7 @@ function lrdd($uri, $debug = false) { logger('lrdd: constructed url: ' . $url); $xml = fetch_url($url); + $headers = $a->get_curl_headers(); if (! $xml) diff --git a/include/poller.php b/include/poller.php index 7df59f727a..cc5f2a9834 100644 --- a/include/poller.php +++ b/include/poller.php @@ -9,7 +9,7 @@ function poller_run(&$argv, &$argc){ if(is_null($a)) { $a = new App; } - + if(is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); @@ -57,17 +57,17 @@ function poller_run(&$argv, &$argc){ load_hooks(); logger('poller: start'); - + // run queue delivery process in the background proc_run('php',"include/queue.php"); - + // expire any expired accounts q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 AND `account_expires_on` != '0000-00-00 00:00:00' AND `account_expires_on` < UTC_TIMESTAMP() "); - + // delete user and contact records for recently removed accounts $r = q("SELECT * FROM `user` WHERE `account_removed` = 1 AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); @@ -77,12 +77,12 @@ function poller_run(&$argv, &$argc){ q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid'])); } } - + $abandon_days = intval(get_config('system','account_abandon_days')); if($abandon_days < 1) $abandon_days = 0; - + // once daily run birthday_updates and then expire in background diff --git a/view/theme/vier/profile_vcard.tpl b/view/theme/vier/profile_vcard.tpl index 4537fd0720..aa716f100b 100644 --- a/view/theme/vier/profile_vcard.tpl +++ b/view/theme/vier/profile_vcard.tpl @@ -18,7 +18,7 @@ {{ else }} - +
{{ endif }} From 2c93067682cf193fa4b155928ba6ccaf824498f2 Mon Sep 17 00:00:00 2001 From: "Michael - piratica.eu" Date: Sat, 26 Jan 2013 16:46:43 +0100 Subject: [PATCH 12/28] Performance: Adding several variables for performance measuring. --- boot.php | 10 ++++++++-- include/dba.php | 10 ++++++---- include/network.php | 31 +++++++++++++++++++++++-------- include/text.php | 41 ++++++++++++++++++++++++----------------- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/boot.php b/boot.php index cd7fa03b59..b851068f40 100644 --- a/boot.php +++ b/boot.php @@ -355,7 +355,8 @@ if(! class_exists('App')) { public $identities; public $is_mobile; public $is_tablet; - + public $performance = array(); + public $nav_sel; public $category; @@ -403,7 +404,7 @@ if(! class_exists('App')) { private $cached_profile_image; private $cached_profile_picdate; - + function __construct() { global $default_timezone, $argv, $argc; @@ -412,6 +413,11 @@ if(! class_exists('App')) { date_default_timezone_set($this->timezone); + $this->performance["start"] = microtime(true); + $this->performance["database"] = 0; + $this->performance["network"] = 0; + $this->performance["rendering"] = 0; + $this->config = array(); $this->page = array(); $this->pager= array(); diff --git a/include/dba.php b/include/dba.php index a9f70aa40d..dd7f56bfd9 100644 --- a/include/dba.php +++ b/include/dba.php @@ -78,18 +78,20 @@ class dba { $this->error = ''; - if(x($a->config,'system') && x($a->config['system'],'db_log')) - $stamp1 = microtime(true); + $stamp1 = microtime(true); if($this->mysqli) $result = @$this->db->query($sql); else $result = @mysql_query($sql,$this->db); + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $a->performance["database"] += (float)$duration; + if(x($a->config,'system') && x($a->config['system'],'db_log')) { - $stamp2 = microtime(true); - $duration = round($stamp2-$stamp1, 3); if (($duration > $a->config["system"]["db_loglimit"])) { + $duration = round($duration, 3); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @file_put_contents($a->config["system"]["db_log"], $duration."\t". basename($backtrace[1]["file"])."\t". diff --git a/include/network.php b/include/network.php index 1de65c42cb..10590f8bf4 100644 --- a/include/network.php +++ b/include/network.php @@ -7,10 +7,12 @@ if(! function_exists('fetch_url')) { function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) { + $stamp1 = microtime(true); + $a = get_app(); $ch = @curl_init($url); - if(($redirects > 8) || (! $ch)) + if(($redirects > 8) || (! $ch)) return false; @curl_setopt($ch, CURLOPT_HEADER, true); @@ -101,6 +103,11 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $body = substr($s,strlen($header)); $a->set_curl_headers($header); @curl_close($ch); + + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $a->performance["network"] += (float)$duration; + return($body); }} @@ -108,6 +115,9 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ if(! function_exists('post_url')) { function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) { + + $stamp1 = microtime(true); + $a = get_app(); $ch = curl_init($url); if(($redirects > 8) || (! $ch)) @@ -190,6 +200,11 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $a->set_curl_headers($header); curl_close($ch); + + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $a->performance["network"] += (float)$duration; + return($body); }} @@ -299,9 +314,9 @@ function webfinger_dfrn($s,&$hcard) { if($link['@attributes']['rel'] === NAMESPACE_DFRN) $profile_link = $link['@attributes']['href']; if($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB) - $profile_link = 'stat:' . $link['@attributes']['template']; + $profile_link = 'stat:' . $link['@attributes']['template']; if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') - $hcard = $link['@attributes']['href']; + $hcard = $link['@attributes']['href']; } } return $profile_link; @@ -417,7 +432,7 @@ function lrdd($uri, $debug = false) { elseif(x($link['@attributes'],'href')) $href = $link['@attributes']['href']; } - } + } } if((! isset($tpl)) || (! strpos($tpl,'{uri}'))) @@ -436,7 +451,7 @@ function lrdd($uri, $debug = false) { $lines = explode("\n",$headers); if(count($lines)) { - foreach($lines as $line) { + foreach($lines as $line) { if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) { return(fetch_xrd_links($matches[1])); break; @@ -482,7 +497,7 @@ function lrdd($uri, $debug = false) { $lines = explode("\n",$headers); if(count($lines)) { - foreach($lines as $line) { + foreach($lines as $line) { // TODO alter the following regex to support multiple relations (space separated) if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) { $pagelink = $matches[1]; @@ -598,14 +613,14 @@ function fetch_xrd_links($url) { if(! function_exists('validate_url')) { function validate_url(&$url) { - + // no naked subdomains (allow localhost for tests) if(strpos($url,'.') === false && strpos($url,'/localhost/') === false) return false; if(substr($url,0,4) != 'http') $url = 'http://' . $url; $h = @parse_url($url); - + if(($h) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { return true; } diff --git a/include/text.php b/include/text.php index 53dd06d1fd..8f0b07bc93 100644 --- a/include/text.php +++ b/include/text.php @@ -6,16 +6,17 @@ // returns substituted string. // WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other. // For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing, -// depending on the order in which they were declared in the array. +// depending on the order in which they were declared in the array. require_once("include/template_processor.php"); require_once("include/friendica_smarty.php"); -if(! function_exists('replace_macros')) { +if(! function_exists('replace_macros')) { function replace_macros($s,$r) { global $t; -// $ts = microtime(); + $stamp1 = microtime(true); + $a = get_app(); if($a->theme['template_engine'] === 'smarty3') { @@ -34,12 +35,14 @@ function replace_macros($s,$r) { } else { $r = $t->replace($s,$r); - + $output = template_unescape($r); } -// $tt = microtime() - $ts; -// $a = get_app(); -// $a->page['debug'] .= "$tt
\n"; + $a = get_app(); + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $a->performance["rendering"] += (float)$duration; + return $output; }} @@ -427,12 +430,12 @@ function load_view_file($s) { $d = dirname($s); if(file_exists("$d/$lang/$b")) return file_get_contents("$d/$lang/$b"); - + $theme = current_theme(); if(file_exists("$d/theme/$theme/$b")) return file_get_contents("$d/theme/$theme/$b"); - + return file_get_contents($s); }} @@ -458,7 +461,8 @@ function get_intltext_template($s) { if(! function_exists('get_markup_template')) { function get_markup_template($s, $root = '') { -// $ts = microtime(); + $stamp1 = microtime(true); + $a = get_app(); if($a->theme['template_engine'] === 'smarty3') { @@ -467,18 +471,21 @@ function get_markup_template($s, $root = '') { $template = new FriendicaSmarty(); $template->filename = $template_file; -// $tt = microtime() - $ts; -// $a->page['debug'] .= "$tt
\n"; + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $a->performance["rendering"] += (float)$duration; + return $template; } else { $template_file = get_template_file($a, $s, $root); -// $file_contents = file_get_contents($template_file); -// $tt = microtime() - $ts; -// $a->page['debug'] .= "$tt
\n"; -// return $file_contents; + + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $a->performance["rendering"] += (float)$duration; + return file_get_contents($template_file); - } + } }} if(! function_exists("get_template_file")) { From fdee002f73bce767c364b58daafeccc8eff5927e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 26 Jan 2013 18:35:39 +0100 Subject: [PATCH 13/28] Several improvements for performance measuring --- boot.php | 7 +++++ include/bbcode.php | 4 +++ include/dba.php | 7 ++++- include/items.php | 2 ++ include/network.php | 13 ++++----- include/plugin.php | 17 +++++++---- include/tags.php | 2 ++ include/text.php | 69 ++++++++++++++++++++++++++++++--------------- mod/item.php | 2 ++ 9 files changed, 87 insertions(+), 36 deletions(-) diff --git a/boot.php b/boot.php index b851068f40..b0e77a71fb 100644 --- a/boot.php +++ b/boot.php @@ -417,6 +417,7 @@ if(! class_exists('App')) { $this->performance["database"] = 0; $this->performance["network"] = 0; $this->performance["rendering"] = 0; + $this->performance["parser"] = 0; $this->config = array(); $this->page = array(); @@ -725,6 +726,12 @@ if(! class_exists('App')) { return $this->rdelim[$engine]; } + function save_timestamp($stamp1, $value) { + $stamp2 = microtime(true); + $duration = (float)($stamp2-$stamp1); + $this->performance[$value] += (float)$duration; + } + } } diff --git a/include/bbcode.php b/include/bbcode.php index 613c2b7db0..45213cc3b7 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -283,6 +283,8 @@ function bb_ShareAttributes($match) { function bbcode($Text,$preserve_nl = false, $tryoembed = true) { + $stamp1 = microtime(true); + $a = get_app(); // Hide all [noparse] contained bbtags by spacefying them @@ -637,6 +639,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { call_hooks('bbcode',$Text); + $a->save_timestamp($stamp1, "parser"); + return $Text; } diff --git a/include/dba.php b/include/dba.php index dd7f56bfd9..50354b7f49 100644 --- a/include/dba.php +++ b/include/dba.php @@ -23,6 +23,9 @@ class dba { public $error = false; function __construct($server,$user,$pass,$db,$install = false) { + global $a; + + $stamp1 = microtime(true); $server = trim($server); $user = trim($user); @@ -64,6 +67,8 @@ class dba { if(! $install) system_unavailable(); } + + $a->save_timestamp($stamp1, "network"); } public function getdb() { @@ -87,7 +92,6 @@ class dba { $stamp2 = microtime(true); $duration = (float)($stamp2-$stamp1); - $a->performance["database"] += (float)$duration; if(x($a->config,'system') && x($a->config['system'],'db_log')) { if (($duration > $a->config["system"]["db_loglimit"])) { @@ -164,6 +168,7 @@ class dba { } } + $a->save_timestamp($stamp1, "database"); if($this->debug) logger('dba: ' . printable(print_r($r, true))); diff --git a/include/items.php b/include/items.php index 54b392b386..1a50ac204a 100755 --- a/include/items.php +++ b/include/items.php @@ -1159,7 +1159,9 @@ function item_store($arr,$force_parent = false) { if (($cachefile != '') AND !file_exists($cachefile)) { $s = prepare_text($arr['body']); + $stamp1 = microtime(true); file_put_contents($cachefile, $s); + $a->save_timestamp($stamp1, "file"); logger('item_store: put item '.$current_post.' into cachefile '.$cachefile); } diff --git a/include/network.php b/include/network.php index 10590f8bf4..400c1386be 100644 --- a/include/network.php +++ b/include/network.php @@ -104,9 +104,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $a->set_curl_headers($header); @curl_close($ch); - $stamp2 = microtime(true); - $duration = (float)($stamp2-$stamp1); - $a->performance["network"] += (float)$duration; + $a->save_timestamp($stamp1, "network"); return($body); }} @@ -201,9 +199,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) curl_close($ch); - $stamp2 = microtime(true); - $duration = (float)($stamp2-$stamp1); - $a->performance["network"] += (float)$duration; + $a->save_timestamp($stamp1, "network"); return($body); }} @@ -851,8 +847,11 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) $i = fetch_url($scaled); $cachefile = get_cachefile(hash("md5", $scaled)); - if ($cachefile != '') + if ($cachefile != '') { + $stamp1 = microtime(true); file_put_contents($cachefile, $i); + $a->save_timestamp($stamp1, "file"); + } // guess mimetype from headers or filename $type = guess_image_type($mtch[1],true); diff --git a/include/plugin.php b/include/plugin.php index db3224f296..a6928793d4 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -201,12 +201,15 @@ function get_plugin_info($plugin){ 'author' => array(), 'version' => "" ); - + if (!is_file("addon/$plugin/$plugin.php")) return $info; - + + $stamp1 = microtime(true); $f = file_get_contents("addon/$plugin/$plugin.php"); + $a->save_timestamp($stamp1, "file"); + $r = preg_match("|/\*.*\*/|msU", $f, $m); - + if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { @@ -266,11 +269,13 @@ function get_theme_info($theme){ $info['unsupported'] = true; if (!is_file("view/theme/$theme/theme.php")) return $info; - + + $stamp1 = microtime(true); $f = file_get_contents("view/theme/$theme/theme.php"); + $a->save_timestamp($stamp1, "file"); + $r = preg_match("|/\*.*\*/|msU", $f, $m); - - + if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { diff --git a/include/tags.php b/include/tags.php index b02adc3d83..c81a752d54 100644 --- a/include/tags.php +++ b/include/tags.php @@ -46,7 +46,9 @@ function create_tags_from_item($itemid) { if (($cachefile != '') AND !file_exists($cachefile)) { $s = prepare_text($message['body']); + $stamp1 = microtime(true); file_put_contents($cachefile, $s); + $a->save_timestamp($stamp1, "file"); logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile); } diff --git a/include/text.php b/include/text.php index 8f0b07bc93..83639ce85c 100644 --- a/include/text.php +++ b/include/text.php @@ -428,15 +428,26 @@ function load_view_file($s) { $lang = 'en'; $b = basename($s); $d = dirname($s); - if(file_exists("$d/$lang/$b")) - return file_get_contents("$d/$lang/$b"); + if(file_exists("$d/$lang/$b")) { + $stamp1 = microtime(true); + $content = file_get_contents("$d/$lang/$b"); + $a->save_timestamp($stamp1, "file"); + return $content; + } $theme = current_theme(); - if(file_exists("$d/theme/$theme/$b")) - return file_get_contents("$d/theme/$theme/$b"); + if(file_exists("$d/theme/$theme/$b")) { + $stamp1 = microtime(true); + $content = file_get_contents("$d/theme/$theme/$b"); + $a->save_timestamp($stamp1, "file"); + return $content; + } - return file_get_contents($s); + $stamp1 = microtime(true); + $content = file_get_contents($s); + $a->save_timestamp($stamp1, "file"); + return $content; }} if(! function_exists('get_intltext_template')) { @@ -451,12 +462,22 @@ function get_intltext_template($s) { if(! isset($lang)) $lang = 'en'; - if(file_exists("view/$lang$engine/$s")) - return file_get_contents("view/$lang$engine/$s"); - elseif(file_exists("view/en$engine/$s")) - return file_get_contents("view/en$engine/$s"); - else - return file_get_contents("view$engine/$s"); + if(file_exists("view/$lang$engine/$s")) { + $stamp1 = microtime(true); + $content = file_get_contents("view/$lang$engine/$s"); + $a->save_timestamp($stamp1, "file"); + return $content; + } elseif(file_exists("view/en$engine/$s")) { + $stamp1 = microtime(true); + $content = file_get_contents("view/en$engine/$s"); + $a->save_timestamp($stamp1, "file"); + return $content; + } else { + $stamp1 = microtime(true); + $content = file_get_contents("view$engine/$s"); + $a->save_timestamp($stamp1, "file"); + return $content; + } }} if(! function_exists('get_markup_template')) { @@ -470,21 +491,19 @@ function get_markup_template($s, $root = '') { $template = new FriendicaSmarty(); $template->filename = $template_file; - - $stamp2 = microtime(true); - $duration = (float)($stamp2-$stamp1); - $a->performance["rendering"] += (float)$duration; + $a->save_timestamp($stamp1, "rendering"); return $template; } else { $template_file = get_template_file($a, $s, $root); + $a->save_timestamp($stamp1, "rendering"); - $stamp2 = microtime(true); - $duration = (float)($stamp2-$stamp1); - $a->performance["rendering"] += (float)$duration; + $stamp1 = microtime(true); + $content = file_get_contents($template_file); + $a->save_timestamp($stamp1, "file"); + return $content; - return file_get_contents($template_file); } }} @@ -541,8 +560,10 @@ function logger($msg,$level = 0) { if((! $debugging) || (! $logfile) || ($level > $loglevel)) return; - + + $stamp1 = microtime(true); @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND); + $a->save_timestamp($stamp1, "file"); return; }} @@ -1029,11 +1050,15 @@ function prepare_body($item,$attach = false) { $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body'])); if (($cachefile != '')) { - if (file_exists($cachefile)) + if (file_exists($cachefile)) { + $stamp1 = microtime(true); $s = file_get_contents($cachefile); - else { + $a->save_timestamp($stamp1, "file"); + } else { $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 diff --git a/mod/item.php b/mod/item.php index 452ec8a36d..926fbbf525 100644 --- a/mod/item.php +++ b/mod/item.php @@ -762,7 +762,9 @@ function item_post(&$a) { if (($cachefile != '') AND !file_exists($cachefile)) { $s = prepare_text($datarray['body']); + $stamp1 = microtime(true); file_put_contents($cachefile, $s); + $a->save_timestamp($stamp1, "file"); logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile); } From 2cb576d30523088900813d491f3accf9cbbf1857 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 27 Jan 2013 13:57:44 +0100 Subject: [PATCH 14/28] Bugfixing after adding timestamps --- boot.php | 13 ++++-- include/conversation.php | 1 - include/plugin.php | 16 +++++--- include/text.php | 4 +- index.php | 2 +- mod/admin.php | 85 +++++++++++++++++++--------------------- mod/network.php | 14 +++---- object/Conversation.php | 2 + 8 files changed, 72 insertions(+), 65 deletions(-) diff --git a/boot.php b/boot.php index b0e77a71fb..da8ee8efa8 100644 --- a/boot.php +++ b/boot.php @@ -418,6 +418,8 @@ if(! class_exists('App')) { $this->performance["network"] = 0; $this->performance["rendering"] = 0; $this->performance["parser"] = 0; + $this->performance["marktime"] = 0; + $this->performance["markstart"] = microtime(true); $this->config = array(); $this->page = array(); @@ -726,12 +728,17 @@ if(! class_exists('App')) { return $this->rdelim[$engine]; } - function save_timestamp($stamp1, $value) { - $stamp2 = microtime(true); - $duration = (float)($stamp2-$stamp1); + function save_timestamp($stamp, $value) { + $duration = (float)(microtime(true)-$stamp); + $this->performance[$value] += (float)$duration; + $this->performance["marktime"] += (float)$duration; } + function mark_timestamp($mark) { + //$this->performance["markstart"] -= microtime(true) - $this->performance["marktime"]; + $this->performance["markstart"] = microtime(true) - $this->performance["markstart"] - $this->performance["marktime"]; + } } } diff --git a/include/conversation.php b/include/conversation.php index cc66d380b7..306799c52c 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -368,7 +368,6 @@ function visible_activity($item) { if(!function_exists('conversation')) { function conversation(&$a, $items, $mode, $update, $preview = false) { - require_once('include/bbcode.php'); $ssl_state = ((local_user()) ? true : false); diff --git a/include/plugin.php b/include/plugin.php index a6928793d4..7a4a96670d 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -8,7 +8,7 @@ function uninstall_plugin($plugin){ q("DELETE FROM `addon` WHERE `name` = '%s' ", dbesc($plugin) ); - + @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_uninstall')) { $func = $plugin . '_uninstall'; @@ -28,9 +28,9 @@ function install_plugin($plugin) { if(function_exists($plugin . '_install')) { $func = $plugin . '_install'; $func(); - + $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0); - + $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ", dbesc($plugin), intval($t), @@ -195,6 +195,9 @@ function call_hooks($name, &$data = null) { if (! function_exists('get_plugin_info')){ function get_plugin_info($plugin){ + + $a = get_app(); + $info=Array( 'name' => $plugin, 'description' => "", @@ -229,10 +232,10 @@ function get_plugin_info($plugin){ $info[$k]=$v; } } - + } } - + } return $info; }} @@ -241,7 +244,7 @@ function get_plugin_info($plugin){ /* * parse theme comment in search of theme infos. * like - * + * * * Name: My Theme * * Description: My Cool Theme * * Version: 1.2.3 @@ -270,6 +273,7 @@ function get_theme_info($theme){ if (!is_file("view/theme/$theme/theme.php")) return $info; + $a = get_app(); $stamp1 = microtime(true); $f = file_get_contents("view/theme/$theme/theme.php"); $a->save_timestamp($stamp1, "file"); diff --git a/include/text.php b/include/text.php index 83639ce85c..9ff5c79077 100644 --- a/include/text.php +++ b/include/text.php @@ -39,9 +39,7 @@ function replace_macros($s,$r) { $output = template_unescape($r); } $a = get_app(); - $stamp2 = microtime(true); - $duration = (float)($stamp2-$stamp1); - $a->performance["rendering"] += (float)$duration; + $a->save_timestamp($stamp1, "rendering"); return $output; }} diff --git a/index.php b/index.php index 0ea09c0c7a..49e6fccb05 100644 --- a/index.php +++ b/index.php @@ -33,7 +33,7 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false $lang = get_browser_language(); - + load_translation_table($lang); /** diff --git a/mod/admin.php b/mod/admin.php index 89363541ca..dd9ff84512 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -20,7 +20,7 @@ function admin_post(&$a){ if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) return; - + // urls @@ -54,7 +54,7 @@ function admin_post(&$a){ } info(t('Theme settings updated.')); if(is_ajax()) return; - + goaway($a->get_baseurl(true) . '/admin/themes/' . $theme ); return; break; @@ -100,9 +100,9 @@ function admin_content(&$a) { 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync"), //'update' => Array($a->get_baseurl(true)."/admin/update/", t("Software Update") , "update") ); - + /* get plugins admin page */ - + $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1"); $aside['plugins_admin']=Array(); foreach ($r as $h){ @@ -111,7 +111,7 @@ function admin_content(&$a) { // temp plugins with admin $a->plugins_admin[] = $plugin; } - + $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs"); $t = get_markup_template("admin_aside.tpl"); @@ -130,7 +130,6 @@ function admin_content(&$a) { * Page content */ $o = ''; - // urls if ($a->argc > 1){ switch ($a->argv[1]){ @@ -161,7 +160,7 @@ function admin_content(&$a) { } else { $o = admin_page_summary($a); } - + if(is_ajax()) { echo $o; killme(); @@ -431,14 +430,14 @@ function admin_page_site(&$a) { } } } - - + + /* Banner */ $banner = get_config('system','banner'); if($banner == false) $banner = 'logoFriendica'; $banner = htmlspecialchars($banner); - + //echo "
"; var_dump($lang_choices); die("
"); /* Register policy */ @@ -763,7 +762,7 @@ function admin_page_users(&$a){ * @return string */ function admin_page_plugins(&$a){ - + /** * Single plugin */ @@ -773,9 +772,9 @@ function admin_page_plugins(&$a){ notice( t("Item not found.") ); return ''; } - + if (x($_GET,"a") && $_GET['a']=="t"){ - check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't'); + check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't'); // Toggle plugin status $idx = array_search($plugin, $a->plugins); @@ -800,52 +799,53 @@ function admin_page_plugins(&$a){ } else { $status="off"; $action= t("Enable"); } - + $readme=Null; if (is_file("addon/$plugin/README.md")){ $readme = file_get_contents("addon/$plugin/README.md"); $readme = Markdown($readme); } else if (is_file("addon/$plugin/README")){ $readme = "
". file_get_contents("addon/$plugin/README") ."
"; - } - + } + $admin_form=""; if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){ @require_once("addon/$plugin/$plugin.php"); $func = $plugin.'_plugin_admin'; $func($a, $admin_form); } - + $t = get_markup_template("admin_plugins_details.tpl"); + return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Plugins'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(true), - + '$plugin' => $plugin, '$status' => $status, '$action' => $action, '$info' => get_plugin_info($plugin), '$str_author' => t('Author: '), - '$str_maintainer' => t('Maintainer: '), - + '$str_maintainer' => t('Maintainer: '), + '$admin_form' => $admin_form, '$function' => 'plugins', '$screenshot' => '', '$readme' => $readme, - '$form_security_token' => get_form_security_token("admin_themes"), + '$form_security_token' => get_form_security_token("admin_themes"), )); - } - - - + } + + + /** * List plugins */ - + $plugins = array(); $files = glob("addon/*/"); if($files) { @@ -857,7 +857,7 @@ function admin_page_plugins(&$a){ } } } - + $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array( '$title' => t('Administration'), @@ -928,7 +928,7 @@ function rebuild_theme_table($themes) { return $o; } - + /** * Themes admin page * @@ -936,7 +936,7 @@ function rebuild_theme_table($themes) { * @return string */ function admin_page_themes(&$a){ - + $allowed_themes_str = get_config('system','allowed_themes'); $allowed_themes_raw = explode(',',$allowed_themes_str); $allowed_themes = array(); @@ -972,9 +972,9 @@ function admin_page_themes(&$a){ notice( t("Item not found.") ); return ''; } - + if (x($_GET,"a") && $_GET['a']=="t"){ - check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't'); + check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't'); // Toggle theme status @@ -998,28 +998,27 @@ function admin_page_themes(&$a){ } else { $status="off"; $action= t("Enable"); } - + $readme=Null; if (is_file("view/theme/$theme/README.md")){ $readme = file_get_contents("view/theme/$theme/README.md"); $readme = Markdown($readme); } else if (is_file("view/theme/$theme/README")){ $readme = "
". file_get_contents("view/theme/$theme/README") ."
"; - } - + } + $admin_form=""; if (is_file("view/theme/$theme/config.php")){ require_once("view/theme/$theme/config.php"); if(function_exists("theme_admin")){ $admin_form = theme_admin($a); } - + } - $screenshot = array( get_theme_screenshot($theme), t('Screenshot')); if(! stristr($screenshot[0],$theme)) - $screenshot = null; + $screenshot = null; $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array( @@ -1028,7 +1027,7 @@ function admin_page_themes(&$a){ '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(true), - + '$plugin' => $theme, '$status' => $status, '$action' => $action, @@ -1042,21 +1041,19 @@ function admin_page_themes(&$a){ '$form_security_token' => get_form_security_token("admin_themes"), )); - } - - - + } + /** * List themes */ - + $xthemes = array(); if($themes) { foreach($themes as $th) { $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name'])); } } - + $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array( '$title' => t('Administration'), diff --git a/mod/network.php b/mod/network.php index 872c34da95..9909cd4451 100644 --- a/mod/network.php +++ b/mod/network.php @@ -321,7 +321,7 @@ function network_query_get_sel_net() { if(x($_GET,'nets')) { $network = $_GET['nets']; } - + return $network; } @@ -382,14 +382,14 @@ function network_content(&$a, $update = 0) { // item filter tabs // TODO: fix this logic, reduce duplication //$a->page['content'] .= '
'; - + list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a); // if no tabs are selected, defaults to comments if ($no_active=='active') $all_active='active'; //echo "
"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme();
 
 	$cmd = (($datequery) ? '' : $a->cmd);
-	$len_naked_cmd = strlen(str_replace('/new','',$cmd));		
+	$len_naked_cmd = strlen(str_replace('/new','',$cmd));
 
 	// tabs
 	$tabs = array(
@@ -435,10 +435,10 @@ function network_content(&$a, $update = 0) {
 //			'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
 //			'sel'=> $spam_active,
 //			'title' => t('Posts flagged as SPAM'),
-//		),	
+//		),
 
 	);
-	
+
 	if(feature_enabled(local_user(),'personal_tab')) {
 		$tabs[] = array(
 			'label' => t('Personal'),
@@ -571,11 +571,11 @@ function network_content(&$a, $update = 0) {
 	}
 
 
-	// We don't have to deal with ACL's on this page. You're looking at everything
+	// We don't have to deal with ACLs on this page. You're looking at everything
 	// that belongs to you, hence you can see all of it. We will filter by group if
 	// desired. 
 
-	
+
 	$sql_options  = (($star) ? " and starred = 1 " : '');
 	$sql_options .= (($bmark) ? " and bookmark = 1 " : '');
 
diff --git a/object/Conversation.php b/object/Conversation.php
index 8b838f7d00..bd7a95cf2a 100644
--- a/object/Conversation.php
+++ b/object/Conversation.php
@@ -127,6 +127,7 @@ class Conversation extends BaseObject {
 	 *      _ false on failure
 	 */
 	public function get_template_data($alike, $dlike) {
+		global $a;
 		$result = array();
 
 		foreach($this->threads as $item) {
@@ -140,6 +141,7 @@ class Conversation extends BaseObject {
 			$result[] = $item_data;
 		}
 
+		//$a->mark_timestamp();
 		return $result;
 	}
 

From bc972e16ce513fd610615d190046cd43e01fb92d Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Sun, 27 Jan 2013 23:25:04 +0100
Subject: [PATCH 15/28] New function to complete threads from ostatus postings

---
 boot.php                         |   1 +
 include/items.php                |  34 ++++++++--
 include/ostatus_conversation.php | 112 +++++++++++++++++++++++++++++++
 include/plugin.php               |   3 +-
 object/Item.php                  |  16 ++---
 5 files changed, 152 insertions(+), 14 deletions(-)
 create mode 100644 include/ostatus_conversation.php

diff --git a/boot.php b/boot.php
index da8ee8efa8..fa968ce42e 100644
--- a/boot.php
+++ b/boot.php
@@ -208,6 +208,7 @@ define ( 'TERM_CATEGORY',  3 );
 define ( 'TERM_PCATEGORY', 4 );
 define ( 'TERM_FILE',      5 );
 define ( 'TERM_SAVEDSEARCH', 6 );
+define ( 'TERM_CONVERSATION', 7 );
 
 define ( 'TERM_OBJ_POST',  1 );
 define ( 'TERM_OBJ_PHOTO', 2 );
diff --git a/include/items.php b/include/items.php
index 1a50ac204a..94835d7ad1 100755
--- a/include/items.php
+++ b/include/items.php
@@ -831,15 +831,28 @@ function get_atom_elements($feed,$item) {
 		}
 	}
 
+	// Search for ostatus conversation url
+	$links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"];
+
+	foreach ($links as $link) {
+		$conversation = array_shift($link["attribs"]);
+
+		if ($conversation["rel"] == "ostatus:conversation") {
+			$res["ostatus_conversation"] = $conversation["href"];
+			logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]);
+		}
+	};
+
 	$arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
 
 	call_hooks('parse_atom', $arr);
 
 	//if (($res["title"] != "") or (strpos($res["body"], "RT @") > 0)) {
 	//if (strpos($res["body"], "RT @") !== false) {
-	//	$debugfile = tempnam("/home/ike/log", "item-res2-");
-	//	file_put_contents($debugfile, serialize($arr));
-	//}
+	/*if (strpos($res["body"], "@") !== false) {
+		$debugfile = tempnam("/var/www/virtual/pirati.ca/phptmp/", "item-res2-");
+		file_put_contents($debugfile, serialize($arr));
+	}*/
 
 	return $res;
 }
@@ -878,6 +891,15 @@ function item_store($arr,$force_parent = false) {
 		unset($arr['dsprsig']);
 	}
 
+	// if an OStatus conversation url was passed in, it is stored and then
+	// removed from the array.
+	$ostatus_conversation = null;
+
+	if (isset($arr["ostatus_conversation"])) {
+		$ostatus_conversation = $arr["ostatus_conversation"];
+	        unset($arr["ostatus_conversation"]);
+	}
+
 	if(x($arr, 'gravity'))
 		$arr['gravity'] = intval($arr['gravity']);
 	elseif($arr['parent-uri'] === $arr['uri'])
@@ -969,9 +991,9 @@ function item_store($arr,$force_parent = false) {
 		$deny_cid  = $arr['deny_cid'];
 		$deny_gid  = $arr['deny_gid'];
 	}
-	else { 
+	else {
 
-		// find the parent and snarf the item id and ACL's
+		// find the parent and snarf the item id and ACLs
 		// and anything else we need to inherit
 
 		$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1",
@@ -1076,6 +1098,7 @@ function item_store($arr,$force_parent = false) {
 		$current_post = $r[0]['id'];
 		logger('item_store: created item ' . $current_post);
 		create_tags_from_item($r[0]['id']);
+		// ostatus_conversation
 	} else {
 		logger('item_store: could not locate created item');
 		return 0;
@@ -1159,6 +1182,7 @@ function item_store($arr,$force_parent = false) {
 
 	if (($cachefile != '') AND !file_exists($cachefile)) {
 		$s = prepare_text($arr['body']);
+		$a = get_app();
 		$stamp1 = microtime(true);
 		file_put_contents($cachefile, $s);
 		$a->save_timestamp($stamp1, "file");
diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php
new file mode 100644
index 0000000000..a566733905
--- /dev/null
+++ b/include/ostatus_conversation.php
@@ -0,0 +1,112 @@
+items);
+
+		foreach ($items as $single_conv) {
+			//print_r($single_conv);
+
+			if (isset($single_conv->context->inReplyTo->id))
+				$parent_uri = $single_conv->context->inReplyTo->id;
+			else
+				$parent_uri = $parent["uri"];
+
+			$message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
+						intval($message["uid"]), dbesc($single_conv->id));
+			if ($message_exists) {
+				$existing_message = $message_exists[0];
+				$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d LIMIT 1",
+					intval($parent["id"]),
+					dbesc($parent["uri"]),
+					dbesc($parent_uri),
+					intval($existing_message["id"]));
+				continue;
+			}
+
+			$arr = array();
+			$arr["uri"] = $single_conv->id;
+			$arr["uid"] = $message["uid"];
+			$arr["contact-id"] = $parent["contact-id"]; // To-Do
+			$arr["parent"] = $parent["id"];
+			$arr["parent-uri"] = $parent["uri"];
+			$arr["thr-parent"] = $parent_uri;
+			$arr["created"] = $single_conv->published;
+			$arr["edited"] = $single_conv->published;
+			$arr["owner-name"] = $single_conv->actor->contact->displayName;
+			//$arr["owner-name"] = $single_conv->actor->contact->preferredUsername;
+			$arr["owner-link"] = $single_conv->actor->id;
+			$arr["owner-avatar"] = $single_conv->actor->image->url;
+			$arr["author-name"] = $single_conv->actor->contact->displayName;
+			//$arr["author-name"] = $single_conv->actor->contact->preferredUsername;
+			$arr["author-link"] = $single_conv->actor->id;
+			$arr["author-avatar"] = $single_conv->actor->image->url;
+			$arr["body"] = html2bbcode($single_conv->content);
+			$arr["app"] = strip_tags($single_conv->statusnet_notice_info->source);
+			if ($arr["app"] == "")
+				$arr["app"] = $single_conv->provider->displayName;
+			$arr["verb"] = $parent["verb"];
+			$arr["visible"] = $parent["visible"];
+			$arr["location"] = $single_conv->location->displayName;
+			$arr["coord"] = trim($single_conv->location->lat." ".$single_conv->location->lon);
+
+			if ($arr["location"] == "")
+				unset($arr["location"]);
+
+			if ($arr["coord"] == "")
+				unset($arr["coord"]);
+
+			item_store($arr);
+			//print_r($arr);
+		}
+	}
+}
+
+$id = 282481;
+$conversation = "http://identi.ca/conversation/98268580";
+
+complete_conversation($id, $conversation);
+?>
diff --git a/include/plugin.php b/include/plugin.php
index 7a4a96670d..12c29d1a6e 100644
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -158,6 +158,8 @@ function load_hooks() {
 
 if(! function_exists('call_hooks')) {
 function call_hooks($name, &$data = null) {
+	$stamp1 = microtime(true);
+
 	$a = get_app();
 
 	if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
@@ -177,7 +179,6 @@ function call_hooks($name, &$data = null) {
 			}
 		}
 	}
-
 }}
 
 
diff --git a/object/Item.php b/object/Item.php
index 18281e9bcb..aa58287532 100644
--- a/object/Item.php
+++ b/object/Item.php
@@ -190,10 +190,10 @@ class Item extends BaseObject {
 		 * Maybe we should establish a way to be notified about conversation changes
 		 */
 		$this->check_wall_to_wall();
-		
+
 		if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url()))
 			$osparkle = ' sparkle';
-		
+
 		if($this->is_toplevel()) {
 			if($conv->get_profile_owner() == local_user()) {
 				$isstarred = (($item['starred']) ? "starred" : "unstarred");
@@ -283,14 +283,14 @@ class Item extends BaseObject {
 
 			'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
 			'tags' => $tags,
-            'hashtags' => $hashtags,
-            'mentions' => $mentions,
+			'hashtags' => $hashtags,
+			'mentions' => $mentions,
 			'txt_cats' => t('Categories:'),
 			'txt_folders' => t('Filed under:'),
 			'has_cats' => ((count($categories)) ? 'true' : ''),
 			'has_folders' => ((count($folders)) ? 'true' : ''),
-            'categories' => $categories,
-            'folders' => $folders,
+			'categories' => $categories,
+			'folders' => $folders,
 			'body' => $body_e,
 			'text' => $text_e,
 			'id' => $this->get_id(),
@@ -361,12 +361,12 @@ class Item extends BaseObject {
 				}
 			}
 		}
-		
+
         if ($this->is_toplevel()) {
             $result['total_comments_num'] = "$total_children";
             $result['total_comments_text'] = tt('comment', 'comments', $total_children);
         }
-        
+
 		$result['private'] = $item['private'];
 		$result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
 

From e668fece109f529345e5f3377c0bdcd2ab15161f Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Mon, 28 Jan 2013 01:16:51 +0100
Subject: [PATCH 16/28] ostatus auto completion now seems to work.

---
 include/items.php                |  6 ++++-
 include/ostatus_conversation.php | 40 +++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/include/items.php b/include/items.php
index 94835d7ad1..13566075ba 100755
--- a/include/items.php
+++ b/include/items.php
@@ -8,6 +8,7 @@ require_once('include/Photo.php');
 require_once('include/tags.php');
 require_once('include/text.php');
 require_once('include/email.php');
+require_once('include/ostatus_conversation.php');
 
 function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
 
@@ -1098,7 +1099,6 @@ function item_store($arr,$force_parent = false) {
 		$current_post = $r[0]['id'];
 		logger('item_store: created item ' . $current_post);
 		create_tags_from_item($r[0]['id']);
-		// ostatus_conversation
 	} else {
 		logger('item_store: could not locate created item');
 		return 0;
@@ -1135,6 +1135,10 @@ function item_store($arr,$force_parent = false) {
 	);
 	create_tags_from_item($current_post);
 
+	// Complete ostatus threads
+	if ($ostatus_conversation)
+		complete_conversation($current_post, $ostatus_conversation);
+
         $arr['id'] = $current_post;
         $arr['parent'] = $parent_id;
         $arr['allow_cid'] = $allow_cid;
diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php
index a566733905..2851fdb1f9 100644
--- a/include/ostatus_conversation.php
+++ b/include/ostatus_conversation.php
@@ -1,5 +1,5 @@
 items);
 
 		foreach ($items as $single_conv) {
 			//print_r($single_conv);
 
+			if ($first_id == "") {
+				$first_id = $single_conv->id;
+
+				$new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
+					intval($message["uid"]), dbesc($first_id));
+				if ($new_parents)
+					$parent = $new_parents[0];
+
+				logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid);
+			}
+
 			if (isset($single_conv->context->inReplyTo->id))
 				$parent_uri = $single_conv->context->inReplyTo->id;
 			else
@@ -99,14 +116,25 @@ function complete_conversation($itemid, $conversation_url) {
 			if ($arr["coord"] == "")
 				unset($arr["coord"]);
 
-			item_store($arr);
+			$newitem = item_store($arr);
+
+			// If the newly created item is the top item then change the parent settings of the thread
+			if ($newitem AND ($arr["uri"] == $first_id)) {
+				logger('complete_conversation: changing parents to parent '.$newitem.' old parent: '.$parent["id"].' new uri: '.$arr["uri"]);
+				$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d",
+					intval($newitem),
+					dbesc($arr["uri"]),
+					intval($parent["id"]));
+				logger('complete_conversation: done changing parents to parent '.$newitem);
+			}
 			//print_r($arr);
 		}
 	}
 }
-
+/*
 $id = 282481;
 $conversation = "http://identi.ca/conversation/98268580";
 
 complete_conversation($id, $conversation);
+*/
 ?>

From 9967c9892d68b2c8f4c7085367891d2e74db8ddb Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Mon, 28 Jan 2013 01:22:00 +0100
Subject: [PATCH 17/28] only change parents when parents are changed.

---
 include/ostatus_conversation.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php
index 2851fdb1f9..4bf80aa042 100644
--- a/include/ostatus_conversation.php
+++ b/include/ostatus_conversation.php
@@ -17,7 +17,7 @@ function complete_conversation($itemid, $conversation_url) {
 	require_once('include/html2bbcode.php');
 	require_once('include/items.php');
 
-	logger('complete_conversation: completing conversation url '.$conversation_url.' for id '.$itemid);
+	//logger('complete_conversation: completing conversation url '.$conversation_url.' for id '.$itemid);
 
 	$messages = q("SELECT `uid`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
 	if (!$messages)
@@ -43,7 +43,7 @@ function complete_conversation($itemid, $conversation_url) {
 
 	$conv = str_replace("/conversation/", "/api/statusnet/conversation/", $conversation_url).".as";
 
-	logger('complete_conversation: fetching conversation url '.$conversation_url.' for '.$itemid);
+	logger('complete_conversation: fetching conversation url '.$conv.' for '.$itemid);
 	$conv_as = fetch_url($conv);
 
 	if ($conv_as) {
@@ -61,10 +61,10 @@ function complete_conversation($itemid, $conversation_url) {
 
 				$new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
 					intval($message["uid"]), dbesc($first_id));
-				if ($new_parents)
+				if ($new_parents AND ($itemid != $parent["id"])) {
 					$parent = $new_parents[0];
-
-				logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid);
+					logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid);
+				}
 			}
 
 			if (isset($single_conv->context->inReplyTo->id))

From 2350aa54ebae23394d9e36445247dcd2235e7173 Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Wed, 30 Jan 2013 01:31:27 +0100
Subject: [PATCH 18/28] OStatus-Conversation auto completion works now. Some
 performance issues added as well.

---
 database.sql                     |  1 +
 include/ostatus_conversation.php | 72 +++++++++++++++-----------------
 mod/community.php                |  3 +-
 mod/search.php                   |  5 ++-
 mods/readme.txt                  |  1 +
 5 files changed, 40 insertions(+), 42 deletions(-)

diff --git a/database.sql b/database.sql
index cf060ebf49..da0d8c3aae 100644
--- a/database.sql
+++ b/database.sql
@@ -591,6 +591,7 @@ CREATE TABLE IF NOT EXISTS `item` (
   KEY `uid_created` (`uid`, `created`),
   KEY `uid_unseen` (`uid`, `unseen`),
   KEY `mention` (`mention`),
+  KEY `resource-id` (`resource-id`),
   FULLTEXT KEY `title` (`title`),
   FULLTEXT KEY `body` (`body`),
   FULLTEXT KEY `allow_cid` (`allow_cid`),
diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php
index 4bf80aa042..3d40d673d1 100644
--- a/include/ostatus_conversation.php
+++ b/include/ostatus_conversation.php
@@ -1,16 +1,4 @@
 items);
 
 		foreach ($items as $single_conv) {
-			//print_r($single_conv);
-
 			if ($first_id == "") {
 				$first_id = $single_conv->id;
 
 				$new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
 					intval($message["uid"]), dbesc($first_id));
-				if ($new_parents AND ($itemid != $parent["id"])) {
+				if ($new_parents) {
 					$parent = $new_parents[0];
 					logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid);
+				} else {
+					$parent["id"] = 0;
+					$parent["uri"] = $first_id;
 				}
 			}
 
@@ -72,33 +61,37 @@ function complete_conversation($itemid, $conversation_url) {
 			else
 				$parent_uri = $parent["uri"];
 
-			$message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
-						intval($message["uid"]), dbesc($single_conv->id));
-			if ($message_exists) {
-				$existing_message = $message_exists[0];
-				$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d LIMIT 1",
-					intval($parent["id"]),
-					dbesc($parent["uri"]),
-					dbesc($parent_uri),
-					intval($existing_message["id"]));
-				continue;
+			if ($parent["id"] != 0) {
+				$message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
+							intval($message["uid"]), dbesc($single_conv->id));
+				if ($message_exists) {
+					$existing_message = $message_exists[0];
+					$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d LIMIT 1",
+						intval($parent["id"]),
+						dbesc($parent["uri"]),
+						dbesc($parent_uri),
+						intval($existing_message["id"]));
+					continue;
+				}
 			}
 
 			$arr = array();
 			$arr["uri"] = $single_conv->id;
+			$arr["plink"] = $single_conv->id;
 			$arr["uid"] = $message["uid"];
 			$arr["contact-id"] = $parent["contact-id"]; // To-Do
-			$arr["parent"] = $parent["id"];
+			if ($parent["id"] != 0)
+				$arr["parent"] = $parent["id"];
 			$arr["parent-uri"] = $parent["uri"];
 			$arr["thr-parent"] = $parent_uri;
 			$arr["created"] = $single_conv->published;
 			$arr["edited"] = $single_conv->published;
-			$arr["owner-name"] = $single_conv->actor->contact->displayName;
-			//$arr["owner-name"] = $single_conv->actor->contact->preferredUsername;
+			//$arr["owner-name"] = $single_conv->actor->contact->displayName;
+			$arr["owner-name"] = $single_conv->actor->contact->preferredUsername;
 			$arr["owner-link"] = $single_conv->actor->id;
 			$arr["owner-avatar"] = $single_conv->actor->image->url;
-			$arr["author-name"] = $single_conv->actor->contact->displayName;
-			//$arr["author-name"] = $single_conv->actor->contact->preferredUsername;
+			//$arr["author-name"] = $single_conv->actor->contact->displayName;
+			$arr["author-name"] = $single_conv->actor->contact->preferredUsername;
 			$arr["author-link"] = $single_conv->actor->id;
 			$arr["author-avatar"] = $single_conv->actor->image->url;
 			$arr["body"] = html2bbcode($single_conv->content);
@@ -120,21 +113,22 @@ function complete_conversation($itemid, $conversation_url) {
 
 			// If the newly created item is the top item then change the parent settings of the thread
 			if ($newitem AND ($arr["uri"] == $first_id)) {
-				logger('complete_conversation: changing parents to parent '.$newitem.' old parent: '.$parent["id"].' new uri: '.$arr["uri"]);
+				logger('complete_conversation: setting new parent to id '.$newitem);
+				$new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
+					intval($message["uid"]), intval($newitem));
+				if ($new_parents) {
+					$parent = $new_parents[0];
+					logger('complete_conversation: done changing parents to parent '.$newitem);
+				}
+
+				/*logger('complete_conversation: changing parents to parent '.$newitem.' old parent: '.$parent["id"].' new uri: '.$arr["uri"]);
 				$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d",
 					intval($newitem),
 					dbesc($arr["uri"]),
 					intval($parent["id"]));
-				logger('complete_conversation: done changing parents to parent '.$newitem);
+				logger('complete_conversation: done changing parents to parent '.$newitem.' '.print_r($r, true));*/
 			}
-			//print_r($arr);
 		}
 	}
 }
-/*
-$id = 282481;
-$conversation = "http://identi.ca/conversation/98268580";
-
-complete_conversation($id, $conversation);
-*/
 ?>
diff --git a/mod/community.php b/mod/community.php
index aa5bb7268d..a7f5c9bf82 100644
--- a/mod/community.php
+++ b/mod/community.php
@@ -75,12 +75,13 @@ function community_content(&$a, $update = 0) {
 		AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
 		AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' 
 		AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
-		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 group by `item`.`uri`
+		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
 		ORDER BY `received` DESC LIMIT %d, %d ",
 		intval($a->pager['start']),
 		intval($a->pager['itemspage'])
 
 	);
+//		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 group by `item`.`uri`
 
 	if(! count($r)) {
 		info( t('No results.') . EOL);
diff --git a/mod/search.php b/mod/search.php
index c6d5989fb5..b368deb49d 100644
--- a/mod/search.php
+++ b/mod/search.php
@@ -164,9 +164,10 @@ function search_content(&$a) {
 		        AND (( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0) 
 			        OR `item`.`uid` = %d )
 		        AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
-		        $sql_extra group by `item`.`uri` ", 
+		        $sql_extra ",
 		        intval(local_user())
 	        );
+//		        $sql_extra group by `item`.`uri` ",
 
 	        if(count($r))
 		        $a->set_pager_total(count($r));
@@ -189,13 +190,13 @@ function search_content(&$a) {
 			OR `item`.`uid` = %d )
 		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
 		$sql_extra
-		group by `item`.`uri`	
 		ORDER BY `received` DESC LIMIT %d , %d ",
 		intval(local_user()),
 		intval($a->pager['start']),
 		intval($a->pager['itemspage'])
 
 	);
+//		group by `item`.`uri`
 
 	if(! count($r)) {
 		info( t('No results.') . EOL);
diff --git a/mods/readme.txt b/mods/readme.txt
index 9e79f843fe..d74b846d00 100644
--- a/mods/readme.txt
+++ b/mods/readme.txt
@@ -3,3 +3,4 @@ Site speed can be improved when the following indexes are set. They cannot be se
 CREATE INDEX `uid_commented` ON `item` (`uid`, `commented`);
 CREATE INDEX `uid_created` ON `item` (`uid`, `created`);
 CREATE INDEX `uid_unseen` ON `item` (`uid`, `unseen`);
+CREATE INDEX `resource-id` ON `item` (`resource-id`);

From c9307eb96a1cd6f0f99ef01127a3ec6d356543ef Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Mon, 4 Feb 2013 00:57:23 +0100
Subject: [PATCH 19/28] OStatus conversation are now checked every 30 minutes
 for new answers.

---
 include/ostatus_conversation.php           | 61 ++++++++++++++++++----
 include/poller.php                         |  3 +-
 library/fancybox/jquery.fancybox-1.3.4.css | 16 +++---
 3 files changed, 60 insertions(+), 20 deletions(-)

diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php
index 3d40d673d1..cdaf80d76b 100644
--- a/include/ostatus_conversation.php
+++ b/include/ostatus_conversation.php
@@ -1,9 +1,39 @@
  time()) {
+                        logger('complete_conversation: poll intervall not reached');
+                        return;
+                }
+        }
+
+        logger('complete_conversation: cron_start');
+
+        $start = date("Y-m-d H:i:s", time() - 86400);
+        $conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'", 
+                                dbesc($start));
+        foreach ($conversations AS $conversation) {
+                $id = $conversation['oid'];
+                $url = $conversation['url'];
+                complete_conversation($id, $url);
+        }
+
+        logger('complete_conversation: cron_end');
+
+        set_config('system','ostatus_last_poll', time());
+}
+
+function complete_conversation($itemid, $conversation_url, $only_add_conversation = false) {
+	global $a;
 
 	//logger('complete_conversation: completing conversation url '.$conversation_url.' for id '.$itemid);
 
@@ -12,13 +42,6 @@ function complete_conversation($itemid, $conversation_url) {
 		return;
 	$message = $messages[0];
 
-	// Get the parent
-	$parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
-			intval($message["uid"]), intval($message["parent"]));
-	if (!$parents)
-		return;
-	$parent = $parents[0];
-
 	// Store conversation url if not done before
 	$conversation = q("SELECT `url` FROM `term` WHERE `uid` = %d AND `oid` = %d AND `otype` = %d AND `type` = %d",
 		intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION));
@@ -29,6 +52,19 @@ function complete_conversation($itemid, $conversation_url) {
 		logger('complete_conversation: Storing conversation url '.$conversation_url.' for id '.$itemid);
 	}
 
+	if ($only_add_conversation)
+		return;
+
+	// Get the parent
+	$parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
+			intval($message["uid"]), intval($message["parent"]));
+	if (!$parents)
+		return;
+	$parent = $parents[0];
+
+	require_once('include/html2bbcode.php');
+	require_once('include/items.php');
+
 	$conv = str_replace("/conversation/", "/api/statusnet/conversation/", $conversation_url).".as";
 
 	logger('complete_conversation: fetching conversation url '.$conv.' for '.$itemid);
@@ -111,6 +147,9 @@ function complete_conversation($itemid, $conversation_url) {
 
 			$newitem = item_store($arr);
 
+			// Add the conversation entry (but don't fetch the whole conversation)
+			complete_conversation($newitem, $conversation_url, true);
+
 			// If the newly created item is the top item then change the parent settings of the thread
 			if ($newitem AND ($arr["uri"] == $first_id)) {
 				logger('complete_conversation: setting new parent to id '.$newitem);
diff --git a/include/poller.php b/include/poller.php
index c9c46188f6..e85a4555d3 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -86,7 +86,8 @@ function poller_run(&$argv, &$argc){
 	if($abandon_days < 1)
 		$abandon_days = 0;
 
-
+	// Check OStatus conversations
+	check_conversations();
 
 	// once daily run birthday_updates and then expire in background
 
diff --git a/library/fancybox/jquery.fancybox-1.3.4.css b/library/fancybox/jquery.fancybox-1.3.4.css
index 6f53d8f4a2..50dbd67a89 100644
--- a/library/fancybox/jquery.fancybox-1.3.4.css
+++ b/library/fancybox/jquery.fancybox-1.3.4.css
@@ -349,11 +349,11 @@
 
 .fancybox-ie .fancybox-bg { background: transparent !important; }
 
-.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_n.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_ne.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_e.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_se.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_s.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_sw.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_w.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.png', sizingMethod='scale'); }
\ No newline at end of file
+.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_n.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_ne.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_e.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_se.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_s.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_sw.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_w.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_nw.png', sizingMethod='scale'); }

From 5e077e541ae5c627a9626454f1c36b2a1470d3c4 Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Wed, 6 Feb 2013 08:01:46 +0100
Subject: [PATCH 20/28] The community page is speeded up. Photos will be
 compressed before the output.

---
 mod/community.php |  7 ++++---
 mod/photo.php     | 12 ++++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/mod/community.php b/mod/community.php
index a7f5c9bf82..e267447e41 100644
--- a/mod/community.php
+++ b/mod/community.php
@@ -64,7 +64,8 @@ function community_content(&$a, $update = 0) {
 
 	}
 
-	$r = q("SELECT distinct(`item`.`uri`), `item`.*, `item`.`id` AS `item_id`, 
+	//$r = q("SELECT distinct(`item`.`uri`)
+	$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, 
 		`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`,
@@ -75,13 +76,13 @@ function community_content(&$a, $update = 0) {
 		AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
 		AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' 
 		AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
-		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
 		ORDER BY `received` DESC LIMIT %d, %d ",
 		intval($a->pager['start']),
 		intval($a->pager['itemspage'])
 
 	);
-//		AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 group by `item`.`uri`
+//		group by `item`.`uri`
 
 	if(! count($r)) {
 		info( t('No results.') . EOL);
diff --git a/mod/photo.php b/mod/photo.php
index 93db82a641..c92ab387b0 100644
--- a/mod/photo.php
+++ b/mod/photo.php
@@ -106,7 +106,7 @@ function photo_init(&$a) {
 			intval($resolution)
 		);
 		if(count($r)) {
-			
+
 			$sql_extra = permissions_sql($r[0]['uid']);
 
 			// Now we'll see if we can access the photo
@@ -169,13 +169,13 @@ function photo_init(&$a) {
 		}
 	}
 
-	if(isset($customres) && $customres > 0 && $customres < 500) {
-		$ph = new Photo($data, $mimetype);
-		if($ph->is_valid()) {
+	$ph = new Photo($data, $mimetype);
+	if($ph->is_valid()) {
+		if(isset($customres) && $customres > 0 && $customres < 500) {
 			$ph->scaleImageSquare($customres);
-			$data = $ph->imageString();
-			$mimetype = $ph->getType();
 		}
+		$data = $ph->imageString();
+		$mimetype = $ph->getType();
 	}
 
 	if(function_exists('header_remove')) {

From 3e58060b308f045613c3b57b62c0fb47890c7bdb Mon Sep 17 00:00:00 2001
From: Michael Vogel 
Date: Fri, 15 Feb 2013 20:14:45 +0100
Subject: [PATCH 21/28] API: beautify the output of repeated items Vier:
 Birthday reminder looks better

---
 include/api.php           | 22 +++++++++---------
 include/bbcode.php        | 49 ++++++++++++++++++++++++++++++++-------
 view/theme/vier/style.css |  5 +++-
 3 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/include/api.php b/include/api.php
index 4efb0c614a..81255ca37f 100644
--- a/include/api.php
+++ b/include/api.php
@@ -516,13 +516,13 @@
                         $txt = $purifier->purify($txt);
 		}
 		$txt = html2bbcode($txt);
-		
+
                 $a->argv[1]=$user_info['screen_name']; //should be set to username?
-		
+
 		$_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
                 require_once('mod/wall_upload.php');
 		$bebop = wall_upload_post($a);
-                
+
 		//now that we have the img url in bbcode we can add it to the status and insert the wall item.
                 $_REQUEST['body']=$txt."\n\n".$bebop;
                 require_once('mod/item.php');
@@ -629,7 +629,7 @@
 
 		if (count($lastwall)>0){
 			$lastwall = $lastwall[0];
-			
+
 			$in_reply_to_status_id = '';
 			$in_reply_to_user_id = '';
 			$in_reply_to_screen_name = '';
@@ -637,9 +637,9 @@
 				$in_reply_to_status_id=$lastwall['parent'];
 				$in_reply_to_user_id = $lastwall['reply_uid'];
 				$in_reply_to_screen_name = $lastwall['reply_author'];
-			}  
+			}
 			$status_info = array(
-				'text' => html2plain(bbcode($lastwall['body']), 0),
+				'text' => html2plain(bbcode($lastwall['body'], false, false, true), 0),
 				'truncated' => false,
 				'created_at' => api_date($lastwall['created']),
 				'in_reply_to_status_id' => $in_reply_to_status_id,
@@ -694,11 +694,11 @@
 				$in_reply_to_status_id=$lastwall['parent'];
 				$in_reply_to_user_id = $lastwall['reply_uid'];
 				$in_reply_to_screen_name = $lastwall['reply_author'];
-			}  
+			}
 			$user_info['status'] = array(
 				'created_at' => api_date($lastwall['created']),
 				'id' => $lastwall['contact-id'],
-				'text' => html2plain(bbcode($lastwall['body']), 0),
+				'text' => html2plain(bbcode($lastwall['body'], false, false, true), 0),
 				'source' => (($lastwall['app']) ? $lastwall['app'] : 'web'),
 				'truncated' => false,
 				'in_reply_to_status_id' => $in_reply_to_status_id,
@@ -1300,11 +1300,11 @@
 				$ret['text'] = bbcode($item['body']);
 			}
 			elseif ($_GET["getText"] == "plain") {
-				$ret['text'] = html2plain(bbcode($item['body']), 0);
+				$ret['text'] = html2plain(bbcode($item['body'], false, false, true), 0);
 			}
 		}
 		else {
-			$ret['text'] = $item['title']."\n".html2plain(bbcode($item['body']), 0);
+			$ret['text'] = $item['title']."\n".html2plain(bbcode($item['body'], false, false, true), 0);
 		}
 		if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
 			unset($ret['sender']);
@@ -1348,7 +1348,7 @@
 			}
 
 			// Workaround for ostatus messages where the title is identically to the body
-			$statusbody = trim(html2plain(bbcode($item['body']), 0));
+			$statusbody = trim(html2plain(bbcode($item['body'], false, false, true), 0));
 			$statustitle = trim($item['title']);
 
 			if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false))
diff --git a/include/bbcode.php b/include/bbcode.php
index 45213cc3b7..a587d8c380 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -278,10 +278,37 @@ function bb_ShareAttributes($match) {
         return($text);
 }
 
+function bb_ShareAttributesSimple($match) {
+
+        $attributes = $match[1];
+
+        $author = "";
+        preg_match("/author='(.*?)'/ism", $attributes, $matches);
+        if ($matches[1] != "")
+                $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
+
+        preg_match('/author="(.*?)"/ism', $attributes, $matches);
+        if ($matches[1] != "")
+                $author = $matches[1];
+
+        $profile = "";
+        preg_match("/profile='(.*?)'/ism", $attributes, $matches);
+        if ($matches[1] != "")
+                $profile = $matches[1];
+
+        preg_match('/profile="(.*?)"/ism', $attributes, $matches);
+        if ($matches[1] != "")
+                $profile = $matches[1];
+
+        $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.":
»".$match[2]."«"; + + return($text); +} + // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica - Mike Macgirvin -function bbcode($Text,$preserve_nl = false, $tryoembed = true) { +function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = false) { $stamp1 = microtime(true); @@ -342,13 +369,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace("\r\n","\n", $Text); // removing multiplicated newlines -// $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]"); -// $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]"); -// do { -// $oldtext = $Text; -// $Text = str_replace($search, $replace, $Text); -// } while ($oldtext != $Text); - + if (get_config("system", "remove_multiplicated_lines")) { + $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]"); + $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]"); + do { + $oldtext = $Text; + $Text = str_replace($search, $replace, $Text); + } while ($oldtext != $Text); + } $Text = str_replace(array("\r","\n"), array('
','
'), $Text); @@ -517,7 +545,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); // Shared content - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + if (!$simplehtml) + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + else + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple",$Text); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index aa66769db2..4a116c5b72 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -1020,6 +1020,9 @@ section { max-width: 766px; padding: 10px 10px 10px 10px; background-color: white; + border-bottom: 1px solid lightgray; + border-right: 1px solid lightgray; + border-left: 1px solid lightgray; } /* wall item */ .tread-wrapper { @@ -1727,7 +1730,7 @@ div.pager, .birthday-notice, ul.tabs a, #jot-preview-link, .comment-edit-submit- background: linear-gradient(top, #ffffff 0%,#ececf2 100%);*/ } -#event-notice:hover, ul.tabs li .active, ul.tabs a:hover, #jot-preview-link:hover, .comment-edit-submit-wrapper .fakelink:hover { +#event-notice:hover, #birthday-notice:hover, ul.tabs li .active, ul.tabs a:hover, #jot-preview-link:hover, .comment-edit-submit-wrapper .fakelink:hover { color: black; background-color: #e5e5e5; text-decoration: none; From 1a1984c78de11fd168e383f9151faff5584a7da1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 17 Feb 2013 12:36:54 +0100 Subject: [PATCH 22/28] Updated from master --- library/fancybox/jquery.fancybox-1.3.4.css | 359 --------------------- 1 file changed, 359 deletions(-) delete mode 100644 library/fancybox/jquery.fancybox-1.3.4.css diff --git a/library/fancybox/jquery.fancybox-1.3.4.css b/library/fancybox/jquery.fancybox-1.3.4.css deleted file mode 100644 index 50dbd67a89..0000000000 --- a/library/fancybox/jquery.fancybox-1.3.4.css +++ /dev/null @@ -1,359 +0,0 @@ -/* - * FancyBox - jQuery Plugin - * Simple and fancy lightbox alternative - * - * Examples and documentation at: http://fancybox.net - * - * Copyright (c) 2008 - 2010 Janis Skarnelis - * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. - * - * Version: 1.3.4 (11/11/2010) - * Requires: jQuery v1.3+ - * - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - */ - -#fancybox-loading { - position: fixed; - top: 50%; - left: 50%; - width: 40px; - height: 40px; - margin-top: -20px; - margin-left: -20px; - cursor: pointer; - overflow: hidden; - z-index: 1104; - display: none; -} - -#fancybox-loading div { - position: absolute; - top: 0; - left: 0; - width: 40px; - height: 480px; - background-image: url('fancybox.png'); -} - -#fancybox-overlay { - position: absolute; - top: 0; - left: 0; - width: 100%; - z-index: 1100; - display: none; -} - -#fancybox-tmp { - padding: 0; - margin: 0; - border: 0; - overflow: auto; - display: none; -} - -#fancybox-wrap { - position: absolute; - top: 0; - left: 0; - padding: 20px; - z-index: 1101; - outline: none; - display: none; -} - -#fancybox-outer { - position: relative; - width: 100%; - height: 100%; - background: #fff; -} - -#fancybox-content { - width: 0; - height: 0; - padding: 0; - outline: none; - position: relative; - overflow: hidden; - z-index: 1102; - border: 0px solid #fff; -} - -#fancybox-hide-sel-frame { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - background: transparent; - z-index: 1101; -} - -#fancybox-close { - position: absolute; - top: -15px; - right: -15px; - width: 30px; - height: 30px; - background: transparent url('fancybox.png') -40px 0px; - cursor: pointer; - z-index: 1103; - display: none; -} - -#fancybox-error { - color: #444; - font: normal 12px/20px Arial; - padding: 14px; - margin: 0; -} - -#fancybox-img { - width: 100%; - height: 100%; - padding: 0; - margin: 0; - border: none; - outline: none; - line-height: 0; - vertical-align: top; -} - -#fancybox-frame { - width: 100%; - height: 100%; - border: none; - display: block; -} - -#fancybox-left, #fancybox-right { - position: absolute; - bottom: 0px; - height: 100%; - width: 35%; - cursor: pointer; - outline: none; - background: transparent url('blank.gif'); - z-index: 1102; - display: none; -} - -#fancybox-left { - left: 0px; -} - -#fancybox-right { - right: 0px; -} - -#fancybox-left-ico, #fancybox-right-ico { - position: absolute; - top: 50%; - left: -9999px; - width: 30px; - height: 30px; - margin-top: -15px; - cursor: pointer; - z-index: 1102; - display: block; -} - -#fancybox-left-ico { - background-image: url('fancybox.png'); - background-position: -40px -30px; -} - -#fancybox-right-ico { - background-image: url('fancybox.png'); - background-position: -40px -60px; -} - -#fancybox-left:hover, #fancybox-right:hover { - visibility: visible; /* IE6 */ -} - -#fancybox-left:hover span { - left: 20px; -} - -#fancybox-right:hover span { - left: auto; - right: 20px; -} - -.fancybox-bg { - position: absolute; - padding: 0; - margin: 0; - border: 0; - width: 20px; - height: 20px; - z-index: 1001; -} - -#fancybox-bg-n { - top: -20px; - left: 0; - width: 100%; - background-image: url('fancybox-x.png'); -} - -#fancybox-bg-ne { - top: -20px; - right: -20px; - background-image: url('fancybox.png'); - background-position: -40px -162px; -} - -#fancybox-bg-e { - top: 0; - right: -20px; - height: 100%; - background-image: url('fancybox-y.png'); - background-position: -20px 0px; -} - -#fancybox-bg-se { - bottom: -20px; - right: -20px; - background-image: url('fancybox.png'); - background-position: -40px -182px; -} - -#fancybox-bg-s { - bottom: -20px; - left: 0; - width: 100%; - background-image: url('fancybox-x.png'); - background-position: 0px -20px; -} - -#fancybox-bg-sw { - bottom: -20px; - left: -20px; - background-image: url('fancybox.png'); - background-position: -40px -142px; -} - -#fancybox-bg-w { - top: 0; - left: -20px; - height: 100%; - background-image: url('fancybox-y.png'); -} - -#fancybox-bg-nw { - top: -20px; - left: -20px; - background-image: url('fancybox.png'); - background-position: -40px -122px; -} - -#fancybox-title { - font-family: Helvetica; - font-size: 12px; - z-index: 1102; -} - -.fancybox-title-inside { - padding-bottom: 10px; - text-align: center; - color: #333; - background: #fff; - position: relative; -} - -.fancybox-title-outside { - padding-top: 10px; - color: #fff; -} - -.fancybox-title-over { - position: absolute; - bottom: 0; - left: 0; - color: #FFF; - text-align: left; -} - -#fancybox-title-over { - padding: 10px; - background-image: url('fancy_title_over.png'); - display: block; -} - -.fancybox-title-float { - position: absolute; - left: 0; - bottom: -20px; - height: 32px; -} - -#fancybox-title-float-wrap { - border: none; - border-collapse: collapse; - width: auto; -} - -#fancybox-title-float-wrap td { - border: none; - white-space: nowrap; -} - -#fancybox-title-float-left { - padding: 0 0 0 15px; - background: url('fancybox.png') -40px -90px no-repeat; -} - -#fancybox-title-float-main { - color: #FFF; - line-height: 29px; - font-weight: bold; - padding: 0 0 3px 0; - background: url('fancybox-x.png') 0px -40px; -} - -#fancybox-title-float-right { - padding: 0 0 0 15px; - background: url('fancybox.png') -55px -90px no-repeat; -} - -/* IE6 */ - -.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_close.png', sizingMethod='scale'); } - -.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_left.png', sizingMethod='scale'); } -.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.png', sizingMethod='scale'); } - -.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_over.png', sizingMethod='scale'); zoom: 1; } -.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_left.png', sizingMethod='scale'); } -.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_main.png', sizingMethod='scale'); } -.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); } - -.fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame { - height: expression(this.parentNode.clientHeight + "px"); -} - -#fancybox-loading.fancybox-ie6 { - position: absolute; margin-top: 0; - top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'); -} - -#fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_loading.png', sizingMethod='scale'); } - -/* IE6, IE7, IE8 */ - -.fancybox-ie .fancybox-bg { background: transparent !important; } - -.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_n.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_ne.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_e.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_se.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_s.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_sw.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_w.png', sizingMethod='scale'); } -.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='library/fancybox/fancy_shadow_nw.png', sizingMethod='scale'); } From 7e154d5e4cb0c6be4631beef33a2ec1acc1fbdf5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 17 Feb 2013 18:05:30 +0100 Subject: [PATCH 23/28] plugin: orphaned hooks weren't deleted. update: fixing update job for tags. --- boot.php | 2 +- include/plugin.php | 2 +- update.php | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/boot.php b/boot.php index d77e653f14..0467524f68 100644 --- a/boot.php +++ b/boot.php @@ -14,7 +14,7 @@ require_once('include/features.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_VERSION', '3.1.1612' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1161 ); +define ( 'DB_UPDATE_VERSION', 1162 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/include/plugin.php b/include/plugin.php index 9795cacf92..b89cb2c53d 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -175,7 +175,7 @@ function call_hooks($name, &$data = null) { } else { // remove orphan hooks - q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1", + q("delete from hook where hook = '%s' and file = '%s' and function = '%s' limit 1", dbesc($name), dbesc($hook[0]), dbesc($hook[1]) diff --git a/update.php b/update.php index 89b55cdb9c..6dd58757b9 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Sun, 17 Feb 2013 18:46:39 +0100 Subject: [PATCH 24/28] added robots.txt to the igmnored files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 038ac32a55..bf4bd454b1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ favicon.* home.html addon *~ +robots.txt #ignore documentation, it should be newly built doc/api From 39d8fec290613cac87c2821b9f7b20fa94d319ca Mon Sep 17 00:00:00 2001 From: 23n Date: Wed, 20 Feb 2013 21:01:19 +0100 Subject: [PATCH 25/28] no more googlegroups googlegroup links deleted, librelist mail list archive added --- doc/Home.md | 3 +-- doc/de/Home.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/Home.md b/doc/Home.md index b54ce35856..e986c89ac9 100644 --- a/doc/Home.md +++ b/doc/Home.md @@ -36,8 +36,7 @@ Friendica Documentation and Resources **External Resources** * [Main Website](http://friendica.com) -* [Forums](http://groups.google.com/group/friendica) -* [Developer Forums](http://groups.google.com/group/friendica-dev) +* [Mailing List Archive](http://librelist.com/browser/friendica/) **About** diff --git a/doc/de/Home.md b/doc/de/Home.md index b2d8c52e4f..260e368a9e 100644 --- a/doc/de/Home.md +++ b/doc/de/Home.md @@ -36,8 +36,7 @@ Friendica - Dokumentation und Ressourcen **Externe Ressourcen** * [Haupt-Webseite](http://friendica.com) -* [Foren](http://groups.google.com/group/friendica) -* [Entwickler-Foren](http://groups.google.com/group/friendica-dev) +* [Mailing Liste](http://librelist.com/browser/friendica/) * [Deutsches Friendica-Wiki](http://wiki.toktan.org/doku.php) **Über diese Seite** From 7a1947b88a688505298959020e000c186139c806 Mon Sep 17 00:00:00 2001 From: pixelroot Date: Wed, 20 Feb 2013 21:03:02 +0100 Subject: [PATCH 26/28] modified: view/theme/smoothly/style.css modified: view/theme/smoothly/theme.php --- view/theme/smoothly/style.css | 73 +++++++++++++++++++++++++++++------ view/theme/smoothly/theme.php | 2 +- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index 8e240da3ef..e347ce4e1c 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -2,7 +2,7 @@ style.css Smoothly - Created by alex@friendica.pixelbits.de on 2013-01-11 + Created by alex@friendica.pixelbits.de on 2013-02-20 ** Colors ** Blue links - #1873a2 @@ -3522,7 +3522,7 @@ margin-left: 0px; /* ========= */ #adminpage { - width: 80%; + width: 90%; } #pending-update { @@ -3630,13 +3630,25 @@ margin-left: 0px; /* =============== */ .field { - width: 90%; + margin-bottom: 10px; + overflow: auto; + padding-bottom: 0px; + width: 100%; +} + +.field.radio .field_help { + margin-left: 205px; +} + +.field .field_help { + color: #666666; + display: block; + margin-left: 200px; } .field label { - float: left; - min-width: 120px; - margin: 5px 10px 0 0; + float: left; + width: 200px; } .field checkbox { @@ -3646,17 +3658,13 @@ margin-left: 0px; .field input, .field textarea { - width: 220px; + width: 400px; border: 1px solid #CDCDCD; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } -.field textarea { - height: 100px; -} - .field password { height: 100px; margin-left: 150px; @@ -4346,6 +4354,12 @@ div #datebrowse-sidebar.widget { margin:10px 10px 0 0; } +#id_maxreq, +#id_cntunkmail, +#id_expire { + width: 75px; +} + #id_post_newfriend, #id_post_joingroup, #id_post_profilechange, @@ -4358,7 +4372,7 @@ div #datebrowse-sidebar.widget { #id_notify7, #id_notify8, #id_allow_location { - margin: 6px 0 0 0; + margin: 6px 0 0 10px; } #settings-form {} @@ -4374,6 +4388,7 @@ div #datebrowse-sidebar.widget { } #settings-notifications { + width: 400px; border: 1px solid #7C7D7B; box-shadow: 0 0 8px #BDBDBD; -moz-box-shadow: 3px 3px 4px #959494; @@ -4426,3 +4441,37 @@ div #datebrowse-sidebar.widget { width: auto !important; margin-bottom: 5px !important; } + +.onoff { + margin-right: 10px; +} + +.settings-heading { + margin: 25px 0 25px 0; +} + +#id_itemcache, +#id_basepath, +#id_temppath, +#id_lockpath, +#id_proxyuser, +#id_proxy, +#id_allowed_email, +#id_allowed_sites, +#id_directory_submit_url, +#id_register_text { + width: 440px; +} + +#id_itemcache_duration, +#id_abandon_days, +#id_maxloadavg, +#id_poll_interval, +#id_delivery_interval, +#id_timeout, +#id_jpegimagequality, +#id_maximagelength, +#id_maximagesize, +#id_max_daily_registrations { + width: 75px; +} diff --git a/view/theme/smoothly/theme.php b/view/theme/smoothly/theme.php index 16a33d678c..c88b278274 100644 --- a/view/theme/smoothly/theme.php +++ b/view/theme/smoothly/theme.php @@ -3,7 +3,7 @@ /* * Name: Smoothly * Description: Like coffee with milk. Theme optimized for iPad[2]. - * Version: Version 0.132 + * Version: Version 0.21 * Author: Alex * Maintainer: Alex * Screenshot: Screenshot From c90272e2ae52ecab496c6aab068a485b8b22e19a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 20 Feb 2013 21:47:36 +0100 Subject: [PATCH 27/28] supressing warning when importing items. Speeding up community. Changed query for the search. --- include/items.php | 16 +++++++++------- mod/community.php | 2 +- mod/search.php | 10 +++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/items.php b/include/items.php index 46eafdc25b..b7be27932f 100755 --- a/include/items.php +++ b/include/items.php @@ -835,14 +835,16 @@ function get_atom_elements($feed,$item) { // Search for ostatus conversation url $links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"]; - foreach ($links as $link) { - $conversation = array_shift($link["attribs"]); + if (is_array($links)) { + foreach ($links as $link) { + $conversation = array_shift($link["attribs"]); - if ($conversation["rel"] == "ostatus:conversation") { - $res["ostatus_conversation"] = $conversation["href"]; - logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]); - } - }; + if ($conversation["rel"] == "ostatus:conversation") { + $res["ostatus_conversation"] = $conversation["href"]; + logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]); + } + }; + } $arr = array('feed' => $feed, 'item' => $item, 'result' => $res); diff --git a/mod/community.php b/mod/community.php index e267447e41..27a9e21941 100644 --- a/mod/community.php +++ b/mod/community.php @@ -70,7 +70,7 @@ function community_content(&$a, $update = 0) { `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, `user`.`nickname`, `user`.`hidewall` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM `item` FORCE INDEX (`received`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' diff --git a/mod/search.php b/mod/search.php index 93feebdd9a..f7d235d458 100644 --- a/mod/search.php +++ b/mod/search.php @@ -140,9 +140,13 @@ function search_content(&$a) { }*/ if($tag) { - $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d", + //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d", + // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); + //$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + + $sql_extra = sprintf(" AND EXISTS (SELECT * FROM `term` WHERE `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d) GROUP BY `item`.`uri` ", dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); - $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + $sql_table = "`item` FORCE INDEX (`uri`) "; } 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))); @@ -178,7 +182,7 @@ function search_content(&$a) { } } - $r = q("SELECT distinct(`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`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, From 5c6562a996ceed10154cb8305b6a6950f22dc2db Mon Sep 17 00:00:00 2001 From: pixelroot Date: Thu, 21 Feb 2013 08:46:30 +0100 Subject: [PATCH 28/28] modified: view/theme/smoothly/style.css --- view/theme/smoothly/style.css | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index e347ce4e1c..cbce920e73 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -2,7 +2,7 @@ style.css Smoothly - Created by alex@friendica.pixelbits.de on 2013-02-20 + Created by alex@friendica.pixelbits.de on 2013-02-21 ** Colors ** Blue links - #1873a2 @@ -202,6 +202,12 @@ section { clear: both; } +.login-extra-links { + width: 100%; + margin-left: 145px; + clear: both; +} + #login-extra-links a { display: block; margin: 10px; @@ -215,7 +221,7 @@ section { } #login_standard { - width: 250px; + width: 260px; float: left; border: 1px solid #7C7D7B; border-radius: 5px; @@ -256,7 +262,7 @@ section { } #login-submit-button { - width: 271px; + width: 280px; } .login-form, @@ -4475,3 +4481,4 @@ div #datebrowse-sidebar.widget { #id_max_daily_registrations { width: 75px; } +