[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/lib/ -> txplib_forms.php (source)

   1  <?php
   2  
   3  /*
   4  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/lib/txplib_forms.php $
   5  $LastChangedRevision: 3079 $
   6  */
   7  
   8  //-------------------------------------------------------------
   9  
  10  	function radioSet($vals, $field, $var, $tabindex = '', $id = '')
  11      {
  12          $id = ($id) ? $id.'-'.$field : $field;
  13  
  14          foreach ($vals as $a => $b)
  15          {
  16              $out[] = '<input type="radio" id="'.$id.'-'.$a.'" name="'.$field.'" value="'.$a.'" class="radio"';
  17              $out[] = ($a == $var) ? ' checked="checked"' : '';
  18              $out[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
  19              $out[] = ' /><label for="'.$id.'-'.$a.'">'.$b.'</label> ';
  20          }
  21  
  22          return join('', $out);
  23      }
  24  
  25  //-------------------------------------------------------------
  26  
  27  	function yesnoRadio($field, $var, $tabindex = '', $id = '')
  28      {
  29          $vals = array(
  30              '0' => gTxt('no'),
  31              '1' => gTxt('yes')
  32          );
  33          return radioSet ($vals, $field, $var, $tabindex, $id);
  34      }
  35  
  36  //-------------------------------------------------------------
  37  
  38  	function onoffRadio($field, $var, $tabindex = '', $id = '')
  39      {
  40          $vals = array(
  41              '0' => gTxt('off'),
  42              '1' => gTxt('on')
  43          );
  44  
  45          return radioSet ($vals, $field, $var, $tabindex, $id);
  46      }
  47  
  48  //-------------------------------------------------------------
  49  
  50  	function selectInput($name = '', $array = '', $value = '', $blank_first = '', $onchange = '', $select_id = '', $check_type = false)
  51      {
  52          $out = array();
  53  
  54          $selected = false;
  55  
  56          foreach ($array as $avalue => $alabel)
  57          {
  58              if ($check_type) {
  59                  if ($avalue === $value || $alabel === $value) {
  60                      $sel = ' selected="selected"';
  61                      $selected = true;
  62                  } else {
  63                      $sel = '';
  64                  }
  65              }
  66  
  67              else {
  68                  if ($avalue == $value || $alabel == $value) {
  69                      $sel = ' selected="selected"';
  70                      $selected = true;
  71                  } else {
  72                      $sel = '';
  73                  }
  74              }
  75  
  76              $out[] = n.t.'<option value="'.htmlspecialchars($avalue).'"'.$sel.'>'.htmlspecialchars($alabel).'</option>';
  77          }
  78  
  79          return '<select'.( $select_id ? ' id="'.$select_id.'"' : '' ).' name="'.$name.'" class="list"'.
  80              ($onchange == 1 ? ' onchange="submit(this.form);"' : $onchange).
  81              '>'.
  82              ($blank_first ? n.t.'<option value=""'.($selected == false ? ' selected="selected"' : '').'></option>' : '').
  83              ( $out ? join('', $out) : '').
  84              n.'</select>';
  85      }
  86  
  87  //-------------------------------------------------------------
  88  
  89  	function treeSelectInput($select_name = '', $array = '', $value = '', $select_id = '', $truncate = 0)
  90      {
  91          $out = array();
  92  
  93          $selected = false;
  94  
  95          foreach ($array as $a)
  96          {
  97              if ($a['name'] == 'root')
  98              {
  99                  continue;
 100              }
 101  
 102              extract($a);
 103  
 104              if ($name == $value)
 105              {
 106                  $sel = ' selected="selected"';
 107                  $selected = true;
 108              }
 109  
 110              else
 111              {
 112                  $sel = '';
 113              }
 114  
 115              $sp = str_repeat(sp.sp, $level);
 116  
 117              if (($truncate > 3) && (strlen(utf8_decode($title)) > $truncate)) {
 118                  $htmltitle = ' title="'.htmlspecialchars($title).'"';
 119                  $title = preg_replace('/^(.{0,'.($truncate - 3).'}).*$/su','$1',$title);
 120                  $hellip = '&#8230;';
 121              } else {
 122                  $htmltitle = $hellip = '';
 123              }
 124  
 125              $out[] = n.t.'<option value="'.htmlspecialchars($name).'"'.$htmltitle.$sel.'>'.$sp.htmlspecialchars($title).$hellip.'</option>';
 126          }
 127  
 128          return n.'<select'.( $select_id ? ' id="'.$select_id.'" ' : '' ).' name="'.$select_name.'" class="list">'.
 129              n.t.'<option value=""'.($selected == false ? ' selected="selected"' : '').'>&nbsp;</option>'.
 130              ( $out ? join('', $out) : '').
 131              n.'</select>';
 132      }
 133  
 134  //-------------------------------------------------------------
 135  	function fInput($type,                   // generic form input
 136                      $name,
 137                      $value,
 138                      $class='',
 139                      $title='',
 140                      $onClick='',
 141                      $size='',
 142                      $tab='',
 143                      $id='',
 144                      $disabled = false)
 145      {
 146          $o  = '<input type="'.$type.'"';
 147          $o .= ' value="'.htmlspecialchars($value).'"';
 148          $o .= strlen($name)? ' name="'.$name.'"' : '';
 149          $o .= ($size)     ? ' size="'.$size.'"' : '';
 150          $o .= ($class)    ? ' class="'.$class.'"' : '';
 151          $o .= ($title)    ? ' title="'.$title.'"' : '';
 152          $o .= ($onClick)  ? ' onclick="'.$onClick.'"' : '';
 153          $o .= ($tab)      ? ' tabindex="'.$tab.'"' : '';
 154          $o .= ($id)       ? ' id="'.$id.'"' : '';
 155          $o .= ($disabled) ? ' disabled="disabled"' : '';
 156          $o .= " />";
 157          return $o;
 158      }
 159  
 160  // -------------------------------------------------------------
 161      // deprecated (use escape_title instead), remove in crockery
 162  	function cleanfInput($text)
 163      {
 164          return escape_title($text);
 165      }
 166  
 167  //-------------------------------------------------------------
 168  	function hInput($name,$value)        // hidden form input
 169      {
 170          return fInput('hidden',$name,$value);
 171      }
 172  
 173  //-------------------------------------------------------------
 174  	function sInput($step)                // hidden step input
 175      {
 176          return hInput('step',$step);
 177      }
 178  
 179  //-------------------------------------------------------------
 180  	function eInput($event)                // hidden event input
 181      {
 182          return hInput('event',$event);
 183      }
 184  
 185  //-------------------------------------------------------------
 186  
 187  	function checkbox($name, $value, $checked = '1', $tabindex = '', $id = '')
 188      {
 189          $o[] = '<input type="checkbox" name="'.$name.'" value="'.$value.'"';
 190          $o[] = ($id) ? ' id="'.$id.'"' : '';
 191          $o[] = ($checked == '1') ? ' checked="checked"' : '';
 192          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 193          $o[] = ' class="checkbox" />';
 194  
 195          return join('', $o);
 196      }
 197  
 198  //-------------------------------------------------------------
 199  
 200  	function checkbox2($name, $value, $tabindex = '', $id = '')
 201      {
 202          $o[] = '<input type="checkbox" name="'.$name.'" value="1"';
 203          $o[] = ($id) ? ' id="'.$id.'"' : '';
 204          $o[] = ($value == '1') ? ' checked="checked"' : '';
 205          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 206          $o[] = ' class="checkbox" />';
 207  
 208          return join('', $o);
 209      }
 210  
 211  //-------------------------------------------------------------
 212  
 213  	function radio($name, $value, $checked = '1', $id = '', $tabindex = '')
 214      {
 215          $o[] = '<input type="radio" name="'.$name.'" value="'.$value.'"';
 216          $o[] = ($id) ? ' id="'.$id.'"' : '';
 217          $o[] = ($checked == '1') ? ' checked="checked"' : '';
 218          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 219          $o[] = ' class="radio" />';
 220  
 221          return join('', $o);
 222      }
 223  
 224  //-------------------------------------------------------------
 225  
 226  	function form($contents, $style = '', $onsubmit = '', $method = 'post', $class = '', $fragment = '')
 227      {
 228          return n.'<form method="'.$method.'" action="index.php'.($fragment ? '#'.$fragment.'"' : '"').
 229              ($class ? ' class="'.$class.'"' : '').
 230              ($style ? ' style="'.$style.'"' : '').
 231              ($onsubmit ? ' onsubmit="return '.$onsubmit.'"' : '').
 232              '>'.$contents.'</form>'.n;
 233      }
 234  
 235  // -------------------------------------------------------------
 236  	function fetch_editable($name,$event,$identifier,$id)
 237      {
 238          $q = fetch($name,'txp_'.$event,$identifier,$id);
 239          return htmlspecialchars($q);
 240      }
 241  
 242  //-------------------------------------------------------------
 243  
 244  	function text_area($name, $h, $w, $thing = '', $id = '')
 245      {
 246          $id = ($id) ? ' id="'.$id.'"' : '';
 247          return '<textarea'.$id.' name="'.$name.'" cols="40" rows="5" style="width:'.$w.'px; height:'.$h.'px;">'.htmlspecialchars($thing).'</textarea>';
 248      }
 249  
 250  //-------------------------------------------------------------
 251  	function type_select($options)
 252      {
 253          return '<select name="type">'.n.type_options($options).'</select>'.n;
 254      }
 255  
 256  //-------------------------------------------------------------
 257  	function type_options($array)
 258      {
 259          foreach($array as $a=>$b) {
 260              $out[] = t.'<option value="'.$a.'">'.gTxt($b).'</option>'.n;
 261          }
 262          return join('',$out);
 263      }
 264  
 265  
 266  //-------------------------------------------------------------
 267  	function radio_list($name, $values, $current_val='', $hilight_val='')
 268      {
 269          // $values is an array of value => label pairs
 270          foreach ($values as $k => $v)
 271          {
 272              $id = $name.'-'.$k;
 273              $out[] = n.t.'<li>'.radio($name, $k, ($current_val == $k) ? 1 : 0, $id).
 274                  '<label for="'.$id.'">'.($hilight_val == $k ? strong($v) : $v).'</label></li>';
 275          }
 276  
 277          return '<ul class="plain-list">'.join('', $out).n.'</ul>';
 278      }
 279  
 280  //--------------------------------------------------------------
 281  	function tsi($name,$datevar,$time,$tab='')
 282      {
 283          $size = ($name=='year' or $name=='exp_year') ? 4 : 2;
 284          $s = ($time == 0)? '' : safe_strftime($datevar, $time);
 285          return n.'<input type="text" name="'.$name.'" value="'.
 286              $s
 287          .'" size="'.$size.'" maxlength="'.$size.'" class="edit"'.(empty($tab) ? '' : ' tabindex="'.$tab.'"').' title="'.gTxt('article_'.$name).'" />';
 288      }
 289  
 290  ?>


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7