public function uploadAction()
{
$layoutId = $this->getRouteMatch()->getParam('id', null);
if (!empty($layoutId)) {
$layout = Layout\Model::fromId($layoutId);
if (empty($layout) or empty($_FILES['upload']['tmp_name']) or $_FILES['upload']['error'] != UPLOAD_ERR_OK) {
$this->flashMessenger()->addErrorMessage('Can not upload layout');
return $this->redirect()->toRoute('development/layout/edit', array('id' => $layoutId));
}
$layout->setContent(file_get_contents($_FILES['upload']['tmp_name']));
$layout->save();
$this->flashMessenger()->addSuccessMessage('Layout updated');
return $this->redirect()->toRoute('development/layout/edit', array('id' => $layoutId));
}
if (empty($_FILES['upload'])) {
$this->flashMessenger()->addErrorMessage('Can not upload layouts');
return $this->redirect()->toRoute('development/layout');
}
foreach ($_FILES['upload']['name'] as $idx => $name) {
if ($_FILES['upload']['error'][$idx] != UPLOAD_ERR_OK) {
continue;
}
$identifier = preg_replace('~\\.phtml$~', '', $name);
$layout = Layout\Model::fromIdentifier($identifier);
if (empty($layout)) {
continue;
}
$layout->setContent(file_get_contents($_FILES['upload']['tmp_name'][$idx]));
$layout->save();
}
$this->flashMessenger()->addSuccessMessage('Layouts updated');
return $this->redirect()->toRoute('development/layout');
}