| #0 | Phalcon\Image\Adapter\Gd->__construct(files/thumbs/)
/usr/share/nginx/html/admin/app/controllers/GalleriesController.php (275) <?php
class GalleriesController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
if ($this->session->has("user")) {
$user = $this->session->get("user");
$this->view->user = $user;
$this->view->menu = Menu::render($user['tipo']);
$list_fields = Galleries::get_list_fields();
$this->view->list_fields = $list_fields;
$this->view->class_name = 'galleries';
$this->view->module_name = 'Galerias de Imagens';
$this->view->op_act = 6;
$query_records = Galleries::find(array(
"conditions" => "id >= 1 ",
"order" => "id ASC"
));
$this->view->records = Galleries::listMyRecords($list_fields, $query_records);
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function addAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$this->view->user = $user;
$this->view->menu = Menu::render($user['tipo']);
$this->view->list_fields = Galleries::get_add_fields();
$this->view->class_name = 'galleries';
$this->view->module_name = 'Galerias de Imagens';
$this->view->op_act = 6;
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function saveAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$request = new Phalcon\Http\Request();
$gallery = new Galleries();
$gallery->name = $request->getPost("name");
$gallery->state = $request->getPost("state");
if ($gallery->save()) {
$this->response->redirect('galleries/edit/'.$gallery->id);
} else {
$this->dispatcher->forward(array(
"controller" => "galleries",
"action" => "add"
));
}
$this->view->disable();
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function editAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$this->view->user = $user;
$id = $this->dispatcher->getParam("id");
$this->view->id = $id;
$this->view->menu = Menu::render($user['tipo']);
$this->view->list_fields = Galleries::get_add_fields();
$this->view->class_name = 'galleries';
$this->view->module_name = 'Galerias de Imagens';
$this->view->op_act = 6;
$this->view->reg = Galleries::findFirst("id = ".$id);
$this->view->container = GalleryContainer::find("gallery_id = '".$id."'");
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function updateAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$request = new Phalcon\Http\Request();
$id = $this->dispatcher->getParam("id");
$gallery = Galleries::findFirst("id = ".$id);
$gallery->name = $request->getPost("name");
$gallery->state = $request->getPost("state");
if ($text->save()) {
$this->response->redirect('galleries');
} else {
$this->dispatcher->forward(array(
"controller" => "galleries",
"action" => "edit",
"params" => array('id' => $id),
));
}
$this->view->disable();
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function uploadAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$request = new Phalcon\Http\Request();
$id = $this->dispatcher->getParam("id");
$container = new GalleryContainer();
$container->gallery_id = $id;
$container->title = $request->getPost("file_title");
if ($this->request->hasFiles() == true) {
$baseLocation = 'files/';
$thumbsLocation = 'files/thumbs/';
foreach ($this->request->getUploadedFiles() as $file) {
$imagem = $file->getName();
$extention = explode('.', $imagem);
$ext = $extention[sizeof($extention)-1];
$filename = md5(time()).'.'.$ext;
$container->file = $filename;
$file->moveTo($baseLocation . $filename);
shell_exec('chmod 755 ' . $baseLocation . $filename);
$image = new Phalcon\Image\Adapter\GD($baseLocation . $filename);
$ori_width = $image->getWidth();
$ori_height = $image->getHeight();
$image->resize(300, round($ori_height * (300/$ori_width), 2))->save($thumbsLocation . $filename);
shell_exec('chmod 755 ' . $thumbsLocation . $filename);
}
}
if ($container->save()) {
$this->response->redirect('galleries/edit/'.$id);
} else {
$this->dispatcher->forward(array(
"controller" => "galleries",
"action" => "edit",
"params" => array('id' => $id),
));
}
$this->view->disable();
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function changeFaceAction(){
$request = new Phalcon\Http\Request();
$gal = $this->dispatcher->getParam("id");
$img = $request->getPost("img");
$old = GalleryContainer::findFirst("gallery_id = '".$gal."' AND face=1");
if ($old) {
$old->face = 0;
$old->save();
}
$new = GalleryContainer::findFirst("id = '".$img."'");
if ($new) {
$new->face = 1;
$new->save();
}
$this->view->disable();
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setContent('DONE');
$response->send();
}
public function changeTitleAction() {
$request = new Phalcon\Http\Request();
$img = $request->getPost("id");
$text = $request->getPost("text");
$image = GalleryContainer::findFirst("id = '".$img."'");
if ($image) {
$image->title = $text;
$image->save();
}
$this->view->disable();
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setContent('DONE');
$response->send();
}
public function deleteAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$id = $this->dispatcher->getParam("id");
$gallery = Galleries::findFirst("id = ".$id);
$gallery->delete();
$pics = GalleryContainer::find("gallery_id = '".$id."'");
$baseLocation = 'files/';
$thumbsLocation = 'files/thumbs/';
foreach ($pics as $pic) {
if (file_exists($baseLocation . $pic->file)) {
unlink($baseLocation . $pic->file);
}
if (file_exists($thumbsLocation . $pic->file)) {
unlink($thumbsLocation . $pic->file);
}
$pic->delete();
}
$this->response->redirect('galleries');
$this->view->disable();
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function renderAction(){
$request = new Phalcon\Http\Request();
$size = explode('x', $this->dispatcher->getParam("size"));
$file = $this->dispatcher->getParam("file");
$image = new Phalcon\Image\Adapter\GD("files/thumbs/".$file);
$dest = '/tmp/'.uniqid().'.jpg';
$ori_width = $image->getWidth();
$ori_height = $image->getHeight();
$new_height = $ori_height * ($size[0]/$ori_width);
if ($new_height < $size[1]) {
$new_height = $size[1];
$new_width = $ori_width * ($new_height/$ori_height);
} else {
$new_width = $size[0];
}
$image->resize($new_width, $new_height);
$image->save($dest, 100);
$image = new Phalcon\Image\Adapter\GD($dest);
$image->crop($size[0], $size[1]);
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setHeader('Content-Type', 'image/jpeg');
$response->setContent($image->render());
$response->send();
unlink($dest);
$this->view->disable();
}
public function openAction(){
$request = new Phalcon\Http\Request();
$file = $this->dispatcher->getParam("id");
$image = new Phalcon\Image\Adapter\GD("files/".$file);
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setHeader('Content-Type', 'image/jpeg');
$response->setContent($image->render());
$response->send();
$this->view->disable();
}
public function change_stateAction(){
if ($this->session->has("user")) {
$user = $this->session->get("user");
$id = $this->dispatcher->getParam("id");
$request = new Phalcon\Http\Request();
$status = $request->getPost("val");
$gal = Galleries::findFirst("id = ".$id);
if ($status == 1) $newS = 0;
else $newS = 1;
$gal->state = $newS;
$gal->save();
$this->view->disable();
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setContent('{"success": true, "val":'.$newS.'}');
$response->send();
} else {
$this->dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
}
}
public function removePicAction(){
$request = new Phalcon\Http\Request();
$gal = $this->dispatcher->getParam("id");
$img = $request->getPost("img");
$old = GalleryContainer::findFirst("id = '".$img."'");
if ($old) {
$baseLocation = 'files/';
$thumbsLocation = 'files/thumbs/';
if (file_exists($baseLocation . $old->file)) {
unlink($baseLocation . $old->file);
}
if (file_exists($thumbsLocation . $old->file)) {
unlink($thumbsLocation . $old->file);
}
$old->delete();
}
$this->view->disable();
$response = new \Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setContent('DONE');
$response->send();
}
}
|