/** * Perform initial checks and load requested view * * @param string $url * URL path of requested view */ public function load($url = null) { // Check for login Controller::instance()->isLoggedIn(); if (!Controller::instance()->isLoggedIn()) { $this->parseURL('/login'); } else { try { if (is_null($url)) { // Get user's default section $section_handle = Controller::instance()->User->default_section; // If the section exists, load publish view try { $section = Section::loadFromHandle($section_handle); $this->parseURL('/publish/' . $section_handle); } catch (Exception $e) { $this->parseURL('/blueprints/sections/'); } } else { $this->parseURL($url); } // TODO: Fix this if (!$this instanceof AdministrationView) { throw new Exception('View not found'); } } catch (Exception $e) { throw $e; //catch the exception print 'Sorry could not load ' . $url; } } }
public function __construct() { $this->view = Controller::instance()->View; $this->document = $this->view->document; $this->url = Controller::instance()->url; // Probably a neater way to store and fetch the section handle $this->section = Section::loadFromHandle($this->view->params[0]); $this->setTitle(); }
public function prepareDestinationColumnValue() { $section = Section::loadFromHandle($this->_parameters->section); if ($section instanceof Section) { return Widget::TableData(Widget::Anchor($section->name, ADMIN_URL . '/blueprints/sections/edit/' . $section->handle . '/', array('title' => $section->handle))); } else { return Widget::TableData(__('None'), array('class' => 'inactive')); } }
function __actionIndex() { $checked = is_array($_POST['items']) ? array_keys($_POST['items']) : null; $callback = Administration::instance()->getPageCallback(); if (is_array($checked) && !empty($checked)) { switch ($_POST['with-selected']) { case 'delete': ### # Delegate: Delete # Description: Prior to deletion of entries. Array of Entries is provided. # The array can be manipulated Extension::notify('Delete', '/publish/', array('entry_id' => &$checked)); foreach ($checked as $entry_id) { Entry::delete($entry_id); } redirect($_SERVER['REQUEST_URI']); default: ## TODO: Add delegate // I've add this in a 2.0.8 commit, look for it //brendan list($option, $field_handle, $value) = explode('::', $_POST['with-selected'], 3); if ($option == 'toggle') { // TO DO: This is a funky way to access a field via its handle. Might need to rethink this $section = Section::loadFromHandle($callback['context']['section_handle']); foreach ($section->fields as $f) { if ($f->{'element-name'} == $field_handle) { $field = $f; break; } } if ($field instanceof Field) { foreach ($checked as $entry_id) { $entry = Entry::loadFromID($entry_id); $entry->data()->{$field_handle} = $field->processData($value, $entry); $this->errors->flush(); Entry::save($entry, $this->errors); } } redirect($_SERVER['REQUEST_URI']); } break; } } }
public function __form(Entry $existing = NULL) { $callback = Administration::instance()->getPageCallback(); $section = Section::loadFromHandle($callback['context']['section_handle']); // Check that a layout and fields exist if (isset($section->fields)) { $this->alerts()->append(__('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(ADMIN_URL . '/blueprints/sections/edit/' . $section->handle . '/')), AlertStack::ERROR); } $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), $section->name))); $subheading = __('New Entry'); if (!is_null($existing) && $existing instanceof Entry) { if (is_null($this->entry) || !$this->entry instanceof Entry) { $this->entry = $existing; } // Grab the first field in the section $first_field = $section->fields[0]; $field_data = (object) array(); if (!is_null($existing->data()->{$first_field->{'element-name'}})) { $field_data = $existing->data()->{$first_field->{'element-name'}}; } $subheading = $first_field->prepareTableValue($field_data); } if (is_null($this->entry) || !$this->entry instanceof Entry) { $this->entry = new Entry(); } $this->entry->section = $callback['context']['section_handle']; $this->appendSubheading($subheading); $this->entry->findDefaultFieldData(); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->core()->symphony->{'maximum-upload-size'}, 'hidden')); // Check if there is a field to prepopulate if (isset($_REQUEST['prepopulate']) && strlen(trim($_REQUEST['prepopulate'])) > 0) { $field_handle = key($_REQUEST['prepopulate']); $value = stripslashes(rawurldecode($_REQUEST['prepopulate'][$field_handle])); $prepopulate_filter = "?prepopulate[{$field_handle}]=" . rawurlencode($value); $this->Form->setAttribute('action', Administration::instance()->getCurrentPageURL() . $prepopulate_filter); if (is_null($existing)) { $this->entry->data()->{$field_handle}->value = $value; } } // Status message: if (isset($callback['flag']) and !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('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__), ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/new/' . $prepopulate_filter, ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('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__), ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/new/' . $prepopulate_filter, ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/')), AlertStack::SUCCESS); break; } } // Load all the fields for this section $section_fields = array(); foreach ($section->fields as $index => $field) { $section_fields[$field->{'element-name'}] = $field; } $layout = new Layout(); if (is_array($section->layout) && !empty($section->layout)) { foreach ($section->layout as $data) { $column = $layout->createColumn($data->size); foreach ($data->fieldsets as $data) { $fieldset = $this->createElement('fieldset'); if (isset($data->collapsed) && $data->collapsed == 'yes') { $fieldset->setAttribute('class', 'collapsed'); } if (isset($data->name) && strlen(trim($data->name)) > 0) { $fieldset->appendChild($this->createElement('h3', $data->name)); } foreach ($data->fields as $handle) { $field = $section_fields[$handle]; if (!$field instanceof Field) { continue; } $div = $this->createElement('div', NULL, array('class' => trim(sprintf('field field-%s %s %s', $field->handle(), $this->__calculateWidth($field->width), $field->required == 'yes' ? 'required' : '')))); $field->displayPublishPanel($div, isset($this->errors->{$field->{'element-name'}}) ? $this->errors->{$field->{'element-name'}} : new MessageStack(), $this->entry, $this->entry->data()->{$field->{'element-name'}}); $fieldset->appendChild($div); } $column->appendChild($fieldset); } $layout->appendTo($this->Form); } } else { $this->alerts()->append(__('You haven\'t set any section layout rules. <a href="%s">Click here to define a layout.</a>', array(ADMIN_URL . '/blueprints/sections/layout/' . $section->handle . '/')), AlertStack::ERROR); $column = $layout->createColumn(Layout::LARGE); $fieldset = $this->createElement('fieldset'); $header = $this->createElement('h3', __('Untitled')); $fieldset->appendChild($header); if (is_array($section->fields)) { foreach ($section->fields as $field) { $div = $this->createElement('div', NULL, array('class' => trim(sprintf('field field-%s %s %s', $field->handle(), $this->__calculateWidth($field->width), $field->required == 'yes' ? 'required' : 'optional')))); $field->displayPublishPanel($div, isset($this->errors->{$field->{'element-name'}}) ? $this->errors->{$field->{'element-name'}} : new MessageStack(), $this->entry, $this->entry->data()->{$field->{'element-name'}}); $fieldset->appendChild($div); } } $column->appendChild($fieldset); $layout->appendTo($this->Form); } $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $existing ? __('Save Changes') : __('Create Entry'), array('accesskey' => 's'))); if (!is_null($existing)) { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this entry')))); } $this->Form->appendChild($div); }
protected function login(MessageStack $errors, Register $parameter_output, array $data) { $section = Section::loadFromHandle($this->parameters()->{'section'}); $wheres = array(); $joins = null; // Find fields: foreach ($section->fields as $field) { if ($field instanceof FieldMemberName) { $field_name = $field; $handle_name = $field->{'element-name'}; } else { if ($field instanceof FieldMemberEmail) { $field_email = $field; $handle_email = $field->{'element-name'}; } else { if ($field instanceof FieldMemberPassword) { $field_password = $field; $handle_password = $field->{'element-name'}; } } } } if (!isset($field_email) or !isset($field_password)) { throw new Exception(__('Section does not contain required fields.')); } // Simulate data from cookie: if (empty($data) and $this->readSession()) { $session = $this->readSession(); $fields = array($field_email->{'element-name'} => $session->email, $field_password->{'element-name'} => $session->login); } else { $this->deleteSession(); $fields = $data['fields']; } // Apply default values: foreach ($this->parameters()->{'defaults'} as $name => $value) { if (!isset($fields[$name])) { $fields[$name] = $value; } else { if (is_string($fields[$name]) and $fields[$name] == '') { $fields[$name] = $value; } else { if (is_array($fields[$name]) and empty($fields[$name])) { $fields[$name] = array($value); } } } } // Apply override values: foreach ($this->parameters()->{'overrides'} as $name => $value) { if (is_array($fields[$name])) { $fields[$name] = array($value); } else { $fields[$name] = $value; } } // Find values: if (isset($field_name)) { $value_name = (isset($fields[$handle_name]) and strlen($fields[$handle_name]) > 0) ? $fields[$handle_name] : null; } if (isset($field_email)) { $value_email = (isset($fields[$handle_email]) and strlen($fields[$handle_email]) > 0) ? $fields[$handle_email] : null; } if (isset($field_password)) { $value_password = (isset($fields[$handle_password]) and strlen($fields[$handle_password]) > 0) ? $fields[$handle_password] : null; } if (is_null($value_email) and is_null($value_name) or is_null($value_password)) { throw new Exception(__('Missing login credentials.')); } // Build query: $where_password = array(); $value_password = array('value' => $value_password, 'type' => 'is'); $field_password->buildFilterQuery($value_password, $joins, $where_password, $parameter_output); if (isset($field_email) and !is_null($value_email)) { $where_email = $where_password; $value_email = array('value' => $value_email, 'type' => 'is'); $field_email->buildFilterQuery($value_email, $joins, $where_email, $parameter_output); $wheres[] = '(' . implode("\nAND ", $where_email) . ')'; } if (isset($field_name) and !is_null($value_name)) { $where_name = $where_password; $value_name = array('value' => $value_name, 'type' => 'is'); $field_name->buildFilterQuery($value_name, $joins, $where_name, $parameter_output); $wheres[] = '(' . implode("\nAND ", $where_name) . ')'; } array_unshift($wheres, null); $wheres = implode("\nOR ", $wheres); $query = "\nSELECT DISTINCT\n\te.*\nFROM\n\t`tbl_entries` AS e{$joins}\nWHERE\n\tFALSE{$wheres}\n\t\t\t"; //echo '<pre>', htmlentities($query), '</pre>'; exit; // Find entry: $result = Symphony::Database()->query($query, array(), 'EntryResult'); if (!$result->valid()) { throw new Exception(__('Invalid login credentials.')); } $entry = $result->current(); $email = $entry->data()->{$handle_email}->value; $code = $entry->data()->{$handle_password}->code; $login = $this->driver->createToken($code, 'login'); if ($this->parameters()->{'create-cookie'} == true) { $this->writeCookie($login, $email); } $event_name = $this->parameters()->{'root-element'}; $parameter_output->{"event-{$event_name}.system.id"} = $entry->id; $parameter_output->{"event-{$event_name}.member.email"} = $email; $parameter_output->{"event-{$event_name}.member.login"} = $login; // Remove login fields: unset($fields[$handle_name], $fields[$handle_email], $fields[$handle_password]); // Set password as optional: $fields[$handle_password] = array('validate' => array('optional' => $this->driver->createToken($code, 'validate')), 'change' => array('optional' => $this->driver->createToken($code, 'change'))); // Update fields: $entry->setFieldDataFromFormArray($fields); ### # Delegate: EntryPreCreate # Description: Just prior to creation of an Entry. Entry object provided Extension::notify('EntryPreCreate', '/frontend/', array('entry' => &$entry)); $status = Entry::save($entry, $errors); if ($status != Entry::STATUS_OK) { throw new Exception(__('Entry encountered errors when saving.')); } ### # Delegate: EntryPostCreate # Description: Creation of an Entry. New Entry object is provided. Extension::notify('EntryPostCreate', '/frontend/', array('entry' => $entry)); }
private static function __loadExistingSection($handle) { try { return Section::loadFromHandle($handle); } catch (SectionException $e) { switch ($e->getCode()) { case Section::ERROR_SECTION_NOT_FOUND: throw new SymphonyErrorPage(__('The section you requested to edit does not exist.'), __('Section not found'), NULL, array('HTTP/1.0 404 Not Found')); break; default: case Section::ERROR_FAILED_TO_LOAD: throw new SymphonyErrorPage(__('The section you requested could not be loaded. Please check it is readable.'), __('Failed to load section')); break; } } catch (Exception $e) { throw new SymphonyErrorPage(sprintf(__("An unknown error has occurred. %s"), $e->getMessage()), __('Unknown Error'), NULL, array('HTTP/1.0 500 Internal Server Error')); } }
public function processData($data, Entry $entry = null) { $result = array(); if (!is_array($data)) { return $result; } foreach ($data as $key => $fields) { if (is_numeric($key)) { $joined = Entry::loadFromId($key); $section = Section::loadFromHandle($joined->section); } else { $section = Section::loadFromHandle($key); $result[$key] = array(); } foreach ($fields as $field_handle => $value) { $field = $section->fetchFieldByHandle($field_handle); $result[$key][$field_handle] = $field->processData($value, $entry); } break; } return $result; }
public function display($page) { // Default headers. Can be overwritten later //self::$Headers->append('HTTP/1.0 200 OK'); self::$Headers->append('Content-Type', 'text/html;charset=utf-8'); self::$Headers->append('Expires', 'Mon, 12 Dec 1982 06:14:00 GMT'); self::$Headers->append('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT'); self::$Headers->append('Cache-Control', 'no-cache, must-revalidate, max-age=0'); self::$Headers->append('Pragma', 'no-cache'); $this->isLoggedIn(); if (empty($page)) { if (!$this->isLoggedIn()) { $page = '/login'; } else { $section_handle = $this->User->default_section; // Make sure section exists: try { $section = Section::loadFromHandle($section_handle); redirect(ADMIN_URL . "/publish/{$section_handle}/"); } catch (Exception $e) { redirect(ADMIN_URL . '/blueprints/sections/'); } } } if (!($this->_callback = $this->getPageCallback($page))) { throw new AdministrationPageNotFoundException($page); } include_once (isset($this->_callback['driverlocation']) ? $this->_callback['driverlocation'] : CONTENT) . '/content.' . $this->_callback['driver'] . '.php'; $this->Page = new $this->_callback['classname'](); // Widget class needs a document in order to create elements Widget::init($this->Page); #### # Delegate: AdminPagePreBuild # Description: Immediately before building the admin page. Provided with the page and callback # Global: Yes Extension::notify('AdminPagePreBuild', '/administration/', array('page' => &$this->Page, 'callback' => &$this->_callback)); if (!$this->isLoggedIn() && $this->_callback['driver'] != 'login') { if (is_callable(array($this->Page, 'handleFailedAuthorisation'))) { $this->Page->handleFailedAuthorisation(); } else { include_once CONTENT . '/content.login.php'; $this->Page = new contentLogin(); $this->Page->build(); } } else { $this->Page->build($this->_callback['context']); } #### # Delegate: AdminPagePreGenerate # Description: Immediately before generating the admin page. Provided with the page object # Global: Yes Extension::notify('AdminPagePreGenerate', '/administration/', array('page' => &$this->Page)); $output = (string) $this->Page; #### # Delegate: AdminPagePostGenerate # Description: Immediately after generating the admin page. Provided with string containing page source # Global: Yes Extension::notify('AdminPagePostGenerate', '/administration/', array('output' => &$output)); self::Headers()->render(); return $output; }
public function prepareTableValue($data, DOMElement $link = NULL) { if (!is_array($data) || empty($data)) { return parent::prepareTableValue(NULL, $link); } $result = Administration::instance()->Page->createDocumentFragment(); foreach ($data as $index => $d) { try { $entry = Entry::loadFromID($d->relation_id); foreach ($this->{'related-fields'} as $key => $value) { list($section_handle, $field_handle) = $value; if ($section_handle != $entry->meta()->section) { continue; } $section = Section::loadFromHandle($section_handle); $field = $section->fetchFieldByHandle($field_handle); $value = $field->prepareTableValue($entry->data()->{$field_handle}); // TODO: handle passing links if ($index > 0) { $result->appendChild(new DOMText(', ')); } $result->appendChild(Widget::anchor($value, sprintf('%s/publish/%s/edit/%d/', ADMIN_URL, $section_handle, $entry->meta()->id))); break; } } catch (Exception $e) { } } if (!$result->hasChildNodes()) { return parent::prepareTableValue(NULL, $link); } return $result; }
public function render(Register $ParameterOutput, $joins = NULL, array $where = array(), $filter_operation_type = self::FILTER_AND) { $execute = true; $result = new XMLDocument(); $result->appendChild($result->createElement($this->parameters()->{'root-element'})); $root = $result->documentElement; // Conditions // If any one condtion returns true (that is, do not execute), the DS will not execute at all if (is_array($this->parameters()->conditions)) { foreach ($this->parameters()->conditions as $condition) { if (preg_match('/:/', $condition['parameter'])) { $c = Datasource::replaceParametersInString($condition['parameter'], $ParameterOutput); } else { $c = Datasource::resolveParameter($condition['parameter'], $ParameterOutput); } // Is Empty if ($condition['logic'] == 'empty' && (is_null($c) || strlen($c) == 0)) { $execute = false; } elseif ($condition['logic'] == 'set' && !is_null($c)) { $execute = false; } if ($execute !== true) { return NULL; } } } // Grab the section try { $section = Section::loadFromHandle($this->parameters()->section); } catch (SectionException $e) { } catch (Exception $e) { } $pagination = (object) array('total-entries' => NULL, 'entries-per-page' => max(1, (int) self::replaceParametersInString($this->parameters()->limit, $ParameterOutput)), 'total-pages' => NULL, 'current-page' => max(1, (int) self::replaceParametersInString($this->parameters()->page, $ParameterOutput))); $pagination->{'record-start'} = max(0, ($pagination->{'current-page'} - 1) * $pagination->{'entries-per-page'}); $order = $sort = NULL; // Apply the Sorting & Direction if ($this->parameters()->{'sort-order'} == 'random') { $order = 'RAND()'; } else { $sort = strtolower($this->parameters()->{'sort-order'}) == 'asc' ? 'ASC' : 'DESC'; // System Field if (preg_match('/^system:/i', $this->parameters()->{'sort-field'})) { switch (preg_replace('/^system:/i', NULL, $this->parameters()->{'sort-field'})) { case 'id': $order = "e.id {$sort}"; break; case 'creation-date': $order = "e.creation_date {$sort}"; break; case 'modification-date': $order = "e.modification_date {$sort}"; break; } } else { $join = NULL; $sort_field = $section->fetchFieldByHandle($this->parameters()->{'sort-field'}); if ($sort_field instanceof Field && $sort_field->isSortable() && method_exists($sort_field, "buildSortingQuery")) { $sort_field->buildSortingQuery($join, $order); $joins .= sprintf($join, $sort_field->section, $sort_field->{'element-name'}); $order = sprintf($order, $sort); } } } // Process Datasource Filters for each of the Fields if (is_array($this->parameters()->filters) && !empty($this->parameters()->filters)) { foreach ($this->parameters()->filters as $k => $filter) { if ($filter['element-name'] == 'system:id') { $filter_value = $this->prepareFilterValue($filter['value'], $ParameterOutput); if (!is_array($filter_value)) { continue; } $filter_value = array_map('intval', $filter_value); if (empty($filter_value)) { continue; } $where[] = sprintf("(e.id %s IN (%s))", $filter['type'] == 'is-not' ? 'NOT' : NULL, implode(',', $filter_value)); } else { $field = $section->fetchFieldByHandle($filter['element-name']); if ($field instanceof Field) { $field->buildFilterQuery($filter, $joins, $where, $ParameterOutput); } } } } // Escape percent symbold: $where = array_map(create_function('$string', 'return str_replace(\'%\', \'%%\', $string);'), $where); $query = sprintf('SELECT DISTINCT SQL_CALC_FOUND_ROWS e.* FROM `tbl_entries` AS `e` %1$s WHERE `section` = "%2$s" %3$s ORDER BY %4$s LIMIT %5$d, %6$d', $joins, $section->handle, is_array($where) && !empty($where) ? 'AND (' . implode($filter_operation_type == self::FILTER_AND ? ' AND ' : ' OR ', $where) . ')' : NULL, $order, $pagination->{'record-start'}, $pagination->{'entries-per-page'}); try { $entries = Symphony::Database()->query($query, array($section->handle, $section->{'publish-order-handle'}), 'EntryResult'); if (isset($this->parameters()->{'append-pagination'}) && $this->parameters()->{'append-pagination'} === true) { $pagination->{'total-entries'} = (int) Symphony::Database()->query("SELECT FOUND_ROWS() AS `total`")->current()->total; $pagination->{'total-pages'} = (int) ceil($pagination->{'total-entries'} * (1 / $pagination->{'entries-per-page'})); // Pagination Element $root->appendChild(General::buildPaginationElement($result, $pagination->{'total-entries'}, $pagination->{'total-pages'}, $pagination->{'entries-per-page'}, $pagination->{'current-page'})); } if (isset($this->parameters()->{'append-sorting'}) && $this->parameters()->{'append-sorting'} === true) { $sorting = $result->createElement('sorting'); $sorting->setAttribute('field', $this->parameters()->{'sort-field'}); $sorting->setAttribute('order', $this->parameters()->{'sort-order'}); $root->appendChild($sorting); } $schema = array(); // Build Entry Records if ($entries->valid()) { // Do some pre-processing on the include-elements. if (is_array($this->parameters()->{'included-elements'}) && !empty($this->parameters()->{'included-elements'})) { $included_elements = (object) array('system' => array(), 'fields' => array()); foreach ($this->parameters()->{'included-elements'} as $element) { $element_name = $mode = NULL; if (preg_match_all('/^([^:]+):\\s*(.+)$/', $element, $matches, PREG_SET_ORDER)) { $element_name = $matches[0][1]; $mode = $matches[0][2]; } else { $element_name = $element; } if ($element_name == 'system') { $included_elements->system[] = $mode; } else { $field = $section->fetchFieldByHandle($element_name); if (!$field instanceof Field) { continue; } $schema[] = $element_name; $included_elements->fields[] = array('element-name' => $element_name, 'instance' => $field, 'mode' => !is_null($mode) > 0 ? trim($mode) : NULL); } } } // Do some pre-processing on the param output array if (is_array($this->parameters()->{'parameter-output'}) && !empty($this->parameters()->{'parameter-output'})) { $parameter_output = (object) array('system' => array(), 'fields' => array()); foreach ($this->parameters()->{'parameter-output'} as $element) { if (preg_match('/^system:/i', $element)) { $parameter_output->system[preg_replace('/^system:/i', NULL, $element)] = array(); } else { $schema[] = $element; $parameter_output->fields[$element] = array(); } } } $entries->setSchema($schema); foreach ($entries as $e) { // If there are included elements, need an entry element. if (is_array($this->parameters()->{'included-elements'}) && !empty($this->parameters()->{'included-elements'})) { $entry = $result->createElement('entry'); $entry->setAttribute('id', $e->id); $root->appendChild($entry); foreach ($included_elements->system as $field) { switch ($field) { case 'creation-date': $entry->appendChild(General::createXMLDateObject($result, DateTimeObj::fromGMT($e->creation_date), 'creation-date')); break; case 'modification-date': $entry->appendChild(General::createXMLDateObject($result, DateTimeObj::fromGMT($e->modification_date), 'modification-date')); break; case 'user': $obj = User::load($e->user_id); $user = $result->createElement('user', $obj->getFullName()); $user->setAttribute('id', $e->user_id); $user->setAttribute('username', $obj->username); $user->setAttribute('email-address', $obj->email); $entry->appendChild($user); break; } } foreach ($included_elements->fields as $field) { $field['instance']->appendFormattedElement($entry, $e->data()->{$field['element-name']}, false, $field['mode'], $e); } } if (is_array($this->parameters()->{'parameter-output'}) && !empty($this->parameters()->{'parameter-output'})) { foreach ($parameter_output->system as $field => $existing_values) { switch ($field) { case 'id': $parameter_output->system[$field][] = $e->id; break; case 'creation-date': $parameter_output->system[$field][] = DateTimeObj::get('Y-m-d H:i:s', DateTimeObj::fromGMT($e->creation_date)); break; case 'modification-date': $parameter_output->system[$field][] = DateTimeObj::get('Y-m-d H:i:s', DateTimeObj::fromGMT($e->modification_date)); break; case 'user': $parameter_output->system[$field][] = $e->user_id; break; } } foreach ($parameter_output->fields as $field => $existing_values) { if (!isset($e->data()->{$field}) or is_null($e->data()->{$field})) { continue; } $o = $section->fetchFieldByHandle($field)->getParameterOutputValue($e->data()->{$field}, $e); if (is_array($o)) { $parameter_output->fields[$field] = array_merge($o, $parameter_output->fields[$field]); } else { $parameter_output->fields[$field][] = $o; } } } } // Add in the param output values to the ParameterOutput object if (is_array($this->parameters()->{'parameter-output'}) && !empty($this->parameters()->{'parameter-output'})) { foreach ($parameter_output->system as $field => $values) { $key = sprintf('ds-%s.system.%s', $this->parameters()->{'root-element'}, $field); $values = array_filter($values); if (is_array($values) && !empty($values)) { $ParameterOutput->{$key} = array_unique($values); } } foreach ($parameter_output->fields as $field => $values) { $key = sprintf('ds-%s.%s', $this->parameters()->{'root-element'}, $field); $values = array_filter($values); if (is_array($values) && !empty($values)) { $ParameterOutput->{$key} = array_unique($values); } } } } elseif ($this->parameters()->{'redirect-404-on-empty'} === true) { throw new FrontendPageNotFoundException(); } else { $this->emptyXMLSet($root); } } catch (DatabaseException $e) { $root->appendChild($result->createElement('error', $e->getMessage())); } return $result; }
public function findDefaultFieldData() { $section = Section::loadFromHandle($this->section); foreach ($section->fields as $field) { $element = $field->{'element-name'}; if (isset($this->data()->{$element})) { continue; } $this->data()->{$element} = $field->processData(NULL, $this); } }
public function __actionDelete(array $sections, $redirect) { $success = true; $callback = Administration::instance()->getPageCallback(); $current_page = $callback['pageroot'] . (isset($callback['context'][0]) && $callback['context'][0] != 'index' ? $callback['context'][0] . '/' : NULL); foreach ($sections as $handle) { try { Section::delete(Section::loadFromHandle($handle)); ### # Delegate: SectionPostDelete Extension::notify('SectionPostDelete', $current_page, array('handle' => $handle)); } catch (SectionException $e) { $success = false; $this->alerts()->append($e->getMessage(), AlertStack::ERROR, $e); } catch (Exception $e) { $success = false; $this->alerts()->append(__('An unknown error has occurred. <a class="more">Show trace information.</a>'), AlertStack::ERROR, $e); } } if ($success) { redirect($redirect); } }
public function current() { $record = parent::current(); $entry = new Entry(); foreach ($record as $key => $value) { $entry->{$key} = $value; } if (empty($this->data)) { return $entry; } // Load the section try { $section = Section::loadFromHandle($entry->section); } catch (SectionException $e) { throw new EntryException('Section specified, "' . $entry->section . '", in Entry object is invalid.'); } catch (Exception $e) { throw new EntryException('The following error occurred: ' . $e->getMessage()); } // Loop over the section fields, and in they are in the desired schema, populate an entry_data // array with the information. This doesn't respect fields allow_multiple setting though, although // I don't even think that's a problem to be honest as that validation should be taking place at the // entry creation level, not when it's being read. foreach ($section->fields as $field) { if (!empty($this->schema) && !in_array($field->{'element-name'}, $this->schema)) { continue; } $entry_data = array(); foreach ($this->data[$field->{'element-name'}] as $key => $data) { if ($data->{$field->fetchDataKey()} != $entry->id) { continue; } $entry_data[] = $data; } $entry->data()->{$field->{'element-name'}} = count($entry_data) == 1 ? current($entry_data) : $entry_data; } return $entry; }
public function render(Register $ParameterOutput) { $result = new XMLDocument(); $root = $result->createElement($this->parameters()->{'root-element'}); try { ## User Filtering if (is_array($this->parameters()->filters) && !empty($this->parameters()->filters)) { $user_ids = NULL; $where_clauses = array(); $query = "SELECT * FROM `tbl_users` WHERE 1 %s ORDER BY `id` ASC"; foreach ($this->parameters()->filters as $field => $value) { if (!is_array($value) && trim($value) == '') { continue; } $value = self::replaceParametersInString($value, $ParameterOutput); if (!is_array($value)) { $value = preg_split('/,\\s*/', $value, -1, PREG_SPLIT_NO_EMPTY); $value = array_map('trim', $value); } $where_clauses[] = sprintf("`%s` IN ('%s')", str_replace('-', '_', $field), implode(',', $value)); } // Should the $where_clauses array be empty, it means there were no valid filters. I.E. they were all empty strings. // If that is the case, we still want Users to get returned, hence the "WHERE 1" part of the SQL to avoid errors. if (!empty($where_clauses)) { $where_clauses = 'AND' . implode(' AND ', $where_clauses); } else { $where_clauses = NULL; } $users = Symphony::Database()->query(sprintf($query, $where_clauses), array(), 'UserResult'); } else { $users = new UserIterator(); } if ($users->length() > 0) { $included_fields = $this->parameters()->{'included-elements'}; foreach ($users as $user) { $xUser = $result->createElement('user', null); $xUser->setAttribute('id', $user->id); foreach ($included_fields as $element) { switch ($element) { case 'name': $xUser->appendChild($result->createElement('name', $user->getFullName())); break; case 'email-address': $xUser->appendChild($result->createElement('email-address', $user->email)); break; case 'username': $xUser->appendChild($result->createElement('username', $user->username)); break; case 'language': if (!is_null($user->language)) { $xUser->appendChild($result->createElement('language', $user->language)); } break; case 'authentication-token': if ($user->isTokenActive()) { $xUser->appendChild($result->createElement('authentication-token', $user->createAuthToken())); } break; case 'default-section': try { $section = Section::loadFromHandle($user->default_section); $default_section = $result->createElement('default-section', $section->name); $default_section->setAttribute('handle', $section->handle); $xUser->appendChild($default_section); } catch (SectionException $error) { // Do nothing, section doesn't exist, but no need to error out about it.. } break; default: break; } } $root->appendChild($xUser); } } else { throw new DataSourceException("No records found."); } } catch (Exception $error) { $root->appendChild($result->createElement('error', General::sanitize($error->getMessage()))); } $result->appendChild($root); return $result; }