private function minivardump($vars)
 {
     if (count($vars) == 0) {
         return;
     }
     $varCnt = 0;
     foreach ($vars as $var) {
         if (is_string($var)) {
             if (strlen($var) > 20) {
                 echo '<span title="' . h($var) . '">\'' . h(substr($var, 0, 20)) . '\'...</span>';
             } else {
                 echo "'" . h($var) . "'";
             }
         } else {
             if (is_numeric($var)) {
                 echo h($var);
             } else {
                 echo h(kataFunc::getValueInfo($var));
             }
         }
         $varCnt++;
         if ($varCnt > 2 && count($vars) > 2) {
             echo '...';
             break;
         }
         if ($varCnt < count($vars)) {
             echo ', ';
         }
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     $start = microtime(true);
     $this->result = mysql_query($sql, $this->link);
     if (false === $this->result) {
         switch (mysql_errno($this->link)) {
             case 1062:
                 throw new DatabaseDuplicateException(mysql_error($this->link));
                 break;
             default:
                 writeLog(mysql_error($this->link) . ': ' . $sql, 1);
                 throw new DatabaseErrorException(mysql_error($this->link), $sql);
                 break;
         }
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), mysql_affected_rows($this->link), mysql_error($this->link), microtime(true) - $start . 'sec');
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->link) {
         $this->connect();
     }
     $start = microtime(true);
     $error = '';
     $this->result = $this->link->query($sql);
     if (false === $this->result) {
         $error = implode(';', $this->link->errorInfo());
         writeLog($error . ': ' . $sql, 1);
         throw new DatabaseErrorException($error, $sql);
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), false !== $this->result ? $this->result->rowCount() : '', $error, microtime(true) - $start . 'sec');
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->link) {
         $this->connect();
     }
     $start = microtime(true);
     $error = 0;
     $this->result = $this->link->query($sql);
     if (false === $this->result) {
         writeLog($this->link->lastErrorMsg() . ': ' . $sql, 1);
         throw new DatabaseErrorException($this->link->lastErrorMsg());
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), $this->link->changes(), $this->link->lastErrorMsg(), microtime(true) - $start . 'sec');
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->link) {
         $this->connect();
     }
     $start = microtime(true);
     $this->result = mssql_query($sql, $this->link);
     if (false === $this->result) {
         $msg = mssql_get_last_message();
         //TODO another way would be to check @@ERROR for errors 2601/2627 which is ALSO language dependend *facepalm*
         if (stripos($msg, 'duplicate') !== false) {
             DatabaseDuplicateException($msg);
         } else {
             writeLog($msg . ': ' . $sql, 1);
             throw new DatabaseErrorException($msg, $sql);
         }
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), '', mssql_get_last_message(), microtime(true) - $start . 'sec');
     }
 }
 /**
  * set key only if the stored casToken equals our castoken (=key is unchanged)
  * @param float $casToken castoken previously obtained by readCas
  * @param string $id keyname
  * @param string $value keyvalue
  * @param integer $ttl time to live in seconds
  * @param string|bool $forceMethod method to use
  * @return boolean
  */
 public function compareAndSwap($casToken, $id, $value, $ttl = 0, $forceMethod = false)
 {
     if (DEBUG > 2) {
         $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, '*caching off*', 0);
         return false;
     }
     $startTime = microtime(true);
     $this->initialize();
     $id = CACHE_IDENTIFIER . '-' . $id;
     if (false === $forceMethod) {
         $this->method = $this->defaultMethod;
     } else {
         $this->method = $forceMethod;
     }
     if (self::CM_MEMCACHED == $this->method) {
         $this->initMemcached(true);
         $r = $this->memcachedClass->cas($casToken, $id, $value, $ttl);
         $done = true;
         if ($r && $this->memcachedClass->getResultCode() == Memcached::RES_SUCCESS) {
             $done = true;
         }
         $done = false;
         if (DEBUG > 0) {
             $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, $done ? 'swapped' : 'my data is stale', microtime(true) - $startTime);
         }
         return $done;
     }
     throw new Exception('ExtCacheUtil: compareAndSwap works only with memcache(d)');
 }
 /**
  * extract,clean and dequote any given get/post-parameters
  * find out which controller and view we should use
  * @param string $url raw url (see dispatch())
  */
 private function constructParams($url)
 {
     $paramList = explode('/', $url);
     while (count($paramList) > 0 && '' == $paramList[count($paramList) - 1]) {
         array_pop($paramList);
     }
     $ajax = 0;
     if (isset($paramList[0]) && $paramList[0] == 'ajax') {
         array_shift($paramList);
         $ajax = 1;
     }
     $controller = "main";
     if (isset($paramList[0]) && !empty($paramList[0])) {
         $controller = strtolower(array_shift($paramList));
     }
     $action = '';
     if (isset($paramList[0]) && !empty($paramList[0])) {
         $action = strtolower(array_shift($paramList));
     } else {
         if (isset($paramList[0])) {
             unset($paramList[0]);
         }
     }
     $this->params['pass'] = $paramList;
     $kataUrl = is($_GET['kata'], '');
     unset($_GET['kata']);
     if (!empty($_GET)) {
         if (ini_get('magic_quotes_gpc') == 1) {
             $this->params['url'] = kataFunc::stripslashes_deep($_GET);
         } else {
             $this->params['url'] = $_GET;
         }
     }
     if (!empty($_POST)) {
         if (ini_get('magic_quotes_gpc') == 1) {
             $this->params['form'] = kataFunc::stripslashes_deep($_POST);
         } else {
             $this->params['form'] = $_POST;
         }
     }
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         $ajax = 1;
     }
     $this->params['controller'] = $controller;
     $this->params['action'] = $action;
     $this->params['https'] = env('HTTPS') != '' ? 1 : 0;
     $this->params['ajax'] = $ajax;
     if (php_sapi_name() == 'cli') {
         $this->params['type'] = 'cli';
     } else {
         $this->params['type'] = env('REQUEST_METHOD');
     }
     $this->params['raw'] = $kataUrl;
 }
 /**
  * @ignore
  * @param mixed $var variable to dump
  * @param bool $isTable if variable is an array we use a table to display each line
  */
 function kataDebugOutput($var = null, $isTable = false)
 {
     kataFunc::debugOutput($var, $isTable);
 }
 /**
  * extract,clean and dequote any given get/post-parameters
  * find out which controller and view we should use
  * @param string $url raw url (see dispatch())
  */
 private function constructParams($url, $routes = null)
 {
     //do we have routes?
     if (!empty($routes) && is_array($routes)) {
         krsort($routes);
         if (!empty($routes[$url])) {
             $url = $routes[$url];
         } else {
             foreach ($routes as $old => $new) {
                 //					if (($old != '') && ($old.'/' == substr($url, 0, strlen($old.'/')))) {
                 if ($old != '' && $old == substr($url, 0, strlen($old))) {
                     $url = $new . substr($url, strlen($old));
                     break;
                 }
             }
             //foreach
         }
         //!empty
         // does route-target have a query-string? parse it
         $x = strpos($url, '?');
         if (false !== $x) {
             $result = array();
             parse_str(substr($url, $x + 1), $result);
             $_GET = array_merge($_GET, $result);
             $url = substr($url, 0, $x - 1);
         }
     }
     $paramList = explode('/', $url);
     while (count($paramList) > 0 && '' == $paramList[count($paramList) - 1]) {
         array_pop($paramList);
     }
     if (isset($paramList[0]) && $paramList[0] == 'ajax') {
         array_shift($paramList);
         $this->params['isAjax'] = 1;
     } else {
         $this->params['isAjax'] = 0;
     }
     $controller = "main";
     if (isset($paramList[0]) && !empty($paramList[0])) {
         $controller = strtolower(array_shift($paramList));
     }
     $action = '';
     if (isset($paramList[0]) && !empty($paramList[0])) {
         $action = strtolower(array_shift($paramList));
     } else {
         if (isset($paramList[0])) {
             unset($paramList[0]);
         }
     }
     $this->params['pass'] = $paramList;
     $kataUrl = is($_GET['kata'], '');
     unset($_GET['kata']);
     if (!empty($_GET)) {
         if (ini_get('magic_quotes_gpc') == 1) {
             $this->params['url'] = kataFunc::stripslashes_deep($_GET);
         } else {
             $this->params['url'] = $_GET;
         }
     }
     $this->params['callUrl'] = $kataUrl;
     if (!empty($_POST)) {
         if (ini_get('magic_quotes_gpc') == 1) {
             $this->params['form'] = kataFunc::stripslashes_deep($_POST);
         } else {
             $this->params['form'] = $_POST;
         }
     }
     $this->params['controller'] = $controller;
     $this->params['action'] = $action;
 }
 function read($id, $forceMethod = false)
 {
     if (DEBUG > 2) {
         $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, '*caching off*', 0);
         return false;
     }
     if ($this->useRequestCache && isset($this->requestCache[$id])) {
         $data = $this->requestCache[$id];
         if (DEBUG > 0) {
             $this->results[] = array(kataFunc::getLineInfo(), 'reqCache', $id, kataFunc::getValueInfo($data), 0);
         }
         return $data;
     }
     $startTime = microtime(true);
     $this->initialize();
     $data = $this->_read($id, $forceMethod);
     if (DEBUG > 0) {
         $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, kataFunc::getValueInfo($data), microtime(true) - $startTime);
     }
     if ($this->useRequestCache) {
         $this->requestCache[$id] = $data;
     }
     return $data;
 }