2013-08-11 13:30:41 +02:00
|
|
|
<?php
|
2018-11-16 21:48:59 +01:00
|
|
|
/**
|
|
|
|
* This file is part of RSS-Bridge, a PHP project capable of generating RSS and
|
|
|
|
* Atom feeds for websites that don't have one.
|
|
|
|
*
|
|
|
|
* For the full license information, please view the UNLICENSE file distributed
|
|
|
|
* with this source code.
|
|
|
|
*
|
|
|
|
* @package Core
|
|
|
|
* @license http://unlicense.org/ UNLICENSE
|
|
|
|
* @link https://github.com/rss-bridge/rss-bridge
|
|
|
|
*/
|
|
|
|
|
2019-06-08 17:01:38 +02:00
|
|
|
/**
|
|
|
|
* Builds a GitHub search query to find open bugs for the current bridge
|
|
|
|
*/
|
|
|
|
function buildGitHubSearchQuery($bridgeName){
|
|
|
|
return REPOSITORY
|
|
|
|
. 'issues?q='
|
|
|
|
. urlencode('is:issue is:open ' . $bridgeName);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:16:16 +02:00
|
|
|
/**
|
|
|
|
* Returns an URL that automatically populates a new issue on GitHub based
|
|
|
|
* on the information provided
|
|
|
|
*
|
2018-11-16 21:48:59 +01:00
|
|
|
* @param string $title string Sets the title of the issue
|
|
|
|
* @param string $body string Sets the body of the issue (GitHub markdown applies)
|
|
|
|
* @param string $labels mixed (optional) Specifies labels to add to the issue
|
|
|
|
* @param string $maintainer string (optional) Specifies the maintainer for the issue.
|
2017-07-29 19:16:16 +02:00
|
|
|
* The maintainer only applies if part of the development team!
|
2018-11-16 21:48:59 +01:00
|
|
|
* @return string|null A qualified URL to a new issue with populated conent or null.
|
|
|
|
*
|
|
|
|
* @todo This function belongs inside a class
|
2017-07-29 19:16:16 +02:00
|
|
|
*/
|
|
|
|
function buildGitHubIssueQuery($title, $body, $labels = null, $maintainer = null){
|
|
|
|
if(!isset($title) || !isset($body) || empty($title) || empty($body)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add title and body
|
2018-11-05 19:05:59 +01:00
|
|
|
$uri = REPOSITORY
|
|
|
|
. 'issues/new?title='
|
2017-07-29 19:16:16 +02:00
|
|
|
. urlencode($title)
|
|
|
|
. '&body='
|
|
|
|
. urlencode($body);
|
|
|
|
|
|
|
|
// Add labels
|
|
|
|
if(!is_null($labels) && is_array($labels) && count($labels) > 0) {
|
|
|
|
if(count($lables) === 1) {
|
|
|
|
$uri .= '&labels=' . urlencode($labels[0]);
|
|
|
|
} else {
|
|
|
|
foreach($labels as $label) {
|
|
|
|
$uri .= '&labels[]=' . urlencode($label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif(!is_null($labels) && is_string($labels)) {
|
|
|
|
$uri .= '&labels=' . urlencode($labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add maintainer
|
|
|
|
if(!empty($maintainer)) {
|
|
|
|
$uri .= '&assignee=' . urlencode($maintainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the exception message as HTML string
|
|
|
|
*
|
2018-11-16 21:48:59 +01:00
|
|
|
* @param object $e Exception The exception to show
|
|
|
|
* @param object $bridge object The bridge object
|
|
|
|
* @return string|null Returns the exception as HTML string or null.
|
|
|
|
*
|
|
|
|
* @todo This function belongs inside a class
|
2017-07-29 19:16:16 +02:00
|
|
|
*/
|
|
|
|
function buildBridgeException($e, $bridge){
|
2018-04-04 20:02:40 +02:00
|
|
|
if(( !($e instanceof \Exception) && !($e instanceof \Error)) || !($bridge instanceof \BridgeInterface)) {
|
2017-07-29 19:16:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $bridge->getName() . ' failed with error ' . $e->getCode();
|
|
|
|
|
|
|
|
// Build a GitHub compatible message
|
|
|
|
$body = 'Error message: `'
|
|
|
|
. $e->getMessage()
|
|
|
|
. "`\nQuery string: `"
|
2018-11-26 18:33:51 +01:00
|
|
|
. (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '')
|
2018-06-30 10:24:22 +02:00
|
|
|
. "`\nVersion: `"
|
|
|
|
. Configuration::getVersion()
|
|
|
|
. '`';
|
2017-07-29 19:16:16 +02:00
|
|
|
|
2018-10-15 17:21:43 +02:00
|
|
|
$body_html = nl2br($body);
|
2019-06-01 22:32:41 +02:00
|
|
|
$link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer());
|
2019-06-08 17:01:38 +02:00
|
|
|
$searchQuery = buildGitHubSearchQuery($bridge::NAME);
|
2017-07-29 19:16:16 +02:00
|
|
|
|
|
|
|
$header = buildHeader($e, $bridge);
|
2018-10-15 17:21:43 +02:00
|
|
|
$message = <<<EOD
|
|
|
|
<strong>{$bridge->getName()}</strong> was unable to receive or process the
|
|
|
|
remote website's content!<br>
|
|
|
|
{$body_html}
|
|
|
|
EOD;
|
2019-06-08 17:01:38 +02:00
|
|
|
$section = buildSection($e, $bridge, $message, $link, $searchQuery);
|
2017-07-29 19:16:16 +02:00
|
|
|
|
2018-10-15 17:21:43 +02:00
|
|
|
return $section;
|
2017-07-29 19:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the exception message as HTML string
|
|
|
|
*
|
2018-11-16 21:48:59 +01:00
|
|
|
* @param object $e Exception The exception to show
|
|
|
|
* @param object $bridge object The bridge object
|
|
|
|
* @return string|null Returns the exception as HTML string or null.
|
|
|
|
*
|
|
|
|
* @todo This function belongs inside a class
|
2017-07-29 19:16:16 +02:00
|
|
|
*/
|
|
|
|
function buildTransformException($e, $bridge){
|
2018-04-04 20:02:40 +02:00
|
|
|
if(( !($e instanceof \Exception) && !($e instanceof \Error)) || !($bridge instanceof \BridgeInterface)) {
|
2017-07-29 19:16:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $bridge->getName() . ' failed with error ' . $e->getCode();
|
|
|
|
|
|
|
|
// Build a GitHub compatible message
|
|
|
|
$body = 'Error message: `'
|
|
|
|
. $e->getMessage()
|
|
|
|
. "`\nQuery string: `"
|
2018-11-26 18:33:51 +01:00
|
|
|
. (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '')
|
|
|
|
. '`';
|
2017-07-29 19:16:16 +02:00
|
|
|
|
2019-06-01 22:32:41 +02:00
|
|
|
$link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer());
|
2019-06-08 17:01:38 +02:00
|
|
|
$searchQuery = buildGitHubSearchQuery($bridge::NAME);
|
2017-07-29 19:16:16 +02:00
|
|
|
$header = buildHeader($e, $bridge);
|
|
|
|
$message = "RSS-Bridge was unable to transform the contents returned by
|
|
|
|
<strong>{$bridge->getName()}</strong>!";
|
2019-06-08 17:01:38 +02:00
|
|
|
$section = buildSection($e, $bridge, $message, $link, $searchQuery);
|
2017-07-29 19:16:16 +02:00
|
|
|
|
|
|
|
return buildPage($title, $header, $section);
|
|
|
|
}
|
|
|
|
|
2018-11-16 21:48:59 +01:00
|
|
|
/**
|
|
|
|
* Builds a new HTML header with data from a exception an a bridge
|
|
|
|
*
|
|
|
|
* @param object $e The exception object
|
|
|
|
* @param object $bridge The bridge object
|
|
|
|
* @return string The HTML header
|
|
|
|
*
|
|
|
|
* @todo This function belongs inside a class
|
|
|
|
*/
|
2017-07-29 19:16:16 +02:00
|
|
|
function buildHeader($e, $bridge){
|
|
|
|
return <<<EOD
|
|
|
|
<header>
|
|
|
|
<h1>Error {$e->getCode()}</h1>
|
|
|
|
<h2>{$e->getMessage()}</h2>
|
|
|
|
<p class="status">{$bridge->getName()}</p>
|
|
|
|
</header>
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
|
2018-11-16 21:48:59 +01:00
|
|
|
/**
|
|
|
|
* Builds a new HTML section
|
|
|
|
*
|
|
|
|
* @param object $e The exception object
|
|
|
|
* @param object $bridge The bridge object
|
|
|
|
* @param string $message The message to display
|
|
|
|
* @param string $link The link to include in the anchor
|
2019-06-08 17:01:38 +02:00
|
|
|
* @param string $searchQuery A GitHub search query for the current bridge
|
2018-11-16 21:48:59 +01:00
|
|
|
* @return string The HTML section
|
|
|
|
*
|
|
|
|
* @todo This function belongs inside a class
|
|
|
|
*/
|
2019-06-08 17:01:38 +02:00
|
|
|
function buildSection($e, $bridge, $message, $link, $searchQuery){
|
2017-07-29 19:16:16 +02:00
|
|
|
return <<<EOD
|
|
|
|
<section>
|
|
|
|
<p class="exception-message">{$message}</p>
|
|
|
|
<div class="advice">
|
|
|
|
<ul class="advice">
|
|
|
|
<li>Press Return to check your input parameters</li>
|
|
|
|
<li>Press F5 to retry</li>
|
2019-06-08 17:01:38 +02:00
|
|
|
<li>Check if this issue was already reported on <a href="{$searchQuery}">GitHub</a> (give it a thumbs-up)</li>
|
2018-10-15 17:21:43 +02:00
|
|
|
<li>Open a <a href="{$link}">GitHub Issue</a> if this error persists</li>
|
2017-07-29 19:16:16 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
2019-06-08 17:01:38 +02:00
|
|
|
<a href="{$searchQuery}" title="Opens GitHub to search for similar issues">
|
|
|
|
<button>Search GitHub Issues</button>
|
|
|
|
</a>
|
2017-07-29 19:16:16 +02:00
|
|
|
<a href="{$link}" title="After clicking this button you can review
|
|
|
|
the issue before submitting it"><button>Open GitHub Issue</button></a>
|
|
|
|
<p class="maintainer">{$bridge->getMaintainer()}</p>
|
|
|
|
</section>
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
|
2018-11-16 21:48:59 +01:00
|
|
|
/**
|
|
|
|
* Builds a new HTML page
|
|
|
|
*
|
|
|
|
* @param string $title The HTML title
|
|
|
|
* @param string $header The HTML header
|
|
|
|
* @param string $section The HTML section
|
|
|
|
* @return string The HTML page
|
|
|
|
*
|
|
|
|
* @todo This function belongs inside a class
|
|
|
|
*/
|
2017-07-29 19:16:16 +02:00
|
|
|
function buildPage($title, $header, $section){
|
|
|
|
return <<<EOD
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title>{$title}</title>
|
|
|
|
<link href="static/style.css" rel="stylesheet">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
{$header}
|
|
|
|
{$section}
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOD;
|
|
|
|
}
|