Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added onBeforeRender Trigger

Added onAfterCacheRender Trigger
Added parse method to JDocument and JDocumentHTML
Moved all "system" triggers inside of JApplication/children

git-svn-id: http://joomlacode.org/svn/joomla/development/trunk@11435 6f6e1ebd-4c2b-0410-823f-f34bde69bce9
  • Loading branch information...
commit c563a6407df8b87439c58a7887d09b49b947b376 1 parent 5acb915
@ircmaxell ircmaxell authored
View
6 administrator/includes/application.php
@@ -79,7 +79,7 @@ function initialise($options = array())
*/
function route()
{
-
+ parent::route();
}
/**
@@ -138,6 +138,7 @@ function dispatch($component = NULL)
$contents = JComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
+ $this->triggerEvent('onAfterDispatch');
}
/**
@@ -162,8 +163,11 @@ function render()
);
$document =& JFactory::getDocument();
+ $document->prepare($params);
+ $this->triggerEvent('onBeforeRender');
$data = $document->render($this->getCfg('caching'), $params );
JResponse::setBody($data);
+ $this->triggerEvent('onAfterRender');
}
/**
View
19 administrator/index.php
@@ -35,12 +35,8 @@
$mainframe->initialise(array(
'language' => $mainframe->getUserState( "application.lang", 'lang' )
));
-
-JPluginHelper::importPlugin('system');
-
-// trigger the onAfterInitialise events
+// Profiling
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
-$mainframe->triggerEvent('onAfterInitialise');
/**
* ROUTE THE APPLICATION
@@ -48,22 +44,17 @@
* NOTE :
*/
$mainframe->route();
-
-// trigger the onAfterRoute events
+// Profiling
JDEBUG ? $_PROFILER->mark('afterRoute') : null;
-$mainframe->triggerEvent('onAfterRoute');
/**
* DISPATCH THE APPLICATION
*
* NOTE :
*/
-
$mainframe->dispatch();
-
-// trigger the onAfterDispatch events
+// Profiling
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
-$mainframe->triggerEvent('onAfterDispatch');
/**
* RENDER THE APPLICATION
@@ -71,10 +62,8 @@
* NOTE :
*/
$mainframe->render();
-
-// trigger the onAfterRender events
+// Profiling
JDEBUG ? $_PROFILER->mark( 'afterRender' ) : null;
-$mainframe->triggerEvent( 'onAfterRender' );
/**
* RETURN THE RESPONSE
View
20 includes/application.php
@@ -76,7 +76,19 @@ public function initialise( $options = array())
* @access public
*/
public function route() {
- parent::route();
+ // get the full request URI
+ $uri = clone(JURI::getInstance());
+
+ $router =& $this->getRouter();
+ $result = $router->parse($uri);
+
+ JRequest::set($result, 'get', false );
+
+ // authorization
+ $Itemid = JRequest::getInt('Itemid');
+ $this->authorize($Itemid);
+
+ $this->triggerEvent('onAfterRoute');
}
/**
@@ -126,6 +138,7 @@ public function dispatch($component = null)
$contents = JComponentHelper::renderComponent($component);
$document->setBuffer( $contents, 'component');
+ $this->triggerEvent('onAfterDispatch');
}
/**
@@ -168,8 +181,11 @@ public function render()
} break;
}
- $data = $document->render( $this->getCfg('caching'), $params);
+ $document->parse($params);
+ $this->triggerEvent('onBeforeRender');
+ $data = $document->render($this->getCfg('caching'), $params );
JResponse::setBody($data);
+ $this->triggerEvent('onAfterRender');
}
/**
View
25 index.php
@@ -24,8 +24,6 @@
*
* NOTE :
*/
-
-
$mainframe =& JFactory::getApplication('site');
/**
@@ -33,14 +31,9 @@
*
* NOTE :
*/
- // set the language
$mainframe->initialise();
-
- JPluginHelper::importPlugin('system');
-
- // trigger the onAfterInitialise events
+ // profiling
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
- $mainframe->triggerEvent('onAfterInitialise');
/**
* ROUTE THE APPLICATION
@@ -48,14 +41,8 @@
* NOTE :
*/
$mainframe->route();
-
- // authorization
- $Itemid = JRequest::getInt('Itemid');
- $mainframe->authorize($Itemid);
-
- // trigger the onAfterRoute events
+ // profiling
JDEBUG ? $_PROFILER->mark('afterRoute') : null;
- $mainframe->triggerEvent('onAfterRoute');
/**
* DISPATCH THE APPLICATION
@@ -63,10 +50,8 @@
* NOTE :
*/
$mainframe->dispatch();
-
- // trigger the onAfterDispatch events
+ // Profiling
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
- $mainframe->triggerEvent('onAfterDispatch');
/**
* RENDER THE APPLICATION
@@ -74,10 +59,8 @@
* NOTE :
*/
$mainframe->render();
-
- // trigger the onAfterRender events
+ // Profiling
JDEBUG ? $_PROFILER->mark('afterRender') : null;
- $mainframe->triggerEvent('onAfterRender');
/**
* RETURN THE RESPONSE
View
6 installation/CHANGELOG
@@ -28,6 +28,12 @@ COMMITERS
Do not forget to update this page on the wiki when making changes relevant to developers:
http://docs.joomla.org/index.php?title=Version_1.6_Developer_Notes
+24-Jan-2009 Anthony Ferrara
+ + Added onBeforeRender Trigger
+ + Added onAfterCacheRender Trigger
+ + Added parse method to JDocument and JDocumentHTML
+ ^ Moved all "system" triggers inside of JApplication/children
+
24-Jan-2009 Andrew Eddie
^ Move text files to /installation/ folder
View
10 libraries/joomla/application/application.php
@@ -185,6 +185,9 @@ public function initialise($options = array())
$editor = $user->getParam('editor', $this->getCfg('editor'));
$editor = JPluginHelper::isEnabled('editors', $editor) ? $editor : $this->getCfg('editor');
$config->setValue('config.editor', $editor);
+
+ JPluginHelper::importPlugin('system');
+ $this->triggerEvent('onAfterInitialise');
}
/**
@@ -207,6 +210,8 @@ public function route()
$result = $router->parse($uri);
JRequest::set($result, 'get', false );
+
+ $this->triggerEvent('onAfterRoute');
}
/**
@@ -228,6 +233,8 @@ public function dispatch($component = null)
$contents = JComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
+
+ $this->triggerEvent('onAfterDispatch');
}
/**
@@ -249,8 +256,11 @@ public function render()
);
$document =& JFactory::getDocument();
+ $document->parse($params);
+ $this->triggerEvent('onBeforeRender');
$data = $document->render($this->getCfg('caching'), $params );
JResponse::setBody($data);
+ $this->triggerEvent('onAfterRender');
}
/**
View
10 libraries/joomla/document/document.php
@@ -754,6 +754,16 @@ public function &loadRenderer( $type )
}
/**
+ * Parses the document and prepares the buffers
+ *
+ * @access public
+ * @return null
+ */
+ public function parse($params = array()) {
+ return null;
+ }
+
+ /**
* Outputs the document
*
* @access public
View
127 libraries/joomla/document/html/html.php
@@ -42,6 +42,16 @@ class JDocumentHTML extends JDocument
public $baseurl = null;
public $params = null;
public $_file = null;
+
+ /**
+ * String holding parsed template
+ */
+ protected $_template = '';
+
+ /**
+ * Array of parsed template JDoc tags
+ */
+ protected $_template_tags = array();
/**
* Class constructor
@@ -206,6 +216,17 @@ public function setBuffer($contents, $type, $name = null)
}
/**
+ * Parses the template and populates the buffer
+ *
+ * @access public
+ * @param array parameters for fetching the template
+ */
+ public function parse($params = array()) {
+ $this->_template = $this->_loadTemplate($params);
+ $this->_parseTemplate();
+ }
+
+ /**
* Outputs the template to the browser.
*
* @access public
@@ -215,42 +236,13 @@ public function setBuffer($contents, $type, $name = null)
*/
public function render( $caching = false, $params = array())
{
- // check
- $directory = isset($params['directory']) ? $params['directory'] : 'templates';
- $template = JFilterInput::_($params['template'], 'cmd');
- $file = JFilterInput::_($params['file'], 'cmd');
-
- if ( !file_exists( $directory.DS.$template.DS.$file) ) {
- $template = 'system';
+ if(!empty($this->_template)) {
+ $data = $this->_renderTemplate();
+ } else {
+ $this->parse($params);
+ $data = $this->_renderTemplate();
}
-
- // Parse the template INI file if it exists for parameters and insert
- // them into the template.
- if (is_readable( $directory.DS.$template.DS.'params.ini' ) )
- {
- $content = file_get_contents($directory.DS.$template.DS.'params.ini');
- $params = new JParameter($content);
- }
-
- // Load the language file for the template
- $lang =& JFactory::getLanguage();
- // 1.5 or core
- $lang->load( 'tpl_'.$template );
- // 1.6
- $lang->load( 'joomla', $directory.DS.$template );
-
- // Assign the variables
- $this->template = $template;
- $this->baseurl = JURI::base(true);
- $this->params = $params;
-
- // load
- $data = $this->_loadTemplate($directory.DS.$template, $file);
-
- // parse
- $data = $this->_parseTemplate($data);
-
- //output
+
parent::render();
return $data;
}
@@ -360,17 +352,56 @@ public function _loadTemplate($directory, $filename)
}
/**
+ * Load the template, and initialize the params
+ *
+ * @param array parameters to determine the template
+ */
+ protected function _loadTemplate($params = array()) {
+ // check
+ $directory = isset($params['directory']) ? $params['directory'] : 'templates';
+ $template = JFilterInput::_($params['template'], 'cmd');
+ $file = JFilterInput::_($params['file'], 'cmd');
+
+ if ( !file_exists( $directory.DS.$template.DS.$file) ) {
+ $template = 'system';
+ }
+
+ // Parse the template INI file if it exists for parameters and insert
+ // them into the template.
+ if (is_readable( $directory.DS.$template.DS.'params.ini' ) )
+ {
+ $content = file_get_contents($directory.DS.$template.DS.'params.ini');
+ $params = new JParameter($content);
+ }
+
+ // Load the language file for the template
+ $lang =& JFactory::getLanguage();
+ // 1.5 or core
+ $lang->load( 'tpl_'.$template );
+ // 1.6
+ $lang->load( 'joomla', $directory.DS.$template );
+
+ // Assign the variables
+ $this->template = $template;
+ $this->baseurl = JURI::base(true);
+ $this->params = $params;
+
+ // load
+ $this->_template = $this->_loadTemplate($directory.DS.$template, $file);
+ }
+
+ /**
* Parse a document template
*
* @access public
* @param string $data The data too parse
* @return The parsed contents of the template
*/
- public function _parseTemplate($data)
+ public function _parseTemplate()
{
$replace = array();
$matches = array();
- if(preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $data, $matches))
+ if(preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $this->_template, $matches))
{
$matches[0] = array_reverse($matches[0]);
$matches[1] = array_reverse($matches[1]);
@@ -384,12 +415,24 @@ public function _parseTemplate($data)
$type = $matches[1][$i];
$name = isset($attribs['name']) ? $attribs['name'] : null;
- $replace[$i] = $this->getBuffer($type, $name, $attribs);
+ $this->getBuffer($type, $name, $attribs);
+ $this->_template_tags[$matches[0]] = array('type'=>$type, 'name' => $name);
}
-
- $data = str_replace($matches[0], $replace, $data);
}
-
- return $data;
+ }
+
+ /**
+ * Render pre-parsed template
+ *
+ * @return string rendered template
+ */
+ protected function _renderTemplate() {
+ $replace = array();
+ $with = array();
+ foreach($this->_template_tags AS $jdoc => $args) {
+ $replace[] = $jdoc;
+ $with[] = $this->getBuffer($args['type'], $args['name']);
+ }
+ return str_replace($replace, $with, $this->_template);
}
}
View
3  plugins/system/cache.php
@@ -72,6 +72,7 @@ function onAfterInitialise()
// the following code searches for a token in the cached page and replaces it with the
// proper token.
$user = &JFactory::getUser();
+ $app = JFactory::getApplication();
$token = JUtility::getToken();
$search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
$replacement = '<input type="hidden" name="'.$token.'" value="1" />';
@@ -79,6 +80,8 @@ function onAfterInitialise()
JResponse::setBody($data);
+ $app->triggerEvent('onAfterCacheRender');
+
echo JResponse::toString($mainframe->getCfg('gzip'));
if(JDEBUG)
Please sign in to comment.
Something went wrong with that request. Please try again.