Esempio n. 1
0
 /**
  * Retrieve the initial or submitted value.
  *
  * @return	string
  */
 public function getValue()
 {
     // redefine default value
     $value = $this->value;
     // form submitted
     if ($this->isSubmitted()) {
         // post/get data
         $data = $this->getMethod(true);
         // submitted by post (may be empty)
         if (isset($data[$this->getName()])) {
             $value = $data[$this->getName()];
             $value = is_array($value) ? 'Array' : (string) $value;
             // maximum length?
             if (isset($this->attributes['maxlength']) && $this->attributes['maxlength'] > 0) {
                 $value = mb_substr($value, 0, (int) $this->attributes['maxlength'], Spoon::getCharset());
             }
         }
     }
     return $value;
 }
Esempio n. 2
0
 /**
  * Retrieve the initial or submitted value.
  *
  * @param	bool[optional] $allowHTML	Is HTML allowed?
  * @return	string
  */
 public function getValue($allowHTML = null)
 {
     // redefine default value
     $value = $this->value;
     // added to form
     if ($this->isSubmitted()) {
         // post/get data
         $data = $this->getMethod(true);
         // submitted by post/get (may be empty)
         if (isset($data[$this->attributes['name']])) {
             // value
             $value = $data[$this->getName()];
             $value = is_scalar($value) ? (string) $value : 'Array';
             if (!$allowHTML) {
                 $value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value);
             }
         }
     }
     return $value;
 }
Esempio n. 3
0
 /**
  * Dumps the output of a variable in a more readable manner.
  *
  * @param	mixed $var				The variable to dump.
  * @param	bool[optional] $exit	Should the code stop here?
  */
 public static function dump($var, $exit = true)
 {
     ob_start();
     var_dump($var);
     $output = ob_get_clean();
     // Make sure var_dump is not overridden by Xdebug before tweaking its output.
     // Note that all truthy INI values ("On", "true", 1) are returned as "1" by ini_get().
     $hasXdebugVarDump = extension_loaded('xdebug') && ini_get('xdebug.overload_var_dump') === '1';
     if (!$hasXdebugVarDump) {
         $output = preg_replace('/\\]\\=\\>\\n(\\s+)/m', '] => ', $output);
         $output = '<pre>' . htmlspecialchars($output, ENT_QUOTES, Spoon::getCharset()) . '</pre>';
     }
     echo $output;
     if ($exit) {
         exit;
     }
 }
Esempio n. 4
0
    /**
     * Parse the forms.
     *
     * @return	string				The updated content, containing the parsed form tags.
     * @param	string $content		The content that may contain the form tags.
     */
    protected function parseForms($content)
    {
        // regex pattern
        $pattern = '/\\{form:([a-z0-9_]+?)\\}?/siU';
        // find matches
        if (preg_match_all($pattern, $content, $matches)) {
            // loop matches
            foreach ($matches[1] as $name) {
                // init vars
                $search = array();
                $replace = array();
                // start & close tag
                $search = array('{form:' . $name . '}', '{/form:' . $name . '}');
                // using UTF-8 as charset
                if (Spoon::getCharset() == 'utf-8') {
                    $replace[0] = '<?php
					if(isset($this->forms[\'' . $name . '\']))
					{
						?><form accept-charset="UTF-8" action="<?php echo $this->forms[\'' . $name . '\']->getAction(); ?>" method="<?php echo $this->forms[\'' . $name . '\']->getMethod(); ?>"<?php echo $this->forms[\'' . $name . '\']->getParametersHTML(); ?>>
						<?php echo $this->forms[\'' . $name . '\']->getField(\'form\')->parse();
						if($this->forms[\'' . $name . '\']->getUseToken())
						{
							?><input type="hidden" name="form_token" id="<?php echo $this->forms[\'' . $name . '\']->getField(\'form_token\')->getAttribute(\'id\'); ?>" value="<?php echo htmlspecialchars($this->forms[\'' . $name . '\']->getField(\'form_token\')->getValue()); ?>" />
						<?php } ?>';
                } else {
                    $replace[0] = '<?php
					if(isset($this->forms[\'' . $name . '\']))
					{
						?><form action="<?php echo $this->forms[\'' . $name . '\']->getAction(); ?>" method="<?php echo $this->forms[\'' . $name . '\']->getMethod(); ?>"<?php echo $this->forms[\'' . $name . '\']->getParametersHTML(); ?>>
						<?php echo $this->forms[\'' . $name . '\']->getField(\'form\')->parse();
						if($this->forms[\'' . $name . '\']->getUseToken())
						{
							?><input type="hidden" name="form_token" id="<?php echo $this->forms[\'' . $name . '\']->getField(\'form_token\')->getAttribute(\'id\'); ?>" value="<?php echo htmlentities($this->forms[\'' . $name . '\']->getField(\'form_token\')->getValue()); ?>" />
						<?php } ?>';
                }
                $replace[1] = '</form>
				<?php } ?>';
                $content = str_replace($search, $replace, $content);
            }
        }
        return $content;
    }
Esempio n. 5
0
 /**
  * Transform the string to uppercase.
  *
  * @return	string			The string, completly uppercased.
  * @param	string $string	The string that you want to apply this method on.
  */
 public static function uppercase($string)
 {
     return mb_convert_case($string, MB_CASE_UPPER, Spoon::getCharset());
 }
Esempio n. 6
0
 /**
  * Retrieve the initial or submitted value.
  *
  * @return	string
  * @param	bool[optional] $allowHTML	Is HTML allowed?
  */
 public function getValue($allowHTML = null)
 {
     // redefine html & default value
     $allowHTML = $allowHTML !== null ? (bool) $allowHTML : $this->isHTML;
     $value = $this->value;
     // contains html
     if ($this->isHTML) {
         // set value
         $value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value);
     }
     // form submitted
     if ($this->isSubmitted()) {
         // post/get data
         $data = $this->getMethod(true);
         // submitted by post (may be empty)
         if (isset($data[$this->getName()])) {
             // value
             $value = isset($data[$this->getName()]) ? $data[$this->getName()] : '';
             if (is_array($value)) {
                 $value = 'Array';
             }
             // maximum length?
             if (isset($this->attributes['maxlength']) && $this->attributes['maxlength'] > 0) {
                 $value = mb_substr($value, 0, (int) $this->attributes['maxlength'], Spoon::getCharset());
             }
             // html allowed?
             if (!$allowHTML) {
                 $value = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value);
             }
         }
     }
     return $value;
 }
Esempio n. 7
0
 /**
  * Changes the charset from standard utf-8 to your preferred value.
  *
  * @param	string[optional] $charset	The charset to use, default is utf-8.
  */
 public function setCharset($charset = 'utf-8')
 {
     $this->charset = $charset !== null ? SpoonFilter::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset();
 }
Esempio n. 8
0
 /**
  * Prepares a string so that it can be used in urls.
  *
  * @return	string						The urlised string.
  * @param	string $value				The value that should be urlised.
  * @param	string[optional] $charset	The charset to use, default is based on Spoon::getCharset().
  */
 public static function urlise($value, $charset = null)
 {
     // define charset
     $charset = $charset !== null ? self::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset();
     // reserved characters (RFC 3986)
     $reservedCharacters = array('/', '?', ':', '@', '#', '[', ']', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=');
     // remove reserved characters
     $value = str_replace($reservedCharacters, ' ', $value);
     // replace double quote, since this one might cause problems in html (e.g. <a href="double"quote">)
     $value = str_replace('"', ' ', $value);
     // replace spaces by dashes
     $value = str_replace(' ', '-', $value);
     // only urlencode if not yet urlencoded
     if (urldecode($value) == $value) {
         // to lowercase
         $value = mb_strtolower($value, $charset);
         // urlencode
         $value = urlencode($value);
     }
     // convert "--" to "-"
     $value = preg_replace('/\\-+/', '-', $value);
     // trim - signs
     return trim($value, '-');
 }
Esempio n. 9
0
 /**
  * Retrieve the method post/get.
  *
  * @return	string
  */
 public function getMethod()
 {
     // prevent against xss
     $method = Spoon::getCharset() == 'utf-8' ? SpoonFilter::htmlspecialchars($this->method) : SpoonFilter::htmlentities($this->method);
     return $method;
 }
Esempio n. 10
0
 /**
  * Makes this string lowercase.
  *    syntax: {{ $string|lowercase }}.
  *
  *
  * @param string $string The string that you want to apply this method on.
  *
  * @return string The string, completely lowercased.
  */
 public static function lowercase($string)
 {
     return mb_convert_case($string, MB_CASE_LOWER, \Spoon::getCharset());
 }