Merge pull request #6 from flashwave/analysis-XZ7k6q

Applied fixes from StyleCI
This commit is contained in:
flash 2015-12-02 15:40:45 +01:00
commit bf44b6b807
6 changed files with 25 additions and 15 deletions

View file

@ -19,7 +19,8 @@ class BBcode
private $bbcode; private $bbcode;
// Constructor // Constructor
public function __construct($text = null) { public function __construct($text = null)
{
// Create new parser class // Create new parser class
$this->bbcode = new Parser(); $this->bbcode = new Parser();
@ -33,7 +34,8 @@ class BBcode
} }
// Add basic bbcodes // Add basic bbcodes
public function loadStandardCodes() { public function loadStandardCodes()
{
// Add the standard definitions // Add the standard definitions
$this->bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet()); $this->bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet());
@ -86,22 +88,26 @@ class BBcode
} }
// Set text // Set text
public function text($text) { public function text($text)
{
$this->bbcode->parse($text); $this->bbcode->parse($text);
} }
// Get as HTML // Get as HTML
public function toHTML() { public function toHTML()
{
return nl2br($this->bbcode->getAsHtml()); return nl2br($this->bbcode->getAsHtml());
} }
// Get as BBmarkup // Get as BBmarkup
public function toEditor() { public function toEditor()
{
return $this->bbcode->getAsBBCode(); return $this->bbcode->getAsBBCode();
} }
// Get as plaintext // Get as plaintext
public function toPlain() { public function toPlain()
{
return $this->bbcode->getAsText(); return $this->bbcode->getAsText();
} }
} }

View file

@ -9,7 +9,8 @@ use JBBCode\Parser;
use JBBCode\CodeDefinition; use JBBCode\CodeDefinition;
use JBBCode\ElementNode; use JBBCode\ElementNode;
class Align extends CodeDefinition { class Align extends CodeDefinition
{
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -27,7 +28,7 @@ class Align extends CodeDefinition {
$content = ""; $content = "";
foreach($el->getChildren() as $child) { foreach ($el->getChildren() as $child) {
$content .= $child->getAsHTML(); $content .= $child->getAsHTML();
} }

View file

@ -9,7 +9,8 @@ use JBBCode\Parser;
use JBBCode\CodeDefinition; use JBBCode\CodeDefinition;
use JBBCode\ElementNode; use JBBCode\ElementNode;
class Code extends CodeDefinition { class Code extends CodeDefinition
{
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();

View file

@ -39,7 +39,7 @@ class Lists extends CodeDefinition
$listPieces = explode('[*]', $bodyHtml); $listPieces = explode('[*]', $bodyHtml);
unset($listPieces[0]); unset($listPieces[0]);
$listPieces = array_map(function($li) { $listPieces = array_map(function ($li) {
return '<li>'.$li.'</li>'; return '<li>'.$li.'</li>';
}, $listPieces); }, $listPieces);
return '<ul>'.implode('', $listPieces).'</ul>'; return '<ul>'.implode('', $listPieces).'</ul>';

View file

@ -9,7 +9,8 @@ use JBBCode\Parser;
use JBBCode\CodeDefinition; use JBBCode\CodeDefinition;
use JBBCode\ElementNode; use JBBCode\ElementNode;
class Size extends CodeDefinition { class Size extends CodeDefinition
{
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -24,7 +25,7 @@ class Size extends CodeDefinition {
$content = ""; $content = "";
foreach($el->getChildren() as $child) { foreach ($el->getChildren() as $child) {
$content .= $child->getAsHTML(); $content .= $child->getAsHTML();
} }

View file

@ -10,7 +10,8 @@ use JBBCode\Parser;
use JBBCode\CodeDefinition; use JBBCode\CodeDefinition;
use JBBCode\ElementNode; use JBBCode\ElementNode;
class YouTube extends CodeDefinition { class YouTube extends CodeDefinition
{
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -21,13 +22,13 @@ class YouTube extends CodeDefinition {
{ {
$content = ""; $content = "";
foreach($el->getChildren() as $child) { foreach ($el->getChildren() as $child) {
$content .= $child->getAsBBCode(); $content .= $child->getAsBBCode();
} }
$foundMatch = preg_match('/^([A-z0-9=\-]+?)$/i', $content, $matches); $foundMatch = preg_match('/^([A-z0-9=\-]+?)$/i', $content, $matches);
if(!$foundMatch) { if (!$foundMatch) {
return $el->getAsBBCode(); return $el->getAsBBCode();
} else { } else {
return "<iframe width=\"640\" height=\"390\" src=\"https://www.youtube.com/embed/".$matches[1]."\" frameborder=\"0\" allowfullscreen></iframe>"; return "<iframe width=\"640\" height=\"390\" src=\"https://www.youtube.com/embed/".$matches[1]."\" frameborder=\"0\" allowfullscreen></iframe>";