/** * Returns canonicalized absolute pathname to a file or directory. * * This works with non-existant paths. For directories there won't be a trailing slash. * * LICENSE: * This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @author Michael Wallner <*****@*****.**> * @copyright 2004-2005 Michael Wallner * @license PHP License 3.0 http://www.php.net/license/3_0.txt * @link http://pear.php.net/package/File * @param string Path to canonicalize to absolute path * @param string Directory Seperator (default: Value from DIRECTORY_SEPERATOR) * @return string Canonicalized absolute pathname * @static */ public static function realPath($path, $separator = DIRECTORY_SEPARATOR) { if (!strlen($path)) { return $separator; } $drive = ''; if (SystemEnvironment::isWindows() == true) { $path = preg_replace('/[\\\\\\/]/', $separator, $path); if (preg_match('/([a-zA-Z]\\:)(.*)/', $path, $matches)) { $drive = $matches[1]; $path = $matches[2]; } else { $cwd = getcwd(); $drive = substr($cwd, 0, 2); if ($path[0] !== $separator[0]) { $path = substr($cwd, 3) . $separator . $path; } } } elseif ($path[0] !== $separator) { $path = getcwd() . $separator . $path; } $dirStack = array(); foreach (explode($separator, $path) as $dir) { if (strlen($dir) && $dir !== '.') { if ($dir == '..') { array_pop($dirStack); } else { $dirStack[] = $dir; } } } return $drive . $separator . implode($separator, $dirStack); }
public function suggest() { $data = array(); $id = Request::get(1, VAR_INT); $q = Request::get('q'); $q = SystemEnvironment::fromUtf8($q); $db = Database::getObject(); $db->query("SELECT * FROM <p>fields WHERE id = <id:int>", compact("id")); if ($db->numRows() == 1) { $field = CustomField::constructObject($db->fetchAssoc()); if ($field instanceof CustomAutoCompleteTextField) { $data = $field->getList($q); } } Response::getObject()->sendHeader('Content-Type: text/plain; charset=' . Config::get('intl.charset')); echo implode("\n", $data); }
public static function checkMX($host) { if (empty($host)) { return false; } $host_idna = self::normalizeHost($host); if (SystemEnvironment::functionExists('checkdnsrr')) { if (checkdnsrr($host_idna, 'MX') === false) { return false; } else { return true; } } else { @exec("nslookup -querytype=MX {$host_idna}", $output); while (list($k, $line) = each($output)) { # Valid records begin with host name if (preg_match("~^(" . preg_quote($host) . "|" . preg_quote($host_idna) . ")~i", $line)) { return true; } } return false; } }
public static function toUtf8($string) { if (SystemEnvironment::functionExists('mb_convert_encoding')) { $string = mb_convert_encoding($string, 'UTF-8', Config::get('intl.charset')); } else { if (SystemEnvironment::functionExists('iconv')) { $string = iconv(Config::get('intl.charset'), 'UTF-8', $string); } else { $string = utf8_encode($string); } } return $string; }