Remove the old hashtag functions, change it to the new functionality.

This commit is contained in:
Michael Vogel 2015-03-01 20:40:38 +01:00
parent bf0f7c3d0a
commit 3f1d186106
3 changed files with 23 additions and 113 deletions

View file

@ -833,32 +833,6 @@ function diaspora_post($importer,$xml,$msg) {
$str_tags = ''; $str_tags = '';
$tags = get_tags($body);
rsort($tags);
if(count($tags)) {
foreach($tags as $tag) {
if(strpos($tag,'#') === 0) {
if(strpos($tag,'[url='))
continue;
// don't link tags that are already embedded in links
if(preg_match('/\[(\S*?)' . preg_quote($tag,'/') . '(\S*?)\]/',$body))
continue;
if(preg_match('/\[(\S*?)\]\((\S*?)' . preg_quote($tag,'/') . '(\S*?)\)/',$body))
continue;
$basetag = str_replace('_',' ',substr($tag,1));
$body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
if(strlen($str_tags))
$str_tags .= ',';
$str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
continue;
}
}
}
$cnt = preg_match_all('/@\[url=(.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); $cnt = preg_match_all('/@\[url=(.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER);
if($cnt) { if($cnt) {
foreach($matches as $mtch) { foreach($matches as $mtch) {
@ -1055,34 +1029,8 @@ function diaspora_fetch_message($guid, $server, $level = 0) {
return false; return false;
$item["tag"] = ''; $item["tag"] = '';
$tags = get_tags($body);
if(count($tags)) {
foreach($tags as $tag) {
if(strpos($tag,'#') === 0) {
if(strpos($tag,'[url='))
continue;
// don't link tags that are already embedded in links
if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
continue;
if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
continue;
$basetag = str_replace('_',' ',substr($tag,1));
$body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
if(strlen($item["tag"]))
$item["tag"] .= ',';
$item["tag"] .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
continue;
}
}
}
$item["body"] = $body; $item["body"] = $body;
return $item; return $item;
} }
@ -1482,34 +1430,6 @@ function diaspora_comment($importer,$xml,$msg) {
$datarray = array(); $datarray = array();
$str_tags = '';
$tags = get_tags($body);
if(count($tags)) {
foreach($tags as $tag) {
if(strpos($tag,'#') === 0) {
if(strpos($tag,'[url='))
continue;
// don't link tags that are already embedded in links
if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
continue;
if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
continue;
$basetag = str_replace('_',' ',substr($tag,1));
$body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
if(strlen($str_tags))
$str_tags .= ',';
$str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
continue;
}
}
}
$datarray['uid'] = $importer['uid']; $datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id']; $datarray['contact-id'] = $contact['id'];
$datarray['type'] = 'remote-comment'; $datarray['type'] = 'remote-comment';
@ -1533,7 +1453,6 @@ function diaspora_comment($importer,$xml,$msg) {
$datarray['author-link'] = $person['url']; $datarray['author-link'] = $person['url'];
$datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
$datarray['body'] = $body; $datarray['body'] = $body;
$datarray['tag'] = $str_tags;
// We can't be certain what the original app is if the message is relayed. // We can't be certain what the original app is if the message is relayed.
if(($parent_item['origin']) && (! $parent_author_signature)) if(($parent_item['origin']) && (! $parent_author_signature))

View file

@ -1610,7 +1610,16 @@ function item_body_set_hashtags(&$item) {
continue; continue;
$basetag = str_replace('_',' ',substr($tag,1)); $basetag = str_replace('_',' ',substr($tag,1));
$item["body"] = str_replace($tag,'#[url='.$a->get_baseurl().'/search?tag='.rawurlencode($basetag).']'.$basetag.'[/url]', $item["body"]);
$newtag = '#[url='.$a->get_baseurl().'/search?tag='.rawurlencode($basetag).']'.$basetag.'[/url]';
$item["body"] = str_replace($tag, $newtag, $item["body"]);
if(!stristr($item["tag"],"/search?tag=".$basetag."]".$basetag."[/url]")) {
if(strlen($item["tag"]))
$item["tag"] = ','.$item["tag"];
$item["tag"] = $newtag.$item["tag"];
}
} }
// Convert back the masked hashtags // Convert back the masked hashtags

View file

@ -23,6 +23,7 @@ require_once('include/tags.php');
require_once('include/files.php'); require_once('include/files.php');
require_once('include/threads.php'); require_once('include/threads.php');
require_once('include/text.php'); require_once('include/text.php');
require_once('include/items.php');
function item_post(&$a) { function item_post(&$a) {
@ -34,7 +35,6 @@ function item_post(&$a) {
$uid = local_user(); $uid = local_user();
if(x($_REQUEST,'dropitems')) { if(x($_REQUEST,'dropitems')) {
require_once('include/items.php');
$arr_drop = explode(',',$_REQUEST['dropitems']); $arr_drop = explode(',',$_REQUEST['dropitems']);
drop_items($arr_drop); drop_items($arr_drop);
$json = array('success' => 1); $json = array('success' => 1);
@ -569,7 +569,7 @@ function item_post(&$a) {
* and we are replying, and there isn't one already * and we are replying, and there isn't one already
*/ */
if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS) if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS)
&& ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) { && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
$body = '@' . $parent_contact['nick'] . ' ' . $body; $body = '@' . $parent_contact['nick'] . ' ' . $body;
$tags[] = '@' . $parent_contact['nick']; $tags[] = '@' . $parent_contact['nick'];
@ -582,6 +582,9 @@ function item_post(&$a) {
if(count($tags)) { if(count($tags)) {
foreach($tags as $tag) { foreach($tags as $tag) {
if(strpos($tag,'#') === 0)
continue;
// If we already tagged 'Robert Johnson', don't try and tag 'Robert'. // If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
// Robert Johnson should be first in the $tags array // Robert Johnson should be first in the $tags array
@ -713,6 +716,9 @@ function item_post(&$a) {
if($orig_post) if($orig_post)
$datarray['edit'] = true; $datarray['edit'] = true;
// Search for hashtags
item_body_set_hashtags($datarray);
// preview mode - prepare the body for display and send it via json // preview mode - prepare the body for display and send it via json
if($preview) { if($preview) {
@ -1035,10 +1041,9 @@ function item_content(&$a) {
$o = ''; $o = '';
if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
require_once('include/items.php');
$o = drop_item($a->argv[2], !is_ajax()); $o = drop_item($a->argv[2], !is_ajax());
if (is_ajax()){ if (is_ajax()){
// ajax return: [<item id>, 0 (no perm) | <owner id>] // ajax return: [<item id>, 0 (no perm) | <owner id>]
echo json_encode(array(intval($a->argv[2]), intval($o))); echo json_encode(array(intval($a->argv[2]), intval($o)));
killme(); killme();
} }
@ -1047,9 +1052,9 @@ function item_content(&$a) {
} }
/** /**
* This function removes the tag $tag from the text $body and replaces it with * This function removes the tag $tag from the text $body and replaces it with
* the appropiate link. * the appropiate link.
* *
* @param unknown_type $body the text to replace the tag in * @param unknown_type $body the text to replace the tag in
* @param unknown_type $inform a comma-seperated string containing everybody to inform * @param unknown_type $inform a comma-seperated string containing everybody to inform
* @param unknown_type $str_tags string to add the tag to * @param unknown_type $str_tags string to add the tag to
@ -1063,29 +1068,6 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
$replaced = false; $replaced = false;
$r = null; $r = null;
//is it a hash tag?
if(strpos($tag,'#') === 0) {
//if the tag is replaced...
if(strpos($tag,'[url='))
//...do nothing
return $replaced;
//base tag has the tags name only
$basetag = str_replace('_',' ',substr($tag,1));
//create text for link
$newtag = '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
//replace tag by the link
$body = str_replace($tag, $newtag, $body);
$replaced = true;
//is the link already in str_tags?
if(! stristr($str_tags,$newtag)) {
//append or set str_tags
if(strlen($str_tags))
$str_tags .= ',';
$str_tags .= $newtag;
}
return $replaced;
}
//is it a person tag? //is it a person tag?
if(strpos($tag,'@') === 0) { if(strpos($tag,'@') === 0) {
//is it already replaced? //is it already replaced?