PHP . SU
Программирование на PHP, MySQL и другие веб-технологии
Страниц (1): [1]
Найдено сообщений: 8
akaish
Отправлено: 10 Мая, 2010 - 07:21:34 • Тема: Класс для работы с файловой системой • Форум: Напишите за меня, пожалуйста
Ответов: 3 Просмотров: 51
Дали мне заказик, написать простой парсер с поддержкой шаблонов для парсинга, мозги не работают(((
В принципе, парсер готов на 70%, но, вглядевшись в код туманным взглядом, понял, что собирать и отлаживать всю эту бяку буду долго...
Если кому интересно, плод моей больной фантазии после сдачи выложу сюда, просто хочется с кем-нибудь обсудить, как и куда засунуть мне руки))
akaish
Отправлено: 10 Мая, 2010 - 01:04:07 • Тема: Класс для работы с файловой системой • Форум: Напишите за меня, пожалуйста
Ответов: 3 Просмотров: 51
Немного поигрался с cURL =))
PHP:
скопировать код в буфер обмена
<?PHP
Class Curl
{
public $targeturl , $htmltext ;
public $sslverificate , $sslcheckdomain ;
public $headers , $from_refer , $agent , $followlocation , $returntransfer , $cookiesession , $timeout ;
private $curlobject ;
public function __construct( $targeturl , $ifissetparameters )
{
$this -> targeturl = $targeturl ;
if ( $ifissetparameters != "no" and
is_array ( $ifissetparameters ) and
sizeof ( $ifissetparameters ) == 9
) {
$this -> headers = $ifissetparameters [ 0] ;
$this -> from_refer = $ifissetparameters [ 1] ;
$this -> agent = $ifissetparameters [ 2] ;
$this -> followlocation = $ifissetparameters [ 3] ;
$this -> returntransfer = $ifissetparameters [ 4] ;
$this -> cookiesession = $ifissetparameters [ 5] ;
$this -> timeout = $ifissetparameters [ 6] ;
$this -> sslverificate = $ifissetparameters [ 7] ;
$this -> sslcheckdomain = $ifissetparameters [ 8] ;
}
elseif ( $ifissetparameters == "no" )
{
$header [ ] = "Accept: text/html;q=0.9, text/plain;q=0.8, image/png, */*;q=0.5" ;
$header [ ] = "Accept_charset: windows-1251, utf-8, utf-16;q=0.6, *;q=0.1" ;
$header [ ] = "Accept_encoding: identity" ;
$header [ ] = "Accept_language: en-us,en;q=0.5" ;
$header [ ] = "Connection: close" ;
$header [ ] = "Cache-Control: no-store, no-cache, must-revalidate" ;
$header [ ] = "Keep_alive: 300" ;
$header [ ] = "Expires: Thu, 01 Jan 1970 00:00:01 GMT" ;
$this -> headers = $header ;
$this -> agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU; rv:1.7.12) Gecko/20050919 Firefox/1.0.7" ;
$this -> from_refer = $this -> targeturl ;
$this -> followlocation = true ;
$this -> returntransfer = true ;
$this -> cookiesession = true ;
$this -> timeout = 50 ;
$this -> sslcheckdomain = false ;
$this -> sslverificate = false ;
}
else
{
die ( "Не получается создать кёрл объект, так как я не имею информации для его создания или информация неккоректна" ) ; }
self :: CurlSetOpt ( ) ;
}
private function CurlSetOpt( )
{
$this -> curlobject = curl_init ( $this -> targeturl ) ; curl_setopt ( $this -> curlobject , CURLOPT_RETURNTRANSFER
, $this -> returntransfer ) ; if ( $this -> cookiesession == true )
{
curl_setopt ( $this -> curlobject , CURLOPT_COOKIESESSION
, $this -> cookiesession ) ; curl_setopt ( $this -> curlobject , CURLOPT_COOKIEJAR
, "cookie" ) ; curl_setopt ( $this -> curlobject , CURLOPT_COOKIEFILE
, "cookie" ) ; }
curl_setopt ( $this -> curlobject , CURLOPT_FOLLOWLOCATION
, $this -> followlocation ) ; curl_setopt ( $this -> curlobject , CURLOPT_CONNECTTIMEOUT
, $this -> timeout ) ; curl_setopt ( $this -> curlobject , CURLOPT_USERAGENT
, $this -> agent ) ; curl_setopt ( $this -> curlobject , CURLOPT_REFERER
, $this -> from_refer ) ; curl_setopt ( $this -> curlobject , CURLOPT_HTTPHEADER
, $this -> headers ) ; curl_setopt ( $this -> curlobject , CURLOPT_SSL_VERIFYPEER
, $this -> sslverificate ) ; curl_setopt ( $this -> curlobject , CURLOPT_SSL_VERIFYHOST
, $this -> sslcheckdomain ) ; return ;
}
public function GetPageText( )
{
$this -> htmltext = curl_exec ( $this -> curlobject ) ; return ;
}
private function __destruct( )
{
}
}
?>
akaish
Отправлено: 28 Апреля, 2010 - 02:50:15 • Тема: Класс для работы с файловой системой • Форум: Напишите за меня, пожалуйста
Ответов: 3 Просмотров: 51
Итак, ещё один маленький класс, на этотраз для работы с MySQL:
PHP:
скопировать код в буфер обмена
<?PHP
/**
* @author akaish akaish-troyan.net
* @category sql-lib
* @desc some common functions to operate with sql
*/
class sql
{
//Descr: vars
public $link , $tablearray , $query , $resultarray , $affectedrows , $result ;
private $dbhost , $databaseuser , $databasepassword , $databaseport ;
//Descr: constructor
public function __construct( )
{
$this -> Vars ( ) ;
$this -> NewConnection ( ) ;
$this -> GetArrayOfTables ( ) ;
}
//Descr: here we can definite some variables
private function Vars( )
{
$this -> dbhost = "" ;
$this -> databaseuser = "" ;
$this -> databasepassword = "" ;
$this -> databaseport = "" ;
}
//Descr: create new connection
private function NewConnection( )
{
$this -> link = mysql_connect ( $this -> dbhost , $this -> databaseuser , $this -> databasepassword , $this -> databaseport ) or
die ( "Some error occured with connecting: " . mysql_error ( $this -> link ) ) ; return ;
}
// Descr: close connection
private function CloseConnection( )
{
return ;
}
// Descr: this function gets table's names from sys database
protected function GetArrayOfTables( )
{
$this -> query = "SHOW TABLES" ;
for ( $i = 0 ; $i < $affrows ; $i ++ )
{
}
$this -> tablearray = $arrayoftb ;
return ;
}
// Descr: execute query
private function ExecQuery( )
{
if ( self :: CheckQueryForLegacy ( ) )
{
$this -> result = mysql_query ( $this -> query , $this -> link ) or
die ( "Can not execute query " . $this -> query . ", reason: " . mysql_error ( $this -> link ) ) ; return ;
}
else
{
echo "Query " . $this -> query . " was denied by function CheckQueryForLegacy" ;
return ;
}
}
// Descr: checks some conditions
private function CheckQueryForLegacy( )
{
$testarray = explode ( " " , $this -> query ) ; $operation = $testarray [ 0] ;
switch ( $operation )
{
case "DROP" :
if ( $testarray [ 1 ] == "TABLE" )
{
return self :: CheckIfExistsTable ( $testarray [ 2] ) ;
}
break ;
case "DELETE" :
if ( $testarray [ 1 ] == "TABLE" )
{
return self :: CheckIfExistsTable ( $testarray [ 2] ) ;
}
break ;
case "CREATE" :
if ( $testarray [ 1 ] == "TABLE" )
{
return ! self :: CheckIfExistsTable ( $testarray [ 2] ) ;
}
break ;
}
return TRUE ;
}
// Descr: check existance of table
private function CheckIfExistsTable( $table )
{
return in_array ( $table , $this -> tablearray ) ; }
// Descr: Save from result
public function ExecuteAndSaveToArray( $query )
{
$this -> query = $query ;
self :: ExecQuery ( ) ;
for ( $i = 0 ; $i < $this -> affectedrows ; $i ++ )
{
}
return ;
}
}
?>
akaish
Отправлено: 19 Апреля, 2010 - 05:02:55 • Тема: Превью изображения • Форум: Программирование на PHP
Ответов: 3 Просмотров: 371
Лучше всё-таки создавать реальный превью. Советую почитать про gd и exif.
Вообще делается такая штука просто. Из плюсов: снижение траффика, из минусов: превью занимает место. Конечно, можно создавать превью на лету, но это сильно займёт процессор.
Эта тема неплохо описана у Аткинсона и Сураски.
Если надо, могу написать сжималку, но тогда в личку.
akaish
Отправлено: 19 Апреля, 2010 - 00:05:11 • Тема: Класс для работы с файловой системой • Форум: Напишите за меня, пожалуйста
Ответов: 3 Просмотров: 51
Итак, не так давно я понял, что в php я не полный нуб =)
Изучил ооп, вещи даже работают =)
Решил начать писать библиотеки для php, что бы потом на их основе написать что-либо приличное. Данный сайт очень помог мне в изучении как программирования в целом, так и php в частности. Недавно даже понял, что могу писать на любом c-подобном языке после недельного ознакомления с мануалами.
Теперь я бы хотел помочь остальным. Сюда и себе на сайт (http://akaish-troyan[dot]net ) я буду выкладывать свои исходники. Что-то написано хорошо, что-то плохо, но надеюсь, что они окажутся вам полезны = )
Итак, библиотеку можно скачать тут: http://blog[dot]akaish-troyan[dot]net/?p=34
Вот и она (библиотека простейшая):
PHP:
скопировать код в буфер обмена
<?PHP
/**
* @author akaish: akaish@mail.ru akaish-troyan.net akaish@akaish-troyan.net
* @category lib to work with filesys
* @version 0.1
*/
Class FileSys
{
//Descr: variables and contstants
public $path , $whattowrite , $chmod ;
private $fileid , $dir ;
//Descr: constructor
private function __construct( $path , $chmod = "0770" )
{
$this -> path = $path ;
$this -> chmod = $chmod ;
}
//Descr: check if file exists
private function IfFileExists( )
{
}
//Descr: open file
public function OpenFile( $mod )
{
if ( self :: IfFileExists ( ) )
{
$fileid = fopen ( $this -> path , $mod ) or
die ( print ( "Error: I cant open file" . $this -> path ) ) ; return ;
}
else
{
echo "File " . $this -> path . " doesn't exists" ;
return ;
}
}
//Descr: Get array of files in target directory
{
$i = 0 ;
while ( false !== ( $file = readdir ( $this -> dir ) ) ) {
if ( $file != "." && $file != ".." )
{
$arrayoffiles [ $i ] = $file ;
$i ++;
}
}
return $arrayoffiles ;
}
//Descr: ReWriteFile
protected function ReWrite( )
{
$this -> fileid = self :: OpenFile ( "w+" ) ;
fwrite ( $this -> fileid , $this -> whattowrite , 2048
) or
die ( print ( "FileSys::ReWrite error:" . $this -> path ) ) ; return ;
}
//Descr: Delete File
protected function DeleteFile( )
{
if ( self :: IfFileExists ( ) )
{
echo "File " . $this -> path . " was deleted succesesfully!" ;
return ;
}
else
{
echo "Can not delete file: It doesn't exists!" ;
return ;
}
}
//Descr: Create file
public final function CreateFile( )
{
if ( self :: IfFileExists ( ) )
{
echo "File " . $this -> path . " is already exists" ;
return false ;
}
else
{
fopen ( $this -> path , "w+" ) or
die ( "Error with creating file:" . $this -> path ) ; return true ;
}
}
//Descr: delete folder
public final function DeleteDir( )
{
if ( ! self :: IfFileExists ( ) )
{
echo "Folder " . $this -> path . " is not exists" ;
return false ;
}
else
{
rmdir ( $this -> path ) or
die ( "Error with deleting folder:" . $this -> path ) ; return true ;
}
}
//Descr: create folder
public final function CreateDir( )
{
if ( self :: IfFileExists ( ) )
{
echo "Folder " . $this -> path . " is already exists" ;
return false ;
}
else
{
mkdir ( $this -> path , $this -> chmod ) or
die ( "Error with creating folder:" . $this -> path ) ; return true ;
}
}
//Descr: destructor
private final function __destruct( )
{
}
}
?>
Страниц (1): [1]
Powered by ExBB FM 1.0 RC1. InvisionExBB