Author: Jonathan.Wage
Date: 2010-01-19 19:30:07 +0100 (Tue, 19 Jan 2010)
New Revision: 26894

Added:
   plugins/sfSympalPlugin/trunk/lib/sfSympalActions.class.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalConfig.class.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalContext.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalPluginEnabler.class.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalSitemapGenerator.class.php
Removed:
   plugins/sfSympalPlugin/trunk/lib/core/
Log:
[1.4][sfSympalPlugin][1.0] Removing core directory and moving classes to lib 
root


Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalActions.class.php (from rev 
26892, plugins/sfSympalPlugin/trunk/lib/core/sfSympalActions.class.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalActions.class.php                  
        (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalActions.class.php  2010-01-19 
18:30:07 UTC (rev 26894)
@@ -0,0 +1,207 @@
+<?php
+
+class sfSympalActions extends sfSympalExtendClass
+{
+  public function resetSympalRoutesCache()
+  {
+    // Reset the routes cache incase of the url changing or a custom url was 
added
+    return 
$this->getContext()->getConfiguration()->getPluginConfiguration('sfSympalPlugin')
+      ->getSympalConfiguration()->getCache()->resetRouteCache();
+  }
+
+  public function clearCache(array $options = array())
+  {
+    chdir(sfConfig::get('sf_root_dir'));
+    $task = new sfCacheClearTask($this->getContext()->getEventDispatcher(), 
new sfFormatter());
+    $task->run(array(), $options);
+
+    $this->resetSympalRoutesCache();
+  }
+
+  public function isAjax()
+  {
+    $request = $this->getRequest();
+    return $request->isXmlHttpRequest() || $request->getParameter('is_ajax');
+  }
+
+  public function getSympalContext()
+  {
+    return sfSympalContext::getInstance();
+  }
+
+  public function checkFilePermissions($items = null)
+  {
+    if ($items === null)
+    {
+      $items = array();
+
+      if (file_exists(sfConfig::get('sf_upload_dir')))
+      {
+        $items[] = sfConfig::get('sf_upload_dir');
+      }
+      $items[] = sfConfig::get('sf_cache_dir');
+      $items[] = sfConfig::get('sf_web_dir').'/cache';
+      $items[] = sfConfig::get('sf_config_dir');
+      $items[] = sfConfig::get('sf_data_dir').'/sql';
+      $items[] = sfConfig::get('sf_log_dir');
+      $items[] = sfConfig::get('sf_lib_dir');
+      $items[] = sfConfig::get('sf_plugins_dir');
+      $items[] = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'symfony';
+    } else {
+      $items = (array) $items;
+    }
+
+    $dirs = sfFinder::type('dir')->in($items);
+    $files = sfFinder::type('file')->in($items);
+    $checks = array_merge($dirs, $files);
+
+    $error = false;
+    foreach ($checks as $check)
+    {
+      if (!is_writable($check))
+      {
+        $error = true;
+        break;
+      }
+    }
+
+    if ($error)
+    {
+      $this->getUser()->setFlash('error', 'Sympal requires that some files and 
folders are writeable in your project. The file "'.$check.'" specifically is 
not writeable. Run the sympal:fix-perms task to fix or manually adjust the 
permissions.');
+    }
+
+    if ($error)
+    {
+      return false;
+    } else {
+      return true;
+    }
+  }
+
+  public function getSympalContentActionLoader()
+  {
+    return 
$this->getSympalContext()->getSympalContentActionLoader($this->getSubject());
+  }
+
+  public function loadTheme($name)
+  {
+    return $this->getSympalContext()->loadTheme($name);
+  }
+
+  public function loadThemeOrDefault($name)
+  {
+    if ($name)
+    {
+      return $this->getSympalContext()->loadTheme($name);
+    } else {
+      return 
$this->getSympalContext()->loadTheme(sfSympalConfig::get('default_theme'));
+    }
+  }
+
+  public function loadDefaultTheme()
+  {
+    $this->loadTheme(sfSympalConfig::get('default_theme'));
+  }
+
+  public function loadAdminTheme()
+  {
+    $this->loadTheme(sfSympalConfig::get('admin_theme', null, 'admin'));
+  }
+
+  public function loadSiteTheme()
+  {
+    
$this->loadThemeOrDefault($this->getSympalContext()->getSite()->getTheme());
+  }
+
+  public function askConfirmation($title, $message, $variables = array())
+  {
+    $e = explode('/', $message);
+    if (count($e) == 2)
+    {
+      try {
+        $message = sfSympalToolkit::getSymfonyResource($e[0], $e[1], 
$variables);
+      } catch (Exception $e) {
+        throw new sfException('Invalid confirmation message: 
'.$e->getMessage());
+      }
+    }
+
+    $request = $this->getRequest();
+
+    if ($request->hasParameter('sympal_ask_confirmation') && 
$request->getParameter('sympal_ask_confirmation'))
+    {
+      if ($request->getParameter('yes'))
+      {
+        return true;
+      } else {
+        if ($this->isAjax())
+        {
+          $url = $request->getParameter('redirect_url');
+          $this->redirect($url.(strpos($url, '?') !== false ? '&' : 
'?').'ajax=1');          
+        } else {
+          $this->redirect($request->getParameter('redirect_url'));
+        }
+      }
+    } else {
+      $this->getResponse()->setTitle($title);
+      $request->setAttribute('title', $title);
+      $request->setAttribute('message', $message);
+      $request->setAttribute('is_ajax', $this->isAjax());
+
+      $this->forward('sympal_default', 'ask_confirmation');
+    }
+  }
+
+  public function forwardToRoute($route, $params = array())
+  {
+    $full = $route;
+    if (strstr($route, '?'))
+    {
+      $pos = strpos($route, '?');
+      $route = substr($route, 1, $pos - 1);
+    } else {
+      $route = substr($route, 1, strlen($route));
+    }
+
+    $r = $this->getContext()->getRouting();
+    $routes = $r->getRoutes();
+    if ( ! isset($routes[$route]))
+    {
+      throw new sfException('Could not find route named: "' . $route . '"');
+    }
+
+    if (isset($pos))
+    {
+      $p = substr($full, $pos + 1, strlen($full));
+      $e = explode('&', $p);
+
+      foreach ($e as $k => $v)
+      {
+        $e2 = explode('=', $v);
+        if ((isset($e2[0]) && $e2[0]) && (isset($e2[1]) && $e2[1]))
+        {
+          $params[$e2[0]] = $e2[1];
+        }
+      }
+    }
+
+    $routeInfo = $routes[$route];
+    $params = array_merge($routeInfo->getDefaults(), $params);
+
+    foreach ($params as $key => $value)
+    {
+      $this->getRequest()->setParameter($key, $value);
+    }
+
+    $this->forward($params['module'], $params['action']);
+  }
+
+  public function goBack()
+  {
+    $this->redirect($this->getRequest()->getReferer());
+  }
+
+  public function refresh()
+  {
+    $this->redirect($this->getRequest()->getUri());
+  }
+}
\ No newline at end of file

Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalConfig.class.php (from rev 
26892, plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfig.class.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalConfig.class.php                   
        (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalConfig.class.php   2010-01-19 
18:30:07 UTC (rev 26894)
@@ -0,0 +1,95 @@
+<?php
+
+class sfSympalConfig extends sfConfig
+{
+  public static function get($group, $name = null, $default = null)
+  {
+    $default = $default === null ? false : $default;
+    if ($name === null)
+    {
+      return isset(self::$config['app_sympal_config_'.$group]) ? 
self::$config['app_sympal_config_'.$group] : $default;
+    } else {
+      return isset(self::$config['app_sympal_config_'.$group][$name]) ? 
self::$config['app_sympal_config_'.$group][$name] : $default;
+    }
+  }
+
+  public static function set($group, $name, $value = null)
+  {
+    if (is_null($value))
+    {
+      return self::$config['app_sympal_config_'.$group] = $name;
+    } else {
+      return self::$config['app_sympal_config_'.$group][$name] = $value;
+    }
+  }
+
+  public static function isI18nEnabled($name = null)
+  {
+    if ($name)
+    {
+      if (is_object($name))
+      {
+        $name = get_class($name);
+      }
+      return isset(self::$config['app_sympal_config_i18n']) && 
self::$config['app_sympal_config_i18n'] && 
isset(self::$config['app_sympal_config_internationalized_models'][$name]);
+    } else {
+      return isset(self::$config['app_sympal_config_i18n']) && 
self::$config['app_sympal_config_i18n'];
+    }
+  }
+
+  public static function getCurrentVersion()
+  {
+    return 
isset(self::$config['app_sympal_config_asset_paths']['current_version']) ? 
self::$config['app_sympal_config_asset_paths']['current_version'] : 
sfSympalPluginConfiguration::VERSION;
+  }
+
+  public static function getAssetPath($path)
+  {
+    return isset(self::$config['app_sympal_config_asset_paths'][$path]) ? 
self::$config['app_sympal_config_asset_paths'][$path] : $path;
+  }
+
+  public static function getAdminGeneratorTheme()
+  {
+    $theme = sfSympalConfig::get('themes', sfSympalConfig::get('admin_theme'));
+    return isset($theme['admin_generator_theme']) ? 
$theme['admin_generator_theme'] : 
sfSympalConfig::get('default_admin_generator_theme', null, 'sympal_admin');
+  }
+
+  public static function getAdminGeneratorClass()
+  {
+    $theme = sfSympalConfig::get('themes', sfSympalConfig::get('admin_theme'));
+    return isset($theme['admin_generator_class']) ? 
$theme['admin_generator_class'] : 
sfSympalConfig::get('default_admin_generator_class', null, 
'sfSympalDoctrineGenerator');
+  }
+
+  public static function writeSetting($group, $name, $value = null, 
$application = false)
+  {
+    if (is_null($value))
+    {
+      $value = $name;
+      $name = $group;
+      $group = null;
+    }
+
+    if ($application)
+    {
+      $path = sfConfig::get('sf_app_dir').'/config/app.yml';
+    } else {
+      $path = sfConfig::get('sf_config_dir').'/app.yml';
+    }
+
+    if (!file_exists($path))
+    {
+      touch($path);
+    }
+    $array = (array) sfYaml::load(file_get_contents($path));
+
+    if (is_null($group))
+    {
+      $array['all']['sympal_config'][$name] = $value;
+    } else {
+      $array['all']['sympal_config'][$group][$name] = $value;
+    }
+
+    self::set($group, $name, $value);
+
+    file_put_contents($path, sfYaml::dump($array, 4));
+  }
+}
\ No newline at end of file

Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php (from 
rev 26892, 
plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php            
                (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php    
2010-01-19 18:30:07 UTC (rev 26894)
@@ -0,0 +1,411 @@
+<?php
+
+class sfSympalConfiguration
+{
+  protected
+    $_dispatcher,
+    $_projectConfiguration,
+    $_sympalContext,
+    $_symfonyContext,
+    $_doctrineManager,
+    $_bootstrap,
+    $_plugins = array(),
+    $_modules = array(),
+    $_layouts = array();
+
+  public function __construct(sfEventDispatcher $dispatcher, 
ProjectConfiguration $projectConfiguration)
+  {
+    // We disable Symfony autoload again feature because it is too slow in dev 
mode
+    // If you introduce a new class when using sympal you just must clear your
+    // cache manually
+    sfAutoloadAgain::getInstance()->unregister();
+
+    $this->_dispatcher = $dispatcher;
+    $this->_projectConfiguration = $projectConfiguration;
+    $this->_doctrineManager = Doctrine_Manager::getInstance();
+
+    $this->_initializeSymfonyConfig();
+
+    sfOutputEscaper::markClassesAsSafe(array(
+      'sfSympalContent',
+      'sfSympalContentTranslation',
+      'sfSympalContentSlot',
+      'sfSympalContentSlotTranslation',
+      'sfSympalMenuItem',
+      'sfSympalMenuItemTranslation',
+      'sfSympalContentRenderer',
+      'sfSympalMenu',
+      'sfParameterHolder',
+      'sfSympalDataGrid',
+      'sfSympalUpgradeFromWeb',
+      'sfSympalServerCheckHtmlRenderer',
+      'sfSympalSitemapGenerator'
+    ));
+
+    $this->_dispatcher->connect('context.load_factories', array($this, 
'bootstrap'));
+    $this->_dispatcher->connect('component.method_not_found', array(new 
sfSympalActions(), 'extend'));
+    $this->_dispatcher->connect('controller.change_action', array($this, 
'initializeTheme'));
+    $this->_dispatcher->connect('template.filter_parameters', array($this, 
'filterTemplateParameters'));
+    $this->_dispatcher->connect('form.method_not_found', array(new 
sfSympalForm(), 'extend'));
+    $this->_dispatcher->connect('form.post_configure', array('sfSympalForm', 
'listenToFormPostConfigure'));
+    $this->_dispatcher->connect('form.filter_values', array('sfSympalForm', 
'listenToFormFilterValues'));
+    $this->_dispatcher->connect('routing.load_configuration', array($this, 
'listenToRoutingLoadConfiguration'));
+    $this->_dispatcher->connect('routing.load_configuration', array($this, 
'listenToRoutingLoadConfiguration'));
+
+    if (sfSympalConfig::get('page_cache', 'super') && 
sfConfig::get('sf_cache'))
+    {
+      $superCache = new sfSympalSuperCache($this);
+      $this->_dispatcher->connect('response.filter_content', 
array($superCache, 'listenToResponseFilterContent'));
+    }
+
+    $this->_dispatcher->connect('task.cache.clear', array($this, 
'listenToTaskCacheClear'));
+
+    
$this->_doctrineManager->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, 
false);
+    $this->_doctrineManager->setAttribute(Doctrine_Core::ATTR_TABLE_CLASS, 
'sfSympalDoctrineTable');
+    $this->_doctrineManager->setAttribute(Doctrine_Core::ATTR_QUERY_CLASS, 
'sfSympalDoctrineQuery');
+    
$this->_doctrineManager->setAttribute(Doctrine_Core::ATTR_COLLECTION_CLASS, 
'sfSympalDoctrineCollection');
+  }
+
+  public function listenToTaskCacheClear(sfEvent $event)
+  {
+    $event->getSubject()->logSection('sympal', 'Clearing web cache folder');
+
+    $cacheDir = sfConfig::get('sf_web_dir').'/cache';
+    if (is_dir($cacheDir))
+    {
+      
$event->getSubject()->getFilesystem()->remove(sfFinder::type('file')->ignore_version_control()->discard('.sf')->in($cacheDir));
+    }
+  }
+
+  public function listenToRoutingLoadConfiguration(sfEvent $event)
+  {
+    // Append route at end to catch all
+    $event->getSubject()->appendRoute('sympal_default', new sfRoute('/*', 
array(
+      'module' => 'sympal_default',
+      'action' => 'default'
+    )));
+  }
+
+  /**
+   * Callable attached to Symfony event context.load_factories. When this event
+   * is triggered we also create the Sympal context.
+   */
+  public function bootstrap(sfEvent $event)
+  {
+    $this->_projectConfiguration = $event->getSubject()->getConfiguration();
+
+    $record = 
Doctrine_Core::getTable(sfSympalConfig::get('user_model'))->getRecordInstance();
+    $this->_dispatcher->notify(new sfEvent($record, 
'sympal.user.set_table_definition', array('object' => $record)));
+
+    $this->_cache = new sfSympalCache($this);
+
+    $this->_symfonyContext = $event->getSubject();
+    $this->_sympalContext = 
sfSympalContext::createInstance($this->_symfonyContext, $this);
+
+    $this->_enableModules();
+
+    $this->_checkSympalInstall();
+
+    $this->initializeTheme();
+
+    $this->_projectConfiguration->loadHelpers(array(
+      'Sympal', 'SympalContentSlot', 'SympalMenu', 'SympalPager', 'I18N', 
'Asset'
+    ));
+  }
+
+  public function filterTemplateParameters(sfEvent $event, $parameters)
+  {
+    $parameters['sf_sympal_context'] = $this->_sympalContext;
+    if ($content = $this->_sympalContext->getCurrentContent())
+    {
+      $parameters['sf_sympal_content'] = $content;
+    }
+    if ($menuItem = $this->_sympalContext->getCurrentMenuItem())
+    {
+      $parameters['sf_sympal_menu_item'] = $menuItem;
+    }
+    return $parameters;
+  }
+
+  public function getDoctrineManager()
+  {
+    return $this->_doctrineManager;
+  }
+
+  public function getCache()
+  {
+    return $this->_cache;
+  }
+
+  public function getSympalContext()
+  {
+    return $this->_sympalContext;
+  }
+
+  public function getContentTypes()
+  {
+    return $this->_cache->getContentTypes();
+  }
+
+  public function getProjectConfiguration()
+  {
+    return $this->_projectConfiguration;
+  }
+
+  public function getRequiredPlugins()
+  {
+    $requiredPlugins = array();
+    foreach ($this->_projectConfiguration->getPlugins() as $pluginName)
+    {
+      if (strpos($pluginName, 'sfSympal') !== false)
+      {
+        $dependencies = 
sfSympalPluginToolkit::getPluginDependencies($pluginName);
+        $requiredPlugins = array_merge($requiredPlugins, $dependencies);
+      }
+    }
+
+    return array_values(array_unique($requiredPlugins));
+  }
+
+  public function getCorePlugins()
+  {
+    return sfSympalPluginConfiguration::$dependencies;
+  }
+
+  public function getContentTypePlugins()
+  {
+    $contentTypePlugins = array();
+    $plugins = $this->getPluginPaths();
+
+    foreach ($plugins as $plugin => $path)
+    {
+      $manager = new sfSympalPluginManager($plugin, 
$this->_projectConfiguration, new sfFormatter());
+      if ($contentType = $manager->getContentTypeForPlugin())
+      {
+        $contentTypePlugins[$plugin] = $plugin;
+      }
+    }
+    return $contentTypePlugins;
+  }
+
+  public function getInstalledPlugins()
+  {
+    return $this->getOtherPlugins();
+  }
+
+  public function getAddonPlugins()
+  {
+    return sfSympalPluginToolkit::getAvailablePlugins();
+  }
+
+  public function getOtherPlugins()
+  {
+    return array_diff($this->getPlugins(), $this->getRequiredPlugins());
+  }
+
+  public function getAllManageablePlugins()
+  {
+    $plugins = array_merge($this->getAddonPlugins(), 
$this->getInstalledPlugins());
+    $plugins = array_unique($plugins);
+
+    return $plugins;
+  }
+
+  public function getPlugins()
+  {
+    return array_keys($this->getPluginPaths());
+  }
+
+  public function getPluginPaths()
+  {
+    if (!$this->_plugins)
+    {
+      $configuration = ProjectConfiguration::getActive();
+      $pluginPaths = $configuration->getAllPluginPaths();
+      $this->_plugins = array();
+      foreach ($pluginPaths as $pluginName => $path)
+      {
+        if (strpos($pluginName, 'sfSympal') !== false)
+        {
+          $this->_plugins[$pluginName] = $path;
+        }
+      }
+    }
+
+    return $this->_plugins;
+  }
+
+  public function getModules()
+  {
+    return $this->getCache()->getModules();
+  }
+
+  public function getLayouts()
+  {
+    return $this->getCache()->getLayouts();
+  }
+
+  public function getThemes()
+  {
+    return sfSympalConfig::get('themes', null, array());
+  }
+
+  public function getContentTemplates($model)
+  {
+    return sfSympalConfig::get($model, 'content_templates', array());
+  }
+
+  public function isAdminModule()
+  {
+    $module = $this->_symfonyContext->getRequest()->getParameter('module');
+    $adminModules = sfSympalConfig::get('admin_modules');
+    return array_key_exists($module, $adminModules);
+  }
+
+  public function getThemeForRequest()
+  {
+    $request = $this->_symfonyContext->getRequest();
+    $module = $request->getParameter('module');
+
+    if ($this->isAdminModule())
+    {
+      return sfSympalConfig::get('admin_theme', null, 'admin');
+    }
+
+    if (sfSympalConfig::get('allow_changing_theme_by_url'))
+    {
+      $user = $this->_symfonyContext->getUser();
+
+      if ($theme = 
$request->getParameter(sfSympalConfig::get('theme_request_parameter_name', 
null, 'sf_sympal_theme')))
+      {
+        $user->setCurrentTheme($theme);
+        return $theme;
+      }
+
+      if ($theme = $user->getCurrentTheme())
+      {
+        return $theme;
+      }
+    }
+
+    if ($theme = sfSympalConfig::get($module, 'theme'))
+    {
+      return $theme;
+    }
+
+    if ($theme = $theme = 
sfSympalConfig::get(sfContext::getInstance()->getRouting()->getCurrentRouteName(),
 'theme'))
+    {
+      return $theme;
+    }
+
+    return sfSympalConfig::get('default_theme');
+  }
+
+  public function initializeTheme()
+  {
+    if (!$this->_symfonyContext->getRequest()->isXmlHttpRequest())
+    {
+      $this->_sympalContext->loadTheme($this->getThemeForRequest());
+    }
+  }
+
+  public function checkPluginDependencies()
+  {
+    foreach ($this->_projectConfiguration->getPlugins() as $pluginName)
+    {
+      if (strpos($pluginName, 'sfSympal') !== false)
+      {
+        $dependencies = 
sfSympalPluginToolkit::getPluginDependencies($pluginName);
+        sfSympalPluginToolkit::checkPluginDependencies($pluginName, 
$dependencies);
+      }
+    }
+  }
+
+  private function _enableModules()
+  {
+    if (sfSympalConfig::get('enable_all_modules', null, true))
+    {
+      $modules = sfConfig::get('sf_enabled_modules', array());
+      if (sfSympalConfig::get('enable_all_modules'))
+      {
+        $modules = array_merge($modules, $this->getModules());
+      } else {
+        $modules = array_merge($modules, 
sfSympalConfig::get('enabled_modules', null, array()));
+      }
+      sfConfig::set('sf_enabled_modules', $modules);
+    }
+  }
+
+  private function _checkSympalInstall()
+  {
+    $sfContext = sfContext::getInstance();
+    $request = $sfContext->getRequest();
+
+    // Prepare the symfony application is it has not been prepared yet
+    if (!$sfContext->getUser() instanceof sfSympalUser)
+    {
+      chdir(sfConfig::get('sf_root_dir'));
+      $task = new sfSympalEnableForAppTask($this->_dispatcher, new 
sfFormatter());
+      $task->run(array($this->_projectConfiguration->getApplication()), 
array());
+
+      $sfContext->getController()->redirect('@homepage');
+    }
+
+    // Redirect to install module if...
+    //  not in test environment
+    //  sympal has not been installed
+    //  module is not already sympal_install
+    if (sfConfig::get('sf_environment') != 'test' && 
!sfSympalConfig::get('installed') && $request->getParameter('module') != 
'sympal_install')
+    {
+      $sfContext->getController()->redirect('@sympal_install');
+    }
+
+    // Redirect to homepage if no site record exists so we can prompt the user 
to create
+    // a site record for this application
+    // This check is only ran in dev mode
+    if (sfConfig::get('sf_environment') == 'dev' && 
!$this->_sympalContext->getSite() && $sfContext->getRequest()->getPathInfo() != 
'/')
+    {
+      $sfContext->getController()->redirect('@homepage');
+    }
+  }
+
+  private function _initializeSymfonyConfig()
+  {
+    sfConfig::set('sf_cache', sfSympalConfig::get('page_cache', 'enabled', 
false));
+    sfConfig::set('sf_admin_module_web_dir', 
sfSympalConfig::get('admin_module_web_dir', null, '/sfSympalAdminPlugin'));
+
+    sfConfig::set('app_sf_guard_plugin_success_signin_url', 
sfSympalConfig::get('success_signin_url'));
+
+    if (sfConfig::get('sf_login_module') == 'default')
+    {
+      sfConfig::set('sf_login_module', 'sympal_auth');
+      sfConfig::set('sf_login_action', 'signin');
+    }
+
+    if (sfConfig::get('sf_secure_module') == 'default')
+    {
+      sfConfig::set('sf_secure_module', 'sympal_auth');
+      sfConfig::set('sf_secure_action', 'secure');
+    }
+
+    if (sfConfig::get('sf_error_404_module') == 'default')
+    {
+      sfConfig::set('sf_error_404_module', 'sympal_default');
+      sfConfig::set('sf_error_404_action', 'error404');
+    }
+
+    if (sfConfig::get('sf_module_disabled_module') == 'default')
+    {
+      sfConfig::set('sf_module_disabled_module', 'sympal_default');
+      sfConfig::set('sf_module_disabled_action', 'disabled');
+    }
+
+    sfConfig::set('sf_jquery_path', sfSympalConfig::get('jquery_reloaded', 
'path'));
+    sfConfig::set('sf_jquery_plugin_paths', 
sfSympalConfig::get('jquery_reloaded', 'plugin_paths'));
+  }
+
+  public static function getActive()
+  {
+    return 
sfApplicationConfiguration::getActive()->getPluginConfiguration('sfSympalPlugin')->getSympalConfiguration();
+  }
+}
\ No newline at end of file

Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalContext.php (from rev 26892, 
plugins/sfSympalPlugin/trunk/lib/core/sfSympalContext.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalContext.php                        
        (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalContext.php        2010-01-19 
18:30:07 UTC (rev 26894)
@@ -0,0 +1,191 @@
+<?php
+
+class sfSympalContext
+{
+  protected static
+    $_instances = array(),
+    $_current;
+
+  protected
+    $_site,
+    $_siteSlug,
+    $_sympalConfiguration,
+    $_symfonyContext,
+    $_currentMenuItem,
+    $_currentContent,
+    $_currentSite,
+    $_previousTheme,
+    $_theme,
+    $_themeObjects = array();
+
+  public function __construct(sfSympalConfiguration $sympalConfiguration, 
sfContext $symfonyContext)
+  {
+    $this->_siteSlug = $symfonyContext->getConfiguration()->getApplication();
+    $this->_sympalConfiguration = $sympalConfiguration;
+    $this->_symfonyContext = $symfonyContext;
+  }
+
+  public function getCurrentMenuItem()
+  {
+    return $this->_currentMenuItem;
+  }
+
+  public function setCurrentMenuItem(sfSympalMenuItem $menuItem)
+  {
+    $this->_currentMenuItem = $menuItem;
+  }
+
+  public function getCurrentContent()
+  {
+    return $this->_currentContent;
+  }
+
+  public function setCurrentContent(sfSympalContent $content)
+  {
+    $this->_currentContent = $content;
+    if (!$this->_site)
+    {
+      $this->_site = $content->getSite();
+    }
+    if ($menuItem = $content->getMenuItem())
+    {
+      $this->_currentMenuItem = $menuItem;
+    }
+  }
+
+  public function setSite(sfSympalSite $site)
+  {
+    $this->_site = $site;
+  }
+
+  public function getSite()
+  {
+    if (!$this->_site)
+    {
+      $this->_site =  Doctrine_Core::getTable('sfSympalSite')
+        ->createQuery('s')
+        ->where('s.slug = ?', $this->_siteSlug)
+        ->fetchOne();
+    }
+    return $this->_site;
+  }
+
+  public function shouldLoadFrontendEditor()
+  {
+    return 
$this->_symfonyContext->getConfiguration()->getPluginConfiguration('sfSympalEditorPlugin')->shouldLoadEditor();
+  }
+
+  public function getSiteSlug()
+  {
+    return $this->_siteSlug;
+  }
+
+  public function getTheme()
+  {
+    return $this->_theme;
+  }
+
+  public function getThemeObject($name = null)
+  {
+    $theme = $name ? $name : $this->_theme;
+    if (!isset($this->_themeObjects[$theme]))
+    {
+      $configurationArray = sfSympalConfig::get('themes', $theme);
+      $configurationArray['name'] = $theme;
+
+      $configurationClass = isset($configurationArray['config_class']) ? 
$configurationArray['class'] : 'sfSympalThemeConfiguration';
+      $themeClass = isset($configurationArray['theme_class']) ? 
$configurationArray['theme_class'] : 'sfSympalTheme';
+      $configuration = new $configurationClass($configurationArray);
+      $this->_themeObjects[$theme] = new $themeClass($this, $configuration);
+    }
+    return isset($this->_themeObjects[$theme]) ? $this->_themeObjects[$theme] 
: false;
+  }
+
+  public function getThemeObjects()
+  {
+    return $this->_themeObjects;
+  }
+
+  public function isAdminModule()
+  {
+    return $this->_sympalConfiguration->isAdminModule();
+  }
+
+  public function getPreviousTheme()
+  {
+    return $this->getThemeObject($this->_previousTheme);
+  }
+
+  public function unloadPreviousTheme()
+  {
+    if ($previousTheme = $this->getPreviousTheme())
+    {
+      $previousTheme->unload();
+    }
+  }
+
+  public function setTheme($theme)
+  {
+    $this->_theme = $theme;
+  }
+
+  public function loadTheme($name = null)
+  {
+    $this->_previousTheme = $this->_theme;
+    $theme = $name ? $name : $this->_theme;
+    $this->setTheme($theme);
+    if ($theme = $this->getThemeObject($theme))
+    {
+      return $theme->load();
+    }
+  }
+
+  public function getSympalConfiguration()
+  {
+    return $this->_sympalConfiguration;
+  }
+
+  public function getSymfonyContext()
+  {
+    return $this->_symfonyContext;
+  }
+
+  public function getContentRenderer(sfSympalContent $content, $format = 
'html')
+  {
+    return new sfSympalContentRenderer($this, $content, $format);
+  }
+
+  public function getSympalContentActionLoader(sfActions $actions)
+  {
+    return new sfSympalContentActionLoader($actions);
+  }
+
+  public static function getInstance($site = null)
+  {
+    if (is_null($site))
+    {
+      if (!self::$_current)
+      {
+        throw new InvalidArgumentException('Could not find a current sympal 
context instance');
+      }
+      return self::$_current;
+    }
+
+    if (!isset(self::$_instances[$site]))
+    {
+      throw new sfException($site.' instance does not exist.');
+    }
+    return self::$_instances[$site];
+  }
+
+  public static function createInstance(sfContext $symfonyContext, 
sfSympalConfiguration $sympalConfiguration)
+  {
+    $site = $symfonyContext->getConfiguration()->getApplication();
+
+    $instance = new self($sympalConfiguration, $symfonyContext);
+    self::$_instances[$site] = $instance;
+    self::$_current = $instance;
+
+    return self::$_instances[$site];
+  }
+}
\ No newline at end of file

Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalPluginEnabler.class.php (from 
rev 26892, 
plugins/sfSympalPlugin/trunk/lib/core/sfSympalPluginEnabler.class.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalPluginEnabler.class.php            
                (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalPluginEnabler.class.php    
2010-01-19 18:30:07 UTC (rev 26894)
@@ -0,0 +1,98 @@
+<?php
+
+class sfSympalPluginEnabler
+{
+  private
+    $_configuration,
+    $_isSympalEnabled = null,
+    $_sympalPluginPath = null;
+
+  public function __construct(ProjectConfiguration $configuration)
+  {
+    $this->_configuration = $configuration;
+    $this->_sympalPluginPath = realpath(dirname(__FILE__).'/../..');
+  }
+
+  public function isSympalEnabled()
+  {
+    if ($this->_isSympalEnabled === null)
+    {
+      $this->_isSympalEnabled = true;
+      if ($application = sfConfig::get('sf_app'))
+      {
+        $reflection = new ReflectionClass($application.'Configuration');
+        if ($reflection->getConstant('disableSympal'))
+        {
+          $this->_isSympalEnabled = false;
+        }
+      }
+    }
+    return $this->_isSympalEnabled;
+  }
+
+  public function enableSympalPlugins()
+  {
+    if (!$this->isSympalEnabled())
+    {
+      return false;
+    }
+
+    $this->_configuration->enablePlugins('sfDoctrinePlugin');
+    $this->_configuration->enablePlugins('sfSympalPlugin');
+    $this->_configuration->setPluginPath('sfSympalPlugin', 
$this->_sympalPluginPath);
+
+    $this->enableSympalCorePlugins(sfSympalPluginConfiguration::$dependencies);
+  }
+
+  public function enableFrontendPlugins()
+  {
+    if (!$this->isSympalEnabled())
+    {
+      return false;
+    }
+
+    $this->_configuration->enablePlugins('sfDoctrinePlugin');
+    $this->_configuration->enablePlugins('sfSympalPlugin');
+    $this->_configuration->setPluginPath('sfSympalPlugin', 
$this->_sympalPluginPath);
+
+    $this->enableSympalCorePlugins(array(
+      'sfDoctrineGuardPlugin',
+      'sfFeed2Plugin',
+      'sfWebBrowserPlugin',
+      'sfSympalMenuPlugin',
+      'sfSympalPagesPlugin',
+      'sfSympalContentListPlugin',
+      'sfSympalDataGridPlugin',
+      'sfSympalUserPlugin',
+      'sfSympalRenderingPlugin',
+    ));
+  }
+
+  public function enableSympalCorePlugins($plugins)
+  {
+    foreach ((array) $plugins as $plugin)
+    {
+      $this->_configuration->enablePlugins($plugin);
+      $this->_configuration->setPluginPath($plugin, 
$this->_sympalPluginPath.'/lib/plugins/'.$plugin);
+    }
+  }
+
+  public function disableSympalCorePlugins($plugins)
+  {
+    foreach ((array) $plugins as $plugin)
+    {
+      $this->_configuration->disablePlugins($plugin);
+      $this->_configuration->setPluginPath($plugin, false);
+    }
+  }
+
+  public function overrideSympalPlugin($plugin, $newPlugin, $newPluginPath = 
null)
+  {
+    $this->_configuration->disablePlugins($plugin);
+    $this->_configuration->enablePlugins($newPlugin);
+    if ($newPluginPath)
+    {
+      $this->_configuration->setPluginPath($newPlugin, $newPluginPath);
+    }
+  }
+}
\ No newline at end of file

Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php (from rev 
26892, plugins/sfSympalPlugin/trunk/lib/core/sfSympalRedirecter.class.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php               
                (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php       
2010-01-19 18:30:07 UTC (rev 26894)
@@ -0,0 +1,42 @@
+<?php
+
+class sfSympalRedirecter
+{
+  private $_actions;
+
+  public function __construct(sfActions $actions)
+  {
+    $this->_actions = $actions;
+  }
+
+  public function getRedirect()
+  {
+    return Doctrine_Core::getTable('sfSympalRedirect')
+      ->createQuery('r')
+      ->leftJoin('r.Content c')
+      ->leftJoin('c.Type t')
+      ->where('r.source = ?', $this->_actions->getRequest()->getPathInfo())
+      ->andWhere('r.site_id = ?', 
$this->_actions->getSympalContext()->getSite()->getId())
+      ->fetchOne();
+  }
+
+  public function redirect()
+  {
+    if ($redirect = $this->getRedirect())
+    {
+      if ($destination = $redirect->getDestination())
+      {
+        // If the destination is not a url or a symfony route then prefix
+        // it with the current requests pathinfo prefix
+        if ($destination[0] != '@' && substr($destination, 0, 3) != 'http')
+        {
+          $destination = trim($destination, '/');
+          $destination = 
$this->_actions->getRequest()->getPathInfoPrefix().'/'.$destination;
+        }
+      } else {
+        $destination = $redirect->getContent()->getUrl();
+      }
+      $this->_actions->redirect($destination);
+    }
+  }
+}
\ No newline at end of file

Copied: plugins/sfSympalPlugin/trunk/lib/sfSympalSitemapGenerator.class.php 
(from rev 26892, 
plugins/sfSympalPlugin/trunk/lib/core/sfSympalSitemapGenerator.class.php)
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalSitemapGenerator.class.php         
                (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalSitemapGenerator.class.php 
2010-01-19 18:30:07 UTC (rev 26894)
@@ -0,0 +1,53 @@
+<?php
+
+class sfSympalSitemapGenerator
+{
+  protected
+    $_site,
+    $_baseUrl;
+
+  public function __construct($site)
+  {
+    $this->_site = $site;
+  }
+
+  public function generate()
+  {
+    return sprintf('<?xml version="1.0" encoding="UTF-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9";>
+%s
+</urlset>',
+    $this->_generateUrlsXml($this->_getContent())
+    );
+  }
+
+  protected function _getContent()
+  {
+    return Doctrine_Core::getTable('sfSympalContent')
+      ->createQuery('c')
+      ->select('c.*, t.*')
+      ->innerJoin('c.Type t')
+      ->innerJoin('c.Site s WITH s.slug = ?', $this->_site)
+      ->execute();
+  }
+
+  protected function _generateUrlsXml(Doctrine_Collection $contentCollection)
+  {
+    $urls = array();
+    foreach($contentCollection as $content)
+    {
+      $urls[] = $this->_generateUrlXml($content);
+    }
+
+    return implode("\n", $urls);
+  }
+
+  protected function _generateUrlXml(sfSympalContent $content)
+  {
+    return sprintf('  <url>
+    <loc>
+      %s
+    </loc>
+  </url>', $content->getUrl(array('absolute' => true)));
+  }
+}
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to