PDA

View Full Version : [solved] Automatic removal of [img] and [youtube] tags when quoting posts


pjkcards
05-19-2014, 07:00 AM
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:

// ################################################## ###########################
/**
* 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','vime o','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?