Ejemplo n.º 1
0
 public static function shortcut($defs, $value, $tag = 'h3', $props = NULL)
 {
     $name = strtolower(str_replace(' ', '_', $value));
     $info = self::process_info($defs, array(), $name);
     $info['tags'] = array('<' . $tag . Formo::quicktagss($props) . '>', '</' . $tag . '>');
     $info['value'] = $value;
     return new Formo_h_Driver($name, $info);
 }
Ejemplo n.º 2
0
 public function render()
 {
     $sel = '';
     $sel .= '<select name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . ">" . "\n";
     foreach ($this->values as $k => $v) {
         $k = preg_replace('/_[bB][lL][aA][nN][kK][0-9]*_/', '', $k);
         $selected = $v == $this->value ? " selected='selected'" : '';
         $sel .= "\t\t" . '<option value="' . $v . '"' . $selected . '>' . $k . '</option>' . "\n";
     }
     $sel .= "</select>";
     return $sel;
 }
Ejemplo n.º 3
0
 public function render()
 {
     // create captcha object here if it's an image
     if (!$this->captcha) {
         $this->captcha = Captcha::factory($this->group);
     }
     // add the clear html to the close tag
     $this->close = $this->clear . $this->close;
     // only load the captcha if we're not sure it's a human
     if (!$this->captcha->promoted()) {
         return $this->captcha_open . "\n" . $this->captcha->render(TRUE) . "\n" . $this->captcha_close . $this->input_open . '<input type="text" name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . ' />' . "\n" . $this->input_close;
     }
 }
Ejemplo n.º 4
0
 public function render()
 {
     $sel = '';
     $sel .= '<select name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . ">" . "\n";
     $i = 0;
     foreach ($this->values as $v => $k) {
         if ($i == 0 and $this->blank === TRUE) {
             $sel .= $this->_option('', '', '');
         }
         if (is_array($this->blank) and in_array($i, $this->blank)) {
             $sel .= $this->_option('', '', '');
         }
         $k = preg_replace('/_[bB][lL][aA][nN][kK][0-9]*_/', '', $k);
         $selected = $v == $this->value ? ' selected="selected"' : '';
         $sel .= $this->_option($k, $v, $selected);
         $i++;
     }
     $sel .= "</select>";
     return $sel;
 }
Ejemplo n.º 5
0
 public function render()
 {
     return '<input type="submit" name="' . preg_replace('/ /', '_', $this->name) . '" value="' . htmlspecialchars($this->value) . '"' . Formo::quicktagss($this->_find_tags()) . ' />';
 }
Ejemplo n.º 6
0
 public function render()
 {
     return '<input type="text" name="' . $this->name . '" value="' . htmlspecialchars($this->value) . '"' . Formo::quicktagss($this->_find_tags()) . ' />';
 }
Ejemplo n.º 7
0
 protected function render_legend()
 {
     return '<legend' . Formo::quicktagss($this->legend_tags) . '>' . $this->legend_name . '</legend>' . "\n";
 }
Ejemplo n.º 8
0
 public function render()
 {
     $quote = preg_match('/"/', $this->value) ? "'" : '"';
     return '<input type="hidden" name="' . $this->name . '" value=' . $quote . $this->value . $quote . '' . Formo::quicktagss($this->_find_tags()) . ' />';
 }
Ejemplo n.º 9
0
 public function render()
 {
     $value = $this->keep === TRUE ? ' value="' . $this->value . '"' : '';
     return '<input type="password" name="' . $this->name . '"' . $value . Formo::quicktagss($this->_find_tags()) . ' />';
 }
Ejemplo n.º 10
0
 public function render()
 {
     $checked = $this->checked === TRUE ? ' checked="checked"' : '';
     return '<input type="radio" value="' . $this->value . '" name="' . $this->name . '"' . $checked . Formo::quicktagss($this->_find_tags()) . ' />';
 }
Ejemplo n.º 11
0
 public function render()
 {
     return '<input type="image" name="' . $this->name . '" value="' . $this->value . '"' . Formo::quicktagss($this->_find_tags()) . ' />';
 }
