From 61e55f145ba5469b2a3cc8dd82f7a5638936d7bd Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Mon, 17 Sep 2012 15:12:40 +0200 Subject: [PATCH] Now removing code chunks from the RSS feed. --- .../Resources/views/Blog/feed.xml.twig | 2 +- .../FrontBundle/Twig/CodeChunk.php | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/feed.xml.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/feed.xml.twig index f407ec3..ae35fc1 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/feed.xml.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/feed.xml.twig @@ -19,7 +19,7 @@ {{ 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 }) }} {{ 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 {{ post.createdAt|date('r') }} - + {{ 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 }) }} {# diff --git a/src/GergelyPolonkai/FrontBundle/Twig/CodeChunk.php b/src/GergelyPolonkai/FrontBundle/Twig/CodeChunk.php index bf65df0..162c272 100644 --- a/src/GergelyPolonkai/FrontBundle/Twig/CodeChunk.php +++ b/src/GergelyPolonkai/FrontBundle/Twig/CodeChunk.php @@ -46,6 +46,7 @@ class CodeChunk extends \Twig_Extension { return array( '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; } + 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() { return "code_chunk";