REPLACE INTO << Ouch, I never had to use this when using the XenForo Datawriter correctly
VARCHAR( 10000 ) << ouch, something tells me you should be using a large object column (try a text column)
mysql_real_escape_string($html) << Sounds dangerous, why not let the Datawriter handel anything that could be abused
I would be careful with inserting and then displaying html, particulary if it's from users input (even when using the datawriter, user could attempt to manipulate the HTML <b>bold test</b> <script>sendMeTheAdminsCookie();</script>
What I did when first learning how to insert/replace in XF is to looked at how the core and how other plugins do it
Have a look at Jaxels datawriters (that's where I looked 1st), for instance, one of my DataWriters (slightly simplified):
Code:
class XenKingDir_DataWriter_Directory extends XenForo_DataWriter
{
protected function _getFields()
{
return array(
'sf_xenkingdir_directory_node' => array(
'node_id' => array('type' => self::TYPE_UINT, 'autoIncrement' => true),
'description' => array('type' => self::TYPE_STRING, 'default' => ''),
)
);
}
protected function _getNodeModel()
{
return $this->getModelFromCache('XenKingDir_Model_Directory');
}
protected function _getExistingData($data)
{
if (!$nodeId = $this->_getExistingPrimaryKey($data))
{
return false;
}
return array('sf_xenkingdir_directory_node' => $this->_getNodeModel()->getNodeById($nodeId));
}
protected function _getUpdateCondition($tableName)
{
return 'node_id = ' . $this->_db->quote($this->getExisting('node_id'));
}
}
You'll need to write the models "getNodeById($nodeId)" or whatever it is you use. Then, if you do come accross something where you need to a "replace into" _getExistingData will automatically be called when the primary key is found using setExistingData, for instance when doing this:
Code:
$writer = XenForo_DataWriter::create('XenKingDir_DataWriter_Directory');
$writer->setExistingData($node_id); // in this case, the primary key exist so we can set as existing data
$writer->bulkSet($arrayForTheRest);
$writer->save();