Browse Source

Merge pull request #4399 from MrPetovan/task/3878-move-include-bbcode-to-src

Move include/bbcode to src/ part 1 : Everything but bbcode()
pull/4410/head
Tobias Diekershoff 4 years ago
committed by GitHub
parent
commit
85c8bf0228
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 66
      boot.php
  2. 23
      doc/BBCode.md
  3. 4
      include/acl_selectors.php
  4. 4
      include/api.php
  5. 10
      include/bb2diaspora.php
  6. 1439
      include/bbcode.php
  7. 8
      include/conversation.php
  8. 4
      mod/display.php
  9. 1365
      src/Content/Text/BBCode.php
  10. 37
      src/Content/Text/Plaintext.php
  11. 124
      src/Core/Protocol.php
  12. 8
      src/Model/Conversation.php
  13. 5
      src/Protocol/DFRN.php
  14. 13
      view/theme/frio/theme.php
  15. 10
      view/theme/frost/theme.php

66
boot.php

@ -1,6 +1,6 @@
<?php
/** @file boot.php
*
/**
* @file_tag_unsave_file boot.php
* This file defines some global constants and includes the central App class.
*/
@ -24,11 +24,13 @@ use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Database\DBStructure;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Util\DateTimeFormat;
require_once 'include/text.php';
@ -232,47 +234,51 @@ define('CP_USERS_AND_GLOBAL', 2);
/**
* @name Protocols
* @deprecated since version 3.6
* @see Conversation
*
* Different protocols that we are storing
* @{
*/
define('PROTOCOL_UNKNOWN', 0);
define('PROTOCOL_DFRN', 1);
define('PROTOCOL_DIASPORA', 2);
define('PROTOCOL_OSTATUS_SALMON', 3);
define('PROTOCOL_OSTATUS_FEED', 4); // Deprecated
define('PROTOCOL_GS_CONVERSATION', 5); // Deprecated
define('PROTOCOL_SPLITTED_CONV', 6);
define('PROTOCOL_UNKNOWN' , Conversation::PROTOCOL_UNKNOWN);
define('PROTOCOL_DFRN' , Conversation::PROTOCOL_DFRN);
define('PROTOCOL_DIASPORA' , Conversation::PROTOCOL_DIASPORA);
define('PROTOCOL_OSTATUS_SALMON' , Conversation::PROTOCOL_OSTATUS_SALMON);
define('PROTOCOL_OSTATUS_FEED' , Conversation::PROTOCOL_OSTATUS_FEED); // Deprecated
define('PROTOCOL_GS_CONVERSATION', Conversation::PROTOCOL_GS_CONVERSATION); // Deprecated
define('PROTOCOL_SPLITTED_CONV' , Conversation::PROTOCOL_SPLITTED_CONV);
/**
* @}
*/
/**
* @name Network
* @name Network constants
* @deprecated since version 3.6
* @see Protocol
*
* Network and protocol family types
* @{
*/
define('NETWORK_DFRN', 'dfrn'); // Friendica, Mistpark, other DFRN implementations
define('NETWORK_ZOT', 'zot!'); // Zot! - Currently unsupported
define('NETWORK_OSTATUS', 'stat'); // GNU-social, Pleroma, Mastodon, other OStatus implementations
define('NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol
define('NETWORK_DIASPORA', 'dspr'); // Diaspora
define('NETWORK_MAIL', 'mail'); // IMAP/POP
define('NETWORK_FACEBOOK', 'face'); // Facebook API
define('NETWORK_LINKEDIN', 'lnkd'); // LinkedIn
define('NETWORK_XMPP', 'xmpp'); // XMPP - Currently unsupported
define('NETWORK_MYSPACE', 'mysp'); // MySpace - Currently unsupported
define('NETWORK_GPLUS', 'goog'); // Google+
define('NETWORK_PUMPIO', 'pump'); // pump.io
define('NETWORK_TWITTER', 'twit'); // Twitter
define('NETWORK_DIASPORA2', 'dspc'); // Diaspora connector
define('NETWORK_STATUSNET', 'stac'); // Statusnet connector
define('NETWORK_APPNET', 'apdn'); // app.net - Dead protocol
define('NETWORK_NEWS', 'nntp'); // Network News Transfer Protocol - Currently unsupported
define('NETWORK_ICALENDAR', 'ical'); // iCalendar - Currently unsupported
define('NETWORK_PNUT', 'pnut'); // pnut.io - Currently unsupported
define('NETWORK_PHANTOM', 'unkn'); // Place holder
define('NETWORK_DFRN' , Protocol::DFRN); // Friendica, Mistpark, other DFRN implementations
define('NETWORK_ZOT' , Protocol::ZOT); // Zot! - Currently unsupported
define('NETWORK_OSTATUS' , Protocol::OSTATUS); // GNU-social, Pleroma, Mastodon, other OStatus implementations
define('NETWORK_FEED' , Protocol::FEED); // RSS/Atom feeds with no known "post/notify" protocol
define('NETWORK_DIASPORA' , Protocol::DIASPORA); // Diaspora
define('NETWORK_MAIL' , Protocol::MAIL); // IMAP/POP
define('NETWORK_FACEBOOK' , Protocol::FACEBOOK); // Facebook API
define('NETWORK_LINKEDIN' , Protocol::LINKEDIN); // LinkedIn
define('NETWORK_XMPP' , Protocol::XMPP); // XMPP - Currently unsupported
define('NETWORK_MYSPACE' , Protocol::MYSPACE); // MySpace - Currently unsupported
define('NETWORK_GPLUS' , Protocol::GPLUS); // Google+
define('NETWORK_PUMPIO' , Protocol::PUMPIO); // pump.io
define('NETWORK_TWITTER' , Protocol::TWITTER); // Twitter
define('NETWORK_DIASPORA2', Protocol::DIASPORA2); // Diaspora connector
define('NETWORK_STATUSNET', Protocol::STATUSNET); // Statusnet connector
define('NETWORK_APPNET' , Protocol::APPNET); // app.net - Dead protocol
define('NETWORK_NEWS' , Protocol::NEWS); // Network News Transfer Protocol - Currently unsupported
define('NETWORK_ICALENDAR', Protocol::ICALENDAR); // iCalendar - Currently unsupported
define('NETWORK_PNUT' , Protocol::PNUT); // pnut.io - Currently unsupported
define('NETWORK_PHANTOM' , Protocol::PHANTOM); // Place holder
/**
* @}
*/

23
doc/BBCode.md

@ -165,7 +165,7 @@ line
code</code></td>
</tr>
<tr>
<td>[code=php]function text_highlight($s,$lang)[/code]</td>
<td>[code=php]function text_highlight($s,$lang)[/code]<sup><a href="#supported-code">1</a></sup></td>
<td><code><div class="hl-main"><ol class="hl-main"><li><span class="hl-code">&nbsp;</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">text_highlight</span><span class="hl-brackets">(</span><span class="hl-var">$s</span><span class="hl-code">,</span><span class="hl-var">$lang</span><span class="hl-brackets">)</span></li></ol></div></code></td>
</tr>
<tr>
@ -208,6 +208,27 @@ code</code></td>
</tr>
</table>
<a name="supported-code">1</a>: Supported language parameter values for code highlighting:
- abap
- avrc
- cpp
- css
- diff
- dtd
- html
- java
- javascript
- js
- mysql
- perl
- php
- python
- ruby
- sh
- sql
- vbscript
- xml
### Titles
<table class="bbcodes">

4
include/acl_selectors.php

@ -2,12 +2,14 @@
/**
* @file include/acl_selectors.php
*/
use Friendica\App;
use Friendica\Content\Feature;
use Friendica\Content\Widget;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
@ -248,7 +250,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
}
if ($privmail) {
$trimmed = GetProfileUsername($rr['url'], $rr['name'], false);
$trimmed = Protocol::formatMention($rr['url'], $rr['name']);
} else {
$trimmed = mb_substr($rr['name'],0,20);
}

