/** * Checks if the passed string is a valid email address. * * @param string The email address to check. * @return boolean True if the email is a valid format, false if not. */ function is_email_address($email) { // If the email is empty it can't be valid if (empty($email)) { return false; } // If the email doesnt have exactle 1 @ it isnt valid if (isc_substr_count($email, '@') != 1) { return false; } $matches = array(); $local_matches = array(); preg_match(':^([^@]+)@([a-zA-Z0-9\\-][a-zA-Z0-9\\-\\.]{0,254})$:', $email, $matches); if (count($matches) != 3) { return false; } $local = $matches[1]; $domain = $matches[2]; // If the local part has a space but isnt inside quotes its invalid if (isc_strpos($local, ' ') && (isc_substr($local, 0, 1) != '"' || isc_substr($local, -1, 1) != '"')) { return false; } // If there are not exactly 0 and 2 quotes if (isc_substr_count($local, '"') != 0 && isc_substr_count($local, '"') != 2) { return false; } // if the local part starts or ends with a dot (.) if (isc_substr($local, 0, 1) == '.' || isc_substr($local, -1, 1) == '.') { return false; } // If the local string doesnt start and end with quotes if ((isc_strpos($local, '"') || isc_strpos($local, ' ')) && (isc_substr($local, 0, 1) != '"' || isc_substr($local, -1, 1) != '"')) { return false; } preg_match(':^([\\ \\"\\w\\!\\#\\$\\%\\&\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~\\.]{1,64})$:', $local, $local_matches); // Check the domain has at least 1 dot in it if (isc_strpos($domain, '.') === false) { return false; } if (!empty($local_matches)) { return true; } else { return false; } }
/** * Convert a URL to a location in the file system based on the Interspire Shopping Cart URL. * * @param string The URL to convert to a relative path on the file system. * @param string An error message, passed by reference. * @return string The file system path to the URL. */ public function URLToPath($url, &$err) { if (isc_substr($GLOBALS['ShopPath'], -1) == '/') { $GLOBALS['ShopPath'] = isc_substr($GLOBALS['ShopPath'], 0, -1); } $ourURL = @parse_url($GLOBALS['ShopPath']); $theirURL = @parse_url($url); if (!is_array($ourURL) && !is_array($theirURL) || $theirURL['scheme'] != 'http') { $err = GetLang('InvalidImportURL'); return false; } if ($ourURL['host'] != $theirURL['host']) { $err = GetLang('InvalidImportURLDomain'); return false; } if (isset($ourURL['path'])) { $upDirectories = str_repeat("../", isc_substr_count($ourURL['path'], "/")); } else { $upDirectories = ''; } if (isset($theirURL['path'])) { if (isc_substr($theirURL['path'], 0, 1) == "/") { $theirURL['path'] = isc_substr($theirURL['path'], 1); } } else { $theirURL['path'] = ''; } return APP_ROOT . "/../" . $upDirectories . $theirURL['path']; }