Renamed Diagnostic to Debug and deleted ItemSource (already defined)

This commit is contained in:
Philipp Holzer 2019-05-19 03:02:58 +02:00
parent 48bba87abe
commit 492d7abe92
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
8 changed files with 21 additions and 77 deletions

175
src/Module/Debug/Babel.php Normal file
View file

@ -0,0 +1,175 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Content\Text;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Model\Item;
/**
* Translates input text into different formats (HTML, BBCode, Markdown)
*/
class Babel extends BaseModule
{
public static function content()
{
function visible_whitespace($s)
{
$s = str_replace(' ', '&nbsp;', $s);
return str_replace(["\r\n", "\n", "\r"], '<br />', $s);
}
$results = [];
if (!empty($_REQUEST['text'])) {
switch (defaults($_REQUEST, 'type', 'bbcode')) {
case 'bbcode':
$bbcode = trim($_REQUEST['text']);
$results[] = [
'title' => L10n::t('Source input'),
'content' => visible_whitespace($bbcode)
];
$plain = Text\BBCode::toPlaintext($bbcode, false);
$results[] = [
'title' => L10n::t('BBCode::toPlaintext'),
'content' => visible_whitespace($plain)
];
$html = Text\BBCode::convert($bbcode);
$results[] = [
'title' => L10n::t('BBCode::convert (raw HTML)'),
'content' => visible_whitespace(htmlspecialchars($html))
];
$results[] = [
'title' => L10n::t('BBCode::convert'),
'content' => $html
];
$bbcode2 = Text\HTML::toBBCode($html);
$results[] = [
'title' => L10n::t('BBCode::convert => HTML::toBBCode'),
'content' => visible_whitespace($bbcode2)
];
$markdown = Text\BBCode::toMarkdown($bbcode);
$results[] = [
'title' => L10n::t('BBCode::toMarkdown'),
'content' => visible_whitespace($markdown)
];
$html2 = Text\Markdown::convert($markdown);
$results[] = [
'title' => L10n::t('BBCode::toMarkdown => Markdown::convert'),
'content' => $html2
];
$bbcode3 = Text\Markdown::toBBCode($markdown);
$results[] = [
'title' => L10n::t('BBCode::toMarkdown => Markdown::toBBCode'),
'content' => visible_whitespace($bbcode3)
];
$bbcode4 = Text\HTML::toBBCode($html2);
$results[] = [
'title' => L10n::t('BBCode::toMarkdown => Markdown::convert => HTML::toBBCode'),
'content' => visible_whitespace($bbcode4)
];
$item = [
'body' => $bbcode,
'tag' => '',
];
Item::setHashtags($item);
$results[] = [
'title' => L10n::t('Item Body'),
'content' => visible_whitespace($item['body'])
];
$results[] = [
'title' => L10n::t('Item Tags'),
'content' => $item['tag']
];
break;
case 'markdown':
$markdown = trim($_REQUEST['text']);
$results[] = [
'title' => L10n::t('Source input (Diaspora format)'),
'content' => '<pre>' . $markdown . '</pre>'
];
$html = Text\Markdown::convert($markdown);
$results[] = [
'title' => L10n::t('Markdown::convert (raw HTML)'),
'content' => visible_whitespace(htmlspecialchars($html))
];
$results[] = [
'title' => L10n::t('Markdown::convert'),
'content' => $html
];
$bbcode = Text\Markdown::toBBCode($markdown);
$results[] = [
'title' => L10n::t('Markdown::toBBCode'),
'content' => '<pre>' . $bbcode . '</pre>'
];
break;
case 'html' :
$html = trim($_REQUEST['text']);
$results[] = [
'title' => L10n::t('Raw HTML input'),
'content' => htmlspecialchars($html)
];
$results[] = [
'title' => L10n::t('HTML Input'),
'content' => $html
];
$bbcode = Text\HTML::toBBCode($html);
$results[] = [
'title' => L10n::t('HTML::toBBCode'),
'content' => visible_whitespace($bbcode)
];
$html2 = Text\BBCode::convert($bbcode);
$results[] = [
'title' => L10n::t('HTML::toBBCode => BBCode::convert'),
'content' => $html2
];
$results[] = [
'title' => L10n::t('HTML::toBBCode => BBCode::convert (raw HTML)'),
'content' => htmlspecialchars($html2)
];
$markdown = Text\HTML::toMarkdown($html);
$results[] = [
'title' => L10n::t('HTML::toMarkdown'),
'content' => visible_whitespace($markdown)
];
$text = Text\HTML::toPlaintext($html);
$results[] = [
'title' => L10n::t('HTML::toPlaintext'),
'content' => '<pre>' . $text . '</pre>'
];
}
}
$tpl = Renderer::getMarkupTemplate('babel.tpl');
$o = Renderer::replaceMacros($tpl, [
'$text' => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''],
'$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
'$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
'$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
'$results' => $results
]);
return $o;
}
}

53
src/Module/Debug/Feed.php Normal file
View file

@ -0,0 +1,53 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Model;
use Friendica\Protocol;
use Friendica\Util\Network;
/**
* Tests a given feed of a contact
*/
class Feed extends BaseModule
{
public static function init()
{
if (!local_user()) {
info(L10n::t('You must be logged in to use this module'));
self::getApp()->internalRedirect();
}
}
public static function content()
{
$result = [];
if (!empty($_REQUEST['url'])) {
$url = $_REQUEST['url'];
$importer = Model\User::getById(local_user());
$contact_id = Model\Contact::getIdForURL($url, local_user(), true);
$contact = Model\Contact::getById($contact_id);
$xml = Network::fetchUrl($contact['poll']);
$dummy = null;
$import_result = Protocol\Feed::import($xml, $importer, $contact, $dummy, true);
$result = [
'input' => $xml,
'output' => var_export($import_result, true),
];
}
$tpl = Renderer::getMarkupTemplate('feedtest.tpl');
return Renderer::replaceMacros($tpl, [
'$url' => ['url', L10n::t('Source URL'), defaults($_REQUEST, 'url', ''), ''],
'$result' => $result
]);
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Model\Item;
use Friendica\Network\HTTPException;
/**
* Print the body of an Item
*/
class ItemBody extends BaseModule
{
public static function content()
{
if (!local_user()) {
throw new HTTPException\UnauthorizedException(L10n::t('Access denied.'));
}
$app = self::getApp();
// @TODO: Replace with parameter from router
$itemId = (($app->argc > 1) ? intval($app->argv[1]) : 0);
if (!$itemId) {
throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
}
$item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]);
if (!empty($item)) {
if ($app->isAjax()) {
echo str_replace("\n", '<br />', $item['body']);
exit();
} else {
return str_replace("\n", '<br />', $item['body']);
}
} else {
throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
}
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\Installer;
use Friendica\Core\L10n;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
class Localtime extends BaseModule
{
public static function post()
{
$time = defaults($_REQUEST, 'time', 'now');
$bd_format = L10n::t('l F d, Y \@ g:i A');
if (!empty($_POST['timezone'])) {
self::getApp()->data['mod-localtime'] = DateTimeFormat::convert($time, $_POST['timezone'], 'UTC', $bd_format);
}
}
public static function content()
{
$app = self::getApp();
$time = defaults($_REQUEST, 'time', 'now');
$output = '<h3>' . L10n::t('Time Conversion') . '</h3>';
$output .= '<p>' . L10n::t('Friendica provides this service for sharing events with other networks and friends in unknown timezones.') . '</p>';
$output .= '<p>' . L10n::t('UTC time: %s', $time) . '</p>';
if (!empty($_REQUEST['timezone'])) {
$output .= '<p>' . L10n::t('Current timezone: %s', $_REQUEST['timezone']) . '</p>';
}
if (!empty($app->data['mod-localtime'])) {
$output .= '<p>' . L10n::t('Converted localtime: %s', $app->data['mod-localtime']) . '</p>';
}
$output .= '<form action ="' . $app->getBaseURL() . '/localtime?f=&time=' . $time . '" method="post" >';
$output .= '<p>' . L10n::t('Please select your timezone:') . '</p>';
$output .= Temporal::getTimezoneSelect(defaults($_REQUEST, 'timezone', Installer::DEFAULT_TZ));
$output .= '<input type="submit" name="submit" value="' . L10n::t('Submit') . '" /></form>';
return $output;
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Network\HTTPException;
use Friendica\Network\Probe as NetworkProbe;
/**
* Fetch information (protocol endpoints and user information) about a given uri
*/
class Probe extends BaseModule
{
public static function content()
{
if (!local_user()) {
$e = new HTTPException\ForbiddenException(L10n::t('Only logged in users are permitted to perform a probing.'));
$e->httpdesc = L10n::t('Public access denied.');
throw $e;
}
$addr = defaults($_GET, 'addr', '');
$res = '';
if (!empty($addr)) {
$res = NetworkProbe::uri($addr, '', 0, false);
$res = print_r($res, true);
}
$tpl = Renderer::getMarkupTemplate('probe.tpl');
return Renderer::replaceMacros($tpl, [
'$addr' => ['addr',
L10n::t('Lookup address'),
$addr,
'',
'required'
],
'$res' => $res,
]);
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Network\Probe;
/**
* Web based module to perform webfinger probing
*/
class WebFinger extends BaseModule
{
public static function content()
{
if (!local_user()) {
$e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Only logged in users are permitted to perform a probing.'));
$e->httpdesc = L10n::t('Public access denied.');
throw $e;
}
$addr = defaults($_GET, 'addr', '');
$res = '';
if (!empty($addr)) {
$res = Probe::lrdd($addr);
$res = print_r($res, true);
}
$tpl = Renderer::getMarkupTemplate('webfinger.tpl');
return Renderer::replaceMacros($tpl, [
'$addr' => $addr,
'$res' => $res,
]);
}
}