$ADMIN_USER_ID = 1; // set this to the user_id of the user who will take credit for these changes
$ADMIN_USER_NAME = 'pegasus'; // set this to the username of the user who will take credit for these changes
$pages = \XF::db()->query("
SELECT pageid
FROM xf_vw_page
"); // preferably use limits/paging
while ($rec = $pages->fetch())
{
$page = \vw_Hard_Core::controller('Fetch')->get('Page', $rec['pageid']);
if ($page)
{
$dm = \vw_Hard_Core::controller('DM')->create('Page', 'SILENT');
$dm->set_info('is_automated', 1);
$dm->set_existing($page);
$canfield = true;
$exact = false;
$rules = \vw_Hard_Core::model('TemplatePack')->get_content_rules($page);
if ($rules AND !empty($rules['value']) AND $rules['value'] == 'exact')
{
$exact = true;
if (empty($rules['customfield']))
{
$canfield = false;
}
}
if ($canfield)
{
$hascached = \vw_Hard_Core::model('CustomField')->has_cached_values($page);
$fields = \vw_Hard_Core::model('CustomField')->relevant($page);
$altvalues = array();
$oldvalues = array();
$values = array();
if ($hascached)
{
$oldvalues = \vw_Hard_Core::model('CustomField')->values($page, $fields, false);
$altvalues = \vw_Hard_Core::model('CustomField')->values($page, $fields, true);
$values = $oldvalues;
foreach ($fields AS $fieldid => $field)
{
switch ($field['fieldtype'])
{
case 'bbcode':
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// DO YOUR DATATABLES CONVERSION MAGIC HERE
// $values[$fieldid] = str_replace('[datatable]', '[table]', $values[$fieldid]);
break;
}
}
}
$dm->set_info('old_custom_field_values', $oldvalues);
$dm->set_info('new_custom_field_values', $values);
$dm->set_info('alt_custom_field_values', $altvalues);
if (!empty($page['templateid']) AND !$exact)
{
$oldtplvalues = array();
$tplvalues = array();
if ($hascached)
{
$tplfields = \vw_Hard_Core::model('CustomField')->templates($page);
$oldtplvalues = \vw_Hard_Core::model('CustomField')->values($page, $tplfields, false);
$tplvalues = $oldtplvalues;
foreach ($tplfields AS $tplfieldid => $tplfield)
{
switch ($tplfield['fieldtype'])
{
case 'bbcode':
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// DO YOUR DATATABLES CONVERSION MAGIC HERE
// $tplvalues[$tplfieldid] = str_replace('[datatable]', '[table]', $tplvalues[$tplfieldid]);
break;
}
}
}
$dm->set_info('old_template_field_values', $oldtplvalues);
$dm->set_info('new_template_field_values', $tplvalues);
}
}
$dm->set_info('revision_visible', 1);
$dm->set('userid', $ADMIN_USER_ID);
$dm->set('username', $ADMIN_USER_NAME);
$dm->set('reason', 'converted datatables to TABLE bb-code');
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// DO YOUR DATATABLES CONVERSION MAGIC HERE
// $page['pagetext'] = str_replace('[datatable]', '[table]', $page['pagetext']);
$dm->set('pagetext', $page['pagetext']);
$dm->process_custom_fields();
$dm->save();
unset($dm);
}
}