Exemplo n.º 1
0
 static function processLibXMLerrors(MessageStack $errors)
 {
     foreach (libxml_get_errors() as $error) {
         $error->type = $type;
         $errors->append(NULL, $error);
     }
     libxml_clear_errors();
 }
Exemplo n.º 2
0
 public function validateData(MessageStack $errors, Entry $entry, $data = null)
 {
     if (!isset($data->value) or strlen(trim($data->value)) == 0) {
         $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->{'name'})), 'code' => self::ERROR_MISSING));
         return self::STATUS_ERROR;
     }
     if (!preg_match('/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i', $data->value)) {
         $errors->append(null, (object) array('message' => __("'%s' must be a valid email address.", array($this->{'name'})), 'code' => self::ERROR_INVALID));
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
Exemplo n.º 3
0
 public function save(MessageStack $errors)
 {
     $xsl_errors = new MessageStack();
     if (strlen(trim($this->parameters()->xml)) == 0) {
         $errors->append('xml', __('This is a required field'));
     } elseif (!General::validateXML($this->parameters()->xml, $xsl_errors)) {
         if (XSLProc::hasErrors()) {
             $errors->append('xml', sprintf('XSLT specified is invalid. The following error was returned: "%s near line %s"', $xsl_errors->current()->message, $xsl_errors->current()->line));
         } else {
             $errors->append('xml', 'XSLT specified is invalid.');
         }
     }
     return parent::save($errors);
 }
Exemplo n.º 4
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = NULL, $data = NULL)
 {
     $document = $wrapper->ownerDocument;
     $element_name = $this->{'element-name'};
     $label = Widget::Label(isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->name);
     if ($this->{'required'} != 'yes') {
         $label->appendChild($wrapper->ownerDocument->createElement('em', __('Optional')));
     }
     $input = Widget::Input("fields[{$element_name}]", $data->value);
     $label->appendChild($input);
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Exemplo n.º 5
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = null, $data = null)
 {
     if (is_null($entry->id) && $this->{'default-state'} == 'on') {
         $value = 'yes';
     } else {
         if (is_null($data) && $this->{'required'} == 'yes') {
             $value = null;
         } else {
             if (is_null($data)) {
                 ## TODO: Don't rely on $_POST
                 if (isset($_POST) && !empty($_POST)) {
                     $value = 'no';
                 } elseif ($this->{'default-state'} == 'on') {
                     $value = 'yes';
                 } else {
                     $value = 'no';
                 }
             } else {
                 $value = $data->value == 'yes' ? 'yes' : 'no';
             }
         }
     }
     $label = Widget::Label();
     $input = Widget::Input('fields[' . $this->{'element-name'} . ']', 'yes', 'checkbox', $value == 'yes' ? array('checked' => 'checked') : array());
     $label->appendChild($input);
     $label->appendChild(new DOMText(isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->{'name'}));
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Exemplo n.º 6
0
 public function validateData(MessageStack $errors, Entry $entry, $data = null)
 {
     if (!isset($data->value) or strlen(trim($data->value)) == 0) {
         $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->{'name'})), 'code' => self::ERROR_MISSING));
         return self::STATUS_ERROR;
     }
     if (!preg_match('/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i', $data->value)) {
         $errors->append(null, (object) array('message' => __("'%s' must be a valid email address.", array($this->{'name'})), 'code' => self::ERROR_INVALID));
         return self::STATUS_ERROR;
     }
     $result = Symphony::Database()->query("\n\t\t\t\t\tSELECT COUNT(*) as `count`\n\t\t\t\t\tFROM `tbl_data_%s_%s`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`value` = '%s'\n\t\t\t\t\t\tAND `entry_id` != %d\n\t\t\t\t", array($entry->section, $this->{'element-name'}, $data->value, $entry->id));
     if ((int) $result->current()->count != 0) {
         $errors->append(null, (object) array('message' => __("'%s' must be unique.", array($this->{'name'})), 'code' => self::ERROR_INVALID));
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
 public static function save(self $role, MessageStack &$errors)
 {
     // Validation
     if (strlen(trim($role->name)) == 0) {
         $errors->append('name', __('Name is required.'));
     } elseif (Symphony::Database()->query("SELECT `id` FROM `tbl_uac_roles` WHERE `name` = '%s' %s", array($role->name, isset($role->id) ? "AND `id` != {$role->id} " : NULL))->length() > 0) {
         $errors->append('name', __('A role with that name already exists.'));
     }
     if ($errors->length() > 0) {
         throw new RoleException('Errors were encountered whist attempting to save.');
     }
     // Saving
     $result = Symphony::Database()->insert('tbl_uac_roles', array('id' => $role->id, 'name' => $role->name, 'description' => $role->description), Database::UPDATE_ON_DUPLICATE);
     if (!isset($role->id)) {
         $role->id = $result;
     }
     Symphony::Database()->delete('tbl_uac_permissions', array($role->id), '`role_id` = %d');
     foreach ($role->permissions as $name => $level) {
         list($key, $type) = preg_split('/\\./', $name, 2, PREG_SPLIT_NO_EMPTY);
         Symphony::Database()->insert('tbl_uac_permissions', array('id' => NULL, 'role_id' => $role->id, 'key' => $key, 'type' => $type, 'level' => $level));
     }
     return $result;
 }
Exemplo n.º 8
0
 public function validateData(MessageStack $errors, Entry $entry = null, $data = null)
 {
     $data = preg_split('/' . preg_quote($this->{'delimiter'}) . '/i', $data->value, -1, PREG_SPLIT_NO_EMPTY);
     $data = array_map('trim', $data);
     if (!is_array($data)) {
         $data = array($data);
     }
     $data = General::array_remove_duplicates($data, true);
     foreach ($data as $tag) {
         if ($this->{'required'} == 'yes' and strlen(trim($data->value)) == 0) {
             $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->{'publish-label'})), 'code' => self::ERROR_MISSING));
             return self::STATUS_ERROR;
         }
         if (!isset($data->value)) {
             return self::STATUS_OK;
         }
         if (!$this->applyValidationRules($data->value)) {
             $errors->append(null, (object) array('message' => __("'%s' contains invalid data. Please check the contents.", array($this->{'publish-label'})), 'code' => self::ERROR_INVALID));
             return self::STATUS_ERROR;
         }
     }
     return self::STATUS_OK;
 }
