diff --git a/.gitignore b/.gitignore index 3fbe668c9..72e5ffada 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,4 @@ # Data for wallabag data/assets/* -data/db/poche*.sqlite +data/db/wallabag*.sqlite diff --git a/app/AppKernel.php b/app/AppKernel.php index fe61b255d..d134de3cc 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -21,6 +21,7 @@ class AppKernel extends Kernel new JMS\SerializerBundle\JMSSerializerBundle(), new Nelmio\ApiDocBundle\NelmioApiDocBundle(), new Nelmio\CorsBundle\NelmioCorsBundle(), + new Liip\ThemeBundle\LiipThemeBundle(), new Wallabag\CoreBundle\WallabagCoreBundle() ); diff --git a/app/config/config.yml b/app/config/config.yml index 8e7258ea7..1bd93d645 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -128,3 +128,24 @@ nelmio_cors: allow_methods: ['POST', 'PUT', 'GET', 'DELETE'] max_age: 3600 hosts: ['^api\.'] + +liip_theme: + load_controllers: false + themes: + - baggy + - dark + - default + - dmagenta + - solarized + - solarized-dark + autodetect_theme: wallabag_core.helper.detect_active_theme + + path_patterns: + app_resource: + - %%app_path%%/views/themes/%%current_theme%%/%%template%% + - %%app_path%%/views/%%template%% + bundle_resource: + - %%bundle_path%%/Resources/views/themes/%%current_theme%%/%%template%% + bundle_resource_dir: + - %%dir%%/views/themes/%%current_theme%%/%%bundle_name%%/%%template%% + - %%dir%%/views/%%bundle_name%%/%%override_path%% diff --git a/app/config/config_test.yml b/app/config/config_test.yml index 83e2922a2..a6ead1e82 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -17,4 +17,6 @@ swiftmailer: doctrine: dbal: - path: %kernel.root_dir%/../data/db/poche_test.sqlite + driver: pdo_sqlite + path: %kernel.root_dir%/../data/db/wallabag_test.sqlite + host: localhost diff --git a/app/config/routing.yml b/app/config/routing.yml index 20f6979a6..d681b39b7 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -19,6 +19,6 @@ logout: path: /logout rest : - type : rest - resource : "routing_rest.yml" - prefix : /api \ No newline at end of file + type : rest + resource : "routing_rest.yml" + prefix : /api diff --git a/composer.json b/composer.json index d49f3df36..0b162c028 100644 --- a/composer.json +++ b/composer.json @@ -75,6 +75,7 @@ "tecnick.com/tcpdf": "~6.2", "simplepie/simplepie": "~1.3.1", "htmlawed/htmlawed": "dev-master", + "liip/theme-bundle": "1.1.3", "wallabag/PHP-Flash-Messages": "dev-master", "wallabag/kriss_php5": "dev-master", "wallabag/pagination": "dev-master", diff --git a/composer.lock b/composer.lock index 8fd4b2ab2..a6102a819 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "4cbcfeafb3c1dc4ed8c364e93969808f", + "hash": "fd56c671d70f498ccc1996450479fbdc", "packages": [ { "name": "doctrine/annotations", @@ -1282,6 +1282,61 @@ ], "time": "2014-12-12 05:04:05" }, + { + "name": "liip/theme-bundle", + "version": "1.1.3", + "target-dir": "Liip/ThemeBundle", + "source": { + "type": "git", + "url": "https://github.com/liip/LiipThemeBundle.git", + "reference": "a594cc6deda293034b8fd7795c9950f02fc8251b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/liip/LiipThemeBundle/zipball/a594cc6deda293034b8fd7795c9950f02fc8251b", + "reference": "a594cc6deda293034b8fd7795c9950f02fc8251b", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/framework-bundle": "~2.0" + }, + "require-dev": { + "symfony/console": "~2.0", + "symfony/expression-language": "~2.6" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "Liip\\ThemeBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Community contributions", + "homepage": "https://github.com/liip/LiipThemeBundle/contributors" + }, + { + "name": "Liip AG", + "homepage": "http://www.liip.ch/" + } + ], + "description": "Provides theming support for #Symfony2 Bundles", + "keywords": [ + "themes", + "theming" + ], + "time": "2015-02-02 15:55:54" + }, { "name": "mgargano/simplehtmldom", "version": "1.5", @@ -2590,7 +2645,7 @@ "description": "Libraries from @fivefilters.", "homepage": "https://github.com/wallabag/Fivefilters_Libraries", "support": { - "source": "https://github.com/wallabag/Fivefilters_Libraries/tree/master", + "source": "https://github.com/wallabag/Fivefilters_Libraries/tree/1.0.0", "issues": "https://github.com/wallabag/Fivefilters_Libraries/issues" }, "time": "2015-01-19 20:19:28" @@ -2635,7 +2690,7 @@ "description": "PHP Classes for dynamically generating EPub files.", "homepage": "https://github.com/wallabag/PHPePub", "support": { - "source": "https://github.com/wallabag/PHPePub/tree/master" + "source": "https://github.com/wallabag/PHPePub/tree/2.1.0" }, "time": "2015-01-19 11:44:19" }, @@ -2672,7 +2727,7 @@ "description": "A simple and smart (or stupid) php5 snippets repository", "homepage": "https://github.com/wallabag/kriss_php5", "support": { - "source": "https://github.com/wallabag/kriss_php5/tree/master" + "source": "https://github.com/wallabag/kriss_php5/tree/1.0.0" }, "time": "2015-01-18 21:21:43" }, @@ -2709,7 +2764,7 @@ "description": "Paginate record sets, not tied in directly to a database.", "homepage": "https://github.com/wallabag/pagination", "support": { - "source": "https://github.com/wallabag/pagination/tree/master" + "source": "https://github.com/wallabag/pagination/tree/1.0.0" }, "time": "2015-01-19 09:24:39" }, @@ -2755,7 +2810,7 @@ "sessions" ], "support": { - "source": "https://github.com/wallabag/PHP-Flash-Messages/tree/master" + "source": "https://github.com/wallabag/PHP-Flash-Messages/tree/1.0.0" }, "time": "2015-01-18 19:51:55" }, @@ -2809,7 +2864,7 @@ "html" ], "support": { - "source": "https://github.com/wallabag/php-readability/tree/master", + "source": "https://github.com/wallabag/php-readability/tree/1.0.0", "issues": "https://github.com/wallabag/php-readability/issues" }, "time": "2015-01-19 12:25:38" @@ -2847,7 +2902,7 @@ "description": "An experimental Mobipocket file creator in PHP.", "homepage": "https://github.com/wallabag/phpMobi", "support": { - "source": "https://github.com/wallabag/phpMobi/tree/master" + "source": "https://github.com/wallabag/phpMobi/tree/1.0.0" }, "time": "2015-01-19 12:43:17" }, diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 68e034fa7..4e8958759 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -7,7 +7,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\User; -use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; use Wallabag\CoreBundle\Form\Type\UserType; use Wallabag\CoreBundle\Form\Type\NewUserType; @@ -25,14 +24,18 @@ class ConfigController extends Controller $config = $this->getConfig(); $user = $this->getUser(); - // handle basic config detail - $configForm = $this->createForm(new ConfigType(), $config); + // handle basic config detail (this form is defined as a service) + $configForm = $this->createForm('config', $config); $configForm->handleRequest($request); if ($configForm->isValid()) { $em->persist($config); $em->flush(); + // switch active theme + $activeTheme = $this->get('liip_theme.active_theme'); + $activeTheme->setName($config->getTheme()); + $this->get('session')->getFlashBag()->add( 'notice', 'Config saved' diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 7b4464a17..91f9bfe82 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -48,7 +48,7 @@ class Config private $language; /** - * @ORM\ManyToOne(targetEntity="User", inversedBy="config") + * @ORM\OneToOne(targetEntity="User", inversedBy="config") */ private $user; diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index 193dfebc2..ed5cfe535 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -92,6 +92,11 @@ class User implements AdvancedUserInterface, \Serializable */ private $entries; + /** + * @ORM\OneToOne(targetEntity="Config", mappedBy="user") + */ + private $config; + public function __construct() { $this->salt = md5(uniqid(null, true)); @@ -320,4 +325,26 @@ class User implements AdvancedUserInterface, \Serializable { return $this->isActive; } + /** + * Set config + * + * @param \Wallabag\CoreBundle\Entity\Config $config + * @return User + */ + public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null) + { + $this->config = $config; + + return $this; + } + + /** + * Get config + * + * @return \Wallabag\CoreBundle\Entity\Config + */ + public function getConfig() + { + return $this->config; + } } diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php index a1e0ce47d..0c8706e2a 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php @@ -7,20 +7,23 @@ use Symfony\Component\OptionsResolver\OptionsResolverInterface; class ConfigType extends AbstractType { + private $themes = array(); + + /** + * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes) + */ + public function __construct($themes) + { + $this->themes = array_combine( + $themes, + array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes) + ); + } + public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('theme', 'choice', array( - 'choices' => array( - 'baggy' => 'Baggy', - 'courgette' => 'Courgette', - 'dark' => 'Dark', - 'default' => 'Default', - 'dmagenta' => 'Dmagenta', - 'solarized' => 'Solarized', - 'solarized_dark' => 'Solarized Dark', - ), - )) + ->add('theme', 'choice', array('choices' => $this->themes)) ->add('items_per_page', 'text') ->add('language') ->add('save', 'submit') diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php new file mode 100644 index 000000000..2a943bb7d --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -0,0 +1,47 @@ +securityContext = $securityContext; + } + + public function setUserAgent($userAgent) + { + } + + /** + * This should return the active theme for the logged in user. + * No active theme for: + * - anonymous user + * - user without a config (shouldn't happen..) + * + * @return string + */ + public function getType() + { + $user = $this->securityContext->getToken()->getUser(); + + // anon user don't deserve a theme + if (!$user instanceof User) { + return false; + } + + $config = $user->getConfig(); + + if (!$config) { + return false; + } + + return $config->getTheme(); + } +} diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index b066c1a3b..5437d1cf8 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -1,15 +1,29 @@ services: - wallabag_core.twig.wallabag: + wallabag_core.twig.extension: class: Wallabag\CoreBundle\Twig\Extension\WallabagExtension tags: - { name: twig.extension } + wsse.security.authentication.provider: class: Wallabag\CoreBundle\Security\Authentication\Provider\WsseProvider public: false arguments: ['', '%kernel.cache_dir%/security/nonces'] + wsse.security.authentication.listener: class: Wallabag\CoreBundle\Security\Firewall\WsseListener public: false tags: - { name: monolog.logger, channel: wsse } arguments: ['@security.context', '@security.authentication.manager', '@logger'] + + wallabag_core.helper.detect_active_theme: + class: Wallabag\CoreBundle\Helper\DetectActiveTheme + arguments: + - @security.context + + wallabag_core.form.type.config: + class: Wallabag\CoreBundle\Form\Type\ConfigType + arguments: + - %liip_theme.themes% + tags: + - { name: form.type, alias: config } diff --git a/src/Wallabag/CoreBundle/Resources/views/_head.html.twig b/src/Wallabag/CoreBundle/Resources/views/_head.html.twig index 3bdbe8124..b7ec3a830 100755 --- a/src/Wallabag/CoreBundle/Resources/views/_head.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/_head.html.twig @@ -1,28 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - +{% include "WallabagCoreBundle:themes:_global/_head_icon.html.twig" %} diff --git a/src/Wallabag/CoreBundle/Resources/views/_messages.html.twig b/src/Wallabag/CoreBundle/Resources/views/_messages.html.twig index e69de29bb..18e294c9d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/_messages.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/_messages.html.twig @@ -0,0 +1,9 @@ + +{% if flashMessages %} +
+{% endif %} diff --git a/src/Wallabag/CoreBundle/Resources/views/_top.html.twig b/src/Wallabag/CoreBundle/Resources/views/_top.html.twig index 9313071dc..a4403c130 100755 --- a/src/Wallabag/CoreBundle/Resources/views/_top.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/_top.html.twig @@ -1,5 +1,5 @@