Exemplo n.º 1
0
 function updateSettings()
 {
     global $_PB_CACHE;
     if (isset($_PB_CACHE['setting']) && is_array($_PB_CACHE['setting'])) {
         writeCache('setting', '', '$_PB_CACHE[\'setting\'] = ' . evalArray($_PB_CACHE['setting']) . ";\n\n");
     }
 }
Exemplo n.º 2
0
function renderRequest($url)
{
    if (caching) {
        $cache = readCache($url);
        if ($cache) {
            list($contentType, $content) = $cache;
            return [true, [$contentType, base64_decode($content)]];
        }
    }
    list($rBool, $rData, $bCache) = doRequest($url);
    if (!$rBool) {
        if (caching) {
            if ($bCache) {
                bulkCacheTimestampUpdate();
            }
            $cache = readCache($url, true);
            if ($cache) {
                list($contentType, $content) = $cache;
                return [true, [$contentType, base64_decode($content)]];
            }
        }
        return [false, $rData];
    }
    if (caching) {
        if (!writeCache($url, $rData)) {
            error_log('could not write to cache');
        }
    }
    list($contentType, $content) = $rData;
    return [true, [$contentType, base64_decode($content)]];
}
Exemplo n.º 3
0
/**
 * Count number of requested IP addresses
 */
function countRequestedIPaddresses()
{
    # check if already in cache
    if ($vtmp = checkCache("openrequests", 0)) {
        return $vtmp;
    } else {
        global $database;
        /* set query, open db connection and fetch results */
        $query = 'select count(*) from requests where `processed` = 0;';
        /* execute */
        try {
            $details = $database->getArray($query);
        } catch (Exception $e) {
            $error = $e->getMessage();
            print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>";
            return false;
        }
        # save to cche
        writeCache("openrequests", 0, $details[0]['count(*)']);
        # return
        return $details[0]['count(*)'];
    }
}
Exemplo n.º 4
0
function getAllSlaves($subnetId, $multi = false)
{
    # check cache
    if ($vtmp = checkCache("allslaves", $subnetId . "_{$multi}")) {
        return $vtmp;
    } else {
        global $removeSlaves;
        $end = false;
        # breaks while
        $removeSlaves[] = $subnetId;
        # first
        # db
        global $db;
        # get variables from config file
        $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
        while ($end == false) {
            /* get all immediate slaves */
            $query = "select * from `subnets` where `masterSubnetId` = '{$subnetId}' order by `id` asc; ";
            /* execute query */
            try {
                $slaves2 = $database->getArray($query);
            } catch (Exception $e) {
                $error = $e->getMessage();
                print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>";
                return false;
            }
            # we have more slaves
            if (sizeof($slaves2) != 0) {
                # recursive
                foreach ($slaves2 as $slave) {
                    $removeSlaves[] = $slave['id'];
                    getAllSlaves($slave['id']);
                    $end = true;
                }
            } else {
                $end = true;
            }
        }
        # save cache
        if (sizeof($removeSlaves) > 0) {
            writeCache("allslaves", $subnetId . "_{$multi}", $removeSlaves);
        }
    }
}
Exemplo n.º 5
0
/**
 *	get whole tree path for subnetId - from parent all slaves
 *
 * 	if multi than create multidimensional array
 */
function getAllSlavesReturn($subnetId)
{
    # check cache
    if ($vtmp = checkCache("allslavesReturn", $subnetId)) {
        return $vtmp;
    } else {
        $end = false;
        # breaks while
        $allSlaves[] = $subnetId;
        # first
        # db
        global $database;
        while ($end == false) {
            /* get all immediate slaves */
            $query = "select `id` from `subnets` where `masterSubnetId` = '{$subnetId}' order by `id` asc; ";
            /* execute query */
            try {
                $slaves2 = $database->getArray($query);
            } catch (Exception $e) {
                $error = $e->getMessage();
                print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>";
                return false;
            }
            # we have more slaves
            if (sizeof($slaves2) != 0) {
                # recursive
                foreach ($slaves2 as $slave) {
                    $allSlaves[] = $slave['id'];
                    getAllSlavesReturn($slave['id']);
                    $end = true;
                }
            } else {
                $end = true;
            }
        }
        # save cache
        if (sizeof($allSlaves) > 0) {
            writeCache("allslaves", $subnetId, $allSlaves);
        }
        # return
        return $allSlaves;
    }
}
Exemplo n.º 6
0
/**
 *	Group details by ID
 */
