From 5bcd9f079b9122c7600b0ac926ab4f9cf68e57ac Mon Sep 17 00:00:00 2001 From: "Gergely Polonkai (W00d5t0ck)" Date: Tue, 4 Sep 2012 13:09:32 +0200 Subject: [PATCH] Added basic blog functionality Signed-off-by: Gergely Polonkai (W00d5t0ck) --- app/AppKernel.php | 4 +- .../Version20120904115727.php | 32 ++++ app/config/config.yml | 12 ++ app/config/parameters.yml | 8 +- composer.json | 2 + .../FrontBundle/Controller/BlogController.php | 41 +++++ .../Controller/DefaultController.php | 10 +- .../DependencyInjection/Configuration.php | 1 - .../FrontBundle/Entity/Post.php | 163 ++++++++++++++++++ .../FrontBundle/Entity/User.php | 88 ++++++++++ .../Resources/views/Blog/viewPost.html.twig | 6 + .../views/Default/front_base.html.twig | 1 - .../Resources/views/Default/index.html.twig | 15 +- .../FrontBundle/Service/Slugifier.php | 43 +++++ .../DependencyInjection/Configuration.php | 1 - .../GeshiBundle/Resources/config/services.yml | 2 +- .../GeshiBundle/Twig/GeshiHighlight.php | 4 +- 17 files changed, 412 insertions(+), 21 deletions(-) create mode 100644 app/DoctrineMigrations/Version20120904115727.php create mode 100644 src/GergelyPolonkai/FrontBundle/Controller/BlogController.php create mode 100644 src/GergelyPolonkai/FrontBundle/Entity/Post.php create mode 100644 src/GergelyPolonkai/FrontBundle/Entity/User.php create mode 100644 src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig create mode 100644 src/GergelyPolonkai/FrontBundle/Service/Slugifier.php diff --git a/app/AppKernel.php b/app/AppKernel.php index cbcd68a..eb09665 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -20,7 +20,9 @@ class AppKernel extends Kernel new JMS\AopBundle\JMSAopBundle(), new JMS\DiExtraBundle\JMSDiExtraBundle($this), new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), - new Io\TcpdfBundle\IoTcpdfBundle(), + new Io\TcpdfBundle\IoTcpdfBundle(), + new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(), new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(), ); diff --git a/app/DoctrineMigrations/Version20120904115727.php b/app/DoctrineMigrations/Version20120904115727.php new file mode 100644 index 0000000..d6f19ec --- /dev/null +++ b/app/DoctrineMigrations/Version20120904115727.php @@ -0,0 +1,32 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); + + $this->addSql("CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(50) NOT NULL, name VARCHAR(100) NOT NULL, UNIQUE INDEX UNIQ_1483A5E9F85E0677 (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB"); + $this->addSql("CREATE TABLE blog_posts (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, title VARCHAR(100) NOT NULL, slug VARCHAR(100) NOT NULL, content LONGTEXT NOT NULL, created_at DATETIME NOT NULL, INDEX IDX_78B2F932A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB"); + $this->addSql("ALTER TABLE blog_posts ADD CONSTRAINT FK_78B2F932A76ED395 FOREIGN KEY (user_id) REFERENCES users (id)"); + } + + public function down(Schema $schema) + { + // this down() migration is autogenerated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); + + $this->addSql("ALTER TABLE blog_posts DROP FOREIGN KEY FK_78B2F932A76ED395"); + $this->addSql("DROP TABLE users"); + $this->addSql("DROP TABLE blog_posts"); + } +} diff --git a/app/config/config.yml b/app/config/config.yml index 70b76a9..b41bb37 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -57,3 +57,15 @@ swiftmailer: username: %mailer_user% password: %mailer_password% spool: { type: memory } + +jms_di_extra: + locations: + all_bundles: false + bundles: [ GergelyPolonkaiFrontBundle ] + +stof_doctrine_extensions: + default_locale: en_US + orm: + default: + sluggable: true + timestampable: true \ No newline at end of file diff --git a/app/config/parameters.yml b/app/config/parameters.yml index 6f0c6ee..0da2335 100644 --- a/app/config/parameters.yml +++ b/app/config/parameters.yml @@ -2,9 +2,9 @@ parameters: database_driver: pdo_mysql database_host: localhost database_port: ~ - database_name: symfony - database_user: root - database_password: ~ + database_name: gergelypolonkai + database_user: gergelypolonkai + database_password: the8dooM mailer_transport: smtp mailer_host: localhost @@ -12,4 +12,4 @@ parameters: mailer_password: ~ locale: en - secret: ThisTokenIsNotSoSecretChangeIt + secret: rie5chooqu8oche5ha6Keidop3ahxoob diff --git a/composer.json b/composer.json index db5f94f..7f47d0b 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,8 @@ "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*", "easybook/geshi": "dev-master", + "stof/doctrine-extensions-bundle": "dev-master", + "doctrine/doctrine-migrations-bundle": "dev-master", "gergelypolonkai/tcpdfbundle": "dev-master" }, "scripts": { diff --git a/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php new file mode 100644 index 0000000..181bc77 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php @@ -0,0 +1,41 @@ +setDate($year, $month, $day); + $date->setTime(0, 0, 0); + $date2 = new \DateTime(); + $date2->setDate($year, $month, $day); + $date2->setTime(0, 0, 0); + $date2->add(new \DateInterval('P1D')); + + $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p WHERE p.slug = :slug AND p.createdAt BETWEEN :date1 AND :date2"); + $query->setParameter(':slug', $slug); + $query->setParameter(':date1', $date); + $query->setParameter(':date2', $date2); + $post = $query->getOneOrNullResult(); + + return array( + 'post' => $post, + ); + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php index d12d8c9..20b1894 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php @@ -17,7 +17,13 @@ class DefaultController extends Controller */ public function indexAction() { - return array(); + $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p ORDER BY p.createdAt DESC"); + $query->setMaxResults(4); + $posts = $query->getResult(); + + return array( + 'posts' => $posts, + ); } /** @@ -30,7 +36,7 @@ class DefaultController extends Controller } /** - * @param string $_format + * @param string $_format * * @Route("/resume.{_format}", name="GergelyPolonkaiFrontBundle_resume") * @Template diff --git a/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php b/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php index 286ed20..9af3dba 100644 --- a/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php +++ b/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php @@ -23,7 +23,6 @@ class Configuration implements ConfigurationInterface // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for // more information on that topic. - return $treeBuilder; } } diff --git a/src/GergelyPolonkai/FrontBundle/Entity/Post.php b/src/GergelyPolonkai/FrontBundle/Entity/Post.php new file mode 100644 index 0000000..82b91b8 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Entity/Post.php @@ -0,0 +1,163 @@ +id; + } + + /** + * Set title + * + * @param string $title + * @return Post + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Get slug + * + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * Set user + * + * @param GergelyPolonkai\FrontBundle\Entity\User $user + * @return Post + */ + public function setUser(\GergelyPolonkai\FrontBundle\Entity\User $user) + { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return GergelyPolonkai\FrontBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } + + /** + * Set content + * + * @param string $content + * @return Post + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * Get content + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Get createdAt + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Entity/User.php b/src/GergelyPolonkai/FrontBundle/Entity/User.php new file mode 100644 index 0000000..0bc5f30 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Entity/User.php @@ -0,0 +1,88 @@ +id; + } + + /** + * Set username + * + * @param string $username + * @return User + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * Get username + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set name + * + * @param string $name + * @return User + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig new file mode 100644 index 0000000..2cfd600 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig @@ -0,0 +1,6 @@ +{% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %} +{% block content %} +

{{ post.title }}

+ +{{ post.content|raw }} +{% endblock content %} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig index 1ae49c9..14139c6 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig @@ -42,4 +42,3 @@ - diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/index.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/index.html.twig index a1e8386..08bf983 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/index.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/index.html.twig @@ -1,12 +1,9 @@ {% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %} + {% block content %} -

Upgrades requiring a reboot on Linux? At last!

- -

I've recently received an article on Google+ about Fedora's new idea: package upgrades that require a reboot. The article said that Linux guys have lost their primary adoo: "Haha! I don't have to reboot my system to install system upgrades!" My answer was always this: "You should..."

-

I think this can be a great idea if distros implement it well. PackageKit was a good first step on this road. That software could easily solve such an issue. However, it is sooo easy to do it wrong. The kernel, of course, can not be upgraded online (or could it be? I have some theories on this subject, wonder if it can be implemented...), but other packages are much different. From the users' point of view the best would be if the packages would be upgraded in the background seemlessly. E.g. PackageKit should check if the given executable is running. If not, it should upgrade it, while notifying the user like "hey dude, don't start Anjuta now, I'm upgrading it!", or simply denying to start it. Libraries are a bit different, as PackageKit should check if any running executables are using the library. Meanwhile, PK should also keep a notification somewhere telling the users that some packages could be upgraded, but without stopping this-and-that, it can not be done.

-

I know these things are easier said than done. But I think (a) users should tell such ideas to the developers and (b) developers (mostly large companies, like Microsoft or Apple) should listen to them, and at least think of these ideas. Some users are not as stupid as they think...

-

Wordpress madness

- -

I'm a bit fed up that I had to install MySQL on my server to have Wordpress working, so I've Googled a bit to find a solution for my pain. I found this: http://codex.wordpress.org/Using_Alternative_Databases. I don't know when this post was written, but I think it's a bit out of date. I mean come on, PDO is the part of PHP for ages now, and they say adding a DBAL to the dependencies would be a project as large as (or larger than) WP itself. Well, yes, but PHP is already a dependency, isn't it? Remove it guys, it's too large!

-

Okay, to be serious... Having a heavily MySQL dependent codebase is a bad thing in my opinion, and changing it is no easy task. But once it is done, it would be a child's play to keep it up to date, and to port WP to other database backends. And it would be more than enough to call it 4.0, and raising version numbers fast is a must nowadays (right, Firefox and Linux Kernel guys?)

+{% for post in posts %} +

{{ post.title }}

+ +{{ post.content|raw }} +{% endfor %} {% endblock content %} diff --git a/src/GergelyPolonkai/FrontBundle/Service/Slugifier.php b/src/GergelyPolonkai/FrontBundle/Service/Slugifier.php new file mode 100644 index 0000000..64e9f52 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Service/Slugifier.php @@ -0,0 +1,43 @@ +geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $this->geshi->enable_keyword_links(false); $this->geshi->enable_classes(); + return $this->geshi->parse_code(); } - public function getName() { + public function getName() + { return 'geshi_highlighter'; } }