Catatan Skrip untuk Web Development


Image

htaccess untuk Rewrite URL (versi CMS Lokomedia)

<IfModule mod_rewrite.c>

RewriteEngine On

 

RewriteRule ^home$ main.php?module=home [L]

RewriteRule ^news-([0-9]+)-(.*)\.html$ main.php?module=news&id=$1 [L]

RewriteRule ^page-news-(.*)-([0-9]+)\.html$ main.php?module=news&id=$1&page=$2 [L]

</IfModule>

 

htaccess untuk keperluan penting lainnya (keamanan & redirect karena error 404)

Options All -Indexes

ErrorDocument 404 http://localhost/404.php

 

 

Validasi Form dengan JavaScript

function validasi ( form )

{

        if ( form.name.value == ” ) {

                alert ( ‘You must fill your name!’ );

                form.name.focus();

                return ( false );

        }

        if ( form.email.value == ” ) {

                alert ( ‘You must fill your email address!’ );

                form.email.focus();

                return ( false );

        }

        return ( true );

}

 

 

Mengambil Hanya Sebagian Berita

$newscontent = strip_tags ( nl2br ( $r[‘news_content’] ) );

$newscontent = substr ( $newscontent, 0, 250 );

$newscontent = substr ( $newscontent, 0, strrpos($newscontent, ‘ ‘) );

 

 

Aturan Import CSS

@import url(mainmenu.css);

@import url(secondarymenu.css);

 

 

Fungsi untuk Menangkal SQL Injection

function anti_sql_injection ( $data )

{

         $filter = mysql_real_escape_string ( stripslashes ( strip_tags ( htmlspecialchars ( $data, ENT_QUOTES ) ) );

         return $filter;

}

 

 

Search Box dengan Hightlight Text

<input type=text name=”search_term” value=”Search…” onclick=”if(this.value==’Search…’) this.value=”” onblur=”if(this.value==”) this.value=’Search…'” />

 

 

Pencarian dengan Multiple Keyword

$search_term = trim ( $_POST[‘search_term’] );

$search_term = mysql_real_escape_string ( strip_tags ( $search_term ) );

$explode_text = explode ( ‘ ‘, $search_term );

$explode_count = count ( $explode_text );

 

$sql = ‘SELECT title, news_content, author, category FROM news WHERE ‘;

for ( $i = 0; $i < $explode_text; $i++ ) {

         $sql .= “news_content LIKE ‘%$explode_text[$i]%'”;

         if ( $i < ( $explode_count – 1 ) ) {

                 $sql .= ‘ OR ‘;

         }

}

$sql .= ‘ ORDER BY id_news DESC’;

 

 

Menyertakan Favican dan Icon RSS

// Favicon dapat berupa file *.ico atau *.png yang berukuran 16x16px, 32x32px, 64x64px

<link rel=”shortcut icon” href=”http://localhost/favicon.png&#8221; />

<link rel=alternate type=”application/rss+xml” title=”RSS 2.0″ href=”http://localhost/rss.xml&#8221; />

 

 

Generate RSS

$rss = mysql_query ( ‘SELECT id_news, title, news_content FROM news ORDER BY id_news DESC LIMIT 10’ );

$file = fopen ( ‘rss.xml’, ‘w’ );

 

fwrite ( $file, ‘<?xml version=”1.0″?>

         <rss version=”2.0″>

         <title>RSS 2.0</title>

         <link>http://localhost/</link&gt;

         <description>Welcome to RSS Service. You can subscribe these our recent news:</description>

         <language>en-us</language>’ );

 

while ( $r = mysql_fetch_array ( $rss ) ) {

         $newscontent = htmlentities ( strip_tags ( nl2br ( $r[‘news_content’] ) ) );

         $newscontent = substr ( $newscontent, 0, 250 );

         $newscontent = substr ( $newscontent, 0, strrpos ( $newscontent, ‘ ‘ ) );

 

 

         fwrite ( $file, “<item>

                <title>$r[title]</title>

                <link>http://localhost/news-$r%5Bid_news%5D-$r%5Btitle_seo%5D.html</link&gt;

                <description>$newscontent</description>” );

}

 

fwrite ( $file, ‘</channel>

        </rss>’ );

fclose ( $file );

 

 

jQuery untuk Membuat Slideshow Headline

var timer = null;

 

function openContent ( trigger, divID )

{

         $(‘#divTrigger a’).each(

                 function () {

                       $(this).css({

                             ‘background-color’ : ‘#900’,

                             ‘color’ : ‘#fff’

                       });

                }

         );

         $(trigger).css({

                 ‘background-color’ : ‘#fc0’,

                 ‘color’ : ‘#000’

         });

 

         $(‘#divContent div’).hide();

         $(‘#’ + divID).fadeIn(‘slow’);

 

         if(timer != null) clearTimeout(timer);

         timer = setTimeout (

                 function () {

                       var nextAnchor = ( $(trigger).next(‘a’).text() == ” ) ? $(‘#divTrigger a:first’) : $(trigger).next();

                       nextAnchor.click();

                 }, 5000

         );

}

One thought on “Catatan Skrip untuk Web Development

  1. eko rozpek 13 April 2012 / 01:49

    asik

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s