Skip to content

Commit

Permalink
Added Purifier and Markdown helpers, added composer.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed May 7, 2013
1 parent 1780787 commit f2258e7
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"php": ">=5.3.0",
"michelf/php-markdown": "1.3",
"twig/twig": "1.12.*",
"smarty/smarty": "3.1.*"
"smarty/smarty": "3.1.*",
"ezyang/htmlpurifier": "v4.5.0"
}
}
212 changes: 212 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions framework/helpers/Markdown.php
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
{
}
34 changes: 34 additions & 0 deletions framework/helpers/Purifier.php
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
{
}
51 changes: 51 additions & 0 deletions framework/helpers/base/Markdown.php
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);
}
}
43 changes: 43 additions & 0 deletions framework/helpers/base/Purifier.php
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);
}
}

0 comments on commit f2258e7

Please sign in to comment.