public function add() { App::import('Sanitize'); $this->pageTitle .= ' - Dodaj'; if($this->data) { $u = $this->Upload; $s = $this->Session; $this->Post->id =(int) $s->read('id'); $this->Post->delete(); $s->delete('step2'); $s->delete('id'); $s->delete('img'); $s->delete('hash'); $this->redirect($this->referer()); } $s->del('step2'); return; } if((int)$s->read('Auth.User.active')===2) { $s->setFlash('Twoje konto jest nieaktywne, potwierdź adres email.'); $this->redirect($this->referer()); } if(!$s->check('step2')) { if(!$s->check('img')) { $u->upload($this->data['Post']['img']); } else { $u->upload(WWW_ROOT.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg'); } if($u->uploaded) { if($s->check('img')) { $now = $s->read('img'); } else { } if($s->check('hash')) { $hash = $s->read('hash'); } else { $hash = $this->Pwd->alphaNumPass(); $s->write('hash',$hash); } $title = $this->data['Post']['title']; $_size = 0; $_tsize = 0; $_size += 19; $_tsize += 11; $_size += 8; } $u->file_new_name_body = 'img'; $u->image_convert = 'png'; $u->image_resize = true; $u->image_x = 440; $u->image_safe_name = false; $u->image_ratio_y = true; $res = $u->process(); $img = imagecreatefromstring($res); imagejpeg($img,WWW_ROOT.'pic/sess/'.$now.'-1'.$s->read('hash').'.jpg',100); imagedestroy($img); $u->image_convert = 'png'; $u->image_resize = true; $u->image_x = 436; $u->image_ratio_y = true; $u->image_border_color = '#FFFFFF'; $u->image_border = '2px 2px 2px 2px'; $res = $u->process(); if($u->processed) { $img = imagecreatefromstring($res); $height = ($u->image_dst_y + 138); $bg = imagecreatetruecolor(500,$height); imagecopy($bg, $img,30,30,0,0,440,$height); $black = imagecolorallocate($bg,0,0,0); $white = imagecolorallocate($bg,255,255,255); $font = WWW_ROOT.'fonts/DejaVuSerif.ttf'; $bbox = imagettfbbox(18,0,$font,$title); $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2); $y = ($u->image_dst_y + 58 + $_tsize); imagettftext($bg,18,0,$x,$y,$white,$font,$title); $bbox = imagettfbbox(10,0,$font,$body[0]); $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2); $y = ($u->image_dst_y + 78 + $_size); imagettftext($bg,10,0,$x,$y,$white,$font,$body[0]); $bbox = imagettfbbox(10,0,$font,$body[1]); $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2); $y = ($u->image_dst_y + 96 + $_size); imagettftext($bg,10,0,$x,$y,$white,$font,$body[1]); } $bbox = imagettfbbox(10,0,$font,$body[2]); $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2); $y = ($u->image_dst_y + 114); imagettftext($bg,10,0,$x,$y,$white,$font,$body[2]); } $gray = imagecolorallocate($bg,80,80,80); $bbox = imagettfbbox(8,0,$font,$_SERVER['HTTP_HOST']); $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2); $y = ($u->image_dst_y + 134); imagettftext($bg,8,0,$x,$y,$gray,$font,$_SERVER['HTTP_HOST']); imagejpeg($bg, WWW_ROOT.'pic/sess/'.$now.'-2'.$s->read('hash').'.jpg',100); imagedestroy($img); imagedestroy($bg); if(!$s->check('id')) { $this->Post->create(); } else { $this->Post->id =(int) $s->read('id'); } $this->Post->set('public',2); 'Post'=>array( 'id'=>$this->Post->id, 'user_id'=>$this->Session->read('Auth.User.id'), 'title'=>Sanitize::html($title), 'body'=>Sanitize::html($this->data['Post']['body']), 'img'=>'pic/'.$now.'-'.$hash.'.jpg'), 'public' => 2 ) ); $s->write('id',$this->Post->id); $s->write('step2',true); $s->write('img',$now); return; } else { $s->setFlash('Nie można wgrać zdjęcia.'); return; } } } else { $u->upload(WWW_ROOT.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg'); if($u->uploaded) { $u->image_convert = 'jpg'; $u->jpeg_quality = 100; $u->file_safe_name = false; $u->file_new_name_body = $s->read('img').'-'.$s->read('hash'); $u->process(WWW_ROOT.'/pic/'); if($u->processed) { $this->Post->id =(int) $s->read('id'); $this->Post->set('public', 0); $this->Post->save(); foreach($tag as $k=>$v) { if($k==(int) $this->getOpt('max_tags')) break; $t = $this->Tag->findByName($v); if($t) { $this->PostsTag->create(); $this->Tag->id=$t['Tag']['id']; $this->PostsTag->save(array('PostsTag'=>array('post_id'=>$this->Post->id,'tag_id'=>$t['Tag']['id']))); continue; } $this->Tag->create(); $this->PostsTag->create(); $this->PostsTag->save(array('PostsTag'=>array('post_id'=>$this->Post->id,'tag_id'=>$this->Tag->id))); } } $s->del('id'); $s->del('step2'); $s->del('img'); $s->del('hash'); $this->redirect('/view/'.$this->Post->id); } } } } }
Proszę o pomoc, z góry dziękuję!