Keyword

Forbid links in commens?

  • web_dev
  • web_dev's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 9 months ago #130586 by web_dev
Forbid links in commens? was created by web_dev
It's possible to forbid links in comment form?

Please Log in or Create an account to join the conversation.

More
10 years 9 months ago #130587 by Lefteris
Replied by Lefteris on topic Re: Forbid links in commens?
Hi. Do you want to hide the URL field or strip links from the comments text?

Please Log in or Create an account to join the conversation.

  • web_dev
  • web_dev's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 9 months ago #130588 by web_dev
Replied by web_dev on topic Re: Forbid links in commens?
Hi,

i want to strip links from the comments text

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #130589 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Forbid links in commens?
You can use strip_tags:

php.net/manual/en/function.strip-tags.php

eg:
<?php echo strip_tags($comment->commentText); ?>

The code for the comments list is located in the item.php file.

Please Log in or Create an account to join the conversation.

  • BrethrenArchives.Com
  • BrethrenArchives.Com's Avatar
  • Offline
  • Junior Member
More
10 years 6 months ago - 10 years 6 months ago #130590 by BrethrenArchives.Com
Replied by BrethrenArchives.Com on topic Re: Forbid links in commens?
Krikor,

Thank you commenting on this topic. Here is a link to a comment on my site. Am I also seeing that the HTML on this page will disappear?

Where do I find the item.php file please?

Cordially,
A. Wayne Webb

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 6 months ago #130591 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Forbid links in commens?
I get a 403 - not permitted error when I try to access these links.

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #143979 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
Can I use the strip_tags function on Extra Fields?
I tried using the following code, but it did not convert the special characters to HTML entities:
<?php echo strip_tags($this->item->extraFields->NAME->value); ?>

Note: Current PHP version: 5.3.29

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #143988 by Krikor Boghossian
Replied by Krikor Boghossian on topic Forbid links in commens?
You can also specify which tags are allowed in the funtion's params.
php.net/strip_tags

You can also use srt_replace php.net/str_replace
So you can add rel="nofollow" if you do not want to remove the links.

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #143994 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
I am not looking to accomplish anything with comments. I merely replied to this thread because it was the only post that mentioned tag stripping.

My goal is to echo Extra Fields for meta purposes, which would require the removal of special characters especially quotes and apostrophes.

I thought I could use the existing strip_tags function, but it is not working in my item template override.

Can you please provide the specific code needed to accomplish tag stripping of an Extra Field. Thanks :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago - 9 years 11 months ago #143995 by Krikor Boghossian
Replied by Krikor Boghossian on topic Forbid links in commens?
Sorry I misread the question.
Yes you can strip tags in an extrafield.

Strip_tags will remove (as delete) all your HTML tags (not strings).
If you want to convert it to entities, you need to use another PHP function - htmlentities php.net/htmlentities

Finally this function won't probably help you since what you need is a string replacer.

This is what you should use -> php.net/str_replace
Check the "Example #1 Basic str_replace() examples" section which is exactly what you need.
It will remove every character you do not need.

This method can be used in pretty much all text-related elements of K2.
Last edit: 9 years 11 months ago by Krikor Boghossian.

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #143997 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
Thanks Krikor, but you forget I am not a programmer. Can you please provide sample code. I basically just need to remove single and double quotes as to not break the meta data that the extra field is being used to populate.

I tried the following, but is does not work:
<?php 
$cleanfield = $this->item->extraFields->NAME->value;
$cleanfield = htmlspecialchars($cleanfield, ENT_QUOTES);
echo $cleanfield; 
?>

Please provide cut & paste code :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #143998 by Krikor Boghossian
Replied by Krikor Boghossian on topic Forbid links in commens?
The code seems correct. What does it produce?
PS. if this is intended for metadata where each character counts, 160 is the limit, I would personally strip them. htmlentities() will increase the character count.

This should do the trick.
gist.github.com/kricore/7abc76e04c1bc9235ce2

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #144001 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
Thank you - just one more small thing, instead of removing single & double quotes I changed the code to replace them with HTML entities.

I also provided the specific code to use an Extra Field for meta data

My very first Gist post :)
gist.github.com/heyjoecampbell/d62f6ccc019c07284a88

As I said before, I am not a coder, just a guy inspired to create an amazing Joomla K2 Website - I GREATLY appreciate the support you have shown me since day one :)

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago - 9 years 11 months ago #144004 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
How do apply if isset/else statements within addCustomTag meta data statements (with & without str_replace)

Standard addCustomTag
<?php
$doc->addCustomTag('<meta name="anything" content="'.$this->item->extraFields->AAA->value.'" />');
?>

Standard addCustomTag (with str_replace)
<?
$doc->addCustomTag('<meta name="anything" content="'.str_replace($nonsafe, $safe, $this->item->extraFields->AAA->value).'" />');
?>

Here's the logic I am trying to produce:

<?php $doc->addCustomTag(
if(isset($this->item->extraFields->AAA->value)): ?><meta name="anything" content="'.$this->item->extraFields->AAA->value.'" /><?php else: ?><meta name="anything" content="'.$this->item->extraFields->BBB->value.'" />
<?php endif; ?>
); ?>

