اما بعد اليوم قررت ان اطرح لكم مكتبتي في الكلاسات لكن لم اضعها كلها لوقتي الضيق
في البداية اول كلاس BMYSQL 0.5 وهو كلاسي في التعامل مع MYSQL و تسهيل كتابة كود SQL بطريقة سريعة جدا
الكلاس
<?php
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* Project: BMysql 0.5
* Author: Bilal El Moussaoui <bil-elmoussaoui@live.fr> - <bil.elmoussaoui@gmail.com>
* Compatiable : PHP 4 and PHP 5 or more than
* Date 24/12/2010 15:32
* Last Update :11/12/2010 1:53
* Don't Remove This Copyright Message
**************************************************************************/
class BMysql
{
/*
* BMysql attributtes
* */
private $Table_Prefix,$ConnectionLink,$DbName;
/* construct function for php 5 or more
* @param : database prefix
* @param : database info
* @ex : array("dbhost" => "localhost", "dbuser" => "root", "dbpass" => "root" , "dbname" => "bilal")
* */
public function __construct($DbPrefix,$database)
{
$this->Table_Prefix = $DbPrefix;
$this->DbName = $database["dbname"];
try
{
$this->ConnectionLink = mysql_connect($database["dbhost"],$database["dbuser"],$database["dbpass"]);
if(!$this->ConnectionLink)
throw new Exception($this->ErrorSql("Not Connected To Server Error"));
$Select = mysql_select_db($database["dbname"],$this->ConnectionLink);
if(!$Select)
throw new Exception($this->ErrorSql("Select Database Error"));
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
}
/* error function
* @param : error message
* */
private function ErrorSql($error)
{
die("<div dir='ltr'><h1>".$error."</h1> ".mysql_errno()." : ".mysql_error()."</div>");
}
/* query function
* @param : sql code
* */
protected function Query($dbCode)
{
try
{
if(!$this->ConnectionLink)
throw new Exception($this->ErrorSql("Could Not Connect To the Server Plz Check Your Config File"));
else
$Query = mysql_query($dbCode,$this->ConnectionLink);
if(!preg_match("#^[INSERT|UPDATE|DELETE|CREATE|DROP|TRUNCATE|SHOW|RENAME]#i",$dbCode)):
throw new Exception($this->ErrorSql("You Have An Error In Your Sql Code When You Use ".__CLASS__." System"));// send the error message
endif;
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Query;
}
/* Num Rows Function
* @param : Query var
* */
public function NumRows($dbCode)
{
try
{
$Num = mysql_num_rows($dbCode);
if(!isset($Num) && empty($Num))
throw new Exception($this->ErrorSql("Num Rows Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Num;
}
/*
* close connection function
* */
public function ConClose()
{
try
{
if(!$this->ConnectionLink)
throw new Exception($this->ErrorSql("Could Not Connect To the database"));
$Close = mysql_close($this->ConnectionLink);
if(!$Close)
throw new Exception($this->ErrorSql("Close Connection Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Close;
}
/* set charset function
* @param : charset
* */
public function SetCharset($Charset)
{
try
{
if(function_exists("mysql_set_charset"))
if(!$this->ConnectionLink):
$setCharset = mysql_set_charset($Charset);
else:
$setCharset = mysql_set_charset($Charset,$this->ConnectionLink);
endif;
if(!isset($setCharset))
throw new Exception("Set Charset mysql_set_charset Error");// send the error message
$SetCharacter = mysql_query("SET CHARACTER ".$Charset);
if(!isset($SetCharacter))
throw new Exception("SET CHARACTER Error");// send the error message
$SetNames = mysql_query("SET NAMES ".$Charset);
if(!isset($SetNames))
throw new Exception("SET NAMES Error");// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
}
/* fetch assoc function
* @param: Query var
* */
public function SqlAssoc($dbCode)
{
try
{
$Array = mysql_fetch_assoc($dbCode);
if(!isset($Array))
{
throw new Exception($this->ErrorSql("Mysql Fetch Assoc Error"));// send the error message
}
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Array;
}
/* fetch object function
* @param: Query var
* */
public function SqlObject($dbCode)
{
try
{
$Rows = mysql_fetch_object($dbCode);
if(!isset($Rows))
throw new Exception($this->ErrorSql("Mysql Fetch Object Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Rows;
}
/* free sql function
* @param: Query var
* */
public function FreeSql($Query)
{
try
{
$Free = mysql_free_result($Query);
if(!$Free)
throw new Exception($this->ErrorSql("Mysql Free Sql Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Free;
}
/* Delete Checkbox Function
* @param : table name
* @param : primary key field name
* @param : post
* */
public function DeleteCheckbox($Table,$Id,$PostId)
{
$ImplodesId = implode(", ",$PostId);
try
{
$Delete = $this->Query("DELETE FROM `".$this->DbName."`.`".$this->Table_Prefix."".$Table."` WHERE
".$this->EscapeString($Id)." IN(".$this->EscapeString($ImplodesId).")");
if(!$Delete)
throw new Exception($this->ErrorSql("Multi Delete Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Delete;
}
/* delete function
* @param : table name
* @param : where sql code
* */
public function Delete($Table,$Where)
{
try
{
$Delete = $this->Query("DELETE FROM `".$this->DbName."`.`".$this->Table_Prefix."".$Table."` WHERE ".$Where." ");
if(!$Delete)
throw new Exception($this->ErrorSql("Delete Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Delete;
}
/* select function
* @param : table name
* @param : fields
* @param : where sql code
* @param : order by sql code
* @param : limit sql code
* */
public function Select($Table,$Fields="*",$Where=false,$OrderBy=false,$Limit=false,$return=false)
{
$Query = "SELECT ".$Fields." FROM `".$this->DbName."`.`".$this->Table_Prefix."".$Table."` ";
if($Where != false)
$Query .= " WHERE ".$Where;
if($OrderBy != false)
$Query .= " ORDER BY ".$OrderBy;
if($Limit != false)
$Query .= " LIMIT ".$Limit;
if($return == false)
{
try
{
$Select = $this->Query($Query);
if(!$Select)
throw new Exception($this->ErrorSql("Select Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
}
else
{
$Select = $Query;
}
return $Select;
}
/* checking if id exists function
* @param : table name
* @param : primary key field name
* @param : field value
* */
public function CheckingIdExists($Table,$IdField,$IdValue)
{
try
{
$Query = $this->Select($Table,$IdField,"`".$IdField."`='".$IdValue."'",false,1);
if(!$Query)
throw new Exception($this->ErrorSql("Checking Id Exists Error"));// send the error message
$Num = $this->NumRows($Query);
if($Num > 0)
return true;
else
return false;
$this->FreeSql($Query);
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
}
/* insert function
* @param : table name
* @param : array when make the keys is the fields and the value of keys is the value of fields
* @exemple : array("fields" => "value");
* */
public function Insert($Table,$Array)
{
if(!is_array($Array))
return false;
$keys = implode(", ",array_keys($Array));
$values = implode("', '",array_values($Array));
try
{
$Insert = $this->Query("INSERT INTO `".$this->DbName."`.`".$this->Table_Prefix."".$Table."`
(".$keys.") VALUES ('".$values."')");
if(!$Insert)
throw new Exception($this->ErrorSql("Insert Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Insert;
}
/* inner join function
* @param : array when make in the first key the first table and in his value make the primary key field
* and in the second key put the second talbe and in his value make the primary key field
* @param : selected fields
* @param : where sql code
* @param : order by sql code
* @param : limit sql code
* */
public function SelectInnerJoin($array,$Fields="*",$Where=false,$OrderBy=false,$Limit=false,$return=false)
{
if(!is_array($array))
return false;
$keys = array_keys($array);
$values = array_values($array);
$Query = "SELECT ".$Fields." FROM `".$this->DbName."`.".$this->Table_Prefix."".$keys[0]." INNER JOIN `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`
ON `".$this->DbName."`.`".$this->Table_Prefix."".$keys[0]."`.`".$values[0]."` = `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`.`".$values[1]."` ";
if($Where != false)
$Query .= " WHERE ".$Where;
if($OrderBy != false)
$Query .= " ORDER BY ".$OrderBy;
if($Limit != false)
$Query .= " LIMIT ".$Limit;
if($return == false)
{
try
{
$Result = $this->Query($Query);
if(!$Result)
throw new Exception($this->ErrorSql("Select Inner Join Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Result;
}
else
{
return $Query;
}
}
/* right join function
* @param : array when make in the first key the first table and in his value make the primary key field
* and in the second key put the second talbe and in his value make the primary key field
* @param : selected fields
* @param : where sql code
* @param : order by sql code
* @param : limit sql code
* */
public function SelectRightJoin($array,$Fields="*",$Where=false,$OrderBy=false,$Limit=false,$return=false)
{
if(!is_array($array))
return false;
$keys = array_keys($array);
$values = array_values($array);
$Query = "SELECT ".$Fields." FROM `".$this->DbName."`.".$this->Table_Prefix."".$keys[0]." RIGHT JOIN `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`
ON `".$this->DbName."`.`".$this->Table_Prefix."".$keys[0]."`.`".$values[0]."` = `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`.`".$values[1]."` ";
if($Where != false)
$Query .= " WHERE ".$Where;
if($OrderBy != false)
$Query .= " ORDER BY ".$OrderBy;
if($Limit != false)
$Query .= " LIMIT ".$Limit;
if($return == false)
{
try
{
$Result = $this->Query($Query);
if(!$Result)
throw new Exception($this->ErrorSql("Select Right Join Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Result;
}
else
{
return $Query;
}
}
/* full join function
* @param : array when make in the first key the first table and in his value make the primary key field
* and in the second key put the second talbe and in his value make the primary key field
* @param : selected fields
* @param : where sql code
* @param : order by sql code
* @param : limit sql code
* */
public function SelectFullJoin($array,$Fields="*",$Where=false,$OrderBy=false,$Limit=false,$return=false)
{
if(!is_array($array))
return false;
$keys = array_keys($array);
$values = array_values($array);
$Query = "SELECT ".$Fields." FROM `".$this->DbName."`.".$this->Table_Prefix."".$keys[0]." FULL JOIN `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`
ON `".$this->DbName."`.`".$this->Table_Prefix."".$keys[0]."`.`".$values[0]."` = `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`.`".$values[1]."` ";
if($Where != false)
$Query .= " WHERE ".$Where;
if($OrderBy != false)
$Query .= " ORDER BY ".$OrderBy;
if($Limit != false)
$Query .= " LIMIT ".$Limit;
if($return == false)
{
try
{
$Result = $this->Query($Query);
if(!$Result)
throw new Exception($this->ErrorSql("Select Full Join Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Result;
}
else
{
return $Query;
}
}
/* left join function
* @param : array when make in the first key the first table and in his value make the primary key field
* and in the second key put the second talbe and in his value make the primary key field
* @param : selected fields
* @param : where sql code
* @param : order by sql code
* @param : limit sql code
* */
public function SelectLeftJoin($array,$Fields="*",$Where=false,$OrderBy=false,$Limit=false,$return=false)
{
if(!is_array($array))
return false;
$keys = array_keys($array);
$values = array_values($array);
$Query = "SELECT ".$Fields." FROM `".$this->DbName."`.".$this->Table_Prefix."".$keys[0]." LEFT JOIN `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`
ON `".$this->DbName."`.`".$this->Table_Prefix."".$keys[0]."`.`".$values[0]."` = `".$this->DbName."`.`".$this->Table_Prefix."".$keys[1]."`.`".$values[1]."` ";
if($Where != false)
$Query .= " WHERE ".$Where;
if($OrderBy != false)
$Query .= " ORDER BY ".$OrderBy;
if($Limit != false)
$Query .= " LIMIT ".$Limit;
if($return == false)
{
try
{
$Result = $this->Query($Query);
if(!$Result)
throw new Exception($this->ErrorSql("Select Left Join Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Result;
}
else
{
return $Query;
}
}
/* update function
* @param : table name
* @param : array on put in the keys the fields name and in his value on put the value of the fields
* @ex : array("user_name"=> "Bilal","user_pass" => "no");
* @param : where sql code
* @param : limit sql code
* */
public function Update($Table,$Array,$Where=false,$Limit=false,$useComma=true)
{
if(!is_array($Array))
return false;
$Query = "";
$Comma = "";
foreach ($Array as $Fields => $Values)
{
if($useComma == true)
{
$Query .= $Comma."`".$Fields."`='".$Values."'";
}
else
{
$Query .= $Comma."`".$Fields."`=".$Values."";
}
$Comma = ', ';
}
if($Where != false)
$Query .= " WHERE ".$Where;
if($Limit != false)
$Query .= " LIMIT ".$Limit;
try
{
$Qupdate = $this->Query("UPDATE `".$this->DbName."`.`".$this->Table_Prefix."".$Table."` SET ".$Query);
if(!$Qupdate)
throw new Exception($this->ErrorSql("Update Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Qupdate;
}
/* num sql function
* @param : sql code
* */
public function NumSQL($dbCode)
{
try
{
$Query = $this->Query($dbCode);
if(!$Query)
throw new Exception($this->ErrorSql("Num Sql Query Error"));// send the error message
$Num = $this->NumRows($Query);
if(!isset($Num) && empty($Num))
throw new Exception($this->ErrorSql("Num Sql Num Rows Error"));// send the error message
return $Num;
$this->FreeSql($Query);
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
}
/* create database function
* @param : database name
* */
public function CreateDB($DbName)
{
try
{
if(function_exists("mysql_create_db")) // check if the function exists
$Query = mysql_create_db($DbName);
else
$Query = $this->Query("CREATE DATABASE IF NOT EXISTS `".$DbName."`");
if(!$Query):
throw new Exception($this->ErrorSql("Create Dtabase Error"));// send the error message
endif;
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Query;
}
/* delete database function
* @param : database name
* */
public function DeleteDB($DbName)
{
try
{
if(function_exists("mysql_drop_db")) // check if the function exists
$Query = mysql_drop_db($DbName);
else
$Query = $this->Query("DROP DATABASE IF EXISTS `".$DbName."`");
if(!$Query):
throw new Exception($this->ErrorSql("Delete Database Error")); // send the error message
endif;
}
catch(Exception $e)
{
$e->getMessage(); // print the message
}
return $Query;
}
/* turncate table function
* @param : table name
* */
public function TurncateTable($Table)
{
try
{
$Query = $this->Query("TRUNCATE TABLE `".$this->DbName."`.`".$Table."`");
if(!$Query)
throw new Exception($this->ErrorSql("Turncate Table Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Query;
}
/* delete table function
* @param : table name
* */
public function DropTable($Table)
{
try
{
$Query = $this->Query("DROP TABLE `".$this->DbName."`.`".$Table."`");
if(!$Query)
throw new Exception($this->ErrorSql("Drop Table Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Query;
}
/* show table function
* @param : table name
* */
public function ShowTable($table)
{
try
{
$Query = $this->Query("SHOW CREATE TABLE `".$this->DbName."`.`".$table."`");
if(!$Query)
throw new Exception($this->ErrorSql("Show Table Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Query;
}
/* escepe string function
* @param: text
* */
public function EscapeString($var)
{
if(function_exists("mysql_escape_string"))
{// check if the function exists
$var = mysql_escape_string($var);
}
else if(function_exists("mysql_real_escape_string"))
{
if(!$this->ConnectionLink)
$var = mysql_real_escape_string($var);
else
$var = mysql_real_escape_string($var,$this->ConnectionLink);
}
else
{
$var = addslashes($var);
}
return $var;
}
/* rename table function
* @param : old name of table
* @param : new name of table
* */
public function RenameTable($OldName,$NewName)
{
try
{
$Query = $this->Query("RENAME TABLE `".$this->DbName."`.`".$OldName."` TO `".$this->DbName."`.`".$NewName."`");
if(!$Query)
throw new Exception($this->ErrorSql("Rename Table Error"));// send the error message
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
}
/* list tables function
* @param : database name
* */
public function ListTables($database)
{
try
{
if(!$this->ConnectionLink)
$Query = mysql_list_tables($database);
else
$Query = mysql_list_tables($database,$this->ConnectionLink);
if(!$Query):
throw new Exception($this->ErrorSql("List Tables Error"));// send the error message
endif;
}
catch(Exception $e)
{
$e->getMessage();// print the message
}
return $Query;
}
#=> End Class
}
class Backup extends BMysql
{
private $--SS--Titlte;
public function __Set--SS--Title($title)
{
$this->--SS--Titlte = $title;
}
public function __GetBackUp($postName)
{
global $_POST;
$tables = $_POST[$postName];
$date = date("d/m/y - h:i",time());
$db =
"-- phpMyAdmin SQL Dump
-- http://www.phpmyadmin.net
-- ".$this->--SS--Titlte."
-- Serveur: localhost
-- Generate Date : ".$date."
-- By Bilal Elmoussaoui
-- Database : `".parent::DbName."`
--
-- --------------------------------------------------------
\r\n";
foreach($tables as $table)
{
$query = parent::Query("SHOW CREATE TABLE ". $table);
$t_n = parent::SQLArray($query);
$db .=
"--
-- Structure Of Table `$table`
--
\r\n";
$db .= $t_n['Create Table'] . ";\r\n\r\n";//
$resData = parent::Select($t_n["Table"],"*");
$db .=
"--
-- Content Of Table `$table`
--
\r\n";
while($result = parent::SQLArray(($resData))
{
$num_fields = mysql_num_fields($resData);
$row = mysql_fetch_row($resData);
for($i=0; $i < $num_fields; $i++){
$fields[] .= "`".mysql_field_name($resData,$i)."`";
$values[] .= "'$row[$i]'";
}
$fields = join(", ", $fields);
$values = join(", ", $values);
$insert = "INSERT INTO `$t_n[Table]` ($fields) VALUES ($values);";
$db .= $insert . "\r\n";
unset($fields,$values);
}
parent::FreeSql($resData);
parent::FreeSql($query);
}
header("Content-length: " . strlen($db));
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=".parent::DbName.".sql");
echo $db;
exit();
}
}
?>
كلاسي لمحاربة flood
Bflood 0.1
<?php
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Project: Bflood 0.1
* Link: http://cliprz-php.com
* Author: Bilal El Moussaoui <bil-elmoussaoui@live.fr> - <bil.elmoussaoui@gmail.com>
* Compatiable : PHP 4 and PHP 5 or more than
* Don't Remove This Copyright Message
**************************************************************************/
class BFlood {
public $SessionPrefix;#=> The Session Prefix
public $Time = "30"; #=> The time
public $SessionName = "flood"; #=> The Session Name
public $Message;#=> The Msg
public function __construct()
{
if(!isset($_SESSION) && !$_SESSION): session_start(); endif;
$this->SessionPrefix = SEFX;
}
public function MakeSession()
{
$_SESSION[$this->SessionPrefix.$this->SessionName] = time();
}
public function Checking()
{
if($_SESSION[$this->SessionPrefix.$this->SessionName] >= time() - $this->Time)
{
return TRUE;
}
else
{
unset($_SESSION[$this->SessionPrefix.$this->SessionName]);
}
}
}
?>
كلاسي للتعامل مع SEO من اجل ارشفة افضل BSeo 0.1 Beta
<?php
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Project: BSeo 0.1 Beta
* Author: Bilal El Moussaoui <bil-elmoussaoui@live.fr> - <bil.elmoussaoui@gmail.com>
* Compatiable : PHP 4 and PHP 5 or more than
* Don't Remove This Copyright Message
**************************************************************************/
class BSeo
{
public $SiteTitleBreak = ' - ';
public $AddToTitle;
public $SiteHead;
public $File = '.htaccess';
public $Change = array();// array("index.php" => "index.html")
public function __construct()
{
if(!is_array($this->Change))
return false;
}
private function ChackHtaccess()
{
if(file_exists($this->File) && is_writable($this->File) && is_readable($this->File))
return true;
else
return false;
}
public function ChangeExt()
{
if($this->ChackHtaccess() === true)
{
$OpenToWrite = fopen($this->File,'w');
$OpenToRead = fopen($this->File,'r');
$Read = fread($OpenToRead,filesize($this->File));
$NewContent = '';
foreach($this->Change as $keys => $value)
{
$NewContent .= str_ireplace($keys,$value,$Read);
}
$Write = fwrite($OpenToWrite,$NewContent);
unset($Read,$Write,$NewContent);
fclose($OpenToRead);
fclose($OpenToWrite);
}
}
public function GetTitle()
{
global $db;
$Query = $db->Select("main_setting","site_title",false,false,1);
$Rows = $db->SqlObject($Query);
return $Rows->site_title.$this->SiteTitleBreak.$this->AddToTitle($this->AddToTitle);
$db->FreeSql($Query);
}
public function AddToTitle($title)
{
$this->AddToTitle =$title;
return $this->AddToTitle;
}
public function NewHead()
{
return $this->AddToHead($this->SiteHead);
}
private function AddToHead($Content)
{
$this->SiteHead = $Content;
return $this->SiteHead;
}
private function AddMeta($name,$Content)
{
if(!preg_match('#^[a-zA-Z]$#',$name))
return false;
else
return '<meta name="'.$name.'" content="'.$Content.'" />';
}
public function NewMeta($name,$Content)
{
return $this->AddMeta($name,$Content);
}
public function SeoUrl($SUrl,$SimpleUrl)
{
global $db;
$Query = $db->Select("main_setting","SeoUrl",false,false,1);
$Rows = $db->SqlObject($Query);
if($Rows->SeoUrl == 0)
{
return $SimpleUrl;
}
else if($$Rows->SeoUrl == 1)
{
return $SUrl;
}
$db->FreeSql($Query);
}
}
?>
كلاسي لمتابعة الاخطاء BErrors 0.1
<?php
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Project: BErrors 0.1
* Author: Bilal El Moussaoui <bil-elmoussaoui@live.fr> - <bil.elmoussaoui@gmail.com>
* Compatiable : PHP 4 and PHP 5 or more than
* Date 21/12/2010 19:40
* Don't Remove This Copyright Message
**************************************************************************/
class BErrors
{
private $ShowError = true;
public $Errors = array(
E_WARNING => '|',
E_PARSE => '|',
E_ERROR => '|',
E_USER_ERROR => '|',
E_USER_WARNING
);
public function __construct($error)
{
$this->ShowError = $error;
}
public function __SetShowErrors($type)
{
$this->ShowError = $type;
return serialize($this->ShowError);
}
public function myErrorHandler($errno, $errstr, $errfile, $errline){
switch ($errno) {
foreach($this->Errors as $key)
case $key:
echo "<strong>MY '.$key.'</strong>[".$errno."] : ".$errstr, $errfile, $errline."<br />\n";
break;
}
}
public function __SetErrorHandler($functionName)
{
try
{
if(!function_exists($functionName))
{
throw new Exception('Error The function '.$functionName.' is not exists');
$functionName = $this->myErrorHandler();
}
set_error_handler($this->myErrorHandler());
}catch(Exception $e)
{
$e->getMessage();
}
}
public function __GetLastErrorLog()
{
while($errors = error_get_last())
{
echo "<strong>MY '.$errors['type'].'</strong> file:'.$errors['file'].' on line : '.$errors['line'].' the message : '.$errors['message'].'<br />\n";
}
}
public function __SetDisplayErrors()
{
if(unserialize($this->ShowError) === true)
{
ini_set('display_errors',true);
$x = '';
foreach($this->Errors as $key => $value)
{
$x .= $key.$value;
}
error_reporting($x);
}
else
{
ini_set('display_errors',false);
error_reporting(0);
}
}
}
?>
كلاس Bip للتعامل مع ايبي من احضار للعلم و اسم الدولة و المدينة ومكانك في العالم عبر خريطة Google Map
<?php
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Project: Bip 0.1 Beta
* Author: Bilal El Moussaoui <bil-elmoussaoui@live.fr> - <bil.elmoussaoui@gmail.com>
* Compatiable : PHP 4 and PHP 5 or more than
* Date 25/10/2010 15:32
* Last Update :27/11/2010 14:52
* Don't Remove This Copyright Message
**************************************************************************/
class BIp
{
private $ip,$Content;
public function __construct()
{
$this->ip = $this->__GetRealIp();
}
private function __GetRealIp()
{
if (getenv(HTTP_X_FORWARDED_FOR)){
$ip = getenv(HTTP_X_FORWARDED_FOR);
}elseif (getenv(HTTP_CLIENT_IP)){
$ip = getenv(HTTP_CLIENT_IP);
}else {
$ip = getenv(REMOTE_ADDR);
}
return $ip;
}
private function __GetContent()
{
try{
$this->Content = simplexml_load_file('http://api.ipinfodb.com/v2/ip_query.php?key=02965caf810247e0ab074c988e4c336b6f5cb2e76e633471d43ab3a8dcb48245
&ip='.$this->ip.'&timezone=true');
if(!$this->Content)
{
throw new Exception("Could not get the xml file");
}
}catch(Exception $e)
{
$e->getMessage();
}
return $this->Content;
}
public function __GetCountryName()
{
$this->__GetContent();
return $this->Content->CountryName;
}
public function __GetCity()
{
$this->__GetContent();
return $this->Content->City;
}
public function __GetCountyFlag()
{
$this->__GetContent();
$country = strtolower($this->__GetCountryName());
return "http://www.printableworldflags.com/icon-flags/16/".$country.".png";
}
public function __GetTimezoneName()
{
$this->__GetContent();
return $this->Content->TimezoneName;
}
public function __GetRegionName()
{
$this->__GetContent();
return $this->Content->RegionName;
}
public function __GetGoogleMap()
{
$this->__GetContent();
$x = '
<div id="map" style="width: 400px; height: 300px; margin-top:20px;"></div>
<--SS-- src="http://maps.google.com/maps?file=api&v=1&key=APIKEY" type="text/--SS--"></--SS-->
<--SS-- type="text/--SS--">
var map = new GMap(document.getElementById("map"));
var point = new GPoint('.$this->Content->longitude.','.$this->Content->latitude.');
map.centerAndZoom(point, 3);
var marker = new GMarker(point);
map.addOverlay(marker);
</--SS-->';
return $x;
}
}
$ip = new BIp();
echo $ip->__GetCountryName();
?>
سينم تحديث هاته المكتبة في اقرب و قت
و السلام خبر ختام
infomed
20:12 - 2010/12/25 معلومات عن العضو
الأحد مايو 05, 2024 7:07 pm من طرف سها مجدى
» غسيل مكيفات سبليت بالرياض
الأربعاء أبريل 17, 2024 5:59 pm من طرف سها مجدى
» شركة تشطيب فلل بالباحة
الثلاثاء أبريل 09, 2024 6:36 pm من طرف سها مجدى
» شركة مقاولات بالمبرز
الأربعاء أبريل 03, 2024 4:53 pm من طرف سها مجدى
» شركة نقل عفش بالرياض الياسمين
الجمعة مارس 22, 2024 7:02 pm من طرف سها مجدى
» مقاول اسفلت بالرياض
الخميس مارس 14, 2024 12:12 am من طرف سها مجدى
» شركة تركيب المصاعد بعسير
الجمعة مارس 08, 2024 8:34 pm من طرف سها مجدى
» مبلطين ممتازين بالرياض
الثلاثاء مارس 05, 2024 10:49 pm من طرف سها مجدى
» شركة مقاولات بخميس مشيط
السبت مارس 02, 2024 11:03 pm من طرف سها مجدى