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>';
                     }
                 }
             }
         }
     }
 }
 private function filterValue($id, $value)
 {
     if (in_array($id, sgConfiguration::get('settings.FlatCMSEditorPlugin.textarea_fields'))) {
         return FlatCMSEditorPluginConfiguration::getPurifier()->purify($value);
     }
     return filter_var($value, FILTER_SANITIZE_STRING);
 }
    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'));
    }
 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;
 }
 public function render($template = NULL)
 {
     if (is_null($template)) {
         $template = '_' . $this->class . '_' . $this->method;
     }
     try {
         $this->loadTemplate($template);
     } catch (Exception $error) {
         if (sgConfiguration::get('settings.debug')) {
             return '<pre>' . $error->getMessage() . "\n" . $error->getTraceAsString() . '</pre>';
         }
         return '';
     }
     return sgView::getInstance()->render($this->getTemplateVars());
 }
Example #6
0
 public function setPaths(array $templatePaths = array(), $overridePaths = FALSE)
 {
     if (!$overridePaths) {
         $this->templatePaths[] = sgConfiguration::getRootDir() . '/views';
         $enabledPlugins = sgConfiguration::get('settings.enabled_plugins', array());
         foreach ($enabledPlugins as $plugin) {
             if (is_dir(sgConfiguration::getRootDir() . "/plugins/{$plugin}/views")) {
                 $this->templatePaths[] = sgConfiguration::getRootDir() . "/plugins/{$plugin}/views";
             }
         }
         $this->templatePaths[] = dirname(__FILE__) . '/views';
     }
     if (isset($this->twig)) {
         $this->twig->getLoader()->setPaths($this->templatePaths);
     }
 }
 public static function registerDoctrine()
 {
     if (self::$doctrineLoaded) {
         return;
     }
     $settings = sgConfiguration::get('settings.DoctrinePlugin');
     Doctrine_Core::setExtensionsPath(self::getPath('extensions'));
     Doctrine_Core::setModelsDirectory(self::getPath('models'));
     $manager = Doctrine_Manager::getInstance();
     $manager->openConnection($settings['dsn'], 'doctrine');
     if (isset($settings['attributes'])) {
         foreach ($settings['attributes'] as $attribute => $value) {
             $manager->setAttribute($attribute, $value);
         }
     }
     self::$doctrineLoaded = true;
 }
 private function pluginOp($pluginName, $op, $actionString)
 {
     $plugins = sgConfiguration::getPlugins();
     if (isset($plugins[$pluginName])) {
         $plugin = $plugins[$pluginName];
         if (isset($plugin->configuration) && is_object($plugin->configuration) && method_exists($plugin->configuration, $op)) {
             $opString = sgCLI::formatText($op, array('options' => array('bright', 'underscore')), sgCLI::STYLE_CONFIRM, false);
             if (sgCLI::confirm("Are you sure you want to {$opString} the plugin \"{$plugin->name}\"?")) {
                 sgCLI::println(ucwords($actionString) . " Plugin \"{$plugin->name}\":", sgCLI::STYLE_HEADER);
                 sgConfiguration::executePluginHook($plugin, $op);
             }
         } else {
             sgClI::println("Nothing to {$op}.", sgCLI::STYLE_INFO);
         }
     } else {
         sgClI::println("{$pluginName} is not an enabled plugin.", sgCLI::STYLE_ERROR);
     }
 }
 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);
    }
 public function executeDoctrineCli($arguments = array(), $options = array())
 {
     try {
         DoctrinePluginConfiguration::init();
     } catch (Exception $e) {
         sgCLI::error($e->getMessage());
         return false;
     }
     // spl_autoload_register(array('Doctrine', 'modelsAutoload'));
     spl_autoload_register(array('Doctrine', 'extensionsAutoload'));
     $settings = sgConfiguration::get('settings.DoctrinePlugin');
     $settings['generate_models_options']['suffix'] = '.class.php';
     $config = array('data_fixtures_path' => DoctrinePluginConfiguration::getPath('fixtures'), 'models_path' => DoctrinePluginConfiguration::getPath('models'), 'migrations_path' => DoctrinePluginConfiguration::getPath('mogrations'), 'sql_path' => DoctrinePluginConfiguration::getPath('sql'), 'yaml_schema_path' => DoctrinePluginConfiguration::getPath('schema'), 'generate_models_options' => $settings['generate_models_options']);
     $cg = new Console_Getopt();
     $params = $cg->readPHPArgv();
     $params[0] .= ' ' . $params[1];
     unset($params[1]);
     $params = array_merge($params);
     $cli = new DoctrinePluginCli($config);
     $cli->run($params);
 }
 public static function shutdown()
 {
     if (sgConfiguration::get('settings.cache_autoload')) {
         $cacheFile = sgConfiguration::get('settings.cache_dir') . '/sgAutoloadCache.cache';
         if (!file_exists($cacheFile)) {
             $data = serialize(self::$_cache);
             file_put_contents($cacheFile, $data);
         }
     }
 }
 public static function loadConfigFromArray($configType, array $config)
 {
     $newConfig = array($configType => $config);
     self::$config = sgToolkit::arrayMergeRecursiveDistinct(self::$config, $newConfig);
 }
Example #14
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()));
Example #15
0
 public static function shutdown()
 {
     if (sgConfiguration::get('settings.cache_routes')) {
         self::saveCachedRoutes();
     }
 }
 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());
 }