Fix styling
This commit is contained in:
1 parent
db87a5d45f
commit
aee28b3450
4 files changed
+15
-14
No files matched your search
@@ -1,8 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Mattitja\Cision\Cision;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Str;
|
use Mattitja\Cision\Cision;
|
||||||
|
|
||||||
it('can fetch press releases from the RSS feed', function () {
|
it('can fetch press releases from the RSS feed', function () {
|
||||||
Http::fake([
|
Http::fake([
|
||||||
@@ -25,7 +24,7 @@ it('can fetch and parse full article content', function () {
|
|||||||
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
|
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$cision = new Cision();
|
$cision = new Cision;
|
||||||
$content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
|
$content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
|
||||||
|
|
||||||
expect($content)->toHaveKeys(['header', 'published_at', 'content']);
|
expect($content)->toHaveKeys(['header', 'published_at', 'content']);
|
||||||
|
|||||||
+6
-6
@@ -3,10 +3,10 @@
|
|||||||
namespace Mattitja\Cision;
|
namespace Mattitja\Cision;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Http\Client\Response;
|
use Illuminate\Http\Client\Response;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Mattitja\Cision\Support\HtmlCleaner;
|
use Mattitja\Cision\Support\HtmlCleaner;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
class Cision
|
class Cision
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,7 @@ class Cision
|
|||||||
/**
|
/**
|
||||||
* Constructor that accepts a slug identifier for the feed.
|
* Constructor that accepts a slug identifier for the feed.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $slug = null)
|
public function __construct(?string $slug = null)
|
||||||
{
|
{
|
||||||
$this->slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', '');
|
$this->slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', '');
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ class Cision
|
|||||||
$query['m'] = $type;
|
$query['m'] = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Http::get('https://news.cision.com/se/ListItems?' . http_build_query($query));
|
return Http::get('https://news.cision.com/se/ListItems?'.http_build_query($query));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseResponse(string $data, int $page): array|false
|
protected function parseResponse(string $data, int $page): array|false
|
||||||
@@ -116,7 +116,7 @@ class Cision
|
|||||||
|
|
||||||
// Suppress XML parsing warnings
|
// Suppress XML parsing warnings
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
|
$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
|
|
||||||
if ($xml === false) {
|
if ($xml === false) {
|
||||||
@@ -128,7 +128,7 @@ class Cision
|
|||||||
$rows = json_decode($json, true);
|
$rows = json_decode($json, true);
|
||||||
|
|
||||||
// Validate structure
|
// Validate structure
|
||||||
if (!isset($rows['channel']['item'])) {
|
if (! isset($rows['channel']['item'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace Mattitja\Cision;
|
|||||||
|
|
||||||
use Spatie\LaravelPackageTools\Package;
|
use Spatie\LaravelPackageTools\Package;
|
||||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||||
use Mattitja\Cision\Commands\CisionCommand;
|
|
||||||
|
|
||||||
class CisionServiceProvider extends PackageServiceProvider
|
class CisionServiceProvider extends PackageServiceProvider
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Mattitja\Cision\Support;
|
namespace Mattitja\Cision\Support;
|
||||||
|
|
||||||
|
use DOMElement;
|
||||||
use DOMNode;
|
use DOMNode;
|
||||||
use DOMText;
|
use DOMText;
|
||||||
use DOMElement;
|
|
||||||
|
|
||||||
class HtmlCleaner
|
class HtmlCleaner
|
||||||
{
|
{
|
||||||
@@ -17,7 +17,7 @@ class HtmlCleaner
|
|||||||
return $node->wholeText;
|
return $node->wholeText;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($node instanceof DOMElement)) {
|
if (! ($node instanceof DOMElement)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ class HtmlCleaner
|
|||||||
return '<br>';
|
return '<br>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,9 +53,11 @@ class HtmlCleaner
|
|||||||
$html = $node->C14N();
|
$html = $node->C14N();
|
||||||
$isItalic = str_starts_with(trim($html), '<em') || str_starts_with(trim($html), '<i');
|
$isItalic = str_starts_with(trim($html), '<em') || str_starts_with(trim($html), '<i');
|
||||||
$class = $isItalic ? ' class="italic"' : '';
|
$class = $isItalic ? ' class="italic"' : '';
|
||||||
return "<p{$class}>" . trim($inner) . "</p>";
|
|
||||||
|
return "<p{$class}>".trim($inner).'</p>';
|
||||||
}
|
}
|
||||||
return "<{$tag}>" . trim($inner) . "</{$tag}>";
|
|
||||||
|
return "<{$tag}>".trim($inner)."</{$tag}>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($tag, $allowedInline)) {
|
if (in_array($tag, $allowedInline)) {
|
||||||
|
|||||||
Reference in new issue
Block a user