Skip to content

Commit

Permalink
Have been added:
Browse files Browse the repository at this point in the history
1) Code strip tags.
2) Settings for necessary tags which will be no cutting off.
  • Loading branch information
Ivanov Dmitry committed May 18, 2017
1 parent 941a720 commit dc8157b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/ContentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function __construct($url, Array $params = []) {
$this->url = $url;
$this->urlParams = parse_url($this->getURL());
$this->parsingResult = $this->parse();
if ($this->needsCodeStrip()) {
$this->parsingResult->stripContent();
}
if ($this->needsCodeClean()) {
$this->parsingResult->cleanContent();
}
Expand Down Expand Up @@ -96,6 +99,15 @@ final protected function needsCodeClean() {
return ((bool)config('deepslam.parser.clean_code'));
}

/**
* Checks whether have to strip tags or not.
*
* @return bool True - need to strip tags, false - needn't to strip tags
*/
final protected function needsCodeStrip() {
return ((bool)config('deepslam.parser.strip_tags'));
}

/*** STATIC LAYER ***/

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ContentParserMercury.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final protected function parse():ParsingResult
{
$result = new ParsingResult();
$response = Curl::to('https://mercury.postlight.com/parser?url='.urlencode($this->getURL()))
->withHeaders(array('x-api-key: '.config('deepslam.mercury.api-key')))
->withHeaders(array('x-api-key: '.config('deepslam.mercury.api_key')))
->asJson()
->get();
if (!is_null($response)) {
Expand Down
9 changes: 9 additions & 0 deletions src/ParsingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,14 @@ public function isEmpty() {
public function cleanContent() {
$this->params["content"] = preg_replace( '/\s?(style|class|id)=[\'"]{1}.*[\'"]{1}/sUi', '', $this->params["content"], -1 );
}

/**
* Let's strip tags from unwilling tags
*
*@return String Stripped content
*/
public function stripContent() {
$this->params["content"] = strip_tags($this->params["content"], implode('',config('deepslam.parser.allowed_tags')));
}
}
?>
2 changes: 1 addition & 1 deletion src/config/mercury.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
return [
'api-key' => 'YVMpLAlWqWk9DSJHcWMCdsFhqMSrIhoK0YaQwfX6',
'api_key' => 'YVMpLAlWqWk9DSJHcWMCdsFhqMSrIhoK0YaQwfX6',
];
?>
31 changes: 30 additions & 1 deletion src/config/parser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
<?php
return [
"clean_code" => true,
"clean_code" => true,//Clean code from different styles, classes etc.
"strip_tags" => true,//Strip tags?
"allowed_tags" => [//List of the allowed tags
'<br>',
'<p>',
'<a>',
'<ul>',
'<ol>',
'<li>',
'<i>',
'<b>',
'<strong>',
'<img>',
'<span>',
'<pre>',
'<code>',
'<table>',
'<tr>',
'<th>',
'<td>',
'<tbody>',
'<thead>',
'<tfoot>',
'<h1>',
'<h2>',
'<h3>',
'<h4>',
'<h5>',
'<h6>',
],
"parsers" => [
'mercury' => \Deepslam\ContentParser\ContentParserMercury::class,
'graby' => \Deepslam\ContentParser\ContentParserGraby::class,
Expand Down

0 comments on commit dc8157b

Please sign in to comment.