コード例 #1
0
ファイル: Upload.php プロジェクト: robtuley/knotwerk
 /**
  * Validate element file upload.
  *
  * @param T_Cage_Array $source  source array (to ignore!)
  * @return T_Form_Element  fluent interface
  */
 function validate(T_Cage_Array $source)
 {
     $this->reset();
     $this->is_present = $this->isSubmitted($source);
     /* quit if not present, checking that is present if required */
     if (!$this->is_present) {
         if ($this->is_required) {
             $this->error = new T_Form_Error('is missing');
         }
         return $this;
     }
     /* check that no error has occurred during the upload */
     if ($source->isFileError($this->getFieldname())) {
         $err = $source->asFileError($this->getFieldname());
         $this->error = new T_Form_Error($err->getMessage());
         return $this;
     }
     /* get caged value */
     $upload = $source->asFile($this->getFieldname());
     /* now validate input by filtering */
     try {
         foreach ($this->filters as $filter) {
             $upload = _transform($upload, $filter);
         }
     } catch (T_Exception_Filter $e) {
         $this->error = new T_Form_Error($e->getMessage());
         return $this;
     }
     $this->clean = $upload;
     return $this;
 }
コード例 #2
0
ファイル: XhtmlError.php プロジェクト: robtuley/knotwerk
 /**
  * Return XHTML string.
  *
  * @return string
  */
 function __toString()
 {
     $xhtml = '';
     if (count($this->errors) == 0) {
         return $xhtml;
     }
     $f = new T_Filter_Xhtml();
     $xhtml = '<div class="error">' . EOL . '    <p>There were some problems with your submission:</p>' . EOL . '    <ul>' . EOL;
     foreach ($this->errors as $node) {
         $error = $node->getError();
         $msg = '';
         if (!$node instanceof T_Form_Container && !$node instanceof T_Form_Hidden) {
             $msg .= '<a href="#' . $node->getAlias() . '">' . $node->getLabel($f) . '</a> ';
         }
         $msg .= _transform($error->getMessage(), $f);
         $xhtml .= '        <li>' . $msg . '</li>' . EOL;
     }
     $xhtml .= '    </ul>' . EOL;
     if (count($this->recomplete) > 0) {
         $fields = array();
         foreach ($this->recomplete as $node) {
             $fields[] = '<a href="#' . $node->getAlias() . '">' . $node->getLabel($f) . '</a>';
         }
         $xhtml .= '    <p class="recomplete">In addition for security reasons the ' . implode(', ', $fields) . ' ';
         if (count($fields) > 1) {
             $xhtml .= 'fields have been cleared and need';
         } else {
             $xhtml .= 'field has been cleared and needs';
         }
         $xhtml .= ' to be recompleted.</p>' . EOL;
     }
     $xhtml .= '</div>';
     return $xhtml;
 }
コード例 #3
0
ファイル: Redirect.php プロジェクト: robtuley/knotwerk
 /**
  * Initialise redirect request.
  *
  * Note that the redirect URL must be an ABSOLUTE rather than relative URL.
  * IIS under CGI mode has a bug which will crash when redirecting to
  * relative URLs.
  *
  * @param string $url  URL to redirect to
  */
 function __construct($url)
 {
     $f = new T_Filter_Xhtml();
     $content = '<html><head>' . '<meta http-equiv="Refresh" content="1;url=' . _transform($url, $f) . '">' . '</head><body>' . '<a href="' . _transform($url, $f) . '">Continue &rsaquo;</a>' . '</body></html>';
     parent::__construct(303);
     $this->setHeader("Location", $url);
     $this->setContent($content);
 }
コード例 #4
0
ファイル: DocBlockTypeTag.php プロジェクト: robtuley/knotwerk
 /**
  * Return string representation of type.
  *
  * @param function $filter
  * @return string
  */
 function getCombinedType($filter = null)
 {
     $type = $this->type ? $this->type : 'unknown';
     if ($this->isArray()) {
         $type .= '[]';
     }
     return _transform($type, $filter);
 }
コード例 #5
0
ファイル: Php.php プロジェクト: robtuley/knotwerk
 /**
  * Convert PHP source code to XHTML.
  *
  * The code is exported as an ordered list, with keywords, comments, etc.
  * highlighted with class spans.
  *
  * @return string  source code as marked up XHTML.
  */
 function doTransform($src)
 {
     $tokens = token_get_all(trim($src));
     $f = new T_Filter_Xhtml();
     $is_even = true;
     /* next line is even */
     $in_quotes = false;
     /* tracks if in *parsed* quoted string */
     $out = '<ol class="php">' . EOL . '    ' . '<li><code>';
     foreach ($tokens as $t) {
         /* standardize token (maybe array, or just plain content). */
         if (is_array($t)) {
             list($t_type, $t_content) = $t;
             $t_class = $this->getClassFromToken($t_type);
         } else {
             $t_type = false;
             $t_class = false;
             $t_content = $t;
         }
         /* If there is a double quoted string that contains embedded
            variables, the string is tokenized as components, and within
            this string is the only time we want to label T_STRING types as
            actual strings. The double quotes in this case always appear in
            on their own,and we use the $in_quotes to track this status */
         if ($t_type === false && $t_content === '"') {
             $t_class = $this->getClassFromToken(T_CONSTANT_ENCAPSED_STRING);
             $in_quotes = !$in_quotes;
         } elseif ($in_quotes && $t_type === T_STRING) {
             $t_class = $this->getClassFromToken(T_CONSTANT_ENCAPSED_STRING);
         }
         /* act on token. This is complicated by the fact that a token
            content can contain EOL markers, and in this case the token
            content must be separated at these lines. */
         $t_content = explode("\n", $t_content);
         for ($i = 0, $max = count($t_content) - 1; $i <= $max; $i++) {
             /* add new line (only from 2nd iteration onwards) */
             if ($i > 0) {
                 $e_class = $is_even ? ' class="even"' : '';
                 $is_even = !$is_even;
                 $out .= '</code></li>' . EOL . '    ' . '<li' . $e_class . '><code>';
             }
             /* right trim token content if it is at end of a line */
             $line = $t_content[$i];
             if ($i < $max) {
                 $line = rtrim($line);
             }
             /* wrap content in spans */
             if ($t_class !== false && strlen($line) > 0) {
                 $out .= '<span class="' . $t_class . '">' . _transform($line, $f) . '</span>';
             } else {
                 $out .= _transform($line, $f);
             }
         }
     }
     $out .= '</code></li>' . EOL . '</ol>';
     return $out;
 }
コード例 #6
0
ファイル: template.php プロジェクト: jgosier/kamusi
/**
 * NOUNS
 * Pluralize the given noun using the plural rules.
 * @param $word noun to be pluralized
 *
 * @return pluralized word
 */
function _pluralize($word, $lang = 'en')
{
    if (strlen($word) == 1 || strlen($word) == 2) {
        return "";
    } else {
        $rules = _get_plural_rules($lang);
        return _transform($word, $rules);
    }
}
コード例 #7
0
 function testRejectsImageWhereAspectLessThanRange()
 {
     $filter = new T_Validate_ImageAspectRange(0.5, 2);
     $img = new T_Image_Gd(3, 8);
     try {
         _transform($img, $filter);
         $this->fail();
     } catch (T_Exception_Filter $e) {
     }
 }
コード例 #8
0
ファイル: GeoCode.php プロジェクト: robtuley/knotwerk
 /**
  * Bias the geocode to a particular country.
  *
  * @param string $code  ISO 3166-1 country code
  * @return T_Google_GeoCode  fluent interface
  */
 function biasToCountry($code)
 {
     if ($code) {
         $filter = new T_Filter_CcTld();
         $this->cc_tld = _transform($code, $filter);
     } else {
         $this->cc_tld = false;
     }
     return $this;
 }
