/** * Gets the HTML of a option * @param string $key name of the option * @param string $value value for the option * @param boolean $isSelected flag to see if this option is selected * @return string */ protected function getHtmlOption($key, $value, $isSelected) { $idSuffix = ucfirst(String::safeString($key)); $id = $this->getId() . $idSuffix; $html = '<input' . $this->getAttributeHtml('type', $this->isMultiple() ? 'checkbox' : 'radio') . $this->getNameHtml() . $this->getAttributeHtml('value', $key) . ($isSelected ? $this->getAttributeHtml('checked', 'checked') : '') . $this->getAttributeHtml('id', $id) . $this->getClassHtml() . $this->getAttributesHtml() . ' />'; if (!$value) { return $html; } $html .= '<label'; if ($id) { $html .= $this->getAttributeHtml('for', $id); } $html .= '>' . $value . '</label>'; return $html; }
/** * Gets the HTML for a specific option in this field * @param string $option key of the option * @return string * @throws zibo\ZiboException when no options set for this field * @throws zibo\ZiboException when the provided option could not be found */ public function getOptionHtml($option) { $html = ''; if (!$this->options) { throw new ZiboException('No options set'); } if (!isset($this->options[$option])) { throw new ZiboException($option . ' is not in the option list'); } $idSuffix = ucfirst(String::safeString($option)); $id = $this->getId() . $idSuffix; $value = $this->options[$option]; $isSelected = false; $selected = null; $this->processValue($option, $value, $isSelected, $selected); return $this->getSubmitHtml($id, $value, $option); }
/** * Validates the data and generates the slug for the data * @param mixed $data The data object of the model * @return null * @throws zibo\library\validation\exception\ValidationException when the data is not valid */ public function validate($data) { $slugString = $this->getSlugString($data); if ($slugString) { $slug = $baseSlug = String::safeString($slugString); $index = 1; do { $query = $this->createQuery(); $query->addCondition('{slug} = %1%', $slug); if ($data->id) { $query->addCondition('{id} <> %1%', $data->id); } if ($query->count()) { $slug = $baseSlug . '-' . $index; $index++; } else { break; } } while (true); $data->slug = $slug; } parent::validate($data); }
/** * @dataProvider providerSafeString */ public function testSafeString($expected, $value) { $locale = setlocale(LC_ALL, 'en_IE.utf8', 'en_IE', 'en'); $result = String::safeString($value); $this->assertEquals($expected, $result); }
/** * Action to rename a file or directory * * Every argument to this method is a part of the rename path. eg. * $fb->renameAction('application', 'data', 'test.txt') would rename to application/data/test.txt * @return null */ public function renameAction() { $pieces = func_get_args(); $file = $this->getFileFromPieces($pieces, false); if (!$file) { $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); } else { $absoluteFile = new File($this->fileBrowser->getRoot(), $file); if (!$absoluteFile->exists()) { $this->addError(self::TRANSLATION_ERROR_EXIST_NOT, array('path' => $file)); $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); } } if ($this->response->getStatusCode() == Response::STATUS_CODE_NOT_FOUND) { $this->response->setView(new BaseView()); return; } $basePath = $this->request->getBasePath(); $parent = $absoluteFile->getParent(); $redirectUrl = $basePath . '/' . self::ACTION_PATH . '/' . $this->fileBrowser->getPath($parent, false); $form = new RenameForm($basePath . '/' . self::ACTION_RENAME . '/' . $file, $file); if ($form->isSubmitted()) { if ($form->isCancelled()) { $this->response->setRedirect($redirectUrl); return; } try { $form->validate(); $name = $form->getFileName(); $name = String::safeString($name); $destination = new File($parent, $name); if ($destination->getAbsolutePath() != $absoluteFile->getPath() && $destination->exists()) { $error = new ValidationError(self::TRANSLATION_ERROR_EXIST, '%path% exists already', array('path' => $this->fileBrowser->getPath($destination, false))); $exception = new ValidationException(); $exception->addErrors(RenameForm::FIELD_NAME, array($error)); throw $exception; } $absoluteFile->move($destination); $this->addInformation(self::TRANSLATION_INFORMATION_RENAMED, array('old' => $file->getName(), 'new' => $name)); $this->response->setRedirect($redirectUrl); return; } catch (ValidationException $exception) { $form->setValidationException($exception); } catch (Exception $exception) { Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1); $this->addError(self::TRANSLATION_ERROR, array('error' => $exception->getMessage())); $this->response->setStatusCode(Response::STATUS_CODE_SERVER_ERROR); } } if (!$absoluteFile->isWritable() || !$absoluteFile->getParent()->isWritable()) { $this->addWarning(self::TRANSLATION_ERROR_WRITABLE, array('path' => $file)); $form->setIsDisabled(true, RenameForm::BUTTON_SUBMIT); } $view = new RenameView($form, $file); $view->setPageTitle(Module::TRANSLATION_FILE_BROWSER, true); $this->response->setView($view); }
function smarty_modifier_safeString($string) { return String::safeString($string); }
/** * Upload a file * @param array $file Array with file upload details from PHP * @return string path to the uploaded file */ private function uploadFile($file) { if ($file['error'] == UPLOAD_ERR_NO_FILE) { $default = $this->getDefaultValue(); if (empty($default)) { $default = parent::getRequestValue($this->getName() . self::SUFFIX_DEFAULT); if (empty($default)) { $default = self::DEFAULT_VALUE; } } return $default; } $this->isUploadError($file); $this->uploadPath->create(); $uploadFileName = String::safeString($file['name']); $uploadFile = new File($this->uploadPath, $uploadFileName); if (!$this->willOverwrite()) { $uploadFile = $uploadFile->getCopyFile(); } if (!move_uploaded_file($file['tmp_name'], $uploadFile->getPath())) { throw new ZiboException('Could not move the uploaded file ' . $file['tmp_name'] . ' to ' . $uploadFile->getPath()); } $uploadFile->setPermissions(0644); return $uploadFile->getPath(); }
/** * Validate a node object * @return null * @throws zibo\library\validation\exception\ValidationException when the data is invalid * * @todo validate the route (unique) */ public function validate($data) { if (!isset($data->route) || empty($data->route)) { return parent::validate($data); } $route = rtrim(ltrim($data->route, Request::QUERY_SEPARATOR), Request::QUERY_SEPARATOR); $tokens = explode(Request::QUERY_SEPARATOR, $route); foreach ($tokens as $index => $token) { $token = String::safeString($token); if (empty($token)) { unset($tokens[$index]); } else { $tokens[$index] = $token; } } $data->route = implode(Request::QUERY_SEPARATOR, $tokens); try { parent::validate($data); $exception = new ValidationException(); } catch (ValidationException $e) { $exception = $e; } $query = $this->createQuery(0, $data->dataLocale, false); $query->setFields('{id}'); $query->addCondition('{parent} LIKE %1% AND {route} = %2% AND {id} <> %3%', $data->getRootNodeId() . self::PATH_SEPARATOR . '%', $data->route, $data->id); $node = $query->queryFirst(); if ($node) { $error = new ValidationError(self::VALIDATION_ROUTE_ERROR_CODE, self::VALIDATION_ROUTE_ERROR_MESSAGE, array('route' => $data->route, 'node' => $node->id)); $exception->addErrors('route', array($error)); } if ($exception->hasErrors()) { throw $exception; } }