예제 #1
0
파일: dja_utils.php 프로젝트: idlesign/dja
 public function reverse($viewname, $urlconf = null, array $args = array(), array $kwargs = array(), $prefix = null, $current_app = null)
 {
     $indexes = array_keys($this->_rules, $viewname);
     $re_params = '~(?P<ngroup>\\((\\?P<(?P<name>[^>]+)>)?[^)]+\\))~';
     foreach ($indexes as $url_pattern) {
         $matched = preg_match_all($re_params, $url_pattern, $matches, PREG_SET_ORDER);
         if ($matched !== false) {
             $args_from_pattern = array();
             foreach ($matches as $match) {
                 if (isset($match['name'])) {
                     $args_from_pattern[$match['name']] = $match['ngroup'];
                 } else {
                     $args_from_pattern[] = $match['ngroup'];
                 }
             }
             $unknown_args = array_diff(array_keys($args_from_pattern), array_keys($kwargs));
             if (count($kwargs) == $matched && empty($unknown_args)) {
                 return iri_to_uri($this->populatePattern($url_pattern, $args_from_pattern, $kwargs));
             } elseif (count($args) == $matched) {
                 return iri_to_uri($this->populatePattern($url_pattern, array_values($args_from_pattern), $args));
             }
         }
     }
     $kwargs_flat = array();
     foreach ($kwargs as $k => $v) {
         $kwargs_flat[] = $k . '=' . $v;
     }
     throw new UrlNoReverseMatch(sprintf('Reverse for \'%s\' with arguments \'%s\' and keyword arguments \'%s\' not found.', $viewname, join(', ', $args), join(', ', $kwargs_flat)));
 }
예제 #2
0
$lib->filter('escapejs', function ($value) {
    return escapejs($value);
});
//stringfilter
$lib->filter('fix_ampersands', function ($value) {
    return preg_replace('~&(?!(\\w+|#\\d+);)~', '&amp;', $value);
}, array('is_safe' => True));
//stringfilter
$lib->filter('floatformat', function ($text, $arg = -1) {
    $input_val = (string) $text;
    $input_val = round($input_val, 1);
    return $input_val;
}, array('is_safe' => True));
//stringfilter
$lib->filter('iriencode', function ($value) {
    return iri_to_uri($value);
}, array('is_safe' => True));
//stringfilter
$lib->filter('linenumbers', function ($value, $autoescape = null) {
    $lines = explode("\n", $value);
    // Find the maximum width of the line count, for use with zero padding string format command
    $width = strlen(count($lines));
    if (!$autoescape || $value instanceof SafeData) {
        $i = 0;
        foreach ($lines as $line) {
            $lines[$i] = sprintf('%0' . $width . 'd. ' . $line, $i + 1);
            $i++;
        }
    } else {
        $i = 0;
        foreach ($lines as $line) {