Beispiel #1
0
 private static function parseValue($arg, $key)
 {
     if (false === ($back = Common::regex('/(\\d{1,}[\\.,]?\\d{0,3}) *' . $key . '/i', $arg))) {
         return -1;
     }
     return floatval(str_replace(',', '.', $back));
 }
Beispiel #2
0
 public static function testSmiley(WC_Challenge $chall, $smiley, $path)
 {
     $back = true;
     # Test passed :S?
     # Generate test input :)
     $ues = str_replace('\\', '', $smiley);
     $ues = Common::regex('#/([^/]+)/#', $ues);
     $text = 'Test ' . $ues . '. Test ' . $ues;
     echo GWF_Box::box($text, $chall->lang('test_input'));
     # Generate test output :)
     if (NULL === ($out = self::replaceSmiley($smiley, $path, $text))) {
         $back = false;
         $out = $text;
     }
     # Output the test :)
     echo GWF_Box::box($out, $chall->lang('test_output'));
     return $back;
 }
Beispiel #3
0
 private function getElevatorN()
 {
     $c = $this->getElevatorCity();
     $floor = Common::regex("/^{$c}([C0-9]*)_/", $this->getName());
     if ($floor === '') {
         return 0;
     } elseif ($floor[0] === 'C') {
         return -intval(substr($floor, 1), 10);
     } else {
         return intval($floor, 10) - 1;
     }
 }
Beispiel #4
0
 /**
  * 
  * @param string $url
  * @return Ambigous <string, false, boolean, unknown>
  */
 public static function getDomain($url)
 {
     $url = Common::substrFrom($url, '://', $url);
     $url = Common::substrUntil($url, '/', $url);
     return Common::regex('#([^\\.]+\\.[^\\.]+)$#D', $url);
 }
Beispiel #5
0
 public static function getByLongName($username)
 {
     if (0 === ($sid = (int) Common::regex('/^.+\\{(\\d+)\\}$/', $username))) {
         return false;
     }
     $username = Shadowfunc::toShortname($username);
     $username = self::escape($username);
     if (false === ($player = self::table(__CLASS__)->selectFirstObject('*', "sr4pl_sid={$sid} AND sr4pl_name='{$username}'"))) {
         return false;
     }
     return self::reloadPlayer($player);
 }
Beispiel #6
0
 private function getDescription($url)
 {
     # Get page content
     # TODO: Only download .txt and .html content!
     GWF_HTTP::setTimeout(10);
     GWF_HTTP::setConnectTimeout(3);
     $content = GWF_HTTP::getFromURL($url, true);
     GWF_HTTP::setTimeout();
     GWF_HTTP::setConnectTimeout();
     if ($content === false) {
         Dog_Log::error('Mod_Link::getDescription(): getFromURL() failed. URL: ' . $url);
         return false;
     }
     list($head, $content) = preg_split("/[\r\n]{4}/", $content, 2);
     $type = Common::regex('/Content-Type: *(.*)/Di', $head);
     echo $type . PHP_EOL;
     if (Common::startsWith($type, 'image')) {
         return array('image', $content);
     }
     # Get Title from html
     if (0 === preg_match('#< *title *>([^<]+)< */ *title *>#i', $content, $matches)) {
         return false;
     }
     $title = $this->decode($matches[1]);
     $descr = '';
     if (1 === preg_match('#(< *meta.*description[^>]*>)#i', $content, $matchesB)) {
         $tag = $matchesB[1];
         if (1 === preg_match('#content=["\']([^"\']+)["\']#', $tag, $matchesB)) {
             $descr = ' - ' . $this->decode($matchesB[1]);
         }
     }
     return array('html', $title . ' - ' . $descr);
 }
Beispiel #7
0
 public function getLevelNum()
 {
     $back = Common::regex('/(\\d+)/', $this->getTitle());
     return $back < 1 ? false : (int) $back;
 }
Beispiel #8
0
function warscore_get_level_num($level)
{
    return Common::regex('/(\\d+)/', $level);
}
Beispiel #9
0
 public static function matchSymbols($username)
 {
     $pattern = preg_quote(self::allSymbols());
     $pattern = "/^([{$pattern}]+)/";
     return Common::regex($pattern, $username);
 }