<?php
function check_html($string,$res=""){
if($res==""){
$string=htmlspecialchars ($string);
$string = ereg_replace("\n","<br>",$string);
$string = ereg_replace("\[b\]","<b>",$string);
$string = ereg_replace("\[/b\]","</b>",$string);
$string = ereg_replace("\[i\]","<i>",$string);
$string = ereg_replace("\[/i\]","</i>",$string);
$string = ereg_replace("\[u\]","<u>",$string);
$string = ereg_replace("\[/u\]","</u>",$string);
$string = ereg_replace("\[codigo\]","<font class=codigo>",$string);
$string = ereg_replace("\[fincodigo\]","</font>",$string);
$string = ereg_replace("\[link\]","<a href=\"",$string);
$string = ereg_replace("\[sep\]","\">",$string);
$string = ereg_replace("\[/link\]","<\a>",$string);
return($string);
}else{
$string=htmlspecialchars($string);
return($string);
}
}
?> R10 PHP Kod Bankası (Güncel)
61
●9.240
- 14-04-2008, 00:12:01Üyeliği durdurulduBBkod fonksiyonu:
- 14-04-2008, 00:12:56Üyeliği durduruldu
function file_size($file){ $size=filesize($file); if($size >= 1073741824){ $size=round($size/1073741824)."Gb"; } elseif($size >= 1048576){ $size=round($size/1048576)."Mb"; } elseif($size >= 1024){ $size=round($size/1024)."Kb"; }else{ $size=$size. "b"; } echo "File size: <b>$size</b>" ; } file_size($file="index.php"); - 14-04-2008, 00:14:22Üyeliği durduruldu
function birdensuna($sayi,$maximum) { if ( $sayi >= 1 AND $sayi <= $maximum ) { return $sayi; } else { return $maximum; } } function sayfa_baglantilari($ana_baglanti,$sayfa_degiskeni,$eleman_sayisi,$sayfa_basina,$aktif_sayfa,$ekmi) { // Bu fonksiyon calismak icin birdensuna() fonksiyonunu gerektirir $sayfa_sayisi = ceil($eleman_sayisi/$sayfa_basina); if ( $aktif_sayfa < 1 OR $aktif_sayfa > $sayfa_sayisi ) { $aktif_sayfa = 1; } $sayfalar_araligi = ceil($sayfa_sayisi/20); // sayisi kucultuldukce baglanti sayisi azalir $sayfalanacak = array(1,$sayfa_sayisi,birdensuna(($aktif_sayfa-20),$sayfa_sayisi) ,birdensuna(($aktif_sayfa-15),$sayfa_sayisi),birdensuna(($aktif_sayfa-10),$sayfa_sayisi) ,birdensuna(($aktif_sayfa-5),$sayfa_sayisi),birdensuna(($aktif_sayfa-2),$sayfa_sayisi) ,birdensuna(($aktif_sayfa-1),$sayfa_sayisi),$aktif_sayfa ,birdensuna(($aktif_sayfa+1),$sayfa_sayisi),birdensuna(($aktif_sayfa+2),$sayfa_sayisi) ,birdensuna(($aktif_sayfa+5),$sayfa_sayisi),birdensuna(($aktif_sayfa+10),$sayfa_sayisi) ,birdensuna(($aktif_sayfa+15),$sayfa_sayisi),birdensuna(($aktif_sayfa+20),$sayfa_sayisi)); for ($i=$aktif_sayfa;$i>0;$i=$i-$sayfalar_araligi) { $sayfalanacak[] = $i; } for ($i=$aktif_sayfa;$i<$sayfa_sayisi;$i=$i+$sayfalar_araligi) { $sayfalanacak[] = $i; } $sayfalanacak = array_unique($sayfalanacak); sort($sayfalanacak); foreach ( $sayfalanacak as $sayfa_no ) { if ( $sayfa_no == $aktif_sayfa ) { echo "[$sayfa_no] "; } else { if ( $ekmi == 0 ) { echo "<a href=\"$ana_baglanti?$sayfa_degiskeni=$sayfa_no\">$sayfa_no</a> "; } else { echo "<a href=\"$ana_baglanti&$sayfa_degiskeni=$sayfa_no\">$sayfa_no</a> "; } } } }Örnek olarak:
sayfa_baglantilari("http://localhost/index.php","sayfa",2,1,2,0);şeklinde bir çağırma şöyle bir çıktı üretecektir. ( Sayfa bağlantılarıda verilmiş şekilde. )
1 [2]
ya da
sayfa_baglantilari("http://localhost/index.php","sayfa",500,10,1,0);şeklinde bir çağırma
[1] 2 3 4 6 7 10 11 13 16 19 21 22 25 28 31 34 37 40 43 46 49 50
şeklinde sayfa bağlantıları verilmiş halde bir çıktı üretecektir. - 14-04-2008, 00:15:01Üyeliği durduruldu
<?php // eski lirayi kuruslari olmadan ytl'ye cevirir function tl2ytl ($tl) { return floor($tl / 1000000); } // eski liranin kuruslarini yuvarlayarak bulur, en kucuk kurus birimi girilebilir function tl2yk ($tl , $enKucukKurus=1) { return (round ($tl/10000/$enKucukKurus) * $enKucukKurus) % 100; } // eski lirayi yeni liraya cevirir function ytl ($tl, $enKucukKurus=1) { $yk = tl2yk($tl, $enKucukKurus); while (strlen($yk)<2) $yk = "0" . $yk; return tl2ytl($tl) . "," . $yk . " YTL"; } ?> - 14-04-2008, 00:15:42Üyeliği durdurulduFTP'de Dosya Kontrolü
FTP'de dosya kontrolü yapan bu fonksiyonu belki günün birinde birine lazım olur diye koyuyorum buraya; olmaz olmaz demeyin bana lazım oldu mesela ondan yazdım
// cappytoi tarafından hazırlanmıştır :))) tepe tepe kullanın, geliştirin, dağıtın :)) // $ftpurl = dosyanın tam adresidir (örneğin: ftp://ftp.e-kolay.net/bilgisayar/oyun/gunviper/GunViper040.exe) // $ftp_kull kullanıcı adı $ftp_sif de sifredir, eğer kullanıcı adı ve sifre gereksizse bişey yazmayın // $ana_klasor acayip opsiyonel bir olay fakat bazı ftp sunucularında dosyalar public_html veya httpdocs altında olabiliyor. Bunu da onun için koydum. function ftp_dosya_bul ($ftpurl, $ftp_kull = "anonymous", $ftp_sif = "anonymous", $ana_klasor = 0) { $ftpurl = eregi_replace("ftp://","",$ftpurl); $ftpurl = explode("/",$ftpurl); $urlayirsayi = count($ftpurl); $dosyasayi = $urlayirsayi - 1; $dosya = $ftpurl[$dosyasayi]; $ftp_server = $ftpurl[0]; $conn_id = ftp_connect($ftp_server) or die("$ftp_server adresine bağlanamadı"); @ftp_login($conn_id, $ftp_kull, $ftp_sif); if ($ana_klasor != 0) { ftp_chdir($conn_id, $ana_klasor); } $i = 1; while ($i < $dosyasayi) { ftp_chdir($conn_id, $ftpurl[$i]); $i++; } $sorgu = ftp_size($conn_id, $dosya); // Dosya bulunamazsa $sorgu -1 değerini alıyor ftp_close($conn_id); return $sorgu; } - 14-04-2008, 00:17:10Üyeliği durdurulduArkadaşlar basit bir üyelik sistemi sınıfı gönderiyorum.
Bu üyelik sınıfı üye kaydı, bilgi güncelleme, giriş ve çıkışını kontrol ediyor.
Ancak 2 ayrı sınıfa daha bağımlılık duyuyor...
onları da ekte veriyorum....
Bunlardan kontrol sınıfı gerekli string kontrollerini yapıyor.
database sınıfı veritabanı işlemlerini yürütüyor.
database sınıfını Mambo Open Source'dan ayıkladım...
Ve gayet kullanışlı....
Kolay gele...
İlk önce database sınıfı gerekli şifrelerle mysql e bağlı olarak çağrılmalı!.
Üyelik sınıfı:
defined('_DOGRULUK_KONTROLU_YAPILDI') or die('Direk Erişim Yasaklandı.'); include_once("class.kontrol.php"); /** * yildizib@yahoo.com * İbrahim YILDIZ * * @version $1.0$ * @copyright Mart 2005 * bu class database classi ile birlikte tasarlandı.database * classı mambo open source dan alınabilir... */ class Uyelik{ var $_tabloadi = "uyeler"; var $_kuladialani = "kuladi"; var $_sifrealani = "sifre"; function UyeKayitEt(& $liste, $kuladi){ global $db; if(Kontrol :: BosMu($kuladi)) return -1; if(!Kontrol :: SadeceSayiVeHarfMi($kuladi))return -2; if($this -> UyeZatenKayitliMi($kuladi) != 0) return -3; if(!$db -> insertObject($this -> _tabloadi, $liste, null, null)){ // echo "Ekleme Hatası 0001"; return 0; } return 1; } function UyeProfilGuncelle($kuladi, & $liste){ global $db; if(Kontrol :: BosMu($kuladi)) return -1; $uyebilgileri = $this -> UyeBilgisiGetir($kuladi); if($liste -> id != $uyebilgileri -> id) return -2; if(!$db -> updateObject($this -> _tabloadi, $liste, "id", null)){ // echo "Ekleme Hatası 0001"; return 0; } return 1; } function UyeBilgisiGetir($kuladi){ global $db; if(Kontrol :: BosMu($kuladi)) return 0; $sql = "SELECT * FROM $this->_tabloadi WHERE $this->_kuladialani='$kuladi'"; $db -> SetQuery($sql); if(!$db -> loadObject($sonuc)) return -1; return $sonuc; } function UyeZatenKayitliMi($kuladi){ global $db; if(Kontrol :: BosMu($kuladi)) return -1; $sql = "SELECT * FROM $this->_tabloadi WHERE $this->_kuladialani='$kuladi'"; $db -> SetQuery($sql); if(!$db -> query()) return -2; if($db -> getNumRows() > 0)return 1; if($db -> getNumRows() == 0)return 0; return -3; } function SifreOnayiKontrol($sifre, $sifre_onayi){ if($sifre == $sifre_onayi) return 1; return 0; } function UyeGirisKontrol($kuladi, $sifre){ global $db; if(Kontrol :: BosMu($kuladi) || Kontrol :: BosMu($sifre)) return 0; $UyelikBilgisi = $this -> UyeBilgisiGetir($kuladi); if(!is_object($UyelikBilgisi)) return $UyelikBilgisi; $sifre_alani = "UyelikBilgisi->" . $this -> _sifrealani; if(${$sifre_alani} != $sifre)return -1; return 1; } function UyeOturumAcmaIslemleri($kuladi, $sifre){ global $db, $_SESSION; if(Kontrol :: BosMu($kuladi) || Kontrol :: BosMu($sifre)) return 0; $kontrol_sonucu = $this -> UyeGirisKontrol($kuladi, $sifre); if($kontrol_sonucu != 1)return $kontrol_sonucu; session_start(); $_SESSION["kuladi"] = $kuladi; return 1; } function UyeOturumKapamaIslemleri(){ global $_SESSION; $_SESSION["kuladi"] = ''; if(!session_destroy()) return 0; return 1; } } // end classkontrol sınıfı
defined('_DOGRULUK_KONTROLU_YAPILDI') or die('Direk Erişim Yasaklandı.'); /** * Kontrol * gerekli kontrolleri yapar bu sınıf * * @package * @author RANA ARZIK, İbrahim YILDIZ * @copyright Copyright (c) 2005 * @version $Id$ * @access public */ class Kontrol{ function BosMu($degisken){ if(isset($degisken) || $degisken != "") return 0; return 1; } function SadeceSayiVeHarfMi($kuladi){ setlocale(LC_ALL, 'tr_TR.ISO8859-9'); if(ctype_alnum($kuladi)) return 1; return 0; } function EpostaDogruMu($email){ $email = eregi_replace(" ", "" , $email); if ($email == ""){ return -1; //Boş bırakılmış eposta adrsi } $goodem = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email, $trashed); if (!$goodem) return 0; //geçersiz eposta adresi return 1; //doğru eposta adresi } function TrimStripslashes($degisken){ $sonuc = trim(stripslashes($degisken)); return $sonuc; } function BoslukAl($degisken){ $degisken = eregi_replace(" ", "" , $degisken); return $degisken; } function TarihiBizimkineDonustur($tarih){ list($yil, $ay, $gun) = split('[/.-]', $tarih); $y_tarih = "$gun.$ay.$yil"; return $y_tarih; } function SifreUret(){ $salt = "abcdefghijklmnoprstuvyzwxqABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $len = strlen($salt); $makepass = ""; mt_srand(10000000 * (double)microtime()); for ($i = 0; $i < 8; $i++) $makepass .= $salt[mt_rand(0, $len - 1)]; return $makepass; } } //end class - 14-04-2008, 00:18:20Üyeliği durduruldukendi kullandığım basit ama kullanışlı bir Template moturu
function dosya_oku($dosya) { $boyut = filesize($dosya); $actik = fopen("$dosya", 'r'); while ( ! feof ($actik ) ) { $oku .= fgets ( $actik, $boyut ) ; } fclose($actik); return $oku; } ################################## DOSYA OKUMA ################################################ ################################## ŞABLON ##################################################### function sablon($dosya) { //$icerik = file_get_contents($dosya); // php versionu destekliyorsa açık $icerik = dosya_oku($dosya); // php versionu file_get_contents i destekliyorsa kapalı preg_match_all ("/{'([\w]+)'}/", $icerik,$degiskenler); $say=array(); if (count($degiskenler[0])>0) $say = $degiskenler[0]; $c = count($say); for ($i=0; $i<$c; $i++) { $say[$i] = str_replace("{'","",$say[$i]); $say[$i] = str_replace("'}","",$say[$i]); } foreach ($say as $isim) { $atik = "{'$isim'}"; $icerik=str_replace($atik,$GLOBALS[$isim],$icerik); } return $icerik; }Kullanımı:
örnek HTML dosyamıza değişkenleri {'ana_sayfa'} ve {'menu'} şeklinde atıyoruz.
sonrasında
$ana_sayfa = "sorgular ve sonuç bu değişkende toplanıyor"; // değerler $menu = "Ana Sayfa | Linkler | vs... link vererek tabi"; // değerler $bas = sablon("template_ismi.html"); // değerler html dosyasına yazılıyor echo $bas; // çıktı gönderildi.HTML de sonucu görün...
Not: PHP versiyonu düşükse, yani file_get_contents fonksiyonu çalışmıyorsa
dosya_oku fonksiyonu ile çalışır, file_get_contents varsa dosya_oku fonksiyonu kapatılabilir... - 14-04-2008, 00:21:38Üyeliği durdurulduÜyelik sistemi için gerekli database sınıfı:
class database { var $_sql=''; var $_errorNum=0; var $_errorMsg=''; var $_table_prefix=''; var $_resource=''; var $_cursor=null; function database( $host='localhost', $user, $pass, $db, $table_prefix ) { // perform a number of fatality checks, then die gracefully if (!function_exists( 'mysql_connect' )) { //or die( 'FATAL ERROR: MySQL support not available. Please check your configuration.' ); $mosSystemError = 1; include "configuration.php"; include "offline.php"; exit(); } if (!($this->_resource = @mysql_connect( $host, $user, $pass ))) { //or die( 'FATAL ERROR: Connection to database server failed.' ); $mosSystemError = 1; include "configuration.php"; include "offline.php"; exit(); } if (!mysql_select_db($db)) { //or die( "FATAL ERROR: Database not found. Operation failed with error: ".mysql_error()); $mosSystemError = 1; include "configuration.php"; include "offline.php"; exit(); } $this->_table_prefix = $table_prefix; } function openConnectionWithReturn($query){ $result=mysql_query($query) or die("Query failed with error: ".mysql_error()); return $result; } function openConnectionNoReturn($query){ mysql_query($query) or die("Query failed with error: ".mysql_error()); } function getErrorNum() { return $this->_errorNum; } function getErrorMsg() { return str_replace( array( "\n", "'" ), array( '\n', "\'" ), $this->_errorMsg ); } function getEscaped( $text ) { return mysql_escape_string( $text ); } function setQuery( $sql, $prefix='#__' ) { $this->_sql = str_replace( $prefix, $this->_table_prefix, $sql ); } /** * @return string The current value of the internal SQL vairable */ function getQuery() { return "<pre>" . htmlspecialchars( $this->_sql ) . "</pre>"; } /** * Execute the query * @return mixed A database resource if successful, FALSE if not. */ function query() { $this->_errorNum = 0; $this->_errorMsg = ''; $this->_cursor = mysql_query( $this->_sql, $this->_resource ); if (!$this->_cursor) { $this->_errorNum = mysql_errno( $this->_resource ); $this->_errorMsg = mysql_error( $this->_resource )." SQL=$this->_sql"; return false; } return $this->_cursor; } function query_batch( $abort_on_error=true, $p_transaction_safe = false) { $this->_errorNum = 0; $this->_errorMsg = ''; if ($p_transaction_safe) { $si = mysql_get_server_info(); preg_match_all( "/(\d+)\.(\d+)\.(\d+)/i", $si, $m ); if ($m[1] >= 4) { $this->_sql = 'START TRANSACTION;' . $this->_sql . '; COMMIT;'; } else if ($m[2] >= 23 && $m[3] >= 19) { $this->_sql = 'BEGIN WORK;' . $this->_sql . '; COMMIT;'; } else if ($m[2] >= 23 && $m[3] >= 17) { $this->_sql = 'BEGIN;' . $this->_sql . '; COMMIT;'; } } $query_split = preg_split ("/[;]+/", $this->_sql); $error = 0; foreach ($query_split as $command_line) { $command_line = trim( $command_line ); if ($command_line != '') { $this->_cursor = mysql_query( $command_line, $this->_resource ); if (!$this->_cursor) { $error = 1; echo 'xxx '; $this->_errorNum .= mysql_errno( $this->_resource ) . ' '; $this->_errorMsg .= mysql_error( $this->_resource )." SQL=$command_line <br />"; if ($abort_on_error) { return $this->_cursor;; } } } } return $error ? false : true; } /** * Diagnostic function */ function explain() { $temp = $this->_sql; $this->_sql = "EXPLAIN $this->_sql"; $this->query(); if (!($cur = $this->query())) { return null; } $first = true; $buf = "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" bgcolor=\"#000000\" align=\"center\">"; $buf .= $this->getQuery(); while ($row = mysql_fetch_assoc( $cur )) { if ($first) { $buf .= "<tr>"; foreach ($row as $k=>$v) { $buf .= "<th bgcolor=\"#ffffff\">$k</th>"; } $buf .= "</tr>"; $first = false; } $buf .= "<tr>"; foreach ($row as $k=>$v) { $buf .= "<td bgcolor=\"#ffffff\">$v</td>"; } $buf .= "</tr>"; } $buf .= "</table><br /> "; mysql_free_result( $cur ); $this->_sql = $temp; return "<div style=\"background-color:#FFFFCC\" align=\"left\">$buf</div>"; } function getNumRows( $cur=null ) { return mysql_num_rows( $cur ? $cur : $this->_cursor ); } function loadResult() { if (!($cur = $this->query())) { return null; } $ret = null; if ($row = mysql_fetch_row( $cur )) { $ret = $row[0]; } mysql_free_result( $cur ); return $ret; } /** * Load an array of single field results into an array */ function loadResultArray($numinarray = 0) { if (!($cur = $this->query())) { return null; } $array = array(); while ($row = mysql_fetch_row( $cur )) { $array[] = $row[$numinarray]; } mysql_free_result( $cur ); return $array; } function loadObject( &$object ) { if ($object != null) { if (!($cur = $this->query())) { return false; } if ($array = mysql_fetch_assoc( $cur )) { mysql_free_result( $cur ); mosBindArrayToObject( $array, $object ); return true; } else { return false; } } else { if ($cur = $this->query()) { if ($object = mysql_fetch_object( $cur )) { mysql_free_result( $cur ); return true; } else { $object = null; return false; } } else { return false; } } } function loadObjectList( $key='' ) { if (!($cur = $this->query())) { return null; } $array = array(); while ($row = mysql_fetch_object( $cur )) { if ($key) { $array[$row->$key] = $row; } else { $array[] = $row; } } mysql_free_result( $cur ); return $array; } /** * @return The first row of the query. */ function loadRow() { if (!($cur = $this->query())) { return null; } $ret = null; if ($row = mysql_fetch_row( $cur )) { $ret = $row; } mysql_free_result( $cur ); return $ret; } function loadRowList( $key='' ) { if (!($cur = $this->query())) { return null; } $array = array(); while ($row = mysql_fetch_row( $cur )) { if ($key) { $array[$row->$key] = $row; } else { $array[] = $row; } } mysql_free_result( $cur ); return $array; } function insertObject( $table, &$object, $keyName = NULL, $verbose=false ) { $fmtsql = "INSERT INTO $table ( %s ) VALUES ( %s ) "; foreach (get_object_vars( $object ) as $k => $v) { if (is_array($v) or is_object($v) or $v == NULL) { continue; } if ($k[0] == '_') { // internal field continue; } $fields[] = "`$k`"; $values[] = "'" . $this->getEscaped( $v ) . "'"; } $this->setQuery( sprintf( $fmtsql, implode( ",", $fields ) , implode( ",", $values ) ) ); ($verbose) && print "$sql<br />\n"; if (!$this->query()) { return false; } $id = mysql_insert_id(); ($verbose) && print "id=[$id]<br />\n"; if ($keyName && $id) { $object->$keyName = $id; } return true; } function updateObject( $table, &$object, $keyName, $updateNulls=true ) { $fmtsql = "UPDATE $table SET %s WHERE %s"; foreach (get_object_vars( $object ) as $k => $v) { if( is_array($v) or is_object($v) or $k[0] == '_' ) { // internal or NA field continue; } if( $k == $keyName ) { // PK not to be updated $where = "$keyName='" . $this->getEscaped( $v ) . "'"; continue; } if ($v === NULL && !$updateNulls) { continue; } if( $v == '' ) { $val = "''"; } else { $val = "'" . $this->getEscaped( $v ) . "'"; } $tmp[] = "`$k`=$val"; } $this->setQuery( sprintf( $fmtsql, implode( ",", $tmp ) , $where ) ); return $this->query(); } function getObjectList( $index=null, $maxrows=NULL ) { $this->_errorNum = 0; $this->_errorMsg = ''; if (!($cur = mysql_query( $this->_sql ))) {; $this->_errorNum = mysql_errno(); $this->_errorMsg = mysql_error(); return false; } $list = array(); $cnt = 0; while ($obj = mysql_fetch_object( $cur )) { if ($index) { $list[$obj->$index] = $obj; } else { $list[] = $obj; } if( $maxrows && $maxrows == $cnt++ ) { break; } } mysql_free_result( $cur ); return $list; } /** * @param boolean If TRUE, displays the last SQL statement sent to the database * @return string A standised error message */ function stderr( $showSQL = false ) { return "DB function failed with error number $this->_errorNum" ."<br /><font color=\"red\">$this->_errorMsg</font>" .($showSQL ? "<br />SQL = <pre>$this->_sql</pre>" : ''); } function insertid() { return mysql_insert_id(); } function getVersion() { return mysql_get_server_info(); } function GenID( $foo1=null, $foo2=null ) { return '0'; } } class mosDBTable { var $_tbl = ''; var $_tbl_key = ''; var $_error = ''; var $_db = null; function mosDBTable( $table, $key, &$db ) { $this->_tbl = $table; $this->_tbl_key = $key; $this->_db = $db; } /** * @return string Returns the error message */ function getError() { return $this->_error; } function get( $_property ) { if(isset( $this->$_property )) { return $this->$_property; } else { return null; } } /** * Set the value of the class variable * @param string The name of the class variable * @param mixed The value to assign to the variable */ function set( $_property, $_value ) { $this->$_property = $_value; } function bind( $array, $ignore="" ) { if (!is_array( $array )) { $this->_error = get_class( $this )."::bind failed."; return false; } else { return mosBindArrayToObject( $array, $this, $ignore ); } } /** * binds an array/hash to this object * @param int $oid optional argument, if not specifed then the value of current key is used * @return any result from the database operation */ function load( $oid=null ) { $k = $this->_tbl_key; if ($oid !== null) { $this->$k = $oid; } $oid = $this->$k; if ($oid === null) { return false; } $this->_db->setQuery( "SELECT * FROM $this->_tbl WHERE $this->_tbl_key='$oid'" ); return $this->_db->loadObject( $this ); } function check() { return true; } /** * Inserts a new row if id is zero or updates an existing row in the database table * * Can be overloaded/supplemented by the child class * @param boolean If false, null object variables are not updated * @return null|string null if successful otherwise returns and error message */ function store( $updateNulls=false ) { $k = $this->_tbl_key; global $migrate; if( $this->$k && !$migrate) { $ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls ); } else { $ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key ); } if( !$ret ) { $this->_error = get_class( $this )."::store failed <br />" . $this->_db->getErrorMsg(); return false; } else { return true; } } /** */ function move( $dirn, $where='' ) { $k = $this->_tbl_key; $sql = "SELECT $this->_tbl_key, ordering FROM $this->_tbl"; if ($dirn < 0) { $sql .= "\nWHERE ordering < $this->ordering"; $sql .= ($where ? "\n AND $where" : ''); $sql .= "\nORDER BY ordering DESC\nLIMIT 1"; } else if ($dirn > 0) { $sql .= "\nWHERE ordering > $this->ordering"; $sql .= ($where ? "\n AND $where" : ''); $sql .= "\nORDER BY ordering\nLIMIT 1"; } else { $sql .= "\nWHERE ordering = $this->ordering"; $sql .= ($where ? "\n AND $where" : ''); $sql .= "\nORDER BY ordering\nLIMIT 1"; } $this->_db->setQuery( $sql ); $row = null; if ($this->_db->loadObject( $row )) { print_r($row); $this->_db->setQuery( "UPDATE $this->_tbl SET ordering='$row->ordering'" . "\nWHERE $this->_tbl_key='".$this->$k."'" ); $this->_db->query(); $this->_db->setQuery( "UPDATE $this->_tbl SET ordering='$this->ordering'" . "\nWHERE $this->_tbl_key='".$row->$k."'" ); $this->_db->query(); $this->ordering = $row->ordering; } else { $this->_db->setQuery( "UPDATE $this->_tbl SET ordering='$this->ordering'" . "\nWHERE $this->_tbl_key='".$this->$k."'" ); $this->_db->query(); } } function updateOrder( $where='' ) { $k = $this->_tbl_key; if (!array_key_exists( 'ordering', get_class_vars( get_class( $this ) ) )) { $this->_error = "WARNING: ".get_class( $this )." does not support ordering."; return false; } if ($this->_tbl == "#__content_frontpage") { $order2 = ", content_id DESC"; } else { $order2 = ""; } $this->_db->setQuery( "SELECT $this->_tbl_key, ordering FROM $this->_tbl" . ($where ? "\nWHERE $where" : '') . "\nORDER BY ordering".$order2 ); if (!($orders = $this->_db->loadObjectList())) { $this->_error = $this->_db->getErrorMsg(); return false; } // first pass, compact the ordering numbers for ($i=0, $n=count( $orders ); $i < $n; $i++) { if ($orders[$i]->ordering > 0) { $orders[$i]->ordering = $i+1; } } $shift = 0; $n=count( $orders ); for ($i=0; $i < $n; $i++) { //echo "i=$i id=".$orders[$i]->$k." order=".$orders[$i]->ordering; if ($orders[$i]->$k == $this->$k) { // place 'this' record in the desired location $orders[$i]->ordering = min( $this->ordering, $n ); $shift = 1; } else if ($orders[$i]->ordering >= $this->ordering && $this->ordering > 0) { $orders[$i]->ordering++; } } // compact once more until I can find a better algorithm for ($i=0, $n=count( $orders ); $i < $n; $i++) { if ($orders[$i]->ordering > 0) { $orders[$i]->ordering = $i+1; $this->_db->setQuery( "UPDATE $this->_tbl" . "\nSET ordering='".$orders[$i]->ordering."' WHERE $k='".$orders[$i]->$k."'" ); $this->_db->query(); //echo $this->_db->getQuery(); } } // if we didn't reorder the current record, make it last if ($shift == 0) { $order = $n+1; $this->_db->setQuery( "UPDATE $this->_tbl" . "\nSET ordering='$order' WHERE $k='".$this->$k."'" ); $this->_db->query(); } return true; } function canDelete( $oid=null, $joins=null ) { $k = $this->_tbl_key; if ($oid) { $this->$k = intval( $oid ); } if (is_array( $joins )) { $select = "$k"; $join = ""; foreach( $joins as $table ) { $select .= ",\nCOUNT(DISTINCT {$table['idfield']}) AS {$table['idfield']}"; $join .= "\nLEFT JOIN {$table['name']} ON {$table['joinfield']} = $k"; } $this->_db->setQuery( "SELECT $select\nFROM $this->_tbl\n$join\nWHERE $k = ".$this->$k." GROUP BY $k" ); if ($obj = $this->_db->loadObject()) { $this->_error = $this->_db->getErrorMsg(); return false; } $msg = array(); foreach( $joins as $table ) { $k = $table['idfield']; if ($obj->$k) { $msg[] = $AppUI->_( $table['label'] ); } } if (count( $msg )) { $this->_error = "noDeleteRecord" . ": " . implode( ', ', $msg ); return false; } else { return true; } } return true; } function delete( $oid=null ) { //if (!$this->canDelete( $msg )) { // return $msg; //} $k = $this->_tbl_key; if ($oid) { $this->$k = intval( $oid ); } $this->_db->setQuery( "DELETE FROM $this->_tbl WHERE $this->_tbl_key = '".$this->$k."'" ); if ($this->_db->query()) { return true; } else { $this->_error = $this->_db->getErrorMsg(); return false; } } function checkout( $who, $oid=null ) { if (!array_key_exists( 'checked_out', get_class_vars( get_class( $this ) ) )) { $this->_error = "WARNING: ".get_class( $this )." does not support checkouts."; return false; } $k = $this->_tbl_key; if ($oid !== null) { $this->$k = $oid; } $time = date( "%Y-%m-%d H:i:s" ); if (intval( $who )) { // new way of storing editor, by id $this->_db->setQuery( "UPDATE $this->_tbl" . "\nSET checked_out='$who', checked_out_time='$time'" . "\nWHERE $this->_tbl_key='".$this->$k."'" ); } else { // old way of storing editor, by name $this->_db->setQuery( "UPDATE $this->_tbl" . "\nSET checked_out='1', checked_out_time='$time', editor='".$who."' " . "\nWHERE $this->_tbl_key='".$this->$k."'" ); } return $this->_db->query(); } function checkin( $oid=null ) { if (!array_key_exists( 'checked_out', get_class_vars( get_class( $this ) ) )) { $this->_error = "WARNING: ".get_class( $this )." does not support checkin."; return false; } $k = $this->_tbl_key; if ($oid !== null) { $this->$k = $oid; } $time = date("H:i:s"); $this->_db->setQuery( "UPDATE $this->_tbl" . "\nSET checked_out='0', checked_out_time='0000-00-00 00:00:00'" . "\nWHERE $this->_tbl_key='".$this->$k."'" ); return $this->_db->query(); } function hit( $oid=null ) { global $mosConfig_enable_log_items; $k = $this->_tbl_key; if ($oid !== null) { $this->$k = intval( $oid ); } $this->_db->setQuery( "UPDATE $this->_tbl SET hits=(hits+1) WHERE $this->_tbl_key='$this->id'" ); $this->_db->query(); if (@$mosConfig_enable_log_items) { $now = date( "Y-m-d" ); $this->_db->setQuery( "SELECT hits" . "\nFROM #__core_log_items" . "\nWHERE time_stamp='$now' AND item_table='$this->_tbl' AND item_id='".$this->$k."'" ); $hits = intval( $this->_db->loadResult() ); if ($hits) { $this->_db->setQuery( "UPDATE #__core_log_items SET hits=(hits+1)" . "\nWHERE time_stamp='$now' AND item_table='$this->_tbl' AND item_id='".$this->$k."'" ); $this->_db->query(); } else { $this->_db->setQuery( "INSERT INTO #__core_log_items VALUES" . "\n('$now','$this->_tbl','".$this->$k."','1')" ); $this->_db->query(); } } } function save( $source, $order_filter ) { if (!$this->bind( $_POST )) { return false; } if (!$this->check()) { return false; } if (!$this->store()) { return false; } if (!$this->checkin()) { return false; } $filter_value = $this->$order_filter; $this->updateOrder( $order_filter ? "`$order_filter`='$filter_value'" : "" ); $this->_error = ''; return true; } function publish_array( $cid=null, $publish=1, $myid=0 ) { if (!is_array( $cid ) || count( $cid ) < 1) { $this->_error = "No items selected."; return false; } $cids = implode( ',', $cid ); $this->_db->setQuery( "UPDATE $this->_tbl SET published='$publish'" . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$myid'))" ); if (!$this->_db->query()) { $this->_error = $this->_db->getErrorMsg(); return false; } if (count( $cid ) == 1) { $this->checkin( $cid[0] ); } $this->_error = ''; return true; } }bu sınıfın kullanımına örnek:
include_once( "members/kutuphane/database.php" ); $db = new database( $config["sql_host"], $config["sql_username"], $config["sql_password"], $config["sql_database"], "" ) or die( "Veri tabanı Bağlanma Hatası" );