PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_content/controller.php

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