function build_widget() { $value = $this->_get('value'); if (is_null($value)) { $value = ""; } assert('is_string($value); // only plain strings can be used as field value: type: ' . gettype($value)); $name = $this->get('name'); $widgets = array(); if ($this->get('show-img-preview') && $value) { $widgets[] = ax_div_class(ax_img_src($this->get('preview-dir') . $value), 'preview'); } elseif ($this->get('show-link-preview') && $value) { $widgets[] = ax_div_class(ax_a_href($value, $this->get('preview-dir') . $value), 'preview'); } $remove_label = $this->_get('remove-label'); if ($remove_label && $value) { $subattr = array('type' => 'checkbox', 'name' => $name . '-remove'); $widgets[] = new AnewtXHTMLInput(null, $subattr); $subattr = array('for' => $name . '-remove'); $widgets[] = new AnewtXHTMLLabel($remove_label, $subattr); $widgets[] = ax_br(); } /* XML tag attributes used both for single line and multiline */ $attr = array('name' => $this->get('name'), 'id' => $this->get('id'), 'type' => 'file'); if ($this->_get('readonly')) { $attr['readonly'] = 'readonly'; } if ($this->_get('disabled')) { $attr['disabled'] = 'disabled'; } $size = $this->_get('size'); if (!is_null($size)) { assert('is_int($size);'); $attr['size'] = (string) $size; } $maxlength = $this->_get('maxlength'); if (!is_null($maxlength)) { assert('is_int($maxlength);'); $attr['maxlength'] = (string) $maxlength; } $max_file_size = $this->_get('max_file_size'); if (!is_null($max_file_size)) { $subattr = array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => (string) $max_file_size); $widgets[] = new AnewtXHMTLInput(null, $subattr); } $widget = new AnewtXHTMLInput(null, $attr); /* Styling */ $widget->add_class('fileupload'); if (!$this->_get('required')) { $widget->add_class('optional'); } /* Optional extra class value */ $class = $this->_get('class'); if (!is_null($class)) { $widget->add_class($class); } /* Help text, if any */ $help = $this->_get('help'); if (!is_null($help)) { $help_text = to_string($help); $widget->set_attribute('title', $help_text); $widget->add_class('with-help'); } $widgets[] = $widget; /* Add secondary label, if any */ $secondary_label = $this->_get('secondary-label'); if (!is_null($secondary_label)) { $widgets[] = $secondary_label; } $out = ax_fragment($widgets); return $out; }
$fragment->append_child(new AnewtXHTMLHeader2('Forms')); $form = new AnewtXHTMLForm(null, array('method' => 'GET')); $input_fragment = new AnewtXHTMLFragment(); $input_fragment->append_child(new AnewtXHTMLLabel('Label: ', array('for' => 'test'))); $input_fragment->append_child(new AnewtXHTMLInput(null, array('name' => 'test', 'id' => 'test', 'type' => 'text'))); $form->append_child(new AnewtXHTMLParagraph($input_fragment)); $select = new AnewtXHTMLSelect(null, array('name' => 'select')); $select->append_child(new AnewtXHTMLOption('First', array('value' => 'first'))); $select->append_child(new AnewtXHTMLOption('Second', array('value' => 'second'))); $select->append_child(new AnewtXHTMLOption('Third', array('value' => 'third'))); $form->append_child(new AnewtXHTMLParagraph($select)); $fragment->append_child($form); $form->append_child(new AnewtXHTMLParagraph(new AnewtXHTMLInput(null, array('type' => 'submit')))); /* Convenience API */ $r = array(); $r[] = ax_h2('Convenience API'); $r[] = ax_p('Test with some <& special characters.', array('style' => 'color: #ccc;')); $r[] = ax_p_class(ax_raw('This is <strong>strong</strong>'), 'someclass'); $r[] = ax_p(ax_abbr('ICE', 'InterCity Express')); $r[] = ax_p(array('Test', ax_br(), 'after the break')); $p = ax_p(array('testje', array('1', '2'), ax_strong('blablabla'))); $p->set_attribute('id', 'paragraph-id'); $p->set_class('foo bar baz'); $p->remove_class('bar'); $p->add_class('quux'); $p->append_child(ax_a_href('name', '/url/')); $r[] = $p; $r[] = ax_p(ax_sprintf('%s & %s', ax_span_class('Sugar', 'sweet'), 'Spice')); $fragment->append_child(ax_fragment($r, ax_p('final paragraph'))); /* Final output */ echo to_string($fragment), NL;
function sum_method() { $methods_sh = array('id3' => 'id3', 'filename' => 'file', 'anchor' => 'anch', '' => ''); $display_values = array(); foreach ($this->method_counts as $method => $count) { $display_values[] = array(ax_raw("∑ " . $methods_sh[$method] . "="), $count, ax_br()); } return $display_values; }