forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Purifier and Markdown helpers, added composer.lock
- Loading branch information
Showing
6 changed files
with
375 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @link http://www.yiiframework.com/ | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yii\helpers; | ||
|
||
/** | ||
* Markdown provides an ability to transform markdown into HTML. | ||
* | ||
* Basic usage is the following: | ||
* | ||
* ```php | ||
* $my_html = Markdown::process($my_text); | ||
* ``` | ||
* | ||
* If you want to configure the parser: | ||
* | ||
* ```php | ||
* $my_html = Markdown::process($my_text, array( | ||
* 'fn_id_prefix' => 'footnote_', | ||
* )); | ||
* ``` | ||
* | ||
* For more details please refer to [PHP Markdown library documentation](http://michelf.ca/projects/php-markdown/). | ||
* @author Alexander Makarov <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class Markdown extends base\Markdown | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @link http://www.yiiframework.com/ | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yii\helpers; | ||
|
||
/** | ||
* Purifier provides an ability to clean up HTML from any harmful code. | ||
* | ||
* Basic usage is the following: | ||
* | ||
* ```php | ||
* $my_html = Purifier::process($my_text); | ||
* ``` | ||
* | ||
* If you want to configure it: | ||
* | ||
* ```php | ||
* $my_html = Purifier::process($my_text, array( | ||
* 'Attr.EnableID' => true, | ||
* )); | ||
* ``` | ||
* | ||
* For more details please refer to HTMLPurifier documentation](http://htmlpurifier.org/). | ||
* | ||
* @author Alexander Makarov <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class Purifier extends base\Purifier | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @link http://www.yiiframework.com/ | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yii\helpers\base; | ||
|
||
\Yii::setAlias('@Michelf', \Yii::getAlias('@yii').'/../vendor/michelf/php-markdown/Michelf'); | ||
use Michelf\MarkdownExtra; | ||
|
||
/** | ||
* Markdown provides an ability to transform markdown into HTML. | ||
* | ||
* Basic usage is the following: | ||
* | ||
* ```php | ||
* $my_html = Markdown::process($my_text); | ||
* ``` | ||
* | ||
* If you want to configure the parser: | ||
* | ||
* ```php | ||
* $my_html = Markdown::process($my_text, array( | ||
* 'fn_id_prefix' => 'footnote_', | ||
* )); | ||
* ``` | ||
* | ||
* For more details please refer to [PHP Markdown library documentation](http://michelf.ca/projects/php-markdown/). | ||
* @author Alexander Makarov <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class Markdown | ||
{ | ||
/** | ||
* @var MarkdownExtra | ||
*/ | ||
protected static $markdown; | ||
|
||
public static function process($content, $config = array()) | ||
{ | ||
if (static::$markdown===null) { | ||
static::$markdown = new MarkdownExtra(); | ||
} | ||
foreach ($config as $name => $value) { | ||
static::$markdown->{$name} = $value; | ||
} | ||
return static::$markdown->transform($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @link http://www.yiiframework.com/ | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
namespace yii\helpers\base; | ||
|
||
if (!class_exists('HTMLPurifier_Bootstrap', false)) { | ||
require_once(\Yii::getAlias('@yii').'/../vendor/ezyang/htmlpurifier/library'.DIRECTORY_SEPARATOR.'HTMLPurifier.auto.php'); | ||
} | ||
|
||
/** | ||
* Purifier provides an ability to clean up HTML from any harmful code. | ||
* | ||
* Basic usage is the following: | ||
* | ||
* ```php | ||
* $my_html = Purifier::process($my_text); | ||
* ``` | ||
* | ||
* If you want to configure it: | ||
* | ||
* ```php | ||
* $my_html = Purifier::process($my_text, array( | ||
* 'Attr.EnableID' => true, | ||
* )); | ||
* ``` | ||
* | ||
* For more details please refer to HTMLPurifier documentation](http://htmlpurifier.org/). | ||
* | ||
* @author Alexander Makarov <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class Purifier | ||
{ | ||
public static function process($content, $config = null) | ||
{ | ||
$purifier=\HTMLPurifier::instance($config); | ||
$purifier->config->set('Cache.SerializerPath', \Yii::$app->getRuntimePath()); | ||
return $purifier->purify($content); | ||
} | ||
} |