private function createEntryFromPost()
 {
     include_once TOOLKIT . '/class.sectionmanager.php';
     include_once TOOLKIT . '/class.entrymanager.php';
     // section id
     $source = $this->getSection();
     $section = SectionManager::fetch($source);
     $fields = $section->fetchFields();
     $entry = null;
     if ($id > 0) {
         // edit
         $entry = EntryManager::fetch($id);
         if (empty($entry)) {
             throw new Exception(sprintf(__('Entry id %s not found'), $id));
         }
         $entry = $entry[0];
     } else {
         // create
         $entry = EntryManager::create();
         $entry->set('section_id', $source);
     }
     foreach ($fields as $f) {
         $data = $this->getFieldValue($f->get('element_name'));
         if ($data != null) {
             $entry->setData($f->get('id'), $data);
         }
     }
     if (!$entry->commit()) {
         throw new Exception(sprintf('Could not create entry: %s', mysql_error()));
     }
     return $entry;
 }
 private function __doit($source, $fields, &$result, $entry_id = NULL, $cookie = NULL)
 {
     include_once TOOLKIT . '/class.sectionmanager.php';
     include_once TOOLKIT . '/class.entrymanager.php';
     $sectionManager = new SectionManager($this->_Parent);
     if (!($section = $sectionManager->fetch($source))) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', 'Section is invalid'));
         return false;
     }
     $entryManager = new EntryManager($this->_Parent);
     if (isset($entry_id) && $entry_id != NULL) {
         $entry =& $entryManager->fetch($entry_id);
         $entry = $entry[0];
         if (!is_object($entry)) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', 'Invalid Entry ID specified. Could not create Entry object.'));
             return false;
         }
     } else {
         $entry =& $entryManager->create();
         $entry->set('section_id', $source);
     }
     if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, $entry->get('id') ? true : false)) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', 'Entry encountered errors when saving.'));
         foreach ($errors as $field_id => $message) {
             $field = $entryManager->fieldManager->fetch($field_id);
             $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('type' => $fields[$field->get('element_name')] == '' ? 'missing' : 'invalid')));
         }
         if (isset($cookie) && is_object($cookie)) {
             $result->appendChild($cookie);
         }
         return false;
     } elseif (__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, $entry->get('id') ? true : false)) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', 'Entry encountered errors when saving.'));
         foreach ($errors as $err) {
             $field = $entryManager->fieldManager->fetch($err['field_id']);
             $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('type' => 'invalid')));
         }
         if (isset($cookie) && is_object($cookie)) {
             $result->appendChild($cookie);
         }
         return false;
     } else {
         if (!$entry->commit()) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', 'Unknown errors where encountered when saving.'));
             if (isset($cookie) && is_object($cookie)) {
                 $result->appendChild($cookie);
             }
             return false;
         }
     }
     return $entry;
 }
 public function symHaveEntryInDatabase($section, $data)
 {
     $sectionId = \SectionManager::fetchIDFromHandle($section);
     $entry = \EntryManager::create();
     $entry->set('section_id', $sectionId);
     if ($entry->setDataFromPost($data) == __ENTRY_FIELD_ERROR__) {
         throw 'Error setting data';
     }
     $entry->commit();
     return $entry->get('id');
 }
 public function unserializeEntry($entry_id, $version)
 {
     $entry = unserialize(file_get_contents(MANIFEST . '/versions/' . $entry_id . '/' . $version . '.dat'));
     $entryManager = new EntryManager(Symphony::Engine());
     $new_entry = $entryManager->create();
     $new_entry->set('id', $entry['id']);
     $new_entry->set('author_id', $entry['author_id']);
     $new_entry->set('section_id', $entry['section_id']);
     $new_entry->set('creation_date', $entry['creation_date']);
     $new_entry->set('creation_date_gmt', $entry['creation_date_gmt']);
     foreach ($entry['data'] as $field_id => $value) {
         $new_entry->setData($field_id, $value);
     }
     return $new_entry;
 }
Ejemplo n.º 5
0
 /**
  * This function does the bulk of processing the Event, from running the delegates
  * to validating the data and eventually saving the data into Symphony. The result
  * of the Event is returned via the `$result` parameter.
  *
  * @param array $fields
  *  An array of $_POST data, to process and add/edit an entry.
  * @param XMLElement $result
  *  The XMLElement contains the result of the Event, it is passed by
  *  reference.
  * @param integer $position
  *  When the Expect Multiple filter is added, this event should expect
  *  to deal with adding (or editing) multiple entries at once.
  * @param integer $entry_id
  *  If this Event is editing an existing entry, that Entry ID will
  *  be passed to this function.
  * @return XMLElement
  *  The result of the Event
  */
 public function __doit($fields, XMLElement &$result, $position = null, $entry_id = null)
 {
     $post_values = new XMLElement('post-values');
     if (!is_array($this->eParamFILTERS)) {
         $this->eParamFILTERS = array();
     }
     // Check to see if the Section of this Event is valid.
     if (!($section = SectionManager::fetch($this->getSource()))) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('The Section, %s, could not be found.', array($this->getSource()))));
         return false;
     }
     // Create the post data element
     if (is_array($fields) && !empty($fields)) {
         General::array_to_xml($post_values, $fields, true);
     }
     // If the EventPreSaveFilter fails, return early
     if ($this->processPreSaveFilters($result, $fields, $post_values, $entry_id) === false) {
         return false;
     }
     // If the `$entry_id` is provided, check to see if it exists.
     // @todo If this was moved above PreSaveFilters, we can pass the
     // Entry object to the delegate meaning extensions don't have to
     // do that step.
     if (isset($entry_id)) {
         $entry = EntryManager::fetch($entry_id);
         $entry = $entry[0];
         if (!is_object($entry)) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('The Entry, %s, could not be found.', array($entry_id))));
             return false;
         }
     } else {
         $entry = EntryManager::create();
         $entry->set('section_id', $this->getSource());
     }
     // Validate the data. `$entry->checkPostData` loops over all fields calling
     // checkPostFieldData function. If the return of the function is `__ENTRY_FIELD_ERROR__`
     // then abort the event, adding the error messages to the `$result`.
     if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, $entry->get('id') ? true : false)) {
         $result = self::appendErrors($result, $fields, $errors, $post_values);
         return false;
     } else {
         if (__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, $entry->get('id') ? true : false)) {
             $result = self::appendErrors($result, $fields, $errors, $post_values);
             return false;
         } else {
             if ($entry->commit() === false) {
                 $result->setAttribute('result', 'error');
                 $result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.')));
                 if (isset($post_values) && is_object($post_values)) {
                     $result->appendChild($post_values);
                 }
                 return false;
             } else {
                 $result->setAttributeArray(array('result' => 'success', 'type' => isset($entry_id) ? 'edited' : 'created', 'id' => $entry->get('id')));
                 $result->appendChild(new XMLElement('message', isset($entry_id) ? __('Entry edited successfully.') : __('Entry created successfully.')));
             }
         }
     }
     // PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
     if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
         $result = $this->processSendMailFilter($result, $_POST['send-email'], $fields, $section, $entry);
     }
     $result = $this->processPostSaveFilters($result, $fields, $entry);
     $result = $this->processFinalSaveFilters($result, $fields, $entry);
     if (isset($post_values) && is_object($post_values)) {
         $result->appendChild($post_values);
     }
     return true;
 }
Ejemplo n.º 6
0
 function __viewEdit()
 {
     $sectionManager = new SectionManager($this->_Parent);
     if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
         $this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle'])), false, true);
     }
     $section = $sectionManager->fetch($section_id);
     $entry_id = intval($this->_context['entry_id']);
     $entryManager = new EntryManager($this->_Parent);
     $entryManager->setFetchSorting('id', 'DESC');
     if (!($existingEntry = $entryManager->fetch($entry_id))) {
         $this->_Parent->customError(E_USER_ERROR, __('Unknown Entry'), __('The entry you are looking for could not be found.'), false, true);
     }
     $existingEntry = $existingEntry[0];
     // If there is post data floating around, due to errors, create an entry object
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
         $entry =& $entryManager->create();
         $entry->set('section_id', $existingEntry->get('section_id'));
         $entry->set('id', $entry_id);
         $entry->setDataFromPost($fields, $error, true);
     } else {
         $entry = $existingEntry;
         if (!$section) {
             $section = $sectionManager->fetch($entry->get('section_id'));
         }
     }
     if (isset($this->_context['flag'])) {
         $link = 'publish/' . $this->_context['section_handle'] . '/new/';
         list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3);
         if (is_numeric($field_id) && $value) {
             $link .= "?prepopulate[{$field_id}]={$value}";
         }
         switch ($flag) {
             case 'saved':
                 $this->pageAlert(__('Entry updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Entry created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
                 break;
         }
     }
     ### Determine the page title
     $field_id = $this->_Parent->Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1");
     $field = $entryManager->fieldManager->fetch($field_id);
     $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id)));
     if (trim($title) == '') {
         $title = 'Untitled';
     }
     $this->setPageType('form');
     $this->Form->setAttribute('enctype', 'multipart/form-data');
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array(__('Symphony'), $section->get('name'), $title)));
     $this->appendSubheading($title);
     $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', $this->_Parent->Configuration->get('max_upload_size', 'admin'), 'hidden'));
     ###
     $primary = new XMLElement('fieldset');
     $primary->setAttribute('class', 'primary');
     $sidebar_fields = $section->fetchFields(NULL, 'sidebar');
     $main_fields = $section->fetchFields(NULL, 'main');
     if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) {
         $primary->appendChild(new XMLElement('p', __('It looks like your trying to create an entry. Perhaps you want custom fields first? <a href="%s">Click here to create some.</a>', array(URL . '/symphony/blueprints/sections/edit/' . $section->get('id') . '/'))));
     } else {
         if (is_array($main_fields) && !empty($main_fields)) {
             foreach ($main_fields as $field) {
                 $primary->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($primary);
         }
         if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
             $sidebar = new XMLElement('fieldset');
             $sidebar->setAttribute('class', 'secondary');
             foreach ($sidebar_fields as $field) {
                 $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($sidebar);
         }
     }
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
     $button = new XMLElement('button', __('Delete'));
     $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this entry')));
     $div->appendChild($button);
     $this->Form->appendChild($div);
 }
 public function log($type, $entry)
 {
     if (!$this->initialize()) {
         return false;
     }
     $admin = Administration::instance();
     $em = new EntryManager($admin);
     $section = $this->getAuditSection();
     $fields = array('author' => $entry->get('author_id'), 'created' => 'now', 'dump' => serialize($entry->getData()), 'entry' => array('source_entry' => $entry->get('id'), 'source_section' => $entry->get('section_id')), 'type' => $type);
     // No auditing the audits section:
     if ($entry->get('section_id') == $section->get('id')) {
         return false;
     }
     $audit = $em->create();
     $audit->set('section_id', $section->get('id'));
     $audit->set('author_id', $entry->get('author_id'));
     $audit->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
     $audit->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
     $audit->setDataFromPost($fields, $error);
     $audit->commit();
 }
 private function getXML($position = 0, $entry_id = NULL)
 {
     // Cache stuff that can be reused between filter fields and entries
     static $post;
     static $postValues;
     // Remember if $post contains multiple entries or not
     static $expectMultiple;
     $xml = new XMLElement('data');
     // Get post values
     if (empty($postValues) || $position > 0) {
         // TODO: handle post of multiple entries at the same time
         if (empty($post)) {
             $post = General::getPostData();
             // Check if post contains multiple entries or not
             // TODO: make some hidden field required for post, so we can check for sure
             //       if $post['fields'][0]['conditionalizer'] exists?
             $expectMultiple = is_array($post['fields']) && is_array($post['fields'][0]) ? true : false;
         }
         if (!empty($post['fields']) && is_array($post['fields'])) {
             $postValues = new XMLElement('post');
             if ($expectMultiple == true) {
                 if (!empty($entry_id) && isset($post['id'])) {
                     // $entry_id overrides $position
                     foreach ($post['id'] as $pos => $id) {
                         if ($id == $entry_id) {
                             $position = $pos;
                             break;
                         }
                     }
                 } else {
                     if (isset($post['id'][$position]) && is_numeric($post['id'][$position])) {
                         $entry_id = $post['id'][$position];
                     }
                 }
                 $postValues->setAttribute('position', $position);
                 General::array_to_xml($postValues, $post['fields'][$position], false);
             } else {
                 if ($position < 1) {
                     if (empty($entry_id) && isset($post['id']) && is_numeric($post['id'])) {
                         $entry_id = $post['id'];
                     }
                     General::array_to_xml($postValues, $post['fields'], false);
                 } else {
                     // TODO: add error element?
                 }
             }
         }
     }
     if (!empty($postValues)) {
         $xml->appendChild($postValues);
     }
     // Get old entry
     $entry = NULL;
     if (!class_exists('EntryManager')) {
         include_once TOOLKIT . '/class.entrymanager.php';
     }
     if (!empty($entry_id)) {
         $entry = EntryManager::fetch($entry_id);
         $entry = $entry[0];
         if (is_object($entry)) {
             $entry_xml = new XMLElement('old-entry');
             $entry_xml->setAttribute('position', $position);
             $this->appendEntryXML($entry_xml, $entry);
             $xml->appendChild($entry_xml);
         } else {
             $entry = NULL;
         }
     } else {
         $entry = EntryManager::create();
         $entry->set('section_id', $this->get('parent_section'));
     }
     // Set new entry data. Code found in event.section.php:
     // https://github.com/symphonycms/symphony-2/blob/29244318e4de294df780513ee027edda767dd75a/symphony/lib/toolkit/events/event.section.php#L99
     if (is_object($entry)) {
         self::$recursion = true;
         if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($expectMultiple ? $post['fields'][$position] : $post['fields'], $errors, $entry->get('id') ? true : false)) {
             // Return early - other fields will mark their errors
             self::$recursion = false;
             return self::__OK__;
         } else {
             if (__ENTRY_OK__ != $entry->setDataFromPost($expectMultiple ? $post['fields'][$position] : $post['fields'], $errors, true, $entry->get('id') ? true : false)) {
                 // Return early - other fields will mark their errors.
                 self::$recursion = false;
                 return self::__OK__;
             }
         }
         self::$recursion = false;
         $entry_xml = new XMLElement('entry');
         $entry_xml->setAttribute('position', $position);
         $this->appendEntryXML($entry_xml, $entry);
         $xml->appendChild($entry_xml);
     }
     // Get author
     if ($temp = Symphony::Engine()->Author) {
         $author = new XMLElement('author');
         $author->setAttribute('id', $temp->get('id'));
         $author->setAttribute('user_type', $temp->get('user_type'));
         $author->setAttribute('primary', $temp->get('primary'));
         $author->setAttribute('username', $temp->get('username'));
         $author->setAttribute('first_name', $temp->get('first_name'));
         $author->setAttribute('last_name', $temp->get('last_name'));
         $xml->appendChild($author);
     }
     return $xml;
 }
Ejemplo n.º 9
0
 public function __viewDo()
 {
     if (count($_POST) > 0 && count($this->_errors) > 0) {
         if (is_array($this->_errors)) {
             $this->pageAlert("\n\t\t\t\t\t\tAn error occurred while processing this form.\n\t\t\t\t\t\t<a href=\"#error\">" . $this->parseErrors() . " Rolling back.</a>", AdministrationPage::PAGE_ALERT_ERROR);
         }
     } elseif (count($_POST) > 0) {
         $this->pageAlert("Successfully added a whole slew of entries, {$this->_entries_count} to be exact. \n\t\t\t\t\tTo do it again, <a href=\"{$this->_uri}/\">Give it another go below.</a>", Alert::SUCCESS, array('created', URL, 'extension/multipleuploadinjector'));
     }
     $this->setPageType('form');
     $this->Form->setAttribute('enctype', 'multipart/form-data');
     $this->setTitle('Symphony &ndash; Add Multiple Files From a Folder');
     // // Edit:
     // if ($this->_action == 'edit')	{
     // 	if (!$this->_valid && count($this->_errors) == 0)
     // 		if (count($this->_files) > 0) {
     // 			$this->appendSubHeading('Added '.implode(', ',$this->_files));
     // 		}
     // }
     // else
     $this->appendSubheading('Inject!');
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'settings');
     $fieldset->appendChild(new XMLElement('legend', 'Essentials'));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'group');
     $label = Widget::Label(__('Source (where these are all going)'));
     $sectionManager = new SectionManager($this->_Parent);
     $sections = $sectionManager->fetch();
     $options[0]['label'] = 'Sections';
     foreach ($sections as $section) {
         $s = $section->fetchFields();
         $go = false;
         foreach ($s as $f) {
             if (in_array($f->get('type'), $this->_driver->getTypes())) {
                 $go = true;
             }
         }
         if ($go) {
             $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section);
             $options[0]['options'][] = array($section->get('id'), $_POST['fields']['source'] == $section->get('id'), $section->get('name'));
         }
     }
     $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context')));
     $div->appendChild($label);
     $label = Widget::Label(__('Directory where images are stored'));
     $options = array();
     $options[] = array('/workspace' . $this->_driver->getMUI(), false, '/workspace' . $this->_driver->getMUI());
     $ignore = array('events', 'data-sources', 'text-formatters', 'pages', 'utilities');
     $directories = General::listDirStructure(WORKSPACE . $this->_driver->getMUI(), true, 'asc', DOCROOT, $ignore);
     if (!empty($directories) && is_array($directories)) {
         foreach ($directories as $d) {
             $d = '/' . trim($d, '/');
             if (!in_array($d, $ignore)) {
                 $options[] = array($d, $d == '/workspace' . $this->_driver->getMUI() . '/' . date('Y-m-d') ? true : false, $d);
             }
         }
     }
     $label->appendChild(Widget::Select('fields[sourcedir]', $options));
     $div->appendChild($label);
     $fieldset->appendChild($div);
     $div = new XMLElement('div');
     $div->setAttribute('class', 'group');
     $label = Widget::Label(__('Delete directory and contents after successful import?'));
     $label->appendChild(Widget::Input('fields[remove]', null, 'checkbox'));
     $div->appendChild($label);
     $fieldset->appendChild($div);
     $this->Form->appendChild($fieldset);
     /* now the section fields */
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'settings contextual ' . __('sections') . ' ' . __('authors') . ' ' . __('navigation') . ' ' . __('Sections') . ' ' . __('System'));
     $fieldset->appendChild(new XMLElement('legend', __('Choose Default Values')));
     $entryManager = new EntryManager($this->_Parent);
     foreach ($field_groups as $section_id => $section_data) {
         // create a dummy entry
         $entry = $entryManager->create();
         $entry->set('section_id', $section_id);
         $div = new XMLElement('div');
         $div->setAttribute('class', 'contextual ' . $section_id);
         $primary = new XMLElement('fieldset');
         $primary->setAttribute('class', 'primary');
         $sidebar_fields = $section_data['section']->fetchFields();
         // $main_fields = $section_data['section']->fetchFields(NULL, 'main');
         // if(is_array($main_fields) && !empty($main_fields)){
         // 	foreach($main_fields as $field){
         // 		if (!in_array($field->get('type'),$this->_driver->getTypes()))
         // 			$primary->appendChild($this->__wrapFieldWithDiv($field));
         // 	}
         // 	$div->appendChild($primary);
         // }
         if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
             $sidebar = new XMLElement('fieldset');
             $sidebar->setAttribute('class', 'primary');
             foreach ($sidebar_fields as $field) {
                 if (!in_array($field->get('type'), $this->_driver->getTypes())) {
                     $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry, $section_id, null, null));
                 }
             }
             $div->appendChild($sidebar);
         }
         $fieldset->appendChild($div);
     }
     $this->Form->appendChild($fieldset);
     $submit = Widget::Input('action[save]', 'Process files', 'submit', array('accesskey' => 's'));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild($submit);
     $this->Form->appendChild($div);
 }