Exemplo n.º 9
0
 public function validateData(MessageStack $errors, Entry $entry, $data = null)
 {
     $status = self::STATUS_OK;
     foreach ($data as $key => $fields) {
         if (is_numeric($key)) {
             $joined = Entry::loadFromId($key);
             $section = Section::loadFromHandle($joined->section);
         } else {
             $section = Section::loadFromHandle($key);
         }
         foreach ($fields as $field_handle => $value) {
             $field = $section->fetchFieldByHandle($field_handle);
             $field_errors = new MessageStack();
             $field_status = $field->validateData($field_errors, $entry, $value);
             $errors->append($field_handle, $field_errors);
             if ($field_status != self::STATUS_OK) {
                 $status = self::STATUS_ERROR;
             }
         }
     }
     return $status;
 }
Exemplo n.º 10
0
 public function validateData(MessageStack $errors, Entry $entry = NULL, $data = NULL)
 {
     if ($this->required == 'yes' && empty($data)) {
         $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->{'publish-label'})), 'code' => self::ERROR_MISSING));
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
Exemplo n.º 11
0
 public function validateData(MessageStack $errors, Entry $entry, $data = null)
 {
     if (!isset($data->value) or strlen(trim($data->value)) == 0) {
         $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->{'name'})), 'code' => self::ERROR_MISSING));
         return self::STATUS_ERROR;
     }
     if (!$this->applyValidationRules($data->value)) {
         $errors->append(null, (object) array('message' => __("'%s' contains invalid data. Please check the contents.", array($this->{'publish-label'})), 'code' => self::ERROR_INVALID));
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
Exemplo n.º 12
0
 public function validateData(MessageStack $errors, Entry $entry = null, $data = null)
 {
     if (!is_array($data)) {
         $data = array($data);
     }
     if ($this->required == 'yes' && (!isset($data[0]->user_id) || strlen(trim($data[0]->user_id)) == 0)) {
         $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->{'publish-label'})), 'code' => self::ERROR_MISSING));
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
Exemplo n.º 13
0
 public static function save(Section $section, MessageStack $messages, $essentials = null, $simulate = false)
 {
     $pathname = sprintf('%s/%s.xml', $section->path, $section->handle);
     // Check to ensure all the required section fields are filled
     if (!isset($section->name) || strlen(trim($section->name)) == 0) {
         $messages->append('name', __('This is a required field.'));
     } elseif (file_exists($pathname)) {
         $existing = self::load($pathname);
         if (isset($existing->guid) and $existing->guid != $section->guid) {
             $messages->append('name', __('A Section with the name <code>%s</code> already exists', array($section->name)));
         }
         unset($existing);
     }
     ## Check to ensure all the required section fields are filled
     if (!isset($section->{'navigation-group'}) || strlen(trim($section->{'navigation-group'})) == 0) {
         $messages->append('navigation-group', __('This is a required field.'));
     }
     if (is_array($section->fields) && !empty($section->fields)) {
         foreach ($section->fields as $index => $field) {
             $field_stack = new MessageStack();
             if ($field->validateSettings($field_stack, false, false) != Field::STATUS_OK) {
                 $messages->append("field::{$index}", $field_stack);
             }
         }
     }
     if ($messages->length() > 0) {
         throw new SectionException(__('Section could not be saved. Validation failed.'), self::ERROR_MISSING_OR_INVALID_FIELDS);
     }
     if ($simulate) {
         return true;
     }
     $section->sanitizeLayout();
     return file_put_contents($pathname, (string) $section);
 }
