?? controller.php
字號:
// Uncategorized category mapped to uncategorized section $uncat = new stdClass(); $uncat->id = 0; $uncat->title = JText::_('Uncategorized'); $uncat->section = 0; $cat_list[] = $uncat; foreach ($sections as $section) { $sectioncategories[$section->id] = array (); $rows2 = array (); foreach ($cat_list as $cat) { if ($cat->section == $section->id) { $rows2[] = $cat; } } foreach ($rows2 as $row2) { $sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title'); } } $sectioncategories['-1'][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title'); $categories = array(); foreach ($cat_list as $cat) { if($cat->section == $row->sectionid) $categories[] = $cat; } $categories[] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title'); $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($row->catid)); // build the html select list for ordering $query = 'SELECT ordering AS value, title AS text' . ' FROM #__content' . ' WHERE catid = ' . (int) $row->catid . ' AND state >= 0' . ' ORDER BY ordering'; if($edit) $lists['ordering'] = JHTML::_('list.specificordering', $row, $id, $query, 1); else $lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query, 1); // build the html radio buttons for frontpage $lists['frontpage'] = JHTML::_('select.booleanlist', 'frontpage', '', $row->frontpage); // build the html radio buttons for published $lists['state'] = JHTML::_('select.booleanlist', 'state', '', $row->state); /* * We need to unify the introtext and fulltext fields and have the * fields separated by the {readmore} tag, so lets do that now. */ if (JString::strlen($row->fulltext) > 1) { $row->text = $row->introtext . "<hr id=\"system-readmore\" />" . $row->fulltext; } else { $row->text = $row->introtext; } // Create the form $form = new JParameter('', JPATH_COMPONENT.DS.'models'.DS.'article.xml'); // Details Group $active = (intval($row->created_by) ? intval($row->created_by) : $user->get('id')); $form->set('created_by', $active); $form->set('access', $row->access); $form->set('created_by_alias', $row->created_by_alias); $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S')); $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S')); if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $db->getNullDate()) { $form->set('publish_down', JText::_('Never')); } else { $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S')); } // Advanced Group $form->loadINI($row->attribs); // Metadata Group $form->set('description', $row->metadesc); $form->set('keywords', $row->metakey); $form->loadINI($row->metadata); ContentView::editContent($row, $contentSection, $lists, $sectioncategories, $option, $form); } /** * Saves the article an edit form submit * @param database A database connector object */ function saveContent() { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db = & JFactory::getDBO(); $user = & JFactory::getUser(); $dispatcher = & JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $details = JRequest::getVar( 'details', array(), 'post', 'array'); $option = JRequest::getCmd( 'option' ); $task = JRequest::getCmd( 'task' ); $sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' ); $redirect = JRequest::getVar( 'redirect', $sectionid, 'post', 'int' ); $menu = JRequest::getVar( 'menu', 'mainmenu', 'post', 'cmd' ); $menuid = JRequest::getVar( 'menuid', 0, 'post', 'int' ); $nullDate = $db->getNullDate(); $row = & JTable::getInstance('content'); if (!$row->bind(JRequest::get('post'))) { JError::raiseError( 500, $db->stderr() ); return false; } $row->bind($details); // sanitise id field $row->id = (int) $row->id; $isNew = true; // Are we saving from an item edit? if ($row->id) { $isNew = false; $datenow =& JFactory::getDate(); $row->modified = $datenow->toMySQL(); $row->modified_by = $user->get('id'); } $row->created_by = $row->created_by ? $row->created_by : $user->get('id'); if ($row->created && strlen(trim( $row->created )) <= 10) { $row->created .= ' 00:00:00'; } $config =& JFactory::getConfig(); $tzoffset = $config->getValue('config.offset'); $date =& JFactory::getDate($row->created, $tzoffset); $row->created = $date->toMySQL(); // Append time if not added to publish date if (strlen(trim($row->publish_up)) <= 10) { $row->publish_up .= ' 00:00:00'; } $date =& JFactory::getDate($row->publish_up, $tzoffset); $row->publish_up = $date->toMySQL(); // Handle never unpublish date if (trim($row->publish_down) == JText::_('Never') || trim( $row->publish_down ) == '') { $row->publish_down = $nullDate; } else { if (strlen(trim( $row->publish_down )) <= 10) { $row->publish_down .= ' 00:00:00'; } $date =& JFactory::getDate($row->publish_down, $tzoffset); $row->publish_down = $date->toMySQL(); } // Get a state and parameter variables from the request $row->state = JRequest::getVar( 'state', 0, '', 'int' ); $params = JRequest::getVar( 'params', null, 'post', 'array' ); // Build parameter INI string if (is_array($params)) { $txt = array (); foreach ($params as $k => $v) { $txt[] = "$k=$v"; } $row->attribs = implode("\n", $txt); } // Get metadata string $metadata = JRequest::getVar( 'meta', null, 'post', 'array'); if (is_array($metadata)) { $txt = array(); foreach ($metadata as $k => $v) { if ($k == 'description') { $row->metadesc = $v; } elseif ($k == 'keywords') { $row->metakey = $v; } else { $txt[] = "$k=$v"; } } $row->metadata = implode("\n", $txt); } // Prepare the content for saving to the database ContentHelper::saveContentPrep( $row ); // Make sure the data is valid if (!$row->check()) { JError::raiseError( 500, $db->stderr() ); return false; } // Increment the content version number $row->version++; $result = $dispatcher->trigger('onBeforeContentSave', array(&$row, $isNew)); if(in_array(false, $result, true)) { JError::raiseError(500, $row->getError()); return false; } // Store the content to the database if (!$row->store()) { JError::raiseError( 500, $db->stderr() ); return false; } // Check the article and update item order $row->checkin(); $row->reorder('catid = '.(int) $row->catid.' AND state >= 0'); /* * We need to update frontpage status for the article. * * First we include the frontpage table and instantiate an instance of it. */ require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php'); $fp = new TableFrontPage($db); // Is the article viewable on the frontpage? if (JRequest::getVar( 'frontpage', 0, '', 'int' )) { // Is the item already viewable on the frontpage? if (!$fp->load($row->id)) { // Insert the new entry $query = 'INSERT INTO #__content_frontpage' . ' VALUES ( '. (int) $row->id .', 1 )'; $db->setQuery($query); if (!$db->query()) { JError::raiseError( 500, $db->stderr() ); return false; } $fp->ordering = 1; } } else { // Delete the item from frontpage if it exists if (!$fp->delete($row->id)) { $msg .= $fp->stderr(); } $fp->ordering = 0; } $fp->reorder(); $cache = & JFactory::getCache('com_content'); $cache->clean(); $dispatcher->trigger('onAfterContentSave', array(&$row, $isNew)); switch ($task) { case 'go2menu' : $mainframe->redirect('index.php?option=com_menus&menutype='.$menu); break; case 'go2menuitem' : $mainframe->redirect('index.php?option=com_menus&menutype='.$menu.'&task=edit&id='.$menuid); break; case 'menulink' : ContentHelper::menuLink($redirect, $row->id); break; case 'resethits' : ContentHelper::resetHits($redirect, $row->id); break; case 'apply' : $msg = JText::sprintf('SUCCESSFULLY SAVED CHANGES TO ARTICLE', $row->title); $mainframe->redirect('index.php?option=com_content§ionid='.$redirect.'&task=edit&cid[]='.$row->id, $msg); break; case 'save' : default : $msg = JText::sprintf('Successfully Saved Article', $row->title); $mainframe->redirect('index.php?option=com_content§ionid='.$redirect, $msg); break; } } /** * Changes the state of one or more content pages * * @param string The name of the category section * @param integer A unique category id (passed from an edit form) * @param array An array of unique category id numbers * @param integer 0 if unpublishing, 1 if publishing * @param string The name of the current user */ function changeContent( $state = 0 ) { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db = & JFactory::getDBO(); $user = & JFactory::getUser(); $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); JArrayHelper::toInteger($cid); $option = JRequest::getCmd( 'option' ); $task = JRequest::getCmd( 'task' ); $rtask = JRequest::getCmd( 'returntask', '', 'post' ); if ($rtask) { $rtask = '&task='.$rtask; } if (count($cid) < 1) { $redirect = JRequest::getVar( 'redirect', '', 'post', 'int' ); $action = ($state == 1) ? 'publish' : ($state == -1 ? 'archive' : 'unpublish'); $msg = JText::_('Select an item to') . ' ' . JText::_($action); $mainframe->redirect('index.php?option='.$option.$rtask.'§ionid='.$redirect, $msg, 'error'); } // Get some variables for the query $uid = $user->get('id'); $total = count($cid); $cids = implode(',', $cid); $query = 'UPDATE #__content' . ' SET state = '. (int) $state . ' WHERE id IN ( '. $cids .' ) AND ( checked_out = 0 OR (checked_out = '. (int) $uid .' ) )'; $db->setQuery($query); if (!$db->query()) { JError::raiseError( 500, $db->getErrorMsg() ); return false; } if (count($cid) == 1) { $row = & JTable::getInstance('content'); $row->checkin($cid[0]); } switch ($state) { case -1 : $msg = JText::sprintf('Item(s) successfully Archived', $total); break; case 1 : $msg = JText::sprintf('Item(s) successfully Published', $total); break; case 0 : default : if ($task == 'unarchive') { $msg = JText::sprintf('Item(s) successfully Unarchived', $total); } else { $msg = JText::sprintf('Item(s) successfully Unpublished', $total); } break; } $cache = & JFactory::getCache('com_content'); $cache->clean(); // Get some return/redirect information from the request $redirect = JRequest::getVar( 'redirect', $row->sectionid, 'post', 'int' ); $mainframe->redirect('index.php?option='.$option.$rtask.'§ionid='.$redirect, $msg); } /** * Changes the frontpage state of one or more articles * */ function toggleFrontPage() { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); $option = JRequest::getCmd( 'option' ); $msg = null; JArrayHelper::toInteger($cid); if (count($cid) < 1) { $msg = JText::_('Select an item to toggle'); $mainframe->redirect('index.php?option='.$option, $msg, 'error'); } /* * We need to update frontpage status for the articles. * * First we include the frontpage table and instantiate an instance of * it. */ require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php'); $fp = new TableFrontPage($db); foreach ($cid as $id) { // toggles go to first place if ($fp->load($id)) { if (!$fp->delete($id)) { $msg .= $fp->stderr(); } $fp->ordering = 0; } else { // new entry $query = 'INSERT INTO #__content_frontpage' . ' VALUES ( '. (int) $id .', 0 )'; $db->setQuery($query); if (!$db->query()) { JError::raiseError( 500, $db->stderr() ); return false; } $fp->ordering = 0; } $fp->reorder(); } $cache = & JFactory::getCache('com_content'); $cache->clean(); $mainframe->redirect('index.php?option='.$option, $msg); } function removeContent() { global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db = & JFactory::getDBO(); $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); $option = JRequest::getCmd( 'option' ); $return = JRequest::getCmd( 'returntask', '', 'post' ); $nullDate = $db->getNullDate(); JArrayHelper::toInteger($cid); if (count($cid) < 1) { $msg = JText::_('Select an item to delete'); $mainframe->redirect('index.php?option='.$option, $msg, 'error'); } // Removed content gets put in the trash [state = -2] and ordering is always set to 0 $state = '-2'; $ordering = '0'; // Get the list of content id numbers to send to trash. $cids = implode(',', $cid); // Update articles in the database $query = 'UPDATE #__content' . ' SET state = '.(int) $state . ', ordering = '.(int) $ordering . ', checked_out = 0, checked_out_time = '.$db->Quote($nullDate). ' WHERE id IN ( '. $cids. ' )'; $db->setQuery($query); if (!$db->query()) { JError::raiseError( 500, $db->getErrorMsg() ); return false; } $cache = & JFactory::getCache('com_content'); $cache->clean(); $msg = JText::sprintf('Item(s) sent to the Trash', count($cid)); $mainframe->redirect('index.php?option='.$option.'&task='.$return, $msg); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -