Permalink
Browse files

initial release

Added some basic functions, there is still alot stuff to do.
At this state it's a good base for everyone that starts programming a blog
  • Loading branch information...
0 parents commit caec7d06c548ceb8e867021c4c56b3f45e2c508a @bloodywing committed Jan 23, 2012
@@ -0,0 +1,8 @@
+<IfModule mod_rewrite.c>
+ Options -MultiViews
+
+ RewriteEngine On
+ #RewriteBase /path/to/app
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteRule ^ index.php [L]
+</IfModule>
@@ -0,0 +1,16 @@
+<?php
+ error_reporting(E_ALL);
+
+ if(!isset($here)) {
+ $here = __DIR__;
+ }
+
+ if(!defined('LIB')) {
+ define('LIB', __DIR__.'/lib');
+ }
+
+ include LIB.'/constants.php';
+ include LIB.'/publish.php';
+
+ blog_run();
+?>
@@ -0,0 +1,61 @@
+<?php
+require 'silex.phar';
+
+/** @var $app Silex\Application */
+$app = new Silex\Application();
+
+/**
+ * Settins
+ */
+
+/**
+ * Turn Debug on or off
+ */
+(DEBUG == 1) ? $app['debug'] = true : $app['debug'] = false;
+
+/**
+ * Twig as Tempatesystem
+ */
+
+$app['autoloader']->registerNamespace('SilexExtension', __DIR__ . '/../vendor/silex-extension/src');
+$app['autoloader']->register();
+$app->register(new Silex\Provider\TwigServiceProvider(), array(
+ 'twig.class_path' => __DIR__.'/../vendor/twig/lib',
+ 'twig.path' => __DIR__.'/../tmpl/'
+));
+
+use Symfony\Component\ClassLoader\UniversalClassLoader;
+$loader = new UniversalClassLoader();
+$loader->registerNameSpace('entities', __DIR__);
+$loader->register();
+
+/**
+ * Symfony Validator Extension
+ */
+
+$app->register(new Silex\Provider\ValidatorServiceProvider(), array(
+ 'validator.class_path' => __DIR__.'/../vendor/symfony/src'
+));
+
+/**
+ * MongoDB
+ */
+$app->register(new SilexExtension\MongoDbExtension(), array(
+ 'mongodb.class_path' => __DIR__.'/../vendor/mongodb/lib',
+ 'mongodb.connection' => array(
+ 'configuration' => function($configuration) {
+ $configuration->setLoggerCallable(function($logs){
+ (DEBUG == 1) ? print_r($logs) : null;
+ });
+ }
+ )
+));
+
+/**
+ * Register some needed providers
+ * You can simply add more here
+ */
+
+$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
+
+?>
@@ -0,0 +1,5 @@
+<?php
+define('DEBUG', 0);
+define('MONGODB', 'blog');
+
+?>
@@ -0,0 +1,105 @@
+<?php
+
+namespace entities;
+
+/**
+ * Description of Article
+ *
+ * @author pierre
+ */
+class Article {
+ private $id;
+ private $author;
+ private $title;
+ private $body;
+ private $date;
+ private $tags = array();
+
+ public function save($app) {
+ /* @var $db \Doctrine\MongoDB\Connection */
+ $db = $app['mongodb'];
+ /* @var $collection \Doctrine\MongoDB\LoggableCollection */
+ $collection = $db->selectCollection(MONGODB, 'articles');
+ $self = array(
+ 'Author' => $this->author,
+ 'Title' => $this->title,
+ 'Body' => $this->body,
+ 'Date' => $this->date,
+ 'Tags' => $this->tags
+ );
+ $collection->insert($self);
+ }
+
+ /**
+ *
+ * @param type $app
+ * @return \Doctrine\MongoDB\Cursor
+ */
+ public function getAll(\Silex\Application $app) {
+ /* @var $db \Doctrine\MongoDB\Connection */
+ $db = $app['mongodb'];
+ /* @var $collection \Doctrine\MongoDB\LoggableCollection */
+ $collection = $db->selectCollection(MONGODB, 'articles');
+ return $collection->find();
+ }
+
+ public function getOne(\Silex\Application $app, $title) {
+ /* @var $db \Doctrine\MongoDB\Connection */
+ $db = $app['mongodb'];
+ /* @var $collection \Doctrine\MongoDB\LoggableCollection */
+ $collection = $db->selectCollection(MONGODB, 'articles');
+ return $collection->findOne(array('Title' => $title));
+ }
+
+ public function getId() {
+ return $this->id;
+ }
+
+ public function setId($id) {
+ $this->id = $id;
+ }
+
+ public function getAuthor() {
+ return $this->author;
+ }
+
+ public function setAuthor($author) {
+ $this->author = $author;
+ }
+
+ public function getTitle() {
+ return $this->title;
+ }
+
+ public function setTitle($title) {
+ $this->title = $title;
+ }
+
+ public function getBody() {
+ return $this->body;
+ }
+
+ public function setBody($body) {
+ $this->body = $body;
+ }
+
+ public function getDate() {
+ return $this->date;
+ }
+
+ public function setDate($date) {
+ $this->date = $date;
+ }
+
+ public function getTags() {
+ return $this->tags;
+ }
+
+ public function setTags($tags) {
+ $this->tags = $tags;
+ }
+
+
+}
+
+?>
@@ -0,0 +1,10 @@
+<?php
+include 'bootstrap.php';
+
+/* @var $app Silex\Application */
+$app->get('/navigation', function() use($app) {
+ return $app['twig']->render('Navigation.twig',array(
+ 'navlinks' => array($app['url_generator']->generate('Home'))
+ ));
+});
+?>
@@ -0,0 +1,49 @@
+<?php
+ include 'bootstrap.php';
+ use entities\Article;
+
+ function get_articles() {
+ /* @var $app Silex\Application */
+ global $app;
+
+ $collection = 'articles';
+ $app->get('/', function() use($app, $collection) {
+ $article = new Article();
+ /* @var $cursor Doctrine\MongoDB\LoggableCursor */
+ $cursor = $article->getAll($app);
+
+ $posts = '';
+ foreach($cursor->toArray() as $post) {
+ /**
+ * Clean Code :)
+ */
+ $posts[] = $post;
+ }
+
+ return $app['twig']->render('Articles.twig', array('articles' => $posts));
+
+ });
+ }
+
+ function get_article($title){
+ global $app;
+
+ /** Revert Title */
+ $original_title = str_replace('_', ' ', $title);
+ $article = new Article();
+ $oneArticle = $article->getOne($app,$original_title);
+ return $app['twig']->render('Post.twig', array('a' => $oneArticle));
+ }
+
+ function blog_run() {
+ global $app;
+ //var_dump($app->get('/article/{id}', show_article($id))->assert('id', '\d+'));
+
+ $app->get('/{pageName}', get_articles())->bind('home');
+ $app->get('/article/{article_title}', function($article_title){
+ return get_article($article_title);
+ });
+ $app->run();
+ }
+
+?>
Binary file not shown.
@@ -0,0 +1,18 @@
+{% from 'forms.twig' import input as forms %}
+<html>
+ <head>
+ {% block head %}
+ <title>Bitte einloggen</title>
+ {% endblock %}
+ </head>
+ <body>
+ <p>
+ <form action="" method="POST">
+ {{ forms('login', user) }}
+ {{ forms('password', password, 'password') }}
+ {{ forms('submit', "Login", 'submit') }}
+ </form>
+ </p>
+ {{log}}
+ </body>
+</html>
@@ -0,0 +1,12 @@
+{# empty Twig template #}
+
+{% extends "Main.twig" %}
+
+{% block articles %}
+{% for a in articles %}
+<div id='articlehead'>
+ <h2><a href="/article/{{a.Title|replace(' ', '_')}}">{{ a.Title }}</a></h2> :: <small>{{ a.Author }}</small> :: {{ a.Date|date("d/m/Y @ H:t") }}
+</div>
+<p id='body'>{{a.Body}}</p>
+{% endfor %}
+{% endblock %}
@@ -0,0 +1,12 @@
+<html>
+ <head>
+ {% include 'misc/head.twig' %}
+ <title>Nice Blog {{ pagename }}</title>
+ </head>
+ <body>
+ <div id="content">
+ {% block articles %}
+ {% endblock %}
+ </div>
+ </body>
+</html>
@@ -0,0 +1,10 @@
+{# empty Twig template #}
+
+{% extends "Main.twig" %}
+
+{% block articles %}
+<div id='articlehead'>
+ <h2><a href="/article/{{a.Title|replace(' ', '_')}}">{{ a.Title }}</a></h2> :: <small>{{ a.Author }}</small> :: {{ a.Date|date("d/m/Y @ H:t") }}
+</div>
+<p id='body'>{{a.Body}}</p>
+{% endblock %}
@@ -0,0 +1,10 @@
+<style type="text/css">
+ html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,
+ form,fieldset,legend,input,textarea,p,
+ blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;display:inline}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}
+
+ html { background: #eee; padding: 10px }
+ body { font: 11px Verdana, Arial, sans-serif; color: #333 }
+ img { border: 0; }
+ #content { width:970px; margin:0 auto; }
+ </style>
@@ -0,0 +1,3 @@
+{% macro input(name, value, type, size) %}
+ <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
+{% endmacro %}
@@ -0,0 +1,3 @@
+{% include "misc/css.twig" %}
+<meta name="keywords" content="{{ keywords }}" />
+<meta name="description" content="{{ description }}" />

0 comments on commit caec7d0

Please sign in to comment.