Ejemplo n.º 12
0
 public function render()
 {
     return '<textarea name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . '>' . htmlspecialchars($this->value) . '</textarea>';
 }
Ejemplo n.º 13
0
 public function render()
 {
     return '<button name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . '>' . $this->value . '</button>';
 }
Ejemplo n.º 14
0
 protected function validate_this()
 {
     $input = Input::instance();
     $fname = isset($_FILES[$this->name . '_file']) ? $this->name . '_file' : $this->name;
     $file = isset($_FILES[$fname]) ? $_FILES[$fname] : NULL;
     $already_uploaded = $input->post($this->name . '_path') ? TRUE : FALSE;
     $this->was_validated = TRUE;
     if ($this->required and empty($file['name']) and !$already_uploaded) {
         if ($already_uploaded and is_file($input->post($this->name . '_path'))) {
             unlink($input->post($this->name . '_path'));
         }
         $this->error = $this->required_msg;
         return $this->error;
     } elseif (!$this->required and !$input->post($this->name) and empty($file['name'])) {
         return;
     } else {
         $allowed_types = Formo::splitby($this->allowed_types);
         $time = time();
         // this means we're good with the file uploaded already
         if ($already_uploaded === TRUE and !$file['name']) {
             $full_path = $input->post($this->name . '_path');
             $path = array_pop(explode('/', $full_path));
             $file_name = $input->post($this->name);
         } elseif ($file['name']) {
             // delete old entry
             if ($already_uploaded) {
                 $full_path = $input->post($this->name . '_path');
                 $path = array_pop(preg_split('/\\//', $full_path));
                 $file_name = $input->post($this->name);
                 if (is_file($full_path)) {
                     unlink($full_path);
                 }
             }
             // start validating
             if (!upload::required($file)) {
                 return $this->error = Kohana::lang('formo.invalidfile');
             }
             if (!upload::size($file, array($this->max_size))) {
                 return $this->error = Kohana::lang('formo.too_large') . ' (' . $this->max_size . ')';
             }
             if (!upload::type($file, $allowed_types)) {
                 return $this->error = Kohana::lang('formo.invalid_type');
             }
             $full_path = upload::save($fname, $time . $file['name'], DOCROOT . $this->upload_path, 0777);
             $path = array_pop(preg_split('/\\//', $full_path));
             $file_name = $file['name'];
         }
         // fill $this->data with appropriate info
         $this->data['orig_name'] = $file_name;
         $this->data['file_name'] = end(preg_split('/\\//', $full_path));
         $this->data['path'] = preg_replace('/\\/' . $this->data['file_name'] . '/', '', $full_path);
         $this->data['full_path'] = $full_path;
         $this->data['file_ext'] = strtolower(substr(strrchr($file_name, '.'), 1));
         $this->data['file_type'] = reset(Kohana::config('mimes.' . $this->data['file_ext']));
         $this->data['bytes'] = filesize($full_path);
         $this->data['file_size'] = round(filesize($full_path) / 1024, 2);
         $this->data['time'] = $time;
         if ($isize = getimagesize($full_path)) {
             $this->data['is_image'] = 1;
             $this->data['image_width'] = $isize[0];
             $this->data['image_height'] = $isize[1];
             $this->data['image_size_str'] = $isize[3];
         } else {
             $this->data['is_image'] = 0;
             $this->data['image_width'] = NULL;
             $this->data['image_height'] = NULL;
             $this->data['image_size_str'] = NULL;
         }
         $this->value = $this->data;
         // create the extra stuff for saving past, accepted uploads and unvalidated forms
         $this->type = 'text';
         $this->_was_file = TRUE;
         $this->add_class($this->file_link_class);
         $this->value = $file_name;
         $this->readOnly = 'readOnly';
         $this->onClick = 'file_replace(\'' . $this->id . '\')';
         $oldclose = $this->element_close;
         $class = !empty($this->class) ? ' class="' . preg_replace('/ *' . $this->file_link_class . '/', '', $this->class) . '"' : '';
         $this->str = '<input type="text" name="' . $this->name . '" value="' . $this->value . '"' . Formo::quicktagss($this->_find_tags()) . ' />' . '<script type="text/javascript">' . "\n" . 'function file_replace(id){' . "\n" . 'var txt = document.getElementById(id);' . "\n" . 'var file = document.getElementById(id+"_file");' . "\n" . 'txt.style.display = "none";' . "\n" . 'file.style.display = "inline";' . "\n" . '}' . "\n" . '</script>' . "\n" . '<input type="hidden" name="' . $this->name . '_path" id="' . $this->id . '_path" value="' . $full_path . '" />' . "\n" . '<input type="file" name="' . $this->name . '_file" id="' . $this->id . '_file"' . $class . ' style="display:none"/>' . "\n" . $oldclose;
     }
 }
