mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-02 09:04:44 +02:00
Reformat codebase v4 (#2872)
Reformat code base to PSR12 Co-authored-by: rssbridge <noreply@github.com>
This commit is contained in:
parent
66568e3a39
commit
4f75591060
398 changed files with 58607 additions and 56442 deletions
|
@ -1,110 +1,106 @@
|
|||
<?php
|
||||
|
||||
class GitHubGistBridge extends BridgeAbstract {
|
||||
class GitHubGistBridge extends BridgeAbstract
|
||||
{
|
||||
const NAME = 'GitHubGist comment bridge';
|
||||
const URI = 'https://gist.github.com';
|
||||
const DESCRIPTION = 'Generates feeds for Gist comments';
|
||||
const MAINTAINER = 'logmanoriginal';
|
||||
const CACHE_TIMEOUT = 3600;
|
||||
|
||||
const NAME = 'GitHubGist comment bridge';
|
||||
const URI = 'https://gist.github.com';
|
||||
const DESCRIPTION = 'Generates feeds for Gist comments';
|
||||
const MAINTAINER = 'logmanoriginal';
|
||||
const CACHE_TIMEOUT = 3600;
|
||||
const PARAMETERS = [[
|
||||
'id' => [
|
||||
'name' => 'Gist',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'title' => 'Insert Gist ID or URI',
|
||||
'exampleValue' => '2646763'
|
||||
]
|
||||
]];
|
||||
|
||||
const PARAMETERS = array(array(
|
||||
'id' => array(
|
||||
'name' => 'Gist',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'title' => 'Insert Gist ID or URI',
|
||||
'exampleValue' => '2646763'
|
||||
)
|
||||
));
|
||||
private $filename;
|
||||
|
||||
private $filename;
|
||||
public function getURI()
|
||||
{
|
||||
$id = $this->getInput('id') ?: '';
|
||||
|
||||
public function getURI() {
|
||||
$urlpath = parse_url($id, PHP_URL_PATH);
|
||||
|
||||
$id = $this->getInput('id') ?: '';
|
||||
if ($urlpath) {
|
||||
$components = explode('/', $urlpath);
|
||||
$id = end($components);
|
||||
}
|
||||
|
||||
$urlpath = parse_url($id, PHP_URL_PATH);
|
||||
return static::URI . '/' . $id;
|
||||
}
|
||||
|
||||
if($urlpath) {
|
||||
public function getName()
|
||||
{
|
||||
return $this->filename ? $this->filename . ' - ' . static::NAME : static::NAME;
|
||||
}
|
||||
|
||||
$components = explode('/', $urlpath);
|
||||
$id = end($components);
|
||||
public function collectData()
|
||||
{
|
||||
$html = getSimpleHTMLDOM(
|
||||
$this->getURI(),
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
DEFAULT_TARGET_CHARSET,
|
||||
false, // Do NOT remove line breaks
|
||||
DEFAULT_BR_TEXT,
|
||||
DEFAULT_SPAN_TEXT
|
||||
);
|
||||
|
||||
}
|
||||
$html = defaultLinkTo($html, $this->getURI());
|
||||
|
||||
return static::URI . '/' . $id;
|
||||
$fileinfo = $html->find('[class~="file-info"]', 0)
|
||||
or returnServerError('Could not find file info!');
|
||||
|
||||
}
|
||||
$this->filename = $fileinfo->plaintext;
|
||||
|
||||
public function getName() {
|
||||
return $this->filename ? $this->filename . ' - ' . static::NAME : static::NAME;
|
||||
}
|
||||
$comments = $html->find('div[class~="TimelineItem"]');
|
||||
|
||||
public function collectData() {
|
||||
if (is_null($comments)) { // no comments yet
|
||||
return;
|
||||
}
|
||||
|
||||
$html = getSimpleHTMLDOM($this->getURI(),
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
DEFAULT_TARGET_CHARSET,
|
||||
false, // Do NOT remove line breaks
|
||||
DEFAULT_BR_TEXT,
|
||||
DEFAULT_SPAN_TEXT);
|
||||
foreach ($comments as $comment) {
|
||||
$uri = $comment->find('a[href*=#gistcomment]', 0)
|
||||
or returnServerError('Could not find comment anchor!');
|
||||
|
||||
$html = defaultLinkTo($html, $this->getURI());
|
||||
$title = $comment->find('h3', 0);
|
||||
|
||||
$fileinfo = $html->find('[class~="file-info"]', 0)
|
||||
or returnServerError('Could not find file info!');
|
||||
$datetime = $comment->find('[datetime]', 0)
|
||||
or returnServerError('Could not find comment datetime!');
|
||||
|
||||
$this->filename = $fileinfo->plaintext;
|
||||
$author = $comment->find('a.author', 0)
|
||||
or returnServerError('Could not find author name!');
|
||||
|
||||
$comments = $html->find('div[class~="TimelineItem"]');
|
||||
$message = $comment->find('[class~="comment-body"]', 0)
|
||||
or returnServerError('Could not find comment body!');
|
||||
|
||||
if(is_null($comments)) { // no comments yet
|
||||
return;
|
||||
}
|
||||
$item = [];
|
||||
|
||||
foreach($comments as $comment) {
|
||||
$item['uri'] = $uri->href;
|
||||
$item['title'] = str_replace('commented', 'commented on', $title->plaintext ?? '');
|
||||
$item['timestamp'] = strtotime($datetime->datetime);
|
||||
$item['author'] = '<a href="' . $author->href . '">' . $author->plaintext . '</a>';
|
||||
$item['content'] = $this->fixContent($message);
|
||||
// $item['enclosures'] = array();
|
||||
// $item['categories'] = array();
|
||||
|
||||
$uri = $comment->find('a[href*=#gistcomment]', 0)
|
||||
or returnServerError('Could not find comment anchor!');
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$title = $comment->find('h3', 0);
|
||||
|
||||
$datetime = $comment->find('[datetime]', 0)
|
||||
or returnServerError('Could not find comment datetime!');
|
||||
|
||||
$author = $comment->find('a.author', 0)
|
||||
or returnServerError('Could not find author name!');
|
||||
|
||||
$message = $comment->find('[class~="comment-body"]', 0)
|
||||
or returnServerError('Could not find comment body!');
|
||||
|
||||
$item = array();
|
||||
|
||||
$item['uri'] = $uri->href;
|
||||
$item['title'] = str_replace('commented', 'commented on', $title->plaintext ?? '');
|
||||
$item['timestamp'] = strtotime($datetime->datetime);
|
||||
$item['author'] = '<a href="' . $author->href . '">' . $author->plaintext . '</a>';
|
||||
$item['content'] = $this->fixContent($message);
|
||||
// $item['enclosures'] = array();
|
||||
// $item['categories'] = array();
|
||||
|
||||
$this->items[] = $item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Removes all unnecessary tags and adds formatting */
|
||||
private function fixContent($content){
|
||||
|
||||
// Restore code (inside <pre />) highlighting
|
||||
foreach($content->find('pre') as $pre) {
|
||||
|
||||
$pre->style = <<<EOD
|
||||
/** Removes all unnecessary tags and adds formatting */
|
||||
private function fixContent($content)
|
||||
{
|
||||
// Restore code (inside <pre />) highlighting
|
||||
foreach ($content->find('pre') as $pre) {
|
||||
$pre->style = <<<EOD
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
font-size: 85%;
|
||||
|
@ -116,46 +112,40 @@ box-sizing: border-box;
|
|||
margin-bottom: 16px;
|
||||
EOD;
|
||||
|
||||
$code = $pre->find('code', 0);
|
||||
$code = $pre->find('code', 0);
|
||||
|
||||
if($code) {
|
||||
|
||||
$code->style = <<<EOD
|
||||
if ($code) {
|
||||
$code->style = <<<EOD
|
||||
white-space: pre;
|
||||
word-break: normal;
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// find <code /> not inside <pre /> (`inline-code`)
|
||||
foreach ($content->find('code') as $code) {
|
||||
if ($code->parent()->tag === 'pre') {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// find <code /> not inside <pre /> (`inline-code`)
|
||||
foreach($content->find('code') as $code) {
|
||||
|
||||
if($code->parent()->tag === 'pre') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$code->style = <<<EOD
|
||||
$code->style = <<<EOD
|
||||
background-color: rgba(27,31,35,0.05);
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 3px;
|
||||
EOD;
|
||||
}
|
||||
|
||||
}
|
||||
// restore text spacing
|
||||
foreach ($content->find('p') as $p) {
|
||||
$p->style = 'margin-bottom: 16px;';
|
||||
}
|
||||
|
||||
// restore text spacing
|
||||
foreach($content->find('p') as $p) {
|
||||
$p->style = 'margin-bottom: 16px;';
|
||||
}
|
||||
// Remove unnecessary tags
|
||||
$content = strip_tags(
|
||||
$content->innertext,
|
||||
'<p><a><img><ol><ul><li><table><tr><th><td><string><pre><code><br><hr><h>'
|
||||
);
|
||||
|
||||
// Remove unnecessary tags
|
||||
$content = strip_tags(
|
||||
$content->innertext,
|
||||
'<p><a><img><ol><ul><li><table><tr><th><td><string><pre><code><br><hr><h>'
|
||||
);
|
||||
|
||||
return $content;
|
||||
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue