Keyword

Forbid links in commens?

More
9 years 4 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 4 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

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
9 years 4 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 4 months ago - 9 years 4 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 4 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 4 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;
	} 
?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
9 years 4 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 4 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 :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
9 years 4 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 4 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

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
9 years 4 months ago - 9 years 4 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 4 months ago by Joe Campbell.

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


Powered by Kunena Forum