Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2011, 12:51 PM
Alfa1's Avatar
Alfa1 Alfa1 is offline
 
Join Date: Dec 2005
Location: Netherlands
Posts: 3,537
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to remove links from a database field?

I have links and Downloads Manager installed. In 1100 entries in there are dead links in the description field, due to copy -pasting of text.
I need to remove all links from the that description field, so that only plain text remains in that field. The database table is vb_linkslink and the field is linkdesc

Links look like this:
Code:
[url="http://www.somesite.com/entrez?Db=pubmed&Cmd=Search&Term=%22Guo%20Y%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus"][color=black]Some author name[/color][/url]
I would like to remove the link and keep the Author name.

Does anyone know what query I could use to do this?
Reply With Quote
  #2  
Old 07-02-2011, 08:11 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't think a query would work on something like this. You'll need a custom script and need to use some sort of regular expression to find matches and remove them.
Reply With Quote
  #3  
Old 07-02-2011, 08:37 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
/**
* Strips away bbcode from a given string, leaving plain text
*
* @param    string    Text to be stripped of bbcode tags
* @param    boolean    If true, strip away quote tags AND their contents
* @param    boolean    If true, use the fast-and-dirty method rather than the shiny and nice method
* @param    boolean    If true, display the url of the link in parenthesis after the link text
* @param    boolean    If true, strip away img/video tags and their contents
* @param    boolean    If true, keep [quote] tags. Useful for API.
*
* @return    string
*/
function strip_bbcode($message$stripquotes false$fast_and_dirty false$showlinks true$stripimg false$keepquotetags false
So, Something like this?

PHP Code:
$result $vbulletin->db->query_write("
    SELECT linkid
         , linkdesc
      FROM " 
TABLE_PREFIX "linkslink
"
);

while (
$link $vbulletin->db->fetch_array($result)) {    
    
$vbulletin->db->query_write(fetch_query_sql(
        array(
'linkdesc' => strip_bbcode($link['linkdesc'])),
        
'linkslink',
        
"WHERE linkid = $link[linkid]"
    
));

Reply With Quote
  #4  
Old 07-04-2011, 12:17 AM
Alfa1's Avatar
Alfa1 Alfa1 is offline
 
Join Date: Dec 2005
Location: Netherlands
Posts: 3,537
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where should that code go to execute it?
Reply With Quote
  #5  
Old 07-04-2011, 01:45 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For things like that I usually create a plugin using hook misc_start and code like this:

PHP Code:
if ($_REQUEST['do'] == 'fixlinks')
{
    
// code here

    
exit("Done fixlinks.");


then go to page misc.php?do=fixlinks to run it, and disable or delete it when I'm done.
Reply With Quote
  #6  
Old 07-04-2011, 04:21 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

New PHP file works too...

PHP Code:
<?php

error_reporting
(E_ALL E_NOTICE 8192);

require(
'./global.php');

$result $vbulletin->db->query_write("
    SELECT linkid
         , linkdesc
      FROM " 
TABLE_PREFIX "linkslink
"
);

while (
$link $vbulletin->db->fetch_array($result)) {    
    
$vbulletin->db->query_write(fetch_query_sql(
        array(
'linkdesc' => strip_bbcode($link['linkdesc'])),
        
'linkslink',
        
"WHERE linkid = $link[linkid]"
    
));
}  

die(
'Done');
Reply With Quote
  #7  
Old 07-04-2011, 08:04 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
New PHP file works too...

Nice, that is pretty simple. For some reason I've been under the impression that a few more things would need to be defined for that to work.
Reply With Quote
  #8  
Old 07-04-2011, 02:34 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nope, those are the only two required lines (error_reporting, require global.php)

The rest are good practice but don't matter for quick one-off scripts.
Reply With Quote
  #9  
Old 07-04-2011, 03:48 PM
Alfa1's Avatar
Alfa1 Alfa1 is offline
 
Join Date: Dec 2005
Location: Netherlands
Posts: 3,537
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Unfortunately that didnt work as planned.

Instead of hotlinked words, I now have this:
Code:
Eur J Pharmacol. (javascript:AL_get(this, 'jour', 'Eur J Pharmacol.')); 1998 Jan 12;341(2-3):131-4
 
Schultz DM  (http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22Schultz%20DM%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus),  Prescher JA  (http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22Prescher%20JA%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus),  Kidd S  (http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22Kidd%20S%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus),  Marona-Lewicka D  (http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22Marona-Lewicka%20D%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus),  Nichols DE  (http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22Nichols%20DE%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus),  Monte A  (http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=Search&Term=%22Monte%20A%22%5BAuthor%5D&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_DiscoveryPanel.Pubmed_RVAbstractPlus)
It should read:
Code:
Eur J Pharmacol.  1998 Jan 12;341(2-3):131-4
 
Schultz DM,  Prescher JA,  Kidd S,  Marona-Lewicka D,  Nichols DE,  Monte A
Please let me know ASAP if I should revert the database table. I have 90k users adding stuff.
Reply With Quote
  #10  
Old 07-04-2011, 04:20 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd revert it for now, yeah.

If you want to send me a few example rows (10-50 or so) I can get it working for you, but will be difficult without any real data.

--------------- Added [DATE]1309800396[/DATE] at [TIME]1309800396[/TIME] ---------------

If you want, try it again, and set $showlinks to false (4th argument to strip_bbcode). That should do the trick.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:41 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.05653 seconds
  • Memory Usage 2,275KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete