PDA

View Full Version : IMG tags mass rewriting?


musicoff
03-15-2017, 09:42 AM
Hi everyone,
we've migrated from SMF to vB5. It seems that IMG tag sizes aren't recognized since now we're full of topic with broken codes like:

[img width=220 height=600

We're trying to understand if is possible to mass editing them setting to simple IMG tags without size, in order to recover the linked images.

Anyone had the same problem? Suggestions?
Thanks in advance.

Dave
03-17-2017, 05:02 PM
Edit: just noticed it's for vBulletin 5... nvm.

I originally thought this was for vBulletin 4, so this will not work for your forum, but I decided to just post the script here anyway:

You could use something like this in PHP to mass rewrite IMG tags that look like: [img width=123 height=123] to [img]. Create a PHP file in the root of your forum and then visit it in the browser or execute it through the command line interface.

I recommend executing it against a test database first since I didn't test it.
Also if you have a very big database, it may timeout.

<?php

require("./global.php");
set_time_limit(360);

$q = $vbulletin->db->query_read("SELECT postid, pagetext FROM " . TABLE_PREFIX ."post WHERE pagetext like '%[img %]'");

while($row = $vbulletin->db->fetch_assoc($q)){
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "post
SET pagetext = '" . $vbulletin->db->escape_string(preg_replace("/\[img\s(width=(...)\sheight=(...))\]/im", "[img]", $row['pagetext'])) . "'
WHERE postid = " . $row['postid']);
}

musicoff
03-19-2017, 09:33 AM
Edit: just noticed it's for vBulletin 5... nvm.


Thanks anyway, maybe we could start from this to formulate a solution for our problem.
Any other suggestion is welcome.

Thanks.