[ Index ] [ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

PHP Cross Reference of TXP stable 4.0.6

title

Body

[close]

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

   1  <?php
   2  
   3  /*
   4  $HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/lib/txplib_html.php $
   5  $LastChangedRevision: 2696 $
   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  	function end_page()
  16      {
  17          global $txp_user,$event;
  18          if($event!='tag') {
  19              echo '<div id="end_page">',
  20              navPop().n,
  21              '<a href="http://www.textpattern.com"><img src="txp_img/carver.gif" width="60" height="48" border="0" alt="" /></a>'.n;
  22              echo graf('Textpattern &#183; '.txp_version).n;
  23              echo($txp_user)
  24              ?    graf(gTxt('logged_in_as').' '.span(htmlspecialchars($txp_user)).br.
  25                      '<a href="index.php?logout=1">'.gTxt('logout').'</a>', ' id="moniker"').n.'</div>'
  26              :    '</div>';
  27              echo n.'</body>'.n.'</html>';
  28          }
  29      }
  30  
  31  // -------------------------------------------------------------
  32  
  33  	function column_head($value, $sort = '', $event = '', $is_link = '', $dir = '', $crit = '', $method = '', $class = '')
  34      {
  35          return column_multi_head( array(
  36                      array ('value' => $value, 'sort' => $sort, 'event' => $event, 'is_link' => $is_link,
  37                             'dir' => $dir, 'crit' => $crit, 'method' => $method)
  38                  ), $class);
  39      }
  40  
  41  // -------------------------------------------------------------
  42  
  43  	function column_multi_head($head_items, $class='')
  44      {
  45          $o = n.t.'<th'.($class ? ' class="'.$class.'"' : '').'>';
  46          $first_item = true;
  47          foreach ($head_items as $item)
  48          {
  49              if (empty($item)) continue;
  50              extract(lAtts(array(
  51                  'value'        => '',
  52                  'sort'        => '',
  53                  'event'        => '',
  54                  'is_link'    => '',
  55                  'dir'        => '',
  56                  'crit'        => '',
  57                  'method'    => '',
  58              ),$item));
  59  
  60              $o .= ($first_item) ? '' : ', '; $first_item = false;
  61  
  62              if ($is_link)
  63              {
  64                  $o .= '<a href="index.php?step=list';
  65  
  66                  $o .= ($event) ? a."event=$event" : '';
  67                  $o .= ($sort) ? a."sort=$sort" : '';
  68                  $o .= ($dir) ? a."dir=$dir" : '';
  69                  $o .= ($crit) ? a."crit=$crit" : '';
  70                  $o .= ($method) ? a."search_method=$method" : '';
  71  
  72                  $o .= '">';
  73              }
  74  
  75              $o .= gTxt($value);
  76  
  77              if ($is_link)
  78              {
  79                  $o .= '</a>';
  80              }
  81          }
  82          $o .= '</th>';
  83  
  84          return $o;
  85      }
  86  
  87  // -------------------------------------------------------------
  88  	function hCell($text="",$caption="")
  89      {
  90          $text = (!$text) ? sp : $text;
  91          return tag($text,'th');
  92      }
  93  
  94  // -------------------------------------------------------------
  95  	function sLink($event,$step,$linktext,$class='')
  96      {
  97          $c = ($class) ? ' class="'.$class.'"' : '';
  98          return '<a href="?event='.$event.a.'step='.$step.'"'.$c.'>'.$linktext.'</a>';
  99      }
 100  
 101  // -------------------------------------------------------------
 102  	function eLink($event,$step='',$thing='',$value='',$linktext,$thing2='',$val2='')
 103      {
 104          return join('',array(
 105              '<a href="?event='.$event,
 106              ($step) ? a.'step='.$step : '',
 107              ($thing) ? a.''.$thing.'='.urlencode($value) : '',
 108              ($thing2) ? a.''.$thing2.'='.urlencode($val2) : '',
 109              '">'.escape_title($linktext).'</a>'
 110          ));
 111      }
 112  
 113  // -------------------------------------------------------------
 114  	function wLink($event,$step='',$thing='',$value='')
 115      {
 116          return join('',array(
 117              '<a href="index.php?event='.$event,
 118              ($step) ? a.'step='.$step : '',
 119              ($thing) ? a.''.$thing.'='.urlencode($value) : '',
 120              '" class="dlink">'.sp.'!'.sp.'</a>'
 121          ));
 122      }
 123  
 124  // -------------------------------------------------------------
 125  
 126  	function dLink($event, $step, $thing, $value, $verify = '', $thing2 = '', $thing2val = '', $get = '', $remember = null) {
 127          if ($remember) {
 128              list($page, $sort, $dir, $crit, $search_method) = $remember;
 129          }
 130  
 131          if ($get) {
 132              $url = '?event='.$event.a.'step='.$step.a.$thing.'='.urlencode($value);
 133  
 134              if ($thing2) {
 135                  $url .= a.$thing2.'='.urlencode($thing2val);
 136              }
 137  
 138              if ($remember) {
 139                  $url .= a.'page='.$page.a.'sort='.$sort.a.'dir='.$dir.a.'crit='.$crit.a.'search_method='.$search_method;
 140              }
 141  
 142              return join('', array(
 143                  '<a href="'.$url.'" class="dlink" onclick="return verify(\'',
 144                  ($verify) ? gTxt($verify) : gTxt('confirm_delete_popup'),
 145                  '\')">&#215;</a>'
 146              ));
 147          }
 148  
 149          return join('', array(
 150              '<form method="post" action="index.php" onsubmit="return confirm(\''.gTxt('confirm_delete_popup').'\');">',
 151               fInput('submit', '', '&#215;', 'smallerbox'),
 152               eInput($event).
 153               sInput($step),
 154               hInput($thing, $value),
 155               ($thing2) ? hInput($thing2, $thing2val) : '',
 156               ($remember) ? hInput('page', $page) : '',
 157               ($remember) ? hInput('sort', $sort) : '',
 158               ($remember) ? hInput('dir', $dir) : '',
 159               ($remember) ? hInput('crit', $crit) : '',
 160               ($remember) ? hInput('search_method', $search_method) : '',
 161              '</form>'
 162          ));
 163      }
 164  
 165  // -------------------------------------------------------------
 166  	function aLink($event,$step,$thing,$value,$thing2,$value2)
 167      {
 168          $o = '<a href="?event='.$event.a.'step='.$step.
 169              a.$thing.'='.urlencode($value).a.$thing2.'='.urlencode($value2).'"';
 170          $o.= ' class="alink">+</a>';
 171          return $o;
 172      }
 173  
 174  // -------------------------------------------------------------
 175  	function prevnext_link($name,$event,$step,$id,$titling='')
 176      {
 177          return '<a href="?event='.$event.a.'step='.$step.a.'ID='.$id.
 178              '" class="navlink" title="'.$titling.'">'.$name.'</a> ';
 179      }
 180  
 181  // -------------------------------------------------------------
 182  
 183  	function PrevNextLink($event, $page, $label, $type, $sort = '', $dir = '', $crit = '', $search_method = '')
 184      {
 185          return '<a href="?event='.$event.a.'step=list'.a.'page='.$page.
 186              ($sort ? a.'sort='.$sort : '').
 187              ($dir ? a.'dir='.$dir : '').
 188              ($crit ? a.'crit='.$crit : '').
 189              ($search_method ? a.'search_method='.$search_method : '').
 190              '" class="navlink">'.
 191              ($type == 'prev' ? '&#8249;'.sp.$label : $label.sp.'&#8250;').
 192              '</a>';
 193      }
 194  
 195  // -------------------------------------------------------------
 196  
 197  	function nav_form($event, $page, $numPages, $sort, $dir, $crit, $search_method)
 198      {
 199          if ($numPages > 1)
 200          {
 201              $option_list = array();
 202  
 203              for ($i = 1; $i <= $numPages; $i++)
 204              {
 205                  if ($i == $page)
 206                  {
 207                      $option_list[] = '<option value="'.$i.'" selected="selected">'."$i/$numPages".'</option>';
 208                  }
 209  
 210                  else
 211                  {
 212                      $option_list[] = '<option value="'.$i.'">'."$i/$numPages".'</option>';
 213                  }
 214              }
 215  
 216              $nav = array();
 217  
 218              $nav[] = ($page > 1) ?
 219                  PrevNextLink($event, $page - 1, gTxt('prev'), 'prev', $sort, $dir, $crit, $search_method).sp :
 220                  tag('&#8249; '.gTxt('prev'), 'span', ' class="navlink-disabled"').sp;
 221  
 222              $nav[] = '<select name="page" class="list" onchange="submit(this.form);">';
 223              $nav[] = n.join(n, $option_list);
 224              $nav[] = n.'</select>';
 225              $nav[] = '<noscript> <input type="submit" value="'.gTxt('go').'" class="smallerbox" /></noscript>';
 226  
 227              $nav[] = ($page != $numPages) ?
 228                  sp.PrevNextLink($event, $page + 1, gTxt('next'), 'next', $sort, $dir, $crit, $search_method) :
 229                  sp.tag(gTxt('next').' &#8250;', 'span', ' class="navlink-disabled"');
 230  
 231              return '<form class="prev-next" method="get" action="index.php">'.
 232                  n.eInput($event).
 233                  ( $sort ? n.hInput('sort', $sort).n.hInput('dir', $dir) : '' ).
 234                  ( $crit ? n.hInput('crit', $crit).n.hInput('search_method', $search_method) : '' ).
 235                  join('', $nav).
 236                  '</form>';
 237          }
 238  
 239          else
 240          {
 241              return graf($page.'/'.$numPages, ' class="prev-next"');
 242          }
 243      }
 244  
 245  // -------------------------------------------------------------
 246  	function startSkelTable()
 247      {
 248          return
 249          '<table width="300" cellpadding="0" cellspacing="0" style="border:1px #ccc solid">';
 250      }
 251  
 252  // -------------------------------------------------------------
 253  	function startTable($type,$align='',$class='',$p='',$w='')
 254      {
 255          if (!$p) $p = ($type=='edit') ? 3 : 0;
 256          $align = (!$align) ? 'center' : $align;
 257          $class = ($class) ? ' class="'.$class.'"' : '';
 258          $width = ($w) ? ' width="'.$w.'"' : '';
 259          return '<table cellpadding="'.$p.'" cellspacing="0" border="0" id="'.
 260              $type.'" align="'.$align.'"'.$class.$width.'>'.n;
 261      }
 262  
 263  // -------------------------------------------------------------
 264  	function endTable ()
 265      {
 266          return n.'</table>'.n;
 267      }
 268  
 269  // -------------------------------------------------------------
 270  	function stackRows()
 271      {
 272          foreach(func_get_args() as $a) { $o[] = tr($a); }
 273          return join('',$o);
 274      }
 275  
 276  // -------------------------------------------------------------
 277      function td($content='',$width='',$class='',$id='')
 278      {
 279          $content = (!$content) ? '&#160;' : $content;
 280          $atts[] = ($width)  ? ' width="'.$width.'"' : '';
 281          $atts[] = ($class)  ? ' class="'.$class.'"' : '';
 282          $atts[] = ($id)  ? ' id="'.$id.'"' : '';
 283          return t.tag($content,'td',join('',$atts)).n;
 284      }
 285  
 286  // -------------------------------------------------------------
 287  	function tda($content,$atts='')
 288      {
 289          return tag($content,'td',$atts);
 290      }
 291  
 292  // -------------------------------------------------------------
 293  	function tdtl($content,$atts='')
 294      {
 295          return tag($content,'td',' style="vertical-align:top;text-align:left;padding:8px"'.$atts);
 296      }
 297  
 298  // -------------------------------------------------------------
 299      function tr($content,$atts='')
 300      {
 301          return tag($content,'tr',$atts);
 302      }
 303  
 304  // -------------------------------------------------------------
 305  	function tdcs($content,$span,$width="",$class='')
 306      {
 307          return join('',array(
 308              t.'<td align="left" valign="top" colspan="'.$span.'"',
 309              ($width) ? ' width="'.$width.'"' : '',
 310              ($class) ? ' class="'.$class.'"' : '',
 311              ">$content</td>\n"
 312          ));
 313      }
 314  
 315  // -------------------------------------------------------------
 316  	function tdrs($content,$span,$width="")
 317      {
 318          return join('',array(
 319              t.'<td align="left" valign="top" rowspan="'.$span.'"',
 320              ($width) ? ' width="'.$width.'"' : '',">$content</td>".n
 321          ));
 322      }
 323  
 324  // -------------------------------------------------------------
 325  
 326  	function fLabelCell($text, $help = '', $label_id = '')
 327      {
 328          $help = ($help) ? popHelp($help) : '';
 329  
 330          $cell = gTxt($text).' '.$help;
 331  
 332          if ($label_id)
 333          {
 334              $cell = '<label for="'.$label_id.'">'.$cell.'</label>';
 335          }
 336  
 337          return tda($cell,' class="noline" style="text-align: right; vertical-align: middle;"');
 338      }
 339  
 340  // -------------------------------------------------------------
 341  
 342  	function fInputCell($name, $var = '', $tabindex = '', $size = '', $help = '', $id = '')
 343      {
 344          $pop = ($help) ? sp.popHelp($name) : '';
 345  
 346          return tda(
 347              fInput('text', $name, $var, 'edit', '', '', $size, $tabindex, $id).$pop
 348          ,' class="noline"');
 349      }
 350  
 351  // -------------------------------------------------------------
 352  	function tag($content,$tag,$atts='')
 353      {
 354          return ($content) ? '<'.$tag.$atts.'>'.$content.'</'.$tag.'>' : '';
 355      }
 356  
 357  // -------------------------------------------------------------
 358  	function graf ($item,$atts='')
 359      {
 360          return tag($item,'p',$atts);
 361      }
 362  
 363  // -------------------------------------------------------------
 364  	function hed($item,$level,$atts='')
 365      {
 366          return tag($item,'h'.$level,$atts);
 367      }
 368  
 369  // -------------------------------------------------------------
 370  	function href($item,$href,$atts='')
 371      {
 372          return tag($item,'a',$atts.' href="'.$href.'"');
 373      }
 374  
 375  // -------------------------------------------------------------
 376  	function strong($item)
 377      {
 378          return tag($item,'strong');
 379      }
 380  
 381  // -------------------------------------------------------------
 382  	function span($item)
 383      {
 384          return tag($item,'span');
 385      }
 386  
 387  // -------------------------------------------------------------
 388  	function htmlPre($item)
 389      {
 390          return '<pre>'.tag($item,'code').'</pre>';
 391      }
 392  
 393  // -------------------------------------------------------------
 394  	function comment($item)
 395      {
 396          return '<!-- '.$item.' -->';
 397      }
 398  
 399  // -------------------------------------------------------------
 400  	function small($item)
 401      {
 402          return tag($item,'small');
 403      }
 404  
 405  // -------------------------------------------------------------
 406  	function assRow($array, $atts ='')
 407      {
 408          foreach($array as $a => $b) $o[] = tda($a,' width="'.$b.'"');
 409          return tr(join(n.t,$o), $atts);
 410      }
 411  
 412  // -------------------------------------------------------------
 413  	function assHead()
 414      {
 415          $array = func_get_args();
 416          foreach($array as $a) $o[] = hCell(gTxt($a));
 417          return tr(join('',$o));
 418      }
 419  
 420  // -------------------------------------------------------------
 421  
 422  	function popHelp($help_var, $width = '', $height = '')
 423      {
 424          return '<a target="_blank"'.
 425              ' href="http://rpc.textpattern.com/help/?item='.$help_var.a.'language='.LANG.'"'.
 426              ' onclick="popWin(this.href'.
 427              ($width ? ', '.$width : '').
 428              ($height ? ', '.$height : '').
 429              '); return false;" class="pophelp">?</a>';
 430      }
 431  
 432  // -------------------------------------------------------------
 433  
 434  	function popHelpSubtle($help_var, $width = '', $height = '')
 435      {
 436          return '<a target="_blank"'.
 437              ' href="http://rpc.textpattern.com/help/?item='.$help_var.a.'language='.LANG.'"'.
 438              ' onclick="popWin(this.href'.
 439              ($width ? ', '.$width : '').
 440              ($height ? ', '.$height : '').
 441              '); return false;">?</a>';
 442      }
 443  
 444  // -------------------------------------------------------------
 445  
 446  	function popTag($var, $text, $width = '', $height = '')
 447      {
 448          return '<a target="_blank"'.
 449              ' href="?event=tag'.a.'tag_name='.$var.'"'.
 450              ' onclick="popWin(this.href'.
 451              ($width ? ', '.$width : '').
 452              ($height ? ', '.$height : '').
 453              '); return false;">'.$text.'</a>';
 454      }
 455  
 456  // -------------------------------------------------------------
 457  
 458  	function popTagLinks($type)
 459      {
 460          global $txpcfg;
 461  
 462          include txpath.'/lib/taglib.php';
 463  
 464          $arname = $type.'_tags';
 465  
 466          $out = array();
 467  
 468          $out[] = n.'<ul class="plain-list small">';
 469  
 470          foreach ($$arname as $a)
 471          {
 472              $out[] = n.t.tag(popTag($a,gTxt('tag_'.$a)), 'li');
 473          }
 474  
 475          $out[] = n.'</ul>';
 476  
 477          return join('', $out);
 478      }
 479  
 480  //-------------------------------------------------------------
 481  	function messenger($thing,$thething,$action)
 482      {
 483          return gTxt($thing).' '.strong($thething).' '.gTxt($action);
 484      }
 485  
 486  // -------------------------------------------------------------
 487  
 488  	function pageby_form($event, $val)
 489      {
 490          $vals = array(
 491              15  => 15,
 492              25  => 25,
 493              50  => 50,
 494              100 => 100
 495          );
 496  
 497          $select_page = selectInput('qty', $vals, $val,'', 1);
 498  
 499          // proper localisation
 500          $page = str_replace('{page}', $select_page, gTxt('view_per_page'));
 501  
 502          return form(
 503              '<div style="margin: auto; text-align: center;">'.
 504                  $page.
 505                  eInput($event).
 506                  sInput($event.'_change_pageby').
 507                  '<noscript> <input type="submit" value="'.gTxt('go').'" class="smallerbox" /></noscript>'.
 508              '</div>'
 509          );
 510      }
 511  // -------------------------------------------------------------
 512  
 513  	function upload_form($label, $pophelp, $step, $event, $id = '', $max_file_size = '1000000', $label_id = '', $class = 'upload-form')
 514      {
 515          global $sort, $dir, $page, $search_method, $crit;
 516  
 517          $class = ($class) ? ' class="'.$class.'"' : '';
 518  
 519          $label_id = ($label_id) ? $label_id : $event.'-upload';
 520  
 521          return n.n.'<form'.$class.' method="post" enctype="multipart/form-data" action="index.php">'.
 522              n.'<div>'.
 523  
 524              (!empty($max_file_size)? n.hInput('MAX_FILE_SIZE', $max_file_size): '').
 525              n.eInput($event).
 526              n.sInput($step).
 527              n.hInput('id', $id).
 528  
 529              n.hInput('sort', $sort).
 530              n.hInput('dir', $dir).
 531              n.hInput('page', $page).
 532              n.hInput('search_method', $search_method).
 533              n.hInput('crit', $crit).
 534  
 535              n.graf(
 536                  '<label for="'.$label_id.'">'.$label.'</label>'.sp.popHelp($pophelp).sp.
 537                      fInput('file', 'thefile', '', 'edit', '', '', '', '', $label_id).sp.
 538                      fInput('submit', '', gTxt('upload'), 'smallerbox')
 539              ).
 540  
 541              n.'</div>'.
 542              n.'</form>';
 543      }
 544  
 545  //-------------------------------------------------------------
 546  
 547  	function search_form($event, $step, $crit, $methods, $method, $default_method)
 548      {
 549          $method = ($method) ? $method : $default_method;
 550  
 551          return n.n.form(
 552              graf(
 553                  '<label for="'.$event.'-search">'.gTxt('search').'</label>'.sp.
 554                  selectInput('search_method', $methods, $method, '', '', $event.'-search').sp.
 555                  fInput('text', 'crit', $crit, 'edit', '', '', '15').
 556                  eInput($event).
 557                  sInput($step).
 558                  fInput('submit', 'search', gTxt('go'), 'smallerbox')
 559              )
 560          , '', '', 'get', 'search-form');
 561      }
 562  
 563  //-------------------------------------------------------------
 564  
 565  	function pref_text($name, $val, $id = '')
 566      {
 567          $id = ($id) ? $id : $name;
 568  
 569          $vals = array(
 570              USE_TEXTILE          => gTxt('use_textile'),
 571              CONVERT_LINEBREAKS   => gTxt('convert_linebreaks'),
 572              LEAVE_TEXT_UNTOUCHED => gTxt('leave_text_untouched')
 573          );
 574  
 575          return selectInput($name, $vals, $val, '', '', $id);
 576      }
 577  
 578  //-------------------------------------------------------------
 579  	function dom_attach($id, $content, $noscript='', $wraptag='div', $wraptagid='')
 580      {
 581  
 582          $c = addcslashes($content, "\r\n\"\'");
 583          $c = preg_replace('@<(/?)script@', '\\x3c$1script', $c);
 584          $js = <<<EOF
 585  var e = document.getElementById('{$id}');
 586  var n = document.createElement('{$wraptag}');
 587  n.innerHTML = '{$c}';
 588  n.setAttribute('id','{$wraptagid}');
 589  e.appendChild(n);
 590  EOF;
 591  
 592          return script_js($js, $noscript);
 593      }
 594  
 595  //-------------------------------------------------------------
 596  	function script_js($js, $noscript='')
 597      {
 598          $out = '<script type="text/javascript">'.n.
 599              '<!--'.n.
 600              trim($js).n.
 601              '// -->'.n.
 602              '</script>'.n;
 603          if ($noscript)
 604              $out .= '<noscript>'.n.
 605                  trim($noscript).n.
 606                  '</noscript>'.n;
 607          return $out;
 608      }
 609  
 610  //-------------------------------------------------------------
 611  	function toggle_box($classname, $form=0) {
 612  
 613          $name = 'cb_toggle_'.$classname;
 614          $i =
 615              '<input type="checkbox" name="'.$name.'" id="'.$name.'" value="1" '.
 616              (cs('toggle_'.$classname) ? 'checked="checked" ' : '').
 617              'class="checkbox" onclick="toggleClassRemember(\''.$classname.'\');" />'.
 618              ' <label for="'.$name.'">'.gTxt('detail_toggle').'</label> '.
 619              script_js("setClassRemember('".$classname."');addEvent(window, 'load', function(){setClassRemember('".$classname."');});");
 620          if ($form)
 621              return n.form($i);
 622          else
 623              return n.$i;
 624      }
 625  
 626  //-------------------------------------------------------------
 627  	function cookie_box($classname, $form=1) {
 628  
 629          $name = 'cb_'.$classname;
 630          $val = cs('toggle_'.$classname) ? 1 : 0;
 631  
 632          $i =
 633              '<input type="checkbox" name="'.$name.'" id="'.$name.'" value="1" '.
 634              ($val ? 'checked="checked" ' : '').
 635              'class="checkbox" onclick="setClassRemember(\''.$classname.'\','.(1-$val).');submit(this.form);" />'.
 636              ' <label for="'.$name.'">'.gTxt($classname).'</label> ';
 637  
 638          if ($form) {
 639              $args = empty($_SERVER['QUERY_STRING']) ? '' : '?'.htmlspecialchars($_SERVER['QUERY_STRING']);
 640              return '<form class="'.$name.'" method="post" action="index.php'.$args.'">'.$i.eInput(gps('event')).n.'<noscript><div><input type="submit" value="'.gTxt('go').'" /></div></noscript></form>';
 641          } else {
 642              return n.$i;
 643          }
 644      }
 645  
 646  
 647  //-------------------------------------------------------------
 648  	function fieldset($content, $legend='', $id='') {
 649          $a_id = ($id ? ' id="'.$id.'"' : '');
 650          return tag(trim(tag($legend, 'legend').n.$content), 'fieldset', $a_id);
 651      }
 652  
 653  ?>


Generated: Mon Feb 18 03:42:45 2008 Cross-referenced by PHPXref 0.7