Commit add4ecfc authored by Hermann Mayer's avatar Hermann Mayer

Moved DashboardAction from BlogController to BlogController (Service). Added…

Moved DashboardAction from BlogController to BlogController (Service). Added support for rss rendering of DashboardAction.
parent cb1e559c
......@@ -46,36 +46,6 @@ class BlogController extends Controller
));
}
/**
* dashboardAction
*
* @access public
* @return void
*/
public function dashboardAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('JityHomepageBundle:Article')->findBy(array(), array('createdAt' => 'DESC'), 10);
foreach ($entities as $entity) {
// Get only the first paragraph (all until first blank line)
$matches = '';
preg_match("/((.*|\n)*)\n[\s]/", $entity->getContent(), $matches);
if (!empty($matches[0])) {
$entity->setContent(trim($matches[0]));
} else {
$entity->setContent(trim(substr($entity->getContent(), 0, 400)));
}
}
return $this->render('JityHomepageBundle:Blog:dashboard.html.twig', array(
'entities' => $entities,
));
}
/**
* sectionArchivAction
*
......
......@@ -4,9 +4,8 @@ namespace Jity\HomepageBundle\DependencyInjection\Service\Controller;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpFoundation\Response;
JMS\DiExtraBundle\Annotation as DI,
Symfony\Component\HttpFoundation\Response;
/**
* BlogController
......@@ -61,7 +60,40 @@ class BlogController extends AbstractService
*/
public function process()
{
return $this->container->get('templating')->render('JityHomepageBundle:Service:Blog/news.html.twig', array());
$em = $this->container->get('doctrine.orm.entity_manager');
$entities = $em->getRepository('JityHomepageBundle:Article')->findBy(array(), array('createdAt' => 'DESC'), 10);
foreach ($entities as $entity) {
// Get only the first paragraph (all until first blank line)
$matches = '';
preg_match("/((.*|\n)*)\n[\s]/", $entity->getContent(), $matches);
if (!empty($matches[0])) {
$entity->setContent(trim($matches[0]));
} else {
$entity->setContent(trim(substr($entity->getContent(), 0, 400)));
}
}
$format = $this->container->get('request')->getRequestFormat();
$content = $this->container->get('templating')->render('JityHomepageBundle:Service:Blog/dashboard.' . $format . '.twig', array(
'entities' => $entities
));
if ('rss' == $format) {
// We dont want to process further [default behavior: return rendered
// partial to the controller who requested this service ]
$response = new Response($content);
$response->send();
} else {
return $content;
}
}
}
......@@ -3,8 +3,10 @@ info:
defaults: { _controller: JityHomepageBundle:Default:showInfo }
page:
pattern: /{slug}
defaults: { _controller: JityHomepageBundle:Default:showPage, slug: ~, service: ~ }
pattern: /{slug}.{_format}
defaults: { _controller: JityHomepageBundle:Default:showPage, slug: ~, service: ~, _format: html }
requirements:
_format: html|rss
# page:
# pattern: /{slug}
......
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
version="2.0">
<channel>
{% set host = app.request.scheme ~ '://' ~ app.request.httpHost %}
{% set feedTitle = "Neuste Artikel von " ~ app.request.httpHost|capitalize %}
{% set feedDesc = "Die neusten Artikel von " ~ app.request.httpHost|capitalize ~ "."%}
{% set pageLink = url('page', {slug: 'blog'}) %}
{% set feedLink = pageLink ~ ".rss" %}
<title>{{ feedTitle }}</title>
<link>{{ pageLink }}</link>
<description>{{ feedDesc }}</description>
<language>de-de</language>
<pubDate>{{ "now"|date('r') }}</pubDate>
<image>
<url>{{ host ~ asset('apple-touch-icon.png') }}</url>
<title>{{ feedTitle }}</title>
<link>{{ pageLink }}</link>
</image>
{% if entities %}
<atom:link href="{{ feedLink }}" rel="self" type="application/rss+xml" />
{% for article in entities %}
{% set author = "Anonymous" %}
{% set authorEmail = "" %}
{% set authorAvatar = "" %}
{% if article.author %}
{% set author = article.author.firstName ~ " " ~ article.author.lastName %}
{% set authorEmail = article.author.email ~ " " %}
{% if article.author.picture is not empty %}
{% set authorAvatar = '<img src="' ~ article.author.picture ~ '" width="100" height="100" vspace="3" hspace="8" align="left"/>' %}
{% endif %}
{% endif %}
{% set articleUrl = url('article', {slug: article.slug}) %}
<item>
<title>{{ article.title }}</title>
<description>{{ article.content }}</description>
<content:encoded>
<![CDATA[
{{ authorAvatar }}{{ article.content }}
]]>
</content:encoded>
<link>{{ articleUrl }}</link>
<author>{{ authorEmail }}({{ author }})</author>
<guid>{{ articleUrl }}</guid>
<pubDate>{{ article.createdAt|date('r') }}</pubDate>
</item>
{% endfor %}
{% else %}
{% endif %}
</channel>
</rss>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment