diff options
-rwxr-xr-x | include/api.php | 37 | ||||
-rw-r--r-- | include/html2plain.php | 63 |
2 files changed, 83 insertions, 17 deletions
diff --git a/include/api.php b/include/api.php index aacd47177..64772d657 100755 --- a/include/api.php +++ b/include/api.php @@ -785,6 +785,7 @@ api_register_func('api/statuses/show','api_statuses_show', true); //api_register_func('api/statuses/mentions','api_statuses_mentions', true); + //api_register_func('api/statuses/replies','api_statuses_mentions', true); function api_statuses_user_timeline(&$a, $type){ @@ -932,7 +933,7 @@ } $status = array( - 'text' => html2plain(bbcode($item['body']), 0), + 'text' => trim($item['title']." \n".html2plain(bbcode($item['body']), 0)), 'truncated' => False, 'created_at'=> api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, @@ -1306,4 +1307,36 @@ api_register_func('api/oauth/request_token', 'api_oauth_request_token', false); api_register_func('api/oauth/access_token', 'api_oauth_access_token', false); - +/* +Not implemented by now: +statuses/public_timeline +statuses/mentions +statuses/replies +statuses/retweets_of_me +statuses/destroy +statuses/retweet +friendships/create +friendships/destroy +friendships/exists +friendships/show +account/update_location +account/update_profile_background_image +account/update_profile_image +favorites +favorites/create +favorites/destroy +blocks/create +blocks/destroy +oauth/authorize + +Not implemented in status.net: +statuses/retweeted_to_me +statuses/retweeted_by_me +direct_messages/destroy +account/end_session +account/update_delivery_device +notifications/follow +notifications/leave +blocks/exists +blocks/blocking +*/ diff --git a/include/html2plain.php b/include/html2plain.php index d367d7c1f..fe0e3326e 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -5,7 +5,9 @@ function breaklines($line, $level, $wraplength = 75) { if ($wraplength == 0) - return($line); + $wraplength = 2000000; + + // return($line); $wraplen = $wraplength-$level; @@ -74,7 +76,26 @@ function quotelevel($message, $wraplength = 75) return(implode($newlines, "\n")); } -function html2plain($html, $wraplength = 75) +function collecturls($message) { + $pattern = '/<a.*?href="(.*?)".*?>(.*?)<\/a>/is'; + preg_match_all($pattern, $message, $result, PREG_SET_ORDER); + + $urls = array(); + foreach ($result as $treffer) { + // A list of some links that should be ignored + $list = array("/user/", "/tag/", "/profile/", "/search?search=", "mailto:", "/u/", "/node/", + "//facebook.com/profile.php?id=", "//plus.google.com/"); + foreach ($list as $listitem) + if (strpos($treffer[1], $listitem) !== false) + $ignore = true; + + if (!$ignore) + $urls[$treffer[1]] = $treffer[1]; + } + return($urls); +} + +function html2plain($html, $wraplength = 75, $compact = false) { global $lang; @@ -97,16 +118,9 @@ function html2plain($html, $wraplength = 75) $message = str_replace(array("\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"), array("<", ">", "<br>", " ", ""), $message); $message = preg_replace('= [\s]*=i', " ", $message); - // nach <a href="...">...</a> suchen, die ... miteinander vergleichen und bei Gleichheit durch ein einzelnes ... ersetzen. - $pattern = '/<a.*?href="(.*?)".*?>(.*?)<\/a>/is'; - preg_match_all($pattern, $message, $result, PREG_SET_ORDER); + // Collecting all links + $urls = collecturls($message); - foreach ($result as $treffer) { - if ($treffer[1] == $treffer[2]) { - $search = '<a href="'.$treffer[1].'" target="external-link">'.$treffer[1].'</a>'; - $message = str_replace($search, $treffer[1], $message); - } - } @$doc->loadHTML($message); node2bbcode($doc, 'html', array(), '', ''); @@ -124,7 +138,10 @@ function html2plain($html, $wraplength = 75) node2bbcode($doc, 'u', array(), '_', '_'); */ - node2bbcode($doc, 'blockquote', array(), '[quote]', "[/quote]\n"); + if ($compact) + node2bbcode($doc, 'blockquote', array(), "»", "«"); + else + node2bbcode($doc, 'blockquote', array(), '[quote]', "[/quote]\n"); node2bbcode($doc, 'br', array(), "\n", ''); @@ -151,15 +168,23 @@ function html2plain($html, $wraplength = 75) // Problem: there is no reliable way to detect if it is a link to a tag or profile //node2bbcode($doc, 'a', array('href'=>'/(.+)/'), ' $1 ', '', true); + node2bbcode($doc, 'a', array('href'=>'/(.+)/', 'rel'=>'oembed'), ' $1 ', '', true); //node2bbcode($doc, 'img', array('alt'=>'/(.+)/'), '$1', ''); //node2bbcode($doc, 'img', array('title'=>'/(.+)/'), '$1', ''); //node2bbcode($doc, 'img', array(), '', ''); - node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]'); + if (!$compact) + node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]'); + else + node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '', ''); + + node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), ' $1 ', '', true); $message = $doc->saveHTML(); - $message = str_replace("[img]", "", $message); - $message = str_replace("[/img]", "", $message); + if (!$compact) { + $message = str_replace("[img]", "", $message); + $message = str_replace("[/img]", "", $message); + } // was ersetze ich da? // Irgendein stoerrisches UTF-Zeug @@ -175,6 +200,14 @@ function html2plain($html, $wraplength = 75) $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8'); + if (!$compact) { + $counter = 1; + foreach ($urls as $id=>$url) + if (strpos($message, $url) == false) + $message .= "\n".$url." "; + //$message .= "\n[".($counter++)."] ".$url; + } + do { $oldmessage = $message; $message = str_replace("\n\n\n", "\n\n", $message); |