Such a cool thing draws Webgrind , conveniently and clearly
// $ content - template
// $ rec - variables
$ content = preg_replace ( "/ \\ $ ([AZ] [A-Z0-9 _] +) /" , "@ \\ 1 @" , $ content ) ;
if ( is_array ( $ rec ) ) {
foreach ( $ rec as $ key => $ value ) {
$ name = strtoupper ( $ key ) ;
$ content = str_replace ( "@ $ name @" , " $ value " , " $ content " ) ;
}
}
return $ content ;
function n ( ) {
global $ db , $ CONSTANTS , $ user , ...; // many in one word
echo $ CONSTANTS [ HOMEPAGE_BANNER1_ID ] ; // think this is a constant?
echo $ CONSTANTS [ HOMEPAGE_BANNER2_ID ] ; // do you know what's inside?
echo $ CONSTANTS [ HOMEPAGE_BANNER3_ID ] ; // 1, 2, 3, which do not change at all where O_o is declared
}
tpl | - index.tpl | - index2.tpl | - index3.tpl | - index __. tpl `- index.44.tpl
If a boy likes work
pokes a finger in the book,
write about this here:
he's a good boy.
// we do not read manuals
while ( $ row = mysql_fetch_array ( $ res ) ) {
if ( $ row ) {
foreach ( $ row AS $ key => $ field ) {
if ( ereg ( "^ [0-9] +" , $ key ) ) {
unset ( $ row [ $ key ] ) ;
}
}
}
$ rows [ ] = $ row ;
}
// if you finish a little
// trifle, of course, but an increase of ~ 0.1 sec. 23162 calls occur
while ( $ row = mysql_fetch_array ( $ res , MYSQL_ASSOC ) ) {
$ rows [ ] = $ row ;
}
$ sqls [ ] = $ sql ;
if ( is_array ( $ sqls ) ) {
foreach ( $ sqls AS $ ssql ) {
if ( $ ssql ) {
$ res = mysql_db_query ( $ db [ 'name' ] , $ ssql , $ db [ 'id' ] ) ;
if ( ! $ res ) {
return 0 ;
}
}
}
} else {
return 0 ;
}
// before the query, you can count the number of results
// using the db_count function (called in 96 different places)
function db_count ( $ sql ) {
global $ db ;
$ res = mysql_db_query ( $ db [ 'name' ] , $ sql , $ db [ 'id' ] ) ;
$ result = mysql_num_rows ( $ res ) ;
return $ result ;
}
// send a query to the database
$ res = mysql_db_query ( $ db [ 'name' ] , $ sql , $ db [ 'id' ] ) ;
// calculate the total (although db_count has already been called before)
$ row_count = mysql_num_rows ( $ res ) ;
// calculate how many pages we get
$ page_count = floor ( $ row_count / $ pager [ 'per_page' ] + 1 ) ;
// this is offset
$ bi = ( $ pos - 1 ) * $ pager [ 'per_page' ] ;
// now select only the necessary entries
for ( $ i = $ bi ; $ i < $ bi + $ pager [ "per_page" ] ; $ i ++ ) {
if ( $ i > = $ row_count ) {
break ;
}
if ( ! mysql_data_seek ( $ res , $ i ) ) {
break ;
}
if ( ! ( $ row = mysql_fetch_assoc ( $ res ) ) ) {
break ;
}
// store the result
$ new_rows [ ] = $ row ;
}
// in file categories.sql.php
// function that builds select for HTML
$ offset_string = '' ;
for ( $ i = 1 ; $ i < $ rec [ 'level' ] ; $ i ++ ) {
$ offset_string . = '& nbsp; & nbsp; & nbsp; & nbsp;' ;
}
$ data [ 'row' ] [ 'description' ] = substr ( $ description , 0 , 100 ) ;
$ i = 100 ;
while ( ! ( $ description [ $ i ] == "" || $ description [ $ i ] == "_" ) && $ i < strlen ( $ description ) ) :
$ data [ 'row' ] [ 'description' ] . = $ description [ $ i ] ;
$ i ++;
endwhile ;
if ( $ i < strlen ( $ description ) ) {
$ data [ 'row' ] [ 'description' ] . = "..." ;
}
function db_query ( $ db , $ sql ) { }
function db_sql_query ( $ db , $ sql ) { }
function db_count ( $ db , $ sql ) { }
// etc.
// but why not, because we have one database
function db_query ( $ sql ) {
global $ db ;
}
$ sql = "SELECT id, name, pasw from users where name = ' $ _POST [username] '" ;
// $ rows - records from the database
foreach ( $ rows as $ value ) {
$ total + = $ value [ "price" ] ;
}
switch ( $ params [ 1 ] ) :
case "usageagreement" :
$ page_id = 13 ;
break ;
case "privacypolicy" :
$ page_id = 14 ;
break ;
case "termsandconditions" :
$ page_id = 15 ;
break ;
case "affiliates" :
$ page_id = 22 ;
break ;
case "aboutus" :
$ page_id = 19 ;
break ;
endswitch ;
<! - id is such id ->
< div id = "banner" > ... < / div >
< div id = "banner" > ... < / div >
< div id = "banner" > ... < / div >
< div id = "banner" > ... < / div >
<! - class is almost style ->
< li class = "padding-left: 15px;" > ... < / li >
<! - table layout ->
<! - although it is not necessary to paint 10 nested tables ->
<! - margin, what is a margin? ->
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;
FileETag MTime Size
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
// list of modules that have already been refactored
$ modules = array (
'/ search /' ,
'/ about /'
) ;
$ path = $ _SERVER [ 'REQUEST_URI' ] ;
// we are satisfied with such a simple check
// but a request of the form / search /? ... will no longer be processed
if ( in_array ( $ path , $ modules ) ) {
// connect ZF (inside the standard code from generated public / index.php)
require 'loader.php' ;
exit ( ) ;
}
// and this one will be
foreach ( $ modules as $ module ) {
if ( strpos ( $ path , $ module ) === 0 ) {
require 'loader.php' ;
exit ( ) ;
}
}
$ _SERVER [ 'REQUEST_URI' ] = str_replace ( $ _SERVER [ 'PHP_SELF' ] , '/ admin /' , $ _SERVER [ 'REQUEST_URI' ] ) ;
require 'loader.php' ;
exit ( ) ;
Generation time | Generation time (re) | Generation time (ZF) | Page size | Page Size (ZF) | |
---|---|---|---|---|---|
Home page | 4 663ms | 2 759ms | - | 699.5Kb | 288.0Kb |
Static pages | 3 115ms | 2 008ms | 295ms | 263.3Kb | 166.2Kb |
Page item | 3,082ms | 1,745ms | 180ms | 589.1Kb | 260.8Kb |
Source: https://habr.com/ru/post/102220/
All Articles