vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   [solved] Automatic removal of [img] and [youtube] tags when quoting posts (https://vborg.vbsupport.ru/showthread.php?t=311474)

pjkcards 05-19-2014 07:00 AM

[solved] Automatic removal of [img] and [youtube] tags when quoting posts
 
Often, people quote posts that contain an embedded video or a large image, and when it's done excessively it takes up a lot of unnecessary vertical space (more scrolling) and can cause the threads to take longer to load.

Can images and videos using [img], [youtube], [youtubehd], [video] and other such tags be changed to just the URL of the image or video when using "Reply With Quote"? How can I go about this?

Thanks.

pjkcards 07-23-2014 08:15 AM

bump. Any help would be much appreciated.

Dave 07-23-2014 08:41 AM

<a href="https://vborg.vbsupport.ru/showthread.php?t=260337" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=260337</a>

Is that what you're looking for?

MarkFL 07-24-2014 04:55 AM

While this isn't exactly what you asked for, what I did was edit the strip_quotes function in the file /includes/functions.php, with an array of tags literally defined to simply be removed, along with their contents:

PHP Code:

// #############################################################################
/**
* Strips away a defined set of tags and their contents from the specified string
*
* @param    string    Text to be stripped of tags
*
* @return    string
*/
function strip_quotes($text)
{
    
$tags = array('quote','desmos','graph','img','video','vimeo','youtube');
    
$i 0;

    while (isset(
$tags[$i]))
    {
        
$lowertext strtolower($text);
        
$stack = array();
        
$start_pos = array();
        
$end_pos = array();
        
$quit false;
        
$tag $tags[$i];
        
$taglength strlen($tag);
        
$newtext $text;

        
// find all opening tags

        
$curpos 0;
        do
        {
            
$pos strpos($lowertext'[' $tag$curpos);
            if (
$pos !== false AND ($lowertext[$pos $taglength 1] == '=' OR $lowertext[$pos $taglength 1] == ']'))
            {
                
$start_pos["$pos"] = 'start';
            }

            
$curpos $pos $taglength 1;
        }
        while (
$pos !== false);

        if (
count($start_pos) == 0)
        {
            
$quit true;
        }

        if (
$quit == false)
        {

            
// find all closing $tag tags
            
$curpos 0;
            do
            {
                
$pos strpos($lowertext'[/' $tag ']'$curpos);
                if (
$pos !== false)
                {
                    
$end_pos["$pos"] = 'end';
                    
$curpos $pos $taglength 3;
                }
            }
            while (
$pos !== false);

            if (
count($end_pos) == 0)
            {
                
$quit true;
            }

            if (
$quit == false)
            {

                
// merge them together and sort based on position in string
                
$pos_list $start_pos $end_pos;
                
ksort($pos_list);

                do
                {
                    
// build a stack that represents when a tag is opened
                    // and add non-tag text to the new string
                    
$newtext '';
                    
$substr_pos 0;
                    foreach (
$pos_list AS $pos => $type)
                    {
                        
$stacksize count($stack);
                        if (
$type == 'start')
                        {
                            
// empty stack, so add from the last close tag or the beginning of the string
                            
if ($stacksize == 0)
                            {
                                
$newtext .= substr($text$substr_pos$pos $substr_pos);
                            }
                            
array_push($stack$pos);
                        }
                        else
                        {
                            
// pop off the latest opened tag
                            
if ($stacksize)
                            {
                                
array_pop($stack);
                                
$substr_pos $pos $taglength 3;
                            }
                        }
                    }

                    
// add any trailing text
                    
$newtext .= substr($text$substr_pos);

                    
// check to see if there's a stack remaining, remove those points
                    // as key points, and repeat. Allows emulation of a non-greedy-type
                    // recursion.
                    
if ($stack)
                    {
                        foreach (
$stack AS $pos)
                        {
                            unset(
$pos_list["$pos"]);
                        }
                    }
                }
                while (
$stack);
                
$text $newtext;
            }
        }
        
$i++;
    }
    return 
$newtext;



pjkcards 08-16-2014 03:35 AM

Thanks guys. Dave's link seemed to work.

MarkFL: does your suggestion do anything different?


All times are GMT. The time now is 03:46 PM.

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.01058 seconds
  • Memory Usage 1,766KB
  • 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)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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