Back to Cache class

Method getWorkarounds

public static string
getWorkarounds
(mixed $data, mixed $options = array())
Perform workarounds on retrieved cached data
Parameters
  • array $data Cached data
  • array $options Array of options
Returns
  • string Body of cached data
Since
  • 1.7.0
Class: Cache
Project: Joomla

Method getWorkarounds - Source code

/**
 * Perform workarounds on retrieved cached data
 *
 * @param   array   $data     Cached data
 * @param   array   $options  Array of options
 *
 * @return  string  Body of cached data
 *
 * @since   1.7.0
 */
public static function getWorkarounds($data, $options = array())
{
    $app = Factory::getApplication();
    $document = Factory::getDocument();
    $body = null;
    // Get the document head out of the cache.
    if (isset($options['mergehead']) && $options['mergehead'] == 1 && isset($data['head']) && !empty($data['head']) && method_exists($document, 'mergeHeadData')) {
        $document->mergeHeadData($data['head']);
    } elseif (isset($data['head']) && method_exists($document, 'setHeadData')) {
        $document->setHeadData($data['head']);
    }
    // Get the document MIME encoding out of the cache
    if (isset($data['mime_encoding'])) {
        $document->setMimeEncoding($data['mime_encoding'], true);
    }
    // If the pathway buffer is set in the cache data, get it.
    if (isset($data['pathway']) && \is_array($data['pathway'])) {
        // Push the pathway data into the pathway object.
        $app->getPathway()->setPathway($data['pathway']);
    }
    // @todo check if the following is needed, seems like it should be in page cache
    // If a module buffer is set in the cache data, get it.
    if (isset($data['module']) && \is_array($data['module'])) {
        // Iterate through the module positions and push them into the document buffer.
        foreach ($data['module'] as $name => $contents) {
            $document->setBuffer($contents, 'module', $name);
        }
    }
    // Set cached headers.
    if (isset($data['headers']) && $data['headers']) {
        foreach ($data['headers'] as $header) {
            $app->setHeader($header['name'], $header['value']);
        }
    }
    // The following code searches for a token in the cached page and replaces it with the proper token.
    if (isset($data['body'])) {
        $token = Session::getFormToken();
        $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1">#';
        $replacement = '<input type="hidden" name="' . $token . '" value="1">';
        $data['body'] = preg_replace($search, $replacement, $data['body']);
        $body = $data['body'];
    }
    // Get the document body out of the cache.
    return $body;
}