コード例 #9
0
ファイル: forms.php プロジェクト: robtuley/knotwerk
 protected function postElement($node)
 {
     $xhtml = null;
     if ($help = $node->getHelp()) {
         $f = new T_Filter_Xhtml();
         $xhtml = $this->indent . '<span class="help">' . _transform($help, $f) . '</span>' . EOL;
     }
     $xhtml .= $this->indent . '</li>' . EOL;
     return $xhtml;
 }
コード例 #10
0
ファイル: ToUrlQuery.php プロジェクト: robtuley/knotwerk
 /**
  * Convert query string back to array of values.
  *
  * @param string $query  query string
  * @return array  data
  */
 function reverse($query)
 {
     $data = array();
     parse_str($query, $data);
     if (get_magic_quotes_gpc()) {
         // affected by magic_quotes settings
         $f = new T_Filter_NoMagicQuotes();
         $data = _transform($data, $f);
     }
     return $data;
 }
コード例 #11
0
ファイル: FloatUnsigned.php プロジェクト: robtuley/knotwerk
 function testFilterFailsWhenNotANumber()
 {
     $filter = new T_Validate_FloatUnsigned();
     $invalid = array('', '@', '0.y7', '0.8.0', '8%', '6.7$7', '10..5', '.');
     foreach ($invalid as $term) {
         try {
             _transform($term, $filter);
             $this->fail("Accepted value {$term}");
         } catch (T_Exception_Filter $e) {
         }
     }
 }
コード例 #12
0
 /**
  * Converts coverage to text.
  *
  * @param T_Unit_CodeCoverage $value  data to filter
  * @return string  rendered as string
  */
 protected function doTransform($value)
 {
     $total = $value->getNumExe() + $value->getNumNotExe();
     $render = 'Code coverage: ' . round($value->getCoverageRatio() * 100, 2) . '% ' . '(over ' . $total . ' executable lines)' . EOL;
     if ($value->getNumNotExe() > 0) {
         $table = array(array('File', 'Lines Not Exe'));
         foreach ($value->getNotExe() as $path => $missed) {
             $table[] = array($path, implode(',', $missed));
         }
         $as_table = new T_Filter_TextTable();
         $render .= EOL . _transform($table, $as_table) . EOL;
     }
     return $render;
 }
コード例 #13
0
ファイル: ArrayMap.php プロジェクト: robtuley/knotwerk
 /**
  * Applies filter to each member of array.
  *
  * @param array $value  data to filter
  * @return array  filtered data
  */
 protected function doTransform($value)
 {
     if (!is_array($value)) {
         throw new T_Exception_Filter("{$value} is not an array");
     }
     $i = 1;
     foreach ($value as &$element) {
         try {
             $element = _transform($element, $this->map_filter);
         } catch (T_Exception_Filter $error) {
             $as_ord = new T_Filter_Ordinal();
             $msg = _transform($i, $as_ord) . ' item ' . $error->getMessage();
             throw new T_Exception_Filter($msg);
         }
         $i++;
     }
     return $value;
 }
コード例 #14
0
ファイル: GeoCodeAddress.php プロジェクト: robtuley/knotwerk
 /**
  * Locates an address.
  *
  * @param T_Geo_Address $addr
  * @return T_Geo_Address  point
  */
 protected function doTransform($addr)
 {
     // prepare country
     $addr = clone $addr;
     if ($ctry = $addr->getCountry()) {
         $this->driver->biasToCountry($ctry->getCode());
     } else {
         $this->driver->biasToCountry(false);
     }
     // build query string
     $text = array($addr->getLineOne(), $addr->getLineTwo(), $addr->getCity(), $addr->getState(), $addr->getPostcode());
     $text = implode(', ', array_filter($text));
     // attempt to geocode
     try {
         $point = _transform($text, $this->driver);
     } catch (T_Exception_Filter $e) {
         throw new T_Exception_Filter("Could not locate the address provided");
     }
     // populate data back into address
     $addr->setLongitude($point->getLongitude())->setLatitude($point->getLatitude())->setAltitude($point->getAltitude());
     return $addr;
 }
コード例 #15
0
ファイル: Address.php プロジェクト: robtuley/knotwerk
 /**
  * Validate.
  *
  * If fields are present, build address.
  */
 function validate(T_Cage_Array $src)
 {
     $this->clean = null;
     $this->error = false;
     foreach ($this->children as $child) {
         $child->validate($src);
     }
     $alias = $this->getAlias();
     // check address components are present
     if ($this->isPresent() && $this->isValid()) {
         $line_1 = $this->search($alias . '_line_1');
         $city = $this->search($alias . '_city');
         if (!$line_1->isPresent()) {
             $line_1->setError(new T_Form_Error('is missing'));
         }
         if (!$city->isPresent()) {
             $city->setError(new T_Form_Error('is missing'));
         }
     }
     // build address
     if ($this->isPresent() && $this->isValid()) {
         $data = array();
         $data['line1'] = $this->search($alias . '_line_1')->getValue();
         $data['line2'] = $this->search($alias . '_line_2')->getValue();
         $data['city'] = $this->search($alias . '_city')->getValue();
         $data['state'] = $this->search($alias . '_state')->getValue();
         $data['postcode'] = $this->search($alias . '_postcode')->getValue();
         if ($this->countries) {
             $code = $this->search($alias . '_country')->getValue();
             $data['country'] = $this->countries->getByCode($code);
         } else {
             $data['country'] = null;
         }
         $address = $this->factory->like('T_Geo_Address', $data);
         // filter address
         try {
             foreach ($this->filters as $filter) {
                 $address = _transform($address, $filter);
             }
             $this->setValue($address);
         } catch (T_Exception_Filter $e) {
             $this->setError(new T_Form_Error($e->getMessage()));
             return $this;
         }
     } elseif (!$this->isPresent() && $this->isRequired()) {
         $this->setError(new T_Form_Error('is missing'));
     }
     return $this;
 }
コード例 #16
0
 /**
  * Gets the variable name.
  *
  * @param function $filter
  * @return string
  */
 function getVar($filter = null)
 {
     return _transform($this->var, $filter);
 }
コード例 #17
0
ファイル: Group.php プロジェクト: robtuley/knotwerk
 /**
  * Get element label.
  *
  * @param function $f  filter to apply
  * @return string  element label
  */
 function getLabel($f = null)
 {
     return _transform($this->label, $f);
 }
コード例 #18
0
ファイル: Connection.php プロジェクト: robtuley/knotwerk
 /**
  * Gets the DB type name.
  *
  * @param function $filter  optional filter
  * @return string
  */
 function getName($filter = null)
 {
     return _transform('SQLite', $filter);
 }
コード例 #19
0
ファイル: TableCell.php プロジェクト: robtuley/knotwerk
 /**
  * Gets the span level.
  *
  * @param function $filter
  * @return int
  */
 function getSpan($filter = null)
 {
     return _transform($this->span, $filter);
 }
コード例 #20
0
ファイル: DocBlockTag.php プロジェクト: robtuley/knotwerk
 /**
  * Gets the tag description.
  *
  * @param function $filter
  * @return string
  */
 function getDesc($filter = null)
 {
     return _transform($this->desc, $filter);
 }
コード例 #21
0
ファイル: NativeDriver.php プロジェクト: robtuley/knotwerk
 /**
  * Saves data.
  *
  * @param mixed $data  data
  * @return T_Session_Driver  fluent interface
  */
 function save($data)
 {
     foreach ($this->filters as $f) {
         $data = _transform($data, $f);
     }
     $_SESSION['__data__'] = $data;
     session_write_close();
     return $this;
 }
コード例 #22
0
ファイル: Plain.php プロジェクト: robtuley/knotwerk
 /**
  * Get the content.
  *
  * @param function $filter  optional output filter
  * @return string  content
  */
 function getContent($filter = null)
 {
     return _transform($this->content, $filter);
 }
コード例 #23
0
ファイル: TimePeriod.php プロジェクト: robtuley/knotwerk
 /**
  * Checks that if both fields are present and value, time period meets spec.
  *
  * @param T_Form_Group $value  collection to examine
  * @return void
  * @throws T_Exception_Filter  if time period is not value
  */
 protected function doTransform($value)
 {
     $start = $value->search($this->start);
     $end = $value->search($this->end);
     if (!$start || !$end) {
         $msg = "does not contain {$this->start} or {$this->end}";
         throw new InvalidArgumentException($msg);
     }
     // if either field already has errors, or if not present,
     // no validation is required.
     if (!$start->isValid() || !$start->isPresent() || !$end->isValid() || !$end->isPresent()) {
         return;
     }
     $period = $end->getValue() - $start->getValue();
     if ($period < 0) {
         $msg = "{$end->getLabel()} must be after {$start->getLabel()}";
         throw new T_Exception_Filter($msg);
     }
     if (!is_null($this->min) && $period < $this->min) {
         $f = new T_Filter_HumanTimePeriod();
         $msg = "The period between {$start->getLabel()} and {$end->getLabel()} must be at least " . _transform($this->min, $f);
     }
     if (!is_null($this->max) && $period > $this->max) {
         $f = new T_Filter_HumanTimePeriod();
         $msg = "The period between {$start->getLabel()} and {$end->getLabel()} may be a maximum of " . _transform($this->max, $f);
     }
 }
コード例 #24
0
ファイル: Hidden.php プロジェクト: robtuley/knotwerk
 /**
  * Converts a value to a checksum.
  *
  * @param string $value
  * @return string  checksum
  */
 protected function toChecksum($value)
 {
     if ($this->hash && $this->salt) {
         return _transform($value . $this->salt, $this->hash);
     } else {
         return sha1($value);
     }
 }
