public function GET()
 {
     $model = new FlatCMSPluginPageModel();
     $page = $model->getPage(sgContext::getCurrentPath());
     if ($page) {
         $this->content = $page['content'];
     } else {
         return parent::GET();
     }
     return $this->render($page['template']);
 }
 public function GET()
 {
     $paths = explode('/', sgContext::getCurrentPath());
     $this->title = ucwords(str_replace(array('_', '-'), ' ', end($paths)));
     return $this->render(substr(sgContext::getCurrentPath(), 1));
 }
Beispiel #3
0
 public static function stick($routes)
 {
     if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
     } else {
         if (isset($_REQUEST['_method'])) {
             $method = strtoupper($_REQUEST['_method']);
         } else {
             $method = strtoupper($_SERVER['REQUEST_METHOD']);
         }
     }
     if (!in_array($method, self::$allowedMethods)) {
         throw new BadMethodCallException("Method, {$method}, not supported");
         exit;
     }
     $path = sgContext::getCurrentPath();
     $matchedRoute = null;
     if (sgConfiguration::get('settings.cache_routes')) {
         $matchedRoute = self::checkRouteCache($path, $method);
     }
     if (!$matchedRoute) {
         foreach ($routes as $name => $route) {
             $matches = array();
             $regex = str_replace('/', '\\/', $route['path']);
             $regex = '^' . $regex . '\\/?$';
             if (preg_match("/{$regex}/i", $path, $matches)) {
                 $route['name'] = $name;
                 $route['matches'] = $matches;
                 $route['path'] = $path;
                 $matchedRoute = $route;
                 self::$cachedRoutes["{$method} {$path}"] = $matchedRoute;
                 break;
             }
         }
     }
     if (!$matchedRoute) {
         if (sgConfiguration::get('settings.magic_routing')) {
             $matchedRoute = array('path' => $path, 'class' => 'sgMagicController', 'method' => $method, 'matches' => array());
             self::$cachedRoutes["{$method} {$path}"] = $matchedRoute;
         } else {
             $obj = new sgBaseController($matches);
             print $obj->throwErrorCode('404');
         }
     }
     if ($matchedRoute) {
         if (!sgConfiguration::get('settings.magic_routing') && $matchedRoute['class'] == 'sgMagicController') {
             $obj = new sgBaseController($matchedRoute['matches']);
             print $obj->throwErrorCode('404');
         } else {
             self::dispatch($matchedRoute, $method, $matchedRoute['matches']);
         }
     }
     self::shutdown();
     sgAutoloader::shutdown();
 }
 public function render($template = NULL)
 {
     $plugins = sgConfiguration::getInstance()->getPlugins();
     foreach ($plugins as $plugin) {
         if (isset($plugin->configuration)) {
             sgToolkit::executeMethod($plugin->configuration, 'preRender');
         }
     }
     sgToolkit::executeMethod(sgConfiguration::getInstance(), 'preRender');
     sgToolkit::executeMethod($this, 'preRender');
     try {
         if ($template) {
             $this->loadTemplate($template);
         } else {
             if (isset($this->matchedRoute['template'])) {
                 $this->loadTemplate($this->matchedRoute['template']);
             } else {
                 $this->loadTemplate($this->matchedRoute['name']);
             }
         }
     } catch (Exception $e) {
         return $this->throwError($e);
     }
     // update route cache with appropriate template
     if (sgConfiguration::get('settings.cache_routes')) {
         $method = strtoupper($_SERVER['REQUEST_METHOD']);
         $path = sgContext::getCurrentPath();
         sgGlue::$cachedRoutes["{$method} {$path}"]['template'] = str_replace('.html', '', sgView::getInstance()->getView()->getName());
     }
     return sgView::getInstance()->render($this->getTemplateVars());
 }