×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: solution for getting rid of [color] brackets

solution for getting rid of [color] brackets 10 years 4 months ago #24050

  • X-Bit
  • X-Bit's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 8
At comment preview the [...] are disturbing and BBcode is on my template frontpage off.
So thats how I solved it...
Stripping out with regex and 'non-greedy' matches we first extract the title and put it in a variable called $title_unformated, then we use the regex to extract the brackets including content and write it to the variable $title which will be displayed.
/components/com_comment/templates/default/readmore_preview.php from line 15 on:
<div class='ccomment-preview-container'>
	<?php foreach ($this->comments as $value) : ?>
		<?php
		if ($value->title != '') {
			$title_unformated = stripslashes($value->title);
			$title = preg_replace('/\[.*?\]/', '', $title_unformated);
		} else {
			$title_unformated = stripslashes($value->comment);
			$title = preg_replace('/\[.*?\]/', '', $title_unformated);
		}
		if (JString::strlen($title) > $previewLength) {
			$title = JString::substr($title, 0, $previewLength) . '...';
		}
		?>
There would be probably a quicker way, combining the stripslashes and preg_replace on one line, but I am a lazy guy and leave this to Daniel ;-)

Don't forget to do an override after testing, otherwise you will loose those changes with next update.
Override path would be: templates/MYTEMPLATE/html/com_comment/templates/default/readmore_preview.php

Hope this helps anyone!

solution for getting rid of [color] brackets 10 years 3 months ago #24353

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
I guess that it would be better to run the text through the BB parser?`This way it can replace images and other stuff as well.
  • Page:
  • 1
Time to create page: 0.203 seconds