Exemplo n.º 14
0
 public function save(MessageStack $errors)
 {
     if (strlen(trim($this->parameters()->limit)) == 0 || is_numeric($this->parameters()->limit) && $this->parameters()->limit < 1) {
         $errors->append('limit', __('A result limit must be set'));
     }
     if (strlen(trim($this->parameters()->page)) == 0 || is_numeric($this->parameters()->page) && $this->parameters()->page < 1) {
         $errors->append('page', __('A page number must be set'));
     }
     return parent::save($errors);
 }
Exemplo n.º 15
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = null, $data = null)
 {
     if (!is_array($data)) {
         $data = array($data);
     }
     $selected = array();
     foreach ($data as $d) {
         if (!$d instanceof StdClass || !isset($d->value)) {
             continue;
         }
         $selected[] = $d->value;
     }
     $states = $this->getToggleStates();
     natsort($states);
     $options = array();
     if ($this->{'required'} == 'yes') {
         $options[] = array(null, false);
     }
     foreach ($states as $handle => $v) {
         $options[] = array($v, in_array($v, $selected), $v);
     }
     $fieldname = 'fields[' . $this->{'element-name'} . ']';
     if ($this->{'allow-multiple-selection'} == 'yes') {
         $fieldname .= '[]';
     }
     $label = Widget::Label(isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->name);
     $label->appendChild(Widget::Select($fieldname, $options, $this->{'allow-multiple-selection'} == 'yes' ? array('multiple' => 'multiple') : array()));
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Exemplo n.º 16
0
 public static function save(self $entry, MessageStack &$errors)
 {
     if (!isset($entry->section) || strlen(trim($entry->section)) == 0) {
         throw new EntryException('A section must be specified before attempting to save.');
     }
     // Create a new ID if one is not already set
     $purge_meta_on_error = false;
     if (!isset($entry->id) || is_null($entry->id)) {
         $purge_meta_on_error = true;
         $entry->id = self::generateID($entry->section, $entry->user_id);
     }
     // Update the modification details
     $entry->modification_date = DateTimeObj::get('c');
     $entry->modification_date_gmt = DateTimeObj::getGMT('c');
     // Load the section
     try {
         $section = Section::loadFromHandle($entry->section);
     } catch (SectionException $e) {
         throw new EntryException('Section specified, "' . $entry->section . '", in Entry object is invalid.');
     } catch (Exception $e) {
         throw new EntryException('The following error occurred during saving: ' . $e->getMessage());
     }
     $entry->findDefaultFieldData();
     $status = Field::STATUS_OK;
     // Check the data
     foreach ($section->fields as $field) {
         $field_data = $entry->data()->{$field->{'element-name'}};
         $field_errors = new MessageStack();
         $field_status = $field->validateData($field_errors, $entry, $field_data);
         if ($field_status != Field::STATUS_OK) {
             $status = $field_status;
         }
         $errors->append($field->{'element-name'}, $field_errors);
     }
     // Attempt the saving part
     if ($status == Field::STATUS_OK) {
         // Update the meta row
         Symphony::Database()->insert('tbl_entries', (array) $entry->meta(), Database::UPDATE_ON_DUPLICATE);
         foreach ($section->fields as $field) {
             if (!isset($entry->data()->{$field->{'element-name'}})) {
                 continue;
             }
             $field_data = $entry->data()->{$field->{'element-name'}};
             $field_errors = $errors->{$field->{'element-name'}};
             $status = $field->saveData($field_errors, $entry, $field_data);
             // Cannot continue if a field failed to save
             if ($status != Field::STATUS_OK) {
                 break;
             }
         }
     }
     // Cleanup due to failure
     if ($status != Field::STATUS_OK && $purge_meta_on_error == true) {
         Symphony::Database()->delete('tbl_entries', array(), " `id` = {$entry->id} LIMIT 1");
         return self::STATUS_ERROR;
     }
     /*
     	TODO: 	Implement Cleanup when a Field's value becomes null (ie. clears a field)
     			This will arise if you enter a value in a field, save, then come back
     			and clear the field.
     */
     if ($status != Field::STATUS_OK) {
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
Exemplo n.º 17
0
 public function validate(MessageStack $messages = NULL, $validateAsNew = true)
 {
     $valid = true;
     if ($this->name == '.xsl' || strlen(trim($this->name)) == 0) {
         if ($messages instanceof MessageStack) {
             $messages->append('name', 'This is a required field.');
         }
         $valid = false;
     } elseif ($validateAsNew && file_exists(UTILITIES . "/{$this->name}")) {
         if ($messages instanceof MessageStack) {
             $messages->append('name', 'A utility with name name already exists.');
         }
         $valid = false;
     }
     $error = array();
     if (strlen(trim($this->body)) == 0) {
         if ($messages instanceof MessageStack) {
             $messages->append('body', 'This is a required field.');
         }
         $valid = false;
     } elseif (!General::validateXML($this->body, $errors)) {
         if ($messages instanceof MessageStack) {
             $messages->append('body', sprintf('XSLT specified is invalid. The following error was returned: "%s near line %s"', $error[0]->message, $error[0]->line));
         }
         $valid = false;
     }
     return $valid;
 }
Exemplo n.º 18
0
 public function trigger(Register $ParameterOutput, array $postdata)
 {
     $result = new XMLDocument();
     $result->appendChild($result->createElement($this->parameters()->{'root-element'}));
     $root = $result->documentElement;
     // Apply default values:
     foreach ($this->parameters()->{'defaults'} as $name => $value) {
         if (!isset($postdata['fields'][$name])) {
             $postdata['fields'][$name] = $value;
         } else {
             if (is_string($postdata['fields'][$name]) and $postdata['fields'][$name] == '') {
                 $postdata['fields'][$name] = $value;
             } else {
                 if (is_array($postdata['fields'][$name]) and empty($postdata['fields'][$name])) {
                     $postdata['fields'][$name] = array($value);
                 }
             }
         }
     }
     // Apply override values:
     foreach ($this->parameters()->{'overrides'} as $name => $value) {
         if (is_array($postdata['fields'][$name])) {
             $postdata['fields'][$name] = array($value);
         } else {
             $postdata['fields'][$name] = $value;
         }
     }
     if (isset($postdata['id'])) {
         $entry = Entry::loadFromID($postdata['id']);
         $type = 'edit';
     } else {
         $entry = new Entry();
         $entry->section = $this->parameters()->{'section'};
         if (isset(Frontend::instance()->User) && Frontend::instance()->User instanceof User) {
             $entry->user_id = Frontend::instance()->User->id;
         } else {
             $entry->user_id = (int) Symphony::Database()->query("SELECT `id` FROM `tbl_users` ORDER BY `id` ASC LIMIT 1")->current()->id;
         }
         $type = 'create';
     }
     if (isset($postdata['fields']) && is_array($postdata['fields']) && !empty($postdata['fields'])) {
         $entry->setFieldDataFromFormArray($postdata['fields']);
     }
     $root->setAttribute('type', $type);
     ###
     # Delegate: EntryPreCreate
     # Description: Just prior to creation of an Entry. Entry object provided
     Extension::notify('EntryPreCreate', '/frontend/', array('entry' => &$entry));
     $errors = new MessageStack();
     $status = Entry::save($entry, $errors);
     if ($status == Entry::STATUS_OK) {
         ###
         # Delegate: EntryPostCreate
         # Description: Creation of an Entry. New Entry object is provided.
         Extension::notify('EntryPostCreate', '/frontend/', array('entry' => $entry));
         if ($this->parameters()->{'output-id-on-save'} == true) {
             $ParameterOutput->{sprintf('event-%s-id', $this->parameters()->{'root-element'})} = $entry->id;
         }
         $root->setAttribute('result', 'success');
         $root->setAttribute('id', $entry->id);
         $root->appendChild($result->createElement('message', __("Entry %s successfully.", array($type == 'edit' ? __('edited') : __('created')))));
     } else {
         $root->setAttribute('result', 'error');
         $root->appendChild($result->createElement('message', __('Entry encountered errors when saving.')));
         if (!isset($postdata['fields']) || !is_array($postdata['fields'])) {
             $postdata['fields'] = array();
         }
         $element = $result->createElement('errors');
         $this->appendMessages($element, $errors);
         $root->appendChild($element);
     }
     $messages = new MessageStack();
     ###
     # Delegate: EventPostSaveFilter
     # Description: After saving entry from the front-end. This delegate will not force the Events to terminate if it populates the error
     #              array reference. Provided with the event, message stack, postdata and entry object.
     Extension::notify('EventPostSaveFilter', '/frontend/', array('event' => $this, 'messages' => $messages, 'fields' => $postdata, 'entry' => $entry));
     if ($messages->valid()) {
         $filter = $result->createElement('filters');
         $this->appendMessages($filter, $messages);
         $root->appendChild($filter);
     }
     $element = $result->createElement('values');
     $this->appendValues($element, is_array($postdata['fields']) ? $postdata['fields'] : array());
     $root->appendChild($element);
     return $result;
 }
Exemplo n.º 19
0
 public function saveData(MessageStack $errors, Entry $entry, $data = null)
 {
     $permissions = Symphony::Configuration()->core()->symphony->{'file-write-mode'};
     $data->entry_id = $entry->id;
     ###
     # Delegate: UploadField_PreUploadFile
     # Description: Allow extensions to manipulate saved data before the file is saved to disk.
     Extension::notify('UploadField_PreUploadFile', '/publish/', array('data' => $data, 'field' => $this, 'entry' => $entry));
     $file = DOCROOT . '/' . $data->path . '/' . $data->file;
     // Upload the file:
     if ($data->tmp_name and $data->error == 0) {
         if (!General::uploadFile(DOCROOT . '/' . $data->path, $data->file, $data->tmp_name, $permissions)) {
             $errors->append(null, (object) array('message' => __('There was an error while trying to upload the file <code>%s</code> to the target directory <code>%s</code>.', array($data->name, trim($data->path, '/'))), 'code' => self::ERROR_INVALID));
             return self::STATUS_ERROR;
         }
         // Remove file being replaced:
         if (isset($data->existing) and is_file($data->existing)) {
             $this->cleanupData($entry, $data, $data->existing);
         }
     }
     unset($data->existing);
     unset($data->error);
     unset($data->tmp_name);
     ###
     # Delegate: UploadField_PostUploadFile
     # Description: Allow extensions to manipulate saved data after the file is saved to disk.
     Extension::notify('UploadField_PostUploadFile', '/publish/', array('data' => $data, 'field' => $this, 'entry' => $entry));
     try {
         $data->meta = serialize($data->meta);
         Symphony::Database()->insert(sprintf('tbl_data_%s_%s', $entry->section, $this->{'element-name'}), (array) $data, Database::UPDATE_ON_DUPLICATE);
         return self::STATUS_OK;
     } catch (Exception $e) {
         $errors->append(null, (object) array('message' => __('There was an error while trying to upload the file <code>%s</code> to the target directory <code>workspace/%s</code>.', array($data->name, $path)), 'code' => self::ERROR_INVALID));
     }
     // Remove uploaded file:
     if (isset($file) and is_file($file)) {
         $this->cleanupData($entry, $data, $file);
     }
     return self::STATUS_ERROR;
 }
Exemplo n.º 20
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = NULL, $data = NULL)
 {
     $document = $wrapper->ownerDocument;
     $driver = Extension::load('field_textbox');
     $driver->addPublishHeaders($document);
     $sortorder = $this->{'sortorder'};
     $element_name = $this->{'element-name'};
     $classes = array();
     $label = Widget::Label(isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->name);
     $optional = '';
     if ($this->{'required'} != 'yes') {
         if ((int) $this->{'text-length'} > 0) {
             $optional = $document->createDocumentFragment();
             $optional->appendChild($document->createTextNode(__('$1 of $2 remaining') . ' '));
             $optional->appendChild($document->createEntityReference('ndash'));
             $optional->appendChild($document->createTextNode(' ' . __('Optional')));
         } else {
             $optional = __('Optional');
         }
     } else {
         if ((int) $this->{'text-length'} > 0) {
             $optional = __('$1 of $2 remaining');
         }
     }
     if ($optional) {
         $label->appendChild($wrapper->ownerDocument->createElement('em', $optional));
     }
     // Input box:
     if ($this->{'text-size'} == 'single') {
         $input = Widget::Input("fields[{$element_name}]", $data->value);
         ###
         # Delegate: ModifyTextBoxInlineFieldPublishWidget
         # Description: Allows developers modify the textbox before it is rendered in the publish forms
         $delegate = 'ModifyTextBoxInlineFieldPublishWidget';
     } else {
         $input = Widget::Textarea("fields[{$element_name}]", $data->value, array('rows' => 20, 'cols' => 50));
         ###
         # Delegate: ModifyTextBoxFullFieldPublishWidget
         # Description: Allows developers modify the textbox before it is rendered in the publish forms
         $delegate = 'ModifyTextBoxFullFieldPublishWidget';
     }
     // Add classes:
     $classes[] = 'size-' . $this->{'text-size'};
     if ($this->{'text-formatter'} != 'none') {
         $classes[] = $this->{'text-formatter'};
     }
     $input->setAttribute('class', implode(' ', $classes));
     $input->setAttribute('length', (int) $this->{'text-length'});
     Extension::notify($delegate, '/administration/', array('field' => &$this, 'label' => &$label, 'input' => &$input));
     if (is_null($label)) {
         return;
     }
     $label->appendChild($input);
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Exemplo n.º 21
0
 public function saveData(MessageStack $errors, Entry $entry, $data = null)
 {
     $data->entry_id = $entry->id;
     if (!isset($data->id)) {
         $data->id = NULL;
     }
     try {
         Symphony::Database()->insert(sprintf('tbl_data_%s_%s', $entry->section, $this->{'element-name'}), (array) $data, Database::UPDATE_ON_DUPLICATE);
         return self::STATUS_OK;
     } catch (DatabaseException $e) {
         //	The great irony here is the the getMessage returns something a hell of a lot
         //	more useful than the getDatabaseErrorMessage. ie.
         //	getMessage: MySQL Error (1048): Column 'value' cannot be null in query {$query}
         //	getDatabaseErrorMessage: Column 'value' cannot be null
         $errors->append(null, (object) array('message' => $e->getMessage(), 'code' => $e->getDatabaseErrorCode()));
     } catch (Exception $e) {
         $errors->append(null, (object) array('message' => $e->getMessage(), 'code' => $e->getCode()));
     }
     return self::STATUS_ERROR;
 }
Exemplo n.º 22
0
 public function save(MessageStack $errors)
 {
     $editing = isset($this->parameters()->{'root-element'}) ? $this->parameters()->{'root-element'} : false;
     // About info:
     if (!isset($this->about()->name) || empty($this->about()->name)) {
         $errors->append('about::name', __('This is a required field'));
     }
     try {
         $existing = self::loadFromHandle($this->handle);
     } catch (DataSourceException $e) {
         //	Datasource not found, continue!
     }
     if ($existing instanceof Datasource && $editing != $this->handle) {
         throw new DataSourceException(__('A Datasource with the name <code>%s</code> already exists', array($this->about()->name)));
     }
     // Save type:
     if ($errors->length() <= 0) {
         $user = Administration::instance()->User;
         if (!file_exists($this->getTemplate())) {
             $errors->append('write', __("Unable to find Data Source Type template '%s'.", array($this->getTemplate())));
             throw new DataSourceException(__("Unable to find Data Source Type template '%s'.", array($this->getTemplate())));
         }
         $this->parameters()->{'root-element'} = $this->handle;
         $classname = Lang::createHandle(ucwords($this->about()->name), '_', false, true, array('/[^a-zA-Z0-9_\\x7f-\\xff]/' => NULL), true);
         $pathname = DATASOURCES . "/" . $this->handle . ".php";
         $data = array($classname, var_export($this->about()->name, true), var_export($user->getFullName(), true), var_export(URL, true), var_export($user->email, true), var_export('1.0', true), var_export(DateTimeObj::getGMT('c'), true));
         foreach ($this->parameters() as $value) {
             $data[] = trim(General::var_export($value, true, is_array($value) ? 5 : 0));
         }
         if (General::writeFile($pathname, vsprintf(file_get_contents($this->getTemplate()), $data), Symphony::Configuration()->core()->symphony->{'file-write-mode'})) {
             if ($editing !== false && $editing != $this->handle) {
                 General::deleteFile(DATASOURCES . '/' . $editing . '.php');
             }
             return $pathname;
         }
         $errors->append('write', __('Failed to write datasource "%s" to disk.', array($filename)));
     }
     throw new DataSourceException('Errors were encountered whilst attempting to save.');
 }
Exemplo n.º 23
0
 public function validateData(MessageStack $errors, Entry $entry, $data = null)
 {
     $change = $data->change;
     $validate = $data->validate;
     $status = self::STATUS_OK;
     // Incorrect validation password:
     if (!$validate->optional and $data->password != sha1($validate->password)) {
         $errors->append('validate-password', (object) array('message' => __("Please enter your current password."), 'code' => self::ERROR_INVALID));
         $status = self::STATUS_ERROR;
     }
     // Missing new password:
     if (!$change->optional and $change->password == '') {
         $errors->append('change-password', (object) array('message' => __("Please enter a new password."), 'code' => self::ERROR_MISSING));
         $status = self::STATUS_ERROR;
     }
     // Missing new password confirmation:
     if (!$change->optional and $change->confirm == '') {
         $errors->append('change-confirm', (object) array('message' => __("Please confirm your new password."), 'code' => self::ERROR_MISSING));
         $status = self::STATUS_ERROR;
     }
     // New passwords do not match:
     if (!$change->optional and $change->password != $change->confirm) {
         $errors->append('change-password', (object) array('message' => __("The passwords you entered to not match."), 'code' => self::ERROR_INVALID));
         $status = self::STATUS_ERROR;
     }
     return $status;
 }
Exemplo n.º 24
0
 public function validateData(MessageStack $errors, Entry $entry = NULL, $data = NULL)
 {
     if ($this->required == 'yes' && (!isset($data->value) || strlen(trim($data->value)) == 0)) {
         $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->label)), 'code' => self::ERROR_MISSING));
         return self::STATUS_ERROR;
     }
     return self::STATUS_OK;
 }
Exemplo n.º 25
0
 public function save(MessageStack $errors)
 {
     $xsl_errors = new MessageStack();
     if (strlen(trim($this->parameters()->{'addresses'})) == 0) {
         $errors->append('addresses', __('This is a required field'));
     }
     return parent::save($errors);
 }
Exemplo n.º 26
0
 public function save(MessageStack $errors)
 {
     if (strlen(trim($this->parameters()->url)) == 0) {
         $errors->append('url', __('This is a required field'));
     }
     if (strlen(trim($this->parameters()->xpath)) == 0) {
         $errors->append('xpath', __('This is a required field'));
     }
     //	Cache Lifetime
     if (!is_numeric($this->parameters()->{'cache-lifetime'})) {
         $errors->append('cache-lifetime', __('Must be a valid number'));
     } elseif ($this->parameters()->{'cache-lifetime'} <= 0) {
         $errors->append('cache-lifetime', __('Must be greater than zero'));
     } else {
         $this->parameters()->{'cache-lifetime'} = (int) $this->parameters()->{'cache-lifetime'};
     }
     //	Timeout
     if (!is_numeric($this->parameters()->{'timeout'})) {
         $errors->append('timeout', __('Must be a valid number'));
     } elseif ($this->parameters()->{'timeout'} <= 0) {
         $errors->append('timeout', __('Must be greater than zero'));
     } else {
         $this->parameters()->{'timeout'} = (int) $this->parameters()->{'timeout'};
     }
     return parent::save($errors);
 }
