Author: Mark Scherer
 /**
  * For this helper the controller has to be passed as reference
  * for manual startup with $disableStartup = true (requires this to be called prior to any other method)
  *
  * @param \Cake\Event\Event $event
  * @return void
  */
 public function startup(Event $event)
 {
     // Data preparation
     if (!empty($this->Controller->request->data) && !Configure::read('DataPreparation.notrim')) {
         $this->Controller->request->data = Utility::trimDeep($this->Controller->request->data);
     }
     if (!empty($this->Controller->request->query) && !Configure::read('DataPreparation.notrim')) {
         $this->Controller->request->query = Utility::trimDeep($this->Controller->request->query);
     }
     if (!empty($this->Controller->request->params['pass']) && !Configure::read('DataPreparation.notrim')) {
         $this->Controller->request->params['pass'] = Utility::trimDeep($this->Controller->request->params['pass']);
     }
 }
Exemple #2
0
 /**
  * Checks if a url is valid
  *
  * @param string $url
  * @return bool Success
  */
 protected function _validUrl($url)
 {
     $headers = Utility::getHeaderFromUrl($url);
     if ($headers === false) {
         return false;
     }
     $headers = implode("\n", $headers);
     $protocol = mb_strpos($url, 'https://') === 0 ? 'HTTP' : 'HTTP';
     if (!preg_match('#^' . $protocol . '/.*?\\s+[(200|301|302)]+\\s#i', $headers)) {
         return false;
     }
     if (preg_match('#^' . $protocol . '/.*?\\s+[(404|999)]+\\s#i', $headers)) {
         return false;
     }
     return true;
 }
Exemple #3
0
 /**
  * UtilityTest::testIsValidSaveAll()
  *
  * @covers ::isValidSaveAll
  * @return void
  */
 public function testIsValidSaveAll()
 {
     $result = Utility::isValidSaveAll([]);
     $this->assertFalse($result);
     $result = Utility::isValidSaveAll([true, true]);
     $this->assertTrue($result);
     $result = Utility::isValidSaveAll([true, false]);
     $this->assertFalse($result);
 }
Exemple #4
0
 /**
  * On non-transaction db connections it will return a deep array of bools instead of bool.
  * So we need to call this method inside the modified saveAll() method to return the expected single bool there, too.
  *
  * @param array
  * @return bool
  * @deprecated Not sure this is useful for CakePHP 3.0
  */
 public static function isValidSaveAll($array)
 {
     if (empty($array)) {
         return false;
     }
     $ret = true;
     foreach ($array as $key => $val) {
         if (is_array($val)) {
             $ret = $ret & Utility::logicalAnd($val);
         } else {
             $ret = $ret & $val;
         }
     }
     return (bool) $ret;
 }
 /**
  * Returns current IP address.
  * Note that in debug mode it will emulate it - and retrieve the preconfigured one.
  *
  * NEW: if many ips in row (ip1, ip2, ip3), use last (or first???) one!
  *
  * @return string IP
  */
 public static function findIp()
 {
     if ((int) Configure::read('debug') > 1) {
         if ($ip = Configure::read('App.defaultIp')) {
             return $ip;
         }
         return '127.0.0.1';
     }
     $ip = Utility::getClientIp();
     # usually getClientIp already removes multiple ips in favor of one single ip. but seems to fail sometimes
     if (strpos($ip, ',') !== false) {
         return false;
         //$ips = explode(',', $ip);
         //$ip = trim($ips[0]); # first
         //$ip = trim($ips[count($ips)-1]); # last
     }
     return $ip;
 }