Ejemplo n.º 10
0
 public function __viewEdit()
 {
     $sectionManager = new SectionManager($this->_Parent);
     if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
         Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle'])));
     }
     $section = $sectionManager->fetch($section_id);
     $entry_id = intval($this->_context['entry_id']);
     $entryManager = new EntryManager($this->_Parent);
     $entryManager->setFetchSorting('id', 'DESC');
     if (!($existingEntry = $entryManager->fetch($entry_id))) {
         Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.'));
     }
     $existingEntry = $existingEntry[0];
     // If there is post data floating around, due to errors, create an entry object
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
         $entry =& $entryManager->create();
         $entry->set('section_id', $existingEntry->get('section_id'));
         $entry->set('id', $entry_id);
         $entry->setDataFromPost($fields, $error, true);
     } else {
         $entry = $existingEntry;
         if (!$section) {
             $section = $sectionManager->fetch($entry->get('section_id'));
         }
     }
     /**
      * Just prior to rendering of an Entry edit form.
      *
      * @delegate EntryPreRender
      * @param string $context
      * '/publish/new/'
      * @param Section $section
      * @param Entry $entry
      * @param array $fields
      */
     Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields));
     if (isset($this->_context['flag'])) {
         $link = 'publish/' . $this->_context['section_handle'] . '/new/';
         list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3);
         if (is_numeric($field_id) && $value) {
             $link .= "?prepopulate[{$field_id}]={$value}";
             $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden'));
         }
         switch ($flag) {
             case 'saved':
                 $this->pageAlert(__('Entry updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Entry created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
                 break;
         }
     }
     ### Determine the page title
     $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1");
     $field = $entryManager->fieldManager->fetch($field_id);
     $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id)));
     if (trim($title) == '') {
         $title = 'Untitled';
     }
     // Check if there is a field to prepopulate
     if (isset($_REQUEST['prepopulate'])) {
         $field_id = array_shift(array_keys($_REQUEST['prepopulate']));
         $value = stripslashes(rawurldecode(array_shift($_REQUEST['prepopulate'])));
         $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden'));
     }
     $this->setPageType('form');
     $this->Form->setAttribute('enctype', 'multipart/form-data');
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array(__('Symphony'), $section->get('name'), $title)));
     $this->appendSubheading($title);
     $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden'));
     ###
     $primary = new XMLElement('fieldset');
     $primary->setAttribute('class', 'primary');
     $sidebar_fields = $section->fetchFields(NULL, 'sidebar');
     $main_fields = $section->fetchFields(NULL, 'main');
     if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) {
         $primary->appendChild(new XMLElement('p', __('It looks like you\'re trying to create an entry. Perhaps you want fields first? <a href="%s">Click here to create some.</a>', array(SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/'))));
     } else {
         if (is_array($main_fields) && !empty($main_fields)) {
             foreach ($main_fields as $field) {
                 $primary->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($primary);
         }
         if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
             $sidebar = new XMLElement('fieldset');
             $sidebar->setAttribute('class', 'secondary');
             foreach ($sidebar_fields as $field) {
                 $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($sidebar);
         }
     }
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
     $button = new XMLElement('button', __('Delete'));
     $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?')));
     $div->appendChild($button);
     $this->Form->appendChild($div);
 }
Ejemplo n.º 11
0
 public function checkPostFieldData($data, &$error = null, $entry_id = null)
 {
     $entryManager = new EntryManager($this->_engine);
     $fieldManager = new FieldManager($this->_engine);
     $field = $fieldManager->fetch($this->get('child_field_id'));
     $status = self::__OK__;
     $data = $this->getData();
     // Create:
     foreach ($data['entry'] as $index => $entry_data) {
         $existing_id = $data['entry_id'][$index];
         if (empty($existing_id)) {
             $entry = $entryManager->create();
             $entry->set('section_id', $this->get('child_section_id'));
             $entry->set('author_id', $this->_engine->Author->get('id'));
             $entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
             $entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
         } else {
             $entry = @current($entryManager->fetch($existing_id, $this->get('child_section_id')));
         }
         // Create link:
         if ($field) {
             $entry_data[$field->get('element_name')] = array('parent_entry_id' => $entry_id);
         }
         // Validate:
         if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($entry_data, $errors)) {
             if (!empty($errors)) {
                 self::$errors[$this->get('id')][$index] = $errors;
             }
             $status = self::__INVALID_FIELDS__;
         } elseif (__ENTRY_OK__ != $entry->setDataFromPost($entry_data, $error)) {
             $status = self::__INVALID_FIELDS__;
         }
         self::$entries[$this->get('id')][] = $entry;
     }
     return $status;
 }
 public function validate($data)
 {
     if (!function_exists('handleXMLError')) {
         function handleXMLError($errno, $errstr, $errfile, $errline, $context)
         {
             $context['self']->_errors[] = $errstr;
         }
     }
     if (empty($data)) {
         return null;
     }
     $entryManager = new EntryManager($this->_Parent);
     $fieldManager = new FieldManager($this->_Parent);
     set_time_limit(900);
     set_error_handler('handleXMLError');
     $self = $this;
     // F*****g PHP...
     $xml = new DOMDocument();
     $xml->loadXML($data, LIBXML_COMPACT);
     restore_error_handler();
     $xpath = new DOMXPath($xml);
     $passed = true;
     // Invalid Markup:
     if (empty($xml)) {
         $passed = false;
         // Invalid Expression:
     } else {
         if (($entries = $xpath->query($this->getRootExpression())) === false) {
             $this->_errors[] = sprintf('Root expression <code>%s</code> is invalid.', htmlentities($this->getRootExpression(), ENT_COMPAT, 'UTF-8'));
             $passed = false;
             // No Entries:
         } else {
             if (empty($entries)) {
                 $this->_errors[] = 'No entries to import.';
                 $passed = false;
                 // Test expressions:
             } else {
                 foreach ($this->getFieldMap() as $field_id => $expression) {
                     if ($xpath->evaluate($expression) === false) {
                         $field = $fieldManager->fetch($field_id);
                         $this->_errors[] = sprintf('\'%s\' expression <code>%s</code> is invalid.', $field->get('label'), htmlentities($expression, ENT_COMPAT, 'UTF-8'));
                         $passed = false;
                     }
                 }
             }
         }
     }
     if (!$passed) {
         return self::__ERROR_PREPARING__;
     }
     // Gather data:
     foreach ($entries as $index => $entry) {
         $this->_entries[$index] = array('element' => $entry, 'entry' => null, 'values' => array(), 'errors' => array());
         foreach ($this->getFieldMap() as $field_id => $expressions) {
             if (!is_array($expressions)) {
                 $value = $this->getExpressionValue($xml, $entry, $xpath, $expressions, $debug);
                 //var_dump(is_utf8($value));
             } else {
                 $value = array();
                 foreach ($expressions as $name => $expression) {
                     $value[$name] = $this->getExpressionValue($xml, $entry, $xpath, $expression);
                 }
             }
             $this->_entries[$index]['values'][$field_id] = $value;
         }
     }
     // Validate:
     $passed = true;
     foreach ($this->_entries as &$current) {
         $entry = $entryManager->create();
         $entry->set('section_id', $this->getSection());
         $entry->set('author_id', $this->_Parent->Author->get('id'));
         $entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
         $entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
         $values = array();
         // Map values:
         foreach ($current['values'] as $field_id => $value) {
             $field = $fieldManager->fetch($field_id);
             // Adjust value?
             if (method_exists($field, 'prepareImportValue')) {
                 $value = $field->prepareImportValue($value);
             }
             $values[$field->get('element_name')] = $value;
         }
         // Validate:
         if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($values, $current['errors'])) {
             $passed = false;
         } elseif (__ENTRY_OK__ != $entry->setDataFromPost($values, $error)) {
             $passed = false;
         }
         $current['entry'] = $entry;
     }
     if (!$passed) {
         return self::__ERROR_VALIDATING__;
     }
     return self::__OK__;
 }
<?php

$I = new FunctionalTester($scenario);
$I->wantTo('I want to load SymphonyCMSDb Module');
$I->assertEquals($I->symphonyCMSDBTest(), 'Hello World');
$I->assertNotNull(\EntryManager::create());
Ejemplo n.º 14
0
 /**
  * Create necessary data for an Entry.
  *
  * @param string $section_handle
  * @param array  $section_filters
  * @param int    $position
  * @param array  $original_fields
  *
  * @return array
  */
 private function sectionsPrepareEntry($section_handle, array $section_filters, $position, array $original_fields)
 {
     $action = null;
     $entry_id = null;
     $filters = array();
     // determine filters
     if (isset($original_fields['__filters'])) {
         $filters = is_array($original_fields['__filters']) ? $original_fields['__filters'] : array($original_fields['__filters']);
         unset($original_fields['__filters']);
     }
     $filters = array_replace_recursive($section_filters, $filters);
     // determine entry_id
     if (isset($original_fields['__system-id'])) {
         $entry_id = $original_fields['__system-id'];
         if (is_array($entry_id)) {
             $entry_id = current($entry_id);
         }
         unset($original_fields['__system-id']);
     }
     // determine action
     if (isset($original_fields['__action'])) {
         $action = $original_fields['__action'];
         unset($original_fields['__action']);
     } elseif (is_numeric($entry_id)) {
         $action = SE_Permissions::ACTION_EDIT;
     } else {
         $action = SE_Permissions::ACTION_CREATE;
     }
     // check permissions
     if (isset($original_fields['__skip-permissions'])) {
         $perm_check = false;
     } else {
         $perm_check = true;
     }
     unset($original_fields['__skip-permissions']);
     $fields = $original_fields;
     $res_entry = new XMLElement('entry', null, array('action' => $action));
     $done = false;
     $entry = null;
     // validate $action & get the Entry object
     switch ($action) {
         case SE_Permissions::ACTION_CREATE:
             $entry = EntryManager::create();
             $entry->set('section_id', SectionManager::fetchIDFromHandle($section_handle));
             break;
         case SE_Permissions::ACTION_EDIT:
         case SE_Permissions::ACTION_DELETE:
             $entry = EntryManager::fetch($entry_id);
             $entry = $entry[0];
             if (!$entry instanceof Entry) {
                 $this->error = true;
                 $done = true;
                 $this->resultEntry($res_entry, 'error', __('The Entry `%d` could not be found.', array($entry_id)));
             }
             break;
         default:
             $done = true;
             $this->resultEntry($res_entry, 'error', __('Requested action `%s` is not supported.', array($action)));
             break;
     }
     // fire PreSaveFilter
     $res_filters = new XMLElement('filters');
     if (!$done) {
         if (!$this->filtersProcessPrepare($res_filters, $section_handle, $entry, $fields, $original_fields, $filters, $action)) {
             $this->error = true;
             $this->resultEntry($res_entry, 'error');
         }
     }
     return array('action' => $action, 'id' => $entry_id, 'perm_check' => $perm_check, 'entry' => $entry, 'orig_fields' => $original_fields, 'fields' => $fields, 'filters' => $filters, 'done' => $done, 'result' => new XMLElement('entry', null, array('position' => $position)), 'res_entry' => $res_entry, 'res_fields' => new XMLElement('fields'), 'res_filters' => $res_filters);
 }
 public function grab(array &$param_pool = NULL)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     $result->setAttribute('type', 'section-schema');
     // retrieve this section
     $section_id = SectionManager::fetchIDFromHandle($this->dsParamSECTION);
     $section = SectionManager::fetch($section_id);
     $result->setAttribute('id', $section_id);
     $result->setAttribute('handle', $section->get('handle'));
     $entry_count = EntryManager::fetchCount($section_id);
     $result->setAttribute('total-entries', $entry_count);
     // instantiate a dummy entry to instantiate fields and default values
     $entry = EntryManager::create();
     $entry->set('section_id', $section_id);
     $section_fields = $section->fetchFields();
     // for each field in the section
     foreach ($section_fields as $section_field) {
         $field = $section_field->get();
         // Skip fields that have not been selected:
         if (!in_array($field['element_name'], $this->dsParamFIELDS)) {
             continue;
         }
         $f = new XMLElement($field['element_name']);
         $f->setAttribute('required', $field['required']);
         foreach ($field as $key => $value) {
             // Core attributes, these are common to all fields
             if (in_array($key, array('id', 'type', 'required', 'label', 'location', 'show_column', 'sortorder'))) {
                 $f->setattribute(Lang::createHandle($key), General::sanitize($value));
             }
             /*
             	Other properties are output as element nodes. Here we filter those we
             	definitely don't want. Fields can have any number of properties, so it
             	makes sense to filter out those we don't want rather than explicitly
             	choose the ones we do.
             */
             if (!in_array($key, array('id', 'type', 'required', 'label', 'show_column', 'sortorder', 'element_name', 'parent_section', 'location', 'field_id', 'related_field_id', 'static_options', 'dynamic_options', 'pre_populate_source', 'limit', 'allow_author_change'))) {
                 if (strlen($value) > 0) {
                     $f->appendChild(new XMLElement(Lang::createHandle($key), General::sanitize($value)));
                 }
             }
         }
         // Allow a field to define its own schema XML:
         if (method_exists($section_field, 'appendFieldSchema')) {
             $section_field->appendFieldSchema($f);
             $result->appendChild($f);
             continue;
         }
         // check that we can safely inspect output of displayPublishPanel (some custom fields do not work)
         if (in_array($field['type'], self::$_incompatible_publishpanel)) {
             continue;
         }
         // grab the HTML used in the Publish entry form
         $html = new XMLElement('html');
         $section_field->displayPublishPanel($html);
         $dom = new DomDocument();
         $dom->loadXML($html->generate());
         $xpath = new DomXPath($dom);
         $options = new XMLElement('options');
         // find optgroup elements (primarily in Selectbox Link fields)
         foreach ($xpath->query("//*[name()='optgroup']") as $optgroup) {
             $optgroup_element = new XMLElement('optgroup');
             $optgroup_element->setAttribute('label', $optgroup->getAttribute('label'));
             // append child options of this group
             foreach ($optgroup->getElementsByTagName('option') as $option) {
                 $this->__appendOption($option, $optgroup_element, $field);
             }
             $options->appendChild($optgroup_element);
         }
         // find options that aren't children of groups, and list items (primarily for Taglists)
         foreach ($xpath->query("//*[name()='option' and not(parent::optgroup)] | //*[name()='li']") as $option) {
             $this->__appendOption($option, $options, $field);
         }
         if ($options->getNumberOfChildren() > 0) {
             $f->appendChild($options);
         }
         /*
         	When an input has a value and is a direct child of the label, we presume we may need
         	its value (e.g. a pre-populated Date, Order Entries etc.)
         */
         $single_input_value = $xpath->query("//label/input[@value!='']")->item(0);
         if ($single_input_value) {
             $f->appendChild(new XMLElement('initial-value', $single_input_value->getAttribute('value')));
         }
         $result->appendChild($f);
     }
     return $result;
 }
Ejemplo n.º 16
0
 public function checkPostFieldData($data, &$error = null, $entry_id = null)
 {
     if (isset($data['entry']) and is_array($data['entry'])) {
         $entryManager = new EntryManager(Symphony::Engine());
         $fieldManager = new FieldManager(Symphony::Engine());
         $field = $fieldManager->fetch($this->get('linked_field_id'));
         $field_id = $this->get('id');
         $status = self::__OK__;
         $handled_entries = array();
         self::$errors[$field_id] = array();
         self::$entries[$field_id] = array();
         // Create:
         foreach ($data['entry'] as $index => $entry_data) {
             $existing_id = null;
             // Find existing entry:
             if ((int) $data['entry_id'][$index] > 0) {
                 $entries = $entryManager->fetch((int) $data['entry_id'][$index], $this->get('linked_section_id'));
                 if (isset($entries[0])) {
                     $entry = $entries[0];
                     $existing_id = $entry->get('id');
                 }
             }
             // Skip duplicate entries:
             if ($existing_id != null && in_array($existing_id, $handled_entries)) {
                 continue;
             }
             // Create a new entry:
             if ($existing_id == null) {
                 $entry = $entryManager->create();
                 $entry->set('section_id', $this->get('linked_section_id'));
                 $entry->set('author_id', isset(Symphony::Engine()->Author) ? Symphony::Engine()->Author->get('id') : 1);
                 $entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
                 $entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
                 $entry->assignEntryId();
             }
             // Append correct linked data:
             $existing_data = $entry->getData($this->get('linked_field_id'));
             $existing_entries = array();
             if (isset($existing_data['linked_entry_id'])) {
                 if (!is_array($existing_data['linked_entry_id'])) {
                     $existing_entries[] = $existing_data['linked_entry_id'];
                 } else {
                     foreach ($existing_data['linked_entry_id'] as $linked_entry_id) {
                         $existing_entries[] = $linked_entry_id;
                     }
                 }
             }
             if (!in_array($entry_id, $existing_entries)) {
                 $existing_entries[] = $entry_id;
             }
             $entry_data[$field->get('element_name')] = $existing_entries;
             // Validate:
             if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($entry_data, $errors)) {
                 self::$errors[$field_id][$index] = $errors;
                 $status = self::__INVALID_FIELDS__;
             }
             if (__ENTRY_OK__ != $entry->setDataFromPost($entry_data, $error)) {
                 $status = self::__INVALID_FIELDS__;
             }
             // Cleanup dud entry:
             if ($existing_id == null and $status != self::__OK__) {
                 $existing_id = $entry->get('id');
                 $entry->set('id', 0);
                 Symphony::Database()->delete('tbl_entries', " `id` = '{$existing_id}' ");
             }
             self::$entries[$field_id][$index] = $entry;
             $handled_entries[] = $entry->get('id');
         }
         return $status;
     }
     return parent::checkPostFieldData($data, $error, $entry_id);
 }
Ejemplo n.º 17
0
 public function __viewEdit()
 {
     if (!($section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle']))) {
         Administration::instance()->throwCustomError(__('The Section, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>')), __('Unknown Section'), Page::HTTP_STATUS_NOT_FOUND);
     }
     $section = SectionManager::fetch($section_id);
     $entry_id = intval($this->_context['entry_id']);
     $base = '/publish/' . $this->_context['section_handle'] . '/';
     $new_link = $base . 'new/';
     $filter_link = $base;
     EntryManager::setFetchSorting('id', 'DESC');
     if (!($existingEntry = EntryManager::fetch($entry_id))) {
         Administration::instance()->throwCustomError(__('Unknown Entry'), __('The Entry, %s, could not be found.', array($entry_id)), Page::HTTP_STATUS_NOT_FOUND);
     }
     $existingEntry = $existingEntry[0];
     // If there is post data floating around, due to errors, create an entry object
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
         $entry = EntryManager::create();
         $entry->set('id', $entry_id);
         $entry->set('author_id', $existingEntry->get('author_id'));
         $entry->set('section_id', $existingEntry->get('section_id'));
         $entry->set('creation_date', $existingEntry->get('creation_date'));
         $entry->set('modification_date', $existingEntry->get('modification_date'));
         $entry->setDataFromPost($fields, $errors, true);
         // Editing an entry, so need to create some various objects
     } else {
         $entry = $existingEntry;
         $fields = array();
         if (!$section) {
             $section = SectionManager::fetch($entry->get('section_id'));
         }
     }
     /**
      * Just prior to rendering of an Entry edit form.
      *
      * @delegate EntryPreRender
      * @param string $context
      * '/publish/edit/'
      * @param Section $section
      * @param Entry $entry
      * @param array $fields
      */
     Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields));
     // Iterate over the `prepopulate` parameters to build a URL
     // to remember this state for Create New, View all Entries and
     // Breadcrumb links. If `prepopulate` doesn't exist, this will
     // just use the standard pages (ie. no filtering)
     if (isset($_REQUEST['prepopulate'])) {
         $new_link .= $this->getPrepopulateString();
         $filter_link .= $this->getFilterString();
     }
     if (isset($this->_context['flag'])) {
         // These flags are only relevant if there are no errors
         if (empty($this->_errors)) {
             $time = Widget::Time();
             switch ($this->_context['flag']) {
                 case 'saved':
                     $message = __('Entry updated at %s.', array($time->generate()));
                     break;
                 case 'created':
                     $message = __('Entry created at %s.', array($time->generate()));
             }
             $this->pageAlert($message . ' <a href="' . SYMPHONY_URL . $new_link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . $filter_link . '" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS);
         }
     }
     // Determine the page title
     $field_id = Symphony::Database()->fetchVar('id', 0, sprintf("\n            SELECT `id`\n            FROM `tbl_fields`\n            WHERE `parent_section` = %d\n            ORDER BY `sortorder` LIMIT 1", $section->get('id')));
     if (!is_null($field_id)) {
         $field = FieldManager::fetch($field_id);
     }
     if ($field) {
         $title = $field->prepareReadableValue($existingEntry->getData($field->get('id')), $entry_id, true);
     } else {
         $title = '';
     }
     if (trim($title) == '') {
         $title = __('Untitled');
     }
     // Check if there is a field to prepopulate
     if (isset($_REQUEST['prepopulate'])) {
         foreach ($_REQUEST['prepopulate'] as $field_id => $value) {
             $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden'));
         }
     }
     $this->setPageType('form');
     $this->Form->setAttribute('enctype', 'multipart/form-data');
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array($title, $section->get('name'), __('Symphony'))));
     $sidebar_fields = $section->fetchFields(null, 'sidebar');
     $main_fields = $section->fetchFields(null, 'main');
     if (!empty($sidebar_fields) && !empty($main_fields)) {
         $this->Form->setAttribute('class', 'two columns');
     } else {
         $this->Form->setAttribute('class', 'columns');
     }
     // Only show the Edit Section button if the Author is a developer. #938 ^BA
     if (Symphony::Author()->isDeveloper()) {
         $this->appendSubheading($title, Widget::Anchor(__('Edit Section'), SYMPHONY_URL . '/blueprints/sections/edit/' . $section_id . '/', __('Edit Section Configuration'), 'button'));
     } else {
         $this->appendSubheading($title);
     }
     $this->insertBreadcrumbs(array(Widget::Anchor($section->get('name'), SYMPHONY_URL . (isset($filter_link) ? $filter_link : $base))));
     $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden'));
     $primary = new XMLElement('fieldset');
     $primary->setAttribute('class', 'primary column');
     if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) {
         $message = __('Fields must be added to this section before an entry can be created.');
         if (Symphony::Author()->isDeveloper()) {
             $message .= ' <a href="' . SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/" accesskey="c">' . __('Add fields') . '</a>';
         }
         $this->pageAlert($message, Alert::ERROR);
     } else {
         if (is_array($main_fields) && !empty($main_fields)) {
             foreach ($main_fields as $field) {
                 $primary->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($primary);
         }
         if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
             $sidebar = new XMLElement('fieldset');
             $sidebar->setAttribute('class', 'secondary column');
             foreach ($sidebar_fields as $field) {
                 $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($sidebar);
         }
         $div = new XMLElement('div');
         $div->setAttribute('class', 'actions');
         $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?')));
         $div->appendChild($button);
         $this->Form->appendChild($div);
         // Create a Drawer for Associated Sections
         $this->prepareAssociationsDrawer($section);
     }
 }
Ejemplo n.º 18
0
 /**
  * This function does the bulk of processing the Event, from running the delegates
  * to validating the data and eventually saving the data into Symphony. The result
  * of the Event is returned via the `$result` parameter.
  *
  * @param array $fields
  *  An array of $_POST data, to process and add/edit an entry.
  * @param XMLElement $result
  *  The XMLElement contains the result of the Event, it is passed by
  *  reference.
  * @param integer $position
  *  When the Expect Multiple filter is added, this event should expect
  *  to deal with adding (or editing) multiple entries at once.
  * @param integer $entry_id
  *  If this Event is editing an existing entry, that Entry ID will
  *  be passed to this function.
  * @throws Exception
  * @return XMLElement
  *  The result of the Event
  */
 public function __doit(array $fields = array(), XMLElement &$result, $position = null, $entry_id = null)
 {
     $post_values = new XMLElement('post-values');
     if (!is_array($this->eParamFILTERS)) {
         $this->eParamFILTERS = array();
     }
     // Check to see if the Section of this Event is valid.
     if (!($section = SectionManager::fetch($this->getSource()))) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('The Section, %s, could not be found.', array($this->getSource())), array('message-id' => EventMessages::SECTION_MISSING)));
         return false;
     }
     // Create the post data element
     if (!empty($fields)) {
         General::array_to_xml($post_values, $fields, true);
     }
     // If the EventPreSaveFilter fails, return early
     if ($this->processPreSaveFilters($result, $fields, $post_values, $entry_id) === false) {
         return false;
     }
     // If the `$entry_id` is provided, check to see if it exists.
     // @todo If this was moved above PreSaveFilters, we can pass the
     // Entry object to the delegate meaning extensions don't have to
     // do that step.
     if (isset($entry_id)) {
         $entry = EntryManager::fetch($entry_id);
         $entry = $entry[0];
         if (!is_object($entry)) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('The Entry, %s, could not be found.', array($entry_id)), array('message-id' => EventMessages::ENTRY_MISSING)));
             return false;
         }
         // `$entry_id` wasn't provided, create a new Entry object.
     } else {
         $entry = EntryManager::create();
         $entry->set('section_id', $this->getSource());
     }
     // Validate the data. `$entry->checkPostData` loops over all fields calling
     // their `checkPostFieldData` function. If the return of the function is
     // `Entry::__ENTRY_FIELD_ERROR__` then abort the event and add the error
     // messages to the `$result`.
     if (Entry::__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, $entry->get('id') ? true : false)) {
         $result = self::appendErrors($result, $fields, $errors, $post_values);
         return false;
         // If the data is good, process the data, almost ready to save it to the
         // Database. If processing fails, abort the event and display the errors
     } elseif (Entry::__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, $entry->get('id') ? true : false)) {
         $result = self::appendErrors($result, $fields, $errors, $post_values);
         return false;
         // Data is checked, data has been processed, by trying to save the
         // Entry caused an error to occur, so abort and return.
     } elseif ($entry->commit() === false) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.'), array('message-id' => EventMessages::ENTRY_UNKNOWN)));
         if (isset($post_values) && is_object($post_values)) {
             $result->appendChild($post_values);
         }
         return false;
         // Entry was created, add the good news to the return `$result`
     } else {
         $result->setAttributeArray(array('result' => 'success', 'type' => isset($entry_id) ? 'edited' : 'created', 'id' => $entry->get('id')));
         if (isset($entry_id)) {
             $result->appendChild(new XMLElement('message', __('Entry edited successfully.'), array('message-id' => EventMessages::ENTRY_EDITED_SUCCESS)));
         } else {
             $result->appendChild(new XMLElement('message', __('Entry created successfully.'), array('message-id' => EventMessages::ENTRY_CREATED_SUCCESS)));
         }
     }
     // PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
     if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
         $result = $this->processSendMailFilter($result, $_POST['send-email'], $fields, $section, $entry);
     }
     $result = $this->processPostSaveFilters($result, $fields, $entry);
     $result = $this->processFinalSaveFilters($result, $fields, $entry);
     if (isset($post_values) && is_object($post_values)) {
         $result->appendChild($post_values);
     }
     return true;
 }
Ejemplo n.º 19
0
 public function getSectionSchema(&$result, $section_id)
 {
     $entryManager = new EntryManager($this->_Parent);
     $sm = new SectionManager($this->_Parent);
     // retrieve this section
     $section = $sm->fetch($section_id);
     $result->setAttribute('id', $section_id);
     $result->setAttribute('handle', $section->_data['handle']);
     $entry_count = intval($this->_Parent->Database->fetchVar('count', 0, "SELECT count(*) AS `count` FROM `tbl_entries` WHERE `section_id` = '" . $section_id . "' "));
     $result->setAttribute('total-entries', $entry_count);
     // instantiate a dummy entry to instantiate fields and default values
     $entry =& $entryManager->create();
     $entry->set('section_id', $section_id);
     $section_fields = $section->fetchFields();
     // for each field in the section
     foreach ($section_fields as $section_field) {
         $field = $section_field->get();
         $f = new XMLElement($field['element_name']);
         $f->setAttribute('required', $field['required']);
         foreach ($field as $key => $value) {
             // Core attributes, these are common to all fields
             if (in_array($key, array('id', 'type', 'required', 'label', 'location', 'sortorder'))) {
                 $f->setattribute($key, $value);
             }
             /*
             	Other properties are output as element nodes. Here we filter those we
             	definitely don't want. Fields can have any number of properties, so it 
             	makes sense to filter out those we don't want rather than explicitly 
             	choose the ones we do.
             */
             if (!in_array($key, array('id', 'type', 'required', 'label', 'show_column', 'sortorder', 'element_name', 'parent_section', 'location', 'field_id', 'related_field_id', 'static_options', 'dynamic_options', 'pre_populate_source', 'limit', 'allow_author_change'))) {
                 if (strlen($value) > 0) {
                     $f->appendChild(new XMLElement(Lang::createHandle($key), $value));
                 }
             }
         }
         // grab the HTML used in the Publish entry form
         $html = new XMLElement('html');
         $section_field->displayPublishPanel($html);
         $dom = new DomDocument();
         $dom->loadXML($html->generate());
         $xpath = new DomXPath($dom);
         $options = new XMLElement('options');
         // find optgroup elements (primarily in Selectbox Link fields)
         foreach ($xpath->query("//*[name()='optgroup']") as $optgroup) {
             $optgroup_element = new XMLElement('optgroup');
             $optgroup_element->setAttribute('label', $optgroup->getAttribute('label'));
             $options_xpath = new DomXPath($optgroup);
             // append child options of this group
             foreach ($optgroup->getElementsByTagName('option') as $option) {
                 $this->__appendOption($option, $optgroup_element, $field);
             }
             $options->appendChild($optgroup_element);
         }
         // find options that aren't children of groups, and list items (primarily for Taglists)
         foreach ($xpath->query("//*[name()='option' and not(parent::optgroup)] | //*[name()='li']") as $option) {
             $this->__appendOption($option, $options, $field);
         }
         if ($options->getNumberOfChildren() > 0) {
             $f->appendChild($options);
         }
         /*
         	When an input has a value and is a direct child of the label, we presume we may need
         	its value (e.g. a pre-populated Date, Order Entries etc.)
         */
         $single_input_value = $xpath->query("//label/input[@value!='']")->item(0);
         if ($single_input_value) {
             $f->appendChild(new XMLElement('initial-value', $single_input_value->getAttribute('value')));
         }
         $result->appendChild($f);
     }
     return $result;
 }
Ejemplo n.º 20
0
 /**
  * Creates a new entry for each valid file in the `$target_section`
  */
 public function commitFiles()
 {
     $entryManager = new EntryManager(Administration::instance());
     $section = $this->target_section;
     // This is the default field instances that will populated with data.
     $entries = array();
     $fields = array('upload' => $this->target_field, 'name' => null, 'section' => null);
     foreach ($section->fetchFields() as $field) {
         if (General::validateString($field->get('type'), Extension_BulkImporter::$supported_fields['name']) && is_null($fields['name'])) {
             $fields['name'] = $field;
         }
         if (General::validateString($field->get('type'), Extension_BulkImporter::$supported_fields['section']) && is_null($fields['section'])) {
             $fields['section'] = $field;
         }
     }
     foreach ($this->files as $file) {
         $path = '/';
         if ($this->preserve_subdirectories) {
             $path = dirname(substr($file->location, strlen($this->extracted_directory)));
             if ($path != '/') {
                 $path .= '/';
             }
         } else {
             if ($this->archive_is_parent) {
                 $path = '/' . $this->extracted_archive . '/';
             }
         }
         $final_destination = preg_replace("/^\\/workspace/", '', $this->target_field->get('destination')) . $path . $file->rawname;
         if (!$file->isValid($this->target_field, $final_destination)) {
             continue;
         }
         $_post = array();
         $entry = $entryManager->create();
         $entry->set('section_id', $section->get('id'));
         $entry->set('author_id', Administration::instance()->Author->get('id'));
         // Set the Name
         if (!is_null($fields['name'])) {
             $_post[$fields['name']->get('element_name')] = $file->name;
         }
         // Set the Upload Field
         if (is_null($fields['upload'])) {
             throw new Exception(__('No valid upload field found in the <code>%s</code>', array($section->get('name'))));
         }
         $_post[$this->target_field->get('element_name')] = $final_destination;
         // Cache some info, before we move file
         // https://github.com/brendo/bulkimporter/pull/7#issuecomment-1105691
         $meta = array('size' => $file->size, 'mimetype' => $file->mimetype, 'meta' => serialize($this->target_field->getMetaInfo($file->location, $file->mimetype)));
         // Move the image from it's bulk-imported location
         $path = WORKSPACE . dirname($final_destination);
         if (!file_exists($path)) {
             General::realiseDirectory($path);
             chmod($path, intval(0755, 8));
         }
         if (rename($file->location, WORKSPACE . $final_destination)) {
             chmod(WORKSPACE . $final_destination, intval(0755, 8));
         }
         $errors = array();
         //	Check all the fields that they are correct
         if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($_post, $errors)) {
             if (!empty($errors)) {
                 $file->setErrors($errors);
             }
             continue;
         }
         if (__ENTRY_OK__ == $entry->setDataFromPost($_post, $errors, false, false)) {
             //	Because we can't upload the file using the inbuilt function
             //	we have to fake the expected output
             $upload = $entry->getData($this->target_field->get('id'));
             foreach ($meta as $key => $value) {
                 if (empty($upload[$key])) {
                     $upload[$key] = $value;
                 }
             }
             $entry->setData($this->target_field->get('id'), $upload);
             /**
              * Just prior to creation of an Entry
              *
              * @delegate EntryPreCreate
              * @param string $context
              * '/publish/new/'
              * @param Section $section
              * @param Entry $entry
              * @param array $fields
              */
             Symphony::ExtensionManager()->notifyMembers('EntryPreCreate', '/publish/new/', array('section' => $section, 'entry' => &$entry, 'fields' => &$_post));
             if ($entry->commit()) {
                 $file->setUploaded();
                 $entries[$final_destination] = $entry->get('id');
                 /**
                  * Creation of an Entry. New Entry object is provided.
                  *
                  * @delegate EntryPostCreate
                  * @param string $context
                  * '/publish/new/'
                  * @param Section $section
                  * @param Entry $entry
                  * @param array $fields
                  */
                 Symphony::ExtensionManager()->notifyMembers('EntryPostCreate', '/publish/new/', array('section' => $section, 'entry' => $entry, 'fields' => $_post));
             }
         } else {
             $file->setErrors(__('Could not save entry in the <code>%s</code>', array($section->get('name'))));
         }
     }
     // Set the Section Association
     if (!empty($entries) && !is_null($this->linked_entry['linked-entry'])) {
         $entry = current($entryManager->fetch($this->linked_entry['linked-entry']));
         // Linked field, process the array of ID's to add
         $field = $entryManager->fieldManager->fetch($this->linked_entry['linked-field']);
         $result = $field->processRawFieldData($entries, $s, false, $entry->get('id'));
         // Get the current linked entries and merge with the new ones
         $existing_values = $entry->getData($this->linked_entry['linked-field']);
         if (is_array($existing_values['relation_id'])) {
             $result['relation_id'] = array_merge_recursive($result['relation_id'], $existing_values['relation_id']);
         }
         $entry->setData($this->linked_entry['linked-field'], $result);
         $entry->commit();
     }
     $this->entries = $entries;
 }
 public function __viewEdit()
 {
     if (!($section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle']))) {
         Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>')));
     }
     $section = SectionManager::fetch($section_id);
     $entry_id = intval($this->_context['entry_id']);
     EntryManager::setFetchSorting('id', 'DESC');
     if (!($existingEntry = EntryManager::fetch($entry_id))) {
         Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.'));
     }
     $existingEntry = $existingEntry[0];
     // If there is post data floating around, due to errors, create an entry object
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
         $entry =& EntryManager::create();
         $entry->set('section_id', $existingEntry->get('section_id'));
         $entry->set('id', $entry_id);
         $entry->setDataFromPost($fields, $errors, true);
     } else {
         $entry = $existingEntry;
         if (!$section) {
             $section = SectionManager::fetch($entry->get('section_id'));
         }
     }
     /**
      * Just prior to rendering of an Entry edit form.
      *
      * @delegate EntryPreRender
      * @param string $context
      * '/publish/edit/'
      * @param Section $section
      * @param Entry $entry
      * @param array $fields
      */
     Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields));
     if (isset($this->_context['flag'])) {
         $link = 'publish/' . $this->_context['section_handle'] . '/new/';
         list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3);
         if (isset($_REQUEST['prepopulate'])) {
             $link .= '?';
             foreach ($_REQUEST['prepopulate'] as $field_id => $value) {
                 $link .= "prepopulate[{$field_id}]={$value}&amp;";
             }
             $link = preg_replace("/&amp;\$/", '', $link);
         }
         // These flags are only relevant if there are no errors
         if (empty($this->_errors)) {
             switch ($flag) {
                 case 'saved':
                     $this->pageAlert(__('Entry updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/' . $link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS);
                     break;
                 case 'created':
                     $this->pageAlert(__('Entry created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/' . $link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS);
                     break;
             }
         }
     }
     // Determine the page title
     $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1");
     $field = FieldManager::fetch($field_id);
     $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id)));
     if (trim($title) == '') {
         $title = __('Untitled');
     }
     // Check if there is a field to prepopulate
     if (isset($_REQUEST['prepopulate'])) {
         foreach ($_REQUEST['prepopulate'] as $field_id => $value) {
             $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden'));
         }
     }
     $this->setPageType('form');
     $this->Form->setAttribute('enctype', 'multipart/form-data');
     $this->Form->setAttribute('class', 'two columns');
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array($title, $section->get('name'), __('Symphony'))));
     // Only show the Edit Section button if the Author is a developer. #938 ^BA
     if (Administration::instance()->Author->isDeveloper()) {
         $this->appendSubheading($title, Widget::Anchor(__('Edit Section'), SYMPHONY_URL . '/blueprints/sections/edit/' . $section_id, __('Edit Section Configuration'), 'button'));
     } else {
         $this->appendSubheading($title);
     }
     $this->insertBreadcrumbs(array(Widget::Anchor($section->get('name'), SYMPHONY_URL . '/publish/' . $this->_context['section_handle'])));
     $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden'));
     $primary = new XMLElement('fieldset');
     $primary->setAttribute('class', 'primary column');
     $sidebar_fields = $section->fetchFields(NULL, 'sidebar');
     $main_fields = $section->fetchFields(NULL, 'main');
     if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) {
         $message = __('Fields must be added to this section before an entry can be created.');
         if (Administration::instance()->Author->isDeveloper()) {
             $message .= ' <a href="' . SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/" accesskey="c">' . __('Add fields') . '</a>';
         }
         $this->pageAlert($message, Alert::ERROR);
     } else {
         if (is_array($main_fields) && !empty($main_fields)) {
             foreach ($main_fields as $field) {
                 $primary->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($primary);
         }
         if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
             $sidebar = new XMLElement('fieldset');
             $sidebar->setAttribute('class', 'secondary column');
             foreach ($sidebar_fields as $field) {
                 $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry));
             }
             $this->Form->appendChild($sidebar);
         }
         $div = new XMLElement('div');
         $div->setAttribute('class', 'actions');
         $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?')));
         $div->appendChild($button);
         $this->Form->appendChild($div);
     }
 }
Ejemplo n.º 22
0
 function __doit($source, $fields, &$result, &$obj, &$event, $filters, $position = NULL, $entry_id = NULL)
 {
     $post_values = new XMLElement('post-values');
     $post = General::getPostData();
     $filter_results = array();
     ## Create the post data cookie element
     if (is_array($post) && !empty($post)) {
         General::array_to_xml($post_values, $fields, true);
     }
     ###
     # Delegate: EventPreSaveFilter
     # Description: Prior to saving entry from the front-end. This delegate will force the Event to terminate if it populates the error
     #              array reference. Provided with references to this object, the POST data and also the error array
     $obj->ExtensionManager->notifyMembers('EventPreSaveFilter', '/frontend/', array('fields' => $fields, 'event' => &$event, 'messages' => &$filter_results, 'post_values' => &$post_values));
     if (is_array($filter_results) && !empty($filter_results)) {
         foreach ($filter_results as $fr) {
             list($type, $status, $message) = $fr;
             $result->appendChild(buildFilterElement($type, $status ? 'passed' : 'failed', $message));
             if (!$status) {
                 $result->appendChild($post_values);
                 $result->setAttribute('result', 'error');
                 $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
                 return false;
             }
         }
     }
     include_once TOOLKIT . '/class.sectionmanager.php';
     include_once TOOLKIT . '/class.entrymanager.php';
     $sectionManager = new SectionManager($obj);
     if (!($section = $sectionManager->fetch($source))) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('Section is invalid')));
         return false;
     }
     $entryManager = new EntryManager($obj);
     if (isset($entry_id) && $entry_id != NULL) {
         $entry =& $entryManager->fetch($entry_id);
         $entry = $entry[0];
         if (!is_object($entry)) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('Invalid Entry ID specified. Could not create Entry object.')));
             return false;
         }
     } else {
         $entry =& $entryManager->create();
         $entry->set('section_id', $source);
     }
     $filter_errors = array();
     if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, $entry->get('id') ? true : false)) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
         foreach ($errors as $field_id => $message) {
             $field = $entryManager->fieldManager->fetch($field_id);
             $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('type' => $fields[$field->get('element_name')] == '' ? 'missing' : 'invalid', 'message' => General::sanitize($message))));
         }
         if (isset($post_values) && is_object($post_values)) {
             $result->appendChild($post_values);
         }
         return false;
     } elseif (__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, $entry->get('id') ? true : false)) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
         if (isset($errors['field_id'])) {
             $errors = array($errors);
         }
         foreach ($errors as $err) {
             $field = $entryManager->fieldManager->fetch($err['field_id']);
             $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('type' => 'invalid')));
         }
         if (isset($post_values) && is_object($post_values)) {
             $result->appendChild($post_values);
         }
         return false;
     } else {
         if (!$entry->commit()) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.')));
             if (isset($post_values) && is_object($post_values)) {
                 $result->appendChild($post_values);
             }
             return false;
         }
         $result->setAttribute('id', $entry->get('id'));
     }
     ## PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
     if (@in_array('send-email', $filters) && !@in_array('expect-multiple', $filters)) {
         if (!function_exists('__sendEmailFindFormValue')) {
             function __sendEmailFindFormValue($needle, $haystack, $discard_field_name = true, $default = NULL, $collapse = true)
             {
                 if (preg_match('/^(fields\\[[^\\]]+\\],?)+$/i', $needle)) {
                     $parts = preg_split('/\\,/i', $needle, -1, PREG_SPLIT_NO_EMPTY);
                     $parts = array_map('trim', $parts);
                     $stack = array();
                     foreach ($parts as $p) {
                         $field = str_replace(array('fields[', ']'), '', $p);
                         $discard_field_name ? $stack[] = $haystack[$field] : ($stack[$field] = $haystack[$field]);
                     }
                     if (is_array($stack) && !empty($stack)) {
                         return $collapse ? implode(' ', $stack) : $stack;
                     } else {
                         $needle = NULL;
                     }
                 }
                 $needle = trim($needle);
                 if (empty($needle)) {
                     return $default;
                 }
                 return $needle;
             }
         }
         $fields = $_POST['send-email'];
         $fields['recipient'] = __sendEmailFindFormValue($fields['recipient'], $_POST['fields'], true);
         $fields['recipient'] = preg_split('/\\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY);
         $fields['recipient'] = array_map('trim', $fields['recipient']);
         $fields['recipient'] = $obj->Database->fetch("SELECT `email`, `first_name` FROM `tbl_authors` WHERE `username` IN ('" . @implode("', '", $fields['recipient']) . "') ");
         $fields['subject'] = __sendEmailFindFormValue($fields['subject'], $_POST['fields'], true, __('[Symphony] A new entry was created on %s', array($obj->Configuration->get('sitename', 'general'))));
         $fields['body'] = __sendEmailFindFormValue($fields['body'], $_POST['fields'], false, NULL, false);
         $fields['sender-email'] = __sendEmailFindFormValue($fields['sender-email'], $_POST['fields'], true, 'noreply@' . parse_url(URL, PHP_URL_HOST));
         $fields['sender-name'] = __sendEmailFindFormValue($fields['sender-name'], $_POST['fields'], true, 'Symphony');
         $edit_link = URL . '/symphony/publish/' . $section->get('handle') . '/edit/' . $entry->get('id') . '/';
         $body = __('Dear <!-- RECIPIENT NAME -->,') . General::CRLF . __('This is a courtesy email to notify you that an entry was created on the %1$s section. You can edit the entry by going to: %2$s', array($section->get('name'), $edit_link)) . General::CRLF . General::CRLF;
         if (is_array($fields['body'])) {
             foreach ($fields['body'] as $field_handle => $value) {
                 $body .= "// {$field_handle}" . General::CRLF . $value . General::CRLF . General::CRLF;
             }
         } else {
             $body .= $fields['body'];
         }
         $errors = array();
         if (!is_array($fields['recipient']) || empty($fields['recipient'])) {
             $result->appendChild(buildFilterElement('send-email', 'failed', __('No valid recipients found. Check send-email[recipient] field.')));
         } else {
             foreach ($fields['recipient'] as $r) {
                 list($email, $name) = array_values($r);
                 if (!General::sendEmail($email, $fields['sender-email'], $fields['sender-name'], $fields['subject'], str_replace('<!-- RECIPIENT NAME -->', $name, $body))) {
                     $errors[] = $email;
                 }
             }
             if (!empty($errors)) {
                 $xml = buildFilterElement('send-email', 'failed');
                 foreach ($errors as $address) {
                     $xml->appendChild(new XMLElement('recipient', $address));
                 }
                 $result->appendChild($xml);
             } else {
                 $result->appendChild(buildFilterElement('send-email', 'passed'));
             }
         }
     }
     $filter_results = array();
     ###
     # 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 references to this object, the POST data and also the error array
     $obj->ExtensionManager->notifyMembers('EventPostSaveFilter', '/frontend/', array('entry_id' => $entry->get('id'), 'fields' => $fields, 'entry' => $entry, 'event' => &$event, 'messages' => &$filter_results));
     if (is_array($filter_results) && !empty($filter_results)) {
         foreach ($filter_results as $fr) {
             list($type, $status, $message) = $fr;
             $result->appendChild(buildFilterElement($type, $status ? 'passed' : 'failed', $message));
         }
     }
     ###
     # Delegate: EventFinalSaveFilter
     $obj->ExtensionManager->notifyMembers('EventFinalSaveFilter', '/frontend/', array('fields' => $fields, 'event' => &$event, 'errors' => &$filter_errors, 'entry' => $entry));
     $result->setAttributeArray(array('result' => 'success', 'type' => isset($entry_id) ? 'edited' : 'created'));
     $result->appendChild(new XMLElement('message', isset($entry_id) ? __('Entry edited successfully.') : __('Entry created successfully.')));
     if (isset($post_values) && is_object($post_values)) {
         $result->appendChild($post_values);
     }
     return true;
     ## End Function
 }
Ejemplo n.º 23
0
 public function __doit($fields, &$result, $position = null, $entry_id = null)
 {
     $post_values = new XMLElement('post-values');
     $filter_results = array();
     if (!is_array($this->eParamFILTERS)) {
         $this->eParamFILTERS = array();
     }
     // Create the post data cookie element
     if (is_array($fields) && !empty($fields)) {
         General::array_to_xml($post_values, $fields, true);
     }
     /**
      * Prior to saving entry from the front-end. This delegate will
      * force the Event to terminate if it populates the `$filter_results`
      * array. All parameters are passed by reference.
      *
      * @delegate EventPreSaveFilter
      * @param string $context
      * '/frontend/'
      * @param array $fields
      * @param Event $this
      * @param array $messages
      *  An associative array of array's which contain 4 values,
      *  the name of the filter (string), the status (boolean),
      *  the message (string) an optionally an associative array
      *  of additional attributes to add to the filter element.
      * @param XMLElement $post_values
      * @param integer $entry_id
      *  If editing an entry, this parameter will be an integer,
      *  otherwise null.
      */
     Symphony::ExtensionManager()->notifyMembers('EventPreSaveFilter', '/frontend/', array('fields' => &$fields, 'event' => &$this, 'messages' => &$filter_results, 'post_values' => &$post_values, 'entry_id' => &$entry_id));
     if (is_array($filter_results) && !empty($filter_results)) {
         $can_proceed = true;
         foreach ($filter_results as $fr) {
             list($name, $status, $message, $attributes) = $fr;
             $result->appendChild($this->buildFilterElement($name, $status ? 'passed' : 'failed', $message, $attributes));
             if ($status === false) {
                 $can_proceed = false;
             }
         }
         if ($can_proceed !== true) {
             $result->appendChild($post_values);
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
             return false;
         }
     }
     include_once TOOLKIT . '/class.sectionmanager.php';
     include_once TOOLKIT . '/class.entrymanager.php';
     if (!($section = SectionManager::fetch($this->getSource()))) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('The Section, %s, could not be found.', array($this->getSource()))));
         return false;
     }
     if (isset($entry_id)) {
         $entry =& EntryManager::fetch($entry_id);
         $entry = $entry[0];
         if (!is_object($entry)) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('The Entry, %s, could not be found.', array($entry_id))));
             return false;
         }
     } else {
         $entry =& EntryManager::create();
         $entry->set('section_id', $this->getSource());
     }
     if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, $entry->get('id') ? true : false)) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
         foreach ($errors as $field_id => $message) {
             $field = FieldManager::fetch($field_id);
             if (is_array($fields[$field->get('element_name')])) {
                 $type = array_reduce($fields[$field->get('element_name')], array('SectionEvent', '__reduceType'));
             } else {
                 $type = $fields[$field->get('element_name')] == '' ? 'missing' : 'invalid';
             }
             $result->appendChild(new XMLElement($field->get('element_name'), null, array('label' => General::sanitize($field->get('label')), 'type' => $type, 'message' => General::sanitize($message))));
         }
         if (isset($post_values) && is_object($post_values)) {
             $result->appendChild($post_values);
         }
         return false;
     } elseif (__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, $entry->get('id') ? true : false)) {
         $result->setAttribute('result', 'error');
         $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
         foreach ($errors as $field_id => $message) {
             $field = FieldManager::fetch($field_id);
             $result->appendChild(new XMLElement($field->get('element_name'), null, array('label' => General::sanitize($field->get('label')), 'type' => 'invalid', 'message' => General::sanitize($message))));
         }
         if (isset($post_values) && is_object($post_values)) {
             $result->appendChild($post_values);
         }
         return false;
     } else {
         if (!$entry->commit()) {
             $result->setAttribute('result', 'error');
             $result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.')));
             if (isset($post_values) && is_object($post_values)) {
                 $result->appendChild($post_values);
             }
             return false;
         }
         $result->setAttribute('id', $entry->get('id'));
     }
     // PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
     if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
         if (!function_exists('__sendEmailFindFormValue')) {
             function __sendEmailFindFormValue($needle, $haystack, $discard_field_name = true, $default = null, $collapse = true)
             {
                 if (preg_match('/^(fields\\[[^\\]]+\\],?)+$/i', $needle)) {
                     $parts = preg_split('/\\,/i', $needle, -1, PREG_SPLIT_NO_EMPTY);
                     $parts = array_map('trim', $parts);
                     $stack = array();
                     foreach ($parts as $p) {
                         $field = str_replace(array('fields[', ']'), '', $p);
                         $discard_field_name ? $stack[] = $haystack[$field] : ($stack[$field] = $haystack[$field]);
                     }
                     if (is_array($stack) && !empty($stack)) {
                         return $collapse ? implode(' ', $stack) : $stack;
                     } else {
                         $needle = null;
                     }
                 }
                 $needle = trim($needle);
                 if (empty($needle)) {
                     return $default;
                 }
                 return $needle;
             }
         }
         $fields = $_POST['send-email'];
         $db = Symphony::Database();
         $fields['recipient'] = __sendEmailFindFormValue($fields['recipient'], $_POST['fields'], true);
         $fields['recipient'] = preg_split('/\\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY);
         $fields['recipient'] = array_map('trim', $fields['recipient']);
         $fields['subject'] = __sendEmailFindFormValue($fields['subject'], $_POST['fields'], true, __('[Symphony] A new entry was created on %s', array(Symphony::Configuration()->get('sitename', 'general'))));
         $fields['body'] = __sendEmailFindFormValue($fields['body'], $_POST['fields'], false, null, false);
         $fields['sender-email'] = __sendEmailFindFormValue($fields['sender-email'], $_POST['fields'], true, null);
         $fields['sender-name'] = __sendEmailFindFormValue($fields['sender-name'], $_POST['fields'], true, null);
         $fields['reply-to-name'] = __sendEmailFindFormValue($fields['reply-to-name'], $_POST['fields'], true, null);
         $fields['reply-to-email'] = __sendEmailFindFormValue($fields['reply-to-email'], $_POST['fields'], true, null);
         $edit_link = SYMPHONY_URL . '/publish/' . $section->get('handle') . '/edit/' . $entry->get('id') . '/';
         $language = Symphony::Configuration()->get('lang', 'symphony');
         $template_path = Event::getNotificationTemplate($language);
         $body = sprintf(file_get_contents($template_path), $section->get('name'), $edit_link);
         if (is_array($fields['body'])) {
             foreach ($fields['body'] as $field_handle => $value) {
                 $body .= "// {$field_handle}" . PHP_EOL . $value . PHP_EOL . PHP_EOL;
             }
         } else {
             $body .= $fields['body'];
         }
         // Loop over all the recipients and attempt to send them an email
         // Errors will be appended to the Event XML
         $errors = array();
         foreach ($fields['recipient'] as $recipient) {
             $author = AuthorManager::fetchByUsername($recipient);
             if (empty($author)) {
                 $errors['recipient'][$recipient] = __('Recipient not found');
                 continue;
             }
             $email = Email::create();
             // Huib: Exceptions are also thrown in the settings functions, not only in the send function.
             // Those Exceptions should be caught too.
             try {
                 $email->recipients = array($author->get('first_name') => $author->get('email'));
                 if ($fields['sender-name'] != null) {
                     $email->sender_name = $fields['sender-name'];
                 }
                 if ($fields['sender-email'] != null) {
                     $email->sender_email_address = $fields['sender-email'];
                 }
                 if ($fields['reply-to-name'] != null) {
                     $email->reply_to_name = $fields['reply-to-name'];
                 }
                 if ($fields['reply-to-email'] != null) {
                     $email->reply_to_email_address = $fields['reply-to-email'];
                 }
                 $email->text_plain = str_replace('<!-- RECIPIENT NAME -->', $author->get('first_name'), $body);
                 $email->subject = $fields['subject'];
                 $email->send();
             } catch (EmailValidationException $e) {
                 $errors['address'][$author->get('email')] = $e->getMessage();
             } catch (EmailGatewayException $e) {
                 // The current error array does not permit custom tags.
                 // Therefore, it is impossible to set a "proper" error message.
                 // Will return the failed email address instead.
                 $errors['gateway'][$author->get('email')] = $e->getMessage();
             } catch (EmailException $e) {
                 // Because we don't want symphony to break because it can not send emails,
                 // all exceptions are logged silently.
                 // Any custom event can change this behaviour.
                 $errors['email'][$author->get('email')] = $e->getMessage();
             }
         }
         // If there were errors, output them to the event
         if (!empty($errors)) {
             $xml = $this->buildFilterElement('send-email', 'failed');
             foreach ($errors as $type => $messages) {
                 $xType = new XMLElement('error');
                 $xType->setAttribute('error-type', $type);
                 foreach ($messages as $recipient => $message) {
                     $xType->appendChild(new XMLElement('message', $message, array('recipient' => $recipient)));
                 }
                 $xml->appendChild($xType);
             }
             $result->appendChild($xml);
         } else {
             $result->appendChild($this->buildFilterElement('send-email', 'passed'));
         }
     }
     $filter_results = array();
     /**
      * After saving entry from the front-end. This delegate will not force
      * the Events to terminate if it populates the `$filter_results` array.
      * Provided with references to this object, the `$_POST` data and also
      * the error array
      *
      * @delegate EventPostSaveFilter
      * @param string $context
      * '/frontend/'
      * @param integer $entry_id
      * @param array $fields
      * @param Entry $entry
      * @param Event $this
      * @param array $messages
      *  An associative array of array's which contain 4 values,
      *  the name of the filter (string), the status (boolean),
      *  the message (string) an optionally an associative array
      *  of additional attributes to add to the filter element.
      */
     Symphony::ExtensionManager()->notifyMembers('EventPostSaveFilter', '/frontend/', array('entry_id' => $entry->get('id'), 'fields' => $fields, 'entry' => $entry, 'event' => &$this, 'messages' => &$filter_results));
     if (is_array($filter_results) && !empty($filter_results)) {
         foreach ($filter_results as $fr) {
             list($name, $status, $message, $attributes) = $fr;
             $result->appendChild($this->buildFilterElement($name, $status ? 'passed' : 'failed', $message, $attributes));
         }
     }
     $filter_errors = array();
     /**
      * This delegate that lets extensions know the final status of the
      * current Event. It is triggered when everything has processed correctly.
      * The `$messages` array contains the results of the previous filters that
      * have executed, and the `$errors` array contains any errors that have
      * occurred as a result of this delegate. These errors cannot stop the
      * processing of the Event, as that has already been done.
      *
      *
      * @delegate EventFinalSaveFilter
      * @param string $context
      * '/frontend/'
      * @param array $fields
      * @param Event $this
      * @param array $messages
      *  An associative array of array's which contain 4 values,
      *  the name of the filter (string), the status (boolean),
      *  the message (string) an optionally an associative array
      *  of additional attributes to add to the filter element.
      * @param array $errors
      *  An associative array of array's which contain 4 values,
      *  the name of the filter (string), the status (boolean),
      *  the message (string) an optionally an associative array
      *  of additional attributes to add to the filter element.
      * @param Entry $entry
      */
     Symphony::ExtensionManager()->notifyMembers('EventFinalSaveFilter', '/frontend/', array('fields' => $fields, 'event' => $this, 'messages' => $filter_results, 'errors' => &$filter_errors, 'entry' => $entry));
     if (is_array($filter_errors) && !empty($filter_errors)) {
         foreach ($filter_errors as $fr) {
             list($name, $status, $message, $attributes) = $fr;
             $result->appendChild($this->buildFilterElement($name, $status ? 'passed' : 'failed', $message, $attributes));
         }
     }
     $result->setAttributeArray(array('result' => 'success', 'type' => isset($entry_id) ? 'edited' : 'created'));
     $result->appendChild(new XMLElement('message', isset($entry_id) ? __('Entry edited successfully.') : __('Entry created successfully.')));
     if (isset($post_values) && is_object($post_values)) {
         $result->appendChild($post_values);
     }
     return true;
 }
Ejemplo n.º 24
0
 public function validate($source = null, $remote = true)
 {
     if (!function_exists('handleXMLError')) {
         function handleXMLError($errno, $errstr, $errfile, $errline, $context)
         {
             $context['self']->_errors[] = $errstr;
         }
     }
     set_time_limit(900);
     set_error_handler('handleXMLError');
     $self = $this;
     // F*****g PHP...
     $options = $this->options();
     $passed = true;
     if ($remote) {
         if (!is_null($source)) {
             $options['source'] = $source;
         }
         // Support {$root}
         $options['source'] = str_replace('{$root}', URL, $options['source']);
         // Parse timeout, default is 60
         $timeout = isset($options['timeout']) ? (int) $options['timeout'] : 60;
         // Fetch document:
         $gateway = new Gateway();
         $gateway->init();
         $gateway->setopt('URL', $options['source']);
         $gateway->setopt('TIMEOUT', $timeout);
         $data = $gateway->exec();
         $info = $gateway->getInfoLast();
         if (empty($data) || $info['http_code'] >= 400) {
             $this->_errors[] = __('No data to import. URL returned HTTP code %d', array($info['http_code']));
             $passed = false;
         }
     } else {
         if (!is_null($source)) {
             $data = $source;
         } else {
             $this->_errors[] = __('No data to import.');
             $passed = false;
         }
     }
     if (!is_array($options['fields'])) {
         $this->_errors[] = __('No field mappings have been set for this XML Importer.');
         $passed = false;
     }
     if (!$passed) {
         return self::__ERROR_PREPARING__;
     }
     // Load document:
     $xml = new DOMDocument();
     $xml->loadXML($data);
     restore_error_handler();
     $xpath = new DOMXPath($xml);
     $passed = true;
     // Register namespaces:
     if (is_array($options['namespaces'])) {
         foreach ($options['namespaces'] as $namespace) {
             $xpath->registerNamespace($namespace['name'], $namespace['uri']);
         }
     }
     // Invalid Markup:
     if (empty($xml)) {
         $passed = false;
     } else {
         if (($entries = $xpath->query($options['included-elements'])) === false) {
             $this->_errors[] = __('Root expression <code>%s</code> is invalid.', array(General::sanitize($options['included-elements'])));
             $passed = false;
         } else {
             if (is_null($entries) or $entries->length == 0) {
                 $this->_errors[] = __('No entries to import.');
                 $passed = false;
             } else {
                 foreach ($options['fields'] as $mapping) {
                     if ($xpath->evaluate(stripslashes($mapping['xpath'])) !== false) {
                         continue;
                     }
                     $field = FieldManager::fetch($mapping['field']);
                     $this->_errors[] = __('\'%s\' expression <code>%s</code> is invalid.', array($field->get('label'), General::sanitize($mapping['xpath'])));
                     $passed = false;
                 }
             }
         }
     }
     if (!$passed) {
         return self::__ERROR_PREPARING__;
     }
     // Gather data:
     foreach ($entries as $index => $entry) {
         $this->_entries[$index] = array('element' => $entry, 'values' => array(), 'errors' => array(), 'entry' => null);
         foreach ($options['fields'] as $mapping) {
             $values = $this->getExpressionValue($xml, $entry, $xpath, $mapping['xpath'], $debug);
             if (isset($mapping['php']) && $mapping['php'] != '') {
                 $php = stripslashes($mapping['php']);
                 // static helper
                 if (preg_match('/::/', $php)) {
                     foreach ($values as $id => $value) {
                         $values[$id] = call_user_func_array($php, array($value));
                     }
                 } else {
                     foreach ($values as $id => $value) {
                         $function = preg_replace('/\\$value/', "'" . $value . "'", $php);
                         if (!preg_match('/^return/', $function)) {
                             $function = 'return ' . $function;
                         }
                         if (!preg_match('/;$/', $function)) {
                             $function .= ';';
                         }
                         $values[$id] = @eval($function);
                     }
                 }
             }
             $this->_entries[$index]['values'][$mapping['field']] = $values;
         }
     }
     // Validate:
     $passed = true;
     foreach ($this->_entries as &$current) {
         $entry = EntryManager::create();
         $entry->set('section_id', $options['section']);
         $entry->set('author_id', is_null(Symphony::Engine()->Author()) ? '1' : Symphony::Engine()->Author()->get('id'));
         $values = array();
         // Map values:
         foreach ($current['values'] as $field_id => $value) {
             $field = FieldManager::fetch($field_id);
             if (is_array($value)) {
                 if (count($value) === 1) {
                     $value = current($value);
                 }
                 if (count($value) === 0) {
                     $value = '';
                 }
             }
             // Adjust value?
             if (method_exists($field, 'prepareImportValue') && method_exists($field, 'getImportModes')) {
                 $modes = $field->getImportModes();
                 if (is_array($modes) && !empty($modes)) {
                     $mode = current($modes);
                 }
                 $value = $field->prepareImportValue($value, $mode, $entry->get('id'));
             } else {
                 $type = $field->get('type');
                 if ($type == 'author') {
                     if ($field->get('allow_multiple_selection') == 'no') {
                         if (is_array($value)) {
                             $value = array(implode('', $value));
                         }
                     }
                 } else {
                     if ($type == 'datetime') {
                         $value = $value[0];
                     } else {
                         if (is_array($value)) {
                             $value = implode('', $value);
                         }
                     }
                 }
             }
             $values[$field->get('element_name')] = $value;
         }
         // Validate:
         if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($values, $current['errors'])) {
             $passed = false;
         } else {
             if (__ENTRY_OK__ != $entry->setDataFromPost($values, $current['errors'], true, true)) {
                 $passed = false;
             }
         }
         $current['entry'] = $entry;
         $current['values'] = $values;
     }
     if (!$passed) {
         return self::__ERROR_VALIDATING__;
     }
     return self::__OK__;
 }