I would also like to be able to place multiple meta statements within one addCustomTag statement if possible...

<?php $doc->addCustomTag(
if(isset($this->item->extraFields->AAA->value)): ?><meta name="anything" content="'.$this->item->extraFields->AAA->value.'" /><?php else: ?><meta name="anything" content="'.$this->item->extraFields->BBB->value.'" />
<?php endif; ?>

<meta name="anything" content="something" />
<meta name="anything else" content="something else" />

if(isset($this->item->extraFields->CCC->value)): ?><meta name="anything" content="'.$this->item->extraFields->CCC->value.'" /><?php else: ?><meta name="anything" content="'.$this->item->extraFields->DDD->value.'" />
<?php endif; ?>
); ?>

I would very much appreciate if someone could provide cut & paste solutions for both with str_replace and without str_replace.
Last edit: 9 years 11 months ago by Joe Campbell.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #144018 by Krikor Boghossian
Replied by Krikor Boghossian on topic Forbid links in commens?
Here you go. This will also check if the extrafield is blank.
<?php 
	if( isset($this->item->extraFields->AAA->value) && $this->item->extraFields->AAA->value != '' ) {
		// extrafield AAA is set and has a value
		echo $this->item->extraFields->AAA->value;
	} else {
		// no extrafield AAA or it has no value so assign the BBB instead
	       echo $this->item->extraFields->BBB->value;
	} 
?>

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #144029 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
Thank you Krikor, but I need two code samples (in context to the addCustomTag code I previously posted):

- one standard addCustomTag
- one addCustomTag with str_replace

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #144033 by Krikor Boghossian
Replied by Krikor Boghossian on topic Forbid links in commens?
You can combine these methods. The if/ else statement remains the same.
<?php 
	if( isset($this->item->extraFields->AAA->value) && $this->item->extraFields->AAA->value != '' ) {
		// extrafield AAA is set and has a value so render it as is
		$doc->addCustomTag('<meta name="anything" content="'.$this->item->extraFields->AAA->value.'" />');
	} else {
		// no extrafield AAA or it has no value so render the str_replace code
		$doc->addCustomTag('<meta name="anything" content="'.str_replace($nonsafe, $safe, $this->item->extraFields->AAA->value).'" />');
	} 
?>

See the comments so you can replace these blocks with the real extrafields.

Btw Nice work :)

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #144034 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
Thanks for the compliment :)

Is it possible to perform the If Statement within the addCustomTag, so that it's like this...

<?php $doc->addCustomTag('<meta name="description" content="if extrafield-A has value render extrafield-A ELSE render extrafield-B" />'); ?>

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #144036 by Krikor Boghossian
Replied by Krikor Boghossian on topic Forbid links in commens?
That would not be that clean.
A cleaner approach would be this ->
gist.github.com/kricore/2c9a5434748c5f5f6cf9

You can use this gist to build various examples.
Check this post also:
davidwalsh.name/php-ternary-examples

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago - 9 years 11 months ago #144039 by Joe Campbell
Replied by Joe Campbell on topic Forbid links in commens?
I know it's not the cleanest approach, but I have over 20 meta items that I need to render.

Currently, I am using this approach for each condition:

<?php if(isset($this->item->extraFields->AAA->value)): ?>
<?php $doc->addCustomTag('<meta name="anything" content="'.$this->item->extraFields->AAA->value.'" />'); ?>
<?php else: ?>
<?php $doc->addCustomTag('<meta name="anything" content="'.$this->item->extraFields->BBB->value.'" />'); ?>
<?php endif; ?>

I would prefer doing it all on one line, so I would not have to duplicate the addCustomTag statement (with value & else variation).

Is it possible to execute a one line statement? I would need one for each scenario, something like this...

Example: Standard addCustomTag
<?php $doc->addCustomTag('<meta name="description" content="isset(extrafield-A)
echo extrafield-A ELSE echo extrafield-B" />'); ?>

Example: Standard addCustomTag (with str_replace)
<?php $doc->addCustomTag('<meta name="description" content="isset(extrafield-A)
echo str_replace(extrafield-A) ELSE echo str_replace(extrafield-B)" />'); ?>

If so, then it would be much easier to add & modify multiple addCustomTag statements.
Plus I prefer one line statements, as they are easier for me to copy & paste for future uses.

This is what I tried so far, but does not work :(

My bad code for: Standard addCustomTag
<?php $doc->addCustomTag('<meta property="anything" content="'if(isset($this->item->extraFields->AAA->value)) {$this->item->extraFields->AAA->value} else: {$this->item->extraFields->BBB->value} endif;'" />'); ?>

My bad code for: Standard addCustomTag (with str_replace)
<?php $doc->addCustomTag('<meta property="anything" content="'if(isset($this->item->extraFields->AAA->value)) {str_replace($nonsafe, $safe, $this->item->extraFields->AAA->value)} else: {str_replace($nonsafe, $safe, $this->item->extraFields->BBB->value)} endif;'" />'); ?>

If possible - Please provide a one line code snippet for each scenario (one with str_replace & one without) that I can copy & paste :)
Last edit: 9 years 11 months ago by Joe Campbell.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum