自定义编辑器字段未在Joomla 1.5中保存HTML
我在Joomla 1.5管理员面板中添加了额外的编辑器字段:自定义编辑器字段未在Joomla 1.5中保存HTML,joomla,joomla1.5,Joomla,Joomla1.5,我在Joomla 1.5管理员面板中添加了额外的编辑器字段: $editor =& JFactory::getEditor(); echo $editor->display( 'shortdescr', $row->shortdescr , '100%', '150', '75', '20', false ); 所有的工作都很好,但是当我尝试在这个字段中保存html时,joomla删除了html标记,我只得到纯文本 这里是我的saveContent功能: function
$editor =& JFactory::getEditor();
echo $editor->display( 'shortdescr', $row->shortdescr , '100%', '150', '75', '20', false );
所有的工作都很好,但是当我尝试在这个字段中保存html时,joomla删除了html标记,我只得到纯文本
这里是我的saveContent
功能:
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', 'menutype' );
$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;
}
$post=JRequest::get('post');
$post['shortdescr'] = JRequest::getVar( 'shortdescr', '', 'post', 'string', JREQUEST_ALLOWHTML );
$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;
}
}
函数saveContent()
{
全球$大型机;
//检查请求是否伪造
JRequest::checkToken()或jexit('Invalid Token');
//初始化变量
$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'、'menutype');
$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());
返回false;
}
$post=JRequest::get('post');
$post['shortdescr']=JRequest::getVar('shortdescr','post','string',JRequest_allowtml);
$row->bind($details);
//消毒id字段
$row->id=(int)$row->id;
$isNew=true;
//是否从项目编辑中保存?
如果($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');
如果($row->created&&strlen(trim($row->created))已创建。='00:00:00';
}
$config=&JFactory::getConfig();
$tzoffset=$config->getValue('config.offset');
$date=&JFactory::getDate($row->created,$tzoffset);
$row->created=$date->toMySQL();
//如果未添加到发布日期,则追加时间
如果(strlen(trim($row->publish_-up))publish_-up.='00:00:00';
}
$date=&JFactory::getDate($row->publish\u up,$tzoffset);
$row->publish_up=$date->toMySQL();
//句柄从不取消发布日期
如果(修剪($row->publish_down)=JText::(('Never')| |修剪($row->publish_down)=='')
{
$row->publish_down=$nullDate;
}
其他的
{
如果(strlen(trim($row->publish_down))publish_down.='00:00';
}
$date=&JFactory::getDate($row->publish\u down,$tzoffset);
$row->publish_down=$date->toMySQL();
}
//从请求中获取状态和参数变量
$row->state=JRequest::getVar('state',0','int');
$params=JRequest::getVar('params',null',post',array');
//生成参数INI字符串
if(is_数组($params))
{
$txt=array();
foreach($k=>v的参数){
$txt[]=“$k=$v”;
}
$row->attribs=内爆(“\n”,$txt);
}
//获取元数据字符串
$metadata=JRequest::getVar('meta',null',post',array');
if(is_数组($metadata))
{
$txt=array();
foreach($k=>v的元数据){
如果($k=='description'){
$row->metadesc=$v;
}elseif($k=='keywords'){
$row->metakey=$v;
}否则{
$txt[]=“$k=$v”;
}
}
$row->metadata=内爆(“\n”,$txt);
}
//准备要保存到数据库的内容
ContentHelper::saveContentPrep($row);
//确保数据有效
如果(!$row->check()){
JError::raiseError(500,$db->stderr());
返回false;
}
//增加内容版本号
$row->version++;
$result=$dispatcher->trigger('onBeforeContentSave',数组(&$row,$isNew));
if(在_数组中(false,$result,true)){
JError::raiseError(500,$row->getError());
返回false;
}
//将内容存储到数据库中
如果(!$row->store()){
JError::raiseError(500,$db->stderr());
返回false;
}
//检查文章并更新项目顺序
$row->checkin();
$row->reorder('catid='(int)$row->catid.'和状态>=0');
/*
*我们需要更新文章的frontpage状态。
*
*首先,我们包括frontpage表并实例化它的一个实例。
*/
需要一次(JPATH_ADMINISTRATOR.DS.components.DS.com_frontpage.DS.tables.DS.frontpage.php));
$fp=新的TableFrontPage($db);
//这篇文章可以在frontpage上查看吗?
if(JRequest::getVar('frontpage',0','int'))
{
//该项目是否已可在frontpage上查看?
如果(!$fp->load($row->id))
{
//插入新条目
$query='插入#uu内容u首页'。
'值('(int)$row->id',1)';
$db->setQuery($query);
如果(!$db->query())
{
JError::raiseError(500,$db->stderr());
返回false;
}
$fp->ordering=1;
}
}
其他的
{
//从frontpage中删除该项目(如果存在)
如果(!$fp->删除($row->id)){
$msg.=$fp->stderr();
}
$fp->ordering=0;
}
$fp->reorder();
$cache=&JFactory::getCache('com_content');
$cache->clean();
$dispatcher->trigger('onAfterContentSave',数组(&$row,$isNew));
交换机($任务)
{
案例“go2menu”:
$mainframe->redirect('index.php?option=com_menus&menutype='。$menu);
打破
案例“go2menuitem”:
$mainframe->redirect(
'index.php?option=com_menus&menutype='。$menu
“&task=edit&id=”。$menuid
);
$row = & JTable::getInstance('content');
if (!$row->bind(JRequest::get('post'))) {
JError::raiseError( 500, $db->stderr() );
return false;
}
$post=JRequest::get('post');
$post['shortdescr'] = JRequest::getVar( 'shortdescr', '', 'post', 'string', JREQUEST_ALLOWHTML );
$post=JRequest::get('post');
$post['shortdescr'] = JRequest::getVar( 'shortdescr', '', 'post', 'string', JREQUEST_ALLOWHTML );
$row = & JTable::getInstance('content');
if (!$row->bind($post)) {
JError::raiseError( 500, $db->stderr() );
return false;
}