Exemplo n.º 27
0
 public static function save(self $view, MessageStack &$messages, $simulate = false)
 {
     if (!isset($view->title) || strlen(trim($view->title)) == 0) {
         $messages->append('title', __('Title is required.'));
     }
     $pathname = sprintf('%s/%s/%s.config.xml', VIEWS, $view->path, $view->handle);
     if (file_exists($pathname)) {
         $existing = self::loadFromPath($view->path);
         if ($existing->guid != $view->guid) {
             $messages->append('handle', 'A view with that handle already exists.');
         }
         unset($existing);
     }
     if (isset($view->types) && is_array($view->types) && (bool) array_intersect($view->types, array('index', '404', '403'))) {
         foreach ($view->types as $t) {
             switch ($t) {
                 case 'index':
                 case '404':
                 case '403':
                     $views = self::findFromType($t);
                     if (isset($views[$view->guid])) {
                         unset($views[$view->guid]);
                     }
                     if (!empty($views)) {
                         $messages->append('types', __('A view of type "%s" already exists.', array($t)));
                         break 2;
                     }
                     break;
             }
         }
     }
     if (strlen(trim($view->template)) == 0) {
         $messages->append('template', 'Template is required, and cannot be empty.');
     } elseif (!General::validateXML($view->template, $errors)) {
         $fragment = Administration::instance()->Page->createDocumentFragment();
         $fragment->appendChild(new DOMText(__('This document is not well formed. The following error was returned: ')));
         $fragment->appendChild(Administration::instance()->Page->createElement('code', $errors->current()->message));
         $messages->append('template', $fragment);
     }
     if ($messages->length() > 0) {
         throw new ViewException(__('View could not be saved. Validation failed.'), self::ERROR_MISSING_OR_INVALID_FIELDS);
     }
     if ($simulate != true) {
         if (!is_dir(dirname($pathname)) && !mkdir(dirname($pathname), intval(Symphony::Configuration()->core()->symphony->{'directory-write-mode'}, 8), true)) {
             throw new ViewException(__('Could not create view directory. Please check permissions on <code>%s</code>.', $view->path), self::ERROR_FAILED_TO_WRITE);
         }
         // Save the config
         if (!General::writeFile($pathname, (string) $view, Symphony::Configuration()->core()->symphony->{'file-write-mode'})) {
             throw new ViewException(__('View configuration XML could not be written to disk. Please check permissions on <code>%s</code>.', $view->path), self::ERROR_FAILED_TO_WRITE);
         }
         // Save the template file
         $result = General::writeFile(sprintf('%s/%s/%s.xsl', VIEWS, $view->path, $view->handle), $view->template, Symphony::Configuration()->core()->symphony->{'file-write-mode'});
         if (!$result) {
             throw new ViewException(__('Template could not be written to disk. Please check permissions on <code>%s</code>.', $view->path), self::ERROR_FAILED_TO_WRITE);
         }
     }
     return true;
 }
