Example #1
0
/**
 * Inserts ClickTale script to the buffered page.
 * @param string $buffer The buffered page before injecting ClickTale scripts
 * @param array $data Hash of the ClickTale script to inject into the buffer
 * @param string $hash A key used to save this page in the cache
 * @return string The buffer with the ClickTale scripts injected into it (if required)
 */
function ClickTale_Filter($buffer, $data, $hash)
{
    $settings = ClickTale_Settings::Instance();
    $debug = $settings->AllowDebug;
    $config = $settings->getCacheProviderConfig();
    // create token replacements arrays
    $tokens = array();
    $tokens["%FetchFromUrl%"] = str_replace(array("%CacheToken%", "%ClickTaleCacheUrl%"), array($hash, ClickTale_PathToUrl(ClickTale_Root)), $settings->CacheFetchingUrl);
    $tokens["\\"] = "\\\\";
    $tokens["\$"] = "\\\$";
    $tokenKeys = array_keys($tokens);
    $tokenValues = array_values($tokens);
    $topDoNotReplaceWasFound = !empty($data["TopDoNotReplaceCondition"]) && preg_match(ClickTale_NormalizeRegex($data["TopDoNotReplaceCondition"]), $buffer);
    $bottomDoNotReplaceWasFound = !empty($data["BottomDoNotReplaceCondition"]) && preg_match(ClickTale_NormalizeRegex($data["BottomDoNotReplaceCondition"]), $buffer);
    ClickTale_Logger::WriteDebug("Starting to look for injection points. TopDoNotReplaceCondition (bool={$topDoNotReplaceWasFound}). BottomDoNotReplaceCondition(bool={$bottomDoNotReplaceWasFound})");
    if (!empty($data["TopScript"]) && !$topDoNotReplaceWasFound) {
        $data["TopScript"] = str_replace($tokenKeys, $tokenValues, $data["TopScript"]);
        $topInsertAfter = ClickTale_NormalizeRegex($data["TopInsertAfter"]);
        if (empty($topInsertAfter)) {
            $topInsertAfter = "(<body.*?>)";
            // Default value.
        }
        $topInsertAfter = str_replace("/", "\\/", $topInsertAfter);
        if ($debug) {
            $_debugFound = preg_match("/{$topInsertAfter}/i", $buffer);
            ClickTale_Logger::WriteDebug("Top injection point found? (bool={$_debugFound})");
        }
        $buffer = preg_replace("/{$topInsertAfter}/i", "\$0" . $data["TopScript"], $buffer, 1);
    }
    if (!empty($data["BottomScript"]) && !$bottomDoNotReplaceWasFound) {
        $data["BottomScript"] = str_replace($tokenKeys, $tokenValues, $data["BottomScript"]);
        $bottomInsertBefore = ClickTale_NormalizeRegex($data["BottomInsertBefore"]);
        if (empty($bottomInsertBefore)) {
            $bottomInsertBefore = "(</body>)";
            // Default value.
        }
        $bottomInsertBefore = str_replace("/", "\\/", $bottomInsertBefore);
        if ($debug) {
            $_debugFound = preg_match("/{$bottomInsertBefore}/i", $buffer);
            ClickTale_Logger::WriteDebug("Bottom injection point found? (bool={$_debugFound})");
        }
        $buffer = preg_replace("/{$bottomInsertBefore}/i", $data["BottomScript"] . "\$0", $buffer, 1);
    }
    return $buffer;
}
Example #2
0
		   <?php 
if ($cacheConfigValid) {
    ?>
		   <p>
		   	On the left there is a page which will be cached using the settings you specified in the integration module's config.php<br />
			You should see the same page in the right frame where this page is retrieved from the cache
		   </p>
           <script type="text/javascript">
           	function refreshCacheFetch() {
				<?php 
    /*
    $path = $_SERVER["PHP_SELF"];
    $port = $_SERVER["SERVER_PORT"] == 80 ? "" : ":".$_SERVER["SERVER_PORT"];
    $path = $_SERVER["SERVER_NAME"].$port.dirname(dirname($path));
    */
    $fetchFrom = str_replace(array("%CacheToken%", "%ClickTaleCacheUrl%"), array("CacheTest", ClickTale_PathToUrl(ClickTale_Root)), $config->CacheFetchingUrl);
    ?>
				var path = "<?php 
    echo $fetchFrom;
    ?>
";
				document.getElementById("cache-page-fetch").src = path;//../ClickTaleCache.php?t=CacheTest";
			}
           	function refreshCacheTest() {
				document.getElementById("cache-test-page").src = "cache_test_page.php";
				document.getElementById("cache-page-fetch").src = "waiting_for_cache.html";
				var delay = parseFloat(document.getElementById("delay-before-fetching").value) || 0;
				delay = Math.round(delay * 1000);
				
				setTimeout(refreshCacheFetch, delay);
			}