Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/lib/txplib_html.php - 1239 lines - 31987 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.5.4/source/textpattern/lib/txplib_html.php $
   5  $LastChangedRevision: 4163 $
   6  */
   7  
   8      define("t","\t");
   9      define("n","\n");
  10      define("br","<br />");
  11      define("sp","&#160;");
  12      define("a","&#38;");
  13  
  14  
  15  /**
  16   * Render the admin-side theme's footer partial via the "admin_side" > "footer" pluggable UI.
  17   * and send the "admin_side" > "body_end" event.
  18   */
  19  
  20  	function end_page()
  21      {
  22          global $txp_user, $event, $app_mode, $theme, $textarray_script;
  23  
  24          if ($app_mode != 'async' && $event != 'tag') {
  25              echo '</div><!-- /txp-body --><div class="txp-footer">';
  26              echo pluggable_ui('admin_side', 'footer', $theme->footer());
  27              callback_event('admin_side', 'body_end');
  28              echo n.script_js('textpattern.textarray = '.json_encode($textarray_script)).n.
  29              '</div><!-- /txp-footer --></body>'.n.'</html>';
  30          }
  31      }
  32  
  33  
  34  /**
  35   * Render the user interface for one head cell of columnar data.
  36   *
  37   * @param    string    $value    Element text
  38   * @param    string    $sort    Sort criterion ['']
  39   * @param    string    $event    Event name ['']
  40   * @param    boolean    $is_link    Include link to admin action in user interface according to the other params [false]
  41   * @param    string    $dir    Sort direction, either "asc" or "desc" ['']
  42   * @param    string    $crit    Search criterion ['']
  43   * @param    string    $method    Search method ['']
  44   * @param    string    $class    HTML "class" attribute applied to the resulting element ['']
  45   * @param    string    $step    Step name
  46   * @return     string    HTML
  47   */
  48  
  49  	function column_head($value, $sort = '', $event = '', $is_link = '', $dir = '', $crit = '', $method = '', $class = '', $step = 'list')
  50      {
  51          return column_multi_head( array(
  52                      array ('value' => $value, 'sort' => $sort, 'event' => $event, 'step' => $step, 'is_link' => $is_link,
  53                             'dir' => $dir, 'crit' => $crit, 'method' => $method)
  54                  ), $class);
  55      }
  56  
  57  
  58  /**
  59   * Render the user interface for multiple head cells of columnar data.
  60   *
  61   * @param    array    $head_items    An array of hashed elements.
  62   *                                 Valid keys:
  63   *                                  'value'
  64   *                                 'sort'
  65   *                                 'event'
  66   *                                 'is_link'
  67   *                                 'dir'
  68   *                                 'crit'
  69   *                                 'method'
  70   * @param    string    $class    HTML "class" attribute applied to the resulting element
  71   * @return    string    HTML
  72   */
  73  
  74  	function column_multi_head($head_items, $class='')
  75      {
  76          $o = n.t.'<th'.($class ? ' class="'.$class.'"' : '').'>';
  77          $first_item = true;
  78          foreach ($head_items as $item)
  79          {
  80              if (empty($item)) continue;
  81              extract(lAtts(array(
  82                  'value'   => '',
  83                  'sort'    => '',
  84                  'event'   => '',
  85                  'step'    => 'list',
  86                  'is_link' => '',
  87                  'dir'     => '',
  88                  'crit'    => '',
  89                  'method'  => '',
  90              ),$item));
  91  
  92              $o .= ($first_item) ? '' : ', '; $first_item = false;
  93  
  94              if ($is_link)
  95              {
  96                  $o .= '<a href="index.php?step='.$step;
  97  
  98                  $o .= ($event) ? a."event=$event" : '';
  99                  $o .= ($sort) ? a."sort=$sort" : '';
 100                  $o .= ($dir) ? a."dir=$dir" : '';
 101                  $o .= ($crit != '') ? a."crit=$crit" : '';
 102                  $o .= ($method) ? a."search_method=$method" : '';
 103  
 104                  $o .= '">';
 105              }
 106  
 107              $o .= gTxt($value);
 108  
 109              if ($is_link)
 110              {
 111                  $o .= '</a>';
 112              }
 113          }
 114          $o .= '</th>';
 115  
 116          return $o;
 117      }
 118  
 119  
 120  /**
 121   * Render a <th> element.
 122   *
 123   * @param    string    $text    Cell text [space]
 124   * @param    string    $caption    unused  ['']
 125   * @param    string    $atts    HTML attributes  ['']
 126   * @return    string    HTML
 127   */
 128  
 129  	function hCell($text='',$caption='',$atts='')
 130      {
 131          $text = ('' === $text) ? sp : $text;
 132          return tag($text,'th',$atts);
 133      }
 134  
 135  
 136  /**
 137   * Render a link invoking an admin-side action.
 138   *
 139   * @param    string    $event    Event
 140   * @param    string    $step    Step
 141   * @param    string    $linktext    Link text
 142   * @param    string    $class    HTML class attribute for link
 143   * @return    string    HTML
 144   */
 145  
 146  	function sLink($event,$step,$linktext,$class='')
 147      {
 148          $c = ($class) ? ' class="'.$class.'"' : '';
 149          return '<a href="?event='.$event.a.'step='.$step.'"'.$c.'>'.$linktext.'</a>';
 150      }
 151  
 152  
 153  /**
 154   * Render a link invoking an admin-side action while taking up to two additional URL parameters.
 155   *
 156   * @param    string    $event    Event
 157   * @param    string    $step    Step ['']
 158   * @param    string    $thing    URL parameter key #1 ['']
 159   * @param    string    $value    URL parameter value #1 ['']
 160   * @param    string    $linktext    Link text
 161   * @param    string    $thing2    URL parameter key #2 ['']
 162   * @param    string    $val2    URL parameter value #2 ['']
 163   * @param    string    $title    Anchor title ['edit']
 164   * @return    string    HTML
 165   */
 166  
 167  	function eLink($event,$step='',$thing='',$value='',$linktext,$thing2='',$val2='',$title='edit')
 168      {
 169          return join('',array(
 170              '<a href="?event='.$event,
 171              ($step) ? a.'step='.$step : '',
 172              ($thing) ? a.''.$thing.'='.urlencode($value) : '',
 173              ($thing2) ? a.''.$thing2.'='.urlencode($val2) : '',
 174              a.'_txp_token='.form_token(),
 175              '"'.(($title) ? ' title="'.gTxt($title).'"' : '') .'>'.escape_title($linktext).'</a>'
 176          ));
 177      }
 178  
 179  
 180  /**
 181   * Render a link invoking an admin-side action while taking up to one additional URL parameter.
 182   *
 183   * @param    string    $event    Event
 184   * @param    string    $step    Step
 185   * @param    string    $thing    URL parameter key
 186   * @param    string    $value    URL parameter value
 187   * @return            string     HTML
 188   */
 189  
 190  	function wLink($event,$step='',$thing='',$value='')
 191      {
 192          // TODO: Why index.php? while we don't need this in eLink etc.
 193          return join('',array(
 194              '<a href="index.php?event='.$event,
 195              ($step) ? a.'step='.$step : '',
 196              ($thing) ? a.''.$thing.'='.urlencode($value) : '',
 197              a.'_txp_token='.form_token(),
 198              '" class="dlink">'.sp.'!'.sp.'</a>'
 199          ));
 200      }
 201  
 202  
 203  /**
 204   * Render a link invoking an admin-side "delete" action while taking up to two additional URL parameters.
 205   *
 206   * @param    string    $event    Event
 207   * @param    string    $step    Step
 208   * @param    string    $thing    URL parameter key #1
 209   * @param    string    $value    URL parameter value #1
 210   * @param    string    $verify    Show an "Are you sure?" dialogue with this text ['confirm_delete_popup']
 211   * @param    string    $thing2    URL parameter key #2 ['']
 212   * @param    string    $thing2val    URL parameter value #2 ['']
 213   * @param    boolean    $get    Use GET request [false: Use POST request]
 214   * @param    array    $remember    Convey URL parameters for page state. Member sequence is $page, $sort, $dir, $crit, $search_method
 215   */
 216  
 217  	function dLink($event, $step, $thing, $value, $verify = '', $thing2 = '', $thing2val = '', $get = '', $remember = null) {
 218          if ($remember) {
 219              list($page, $sort, $dir, $crit, $search_method) = $remember;
 220          }
 221  
 222          if ($get) {
 223              $url = '?event='.$event.a.'step='.$step.a.$thing.'='.urlencode($value).a.'_txp_token='.form_token();
 224  
 225              if ($thing2) {
 226                  $url .= a.$thing2.'='.urlencode($thing2val);
 227              }
 228  
 229              if ($remember) {
 230                  $url .= a.'page='.$page.a.'sort='.$sort.a.'dir='.$dir.a.'crit='.$crit.a.'search_method='.$search_method;
 231              }
 232  
 233              return join('', array(
 234                  '<a href="'.$url.'" class="dlink destroy" onclick="return verify(\'',
 235                  ($verify) ? gTxt($verify) : gTxt('confirm_delete_popup'),
 236                  '\')">×</a>'
 237              ));
 238          }
 239  
 240          return join('', array(
 241              '<form method="post" action="index.php" onsubmit="return confirm(\''.gTxt('confirm_delete_popup').'\');">',
 242               fInput('submit', '', '×', 'destroy'),
 243               eInput($event).
 244               sInput($step),
 245               hInput($thing, $value),
 246               ($thing2) ? hInput($thing2, $thing2val) : '',
 247               ($remember) ? hInput('page', $page) : '',
 248               ($remember) ? hInput('sort', $sort) : '',
 249               ($remember) ? hInput('dir', $dir) : '',
 250               ($remember) ? hInput('crit', $crit) : '',
 251               ($remember) ? hInput('search_method', $search_method) : '',
 252               n.tInput(),
 253               '</form>'
 254          ));
 255      }
 256  
 257  
 258  /**
 259   * Render a link invoking an admin-side "add" action while taking up to two additional URL parameters.
 260   *
 261   * @param    string    $event    Event
 262   * @param    string    $step    Step
 263   * @param    string    $thing    URL parameter key #1
 264   * @param    string    $value    URL parameter value #1
 265   * @param    string    $thing2    URL parameter key #2
 266   * @param    string    $value2    URL parameter value #2
 267   * @return            string     HTML
 268   */
 269  
 270  	function aLink($event,$step,$thing,$value,$thing2,$value2)
 271      {
 272          $o = '<a href="?event='.$event.a.'step='.$step.a.'_txp_token='.form_token().
 273              a.$thing.'='.urlencode($value).a.$thing2.'='.urlencode($value2).'"';
 274          $o.= ' class="alink">+</a>';
 275          return $o;
 276      }
 277  
 278  
 279  /**
 280   * Render a link invoking an admin-side "previous/next article" action.
 281   *
 282   * @param    string    $name    Link text
 283   * @param    string    $event    Event
 284   * @param    string    $step    Step
 285   * @param    integer    $id    ID of target Textpattern object (article,...)
 286   * @param    string    $titling    HTML title attribute
 287   * @param    string    $rel    HTML rel attribute
 288   * @return    string    HTML
 289   */
 290  
 291  	function prevnext_link($name,$event,$step,$id,$titling='',$rel='')
 292      {
 293          return '<a href="?event='.$event.a.'step='.$step.a.'ID='.$id.
 294              '" class="navlink"'.($titling ? ' title="'.$titling.'"' : '').($rel ? ' rel="'.$rel.'"' : '').'>'.$name.'</a>';
 295      }
 296  
 297  
 298  /**
 299   * Render a link invoking an admin-side "previous/next page" action.
 300   *
 301   * @param    string    $event    Event
 302   * @param    integer    $page    Target page number
 303   * @param    string    $label    Link text
 304   * @param    string    $type    Direction, either "prev" or "next" ['next']
 305   * @param    string    $sort    Sort field ['']
 306   * @param    string    $dir    Sort direction, either "asc" or "desc" ['']
 307   * @param    string    $crit    Search criterion ['']
 308   * @param    string    $search_method    Search method ['']
 309   * @param    string    $step    Step
 310   */
 311  
 312  	function PrevNextLink($event, $page, $label, $type, $sort = '', $dir = '', $crit = '', $search_method = '', $step = 'list')
 313      {
 314          return '<a href="?event='.$event.a.'step='.$step.a.'page='.$page.
 315              ($sort ? a.'sort='.$sort : '').
 316              ($dir ? a.'dir='.$dir : '').
 317              (($crit != '') ? a.'crit='.$crit : '').
 318              ($search_method ? a.'search_method='.$search_method : '').
 319              '" class="navlink" rel="'.$type.'">'.
 320              $label.
 321              '</a>';
 322      }
 323  
 324  
 325  /**
 326   * Render a page navigation form.
 327   *
 328   * @param    string    $event    Event
 329   * @param    integer    $page    Current page number
 330   * @param    integer    $numPages    Total pages
 331   * @param    string    $sort    Sort criterion
 332   * @param    string    $dir    Sort direction, either "asc" or "desc"
 333   * @param    string    $crit    Search criterion
 334   * @param    string    $search_method    Search method
 335   * @param    integer    $total    Total search term hit count [0]
 336   * @param    integer    $limit    First visible search term hit number [0]
 337   * @param    string    $step    Step
 338   * @return    string    HTML
 339   */
 340  
 341  	function nav_form($event, $page, $numPages, $sort, $dir, $crit, $search_method, $total=0, $limit=0, $step='list')
 342      {
 343          global $theme;
 344          if ($crit != '' && $total > 1)
 345          {
 346              $out[] = $theme->announce(
 347                  gTxt('showing_search_results',
 348                      array(
 349                          '{from}'  => (($page - 1) * $limit) + 1,
 350                          '{to}'    => min($total, $page * $limit),
 351                          '{total}' => $total
 352                          )
 353                      )
 354                  );
 355          }
 356  
 357          if ($numPages > 1)
 358          {
 359              $option_list = array();
 360  
 361              for ($i = 1; $i <= $numPages; $i++)
 362              {
 363                  if ($i == $page)
 364                  {
 365                      $option_list[] = '<option value="'.$i.'" selected="selected">'."$i/$numPages".'</option>';
 366                  }
 367  
 368                  else
 369                  {
 370                      $option_list[] = '<option value="'.$i.'">'."$i/$numPages".'</option>';
 371                  }
 372              }
 373  
 374              $nav = array();
 375  
 376              $nav[] = ($page > 1) ?
 377                  PrevNextLink($event, $page - 1, gTxt('prev'), 'prev', $sort, $dir, $crit, $search_method, $step).sp :
 378                  tag(gTxt('prev'), 'span', ' class="navlink-disabled"').sp;
 379  
 380              $nav[] = '<select name="page" onchange="submit(this.form);">';
 381              $nav[] = n.join(n, $option_list);
 382              $nav[] = n.'</select>';
 383  
 384              $nav[] = ($page != $numPages) ?
 385                  sp.PrevNextLink($event, $page + 1, gTxt('next'), 'next', $sort, $dir, $crit, $search_method, $step) :
 386                  sp.tag(gTxt('next'), 'span', ' class="navlink-disabled"');
 387  
 388              $out[] = '<form class="nav-form" method="get" action="index.php">'.
 389                  n.eInput($event).
 390                  n.sInput($step).
 391                  ( $sort ? n.hInput('sort', $sort).n.hInput('dir', $dir) : '' ).
 392                  ( ($crit != '') ? n.hInput('crit', $crit).n.hInput('search_method', $search_method) : '' ).
 393                  '<p class="prev-next">'.
 394                  join('', $nav).
 395                  '</p>'.
 396                  n.tInput().
 397                  n.'</form>';
 398          }
 399          else
 400          {
 401              $out[] = graf($page.'/'.$numPages, ' class="prev-next"');
 402          }
 403  
 404          return join(n, $out);
 405      }
 406  
 407  
 408  /**
 409   * Render start of a layout &lt;table&gt; element.
 410   *
 411   * @deprecated
 412   * @return    string    HTML
 413   */
 414  
 415  	function startSkelTable()
 416      {
 417          return
 418          '<table width="300" cellpadding="0" cellspacing="0" style="border:1px #ccc solid">';
 419      }
 420  
 421  
 422  /**
 423   * Render start of a layout &lt;table&gt; element.
 424   *
 425   * @param    string    $type    HTML id attribute
 426   * @param    string    $align    HTML align attribute ['']
 427   * @param    string    $class    HTML class attribute ['']
 428   * @param    integer    $p    HTML cellpadding attribute
 429   * @param    integer    $w    HTML width atttribute
 430   * @return        string    HTML
 431   */
 432  
 433  	function startTable($id='',$align='',$class='',$p='',$w='')
 434      {
 435          $id = ($id) ? ' id="'.$id.'"' : '';
 436          $align = ($align) ? ' align="'.$align.'"' : '';
 437          $class = ($class) ? ' class="'.$class.'"' : '';
 438          $width = ($w) ? ' width="'.$w.'"' : '';
 439          $padding = ($p) ? ' cellpadding="'.$p.'"' : '';
 440          return '<table'.$id.$class.$width.$padding.$align.'>'.n;
 441      }
 442  
 443  
 444  /**
 445   * Render &lt;/table&gt; tag
 446   *
 447   * @return    string    HTML
 448   */
 449  
 450  	function endTable ()
 451      {
 452          return n.'</table>'.n;
 453      }
 454  
 455  
 456  /**
 457   * Render &lt;tr&gt; elements from input parameters.
 458   *
 459   * @param    mixed,...    $rows    Row contents [null]
 460   * @return    string    HTML
 461   */
 462  
 463  	function stackRows()
 464      {
 465          foreach(func_get_args() as $a) { $o[] = tr($a); }
 466          return join('',$o);
 467      }
 468  
 469  
 470  /**
 471   * Render a &lt;td&gt; element.
 472   *
 473   * @param    string    $content    Cell content ['']
 474   * @param    integer    $width    HTML width attribute ['']
 475   * @param    string    $class    HTML class attribute ['']
 476   * @param    string    $id    HTML id attribute ['']
 477   * @return    string    HTML
 478   */
 479  
 480      function td($content='',$width='',$class='',$id='')
 481      {
 482          $content = ('' === $content) ? '&#160;' : $content;
 483          $atts[] = ($width)  ? ' width="'.$width.'"' : '';
 484          $atts[] = ($class)  ? ' class="'.$class.'"' : '';
 485          $atts[] = ($id)  ? ' id="'.$id.'"' : '';
 486          return t.tag($content,'td',join('',$atts)).n;
 487      }
 488  
 489  
 490  /**
 491   * Render a &lt;td&gt; element with attributes.
 492   *
 493   * @param    string    $content    Cell content
 494   * @param    string    $atts    Cell attributes ['']
 495   * @return    string    HTML
 496   */
 497  
 498  	function tda($content,$atts='')
 499      {
 500          return tag($content,'td',$atts);
 501      }
 502  
 503  
 504  /**
 505   * Render a &lt;td&gt; element with top/left text orientation and other attributes.
 506   *
 507   * @param    string    $content    Cell content
 508   * @param    string    $atts    Cell attributes ['']
 509   * @return    string    HTML
 510   */
 511  
 512  	function tdtl($content,$atts='')
 513      {
 514          return tag($content,'td',$atts);
 515      }
 516  
 517  
 518  /**
 519   * Render a &lt;tr&gt; element with attributes.
 520   *
 521   * @param    string    $content    Cell content
 522   * @param    string    $atts    Cell attributes ['']
 523   * @return    string    HTML
 524   */
 525  
 526      function tr($content,$atts='')
 527      {
 528          return tag($content,'tr',$atts);
 529      }
 530  
 531  
 532  /**
 533   * Render a &lt;td&gt; element with top/left text orientation, colspan and other attributes.
 534   *
 535   * @param    string    $content    Cell content
 536   * @param    integer    $span    Cell colspan attribute
 537   * @param    integer    $width    Cell width attribute ['']
 538   * @param    string    $class    Cell class attribute ['']
 539   * @return    string    HTML
 540   */
 541  
 542  	function tdcs($content,$span,$width="",$class='')
 543      {
 544          return join('',array(
 545              t.'<td colspan="'.$span.'"',
 546              ($width) ? ' width="'.$width.'"' : '',
 547              ($class) ? ' class="'.$class.'"' : '',
 548              ">$content</td>\n"
 549          ));
 550      }
 551  
 552  
 553  /**
 554   * Render a &lt;td&gt; element with top/left text orientation, rowspan and other attributes.
 555   *
 556   * @param    string    $content    Cell content
 557   * @param    integer    $span    Cell rowspan attribute
 558   * @param    integer    $width    Cell width attribute
 559   * @return    string    HTML
 560   */
 561  
 562  	function tdrs($content,$span,$width="")
 563      {
 564          return join('',array(
 565              t.'<td rowspan="'.$span.'"',
 566              ($width) ? ' width="'.$width.'"' : '',">$content</td>".n
 567          ));
 568      }
 569  
 570  
 571  /**
 572   * Render a form label inside a table cell
 573   *
 574   * @param    string    $text    Label text
 575   * @param    string    $help    Help text ['']
 576   * @param    string    $label_id    HTML "for" attribute, i.e. id of corresponding form element
 577   * @return    string    HTML
 578   */
 579  
 580  	function fLabelCell($text, $help = '', $label_id = '')
 581      {
 582          $help = ($help) ? popHelp($help) : '';
 583  
 584          $cell = gTxt($text).' '.$help;
 585  
 586          if ($label_id)
 587          {
 588              $cell = '<label for="'.$label_id.'">'.$cell.'</label>';
 589          }
 590  
 591          return tda($cell,' class="cell-label"');
 592      }
 593  
 594  
 595  /**
 596   * Render a form input inside a table cell.
 597   *
 598   * @param    string    $name    HTML name attribute
 599   * @param    string    $var    Input value ['']
 600   * @param    integer    $tabindex    HTML tabindex attribute ['']
 601   * @param    integer    $size    HTML size attribute ['']
 602   * @param    string    $help    Help text ['']
 603   * @param    string    $id    HTML id attribute
 604   * @return        string    HTML
 605   */
 606  
 607  	function fInputCell($name, $var = '', $tabindex = '', $size = '', $help = '', $id = '')
 608      {
 609          $pop = ($help) ? sp.popHelp($name) : '';
 610  
 611          return tda(fInput('text', $name, $var, '', '', '', $size, $tabindex, $id).$pop);
 612      }
 613  
 614  
 615  /**
 616   * Render a name-value input control with label
 617   *
 618   * @param    string    $name    HTML id / name attribute
 619   * @param    string    $input    complete input control widget (result of fInput(), yesnoRadio(), etc)
 620   * @param    string    $label    Label ['']
 621   * @param    string    $help    pophelp text item ['']
 622   * @param    string    $class    CSS class name to apply to wrapper ['edit-' + $name with underscores replaced with hyphens]
 623   * @param    string    $wraptag_val    Tag to wrap the value in. If set to '', no wrapper is used (useful for textareas) ['span']
 624   * @return        string    HTML
 625   */
 626  
 627  	function inputLabel($name, $input, $label = '', $help = '', $class = '', $wraptag_val='span')
 628      {
 629          $help = ($help) ? sp.popHelp($help) : '';
 630          $class = ($class) ? $class : 'edit-'.str_replace('_', '-', $name);
 631          $label_open = ($label) ? '<label for="'.$name.'">' : '';
 632          $label_close = ($label) ? '</label>' : '';
 633          $label = ($label) ? $label : $name;
 634          $wrapval_open = ($wraptag_val) ? '<'.$wraptag_val.' class="edit-value">' : '';
 635          $wrapval_close = ($wraptag_val) ? '</'.$wraptag_val.'>' : '';
 636  
 637          return graf(
 638              '<span class="edit-label">'.$label_open.gTxt($label).$label_close.$help.'</span>'.n.
 639              $wrapval_open.$input.$wrapval_close
 640          , ' class="'.$class.'"');
 641      }
 642  
 643  
 644  /**
 645   * Render anything as a XML element.
 646   *
 647   * @param    string    $content    Enclosed content
 648   * @param    string    $tag    The tag without brackets
 649   * @param    string    $atts    The element's HTML attributes ['']
 650   * @return    string    HTML
 651   */
 652  
 653  	function tag($content,$tag,$atts='')
 654      {
 655          return ('' !== $content) ? '<'.$tag.$atts.'>'.$content.'</'.$tag.'>' : '';
 656      }
 657  
 658  
 659  /**
 660   * Render a &lt;p&gt; element.
 661   *
 662   * @param    string    $item    Enclosed content
 663   * @param    string    $atts    HTML attributes ['']
 664   * @return    string    HTML
 665   */
 666  
 667  	function graf ($item,$atts='')
 668      {
 669          return tag($item,'p',$atts);
 670      }
 671  
 672  
 673  /**
 674   * Render a &lt;hx&gt; element.
 675   *
 676   * @param    string    $item    Enclosed content
 677   * @param    integer    $level    Heading level 1...6
 678   * @param    string    $atts    HTML attributes ['']
 679   * @return    string    HTML
 680   */
 681  
 682  	function hed($item,$level,$atts='')
 683      {
 684          return tag($item,'h'.$level,$atts);
 685      }
 686  
 687  
 688  /**
 689   * Render an &lt;a&gt; element.
 690   *
 691   * @param    string    $item    Enclosed content
 692   * @param    integer    $level    Heading level 1...6
 693   * @param    string    $atts    HTML attributes ['']
 694   * @return    string    HTML
 695   */
 696  
 697  	function href($item,$href,$atts='')
 698      {
 699          return tag($item,'a',$atts.' href="'.$href.'"');
 700      }
 701  
 702  
 703  /**
 704   * Render a &lt;strong&gt; element.
 705   *
 706   * @param    string    $item    Enclosed content
 707   * @return        string    HTML
 708   */
 709  
 710  	function strong($item)
 711      {
 712          return tag($item,'strong');
 713      }
 714  
 715  
 716  /**
 717   * Render a &lt;span&gt; element.
 718   *
 719   * @param    string    $item    Enclosed content
 720   * @return    string    HTML
 721   */
 722  
 723  	function span($item)
 724      {
 725          return tag($item,'span');
 726      }
 727  
 728  
 729  /**
 730   * Render a &lt;pre&gt; element.
 731   *
 732   * @param    string    $item    Enclosed content
 733   * @return    string    HTML
 734   */
 735  
 736  	function htmlPre($item)
 737      {
 738          return '<pre>'.tag($item,'code').'</pre>';
 739      }
 740  
 741  
 742  /**
 743   * Render a HTML comment (&lt;!-- --&gt;) element.
 744   *
 745   * @param    string    $item    Enclosed content
 746   * @return    string    HTML
 747   */
 748  
 749  	function comment($item)
 750      {
 751          return '<!-- '.$item.' -->';
 752      }
 753  
 754  
 755  /**
 756   * Render a &lt;small&gt element.
 757   *
 758   * @param    string    $item    Enclosed content
 759   * @return    string    HTML
 760   */
 761  
 762  	function small($item)
 763      {
 764          return tag($item,'small');
 765      }
 766  
 767  
 768  /**
 769   * Render a table data row from an array of content => width pairs.
 770   *
 771   * @param    array    $array    Array of content => width pairs
 772   * @param    string    $atts    Table row atrributes
 773   * @return    string    HTML
 774   */
 775  
 776  	function assRow($array, $atts ='')
 777      {
 778          foreach($array as $a => $b) $o[] = tda($a,' width="'.$b.'"');
 779          return tr(join(n.t,$o), $atts);
 780      }
 781  
 782  
 783  /**
 784   * Render a table head row from an array of strings.
 785   *
 786   * @param    array    $value,...    Array of head text strings. L10n is applied to the strings.
 787   * @return    string    HTML
 788   */
 789  
 790  	function assHead()
 791      {
 792          $array = func_get_args();
 793          foreach($array as $a) $o[] = hCell(gTxt($a));
 794          return tr(join('',$o));
 795      }
 796  
 797  
 798  /**
 799   * Render the ubiquitious popup help button.
 800   *
 801   * @param    string    $help_var    Help topic
 802   * @param    integer    $width    Popup window width
 803   * @param    integer    $height    Popup window height
 804   * @return    string    HTML
 805   */
 806  
 807  	function popHelp($help_var, $width = '', $height = '')
 808      {
 809          return '<a rel="help" target="_blank"'.
 810              ' href="'.HELP_URL.'?item='.$help_var.a.'language='.LANG.'"'.
 811              ' onclick="popWin(this.href'.
 812              ($width ? ', '.$width : '').
 813              ($height ? ', '.$height : '').
 814              '); return false;" class="pophelp">?</a>';
 815      }
 816  
 817  
 818  /**
 819   * Render the ubiquitious popup help button with a little less visual noise.
 820   *
 821   * @param    string    $help_var    Help topic
 822   * @param    integer    $width    Popup window width ['']
 823   * @param    integer    $height    Popup window height ['']
 824   * @return    string    HTML
 825   */
 826  
 827  	function popHelpSubtle($help_var, $width = '', $height = '')
 828      {
 829          return '<a rel="help" target="_blank"'.
 830              ' href="http://rpc.textpattern.com/help/?item='.$help_var.a.'language='.LANG.'"'.
 831              ' onclick="popWin(this.href'.
 832              ($width ? ', '.$width : '').
 833              ($height ? ', '.$height : '').
 834              '); return false;" class="pophelpsubtle">?</a>';
 835      }
 836  
 837  
 838  /**
 839   * Popup tag help window.
 840   *
 841   * @param    string    $var    Tag name
 842   * @param    string    $text    Link text
 843   * @param    integer    $width    Popup window width
 844   * @param    integer    $height    Popup window height
 845   * @return    string    HTML
 846   */
 847  
 848  	function popTag($var, $text, $width = '', $height = '')
 849      {
 850          return '<a target="_blank"'.
 851              ' href="?event=tag'.a.'tag_name='.$var.'"'.
 852              ' onclick="popWin(this.href'.
 853              ($width ? ', '.$width : '').
 854              ($height ? ', '.$height : '').
 855              '); return false;">'.$text.'</a>';
 856      }
 857  
 858  
 859  /**
 860   * Render tag builder links.
 861   *
 862   * @param    string    $type    Tag type
 863   * @return    string    HTML
 864   */
 865  
 866  	function popTagLinks($type)
 867      {
 868          include txpath.'/lib/taglib.php';
 869  
 870          $arname = $type.'_tags';
 871  
 872          $out = array();
 873  
 874          $out[] = n.'<ul class="plain-list">';
 875  
 876          foreach ($$arname as $a)
 877          {
 878              $out[] = n.t.tag(popTag($a,gTxt('tag_'.$a)), 'li');
 879          }
 880  
 881          $out[] = n.'</ul>';
 882  
 883          return join('', $out);
 884      }
 885  
 886  
 887  /**
 888   * Render admin-side message text.
 889   *
 890   * @param    string    $thing    Subject
 891   * @param    string    $thething    Predicate (strong)
 892   * @param    string    $action    Object
 893   * @return    string    HTML
 894   */
 895  
 896  	function messenger($thing, $thething='', $action='')
 897      {
 898          return gTxt($thing).' '.strong($thething).' '.gTxt($action);
 899      }
 900  
 901  
 902  /**
 903   * Render a multi-edit form listing editing methods
 904   *
 905   * @param  array   $options array('value' => array( 'label' => '', 'html' => '' ),...)
 906   * @param  string  $event Event
 907   * @param  string  $step Step
 908   * @param  integer $page Page number
 909   * @param  string  $sort Column sorted by
 910   * @param  string  $dir Sorting direction
 911   * @param  string  $crit Search criterion
 912   * @param  string  $search_method Search method
 913   * @return string  HTML
 914   */
 915  
 916  	function multi_edit($options, $event=null, $step=null, $page='', $sort='', $dir='', $crit='', $search_method='')
 917      {
 918          $html = $methods = array();
 919          $methods[''] = gTxt('with_selected_option');
 920  
 921          if ($event === null)
 922          {
 923              global $event;
 924          }
 925  
 926          if ($step === null)
 927          {
 928              $step = $event.'_multi_edit';
 929          }
 930  
 931          callback_event_ref($event.'_ui', 'multi_edit_options', 0, $options);
 932  
 933          foreach($options as $value => $option)
 934          {
 935              if (is_array($option))
 936              {
 937                  $methods[$value] = $option['label'];
 938  
 939                  if (isset($option['html']))
 940                  {
 941                      $html[$value] = '<div class="multi-option multi-option-'.txpspecialchars($value).'">'.$option['html'].'</div>';
 942                  }
 943              }
 944              else
 945              {
 946                  $methods[$value] = $option;
 947              }
 948          }
 949  
 950          return '<div class="multi-edit">'.
 951              n.selectInput('edit_method', $methods, '').
 952              n.eInput($event).
 953              n.sInput($step).
 954              n.hInput('page', $page).
 955              ($sort ? n.hInput('sort', $sort).n.hInput('dir', $dir) : '' ).
 956              ($crit !== '' ? n.hInput('crit', $crit).n.hInput('search_method', $search_method) : '').
 957              n.implode('', $html).
 958              n.fInput('submit', '', gTxt('go')).
 959              n.'</div>';
 960      }
 961  
 962  
 963  /**
 964   * Render a form to select various amounts to page lists by.
 965   *
 966   * @param    string    $event    Event
 967   * @param    integer    $val    Current setting
 968   * @return    string    HTML
 969   */
 970  
 971  	function pageby_form($event, $val)
 972      {
 973          $vals = array(
 974              15  => 15,
 975              25  => 25,
 976              50  => 50,
 977              100 => 100
 978          );
 979  
 980          $select_page = selectInput('qty', $vals, $val,'', 1);
 981  
 982          // proper localisation
 983          $page = str_replace('{page}', $select_page, gTxt('view_per_page'));
 984  
 985          return form(
 986              '<p>'.
 987                  $page.
 988                  eInput($event).
 989                  sInput($event.'_change_pageby').
 990              '</p>'
 991          , '', '', 'post', 'pageby');
 992      }
 993  
 994  
 995  /**
 996   * Render a file upload form via the "$event_ui" > "upload_form" pluggable UI.
 997   *
 998   * @param    string    $label    File name label. May be empty
 999   * @param    string    $pophelp    Help item ['']
1000   * @param    string    $step    Step
1001   * @param    string    $event    Event
1002   * @param    string    $id    File id
1003   * @param    integer    $max_file_size    Maximum allowed file size
1004   * @param    string    $label_id    HTML id attribute for the filename input element
1005   * @param    string    $class    HTML class attribute for the form element
1006   */
1007  
1008  	function upload_form($label, $pophelp = '', $step, $event, $id = '', $max_file_size = '1000000', $label_id = '', $class = 'upload-form')
1009      {
1010          global $sort, $dir, $page, $search_method, $crit;
1011  
1012          extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
1013  
1014          $class = ($class) ? ' class="'.$class.'"' : '';
1015          $p_class = 'edit-'. (($label_id) ? str_replace('_', '-', $label_id) : $event.'-upload');
1016          $label_id = ($label_id) ? $label_id : $event.'-upload';
1017  
1018          $argv = func_get_args();
1019          return pluggable_ui($event.'_ui', 'upload_form',
1020              n.n.'<form'.$class.' method="post" enctype="multipart/form-data" action="index.php">'.
1021  
1022              (!empty($max_file_size)? n.hInput('MAX_FILE_SIZE', $max_file_size): '').
1023              n.eInput($event).
1024              n.sInput($step).
1025              n.hInput('id', $id).
1026  
1027              n.hInput('sort', $sort).
1028              n.hInput('dir', $dir).
1029              n.hInput('page', $page).
1030              n.hInput('search_method', $search_method).
1031              n.hInput('crit', $crit).
1032  
1033              n.graf(
1034                  (($label) ? '<label for="'.$label_id.'">'.$label.'</label>' : '').(($pophelp) ? sp.popHelp($pophelp) : '').n.
1035                      fInput('file', 'thefile', '', '', '', '', '', '', $label_id).n.
1036                      fInput('submit', '', gTxt('upload'))
1037              , ' class="'.$p_class.'"').
1038  
1039              n.tInput().
1040              n.'</form>',
1041              $argv);
1042      }
1043  
1044  
1045  /**
1046   * Render a admin-side search form.
1047   *
1048   * @param    string    $event    Event
1049   * @param    string    $step    Step
1050   * @param    string    $crit    Search criterion
1051   * @param    array    $methods    Valid search methods
1052   * @param    string    $method    Actual search method
1053   * @param    string    $default_method    Default search method
1054   * @return    string    HTML
1055   */
1056  
1057  	function search_form($event, $step, $crit, $methods, $method, $default_method)
1058      {
1059          $method = ($method) ? $method : $default_method;
1060  
1061          return n.n.form(
1062              graf(
1063                  '<label for="'.$event.'-search">'.gTxt('search').'</label>'.
1064                  n.selectInput('search_method', $methods, $method, '', '', $event.'-search').
1065                  n.fInput('text', 'crit', $crit, 'input-medium', '', '', INPUT_MEDIUM).
1066                  n.eInput($event).
1067                  n.sInput($step).
1068                  n.fInput('submit', 'search', gTxt('go'))
1069              )
1070          , '', '', 'get', 'search-form');
1071      }
1072  
1073  /**
1074   * Render a dropdown for selecting text filter method preferences.
1075   *
1076   * @param    string    $name    Element name
1077   * @param    string    $val    Current value
1078   * @param    string    $id    HTML id attribute for the select input element
1079   * @return    string    HTML
1080   */
1081  
1082  	function pref_text($name, $val, $id = '')
1083      {
1084          $id = ($id) ? $id : $name;
1085  
1086          $vals = array(
1087              USE_TEXTILE          => gTxt('use_textile'),
1088              CONVERT_LINEBREAKS   => gTxt('convert_linebreaks'),
1089              LEAVE_TEXT_UNTOUCHED => gTxt('leave_text_untouched')
1090          );
1091  
1092          return selectInput($name, $vals, $val, '', '', $id);
1093      }
1094  
1095  
1096  /**
1097   * Attach a HTML fragment to a DOM node.
1098   *
1099   * @param    string    $id    Target DMO node's id
1100   * @param    string    $content    HTML fragment
1101   * @param    string    $noscript    noscript alternative    fragment ['']
1102   * @param    string    $wraptag    Wrapping HTML element
1103   * @param    string    $wraptagid    Wrapping element's HTML id
1104   * @return    string    HTML/JS
1105   */
1106  
1107  	function dom_attach($id, $content, $noscript='', $wraptag='div', $wraptagid='')
1108      {
1109          $content = escape_js($content);
1110  
1111          $js = <<<EOF
1112              $(document).ready(function() {
1113                  $('#{$id}').append($('<{$wraptag} />').attr('id', '{$wraptagid}').html('{$content}'));
1114              });
1115  EOF;
1116  
1117          return script_js($js, $noscript);
1118      }
1119  
1120  
1121  /**
1122   * Render a &lt:script&gt; element.
1123   *
1124   * @param    string    $js    JavaScript code
1125   * @param    string    $noscript    noscript alternative
1126   * @return    string    HTML with embedded script element
1127   */
1128  
1129  	function script_js($js, $noscript='')
1130      {
1131          $js = preg_replace('#<(/?)script#', '\\x3c$1script', $js);
1132  
1133          $out = '<script type="text/javascript">'.n.
1134              trim($js).n.
1135              '</script>'.n;
1136          if ($noscript)
1137              $out .= '<noscript>'.n.
1138                  trim($noscript).n.
1139                  '</noscript>'.n;
1140          return $out;
1141      }
1142  
1143  
1144  /**
1145   * Render a "Details" toggle checkbox.
1146   *
1147   * @param    string    $classname    Unique identfier. The cookie's name will be derived from this value.
1148   * @param    boolean    $form        Create as a stand-along &lt;form&gt; element [false]
1149   * @return    string    HTML
1150   */
1151  
1152  	function toggle_box($classname, $form=0) {
1153  
1154          $name = 'cb_toggle_'.$classname;
1155          $i =
1156              '<input type="checkbox" name="'.$name.'" id="'.$name.'" value="1" '.
1157              (cs('toggle_'.$classname) ? 'checked="checked" ' : '').
1158              'class="checkbox" onclick="toggleClassRemember(\''.$classname.'\');" />'.
1159              ' <label for="'.$name.'">'.gTxt('detail_toggle').'</label> '.
1160              script_js("setClassRemember('".$classname."');addEvent(window, 'load', function(){setClassRemember('".$classname."');});");
1161          if ($form)
1162              return n.form($i);
1163          else
1164              return n.$i;
1165      }
1166  
1167  
1168  /**
1169   * Render a checkbox to set/unset a browser cookie.
1170   *
1171   * @param    string    $classname    Label text. The cookie's name will be derived from this value.
1172   * @param    boolean    $form        Create as a stand-along &lt;form&gt; element [true]
1173   * @return    string    HTML
1174   */
1175  
1176  	function cookie_box($classname, $form=1) {
1177  
1178          $name = 'cb_'.$classname;
1179          $val = cs('toggle_'.$classname) ? 1 : 0;
1180  
1181          $i =
1182              '<input type="checkbox" name="'.$name.'" id="'.$name.'" value="1" '.
1183              ($val ? 'checked="checked" ' : '').
1184              'class="checkbox" onclick="setClassRemember(\''.$classname.'\','.(1-$val).');submit(this.form);" />'.
1185              ' <label for="'.$name.'">'.gTxt($classname).'</label> ';
1186  
1187          if ($form) {
1188              $args = empty($_SERVER['QUERY_STRING']) ? '' : '?'.txpspecialchars($_SERVER['QUERY_STRING']);
1189              return '<form class="'.$name.'" method="post" action="index.php'.$args.'">'.$i.eInput(gps('event')).n.tInput().'</form>';
1190          } else {
1191              return n.$i;
1192          }
1193      }
1194  
1195  
1196  /**
1197   * Render a &lt;fieldset&gt; element.
1198   *
1199   * @param    string    $content    Enclosed content
1200   * @param    string    $legend    Legend text ['']
1201   * @param    string    $id        HTML id attribute ['']
1202   * @return    string    HTML
1203   */
1204  
1205  	function fieldset($content, $legend='', $id='') {
1206          $a_id = ($id ? ' id="'.$id.'"' : '');
1207          return tag(trim(tag($legend, 'legend').n.$content), 'fieldset', $a_id);
1208      }
1209  
1210  
1211  /**
1212   * Render a link element to hook up txpAsyncHref() with request parameters
1213   *
1214   * @param     string     $item    Link text
1215   * @param     array    $parms    Request parameters; array keys are 'event', 'step', 'thing', 'property'
1216   * @param     string     $atts    HTML attributes
1217   * @return     string     HTML
1218   * @since 4.5.0
1219   * @see textpattern.js: txpAsyncHref
1220   */
1221  
1222  	function asyncHref($item,$parms,$atts='')
1223      {
1224          extract(doSpecial(lAtts(array(
1225              'event'    => $GLOBALS['event'],
1226              'step'     => $GLOBALS['step'],
1227              'thing'    => '',
1228              'property' => '',
1229          ), $parms)));
1230  
1231          $class = "$step async";
1232          $href = "?event=$event&amp;step=$step&amp;thing=$thing&amp;property=$property";
1233          if (AJAXALLY_CHALLENGED) {
1234              $href .= '&amp;value='.txpspecialchars($item).'&amp;_txp_token='.form_token();
1235          }
1236          return href($item, $href, $atts." class=\"$class\"");
1237      }
1238  
1239  ?>

title

Description

title

Description

title

Description

title

title

Body