4
include/api.php

@ -2751,7 +2751,7 @@ function api_get_entitities(&$text, $bbcode)
return [];
}
$bbcode = bb_CleanPictureLinks($bbcode);
$bbcode = BBCode::cleanPictureLinks($bbcode);
// Change pure links in text to bbcode uris
$bbcode = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode);
@ -5171,7 +5171,7 @@ function api_clean_plain_items($Text)
{
$include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false");
$Text = bb_CleanPictureLinks($Text);
$Text = BBCode::cleanPictureLinks($Text);
$URLSearchString = "^\[\]";
$Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);

10
include/bb2diaspora.php

@ -76,10 +76,10 @@ function diaspora2bb($s) {
$s = preg_replace('/([^\]=]|^)(https?\:\/\/)([a-zA-Z0-9:\/\-?&;.=_~#%$!+,@]+(?<!,))/ism', '$1[url=$2$3]$2$3[/url]', $s);
//$s = preg_replace("/([^\]\=]|^)(https?\:\/\/)(vimeo|youtu|www\.youtube|soundcloud)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2$3$4]$2$3$4[/url]',$s);
$s = bb_tag_preg_replace('/\[url\=?(.*?)\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/url\]/ism', '[youtube]$2[/youtube]', 'url', $s);
$s = bb_tag_preg_replace('/\[url\=https?:\/\/www.youtube.com\/watch\?v\=(.*?)\].*?\[\/url\]/ism' , '[youtube]$1[/youtube]', 'url', $s);
$s = bb_tag_preg_replace('/\[url\=?(.*?)\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/url\]/ism' , '[vimeo]$2[/vimeo]' , 'url', $s);
$s = bb_tag_preg_replace('/\[url\=https?:\/\/vimeo.com\/([0-9]+)\](.*?)\[\/url\]/ism' , '[vimeo]$1[/vimeo]' , 'url', $s);
$s = BBCode::pregReplaceInTag('/\[url\=?(.*?)\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/url\]/ism', '[youtube]$2[/youtube]', 'url', $s);
$s = BBCode::pregReplaceInTag('/\[url\=https?:\/\/www.youtube.com\/watch\?v\=(.*?)\].*?\[\/url\]/ism' , '[youtube]$1[/youtube]', 'url', $s);
$s = BBCode::pregReplaceInTag('/\[url\=?(.*?)\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/url\]/ism' , '[vimeo]$2[/vimeo]' , 'url', $s);
$s = BBCode::pregReplaceInTag('/\[url\=https?:\/\/vimeo.com\/([0-9]+)\](.*?)\[\/url\]/ism' , '[vimeo]$1[/vimeo]' , 'url', $s);
// remove duplicate adjacent code tags
$s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s);
@ -130,7 +130,7 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) {
// Since Diaspora is creating a summary for links, this function removes them before posting
if ($fordiaspora) {
$Text = bb_remove_share_information($Text);
$Text = BBCode::removeShareInformation($Text);
}
/**

1439
include/bbcode.php
File diff suppressed because it is too large
View File

8
include/conversation.php

@ -6,6 +6,7 @@
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
@ -72,7 +73,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
$newbody = '';
$cnt = 1;
$pos = get_bb_tag_pos($origbody, 'url', 1);
$pos = BBCode::getTagPosition($origbody, 'url', 0);
while ($pos !== false && $cnt < 1000) {
$search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
@ -90,7 +91,8 @@ function item_redir_and_replace_images($body, $images, $cid) {
$newbody .= $subject;
$cnt++;
$pos = get_bb_tag_pos($origbody, 'url', 1);
// Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
$pos = BBCode::getTagPosition($origbody, 'url', 0);
}
$newbody .= $origbody;
@ -347,7 +349,7 @@ function localize_item(&$item) {
$photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
if (preg_match($photo_pattern, $item['body'])) {
$photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
$item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
$item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
}
// add sparkle links to appropriate permalinks

4
mod/display.php

@ -2,9 +2,11 @@
/**
* @file mod/display.php
*/
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
@ -171,7 +173,7 @@ function display_fetchauthor($a, $item) {
$profiledata["photo"] = $matches[1];
}
$profiledata["nickname"] = $profiledata["name"];
$profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
$profiledata["network"] = Protocol::matchByProfileUrl($profiledata["url"]);
$profiledata["address"] = "";
$profiledata["about"] = "";

1365
src/Content/Text/BBCode.php
File diff suppressed because it is too large
View File

37
src/Content/Text/Plaintext.php

@ -34,4 +34,41 @@ class Plaintext
return $msg;
}
/**
* Returns the character positions of the provided boundaries, optionally skipping a number of first occurrences
*
* @param string $text Text to search
* @param string $open Left boundary
* @param string $close Right boundary
* @param int $occurrences Number of first occurrences to skip
* @return boolean|array
*/
public static function getBoundariesPosition($text, $open, $close, $occurrences = 0)
{
if ($occurrences < 0) {
$occurrences = 0;
}
$start_pos = -1;
for ($i = 0; $i <= $occurrences; $i++) {
if ($start_pos !== false) {
$start_pos = strpos($text, $open, $start_pos + 1);
}
}
if ($start_pos === false) {
return false;
}
$end_pos = strpos($text, $close, $start_pos);
if ($end_pos === false) {
return false;
}
$res = ['start' => $start_pos, 'end' => $end_pos];
return $res;
}
}

