Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added standard Scrutinizer config #7

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
69 changes: 69 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
inherit: true

checks:
php:
verify_property_names: true
verify_argument_usable_as_reference: true
verify_access_scope_valid: true
useless_calls: true
use_statement_alias_conflict: true
variable_existence: true
unused_variables: true
unused_properties: true
unused_parameters: true
unused_methods: true
unreachable_code: true
too_many_arguments: true
sql_injection_vulnerabilities: true
simplify_boolean_return: true
side_effects_or_types: true
security_vulnerabilities: true
return_doc_comments: true
return_doc_comment_if_not_inferrable: true
require_scope_for_properties: true
require_scope_for_methods: true
require_php_tag_first: true
psr2_switch_declaration: true
psr2_class_declaration: true
property_assignments: true
prefer_while_loop_over_for_loop: true
precedence_mistakes: true
precedence_in_conditions: true
phpunit_assertions: true
php5_style_constructor: true
parse_doc_comments: true
parameter_non_unique: true
parameter_doc_comments: true
param_doc_comment_if_not_inferrable: true
optional_parameters_at_the_end: true
one_class_per_file: true
no_unnecessary_if: true
no_trailing_whitespace: true
no_property_on_interface: true
no_non_implemented_abstract_methods: true
no_error_suppression: true
no_duplicate_arguments: true
no_commented_out_code: true
newline_at_end_of_file: true
missing_arguments: true
method_calls_on_non_object: true
instanceof_class_exists: true
foreach_traversable: true
fix_line_ending: true
fix_doc_comments: true
duplication: true
deprecated_code_usage: true
deadlock_detection_in_loops: true
code_rating: true
closure_use_not_conflicting: true
catch_class_exists: true
blank_line_after_namespace_declaration: false
avoid_multiple_statements_on_same_line: true
avoid_duplicate_types: true
avoid_conflicting_incrementers: true
avoid_closing_tag: true
assignment_of_null_return: true
argument_type_checks: true

