Advertisement
Guest User

Untitled

a guest
Dec 28th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. $xmlURL = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req='.date('d/m/Y');
  3. $tpl = isset($tpl) ? $modx->getChunk($tpl) : '€ = [+euro+] Р, $ = [+usd+] Р';
  4.  
  5. //кэширование 6 часов
  6. $filename = MODX_BASE_PATH.'assets/cache/kurs.xml';
  7. if (!file_exists($filename) || (file_exists($filename) && time() > filemtime($filename) + 60*60*6)) {
  8.         $file = file_get_contents($xmlURL);
  9.         if ($file) {
  10.                 file_put_contents($filename, $file);
  11.                 @chmod($filename, 0666);
  12.         }
  13. }
  14.  
  15. $xml = simplexml_load_file($filename);
  16. if ($xml != false){
  17.         $usd = $xml->xpath('Valute[@ID="R01235"]/Value');
  18.         $usd = round(str_replace(',','.',$usd[0]),1);
  19.         $euro = $xml->xpath('Valute[@ID="R01239"]/Value');
  20.         $euro = round(str_replace(',','.',$euro[0]),1);
  21.         $output = str_replace(array('[+usd+]','[+euro+]'),array($usd,$euro),$tpl);
  22.         return $output;
  23. }
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement