public function export($post) { $sectionManager = new SectionManager($this->_Parent); $section = $sectionManager->fetch($post['target']); /* Fetch ** ------------ ** Fetch the entries data using the DM, optionally using ** a filter. */ if ($post['linked-section'] and $post['linked-entry']) { $filter = array($post['linked-section'] => $post['linked-entry']); } else { $filter = null; } require_once EXTENSIONS . '/databasemanipulator/lib/class.databasemanipulator.php'; DatabaseManipulator::associateParent($this->_Parent); $entries = DatabaseManipulator::getEntries($section->get('id'), '*', $filter); $fields_value = $header = $data = array(); /* CSV Header ** -------------- ** Build the header from the fields */ $header_entry = array_values(current($entries)); $output = $this->_driver->str_putcsv(array_keys($header_entry[1])); /* Data ** ----------- ** Get the field scheme, then loop through our data applying the field's prepareTableValue for ** for output. If the field contains a relationship, use resolveLinks to implode the linked values */ foreach ($section->fetchFields() as $field) { $fields_value[$field->get('id')] = $field; } $fields = end($section); foreach ($entries as $k => $v) { foreach ($v['fields'] as $name => $entry) { $f_id = $fields->fetchFieldIDFromElementName($name, $section->get('id')); if (isset($entry)) { if (array_key_exists("linked_entry_id", $entry) or array_key_exists("relation_id", $entry)) { $data[$k][] = $this->resolveLinks(current($entry)); } else { $value = $fields_value[$f_id]->prepareTableValue($entry); ## Dirty hack way to show HREF's in the CSV while stripping away the rest if (strpos($value, "href") === FALSE) { $data[$k][] = preg_replace('/(<[^>]+>)/', '', $value); } else { $pieces = explode('"', $value); $data[$k][] = $pieces[1]; } } } else { ## No value, so null it otherwise our columns won't match up $data[$k][] = null; } } } $output .= $this->_driver->str_putcsv($data); ## We got our CSV, so lets output it, but we'll exit, because we don't want any Symphony output header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename= ' . $this->getFileName($post['target'])); echo $output; exit; }