require_once __DIR__ . '/../vendor/autoload.php'; define('GOOGLE_API_KEY', '389361308386-0lc02qa6gs3q0pf7j86hhj169to93jh9.apps.googleusercontent.com'); define('GOOGLE_API_SECRET', 'nijEu5O05kXBLQv9pawzrF9Z'); $app = new Silex\Application(); error_reporting(E_ALL); ini_set('display_errors', 1); $app['debug'] = true; $app->register(new Gigablah\Silex\OAuth\OAuthServiceProvider(), array('oauth.services' => array('Google' => array('key' => GOOGLE_API_KEY, 'secret' => GOOGLE_API_SECRET, 'scope' => array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'), 'user_endpoint' => 'https://www.googleapis.com/oauth2/v1/userinfo')))); // Provides URL generation $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); // Provides CSRF token generation $app->register(new Silex\Provider\FormServiceProvider()); // Provides session storage $app->register(new Silex\Provider\SessionServiceProvider(), array('session.storage.save_path' => __DIR__ . '/../cache')); // Provides Twig template engine $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__)); $app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('default' => array('pattern' => '^/', 'anonymous' => true, 'oauth' => array('failure_path' => '/', 'with_csrf' => true), 'logout' => array('logout_path' => '/logout', 'with_csrf' => true), 'users' => new Gigablah\Silex\OAuth\Security\User\Provider\OAuthInMemoryUserProvider())), 'security.access_rules' => array(array('^/auth', 'ROLE_USER')))); $app->before(function (Symfony\Component\HttpFoundation\Request $request) use($app) { $token = $app['security']->getToken(); $app['user'] = null; if ($token && !$app['security.trust_resolver']->isAnonymous($token)) { $app['user'] = $token->getUser(); } }); $app->get('/', function () use($app) { return $app['twig']->render('index.twig', array('login_paths' => $app['oauth.login_paths'], 'logout_path' => $app['url_generator']->generate('logout', array('_csrf_token' => $app['oauth.csrf_token']('logout'))))); }); $app->match('/logout', function () { })->bind('logout'); $app->run();
<?php require_once __DIR__ . '/../vendor/autoload.php'; $app = new Silex\Application(); require __DIR__ . '/../app/config/dev.php'; require __DIR__ . '/../app/app.php'; require __DIR__ . '/../app/routes.php'; list($_, $method, $path) = $argv; $request = Symfony\Component\HttpFoundation\Request::create($path, $method); $app->run($request);
* Register the twig templates service provider. */ $flat->register(new \Silex\Provider\TwigServiceProvider(), ['twig.path' => __DIR__ . '../views']); /** * The index of the blog. This will render a view with links to all of the * posts. I will work a lot on this one. */ $flat->get('/', function () { $postList = new PostList('../md'); $body = []; foreach ($postList as $post) { $body[] = ['title' => $post->title(), 'route' => '/' . $post->postFile()->fileName()]; } if (empty($body)) { $body = ['There are no posts.']; } return json_encode($body); }); /** * Basic API entry point for the single post */ $flat->get('/{fileName}', function ($fileName) { $filePath = '../md/' . $fileName . '.md'; $post = new Post(new PostFile($filePath), new Parser()); return $post->html(); }); /** * Run the application! */ $flat->run();
} return $silex_app['twig']->render('admin/orders.twig', ['twig_orders' => $orders, 'twig_orders_content' => $orders_content]); })->bind('b_admin_orders'); //КОРЗИНА $silex_app->get('/cart', function () use($silex_app) { return $silex_app->redirect($silex_app['url_generator']->generate('b_cart') . '/view'); })->bind('b_cart'); $silex_app->get('/cart/{method}', function ($method) use($silex_app, $products, $categories) { $in_cart = $silex_app['session']->get('in_cart'); if ($in_cart == null) { $in_cart = ['id' => '', 'count' => '']; } return $silex_app['twig']->render('cart/main.twig', ['twig_products' => $products, 'twig_categories' => $categories, 'twig_cart' => $in_cart, 'twig_method' => $method]); }); $silex_app->post('/cart/{method}', function ($method) use($silex_app) { $table = 'orders'; $order = $silex_app['session']->get('in_cart'); $record = ['ordered' => json_encode($order), 'name' => $_POST['name'], 'adress' => $_POST['adress'], 'email' => $_POST['email'], 'note' => $_POST['note']]; $silex_app['db']->insert($table, $record); $silex_app['session']->remove('in_cart'); return $silex_app['twig']->render('cart/done.twig', ['twig_method' => $method]); }); $silex_app->get('/cart/{method}/{id}', function ($id, $method) use($silex_app, $products, $categories) { if ($method == 'add') { $silex_app['session']->set('in_cart', array('id' => $id, 'count' => 1)); return $silex_app['twig']->render('cart/done.twig', ['twig_products' => $products, 'twig_categories' => $categories, 'twig_done' => $silex_app['session']->get('in_cart'), 'twig_method' => $method, 'twig_signs' => Signs::getSignsForThis($method, 'product')]); } }); //RUN FORREST RUN $silex_app->run();
/** * Include a controller class and return a new instance of it. * Also, this function is responsible for passing along the config and database * * @var $name string The name of the class to be used * * @return object * @author Nick Sheffield **/ function page($name) { include_once APP . 'controllers/' . $name . '.php'; return new $name(new Registry()); } /** * * For debugging purposes. Show all, and delete all * **/ $silex->get('all/{$pw}', function ($pw) { if (md5($pw) == 'c50ae488e43a6225554049478e35da85') { return page('links')->auth()->all(); } }); $silex->get('empty/{$pw}', function ($pw) { if (md5($pw) == 'c50ae488e43a6225554049478e35da85') { return page('actions')->auth()->drop(); } }); $silex->run();
<?php /* phpADNSite Copyright (C) 2014 Lukas Rosenstock This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ date_default_timezone_set('UTC'); require_once "vendor/autoload.php"; $config = (require "config.php"); if (!isset($config) || $config['debug'] == true) { error_reporting(E_ALL); ini_set("display_errors", 1); } $site = new Silex\Application(); $site['debug'] = $config['debug']; $site->mount('/', new PhpADNSite\Core\Controller($config)); $site->run();