[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/ -> articles.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # This file is part of Plume CMS, a website management application.
   6  # Copyright (C) 2001-2005 Loic d'Anterroches and contributors.
   7  #
   8  # Plume CMS is free software; you can redistribute it and/or modify
   9  # it under the terms of the GNU General Public License as published by
  10  # the Free Software Foundation; either version 2 of the License, or
  11  # (at your option) any later version.
  12  #
  13  # Plume CMS is distributed in the hope that it will be useful,
  14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  # GNU General Public License for more details.
  17  #
  18  # You should have received a copy of the GNU General Public License
  19  # along with this program; if not, write to the Free Software
  20  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21  #
  22  # ***** END LICENSE BLOCK ***** */
  23  
  24  require_once 'path.php';
  25  require_once $_PX_config['manager_path'].'/prepend.php';
  26  require_once $_PX_config['manager_path'].'/inc/class.article.php';
  27  
  28  auth::checkAuth(PX_AUTH_NORMAL);
  29  $is_user_admin = auth::asLevel(PX_AUTH_ADMIN);
  30  
  31  $m = new Manager();
  32  $_px_theme = $m->user->getTheme();
  33  
  34  /* ================================================= *
  35   *       Generate sub-menu                           *
  36   * ================================================= */
  37  
  38  $px_submenu->addItem(__('Back to the list of resources'), 'index.php', 
  39                       'themes/'.$_px_theme.'/images/ico_back.png', false);
  40  $px_submenu->addItem(__('Article list'), 'articles.php?op=list',
  41                       'themes/'.$_px_theme.'/images/ico_article.png', false);
  42  $px_submenu->addItem(__('New article'), 'articles.php',
  43                       'themes/'.$_px_theme.'/images/ico_new.png', false, 
  44                       (!empty($_REQUEST['op'])||empty($_REQUEST['resource_id']))
  45                       );
  46  
  47  
  48  /* ========================================================================= *
  49   *                Process block                                              *
  50   * ========================================================================= */
  51  
  52  
  53  /* ===================================================================== *
  54   *                        add/edit/view an article                       *
  55   * ===================================================================== */
  56  if (empty($_REQUEST['op'])) {
  57  
  58      $ar = new Article();
  59      /* =================================================== *
  60       *  Get current article and check if right to edit it  *
  61       * =================================================== */
  62      $is_editable = true;
  63      if (!empty($_REQUEST['resource_id'])) {
  64          if (false !== $m->loadResource($ar, $_REQUEST['resource_id'])) {
  65              // check the rights
  66              if (!$m->asRightToEdit($ar)) {
  67                  $is_editable = false;
  68              }
  69          } else {
  70              $m->setError(__('Error: The requested article is not available.'), 
  71                           400);
  72              $is_editable = false;
  73          }
  74      } else {
  75          $ar->setDefaults($m->user);
  76      }
  77  
  78      /* ========================== *
  79       *  Get values from the form  *
  80       * ========================== */
  81      if ((!empty($_POST['preview']) || !empty($_POST['publish']) 
  82           || !empty($_POST['transform']) || !empty($_POST['addcategory'])
  83           || !empty($_POST['increase']) || !empty($_POST['increase_x']) 
  84           || !empty($_POST['decrease']) || !empty($_POST['decrease_x'])
  85           ) && $is_editable) {
  86          $ar->set(form::getPostField('a_title'),
  87                   form::getPostField('a_subject'),
  88                   form::getPostField('a_description'),
  89                   form::getPostField('a_description_format'),
  90                   form::getPostField('a_status'),
  91                   form::getPostField('a_path'),
  92                   form::getTimeField('a_dt') /*Publication date */,
  93                   form::getTimeField('a_dt_e') /*End date */,
  94                   form::getPostField('a_noenddate'),
  95                   form::getPostField('a_comment_support'),
  96                   form::getPostField('a_subtype'));
  97  
  98          if ($ar->f('resource_id') == '') {
  99              $ar->setField('category_id', form::getPostField('a_category_id'));
 100          }
 101          if (!empty($_POST['increase']) || !empty($_POST['increase_x'])) {
 102              $m->user->increase('article_textarea_content');
 103          }
 104          if (!empty($_POST['decrease']) || !empty($_POST['decrease_x'])) {
 105              $m->user->decrease('article_textarea_content');
 106          }
 107  
 108          if (!empty($_POST['transform'])) {
 109              $ar->setField('description', 
 110                            '=html'."\n"
 111                            .$ar->getFormattedContent('description','html'));
 112          }
 113      }
 114  
 115      /* ================================================= *
 116       *               Add, edit an article                *
 117       * ================================================= */
 118      if (!empty($_POST['publish']) && $is_editable) {
 119  
 120          if ($ar->f('resource_id') > 0) {
 121              // edit an article
 122              if (false !== ($id = $m->saveArticle($ar))) { 
 123                  if ($ar->f('status') != PX_RESOURCE_STATUS_INEDITION) { 
 124                      $m->setMessage(__('The article was successfully saved.'));
 125                      header('Location: articles.php?op=list');
 126                  } else {
 127                      header('Location: articles.php?resource_id='.
 128                             $ar->f('resource_id'));
 129                  }
 130                  exit;
 131              }                             
 132          } else {
 133              // add an article
 134              $px_category_id = form::getPostField('a_category_id');
 135              $m->user->savePref('article_category_id', $px_category_id);
 136              $m->user->savePref('article_status', 
 137                                 form::getPostField('a_status'));
 138              $m->user->savePref('content_format',
 139                                 form::getPostField('a_description_format'));
 140              $m->user->savePref('article_subtype', 
 141                                 form::getPostField('a_subtype'));
 142              $m->user->savePref('article_comment_support', 
 143                                 form::getPostField('a_comment_support'));
 144              $ar->setField('category_id', $px_category_id);
 145              if (false !== ($id = $m->saveArticle($ar))) {
 146                  $m->setMessage(__('The article was successfully saved.'));
 147                  if ($ar->f('status') != PX_RESOURCE_STATUS_INEDITION) {
 148                      header('Location: articles.php?op=list');
 149                  } else {
 150                      if ($ar->pages->nbRow() == 0) {
 151                          $m->setMessage(sprintf(__('The article was successfully saved.').' '.__('You need now to add the first page of the article. After adding the first page, you can <a href="%s">validate and put online the article</a>.'), 'articles.php?resource_id='.$id));
 152                          header('Location: articles.php?op=page&resource_id='.$id);
 153                      } else {
 154                          header('Location: articles.php?resource_id='.$id);
 155                      }
 156                  }
 157                  exit;
 158              }  
 159          }
 160      }
 161  
 162      /* ================================================= *
 163       *               Associate to a category             *
 164       * ================================================= */
 165      if (strlen(form::getField('addcategory')) 
 166          && strlen(form::getField('a_category_id')) 
 167          && strlen($ar->f('resource_id')) 
 168          && $is_editable) {
 169  
 170          $px_ar_category_id = form::getField('a_category_id');
 171          
 172          $m->user->savePref('article_category_id', $px_ar_category_id);
 173  
 174          if ('main' == form::getField('addcategory')) {
 175              $type = PX_RESOURCE_CATEGORY_MAIN;
 176          } else {
 177              $type = PX_RESOURCE_CATEGORY_OTHER;
 178          } 
 179          
 180          if (false !== $m->addResourceInCategory($ar, $px_ar_category_id, $type)) {
 181              header('Location: articles.php?resource_id='.$ar->f('resource_id'));
 182              exit;
 183          }
 184      }
 185  
 186  
 187  
 188      /* ================================================= *
 189       *              Remove from a category               *
 190       * ================================================= */
 191      else if (strlen(form::getField('delcat')) 
 192          && strlen($ar->f('resource_id')) 
 193          && strlen(form::getField('a_category_id')) 
 194          && $is_editable) {
 195  
 196          $px_category_id = form::getField('a_category_id');
 197          if (false !== $m->removeResourceFromCategory($ar, $px_category_id)) {
 198              header('Location: articles.php?resource_id='.$ar->f('resource_id'));
 199              exit;
 200          }
 201      }
 202  
 203      /* ================================================= *
 204       *               Delete the article                  *
 205       * ================================================= */
 206      else if (strlen(form::getPostField('delete')) && $is_editable) {
 207          if ($m->delArticle($ar) !== false) {
 208              $m->setMessage(__('The article was successfully deleted.'));
 209              header('Location: articles.php?op=list');
 210              exit;
 211          }
 212      }
 213  
 214      /* ================================================= *
 215       *               Simple visualization                *
 216       * ================================================= */
 217      else if (!empty($_POST['preview'])) {
 218          $m->check($ar); // Provide the error feedback
 219      }
 220  
 221      /* ================================================= *
 222       *                 Remove a comment                  *
 223       * ================================================= */
 224      if (strlen(form::getField('delete-comment')) 
 225          && strlen($ar->f('resource_id')) 
 226          && strlen(form::getField('comment_id')) 
 227          && $is_editable) {
 228  
 229          $id = form::getField('comment_id');
 230          if (false !== ($ct = $m->getComment($id, $ar->f('resource_id')))) {
 231              if (false !== $m->delComment($ct)) {
 232                  $m->setMessage(__('The comment was successfully deleted.'));
 233                  header('Location: articles.php?resource_id='.$ar->f('resource_id'));
 234                  exit;
 235              }
 236          }
 237      }
 238  
 239      /* ================================================= *
 240       *                 Add/Edit a comment                *
 241       * ================================================= */
 242      if (strlen(form::getField('publish-comment')) 
 243          && strlen($ar->f('resource_id')) 
 244          && $is_editable) {
 245          $id = form::getField('comment_id');
 246          $ct = new Comment();
 247          if ((int) $id > 0) {
 248              if (false === $ct->load($id)) {
 249                  $m->setError(__('The requested comment does not exist.'));
 250              }
 251          }
 252          if (false === $m->error()) {
 253              $ct->set(form::getField('c_author'), 
 254                       form::getField('c_email'), 
 255                       form::getField('c_website'), 
 256                       form::getField('c_content'),
 257                       $ar->f('resource_id'), 
 258                       ($ct->f('comment_ip')) ? $ct->f('comment_ip') : $_SERVER["REMOTE_ADDR"],
 259                       form::getField('c_status'),
 260                       PX_COMMENT_TYPE_NORMAL,
 261                       ($ct->f('comment_id')) ? $ct->f('comment_user_id') : $m->user->getId());
 262              if (false !== $m->saveComment($ct)) {
 263                  $m->setMessage(__('The comment was successfully saved.'));
 264                  header('Location: articles.php?resource_id='.$ar->f('resource_id'));
 265                  exit;
 266              }
 267          }
 268      }
 269  
 270  
 271      /* ================================= *
 272       *  Get the categories and subtypes  *
 273       * ================================= */
 274      if ($is_editable) {
 275          $arry_cat = $m->getArrayCategories();
 276          $arry_subtypes = $m->getSubTypesArray(PX_RESOURCE_MANAGER_ARTICLE);
 277      }
 278  }
 279  
 280  
 281  
 282  
 283  /* =============================================================== *
 284   *                Add/edit a page                                  *
 285   * =============================================================== */
 286  
 287  if (form::getField('op') == 'page') {
 288      /* ================================================ *
 289       *          Set all the default values              *
 290       * ================================================ */
 291      $ar = new Article();
 292  
 293  
 294  
 295      /* =================================================== *
 296       *  Get current article and check if right to edit it  *
 297       * =================================================== */
 298      $is_editable = true;
 299      if (!empty($_REQUEST['resource_id'])) {
 300          if (false !== $m->loadResource($ar, $_REQUEST['resource_id'])) {
 301              // check the rights
 302              if (!$m->asRightToEdit($ar)) {
 303                  $is_editable = false;
 304              }
 305          } else {
 306              $m->setError(__('Error: The requested article is not available.'), 
 307                           400);
 308              $is_editable = false;
 309          }
 310      } else {
 311          $m->setError(__('Error: The requested article is not available.'), 
 312                           400);
 313          $is_editable = false;
 314      }
 315  
 316      if (!empty($_REQUEST['a_page_id'])) {
 317          // Request a given page.
 318          if (false === $ar->goToPage($_REQUEST['a_page_id'])) {
 319              $is_editable = false;
 320              $m->setError(__('Error: The requested page is not available.'), 
 321                           400);
 322          }
 323      } else {
 324          // Need a new page
 325          $ar->setDefaults($m->user);
 326          $ar->pages->insert();
 327      }
 328  
 329      if ((!empty($_POST['preview']) 
 330           || !empty($_POST['publish']) || !empty($_POST['transform'])
 331           || !empty($_POST['increase']) || !empty($_POST['increase_x']) 
 332           || !empty($_POST['decrease']) || !empty($_POST['decrease_x']))
 333          && $is_editable) {
 334          /* =============================== *
 335           *  Get value from the form        *
 336           * =============================== */
 337          $ar->setPage(form::getField('a_page_id'),
 338                       form::getPostField('a_page_title'),
 339                       form::getPostField('a_page_content'),
 340                       form::getPostField('a_page_content_format'),
 341                       form::getPostField('a_page_number'));
 342  
 343          if (!empty($_POST['increase']) || !empty($_POST['increase_x'])) {
 344              $m->user->increase('article_textarea_page');
 345          }
 346          if (!empty($_POST['decrease']) || !empty($_POST['decrease_x'])) {
 347              $m->user->decrease('article_textarea_page');
 348          }
 349  
 350          if (!empty($_POST['transform'])) {
 351              $ar->pages->setField('page_content', 
 352                                   '=html'."\n"
 353                                   .$ar->getFormattedContent('page_content', 
 354                                                             'html', 'pages'));
 355          }
 356          
 357      }
 358  
 359      
 360      /* ================================================= *
 361       *    Add, edit a page - database operations         *
 362       * ================================================= */
 363      
 364      if (!empty($_POST['publish']) && $is_editable) {
 365          if ($ar->pages->f('page_id') > 0) {
 366              if (false !== ($id = $m->saveArticlePage($ar))) {
 367                  $m->setMessage(__('The page was successfully saved.'));
 368                  header('Location: articles.php?op=page&resource_id='
 369                         .$ar->f('resource_id').'&a_page_id='.$id);
 370                  exit;
 371              }
 372          } else {
 373              $m->user->savePref('content_format', 
 374                                 form::getPostField('a_page_content_format'));
 375              if (false !== ($id = $m->saveArticlePage($ar))) {
 376                  $m->setMessage(__('The page was successfully added.'));
 377                  header('Location: articles.php?op=page&resource_id='
 378                         .$ar->f('resource_id').'&a_page_id='.$id);
 379                  exit;
 380              }
 381          }
 382      }
 383  
 384      else if (!empty($_POST['delete']) 
 385          && $ar->f('resource_id') > 0
 386          && $ar->pages->f('page_id') > 0
 387          && $is_editable) {
 388          if (false !== $m->delArticlePage($ar)) {
 389              $m->setMessage(__('The page was deleted.'));
 390              header('Location: articles.php?resource_id='
 391                     .$ar->f('resource_id'));
 392              exit;
 393          }
 394      }
 395  
 396      else if (!empty($_POST['preview'])) {
 397          $m->checkArticlePage($ar); // Provide the error feedback
 398      }
 399  
 400  } // end of Add, edit a page
 401  
 402  /* =============================================================== *
 403   *                     List the articles                           *
 404   * =============================================================== */
 405  if (form::getField('op') == 'list') {
 406  
 407      //Get the category id and save it
 408      $cat_id = (!empty($_GET['cat_id'])) ? $_GET['cat_id'] : $m->user->getPref('list_articles_cat_id');
 409      $m->user->savePref('list_articles_cat_id', $cat_id, $_SESSION['website_id'], true);
 410      if ($cat_id == 'allcat') $cat_id = '';
 411      
 412      //Get the search query
 413      $px_q = (!empty($_GET['q'])) ? $_GET['q'] : '';
 414  
 415      //Get available months and selected
 416      list($first, $last, $arry_months) = $m->getArrayMonths('articles', $cat_id);
 417      $px_m_s = $m->user->getPref('list_articles_month');
 418      $px_m = (!empty($_GET['m'])) ? $_GET['m'] : ((!empty($px_m_s)) ? $px_m_s : $last);
 419      $m->user->savePref('list_articles_month', $px_m, $_SESSION['website_id'], true);
 420  
 421      if ($px_m == 'alldate') {
 422          $px_m = $first;
 423          $px_end = date::stamp(0, 1 /*1 month after now*/, 0);
 424      } else {
 425          $px_end = date::stamp(0, 1 /*1 month after $px_m */, 0, date::unix($px_m));
 426      }
 427  
 428      if (empty($px_q)) {
 429          $res = $m->getResources(''/* All users */, '' /* All status */, $cat_id, 'articles', $px_m /*Date start */, $px_end /*Date end */);
 430          //get again as possibly modified because of the 'alldate' case
 431          $px_m = $m->user->getPref('list_articles_month');
 432      } else {
 433          $res = $m->searchResources($px_q, false /*Not only the online resources */, 'articles', 'ResourceSet' /*Class used for the results */);
 434          //Search is made on all the date and all the categories
 435          $px_m = 'alldate';
 436          $cat_id = 'allcat';
 437      }
 438  
 439      // Categories
 440      $arry_cat = $m->getArrayCategories(true);
 441  
 442  
 443  }
 444  
 445  /* ========================================================================= *
 446   *                         Display block                                     *
 447   * ========================================================================= */
 448  
 449  /* --------------------------------------------------- *
 450   *   Set title of the page, and load common top page   *
 451   * --------------------------------------------------- */
 452  
 453  $px_title =  __('Articles');
 454  include config::f('manager_path').'/mtemplates/_top.php';
 455  
 456  echo '<h1>'.__('Articles')."</h1>\n\n";
 457  
 458  
 459  if (form::getField('op') == 'page') {
 460      include config::f('manager_path').'/mtemplates/article-page-edit.php';
 461  
 462  } else if (form::getField('op') == 'list') {
 463      include config::f('manager_path').'/mtemplates/article-list.php';
 464  
 465  } else {
 466      include config::f('manager_path').'/mtemplates/article-edit.php';
 467  }
 468  
 469  /* ------------------------------------------------ *
 470   *           Load common bottom page                *
 471   * ------------------------------------------------ */
 472  include config::f('manager_path').'/mtemplates/_bottom.php';
 473  
 474  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics