public function processData($data, Entry $entry = null) { $driver = Extension::load('members'); if (isset($entry->data()->{$this->{'element-name'}})) { $result = $entry->data()->{$this->{'element-name'}}; } else { $result = (object) array('value' => null); } if (!is_null($data)) { $result->value = $data; } return $result; }
public function processData($data, Entry $entry = NULL) { if (isset($entry->data()->{$this->{'element-name'}})) { $result = $entry->data()->{$this->{'element-name'}}; } else { $result = (object) array('value' => null); } if (is_null($data) || strlen(trim($data)) == 0) { $result->value = NULL; if ($this->{'pre-populate'} == 'yes') { $timestamp = strtotime(DateTimeObj::get('c', null)); } } else { $timestamp = strtotime($data); } if (!is_null($timestamp) && $timestamp !== false) { $result->value = DateTimeObj::getGMT('Y-m-d H:i:s', $timestamp); } else { $result->value = $data; } return $result; }
public function processData($data, Entry $entry = null) { $driver = Extension::load('members'); if (isset($entry->data()->{$this->{'element-name'}})) { $result = $entry->data()->{$this->{'element-name'}}; } else { $result = (object) array('code' => null, 'password' => null, 'strength' => 0, 'length' => 0); } $result->change = (object) array('optional' => false, 'password' => null, 'confirm' => null); $result->validate = (object) array('optional' => false, 'password' => null); // Result is change optional? if (isset($data['change']['optional'], $result->code) and $result->code == $driver->extractToken($data['change']['optional'], 'change')) { $result->change->optional = true; } // Result is validate optional? if (isset($data['validate']['optional'], $result->code) and $result->code == $driver->extractToken($data['validate']['optional'], 'validate')) { $result->validate->optional = true; } else { if (!isset($result->code)) { $result->validate->optional = true; } } // Make sure a code is set: if (!isset($result->code) or is_null($result->code) or $result->code == '') { $result->code = uniqid(); } // Change password: if (is_array($data) and isset($data['change']['password'], $data['change']['confirm']) and $data['change']['password'] and $data['change']['confirm']) { $result->change->password = $data['change']['password']; $result->change->confirm = $data['change']['confirm']; $result->length = strlen($data['change']['password']); $result->strength = $driver->checkPasswordStrength($data['change']['password']); } // Validate password: if (is_array($data) and isset($data['validate']['password']) and $data['validate']['password']) { $result->validate->password = $data['validate']['password']; } // If the change password data is not empty, treat it as required: if ($result->change->password != '' or $result->change->confirm != '') { $result->change->optional = false; } // If the validate password data is not empty, treat it as required: if ($result->validate->password != '') { $result->validate->optional = false; } return $result; }
public function processData($data, Entry $entry = NULL) { if (isset($entry->data()->{$this->{'element-name'}})) { $result = $entry->data()->{$this->{'element-name'}}; } else { $result = (object) array('value' => NULL); } $result->value = $data; return $result; }
public function saveData(MessageStack $errors, Entry $entry, $data = null) { $key = key($data); $fields = current($data); if (is_numeric($key)) { $joined = Entry::loadFromId($key); $section_handle = $joined->section; Entry::delete($key); } else { $section_handle = $key; } $joined = new Entry(); $joined->section = $section_handle; // Find the current user ID or just any ID at all: if (isset(Administration::instance()->User) && Administration::instance()->User instanceof User) { $joined->user_id = Administration::instance()->User->id; } else { if (isset(Frontend::instance()->User) && Frontend::instance()->User instanceof User) { $joined->user_id = Frontend::instance()->User->id; } else { $joined->user_id = (int) Symphony::Database()->query("SELECT `id` FROM `tbl_users` ORDER BY `id` ASC LIMIT 1")->current()->id; } } // Set entry data: foreach ($fields as $field_handle => $value) { $joined->data()->{$field_handle} = $value; } //echo '<pre>'; var_dump($section_handle); exit; $status = Entry::save($joined, $errors); if ($status != Entry::STATUS_OK) { return $status; } $row = (object) array('entry_id' => $entry->id, 'joined_id' => $joined->id); try { Symphony::Database()->insert(sprintf('tbl_data_%s_%s', $entry->section, $this->{'element-name'}), (array) $row, Database::UPDATE_ON_DUPLICATE); return self::STATUS_OK; } catch (DatabaseException $e) { $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; }
public function processData($data, Entry $entry = null) { $driver = Extension::load('members'); if (isset($entry->data()->{$this->{'element-name'}})) { $result = $entry->data()->{$this->{'element-name'}}; } else { $result = (object) array('handle' => null, 'value' => null, 'value_formatted' => null); } if (!is_null($data)) { $data = stripslashes($data); $result->handle = $driver->createHandle($this, $entry, $data); $result->value = $data; $result->value_formatted = $this->applyFormatting($data); } return $result; }
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; }
public function processData($data, Entry $entry = null) { $result = (object) array(); $existing = null; if (isset($entry->data()->{$this->{'element-name'}})) { $existing = $entry->data()->{$this->{'element-name'}}; $existing->meta = unserialize($existing->meta); } // Recieving file: if (is_array($data)) { $result = (object) $data; if (isset($result->error)) { switch ($result->error) { case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_EXTENSION: return $result; break; } } // Accept a new file: if (isset($result->name) and trim($result->name) != '') { $result = (object) $data; $result->path = '/' . trim($this->destination, '/'); $result->file = $result->name; if ($this->serialise == 'yes') { $result->file = $this->getHashedFilename($result->file); } } } else { if (is_string($data)) { $existing_file = null; if (isset($existing->file, $existing->path)) { $existing_file = DOCROOT . '/' . trim($existing->path, '/') . '/' . $existing->file; } // Existing data: if ($existing_file === $data) { $result = $existing; } else { if (file_exists($data)) { $result->name = basename($data); $result->path = dirname($data); $result->file = basename($data); $result->size = filesize($data); } } } else { if (isset($existing->file, $existing->path)) { $result = $existing; } } } // Force correct ID to be used: if (isset($existing->id)) { $result->id = $existing->id; } // Track existing file: if (isset($existing->file, $existing->path)) { $result->existing = DOCROOT . '/' . $existing->path . '/' . $existing->file; } // At least have a null existing file: if (!isset($result->existing)) { $result->existing = null; } // Update meta data: $result->meta = $this->getMetaInformation($entry, $result, isset($result->tmp_name) ? $result->tmp_name : $result->existing); if (isset($result->meta['type']) and !empty($result->meta['type'])) { $result->type = $result->meta['type']; } // Make sure we have a type: if (!isset($result->type) or empty($result->type)) { $result->type = 'application/octet-stream'; } return $result; }
public function current() { $record = parent::current(); $entry = new Entry(); foreach ($record as $key => $value) { $entry->{$key} = $value; } if (empty($this->data)) { return $entry; } // 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: ' . $e->getMessage()); } // Loop over the section fields, and in they are in the desired schema, populate an entry_data // array with the information. This doesn't respect fields allow_multiple setting though, although // I don't even think that's a problem to be honest as that validation should be taking place at the // entry creation level, not when it's being read. foreach ($section->fields as $field) { if (!empty($this->schema) && !in_array($field->{'element-name'}, $this->schema)) { continue; } $entry_data = array(); foreach ($this->data[$field->{'element-name'}] as $key => $data) { if ($data->{$field->fetchDataKey()} != $entry->id) { continue; } $entry_data[] = $data; } $entry->data()->{$field->{'element-name'}} = count($entry_data) == 1 ? current($entry_data) : $entry_data; } return $entry; }
public function processData($data, Entry $entry = NULL) { $states = array('on', 'yes'); if (isset($entry->data()->{$this->{'element-name'}})) { $result = $entry->data()->{$this->{'element-name'}}; } else { $result = (object) array('value' => null); } if (!is_null($data)) { if ($this->{'required'} == 'yes' && !in_array(strtolower($data), $states)) { $result->value = null; } else { $result->value = in_array(strtolower($data), $states) ? 'yes' : 'no'; } } return $result; }