<?php

include 'simple_html_dom.php';

header('Content-Type: text/html; charset=utf-8');
define('_JEXEC', 1);

if (file_exists(__DIR__ . '/defines.php')) {
    include_once __DIR__ . '/defines.php';
}

if (!defined('_JDEFINES')) {
    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') . '');

$list = $db->loadObjectList();

for ($i = 0; $i < count($list); $i++) {
	
    setlocale(LC_ALL, 'ru-RU.cp1251');
    echo $i . ' ';
    $title     = $list[$i]->title;
    $introtext = $list[$i]->introtext;
    $id        = $list[$i]->id;
    if ($introtext == "") {
        
        
    } else {
    	
        $dom = str_get_html($introtext);
        
        if ($dom->find("img")) {
            $items = $dom->find("img");
            
            foreach ($items as $img) {
                
                $img->alt = $title;
                
                
                $img->title = $title;
                
            }
        }
        
        $res = $dom->innertext;
        
        $qr_result = $db->setQuery('UPDATE ' . $db->quoteName('#__content') . ' SET ' . $db->quoteName('introtext') . ' = ' . $db->quote($res) . ' WHERE ' . $db->quoteName('id') . ' = ' . $db->quote($id));
        $result    = $db->query();
        
    }
}