public function reorder(Request $req, Response $res) { if (!$req->isPost()) { throw new \Chalk\Exception("Reorder action only accepts POST requests"); } if (!$req->nodeData) { return $res->redirect($this->url(array('action' => 'index'))); } $data = json_decode($req->nodeData); $structure = $this->em('Chalk\\Core\\Structure')->id($req->structure); $nodes = $this->em('Chalk\\Core\\Structure\\Node')->all(['structure' => $structure]); $map = []; foreach ($nodes as $node) { $map[$node->id] = $node; } $it = new \RecursiveIteratorIterator(new Iterator($data), \RecursiveIteratorIterator::SELF_FIRST); $stack = []; foreach ($it as $i => $value) { array_splice($stack, $it->getDepth(), count($stack), array($value)); $depth = $it->getDepth(); $parent = $depth > 0 ? $stack[$depth - 1] : $structure->root; $node = $map[$value->id]; $node->parent->children->removeElement($node); $node->parent = $map[$parent->id]; $node->sort = $i; } $this->em->flush(); $this->notify("Content was moved successfully", 'positive'); if (isset($req->redirect)) { return $res->redirect($req->redirect); } else { return $res->redirect($this->url(array('action' => 'index'))); } }
public function publish(Request $req, Response $res) { $this->chalk->module('core')->publish(); $this->notify("Content was published successfully", 'positive'); if (isset($req->redirect)) { return $res->redirect($req->redirect); } else { return $res->redirect($this->url([], 'index', true)); } }
public function delete(Request $req, Response $res) { $entity = $this->em($req->info)->find($req->id); $this->em->remove($entity); try { $this->em->flush(); } catch (ForeignKeyConstraintViolationException $e) { $this->notify("{$req->info->singular} <strong>{$entity->name}</strong> could not be deleted because it is in use", 'negative'); return $res->redirect($this->url(array('action' => 'edit'))); } $this->notify("{$req->info->singular} <strong>{$entity->name}</strong> was deleted successfully", 'positive'); return $res->redirect($this->url(array('action' => null, 'id' => null))); }
public function merge(Request $req, Response $res) { $merge = new Merge(); $req->view->merge = $wrap = $this->em->wrap($merge); if (!$req->isPost()) { return; } $wrap->graphFromArray($req->bodyParams()); if (!$wrap->graphIsValid()) { $this->notify("{$req->info->plural} could not be merged, please check the messages below", 'negative'); return; } $sourceTag = $this->em('core_tag')->id($merge->sourceTag->id); $targetTag = $this->em('core_tag')->id($merge->targetTag->id); $entities = $this->em('core_content')->all(['tags' => [$sourceTag]]); foreach ($entities as $entity) { $entity->tags->removeElement($sourceTag); if (!$entity->tags->contains($targetTag)) { $entity->tags->add($targetTag); } } $this->em->remove($sourceTag); $this->em->flush(); $this->notify("{$req->info->plural} were merged successfully", 'positive'); return $res->redirect($this->url(array('action' => null, 'id' => null))); }
public function index(Request $req, Response $res) { $items = $this->navList->children('core_setting'); if (count($items)) { $item = current($items); return $res->redirect($this->url($item['url'][0], $item['url'][1], true)); } }
public function preDispatch(Request $req, Response $res) { $this->app->module = $this->chalk->module($req->group); $this->contentList = $this->hook->fire('core_contentList', new InfoList('core_main')); $this->widgetList = $this->hook->fire('core_widgetList', new InfoList()); $this->navList = $this->hook->fire('core_navList', new NavList()); $session = $this->session->data('__Chalk\\Backend'); if (!isset($session->user) && $req->controller !== 'auth') { $redirect = (string) $req->url()->toPart(Url::PART_PATH, true); return $res->redirect($this->url([], 'core_login', true) . $this->url->query(['redirect' => $redirect], true)); } $req->data = (object) []; $req->view = (object) []; if ($req->controller == 'auth') { return; } $req->user = $this->em('Chalk\\Core\\User')->id($session->user); if (!isset($req->user)) { $session->user = null; return $res->redirect($this->url([], 'core_login', true)); } $this->em->listener('core_trackable')->setUser($req->user); $saves = []; if (in_array("{$req->controller}__{$req->action}", $saves)) { $name = "query_" . md5(serialize($req->route['params'])); $params = $req->user->pref($name); unset($params['contentIds']); unset($params['batch']); if (isset($params)) { $req->queryParams($req->queryParams() + $params); } $params = $req->queryParams(); unset($params['contentIds']); unset($params['batch']); $req->user->pref($name, $params); $this->em->flush(); } }
public function delete(Request $req, Response $res) { $node = $this->em('Chalk\\Core\\Structure\\Node')->id($req->node); $parent = $node->parent; $parent->id; foreach ($node->children as $child) { $node->children->removeElement($child); $child->parent = $parent; $child->sort = \Chalk\Core\Structure\Node::VALUE_MAX; } $this->em->remove($node); $this->em->flush(); $this->notify(Chalk::info($node->content)->singular . " <strong>{$node->content->name}</strong> was removed successfully", 'positive'); return $res->redirect($this->url(array('action' => 'index', 'structure' => $node->structure->id), 'core_structure', true)); }
public function edit(Request $req, Response $res) { $name = $req->info->local->name; $entity = isset($req->id) ? $this->em($req->info)->id($req->id) : $this->em($req->info)->create(); $req->view->{$name} = $wrap = $this->em->wrap($entity); if (!$req->isPost()) { return; } $wrap->graphFromArray($req->bodyParams()); if (!$wrap->graphIsValid()) { return; } if (!$this->em->isPersisted($entity)) { $this->em->persist($entity); } $this->em->flush(); $this->notify("{$req->info->singular} <strong>{$entity->name}</strong> was saved successfully", 'positive'); return $res->redirect($this->url([])); }
public function index(Request $req, Response $res) { return $res->redirect($this->url->file($req->file->file)); }
public function logout(Request $req, Response $res) { // $this->session->regenerate(); $session = $this->session->data('__Chalk\\Backend'); $session->user = null; return $res->redirect($this->url([], 'core_login', true)); }
public function index(Request $req, Response $res) { return $res->redirect($this->url($req->alias->content)); }
public function execute(Request $req, Response $res) { $parts = explode('/', $req->path()); if ($parts[0] != 'image') { return; } $file = new File("{$this->_baseDir}/{$req->file}"); $file = $file->toReal(); if (!$file->isWithin($this->_baseDir)) { throw new Image\Exception("File '{$file}' is not within base directory '{$this->_baseDir}'"); } else { if (!$file->isReadable()) { throw new Image\Exception("File '{$file}' is not readable"); } } $transforms = $req->transforms; $params = isset($req->params) ? $req->params : []; $output = $this->_generateOutput($file, $transforms, $params); $image = $this->_manager->make($file->name()); foreach ($transforms as $name) { $this->run($name, $image, $params); } $image->save($output->name(), isset($image->quality) ? $image->quality : 90); return $res->redirect(isset($this->_outputUrlResolver) ? $this->_outputUrlResolver->file($output) : $this->_urlResolver->file($output)); }
public function delete(Request $req, Response $res) { $content = $this->em($req->info)->find($req->content); try { $this->em->remove($content); $this->em->flush(); } catch (ForeignKeyConstraintViolationException $e) { $this->notify("{$req->info->singular} <strong>{$content->name}</strong> cannot be deleted because it is in use", 'negative'); if (isset($req->redirect)) { return $res->redirect($req->redirect); } else { return $res->redirect($this->url(array('action' => 'edit', 'content' => $content->id))); } } $this->notify("{$req->info->singular} <strong>{$content->name}</strong> was deleted successfully", 'positive'); return $res->redirect($this->url(array('action' => 'index', 'content' => null))); }