Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/lib/txplib_forms.php - 306 lines - 9325 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.5.4/source/textpattern/lib/txplib_forms.php $
   5  $LastChangedRevision: 4872 $
   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'.($a == $var ? ' active' : '').'"';
  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="'.txpspecialchars($avalue).'"'.$sel.'>'.txpspecialchars($alabel).'</option>';
  77          }
  78  
  79          return '<select'.( $select_id ? ' id="'.$select_id.'"' : '' ).' name="'.$name.'"'.
  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="'.txpspecialchars($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="'.txpspecialchars($name).'"'.$htmltitle.$sel.'>'.$sp.txpspecialchars($title).$hellip.'</option>';
 126          }
 127  
 128          return n.'<select'.( $select_id ? ' id="'.$select_id.'" ' : '' ).' name="'.$select_name.'">'.
 129              n.t.'<option value=""'.($selected == false ? ' selected="selected"' : '').'>&#160;</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                      $required = false)
 146      {
 147          $o  = '<input type="'.$type.'"';
 148          $o .= ($type == 'file' || $type == 'image') ? '' : ' value="'.txpspecialchars($value).'"';
 149          $o .= strlen($name)? ' name="'.$name.'"' : '';
 150          $o .= ($size)     ? ' size="'.$size.'"' : '';
 151          $o .= ($class)    ? ' class="'.$class.'"' : '';
 152          $o .= ($title)    ? ' title="'.$title.'"' : '';
 153          $o .= ($onClick)  ? ' onclick="'.$onClick.'"' : '';
 154          $o .= ($tab)      ? ' tabindex="'.$tab.'"' : '';
 155          $o .= ($id)       ? ' id="'.$id.'"' : '';
 156          $o .= ($disabled) ? ' disabled="disabled"' : '';
 157          $o .= ($required) ? ' required' : '';
 158          $o .= " />";
 159          return $o;
 160      }
 161  
 162  // -------------------------------------------------------------
 163      // deprecated in 4.2.0
 164  	function cleanfInput($text)
 165      {
 166          trigger_error(gTxt('deprecated_function_with', array('{name}' => __FUNCTION__, '{with}' => 'escape_title')), E_USER_NOTICE);
 167          return escape_title($text);
 168      }
 169  
 170  //-------------------------------------------------------------
 171  	function hInput($name,$value)        // hidden form input
 172      {
 173          return fInput('hidden',$name,$value);
 174      }
 175  
 176  //-------------------------------------------------------------
 177  	function sInput($step)                // hidden step input
 178      {
 179          return hInput('step',$step);
 180      }
 181  
 182  //-------------------------------------------------------------
 183  	function eInput($event)                // hidden event input
 184      {
 185          return hInput('event',$event);
 186      }
 187  
 188  //-------------------------------------------------------------
 189  	function tInput()                // hidden form token input
 190      {
 191          return hInput('_txp_token', form_token());
 192      }
 193  
 194  //-------------------------------------------------------------
 195  
 196  	function checkbox($name, $value, $checked = '1', $tabindex = '', $id = '')
 197      {
 198          $o[] = '<input type="checkbox" name="'.$name.'" value="'.$value.'"';
 199          $o[] = ($id) ? ' id="'.$id.'"' : '';
 200          $o[] = ($checked == '1') ? ' checked="checked"' : '';
 201          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 202          $o[] = ' class="checkbox'.($checked == '1' ? ' active' : '').'" />';
 203  
 204          return join('', $o);
 205      }
 206  
 207  //-------------------------------------------------------------
 208  
 209  	function checkbox2($name, $value, $tabindex = '', $id = '')
 210      {
 211          $o[] = '<input type="checkbox" name="'.$name.'" value="1"';
 212          $o[] = ($id) ? ' id="'.$id.'"' : '';
 213          $o[] = ($value == '1') ? ' checked="checked"' : '';
 214          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 215          $o[] = ' class="checkbox'.($value == '1' ? ' active' : '').'" />';
 216  
 217          return join('', $o);
 218      }
 219  
 220  //-------------------------------------------------------------
 221  
 222  	function radio($name, $value, $checked = '1', $id = '', $tabindex = '')
 223      {
 224          $o[] = '<input type="radio" name="'.$name.'" value="'.$value.'"';
 225          $o[] = ($id) ? ' id="'.$id.'"' : '';
 226          $o[] = ($checked == '1') ? ' checked="checked"' : '';
 227          $o[] = ($tabindex) ? ' tabindex="'.$tabindex.'"' : '';
 228          $o[] = ' class="radio'.($checked == '1' ? ' active' : '').'" />';
 229  
 230          return join('', $o);
 231      }
 232  
 233  //-------------------------------------------------------------
 234  
 235  	function form($contents, $style = '', $onsubmit = '', $method = 'post', $class = '', $fragment = '', $id = '')
 236      {
 237          return n.'<form method="'.$method.'" action="index.php'.($fragment ? '#'.$fragment.'"' : '"').
 238              ($id ? ' id="'.$id.'"' : '').
 239              ($class ? ' class="'.$class.'"' : '').
 240              ($style ? ' style="'.$style.'"' : '').
 241              ($onsubmit ? ' onsubmit="return '.$onsubmit.'"' : '').
 242              '>'.$contents.n.
 243              tInput().n.
 244              '</form>'.n;
 245      }
 246  
 247  // -------------------------------------------------------------
 248  	function fetch_editable($name,$event,$identifier,$id)
 249      {
 250          $q = fetch($name,'txp_'.$event,$identifier,$id);
 251          return txpspecialchars($q);
 252      }
 253  
 254  //-------------------------------------------------------------
 255  
 256  	function text_area($name, $h='', $w='', $thing = '', $id = '', $rows='5', $cols='40')
 257      {
 258          $id = ($id) ? ' id="'.$id.'"' : '';
 259          $rows = ' rows="' . ( ($rows && is_numeric($rows)) ? $rows : '5') . '"';
 260          $cols = ' cols="' . ( ($cols && is_numeric($cols)) ? $cols : '40') . '"';
 261          $width = ($w) ? 'width:'.$w.'px;' : '';
 262          $height = ($h) ? 'height:'.$h.'px;' : '';
 263          $style = ($width || $height) ? ' style="'.$width.$height.'"' : '';
 264          return '<textarea'.$id.' name="'.$name.'"'.$rows.$cols.$style.'>'.txpspecialchars($thing).'</textarea>';
 265      }
 266  
 267  //-------------------------------------------------------------
 268  	function type_select($options)
 269      {
 270          return '<select name="type">'.n.type_options($options).'</select>'.n;
 271      }
 272  
 273  //-------------------------------------------------------------
 274  	function type_options($array)
 275      {
 276          foreach($array as $a=>$b) {
 277              $out[] = t.'<option value="'.$a.'">'.gTxt($b).'</option>'.n;
 278          }
 279          return join('',$out);
 280      }
 281  
 282  
 283  //-------------------------------------------------------------
 284  	function radio_list($name, $values, $current_val='', $hilight_val='')
 285      {
 286          // $values is an array of value => label pairs
 287          foreach ($values as $k => $v)
 288          {
 289              $id = $name.'-'.$k;
 290              $out[] = n.t.'<li class="status-'.$k.' '.$v.($hilight_val == $k ? ' active' : '').'">'.radio($name, $k, ($current_val == $k) ? 1 : 0, $id).
 291                  '<label for="'.$id.'">'.($hilight_val == $k ? strong($v) : $v).'</label></li>';
 292          }
 293  
 294          return '<ul class="status plain-list">'.join('', $out).n.'</ul>';
 295      }
 296  
 297  //--------------------------------------------------------------
 298  	function tsi($name,$datevar,$time,$tab='')
 299      {
 300          $size = ($name=='year' or $name=='exp_year') ? INPUT_XSMALL : INPUT_TINY;
 301          $s = ($time == 0)? '' : safe_strftime($datevar, $time);
 302          return n.'<input type="text" name="'.$name.'" value="'.
 303              $s
 304          .'" size="'.$size.'" maxlength="'.$size.'" class="'.$name.'"'.(empty($tab) ? '' : ' tabindex="'.$tab.'"').' title="'.gTxt('article_'.$name).'" />';
 305      }
 306  ?>

title

Description

title

Description

title

Description

title

title

Body