Exemplo n.º 1
0
 public static function fromInput(JitFilter $input, array $typeInfo)
 {
     $options = new Tracker_Options();
     $options->info = $typeInfo;
     foreach ($typeInfo['params'] as $key => $info) {
         $filter = $info['filter'];
         if (isset($info['count']) && $info['count'] === '*') {
             $rawValue = $input->{$key}->none();
             if ($rawValue !== '') {
                 $values = explode(',', $rawValue);
                 $filter = TikiFilter::get($filter);
                 $values = array_map(array($filter, 'filter'), $values);
             } else {
                 $values = '';
             }
             $options->setParam($key, $values);
         } elseif (isset($info['separator'])) {
             $input->replaceFilter($key, $filter);
             $values = $input->asArray($key, $info['separator']);
             $options->setParam($key, $values);
         } else {
             $options->setParam($key, $input->{$key}->{$filter}());
         }
     }
     return $options;
 }
Exemplo n.º 2
0
/**
 * Variable arguments to be sent as filters for the object list. Filters match the unified search
 * field filters.
 *
 * Reserved parameters:
 *  - name for the field name
 *  - galleryId
 *  - value for the current value (fileId, comma separated for multiple)
 *  - type for the mime type filter (image/*)
 *  - limit for the maximum amount of files (defaults to 1)
 *
 * The component will build a drop list for the object selector if the results fit in a reasonable amount
 * of space or will use autocomplete on the object title otherwise.
 */
function smarty_function_file_selector($params, $smarty)
{
    static $uniqid = 0;
    $arguments = ['name' => null, 'value' => null, 'limit' => 1, 'type' => null, 'galleryId' => 0];
    $input = new JitFilter(array_merge($arguments, $params));
    $input->replaceFilter('value', 'int');
    $smarty->assign('file_selector', ['name' => $input->name->text(), 'value' => array_filter($input->asArray('value', ',')), 'limit' => $input->limit->digits() ?: 1, 'type' => $input->type->text(), 'galleryId' => $input->galleryId->int()]);
    return $smarty->fetch('file_selector.tpl');
}
Exemplo n.º 3
0
}
$jitServer = new JitFilter($_SERVER);
$_SERVER = $serverFilter->filter($_SERVER);
// Rebuild request after gpc fix
// _REQUEST should only contain GET and POST in the app

$prepareInput = new TikiFilter_PrepareInput('~');
$_GET = $prepareInput->prepare($_GET);
$_POST = $prepareInput->prepare($_POST);

$_REQUEST = array_merge($_GET, $_POST);
// Preserve unfiltered values accessible through JIT filtering
$jitPost = new JitFilter($_POST);
$jitGet = new JitFilter($_GET);
$jitRequest = new JitFilter($_REQUEST);
$jitCookie = new JitFilter($_COOKIE);
$jitPost->setDefaultFilter('xss');
$jitGet->setDefaultFilter('xss');
$jitRequest->setDefaultFilter('xss');
$jitCookie->setDefaultFilter('xss');
// Apply configured filters to all other input
if (!isset($inputConfiguration)) $inputConfiguration = array();

array_unshift(
			 $inputConfiguration, array(
				'staticKeyFilters' => array(
					'menu' => 'striptags',
					'cat_categorize' => 'alpha',
					'tab' => 'digits',
					'javascript_enabled' => 'alpha',
					'XDEBUG_PROFILE' => 'int',
Exemplo n.º 4
0
 function testAsArraySplit()
 {
     $test = new JitFilter(array('foo' => '1|2a|3'));
     $test->setDefaultFilter(new Zend_Filter_Digits());
     $this->assertEquals(array('1', '2', '3'), $test->asArray('foo', '|'));
 }
Exemplo n.º 5
0
 function applyInput(\JitFilter $input)
 {
     $input->replaceFilter($this->fieldName, 'text');
     $this->values = $input->asArray($this->fieldName);
 }
Exemplo n.º 6
0
 function testDefault()
 {
     $filter = new JitFilter(array('foo' => 'test123'));
     $filter->setDefaultFilter('digits');
     $this->assertEquals('123', $filter['foo']);
 }
Exemplo n.º 7
0
 function buildOptions($input, $typeInfo)
 {
     if (is_string($typeInfo)) {
         $types = $this->getFieldTypes();
         $typeInfo = $types[$typeInfo];
     }
     if (is_array($input)) {
         $input = new JitFilter($input);
     }
     $parts = array();
     foreach ($typeInfo['params'] as $key => $info) {
         $filter = $info['filter'];
         if (isset($info['count']) && $info['count'] === '*') {
             $values = explode(',', $input->{$key}->none());
             $filter = TikiFilter::get($filter);
             $values = array_map(array($filter, 'filter'), $values);
         } elseif (isset($info['separator'])) {
             $input->setFilter($key, $filter);
             $values = $input->asArray($key, $info['separator']);
             $values = array(implode($info['separator'], $values));
         } else {
             $values = array($input->{$key}->{$filter}());
         }
         foreach ($values as $value) {
             if (isset($info['options']) && !isset($info['options'][$value])) {
                 $value = null;
             }
             $parts[] = $value;
         }
     }
     $rawOptions = implode(',', $parts);
     return rtrim($rawOptions, ',');
 }
Exemplo n.º 8
0
 function getInput(JitFilter $filter, $preferences = array(), $environment = '')
 {
     $out = array();
     foreach ($preferences as $name) {
         $info = $this->getPreference($name);
         if ($environment == 'perspective' && isset($info['perspective']) && $info['perspective'] === false) {
             continue;
         }
         if (isset($info['filter'])) {
             $filter->replaceFilter($name, $info['filter']);
         }
         if (isset($info['separator'])) {
             $out[$name] = $filter->asArray($name, $info['separator']);
         } else {
             $out[$name] = $filter[$name];
         }
     }
     return $out;
 }