Exemplo n.º 28
0
    return $panel;
}
function missing($value)
{
    if (!is_array($value)) {
        $value = (array) $value;
    }
    foreach ($value as $v) {
        if (strlen(trim($v)) == 0) {
            return true;
        }
    }
    return false;
}
$settings = array('website-preferences' => array('name' => 'Symphony CMS'), 'server-preferences' => array('path' => realpath('..'), 'file-permissions' => '0755', 'directory-permissions' => '0755'), 'date-time' => array('region' => date_default_timezone_get(), 'date-format' => 'Y/m/d', 'time-format' => 'H:i:s'), 'database' => array('database' => NULL, 'username' => NULL, 'password' => NULL, 'host' => 'localhost', 'port' => '3306', 'table-prefix' => 'sym_', 'use-compatibility-mode' => 'no'), 'user' => array('username' => NULL, 'password' => NULL, 'confirm-password' => NULL, 'first-name' => NULL, 'last-name' => NULL, 'email-address' => NULL));
$errors = new MessageStack();
if (isset($_POST['action']['install'])) {
    $settings = $_POST;
    // Website Preferences -------------------------------------------------------------------------------------------
    $settings['website-preferences'] = array_map('trim', $settings['website-preferences']);
    // Missing Sitename
    if (missing(array($settings['website-preferences']['name']))) {
        $errors->append('website-preferences', 'Name is a required field.');
    } elseif (missing(array($settings['server-preferences']['path']))) {
        $errors->append('server-preferences', 'Root Path is a required field.');
    } elseif (!is_dir($settings['server-preferences']['path']) || !is_writable($settings['server-preferences']['path'])) {
        $errors->append('server-preferences', 'Path specified does not exist, or is not writable. Please check permissions on that location.');
    } elseif (file_exists(sprintf('%s/manifest/core.xml', rtrim($settings['server-preferences']['path'], '/')))) {
        $errors->append('server-preferences', 'An installation of Symphony already exists at that location.');
    }
    // Database --------------------------------------------------------------------------------------------------
Exemplo n.º 29
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = null, $data = null)
 {
     $name = $this->{'element-name'};
     $value = null;
     // New entry:
     if (is_null($data) && $this->{'pre-populate'} == 'yes') {
         $value = DateTimeObj::get(__SYM_DATETIME_FORMAT__, null);
     } else {
         if (isset($data->value) && !is_null($data->value)) {
             $timestamp = DateTimeObj::toGMT($data->value);
             $value = DateTimeObj::get(__SYM_DATETIME_FORMAT__, $timestamp);
         }
     }
     $label = Widget::Label(isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->name, Widget::Input("fields[{$name}]", $value), array('class' => 'date'));
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Exemplo n.º 30
0
 public function validate(MessageStack $errors)
 {
     if (is_null($this->first_name)) {
         $errors->append('first_name', __('First name is required'));
     }
     if (is_null($this->last_name)) {
         $errors->append('last_name', __('Last name is required'));
     }
     if (is_null($this->email)) {
         $errors->append('email', __('E-mail address is required'));
     } elseif (!General::validateString($this->email, '/^[^@]+@[^\\.@]+\\.[^@]+$/i')) {
         $errors->append('email', __('E-mail address entered is invalid'));
     }
     if (is_null($this->username)) {
         $errors->append('username', __('Username is required'));
     } elseif ($this->id) {
         $result = Symphony::Database()->query("SELECT `username` FROM `tbl_users` WHERE `id` = %d", array($this->id));
         $current_username = $result->current()->username;
         if ($current_username != $this->username && Symphony::Database()->query("SELECT `id` FROM `tbl_users` WHERE `username` = '%s'", array($this->username))->valid()) {
             $errors->append('username', __('Username is already taken'));
         }
     } elseif (Symphony::Database()->query("SELECT `id` FROM `tbl_users` WHERE `username` = '%s'", array($this->username))->valid()) {
         $errors->append('username', __('Username is already taken'));
     }
     if (is_null($this->password)) {
         $errors->append('password', __('Password is required'));
     }
     return $errors->length() == 0;
 }