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>';
                     }
                 }
             }
         }
     }
 }
Ejemplo 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 uninstall()
 {
     $root = sgContext::getInstance()->getRootDir();
     sgToolkit::rmdir($root . '/config/doctrine');
     sgToolkit::rmdir($root . '/lib/doctrine');
     sgToolkit::rmdir($root . '/models/doctrine');
     sgToolkit::rmdir($root . '/data/doctrine');
 }
    public static function uninstall()
    {
        $message = <<<END
Are you you want to uninstall this plugin? Doing this will remove
all of your cms data in the project_root/data/flatcms directory!
END;
        sgCLI::confirm($message);
        sgToolkit::rmdir(sgConfiguration::get('settings.FlatCMSPlugin.data_dir'));
    }
Ejemplo n.º 5
0
 public static function rmdir($path)
 {
     $path = realpath($path);
     if (!is_dir($path)) {
         return false;
     }
     $files = sgToolkit::getFiles($path);
     $files[] = $path;
     self::remove($files);
 }
 public static function getPagePath($path)
 {
     $filepath = sgConfiguration::get('settings.FlatCMSPlugin.data_dir') . $path;
     if (sgToolkit::checkFileLocation($filepath, $path)) {
         if (file_exists("{$filepath}.yml")) {
             return "{$filepath}.yml";
         }
         return false;
     }
     return false;
 }
Ejemplo n.º 7
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;
 }
 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();
     }
 }
    public static function install()
    {
        sgToolkit::touch(sgConfiguration::get('settings.ZendAuthPlugin.passwd_path'));
        $message = <<<END
    You must place the Zend Framework in your project. ZendAuthPlugin will 
    automatically look in project_root/lib/vendor for the Zend dir, or you 
    can specify the lib dir with the config ZendAuthPlugin => zend_lib_path. 
    This path should be the directory containing the Zend dir, without 
    including the Zend/ dir itself. Also remeber to exclude the Zend path from
    the autoloader by adding this line to your ProjectConfiguration before
    the sgAutoload::register() call is made: 
    
    sgAutoloader::setExclusions(array(realpath('path/to/Zend')));
    
    Finally, you must add users to the /data/ZendAuthPlugin.passwd file in the format:

    username:realm:md5(username:realm:password)

END;
        sgCLI::println($message, sgCLI::STYLE_COMMENT);
    }
Ejemplo n.º 10
0
 private static function _initPlugins($dir, array $plugins)
 {
     foreach ($plugins as $pluginName) {
         $plugin = new StdClass();
         $plugin->name = $pluginName;
         $plugin->path = "{$dir}/plugins/{$pluginName}";
         sgAutoloader::loadPaths(array($plugin->path));
         $class = $plugin->name . "Configuration";
         if (class_exists($class)) {
             $configuration = new $class();
             sgToolkit::executeMethod($configuration, 'preConfig');
             $plugin->configuration = $configuration;
         }
         self::loadConfig('settings', "{$plugin->path}/config/config.php", true);
         self::loadConfig('routing', "{$plugin->path}/config/routing.php", true);
         if (isset($configuration)) {
             sgToolkit::executeMethod($configuration, 'postConfig');
         }
         self::$enabledPlugins[$plugin->name] = $plugin;
     }
 }
Ejemplo n.º 11
0
 public static function dispatch($route, $method, $matches)
 {
     sgContext::setCurrentRoute($route);
     if (isset($route['disabled']) && $route['disabled'] == true) {
         if (sgConfiguration::get('settings.debug')) {
             exit('<pre>Route "' . $route['name'] . '" is disabled.' . "\n</pre>");
         }
         $obj = new sgBaseController($matches);
         sgContext::getInstance()->setController($obj);
         print $obj->throwErrorCode('404');
     } else {
         $plugins = sgConfiguration::getInstance()->getPlugins();
         foreach ($plugins as $plugin) {
             if (isset($plugin->configuration)) {
                 sgToolkit::executeMethod($plugin->configuration, 'preExecute');
             }
         }
         sgToolkit::executeMethod(sgConfiguration::getInstance(), 'preExecute');
         if (isset($route['class'])) {
             if (class_exists($route['class'])) {
                 $obj = new $route['class']($matches);
                 sgContext::getInstance()->setController($obj);
                 if (method_exists($obj, $method)) {
                     sgToolkit::executeMethod($obj, 'preExecute');
                     print $obj->{$method}();
                     sgToolkit::executeMethod($obj, 'postExecute');
                 } else {
                     throw new BadMethodCallException("Method, {$method}, not supported");
                 }
             } else {
                 throw new Exception('Class, ' . $route['class'] . ', not found');
             }
         } else {
             $obj = new sgBaseController($matches);
             sgContext::getInstance()->setController($obj);
             sgToolkit::executeMethod($obj, 'preExecute');
             print $obj->{$method}();
             sgToolkit::executeMethod($obj, 'postExecute');
         }
         sgToolkit::executeMethod(sgConfiguration::getInstance(), 'postExecute');
         foreach ($plugins as $plugin) {
             if (isset($plugin->configuration)) {
                 sgToolkit::executeMethod($plugin->configuration, 'postExecute');
             }
         }
     }
 }
Ejemplo n.º 12
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());
 }