function getGroupById($id)
{
    # check if already in cache
    if ($vtmp = checkCache("group", $id)) {
        return $vtmp;
    } else {
        global $database;
        /* execute query */
        $query = "select * from `userGroups` where `g_id`= '{$id}';";
        /* get group */
        try {
            $group = $database->getArray($query);
        } catch (Exception $e) {
            $error = $e->getMessage();
            die("<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>");
        }
        /* return false if none, else list */
        if (sizeof($group) == 0) {
            return false;
        } else {
            writeCache("group", $id, $group[0]);
            return $group[0];
        }
    }
}
Exemplo n.º 7
0
function writeCache($urlAbs)
{
    static $urlRootPage = '';
    static $aCss = [];
    static $aJs = [];
    static $regScript = '/<script src="((?:\\.{0,2}\\/)*(?:[\\w\\d]+\\/)*[\\w\\d]+\\.js)"><\\/script>/i';
    static $regLink = '/<link rel="stylesheet" href="((?:\\.{0,2}\\/)*(?:[\\w\\d]+\\/)*[\\w\\d]+\\.css)" *\\/?>/i';
    static $regIncInline = '/<!-- include src="((?:\\.{0,2}\\/)*(?:[\\w\\d]+\\/)*[\\w\\d]+\\.html)"[\\s\\S]*? -->/i';
    static $regSrc = '/(?<=script src=")(\\/src[^"]+?)(?=")/i';
    if ($urlRootPage === '') {
        $urlRootPage = $urlAbs;
    }
    $txtCnt = getContent($urlAbs);
    if ($txtCnt !== false) {
        collectResources($regLink, $txtCnt, $urlAbs, $aCss);
        collectResources($regScript, $txtCnt, $urlAbs, $aJs);
        preg_match_all($regIncInline, $txtCnt, $aIncs);
        for ($cntIncs = 0; $cntIncs < count($aIncs[0]); $cntIncs++) {
            $sInclude = $aIncs[0][$cntIncs];
            $urlIncRel = $aIncs[1][$cntIncs];
            $urlIncAbs = calAbsUrl($urlIncRel, $urlAbs);
            $txtIncCnt = writeCache($urlIncAbs);
            if ($txtIncCnt === false) {
                $txtIncCnt = "<div>NO FILE {$urlIncRel} in {$urlAbs} !!!</div>";
            }
            $sIncludeHead = str_replace([$urlIncRel, 'include'], [$urlIncAbs, 'include beginning'], $sInclude);
            $txtCnt = str_replace($sInclude, $sIncludeHead . $txtIncCnt . "<!-- include ending src=\"{$urlIncAbs}\" -->", $txtCnt);
        }
    }
    if ($urlRootPage === $urlAbs) {
        if (!DEVELOPING) {
            array_walk($aCss, function ($value, $key) {
                $fileLess = str_replace(".css", ".less", WEBROOT_AT_DISK . $value);
                $fileCss = WEBROOT_AT_DISK . $value;
                $command = "lessc --clean-css {$fileLess} {$fileCss} -s";
                exec($command, $output, $returnCode);
                if ($returnCode !== 0) {
                    echo "{$command} excuted error!!!<br>";
                }
            });
        }
        $aCss = packageResources($aCss);
        array_walk($aCss, function (&$value, $key) {
            $value = "<link rel=\"stylesheet\" href=\"{$value}\">";
        });
        $aJs = packageResources($aJs);
        usort($aJs, "jsRacing");
        array_walk($aJs, function (&$value, $key) {
            $value = "<script src=\"{$value}\"></script>";
        });
        $regScriptOthers = '/<script src="[^"]+?\\.js"><\\/script>/i';
        preg_match_all($regScriptOthers, $txtCnt, $aOthers);
        $aOthers = $aOthers[0];
        $txtCnt = str_replace($aOthers, '', $txtCnt);
        $txtCnt = str_replace(['</head>', '</body>'], [implode(PHP_EOL, $aCss) . '</head>', implode(PHP_EOL, $aOthers) . implode(PHP_EOL, $aJs) . '</body>'], $txtCnt);
        $txtCnt = preg_replace($regSrc, WEBROOT_AT_HOST . "\$1", $txtCnt);
        writeFile(PACKAGE_AT_HOST . $urlAbs, $txtCnt);
        $urlRootPage = '';
        $aCss = $aJs = [];
    }
    return $txtCnt;
}
Exemplo n.º 8
0
function getConversionRate($from, $to)
{
    global $cache_tolerance, $cache_conversion, $webServiceURL;
    $cache_file = $cache_conversion . md5($from) . "-" . md5($to);
    if (isCacheValid($cache_file, $cache_tolerance)) {
        return file_get_contents($cache_file);
    }
    $url = $webServiceURL . "?from=" . $from . "&to=" . $to;
    $cache_contents = updateCache($cache_file, $url);
    if (strlen($cache_contents) > 0) {
        $cache_file_reverse = $cache_conversion . md5($to) . "-" . md5($from);
        $reverse_response = getReverseResponse($cache_contents);
        if (strlen($reverse_response) > 0) {
            writeCache($cache_file_reverse, $reverse_response);
        }
    } else {
        $cache_contents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response>\n<conversion-rate>0.0</conversion-rate>\n<date>:-(</date>\n</response>";
    }
    return $cache_contents;
}
Exemplo n.º 9
0
function ArcadeInfoPanelBlock()
{
    global $context, $txt, $arcSettings, $scripturl;
    $no = 5;
    echo '
	<table width="100%" border="0" cellpadding="1">
		<tr>
			<td colspan="2"><div align="center"><span><i><b>', $txt['arcade_info'], '</b></i></span></div></td>
		</tr>
		<tr>
			<td><span class="middletext">';
    echo '
	<script type="text/javascript">
		var pausecontent=new Array()
		';
    if ($arcSettings['enable_arcade_cache'] == 1) {
        ob_start();
        if (!($cache3Best = readCache('arcadeinfopanel.cache', 86400))) {
            echo 'pausecontent[0]="', addslashes(ArcadeInfoBestPlayers($no)), '";
			';
            echo 'pausecontent[1]="', addslashes(ArcadeInfoNewestGames($no)), '";
			';
            echo 'pausecontent[2]="', addslashes(Arcade3champsBlock($no)), '";
			';
            echo 'pausecontent[3]="', addslashes(ArcadeInfoMostPlayed($no)), '";
			';
            echo 'pausecontent[4]="', addslashes(ArcadeInfoLongestChamps($no)), '";
			';
            $cache3Best = ob_get_contents();
            ob_clean();
            writeCache($cache3Best, 'arcadeinfopanel.cache');
            ob_end_clean();
        }
        echo $cache3Best;
        ob_start();
        if (!($cacheGotd = readCache('gotd.cache', 86400))) {
            echo 'pausecontent[5]="', addslashes(ArcadeGOTDBlock()), '";
			';
            $cacheGotd = ob_get_contents();
            ob_clean();
            writeCache($cacheGotd, 'gotd.cache');
            ob_end_clean();
        }
        echo $cacheGotd;
    } else {
        echo 'pausecontent[0]="', addslashes(ArcadeInfoBestPlayers($no)), '";
			';
        echo 'pausecontent[1]="', addslashes(ArcadeInfoNewestGames($no)), '";
			';
        echo 'pausecontent[2]="', addslashes(Arcade3champsBlock($no)), '";
			';
        echo 'pausecontent[3]="', addslashes(ArcadeInfoMostPlayed($no)), '";
			';
        echo 'pausecontent[4]="', addslashes(ArcadeInfoLongestChamps($no)), '";
			';
        echo 'pausecontent[5]="', addslashes(ArcadeGOTDBlock()), '";
			';
    }
    echo 'pausecontent[6]="', addslashes(ArcadeRandomGameBlock()), '";
	';
    echo '</script>
	<style type="text/css">
	#pescroller1{
	height: 220px;
	border: 0px solid black;
	padding: 5px;
	}

	.someclass{ //class to apply to your escroller(s) if desired
	}

	</style>
	<script type="text/javascript">

	/***********************************************
	* Pausing up-down escroller- © Dynamic Drive (www.dynamicdrive.com)
	* This notice MUST stay intact for legal use
	* Visit http://www.dynamicdrive.com/ for this script and 100s more.
	***********************************************/

	function pauseescroller(content, divId, divClass, delay){
	this.content=content //message array content
	this.tickerid=divId //ID of ticker div to display information
	this.delay=delay //Delay between msg change, in miliseconds.
	this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over escroller (and pause it if it is)
	this.hiddendivpointer=1 //index of message array for hidden div
	document.write(\'<div id="\'+divId+\'" class="\'+divClass+\'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="\'+divId+\'1">\'+content[0]+\'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="\'+divId+\'2">\'+content[1]+\'</div></div>\')
	var escrollerinstance=this
	if (window.addEventListener) //run onload in DOM2 browsers
	window.addEventListener("load", function(){escrollerinstance.initialize()}, false)
	else if (window.attachEvent) //run onload in IE5.5+
	window.attachEvent("onload", function(){escrollerinstance.initialize()})
	else if (document.getElementById) //if legacy DOM browsers, just start escroller after 0.5 sec
	setTimeout(function(){escrollerinstance.initialize()}, 500)
	}
	// -------------------------------------------------------------------
	// initialize()- Initialize escroller method.
	// -Get div objects, set initial positions, start up down animation
	// -------------------------------------------------------------------

	pauseescroller.prototype.initialize=function(){
	this.tickerdiv=document.getElementById(this.tickerid)
	this.visiblediv=document.getElementById(this.tickerid+"1")
	this.hiddendiv=document.getElementById(this.tickerid+"2")
	this.visibledivtop=parseInt(pauseescroller.getCSSpadding(this.tickerdiv))

	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"
	var escrollerinstance=this
	document.getElementById(this.tickerid).onmouseover=function(){escrollerinstance.mouseoverBol=1}
	document.getElementById(this.tickerid).onmouseout=function(){escrollerinstance.mouseoverBol=0}
	if (window.attachEvent) //Clean up loose references in IE
	window.attachEvent("onunload", function(){escrollerinstance.tickerdiv.onmouseover=escrollerinstance.tickerdiv.onmouseout=null})
	setTimeout(function(){escrollerinstance.animateup()}, this.delay)
	}

	// -------------------------------------------------------------------
	// animateup()- Move the two inner divs of the escroller up and in sync
	// -------------------------------------------------------------------

	pauseescroller.prototype.animateup=function(){
	var escrollerinstance=this
	if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
	this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
	this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
	setTimeout(function(){escrollerinstance.animateup()}, 50)
	}
	else{
	this.getinline(this.hiddendiv, this.visiblediv)
	this.swapdivs()
	setTimeout(function(){escrollerinstance.setmessage()}, this.delay)
	}
	}

	// -------------------------------------------------------------------
	// swapdivs()- Swap between which is the visible and which is the hidden div
	// -------------------------------------------------------------------

	pauseescroller.prototype.swapdivs=function(){
	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
	}

	pauseescroller.prototype.getinline=function(div1, div2){
	div1.style.top=this.visibledivtop+"px"
	div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
	}

	// -------------------------------------------------------------------
	// setmessage()- Populate the hidden div with the next message before it\'s visible
	// -------------------------------------------------------------------

	pauseescroller.prototype.setmessage=function(){
	var escrollerinstance=this
	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
	setTimeout(function(){escrollerinstance.setmessage()}, 100)
	else{
	var i=this.hiddendivpointer
	var ceiling=this.content.length
	this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
	this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
	this.animateup()
	}
	}

	pauseescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
	if (tickerobj.currentStyle)
	return tickerobj.currentStyle["paddingTop"]
	else if (window.getComputedStyle) //if DOM2
	return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
	else
	return 0
	}

	</script>
	<script type="text/javascript">

	//new pauseescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)
	new pauseescroller(pausecontent, "pescroller1", "someclass", 2000)
	document.write("<br />")
	</script>
	</span>
	</td>
	</tr>
	</table>
	';
}
Exemplo n.º 10
0
/**
 * Check if subnet contains slaves
 */
