Example #1
0
 /**
  *
  * @param array $data
  * @param string $default currency
  */
 public function import(array $data, $default)
 {
     if (isset($data[0])) {
         $this->save(0, $data[0]);
         unset($data[0]);
     }
     $this->recalculateRates($data, $default);
     //default set first
     $def = $data[$default];
     unset($data[$default]);
     $data = array($default => $def) + $data;
     foreach ($data as $key => $val) {
         $dp = NULL;
         if (!$val instanceof Currency) {
             throw new BankException('Must be class Currency.');
         }
         if ($key == $default) {
             $dt = new \Nette\DateTime('tomorrow');
             if ($this->hourRefresh) {
                 list($hour, $min) = explode(':', $this->hourRefresh);
                 $dt->setTime($hour, $min, 0);
             }
             $dp = array(Caching\Cache::EXPIRATION => $dt);
         }
         $this->save($key, $val, $dp);
     }
 }
Example #2
0
 /**
  * Backup world/ folder. Provide runtime hash when you want to save running server
  * @param string $path path to folder with minecraft
  * @param string $runtimeHash
  * @return boolean
  */
 public function backup($path, $runtimeHash = NULL)
 {
     $date = new Nette\DateTime();
     $filename = $date->format('Y-m-d_H-i');
     $oldumask = umask(0);
     @mkdir($path . 'backups/', 0771);
     umask($oldumask);
     if ($this->serverCmd->isServerRunning($runtimeHash)) {
         return $this->backupRunning($path, $runtimeHash, $filename);
     } else {
         return $this->backupSwitchedOff($path, $filename);
     }
 }
Example #3
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return self
  * @throws XApp_InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     self::checkHeaders();
     setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     $this->removeDuplicateCookies();
     return $this;
 }
Example #4
0
 /**
  * Sets the amount of time allowed between requests before the session will be terminated.
  * @param  string|int|DateTime  time, value 0 means "until the browser is closed"
  * @return self
  */
 public function setExpiration($time)
 {
     if (empty($time)) {
         return $this->setOptions(array('gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME, 'cookie_lifetime' => 0));
     } else {
         $time = Nette\DateTime::from($time)->format('U') - time();
         return $this->setOptions(array('gc_maxlifetime' => $time, 'cookie_lifetime' => $time));
     }
 }
Example #5
0
 /**
  * Restricts the search by modified time.
  * @param  string  "[operator] [date]" example: >1978-01-23
  * @param  mixed
  * @return self
  */
 public function date($operator, $date = NULL)
 {
     if (func_num_args() === 1) {
         // in $operator is predicate
         if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)\\z#i', $operator, $matches)) {
             throw new Nette\InvalidArgumentException('Invalid date predicate format.');
         }
         list(, $operator, $date) = $matches;
         $operator = $operator ? $operator : '=';
     }
     $date = Nette\DateTime::from($date)->format('U');
     return $this->filter(function ($file) use($operator, $date) {
         return Finder::compare($file->getMTime(), $operator, $date);
     });
 }
Example #6
0
 /**
  * Sets the expiration of the section or specific variables.
  * @param  string|int|DateTime  time, value 0 means "until the browser is closed"
  * @param  mixed   optional list of variables / single variable to expire
  * @return self
  */
 public function setExpiration($time, $variables = NULL)
 {
     $this->start();
     if (empty($time)) {
         $time = NULL;
         $whenBrowserIsClosed = TRUE;
     } else {
         $time = Nette\DateTime::from($time)->format('U');
         $max = ini_get('session.gc_maxlifetime');
         if ($time - time() > $max + 3) {
             // bulgarian constant
             trigger_error("The expiration time is greater than the session expiration {$max} seconds", E_USER_NOTICE);
         }
         $whenBrowserIsClosed = FALSE;
     }
     if ($variables === NULL) {
         // to entire section
         $this->meta['']['T'] = $time;
         $this->meta['']['B'] = $whenBrowserIsClosed;
     } elseif (is_array($variables)) {
         // to variables
         foreach ($variables as $variable) {
             $this->meta[$variable]['T'] = $time;
             $this->meta[$variable]['B'] = $whenBrowserIsClosed;
         }
     } else {
         // to variable
         $this->meta[$variables]['T'] = $time;
         $this->meta[$variables]['B'] = $whenBrowserIsClosed;
     }
     return $this;
 }