vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB5 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=262)
-   -   IMG tags mass rewriting? (https://vborg.vbsupport.ru/showthread.php?t=324738)

musicoff 03-15-2017 09:42 AM

IMG tags mass rewriting?
 
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 Code:

<?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

Quote:

Originally Posted by Dave (Post 2584000)
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.


All times are GMT. The time now is 08:19 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01024 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete