<?php
{
include_once __DIR__ . '/defines.php';
}
{
define('JPATH_BASE', __DIR__
); require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
require_once JPATH_BASE . '/libraries/joomla/factory.php';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$qr_result = $db->setQuery('SELECT * FROM ' . $db->quoteName('#__content') . ' WHERE 1');
$list = $db->loadObjectList();
for ($i = 0; $i < count($list); $i++) {
$title = $list[$i]->title;
$fulltext = $list[$i]->fulltext;
$dom = new DOMDocument('4.0','UTF-8');
$dom->substituteEntities = false;
$dom->encoding = "UTF-8";
if ($fulltext != "") {
$dom->loadHTML($fulltext);
}
$nodeHead=$dom->createElement("head");
$nodeMeta=$dom->createElement('meta');
$dom->insertBefore($nodeHead, $dom->firstChild);
$nodeMeta->setAttribute ("http-equiv","Character");
$nodeMeta->setAttribute ("content","ISO-8859-1");
$nodeHead->appendChild($nodeMeta);
$nodeMeta=$dom->createElement('meta');
$nodeMeta->setAttribute ("http-equiv","Content-Type");
$nodeMeta->setAttribute ("content","text/html; charset=ISO-8859-1");
$nodeHead->appendChild($nodeMeta);
$items = $dom->getElementsByTagName("img");
foreach ($items as $img) {
if ($img->getAttribute('alt') == "") {
$img->setAttribute('alt', $title);
}
if ($img->getAttribute('title') == "") {
$img->setAttribute('title', $title);
}
}
$res = $dom->saveHTML();
$res = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|meta|body))[^>]*>\s*~i', '', $res);
$qr_result = $db->setQuery(
'UPDATE ' . $db->quoteName('#__content') .
' SET ' . $db->quoteName('fulltext') . ' = ' . $db->quote($res) .
' WHERE ' . $db->quoteName('title') . ' = ' . $db->quote($title));
$result = $db->query();
}