Remove the old hashtag functions, change it to the new functionality.
This commit is contained in:
parent
bf0f7c3d0a
commit
3f1d186106
3 changed files with 23 additions and 113 deletions
|
@ -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))
|
||||||
|
|
|
@ -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
|
||||||
|
|
32
mod/item.php
32
mod/item.php
|
@ -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);
|
||||||
|
@ -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,7 +1041,6 @@ 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>]
|
||||||
|
@ -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?
|
||||||
|
|
Loading…
Reference in a new issue