コード例 #25
0
ファイル: export.php プロジェクト: robtuley/knotwerk
        if (strcmp(T_PHP_EXT, $ext) !== 0) {
            continue;
        }
        // exclude hidden dir (start with a .), sample dirs (starts with _),
        // and exclude the Test directory..
        $ds = DIRECTORY_SEPARATOR;
        if ($is_dir && (strpos($f, $ds . '.') !== false || strpos($f, $ds . '_') !== false || strpos($f, $ds . 'Test' . $ds) !== false)) {
            continue;
        }
        // now load actual source, and process it.
        $src[] = new T_Code_Php(file_get_contents($f));
    }
}
// order files by dependencies
$filter = new T_Code_Sort();
$src = _transform($src, $filter);
// now package files
$main = null;
$prefix = null;
$svn = 0;
foreach ($src as $php) {
    // process source.
    $php = $php->expand();
    // expand includes
    if (($v = $php->getVersion()) > $svn) {
        $svn = $v;
    }
    $php = $php->compress();
    // compress code
    // export
    switch ($format) {
コード例 #26
0
ファイル: Element.php プロジェクト: robtuley/knotwerk
 /**
  * Get element help text.
  *
  * @param function $f  filter to apply
  * @return string  element label
  */
 function getHelp($f = null)
 {
     return _transform($this->help, $f);
 }
コード例 #27
0
ファイル: Export.php プロジェクト: robtuley/knotwerk
 /**
  * Gets the data.
  *
  * @param function $filter  optional filter
  * @return array
  */
 function getData($filter = null)
 {
     return _transform($this->data, $filter);
 }
コード例 #28
0
ファイル: Address.php プロジェクト: robtuley/knotwerk
 /**
  * Outputs the entire address as a string.
  *
  * This returns the address in a standard format, with the lines separated
  * by carriage returns.
  * Address line 1
  * Address line 2
  * City, State
  * Postal Code/Zip
  * Country
  *
  * @param T_Filter  output filter
  * @return string formatted address
  */
 function asString($filter = null)
 {
     $output = '';
     if (strlen($this->line_one) > 0) {
         $output .= $this->line_one . EOL;
     }
     if (strlen($this->line_two) > 0) {
         $output .= $this->line_two . EOL;
     }
     $line3 = array();
     if (strlen($this->city) > 0) {
         $line3[] = $this->city;
     }
     if (strlen($this->state) > 0) {
         $line3[] = $this->state;
     }
     if (count($line3) > 0) {
         $output .= implode(', ', $line3) . EOL;
     }
     if (strlen($this->post_code) > 0) {
         $output .= $this->post_code . EOL;
     }
     if (!is_null($this->ctry)) {
         $output .= $this->ctry->getName();
     }
     return _transform(mb_trim($output), $filter);
 }
コード例 #29
0
ファイル: Date.php プロジェクト: robtuley/knotwerk
 /**
  * Retrieves the date in a particular format.
  *
  * This function converts the date into a particular format. The
  * following placeholders can be used (a limited selection from
  * the PHP date() function).
  *
  * +--------+------------------------------------+
  * | Code   | Description                        |
  * +--------+------------------------------------+
  * |   d    | numeric day with leading zeros     |
  * |   j    | numeric day with no leading zeros  |
  * |   m    | numeric month with leading zeros   |
  * |   n    | numeric month no leading zeros     |
  * |   Y    | full four-digit year               |
  * |   y    | 2 digit representation of year     |
  * +--------+------------------------------------+
  *
  * @param string $format  format string
  * @param T_Filter  optional filter to apply to output
  * @return string
  */
 function asFormat($format, $filter = null)
 {
     $short_year = strlen($this->year) == 4 ? substr($this->year, 2) : $this->year;
     $replace = array('d' => str_pad($this->day, 2, '0', STR_PAD_LEFT), 'j' => $this->day, 'm' => str_pad($this->month, 2, '0', STR_PAD_LEFT), 'n' => $this->month, 'Y' => $this->year, 'y' => $short_year);
     $date = str_replace(array_keys($replace), $replace, $format);
     return _transform($date, $filter);
 }
コード例 #30
0
ファイル: form_multistep.php プロジェクト: robtuley/knotwerk
$form->addChild($step3);
$fieldset = new T_Form_Fieldset('car_details', 'Your Car');
$step3->addChild($fieldset);
$fieldset->addChild(new T_Form_Text('reg', 'Registration'));
$fieldset->addChild(new T_Form_Text('make', 'Make'));
$fieldset->addChild(new T_Form_Text('model', 'Model'));
$form->setForward($env->getRequestUrl());
// VALIDATE FORM
if ($env->isMethod('POST')) {
    $form->validate($env->input('POST'));
}
// ACTION FORM
if ($form->isPresent() && $form->isValid()) {
    // action..
    echo '<p>Thanks for requesting to get a quote, you details are:</p>';
    echo '<table><thead><tr><th>Description</th><th>Value</th></thead><tbody>';
    $data = array('Name' => $form->search('name')->getValue(), 'Email' => $form->search('email')->getValue(), 'History' => $form->search('penalty')->getValue(), 'Registration' => $form->search('reg')->getValue(), 'Model' => $form->search('make')->getValue(), 'Make' => $form->search('model')->getValue());
    $f = new T_Filter_Xhtml();
    foreach ($data as $name => $val) {
        echo '<tr><td>', _transform($name, $f), '</td><td>', _transform($val, $f), '</td></tr>';
    }
    echo '</tbody></table>';
    echo '<p><a href="' . $env->getRequestUrl()->getUrl($f) . '">Try again &rsaquo;</a></p>';
} else {
    // render form
    $error = new T_Form_XhtmlError();
    $render = new Demo_Form_Xhtml();
    $form->accept($error)->accept($render);
    echo $error, $render;
}
require dirname(__FILE__) . '/inc/footer.php';