[ Index ]

PHP Cross Reference of Textpattern 4.0.8

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


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