/**
  * initialize internal structures
  */
 protected function initialize($checkForType = false)
 {
     if (!defined('MEMCACHED_SERVERS') || strlen(MEMCACHED_SERVERS) == 0) {
         throw new RuntimeException('clusterlockutil: no memcached-servers defined in config');
     }
     if (null === $this->cacheUtil) {
         $this->cacheUtil = getUtil('Cache');
     }
     if ($checkForType) {
         if (false === $this->forceType) {
             throw new Exception('call setCacheType() first');
         }
     }
 }
Пример #2
0
 /**
  * look up ip and return 2-char country code
  *
  * @param string $ip optional, if empty will use iputility to obtain ip
  * @return array 'de' or '--' if unshure
  * @throws ErrorException
  */
 function lookup($ip = '')
 {
     if (empty($ip)) {
         $ipUtil = getUtil('Ip');
         $ip = $ipUtil->getIp();
     }
     if (function_exists('geoip_country_code_by_name')) {
         $temp = geoip_country_code_by_name($ip);
         if (!empty($temp)) {
             return $temp;
         }
         return '--';
     }
     if (is_file($this->cmdLine)) {
         $ret = shell_exec($this->cmdLine . ' ' . $ip);
         if (!empty($ret)) {
             foreach ($ret as $line) {
                 $temp = explode(':', $line);
                 if (!empty($line[1])) {
                     $parts = explode(',', $line);
                     if (!empty($parts[0]) && '--' != $parts[0]) {
                         return $parts[0];
                     }
                     //if !--
                 }
                 //!empty(line)
             }
             //foreach
         }
         //empty $ret
     }
     //file
     if (class_exists('Net_GeoIP')) {
         $inst = NetGeoIP::getInstance();
         $temp = $inst->lookupCountryCode($ip);
         if (!empty($temp)) {
             return $temp;
         }
         return '--';
     }
     throw new ErrorException('geoip: no extension, no binary, no pear-class/db, fatal error');
 }
Пример #3
0
 /**
  * tries to reduce all fields of the given table to basic datatypes
  *
  * @param string $tableName optional tablename to use
  * @return array
  */
 function &describe($tableName = null)
 {
     $tableName = $this->getTableName($tableName);
     $cacheUtil = getUtil('Cache');
     $cacheId = 'describe.' . $this->connection . '.' . $tableName;
     $data = $cacheUtil->read($cacheId, CacheUtility::CM_FILE);
     if (false !== $data) {
         return $data;
     }
     $data = $this->dbo()->describe($tableName);
     $cacheUtil->write($cacheId, $data, MINUTE, CacheUtility::CM_FILE);
     return $data;
 }
Пример #4
0
 /**
  * compress given css-string
  * 
  * @param string $css styles to compress
  * @return string the compressed css
  */
 function compressCss($css)
 {
     $minifyUtil = getUtil('Minify');
     return $minifyUtil->css($css);
 }
 function validateModel($method, $modelname)
 {
     $method = $this->normalizeMethod($method);
     $modelname = strtolower($modelname);
     if (empty($this->params[$method][$modelname])) {
         return array();
     }
     $validateUtil = getUtil('Validate');
     $result = $validateUtil->checkAllWithModel($modelname, $this->params[$method][$modelname]);
     $this->set('__validateErrors', array($modelname => $result));
     return $result;
 }
Пример #6
0
 /**
  * return the given javascript-string in compressed form
  * 
  * @param string $js your javascript
  * @return string your javascript compressed
  */
 function compress($js)
 {
     $minifyUtil = getUtil('Minify');
     return $minifyUtil->js($js);
 }
    {
        echo "{$s}\n";
    }
} else {
    function msg($s)
    {
    }
}
clearstatcache();
$isWindows = substr(PHP_OS, 0, 3) == 'WIN';
////////////////////////////////////////////////////////////////////////////////
if ($isWindows) {
    msg('Detected windows, skipping lockfiles cleanup');
} else {
    msg('Cleaning up lockfiles');
    $lockUtil = getUtil('Lock');
    $lockUtil->garbageCollect(true);
}
msg('Cleaning up sessions');
$sessDir = KATATMP . 'sessions' . DS;
if (file_exists($sessDir) && is_dir($sessDir)) {
    $timeOut = 2400;
    //php default
    if (defined('SESSION_TIMEOUT')) {
        $timeOut = SESSION_TIMEOUT;
    }
    $timeLimit = time() - 2 * $timeOut;
    $dh = opendir($sessDir);
    if ($dh) {
        while (($file = readdir($dh)) !== false) {
            if (substr($file, 0, 5) == 'sess_' && is_file($sessDir . $file)) {