Merge remote-tracking branch 'upstream/2018.08-rc' into ap1

This commit is contained in:
Michael 2018-09-22 15:18:53 +00:00
commit c083ae047c
69 changed files with 16128 additions and 16187 deletions

View file

@ -9,7 +9,7 @@ namespace Friendica;
* The filename of the module in src/Module needs to match the class name
* exactly to make the module available.
*
* @author Hypolite Petovan mrpetovan@gmail.com
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
abstract class BaseModule extends BaseObject
{

View file

@ -31,7 +31,7 @@ require_once 'include/dba.php';
*
* @see https://oembed.com
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class OEmbed
{

View file

@ -25,7 +25,6 @@ use Friendica\Util\Map;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy as ProxyUtils;
use League\HTMLToMarkdown\HtmlConverter;
class BBCode extends BaseObject
{
@ -348,7 +347,7 @@ class BBCode extends BaseObject
*/
public static function toPlaintext($text, $keep_urls = true)
{
$naked_text = preg_replace('/\[(.+?)\]/','', $text);
$naked_text = preg_replace('/\[(.+?)\]\s*/','', $text);
if (!$keep_urls) {
$naked_text = preg_replace('#https?\://[^\s<]+[^\s\.\)]#i', '', $naked_text);
}
@ -1164,21 +1163,6 @@ class BBCode extends BaseObject
return $return;
}
private static function textHighlightCallback($match)
{
// Fallback in case the language doesn't exist
$return = '[code]' . $match[2] . '[/code]';
if (in_array(strtolower($match[1]),
['php', 'css', 'mysql', 'sql', 'abap', 'diff', 'html', 'perl', 'ruby',
'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh', 'bash'])
) {
$return = text_highlight($match[2], strtolower($match[1]));
}
return $return;
}
/**
* @brief Converts a BBCode message to HTML message
*
@ -1227,6 +1211,22 @@ class BBCode extends BaseObject
return $return;
};
// Extracting multi-line code blocks before the whitespace processing
$codeblocks = [];
$text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is",
function ($matches) use (&$codeblocks) {
$return = $matches[0];
if (strpos($matches[2], "\n") !== false) {
$return = '#codeblock-' . count($codeblocks) . '#';
$codeblocks[] = '<pre><code class="language-' . trim($matches[1]) . '">' . trim($matches[2], "\n\r") . '</code></pre>';
}
return $return;
},
$text
);
// Hide all [noparse] contained bbtags by spacefying them
// POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
@ -1273,11 +1273,6 @@ class BBCode extends BaseObject
$text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "\n[share$1$2]$3[/share]", $text);
}
// Check for [code] text here, before the linefeeds are messed with.
// The highlighter will unescape and re-escape the content.
if (strpos($text, '[code=') !== false) {
$text = preg_replace_callback("/\[code=(.*?)\](.*?)\[\/code\]/ism", 'self::textHighlightCallback', $text);
}
// Convert new line chars to html <br /> tags
// nlbr seems to be hopelessly messed up
@ -1771,6 +1766,18 @@ class BBCode extends BaseObject
$text = self::interpolateSavedImagesIntoItemBody($text, $saved_image);
}
// Restore code blocks
$text = preg_replace_callback('/#codeblock-([0-9]+)#/iU',
function ($matches) use ($codeblocks) {
$return = $matches[0];
if (isset($codeblocks[intval($matches[1])])) {
$return = $codeblocks[$matches[1]];
}
return $return;
},
$text
);
// Clean up the HTML by loading and saving the HTML with the DOM.
// Bad structured html can break a whole page.
// For performance reasons do it only with ativated item cache or at export.
@ -1905,23 +1912,6 @@ class BBCode extends BaseObject
// Converting images with size parameters to simple images. Markdown doesn't know it.
$text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $text);
// Extracting multi-line code blocks before the whitespace processing/code highlighter in self::convert()
$codeblocks = [];
$text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is",
function ($matches) use (&$codeblocks) {
$return = $matches[0];
if (strpos($matches[2], "\n") !== false) {
$return = '#codeblock-' . count($codeblocks) . '#';
$prefix = '````' . $matches[1] . PHP_EOL;
$codeblocks[] = $prefix . trim($matches[2]) . PHP_EOL . '````';
}
return $return;
},
$text
);
// Convert it to HTML - don't try oembed
if ($for_diaspora) {
$text = self::convert($text, false, 3);
@ -1951,8 +1941,7 @@ class BBCode extends BaseObject
$stamp1 = microtime(true);
// Now convert HTML to Markdown
$converter = new HtmlConverter();
$text = $converter->convert($text);
$text = HTML::toMarkdown($text);
// unmask the special chars back to HTML
$text = str_replace(['&\_lt\_;', '&\_gt\_;', '&\_amp\_;'], ['&lt;', '&gt;', '&amp;'], $text);
@ -1975,18 +1964,6 @@ class BBCode extends BaseObject
);
}
// Restore code blocks
$text = preg_replace_callback('/#codeblock-([0-9]+)#/iU',
function ($matches) use ($codeblocks) {
$return = '';
if (isset($codeblocks[intval($matches[1])])) {
$return = $codeblocks[$matches[1]];
}
return $return;
},
$text
);
Addon::callHooks('bb2diaspora', $text);
return $text;

View file

@ -11,6 +11,7 @@ use DOMXPath;
use Friendica\Core\Addon;
use Friendica\Util\Network;
use Friendica\Util\XML;
use League\HTMLToMarkdown\HtmlConverter;
class HTML
{
@ -122,7 +123,7 @@ class HTML
// Removing code blocks before the whitespace removal processing below
$codeblocks = [];
$message = preg_replace_callback(
'#<pre><code(?: class="([^"]*)")?>(.*)</code></pre>#iUs',
'#<pre><code(?: class="language-([^"]*)")?>(.*)</code></pre>#iUs',
function ($matches) use (&$codeblocks) {
$return = '[codeblock-' . count($codeblocks) . ']';
@ -131,7 +132,7 @@ class HTML
$prefix = '[code=' . $matches[1] . ']';
}
$codeblocks[] = $prefix . trim($matches[2]) . '[/code]';
$codeblocks[] = $prefix . PHP_EOL . trim($matches[2]) . PHP_EOL . '[/code]';
return $return;
},
$message
@ -672,4 +673,19 @@ class HTML
return trim($message);
}
/**
* Converts provided HTML code to Markdown. The hardwrap parameter maximizes
* compatibility with Diaspora in spite of the Markdown standards.
*
* @param string $html
* @return string
*/
public static function toMarkdown($html)
{
$converter = new HtmlConverter(['hard_break' => true]);
$markdown = $converter->convert($html);
return $markdown;
}
}

View file

@ -14,7 +14,7 @@ use Friendica\Content\Text\HTML;
/**
* Friendica-specific usage of Markdown
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Markdown extends BaseObject
{
@ -32,6 +32,7 @@ class Markdown extends BaseObject
$MarkdownParser = new MarkdownExtra();
$MarkdownParser->hard_wrap = $hardwrap;
$MarkdownParser->code_class_prefix = 'language-';
$html = $MarkdownParser->transform($text);
self::getApp()->save_timestamp($stamp1, "parser");

View file

@ -17,7 +17,7 @@ use Friendica\Util\Network;
/**
* Handle ACL management and display
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class ACL extends BaseObject
{

View file

@ -9,7 +9,7 @@ use Friendica\Util\DateTimeFormat;
/**
* Database Cache Driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
{

View file

@ -7,7 +7,7 @@ use Friendica\Core\Cache;
/**
* Cache Driver Interface
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
interface ICacheDriver
{

View file

@ -10,7 +10,7 @@ use Memcache;
/**
* Memcache Cache Driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class MemcacheCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
{

View file

@ -10,7 +10,7 @@ use Memcached;
/**
* Memcached Cache Driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
{

View file

@ -10,7 +10,7 @@ use Redis;
/**
* Redis Cache Driver. This driver is based on Memcache driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
* @author Roland Haeder <roland@mxchange.org>
*/
class RedisCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver

View file

@ -4,7 +4,7 @@ namespace Friendica\Core\Config;
/**
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
interface IConfigAdapter
{

View file

@ -11,7 +11,7 @@ require_once 'include/dba.php';
*
* Default Config Adapter. Provides the best performance for pages loading few configuration variables.
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class JITConfigAdapter extends BaseObject implements IConfigAdapter
{

View file

@ -11,7 +11,7 @@ require_once 'include/dba.php';
*
* Default PConfig Adapter. Provides the best performance for pages loading few configuration variables.
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
{

View file

@ -13,7 +13,7 @@ require_once 'include/dba.php';
*
* Minimizes the number of database queries to retrieve configuration values at the cost of memory.
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class PreloadConfigAdapter extends BaseObject implements IConfigAdapter
{

View file

@ -13,7 +13,7 @@ require_once 'include/dba.php';
*
* Minimizes the number of database queries to retrieve configuration values at the cost of memory.
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
{

View file

@ -5,7 +5,7 @@ namespace Friendica\Core;
/**
* Description of Console
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Console extends \Asika\SimpleConsole\Console
{

View file

@ -37,8 +37,8 @@ require_once 'include/text.php';
* set to the value of the last parameter. (e.g. "system loglevel 0" will
* disable logging)
*
* @author Tobias Diekershoff
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Config extends \Asika\SimpleConsole\Console
{

View file

@ -5,7 +5,7 @@ namespace Friendica\Core\Console;
/**
* Description of CreateDoxygen
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class CreateDoxygen extends \Asika\SimpleConsole\Console
{

View file

@ -13,7 +13,7 @@ require_once 'include/dba.php';
/**
* @brief Performs database updates from the command line
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class DatabaseStructure extends \Asika\SimpleConsole\Console
{

View file

@ -22,7 +22,7 @@ namespace Friendica\Core\Console;
* This is done for all files, so, in the end removing one file leads to a working doc build.
*
* @author Alexander Kampmann
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class DocBloxErrorChecker extends \Asika\SimpleConsole\Console
{

View file

@ -8,7 +8,7 @@ namespace Friendica\Core\Console;
*
* Outputs a PHP file with language strings used by Friendica
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Extract extends \Asika\SimpleConsole\Console
{

View file

@ -13,8 +13,8 @@ use Friendica\Model\Contact;
*
* License: AGPLv3 or later, same as Friendica
*
* @author Tobias Diekershoff <mrpetovan@gmail.com>
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
{

View file

@ -19,8 +19,8 @@ require_once 'include/text.php';
*
* License: AGPLv3 or later, same as Friendica
*
* @author Tobias Diekershoff
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
{

View file

@ -10,7 +10,7 @@ require_once 'include/dba.php';
/**
* @brief Sets maintenance mode for this node
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Maintenance extends \Asika\SimpleConsole\Console
{

View file

@ -5,7 +5,7 @@ namespace Friendica\Core\Console;
/**
* Read a strings.php file and create messages.po in the same directory
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class PhpToPo extends \Asika\SimpleConsole\Console
{

View file

@ -5,7 +5,7 @@ namespace Friendica\Core\Console;
/**
* Read a messages.po file and create strings.php in the same directory
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class PoToPhp extends \Asika\SimpleConsole\Console
{

View file

@ -6,15 +6,12 @@ use Friendica\Core\L10n;
use Friendica\Core\Config;
/**
* @brief tool to block an account from the node
*
* With this tool, you can block an account in such a way, that no postings
* or comments this account writes are accepted to the node.
* Performs database post updates
*
* License: AGPLv3 or later, same as Friendica
*
* @author Tobias Diekershoff <mrpetovan@gmail.com>
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class PostUpdate extends \Asika\SimpleConsole\Console
{

View file

@ -6,7 +6,7 @@ namespace Friendica\Core\Console;
* Tired of chasing typos and finding them after a commit.
* Run this and quickly see if we've got any parse errors in our application files.
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Typo extends \Asika\SimpleConsole\Console
{

View file

@ -183,6 +183,10 @@ class L10n extends BaseObject
{
$a = self::getApp();
if (!is_numeric($count)) {
logger('Non numeric count called by ' . System::callstack(20));
}
$lang = Config::get('system', 'language');
if (!empty($a->strings[$singular])) {

View file

@ -9,7 +9,7 @@ use Friendica\Util\Network;
/**
* Manage compatibility with federated networks
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Protocol
{

View file

@ -11,7 +11,7 @@ use Friendica\Core\Session\DatabaseSessionHandler;
/**
* High-level Session service class
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Session
{

View file

@ -13,7 +13,7 @@ require_once 'include/text.php';
/**
* SessionHandler using Friendica Cache
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
{

View file

@ -14,7 +14,7 @@ require_once 'include/text.php';
/**
* SessionHandler using database
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface
{

View file

@ -20,7 +20,7 @@ use Friendica\Protocol\OStatus;
*
* @brief Provides public Atom feeds
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Feed extends BaseModule
{

View file

@ -22,7 +22,7 @@ require_once 'include/text.php';
/**
* Login module
*
* @author Hypolite Petovan mrpetovan@gmail.com
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Login extends BaseModule
{

View file

@ -14,7 +14,7 @@ require_once 'include/security.php';
/**
* Logout module
*
* @author Hypolite Petovan mrpetovan@gmail.com
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Logout extends BaseModule
{

View file

@ -12,7 +12,7 @@ use Friendica\Content;
*
* Example: /oembed/aHR0cHM6Ly9...
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Oembed extends BaseModule
{

View file

@ -7,7 +7,7 @@ namespace Friendica\Object;
*
* @see https://oembed.com/#section2.3
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class OEmbed
{

View file

@ -1164,12 +1164,12 @@ class DFRN
* @return int Deliver status. Negative values mean an error.
* @todo Add array type-hint for $owner, $contact
*/
public static function deliver($owner, $contact, $atom, $dissolve = false)
public static function deliver($owner, $contact, $atom, $dissolve = false, $legacy_transport = false)
{
$a = get_app();
// At first try the Diaspora transport layer
if (!$dissolve) {
if (!$dissolve && !$legacy_transport) {
$ret = self::transmit($owner, $contact, $atom);
if ($ret >= 200) {
logger('Delivery via Diaspora transport layer was successful with status ' . $ret);

View file

@ -9,7 +9,7 @@ use Smarty;
/**
* Friendica extension of the Smarty3 template engine
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class FriendicaSmarty extends Smarty
{

View file

@ -9,7 +9,7 @@ use Friendica\Core\Addon;
/**
* Smarty implementation of the Friendica template engine interface
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class FriendicaSmartyEngine implements ITemplateEngine
{

View file

@ -161,7 +161,8 @@ class ParseUrl
$siteinfo['type'] = $oembed_data->type;
}
if (($oembed_data->type == 'link') && ($siteinfo['type'] != 'photo')) {
// See https://github.com/friendica/friendica/pull/5763#discussion_r217913178
if ($siteinfo['type'] != 'photo') {
if (isset($oembed_data->title)) {
$siteinfo['title'] = trim($oembed_data->title);
}
@ -337,7 +338,7 @@ class ParseUrl
$siteinfo['type'] = 'link';
}
if ((@$siteinfo['image'] == '') && !$no_guessing) {
if (empty($siteinfo['image']) && !$no_guessing) {
$list = $xpath->query('//img[@src]');
foreach ($list as $node) {
$img_tag = [];

View file

@ -292,8 +292,10 @@ class Delivery extends BaseObject
self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
return;
}
} else {
} elseif ($cmd != self::RELOCATION) {
$deliver_status = DFRN::deliver($owner, $contact, $atom);
} else {
$deliver_status = DFRN::deliver($owner, $contact, $atom, false, true);
}
logger('Delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status);