public function preExecute()
 {
     $route = sgContext::getCurrentRoute();
     if (isset($route['is_secure']) && $route['is_secure']) {
         self::redirectIfNotAuth();
     }
 }
Exemplo n.º 2
0
 public function executeCoreFixPerms($arguments, $options)
 {
     $path = realpath(sgContext::getInstance()->getRootDir() . '/cache/');
     chmod($path, 0777);
     $files = sgToolkit::getFiles($path);
     sgToolkit::chmod($files, 0777);
 }
 public static function getPath($pathName)
 {
     if (isset(self::$paths[$pathName])) {
         return sgContext::getInstance()->getRootDir() . self::$paths[$pathName];
     }
     return false;
 }
 public function preRender()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $controller = sgContext::getInstance()->getController();
         if ($controller instanceof FlatCMSPluginController) {
             $session = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace());
             $session->FlatCMSEditorPluginFileMTime = filemtime(FlatCMSPluginPageModel::getPagePath(sgContext::getInstance()->getCurrentPath()));
             //figure out better way to handle this so libraries aren't double loaded
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.min.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.mini.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.autogrow.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/tinymce/jscripts/tiny_mce/jquery.tinymce.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.tinymce.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/init.js');
             $controller->js_settings['FlatCMSEditorPlugin'] = array('saveURL' => sgToolkit::url(sgConfiguration::get('routing.FlatCMSEditorPlugin_save.path')), 'currentPath' => sgContext::getInstance()->getCurrentPath());
             if (isset($controller->content) && is_array($controller->content)) {
                 $textarea_fields = sgConfiguration::get('settings.FlatCMSEditorPlugin.textarea_fields', array());
                 foreach ($controller->content as $key => &$field) {
                     if (in_array($key, $textarea_fields)) {
                         $field = '<div class="editable-area" id="' . $key . '">' . $field . '</div>';
                     } else {
                         $field = '<div class="editable" id="' . $key . '">' . $field . '</div>';
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 public function getTemplateVars()
 {
     $templateVars = get_object_vars($this);
     unset($templateVars['twig']);
     $templateVars['context'] = sgContext::getInstance();
     $templateVars['request'] = array('uri' => $_SERVER['REQUEST_URI'], 'method' => $_SERVER['REQUEST_METHOD'], 'ajax' => sgContext::isAjaxRequest(), 'vars' => array('GET' => $_GET, 'POST' => $_POST));
     return $templateVars;
 }
 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']);
 }
Exemplo n.º 7
0
 private static function _initAutoloader()
 {
     if (!sgAutoloader::checkCache()) {
         $paths = array(sgContext::getLibDir());
         foreach (self::$enabledPlugins as $plugin) {
             $paths[] = sgContext::getRootDir() . '/plugins/' . $plugin->name . '/';
         }
         $paths[] = sgContext::getRootDir() . '/config/';
         $paths[] = sgContext::getRootDir() . '/lib/';
         $paths[] = sgContext::getRootDir() . '/controllers/';
         $paths[] = sgContext::getRootDir() . '/models/';
         sgAutoloader::setExclusions(self::get('settings.autoload_exclusions', array()));
         sgAutoloader::loadPaths($paths);
     }
     Twig_Autoloader::register();
 }
Exemplo n.º 8
0
 public final function execute($namespace, $task, $cliParams = array())
 {
     //special case for init-project
     if ("{$namespace}:{$task}" !== 'core:init-project' && "{$namespace}:{$task}" !== 'core:help') {
         if (!file_exists(sgContext::getInstance()->getRootDir() . '/config/ProjectConfiguration.class.php')) {
             sgCLI::error("Task \"{$namespace}:{$task}\" can only be executed in a project directory.");
             return false;
         }
     }
     if ($params = $this->parseParams($namespace, $task, $cliParams)) {
         $executeMethod = sgToolkit::camelCase("execute {$namespace} {$task}");
         $this->{$executeMethod}($params['arguments'], $params['options']);
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 public static function url($path, $absolute = false)
 {
     $env = sgContext::getEnvironment();
     if (strpos($path, '/') === 0) {
         $path = substr($path, 1);
     }
     if ($absolute) {
         $protocol = 'http';
         if (isset($env['HTTPS'])) {
             $protocol .= 's://';
         } else {
             $protocol .= '://';
         }
         return $protocol . $env['HTTP_HOST'] . sgContext::getRelativeBaseUrl() . '/' . $path;
     }
     return sgContext::getRelativeBaseUrl() . '/' . $path;
 }
 public function POST()
 {
     $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
     $adapter = new Zend_Auth_Adapter_Digest(sgConfiguration::get('settings.ZendAuthPlugin.passwd_path'), '*', $data['username'], $data['password']);
     $result = Zend_Auth::getInstance()->authenticate($adapter);
     if ($result && $result->isValid()) {
         if (isset($data['destination'])) {
             header('Location: ' . sgToolkit::url(filter_var($data['destination'], FILTER_SANITIZE_URL)));
             exit;
         }
         header('Location: ' . sgContext::getRelativeBaseUrl());
         exit;
     } else {
         $this->errors = $result->getMessages();
         if (isset($data['destination'])) {
             $_GET['destination'] = $data['destination'];
         }
         return self::GET();
     }
 }
Exemplo n.º 11
0
<?php

return array('FlatCMSPlugin' => array('data_dir' => sgContext::getInstance()->getRootDir() . '/data/flatcms'));
Exemplo n.º 12
0
<?php

return array('ZendAuthPlugin' => array('zend_lib_path' => sgContext::getInstance()->getRootDir() . '/lib/vendor', 'passwd_path' => sgContext::getInstance()->getRootDir() . '/data/ZendAuthPlugin.passwd'));
Exemplo n.º 13
0
 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());
 }
 function GET()
 {
     Zend_Auth::getInstance()->clearIdentity();
     header('Location: ' . sgContext::getRelativeBaseUrl());
 }
Exemplo n.º 15
0
 public static function setCurrentRoute($route)
 {
     self::$currentRoute = $route;
 }
Exemplo n.º 16
0
<?php

return array('magic_routing' => true, 'debug' => false, 'cache_templates' => false, 'cache_routes' => false, 'cache_autoload' => false, 'cache_dir' => sgConfiguration::getRootDir() . '/cache', 'autoload_exclusions' => array('Twig', '.svn', 'CVS', '.git', dirname(__FILE__) . '/../skeleton', dirname(__FILE__) . '/../config'), 'enabled_plugins' => array('Components'), 'js_settings' => array('base' => sgContext::getRelativeBaseUrl()));
Exemplo n.º 17
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();
 }
Exemplo n.º 18
0
 public function GET()
 {
     $paths = explode('/', sgContext::getCurrentPath());
     $this->title = ucwords(str_replace(array('_', '-'), ' ', end($paths)));
     return $this->render(substr(sgContext::getCurrentPath(), 1));
 }