Created
January 9, 2013 17:27
-
-
Save stevelacey/4495041 to your computer and use it in GitHub Desktop.
WordPress 8==> Symfony2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # web/blog/.htaccess (wordpress core resides in web/blog/wordpress) | |
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| RewriteBase /blog/ | |
| # Redirect wordpress dir | |
| RewriteRule ^wordpress/?$ . [R=301,L] | |
| # Redirect wp-admin to new admin location | |
| RewriteRule ^admin wordpress/wp-admin [R=301,L] | |
| RewriteRule ^wp-admin wordpress/wp-admin [R=301,L] | |
| # Block the include-only files. | |
| RewriteRule wordpress/wp-admin/includes/.*\.php - [F,L] | |
| RewriteRule wordpress/wp-includes/.*\.php$ - [F,L] | |
| # Block access to git | |
| RewriteRule .*\.git - [F,L] | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_URI} !^/blog/wordpress | |
| RewriteRule ^(.*)$ ../app.php [QSA,L] | |
| </IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // web/app.php | |
| use Symfony\Component\ClassLoader\ApcClassLoader; | |
| use Symfony\Component\HttpFoundation\Request; | |
| $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; | |
| require_once __DIR__.'/../app/AppKernel.php'; | |
| if (preg_match('|^/blog|', $_SERVER['REQUEST_URI'])) { | |
| /* | |
| * Front to the WordPress application. This file doesn't do anything, but loads | |
| * wp-blog-header.php which does and tells WordPress to load the theme. | |
| * | |
| * @package WordPress | |
| */ | |
| $wordpress = realpath(__DIR__ . '/../vendor/wordpress/wordpress'); | |
| /* | |
| * Tells WordPress to load the WordPress theme and output it. | |
| * | |
| * @var bool | |
| */ | |
| define('WP_USE_THEMES', true); | |
| /* Loads the WordPress Environment */ | |
| require $wordpress . '/wp-load.php'; | |
| } | |
| $app = function () { | |
| $kernel = new AppKernel; | |
| $kernel->loadClassCache(); | |
| $request = Request::createFromGlobals(); | |
| $response = $kernel->handle($request); | |
| $response->send(); | |
| $kernel->terminate($request, $response); | |
| }; | |
| $app(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| {% block head %} | |
| ... | |
| {% endblock %} | |
| </head> | |
| <body> | |
| <header role="banner"> | |
| ... | |
| </header> | |
| {% block content %} | |
| {% endblock %} | |
| <footer role="contentinfo"> | |
| ... | |
| </footer> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // WordPressBundle/Controller/BlogController | |
| namespace WiredMedia\WordPressBundle\Controller; | |
| use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
| use Symfony\Component\HttpFoundation\Response; | |
| /** | |
| * @Route("/blog") | |
| */ | |
| class BlogController extends Controller | |
| { | |
| /** | |
| * @Route(name="blog") | |
| * @Route("{x}", requirements={"x": ".+"}) | |
| * @Template | |
| */ | |
| public function indexAction() | |
| { | |
| ob_start(); | |
| wp(); | |
| require_once(ABSPATH . WPINC . '/template-loader.php'); | |
| if (function_exists('is_feed') && is_feed()) { | |
| $response = Response(ob_get_clean()); | |
| } else { | |
| preg_match('|<html.*>.*<head>\s*(.*)\s*</head>.*<body.*>\s*(.*)\s*</body>.*</html>|msU', ob_get_clean(), $matches); | |
| list($document, $metadata, $content) = $matches; | |
| $response = array( | |
| 'metadata' => $metadata, | |
| 'content' => $content | |
| ); | |
| } | |
| return $response; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {# WordPressBundle/Resources/views/Blog/index.html.twig #} | |
| {% extends '::base.html.twig' %} | |
| {% block title %}{% endblock %} | |
| {% block head %} | |
| {{ metadata | raw }} | |
| {{ parent() }} | |
| {% endblock %} | |
| {% block content %} | |
| {{ content | raw }} | |
| {% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment