[ Index ]

PHP Cross Reference of Joomla 1.5.25

title

Body

[close]

/administrator/components/com_content/ -> controller.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: controller.php 21065 2011-04-03 22:16:32Z dextercowley $
   4   * @package        Joomla
   5   * @subpackage    Content
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.controller');
  19  
  20  /**
  21   * Content Component Controller
  22   *
  23   * @package        Joomla
  24   * @subpackage    Content
  25   * @since 1.5
  26   */
  27  class ContentController extends JController
  28  {
  29      /**
  30       * Articles element
  31       */
  32  	function element()
  33      {
  34          $model    = &$this->getModel( 'element' );
  35          $view    = &$this->getView( 'element');
  36          $view->setModel( $model, true );
  37          $view->display();
  38      }
  39  
  40      /**
  41      * Compiles a list of installed or defined modules
  42      * @param database A database connector object
  43      */
  44  	function viewContent()
  45      {
  46          global $mainframe;
  47  
  48          // Initialize variables
  49          $db            =& JFactory::getDBO();
  50          $filter        = null;
  51  
  52          // Get some variables from the request
  53          $sectionid            = JRequest::getVar( 'sectionid', -1, '', 'int' );
  54          $redirect            = $sectionid;
  55          $option                = JRequest::getCmd( 'option' );
  56          $context            = 'com_content.viewcontent';
  57          $filter_order        = $mainframe->getUserStateFromRequest( $context.'filter_order',        'filter_order',        '',    'cmd' );
  58          $filter_order_Dir    = $mainframe->getUserStateFromRequest( $context.'filter_order_Dir',    'filter_order_Dir',    '',    'word' );
  59          $filter_state        = $mainframe->getUserStateFromRequest( $context.'filter_state',        'filter_state',        '',    'word' );
  60          $catid                = $mainframe->getUserStateFromRequest( $context.'catid',            'catid',            0,    'int' );
  61          $filter_authorid    = $mainframe->getUserStateFromRequest( $context.'filter_authorid',    'filter_authorid',    0,    'int' );
  62          $filter_sectionid    = $mainframe->getUserStateFromRequest( $context.'filter_sectionid',    'filter_sectionid',    -1,    'int' );
  63          $search                = $mainframe->getUserStateFromRequest( $context.'search',            'search',            '',    'string' );
  64          if (strpos($search, '"') !== false) {
  65              $search = str_replace(array('=', '<'), '', $search);
  66          }
  67          $search = JString::strtolower($search);
  68  
  69          $limit        = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
  70          $limitstart    = $mainframe->getUserStateFromRequest($context.'limitstart', 'limitstart', 0, 'int');
  71  
  72          // In case limit has been changed, adjust limitstart accordingly
  73          $limitstart = ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );
  74  
  75          //$where[] = "c.state >= 0";
  76          $where[] = 'c.state != -2';
  77  
  78          // ensure we have a valid value for filter_order
  79          if (!in_array($filter_order, array('c.title', 'c.state', 'frontpage', 'c.ordering', 'groupname',
  80                                      'section_name', 'cc.title', 'author', 'c.created', 'c.hits', 'c.id')))
  81          {
  82              $filter_order = 'section_name';
  83  
  84          }
  85  
  86          if ($filter_order == 'c.ordering') {
  87              $order = ' ORDER BY section_name, cc.title, c.ordering '. $filter_order_Dir;
  88          } else {
  89              $order = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', section_name, cc.title, c.ordering';
  90          }
  91          $all = 1;
  92  
  93          if ($filter_sectionid >= 0) {
  94              $filter = ' WHERE cc.section = '. (int) $filter_sectionid;
  95          }
  96          $section->title = 'All Articles';
  97          $section->id = 0;
  98  
  99          /*
 100           * Add the filter specific information to the where clause
 101           */
 102          // Section filter
 103          if ($filter_sectionid >= 0) {
 104              $where[] = 'c.sectionid = ' . (int) $filter_sectionid;
 105          }
 106          // Category filter
 107          if ($catid > 0) {
 108              $where[] = 'c.catid = ' . (int) $catid;
 109          }
 110          // Author filter
 111          if ($filter_authorid > 0) {
 112              $where[] = 'c.created_by = ' . (int) $filter_authorid;
 113          }
 114          // Content state filter
 115          if ($filter_state) {
 116              if ($filter_state == 'P') {
 117                  $where[] = 'c.state = 1';
 118              } else {
 119                  if ($filter_state == 'U') {
 120                      $where[] = 'c.state = 0';
 121                  } else if ($filter_state == 'A') {
 122                      $where[] = 'c.state = -1';
 123                  } else {
 124                      $where[] = 'c.state != -2';
 125                  }
 126              }
 127          }
 128          // Keyword filter
 129          if ($search) {
 130              $where[] = '(LOWER( c.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ) .
 131                  ' OR c.id = ' . (int) $search . ')';
 132          }
 133  
 134          // Build the where clause of the content record query
 135          $where = (count($where) ? ' WHERE '.implode(' AND ', $where) : '');
 136  
 137          // Get the total number of records
 138          $query = 'SELECT COUNT(*)' .
 139                  ' FROM #__content AS c' .
 140                  ' LEFT JOIN #__categories AS cc ON cc.id = c.catid' .
 141                  ' LEFT JOIN #__sections AS s ON s.id = c.sectionid' .
 142                  $where;
 143          $db->setQuery($query);
 144          $total = $db->loadResult();
 145  
 146  
 147          // Create the pagination object
 148          jimport('joomla.html.pagination');
 149          $pagination = new JPagination($total, $limitstart, $limit);
 150  
 151          // Get the articles
 152          $query = 'SELECT c.*, g.name AS groupname, cc.title AS name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author' .
 153                  ' FROM #__content AS c' .
 154                  ' LEFT JOIN #__categories AS cc ON cc.id = c.catid' .
 155                  ' LEFT JOIN #__sections AS s ON s.id = c.sectionid' .
 156                  ' LEFT JOIN #__groups AS g ON g.id = c.access' .
 157                  ' LEFT JOIN #__users AS u ON u.id = c.checked_out' .
 158                  ' LEFT JOIN #__users AS v ON v.id = c.created_by' .
 159                  ' LEFT JOIN #__content_frontpage AS f ON f.content_id = c.id' .
 160                  $where .
 161                  $order;
 162          $db->setQuery($query, $pagination->limitstart, $pagination->limit);
 163          $rows = $db->loadObjectList();
 164  
 165          // If there is a database query error, throw a HTTP 500 and exit
 166          if ($db->getErrorNum()) {
 167              JError::raiseError( 500, $db->stderr() );
 168              return false;
 169          }
 170  
 171          // get list of categories for dropdown filter
 172          $query = 'SELECT cc.id AS value, cc.title AS text, section' .
 173                  ' FROM #__categories AS cc' .
 174                  ' INNER JOIN #__sections AS s ON s.id = cc.section ' .
 175                  $filter .
 176                  ' ORDER BY s.ordering, cc.ordering';
 177          $lists['catid'] = ContentHelper::filterCategory($query, $catid);
 178  
 179          // get list of sections for dropdown filter
 180          $javascript = 'onchange="document.adminForm.submit();"';
 181          $lists['sectionid'] = JHTML::_('list.section', 'filter_sectionid', $filter_sectionid, $javascript);
 182  
 183          // get list of Authors for dropdown filter
 184          $query = 'SELECT c.created_by, u.name' .
 185                  ' FROM #__content AS c' .
 186                  ' INNER JOIN #__sections AS s ON s.id = c.sectionid' .
 187                  ' LEFT JOIN #__users AS u ON u.id = c.created_by' .
 188                  ' WHERE c.state <> -1' .
 189                  ' AND c.state <> -2' .
 190                  ' GROUP BY u.id' .
 191                  ' ORDER BY u.name, u.id';
 192          $authors[] = JHTML::_('select.option', '0', '- '.JText::_('Select Author').' -', 'created_by', 'name');
 193          $db->setQuery($query);
 194          $authors = array_merge($authors, $db->loadObjectList());
 195          $lists['authorid'] = JHTML::_('select.genericlist',  $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'created_by', 'name', $filter_authorid);
 196  
 197          // state filter
 198          $lists['state'] = JHTML::_('grid.state', $filter_state, 'Published', 'Unpublished', 'Archived');
 199  
 200          // table ordering
 201          $lists['order_Dir']    = $filter_order_Dir;
 202          $lists['order']        = $filter_order;
 203  
 204          // search filter
 205          $lists['search'] = $search;
 206  
 207          ContentView::showContent($rows, $lists, $pagination, $redirect);
 208      }
 209  
 210      /**
 211      * Compiles information to add or edit the record
 212      *
 213      * @param database A database connector object
 214      * @param integer The unique id of the record to edit (0 if new)
 215      * @param integer The id of the content section
 216      */
 217  	function editContent($edit)
 218      {
 219          global $mainframe;
 220  
 221          // Initialize variables
 222          $db                = & JFactory::getDBO();
 223          $user            = & JFactory::getUser();
 224  
 225          $cid            = JRequest::getVar( 'cid', array(0), '', 'array' );
 226          JArrayHelper::toInteger($cid, array(0));
 227          $id                = JRequest::getVar( 'id', $cid[0], '', 'int' );
 228          $option            = JRequest::getCmd( 'option' );
 229          $nullDate        = $db->getNullDate();
 230          $contentSection    = '';
 231          $sectionid        = 0;
 232  
 233          // Create and load the content table row
 234          $row = & JTable::getInstance('content');
 235          if($edit)
 236              $row->load($id);
 237  
 238          if ($id) {
 239              $sectionid = $row->sectionid;
 240              if ($row->state < 0) {
 241                  $mainframe->redirect('index.php?option=com_content', JText::_('You cannot edit an archived item'));
 242              }
 243          }
 244  
 245          // A sectionid of zero means grab from all sections
 246          if ($sectionid == 0) {
 247              $where = ' WHERE section NOT LIKE "%com_%"';
 248          } else {
 249              // Grab from the specific section
 250              $where = ' WHERE section = '. $db->Quote( $sectionid );
 251          }
 252  
 253          /*
 254           * If the item is checked out we cannot edit it... unless it was checked
 255           * out by the current user.
 256           */
 257          if ( JTable::isCheckedOut($user->get ('id'), $row->checked_out ))
 258          {
 259              $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $row->title);
 260              $mainframe->redirect('index.php?option=com_content', $msg);
 261          }
 262  
 263          if ($id)
 264          {
 265              $row->checkout($user->get('id'));
 266  
 267              if (trim($row->images)) {
 268                  $row->images = explode("\n", $row->images);
 269              } else {
 270                  $row->images = array ();
 271              }
 272  
 273              $query = 'SELECT name' .
 274                      ' FROM #__users'.
 275                      ' WHERE id = '. (int) $row->created_by;
 276              $db->setQuery($query);
 277              $row->creator = $db->loadResult();
 278  
 279              // test to reduce unneeded query
 280              if ($row->created_by == $row->modified_by) {
 281                  $row->modifier = $row->creator;
 282              } else {
 283                  $query = 'SELECT name' .
 284                          ' FROM #__users' .
 285                          ' WHERE id = '. (int) $row->modified_by;
 286                  $db->setQuery($query);
 287                  $row->modifier = $db->loadResult();
 288              }
 289  
 290              $query = 'SELECT COUNT(content_id)' .
 291                      ' FROM #__content_frontpage' .
 292                      ' WHERE content_id = '. (int) $row->id;
 293              $db->setQuery($query);
 294              $row->frontpage = $db->loadResult();
 295              if (!$row->frontpage) {
 296                  $row->frontpage = 0;
 297              }
 298          }
 299          else
 300          {
 301              if (!$sectionid && JRequest::getInt('filter_sectionid')) {
 302                  $sectionid =JRequest::getInt('filter_sectionid');
 303              }
 304  
 305              if (JRequest::getInt('catid'))
 306              {
 307                  $row->catid     = JRequest::getInt('catid');
 308                  $category      = & JTable::getInstance('category');
 309                  $category->load($row->catid);
 310                  $sectionid = $category->section;
 311              } else {
 312                  $row->catid = NULL;
 313              }
 314              $createdate =& JFactory::getDate();
 315              $row->sectionid = $sectionid;
 316              $row->version = 0;
 317              $row->state = 1;
 318              $row->ordering = 0;
 319              $row->images = array ();
 320              $row->publish_up = $createdate->toUnix();
 321              $row->publish_down = JText::_('Never');
 322              $row->creator = '';
 323              $row->created = $createdate->toUnix();
 324              $row->modified = $nullDate;
 325              $row->modifier = '';
 326              $row->frontpage = 0;
 327  
 328          }
 329  
 330          $javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\"";
 331  
 332          $query = 'SELECT s.id, s.title' .
 333                  ' FROM #__sections AS s' .
 334                  ' ORDER BY s.ordering';
 335          $db->setQuery($query);
 336  
 337          $sections[] = JHTML::_('select.option', '-1', '- '.JText::_('Select Section').' -', 'id', 'title');
 338          $sections[] = JHTML::_('select.option', '0', JText::_('Uncategorized'), 'id', 'title');
 339          $sections = array_merge($sections, $db->loadObjectList());
 340          $lists['sectionid'] = JHTML::_('select.genericlist',  $sections, 'sectionid', 'class="inputbox" size="1" '.$javascript, 'id', 'title', intval($row->sectionid));
 341  
 342          foreach ($sections as $section)
 343          {
 344              $section_list[] = (int) $section->id;
 345              // get the type name - which is a special category
 346              if ($row->sectionid) {
 347                  if ($section->id == $row->sectionid) {
 348                      $contentSection = $section->title;
 349                  }
 350              } else {
 351                  if ($section->id == $sectionid) {
 352                      $contentSection = $section->title;
 353                  }
 354              }
 355          }
 356  
 357          $sectioncategories = array ();
 358          $sectioncategories[-1] = array ();
 359          $sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
 360          $section_list = implode('\', \'', $section_list);
 361  
 362          $query = 'SELECT id, title, section' .
 363                  ' FROM #__categories' .
 364                  ' WHERE section IN ( \''.$section_list.'\' )' .
 365                  ' ORDER BY ordering';
 366          $db->setQuery($query);
 367          $cat_list = $db->loadObjectList();
 368  
 369          // Uncategorized category mapped to uncategorized section
 370          $uncat = new stdClass();
 371          $uncat->id = 0;
 372          $uncat->title = JText::_('Uncategorized');
 373          $uncat->section = 0;
 374          $cat_list[] = $uncat;
 375          foreach ($sections as $section)
 376          {
 377              $sectioncategories[$section->id] = array ();
 378              $rows2 = array ();
 379              foreach ($cat_list as $cat)
 380              {
 381                  if ($cat->section == $section->id) {
 382                      $rows2[] = $cat;
 383                  }
 384              }
 385              foreach ($rows2 as $row2) {
 386                  $sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title');
 387              }
 388          }
 389          $sectioncategories['-1'][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
 390          $categories = array();
 391          foreach ($cat_list as $cat) {
 392              if($cat->section == $row->sectionid)
 393                  $categories[] = $cat;
 394          }
 395  
 396          $categories[] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
 397          $lists['catid'] = JHTML::_('select.genericlist',  $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($row->catid));
 398  
 399          // build the html select list for ordering
 400          $query = 'SELECT ordering AS value, title AS text' .
 401                  ' FROM #__content' .
 402                  ' WHERE catid = ' . (int) $row->catid .
 403                  ' AND state >= 0' .
 404                  ' ORDER BY ordering';
 405          if($edit)
 406              $lists['ordering'] = JHTML::_('list.specificordering', $row, $id, $query, 1);
 407          else
 408              $lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query, 1);
 409  
 410          // build the html radio buttons for frontpage
 411          $lists['frontpage'] = JHTML::_('select.booleanlist', 'frontpage', '', $row->frontpage);
 412  
 413          // build the html radio buttons for published
 414          $lists['state'] = JHTML::_('select.booleanlist', 'state', '', $row->state);
 415  
 416          /*
 417           * We need to unify the introtext and fulltext fields and have the
 418           * fields separated by the {readmore} tag, so lets do that now.
 419           */
 420          if (JString::strlen($row->fulltext) > 1) {
 421              $row->text = $row->introtext . "<hr id=\"system-readmore\" />" . $row->fulltext;
 422          } else {
 423              $row->text = $row->introtext;
 424          }
 425  
 426          // Create the form
 427          $form = new JParameter('', JPATH_COMPONENT.DS.'models'.DS.'article.xml');
 428  
 429          // Details Group
 430          $active = (intval($row->created_by) ? intval($row->created_by) : $user->get('id'));
 431          $form->set('created_by', $active);
 432          $form->set('access', $row->access);
 433          $form->set('created_by_alias', $row->created_by_alias);
 434  
 435          $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
 436          $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
 437          if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $db->getNullDate()) {
 438              $form->set('publish_down', JText::_('Never'));
 439          } else {
 440              $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
 441          }
 442  
 443          // Advanced Group
 444          $form->loadINI($row->attribs);
 445  
 446          // Metadata Group
 447          $form->set('description', $row->metadesc);
 448          $form->set('keywords', $row->metakey);
 449          $form->loadINI($row->metadata);
 450  
 451          ContentView::editContent($row, $contentSection, $lists, $sectioncategories, $option, $form);
 452      }
 453  
 454      /**
 455      * Saves the article an edit form submit
 456      * @param database A database connector object
 457      */
 458  	function saveContent()
 459      {
 460          global $mainframe;
 461  
 462          // Check for request forgeries
 463          JRequest::checkToken() or jexit( 'Invalid Token' );
 464  
 465          // Initialize variables
 466          $db        = & JFactory::getDBO();
 467          $user        = & JFactory::getUser();
 468          $dispatcher     = & JDispatcher::getInstance();
 469          JPluginHelper::importPlugin('content');
 470  
 471          $details    = JRequest::getVar( 'details', array(), 'post', 'array');
 472          $option        = JRequest::getCmd( 'option' );
 473          $task        = JRequest::getCmd( 'task' );
 474          $sectionid    = JRequest::getVar( 'sectionid', 0, '', 'int' );
 475          $redirect    = JRequest::getVar( 'redirect', $sectionid, 'post', 'int' );
 476          $menu        = JRequest::getVar( 'menu', 'mainmenu', 'post', 'menutype' );
 477          $menuid        = JRequest::getVar( 'menuid', 0, 'post', 'int' );
 478          $nullDate    = $db->getNullDate();
 479  
 480          $row = & JTable::getInstance('content');
 481          if (!$row->bind(JRequest::get('post'))) {
 482              JError::raiseError( 500, $db->stderr() );
 483              return false;
 484          }
 485          $row->bind($details);
 486  
 487          // sanitise id field
 488          $row->id = (int) $row->id;
 489  
 490          $isNew = true;
 491          // Are we saving from an item edit?
 492          if ($row->id) {
 493              $isNew = false;
 494              $datenow =& JFactory::getDate();
 495              $row->modified         = $datenow->toMySQL();
 496              $row->modified_by     = $user->get('id');
 497          }
 498  
 499          $row->created_by     = $row->created_by ? $row->created_by : $user->get('id');
 500  
 501          if ($row->created && strlen(trim( $row->created )) <= 10) {
 502              $row->created     .= ' 00:00:00';
 503          }
 504  
 505          $config =& JFactory::getConfig();
 506          $tzoffset = $config->getValue('config.offset');
 507          $date =& JFactory::getDate($row->created, $tzoffset);
 508          $row->created = $date->toMySQL();
 509  
 510          // Append time if not added to publish date
 511          if (strlen(trim($row->publish_up)) <= 10) {
 512              $row->publish_up .= ' 00:00:00';
 513          }
 514  
 515          $date =& JFactory::getDate($row->publish_up, $tzoffset);
 516          $row->publish_up = $date->toMySQL();
 517  
 518          // Handle never unpublish date
 519          if (trim($row->publish_down) == JText::_('Never') || trim( $row->publish_down ) == '')
 520          {
 521              $row->publish_down = $nullDate;
 522          }
 523          else
 524          {
 525              if (strlen(trim( $row->publish_down )) <= 10) {
 526                  $row->publish_down .= ' 00:00:00';
 527              }
 528              $date =& JFactory::getDate($row->publish_down, $tzoffset);
 529              $row->publish_down = $date->toMySQL();
 530          }
 531  
 532          // Get a state and parameter variables from the request
 533          $row->state    = JRequest::getVar( 'state', 0, '', 'int' );
 534          $params        = JRequest::getVar( 'params', null, 'post', 'array' );
 535  
 536          // Build parameter INI string
 537          if (is_array($params))
 538          {
 539              $txt = array ();
 540              foreach ($params as $k => $v) {
 541                  $txt[] = "$k=$v";
 542              }
 543              $row->attribs = implode("\n", $txt);
 544          }
 545  
 546          // Get metadata string
 547          $metadata = JRequest::getVar( 'meta', null, 'post', 'array');
 548          if (is_array($metadata))
 549          {
 550              $txt = array();
 551              foreach ($metadata as $k => $v) {
 552                  if ($k == 'description') {
 553                      $row->metadesc = $v;
 554                  } elseif ($k == 'keywords') {
 555                      $row->metakey = $v;
 556                  } else {
 557                      $txt[] = "$k=$v";
 558                  }
 559              }
 560              $row->metadata = implode("\n", $txt);
 561          }
 562  
 563          // Prepare the content for saving to the database
 564          ContentHelper::saveContentPrep( $row );
 565  
 566          // Make sure the data is valid
 567          if (!$row->check()) {
 568              JError::raiseError( 500, $db->stderr() );
 569              return false;
 570          }
 571  
 572          // Increment the content version number
 573          $row->version++;
 574  
 575          $result = $dispatcher->trigger('onBeforeContentSave', array(&$row, $isNew));
 576          if(in_array(false, $result, true)) {
 577              JError::raiseError(500, $row->getError());
 578              return false;
 579          }
 580  
 581          // Store the content to the database
 582          if (!$row->store()) {
 583              JError::raiseError( 500, $db->stderr() );
 584              return false;
 585          }
 586  
 587          // Check the article and update item order
 588          $row->checkin();
 589          $row->reorder('catid = '.(int) $row->catid.' AND state >= 0');
 590  
 591          /*
 592           * We need to update frontpage status for the article.
 593           *
 594           * First we include the frontpage table and instantiate an instance of it.
 595           */
 596          require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php');
 597          $fp = new TableFrontPage($db);
 598  
 599          // Is the article viewable on the frontpage?
 600          if (JRequest::getVar( 'frontpage', 0, '', 'int' ))
 601          {
 602              // Is the item already viewable on the frontpage?
 603              if (!$fp->load($row->id))
 604              {
 605                  // Insert the new entry
 606                  $query = 'INSERT INTO #__content_frontpage' .
 607                          ' VALUES ( '. (int) $row->id .', 1 )';
 608                  $db->setQuery($query);
 609                  if (!$db->query())
 610                  {
 611                      JError::raiseError( 500, $db->stderr() );
 612                      return false;
 613                  }
 614                  $fp->ordering = 1;
 615              }
 616          }
 617          else
 618          {
 619              // Delete the item from frontpage if it exists
 620              if (!$fp->delete($row->id)) {
 621                  $msg .= $fp->stderr();
 622              }
 623              $fp->ordering = 0;
 624          }
 625          $fp->reorder();
 626  
 627          $cache = & JFactory::getCache('com_content');
 628          $cache->clean();
 629  
 630          $dispatcher->trigger('onAfterContentSave', array(&$row, $isNew));
 631  
 632          switch ($task)
 633          {
 634              case 'go2menu' :
 635                  $mainframe->redirect('index.php?option=com_menus&menutype=' . $menu);
 636                  break;
 637  
 638              case 'go2menuitem' :
 639                  $mainframe->redirect(
 640                      'index.php?option=com_menus&menutype=' . $menu
 641                      . '&task=edit&id=' . $menuid
 642                  );
 643                  break;
 644  
 645              case 'menulink' :
 646                  ContentHelper::menuLink($redirect, $row->id);
 647                  break;
 648  
 649              case 'resethits' :
 650                  ContentHelper::resetHits($redirect, $row->id);
 651                  break;
 652  
 653              case 'apply' :
 654                  $msg = JText::sprintf('SUCCESSFULLY SAVED CHANGES TO ARTICLE', $row->title);
 655                  $mainframe->redirect('index.php?option=com_content&sectionid='.$redirect.'&task=edit&cid[]='.$row->id, $msg);
 656                  break;
 657  
 658              case 'save' :
 659              default :
 660                  $msg = JText::sprintf('Successfully Saved Article', $row->title);
 661                  $mainframe->redirect('index.php?option=com_content&sectionid='.$redirect, $msg);
 662                  break;
 663          }
 664      }
 665  
 666      /**
 667      * Changes the state of one or more content pages
 668      *
 669      * @param string The name of the category section
 670      * @param integer A unique category id (passed from an edit form)
 671      * @param array An array of unique category id numbers
 672      * @param integer 0 if unpublishing, 1 if publishing
 673      * @param string The name of the current user
 674      */
 675  	function changeContent( $state = 0 )
 676      {
 677          global $mainframe;
 678  
 679          // Check for request forgeries
 680          JRequest::checkToken() or jexit( 'Invalid Token' );
 681  
 682          // Initialize variables
 683          $db        = & JFactory::getDBO();
 684          $user    = & JFactory::getUser();
 685  
 686          $cid    = JRequest::getVar( 'cid', array(), 'post', 'array' );
 687          JArrayHelper::toInteger($cid);
 688          $option    = JRequest::getCmd( 'option' );
 689          $task    = JRequest::getCmd( 'task' );
 690          $rtask    = JRequest::getCmd( 'returntask', '', 'post' );
 691          if ($rtask) {
 692              $rtask = '&task='.$rtask;
 693          }
 694  
 695          if (count($cid) < 1) {
 696              $redirect    = JRequest::getVar( 'redirect', '', 'post', 'int' );
 697              $action        = ($state == 1) ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
 698              $msg        = JText::_('Select an item to') . ' ' . JText::_($action);
 699              $mainframe->redirect('index.php?option='.$option.$rtask.'&sectionid='.$redirect, $msg, 'error');
 700          }
 701  
 702          // Get some variables for the query
 703          $uid    = $user->get('id');
 704          $total    = count($cid);
 705          $cids    = implode(',', $cid);
 706  
 707          $query = 'UPDATE #__content' .
 708                  ' SET state = '. (int) $state .
 709                  ' WHERE id IN ( '. $cids .' ) AND ( checked_out = 0 OR (checked_out = '. (int) $uid .' ) )';
 710          $db->setQuery($query);
 711          if (!$db->query()) {
 712              JError::raiseError( 500, $db->getErrorMsg() );
 713              return false;
 714          }
 715  
 716          if (count($cid) == 1) {
 717              $row = & JTable::getInstance('content');
 718              $row->checkin($cid[0]);
 719          }
 720  
 721          switch ($state)
 722          {
 723              case -1 :
 724                  $msg = JText::sprintf('Item(s) successfully Archived', $total);
 725                  break;
 726  
 727              case 1 :
 728                  $msg = JText::sprintf('Item(s) successfully Published', $total);
 729                  break;
 730  
 731              case 0 :
 732              default :
 733                  if ($task == 'unarchive') {
 734                      $msg = JText::sprintf('Item(s) successfully Unarchived', $total);
 735                  } else {
 736                      $msg = JText::sprintf('Item(s) successfully Unpublished', $total);
 737                  }
 738                  break;
 739          }
 740  
 741          $cache = & JFactory::getCache('com_content');
 742          $cache->clean();
 743  
 744          // Get some return/redirect information from the request
 745          $redirect    = JRequest::getVar( 'redirect', $row->sectionid, 'post', 'int' );
 746  
 747          $mainframe->redirect('index.php?option='.$option.$rtask.'&sectionid='.$redirect, $msg);
 748      }
 749  
 750      /**
 751      * Changes the frontpage state of one or more articles
 752      *
 753      */
 754  	function toggleFrontPage()
 755      {
 756          global $mainframe;
 757  
 758          // Check for request forgeries
 759          JRequest::checkToken() or jexit( 'Invalid Token' );
 760  
 761          // Initialize variables
 762          $db        =& JFactory::getDBO();
 763  
 764          $cid    = JRequest::getVar( 'cid', array(), 'post', 'array' );
 765          $option    = JRequest::getCmd( 'option' );
 766          $msg    = null;
 767  
 768          JArrayHelper::toInteger($cid);
 769  
 770          if (count($cid) < 1) {
 771              $msg = JText::_('Select an item to toggle');
 772              $mainframe->redirect('index.php?option='.$option, $msg, 'error');
 773          }
 774  
 775          /*
 776           * We need to update frontpage status for the articles.
 777           *
 778           * First we include the frontpage table and instantiate an instance of
 779           * it.
 780           */
 781          require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php');
 782          $fp = new TableFrontPage($db);
 783  
 784          foreach ($cid as $id)
 785          {
 786              // toggles go to first place
 787              if ($fp->load($id)) {
 788                  if (!$fp->delete($id)) {
 789                      $msg .= $fp->stderr();
 790                  }
 791                  $fp->ordering = 0;
 792              } else {
 793                  // new entry
 794                  $query = 'INSERT INTO #__content_frontpage' .
 795                          ' VALUES ( '. (int) $id .', 0 )';
 796                  $db->setQuery($query);
 797                  if (!$db->query()) {
 798                      JError::raiseError( 500, $db->stderr() );
 799                      return false;
 800                  }
 801                  $fp->ordering = 0;
 802              }
 803              $fp->reorder();
 804          }
 805  
 806          $cache = & JFactory::getCache('com_content');
 807          $cache->clean();
 808  
 809          $mainframe->redirect('index.php?option='.$option, $msg);
 810      }
 811  
 812  	function removeContent()
 813      {
 814          global $mainframe;
 815  
 816          // Check for request forgeries
 817          JRequest::checkToken() or jexit( 'Invalid Token' );
 818  
 819          // Initialize variables
 820          $db            = & JFactory::getDBO();
 821  
 822          $cid        = JRequest::getVar( 'cid', array(), 'post', 'array' );
 823          $option        = JRequest::getCmd( 'option' );
 824          $return        = JRequest::getCmd( 'returntask', '', 'post' );
 825          $nullDate    = $db->getNullDate();
 826  
 827          JArrayHelper::toInteger($cid);
 828  
 829          if (count($cid) < 1) {
 830              $msg =  JText::_('Select an item to delete');
 831              $mainframe->redirect('index.php?option='.$option, $msg, 'error');
 832          }
 833  
 834          // Removed content gets put in the trash [state = -2] and ordering is always set to 0
 835          $state        = '-2';
 836          $ordering    = '0';
 837  
 838          // Get the list of content id numbers to send to trash.
 839          $cids = implode(',', $cid);
 840  
 841          // Update articles in the database
 842          $query = 'UPDATE #__content' .
 843                  ' SET state = '.(int) $state .
 844                  ', ordering = '.(int) $ordering .
 845                  ', checked_out = 0, checked_out_time = '.$db->Quote($nullDate).
 846                  ' WHERE id IN ( '. $cids. ' )';
 847          $db->setQuery($query);
 848          if (!$db->query())
 849          {
 850              JError::raiseError( 500, $db->getErrorMsg() );
 851              return false;
 852          }
 853  
 854          $cache = & JFactory::getCache('com_content');
 855          $cache->clean();
 856  
 857          $msg = JText::sprintf('Item(s) sent to the Trash', count($cid));
 858          $mainframe->redirect('index.php?option='.$option.'&task='.$return, $msg);
 859      }
 860  
 861      /**
 862      * Cancels an edit operation
 863      */
 864  	function cancelContent()
 865      {
 866          global $mainframe;
 867  
 868          // Check for request forgeries
 869          JRequest::checkToken() or jexit( 'Invalid Token' );
 870  
 871          // Initialize variables
 872          $db    = & JFactory::getDBO();
 873  
 874          // Check the article in if checked out
 875          $row = & JTable::getInstance('content');
 876          $row->bind(JRequest::get('post'));
 877          $row->checkin();
 878  
 879          $mainframe->redirect('index.php?option=com_content');
 880      }
 881  
 882      /**
 883      * Moves the order of a record
 884      * @param integer The increment to reorder by
 885      */
 886  	function orderContent($direction)
 887      {
 888          global $mainframe;
 889  
 890          // Check for request forgeries
 891          JRequest::checkToken() or jexit( 'Invalid Token' );
 892  
 893          // Initialize variables
 894          $db        = & JFactory::getDBO();
 895  
 896          $cid    = JRequest::getVar( 'cid', array(), 'post', 'array' );
 897  
 898          if (isset( $cid[0] ))
 899          {
 900              $row = & JTable::getInstance('content');
 901              $row->load( (int) $cid[0] );
 902              $row->move($direction, 'catid = ' . (int) $row->catid . ' AND state >= 0' );
 903  
 904              $cache = & JFactory::getCache('com_content');
 905              $cache->clean();
 906          }
 907  
 908          $mainframe->redirect('index.php?option=com_content');
 909      }
 910  
 911      /**
 912      * Form for moving item(s) to a different section and category
 913      */
 914  	function moveSection()
 915      {
 916          // Check for request forgeries
 917          JRequest::checkToken() or jexit( 'Invalid Token' );
 918  
 919          // Initialize variables
 920          $db            =& JFactory::getDBO();
 921  
 922          $cid        = JRequest::getVar( 'cid', array(), 'post', 'array' );
 923          $sectionid    = JRequest::getVar( 'sectionid', 0, '', 'int' );
 924  
 925          JArrayHelper::toInteger($cid);
 926  
 927          if (count($cid) < 1) {
 928              $msg = JText::_('Select an item to move');
 929              $mainframe->redirect('index.php?option=com_content', $msg, 'error');
 930          }
 931  
 932          //seperate contentids
 933          $cids = implode(',', $cid);
 934          // Articles query
 935          $query = 'SELECT a.title' .
 936                  ' FROM #__content AS a' .
 937                  ' WHERE ( a.id IN ( '. $cids .' ) )' .
 938                  ' ORDER BY a.title';
 939          $db->setQuery($query);
 940          $items = $db->loadObjectList();
 941  
 942          $query = 'SELECT CONCAT_WS( ", ", s.id, c.id ) AS `value`, CONCAT_WS( " / ", s.title, c.title ) AS `text`' .
 943                  ' FROM #__sections AS s' .
 944                  ' INNER JOIN #__categories AS c ON c.section = s.id' .
 945                  ' WHERE s.scope = "content"' .
 946                  ' ORDER BY s.title, c.title';
 947          $db->setQuery($query);
 948          $rows[] = JHTML::_('select.option', "0, 0", JText::_('UNCATEGORIZED'));
 949          $rows = array_merge($rows, $db->loadObjectList());
 950          // build the html select list
 951          $sectCatList = JHTML::_('select.genericlist',  $rows, 'sectcat', 'class="inputbox" size="8"', 'value', 'text', null);
 952  
 953          ContentView::moveSection($cid, $sectCatList, 'com_content', $sectionid, $items);
 954      }
 955  
 956      /**
 957      * Save the changes to move item(s) to a different section and category
 958      */
 959  	function moveSectionSave()
 960      {
 961          global $mainframe;
 962  
 963          // Check for request forgeries
 964          JRequest::checkToken() or jexit( 'Invalid Token' );
 965  
 966          // Initialize variables
 967          $db            = & JFactory::getDBO();
 968          $user        = & JFactory::getUser();
 969  
 970          $cid        = JRequest::getVar( 'cid', array(0), 'post', 'array' );
 971          $sectionid    = JRequest::getVar( 'sectionid', 0, '', 'int' );
 972          $option        = JRequest::getCmd( 'option' );
 973  
 974          JArrayHelper::toInteger($cid, array(0));
 975  
 976          $sectcat = JRequest::getVar( 'sectcat', '', 'post', 'string' );
 977          $sectcat = explode(',', $sectcat);
 978          $newsect = (int) @$sectcat[0];
 979          $newcat = (int) @$sectcat[1];
 980  
 981          if ((!$newsect || !$newcat) && ($sectcat !== array('0', ' 0'))) {
 982              $mainframe->redirect("index.php?option=com_content&sectionid=$sectionid", JText::_('An error has occurred'));
 983          }
 984  
 985          // find section name
 986          $query = 'SELECT a.title' .
 987                  ' FROM #__sections AS a' .
 988                  ' WHERE a.id = '. (int) $newsect;
 989          $db->setQuery($query);
 990          $section = $db->loadResult();
 991  
 992          // find category name
 993          $query = 'SELECT a.title' .
 994                  ' FROM #__categories AS a' .
 995                  ' WHERE a.id = '. (int) $newcat;
 996          $db->setQuery($query);
 997          $category = $db->loadResult();
 998  
 999          $total    = count($cid);
1000          $cids        = implode(',', $cid);
1001          $uid        = $user->get('id');
1002  
1003          $row = & JTable::getInstance('content');
1004          // update old orders - put existing items in last place
1005          foreach ($cid as $id)
1006          {
1007              $row->load(intval($id));
1008              $row->ordering = 0;
1009              $row->store();
1010              $row->reorder('catid = '.(int) $row->catid.' AND state >= 0');
1011          }
1012  
1013          $query = 'UPDATE #__content SET sectionid = '.(int) $newsect.', catid = '.(int) $newcat.
1014                  ' WHERE id IN ( '.$cids.' )' .
1015                  ' AND ( checked_out = 0 OR ( checked_out = '.(int) $uid.' ) )';
1016          $db->setQuery($query);
1017          if (!$db->query())
1018          {
1019              JError::raiseError( 500, $db->getErrorMsg() );
1020              return false;
1021          }
1022  
1023          // update new orders - put items in last place
1024          foreach ($cid as $id)
1025          {
1026              $row->load(intval($id));
1027              $row->ordering = 0;
1028              $row->store();
1029              $row->reorder('catid = '.(int) $row->catid.' AND state >= 0');
1030          }
1031  
1032          if ($section && $category) {
1033              $msg = JText::sprintf('Item(s) successfully moved to Section', $total, $section, $category);
1034          } else {
1035              $msg = JText::sprintf('ITEM(S) SUCCESSFULLY MOVED TO UNCATEGORIZED', $total);
1036          }
1037  
1038          $mainframe->redirect('index.php?option='.$option.'&sectionid='.$sectionid, $msg);
1039      }
1040  
1041      /**
1042      * Form for copying item(s)
1043      **/
1044  	function copyItem()
1045      {
1046          // Check for request forgeries
1047          JRequest::checkToken() or jexit( 'Invalid Token' );
1048  
1049          // Initialize variables
1050          $db            = & JFactory::getDBO();
1051  
1052          $cid        = JRequest::getVar( 'cid', array(), 'post', 'array' );
1053          $sectionid    = JRequest::getVar( 'sectionid', 0, '', 'int' );
1054          $option        = JRequest::getCmd( 'option' );
1055  
1056          JArrayHelper::toInteger($cid);
1057  
1058          if (count($cid) < 1) {
1059              $msg = JText::_('Select an item to move');
1060              $mainframe->redirect('index.php?option='.$option, $msg, 'error');
1061          }
1062  
1063          //seperate contentids
1064          $cids = implode(',', $cid);
1065          ## Articles query
1066          $query = 'SELECT a.title' .
1067                  ' FROM #__content AS a' .
1068                  ' WHERE ( a.id IN ( '. $cids .' ) )' .
1069                  ' ORDER BY a.title';
1070          $db->setQuery($query);
1071          $items = $db->loadObjectList();
1072  
1073          ## Section & Category query
1074          $query = 'SELECT CONCAT_WS(",",s.id,c.id) AS `value`, CONCAT_WS(" / ", s.title, c.title) AS `text`' .
1075                  ' FROM #__sections AS s' .
1076                  ' INNER JOIN #__categories AS c ON c.section = s.id' .
1077                  ' WHERE s.scope = "content"' .
1078                  ' ORDER BY s.title, c.title';
1079          $db->setQuery($query);
1080  
1081          // Add a row for uncategorized content
1082          $uncat    = JHTML::_('select.option', '0,0', JText::_('UNCATEGORIZED'));
1083          $rows    = $db->loadObjectList();
1084          array_unshift($rows, $uncat);
1085          // build the html select list
1086          $sectCatList = JHTML::_('select.genericlist', $rows, 'sectcat', 'class="inputbox" size="10"', 'value', 'text', NULL);
1087  
1088          ContentView::copySection($option, $cid, $sectCatList, $sectionid, $items);
1089      }
1090  
1091      /**
1092      * saves Copies of items
1093      **/
1094  	function copyItemSave()
1095      {
1096          global $mainframe;
1097  
1098          // Check for request forgeries
1099          JRequest::checkToken() or jexit( 'Invalid Token' );
1100  
1101          // Initialize variables
1102          $db            = & JFactory::getDBO();
1103  
1104          $cid        = JRequest::getVar( 'cid', array(), 'post', 'array' );
1105          $sectionid    = JRequest::getVar( 'sectionid', 0, '', 'int' );
1106          $option        = JRequest::getCmd( 'option' );
1107  
1108          JArrayHelper::toInteger($cid);
1109  
1110          $item    = null;
1111          $sectcat = JRequest::getVar( 'sectcat', '-1,-1', 'post', 'string' );
1112          //seperate sections and categories from selection
1113          $sectcat = explode(',', $sectcat);
1114          $newsect = (int) @$sectcat[0];
1115          $newcat = (int) @$sectcat[1];
1116  
1117          if (($newsect == -1) || ($newcat == -1)) {
1118              $mainframe->redirect('index.php?option=com_content&sectionid='.$sectionid, JText::_('An error has occurred'));
1119          }
1120  
1121          // find section name
1122          $query = 'SELECT a.title' .
1123                  ' FROM #__sections AS a' .
1124                  ' WHERE a.id = '. (int) $newsect;
1125          $db->setQuery($query);
1126          $section = $db->loadResult();
1127  
1128          // find category name
1129          $query = 'SELECT a.title' .
1130                  ' FROM #__categories AS a' .
1131                  ' WHERE a.id = '. (int) $newcat;
1132          $db->setQuery($query);
1133          $category = $db->loadResult();
1134  
1135          if (($newsect == 0) && ($newcat == 0))
1136          {
1137              $section    = JText::_('UNCATEGORIZED');
1138              $category    = JText::_('UNCATEGORIZED');
1139          }
1140  
1141          $total = count($cid);
1142          for ($i = 0; $i < $total; $i ++)
1143          {
1144              $row = & JTable::getInstance('content');
1145  
1146              // main query
1147              $query = 'SELECT a.*' .
1148                      ' FROM #__content AS a' .
1149                      ' WHERE a.id = '.(int) $cid[$i];
1150              $db->setQuery($query, 0, 1);
1151              $item = $db->loadObject();
1152  
1153              // values loaded into array set for store
1154              $row->id                        = NULL;
1155              $row->sectionid                    = $newsect;
1156              $row->catid                        = $newcat;
1157              $row->hits                        = '0';
1158              $row->ordering                    = '0';
1159              $row->title                        = $item->title;
1160              $row->alias                        = $item->alias;
1161              $row->title_alias                = $item->title_alias;
1162              $row->introtext                    = $item->introtext;
1163              $row->fulltext                    = $item->fulltext;
1164              $row->state                        = $item->state;
1165              $row->mask                        = $item->mask;
1166              $row->created                    = $item->created;
1167              $row->created_by                = $item->created_by;
1168              $row->created_by_alias            = $item->created_by_alias;
1169              $row->modified                    = $item->modified;
1170              $row->modified_by                = $item->modified_by;
1171              $row->checked_out                = $item->checked_out;
1172              $row->checked_out_time            = $item->checked_out_time;
1173              $row->publish_up                = $item->publish_up;
1174              $row->publish_down                = $item->publish_down;
1175              $row->images                    = $item->images;
1176              $row->attribs                    = $item->attribs;
1177              $row->version                    = $item->parentid;
1178              $row->parentid                    = $item->parentid;
1179              $row->metakey                    = $item->metakey;
1180              $row->metadesc                    = $item->metadesc;
1181              $row->access                    = $item->access;
1182              $row->metadata                    = $item->metadata;
1183  
1184              if (!$row->check()) {
1185                  JError::raiseError( 500, $row->getError() );
1186                  return false;
1187              }
1188  
1189              if (!$row->store()) {
1190                  JError::raiseError( 500, $row->getError() );
1191                  return false;
1192              }
1193              $row->reorder('catid='.(int) $row->catid.' AND state >= 0');
1194          }
1195  
1196          $msg = JText::sprintf('Item(s) successfully copied to Section', $total, $section, $category);
1197          $mainframe->redirect('index.php?option='.$option.'&sectionid='.$sectionid, $msg);
1198      }
1199  
1200      /**
1201      * @param integer The id of the article
1202      * @param integer The new access level
1203      * @param string The URL option
1204      */
1205  	function accessMenu($access)
1206      {
1207          global $mainframe;
1208  
1209          // Check for request forgeries
1210          JRequest::checkToken() or jexit( 'Invalid Token' );
1211  
1212          // Initialize variables
1213          $db        = & JFactory::getDBO();
1214  
1215          $cid    = JRequest::getVar( 'cid', array(0), 'post', 'array' );
1216          $option    = JRequest::getCmd( 'option' );
1217          $cid    = $cid[0];
1218  
1219          // Create and load the article table object
1220          $row = & JTable::getInstance('content');
1221          $row->load($cid);
1222          $row->access = $access;
1223  
1224          // Ensure the article object is valid
1225          if (!$row->check()) {
1226              JError::raiseError( 500, $row->getError() );
1227              return false;
1228          }
1229  
1230          // Store the changes
1231          if (!$row->store()) {
1232              JError::raiseError( 500, $row->getError() );
1233              return false;
1234          }
1235  
1236          $cache = & JFactory::getCache('com_content');
1237          $cache->clean();
1238  
1239          $mainframe->redirect('index.php?option='.$option);
1240      }
1241  
1242  	function saveOrder()
1243      {
1244          global $mainframe;
1245  
1246          // Check for request forgeries
1247          JRequest::checkToken() or jexit( 'Invalid Token' );
1248  
1249          // Initialize variables
1250          $db            = & JFactory::getDBO();
1251  
1252          $cid        = JRequest::getVar( 'cid', array(0), 'post', 'array' );
1253          $order        = JRequest::getVar( 'order', array (0), 'post', 'array' );
1254          $redirect    = JRequest::getVar( 'redirect', 0, 'post', 'int' );
1255          $rettask    = JRequest::getVar( 'returntask', '', 'post', 'cmd' );
1256          $total        = count($cid);
1257          $conditions    = array ();
1258  
1259          JArrayHelper::toInteger($cid, array(0));
1260          JArrayHelper::toInteger($order, array(0));
1261  
1262          // Instantiate an article table object
1263          $row = & JTable::getInstance('content');
1264  
1265          // Update the ordering for items in the cid array
1266          for ($i = 0; $i < $total; $i ++)
1267          {
1268              $row->load( (int) $cid[$i] );
1269              if ($row->ordering != $order[$i]) {
1270                  $row->ordering = $order[$i];
1271                  if (!$row->store()) {
1272                      JError::raiseError( 500, $db->getErrorMsg() );
1273                      return false;
1274                  }
1275                  // remember to updateOrder this group
1276                  $condition = 'catid = '.(int) $row->catid.' AND state >= 0';
1277                  $found = false;
1278                  foreach ($conditions as $cond)
1279                      if ($cond[1] == $condition) {
1280                          $found = true;
1281                          break;
1282                      }
1283                  if (!$found)
1284                      $conditions[] = array ($row->id, $condition);
1285              }
1286          }
1287  
1288          // execute updateOrder for each group
1289          foreach ($conditions as $cond)
1290          {
1291              $row->load($cond[0]);
1292              $row->reorder($cond[1]);
1293          }
1294  
1295          $cache = & JFactory::getCache('com_content');
1296          $cache->clean();
1297  
1298          $msg = JText::_('New ordering saved');
1299          switch ($rettask)
1300          {
1301              case 'showarchive' :
1302                  $mainframe->redirect('index.php?option=com_content&task=showarchive&sectionid='.$redirect, $msg);
1303                  break;
1304  
1305              default :
1306                  $mainframe->redirect('index.php?option=com_content&sectionid='.$redirect, $msg);
1307                  break;
1308          }
1309      }
1310  
1311  	function previewContent()
1312      {
1313          // Initialize variables
1314          $document        =& JFactory::getDocument();
1315          $db             =& JFactory::getDBO();
1316          $id                = JRequest::getVar( 'id', 0, '', 'int' );
1317          $option            = JRequest::getCmd( 'option' );
1318  
1319          // Get the current default template
1320          $query = 'SELECT template' .
1321                  ' FROM #__templates_menu' .
1322                  ' WHERE client_id = 0' .
1323                  ' AND menuid = 0';
1324          $db->setQuery($query);
1325          $template = $db->loadResult();
1326  
1327          // check if template editor stylesheet exists
1328          if (!file_exists( JPATH_SITE.DS.'templates'.DS.$template.DS.'css'.DS.'editor.css' )) {
1329              $template = 'system';
1330          }
1331  
1332          // Set page title
1333          $document->setTitle(JText::_('Article Preview'));
1334          $document->addStyleSheet(JURI::root() . 'templates/'.$template.'/css/editor.css');
1335          $document->setBase(JUri::root());
1336  
1337          // Render article preview
1338          ContentView::previewContent();
1339      }
1340  
1341  	function insertPagebreak()
1342      {
1343          $document =& JFactory::getDocument();
1344          $document->setTitle(JText::_('PGB ARTICLE PAGEBRK'));
1345          ContentView::insertPagebreak();
1346      }
1347  }


Generated: Mon Nov 14 16:47:20 2011 Cross-referenced by PHPXref 0.7.1