Commit 7f9f1e41 authored by Hermann Mayer's avatar Hermann Mayer

Added Search Controller. Updated example Solr config. Polished Sidebar Sections.

parent 2cbb2365
......@@ -30,6 +30,7 @@ class AppKernel extends Kernel
new EWZ\Bundle\RecaptchaBundle\EWZRecaptchaBundle(),
new Presta\SitemapBundle\PrestaSitemapBundle(),
new Jity\TagGeneratorBundle\JityTagGeneratorBundle(),
new Nelmio\SolariumBundle\NelmioSolariumBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
......
......@@ -69,9 +69,12 @@
<div class="navbar-inner">
<div class="container">
<div class="nav-collapse collapse">
<p class="navbar-text pull-right">
<div class="nav-collapse collapse row">
<p class="navbar-text pull-left">
</p>
<div class="span8">
<ul class="nav">
{% if page is defined %}
......@@ -83,16 +86,19 @@
{% render 'JityHomepageBundle:Default:renderNavigation' with {'currentSlug': currentSlug, 'navigation': 'Default'} %}
</ul>
<form class="form-search navbar-search pull-right">
<div class="input-append">
<input type="text" class="span2 search-query" placeholder="Suchen..">
<button type="submit" class="btn btn-danger"><i class="icon-search icon-white"></i></button>
</div>
</form>
</div>
<div class="span4">
<ul class="nav pull-right">
<ul class="nav pull-left">
<li>
<a href="#" id="themeSwitchBtn" data-theme="{{ theme }}">
<a href="#" id="themeSwitchBtn" data-theme="{{ theme }}"
{% if theme == 'dark' %}
title="Seite hell einfärben"
{% elseif theme == 'bright' %}
title="Seite dunkel einfärben"
{% endif %}
>
<img src="
{% if theme == 'dark' %}
{{ asset('bundles/jityhomepage/img/glyphicons_231_sun.png') }}
......@@ -104,7 +110,7 @@
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" title="Benutzer Kontrollzentrum">
<img src="{{ asset('bundles/jityhomepage/img/glyphicons_003_user.png') }}" />
<b class="caret"></b>
</a>
......@@ -153,6 +159,19 @@
</li>
</ul>
{% if true == searchIsEnabled() %}
<form class="form-search navbar-search pull-left" action="{{ service('search') }}" method="get">
<div class="input-append">
<input name="q" type="text" class="span2 search-query" placeholder="Suchen..">
<button type="submit" class="btn btn-danger"><i class="icon-search icon-white"></i></button>
</div>
</form>
{% endif %}
</div>
</div>
</div>
</div>
......
......@@ -4,6 +4,7 @@ imports:
- { resource: jity.yml }
- { resource: oauth.yml }
- { resource: recaptcha.yml }
- { resource: solr.yml }
framework:
#esi: ~
......
jity_homepage:
search:
enable: true
admin:
email: admin@jity.de #jack@hermann-mayer.net
impress:
site_admin:
name: Herman Mayer
......@@ -17,6 +22,7 @@ jity_homepage:
email: root@hermann-mayer.net
services:
jity.twig.extension.debug:
class: Twig_Extension_Debug
tags:
......
......@@ -2,8 +2,8 @@ hwi_oauth:
resource_owners:
google:
type: google
client_id: "19729315507.apps.googleusercontent.com"
client_secret: "Z3DxaRjiIRw23Bnb54dAGLHw"
client_id: "XXX.apps.googleusercontent.com"
client_secret: "XXX"
scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
# name of the firewall the oauth bundle is active in
......
nelmio_solarium:
clients:
default:
host: localhost
port: 8983
path: /solr
core: jity
timeout: 5
No preview for this file type
......@@ -34,7 +34,7 @@
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"jms/serializer-bundle": "dev-master",
"jms/serializer-bundle": "1.0.x-dev",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"doctrine/data-fixtures": "dev-master",
"knplabs/knp-markdown-bundle": "dev-master",
......@@ -44,7 +44,8 @@
"suncat/mobile-detect-bundle": "dev-master",
"excelwebzone/recaptcha-bundle": "dev-master",
"presta/sitemap-bundle": "dev-sitemap-dumper",
"jity/tag-generator": "dev-master"
"jity/tag-generator": "dev-master",
"nelmio/solarium-bundle": "1.0.x-dev"
},
"scripts": {
"post-install-cmd": [
......
This diff is collapsed.
......@@ -2,13 +2,15 @@
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://server.lan/jity"
user="user"
user="solr"
password="password" />
<document>
<entity name="content"
query="
SELECT
`c`.`id` AS id
, `c`.`type` AS type
, `c`.`slug` AS slug
, `c`.`title` AS title
, `c`.`content` AS content
, CONCAT_WS(' ', `u`.`firstName`, `u`.`lastName`) AS author
......
#Mon Nov 19 21:03:21 CET 2012
content.last_index_time=2012-11-19 21\:03\:21
last_index_time=2012-11-19 21\:03\:21
#Wed Nov 21 20:54:27 CET 2012
content.last_index_time=2012-11-21 20\:54\:27
last_index_time=2012-11-21 20\:54\:27
......@@ -9,23 +9,30 @@
required="true"
type="int" />
<field name="type"
indexed="true"
stored="true"
type="string" />
<field name="slug"
indexed="false"
stored="true"
type="string" />
<field name="title"
indexed="true"
stored="true"
multiValued="true"
type="string" />
<field name="content"
indexed="true"
stored="true"
multiValued="true"
omitNorms="true"
type="text_de" />
<field name="author"
indexed="true"
stored="true"
multiValued="true"
type="string" />
<field name="authorEmail"
......@@ -36,13 +43,11 @@
<field name="tags"
indexed="true"
stored="true"
multiValued="true"
type="string" />
<field name="comments"
indexed="true"
stored="true"
multiValued="true"
type="text_de" />
<!-- catchall field, containing all other searchable text fields (implemented
......
......@@ -55,8 +55,29 @@ Mittel um die aktuelle Seite zu verändern.
<a href="{{ path(\'author_page_new\') }}" class="btn btn-danger" title="Neue Seite anlegen">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_036_file.png") }}" />
</a>
</p>')
->addSidebar($this->getReference('default-sidebar'));
</p>');
/*
* --------------------------------------------------------------------
*/
// Build Quick Operations Section
$quickOperationsArticle = new Section();
$quickOperationsArticle
->setGroup($this->getReference('author-group'))
->setTitle('Quick Operations')
->setContent('<p>
Als Administrator oder Autor bietet Ihnen diese Sektion
Mittel um den aktuellen Artikel zu verändern.
</p>
<p>
<a href="{{ path(\'author_article_edit\', { \'id\': page.id }) }}" class="btn btn-danger" title="Artikel bearbeiten">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_030_pencil.png") }}" />
</a>
<a href="{{ path(\'author_article_new\') }}" class="btn btn-danger" title="Neuen Artikel anlegen">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_036_file.png") }}" />
</a>
</p>');
/*
* --------------------------------------------------------------------
......@@ -80,9 +101,11 @@ Freunden und Bekannten über Googles Soziales Netzwerk oder über Facebook.
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_390_facebook.png") }}" />
Facebook
</a>
</p>')
->addSidebar($this->getReference('default-sidebar'))
->addSidebar($this->getReference('blog-sidebar'));
<a href="https://twitter.com/intent/tweet?original_referer={{ app.request.uri|url_encode }}&source={{ app.request.uri|url_encode }}tweetbutton&text={{ page.title|url_encode }}&url={{ app.request.uri|url_encode }}&via=Jack12816" class="btn btn-info">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_392_twitter_orig.png") }}" />
Twitter
</a>
</p>');
/*
* --------------------------------------------------------------------
......@@ -94,14 +117,38 @@ Freunden und Bekannten über Googles Soziales Netzwerk oder über Facebook.
->setGroup($this->getReference('anonymous-group'))
->setTitle('Folgen')
->setContent('<p>
Sie können den Aktivitäten dieses Artikels, mittels RSS Feed, folgen.
{% if "Article" == page.getType %}
Sie können den Aktivitäten dieses Artikels, mittels RSS Feed, folgen.
Oder folgen Sie meinen Aktivitäten auf Google+ oder über Twitter.
{% elseif "Page" == page.getType %}
Habe ich Ihr Interesse mit meinen Themen geweckt? Dann
folgen Sie meinen Aktivitäten auf Google+ oder über Twitter,
um immer auf dem Laufenden zu sein.
{% endif %}
</p>
<p>
{% if "Article" == page.getType %}
<a href="{{ app.request.uri }}.rss" class="btn btn-danger" title="RSS Feed abonnieren">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_397_rss.png") }}" />
</a>
</p>')
->addSidebar($this->getReference('blog-sidebar'));
{% endif %}
<a href="https://plus.google.com/112941896889448566210/about/p/pub" class="btn btn-danger" title="Google+ Aktivitäten folgen">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_362_google+_alt.png") }}" />
</a>
<a href="https://twitter.com/Jack12816" class="btn btn-danger" title="Twitter Aktivitäten folgen">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_392_twitter.png") }}" />
</a>
</p>');
/*
* --------------------------------------------------------------------
......@@ -121,43 +168,42 @@ werden Favoriten für Sie in der Applikation gespeichert.
<a href="{{ path(\'page\') }}" class="btn btn-danger" title="Zu den Favoriten hinzufügen">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_012_heart_plus.png") }}" />
</a>
</p>')
->addSidebar($this->getReference('default-sidebar'))
->addSidebar($this->getReference('blog-sidebar'));
</p>');
/*
* --------------------------------------------------------------------
*/
// Build Quick Operations Section
$quickOperationsArticle = new Section();
$quickOperationsArticle
->setGroup($this->getReference('author-group'))
->setTitle('Quick Operations')
->setContent('<p>
Als Administrator oder Autor bietet Ihnen diese Sektion
Mittel um den aktuellen Artikel zu verändern.
</p>
<p>
<a href="{{ path(\'author_article_edit\', { \'id\': page.id }) }}" class="btn btn-danger" title="Artikel bearbeiten">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_030_pencil.png") }}" />
</a>
<a href="{{ path(\'author_article_new\') }}" class="btn btn-danger" title="Neuen Artikel anlegen">
<img src="{{ asset("bundles/jityhomepage/img/glyphicons_036_file.png") }}" />
</a>
</p>')
->addSidebar($this->getReference('blog-sidebar'));
$archiv = new Section();
$archiv
->setGroup($this->getReference('anonymous-group'))
->setTitle('Archiv')
->setContent('{% render "JityHomepageBundle:Blog:sectionArchiv" %}');
/*
* --------------------------------------------------------------------
*/
// Build Quick Operations Section
$archiv = new Section();
$quickOperationsPage
->addSidebar($this->getReference('default-sidebar'));
$quickOperationsArticle
->addSidebar($this->getReference('blog-sidebar'));
$share
->addSidebar($this->getReference('default-sidebar'))
->addSidebar($this->getReference('blog-sidebar'));
$follow
->addSidebar($this->getReference('default-sidebar'))
->addSidebar($this->getReference('blog-sidebar'));
$favorites
->addSidebar($this->getReference('default-sidebar'))
->addSidebar($this->getReference('blog-sidebar'));
$archiv
->setGroup($this->getReference('anonymous-group'))
->setTitle('Archiv')
->setContent('{% render "JityHomepageBundle:Blog:sectionArchiv" %}')
->addSidebar($this->getReference('blog-sidebar'));
/*
......
......@@ -89,6 +89,20 @@ class Load30PageData extends AbstractFixture implements OrderedFixtureInterface
* --------------------------------------------------------------------
*/
// Build Search Page
$search = new Page();
$search
->setTitle('Suche')
->setContent('')
->setSidebar($this->getReference('default-sidebar'))
->setAuthor($this->getReference('admin-user'))
->setService($this->getReference('search-service'))
->setIcon('icon-comment');
/*
* --------------------------------------------------------------------
*/
// Build Contact Page
$demo = new Page();
$demo
......@@ -131,6 +145,7 @@ Administrator einzuloggen.
$manager->persist($demo);
$manager->persist($impress);
$manager->persist($contact);
$manager->persist($search);
// Flush to Database
$manager->flush();
......@@ -139,6 +154,7 @@ Administrator einzuloggen.
$this->addReference('demo-page', $demo);
$this->addReference('impress-page', $impress);
$this->addReference('contact-page', $contact);
$this->addReference('search-page', $search);
}
/**
......
......@@ -39,6 +39,11 @@ class Configuration implements ConfigurationInterface
$rootNode
->children()
->arrayNode('search')
->children()
->booleanNode('enable')->defaultValue(false)->end()
->end()
->end()
->arrayNode('admin')
->children()
->scalarNode('email')->isRequired()->end()
......
......@@ -19,7 +19,7 @@ use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
/**
* ImpressController
*
* The Impress Controller deliver a configureable impress functionality.
* The Impress Controller delivers a configureable impress functionality.
*
* @DI\Service("jity_service.controller.impress")
* @DI\Tag("jity_service.controller")
......
<?php
/*
* This file is part of the Jity package.
*
* (c) Hermann Mayer <hermann.mayer92@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jity\HomepageBundle\DependencyInjection\Service\Controller;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI,
Symfony\Component\HttpFoundation\Response;
/**
* SearchController
*
* The Search Controller allows you to fulltext search with Apache Solr.
*
* @DI\Service("jity_service.controller.search")
* @DI\Tag("jity_service.controller")
*
* @uses AbstractService
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class SearchController extends AbstractService
{
/**
* getName
*
* Get the name of the service.
*
* @access public
* @return string
*/
public function getName()
{
return 'search';
}
/**
* getTitle
*
* Get the title of the service.
*
* @access public
* @return string
*/
public function getTitle()
{
return 'Suche';
}
/**
* getDescription
*
* Get the description of the service.
*
* @access public
* @return string
*/
public function getDescription()
{
return 'Fügt die Suchfunktionalität hinzu.';
}
/**
* process
*
* Search for a given query.
*
* @param Request $request Request Object
* @param mixed $query Query from route GET parameter
*
* @access public
* @return void
*/
public function process()
{
$request = $this->container->get('request');
// Prepare the query string
$query = $request->query->get('q');
$fallback = false;
$results = array();
$query = urldecode($query);
// Never query for a null-query
if (false === empty($query)) {
$results = $this->searchAndPrepare($query);
// We did not find anything, thats needs to be impossible
if (0 == count($results)) {
// We should notify the user
$this->container->get('session')->getFlashBag()->add('error',
'Es wurden leider keine direkten Treffer zu Ihrer Suchanfrage gefunden.'
);
// Set fallback switch for the template
$fallback = true;
// Search for all articles as fallback
$results = $this->searchAndPrepare(
'article',
function($client, $select) {
$select->setQueryDefaultField('type');
}
);
}
}
// Debugging Switch
// die('<pre>' . print_r($results, true));
return $this
->container->get('templating')
->render('JityHomepageBundle:Service:Search/index.html.twig', array(
'query' => $query,
'results' => $results,
'fallback' => $fallback
)
);
}
/**
* searchAndPrepare
*
* Fire the query and prepare the results.
*
* @param string $query Query to fire to Apache Solr
* @param \Closure $configure Optional Closure to configure the query
*
* @access private
* @return void
*/
private function searchAndPrepare($query, $configure = null)
{
// Get the solarium client
$client = $this->container->get('solarium.client');
// Assemble a solr query
$select = $client->createSelect();
$select->setQuery($query);
// Run a given closure
if (is_callable($configure)) {
$configure($client, $select);
}
// Fire the solr query
$rawResults = $client->select($select);
$results = array();
// Short cut the content to fit our preview needs
foreach ($rawResults as $result) {
$result = (object) $result->getFields();
// Strip off markdown headlines
$result->content = preg_replace(array('/(\n\r)+/'), "\n", trim(
preg_replace("/.*\n[-]{3,}/", '', $result->content)
));
// Remove all HTML tags (images, etc) - just for sure
$result->content = trim(
preg_replace("/<.*>/", '', $result->content)
);
// Get only the first paragraph (all until first blank line)
$matches = '';
preg_match("/((.*|\n)*)\n[\s]/", $result->content, $matches);
// Split up any tags
if (isset($result->tags)) {
$result->tags = explode(' ', $result->tags);
} else {
$result->tags = array();
}
if (!empty($matches[0])) {
$result->content = trim($matches[0]);
} else {
$result->content = trim(substr($result->content, 0, 400)) . '[..]';
}
// No content is dangerous, so add a notification
if ('[..]' == $result->content) {
$result->content = 'Bei dieser Seite handelt es sich um eine
Service Seite. Aus diesem Grund stehen keine Informationen
zum Inhalt zur Verfügung.';
}
$results[] = $result;
}
return $results;
}
}
......@@ -594,5 +594,21 @@ abstract class AbstractPage
return $collection;
}
/**
* getType
*
* Get the current (extended) type of the abstract base page.
*
* @access public
* @return void
*/
public function getType()
{
// Strip off the namespace and get the class name
// We cant use "end" because it cant handle this
// array in "stream" (needs to be stored in a var)
return current(array_reverse(explode('\\', get_called_class())));
}
}
......@@ -36,10 +36,10 @@ services:
# Use a custom Twig extension to parse twig code
# inside of a twig variable.
#
jity.twig.jity_extension:
class: Jity\HomepageBundle\Twig\JityExtension
tags:
- { name: twig.extension }
# jity.twig.jity_extension:
# class: Jity\HomepageBundle\Twig\JityExtension
# tags:
# - { name: twig.extension }
#
# Custom Logic for OAuth Logins.
......
......@@ -309,13 +309,8 @@ hr {
border-top-width: 2px;
border-top-style: solid;
border-radius: 6px 6px 6px 6px;
margin-top: 15px;