Home arrow News - Articles arrow Behind the Scene arrow Clas-class php yang sederhana, berguna, dan tahan lama
 
  XnRnXZvLpO www.danielhp.com
Clas-class php yang sederhana, berguna, dan tahan lama PDF Print E-mail
Written by Administrator   
Saturday, 29 November 2008

Di dunia pemrograman php, hampir semua class yang kita butuhkan sudah dibuatkan oleh seseorang atau beberapa orang yang baik hati. Dengan mudah kita dapat menggunakannya dan bahkan memodifikasinya. Jujugan terbaik kalau untuk mencari class-class php adalah www.phpclasses.org, walau tampilannya sederhana dan agak aneh, tapi website ini menyimpan ribuan class dengan berbagai fungsi dari seluruh programmer php terbaik dunia. Nah, ini adaah class-class pilihan yang penggunaannya mudah dan cukup sering dicari-cari sebagai pelengkap  website kita.

 


 

A.     Datepicker

 

Biasanya kalau ada suatu input untuk pengisian tanggal, kita sedikit kesulitan untuk merancangnya. Yang sering dilakukan adalh dengan textbox biasa yang dibagi menjadi DD MM YY.  Sebenarnya ada pilihan yang lebih menarik, yaitu dengan menaruh sebuah object yang jika diklik suatu tombol akan memunculkan bentuk seperti tampilan sebuah calendar. Di calendar ini user tinggal klik pada hari dimana dia ingin pakai sebagai input.

Datepicker ini ada banyak pilihan yang bisa digunakan salah satunya adalah class datepicker yang dibuat oleh Stefan Gabos This e-mail address is being protected from spam bots, you need JavaScript enabled to view it .

 

Cara penggunaannya, setelah didownload (datepicker-2006-09-04.zip) , extractlah ke folder anda. Kayaknya akan lebih mudah jika kemudian kita rename agar namanya agak manusiawi, misal jadi datepicker saja. Nah kemudian buat code untuk menggunakannya, seperti contoh dibawah

 

<?php

    require "datepicker/class.datepicker.php";

   

    $db=new datepicker();

    // set format

    $db->dateFormat = "m/d/Y";

?>

Tanggal:

    <input type="text" id="date">

    <input type="button" value="..." onClick="<?=$db->show("date")?>">

 

 

yang jika dijalnkan akan berbentuk seperti gambar dibawah:

 

 

Format tanggal bisa diubah, misal jika ‘d M Y’ akan keluar 11 Mar 2008.

 

 

B.     Text editor

 

Ingat saat bikin content di joomla? Nah disitu ada editor yang cukup bagus, fasilitasnya lengkap tinggal klik-klik saja. Jika anda membuat web sendiri dan ingin untuk nulisnya menggunakan editor seperti yang di joomla ini, caranya sangatllah mudah. Kita pakai saja class tinymce yang sama dengan yang digunakan joomla.

 

Pertama setelah di download, diextract, missal ke folder tinymce dalam folder anda. Kemudian coba kita pakai secara full tombol-tombolnya dikeluarkan semua. Editor ini menghasilkan suatu text html, dimana nanti text html ini akan disimpan ke dalam database. Tapi dalam contoh ini text htmlnya kita tampilkan dibawahnya. Code-nya adalah sebaga berikut:

 

 

<!-- TinyMCE -->

<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script type="text/javascript">

            tinyMCE.init({

                        // General options

                        mode : "textareas",

                        theme : "advanced",

                        plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

 

                        // Theme options

                        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",

                        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",

                        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",

                        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",

                        theme_advanced_toolbar_location : "top",

                        theme_advanced_toolbar_align : "left",

                        theme_advanced_statusbar_location : "bottom",

                        theme_advanced_resizing : true,

 

                        // Example content CSS (should be your site CSS)

                        content_css : "css/content.css",

 

                        // Drop lists for link/image/media/template dialogs

                        template_external_list_url : "lists/template_list.js",

                        external_link_list_url : "lists/link_list.js",

                        external_image_list_url : "lists/image_list.js",

                        media_external_list_url : "lists/media_list.js",

 

                        // Replace values for the template plugin

                        template_replace_values : {

                                    username : "Some User",

                                    staffid : "991234"

                        }

            });

</script>

<!-- /TinyMCE -->

 

<form action="essen.php"  method="post">

<textarea id="content" name="content" rows="15" cols="80" style="width: 80%">

           

</textarea>

<input type="submit" value="simpan" name="simpan" />

</form>

<? if($_POST['simpan']) echo stripslashes($_POST['content']); ?>

 

 

Contoh dari tampilan tinymce adalah seperti dibawah

 

 

 

 

C.     Captcha

 

   Mulai beberapa tahun lalu, saat kita register di suatu website, pasti ada input yang harus dimasukkan isi sesuai gambar yang terlihat. Gambar ini bertujuan agar yang register adalah benar manusia, bukan mesin program yang dengan tujuan tertentu seperti spaming. Gambar ini dinamakan Captcha. Ada banyak pilihn library captcha, disini kita menggunakan php5captcha. Setalh didownload, extract isinya ke folder misal captcha dan siap untuk digunakan. Cukup simpel cara penggunaannya:

 

Pertama buat 1 file untuk menampilkan captcha, missal file capview.php, dengan isi:

 

<?

include 'captcha/Captcha.php';

//session dan font yg digunakan

$options['sessionName'] = 'chachacha';

$options['fontPath'] = 'captcha';

$options['fontFile'] = 'anonymous.gdf';

//besarnya gambar

$options['imageWidth'] = 150;

$options['imageHeight'] = 50;

//karakter yg muncul

$options['allowedChars'] = 'ABCDEF1234567890';

//panjang string dan lebar tiap karakter

$options['stringLength'] = 4;

$options['charWidth'] = 40;

//besarnya blur

$options['blurRadius'] = 3.0;

$options['secretKey'] = 'rahasia';

 

$captcha = new Captcha($options);

$captcha->getCaptcha();

?>

 

 

kemudian di halaman utama, missal halaman pendaftaran atau komentar user, ditaruhlah kode2 dibawah. Sebagai catatan, setting untuk captcha pada  saat menampilkan dan pengecekan harus disamakan.

 

<form action="essen.php" method="post">

tulis karakter <input type="text" name="inputcap" /><img src="capview.php" />

<input type="submit" value="simpan" name="cekcap" />

<?

if($_POST[cekcap])

{

include 'captcha/Captcha.php';

//session dan font yg digunakan

$options['sessionName'] = 'chachacha';

//karakter yg muncul

$options['allowedChars'] = 'ABCDEF1234567890';

//panjang string

$options['stringLength'] = 4;

$options['secretKey'] = 'rahasia';

$captcha = new Captcha($options);

if($captcha->isKeyRight($_POST['inputcap']))

{

 echo "betul";

}

else

{

  echo "salah";

}

}

?>

 

tampilannya adalah seperti gambar dibawah:

 

 

 

 

D. Thumbnailing

 

Beberapa website kadang mempunyai fasilitas untuk menampilkan foto. Foto yang ditampilkan awalnya biasanya berupa thumbnail baru setelah foto thumbnail diklik, keluarlah foto dengan ukuran sebenarnya. Untuk keperluan ini biasanaya user membuat 2 versi foto yaitu versi besar dan versi kecil. Tapi cara ini hanya berlaku untuk website dengan foto yg sedikit dan jarang diupdate. Jika web dengan foto yang banyak dan sering diupdate, misal web fotografi, maka thumbnail dilakukan secara otomatis melalui suatu fungsi. Fungsi untuk membuat thumbnail sangatlah banyak, disini akan digunakan easythumbnail. Cara penggunaannya sangatlah mudah, tinggal mengisikan file gambar yang ingin di thumbnail dan nama file thumbnailnya.

 

 

<?

include("easythumbnail/easythumbnail.class.php");

$thumb= new EasyThumbnail("ym.JPG", "mini.jpg", 120);

?>

Sebelum<img src="ym.JPG"><br />

Sesudah<img src="mini.jpg">

 

Contoh tampilannya adalah seperti dibawah:

 

 

E. Excel

 

Kadang pada beberapa kasus, user suatu website juga sering menggunakan excel dan tetap terus ingin menggunakan excel disamping website yang telah dibuatkan. Yang sering adalah report dapat diexport ke file excel. Permintaan yang lain adalah mengupload data, tapi dengan isi dari excel. Biasanya karena dengan excel user bisa mengerjakan sendiri di rumah data2 yang diperlukan tanpa connect ke internet, kemudian baru dikantor diupload agar masuk ke website.

 

   - Export to Excel

     Report ke excel tidak membutuhkan library apapun, tinggal merubah tipe dokumen saja. dapat dilakukan dengan cara menambahkan  2 baris berikut:

 

header("Content-Type: Application/vnd.ms-excel");

header("Content-Disposition: attachment; filename=Namafile.xls");

 

Biasanya digunakan dengan suatu parameter, jadi jika diklik logo excel misalnya, tetap memanggil halaman yang sama, tapi dengan parameter misal  ?excel=1

Nanti diawal codenya diberi  if($_GET[excel])

 

 

     perlu dicatat, tidak boleh ada satu tag html-pun, termasuk spasi dan enter yang mendahului fungsi diatas. source php boleh ada sepanjang dia tidak mengeluarkan tag html seperti penggunaan echo atau print.

 

   - Import dari excel

     Apabila kita ingin mengambil data dari excel kemudian ingin digunakan, misal dimasukkan ke database, maka yang perlu dilakukan adalah mengupload file excel tersebut, kemudian dengan library tertentu membaca file tersebut, membaca sheet tertentu, dan cell2 tertentu didalamnya. Library yang bisa digunakan cukup banyak. Tinggal cari di httP://www.phpclasses.org tentang 'read excel' (bisa juga untuk fungsi2 lain) dan pilih salah satu library yang sudah dibuatkan oleh orang-orang baik hati dari seluruh dunia.

Salah satunya adalah phpread yang memanfaatkan COM object lewat oleread.inc. Contoh penggunaannya seperti dibawah:

 

<?php

require_once 'Excel/reader.php';

$data = new Spreadsheet_Excel_Reader();

//buka file

$data->read('FILEEXCEL.xls');

//looping untuk semua row pada sheet 1 (index 0)

for ($j = 1; $j <= $data->sheets[0]['numRows']; $j++)

{

  //tampilkan isi kolom A (index 1)

  echo $data->sheets[0]['cells'][$j][1];

  echo '<br>'; 

 //tampilkan isi kolom B (index 2)

  echo $data->sheets[0]['cells'][$j][2];

 ----

 ---- dst

}

           

?>

 

 

 

 

 

 

 

 

F.      Tab

 

Banyak website sekarang yang menggunakan bentuk Tab dialog dalam navigasi-nya. Salah satu website yang terkenal dan berbentuk tab dialog adalah paypal. Class berikut ini digunakan untuk membuat tampilan tab seperti paypal (tapi yang versi sebelum sekarang J ). Nama class-nya adalah paypal tab. 

 

Setelah di download , extract ke folder tertentu, misal folder tab.  Disini akan dicontohkan kita mempunyai 3 halaman php yaitu halaman1.php, halaman2.php, dan halaman3.php.  Masing-masing source-nya diisikan seperti berikut:

 

Halaman1.php

<?

// pake class0nya

require_once("tab/paypaltabs.class.php");

//buat item tabnya

$tabs_items  = array(    'Halaman1'=>'halaman1.php',

                                    'Halaman2'=>'halaman2.php',

                                    'Halaman3'=>'halaman3.php',

);

//lokasi images

$tab_images_url = "tab";

//create tabnya

$tabs = new PayPalTabs($tabs_items,$tab_images_url);

//tampilkan dengan halaman1 terselect

$tabs->ShowTabs('Halaman1');

?>

 

Halaman2.php, dan halaman3.php isinya sama dengan halaman1.php diatas, tapi dengan baris terakhir diubah sesuai nama halaman yang sekarang aktif.

 

Tampilannya akan seperti dibawah:

Comments
Search
Anonymous (122.139.62.xxx) 2009-05-27 01:43:12

cheap wow power leveling cheapest wow power leveling my wow gold buy wow gold replica replica rolex CHEAP wow power level BUY power leveling replica rolex replica CHEAPEST power leveling MY wow power level
cheap rs gold
good BUY wow gold
replica rolex
CHEAPEST wow gold
cheap lotro gold
buy wow gold
my wow gold
cheapest wow gold
CHEAP wow gold zmc
Anonymous (125.113.172.xxx) 2009-08-17 03:28:38

Are you a wholesaler? Have you ever been to China? Did you buy wholesale products direct from Chinese wholesalers? China wholesale, wholesale from China. The Yiwu market is the world's largest wholesale market of promotional gifts, dollar items, shoes wholesale and other wholesale lots. China Amanda is based in Yiwu, your best wholesale source and professional Yiwu Agent. Welcome to attend Yiwu Fair.
sajiannn (125.70.56.xxx) 2009-09-22 00:49:22

Officials saidwow goldforensic evidence atwow goldthe fire's point ofwow goldorigin revealed thatwow goldthe wildfirewow goldamong the largest wow goldin Southern California'swow goldhistory — was an actwow goldof arson.wow gold Whitmore declined
sajiannn (125.70.56.xxx) 2009-09-22 00:50:41

The two firefightersdofus kamaskamas dofusacheter dofusacheter kamasdied Sunday whendofus kamaskamas dofustheir truck careeneddofus kamaskamas dofusacheter kamasoff a steep mountain road.dofus kamaskamas dofusachat kamasLos Angeles Countydofus kamaskamas dofusacheter kamasFire Deputy Chiefdofus kamaskamas dofusacheter des kamasMike Bryant said he wasdofus kamaskamas dofusbuy kamasglad investigatorsdofus kamaskamas dofuswere making progress,
sajiannn (125.70.56.xxx) 2009-09-22 00:52:47

Sept. 11 (Bloomberg)world of warcraft goldcheap wow goldwow orwow power levelingIran said it wantswow poachat gold wowwow levelingtalks about the futurewow orwow gold cheapbuy wow goldof the Palestinianworld of warcraft goldwow gold cheapwow levelpeople and wow geldwow gold kaufenwow powerlevelingreform of the United wow gold buywow gold cheapwow levelingNations Securityworld of warcraft goldwow powow orbuy wow goldCouncil to be tied tocheap wow goldwow power levelingwow powerlevelingany discussion Lord of the Rings Online GoldLOTRO GoldLOTR Goldof nuclear proliferationflyff moneyflyff penyabuy flyff goldin the Middle East.ffxi gilbuy ffxi gilFinal Fantasy XI gil“Security requiresbuy Warhammer goldWarhammer goldreorganization andEverQuest 2 goldeq2 platcreating an opportunityworld of warcraft goldwow powow orfor broad and buy wow goldcheap wow goldwow power levelingwow powerlevelingcollective participationLord of the Rings Online GoldLOTRO GoldLOTR Goldin the management offly for fun
sajiannn (125.70.56.xxx) 2009-09-22 00:53:46

Foreign Ministerworld of warcraft goldwow power levelcheap wow goldManouchehr Mottaki wow power levelingwow powerlevelingbuy wow goldpresented the plan infinal fantasy gilcheap ffxi gilffxi gilTehran on Sept. 9. OfficialsMaple Story Mesosmaplestory MesosMaple Story mesofrom the six nations receivingLOTRO GoldLOTR Goldlord of the rings goldthe proposal met thisrunescape goldrunescape moneyrs moneymonth in Frankfurt to EverQuest 2 goldeq2 platdiscuss Iran’s nuclearflyff penyaflyff hack penyaflyff moneyprogram. The proposals
respond
KristinMAYNARD26 (193.41.185.xxx) 2010-02-27 02:54:53

That's good that people are able to get the loans and that opens up new chances.
Women
Buy Ugg Boots (125.78.240.xxx) 2010-02-27 07:41:09

With all the
boots [url=http://www.zhjugg.com/new-product-ugg-bailey- 

button-58
03-grey-boots-p-]UGG Bailey Button Grey[/url] included in Ugg


Australia’s Classic Collection range the Bailey
chenwei
Button
is lined ugg cardy

oatmeal with twin faced Grade A sheepskin.
Also there is the

UGG Bailey Button traditional

suede heel guard to ensure that not only

is this area
protected but offers this part of the boot support.

Ugg Cardy Boots Plus within the

boots you find each pair has sock liners

that are
made from sheepskin PU foam so increasing the level of

Ugg Cardy comfort a person feels

when wearing them.
激安 ユニフォ&
激安 ユ| (220.161.165.xxx) 2010-02-27 09:02:42

LCZ 
読売巨人軍は 、ビ
;ジターゲ&# 12540;ムで着用&
#12377;  427;夏季限定のӎ 0;|
69;マービジタ ーユニホ
;ーム&# 12301;を 採用しま
2377;。ユニフォーム...このユニ

ホӦ 0; ムの
発表会見&# 12364;12日(&#
26376;A 289;、東京・大৔ 3;ஹ
0;の球団事務 所で開か
れ、&# 12481;ームを代表  
375;て 坂本勇人選手&# ...
Paul Smith (220.161.165.xxx) 2010-02-27 09:22:33

Our store offer the cheap paul smith for you,sale new Paul Smith Shoes,and we will give my best server to you.Come on, more order will get more
discount.You can not miss them!rlh
MBT Shoes
mbt uk (220.161.165.xxx) 2010-02-27 10:15:06

When you purchase Mbt shoes you achieve shoes that appeal mbt shoes to your sense of style while insuring a shoe that does not cause pain and
discomfort after a day mbt trainers shoes of being on your feet. And after your purchase you know you have shoes
that are going to outlast shoes found in most stores. Created for
comfort and long lasting, MBT shoes utilize the highest quality
leather and materials. If you experience mbt uk discomfort from your foot perspiring during the day MBT Shoes applies a
sock lining in the lining of the shoe where you foot rests. mbt shoe This allows your feet to stay dry during the most challenging active
days.hlm
nike-shox (125.78.242.xxx) 2010-02-27 16:40:48

rr
Today, the nike shox basketball shoes

are popular around the world. wholesale nike shox shoes

started out as an American company, but have since expanded around the
globe. They're now available in 120 countries. shox r4

with an emphasis on walking shoes, the engineers at New Balance know
the importance of a proper fit and offer a wide range of widths
and sizes. Often recommended by podiatrists, nike running shoes

take an "endorsed by no one" stance, preferring to let their
technology and comfort sell their shoes instead of paying a
celebrity athlete to do it for them. Additionally, nike shox monster

are available in a variety of styles, each designed for different
needs-motion control, extra support, off road, use etc. New Balance
makes running, walking, tennis, cross-training and basketball shoes
for men and women, and also offers a line of kids' ...
timberland (220.161.165.xxx) 2010-02-27 17:05:45

mm Apparently, 21,000 boots imported by Timberland from Thailand have lead paint on the insole, violating federal lead paint
rules. I'm guessing this paint was used for printing of the
logo inside the boot. Please note Dear Readers, these are Timberland waterproof and children are particularly sensitive to the effects of lead and lead
poisoning. Avoid a lead paint accident that could injure or hurt
your child.
When I first saw this I thought, "How do you make Timberland work boots? Where's the risk of accident or injury?" Then I read further and saw,
"lead paint." The headline reads:"Timberland Recalls Timberland for kids Due to Violation of Lead Paint Standard"The U.S. Consumer Product
Safety Commission announced a voluntary recall of these boots.
Consumers should stop using recalled products immediately.
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
Next >
 
 
(C) 2010 daniel hary prasetyo
Free Joomla Template designed by funky-visions.de
 

articles (a-z order)