fetch(PDO::FETCH_ASSOC))$results[]=$r; if(!$key)return $results; $arr=array(); foreach($results as $r)$arr[$r[$key]]=$r; return $arr; } function dbInit(){ if(isset($GLOBALS['db'])) return $GLOBALS['db']; global $DBVARS; $db=new PDO('mysql:host='.$DBVARS['hostname'].';dbname='.$DBVARS['db_name'],$DBVARS['username'],$DBVARS['password']); $db->query('SET NAMES utf8mb4'); $db -> query ('SET CHARACTER_SET utf8mb4_unicode_ci'); $db->num_queries=0; return $db; } function dbOne($query,$input_parameters = null, &$insert_id= null, $field='') { $r = dbRow($query,$input_parameters, $insert_id); return $r[$field]; } function dbLastInsertId() { return dbOne('select last_insert_id() as id','id'); } function dbQuery($query,$input_parameters = null, &$insert_id= null){ $db=dbInit(); $insert_id= null; if (is_null($input_parameters)) $q=$db->query($query); else { $q =$db->prepare($query); $q->execute($input_parameters); } $db->num_queries++; return $q; } function dbRow($query,$input_parameters = null, &$insert_id= null) { $q = dbQuery($query,$input_parameters, $insert_id); return $q->fetch(PDO::FETCH_ASSOC); } class Page{ static $instances = array(); static $instancesByName = array(); function __construct($v,$byField=0,$fromRow=0,$pvq=0){ # byField: 0=ID; 1=Name; 3=special if (!$byField && is_numeric($v)){ // wg identyfikatora $r=$fromRow? $fromRow: ($v? dbRow("select * from post where id=$v limit 1"): array() ); } else if ($byField == 1){ // wg nazwy $name=strtolower($v); $filename = 'ww.cache/blog/'.$name.'.php'; if (file_exists($filename)) { $homepage = file_get_contents($filename); $pos = strpos($homepage, ""); if ($pos === false) { $plik = 'ww.cache/blog/'.$name.'.php'; $zawartosc=" "; //echo $zawartosc; file_put_contents($plik, $zawartosc); } else return false; } else { include $filename; } } else { $plik = 'ww.cache/blog/'.$name.'.php'; $zawartosc=" "; //echo $zawartosc; file_put_contents($plik, $zawartosc); } else return false; } // $r=dbRow("select * from post where filename like '$name' limit 1"); } else return false; if(!count($r || !is_array($r)))return false; if(!isset($r['id']))$r['id']=0; foreach ($r as $k=>$v) $this->{$k}=$v; $this->urlname=$r['filename']; $this->dbVals=$r; self::$instances[$this->id] =& $this; self::$instancesByName[preg_replace( '/[^a-z0-9]/','-',strtolower($this->urlname) )] =& $this; } function getInstance($id=0,$fromRow=false,$pvq=false){ if (!is_numeric($id)) return false; if (!@array_key_exists($id,self::$instances)) self::$instances[$id]=new Page($id,0,$fromRow,$pvq); return self::$instances[$id]; } function getInstanceByName($name=''){ $name=strtolower($name); $nameIndex=preg_replace('#[^a-z0-9/]#','-',$name); if(@array_key_exists($nameIndex,self::$instancesByName)) return self::$instancesByName[$nameIndex]; self::$instancesByName[$nameIndex]=new Page($name,1); return self::$instancesByName[$nameIndex]; } function getRelativeURL(){ if(isset($this->relativeURL))return $this->relativeURL; $this->relativeURL=''; $this->relativeURL.='/'.$this->getURLSafeName(); return $this->relativeURL; } function getURLSafeName(){ if(isset($this->getURLSafeName)) return $this->getURLSafeName; $r=$this->urlname; $r=preg_replace('/[^a-zA-Z0-9,-]/','-',$r); $this->getURLSafeName=$r; return $r; } } define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/'); require SCRIPTBASE . '.private/config.php'; if (!defined('CONFIG_FILE')) define('CONFIG_FILE',SCRIPTBASE.'.private/config.php'); set_include_path(SCRIPTBASE.'ww.php.classes'.PATH_SEPARATOR.get_include_path()); Trend Lamele i Ryflowania - styl, który nadaje wnętrzom charakteru Noblum.pl