filter:
paths: [code/*, tests/*]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Andrew Short (<[email protected]>)

## Requirements
* SilverStripe 2.4+
* SilverStripe 3.1+
* The External Content module.
* The SilverStripe Blog Module is required for running imports.

Expand All @@ -15,4 +15,4 @@

## Project Links
* [GitHub Project Page](https://github.com/ajshort/silverstripe-rssconnector)
* [Issue Tracker](https://github.com/ajshort/silverstripe-rssconnector/issues)
* [Issue Tracker](https://github.com/ajshort/silverstripe-rssconnector/issues)
9 changes: 6 additions & 3 deletions code/import/RssEntryTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @package silverstripe-rssconnector
*/

require_once Director::baseFolder() . '/rssconnector/thirdparty/htmlpurifier/HTMLPurifier.auto.php';

/**
* Transforms an RSS entry into a local blog entry.
*
Expand Down Expand Up @@ -44,8 +42,13 @@ public function transform($item, $parent, $strategy) {
$entry->Author = $item->AuthorName;
$entry->ProvideComments = isset($params['ProvideComments']);

$content = $item->Content;
$content = str_replace('></iframe>', '> </iframe>', $content);


$purifier = new HTMLPurifier();
$entry->Content = $purifier->purify($item->Content);
$entry->Content = $content;
//$entry->Content = $purifier->purify($content);

if (isset($params['ImportCategories'])) {
$labels = $item->getCategories()->map('Term', 'Label');
Expand Down
77 changes: 64 additions & 13 deletions code/model/RssContentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@ public function init() {
$this->Title = $this->item->get_title();
$this->Link = $this->item->get_link();
$this->Date = $this->item->get_date('Y-m-d H:i:s');
$this->Content = $this->item->get_content();

$content = $this->item->get_content();
$content = str_replace('></iframe>', '> </iframe>', $content);


$this->Content = $content;

if ($author = $this->item->get_author()) {
$this->AuthorName = $author->get_name();
$this->AuthorEmail = $author->get_email();
$this->AuthorLink = $author->get_link();
}

$this->categories = new DataObjectSet();
$this->categories = new ArrayList();

$categories = @$this->item->get_categories();
//$categories = self::simplepie_get_categories($this->item);

if ($categories) foreach ($categories as $category) {
$this->categories->push(new ArrayData(array(
Expand All @@ -53,8 +60,8 @@ public function numChildren() {
return 0;
}

public function stageChildren() {
return new DataObjectSet();
public function stageChildren($showAll = false) {
return new ArrayList();
}

public function getType() {
Expand All @@ -64,16 +71,17 @@ public function getType() {
public function getCMSFields() {
$fields = parent::getCMSFields();

$categories = new TableListField('Categories', false, array(
'Label' => 'Label',
'Term' => 'Term',
'Scheme' => 'Scheme'
));
$categories->setCustomSourceItems($this->categories);

$fields->addFieldsToTab('Root.Details', array(
$categoriesString = '';
foreach ($this->categories as $cat) {
//$categoriesString .= "<li>$cat->Label / $cat->Term / $cat->Scheme</li> \n";
$categoriesString .= "<li>$cat->Label</li> \n";
}
$categoriesString = "<ul>$categoriesString</ul>";


$fields->addFieldsToTab('Root.Main', array(
new HeaderField('CategoriesHeader', 'Categories', 4),
$categories->performReadonlyTransformation()
new LiteralField('Categories', $categoriesString)
));

$fields->addFieldsToTab('Root.Location', array(
Expand All @@ -100,4 +108,47 @@ public function canImport() {
return false;
}



//amended simple pie method for proper category import
//static function simplepie_get_categories($item) {
//
// $categories = array();

// foreach ((array) $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
// {
// $term = null;
// $scheme = null;
// $label = null;
// if (isset($category['attribs']['']['term']))
// {
// $term = $item->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
// }
// if (isset($category['attribs']['']['scheme']))
// {
// $scheme = $item->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
// }
// if (isset($category['attribs']['']['label']))
// {
// $label = $item->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
// }
// $categories[] =& new $item->feed->category_class($term, $scheme, $label);
// }
// foreach ((array) $item->get_item_tags('', 'category') as $category)
// {
// $categories[] =& new $item->feed->category_class($item->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
// }
// foreach ((array) $item->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
// {
// $categories[] =& new $item->feed->category_class($item->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
// }
// foreach ((array) $item->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
// {
// $categories[] =& new $item->feed->category_class($item->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
// }
//
// return $categories;
//}


}
31 changes: 22 additions & 9 deletions code/model/RssContentSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @package silverstripe-rsscontent
*/

require_once 'simplepie/simplepie.inc';

/**
* An external RSS feed that content can be imported from.
*
Expand All @@ -14,16 +12,16 @@ class RssContentSource extends ExternalContentSource {

const DEFAULT_CACHE_LIFETIME = 3600;

public static $db = array(
private static $db = array(
'Url' => 'Varchar(255)',
'CacheLifetime' => 'Int'
);

public static $defaults = array(
private static $defaults = array(
'CacheLifetime' => self::DEFAULT_CACHE_LIFETIME
);

public static $icon = 'rssconnector/images/rssconnector';
private static $icon = 'rssconnector/images/rssconnector';

protected $client;

Expand Down Expand Up @@ -109,9 +107,9 @@ public function getRoot() {
return $this;
}

public function stageChildren() {
public function stageChildren($showAll = false) {
$items = $this->getClient()->get_items();
$children = new DataObjectSet();
$children = new ArrayList();

foreach ($items as $item) {
$children->push(new RssContentItem($this, $item));
Expand All @@ -125,16 +123,31 @@ public function stageChildren() {
*/
public function getClient() {
if (!$this->client) {
$this->client = new SimplePie($this->Url);
$this->client = new SimplePie();

//enabling odd tags - for now only iframe
//TODO make this configurable
$strip_htmltags = $this->client->strip_htmltags;
//array_splice($strip_htmltags, array_search('object', $strip_htmltags), 1);
//array_splice($strip_htmltags, array_search('param', $strip_htmltags), 1);
//array_splice($strip_htmltags, array_search('embed', $strip_htmltags), 1);
array_splice($strip_htmltags, array_search('iframe', $strip_htmltags), 1);

$this->client->strip_htmltags($strip_htmltags);

$this->client->set_feed_url($this->Url);
$this->client->enable_cache(true);
$this->client->set_cache_duration($this->getCacheLifetime());
//$this->client->set_cache_duration(0);
$this->client->set_cache_location(TEMP_FOLDER);
}

$this->client->init();

return $this->client;
}

public function getContentImporter() {
public function getContentImporter($target = NULL) {
return new RssContentImporter();
}

Expand Down
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "anselmdk/silverstripe-rssconnector",
"description": "A fork of the SilverStripe RSS Connector Module",
"type": "silverstripe-module",
"homepage": "https://github.com/anselmdk/silverstripe-rssconnector",
"keywords": ["silverstripe", "rss"],
"authors": [
{"name": "Andrew Short","email": "[email protected]"},
{"name": "Anselm Christophersen","email": "[email protected]"}

],
"support": {
"issues": "https://github.com/anselmdk/silverstripe-rssconnector/issues"
},
"require": {
"silverstripe/cms": "~3.1",
"silverstripe/framework": "~3.1",
"silverstripe/external-content": "dev-master",
"simplepie/simplepie": "dev-master",
"ezyang/htmlpurifier": "dev-master"
},
"extra": {
"installer-name": "rssconnector"
}
}
Empty file removed thirdparty/_manifest_exclude
Empty file.
9 changes: 0 additions & 9 deletions thirdparty/htmlpurifier/CREDITS

This file was deleted.

11 changes: 0 additions & 11 deletions thirdparty/htmlpurifier/HTMLPurifier.auto.php

This file was deleted.

21 changes: 0 additions & 21 deletions thirdparty/htmlpurifier/HTMLPurifier.autoload.php

This file was deleted.

23 changes: 0 additions & 23 deletions thirdparty/htmlpurifier/HTMLPurifier.func.php

This file was deleted.

Loading