Advertisement:

Author Topic: [Tutorial] Add nofollow in item description  (Read 4364 times)

AdsGig

  • Jr. Member
  • **
  • Posts: 72
[Tutorial] Add nofollow in item description
« on: September 15, 2013, 05:44:59 am »
create a file external_nofollow.php and put these file in your theme folder
Code: [Select]
<?php

function enofollow($content)
{
return preg_replace_callback('/<a[^>]+/''callback'$content);
}

function 
callback($matches)
{
$link $matches[0];
$site_link 'http://' $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

if (strpos($link'rel') === false) {
$link preg_replace("%(href=\S(?!$site_link))%i"'rel="nofollow" $1'$link);
} elseif (preg_match("%href=\S(?!$site_link)%i"$link)) {
$link preg_replace('/rel=\S(?!nofollow)\S*/i''rel="nofollow"'$link);
}

return $link;
}

?>


In your theme folder open item.php. Filename depends on your theme and add these on top part
Code: [Select]
require_once('external_nofollow.php');
On item.php look for these 
Code: [Select]
<?php echo(osc_item_description(); ?> and change to
Code: [Select]
<?php echo enofollow(osc_item_description()); ?>
hope to help thanks :)

byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
Re: [Tutorial] Add nofollow in item description
« Reply #1 on: September 15, 2013, 07:53:44 am »
Thankyou....

Very usefull tutorial. But osclass use HTML Purifier.
« Last Edit: September 15, 2013, 08:38:53 am by byteGator »

AdsGig

  • Jr. Member
  • **
  • Posts: 72
Re: [Tutorial] Add nofollow in item description
« Reply #2 on: September 16, 2013, 07:36:16 am »
Thanks @byteGator, how can we use HTML Purifier for this implementation ?  :)

Aficionado

  • Guest
Re: [Tutorial] Add nofollow in item description
« Reply #3 on: September 16, 2013, 07:35:52 pm »
If used with Rich editor (everybody is), then some modification in rich_edit.js takes care of it (along with open the Link to a NEW Window).

No need for any other modification.

Code: [Select]

    tinyMCE.init({
        mode : "none",
        theme : richedit.theme,
        skin: richedit.skin,
        width: richedit.width,
        height: richedit.height,
skin_variant : richedit.skin_variant,
theme_advanced_buttons1 : richedit.theme_advanced_buttons1,
        theme_advanced_buttons2 : richedit.theme_advanced_buttons2,
        theme_advanced_buttons3 : richedit.theme_advanced_buttons3,
        theme_advanced_toolbar_align : "left",
        theme_advanced_toolbar_location : "top",
extended_valid_elements : "a[href|target=_blank|rel=nofollow]",
entity_encoding : "raw",  // needed for non-us languages
        plugins : richedit.plugins,
force_br_newlines : true,
        force_p_newlines : false,
        forced_root_block : '' // Needed for 3.x
    });
   
    $(document).ready(function () {
        $("textarea[id^=description]").each(function(){
            tinyMCE.execCommand("mceAddControl", true, this.id);
        });
    });



AdsGig

  • Jr. Member
  • **
  • Posts: 72
Re: [Tutorial] Add nofollow in item description
« Reply #4 on: September 17, 2013, 07:39:06 am »
If used with Rich editor (everybody is), then some modification in rich_edit.js takes care of it (along with open the Link to a NEW Window).

No need for any other modification.

Code: [Select]

    tinyMCE.init({
        mode : "none",
        theme : richedit.theme,
        skin: richedit.skin,
        width: richedit.width,
        height: richedit.height,
skin_variant : richedit.skin_variant,
theme_advanced_buttons1 : richedit.theme_advanced_buttons1,
        theme_advanced_buttons2 : richedit.theme_advanced_buttons2,
        theme_advanced_buttons3 : richedit.theme_advanced_buttons3,
        theme_advanced_toolbar_align : "left",
        theme_advanced_toolbar_location : "top",
extended_valid_elements : "a[href|target=_blank|rel=nofollow]",
entity_encoding : "raw",  // needed for non-us languages
        plugins : richedit.plugins,
force_br_newlines : true,
        force_p_newlines : false,
        forced_root_block : '' // Needed for 3.x
    });
   
    $(document).ready(function () {
        $("textarea[id^=description]").each(function(){
            tinyMCE.execCommand("mceAddControl", true, this.id);
        });
    });



Thanks aficionado,   am i correct that these will affect only newly created ads?

Aficionado

  • Guest
Re: [Tutorial] Add nofollow in item description
« Reply #5 on: September 17, 2013, 12:37:46 pm »

Thanks aficionado,   am i correct that these will affect only newly created ads?

Yes only for new ads. Correct.


sigivr

  • Sr. Member
  • ****
  • Posts: 471
Re: [Tutorial] Add nofollow in item description
« Reply #6 on: September 21, 2013, 09:21:09 pm »
Sorry but what is this for? I didnt get it :P

Aficionado

  • Guest
Re: [Tutorial] Add nofollow in item description
« Reply #7 on: September 21, 2013, 09:22:48 pm »
Sorry but what is this for? I didnt get it :P

Osclass links in the ads should have been nofollow and probably open to a new window.


AdsGig

  • Jr. Member
  • **
  • Posts: 72
Re: [Tutorial] Add nofollow in item description
« Reply #8 on: September 23, 2013, 12:16:26 pm »
so there you go guys you have 2 solutions here.

If you have an existing ads site then i think you can follow mine but if you're site is just new then Aficionado got some solutions for that :)

Aficionado

  • Guest
Re: [Tutorial] Add nofollow in item description
« Reply #9 on: September 23, 2013, 05:04:14 pm »
There is also something else that needs to be taken care of.

Custom Fields if they are a URL.

To make them nofollow and to open to a new windows.

Changes in hitems.php and the following code (from Osclass 3.1 maybe the lines are different, but you get the idea where to ADD the "rel="nofollow external" target="_blank").

in function osc_item_meta_value()

Code: [Select]

else if($meta['e_type']=="URL") {
            if(osc_field(osc_item_meta(), 's_value', '')!='') {
                if(stripos(osc_field(osc_item_meta(), 's_value', ''),'http://')!==false || stripos(osc_field(osc_item_meta(), 's_value', ''),'https://')!==false) {
                    return '<a href="'.htmlentities(osc_field(osc_item_meta(), 's_value', ''), ENT_COMPAT, "UTF-8").'" rel="nofollow external" target="_blank">'.htmlentities(osc_field(osc_item_meta(), 's_value', ''), ENT_COMPAT, "UTF-8").'</a>';
                } else {
                    return '<a href="http://'.htmlentities(osc_field(osc_item_meta(), 's_value', ''), ENT_COMPAT, "UTF-8").'" rel="nofollow external" target="_blank">'.htmlentities(osc_field(osc_item_meta(), 's_value', ''), ENT_COMPAT, "UTF-8").'</a>';
                }
            } else {
                return '';




« Last Edit: September 23, 2013, 05:07:57 pm by Aficionado »

Diviyah

  • Newbie
  • *
  • Posts: 17
Re: [Tutorial] Add nofollow in item description
« Reply #10 on: June 09, 2014, 07:44:20 pm »
Thanks for the solution.

I have consolidated NOLink solution for custome url and HTMLPurified at http://forums.osclass.org/3-3-x/nofollow-external-links-for-classified/msg98122/#msg98122

It works in https://adzhome.com