punkt
personal space invader
Baistruc
Offline
Gender: 
Posts: 1 457
|
 |
« on: Fri, 08 Jun 2007, 14:46 » |
|
MOTOR DE TEMPLATESScop: de a separa codul php de cel html. Might be useful FISIERE NECESARE:index.php template.inc.php themes/test/index.theme.php index.php<?php global $SETTINGS; include "template.inc.php"; $SETTINGS['theme']='test';
$vars = array( 'middle' => 'HELLO WORLD', 'left' => "[s f=arial s=30px c=#00F]test[/s]" ); $vars2 = array( 'middle' => '<br />FOO BAR', 'left' => "<br />[s f=arial s=30px c=#F00]test2[/s]" ); $TPL = new cTemplate(); $TPL->LOAD(); $TPL->ADD($vars); $TPL->ADD($vars2); $TPL->DRAW(); ?>
template.inc.php<?php class cTemplate{ var $T_OUTPUT=""; var $ERR=""; function LOAD($T_NAME="null"){ if($T_NAME=="null"){ $thisname = basename($_SERVER['SCRIPT_FILENAME']); $thisname = explode(".",$thisname); $thisname = $thisname[0]; $T_NAME = $thisname; } global $SETTINGS; $T_THEMEDIR = "themes/".$SETTINGS['theme']."/"; $T_THEMEFILE = $T_THEMEDIR.$T_NAME.".theme.php"; if(!file_exists($T_THEMEFILE)){ ?> <span style="border: 1px solid black; background-color:#CC0000; color:#FFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px; padding:2px;"> <strong>TEMPLATE ERROR:</strong> Template file doesn't exist!(<?=$T_THEMEFILE?>) </span> <?php }else{ $T_FILE = file_get_contents($T_THEMEFILE); $this->T_OUTPUT = $T_FILE; } } function ADD($T_VARS){ foreach($T_VARS as $k=> $v){ $this->T_OUTPUT = str_replace("{{$k}}", $v."{{$k}}", $this->T_OUTPUT); } } function STORE(){ $T_OUTPUT = $this->T_OUTPUT; $T_OUTPUT = preg_replace('/\{(.*?)\}/is',"", $T_OUTPUT); return $T_OUTPUT;
} function DRAW(){ $T_OUTPUT = $this->T_OUTPUT; $T_OUTPUT = preg_replace('/\[table](.*?)\[\/table\]/is', '$1',$T_OUTPUT); $T_OUTPUT = preg_replace('/\{(.*?)\}/is'," ", $T_OUTPUT); $tags = array( //TABLE TAGS '/\[table class=(.*?)\](.*?)\[\/table\]/is' => 'CLASS-TABLE-TEMPLATE-HERE', '/\[table style=\'(.*?)\'\](.*?)\[\/table\]/is' => 'STYLE-TABLE-TEMPLATE-HERE', '/\[table](.*?)\[\/table\]/is' => 'SIMPLE-TABLE STYLE', //STYLING '/\[b](.*?)\[\/b\]/is' => '<strong>$1</strong>', '/\[col=(.*?)\](.*?)\[\/col\]/is' => '<span style="color:#$1">$2</span>', '/\[size=(.*?)\](.*?)\[\/size\]/is' => '<span style="font-size:$1">$2</span>', '/\[s f=(.*?)\ s=(.*?)\ c=(.*?)\](.*?)\[\/s\]/is' => '<span style="font-family:$1; font-size:$2; color:$3">$4</span>', //EMPTY TEMPLATE TAGS '/\{(.*?)\}/is' => "", ); foreach($tags as $tk=>$tv){ $T_OUTPUT = preg_replace($tk,$tv,$T_OUTPUT); } echo $T_OUTPUT;
} } ?>
themes/test/index.theme.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head>
<body> <table width="800" border="1"> <tr> <td height="100"> </td> <td><div align="center">THEME EXAMPLE</div></td> <td> </td> </tr> <tr> <td height="500">{left}</td> <td width="500">{middle}</td> <td>{right}</td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> </table> </body> </html>
|
|
|
|
« Last Edit: Wed, 15 Aug 2007, 14:57 by punkt »
|
Logged
|
|
|
|
barkayal
Iguana Tamer
Baistruc
Offline
Gender: 
Posts: 166
|
 |
« Reply #1 on: Fri, 08 Jun 2007, 14:59 » |
|
try smarty template engine http://www.smarty.net/it's easy to use and has a lot of features, inclusiv un sistem de caching pentru templateturi.
|
|
|
|
|
Logged
|
|
|
|
wooptoo
Baistruc
Offline
Posts: 4 835
|
 |
« Reply #2 on: Fri, 08 Jun 2007, 15:31 » |
|
thx punkt. Cand voi avea timp voi trece revolushii pe Drupal (sper...). Are un sistem de templates foarte asemanator cu smarty engine si ce ai scris tu, stie caching cum trebuie, nu ca fsckin wordpress, e foarte performant si curat scris si suporta o gramada de plug-ins.
|
|
|
|
|
Logged
|
|
|
|
punkt
personal space invader
Baistruc
Offline
Gender: 
Posts: 1 457
|
 |
« Reply #3 on: Fri, 08 Jun 2007, 17:40 » |
|
l-am scris azi, i was too bored at work, si m-am gandit sa fac ceva sa-mi separ codul html de php (de obicei tind sa amestec html-ul cu php-ul pana nu mai inteleg nimic). Nu prea imi place sa lucrez cu script-uri luate din alte parti, si mai degraba ma chinui sa-mi scriu eu codul de care am nevoie. Mai stii, daca ma tin de capul lui poate ii adaug si eu caching & stuff dar e putin probabil sa-l continui.  edit: 'bbcodes' pt tables nu merg  sunt puse acolo de forma.
|
|
|
|
« Last Edit: Fri, 08 Jun 2007, 17:43 by punkt »
|
Logged
|
|
|
|
Stokky
Baistruc
Offline
Gender: 
Posts: 363
|
 |
« Reply #4 on: Fri, 08 Jun 2007, 19:00 » |
|
try smarty template engine http://www.smarty.net/it's easy to use and has a lot of features, inclusiv un sistem de caching pentru templateturi. qtf, smarty template engine ftw
|
|
|
|
|
Logged
|
|
|
|
punkt
personal space invader
Baistruc
Offline
Gender: 
Posts: 1 457
|
 |
« Reply #5 on: Wed, 15 Aug 2007, 15:06 » |
|
Constante ce contin un interval de timp in secunde.Not much, dar destul de utile cand lucrezi tu timestamp-uri UNIX  . <?php define("SECONDS",1); define("MINUTES",60); define("HOURS",3600); define("DAYS",86400); define("WEEKS",604800); define("MONTHS",2629743.83); define("YEARS",31556926); ?>
EXEMPLU: <?php $start_execution_time = date("U"); ...do-something for a long time... $end_execution_time = date("U"); $diff = ($end_execution_time-$start_execution_time)
if($diff>1*HOUR){echo "It took me ".($diff/MINUTES)." minutes to do that! oO";} ?>
|
|
|
|
« Last Edit: Wed, 15 Aug 2007, 15:42 by punkt »
|
Logged
|
|
|
|
wooptoo
Baistruc
Offline
Posts: 4 835
|
 |
« Reply #6 on: Fri, 26 Oct 2007, 01:42 » |
|
Snippet pt validare email cu regular expressions: eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $mail)
Stolen from: http://www.zend.com/zend/spotlight/ev12apr.php  Functioneaza cel mai bine din cate am gasit pana acuma... nu stiu regex atat de bine incat sa-mi fac eu unul. Pe zend.com e {2,3})$ in loc de {2,4})$, dar articolul e mai vechi (2001) si acum au aparut si domenii din 4 litere ca .info, .mobi etc
|
|
|
|
|
Logged
|
|
|
|
punkt
personal space invader
Baistruc
Offline
Gender: 
Posts: 1 457
|
 |
« Reply #7 on: Wed, 31 Oct 2007, 17:25 » |
|
http://sol-center.ro/www/r.php ( sursa); "pseudo-widget"  pentru ... stuff..  Eu il folosesc pentru Netvibes (inainte sa puneti 'blog-ul' exista chestie RSS pentru FORUM, dar n-am mai gasit o_O) Face refresh la fiecare 10 min. E facut in 15 min (bored), so no complains 'bout caching, aaight?  netvibes: 
|
|
|
|
« Last Edit: Wed, 31 Oct 2007, 17:31 by punkt »
|
Logged
|
|
|
|
|
|
punkt
personal space invader
Baistruc
Offline
Gender: 
Posts: 1 457
|
 |
« Reply #9 on: Wed, 31 Oct 2007, 17:37 » |
|
well... daca e ascuns link-ul nu-l stie nimeni  ... nu am pb cu RSS pe forum, doar ca nu stiam de unde sa-l accesez... Inainte era ceva iconita RSS pe forum >.>
|
|
|
|
|
Logged
|
|
|
|
|
wooptoo
|
Pai detecteaza Opera sau FF daca site-ul are RSS si-ti afiseaza o iconita pe address bar. Click on it.
|
|
wooptoo
Baistruc
Offline
Posts: 4 835
|
 |
« Reply #10 on: Wed, 31 Oct 2007, 23:52 » |
|
Pai detecteaza Opera sau FF daca site-ul are RSS si-ti afiseaza o iconita pe address bar. Click on it.
|
|
|
|
|
Logged
|
|
|
|
|
yoshi
|
mie opera nu-mi arata rss feed pt forum/site :\
|
|
yoshi
fap -> ∞
Coșcojemete
Offline
Gender: 
Posts: 8 386
◕ ◡ ◕
|
 |
« Reply #11 on: Thu, 01 Nov 2007, 00:03 » |
|
mie opera nu-mi arata rss feed pt forum/site :\
|
|
|
|
|
Logged
|
|
|
|
wooptoo
Baistruc
Offline
Posts: 4 835
|
 |
« Reply #12 on: Thu, 24 Jan 2008, 16:52 » |
|
M-am enervat ieri ca vroia sa-mi trimita un prieten ceva si nu merge receive files in pidgin, sooo: filebinUn php script mic care iti permite sa uploadezi doar anumite tipuri de fisiere intr-un director. Poti seta limita de dimensiune. Se integreaza cu modulul autoindex al apache pentru afisarea fisierelor. E compus din 2 fisiere: HEADER.html - pe care apache il include in paginile generate de autoindex si .up.php care se ocupa de uploadul efectiv (are . in fa?? ca sa nu apara in lista fisierelor din director). <h1>filebin</h1>
<style type="text/css"> form { font: normal 1em Verdana, sans-serif; background: #fff; border: solid 1px #8D8D8D; width: 22em; padding: .8em 1em; position: fixed; top: 10px; right: 8px; } h2 { font-size: 1.4em; margin: 0 0 .4em 0; } #allowed { font-size: .8em; } </style>
<form action=".up.php" method="post" enctype="multipart/form-data"> <h2>Upload file</h2> <input type="file" name="file" /> <input type="submit" name="submit" value="Upload" /> <p id="allowed">Allowed: png, gif, jpg, mp3, zip, gz</p> </form>
Tag-ul <style> nu e valid daca e pus acolo, dar asta e. E o limitare a autoindex-ului - nu poti modifica <head>-ul paginilor. <?php if ((($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "audio/mpeg") || ($_FILES["file"]["type"] == "application/zip") || ($_FILES["file"]["type"] == "application/x-gzip")) && ($_FILES["file"]["size"] < 11000000) && ($_FILES["file"]["error"] == 0) && (file_exists("" . $_FILES["file"]["name"]) == 0)) { move_uploaded_file($_FILES["file"]["tmp_name"], "" . $_FILES["file"]["name"]); } header("Location:."); ?>
silence is golden  Live demo here: http://wooptoo.hopto.org/filebin/ yes, you can upload shit  Also, daca poate cineva sa-si dea o parere in legatura cu securitatea scriptului ar fi super. Ma gandeam sa fac un .htaccess care sa dea deny la orice php din director in afara de .up.php... dar trebuie sa mai invat regex 
|
|
|
|
|
Logged
|
|
|
|
punkt
personal space invader
Baistruc
Offline
Gender: 
Posts: 1 457
|
 |
« Reply #13 on: Thu, 24 Jan 2008, 17:53 » |
|
o alternativa la codul tau + respingere fisiere cu extensia php sau exe <?php $allowedtypes = array("image/png","image/gif","image/jpeg"."image/pjpeg","audio/mpeg","application/zip","application/x-gzip"); $deniedext = array("php","exe"); $filetype = $_FILES["file"]["type"]; $filename = $_FILES["file"]["name"]; $fileext = substr($filename,-3,3); //intoarce ultimele 3 litere din $filename if(!file_exists($filename)): if((in_array($filetype,$allowedtypes)) && (!in_array($fileext,$deniedext))): //in_array() rox! move_uploaded_file($_FILES["file"]["tmp_name"], "" . $_FILES["file"]["name"]); endif; endif; ?>
Also securitatea nu prea trebuie sa fie o grija in cazul asta, pentru ca din cate stiu eu nu prea poti sa patesti nimic  Poti sa parsezi numele final ($_FILES['file']['name']) pentru caractere interzise (urlencode(), functii custom, etc) Poti sa scanezi fisierele inainte de upload impotriva virusilor apeland antivirusul de pe sistem (daca ai antivirus) cu exec();
|
|
|
|
« Last Edit: Thu, 24 Jan 2008, 18:16 by punkt »
|
Logged
|
|
|
|
yoshi
fap -> ∞
Coșcojemete
Offline
Gender: 
Posts: 8 386
◕ ◡ ◕
|
 |
« Reply #14 on: Thu, 24 Jan 2008, 21:33 » |
|
upload on website then download is a waste of time. use HFS http://www.rejetto.com/hfs/
|
|
|
|
|
Logged
|
|
|
|
|