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

PHP Cross Reference of TXP stable 4.0.6

title

Body

[close]

/textpattern/include/ -> txp_list.php (source)

   1  <?php
   2  /*
   3      This is Textpattern
   4      Copyright 2005 by Dean Allen
   5       All rights reserved.
   6  
   7      Use of this software indicates acceptance of the Textpattern license agreement
   8  
   9  $HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/include/txp_list.php $
  10  $LastChangedRevision: 2725 $
  11  
  12  */
  13  
  14      if (!defined('txpinterface')) die('txpinterface is undefined.');
  15  
  16      global $statuses;
  17      $statuses = array(
  18          1 => gTxt('draft'),
  19          2 => gTxt('hidden'),
  20          3 => gTxt('pending'),
  21          4 => gTxt('live'),
  22          5 => gTxt('sticky'),
  23      );
  24  
  25      if ($event=='list') {
  26          require_privs('article');
  27  
  28          if(!$step or !in_array($step, array('list_change_pageby','list_list','list_multi_edit','list_list'))){
  29              list_list();
  30          } else $step();
  31      }
  32  
  33  //--------------------------------------------------------------
  34  
  35  	function list_list($message = '', $post = '')
  36      {
  37          global $statuses, $comments_disabled_after, $step, $txp_user;
  38  
  39          pagetop(gTxt('tab_list'), $message);
  40  
  41          extract(get_prefs());
  42  
  43          extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method')));
  44  
  45          $sesutats = array_flip($statuses);
  46  
  47          $dir = ($dir == 'asc') ? 'asc' : 'desc';
  48  
  49          switch ($sort)
  50          {
  51              case 'id':
  52                  $sort_sql = 'ID '.$dir;
  53              break;
  54  
  55              case 'title':
  56                  $sort_sql = 'Title '.$dir.', Posted desc';
  57              break;
  58  
  59              case 'section':
  60                  $sort_sql = 'Section '.$dir.', Posted desc';
  61              break;
  62  
  63              case 'category1':
  64                  $sort_sql = 'Category1 '.$dir.', Posted desc';
  65              break;
  66  
  67              case 'category2':
  68                  $sort_sql = 'Category2 '.$dir.', Posted desc';
  69              break;
  70  
  71              case 'status':
  72                  $sort_sql = 'Status '.$dir.', Posted desc';
  73              break;
  74  
  75              case 'author':
  76                  $sort_sql = 'AuthorID '.$dir.', Posted desc';
  77              break;
  78  
  79              case 'comments':
  80                  $sort_sql = 'comments_count '.$dir.', Posted desc';
  81              break;
  82  
  83              case 'lastmod':
  84                  $sort_sql = 'LastMod '.$dir.', Posted desc';
  85              break;
  86  
  87              default:
  88                  $sort = 'posted';
  89                  $sort_sql = 'Posted '.$dir;
  90              break;
  91          }
  92  
  93          $switch_dir = ($dir == 'desc') ? 'asc' : 'desc';
  94  
  95          $criteria = 1;
  96  
  97          if ($search_method and $crit)
  98          {
  99              $crit_escaped = doSlash($crit);
 100  
 101              $critsql = array(
 102                  'id'         => "ID = '$crit_escaped'",
 103                  'title_body' => "Title rlike '$crit_escaped' or Body rlike '$crit_escaped'",
 104                  'section'     => "Section rlike '$crit_escaped'",
 105                  'categories' => "Category1 rlike '$crit_escaped' or Category2 rlike '$crit_escaped'",
 106                  'status'     => "Status = '".(@$sesutats[gTxt($crit_escaped)])."'",
 107                  'author'     => "AuthorID rlike '$crit_escaped'",
 108                  'posted'      => "Posted like '$crit_escaped%'",
 109                  'lastmod'      => "LastMod like '$crit_escaped%'"
 110              );
 111  
 112              if (array_key_exists($search_method, $critsql))
 113              {
 114                  $criteria = $critsql[$search_method];
 115                  $limit = 500;
 116              }
 117  
 118              else
 119              {
 120                  $search_method = '';
 121                  $crit = '';
 122              }
 123          }
 124  
 125          else
 126          {
 127              $search_method = '';
 128              $crit = '';
 129          }
 130  
 131          $total = safe_count('textpattern', "$criteria");
 132  
 133          if ($total < 1)
 134          {
 135              if ($criteria != 1)
 136              {
 137                  echo n.list_search_form($crit, $search_method).
 138                      n.graf(gTxt('no_results_found'), ' style="text-align: center;"');
 139              }
 140  
 141              else
 142              {
 143                  echo graf(gTxt('no_articles_recorded'), ' style="text-align: center;"');
 144              }
 145  
 146              return;
 147          }
 148  
 149          $limit = max(@$article_list_pageby, 15);
 150  
 151          list($page, $offset, $numPages) = pager($total, $limit, $page);
 152  
 153          echo n.list_search_form($crit, $search_method);
 154  
 155          $rs = safe_rows_start('*, unix_timestamp(Posted) as posted, unix_timestamp(LastMod) as lastmod', 'textpattern',
 156              "$criteria order by $sort_sql limit $offset, $limit"
 157          );
 158  
 159          if ($rs)
 160          {
 161              $total_comments = array();
 162  
 163              // fetch true comment count, not the public comment count
 164              // maybe we should have another row in the db?
 165              $rs2 = safe_rows_start('parentid, count(*) as num', 'txp_discuss', "1 group by parentid order by parentid");
 166  
 167              if ($rs2)
 168              {
 169                  while ($a = nextRow($rs2))
 170                  {
 171                      $pid = $a['parentid'];
 172                      $num = $a['num'];
 173  
 174                      $total_comments[$pid] = $num;
 175                  }
 176              }
 177  
 178              echo n.n.'<form name="longform" method="post" action="index.php" onsubmit="return verify(\''.gTxt('are_you_sure').'\')">'.
 179  
 180                  n.startTable('list','','','','90%').
 181                  n.tr(
 182                      n.column_head('ID', 'id', 'list', true, $switch_dir, $crit, $search_method, ('id' == $sort) ? $dir : '').
 183                      column_head('posted', 'posted', 'list', true, $switch_dir, $crit, $search_method, ('posted' == $sort) ? $dir : '').
 184                      column_head('article_modified', 'lastmod', 'list', true, $switch_dir, $crit, $search_method, (('lastmod' == $sort) ? "$dir " : '').'articles_detail').
 185                      column_head('title', 'title', 'list', true, $switch_dir, $crit, $search_method, ('title' == $sort) ? $dir : '').
 186                      column_head('section', 'section', 'list', true, $switch_dir, $crit, $search_method, ('section' == $sort) ? $dir : '').
 187                      column_head('category1', 'category1', 'list', true, $switch_dir, $crit, $search_method, (('category1' == $sort) ? "$dir " : '').'articles_detail').
 188                      column_head('category2', 'category2', 'list', true, $switch_dir, $crit, $search_method, (('category2' == $sort) ? "$dir " : '').'articles_detail').
 189                      column_head('status', 'status', 'list', true, $switch_dir, $crit, $search_method, ('status' == $sort) ? $dir : '').
 190                      column_head('author', 'author', 'list', true, $switch_dir, $crit, $search_method, ('author' == $sort) ? $dir : '').
 191                      column_head('comments', 'comments', 'list', true, $switch_dir, $crit, $search_method, (('comments' == $sort) ? "$dir " : '').'articles_detail').
 192                      hCell()
 193                  );
 194  
 195              include_once txpath.'/publish/taghandlers.php';
 196  
 197              while ($a = nextRow($rs))
 198              {
 199                  extract($a);
 200  
 201                  if (empty($Title))
 202                  {
 203                      $Title = '<em>'.eLink('article', 'edit', 'ID', $ID, gTxt('untitled')).'</em>';
 204                  }
 205  
 206                  else
 207                  {
 208                      $Title = eLink('article', 'edit', 'ID', $ID, $Title);
 209                  }
 210  
 211                  $Category1 = ($Category1) ? '<span title="'.htmlspecialchars(fetch_category_title($Category1)).'">'.$Category1.'</span>' : '';
 212                  $Category2 = ($Category2) ? '<span title="'.htmlspecialchars(fetch_category_title($Category2)).'">'.$Category2.'</span>' : '';
 213  
 214                  $manage = n.'<ul class="articles_detail">'.
 215                          n.t.'<li>'.eLink('article', 'edit', 'ID', $ID, gTxt('edit')).'</li>'.
 216                          ( ($Status == 4 or $Status == 5) ? n.t.'<li><a href="'.permlinkurl($a).'">'.gTxt('view').'</a></li>' : '' ).
 217                          n.'</ul>';
 218  
 219                  $Status = !empty($Status) ? $statuses[$Status] : '';
 220  
 221                  $comments = gTxt('none');
 222  
 223                  if (isset($total_comments[$ID]) and $total_comments[$ID] > 0)
 224                  {
 225                      $comments = href(gTxt('manage'), 'index.php?event=discuss'.a.'step=list'.a.'search_method=parent'.a.'crit='.$ID).
 226                          ' ('.$total_comments[$ID].')';
 227                  }
 228  
 229                  $comment_status = ($Annotate) ? gTxt('on') : gTxt('off');
 230  
 231                  if ($comments_disabled_after)
 232                  {
 233                      $lifespan = $comments_disabled_after * 86400;
 234                      $time_since = time() - $posted;
 235  
 236                      if ($time_since > $lifespan)
 237                      {
 238                          $comment_status = gTxt('expired');
 239                      }
 240                  }
 241  
 242                  $comments = n.'<ul>'.
 243                      n.t.'<li>'.$comment_status.'</li>'.
 244                      n.t.'<li>'.$comments.'</li>'.
 245                      n.'</ul>';
 246  
 247                  echo n.n.tr(
 248  
 249                      n.td(eLink('article', 'edit', 'ID', $ID, $ID).$manage).
 250  
 251                      td(
 252                          gTime($posted), '', $posted < time() ? '' : 'unpublished'
 253                      ).
 254  
 255                      td(
 256                          gTime($lastmod), '', "articles_detail"
 257                      ).
 258  
 259                      td($Title).
 260  
 261                      td(
 262                          '<span title="'.htmlspecialchars(fetch_section_title($Section)).'">'.$Section.'</span>'
 263                      , 75).
 264  
 265                      td($Category1, 100, "articles_detail").
 266                      td($Category2, 100, "articles_detail").
 267                      td(($a['Status'] < 4 ? $Status : '<a href="'.permlinkurl($a).'">'.$Status.'</a>'), 50).
 268  
 269                      td(
 270                          '<span title="'.htmlspecialchars(get_author_name($AuthorID)).'">'.htmlspecialchars($AuthorID).'</span>'
 271                      ).
 272  
 273                      td($comments, 50, "articles_detail").
 274  
 275                      td((
 276                          (  ($a['Status'] >= 4 and has_privs('article.edit.published'))
 277                          or ($a['Status'] >= 4 and $AuthorID == $txp_user
 278                                                   and has_privs('article.edit.own.published'))
 279                          or ($a['Status'] < 4 and has_privs('article.edit'))
 280                          or ($a['Status'] < 4 and $AuthorID == $txp_user and has_privs('article.edit.own'))
 281                          )
 282                          ? fInput('checkbox', 'selected[]', $ID)
 283                          : '&nbsp;'
 284                      ))
 285                  );
 286              }
 287  
 288              echo n.n.tr(
 289                  tda(
 290                      toggle_box('articles_detail'),
 291                      ' colspan="2" style="text-align: left; border: none;"'
 292                  ).
 293  
 294                  tda(
 295                      select_buttons().
 296                      list_multiedit_form($page, $sort, $dir, $crit, $search_method)
 297                  ,' colspan="9" style="text-align: right; border: none;"')
 298              ).
 299  
 300              n.endTable().
 301              n.'</form>'.
 302  
 303              n.nav_form('list', $page, $numPages, $sort, $dir, $crit, $search_method).
 304  
 305              n.pageby_form('list', $article_list_pageby);
 306          }
 307      }
 308  
 309  // -------------------------------------------------------------
 310  	function list_change_pageby()
 311      {
 312          event_change_pageby('article');
 313          list_list();
 314      }
 315  
 316  // -------------------------------------------------------------
 317  
 318  	function list_search_form($crit, $method)
 319      {
 320          $methods =    array(
 321              'id'                 => gTxt('ID'),
 322              'title_body' => gTxt('title_body'),
 323              'section'     => gTxt('section'),
 324              'categories' => gTxt('categories'),
 325              'status'     => gTxt('status'),
 326              'author'     => gTxt('author'),
 327              'posted'     => gTxt('posted'),
 328              'lastmod'     => gTxt('article_modified')
 329          );
 330  
 331          return search_form('list', 'list', $crit, $methods, $method, 'title_body');
 332      }
 333  
 334  // -------------------------------------------------------------
 335  
 336  	function list_multiedit_form($page, $sort, $dir, $crit, $search_method)
 337      {
 338          $methods = array(
 339              'changesection'   => gTxt('changesection'),
 340              'changecategory1' => gTxt('changecategory1'),
 341              'changecategory2' => gTxt('changecategory2'),
 342              'changestatus'    => gTxt('changestatus'),
 343              'changecomments'  => gTxt('changecomments'),
 344              'changeauthor'    => gTxt('changeauthor'),
 345              'delete'          => gTxt('delete'),
 346          );
 347  
 348          return event_multiedit_form('list', $methods, $page, $sort, $dir, $crit, $search_method);
 349      }
 350  
 351  // -------------------------------------------------------------
 352  
 353  	function list_multi_edit()
 354      {
 355          global $txp_user;
 356  
 357          $selected = ps('selected');
 358  
 359          if (!$selected)
 360          {
 361              return list_list();
 362          }
 363  
 364          $method = ps('edit_method');
 365          $changed = false;
 366          $ids = array();
 367  
 368          if ($method == 'delete')
 369          {
 370              if (!has_privs('article.delete'))
 371              {
 372                  $allowed = array();
 373  
 374                  if (has_privs('article.delete.own'))
 375                  {
 376                      foreach ($selected as $id)
 377                      {
 378                          $id = assert_int($id);
 379                          $author = safe_field('AuthorID', 'textpattern', "ID = $id");
 380  
 381                          if ($author == $txp_user)
 382                          {
 383                              $allowed[] = $id;
 384                          }
 385                      }
 386                  }
 387  
 388                  $selected = $allowed;
 389              }
 390  
 391              foreach ($selected as $id)
 392              {
 393                  $id = assert_int($id);
 394  
 395                  if (safe_delete('textpattern', "ID = $id"))
 396                  {
 397                      $ids[] = $id;
 398                  }
 399              }
 400  
 401              $changed = join(', ', $ids);
 402  
 403              if ($changed)
 404              {
 405                  safe_update('txp_discuss', "visible = ".MODERATE, "parentid in($changed)");
 406              }
 407          }
 408  
 409          else
 410          {
 411              $selected = array_map('assert_int', $selected);
 412              $selected = safe_rows('ID, AuthorID, Status', 'textpattern',
 413                                        'ID in ('. implode(',',$selected) .')');
 414  
 415              $allowed = array();
 416              foreach ($selected as $item)
 417              {
 418                  if ( ($item['Status'] >= 4 and has_privs('article.edit.published'))
 419                    or ($item['Status'] >= 4 and $item['AuthorID'] == $txp_user and has_privs('article.edit.own.published'))
 420                    or ($item['Status'] < 4 and has_privs('article.edit'))
 421                    or ($item['Status'] < 4 and $item['AuthorID'] == $txp_user and has_privs('article.edit.own')))
 422                  {
 423                      $allowed[] = $item['ID'];
 424                  }
 425              }
 426  
 427              $selected = $allowed; unset($allowed);
 428  
 429              switch ($method)
 430              {
 431                  // change author
 432                  case 'changeauthor':
 433  
 434                      $key = 'AuthorID';
 435                      $val = has_privs('article.edit') ? ps('AuthorID') : '';
 436  
 437                      // do not allow to be set to an empty value
 438                      if (!$val)
 439                      {
 440                          $selected = array();
 441                      }
 442  
 443                  break;
 444  
 445                  // change category1
 446                  case 'changecategory1':
 447                      $key = 'Category1';
 448                      $val = ps('Category1');
 449                  break;
 450  
 451                  // change category2
 452                  case 'changecategory2':
 453                      $key = 'Category2';
 454                      $val = ps('Category2');
 455                  break;
 456  
 457                  // change comments
 458                  case 'changecomments':
 459                      $key = 'Annotate';
 460                      $val = (int) ps('Annotate');
 461                  break;
 462  
 463                  // change section
 464                  case 'changesection':
 465  
 466                      $key = 'Section';
 467                      $val = ps('Section');
 468  
 469                      // do not allow to be set to an empty value
 470                      if (!$val)
 471                      {
 472                          $selected = array();
 473                      }
 474  
 475                  break;
 476  
 477                  // change status
 478                  case 'changestatus':
 479  
 480                      $key = 'Status';
 481                      $val = ps('Status');
 482                      if (!has_privs('article.publish') && $val>=4) $val = 3;
 483  
 484                      // do not allow to be set to an empty value
 485                      if (!$val)
 486                      {
 487                          $selected = array();
 488                      }
 489  
 490                  break;
 491  
 492                  default:
 493                      $key = '';
 494                      $val = '';
 495                  break;
 496              }
 497  
 498              if ($selected and $key)
 499              {
 500                  foreach ($selected as $id)
 501                  {
 502                      if (safe_update('textpattern', "$key = '".doSlash($val)."'", "ID = $id"))
 503                      {
 504                          $ids[] = $id;
 505                      }
 506                  }
 507  
 508                  $changed = join(', ', $ids);
 509              }
 510          }
 511  
 512          if ($changed)
 513          {
 514              update_lastmod();
 515  
 516              return list_list(
 517                  messenger('article', $changed, (($method == 'delete') ? 'deleted' : 'modified' ))
 518              );
 519          }
 520  
 521          return list_list();
 522      }
 523  
 524  ?>


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