124
src/Core/Protocol.php

@ -0,0 +1,124 @@
<?php
/*
* @file src/Core/Protocol.php
*/
namespace Friendica\Core;
use Friendica\Util\Network;
/**
* Manage compatibility with federated networks
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Protocol
{
const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
const DIASPORA = 'dspr'; // Diaspora
const DIASPORA2 = 'dspc'; // Diaspora connector
const STATUSNET = 'stac'; // Statusnet connector
const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations
const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
const MAIL = 'mail'; // IMAP/POP
const XMPP = 'xmpp'; // XMPP - Currently unsupported
const FACEBOOK = 'face'; // Facebook API
const LINKEDIN = 'lnkd'; // LinkedIn
const MYSPACE = 'mysp'; // MySpace - Currently unsupported
const GPLUS = 'goog'; // Google+
const PUMPIO = 'pump'; // pump.io
const TWITTER = 'twit'; // Twitter
const APPNET = 'apdn'; // app.net - Dead protocol
const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported
const ICALENDAR = 'ical'; // iCalendar - Currently unsupported
const PNUT = 'pnut'; // pnut.io - Currently unsupported
const ZOT = 'zot!'; // Zot! - Currently unsupported
const PHANTOM = 'unkn'; // Place holder
/**
* Returns the address string for the provided profile URL
*
* @param string $profile_url
* @return string
* @throws Exception
*/
public static function getAddrFromProfileUrl($profile_url)
{
$network = self::matchByProfileUrl($profile_url, $matches);
if ($network === self::PHANTOM) {
throw new Exception('Unknown network for profile URL: ' . $profile_url);
}
$addr = $matches[2] . '@' . $matches[1];
return $addr;
}
/**
* Guesses the network from a profile URL
*
* @param string $profile_url
* @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
* @return type
*/
public static function matchByProfileUrl($profile_url, &$matches = [])
{
if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
return self::TWITTER;
}
if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
return self::APPNET;
}
if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
return self::GPLUS;
}
if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
return self::DFRN;
}
if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
return self::DIASPORA;
}
if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
// RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
return self::DIASPORA;
}
if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
$statusnet_host = $matches[1];
$statusnet_user = $matches[2];
$UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
$user = json_decode($UserData);
if ($user) {
$matches[2] = $user->screen_name;
return self::STATUSNET;
}
}
// pumpio (http://host.name/user)
if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
return self::PUMPIO;
}
return self::PHANTOM;
}
/**
* Returns a formatted mention from a profile URL and a display name
*
* @param string $profile_url
* @param string $display_name
* @return string
*/
public static function formatMention($profile_url, $display_name)
{
return $display_name . '(' . self::getAddrFromProfileUrl($profile_url) . ')';
}
}

