/** * Parses the html for this filefield. * * @param TwigTemplate $template The template to parse the element in. * * @return string * @throws \SpoonFormException */ public function parse($template = null) { // name is required if ($this->attributes['name'] == '') { throw new \SpoonFormException('A name is required for a file field. Please provide a name.'); } // start html generation $output = '<input type="file"'; // add attributes $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />'; // add help txt if needed if (!$this->hideHelpTxt) { if (isset($this->attributes['extension'])) { $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpFileFieldWithMaxFileSize', 'core'), $this->attributes['extension'], Form::getUploadMaxFileSize()) . '</p>'; } else { $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpMaxFileSize'), Form::getUploadMaxFileSize()) . '</p>'; } } // parse to template if ($template !== null) { $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']), $output); $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError text-danger">' . $this->errors . '</span>' : ''); } return $output; }
/** * Load the data. * This will also set some warnings if needed. */ private function loadData() { // inform that the module is not installed yet if (!BackendModel::isModuleInstalled($this->currentModule)) { $this->warnings[] = array('message' => BL::getMessage('InformationModuleIsNotInstalled')); } // fetch the module information $moduleInformation = BackendExtensionsModel::getModuleInformation($this->currentModule); $this->information = $moduleInformation['data']; $this->warnings = $this->warnings + $moduleInformation['warnings']; }
/** * Parse amount of forms sent for the datagrid * * @param int $formId Id of the form. * @param int $sentForms Amount of sent forms. * * @return string */ public static function parseNumForms($formId, $sentForms) { // redefine $formId = (int) $formId; $sentForms = (int) $sentForms; // one form sent if ($sentForms == 1) { $output = BL::getMessage('OneSentForm'); } elseif ($sentForms > 1) { // multiple forms sent $output = sprintf(BL::getMessage('SentForms'), $sentForms); } else { // no forms sent $output = sprintf(BL::getMessage('SentForms'), $sentForms); } // check if data action is allowed if (BackendAuthentication::isAllowedAction('Data', 'FormBuilder')) { // output $output = '<a href="' . BackendModel::createURLForAction('Data') . '&id=' . $formId . '" title="' . $output . '">' . $output . '</a>'; } return $output; }
/** * Get a message from the language-file * * @param string $key The key to get. * @param string $module The module wherein we should search. * * @deprecated * * @return string */ public static function getMessage($key, $module = null) { trigger_error('Backend\\Core\\Engine\\Language is deprecated. It has been moved to Backend\\Core\\Language\\Language', E_USER_DEPRECATED); return parent::getMessage($key, $module); }
/** * @param $message string * * @return string */ private function msg($message) { return BackendLanguage::getMessage($message); }
/** * Fetch the module information from the info.xml file. * * @param string $module * * @return array */ public static function getModuleInformation($module) { $pathInfoXml = BACKEND_MODULES_PATH . '/' . $module . '/info.xml'; $information = array('data' => array(), 'warnings' => array()); if (is_file($pathInfoXml)) { try { $infoXml = @new \SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true); $information['data'] = self::processModuleXml($infoXml); if (empty($information['data'])) { $information['warnings'][] = array('message' => BL::getMessage('InformationFileIsEmpty')); } // check if cronjobs are installed already if (isset($information['data']['cronjobs'])) { foreach ($information['data']['cronjobs'] as $cronjob) { if (!$cronjob['active']) { $information['warnings'][] = array('message' => BL::getError('CronjobsNotSet')); } break; } } } catch (Exception $e) { $information['warnings'][] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded')); } } else { $information['warnings'][] = array('message' => BL::getMessage('InformationFileIsMissing')); } return $information; }
/** * Validate a submitted form and process it. */ private function validateForm() { // The form is submitted if (!$this->frm->isSubmitted()) { return; } /** @var $fileFile \SpoonFormFile */ $fileFile = $this->frm->getField('file'); $zip = null; $zipFiles = null; // Validate the file. Check if the file field is filled and if it's a zip. if ($fileFile->isFilled(BL::err('FieldIsRequired')) && $fileFile->isAllowedExtension(array('zip'), sprintf(BL::getError('ExtensionNotAllowed'), 'zip'))) { // Create ziparchive instance $zip = new ZipArchive(); // Try and open it if ($zip->open($fileFile->getTempFileName()) === true) { // zip file needs to contain some files if ($zip->numFiles > 0) { $infoXml = $this->findInfoFileInZip($zip); // Throw error if info.xml is not found if ($infoXml === null) { return $fileFile->addError(sprintf(BL::getError('NoInformationFile'), $fileFile->getFileName())); } // Parse xml try { // Load info.xml $infoXml = @new \SimpleXMLElement($infoXml, LIBXML_NOCDATA, false); // Convert xml to useful array $this->info = BackendExtensionsModel::processThemeXml($infoXml); // Empty data (nothing useful) if (empty($this->info)) { return $fileFile->addError(BL::getMessage('InformationFileIsEmpty')); } // Define the theme name, based on the info.xml file. $this->themeName = $this->info['name']; } catch (Exception $e) { // Warning that the information file is corrupt return $fileFile->addError(BL::getMessage('InformationFileCouldNotBeLoaded')); } // Wow wow, you are trying to upload an already existing theme if (BackendExtensionsModel::existsTheme($this->themeName)) { return $fileFile->addError(sprintf(BL::getError('ThemeAlreadyExists'), $this->themeName)); } $zipFiles = $this->getValidatedFilesList($zip); } else { // Empty zip file $fileFile->addError(BL::getError('FileIsEmpty')); } } else { // Something went very wrong, probably corrupted return $fileFile->addError(BL::getError('CorruptedFile')); } } // Passed all validation if ($this->frm->isCorrect() && $zip !== null) { // Unpack the zip. If the files were not found inside a parent directory, we create the theme directory. $themePath = FRONTEND_PATH . '/Themes'; if ($this->parentFolderName === null) { $themePath .= "/{$this->themeName}"; } $zip->extractTo($themePath, $zipFiles); // Rename the original name of the parent folder from the zip to the correct theme foldername. $fs = new Filesystem(); $parentZipFolderPath = $themePath . '/' . $this->parentFolderName; if ($this->parentFolderName !== $this->themeName && $this->parentFolderName !== null && $fs->exists($parentZipFolderPath)) { $fs->rename($parentZipFolderPath, "{$themePath}/{$this->themeName}"); } // Run installer BackendExtensionsModel::installTheme($this->themeName); // Redirect with fireworks $this->redirect(BackendModel::createURLForAction('Themes') . '&report=theme-installed&var=' . $this->themeName); } }
/** * Load the data. * This will also set some warnings if needed. */ private function loadData() { // inform that the theme is not installed yet if (!BackendExtensionsModel::isThemeInstalled($this->currentTheme)) { $this->warnings[] = array('message' => BL::getMessage('InformationThemeIsNotInstalled')); } // path to information file $pathInfoXml = FRONTEND_PATH . '/Themes/' . $this->currentTheme . '/info.xml'; // information needs to exists if (is_file($pathInfoXml)) { try { // load info.xml $infoXml = @new \SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true); // convert xml to useful array $this->information = BackendExtensionsModel::processThemeXml($infoXml); // empty data (nothing useful) if (empty($this->information)) { $this->warnings[] = array('message' => BL::getMessage('InformationFileIsEmpty')); } } catch (\Exception $e) { // warning that the information file is corrupt $this->warnings[] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded')); } } else { // warning that the information file is missing $this->warnings[] = array('message' => BL::getMessage('InformationFileIsMissing')); } }