html_head['base']='http://'.implode('/',$tmpa).'/'; //------------- $this->defaultpage=$defaultpage; $this->norights=$defaultpage; if(empty($_GET['p'])) $_GET['p']=$defaultpage; // rozbicie url $this->utgen($_GET['p']); //inicjalizacja smarty $this->template_dir = 'modules/'; $this->plugins_dir = array('models/smarty/plugins'); $this->compile_dir = 'tpl_c/'; //wylistowanie zainstalowanych modulow $katalog = opendir("modules/"); // get each entry while($item = readdir($katalog)) { $this->modules[] = $item; }; } //------------------------------------------------------------------------------ // generowanie urltab //------------------------------------------------------------------------------ function utgen($str) { $this->urltab=array(); $tempurltab = explode('/',$str); foreach($tempurltab as $k=>$v) $this->urltab[]=explode('_',$v); if(empty($this->urltab[0][1])) $this->urltab[0][1]=$this->urltab[0][0]; } //------------------------------------------------------------------------------ // Ustawianie head //------------------------------------------------------------------------------ function addcss($a) //a jest stringiem { $this->css.=''."\n"; } function addjs($a) //a jest stringiem { $this->js.=''."\n"; } //------------------------------------------------------------------------------ // Dodawanie klocków kontentu //------------------------------------------------------------------------------ function add($a) //a jest stringiem { $this->bodyblock[]=$a; } function addf($a) //a jest sciezka do templatki { $this->bodyblock[]=$this->fetch($a); } //------------------------------------------------------------------------------ // Funkcja decyzyjna czy dany modol moze zostać załadowany //------------------------------------------------------------------------------ function auth($allowed=array()) { $a=$this->urltab[0][0]; $b= !empty($this->urltab[0][1])? $this->urltab[0][1]:$this->urltab[0][0]; $x = is_file('modules/'.$a.'/'.$a.'_'.$b.'.php'); if(!$x) $this->utgen($this->defaultpage); else if(!empty($allowed) && !in_array($this->urltab[0][0],$allowed) && !in_array($this->urltab[0][0],$this->offpipe)) $this->utgen($this->norights); //return $x; } //------------------------------------------------------------------------------ // Url //------------------------------------------------------------------------------ function url($a=0,$b=0) { return $this->urltab[$a][$b]; } //------------------------------------------------------------------------------ // Powrót //------------------------------------------------------------------------------ function go_back() { /* $tmp=$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; $tmpa=explode('/',$tmp); unset( $tmpa[ count($tmpa)-1 ] ); $this->html_head['base']='http://'.implode('/',$tmpa).'/'; header('location: http://'.implode('/',$tmpa).$_SESSION['class_body']['go_back']); */ header('location: /'.$_SERVER['HTTP_REFERER']); die(); } //------------------------------------------------------------------------------ // Finalizacja i wyświetlenie wyników //------------------------------------------------------------------------------ function execute() { if(!in_array($this->urltab[0][0],$this->offpipe) && in_array($this->url(0,0),$this->modules) ) { $this->assign('BODY',implode("\n",$this->bodyblock)); $page =' '.$this->html_head['title'].' '.$this->css.' '.$this->js.' '.$this->fetch($this->index_tpl).''; echo $page; unset($_SESSION['class_body']['go_back']); $_SESSION['class_body']['go_back']=$_SERVER['REQUEST_URI']; die(); } else { echo implode("",$this->bodyblock); }; } //------------------------------------------------------------------------------ // uploadplikow //------------------------------------------------------------------------------ function upload($plik) { if ( in_array($_FILES[$plik]["type"],$this->upload_allowedtype) && ($_FILES[$plik]["size"] < $this->upload_allowedsize)) { if ($_FILES[$plik]["error"] > 0) { echo 'err'; return false; } else { $ext=explode('.',$_FILES[$plik]["name"]); $tmpname=md5(date('U'))."gmx".md5($_FILES[$plik]["name"]).'.'.$ext[1]; if (file_exists($this->upload_dir.$tmpname)) { return false; } else { move_uploaded_file($_FILES[$plik]["tmp_name"],$this->upload_dir.$tmpname); return $tmpname; } } } else { return false; } } //------------------------------------------------------------------------------ // wyswietlanie obrazków zcachowanych //------------------------------------------------------------------------------ function image() { $nazwapliku=$this->servicedir."pliki/bodyupload/".$this->url(2,0); $ext=explode('.',$this->url(2,0)); $nazwaplikunew=$this->servicedir."pliki/bodyuploadcache/".$this->url(1,0).$this->url(1,1).$this->url(1,2).$this->url(2,0); //if(!is_file($nazwaplikunew)) { $max=$this->url(1,1); if(empty($max)) $max=999999; resize($nazwapliku,$this->url(1,0),$max,$nazwaplikunew,$this->url(1,2)); //function resize($img, $thumb_width,$thumb_height=10000 $newfilename, $sq=0) }; $nameexp=explode('.',$nazwaplikunew); //print_r($nameexp); //die(); switch(end($nameexp)) { default: case 'jpg': { header('Content-Type: image/jpeg'); readfile($nazwaplikunew); //img = LoadJpeg($nazwaplikunew); //imagejpeg($img); //imagedestroy($img); break; } case 'png': { header('Content-Type: image/png'); $img = LoadPNG($nazwaplikunew); imagepng($img); imagedestroy($img); break; } case 'gif': { break; } } die(); } //------------------------------------------------------------------------------ // zamiana linków na te ładne //------------------------------------------------------------------------------ function linkstr($str) //TODO poprawic wygląd linkow - zadnych '_' i '/' { $tmp=str_replace('_',"-",prepareURL($str)); //str_replace('%',"+",urlencode($str)); return $tmp; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ }; function clearDiacritics($sText) { $aReplacePL = array( 'ą' => 'a', 'ę' => 'e', 'ś' => 's', 'ć' => 'c', 'ó' => 'o', 'ń' => 'n', 'ż' => 'z', 'ź' => 'z', 'ł' => 'l', 'Ą' => 'A', 'Ę' => 'E', 'Ś' => 'S', 'Ć' => 'C', 'Ó' => 'O', 'Ń' => 'N', 'Ż' => 'Z', 'Ź' => 'Z', 'Ł' => 'L' ); return str_replace(array_keys($aReplacePL), array_values($aReplacePL), $sText); } function prepareURL($sText) { // pozbywamy się polskich znaków diakrytycznych $sText = clearDiacritics($sText); // dla przejrzystości wszystko z małych liter $sText = strtolower($sText); // wszystkie spacje zamieniamy na myślniki $sText = str_replace(' ', '-', $sText); // usuń wszytko co jest niedozwolonym znakiem $sText = preg_replace('/[^0-9a-z\-]+/', '', $sText); // zredukuj liczbę myślników do jednego obok siebie $sText = preg_replace('/[\-]+/', '-', $sText); // usuwamy możliwe myślniki na początku i końcu $sText = trim($sText, '-'); return $sText; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ function resize($img, $thumb_width=150,$thumb_height=0, $newfilename, $sq=0) { if($thumb_height==0 && $thumb_width!=0) $thumb_height=$thumb_width; if($thumb_width==0 && $thumb_height!=0) $thumb_width=$thumb_height; $max_width=$thumb_width; $max_height=$thumb_height; $offsetx=0; $offsety=0; //Check if GD extension is loaded if (!extension_loaded('gd') && !extension_loaded('gd2')) { trigger_error("GD is not loaded", E_USER_WARNING); return false; } //Get Image size info list($width_orig, $height_orig, $image_type) = getimagesize($img); switch ($image_type) { case 1: $im = imagecreatefromgif($img); break; case 2: $im = imagecreatefromjpeg($img); break; case 3: $im = imagecreatefrompng($img); break; default: trigger_error('Unsupported filetype!', E_USER_WARNING); break; } /*** calculate the aspect ratio ***/ //------------------------------------------------------------------------------ // skalowanie //------------------------------------------------------------------------------ $aspect_orig = (float) $height_orig / (float)$width_orig; $n=$height_orig; while($n>=$thumb_height || $n/$aspect_orig>=$thumb_width) { $n-=1; }; $thumb_height=(float)$n; $thumb_width=(float)$n/(float)$aspect_orig; //------------------------------------------------------------------------------ $xw=$thumb_width; $yw=$thumb_height; if($sq==1) { $xw=$max_width; $yw=$max_height; $n=$height_orig; while($n>=$max_height+1 && $n/$aspect_orig>=$max_width+1) { $n-=1; }; $thumb_height=(float)$n; $thumb_width=(float)$n/(float)$aspect_orig; $offsetx=($xw-$thumb_width)/2; $offsety=($yw-$thumb_height)/2; }; //------------------------------------------------------------------------------ $newImg = imagecreatetruecolor($xw, $yw); //------------------------------------------------------------------------------ if(($image_type == 1) OR ($image_type==3)) { imagealphablending($newImg, false); imagesavealpha($newImg,true); $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127); imagefilledrectangle($newImg, 0, 0, $thumb_width, $thumb_height, $transparent); } //------------------------------------------------------------------------------ imagecopyresampled($newImg, $im, $offsetx, $offsety, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig); //Generate the file, and rename it to $newfilename switch ($image_type) { case 1: imagegif($newImg,$newfilename); break; case 2: imagejpeg($newImg,$newfilename,90); break; case 3: imagepng($newImg,$newfilename); break; default: trigger_error('Failed resize image!', E_USER_WARNING); break; } //return $newfilename; } function sierotki($str) { $interpunkcja = array( ' .' => '. ', ' ,' => ', ', ' !' => '! ', ' ?' => '? ', ' :' => ': ', ' ;' => '; ', ' ( ' => ' (', ' ) ' => ') ', ' [ ' => ' [', ' ] ' => '] ', ' { ' => ' {', ' } ' => '} ', ' ' => ' ', ' ' => ' ' ); $str = str_replace(array_keys($interpunkcja), array_values($interpunkcja), $str); $za = array('z', 'za', 'zza', 'pod', 'od', 'np.', 'w', 'na', 'do', 'co', 'bez', 'u', 'w', 'nad', 'po', 'i', 'a', 'to', 'że', 'dla','o','by'); $sel = explode(' ', $str); foreach($sel as $k=>$v) { if(in_array(strtolower($v),$za)) $sel[$k]=$v.' '; else $sel[$k]=$v.' '; } $nstr = implode('',$sel); $przed = array('zł','zł.', 'cm','cm.', 'mm','mm.', 'ml.', 'ml', 'kg','usd','eur', 'szt','szt.'); $nsel = explode(' ', $nstr); foreach($nsel as $k=>$v) { if(in_array(strtolower($v),$przed,true)) { $nsel[$k]=' '.$v; } else { $nsel[$k]=' '.$v; } } $nstr2 = implode('',$nsel); return $nstr2; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ ?>