コード例 #1
0
ファイル: article.php プロジェクト: juliano-hallac/fabrik
 function saveArticle()
 {
     // Initialize variables
     $db =& FabrikWorker::getDbo();
     $user =& JFactory::getUser();
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     $this->_postFabrikDataAsArticleData();
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $option = JRequest::getCmd('option');
     $sectionid = JRequest::getVar('sectionid', 0, '', 'int');
     $nullDate = $db->getNullDate();
     $row =& FabTable::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;
     $this->_isNew = true;
     // Are we saving from an item edit?
     if ($row->id) {
         $this->_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
     // should probably punt this logic into the controller, but for now ...
     $articlePublishElementName = $this->_elementBaseName($this->_articlePublishElement);
     $row->state = $this->_formModel->_formData[$articlePublishElementName];
     // probably an array, i.e. coming from a yes/no radio or dropdown
     if (is_array($row->state)) {
         $row->state = $row->state[0];
     }
     $params = JRequest::getVar('params', null, 'post', 'array');
     $row->params = json_encode($params);
     // 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, $this->_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;
     }
     $this->_articleId = $row->id;
     // 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, $this->_isNew));
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
ファイル: controller.php プロジェクト: KIZI/sewebar-cms
 /**
  * Saves the content item an edit form submit
  *
  * @todo
  */
 function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // Initialize variables
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $task = JRequest::getVar('task', null, 'default', 'cmd');
     // Make sure you are logged in and have the necessary access rights
     if ($user->get('gid') < 19) {
         JError::raiseError(403, JText::_('ALERTNOTAUTH'));
         return;
     }
     // Create a user access object for the user
     $access = new stdClass();
     $access->canEdit = $user->authorize('com_content', 'edit', 'content', 'all');
     $access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');
     $access->canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
     if (!($access->canEdit || $access->canEditOwn)) {
         JError::raiseError(403, JText::_("ALERTNOTAUTH"));
     }
     //get data from the request
     $model = $this->getModel('article');
     //get data from request
     $post = JRequest::get('post');
     $post['text'] = JRequest::getVar('text', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //preform access checks
     $isNew = (int) $post['id'] < 1;
     if ($model->store($post)) {
         $msg = JText::_('Article Saved');
         if ($isNew) {
             $post['id'] = (int) $model->get('id');
         }
     } else {
         $msg = JText::_('Error Saving Article');
         JError::raiseError(500, $model->getError());
     }
     // manage frontpage items
     //TODO : Move this into a frontpage model
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_frontpage' . DS . 'tables' . DS . 'frontpage.php';
     $fp = new TableFrontPage($db);
     if (JRequest::getVar('frontpage', false, '', 'boolean')) {
         // toggles go to first place
         if (!$fp->load($post['id'])) {
             // new entry
             $query = 'INSERT INTO #__content_frontpage' . ' VALUES ( ' . (int) $post['id'] . ', 1 )';
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseError(500, $db->stderr());
             }
             $fp->ordering = 1;
         }
     } else {
         // no frontpage mask
         if (!$fp->delete($post['id'])) {
             $msg .= $fp->stderr();
         }
         $fp->ordering = 0;
     }
     $fp->reorder();
     $model->checkin();
     // gets section name of item
     $query = 'SELECT s.title' . ' FROM #__sections AS s' . ' WHERE s.scope = "content"' . ' AND s.id = ' . (int) $post['sectionid'];
     $db->setQuery($query);
     // gets category name of item
     $section = $db->loadResult();
     $query = 'SELECT c.title' . ' FROM #__categories AS c' . ' WHERE c.id = ' . (int) $post['catid'];
     $db->setQuery($query);
     $category = $db->loadResult();
     if ($isNew) {
         // messaging for new items
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_messages' . DS . 'tables' . DS . 'message.php';
         // load language for messaging
         $lang =& JFactory::getLanguage();
         $lang->load('com_messages');
         $query = 'SELECT id' . ' FROM #__users' . ' WHERE sendEmail = 1';
         $db->setQuery($query);
         $users = $db->loadResultArray();
         foreach ($users as $user_id) {
             $msg = new TableMessage($db);
             $msg->send($user->get('id'), $user_id, JText::_('New Item'), JText::sprintf('ON_NEW_CONTENT', $user->get('username'), $post['title'], $section, $category));
         }
     } else {
         // If the article isn't new, then we need to clean the cache so that our changes appear realtime :)
         $cache =& JFactory::getCache('com_content');
         $cache->clean();
     }
     //    if ($access->canPublish)
     //  	{
     // Publishers, admins, etc just get the stock msg
     $msg = JText::_('Item successfully saved.');
     //		}
     //		else
     //		{
     //			$msg = $isNew ? JText::_('THANK_SUB') : JText::_('Item successfully saved.');
     //		}
     $referer = JRequest::getString('ret', base64_encode(JURI::base()), 'get');
     $referer = base64_decode($referer);
     if (!JURI::isInternal($referer)) {
         $referer = '';
     }
     $this->setRedirect($referer, $msg);
 }