<?php
define('IN_PHPBB', true);
define('BB_ROOT', './');
require __DIR__ . '/common.php';
require INC_DIR . '/functions_post.php';
// Start session
$user->session_start();
echo 'Подготовка<br />';
$sql = DB()->fetch_rowset("SELECT t.topic_id, p.post_text
FROM bb_topics t
LEFT JOIN bb_posts_text p ON (p.post_id = t.topic_first_post_id) WHERE descr = '' OR keywords = '' OR topic_image = '' LIMIT 10000");
foreach($sql as $row)
{
$meta = create_metatags($row['post_text']);
if ($bb_cfg['last_added'])
{
preg_match_all('/\[gposter=right\](.*?)\[\/gposter\]/i', $row['post_text'], $poster7, PREG_SET_ORDER);
preg_match_all('/\[gposter=left\](.*?)\[\/gposter\]/i', $row['post_text'], $poster6, PREG_SET_ORDER);
preg_match_all('/\[gposter\](.*?)\[\/gposter\]/i', $row['post_text'], $poster5, PREG_SET_ORDER);
preg_match_all('/\[poster\](.*?)\[\/poster\]/i', $row['post_text'], $poster4, PREG_SET_ORDER);
preg_match_all('/\[img=right\](.*?)\[\/img\]/i', $row['post_text'], $poster3, PREG_SET_ORDER);
preg_match_all('/\[img=left\](.*?)\[\/img\]/i', $row['post_text'], $poster2, PREG_SET_ORDER);
preg_match_all('/\[img\](.*?)\[\/img\]/i', $row['post_text'], $poster1, PREG_SET_ORDER);
$url = empty($url) ? 'noposter.png' : '';
if (isset($poster7[0][1])) $url = $poster7[0][1];
elseif (isset($poster6[0][1])) $url = $poster6[0][1];
elseif (isset($poster5[0][1])) $url = $poster5[0][1];
elseif (isset($poster4[0][1])) $url = $poster4[0][1];
elseif (isset($poster3[0][1])) $url = $poster3[0][1];
elseif (isset($poster2[0][1])) $url = $poster2[0][1];
elseif (isset($poster1[0][1])) $url = $poster1[0][1];
}
DB()->sql_query("UPDATE bb_topics SET topic_image = '$url', keywords = '".$meta['keywords']."', descr = '".$meta['description']."' WHERE topic_id = ".$row['topic_id']."");
}
echo 'Обновление готово.';