function subnetContainsSlaves($subnetId)
{
    # we need new temp variable for empties
    $subnetIdtmp = $subnetId;
    if (strlen($subnetIdtmp) == 0) {
        $subnetIdtmp = "root";
    }
    # check if already in cache
    if ($vtmp = checkCache("subnetcontainsslaves", $subnetIdtmp)) {
        return $vtmp;
    } else {
        global $database;
        /* get all ip addresses in subnet */
        $query = 'SELECT count(*) from `subnets` where `masterSubnetId` = "' . $subnetId . '";';
        /* execute */
        try {
            $slaveSubnets = $database->getArray($query);
        } catch (Exception $e) {
            $error = $e->getMessage();
            print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>";
            return false;
        }
        if ($slaveSubnets[0]['count(*)']) {
            writeCache("subnetcontainsslaves", $subnetIdtmp, true);
            return true;
        } else {
            writeCache("subnetcontainsslaves", $subnetIdtmp, false);
            return false;
        }
    }
}
Exemplo n.º 11
0
<?php

error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
defined('ROOT_PATH') || define('ROOT_PATH', str_replace('/public', '', dirname(__FILE__)));
function writeCache($file, $content)
{
    @($fp = fopen($file, "w"));
    @fwrite($fp, $content);
    @fclose($fp);
}
writeCache(ROOT_PATH . '/cache/gitpull', '1');
echo 'ok...';
Exemplo n.º 12
0
    }
    include_once './template/search.php';
    #echo $template;
} else {
    // show the top ten
    $LASTUPDATE = 0;
    $NEXTUPDATE = 0;
    if (isCached('home')) {
        $template = getCache('home');
        $LASTUPDATE = intToTime(getLastUpdate(getcwd() . '/cache/home.cache'));
        $NEXTUPDATE = intToTime(getNextUpdate(getcwd() . '/cache/home.cache', RANKING_REFRESH_TIME));
    } else {
        $topten = getTopTen();
        include_once './template/home.php';
        // write cache file
        writeCache('home', $template);
        $LASTUPDATE = intToTime(0);
        $NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
    }
    $template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
    $template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/***************************************************************
 * CLOSE DATABASE CONNECTION AND PROCESS PAGE LOAD TIME
 ***************************************************************/
mysql_close($link);
//processing page END
$time_end = microtime(true);
$time = round($time_end - $time_start, 4);
$template = str_replace('{:PROCESSED:}', $time, $template);
/***************************************************************