Example #1
0
 /**
  * Constructor.
  *
  * @param array $options The SameAs Lite Store for which we shall
  * provide RESTful interfaces.
  */
 public function __construct(array $options = array())
 {
     // fake $_SERVER parameters if required (eg command line invocation)
     \SameAsLite\Helper::initialiseServerParameters();
     // set the default format of acceptable parameters
     // see http://docs.slimframework.com/routing/conditions/#application-wide-route-conditions
     \Slim\Route::setDefaultConditions(array('store' => '[a-zA-Z0-9_\\-\\.]+'));
     // initialise and configure Slim, using Twig template engine
     $mode = isset($options['mode']) ? $options['mode'] : 'production';
     $this->app = new \Slim\Slim(array('mode' => $mode, 'debug' => false, 'view' => new \Slim\Views\Twig()));
     // configure Twig
     $this->app->view()->setTemplatesDirectory('assets/twig/');
     $this->app->view()->parserOptions['autoescape'] = false;
     $this->app->view()->set('path', $this->app->request()->getRootUri());
     // register 404 and custom error handlers
     $this->app->notFound(array(&$this, 'outputError404'));
     $this->app->error(array(&$this, 'outputException'));
     // '\SameAsLite\Exception\Exception::outputException'
     set_exception_handler(array(&$this, 'outputException'));
     // '\SameAsLite\Exception\Exception::outputException'
     // Hook to set the api path
     $this->app->hook('slim.before.dispatch', function () {
         // fix api pages such that if viewing a particular store
         // then the store name is automatically injected for you
         $params = $this->app->router()->getCurrentRoute()->getParams();
         if (isset($params['store'])) {
             $apiPath = "datasets/{$params['store']}/api";
         } else {
             $apiPath = 'api';
         }
         $this->app->view()->set('apiPath', $apiPath);
     });
     // save the options
     $this->appOptions = $options;
     // apply options to template
     foreach ($options as $k => $v) {
         $this->app->view->set($k, $v);
     }
 }
Example #2
0
<?php

