Skip to content

Commit

Permalink
refactor: drop usage of Debug::log
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan committed Aug 8, 2024
1 parent 6afd13e commit 20ebd34
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 103 deletions.
1 change: 0 additions & 1 deletion bridges/AsahiShimbunAJWBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function collectData()

foreach ($html->find('#MainInner li a') as $element) {
if ($element->parent()->class == 'HeadlineTopImage-S') {
Debug::log('Skip Headline, it is repeated below');
continue;
}
$item = [];
Expand Down
5 changes: 0 additions & 5 deletions bridges/DagensNyheterDirektBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public function collectData()
$url = self::BASEURL . $link;
$title = $element->find('h2', 0)->plaintext;
$author = $element->find('div.ds-byline__titles', 0)->plaintext;
// Debug::log($link);
// Debug::log($datetime);
// Debug::log($title);
// Debug::log($url);
// Debug::log($author);

$article_content = $element->find('div.direkt-post__content', 0);
$article_html = '';
Expand Down
1 change: 0 additions & 1 deletion bridges/FicbookBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ private function fixDate($date)
$fixed_date = str_replace(' г.', '', $fixed_date);

if ($fixed_date === $date) {
Debug::log('Unable to fix date: ' . $date);
return null;
}

Expand Down
4 changes: 0 additions & 4 deletions bridges/FolhaDeSaoPauloBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ protected function parseItem(array $item)
$item['content'] = $text;
$item['uri'] = explode('*', $item['uri'])[1];
}
} else {
Debug::log('???: ' . $item['uri']);
}
} else {
$item['uri'] = explode('*', $item['uri'])[1];
Expand All @@ -58,13 +56,11 @@ public function collectData()
{
$feed_input = $this->getInput('feed');
if (substr($feed_input, 0, strlen(self::URI)) === self::URI) {
Debug::log('Input:: ' . $feed_input);
$feed_url = $feed_input;
} else {
/* TODO: prepend `/` if missing */
$feed_url = self::URI . '/' . $this->getInput('feed');
}
Debug::log('URL: ' . $feed_url);
$limit = $this->getInput('amount');
$this->collectExpandableDatas($feed_url, $limit);
}
Expand Down
2 changes: 0 additions & 2 deletions bridges/HackerNewsUserThreadsBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public function collectData()
{
$url = 'https://news.ycombinator.com/threads?id=' . $this->getInput('user');
$html = getSimpleHTMLDOM($url);
Debug::log('queried ' . $url);
Debug::log('found ' . $html);

$item = [];
$articles = $html->find('tr[class*="comtr"]');
Expand Down
3 changes: 1 addition & 2 deletions bridges/ItakuBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private function getCommission($id, array $metadata = null)
{
$url = self::URI . '/api/commissions/' . $id . '/?format=json';
$uri = self::URI . '/commissions/' . $id;
// Debug::log(var_dump($metadata));

$data = $metadata ?? $this->getData($url, true, true)
or returnServerError("Could not load $url");

Expand Down Expand Up @@ -664,7 +664,6 @@ private function getImage($id /* array $metadata = null */) //$metadata disabled

private function getData(string $url, bool $cache = false, bool $getJSON = false, array $httpHeaders = [], array $curlOptions = [])
{
// Debug::log($url);
if ($getJSON) { //get JSON object
if ($cache) {
$data = $this->loadCacheValue($url);
Expand Down
8 changes: 0 additions & 8 deletions bridges/JustETFBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ private function fixDate($date)

date_time_set($df, 0, 0);

// Debug::log(date_format($df, 'U'));

return date_format($df, 'U');
}

Expand Down Expand Up @@ -216,8 +214,6 @@ private function extractNewsDate($article)
$element = $article->find('div.subheadline', 0)
or returnServerError('Date not found!');

// Debug::log($element->plaintext);

$date = trim(explode('|', $element->plaintext)[0]);

return $this->fixDate($date);
Expand All @@ -230,8 +226,6 @@ private function extractNewsDescription($article)

$element->find('a', 0)->onclick = '';

// Debug::log($element->innertext);

return $element->innertext;
}

Expand Down Expand Up @@ -300,8 +294,6 @@ private function extractProfileDate($html)
$element = $html->find('div.infobox div.vallabel', 0)
or returnServerError('Date not found!');

// Debug::log($element->plaintext);

$date = trim(explode("\r\n", $element->plaintext)[1]);

return $this->fixDate($date);
Expand Down
12 changes: 7 additions & 5 deletions bridges/MastodonBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ protected function fetchAP($url)
$toSign = '(request-target): get ' . $matches[2] . "\nhost: " . $matches[1] . "\ndate: " . $date;
$result = openssl_sign($toSign, $signature, $pkey, 'RSA-SHA256');
if ($result) {
Debug::log($toSign);
$sig = 'Signature: keyId="' . $keyId . '",headers="(request-target) host date",signature="' .
base64_encode($signature) . '"';
Debug::log($sig);
array_push($headers, $sig);
$sig = sprintf(
'Signature: keyId="%s",headers="(request-target) host date",signature="%s"',
$keyId,
base64_encode($signature)
);

$headers[] = $sig;
}
}
try {
Expand Down
2 changes: 1 addition & 1 deletion bridges/PanacheDigitalGamesBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function collectData()
$image_html = $element->find('.news-item-thumbnail-image', 0);
if ($image_html) {
$image_strings = explode('\'', $image_html);
/* Debug::log('S: ' . count($image_strings) . '||' . implode('_ _', $image_strings)); */

if (count($image_strings) == 4) {
$item['content'] = '<img src="' . $image_strings[1] . '" />';
}
Expand Down
1 change: 0 additions & 1 deletion bridges/PresidenciaPTBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function collectData()
$contexts = $this->getParameters();

foreach (array_keys($contexts['Section']) as $k) {
Debug::log('Key: ' . var_export($k, true));
if ($this->getInput($k)) {
$html = getSimpleHTMLDOMCached($this->getURI() . $k);

Expand Down
7 changes: 1 addition & 6 deletions bridges/SlusheBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,8 @@ public function collectData()

$html = getSimpleHTMLDOM($uri, $headers);

//Debug::log($html);
//Debug::log($html->find('div.blog-item')[0]);

//Loop on each entry
foreach ($html->find('div.blog-item') as $element) {
//Debug::log($element);

$title = $element->find('h3.title', 0)->first_child()->innertext;
$article_uri = $element->find('h3.title', 0)->first_child()->href;
Expand Down Expand Up @@ -153,7 +149,6 @@ public function collectData()
// Add image thumbnail(s)
foreach ($media_uris->find('img') as $media_uri) {
$media_html .= '<a href="' . $article_uri . '">' . $media_uri . '</a>';
//Debug::log('Adding to enclosures: ' . str_replace(' ', '%20', $media_uri->src));
$item['enclosures'][] = str_replace(' ', '%20', $media_uri->src);
}
}
Expand All @@ -165,7 +160,7 @@ public function collectData()
foreach ($media_uris->find('img') as $media_uri) {
$media_html .= '<p>Video:</p><a href="' .
$article_uri . '">' . $media_uri . '</a>';
//Debug::log('Adding to enclosures: ' . $media_uri->src);

$item['enclosures'][] = $media_uri->src;
}
}
Expand Down
5 changes: 2 additions & 3 deletions bridges/ThreadsBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ private function recursiveFind($haystack, $needle)
public function collectData()
{
$html = getSimpleHTMLDOMCached($this->getURI(), static::CACHE_TIMEOUT);
Debug::log(sprintf('Fetched: %s', $this->getURI()));

$jsonBlobs = $html->find('script[type="application/json"]');
Debug::log(sprintf('%d JSON blobs found.', count($jsonBlobs)));

$gatheredCodes = [];
$limit = $this->getInput('limit');
foreach ($jsonBlobs as $jsonBlob) {
Expand All @@ -87,7 +87,6 @@ public function collectData()
}
}
}
Debug::log(sprintf('Candidate codes found in JSON in script tags: %s', print_r($gatheredCodes, true)));

$this->feedName = html_entity_decode($html->find('meta[property=og:title]', 0)->content);
// todo: meta[property=og:description] could populate the feed description
Expand Down
2 changes: 1 addition & 1 deletion bridges/TwitterBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public function collectData()
}
break;
default:
Debug::log('Missing support for media type: ' . $media->type);
break;
}
}
}
Expand Down
29 changes: 3 additions & 26 deletions bridges/TwitterV2Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public function collectData()
. $this->getInput('u'), $authHeaders, $params);

if (isset($user->errors)) {
Debug::log('User JSON: ' . json_encode($user));
returnServerError('Requested username can\'t be found.');
}

Expand Down Expand Up @@ -266,7 +265,6 @@ public function collectData()
(isset($data->errors) && !isset($data->data)) ||
(isset($data->meta) && $data->meta->result_count === 0)
) {
Debug::log('Data JSON: ' . json_encode($data));
switch ($this->queriedContext) {
case 'By keyword or hashtag':
returnServerError('No results for this query.');
Expand Down Expand Up @@ -311,7 +309,6 @@ public function collectData()
foreach ($includesTweets as $includesTweet) {
$includesTweetsIds[] = $includesTweet->id;
}
Debug::log('includesTweetsIds: ' . join(',', $includesTweetsIds));

// Set default params for API query
$params = [
Expand All @@ -336,8 +333,6 @@ public function collectData()

// Create output array with all required elements for each tweet
foreach ($tweets as $tweet) {
//Debug::log('Tweet JSON: ' . json_encode($tweet));

// Skip pinned tweet (if selected)
if ($hidePinned && $tweet->id === $pinnedTweetId) {
continue;
Expand Down Expand Up @@ -376,20 +371,17 @@ public function collectData()
$cleanedQuotedTweet = null;
$quotedUser = null;
if ($isQuote) {
Debug::log('Tweet is quote');
foreach ($includesTweets as $includesTweet) {
if ($includesTweet->id === $tweet->referenced_tweets[0]->id) {
$quotedTweet = $includesTweet;
$cleanedQuotedTweet = nl2br($quotedTweet->text);
//Debug::log('Found quoted tweet');
break;
}
}

$quotedUser = $this->getTweetUser($quotedTweet, $retweetedUsers, $includesUsers);
}
if ($isRetweet || is_null($user)) {
Debug::log('Tweet is retweet, or $user is null');
// Replace tweet object with original retweeted object
if ($isRetweet) {
foreach ($includesTweets as $includesTweet) {
Expand Down Expand Up @@ -430,7 +422,6 @@ public function collectData()
. $this->item['username'] . ')';

$cleanedTweet = nl2br($tweet->text);
//Debug::log('cleanedTweet: ' . $cleanedTweet);

// Perform optional keyword filtering (only keep tweet if keyword is found)
if (! empty($tweetFilter)) {
Expand All @@ -452,7 +443,6 @@ public function collectData()
// Search for and replace URLs in Tweet text
$cleanedTweet = $this->replaceTweetURLs($tweet, $cleanedTweet);
if (isset($cleanedQuotedTweet)) {
Debug::log('Replacing URLs in Quoted Tweet text');
$cleanedQuotedTweet = $this->replaceTweetURLs($quotedTweet, $cleanedQuotedTweet);
}

Expand All @@ -478,9 +468,7 @@ public function collectData()
// Get external link info
$extURL = null;
if (isset($tweet->entities->urls) && strpos($tweet->entities->urls[0]->expanded_url, 'twitter.com') === false) {
Debug::log('Found an external link!');
$extURL = $tweet->entities->urls[0]->expanded_url;
Debug::log($extURL);
$extDisplayURL = $tweet->entities->urls[0]->display_url;
$extTitle = $tweet->entities->urls[0]->title;
$extDesc = $tweet->entities->urls[0]->description;
Expand Down Expand Up @@ -513,15 +501,12 @@ public function collectData()
$ext_media_html = '';
if (!$hideImages) {
if (isset($tweet->attachments->media_keys)) {
Debug::log('Generating HTML for tweet media');
$media_html = $this->createTweetMediaHTML($tweet, $includesMedia, $retweetedMedia);
}
if (isset($quotedTweet->attachments->media_keys)) {
Debug::log('Generating HTML for quoted tweet media');
$quoted_media_html = $this->createTweetMediaHTML($quotedTweet, $includesMedia, $retweetedMedia);
}
if (isset($extURL)) {
Debug::log('Generating HTML for external link media');
if ($this->getInput('noimgscaling')) {
$extMediaURL = $extMediaOrig;
} else {
Expand Down Expand Up @@ -562,7 +547,7 @@ public function collectData()

// Add External Link HTML, if relevant
if (isset($extURL) && !$this->getInput('noexternallink')) {
Debug::log('Adding HTML for external link');

$ext_html = <<<EXTERNAL
<div style="display: table; border-style: solid; border-width: 1px; border-radius: 5px; padding: 5px;">
$ext_media_html<br>
Expand Down Expand Up @@ -653,21 +638,18 @@ private function getTweetUser($tweetObject, $retweetedUsers, $includesUsers)
{
$originalUser = new stdClass(); // make the linters stop complaining
if (isset($retweetedUsers)) {
Debug::log('Searching for tweet author_id in $retweetedUsers');
foreach ($retweetedUsers as $retweetedUser) {
if ($retweetedUser->id === $tweetObject->author_id) {
$matchedUser = $retweetedUser;
Debug::log('Found author_id match in $retweetedUsers');
break;
}
}
}
if (!isset($matchedUser->username) && isset($includesUsers)) {
Debug::log('Searching for tweet author_id in $includesUsers');
foreach ($includesUsers as $includesUser) {
if ($includesUser->id === $tweetObject->author_id) {
$matchedUser = $includesUser;
Debug::log('Found author_id match in $includesUsers');

break;
}
}
Expand All @@ -689,30 +671,26 @@ private function createTweetMediaHTML($tweetObject, $includesMedia, $retweetedMe
$tweetMedia = [];
// Start by checking the original list of tweet Media includes
if (isset($includesMedia)) {
Debug::log('Searching for media_key in $includesMedia');
foreach ($includesMedia as $includesMedium) {
if (
in_array(
$includesMedium->media_key,
$tweetObject->attachments->media_keys
)
) {
Debug::log('Found media_key in $includesMedia');
$tweetMedia[] = $includesMedium;
}
}
}
// If no matches found, check the retweet Media includes
if (empty($tweetMedia) && isset($retweetedMedia)) {
Debug::log('Searching for media_key in $retweetedMedia');
foreach ($retweetedMedia as $retweetedMedium) {
if (
in_array(
$retweetedMedium->media_key,
$tweetObject->attachments->media_keys
)
) {
Debug::log('Found media_key in $retweetedMedia');
$tweetMedia[] = $retweetedMedium;
}
}
Expand Down Expand Up @@ -760,8 +738,7 @@ private function createTweetMediaHTML($tweetObject, $includesMedia, $retweetedMe
EOD;
break;
default:
Debug::log('Missing support for media type: '
. $media->type);
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions bridges/UnraidCommunityApplicationsBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class UnraidCommunityApplicationsBridge extends BridgeAbstract

private function fetchApps()
{
Debug::log('Fetching all applications/plugins');
$this->apps = getContents(self::APPSURI);
$this->apps = json_decode($this->apps, true)['applist'];
}

private function sortApps()
{
Debug::log('Sorting applications/plugins');
usort($this->apps, function ($app1, $app2) {
return $app1['FirstSeen'] < $app2['FirstSeen'] ? 1 : -1;
});
Expand Down
Loading

0 comments on commit 20ebd34

Please sign in to comment.