protected function createComponentAddTagForm() { $form = new AppForm(); $form->addText("name", "Name", 40, 50); $form->addSubmit("s", "Add"); $presenter = $this; $form->onSubmit[] = function ($form) use($presenter) { $name = $form->values["name"]; $tag = new Tag(); $tag->name = $name; $tag->url = String::webalize($name); try { $tag->save(); $presenter->flashMessage("Tag was added!"); $presenter->redirect("default"); } catch (\ModelException $e) { $tag->addErrorsToForm($form); } }; return $form; }
public function setUrl($url) { $this->url = String::webalize($url); }
// security check //if (!$allowed) { // $state["error"] = "You are not allowed to upload files."; //} if (empty($file)) { $state["error"] = "No file was uploaded"; } // check directory if ($root === false || $dir === false || !String::startsWith($dir, $root) || !is_dir($dir) || !is_writable($dir)) { $state["error"] = "Problem with directory to upload."; } if (!empty($state["error"])) { die(json_encode($state)); } if ($file->isOk()) { $filename = String::webalize($file->getName(), "."); $success = @$file->move("{$dir}/{$filename}"); if ($success) { // nastavit typ - je to obrázek? $type = @$file->getImageSize() ? "image" : "file"; $prefix = $type == "image" ? FILES_IMAGE_INCLUDE_PREFIX : FILES_FILE_INCLUDE_PREFIX; $state["filename"] = $prefix . ($folder ? "{$folder}/" : "") . $filename; $state["type"] = $type; } else { $state["error"] = "Move failed"; } } else { $state["error"] = "Upload error " . $file->getError(); } // výstup echo json_encode($state);
public function setName($name) { $this->name = $name; $this->url = \Nette\String::webalize($name); }
/** * Rename file or directory * @param string folder * @param string old item name * @param string new item name */ public function actionRename($folder, $oldname, $newname) { // check rights if (!$this->getUser()->isInRole("admin")) { $this->sendError("Access denied."); } $oldpath = $this->getFolderPath($folder) . "/" . $oldname; $newpath = $this->getFolderPath($folder) . "/" . String::webalize($newname, "."); if (!file_exists($oldpath)) { $this->sendError("File does not exist."); } if (rename($oldpath, $newpath)) { $this->sendResponse(new JsonResponse(array("deleted" => true))); } else { $this->sendError("Unable to rename file."); } }