if (!isset($rpVersion)) {
    die;
}
// globally set some Twig variables
$app->view()->setData(array('docroot' => $app->request->getRootUri() . '/', 'version' => $rpVersion));
// All room ID's must be alphanumeric and N characters
\Slim\Route::setDefaultConditions(array('id' => '[' . preg_quote($rpIDChars) . ']{' . $rpIDLength . '}'));
// numeric routes use this regex
$numericRouteCondition = '[1-9][0-9]{0,}';
// Maintenance Mode Middleware
$downCheck = function () use($app) {
    global $rpDown;
    if (isset($rpDown)) {
        $app->response->setStatus(503);
        $app->view()->setData(array('info' => $rpDown));
        $app->render('down.html');
        $app->stop();
    }
};
$downCheckAjax = function () use($app) {
    global $rpDown;
    if (isset($rpDown)) {
        $app->halt(503);
    }
};
// Error pages
$app->notFound(function () use($app) {
    $app->view()->setData(array('uri' => $app->request->getResourceUri()));
    $app->render('404.html');
Example #3
0
require '../vendor/autoload.php';
use Pkj\Raspberry\PiFace\PiFaceDigital;
if (!class_exists('\\Spi')) {
    die("Spi extension must be installed (https://github.com/frak/php_spi)");
}
$app = new \Slim\Slim(array('debug' => false));
// Exception handler (make sure debug is false above)
$app->error(function (\Exception $e) use($app) {
    print json_encode(array('status' => '500', 'exception' => array('code' => $e->getCode(), 'message' => $e->getMessage())));
});
$app->notFound(function () use($app) {
    print json_encode(array('status' => '404', 'message' => 'Route not found'));
});
$pi = PiFaceDigital::create();
// Defining min/max values
\Slim\Route::setDefaultConditions(array('input' => '[0-' . (count($pi->getInputPins()) - 1) . ']', 'led' => '[0-' . (count($pi->getLeds()) - 1) . ']', 'output' => '[0-' . (count($pi->getOutputPins()) - 1) . ']', 'relay' => '[0-' . (count($pi->getRelays()) - 1) . ']', 'switch' => '[0-' . (count($pi->getSwitches()) - 1) . ']', 'value' => '[0-1]'));
// Begin read only devices
// Input
$app->get('/input/', function () use($app, $pi) {
    responseSuccess(outputAll($pi->getInputPins()));
});
$app->get('/input/:input', function ($input) use($app, $pi) {
    responseSuccess($pi->getInputPins()[$input]->getValue());
});
// Switch
$app->get('/switch/', function () use($app, $pi) {
    responseSuccess(outputAll($pi->getSwitches()));
});
$app->get('/switch/:switch', function ($switch) use($app, $pi) {
    responseSuccess($pi->getSwitches()[$switch]->getValue());
});
Example #4
0
 /**
  * Test route default conditions
  *
  * Pre-conditions:
  * Route class has default conditions;
  *
  * Post-conditions:
  * Case A: Route instance has default conditions;
  * Case B: Route instance has newly merged conditions;
  */
 public function testRouteDefaultConditions()
 {
     \Slim\Route::setDefaultConditions(array('id' => '\\d+'));
     $r = new \Slim\Route('/foo', function () {
     });
     //Case A
     $this->assertEquals(\Slim\Route::getDefaultConditions(), $r->getConditions());
     //Case B
     $r->conditions(array('name' => '[a-z]{2,5}'));
     $c = $r->getConditions();
     $this->assertArrayHasKey('id', $c);
     $this->assertArrayHasKey('name', $c);
 }
Example #5
0
<?php

require_once dirname(__FILE__) . "/common.inc.php";
define("GALLERY_MAX_PER_PAGE", 18);
use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\View\TwitterBootstrap3View;
\Slim\Route::setDefaultConditions(array('lang' => 'en|ja'));
$twigView = new \Slim\Extras\Views\Twig();
$app = new \Slim\Slim(array('debug' => SLIM_DEBUG, 'view' => $twigView, 'templates.path' => dirname(__FILE__) . "/templates"));
$app->hook('slim.before', function () use($app) {
    $app->view()->appendData(array('base_url' => BASE_URL));
});
$app->get("/", function () use($app) {
    index($app, "en");
});
$app->get("/:lang/?", function ($lang) use($app) {
    index($app, $lang);
});
function index($app, $lang)
{
    if (!file_exists($app->view()->getTemplatesDirectory() . "/" . $lang . "/index.html")) {
        $app->notFound();
        return;
    }
    $api_type = $app->request()->params("api_type");
    if (isset($GLOBALS["api_type_list"][$api_type])) {
        $cs_id = $app->request()->params("cs_id");
        if (!ctype_digit($cs_id)) {
            $cs_id = "";
        }
Example #6
0
/**
 * LICENSE: This source code is subject to the license that is available
 * in the LICENSE file distributed along with this package.
 *
 * @package    Penelope
 * @author     Matthew Caruana Galizia <*****@*****.**>
 * @copyright  Karwana Ltd
 * @since      File available since Release 1.0.0
 */
namespace Karwana\Penelope;

const VERSION = '1.0.0';
use Closure;
use Slim;
use Everyman\Neo4j;
Slim\Route::setDefaultConditions(array('node_id' => '\\d+', 'edge_id' => '\\d+'));
class Penelope
{
    use OptionContainer;
    private $schema, $app, $client;
    protected static $defaults = array('path.format.uploads' => '/uploads/:file_name', 'path.format.resources' => '/resources/:resource_path+', 'path.format.search' => '/search');
    public function __construct(Neo4j\Client $client, Slim\Slim $app, Theme $theme = null, array $options = null)
    {
        $this->setOptions($options);
        $this->app = $app;
        $this->client = $client;
        $this->schema = new Schema($client);
        if ($theme) {
            $this->setTheme($theme);
        }
        if ($this->hasOption('upload.directory')) {
Example #7
0
<?php

session_start();
date_default_timezone_set('Europe/Warsaw');
header('Access-Control-Allow-Origin: *');
require 'config_com.php';
require 'app/vendor/Slim/Slim.php';
require 'app/vendor/Swift_Mailer/swift_required.php';
function getConnection()
{
    $dbh = new PDO('mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DBNAME, MYSQL_USER, MYSQL_PASS);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    $dbh->query("SET character_set_results = 'utf8',\n                 character_set_client = 'utf8', \n                 character_set_connection = 'utf8',\n                 character_set_database = 'utf8',  \n                 character_set_server = 'utf8'");
    return $dbh;
}
\Slim\Slim::registerAutoloader();
\Slim\Route::setDefaultConditions(array('slug' => '[0-9-a-zA-Z_]{3,}'));
$transport = Swift_SmtpTransport::newInstance('localhost', 465, 'ssl')->setUsername('test@localhost')->setPassword('polpol');
$mailer = Swift_Mailer::newInstance($transport);
$app = new \Slim\Slim(array('debug' => true));
require 'app/routes/api.php';
$app->notFound(function () use($app) {
    echo '404';
});
$app->run();
Example #8
0
 public function testSetDefaultConditions()
 {
     \Slim\Route::setDefaultConditions(array('id' => '\\d+'));
     $property = new \ReflectionProperty('\\Slim\\Route', 'defaultConditions');
     $property->setAccessible(true);
     $this->assertEquals(array('id' => '\\d+'), $property->getValue());
 }
Example #9
0
    $v->setData('lang', $lang);
    $v->setData('negate', $ui['negate']);
    $v->setData('contrast', $ui['contrast']);
    $v->setData('brightness', $ui['brightness']);
    $v->setData('print', $ui['print']);
    $v->setData('comment', $conf->getComment());
    $fmts = $conf->getFormats();
    $v->setData('thumb_format', $fmts['thumb']);
    $remote_infos = $conf->getRemoteInfos();
    if ($remote_infos !== false) {
        $v->setData('remote_method', $remote_infos['method']);
        $v->setData('remote_uri', $remote_infos['uri']);
    }
});
//set default conditions
Route::setDefaultConditions(array('image' => '.+\\.[a-zA-Z]{3,4}', 'series' => '.+', 'format' => 'full|' . implode('|', array_keys($conf->getFormats()))));
//404 handler
$app->notFound(function () use($app) {
    $app->render('404.html.twig');
});
//custom error handler
$app->error(function (\Exception $e) use($app, $conf, $app_base_url) {
    $resuUri = $app->request()->getResourceUri();
    $etype = get_class($e);
    Analog::error('exception \'' . $etype . '\' with message \'' . $e->getMessage() . '\' in ' . $e->getFile() . ':' . $e->getLine() . "\nStack trace:\n" . $e->getTraceAsString());
    if ((substr($resuUri, 0, 10) === '/ajax/img/' || substr($resuUri, 0, 21) === '/ajax/representative/') && APP_DEBUG !== true) {
        $format = 'default';
        preg_match('/.*\\/format\\/(.*)/', $resuUri, $matches);
        if (isset($matches[1])) {
            $format = $matches[1];
        }
Example #10
0
<?php

require 'system/core/Idiorm.class.php';
require 'system/core/ModeleBase.class.php';
require 'system/core/Condition.class.php';
require 'system/core/GestionnaireSession.class.php';
require 'initialisation.php';
require 'connect.php';
require 'system/core/Slim/Slim.php';
new GestionnaireSession();
\Slim\Slim::registerAutoloader();
\Slim\Route::setDefaultConditions(array('annee' => '(19|20)(\\d){2}', 'id' => '(\\d){1,}', 'page' => '(\\d){1,}'));
$app = new \Slim\Slim(array('debug' => TRUE, 'mode' => 'development', 'templates.path' => Config::DOSSIER_BACK . '/views'));
// require DOSSIER_BACK .'/routes/' . substr($app->request->getResourceUri(), 1) .'.routes.php';
include 'tests.php';
$app->get('/(:annee)', function ($annee = NULL) use($app) {
});
$app->run();
Example #11
0
<?php

require '../vendor/autoload.php';
require 'functions.php';
$loader = new Twig_Loader_Filesystem('../templates');
$twig = new Twig_Environment($loader, array('debug' => true));
$app = new \Slim\Slim();
//Add an application-wide condition to width/height parameters
\Slim\Route::setDefaultConditions(array('width' => '[\\d]*', 'height' => '[\\d]*'));
// Homepage
$app->get('/', function () use($app, $twig) {
    $people = array();
    $dir = new DirectoryIterator('img/');
    foreach ($dir as $fileinfo) {
        if ($fileinfo->isDir() && !$fileinfo->isDot()) {
            array_push($people, $fileinfo->getFilename());
        }
    }
    $currentURL = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    $template = $twig->loadTemplate('views/home.html.twig');
    echo $template->render(array('currenturl' => $currentURL, 'people' => $people));
});
$app->get('/:width/:height', function ($width, $height) use($app) {
    if ($width > 3000 || $height > 3000) {
        echo "Sorry but this size is not available. Max is 3000 x 3000.";
        die;
    }
    serve($width, $height, '');
});
$app->get('/:width', function ($width) use($app) {
    $app->response()->redirect("/{$width}/{$width}", 303);
Example #12
0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once 'vendor/autoload.php';
use models\Crontab;
use models\Crontab\Exception;
use models\SystemUser;
use models\At;
use forms\AddJob;
use services\ExpressionService;
$app = new \Slim\Slim(array('templates.path' => 'application/views', 'debug' => false));
\Slim\Route::setDefaultConditions(array('hash' => '[a-z0-9]{8}'));
// Initialize layout and store it, and use it right away
// as the view for non-XHR requests
$view = new \library\App\Layout();
$view->setTemplatesDirectory($app->config('templates.path'));
$app->config('view', $view);
if (!$app->request->isXhr()) {
    $app->view($view);
}
// Routes
$app->get('/', function () use($app) {
    $crontab = new Crontab();
    $systemUser = new SystemUser();
    $simpleForm = new AddJob\SimpleForm();
    $advancedForm = new AddJob\AdvancedForm();
    $showAlertAtUnavailable = $app->getCookie('showAlertAtUnavailable');
Example #13
0
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
        header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
    }
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
        header("Access-Control-Allow-Headers:  {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
    }
    exit(0);
}
require_once '../vendor/autoload.php';
require_once 'class/autoload.php';
require_once 'amember4/library/Am/Lite.php';
# Initialize the Slim framework
$app = new \Slim\Slim(['view' => new \Slim\Extras\Views\Twig(), 'templates.path' => '../templates', 'log.level' => 4, 'log.enabled' => true, 'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(['path' => '../logs', 'name_format' => 'y-m-d'])]);
# Enforce conditions for route parameters
\Slim\Route::setDefaultConditions(['level' => '\\d+', 'lesson' => '\\d+', 'gender' => '(M|F)', 'width' => '\\d+', 'height' => '\\d+']);
# Implement a hook to redirect users who haven't signed in, or those with an expired membership
$user = \PTA\User::getInstance();
$app->hook('slim.before', function () use($app, $user) {
    $request_path = $app->request()->getPathInfo();
    # Do not allow for exam result submissions to be thwarted by an expired aMember session
    if ($app->request()->isPost() && (preg_match('/\\/\\d+\\/\\d+\\/exam/', $request_path) != 0 || preg_match('/\\/\\d+\\/\\d+\\/result/', $request_path) != 0)) {
        return true;
    }
    if ($user->isLoggedIn() && !$user->isMembershipValid()) {
        # Redirect the user to the signup page unless dealing with an XHR request for user data
        if (!($app->request()->isGet() && substr($request_path, 0, 9) === '/api/user')) {
            $app->redirect('/amember4/signup');
        }
    } else {
        if (!$user->isLoggedIn() && $request_path !== '/login') {
Example #14
0
<?php

\Slim\Route::setDefaultConditions(array('widget' => '(/pag/\\d+)?(/orderby/\\w+/(asc|desc))?(/pag/\\d+)?'));
Example #15
0
 /**
  * Add application-wide route conditions.
  *
  * @see \Slim\Route::setDefaultConditions
  * @return void
  */
 public static function conditions($args)
 {
     return \Slim\Route::setDefaultConditions($args);
 }
Example #16
0
<?php

/************************************************
Filtros globales para parametros

Proyecto: API Rest Full - Codeando.org
Author: Paulo Andrade
Email: source.compug@mail.com
Web: http://www.pauloandrade1.com
************************************************/
// Creamos las condiciones para los parametros
\Slim\Route::setDefaultConditions(array('id' => '[0-9]{0,3}'));
 * "Cross-origion resource sharing" kontrolüne izin verilmesi için eklenmiştir
 * @author Mustafa Zeynel Dağlı
 * @since 2.10.2015
 */
$res = $app->response();
$res->header('Access-Control-Allow-Origin', '*');
$res->header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
//$app->add(new \Slim\Middleware\MiddlewareTest());
$app->add(new \Slim\Middleware\MiddlewareHMAC());
$app->add(new \Slim\Middleware\MiddlewareSecurity());
$app->add(new \Slim\Middleware\MiddlewareBLLManager());
$app->add(new \Slim\Middleware\MiddlewareDalManager());
$app->add(new \Slim\Middleware\MiddlewareServiceManager());
$app->add(new \Slim\Middleware\MiddlewareMQManager());
$pdo = new PDO('pgsql:dbname=ecoman_01_10;host=88.249.18.205;user=postgres;password=1q2w3e4r');
\Slim\Route::setDefaultConditions(array('firstName' => '[a-zA-Z]{3,}', 'page' => '[0-9]{1,}'));
/**
 *  * Okan CIRAN
 * @since 07-01-2016
 */
$app->get("/pkFillComboBoxMainRoles_sysAclRoles/", function () use($app) {
    $BLL = $app->getBLLManager()->get('sysAclRolesBLL');
    //print_r('--****************get parent--' );
    $resCombobox = $BLL->fillComboBoxMainRoles();
    //print_r($resDataMenu);
    $flows = array();
    foreach ($resCombobox as $flow) {
        $flows[] = array("id" => $flow["id"], "text" => $flow["name"], "state" => 'open', "checked" => false, "attributes" => array("notroot" => true, "active" => $flow["active"], "deleted" => $flow["deleted"]));
    }
    //   print_r($flows);
    $app->response()->header("Content-Type", "application/json");
Example #18
0
// https://github.com/zynga/saigon
// Author: Matt West (https://github.com/mhwest13)
// License: BSD 2-Clause
//
/*
 * Saigon API - Index
 */
// Lets load up the composer autoloader
require_once dirname(dirname(__FILE__)) . '/conf/saigon.inc.php';
require_once BASE_PATH . '/vendor/autoload.php';
// Lets load up the saigon autoloader
require_once BASE_PATH . '/lib/classLoader.class.php';
Saigon_ClassLoader::register();
// Lets start up Slim...
$app = new \Slim\Slim();
\Slim\Route::setDefaultConditions(array('deployment' => '[a-zA-Z0-9_-]{1,}', 'staged' => '[1]', 'merged' => '[1]'));
// Internal functions
function check_auth($app, $deployment)
{
    $amodule = AUTH_MODULE;
    $authmodule = new $amodule();
    $return = $authmodule->checkAuth($deployment);
    if ($return === false) {
        $apiResponse = new APIViewData(1, $deployment, "Invalid Login or Invalid Credentials Supplied");
        $app->halt(401, $apiResponse->returnJson());
    }
    return true;
}
function check_revision_status($deployment)
{
    $currRev = RevDeploy::getDeploymentRev($deployment);
Example #19
0
<?php

require 'vendor/autoload.php';
require 'lib/Villiger/View.php';
require 'config.php';
$app = new \Slim\Slim(array('debug' => true, 'templates.path' => './templates', 'view' => new \Villiger\View()));
\Slim\Route::setDefaultConditions(array('language' => '[a-z]{2,2}', 'page' => '[a-z]{3,}'));
$app->get('(/)', function () use($app) {
    $supportedLangs = array('de', 'en');
    $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
    $language = 'en';
    foreach ($languages as $lang) {
        $lang = substr($lang, 0, 2);
        if (in_array($lang, $supportedLangs)) {
            $language = $lang;
            break;
        }
    }
    $app->redirect("/{$language}");
});
$app->get('/:language(/)', function ($language) use($app) {
    $app->render('home.php', array('language' => $language, 'page' => null));
});
$app->get('/:language/:page(/)', function ($language, $page) use($app) {
    $app->render($page . '.php', array('language' => $language, 'page' => $page));
});
$app->run();