8
src/Model/Conversation.php

@ -11,6 +11,14 @@ require_once "include/dba.php";
class Conversation
{
const PROTOCOL_UNKNOWN = 0;
const PROTOCOL_DFRN = 1;
const PROTOCOL_DIASPORA = 2;
const PROTOCOL_OSTATUS_SALMON = 3;
const PROTOCOL_OSTATUS_FEED = 4; // Deprecated
const PROTOCOL_GS_CONVERSATION = 5; // Deprecated
const PROTOCOL_SPLITTED_CONV = 6;
/**
* @brief Store the conversation data
*

5
src/Protocol/DFRN.php

@ -10,6 +10,7 @@ namespace Friendica\Protocol;
use Friendica\App;
use Friendica\Content\OEmbed;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
@ -29,8 +30,6 @@ use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\XML;
use Friendica\Content\Text\BBCode;
use dba;
use DOMDocument;
use DOMXPath;
@ -929,7 +928,7 @@ class DFRN
}
// Remove the abstract element. It is only locally important.
$body = remove_abstract($body);
$body = BBCode::stripAbstract($body);
if ($type == 'html') {
$htmlbody = $body;

13
view/theme/frio/theme.php

@ -6,7 +6,9 @@
* Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus>
*
*/
use Friendica\App;
use Friendica\Content\Text\Plaintext;
use Friendica\Content\Widget;
use Friendica\Core\Addon;
use Friendica\Core\Config;
@ -15,7 +17,6 @@ use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Profile;
use Friendica\Object\Image;
$frio = "view/theme/frio";
@ -90,10 +91,8 @@ function frio_uninstall()
*/
function frio_item_photo_links(App $a, &$body_info)
{
$phototypes = Image::supportedTypes();
$occurence = 1;
$p = bb_find_open_close($body_info['html'], "<a", ">");
$occurence = 0;
$p = Plaintext::getBoundariesPosition($body_info['html'], "<a", ">");
while ($p !== false && ($occurence++ < 500)) {
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
$matches = [];
@ -112,7 +111,7 @@ function frio_item_photo_links(App $a, &$body_info)
$body_info['html'] = str_replace($link, $newlink, $body_info['html']);
}
$p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
$p = Plaintext::getBoundariesPosition($body_info['html'], "<a", ">", $occurence);
}
}
@ -302,7 +301,7 @@ function frio_acl_lookup(App $a, &$results)
$search_txt = dbesc(protect_sprintf(preg_quote($results["search"])));
$searching = true;
}
$sql_extra = '';
if ($searching) {
$sql_extra .= " AND (`attag` LIKE '%%" . dbesc($search_txt) . "%%' OR `name` LIKE '%%" . dbesc($search_txt) . "%%' OR `nick` LIKE '%%" . dbesc($search_txt) . "%%') ";

10
view/theme/frost/theme.php

@ -10,9 +10,9 @@
*/
use Friendica\App;
use Friendica\Content\Text\Plaintext;
use Friendica\Core\Addon;
use Friendica\Core\System;
use Friendica\Object\Image;
function frost_init(App $a) {
$a->videowidth = 400;
@ -49,10 +49,8 @@ function frost_uninstall() {
function frost_item_photo_links(App $a, &$body_info)
{
$phototypes = Image::supportedTypes();
$occurence = 1;
$p = bb_find_open_close($body_info['html'], "<a", ">");
$occurence = 0;
$p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>');
while($p !== false && ($occurence++ < 500)) {
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
@ -73,7 +71,7 @@ function frost_item_photo_links(App $a, &$body_info)
}
$p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
$p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>', $occurence);
}
}
Loading…
Cancel
Save