Now removing code chunks from the RSS feed.

This commit is contained in:
Polonkai Gergely 2012-09-17 15:12:40 +02:00
parent b4165a28ef
commit 61e55f145b
2 changed files with 36 additions and 1 deletions

View File

@ -19,7 +19,7 @@
<link>{{ app.request.scheme }}://{{app.request.host }}{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug }) }}</link> <link>{{ app.request.scheme }}://{{app.request.host }}{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug }) }}</link>
<comments>{{ app.request.scheme }}://{{app.request.host }}{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug }) }}#comments</comments> <comments>{{ app.request.scheme }}://{{app.request.host }}{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug }) }}#comments</comments>
<pubDate>{{ post.createdAt|date('r') }}</pubDate> <pubDate>{{ post.createdAt|date('r') }}</pubDate>
<description><![CDATA[{{post.content}}]]></description> <description><![CDATA[{{ post.content|remove_code_chunks }}]]></description>
<guid>{{ app.request.scheme }}://{{app.request.host }}{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug }) }}</guid> <guid>{{ app.request.scheme }}://{{app.request.host }}{{ path('GergelyPolonkaiFrontBundle_blogViewPost', {year: post.createdAt|date('Y'), month: post.createdAt|date('m'), day: post.createdAt|date('d'), slug: post.slug }) }}</guid>
{# {#
<category><![CDATA[Cat1]]></category> <category><![CDATA[Cat1]]></category>

View File

@ -46,6 +46,7 @@ class CodeChunk extends \Twig_Extension
{ {
return array( return array(
'insert_code_chunks' => new \Twig_Filter_Method($this, 'insertCodeChunks', array('is_safe' => array('html'))), 'insert_code_chunks' => new \Twig_Filter_Method($this, 'insertCodeChunks', array('is_safe' => array('html'))),
'remove_code_chunks' => new \Twig_Filter_Method($this, 'removeCodeChunks', array('is_safe' => array('html'))),
); );
} }
@ -106,6 +107,40 @@ class CodeChunk extends \Twig_Extension
return $string; return $string;
} }
public function removeCodeChunks($string)
{
$m = array();
$chunkRepo = $this->doctrine->getRepository('GergelyPolonkaiFrontBundle:CodeChunk');
while (
preg_match(
'/\\[\\$ code:([^:]+):([^ ]+) \\$\\]/i',
$string, $m, PREG_OFFSET_CAPTURE)
) {
$start = $m[0][1];
$fullTag = $m[0][0];
$len = strlen($fullTag);
$replacement = '';
$string = substr_replace($string, $replacement, $start, $len);
}
while (
preg_match(
'/\\[\\$ code:([^:]+):(.+?) \\$\\]/is',
$string, $m, PREG_OFFSET_CAPTURE)
) {
$start = $m[0][1];
$fullTag = $m[0][0];
$len = strlen($fullTag);
$replacement = '';
$string = substr_replace($string, $replacement, $start, $len);
}
return $string;
}
public function getName() public function getName()
{ {
return "code_chunk"; return "code_chunk";