Strip html tag pada teaser di Drupal 7

Discussion in 'Drupal' started by Dan, Feb 13, 2013.

  1. Dan

    Dan Forum Bot

    Joined:
    Dec 4, 2012
    Messages:
    1,316
    Likes Received:
    257
    Trophy Points:
    83
    Google+:
    Pada forum ini, saya menghilangkan anchor tag pada semua teaser, ini dilakukan supaya meminimalisir abuse yang dilakukan oleh para anggota misal sengaja meletakkan link tertentu pada teaser karena teaser-lah yang diambil pada halaman index seperti pada frontpage, serta tracker. Saya menggunakan template.php, berikut kode yang dipakai:


    Code:
    /**
    * Override or insert variables into the node template.
    */
    function theme_preprocess_node(&$variables) {
      // Strip html tag.
      if(isset($variables['content']['body'][0]['#markup']) && $variables['teaser']) {
        $variables['content']['body'][0]['#markup'] = strip_only($variables['content']['body'][0]['#markup'], '<a>');
      }
    }
    
    /* Strip only selcted tags in theme_preprocess_node function above */
    function strip_only($str, $tags) {
        if(!is_array($tags)) {
            $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
            if(end($tags) == '') array_pop($tags);
        }
        foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
        return $str;
    }
    
     
  2. Jumbulen

    Jumbulen Guest

    Waduh mas, pusing lihat

    Waduh mas, pusing lihat kodenya *wacko*
     
  3. Dan

    Dan Forum Bot

    Joined:
    Dec 4, 2012
    Messages:
    1,316
    Likes Received:
    257
    Trophy Points:
    83
    Google+:
    Sudah ada di Drupal API

    Itu hanya sedikit sih, lagian semua juga sudah ada di Drupal API. *biggrin*

    Postingan hanya untuk ngejar domain authority.
     
  4. Fahmi

    Fahmi Newbie

    Joined:
    Dec 5, 2012
    Messages:
    1,719
    Likes Received:
    159
    Trophy Points:
    63
    Google+:
    ini settingan function

    ini settingan function template ya mas ? boleh tau contohnya menaruuh anchor tag pada teaser ? maksudnya apa yaah ?
     
  5. Dan

    Dan Forum Bot

    Joined:
    Dec 4, 2012
    Messages:
    1,316
    Likes Received:
    257
    Trophy Points:
    83
    Google+:
    Anchor maksudnya link

    Anchor maksudnya link *biggrin*
     
  6. Fahmi

    Fahmi Newbie

    Joined:
    Dec 5, 2012
    Messages:
    1,719
    Likes Received:
    159
    Trophy Points:
    63
    Google+:
    Dan wrote:

    hahaha iyaalah link.. maksudnya naro link di body gitu ? :D
     
  7. Dan

    Dan Forum Bot

    Joined:
    Dec 4, 2012
    Messages:
    1,316
    Likes Received:
    257
    Trophy Points:
    83
    Google+:
    Ini malah menghilangkan tag

    Ini malah menghilangkan tag
    Code:
    <a>
    
    -nya supaya diclick tidak bisa, sewaktu-waktu bisa saja nanti artikel keseluruhan anchornya dihilangkan kalau terlalu banyak spam *biggrin*
     
  8. Fahmi

    Fahmi Newbie

    Joined:
    Dec 5, 2012
    Messages:
    1,719
    Likes Received:
    159
    Trophy Points:
    63
    Google+:
    Dan wrote:

    mudah-mudahan jangan ada yang spamming disini *acute*
     
  9. Dan

    Dan Forum Bot

    Joined:
    Dec 4, 2012
    Messages:
    1,316
    Likes Received:
    257
    Trophy Points:
    83
    Google+:
    Yang menilai Google

    yang menilai spam nantinya Google sih, misal forum ini ke banned ya mau ngga mau harus tegas juga, tapi ada tahapan sebelum itu yaitu kasih nofollow untuk artikelnya dulu tapi signaturenya masih dofollow *biggrin*
     
  10. samuel

    samuel Member

    Joined:
    Feb 5, 2013
    Messages:
    478
    Likes Received:
    15
    Trophy Points:
    18
    Google+:
    ya hati"

    hati" juga iya tuh takut nya ada yg spam, harus ditertibkan kalo ada spam *dirol*
     
  11. profhariz

    profhariz Member

    Joined:
    Jun 25, 2013
    Messages:
    86
    Likes Received:
    1
    Trophy Points:
    8
    Google+:
  12. AhmadWafa

    AhmadWafa Member

    Joined:
    Oct 2, 2013
    Messages:
    870
    Likes Received:
    16
    Trophy Points:
    18
    Google+:
    Koding oh koding, kapan saya bisa pinter ma koding yah . . . *berkeringat*
     
  13. Devita

    Devita Active Member

    Joined:
    Oct 11, 2014
    Messages:
    1,196
    Likes Received:
    43
    Trophy Points:
    48
    Google+:
    Waduh, kalau ngeliat koding kayak gitu masih belim nyantol dipikiran.
     
  14. abu albani

    abu albani Member

    Joined:
    Oct 31, 2014
    Messages:
    69
    Likes Received:
    8
    Trophy Points:
    8
  15. heru.permana19

    heru.permana19 New Member

    Joined:
    Nov 24, 2015
    Messages:
    17
    Likes Received:
    1
    Trophy Points:
    3
    waduh.. apa ini
    sy coba pahami dl mas
     

Share This Page