本文整理汇总了PHP中BL::getError方法的典型用法代码示例。如果您正苦于以下问题:PHP BL::getError方法的具体用法?PHP BL::getError怎么用?PHP BL::getError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BL
的用法示例。
在下文中一共展示了BL::getError方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateForm
/**
* Validate the form
*/
private function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
// redefine fields
$fileFile = $this->frm->getField('file');
$chkOverwrite = $this->frm->getField('overwrite');
// name checks
if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
// only xml files allowed
if ($fileFile->isAllowedExtension(array('xml'), sprintf(BL::getError('ExtensionNotAllowed'), 'xml'))) {
// load xml
$xml = @simplexml_load_file($fileFile->getTempFileName());
// invalid xml
if ($xml === false) {
$fileFile->addError(BL::getError('InvalidXML'));
}
}
}
if ($this->frm->isCorrect()) {
// import
$statistics = BackendLocaleModel::importXML($xml, $chkOverwrite->getValue());
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics));
// everything is imported, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('index') . '&report=imported&var=' . ($statistics['imported'] . '/' . $statistics['total']) . $this->filterQuery);
}
}
}
示例2: loadData
/**
* Load the data.
* This will also set some warnings if needed.
*/
private function loadData()
{
// inform that the module is not installed yet
if (!BackendExtensionsModel::isModuleInstalled($this->currentModule)) {
$this->warnings[] = array('message' => BL::getMessage('InformationModuleIsNotInstalled'));
}
// path to information file
$pathInfoXml = BACKEND_MODULES_PATH . '/' . $this->currentModule . '/info.xml';
// information needs to exists
if (SpoonFile::exists($pathInfoXml)) {
try {
// load info.xml
$infoXml = @new SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
// convert xml to useful array
$this->information = BackendExtensionsModel::processModuleXml($infoXml);
// empty data (nothing useful)
if (empty($this->information)) {
$this->warnings[] = array('message' => BL::getMessage('InformationFileIsEmpty'));
}
// check if cronjobs are installed already
if (isset($this->information['cronjobs'])) {
foreach ($this->information['cronjobs'] as $cronjob) {
if (!$cronjob['active']) {
$this->warnings[] = array('message' => BL::getError('CronjobsNotSet'));
}
break;
}
}
} catch (Exception $e) {
$this->warnings[] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded'));
}
} else {
$this->warnings[] = array('message' => BL::getMessage('InformationFileIsMissing'));
}
}
示例3: validateForm
/**
* Validate the form.
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// get field
$txtName = $this->frm->getField('name');
// name filled in?
if ($txtName->isFilled(BL::getError('NameIsRequired'))) {
// name exists?
if (BackendProfilesModel::existsGroupName($txtName->getValue())) {
// set error
$txtName->addError(BL::getError('GroupNameExists'));
}
}
// no errors?
if ($this->frm->isCorrect()) {
// build item
$values['name'] = $txtName->getValue();
// insert values
$id = BackendProfilesModel::insertGroup($values);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $values));
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('groups') . '&report=group-added&var=' . urlencode($values['name']) . '&highlight=row-' . $id);
}
}
}
示例4: validateForm
/**
* Validate the form
*
* @return void
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// shorten the fields
$txtName = $this->frm->getField('name');
$txtEmail = $this->frm->getField('email');
$ddmMethod = $this->frm->getField('method');
$txtSuccessMessage = $this->frm->getField('success_message');
$txtIdentifier = $this->frm->getField('identifier');
// validate fields
$txtName->isFilled(BL::getError('NameIsRequired'));
$txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired'));
if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') {
$txtEmail->isEmail(BL::getError('EmailIsRequired'));
}
// identifier
if ($txtIdentifier->isFilled()) {
// invalid characters
if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) {
$txtIdentifier->setError(BL::getError('InvalidIdentifier'));
} elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue())) {
$txtIdentifier->setError(BL::getError('UniqueIdentifier'));
}
}
// no errors?
if ($this->frm->isCorrect()) {
// build array
$values['language'] = BL::getWorkingLanguage();
$values['user_id'] = BackendAuthentication::getUser()->getUserId();
$values['name'] = $txtName->getValue();
$values['method'] = $ddmMethod->getValue();
$values['email'] = $values['method'] == 'database_email' ? $txtEmail->getValue() : null;
$values['success_message'] = $txtSuccessMessage->getValue(true);
$values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier();
$values['created_on'] = BackendModel::getUTCDate();
$values['edited_on'] = BackendModel::getUTCDate();
// insert the item
$id = BackendFormBuilderModel::insert($values);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values));
// set frontend locale
FL::setLocale(BL::getWorkingLanguage());
// create submit button
$field['form_id'] = $id;
$field['type'] = 'submit';
$field['settings'] = serialize(array('values' => ucfirst(FL::getLabel('Send'))));
BackendFormBuilderModel::insertField($field);
// everything is saved, so redirect to the editform
$this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id . '&report=added&var=' . urlencode($values['name']) . '#tabFields');
}
}
}
示例5: validateForm
/**
* Validate the form.
*
* @return void
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// get fields
$ddmGroup = $this->frm->getField('group');
$txtExpirationDate = $this->frm->getField('expiration_date');
$txtExpirationTime = $this->frm->getField('expiration_time');
// fields filled?
$ddmGroup->isFilled(BL::getError('FieldIsRequired'));
if ($txtExpirationDate->isFilled()) {
$txtExpirationDate->isValid(BL::getError('DateIsInvalid'));
}
if ($txtExpirationTime->isFilled()) {
$txtExpirationTime->isValid(BL::getError('TimeIsInvalid'));
}
// no errors?
if ($this->frm->isCorrect()) {
// build item
$values['profile_id'] = $this->id;
$values['group_id'] = $ddmGroup->getSelected();
$values['starts_on'] = BackendModel::getUTCDate();
// only format date if not empty
if ($txtExpirationDate->isFilled() && $txtExpirationTime->isFilled()) {
// format date
$values['expires_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($txtExpirationDate, $txtExpirationTime));
}
// insert values
$id = BackendProfilesModel::insertProfileGroup($values);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_profile_add_to_group', array('item' => $values));
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $values['profile_id'] . '&report=membership-added&highlight=row-' . $id . '#tabGroups');
}
}
}
示例6: validateForm
/**
* Validate the form
*/
private function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
// shorten the fields
$txtName = $this->frm->getField('name');
$txtEmail = $this->frm->getField('email');
$ddmMethod = $this->frm->getField('method');
$txtSuccessMessage = $this->frm->getField('success_message');
$txtIdentifier = $this->frm->getField('identifier');
$emailAddresses = (array) explode(',', $txtEmail->getValue());
// validate fields
$txtName->isFilled(BL::getError('NameIsRequired'));
$txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired'));
if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') {
$error = false;
// check the addresses
foreach ($emailAddresses as $address) {
$address = trim($address);
if (!SpoonFilter::isEmail($address)) {
$error = true;
break;
}
}
// add error
if ($error) {
$txtEmail->addError(BL::getError('EmailIsInvalid'));
}
}
// identifier
if ($txtIdentifier->isFilled()) {
// invalid characters
if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) {
$txtIdentifier->setError(BL::getError('InvalidIdentifier'));
} elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue(), $this->id)) {
$txtIdentifier->setError(BL::getError('UniqueIdentifier'));
}
}
if ($this->frm->isCorrect()) {
// build array
$values['name'] = $txtName->getValue();
$values['method'] = $ddmMethod->getValue();
$values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null;
$values['success_message'] = $txtSuccessMessage->getValue(true);
$values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier();
$values['edited_on'] = BackendModel::getUTCDate();
// insert the item
$id = (int) BackendFormBuilderModel::update($this->id, $values);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values));
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($values['name']) . '&highlight=row-' . $id);
}
}
}
示例7: validateForm
/**
* Validate a submitted form and process it.
*/
private function validateForm()
{
// the form is submitted
if ($this->frm->isSubmitted()) {
// shorten field variables
$fileFile = $this->frm->getField('file');
// validate the file
if ($fileFile->isFilled(BL::err('FieldIsRequired')) && $fileFile->isAllowedExtension(array('zip'), sprintf(BL::getError('ExtensionNotAllowed'), 'zip'))) {
$moduleName = $this->installModule();
}
// passed all validation
if ($this->frm->isCorrect()) {
// by now, the module has already been installed in processZipFile()
// redirect with fireworks
$this->redirect(BackendModel::createURLForAction('modules') . '&report=module-installed&var=' . $moduleName . '&highlight=row-module_' . $moduleName);
}
}
}
示例8: validateForm
/**
* Validate the form
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// required fields
$this->frm->getField('file')->isFilled(BL::err('FieldIsRequired'));
$this->frm->getField('label')->isFilled(BL::err('FieldIsRequired'));
$this->frm->getField('format')->isFilled(BL::err('FieldIsRequired'));
// validate syntax
$syntax = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue()));
// init var
$table = BackendExtensionsModel::templateSyntaxToArray($syntax);
// validate the syntax
if ($table === false) {
$this->frm->getField('format')->addError(BL::err('InvalidTemplateSyntax'));
} else {
$html = BackendExtensionsModel::buildTemplateHTML($syntax);
$cellCount = 0;
$first = true;
$errors = array();
// loop rows
foreach ($table as $row) {
// first row defines the cellcount
if ($first) {
$cellCount = count($row);
}
// not same number of cells
if (count($row) != $cellCount) {
// add error
$errors[] = BL::err('InvalidTemplateSyntax');
// stop
break;
}
// doublecheck position names
foreach ($row as $cell) {
// ignore unavailable space
if ($cell != '/') {
// not alphanumeric -> error
if (!in_array($cell, $this->names)) {
$errors[] = sprintf(BL::getError('NonExistingPositionName'), $cell);
} elseif (substr_count($html, '"#position-' . $cell . '"') != 1) {
$errors[] = BL::err('InvalidTemplateSyntax');
}
}
}
// reset
$first = false;
}
// add errors
if ($errors) {
$this->frm->getField('format')->addError(implode('<br />', array_unique($errors)));
}
}
// no errors?
if ($this->frm->isCorrect()) {
// build array
$item['id'] = $this->id;
$item['theme'] = $this->frm->getField('theme')->getValue();
$item['label'] = $this->frm->getField('label')->getValue();
$item['path'] = 'core/layout/templates/' . $this->frm->getField('file')->getValue();
$item['active'] = $this->frm->getField('active')->getChecked() ? 'Y' : 'N';
$item['data']['format'] = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue()));
$item['data']['names'] = $this->names;
$item['data']['default_extras'] = $this->extras;
$item['data']['default_extras_' . BackendLanguage::getWorkingLanguage()] = $this->extras;
// serialize
$item['data'] = serialize($item['data']);
// if this is the default template make the template active
if (BackendModel::getModuleSetting('pages', 'default_template') == $this->record['id']) {
$item['active'] = 'Y';
}
// if the template is in use we can't de-activate it
if (BackendExtensionsModel::isTemplateInUse($item['id'])) {
$item['active'] = 'Y';
}
// insert the item
BackendExtensionsModel::updateTemplate($item);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_edit_template', array('item' => $item));
// set default template
if ($this->frm->getField('default')->getChecked() && $item['theme'] == BackendModel::getModuleSetting('core', 'theme', 'core')) {
BackendModel::setModuleSetting('pages', 'default_template', $item['id']);
}
// update all existing pages using this template to add the newly inserted block(s)
if (BackendExtensionsModel::isTemplateInUse($item['id'])) {
BackendPagesModel::updatePagesTemplates($item['id'], $item['id'], $this->frm->getField('overwrite')->getChecked());
}
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('theme_templates') . '&theme=' . $item['theme'] . '&report=edited-template&var=' . urlencode($item['label']) . '&highlight=row-' . $item['id']);
}
}
}
示例9: validateForm
/**
* Validate the form
*
* @return void
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// get fields
$txtEmail = $this->frm->getField('email');
$txtDisplayName = $this->frm->getField('display_name');
$txtPassword = $this->frm->getField('password');
$txtFirstName = $this->frm->getField('first_name');
$txtLastName = $this->frm->getField('last_name');
$txtCity = $this->frm->getField('city');
$ddmGender = $this->frm->getField('gender');
$ddmDay = $this->frm->getField('day');
$ddmMonth = $this->frm->getField('month');
$ddmYear = $this->frm->getField('year');
$ddmCountry = $this->frm->getField('country');
// email filled in?
if ($txtEmail->isFilled(BL::getError('EmailIsRequired'))) {
// valid email?
if ($txtEmail->isEmail(BL::getError('EmailIsInvalid'))) {
// email already exists?
if (BackendProfilesModel::existsByEmail($txtEmail->getValue(), $this->id)) {
// set error
$txtEmail->addError(BL::getError('EmailExists'));
}
}
}
// display name filled in?
if ($txtDisplayName->isFilled(BL::getError('DisplayNameIsRequired'))) {
// display name already exists?
if (BackendProfilesModel::existsDisplayName($txtDisplayName->getValue(), $this->id)) {
// set error
$txtDisplayName->addError(BL::getError('DisplayNameExists'));
}
}
// one of the bday fields are filled in
if ($ddmDay->isFilled() || $ddmMonth->isFilled() || $ddmYear->isFilled()) {
// valid date?
if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) {
// set error
$ddmYear->addError(BL::getError('DateIsInvalid'));
}
}
// no errors?
if ($this->frm->isCorrect()) {
// build item
$values['email'] = $txtEmail->getValue();
// only update if display name changed
if ($txtDisplayName->getValue() != $this->profile['display_name']) {
$values['display_name'] = $txtDisplayName->getValue();
$values['url'] = BackendProfilesModel::getUrl($txtDisplayName->getValue(), $this->id);
}
// new password filled in?
if ($txtPassword->isFilled()) {
// get new salt
$salt = BackendProfilesModel::getRandomString();
// update salt
BackendProfilesModel::setSetting($this->id, 'salt', $salt);
// build password
$values['password'] = BackendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt);
}
// update values
BackendProfilesModel::update($this->id, $values);
// bday is filled in
if ($ddmYear->isFilled()) {
// mysql format
$birthDate = $ddmYear->getValue() . '-';
$birthDate .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-';
$birthDate .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT);
} else {
$birthDate = null;
}
// update settings
BackendProfilesModel::setSetting($this->id, 'first_name', $txtFirstName->getValue());
BackendProfilesModel::setSetting($this->id, 'last_name', $txtLastName->getValue());
BackendProfilesModel::setSetting($this->id, 'gender', $ddmGender->getValue());
BackendProfilesModel::setSetting($this->id, 'birth_date', $birthDate);
BackendProfilesModel::setSetting($this->id, 'city', $txtCity->getValue());
BackendProfilesModel::setSetting($this->id, 'country', $ddmCountry->getValue());
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values));
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('index') . '&report=saved&var=' . urlencode($values['email']) . '&highlight=row-' . $this->id);
}
}
}
示例10: execute
/**
* Execute the action
*/
public function execute()
{
parent::execute();
// get parameters
$formId = SpoonFilter::getPostValue('form_id', null, '', 'int');
$fieldId = SpoonFilter::getPostValue('field_id', null, '', 'int');
$type = SpoonFilter::getPostValue('type', array('checkbox', 'dropdown', 'heading', 'paragraph', 'radiobutton', 'submit', 'textarea', 'textbox'), '', 'string');
$label = trim(SpoonFilter::getPostValue('label', null, '', 'string'));
$values = trim(SpoonFilter::getPostValue('values', null, '', 'string'));
$defaultValues = trim(SpoonFilter::getPostValue('default_values', null, '', 'string'));
$required = SpoonFilter::getPostValue('required', array('Y', 'N'), 'N', 'string');
$requiredErrorMessage = trim(SpoonFilter::getPostValue('required_error_message', null, '', 'string'));
$validation = SpoonFilter::getPostValue('validation', array('email', 'numeric'), '', 'string');
$validationParameter = trim(SpoonFilter::getPostValue('validation_parameter', null, '', 'string'));
$errorMessage = trim(SpoonFilter::getPostValue('error_message', null, '', 'string'));
// invalid form id
if (!BackendFormBuilderModel::exists($formId)) {
$this->output(self::BAD_REQUEST, null, 'form does not exist');
}
// invalid fieldId
if ($fieldId !== 0 && !BackendFormBuilderModel::existsField($fieldId, $formId)) {
$this->output(self::BAD_REQUEST, null, 'field does not exist');
}
// invalid type
if ($type == '') {
$this->output(self::BAD_REQUEST, null, 'invalid type provided');
}
// init
$errors = array();
// validate textbox
if ($type == 'textbox') {
if ($label == '') {
$errors['label'] = BL::getError('LabelIsRequired');
}
if ($required == 'Y' && $requiredErrorMessage == '') {
$errors['required_error_message'] = BL::getError('ErrorMessageIsRequired');
}
if ($validation != '' && $errorMessage == '') {
$errors['error_message'] = BL::getError('ErrorMessageIsRequired');
}
} elseif ($type == 'textarea') {
if ($label == '') {
$errors['label'] = BL::getError('LabelIsRequired');
}
if ($required == 'Y' && $requiredErrorMessage == '') {
$errors['required_error_message'] = BL::getError('ErrorMessageIsRequired');
}
if ($validation != '' && $errorMessage == '') {
$errors['error_message'] = BL::getError('ErrorMessageIsRequired');
}
} elseif ($type == 'heading' && $values == '') {
$errors['values'] = BL::getError('ValueIsRequired');
} elseif ($type == 'paragraph' && $values == '') {
$errors['values'] = BL::getError('ValueIsRequired');
} elseif ($type == 'submit' && $values == '') {
$errors['values'] = BL::getError('ValueIsRequired');
} elseif ($type == 'dropdown') {
// values trim
$values = trim($values, ',');
// validate
if ($label == '') {
$errors['label'] = BL::getError('LabelIsRequired');
}
if ($required == 'Y' && $requiredErrorMessage == '') {
$errors['required_error_message'] = BL::getError('ErrorMessageIsRequired');
}
if ($values == '') {
$errors['values'] = BL::getError('ValueIsRequired');
}
} elseif ($type == 'radiobutton') {
if ($label == '') {
$errors['label'] = BL::getError('LabelIsRequired');
}
if ($required == 'Y' && $requiredErrorMessage == '') {
$errors['required_error_message'] = BL::getError('ErrorMessageIsRequired');
}
if ($values == '') {
$errors['values'] = BL::getError('ValueIsRequired');
}
} elseif ($type == 'checkbox') {
if ($label == '') {
$errors['label'] = BL::getError('LabelIsRequired');
}
if ($required == 'Y' && $requiredErrorMessage == '') {
$errors['required_error_message'] = BL::getError('ErrorMessageIsRequired');
}
}
// got errors
if (!empty($errors)) {
$this->output(self::OK, array('errors' => $errors), 'form contains errors');
}
// htmlspecialchars except for paragraphs
if ($type != 'paragraph') {
if ($values != '') {
$values = SpoonFilter::htmlspecialchars($values);
}
if ($defaultValues != '') {
//.........这里部分代码省略.........
示例11: getModuleInformation
/**
* Fetch the module information from the info.xml file.
*
* @param string $module
* @return array
*/
public static function getModuleInformation($module)
{
// path to information file
$pathInfoXml = BACKEND_MODULES_PATH . '/' . $module . '/info.xml';
// the module information
$information = array('data' => array(), 'warnings' => array());
// information needs to exists
if (SpoonFile::exists($pathInfoXml)) {
try {
// load info.xml
$infoXml = @new SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
// convert xml to useful array
$information['data'] = self::processModuleXml($infoXml);
// empty data (nothing useful)
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;
}
示例12: validateGeneralForm
/**
* Validates the general tab
*
* @return void
*/
private function validateGeneralForm()
{
// form is submitted
if ($this->frmGeneral->isSubmitted()) {
// validate required fields
$this->frmGeneral->getField('from_name')->isFilled(BL::getError('FieldIsRequired'));
$this->frmGeneral->getField('from_email')->isEmail(BL::getError('EmailIsInvalid'));
$this->frmGeneral->getField('reply_to_email')->isEmail(BL::getError('EmailIsInvalid'));
// user is god
if (BackendAuthentication::getUser()->isGod()) {
$this->frmGeneral->getField('price_per_email')->isFilled(BL::err('FieldIsRequired'));
}
// form is validated
if ($this->frmGeneral->isCorrect()) {
// set sender info
BackendModel::setModuleSetting($this->getModule(), 'from_name', $this->frmGeneral->getField('from_name')->getValue());
BackendModel::setModuleSetting($this->getModule(), 'from_email', $this->frmGeneral->getField('from_email')->getValue());
BackendModel::setModuleSetting($this->getModule(), 'reply_to_email', $this->frmGeneral->getField('reply_to_email')->getValue());
BackendModel::setModuleSetting($this->getModule(), 'plain_text_editable', $this->frmGeneral->getField('plain_text_editable')->getValue());
// set price per email
if (BackendAuthentication::getUser()->isGod()) {
BackendModel::setModuleSetting($this->getModule(), 'price_per_email', $this->frmGeneral->getField('price_per_email')->getValue());
}
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_saved_general_settings');
// redirect to the settings page
$this->redirect(BackendModel::createURLForAction('settings') . '&report=saved#tabGeneral');
}
}
}
示例13: validateForm
/**
* Validate a submitted form and process it.
*/
private function validateForm()
{
// the form is submitted
if ($this->frm->isSubmitted()) {
// shorten field variables
$fileFile = $this->frm->getField('file');
// validate the file
if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
// only zip files allowed
if ($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) {
// get first entry (= the theme folder)
$file = $zip->statIndex(0);
// name of the module we are trying to upload
$themeName = trim($file['name'], '/');
// find info.xml
$infoXml = $zip->getFromName($themeName . '/info.xml');
// add error if info.xml is not found
if ($infoXml === false) {
$fileFile->addError(sprintf(BL::getError('NoInformationFile'), $themeName));
} else {
// parse xml
try {
// load info.xml
$infoXml = @new SimpleXMLElement($infoXml, LIBXML_NOCDATA, false);
// convert xml to useful array
$this->information = BackendExtensionsModel::processThemeXml($infoXml);
// empty data (nothing useful)
if (empty($this->information)) {
$fileFile->addError(BL::getMessage('InformationFileIsEmpty'));
}
// check if theme name in info.xml matches folder name
if ($this->information['name'] != $themeName) {
$fileFile->addError(BL::err('ThemeNameDoesntMatch'));
}
} catch (Exception $e) {
$fileFile->addError(BL::getMessage('InformationFileCouldNotBeLoaded'));
}
}
// wow wow, you are trying to upload an already existing theme
if (BackendExtensionsModel::existsTheme($themeName)) {
$fileFile->addError(sprintf(BL::getError('ThemeAlreadyExists'), $themeName));
}
// list of validated files (these files will actually be unpacked)
$files = array();
// check every file in the zip
for ($i = 0; $i < $zip->numFiles; $i++) {
// get the file name
$file = $zip->statIndex($i);
$fileName = $file['name'];
// yay, in a valid directory
if (stripos($fileName, $themeName . '/') === 0) {
// valid file, add to extraction-list
$files[] = $fileName;
}
}
} else {
$fileFile->addError(BL::getError('FileIsEmpty'));
}
} else {
$fileFile->addError(BL::getError('CorruptedFile'));
}
}
}
// passed all validation
if ($this->frm->isCorrect()) {
// unpack module files
$zip->extractTo(FRONTEND_PATH . '/themes', $files);
// run installer
BackendExtensionsModel::installTheme($themeName);
// redirect with fireworks
$this->redirect(BackendModel::createURLForAction('themes') . '&report=theme-installed&var=' . $themeName);
}
}
}