vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Extract information from URL to use in bbcode. (https://vborg.vbsupport.ru/showthread.php?t=300046)

Tjap 07-12-2013 03:43 PM

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

exel 07-13-2013 08:09 AM

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.

Tjap 07-13-2013 03:25 PM

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

exel 07-13-2013 05:56 PM

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

tbworld 07-13-2013 07:07 PM

Interesting piece of code. Thanks @exel. :)

Tjap 07-14-2013 02:42 PM

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?

exel 07-14-2013 10:15 PM

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:

https://vborg.vbsupport.ru/external/2013/07/36.png

Tjap 07-15-2013 07:35 AM

Wow, thanks alot mate. Works perfectly!

exel 07-15-2013 05:04 PM

Glad to hear. :)


All times are GMT. The time now is 07:09 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.01136 seconds
  • Memory Usage 1,744KB
  • 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
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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