function generateJson() { date_default_timezone_set('Asia/Dhaka'); $time1 = new DateTime(date('Y-m-d h:i:s')); $time2 = new DateTime(date('Y-m-d h:i:s', filectime('cache/dseData.json'))); $interval = $time1->diff($time2); if ($interval->i > 0 || file_exists('cache/dseData.json') === false) { unlink('cache/dseData.json'); $api = new Request(); saveCache('cache', "dseData.json", $api->getResponse('json')); } }
function FootergetContent($url, $fileName) { $content = file_get_contents($url); $start = strpos($content, '<footer>'); $end = strpos($content, '</footer>') + strlen('</footer>'); # mb_strlen not necessary here $footer = substr($content, $start, $end - $start); # transformation //$footer = str_replace('http://www.special-t.com/prehome/index.php?redirect=no', 'http://special-t.custhelp.com/app/country', $footer); if ($GLOBALS['SPT_ENV'] == "UAT") { //$footer = str_replace('https://'.$GLOBALS['SPT_PAYS'].'.special-t.com/', 'http://uat.'.$GLOBALS['SPT_PAYS'].'.special-t.com/', $footer); $footer = str_replace($GLOBALS['SPT_PAYS'] . '.special-t.com', 'uat.' . $GLOBALS['SPT_PAYS'] . '.special-t.com', $footer); } if ($GLOBALS['SPT_ENV'] == "INT") { //$footer = str_replace('https://'.$GLOBALS['SPT_PAYS'].'.special-t.com/', 'http://uat.'.$GLOBALS['SPT_PAYS'].'.special-t.com/', $header); $footer = str_replace($GLOBALS['SPT_PAYS'] . '.special-t.com', 'preprd' . $GLOBALS['SPT_PAYS'] . '-web1.special-t.com', $footer); } # check here if we need to change something for the search $footer = FooterremoveLineFind($footer, 'Varien.searchForm'); $footer = FooterremoveLineFind($footer, 'initAutocomplete'); $domain_cart = $GLOBALS['SPT_HOST'] . 'spt_' . $GLOBALS['SPT_STORE']; $footer = str_replace('</footer>', '<script>function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var obj = JSON.parse(xmlhttp.responseText); var html = obj.cart_sidebar.replace("#topCartContent", "' . $domain_cart . '/checkout/cart/"); var end = html.indexOf("<div id=\\"topCartContent\\""); if (end > 0) html = html.substring(0, end) + "</div>"; document.getElementById("cart_sidebar").innerHTML = html; } } xmlhttp.open("GET","' . $domain_cart . '/ajaxifier/call/index/?no_cache&handles=default,STORE_spt_fr_ch,THEME_frontend_enterprise_nestle,CATEGORY_CAT_CODE_accessories,customer_logged_out,MAP_popup,SHORTCUT_popup,SHORTCUT_uk_popup&blocks=cart_sidebar",true); xmlhttp.send(); } if(window.location.hostname.indexOf("special-t.com")>-1) loadXMLDoc(); </script> </footer></div></div>', $footer); echo $footer; saveCache($fileName, $footer); }
function fGetTweets($user = '', $count = 3) { $file = dirname('.') . $user . '.json'; $options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET); OAuthStore::instance("2Leg", $options); $json = new Services_JSON(); $last = getCacheLastModified($file); $now = time(); if (!$last || $now - $last > REFRESH_INTERVAL) { $response = readTimeline($user, $count); saveCache($file, $response); } else { $response = readCache($file); } $response = $json->decode($response); $response = wrapTweets($response); return $response; }
function getShareToken($appid, $appsecrect, $noncestr, $fileurl, $timestamp) { $GLOBALS["appid"] = $appid; $GLOBALS["appsecrect"] = $appsecrect; $GLOBALS["noncestr"] = $noncestr; $GLOBALS["file"] = $fileurl; $GLOBALS["timestamp"] = $timestamp; if (!file_exists($GLOBALS["file"])) { saveCache($appid, $appsecrect); } else { $cache = file_get_contents($GLOBALS["file"]); $cache = unserialize($cache); $now = time(); if ($now - $cache["time"] > 5400) { saveCache($appid, $appsecrect); } else { $GLOBALS["atoken"] = $cache["token"]; $GLOBALS["aticket"] = $cache["ticket"]; } } }
function HeadergetContent($url, $fileName) { # not used finally, kept just in case $emptyCart = '<div class="cart-nav top-cart" id="top-cart-ajax"> <a href="#topCartContent" class="top-cart-link"> <div class="block-title no-items" id="cartheaderPopupCart"> <span class="number-product">0</span> <p>Panier <span class="price01"><span class="price">0,00 EUR</span></span></p> </div> </a> <div style="display: none; margin: 0px; position: absolute; z-index: 10004;" class="popin modal modalTopCart" id="topCartContent"> <div class="longcontent" id="topCartContentPopup"> <div class="inner-wrapper"> <div class="cart-full clearfix"> <a href="#" title="" class="closePopin"> </a> <h2> <span class="cart-empty">Il n\'y a pas d\'article dans votre panier.</span> </h2> </div> </div> </div> </div> </div>'; $content = file_get_contents($url); $start = strpos($content, '<header>'); $end = strpos($content, '</header>') + strlen('</header>'); # mb_strlen not necessary here # we need the wrapper div to englobe header, see footer for closing divs $header = '<div class="wrapper container_24"><div class="page">' . substr($content, $start, $end - $start); # transformation //$header = str_replace('http://www.special-t.com/prehome/index.php?redirect=no', 'http://special-t.custhelp.com/app/country', $header); $header = str_replace('li class=current', 'li style="text-decoration: underline"', $header); $header = str_replace('#customer-service', '/app', $header); // Country Link; $header = str_replace('http://' . $GLOBALS['SPT_PAYS'] . '.special-t.com/spt_' . $GLOBALS['SPT_ALT_LNG'] . '_' . $GLOBALS['SPT_PAYS'] . '/press', 'http://special-t-' . $GLOBALS['SPT_ALT_LNG'] . '-' . $GLOBALS['SPT_PAYS'] . ($GLOBALS['SPT_ENV'] == "INT" ? '--pro' : '') . ($GLOBALS['SPT_ENV'] == "UAT" ? '--tst' : '') . '.custhelp.com/', $header); if ($GLOBALS['SPT_ENV'] == "PRD") { //$header = str_replace('http://www.special-t.com/prehome/index.php?redirect=no', '/app/country', $header); } if ($GLOBALS['SPT_ENV'] == "UAT") { //$header = str_replace('https://'.$GLOBALS['SPT_PAYS'].'.special-t.com/', 'http://uat.'.$GLOBALS['SPT_PAYS'].'.special-t.com/', $header); //$header = str_replace('http://www.special-t.com/prehome/index.php?redirect=no', 'http://uat.www.special-t.com/prehome/index.php', $header); $header = str_replace($GLOBALS['SPT_PAYS'] . '.special-t.com', 'uat.' . $GLOBALS['SPT_PAYS'] . '.special-t.com', $header); } if ($GLOBALS['SPT_ENV'] == "INT") { //$header = str_replace('https://'.$GLOBALS['SPT_PAYS'].'.special-t.com/', 'http://uat.'.$GLOBALS['SPT_PAYS'].'.special-t.com/', $header); //$header = str_replace('http://www.special-t.com/prehome/index.php?redirect=no', 'http://preprd-web1.special-t.com/prehome/index.php', $header); $header = str_replace($GLOBALS['SPT_PAYS'] . '.special-t.com', 'preprd' . $GLOBALS['SPT_PAYS'] . '-web1.special-t.com', $header); } # check here if we need to change something for the search $header = HeaderremoveLineFind($header, 'Varien.searchForm'); $header = HeaderremoveLineFind($header, 'initAutocomplete'); # check here when we need to manipulate the login $header = HeaderremoveLineFind($header, "BlocksAjax.addBlock('loginLink"); # remove JS cart $header = str_replace("BlocksAjax.addBlock('cart_sidebar');", '', $header); # search with Rightnow and not Magento $tmp = " onsubmit=\"k=document.getElementById('search').value; if(k=== '') return false; window.location = '/app/answers/list/st/5/kw/' + k + '/page/1'; return false;\" "; $header = str_replace('="search_mini_form"', '="search_mini_form"' . $tmp, $header); # straight from Magento $header = str_replace('=search_mini_form ', '=search_mini_form ' . $tmp, $header); # in case it is cached by Imperva ! echo $header; saveCache($fileName, $header); }
<h1>language cache updater</h1> <p><?php $files = parseDirectory($OUTPUTPATH, 'pmo'); $availableLanguages = array(); foreach ($files as $file) { if (!preg_match("/singapore\\.([\\w]+)\\.pmo\$/i", $file, $matches)) { continue; } $i18n = Translator::getInstance($matches[1]); $i18n->readLanguageFile($sgConfig->base_path . $sgConfig->pathto_locale . "singapore." . $i18n->language . ".pmo"); $availableLanguages[$matches[1]] = $i18n->languageStrings[0]['language']; echo "Added {$matches['1']} => " . $i18n->languageStrings[0]['language'] . " to available languages.<br />\n"; } //add english which has no translation files $availableLanguages["en"] = "English"; ksort($availableLanguages); if (saveCache($availableLanguages, $OUTPUTFILE)) { echo "Cache file saved as " . $OUTPUTFILE; } else { echo "Could not save cache file as " . $OUTPUTFILE; } ?> </p> <p>All operations complete. <a href="index.html">Return</a> to tools.</p> </body> </html>
} /* else { echo $f; echo date(" Y-m-d H:i:s ", $t); echo date("Y-m-d H:i:s\n", $remoteFiles[$f]); }*/ } echo "OK\n"; if (count($localFiles) == 0) { echo "No files need to upload.\n"; die; } upload($ftp, $remoteRoot, $localRoot, array_keys($localFiles)); ftp_close($ftp); echo "Saving local file cache..."; if (saveCache($cache, $localRoot)) { echo "OK\n"; } else { echo "Failed\n"; } } function getFtpConnection($host, $port, $user, $pass, $active) { echo "Connecting to FTP server..."; $ftp = @ftp_connect($host, $port); if ($ftp === false) { echo "Failed!\n"; die; } else { echo "OK\n"; }
private function saveRequestCache($request, $login, $xml, $optionsArray) { saveCache(makeRequestPath($request, $login, $optionsArray), $xml); }