本文整理汇总了PHP中InputFilter类的典型用法代码示例。如果您正苦于以下问题:PHP InputFilter类的具体用法?PHP InputFilter怎么用?PHP InputFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InputFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run_create_translation
function run_create_translation($args, $opts)
{
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$opts = $filter->xssFilterHard($opts);
$args = $filter->xssFilterHard($args);
$rootDir = realpath(__DIR__."/../../../../");
$app = new Maveriks\WebApplication();
$app->setRootDir($rootDir);
$loadConstants = false;
$workspaces = get_workspaces_from_args($args);
$lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en';
$translation = new Translation();
CLI::logging("Updating labels Mafe ...\n");
foreach ($workspaces as $workspace) {
try {
echo "Updating labels for workspace " . pakeColor::colorize($workspace->name, "INFO") . "\n";
$translation->generateTransaltionMafe($lang);
} catch (Exception $e) {
echo "Errors upgrading labels for workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n";
}
}
CLI::logging("Create successful\n");
}
示例2: dump
/**
* Dump the contents of the file using fpassthru().
*
* @return void
* @throws Exception if no file or contents.
*/
function dump()
{
if (!$this->data) {
// hmmm .. must be a file that needs to read in
if ($this->inFile) {
$fp = @fopen($this->inFile, "rb");
if (!$fp) {
throw new Exception('Unable to open file: ' . $this->inFile);
}
fpassthru($fp);
@fclose($fp);
} else {
throw new Exception('No data to dump');
}
} else {
$realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
$docuroot = explode('/', $realdocuroot);
array_pop($docuroot);
$pathhome = implode('/', $docuroot) . '/';
array_pop($docuroot);
$pathTrunk = implode('/', $docuroot) . '/';
require_once $pathTrunk . 'gulliver/system/class.inputfilter.php';
$filter = new InputFilter();
$data = $filter->xssFilterHard($this->data);
echo $data;
}
}
示例3: check
/** overloaded check function */
function check()
{
// filter malicious code
$ignoreList = array('params');
$this->filter($ignoreList);
// specific filters
$iFilter = new InputFilter();
if ($iFilter->badAttributeValue(array('href', $this->url))) {
$this->_error = 'Please provide a valid URL';
return false;
}
/** check for valid name */
if (trim($this->title) == '') {
$this->_error = _WEBLINK_TITLE;
return false;
}
if (!(preg_match('http://', $this->url) || preg_match('https://', $this->url) || preg_match('ftp://', $this->url))) {
$this->url = 'http://' . $this->url;
}
/** check for existing name */
$query = "SELECT id" . "\n FROM #__weblinks " . "\n WHERE title = " . $this->_db->Quote($this->title) . "\n AND catid = " . (int) $this->catid;
$this->_db->setQuery($query);
$xid = intval($this->_db->loadResult());
if ($xid && $xid != intval($this->id)) {
$this->_error = _WEBLINK_EXIST;
return false;
}
return true;
}
示例4: getInputFilter
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$inputFilter->add(array('name' => 'id', 'required' => 'true', 'filters' => array(array('name' => 'Int'))));
$inputFilter->add(array('name' => 'jenis', 'required' => 'true', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 100)))));
$inputFilter->add(array('name' => 'inmission', 'required' => 'true'));
}
return $inputFilter;
}
示例5: getInputFilter
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array('name' => 'email', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 100))))));
$inputFilter->add($factory->createInput(array('name' => 'password', 'required' => true)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
示例6: getInputFilter
public function getInputFilter($data)
{
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array('name' => 'id', 'required' => false)));
$validator = new \DoctrineModule\Validator\NoObjectExists(array('object_repository' => $this->objectManager->getRepository($this->entityName), 'fields' => array('fullname')));
//use in check email exist when sign up
$filter = $validator->isValid(array('fullname' => $data['fullName']));
// dumps 'true' if an entity matches
return $filter;
}
示例7: filter
/**
* Filters public properties
* @access protected
* @param array List of fields to ignore
*/
function filter($ignoreList = null)
{
$ignore = is_array($ignoreList);
$iFilter = new InputFilter();
foreach ($this->getPublicProperties() as $k) {
if ($ignore && in_array($k, $ignoreList)) {
continue;
}
$this->{$k} = $iFilter->process($this->{$k});
}
}
示例8: validate_url
/**
* A validation function that returns an error if the value passed in is not a valid URL.
*
* @param string $text A string to test if it is a valid URL
* @param FormControl $control The control that defines the value
* @param FormContainer $form The container that holds the control
* @param string $warning An optional error message
* @return array An empty array if the string is a valid URL, or an array with strings describing the errors
*/
public static function validate_url($text, $control, $form, $warning = null, $schemes = array('http', 'https'), $guess = true)
{
if (!empty($text)) {
$parsed = InputFilter::parse_url($text);
if ($parsed['is_relative']) {
if ($guess) {
// guess if they meant to use an absolute link
$parsed = InputFilter::parse_url('http://' . $text);
if ($parsed['is_error']) {
// disallow relative URLs
$warning = empty($warning) ? _t('Relative urls are not allowed') : $warning;
return array($warning);
} else {
$warning = empty($warning) ? _t('Relative urls are not allowed') : $warning;
return array($warning);
}
}
}
if ($parsed['is_pseudo'] || !in_array($parsed['scheme'], $schemes)) {
// allow only http(s) URLs
$warning = empty($warning) ? _t('Only %s urls are allowed', array(Format::and_list($schemes))) : $warning;
return array($warning);
}
}
return array();
}
示例9: process
function process()
{
$input_filter = new InputFilter();
$input_filter->process($this);
if (!is_null($this->request->get("method"))) {
$basic = array('reqip' => $this->request->userip . ':' . $this->request->clientip, 'uri' => $this->request->url, 'method' => $this->request->get("method"), 'logid' => $this->requestId);
} else {
$basic = array('reqip' => $this->request->userip . ':' . $this->request->clientip, 'uri' => $this->request->url, 'logid' => $this->requestId);
}
kc_log_addbasic($basic);
$dispatch = new Dispatch($this);
App::getTimer()->set('framework prepare');
$dispatch->dispatch_url($this->request->url);
$this->response->send();
KC_LOG_TRACE('[TIME COST STATISTIC] [ ' . App::getTimer()->getString() . ' ].');
}
示例10: rangeDownload
function rangeDownload($location, $mimeType)
{
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$location = $filter->xssFilterHard($location, "path");
if (!file_exists($location)) {
header("HTTP/1.0 404 Not Found");
return;
}
$size = filesize($location);
$time = date('r', filemtime($location));
$fm = @fopen($location, 'rb');
if (!$fm) {
header("HTTP/1.0 505 Internal server error");
return;
}
$begin = 0;
$end = $size - 1;
if (isset($_SERVER['HTTP_RANGE'])) {
if (preg_match('/bytes=\\h*(\\d+)-(\\d*)[\\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
$begin = intval($matches[1]);
if (!empty($matches[2])) {
$end = intval($matches[2]);
}
}
}
header('HTTP/1.0 206 Partial Content');
header("Content-Type: {$mimeType}");
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Accept-Ranges: bytes');
header('Content-Length:' . ($end - $begin + 1));
if (isset($_SERVER['HTTP_RANGE'])) {
header("Content-Range: bytes {$begin}-{$end}/{$size}");
}
header("Content-Disposition: inline; filename={$location}");
header("Content-Transfer-Encoding: binary");
header("Last-Modified: {$time}");
$cur = $begin;
fseek($fm, $begin, 0);
while (!feof($fm) && $cur <= $end && connection_status() == 0) {
set_time_limit(0);
print fread($fm, min(1024 * 16, $end - $cur + 1));
$cur += 1024 * 16;
flush();
}
}
示例11: filter
/**
* returns a filter object to use for this
*
* @param string $name
* @return InputFilter
*/
public final function filter($name)
{
if ($this->_input_filter !== null) {
return $this->_input_filter->filter($name);
}
App::getInstance()->includeFile('Sonic/InputFilter.php');
$this->_input_filter = new InputFilter($this->request());
return $this->_input_filter->filter($name);
}
示例12: test_parse_url_sanitization_javascript
public function test_parse_url_sanitization_javascript()
{
$urls = array('javascript:alert(0);', 'javascript:alert(0);', 'java	script:alert(0);', '	javascript:alert(0);', 'java
script:alert(0);', '
javascript:alert(0);', 'java
script:alert(0);', '
javascript:alert(0);');
foreach ($urls as $url) {
$url = html_entity_decode($url, null, 'UTF-8');
$parsed = InputFilter::parse_url($url);
$this->assert_equal($parsed['scheme'], 'javascript', $url . ' != ' . $parsed['scheme']);
}
}
示例13: execute
public function execute($method, $url, $headers, $body, $config)
{
$merged_headers = array();
foreach ($headers as $k => $v) {
$merged_headers[] = $k . ': ' . $v;
}
// parse out the URL so we can refer to individual pieces
$url_pieces = InputFilter::parse_url($url);
// set up the options we'll use when creating the request's context
$options = array('http' => array('method' => $method, 'header' => implode("\n", $merged_headers), 'timeout' => $config['timeout'], 'follow_location' => $this->can_followlocation, 'max_redirects' => $config['max_redirects'], 'verify_peer' => $config['ssl']['verify_peer'], 'cafile' => $config['ssl']['cafile'], 'capath' => $config['ssl']['capath'], 'local_cert' => $config['ssl']['local_cert'], 'passphrase' => $config['ssl']['passphrase']));
if ($method == 'POST') {
$options['http']['content'] = $body;
}
if ($config['proxy']['server'] != '' && !in_array($url_pieces['host'], $config['proxy']['exceptions'])) {
$proxy = $config['proxy']['server'] . ':' . $config['proxy']['port'];
if ($config['proxy']['username'] != '') {
$proxy = $config['proxy']['username'] . ':' . $config['proxy']['password'] . '@' . $proxy;
}
$options['http']['proxy'] = 'tcp://' . $proxy;
}
// create the context
$context = stream_context_create($options);
// perform the actual request - we use fopen so stream_get_meta_data works
$fh = @fopen($url, 'r', false, $context);
if ($fh === false) {
throw new Exception(_t('Unable to connect to %s', array($url_pieces['host'])));
}
// read in all the contents -- this is the same as file_get_contens, only for a specific stream handle
$body = stream_get_contents($fh);
// get meta data
$meta = stream_get_meta_data($fh);
// close the connection before we do anything else
fclose($fh);
// did we timeout?
if ($meta['timed_out'] == true) {
throw new RemoteRequest_Timeout(_t('Request timed out'));
}
// $meta['wrapper_data'] should be a list of the headers, the same as is loaded into $http_response_header
$headers = array();
foreach ($meta['wrapper_data'] as $header) {
// break the header up into field and value
$pieces = explode(': ', $header, 2);
if (count($pieces) > 1) {
// if the header was a key: value format, store it keyed in the array
$headers[$pieces[0]] = $pieces[1];
} else {
// some headers (like the HTTP version in use) aren't keyed, so just store it keyed as itself
$headers[$pieces[0]] = $pieces[0];
}
}
$this->response_headers = $headers;
$this->response_body = $body;
$this->executed = true;
return true;
}
示例14: actionUpdate
/**
* Updates a particular model.
* @param integer $_GET['id'] the ID of the model to be updated
* @return updated comment text
*/
public function actionUpdate()
{
Yii::app()->end();
//disalow updates
// get Comments object from $id parameter
$model = $this->loadModel($_GET['id']);
// if Comments form exist and was called via ajax
if (isset($_POST['Comments']) && isset($_POST['ajax'])) {
// set form elements to Users model attributes
$model->attributes = $_POST['Comments'];
// clear tag from text
Yii::import('application.extensions.InputFilter.InputFilter');
$filter = new InputFilter(array('br', 'pre'));
$model->comment_text = $filter->process($model->comment_text);
// update comment
$model->save(false);
echo $model->comment_text;
}
Yii::app()->end();
}
示例15: DumpHeaders
function DumpHeaders($filename)
{
global $root_path;
if (!$filename) {
return;
}
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
$isIE = 0;
if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false && strstr($HTTP_USER_AGENT, 'Opera') === false) {
$isIE = 1;
}
if (strstr($HTTP_USER_AGENT, 'compatible; MSIE 6') !== false && strstr($HTTP_USER_AGENT, 'Opera') === false) {
$isIE6 = 1;
}
$aux = preg_replace('[^-a-zA-Z0-9\\.]', '_', $filename);
$aux = explode('_', $aux);
$downloadName = $aux[count($aux) - 1];
// $downloadName = $filename;
//$downloadName = ereg_replace('[^-a-zA-Z0-9\.]', '_', $filename);
if ($isIE && !isset($isIE6)) {
// http://support.microsoft.com/support/kb/articles/Q182/3/15.asp
// Do not have quotes around filename, but that applied to
// "attachment"... does it apply to inline too?
// This combination seems to work mostly. IE 5.5 SP 1 has
// known issues (see the Microsoft Knowledge Base)
header("Content-Disposition: inline; filename={$downloadName}");
// This works for most types, but doesn't work with Word files
header("Content-Type: application/download; name=\"{$downloadName}\"");
//header("Content-Type: $type0/$type1; name=\"$downloadName\"");
//header("Content-Type: application/x-msdownload; name=\"$downloadName\"");
//header("Content-Type: application/octet-stream; name=\"$downloadName\"");
} else {
header("Content-Disposition: attachment; filename=\"{$downloadName}\"");
header("Content-Type: application/octet-stream; name=\"{$downloadName}\"");
}
//$filename = PATH_UPLOAD . "$filename";
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$filename = $filter->xssFilterHard($filename, 'path');
readfile($filename);
}