[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

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

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


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