Exemplo n.º 1
0
 public function init($a)
 {
     parent::init($a);
     if ($this->value) {
         $this->loadValue();
     }
     if (!$this->timezone) {
         $this->timezone = new DateTimeZone(ini_get('date.timezone') ?: 'Asia/Taipei');
     }
     if (!$this->start_year) {
         $this->start_year = 1980;
     }
     if (!$this->end_year) {
         $this->end_year = (int) date('Y');
     }
     $this->formatOptions = array('Y' => array(), 'm' => array(), 'd' => array());
     foreach (range($this->start_year ?: 1980, $this->end_year) as $i) {
         $this->formatOptions['Y'][$i] = $i;
     }
     foreach (range($this->start_year ?: 1980, $this->end_year) as $i) {
         $this->formatOptions['y'][$i] = substr($i, -2);
     }
     foreach (range(1, 12) as $m) {
         $this->formatOptions['m'][sprintf('%02d', $m)] = sprintf('%02d', $m);
     }
     $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
     foreach ($months as $m) {
         $this->formatOptions['M'][$m] = $m;
     }
     foreach (range(1, 31) as $d) {
         $this->formatOptions['d'][sprintf('%02d', $d)] = sprintf('%02d', $d);
     }
     $weekDays = array("Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed");
     foreach ($weekDays as $d) {
         $this->formatOptions['D'][$d] = $d;
     }
     foreach (range(1, 31) as $j) {
         $this->formatOptions['j'][$j] = $j;
     }
     $this->formatOptions['a'] = array('am' => 'am', 'pm' => 'pm');
     $this->formatOptions['A'] = array('AM' => 'AM', 'PM' => 'PM');
     foreach (range(1, 12) as $g) {
         $this->formatOptions['g'][$g] = $g;
     }
     foreach (range(0, 23) as $G) {
         $this->formatOptions['G'][$G] = $G;
     }
     foreach (range(1, 12) as $h) {
         $this->formatOptions['h'][$h] = $h;
     }
     foreach (range(0, 23) as $H) {
         $this->formatOptions['H'][sprintf('%02d', $h)] = sprintf('%02d', $h);
     }
     foreach (range(0, 59) as $i) {
         $this->formatOptions['i'][sprintf('%02d', $i)] = sprintf('%02d', $i);
     }
     foreach (range(0, 59) as $s) {
         $this->formatOptions['s'][sprintf('%02d', $s)] = sprintf('%02d', $s);
     }
 }
Exemplo n.º 2
0
 /**
  * HTML structure
  *
  * <div class="formkit-widget formkit-widget-thumbimagefile formkit-image-wrapper">
  *    <div class="formkit-image-cover">
  *      <img src="...."/>
  *    </div>
  *    <input type="file"...>
  * </div>
  *
  */
 public function init($attributes)
 {
     $this->autoresize_types = array(_('Fit to Width') => 'max_width', _('Fit to Height') => 'max_height', _('Scale') => 'scale', _('Crop and Scale') => 'crop_and_scale');
     parent::init($attributes);
     $this->fileInput = new FileInput($this->name, $attributes);
     $this->imageCover = new Div(array('class' => 'formkit-image-cover'));
     $this->imageCover->setAttributeValue('data-width', $this->dataWidth ?: 200);
     $this->imageCover->setAttributeValue('data-height', $this->dataHeight);
     $this->inputWrapper = new Div();
     $this->inputWrapper->addClass('formkit-widget-thumbimagefile')->addClass('formkit-image-wrapper');
     // if it has a value, generate img
     if ($this->renderImageTag && $this->value) {
         $this->image = new Element('img', array('src' => $this->prefix . $this->value));
         $this->imageCover->append($this->image);
     }
     if ($this->value) {
         $this->fileInput->setAttributeValue('data-image-src', $this->prefix . $this->value);
     }
     if ($this->exif) {
         $this->fileInput->setAttributeValue('data-exif', 'true');
     }
     if ($this->autoresize) {
         $this->fileInput->setAttributeValue('data-autoresize', 'true');
     }
     if ($this->droppreview) {
         $this->fileInput->setAttributeValue('data-droppreview', 'true');
     }
     if ($this->dropupload) {
         $this->fileInput->setAttributeValue('data-dropupload', 'true');
     }
     $this->fileInput->setAttributeValue('data-width', $this->dataWidth);
     $this->fileInput->setAttributeValue('data-height', $this->dataHeight);
     $this->inputWrapper->append($this->imageCover);
     $this->inputWrapper->append($this->fileInput);
     if ($this->autoresize && $this->autoresize_input) {
         $this->fileInput->setAttributeValue('data-autoresize-input', 'true');
         $checkbox = new CheckboxInput($this->name . '_autoresize');
         $checkbox->addClass('autoresize-checkbox');
         if ($this->autoresize_input_check) {
             $checkbox->check();
         }
         $checkboxId = $checkbox->getSerialId();
         $label = new Label(_("Use auto-resize"));
         $label->for($checkboxId);
         $resizeWrapper = new Div();
         $resizeWrapper->append($checkbox);
         $resizeWrapper->append($label);
         $resizeWrapper->addClass("autoresize");
         $this->inputWrapper->append($resizeWrapper);
         if ($this->autoresize_type_input) {
             $resizeTypeWrapper = new Div();
             $resizeTypeWrapper->addClass('autoresize-type');
             $typeSelector = new SelectInput($this->name . '_autoresize_type', ['options' => $this->autoresize_types, 'value' => $this->autoresize_type]);
             $typeSelector->addClass('autoresize-type-selector');
             $resizeTypeWrapper->append($typeSelector);
             $this->inputWrapper->append($resizeTypeWrapper);
         }
     }
 }