Ejemplo n.º 15
0
 public function render()
 {
     return '<input type="password" name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . '" />';
 }
Ejemplo n.º 16
0
    public function render()
    {
        $quicktagss = Formo::quicktagss($this->_find_tags());
        $current_url = url::site(url::current());
        switch ($this->mode) {
            case 'simple':
                // if a source was defined, get the data from there
                // else use the predefined data
                $source = $this->source ? "serviceUrl: '" . $current_url . "'" : "lookup: ['" . implode("', '", $this->data) . "']";
                return <<<EOT
\t<input type="text" rel="simple" name="{$this->name}" id="{$this->name}" value="{$this->value}"{$quicktagss} />
\t<script type="text/javascript">
\t\$(document).ready(function(){
\t\t\$('input#{$this->name}','form[name={$this->formo_name}]').autocomplete({
\t\t\t{$source}
\t\t});
\t});
\t</script>
EOT;
                break;
            case 'paired':
                $classes = $this->class . ' autocomplete';
                return <<<EOT
\t<input type="text" rel="paired" id="{$this->name}" class="{$classes}" />
\t<input type="hidden" name="{$this->name}" value="{$this->value}"{$quicktagss} />
\t
\t<script type="text/javascript">
\t\$(document).ready(function(){
\t\t\$('input#{$this->name}','form[name={$this->formo_name}]').autocomplete({
\t\t\tserviceUrl:'{$current_url}',
\t\t\tonSelect: function(value, data){
\t\t\t\t\$('input[id={$this->name}]')
\t\t\t\t\t.nextAll('[name={$this->name}]')
\t\t\t\t\t.val(data)
\t\t\t\t\t.trigger('change');
\t\t\t}
\t\t}).blur(function(){
\t\t\tif(\$(this).val() == '')
\t\t\t{
\t\t\t\t\$(this).nextAll('[name={$this->name}]')
\t\t\t\t\t.val('')
\t\t\t\t\t.trigger('change');
\t\t\t}
\t\t});
\t});
\t</script>
EOT;
                break;
            case 'multi':
                $this->remove_class('ajaxval');
                $classes = $this->class . ' autocomplete';
                return <<<EOT
\t<input type="text" rel="multi" id="{$this->name}" class="{$classes}" />
\t<script type="text/javascript">
\t\$(document).ready(function(){\t\t
\t\tvar ac_input = \$('input#{$this->name}','form[name={$this->formo_name}]');
\t\t
\t\tac_input.autocomplete({
\t\t\tserviceUrl:'{$current_url}',
\t\t\tonSelect: function(value, data){
\t\t\t\t
\t\t\t\t// create an element that represents the data/value pair
\t\t\t\tvar ac_item = \$('<a href="#" class="autocomplete_item" id="'+data+'">' + value
\t\t\t\t+ '<input type="hidden" name="{$this->name}[]" value="'+data+'" /></a>');
\t\t\t\t
\t\t\t\t// insert it before the autocomplete input
\t\t\t\tac_item.insertBefore(ac_input);
\t\t\t\t
\t\t\t\tac_input.val('').focus();
\t\t\t}
\t\t});
\t\t
\t\t\$('a.autocomplete_item').live('click',function(){
\t\t\t\$(this).remove();
\t\t});
\t});
\t</script>
EOT;
                break;
        }
    }