コード例 #1
0
function ClickTale_LoadRules($path)
{
    if (!file_exists($path)) {
        throw new Exception("Could not find file: {$path}.");
    }
    $key = "Data_" . md5($path);
    $cacheProvider = ClickTale_CacheFactory::DefaultCacheProvider();
    // If available, get rules data from cache.
    if (ClickTale_Settings::Instance()->FilterRulesFile && !ClickTale_FileChanged($path)) {
        $config = ClickTale_Settings::Instance()->getCacheProviderConfig();
        // make sure we don't remove the cached scripts file after pull. This is done on a new copy of the config array
        $config["DeleteAfterPull"] = false;
        if ($cacheProvider->exists($key, $config)) {
            $data = $cacheProvider->pull($key, $config);
            return unserialize($data);
        }
    }
    try {
        $xml = new DOMDocument();
        $succ = $xml->load($path);
        $ruleSet = array();
        if (!$succ) {
            ClickTale_Logger::Write("Error - Can't process the xml scripts file. Make sure it's valid XML.");
            ClickTale_Settings::$hadRuntimeError = true;
            $returnItems = $defaultScriptsFileValues;
        } else {
            $xpath = new DOMXPath($xml);
            $rules = $xpath->query("Rules/Rule");
            foreach ($rules as $rule) {
                $singlerule = array("Name" => $rule->getElementsByTagName('Name')->item(0)->nodeValue, "Pattern" => $rule->getElementsByTagName('Find')->item(0)->nodeValue, "ReplaceWith" => $rule->getElementsByTagName('Replace')->item(0)->nodeValue);
                array_push($ruleSet, $singlerule);
            }
        }
    } catch (Exception $ex) {
        ClickTale_Settings::$hadRuntimeError = true;
        $returnItems = $defaultScriptsFileValues;
    }
    return $ruleSet;
}
コード例 #2
0
function ClickTale_LoadScripts($path)
{
    $defaultScriptsFileValues = array("TopScript" => "", "BottomScript" => "", "TopDoNotReplaceCondition" => "", "BottomDoNotReplaceCondition" => "", "TopInsertAfter" => "", "BottomInsertBefore" => "</body>");
    // We need this even if there is a cached scripts file
    // because the timestamp needs to be checked.
    if (!file_exists($path)) {
        throw new Exception("Could not find file: {$path}.");
    }
    $key = "Data_" . md5($path);
    $cacheProvider = ClickTale_CacheFactory::DefaultCacheProvider();
    // If available, get scripts data from cache.
    if (ClickTale_Settings::Instance()->CacheScriptsFile && !ClickTale_FileChanged($path)) {
        $config = ClickTale_Settings::Instance()->getCacheProviderConfig();
        // make sure we don't remove the cached scripts file after pull. This is done on a new copy of the config array
        $config["DeleteAfterPull"] = false;
        if ($cacheProvider->exists($key, $config)) {
            $data = $cacheProvider->pull($key, $config);
            return unserialize($data);
        }
    }
    try {
        $xml = new DOMDocument();
        $succ = $xml->load($path);
        if (!$succ) {
            ClickTale_Logger::Write("Error - Can't process the xml scripts file. Make sure it's valid XML.");
            ClickTale_Settings::$hadRuntimeError = true;
            $returnItems = $defaultScriptsFileValues;
        } else {
            // Find name=Top and name=Bottom elements using xpath.
            $xpath = new DOMXPath($xml);
            $top = $xpath->query("script[@name=\"Top\"]");
            $bottom = $xpath->query("script[@name=\"Bottom\"]");
            // name=Top and name=Bottom elements are mandatory.
            if (empty($top) || empty($bottom)) {
                throw new Exception("Scripts file must contain <script> elements. One with name=top and one with name=bottom.");
            }
            $returnItems = array("TopScript" => $top->item(0)->textContent, "BottomScript" => $bottom->item(0)->textContent, "TopDoNotReplaceCondition" => @$top->item(0)->attributes->getNamedItem("DoNotReplaceCondition")->value, "BottomDoNotReplaceCondition" => @$bottom->item(0)->attributes->getNamedItem("DoNotReplaceCondition")->value, "TopInsertAfter" => @$bottom->item(0)->attributes->getNamedItem("InsertAfter")->value, "BottomInsertBefore" => @$bottom->item(0)->attributes->getNamedItem("InsertBefore")->value);
            // Store in cache so we will not need to read from file each page request.
            if (ClickTale_Settings::Instance()->CacheScriptsFile) {
                $config = ClickTale_Settings::Instance()->getCacheProviderConfig();
                $config["MaxCachedSeconds"] = false;
                $cacheProvider->store($key, serialize($returnItems), $config);
            }
        }
    } catch (Exception $ex) {
        ClickTale_Settings::$hadRuntimeError = true;
        $returnItems = $defaultScriptsFileValues;
    }
    return $returnItems;
}