Skip to content

Instantly share code, notes, and snippets.

@co3k
Created April 1, 2010 16:05
Show Gist options
  • Save co3k/351994 to your computer and use it in GitHub Desktop.
Save co3k/351994 to your computer and use it in GitHub Desktop.
diff --git a/lib/config/opApplicationConfiguration.class.php b/lib/config/opApplicationConfiguration.class.php
index de3f3f5..8d0e611 100644
--- a/lib/config/opApplicationConfiguration.class.php
+++ b/lib/config/opApplicationConfiguration.class.php
@@ -420,7 +420,33 @@ abstract class opApplicationConfiguration extends sfApplicationConfiguration
public function globEnablePlugin($pattern, $isControllerPath = false)
{
- return $this->globPlugins($pattern, false, $isControllerPath);
+ if (!sfConfig::get('ebi_cache_glob_plugin', false))
+ {
+ return $this->globPlugins($pattern, false, $isControllerPath);
+ }
+
+ $cacheKey = md5(serialize($pattern));
+
+ $cacheFile = '/tmp/'.substr($cacheKey, 0, 2).'_glob_enable_plugin_path.php';
+ if ($isControllerPath)
+ {
+ $cacheFile = '/tmp/'.substr($cacheKey, 0, 2).'_glob_enable_plugin_path_controller.php';
+ }
+
+ $list = array();
+ if (is_file($cacheFile))
+ {
+ $list = include $cacheFile;
+ if (isset($list[$cacheKey]))
+ {
+ return $list[$cacheKey];
+ }
+ }
+
+ $list[$cacheKey] = $this->globPlugins($pattern, false, $isControllerPath);
+ file_put_contents($cacheFile, "<?php\nreturn ".var_export($list, true).';');
+
+ return $list[$cacheKey];
}
public function getGlobalTemplateDir($templateFile)
diff --git a/lib/config/opProjectConfiguration.class.php b/lib/config/opProjectConfiguration.class.php
index 2d6e861..29ea31f 100644
--- a/lib/config/opProjectConfiguration.class.php
+++ b/lib/config/opProjectConfiguration.class.php
@@ -28,6 +28,72 @@ class opProjectConfiguration extends sfProjectConfiguration
opActivateBehavior::disable();
}
+ public function generateFixedMethodToDoctrineRecord(sfEvent $event)
+ {
+ if ($event->getSubject() instanceof sfDoctrineBuildModelTask)
+ {
+ if (!sfConfig::get('ebi_no_magic', false))
+ {
+ return;
+ }
+
+ $defnitionTemplate = "\n public function %s(%s)\n {\n"
+ ." return \$this->_%s('%s'%s);\n"
+ ." }\n";
+
+ $config = $event->getSubject()->getCliConfig();
+ $builderOptions = $this->getPluginConfiguration('sfDoctrinePlugin')->getModelBuilderOptions();
+
+ $models = sfFinder::type('file')->name('Base*.php')->in($config['models_path']);
+ foreach ($models as $model)
+ {
+ $code = file_get_contents($model);
+ $newDefinitions = '';
+
+ $matches = array();
+ if (preg_match_all('/@property (\w+) \$(\w+)/', $code, $matches, PREG_SET_ORDER))
+ {
+ foreach ($matches as $match)
+ {
+ $type = $match[1];
+ $property = $match[2];
+ $getter = 'get'.sfInflector::camelize($property);
+ $setter = 'set'.sfInflector::camelize($property);
+
+ // method is already exists
+ if (false !== strpos($code, 'public function '.$getter.'(')
+ || false !== strpos($code, 'public function '.$setter.'(')
+ )
+ {
+ continue;
+ }
+
+ $isColumn = ord($type[0]) >= 97 && ord($type[0]) <= 122; // a to z
+ if ($isColumn)
+ {
+ // it is not related-column
+ if (false === strpos($code, '\'local\' => \''.$property.'\''))
+ {
+ $newDefinitions .= sprintf($defnitionTemplate, $setter, '$value', 'set', $property, ', $value');
+ $newDefinitions .= sprintf($defnitionTemplate, $getter, '', 'get', $property, '');
+ }
+ }
+ }
+ }
+
+ if ($newDefinitions)
+ {
+ $pos = strrpos($code, '}');
+ $tail = substr($code, $pos);
+ $code = substr($code, 0, $pos);
+ $code .= $newDefinitions.$tail;
+ }
+
+ file_put_contents($model, $code);
+ }
+ }
+ }
+
public function setup()
{
$this->enableAllPluginsExcept(array('sfPropelPlugin'));
@@ -40,6 +106,7 @@ class opProjectConfiguration extends sfProjectConfiguration
));
$this->dispatcher->connect('command.pre_command', array(__CLASS__, 'listenToPreCommandEvent'));
+ $this->dispatcher->connect('command.post_command', array($this, 'generateFixedMethodToDoctrineRecord'));
$this->setupProjectOpenPNE();
}
diff --git a/lib/filter/opAppendXRDSHeaderFilter.class.php b/lib/filter/opAppendXRDSHeaderFilter.class.php
index ea64256..2b82ec2 100644
--- a/lib/filter/opAppendXRDSHeaderFilter.class.php
+++ b/lib/filter/opAppendXRDSHeaderFilter.class.php
@@ -17,6 +17,17 @@
*/
class opAppendXRDSHeaderFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ $route = $this->context->getRouting()->getCurrentRouteName();
+
+ if ('homepage' === $route)
+ {
+ $this->context->getResponse()->setHttpHeader('X-XRDS-Location', $this->context->getController()->genUrl('OpenID/idpXrds', true));
+ }
+
+ }
+
public function execute($filterChain)
{
$route = $this->context->getRouting()->getCurrentRouteName();
diff --git a/lib/filter/opCacheControlFilter.class.php b/lib/filter/opCacheControlFilter.class.php
index 2d331b8..ebe5f6e 100644
--- a/lib/filter/opCacheControlFilter.class.php
+++ b/lib/filter/opCacheControlFilter.class.php
@@ -17,6 +17,33 @@
*/
class opCacheControlFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ }
+
+ public function executePost($filterChain)
+ {
+ $response = $this->getContext()->getResponse();
+ $request = $this->getContext()->getRequest();
+
+ if (!headers_sent())
+ {
+ if ($request->getMobile()->isEZweb())
+ {
+ $response->setHttpHeader('Expires', sfWebResponse::getDate(577731600));
+ $response->setHttpHeader('LastModified', sfWebResponse::getDate(time()));
+
+ $response->addCacheControlHttpHeader('no-store');
+ $response->addCacheControlHttpHeader('no-cache');
+ $response->addCacheControlHttpHeader('must-revalidate');
+ $response->addCacheControlHttpHeader('post-check', 0);
+ $response->addCacheControlHttpHeader('pre-check', 0);
+
+ $response->setHttpHeader('Pragma', 'no-cache');
+ }
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/filter/opCheckEnabledApplicationFilter.class.php b/lib/filter/opCheckEnabledApplicationFilter.class.php
index d656775..f01b8a0 100644
--- a/lib/filter/opCheckEnabledApplicationFilter.class.php
+++ b/lib/filter/opCheckEnabledApplicationFilter.class.php
@@ -17,6 +17,21 @@
*/
class opCheckEnabledApplicationFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ $current = $this->context->getRouting()->getCurrentRouteName();
+ $configName = 'enable_'.$this->getParameter('app', 'pc');
+
+ if (!opConfig::get($configName))
+ {
+ if ($current !== 'error')
+ {
+ $this->context->getController()->redirect('@error');
+ throw new sfStopException();
+ }
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/filter/opEmojiFilter.class.php b/lib/filter/opEmojiFilter.class.php
index 10f1e74..7879c03 100644
--- a/lib/filter/opEmojiFilter.class.php
+++ b/lib/filter/opEmojiFilter.class.php
@@ -19,6 +19,27 @@
*/
class opEmojiFilter extends sfFilter
{
+ public function executePost($filterChain)
+ {
+ $response = $this->getContext()->getResponse();
+ $request = $this->getContext()->getRequest();
+ $content = $response->getContent();
+
+ if (!$request->isMobile())
+ {
+ list($list, $content) = opToolkit::replacePatternsToMarker($content);
+ }
+
+ $content = OpenPNE_KtaiEmoji::convertEmoji($content);
+
+ if (!$request->isMobile())
+ {
+ $content = str_replace(array_keys($list), array_values($list), $content);
+ }
+
+ $response->setContent($content);
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/filter/opExecutionFilter.class.php b/lib/filter/opExecutionFilter.class.php
index 8d9871c..69908c1 100644
--- a/lib/filter/opExecutionFilter.class.php
+++ b/lib/filter/opExecutionFilter.class.php
@@ -17,6 +17,32 @@
*/
class opExecutionFilter extends sfExecutionFilter
{
+ public function executePre($filterChain)
+ {
+ // get the current action instance
+ $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
+
+ // execute the action, execute and render the view
+ if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
+ {
+ $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName()));
+
+ $viewName = $this->handleAction($filterChain, $actionInstance);
+
+ $timer->addTime();
+ $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName()));
+
+ $this->handleView($filterChain, $actionInstance, $viewName);
+
+ $timer->addTime();
+ }
+ else
+ {
+ $viewName = $this->handleAction($filterChain, $actionInstance);
+ $this->handleView($filterChain, $actionInstance, $viewName);
+ }
+ }
+
public static function notifyPreExecuteActionEvent($subject, sfEventDispatcher $dispatcher, sfAction $actionInstance)
{
$moduleName = $actionInstance->getModuleName();
diff --git a/lib/filter/opRememberLoginFilter.class.php b/lib/filter/opRememberLoginFilter.class.php
index b41e372..7c503f5 100644
--- a/lib/filter/opRememberLoginFilter.class.php
+++ b/lib/filter/opRememberLoginFilter.class.php
@@ -17,6 +17,17 @@
*/
class opRememberLoginFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ if ($this->isFirstCall() && !$this->context->getUser()->isAuthenticated())
+ {
+ if ($memberId = $this->context->getUser()->getRememberedMemberId())
+ {
+ $this->context->getUser()->login($memberId);
+ }
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php b/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php
index 6917fb0..990ca8e 100644
--- a/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php
+++ b/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php
@@ -22,6 +22,46 @@
*/
class sfBasicSecurityFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ // disable security on login and secure actions
+ if (
+ (sfConfig::get('sf_login_module') == $this->context->getModuleName()) && (sfConfig::get('sf_login_action') == $this->context->getActionName())
+ ||
+ (sfConfig::get('sf_secure_module') == $this->context->getModuleName()) && (sfConfig::get('sf_secure_action') == $this->context->getActionName())
+ )
+ {
+ return;
+ }
+
+ // NOTE: the nice thing about the Action class is that getCredential()
+ // is vague enough to describe any level of security and can be
+ // used to retrieve such data and should never have to be altered
+ if (!$this->context->getUser()->isAuthenticated())
+ {
+ if (sfConfig::get('sf_logging_enabled'))
+ {
+ $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" requires authentication, forwarding to "%s/%s"', $this->context->getModuleName(), $this->context->getActionName(), sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action')))));
+ }
+
+ // the user is not authenticated
+ $this->forwardToLoginAction();
+ }
+
+ // the user is authenticated
+ $credential = $this->getUserCredential();
+ if (null !== $credential && !$this->context->getUser()->hasCredential($credential))
+ {
+ if (sfConfig::get('sf_logging_enabled'))
+ {
+ $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" requires credentials "%s", forwarding to "%s/%s"', $this->context->getModuleName(), $this->context->getActionName(), sfYaml::dump($credential, 0), sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')))));
+ }
+
+ // the user doesn't have access
+ $this->forwardToSecureAction();
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/vendor/symfony/lib/filter/sfFilter.class.php b/lib/vendor/symfony/lib/filter/sfFilter.class.php
index bfde013..2b3997d 100644
--- a/lib/vendor/symfony/lib/filter/sfFilter.class.php
+++ b/lib/vendor/symfony/lib/filter/sfFilter.class.php
@@ -27,6 +27,14 @@ abstract class sfFilter
public static
$filterCalled = array();
+ public function executePre($filterChain)
+ {
+ }
+
+ public function executePost($filterChain)
+ {
+ }
+
/**
* Class constructor.
*
diff --git a/lib/vendor/symfony/lib/filter/sfFilterChain.class.php b/lib/vendor/symfony/lib/filter/sfFilterChain.class.php
index 4bed13c..8d58d66 100644
--- a/lib/vendor/symfony/lib/filter/sfFilterChain.class.php
+++ b/lib/vendor/symfony/lib/filter/sfFilterChain.class.php
@@ -41,7 +41,15 @@ class sfFilterChain
{
// skip to the next filter
++$this->index;
-
+ for ($i = 0; $i < count($this->chain); $i++)
+ {
+ $this->chain[$i]->executePre($this);
+ }
+ for ($i -= 1; $i >= 0; $i--)
+ {
+ $this->chain[$i]->executePost($this);
+ }
+/*
if ($this->index < count($this->chain))
{
if (sfConfig::get('sf_logging_enabled'))
@@ -52,6 +60,7 @@ class sfFilterChain
// execute the next filter
$this->chain[$this->index]->execute($this);
}
+ */
}
/**
diff --git a/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php b/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php
index 4c5f3df..422f670 100644
--- a/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php
+++ b/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php
@@ -19,6 +19,29 @@
*/
class sfRenderingFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ }
+
+ public function executePost($filterChain)
+ {
+ // get response object
+ $response = $this->context->getResponse();
+
+ // hack to rethrow sfForm and|or sfFormField __toString() exceptions (see sfForm and sfFormField)
+ if (sfForm::hasToStringException())
+ {
+ throw sfForm::getToStringException();
+ }
+ else if (sfFormField::hasToStringException())
+ {
+ throw sfFormField::getToStringException();
+ }
+
+ // send headers + content
+ $response->send();
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php b/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
index 7126498..1357261 100644
--- a/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
+++ b/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
@@ -2683,4 +2683,4 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return (string) $this->_oid;
}
-}
\ No newline at end of file
+}
diff --git a/lib/config/opApplicationConfiguration.class.php b/lib/config/opApplicationConfiguration.class.php
index de3f3f5..9ad8e78 100644
--- a/lib/config/opApplicationConfiguration.class.php
+++ b/lib/config/opApplicationConfiguration.class.php
@@ -18,6 +18,8 @@
abstract class opApplicationConfiguration extends sfApplicationConfiguration
{
static protected $zendLoaded = false;
+ public $globEnablePluginList = array();
+ public $globEnablePluginControllerList = array();
public function initialize()
{
@@ -420,7 +422,41 @@ abstract class opApplicationConfiguration extends sfApplicationConfiguration
public function globEnablePlugin($pattern, $isControllerPath = false)
{
- return $this->globPlugins($pattern, false, $isControllerPath);
+ if (!sfConfig::get('ebi_cache_glob_plugin', false))
+ {
+ return $this->globPlugins($pattern, false, $isControllerPath);
+ }
+
+ $cacheKey = md5(serialize($pattern));
+ $cacheHead = substr($cacheKey, 0, 2);
+
+ $cacheFile = '/tmp/'.substr($cacheKey, 0, 2).'_glob_enable_plugin_path.php';
+ $cacheProperty = 'globEnablePluginList';
+ if ($isControllerPath)
+ {
+ $cacheFile = '/tmp/'.substr($cacheKey, 0, 2).'_glob_enable_plugin_path_controller.php';
+ $cacheProperty = 'globEnablePluginControllerList';
+ }
+
+ $_prop =& $this->$cacheProperty;
+
+ if (empty($_prop[$cacheHead]))
+ {
+ if (is_file($cacheFile))
+ {
+ $_prop[$cacheHead] = include $cacheFile;
+ }
+ }
+
+ if (isset($_prop[$cacheHead][$cacheKey]))
+ {
+ return $_prop[$cacheHead][$cacheKey];
+ }
+
+ $_prop[$cacheHead][$cacheKey] = $this->globPlugins($pattern, false, $isControllerPath);
+ file_put_contents($cacheFile, "<?php\nreturn ".var_export($_prop[$cacheHead], true).';');
+
+ return $_prop[$cacheHead][$cacheKey];
}
diff --git a/lib/config/opProjectConfiguration.class.php b/lib/config/opProjectConfiguration.class.php
index 2d6e861..29ea31f 100644
--- a/lib/config/opProjectConfiguration.class.php
+++ b/lib/config/opProjectConfiguration.class.php
@@ -28,6 +28,72 @@ class opProjectConfiguration extends sfProjectConfiguration
opActivateBehavior::disable();
}
+ public function generateFixedMethodToDoctrineRecord(sfEvent $event)
+ {
+ if ($event->getSubject() instanceof sfDoctrineBuildModelTask)
+ {
+ if (!sfConfig::get('ebi_no_magic', false))
+ {
+ return;
+ }
+
+ $defnitionTemplate = "\n public function %s(%s)\n {\n"
+ ." return \$this->_%s('%s'%s);\n"
+ ." }\n";
+
+ $config = $event->getSubject()->getCliConfig();
+ $builderOptions = $this->getPluginConfiguration('sfDoctrinePlugin')->getModelBuilderOptions();
+
+ $models = sfFinder::type('file')->name('Base*.php')->in($config['models_path']);
+ foreach ($models as $model)
+ {
+ $code = file_get_contents($model);
+ $newDefinitions = '';
+
+ $matches = array();
+ if (preg_match_all('/@property (\w+) \$(\w+)/', $code, $matches, PREG_SET_ORDER))
+ {
+ foreach ($matches as $match)
+ {
+ $type = $match[1];
+ $property = $match[2];
+ $getter = 'get'.sfInflector::camelize($property);
+ $setter = 'set'.sfInflector::camelize($property);
+
+ // method is already exists
+ if (false !== strpos($code, 'public function '.$getter.'(')
+ || false !== strpos($code, 'public function '.$setter.'(')
+ )
+ {
+ continue;
+ }
+
+ $isColumn = ord($type[0]) >= 97 && ord($type[0]) <= 122; // a to z
+ if ($isColumn)
+ {
+ // it is not related-column
+ if (false === strpos($code, '\'local\' => \''.$property.'\''))
+ {
+ $newDefinitions .= sprintf($defnitionTemplate, $setter, '$value', 'set', $property, ', $value');
+ $newDefinitions .= sprintf($defnitionTemplate, $getter, '', 'get', $property, '');
+ }
+ }
+ }
+ }
+
+ if ($newDefinitions)
+ {
+ $pos = strrpos($code, '}');
+ $tail = substr($code, $pos);
+ $code = substr($code, 0, $pos);
+ $code .= $newDefinitions.$tail;
+ }
+
+ file_put_contents($model, $code);
+ }
+ }
+ }
+
public function setup()
{
$this->enableAllPluginsExcept(array('sfPropelPlugin'));
@@ -40,6 +106,7 @@ class opProjectConfiguration extends sfProjectConfiguration
));
$this->dispatcher->connect('command.pre_command', array(__CLASS__, 'listenToPreCommandEvent'));
+ $this->dispatcher->connect('command.post_command', array($this, 'generateFixedMethodToDoctrineRecord'));
$this->setupProjectOpenPNE();
}
diff --git a/lib/filter/opAppendXRDSHeaderFilter.class.php b/lib/filter/opAppendXRDSHeaderFilter.class.php
index ea64256..2b82ec2 100644
--- a/lib/filter/opAppendXRDSHeaderFilter.class.php
+++ b/lib/filter/opAppendXRDSHeaderFilter.class.php
@@ -17,6 +17,17 @@
*/
class opAppendXRDSHeaderFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ $route = $this->context->getRouting()->getCurrentRouteName();
+
+ if ('homepage' === $route)
+ {
+ $this->context->getResponse()->setHttpHeader('X-XRDS-Location', $this->context->getController()->genUrl('OpenID/idpXrds', true));
+ }
+
+ }
+
public function execute($filterChain)
{
$route = $this->context->getRouting()->getCurrentRouteName();
diff --git a/lib/filter/opCacheControlFilter.class.php b/lib/filter/opCacheControlFilter.class.php
index 2d331b8..ebe5f6e 100644
--- a/lib/filter/opCacheControlFilter.class.php
+++ b/lib/filter/opCacheControlFilter.class.php
@@ -17,6 +17,33 @@
*/
class opCacheControlFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ }
+
+ public function executePost($filterChain)
+ {
+ $response = $this->getContext()->getResponse();
+ $request = $this->getContext()->getRequest();
+
+ if (!headers_sent())
+ {
+ if ($request->getMobile()->isEZweb())
+ {
+ $response->setHttpHeader('Expires', sfWebResponse::getDate(577731600));
+ $response->setHttpHeader('LastModified', sfWebResponse::getDate(time()));
+
+ $response->addCacheControlHttpHeader('no-store');
+ $response->addCacheControlHttpHeader('no-cache');
+ $response->addCacheControlHttpHeader('must-revalidate');
+ $response->addCacheControlHttpHeader('post-check', 0);
+ $response->addCacheControlHttpHeader('pre-check', 0);
+
+ $response->setHttpHeader('Pragma', 'no-cache');
+ }
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/filter/opCheckEnabledApplicationFilter.class.php b/lib/filter/opCheckEnabledApplicationFilter.class.php
index d656775..f01b8a0 100644
--- a/lib/filter/opCheckEnabledApplicationFilter.class.php
+++ b/lib/filter/opCheckEnabledApplicationFilter.class.php
@@ -17,6 +17,21 @@
*/
class opCheckEnabledApplicationFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ $current = $this->context->getRouting()->getCurrentRouteName();
+ $configName = 'enable_'.$this->getParameter('app', 'pc');
+
+ if (!opConfig::get($configName))
+ {
+ if ($current !== 'error')
+ {
+ $this->context->getController()->redirect('@error');
+ throw new sfStopException();
+ }
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/filter/opEmojiFilter.class.php b/lib/filter/opEmojiFilter.class.php
index 10f1e74..7879c03 100644
--- a/lib/filter/opEmojiFilter.class.php
+++ b/lib/filter/opEmojiFilter.class.php
@@ -19,6 +19,27 @@
*/
class opEmojiFilter extends sfFilter
{
+ public function executePost($filterChain)
+ {
+ $response = $this->getContext()->getResponse();
+ $request = $this->getContext()->getRequest();
+ $content = $response->getContent();
+
+ if (!$request->isMobile())
+ {
+ list($list, $content) = opToolkit::replacePatternsToMarker($content);
+ }
+
+ $content = OpenPNE_KtaiEmoji::convertEmoji($content);
+
+ if (!$request->isMobile())
+ {
+ $content = str_replace(array_keys($list), array_values($list), $content);
+ }
+
+ $response->setContent($content);
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/filter/opExecutionFilter.class.php b/lib/filter/opExecutionFilter.class.php
index 8d9871c..69908c1 100644
--- a/lib/filter/opExecutionFilter.class.php
+++ b/lib/filter/opExecutionFilter.class.php
@@ -17,6 +17,32 @@
*/
class opExecutionFilter extends sfExecutionFilter
{
+ public function executePre($filterChain)
+ {
+ // get the current action instance
+ $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
+
+ // execute the action, execute and render the view
+ if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
+ {
+ $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName()));
+
+ $viewName = $this->handleAction($filterChain, $actionInstance);
+
+ $timer->addTime();
+ $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName()));
+
+ $this->handleView($filterChain, $actionInstance, $viewName);
+
+ $timer->addTime();
+ }
+ else
+ {
+ $viewName = $this->handleAction($filterChain, $actionInstance);
+ $this->handleView($filterChain, $actionInstance, $viewName);
+ }
+ }
+
public static function notifyPreExecuteActionEvent($subject, sfEventDispatcher $dispatcher, sfAction $actionInstance)
{
$moduleName = $actionInstance->getModuleName();
diff --git a/lib/filter/opRememberLoginFilter.class.php b/lib/filter/opRememberLoginFilter.class.php
index b41e372..7c503f5 100644
--- a/lib/filter/opRememberLoginFilter.class.php
+++ b/lib/filter/opRememberLoginFilter.class.php
@@ -17,6 +17,17 @@
*/
class opRememberLoginFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ if ($this->isFirstCall() && !$this->context->getUser()->isAuthenticated())
+ {
+ if ($memberId = $this->context->getUser()->getRememberedMemberId())
+ {
+ $this->context->getUser()->login($memberId);
+ }
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php b/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php
index 6917fb0..990ca8e 100644
--- a/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php
+++ b/lib/vendor/symfony/lib/filter/sfBasicSecurityFilter.class.php
@@ -22,6 +22,46 @@
*/
class sfBasicSecurityFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ // disable security on login and secure actions
+ if (
+ (sfConfig::get('sf_login_module') == $this->context->getModuleName()) && (sfConfig::get('sf_login_action') == $this->context->getActionName())
+ ||
+ (sfConfig::get('sf_secure_module') == $this->context->getModuleName()) && (sfConfig::get('sf_secure_action') == $this->context->getActionName())
+ )
+ {
+ return;
+ }
+
+ // NOTE: the nice thing about the Action class is that getCredential()
+ // is vague enough to describe any level of security and can be
+ // used to retrieve such data and should never have to be altered
+ if (!$this->context->getUser()->isAuthenticated())
+ {
+ if (sfConfig::get('sf_logging_enabled'))
+ {
+ $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" requires authentication, forwarding to "%s/%s"', $this->context->getModuleName(), $this->context->getActionName(), sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action')))));
+ }
+
+ // the user is not authenticated
+ $this->forwardToLoginAction();
+ }
+
+ // the user is authenticated
+ $credential = $this->getUserCredential();
+ if (null !== $credential && !$this->context->getUser()->hasCredential($credential))
+ {
+ if (sfConfig::get('sf_logging_enabled'))
+ {
+ $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" requires credentials "%s", forwarding to "%s/%s"', $this->context->getModuleName(), $this->context->getActionName(), sfYaml::dump($credential, 0), sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')))));
+ }
+
+ // the user doesn't have access
+ $this->forwardToSecureAction();
+ }
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/vendor/symfony/lib/filter/sfFilter.class.php b/lib/vendor/symfony/lib/filter/sfFilter.class.php
index bfde013..2b3997d 100644
--- a/lib/vendor/symfony/lib/filter/sfFilter.class.php
+++ b/lib/vendor/symfony/lib/filter/sfFilter.class.php
@@ -27,6 +27,14 @@ abstract class sfFilter
public static
$filterCalled = array();
+ public function executePre($filterChain)
+ {
+ }
+
+ public function executePost($filterChain)
+ {
+ }
+
/**
* Class constructor.
*
diff --git a/lib/vendor/symfony/lib/filter/sfFilterChain.class.php b/lib/vendor/symfony/lib/filter/sfFilterChain.class.php
index 4bed13c..8d58d66 100644
--- a/lib/vendor/symfony/lib/filter/sfFilterChain.class.php
+++ b/lib/vendor/symfony/lib/filter/sfFilterChain.class.php
@@ -41,7 +41,15 @@ class sfFilterChain
{
// skip to the next filter
++$this->index;
-
+ for ($i = 0; $i < count($this->chain); $i++)
+ {
+ $this->chain[$i]->executePre($this);
+ }
+ for ($i -= 1; $i >= 0; $i--)
+ {
+ $this->chain[$i]->executePost($this);
+ }
+/*
if ($this->index < count($this->chain))
{
if (sfConfig::get('sf_logging_enabled'))
@@ -52,6 +60,7 @@ class sfFilterChain
// execute the next filter
$this->chain[$this->index]->execute($this);
}
+ */
}
/**
diff --git a/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php b/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php
index 4c5f3df..422f670 100644
--- a/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php
+++ b/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php
@@ -19,6 +19,29 @@
*/
class sfRenderingFilter extends sfFilter
{
+ public function executePre($filterChain)
+ {
+ }
+
+ public function executePost($filterChain)
+ {
+ // get response object
+ $response = $this->context->getResponse();
+
+ // hack to rethrow sfForm and|or sfFormField __toString() exceptions (see sfForm and sfFormField)
+ if (sfForm::hasToStringException())
+ {
+ throw sfForm::getToStringException();
+ }
+ else if (sfFormField::hasToStringException())
+ {
+ throw sfFormField::getToStringException();
+ }
+
+ // send headers + content
+ $response->send();
+ }
+
/**
* Executes this filter.
*
diff --git a/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php b/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
index 7126498..1357261 100644
--- a/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
+++ b/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php
@@ -2683,4 +2683,4 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return (string) $this->_oid;
}
-}
\ No newline at end of file
+}
diff --git a/web/index.php b/web/index.php
index 8d02f46..65af1ef 100644
--- a/web/index.php
+++ b/web/index.php
@@ -8,6 +8,8 @@
* file and the NOTICE file that were distributed with this source code.
*/
+xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
+
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('pc_frontend', 'prod', false);
@@ -18,3 +20,23 @@ if (!opMobileUserAgent::getInstance()->getMobile()->isNonMobile())
}
sfContext::createInstance($configuration)->dispatch();
+
+$xhprof_data = xhprof_disable();
+
+$lastEntry = sfContext::getInstance()->getActionStack()->getLastEntry();
+$routeName = sfContext::getInstance()->getRouting()->getCurrentRouteName();
+$entryId = $routeName.'_'.$lastEntry->getModuleName().'_'.$lastEntry->getActionName().'_'.getmypid();
+
+$XHPROF_ROOT = '/home/co3k/src/xhprof-0.9.2';
+include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
+include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
+
+$xhprof_runs = new XHProfRuns_Default();
+
+$run_id = $xhprof_runs->save_run($xhprof_data, $entryId);
+
+echo '<pre>'.htmlspecialchars("---------------\n".
+ "Assuming you have set up the http based UI for \n".
+ "XHProf at some address, you can view run at \n".
+ "http://ebizori.deb/xhp/index.php?run=$run_id&source=$entryId\n".
+ "---------------\n").'</pre>';
diff --git a/apps/pc_frontend/config/factories.yml b/apps/pc_frontend/config/factories.yml
index 1465851..9463dff 100644
--- a/apps/pc_frontend/config/factories.yml
+++ b/apps/pc_frontend/config/factories.yml
@@ -92,13 +92,7 @@ all:
debug: false
untranslated_prefix: "[T]"
untranslated_suffix: "[/T]"
- cache:
- class: sfFileCache
- param:
- automatic_cleaning_factor: 0
- cache_dir: %SF_I18N_CACHE_DIR%
- lifetime: 86400
- prefix: %SF_APP_DIR%
+ cache: ~
routing:
class: sfPatternRouting
diff --git a/lib/i18n/opI18N.class.php b/lib/i18n/opI18N.class.php
index 3c4c9e2..ce43efa 100644
--- a/lib/i18n/opI18N.class.php
+++ b/lib/i18n/opI18N.class.php
@@ -24,6 +24,80 @@ class opI18N extends sfI18N
$this->terms->configure($this->culture, sfConfig::get('sf_app'));
}
+ public function generateApplicationMessages($dirs)
+ {
+ $catalogues = array();
+
+ $files = sfFinder::type('file')
+ ->follow_link()
+ ->name('*.xml')
+ ->maxdepth(1)
+ ->in($dirs);
+
+ foreach ($files as $file)
+ {
+ $name = basename($file);
+ if (empty($catalogues[$name]))
+ {
+ $catalogues[$name] = array();
+ }
+
+ $messageSource = sfMessageSource::factory('OpenPNE', array());
+ $data = $messageSource->loadData($file);
+
+ $catalogues[$name] = array_merge($catalogues[$name], $data);
+ }
+
+ $cacheDir = sfConfig::get('sf_app_cache_dir').DIRECTORY_SEPARATOR.'i18n';
+
+ $filesystem = new sfFilesystem();
+ $filesystem->mkdirs($cacheDir);
+
+ foreach ($catalogues as $filename => $catalogue)
+ {
+ file_put_contents($cacheDir.DIRECTORY_SEPARATOR.$filename.'.php', '<?php return '.var_export($catalogue, true).';');
+ }
+ }
+
+ public function setMessageSource($dirs, $culture = null)
+ {
+ $cachedDir = sfConfig::get('sf_app_cache_dir').DIRECTORY_SEPARATOR.'i18n';
+ if (is_file($cachedDir.DIRECTORY_SEPARATOR.'messages.ja.xml.php'))
+ {
+ $this->messageSource = sfMessageSource::factory('OpenPNECached', $cachedDir);
+ }
+ else
+ {
+ $this->generateApplicationMessages($dirs);
+
+ if (null === $dirs)
+ {
+ $this->messageSource = $this->createMessageSource();
+ }
+ else
+ {
+ $this->messageSource = sfMessageSource::factory('Aggregate', array_map(array($this, 'createMessageSource'), $dirs));
+ }
+ }
+
+ if (null !== $this->cache)
+ {
+ $this->messageSource->setCache($this->cache);
+ }
+
+ if (null !== $culture)
+ {
+ $this->setCulture($culture);
+ }
+ else
+ {
+ $this->messageSource->setCulture($this->culture);
+ }
+
+ $this->messageFormat = null;
+ }
+
+
public function __($string, $args = array(), $catalogue = 'messages')
{
foreach ($args as $k => $v)
diff --git a/lib/i18n/sfMessageSource_OpenPNECached.class.php b/lib/i18n/sfMessageSource_OpenPNECached.class.php
new file mode 100644
index 0000000..1e153c8
--- /dev/null
+++ b/lib/i18n/sfMessageSource_OpenPNECached.class.php
@@ -0,0 +1,61 @@
+<?php
+
+class sfMessageSource_OpenPNECached extends sfMessageSource_File
+{
+ protected $dataExt = '.xml.php';
+
+ public function getSource($variant)
+ {
+ $result = $this->source.'/'.$variant;
+
+ return $result;
+ }
+
+ public function getCatalogueList($catalogue)
+ {
+ $variants = explode('_', $this->culture);
+ $base = $this->source.DIRECTORY_SEPARATOR.$catalogue.'.';
+
+ return array(
+ $base.$variants[0].$this->dataExt, $base.$this->culture.$this->dataExt,
+ );
+ }
+
+ public function load($catalogue = 'messages')
+ {
+ $variants = $this->getCatalogueList($catalogue);
+
+ $isLoaded = false;
+ foreach ($variants as $variant)
+ {
+ if (isset($this->messages[$variant]))
+ {
+ return true;
+ }
+
+ if (is_file($variant))
+ {
+ $this->messages[$variant] = include($variant);
+ $isLoaded = true;
+ break;
+ }
+ }
+
+ return $isLoaded;
+ }
+
+ public function save($catalogue = 'messages')
+ {
+ return true;
+ }
+
+ public function delete($message, $catalogue='messages')
+ {
+ return true;
+ }
+
+ public function update($text, $target, $comments, $catalogue = 'messages')
+ {
+ return true;
+ }
+}
diff --git a/web/index.php b/web/index.php
index 8d02f46..65af1ef 100644
--- a/web/index.php
+++ b/web/index.php
@@ -8,6 +8,8 @@
* file and the NOTICE file that were distributed with this source code.
*/
+xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
+
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('pc_frontend', 'prod', false);
@@ -18,3 +20,23 @@ if (!opMobileUserAgent::getInstance()->getMobile()->isNonMobile())
}
sfContext::createInstance($configuration)->dispatch();
+
+$xhprof_data = xhprof_disable();
+
+$lastEntry = sfContext::getInstance()->getActionStack()->getLastEntry();
+$routeName = sfContext::getInstance()->getRouting()->getCurrentRouteName();
+$entryId = $routeName.'_'.$lastEntry->getModuleName().'_'.$lastEntry->getActionName().'_'.getmypid();
+
+$XHPROF_ROOT = '/home/co3k/src/xhprof-0.9.2';
+include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
+include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
+
+$xhprof_runs = new XHProfRuns_Default();
+
+$run_id = $xhprof_runs->save_run($xhprof_data, $entryId);
+
+echo '<pre>'.htmlspecialchars("---------------\n".
+ "Assuming you have set up the http based UI for \n".
+ "XHProf at some address, you can view run at \n".
+ "http://ebizori.deb/xhp/index.php?run=$run_id&source=$entryId\n".
+ "---------------\n").'</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment