Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
  #1  
Old 07-12-2013, 03:43 PM
Tjap Tjap is offline
 
Join Date: Oct 2012
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Extract information from URL to use in bbcode.

Dear vBulletin users,

For a while, I've been using a twitter mod on my forum (3.8), it is a mod to embed a tweet by using the following syntax:

Code:
[tweet]twitterstatusid[/tweet]
Now I would like to be able to just post the tweet url (which contains the statusid), now I figured the most simple solution would be to extract the statusid directly from the URL and add the bbcode. Now there is only one problem, I really don't know anything about PHP or XML.

Is there anyone who would like to help me out? It would be greatly appreciated.

Kind regards,
Nick
Reply With Quote
  #2  
Old 07-13-2013, 08:09 AM
exel exel is offline
 
Join Date: Jan 2008
Location: Southern California
Posts: 161
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

May I know what BBCODE mod you're using for this?

As I got a PHP code ready which I tested works perfectly and replaces for example:

https://twitter.com/exelaguilar/stat...24693311152129

To..

[tweet]355224693311152129[/tweet]

But of course, I can't actually test the [tweet] bbcode as I don't have it.
Reply With Quote
  #3  
Old 07-13-2013, 03:25 PM
Tjap Tjap is offline
 
Join Date: Oct 2012
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm using the following mod:

https://vborg.vbsupport.ru/showthread.php?t=287342

It states that it is for vB4, but it works on vB3 as well
Reply With Quote
  #4  
Old 07-13-2013, 05:56 PM
exel exel is offline
 
Join Date: Jan 2008
Location: Southern California
Posts: 161
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Make a plguin for postdata_presave and threadfpdata_presave

And add the following code to both:

PHP Code:
global $vbulletin
    
$pagetext =& $this->fetch_field('pagetext''post'); 
        
    if (
stristr($pagetext,'https://twitter.com/')) {


    
$string $pagetext;
    
$pattern '#https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)#';
    
$replacement '[tweet]$3[/tweet]';

    
$pagetext preg_replace($pattern$replacement$string);

    } 
Won't gurantee anything, but it does indeed convert a twitter link to the format you want.


See: http://elite-source.com/testthis.php
Reply With Quote
2 благодарности(ей) от:
tbworld, Tjap
  #5  
Old 07-13-2013, 07:07 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting piece of code. Thanks @exel.
Reply With Quote
  #6  
Old 07-14-2013, 02:42 PM
Tjap Tjap is offline
 
Join Date: Oct 2012
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much Exel, it works pretty well, except for the fact that vBulletin automatically adds
Code:
[url]
to the url, is there a way to fix this?
Reply With Quote
  #7  
Old 07-14-2013, 10:15 PM
exel exel is offline
 
Join Date: Jan 2008
Location: Southern California
Posts: 161
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here you go:

PHP Code:
global $vbulletin
    
$pagetext =& $this->fetch_field('pagetext''post'); 
        
    if (
stristr($pagetext,'https://twitter.com/')) {

    function 
stripBBCode($text$code
    { 
        
$code str_replace(",""|"$code); 
        
$code str_replace(" """$code); 
        
$pattern '#\[/?(?:' $code ')[^]]*\]#i';
        return 
preg_replace($pattern''$text);  
    } 

    
$string $pagetext;
    
$pattern '#https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)#';
    
$replacement '[tweet]$3[/tweet]';

    
$pagetext preg_replace($pattern$replacement$string);

    
$pagetext stripBBCode($pagetext"url"); 

    } 
Tested here; http://craftgraphics.com/forum/showt...hp?p=65#post65

Only issue with that is it will also strip out [url] for anything else. BUT it will ONLY do that if the post has a twitter link on it.

So if your post has

http://twitter.com/exel/status/123

and http://google.com

it will do

[tweet]123[/tweet]

google.com


But if it doesn't have twitter in the post, it will use the default vbulletin system.

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

Can confirm it works:

Reply With Quote
  #8  
Old 07-15-2013, 07:35 AM
Tjap Tjap is offline
 
Join Date: Oct 2012
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow, thanks alot mate. Works perfectly!
Reply With Quote
  #9  
Old 07-15-2013, 05:04 PM
exel exel is offline
 
Join Date: Jan 2008
Location: Southern California
Posts: 161
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Glad to hear.
Reply With Quote
Reply

Thread Tools
Display Modes

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 07:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06976 seconds
  • Memory Usage 2,252KB
  • 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
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (2)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete