public function view() { $sectionManager = new SectionManager(Administration::instance()); $fieldManager = new FieldManager(Administration::instance()); // Fetch sections & populate a dropdown with the available upload fields $section = $sectionManager->fetch($_GET['section']); foreach ($section->fetchFields() as $field) { if (!preg_match(Extension_BulkImporter::$supported_fields['upload'], $field->get('type'))) { continue; } $element = new XMLElement("field", General::sanitize($field->get('label')), array('id' => $field->get('id'), 'type' => $field->get('type'))); $this->_Result->appendChild($element); } // Check to see if any Sections link to this using the Section Associations table $associations = Symphony::Database()->fetch(sprintf("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`child_section_field_id`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_sections_association`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`parent_section_id` = %d\n\t\t\t\t", Symphony::Database()->cleanValue($_GET['section']))); if (is_array($associations) && !empty($associations)) { foreach ($associations as $related_field) { $field = $fieldManager->fetch($related_field['child_section_field_id']); if (!preg_match(Extension_BulkImporter::$supported_fields['section'], $field->get('type'))) { continue; } $element = new XMLElement("section", General::sanitize($field->get('label')), array('id' => $field->get('id'), 'type' => $field->get('type'), 'section' => $sectionManager->fetch($field->get('parent_section'))->get('name'))); $this->_Result->appendChild($element); } } // Check for Subsection Manager if (Symphony::ExtensionManager()->fetchStatus('subsectionmanager') == EXTENSION_ENABLED) { $associations = Symphony::Database()->fetch(sprintf("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`field_id`\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_fields_subsectionmanager`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`subsection_id` = %d\n\t\t\t\t\t", Symphony::Database()->cleanValue($_GET['section']))); if (is_array($associations) && !empty($associations)) { foreach ($associations as $related_field) { $field = $fieldManager->fetch($related_field['field_id']); if (!preg_match(Extension_BulkImporter::$supported_fields['section'], $field->get('type'))) { continue; } $element = new XMLElement("section", General::sanitize($field->get('label')), array('id' => $field->get('id'), 'type' => $field->get('type'), 'section' => $sectionManager->fetch($field->get('parent_section'))->get('name'))); $this->_Result->appendChild($element); } } } // Check for BiLink if (Symphony::ExtensionManager()->fetchStatus('bilinkfield') == EXTENSION_ENABLED) { $associations = Symphony::Database()->fetch(sprintf("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`field_id`\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_fields_bilink`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`linked_section_id` = %d\n\t\t\t\t\t", Symphony::Database()->cleanValue($_GET['section']))); if (is_array($associations) && !empty($associations)) { foreach ($associations as $related_field) { $field = $fieldManager->fetch($related_field['field_id']); if (!preg_match(Extension_BulkImporter::$supported_fields['section'], $field->get('type'))) { continue; } $element = new XMLElement("section", General::sanitize($field->get('label')), array('id' => $field->get('id'), 'type' => $field->get('type'), 'section' => $sectionManager->fetch($field->get('parent_section'))->get('name'))); $this->_Result->appendChild($element); } } } }
public function entrySaved($context) { require_once MANIFEST . '/jit-recipes.php'; require_once MANIFEST . '/jit-precaching.php'; require_once TOOLKIT . '/class.fieldmanager.php'; $fm = new FieldManager(Symphony::Engine()); $section = $context['section']; if (!$section) { require_once TOOLKIT . '/class.sectionmanager.php'; $sm = new SectionManager(Symphony::Engine()); $section = $sm->fetch($context['entry']->get('section_id')); } // iterate over each field in this entry foreach ($context['entry']->getData() as $field_id => $data) { // get the field meta data $field = $fm->fetch($field_id); // iterate over the field => recipe mapping foreach ($cached_recipes as $cached_recipe) { // check a mapping exists for this section/field combination if ($section->get('handle') != $cached_recipe['section']) { continue; } if ($field->get('element_name') != $cached_recipe['field']) { continue; } // iterate over the recipes mapped for this section/field combination foreach ($cached_recipe['recipes'] as $cached_recipe_name) { // get the file name, includes path relative to workspace $file = $data['file']; if (!isset($file) || is_null($file)) { continue; } // trim the filename from path $uploaded_file_path = explode('/', $file); array_pop($uploaded_file_path); // image path relative to workspace if (is_array($uploaded_file_path)) { $uploaded_file_path = implode('/', $uploaded_file_path); } // iterate over all JIT recipes foreach ($recipes as $recipe) { // only process if the recipe has a URL Parameter (name) if (is_null($recipe['url-parameter'])) { continue; } // if not using wildcard, only process specified recipe names if ($cached_recipe_name != '*' && $cached_recipe_name != $recipe['url-parameter']) { continue; } // process the image using the usual JIT URL and get the result $image_data = file_get_contents(URL . '/image/' . $recipe['url-parameter'] . $file); // create a directory structure that matches the JIT URL structure General::realiseDirectory(WORKSPACE . '/image-cache/' . $recipe['url-parameter'] . $uploaded_file_path); // save the image to disk file_put_contents(WORKSPACE . '/image-cache/' . $recipe['url-parameter'] . $file, $image_data); } } } } }
public function view() { $this->addHeaderToPage('Content-Type', 'text/html'); $field_id = $this->_context[0]; $entry_id = $this->_context[1]; $this->_context['entry_id'] = $entry_id; try { $entry = EntryManager::fetch($entry_id); $entry = $entry[0]; if (!is_a($entry, 'Entry')) { $this->_status = 404; return; } $field = FieldManager::fetch($field_id); if (!is_a($field, 'Field')) { $this->_status = 404; return; } $field->set('id', $field_id); $entry_data = $entry->getData(); $data = new XMLElement('field'); $field->displayPublishPanel($data, $entry_data[$field_id]); echo $data->generate(true); exit; $this->_Result->appendChild($data); } catch (Exception $e) { } }
public function getXPath($entry) { $fieldManager = new FieldManager(Symphony::Engine()); $entry_xml = new XMLElement('entry'); $section_id = $entry->get('section_id'); $data = $entry->getData(); $fields = array(); $entry_xml->setAttribute('id', $entry->get('id')); $associated = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated) and !empty($associated)) { foreach ($associated as $section => $count) { $handle = Symphony::Database()->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t"); $entry_xml->setAttribute($handle, (string) $count); } } // Add fields: foreach ($data as $field_id => $values) { if (empty($field_id)) { continue; } $field = $fieldManager->fetch($field_id); $field->appendFormattedElement($entry_xml, $values, false, null); } $xml = new XMLElement('data'); $xml->appendChild($entry_xml); $dom = new DOMDocument(); $dom->strictErrorChecking = false; $dom->loadXML($xml->generate(true)); $xpath = new DOMXPath($dom); if (version_compare(phpversion(), '5.3', '>=')) { $xpath->registerPhpFunctions(); } return $xpath; }
/** * Appends errors generated from fields during the execution of an Event * * @param XMLElement $result * @param array $fields * @param array $errors * @param object $post_values * @throws Exception * @return XMLElement */ public static function appendErrors(XMLElement $result, array $fields, $errors, $post_values) { $result->setAttribute('result', 'error'); $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array('message-id' => EventMessages::ENTRY_ERRORS))); foreach ($errors as $field_id => $message) { $field = FieldManager::fetch($field_id); // Do a little bit of a check for files so that we can correctly show // whether they are 'missing' or 'invalid'. If it's missing, then we // want to remove the data so `__reduceType` will correctly resolve to // missing instead of invalid. // @see https://github.com/symphonists/s3upload_field/issues/17 if (isset($_FILES['fields']['error'][$field->get('element_name')])) { $upload = $_FILES['fields']['error'][$field->get('element_name')]; if ($upload === UPLOAD_ERR_NO_FILE) { unset($fields[$field->get('element_name')]); } } 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'; } $error = self::createError($field, $type, $message); $result->appendChild($error); } if (isset($post_values) && is_object($post_values)) { $result->appendChild($post_values); } return $result; }
public function findAllFields($section_id) { $fieldManager = new FieldManager(Symphony::Engine()); $fields = $fieldManager->fetch(NULL, $section_id, 'ASC', 'sortorder', NULL, NULL, 'AND (type != "fop")'); if (is_array($fields) && !empty($fields)) { foreach ($fields as $field) { $options[] = 'entry/' . $field->get('element_name'); } } return $options; }
/** * This function will return an array of Entry objects given an ID or an array of ID's. * Do not provide `$entry_id` as an array if not specifying the `$section_id`. This function * is commonly passed custom SQL statements through the `$where` and `$join` parameters * that is generated by the fields of this section * * @param integer|array $entry_id * An array of Entry ID's or an Entry ID to return * @param integer $section_id * The ID of the Section that these entries are contained in * @param integer $limit * The limit of entries to return * @param integer $start * The starting offset of the entries to return * @param string $where * Any custom WHERE clauses * @param string $joins * Any custom JOIN's * @param boolean $group * Whether the entries need to be grouped by Entry ID or not * @param boolean $records_only * If this is set to true, an array of Entry objects will be returned * without any basic pagination information. Defaults to false * @param boolean $buildentries * Whether to return an array of entry ID's or Entry objects. Defaults to * true, which will return Entry objects * @param array $element_names * Choose whether to get data from a subset of fields or all fields in a section, * by providing an array of field names. Defaults to null, which will load data * from all fields in a section. */ public function fetch($entry_id = null, $section_id = null, $limit = null, $start = null, $where = null, $joins = null, $group = false, $buildentries = true, $element_names = null) { $sort = null; if (!$entry_id && !$section_id) { return false; } if (!$section_id) { $section_id = $this->fetchEntrySectionID($entry_id); } $section = $this->sectionManager->fetch($section_id); if (!is_object($section)) { return false; } ## SORTING // A single $entry_id doesn't need to be sorted on if (!is_array($entry_id) && !is_null($entry_id) && is_int($entry_id)) { $sort = null; } else { if ($this->_fetchSortDirection == 'RAND') { $sort = 'ORDER BY RAND() '; } else { if ($this->_fetchSortField == 'date') { $sort = 'ORDER BY `e`.`creation_date` ' . $this->_fetchSortDirection; } else { if ($this->_fetchSortField == 'id') { $sort = 'ORDER BY `e`.`id`' . $this->_fetchSortDirection; } else { if ($this->_fetchSortField && ($field = $this->fieldManager->fetch($this->_fetchSortField))) { $field->buildSortingSQL($joins, $where, $sort, $this->_fetchSortDirection); if (!$group) { $group = $field->requiresSQLGrouping(); } } else { if ($section->get('entry_order') && ($field = $this->fieldManager->fetch($section->get('entry_order')))) { $field->buildSortingSQL($joins, $where, $sort, $section->get('entry_order_direction')); if (!$group) { $group = $field->requiresSQLGrouping(); } } else { $sort = 'ORDER BY `e`.`id`' . $this->_fetchSortDirection; } } } } } } if ($entry_id && !is_array($entry_id)) { $entry_id = array($entry_id); } $sql = "\n\t\t\t\tSELECT " . ($group ? 'DISTINCT ' : '') . "`e`.id,\n\t\t\t\t\t\t`e`.section_id, e.`author_id`,\n\t\t\t\t\t\tUNIX_TIMESTAMP(e.`creation_date`) AS `creation_date`\n\t\t\t\tFROM `tbl_entries` AS `e`\n\t\t\t\t{$joins}\n\t\t\t\tWHERE 1\n\t\t\t\t" . ($entry_id ? "AND `e`.`id` IN ('" . implode("', '", $entry_id) . "') " : '') . "\n\t\t\t\t" . ($section_id && !is_null($sort) ? "AND `e`.`section_id` = '{$section_id}' " : '') . "\n\t\t\t\t{$where}\n\t\t\t\t{$sort}\n\t\t\t\t" . ($limit ? 'LIMIT ' . intval($start) . ', ' . intval($limit) : ''); $rows = Symphony::Database()->fetch($sql); return $buildentries && (is_array($rows) && !empty($rows)) ? $this->__buildEntries($rows, $section_id, $element_names) : $rows; }
public function prepareTableValue($data, XMLElement $link = NULL, $entry_id = NULL) { // build this entry fully $entries = EntryManager::fetch($entry_id); if ($entries === false) { return parent::prepareTableValue(NULL, $link, $entry_id); } $entry = reset(EntryManager::fetch($entry_id)); // get the first field inside this tab $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $this->get('parent_section') . "' AND `sortorder` = " . ($this->get('sortorder') + 1) . " ORDER BY `sortorder` LIMIT 1"); if ($field_id === NULL) { return parent::prepareTableValue(NULL, $link, $entry_id); } $field = FieldManager::fetch($field_id); // get the first field's value as a substitude for the tab's return value return $field->prepareTableValue($entry->getData($field_id), $link, $entry_id); }
/** * Appends errors generated from fields during the execution of an Event * * @param XMLElement $result * @param array $fields * @param array $errors * @param object $post_values * @return XMLElement */ public static function appendErrors(XMLElement $result, array $fields, $errors, $post_values) { $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 $result; }
/** * Appends errors generated from fields during the execution of an Event * * @param XMLElement $result * @param array $fields * @param array $errors * @param object $post_values * @throws Exception * @return XMLElement */ public static function appendErrors(XMLElement $result, array $fields, $errors, $post_values) { $result->setAttribute('result', 'error'); $result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array('message-id' => EventMessages::ENTRY_ERRORS))); 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'; } $error = self::createError($field, $type, $message); $result->appendChild($error); } if (isset($post_values) && is_object($post_values)) { $result->appendChild($post_values); } return $result; }
private function get($database, $field_id, $search, $max) { // Get entries if (!empty($search)) { // Get columns $columns = Symphony::Database()->fetchCol('column_name', sprintf("SELECT column_name\n FROM information_schema.columns\n WHERE table_schema = '%s'\n AND table_name = 'tbl_entries_data_%d'\n AND column_name != 'id'\n AND column_name != 'entry_id';", $database, $field_id)); // Build where clauses $where = array(); foreach ($columns as $column) { $where[] = "`{$column}` LIKE '%{$search}%'"; } // Build query $query = sprintf("SELECT * from sym_entries_data_%d WHERE %s%s;", $field_id, implode($where, " OR "), $max); } else { $query = sprintf("SELECT * from sym_entries_data_%d%s;", $field_id, $max); } // Fetch field values $data = Symphony::Database()->fetch($query); if (!empty($data)) { $field = FieldManager::fetch($field_id); $parent_section = SectionManager::fetch($field->get('parent_section')); $parent_section_handle = $parent_section->get('handle'); foreach ($data as $field_data) { $entry_id = $field_data['entry_id']; if ($field instanceof ExportableField && in_array(ExportableField::UNFORMATTED, $field->getExportModes())) { // Get unformatted value $value = $field->prepareExportValue($field_data, ExportableField::UNFORMATTED, $entry_id); } elseif ($field instanceof ExportableField && in_array(ExportableField::VALUE, $field->getExportModes())) { // Get formatted value $value = $field->prepareExportValue($field_data, ExportableField::VALUE, $entry_id); } else { // Get value from parameter pool $value = $field->getParameterPoolValue($field_data, $entry_id); } $this->_Result['entries'][$entry_id]['value'] = $value; $this->_Result['entries'][$entry_id]['section'] = $parent_section_handle; $this->_Result['entries'][$entry_id]['link'] = APPLICATION_URL . '/publish/' . $parent_section_handle . '/edit/' . $entry_id . '/'; } } }
/** * Build element options. * * @param array $association * Association data * @param array $settings * Data Source settings * @param number $section_id * Section ID * @return array * Element options */ private function buildElementOptions($association, $settings, $section_id) { $elements = array(); $label = FieldManager::fetchHandleFromID($association['child_section_field_id']); $fields = FieldManager::fetch(null, $association['parent_section_id']); if (is_array($fields) || $fields instanceof Traversable) { foreach ($fields as $field) { $modes = $field->fetchIncludableElements(); foreach ($modes as $mode) { $value = $association['parent_section_id'] . '|#|' . $association['parent_section_field_id'] . '|#|' . $label . '|#|' . $mode; $selected = false; if ($section_id == $settings['section_id'] && isset($settings[$label])) { if (in_array($mode, $settings[$label]['elements'])) { $selected = true; } } $elements[] = array($value, $selected, $mode); } } } return array('label' => $label, 'data-label' => $section_id, 'options' => $elements); }
public function view() { $handle = General::sanitize($_GET['handle']); $section = General::sanitize($_GET['section']); $options = array(); $filters = array(); if (!empty($handle) && !empty($section)) { $section_id = SectionManager::fetchIDFromHandle($section); $field_id = FieldManager::fetchFieldIDFromElementName($handle, $section_id); $field = FieldManager::fetch($field_id); if (!empty($field) && $field->canPublishFilter() === true) { if (method_exists($field, 'getToggleStates')) { $options = $field->getToggleStates(); } elseif (method_exists($field, 'findAllTags')) { $options = $field->findAllTags(); } } } foreach ($options as $value => $data) { $filters[] = array('value' => $value ? $value : $data, 'text' => $data ? $data : $value); } $this->_Result['filters'] = $filters; }
public function view() { $entry_id = General::sanitize($_GET['entry_id']); $field_ids = explode(',', General::sanitize($_GET['field_id'])); $parent_section_id = EntryManager::fetchEntrySectionID($entry_id); if ($parent_section_id) { $parent_section = SectionManager::fetch($parent_section_id); $parent_section_handle = $parent_section->get('handle'); // Fetch entry $value = ''; if (!empty($field_ids[0])) { $entry = EntryManager::fetch($entry_id); foreach ($field_ids as $field_id) { $field_data = $entry[0]->getData($field_id); if (!empty($field_data)) { $field = FieldManager::fetch($field_id); if ($field instanceof ExportableField && in_array(ExportableField::UNFORMATTED, $field->getExportModes())) { // Get unformatted value $value = $field->prepareExportValue($field_data, ExportableField::UNFORMATTED, $entry_id); } elseif ($field instanceof ExportableField && in_array(ExportableField::VALUE, $field->getExportModes())) { // Get formatted value $value = $field->prepareExportValue($field_data, ExportableField::VALUE, $entry_id); } else { // Get value from parameter pool $value = $field->getParameterPoolValue($field_data, $entry_id); } } } } // Set data $this->_Result['entry']['value'] = $value; $this->_Result['entry']['section'] = $parent_section_handle; $this->_Result['entry']['link'] = APPLICATION_URL . '/publish/' . $parent_section_handle . '/edit/' . $entry_id . '/'; } // Return results return $this->_Result; }
public function appendScriptToHead($context) { $page_callback = Administration::instance()->getPageCallback(); $page_callback = $page_callback['context']; if (isset($page_callback['section_handle']) && $page_callback['page'] == 'index') { // find sort settings for this section (sort field ID and direction) $section_id = SectionManager::fetchIDFromHandle($page_callback['section_handle']); if (!$section_id) { return; } $section = SectionManager::fetch(SectionManager::fetchIDFromHandle($page_callback['section_handle'])); // we only want a valid entry order field and ascending order only if ($section->getSortingOrder() !== 'asc' || !is_numeric($section->getSortingField())) { return; } $field = FieldManager::fetch($section->getSortingField()); if ($field->get('type') !== 'order_entries') { return; } Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('order-entries', " . json_encode(array('id' => $field->get('id'), 'force-sort' => $field->get('force_sort'))) . ");", array('type' => 'text/javascript')), time()); Administration::instance()->Page->addScriptToHead(URL . '/extensions/order_entries/assets/order_entries.publish.js', time()); Symphony::Configuration()->set("pagination_maximum_rows", 99999, "symphony"); } }
public function execute(array &$param_pool) { $result = new XMLElement($this->dsParamROOTELEMENT); $this->_param_pool = $param_pool; $where = NULL; $joins = NULL; $group = false; include_once TOOLKIT . '/class.entrymanager.php'; if (!($section = SectionManager::fetch((int) $this->getSource()))) { $about = $this->about(); trigger_error(__('The section associated with the data source %s could not be found.', array('<code>' . $about['name'] . '</code>')), E_USER_ERROR); } $sectioninfo = new XMLElement('section', General::sanitize($section->get('name')), array('id' => $section->get('id'), 'handle' => $section->get('handle'))); if ($this->_force_empty_result == true) { $this->_force_empty_result = false; //this is so the section info element doesn't disappear. $result = $this->emptyXMLSet(); $result->prependChild($sectioninfo); return; } if (is_array($this->dsParamINCLUDEDELEMENTS)) { $include_pagination_element = in_array('system:pagination', $this->dsParamINCLUDEDELEMENTS); } else { $this->dsParamINCLUDEDELEMENTS = array(); } if (isset($this->dsParamPARAMOUTPUT) && !is_array($this->dsParamPARAMOUTPUT)) { $this->dsParamPARAMOUTPUT = array($this->dsParamPARAMOUTPUT); } $this->_can_process_system_parameters = $this->canProcessSystemParameters(); if (!isset($this->dsParamPAGINATERESULTS)) { $this->dsParamPAGINATERESULTS = 'yes'; } // Process Filters $this->processFilters($where, $joins, $group); // Process Sorting if ($this->dsParamSORT == 'system:id') { EntryManager::setFetchSorting('id', $this->dsParamORDER); } else { if ($this->dsParamSORT == 'system:date') { EntryManager::setFetchSorting('date', $this->dsParamORDER); } else { EntryManager::setFetchSorting(FieldManager::fetchFieldIDFromElementName($this->dsParamSORT, $this->getSource()), $this->dsParamORDER); } } // combine `INCLUDEDELEMENTS`, `PARAMOUTPUT` and `GROUP` into an // array of field handles to optimise the `EntryManager` queries $datasource_schema = $this->dsParamINCLUDEDELEMENTS; if (is_array($this->dsParamPARAMOUTPUT)) { $datasource_schema = array_merge($datasource_schema, $this->dsParamPARAMOUTPUT); } if ($this->dsParamGROUP) { $datasource_schema[] = FieldManager::fetchHandleFromID($this->dsParamGROUP); } $entries = EntryManager::fetchByPage($this->dsParamPAGINATERESULTS == 'yes' && $this->dsParamSTARTPAGE > 0 ? $this->dsParamSTARTPAGE : 1, $this->getSource(), $this->dsParamPAGINATERESULTS == 'yes' && $this->dsParamLIMIT >= 0 ? $this->dsParamLIMIT : NULL, $where, $joins, $group, !$include_pagination_element ? true : false, true, array_unique($datasource_schema)); /** * Immediately after building entries allow modification of the Data Source entry list * * @delegate DataSourceEntriesBuilt * @param string $context * '/frontend/' * @param Datasource $datasource * @param array $entries * @param array $filters */ Symphony::ExtensionManager()->notifyMembers('DataSourceEntriesBuilt', '/frontend/', array('datasource' => &$this, 'entries' => &$entries, 'filters' => $this->dsParamFILTERS)); if (($entries['total-entries'] <= 0 || $include_pagination_element === true) && (!is_array($entries['records']) || empty($entries['records'])) || $this->dsParamSTARTPAGE == '0') { if ($this->dsParamREDIRECTONEMPTY == 'yes') { throw new FrontendPageNotFoundException(); } $this->_force_empty_result = false; $result = $this->emptyXMLSet(); $result->prependChild($sectioninfo); if ($include_pagination_element) { $pagination_element = General::buildPaginationElement(); if ($pagination_element instanceof XMLElement && $result instanceof XMLElement) { $result->prependChild($pagination_element); } } } else { if (!$this->_param_output_only) { $result->appendChild($sectioninfo); if ($include_pagination_element) { $t = $this->dsParamPAGINATERESULTS == 'yes' && isset($this->dsParamLIMIT) && $this->dsParamLIMIT >= 0 ? $this->dsParamLIMIT : $entries['total-entries']; $pagination_element = General::buildPaginationElement($entries['total-entries'], $entries['total-pages'], $t, $this->dsParamPAGINATERESULTS == 'yes' && $this->dsParamSTARTPAGE > 0 ? $this->dsParamSTARTPAGE : 1); if ($pagination_element instanceof XMLElement && $result instanceof XMLElement) { $result->prependChild($pagination_element); } } } // If this datasource has a Limit greater than 0 or the Limit is not set if (!isset($this->dsParamLIMIT) || $this->dsParamLIMIT > 0) { if (!isset($this->dsParamASSOCIATEDENTRYCOUNTS) || $this->dsParamASSOCIATEDENTRYCOUNTS == 'yes') { $this->_associated_sections = $section->fetchAssociatedSections(); } // If the datasource require's GROUPING if (isset($this->dsParamGROUP)) { self::$_fieldPool[$this->dsParamGROUP] =& FieldManager::fetch($this->dsParamGROUP); $groups = self::$_fieldPool[$this->dsParamGROUP]->groupRecords($entries['records']); foreach ($groups as $element => $group) { foreach ($group as $g) { $result->appendChild($this->processRecordGroup($element, $g)); } } } else { if (isset($entries['records'][0])) { $data = $entries['records'][0]->getData(); $pool = FieldManager::fetch(array_keys($data)); self::$_fieldPool += $pool; } foreach ($entries['records'] as $entry) { $xEntry = $this->processEntry($entry); if ($xEntry instanceof XMLElement) { $result->appendChild($xEntry); } } } } } $param_pool = $this->_param_pool; return $result; }
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}&"; } $link = preg_replace("/&\$/", '', $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 – %2$s – %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); } }
function render() { $this->setPageType('form'); $fields = array(); // If we're editing, make sure the item exists if ($this->_context[0]) { if (!($doc_id = $this->_context[0])) { redirect(URL . '/symphony/extension/documenter/manage'); } $existing = Symphony::Database()->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\td.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_documentation` AS d\n\t\t\t\t\tWHERE\n\t\t\t\t\t\td.id = '{$doc_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { $this->_Parent->customError(E_USER_ERROR, __('Documentation Item not found'), __('The documentation item you requested to edit does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found')); } } // Build the status message if (isset($this->_context[1])) { if ($this->_context[1] == 'saved') { $this->pageAlert(__('Documentation Item updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), URL . '/symphony/extension/documenter/new/', URL . '/symphony/extension/documenter/')), Alert::SUCCESS); } else { $this->pageAlert(__('Documentation Item created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), URL . '/symphony/extension/documenter/new/', URL . '/symphony/extension/documenter/')), Alert::SUCCESS); } } // Find values if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { if ($this->_context[0]) { $fields = $existing; $fields['content'] = General::sanitize($fields['content']); } } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } // Start building the page $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Documentation'), $title))); $this->appendSubheading($title ? $title : __('Untitled')); // Start building the fieldsets $this->Form->setAttribute('class', 'two columns'); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary column'); // Title text input $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = Widget::Error($label, $this->_errors['title']); } $fieldset->appendChild($label); // Content textarea $label = Widget::Label(__('Content')); $content = Widget::Textarea('fields[content]', 30, 80, $fields['content']); if (Symphony::Configuration()->get('text-formatter', 'documentation') != 'none') { $content->setAttribute('class', Symphony::Configuration()->get('text-formatter', 'documentation')); } $label->appendChild($content); $fieldset->appendChild(isset($this->_errors['content']) ? Widget::Error($label, $this->_errors['content']) : $label); $fieldset->appendChild(Widget::Input('autogenerate', __('Auto-generate content according to selected section(s)'), 'button', array('class' => 'button'))); $this->Form->appendChild($fieldset); // Pages multi-select $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'secondary column'); $label = Widget::Label(__('Pages')); if (!is_array($fields['pages'])) { $pages_array = explode(',', $fields['pages']); } else { $pages_array = $fields['pages']; } $options = array(); // Generate a list of sectionField-data for auto-generation of documentation: $arr = array(); // Build the options list using the navigation array foreach (Administration::instance()->Page->_navigation as $menu) { $items = array(); foreach ($menu['children'] as $item) { $items[] = array($item['link'], in_array($item['link'], $pages_array), $menu['name'] . " > " . $item['name']); // If it's a section, add New and Edit pages // NOTE: This will likely break when extensions add custom nav groups if ($menu['name'] != 'Blueprints' and $menu['name'] != 'System') { $items[] = array($item['link'] . 'new/', in_array($item['link'] . 'new/', $pages_array), $menu['name'] . " > " . $item['name'] . " New"); $items[] = array($item['link'] . 'edit/', in_array($item['link'] . 'edit/', $pages_array), $menu['name'] . " > " . $item['name'] . " Edit"); } // Generate a list of sectionField-data for auto-generation of documentation: if ($item['type'] == 'section') { $arr2 = array('name' => $item['name'], 'link' => $item['link'], 'items' => array()); $fields = FieldManager::fetch(null, $item['section']['id']); foreach ($fields as $field) { /* @var $field Field */ $arr2['items'][] = array('label' => $field->get('label')); } $arr[] = $arr2; } } $options[] = array('label' => $menu['name'], 'options' => $items); } Administration::instance()->Page->addElementToHead(new XMLElement('script', 'var sectionFields = ' . json_encode($arr) . ';', array('type' => 'text/javascript'))); $label->appendChild(Widget::Select('fields[pages][]', $options, array('multiple' => 'multiple', 'id' => 'documenter-pagelist'))); if (isset($this->_errors['pages'])) { $label = Widget::Error($label, $this->_errors['pages']); } $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Form actions $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] ? __('Save Changes') : __('Document It'), 'submit', array('accesskey' => 's'))); if ($this->_context[0]) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this template'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function viewForm() { $this->setPageType('form'); $this->appendSubheading(__('Roles')); // Create a group for the essential settings (for now, this is only the role name): $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Role Name')); // The name input field: $label->appendChild(Widget::Input('name', $this->getValue('name'))); $div->appendChild($label); $group->appendChild($div); $this->Form->appendChild($group); // Create a group for the table (this is where the magic happens): $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Sections'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); // The main table: // Set the table head: $tableHead = array(array(__('Name'), null, array('class' => 'name')), array('<span rel="visible">' . __('Visible') . '</span>', null, array('class' => 'center')), array('<span rel="create">' . __('Create') . '</span>', null, array('class' => 'center')), array('<span rel="edit">' . __('Edit') . '</span>', null, array('class' => 'center')), array('<span rel="delete">' . __('Delete') . '</span>', null, array('class' => 'center')), array(__('Fields'), null, array('class' => 'center')), array(__('Entries'), null, array('class' => 'center'))); // Set the table body: $tableBody = array(); // Get the sections: $sections = SectionManager::fetch(); $i = 0; foreach ($sections as $section) { $id = $section->get('id'); $i++; $classArray = $i % 2 == 0 ? array('class' => 'even') : array(); // Create a row for each section, with a rowspan: $row = new XMLElement('tr', null, $classArray); $row->appendChild(new XMLElement('td', $section->get('name'), array('rowspan' => 2))); $row->appendChild($this->tdCheckBox('section[' . $id . '][visible]', $this->checkSection($id, 'visible') == 1)); $row->appendChild($this->tdCheckBox('section[' . $id . '][create]', $this->checkSection($id, 'create') == 1)); $row->appendChild($this->tdCheckBox('section[' . $id . '][edit]', $this->checkSection($id, 'edit') == 1)); $row->appendChild($this->tdCheckBox('section[' . $id . '][delete]', $this->checkSection($id, 'delete') == 1)); $row->appendChild(new XMLElement('td', '<a href="#" rel="fields">Edit</a>', array('class' => 'checkbox'))); $row->appendChild(new XMLElement('td', '<a href="#" rel="entries">Edit</a>', array('class' => 'checkbox'))); $tableBody[] = $row; // Extra row for the fields and entries options: $row = new XMLElement('tr'); $td = new XMLElement('td', null, array('colspan' => 6, 'class' => 'options')); $divFields = new XMLElement('div', null, array('class' => 'sub fields')); $divFields->appendChild(new XMLElement('h3', __('Fields'))); // Put all the fields in here: $thead = array(array(__('Name'), null, array('class' => 'name')), array(__('Hide'))); $tBody = array(); // Get the fields: $fields = FieldManager::fetch(null, $id); if ($fields != false) { foreach ($fields as $field) { $id_field = $field->get('id'); $required = $field->get('required'); $fieldRow = new XMLElement('tr'); $fieldRow->appendChild(new XMLElement('td', $field->get('label'))); if ($required == 'no') { $fieldRow->appendChild($this->tdCheckBox('section[' . $id . '][fields][' . $id_field . '][hidden]', $this->checkFields($id_field, 'hidden') == 1)); } else { $fieldRow->appendChild(new XMLElement('td', __('required') . ' *', array('class' => 'required'))); } $tBody[] = $fieldRow; } } $divFields->appendChild(Widget::Table(Widget::TableHead($thead), null, Widget::TableBody($tBody))); $divFields->appendChild(new XMLElement('p', '* ' . __('You cannot hide required fields'), array('class' => 'info'))); $td->appendChild($divFields); // Entry options: $divEntries = new XMLElement('div', null, array('class' => 'sub entries')); $label = Widget::Label(); // check if this checkbox is checked: $attributes = $this->checkSection($id, 'own_entries') == 1 ? array('checked' => 'checked') : null; $input = Widget::Input('section[' . $id . '][own_entries]', null, 'checkbox', $attributes); $label->setValue($input->generate() . ' ' . __('Author can view/edit own entries only')); $divEntries->appendChild($label); $label = Widget::Label(); $attributes = $this->checkSection($id, 'use_filter') == 1 ? array('checked' => 'checked') : null; $input = Widget::Input('section[' . $id . '][use_filter]', null, 'checkbox', $attributes); $label->setValue($input->generate() . ' ' . __('Use filter')); $divEntries->appendChild($label); $filterRule = new XMLElement('div', null, array('class' => 'filter')); $label = Widget::Label(__('Filter type')); $rule = explode(':', $this->_data['sections'][$id]['filter_rule']); $options = array(array('show', $rule[0] == 'show', 'show'), array('hide', $rule[0] == 'hide', 'hide')); $label->appendChild(Widget::Select('section[' . $id . '][filter_rule_type]', $options)); $filterRule->appendChild($label); $label = Widget::Label(__('ID\'s')); $rule = isset($rule[1]) ? $rule[1] : ''; $label->appendChild(Widget::Input('section[' . $id . '][filter_rule]', $rule)); $filterRule->appendChild($label); $filterRule->appendChild(new XMLElement('p', __('Enter a list of comma-seperated ID\'s. Define ranges with a hyphen.<br />Example: <code>2,3,6-11,13</code>'), array('class' => 'info'))); $divEntries->appendChild($filterRule); $td->appendChild($divEntries); $row->appendChild($td); $tableBody[] = $row; } // Create the table element: $table = Widget::Table(Widget::TableHead($tableHead), null, Widget::TableBody($tableBody), 'author_roles'); $div->appendChild($table); $group->appendChild($div); $this->Form->appendChild($group); // Add custom elements: $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Custom links'))); $label = new XMLElement('label', __('Hide custom menu elements')); $label->appendChild(Widget::Textarea('custom_elements', 5, 15, $this->_data['custom_elements'])); $label->appendChild(new XMLElement('p', __('Enter the links of custom menu elements to exclude these links from the main navigation. You can use this to exclude extensions-driven menu-items like Dashboard or Search Index for example. Give one link per line, and enter the URL after the <code>/symphony/</code>-part. For example: <code>/extension/dashboard/index/</code>.'), array('class' => 'help'))); $group->appendChild($label); $this->Form->appendChild($group); // Add the actions: $actions = new XMLElement('div'); $actions->setAttribute('class', 'actions'); if ($this->_id_role == 0) { $buttonText = __('Create Role'); } else { $buttonText = __('Save Changes'); } // Add the ID: $actions->appendChild(Widget::Input('id_role', (string) $this->_id_role, 'hidden')); $actions->appendChild(Widget::Input('save', $buttonText, 'submit')); $this->Form->appendChild($actions); }
public function __viewEdit($new = false) { $this->setPageType('form'); $this->setTitle(sprintf(__("Symphony - Newsletter Recipient Groups - %s", array(), false), ucfirst($this->_context[1]))); $errors = new XMLElement('errors'); $context = new XMLElement('context'); General::array_to_xml($context, $this->_context); $this->_XML->appendChild($context); // Fix for 2.4 and XSRF if (Symphony::Configuration()->get("enable_xsrf", "symphony") == "yes" && class_exists('XSRF')) { $xsrf_input = new XMLElement('xsrf_input'); $xsrf_input->appendChild(XSRF::formToken()); $this->_XML->appendChild($xsrf_input); } $section_xml = new XMLElement('sections'); $sectionManager = new SectionManager($this); $sections = $sectionManager->fetch(); foreach ($sections as $section) { $entry = new XMLElement('entry'); General::array_to_xml($entry, $section->get()); foreach ($section->fetchFields() as $field) { $field_xml = new XMLElement('field'); General::array_to_xml($field_xml, $field->get()); $filter_html = new XMLElement('filter_html'); $field->displayDatasourceFilterPanel($filter_html, NULL, $errors, $section->get('id')); $field_xml->appendChild($filter_html); $field_elements = new XMLElement('elements'); General::array_to_xml($field_elements, $field->fetchIncludableElements()); $field_xml->appendChild($field_elements); $entry->appendChild($field_xml); } $section_xml->appendChild($entry); } $this->_XML->appendChild($section_xml); $title = __('New Group'); $breadcrumbs = array(Widget::Anchor(__('Email Newsletter Recipients'), SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups/')); $recipientgroups = new XMLElement('recipientgroups'); if ($this->_context[2] == 'saved' || $this->_context[3] == 'saved') { $this->pageAlert(__(__('Email Recipient updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Recipient Groups</a>'), array(Widget::Time()->generate(), SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups/new/', SYMPHONY_URL . '/extension/email_newsletter_manager/recipientgroups/')), Alert::SUCCESS); } if ($new == false) { /* TODO add POST values to XML */ $group = RecipientgroupManager::create($this->_context[1]); if (is_object($group)) { $entry = new XMLElement('entry'); $properties = $group->getProperties(); $about = $group->about(); $title = $about['name']; General::array_to_xml($entry, $about); $source = new XMLElement('source', $properties['source']); $entry->appendChild($source); // Section Only if (is_numeric($properties['source'])) { $fields = new XMLElement('fields'); $email = new XMLElement('email', $properties['email']); $fields->appendChild($email); $name = new XMLElement('name'); General::array_to_xml($name, $properties['name']); $fields->appendChild($name); $entry->appendChild($fields); } // Hack to make sure filter data is preserved in the UI when there is an error in the form. // For next versions: always do the local/user differentiation in php, rather than xslt. // This will make the xslt cleaner and easier to understand and debug. if (!empty($_POST['fields'])) { $properties['filters'] = $_POST['fields']['filter'][0]; } if (!empty($properties['filters'])) { $filters = new XMLElement('filters'); foreach ($properties['filters'] as $filter => $val) { // Section and Author if ($filter == 'id') { $title = new XMLElement('h4', 'System ID'); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $properties['source'] . '][id]', General::sanitize($val))); $filter_entry = new XMLElement('entry', NULL, array('id' => 'id', 'data-type' => 'id')); $filter_entry->appendChild($title); $filter_entry->appendChild($label); $filters->appendChild($filter_entry); } if ($filter == 'system:date') { $title = new XMLElement('h4', 'System Date'); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $properties['source'] . '][system:date]', General::sanitize($val))); $filter_entry = new XMLElement('entry', NULL, array('id' => 'id', 'data-type' => 'system:date')); $filter_entry->appendChild($title); $filter_entry->appendChild($label); $filters->appendChild($filter_entry); } // Section Only if (is_numeric($properties['source'])) { $section = SectionManager::fetch($properties['source']); if (is_object($section)) { $section_fields = $section->fetchFields(); foreach ($section_fields as $field) { $field_ids[] = $field->get('id'); } // only add filters to the duplicator if the field id // belongs to the current section if (is_numeric($filter) && in_array($filter, $field_ids)) { $filter_obj = FieldManager::fetch($filter); if (is_object($filter_obj)) { $filter_entry = new XMLElement('entry', NULL, array('id' => $filter, 'data-type' => FieldManager::fetchHandleFromID($filter))); $filter_obj->displayDatasourceFilterPanel($filter_entry, $val, $errors, is_numeric($properties['source']) ? $properties['source'] : 1); $filters->appendChild($filter_entry); } } } } // Author only if ($properties['source'] == 'authors') { $filter_names = array('username' => 'Username', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'email' => 'Email Address', 'user_type' => 'User Type'); if (in_array($filter, array_keys($filter_names))) { $title = new XMLElement('h4', $filter_names[$filter]); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $properties['source'] . '][username]', General::sanitize($val))); $filter_entry = new XMLElement('entry', NULL, array('id' => 'id', 'data-type' => 'username')); $filter_entry->appendChild($title); $filter_entry->appendChild($label); $filters->appendChild($filter_entry); } } } $entry->appendChild($filters); $title = $about['name']; } if ($properties['source'] == 'static_recipients') { $entry->appendChild(new XMLElement('static_recipients', '<![CDATA[' . $group->recipients . ']]>')); } $recipientgroups->appendChild($entry); $this->_XML->appendChild($recipientgroups); } else { Administration::instance()->errorPageNotFound(); } } $this->insertBreadcrumbs($breadcrumbs); $this->appendSubheading($title); }
/** * Append presets * @param $context */ public function appendPresets($context) { Symphony::Engine()->Page->addScriptToHead(URL . '/extensions/ckeditor/assets/preferences.js', 4676); $wrapper = $context['wrapper']; $fieldset = new XMLElement('fieldset', '', array('class' => 'settings')); $fieldset->appendChild(new XMLElement('legend', __('CKEditor File Browser'))); $sectionManager = new SectionManager($this); $sections = $sectionManager->fetch(); // Check which sections are allowed: $data = Symphony::Configuration()->get('sections', 'ckeditor'); $checkedSections = $data != false ? explode(',', $data) : array(); // If there are no sections found: if ($sections) { $options = array(); foreach ($sections as $section) { $options[] = array($section->get('id'), in_array($section->get('id'), $checkedSections), $section->get('name')); } $label = Widget::Label(__('Permitted sections for the file browser:')); $label->appendChild(Widget::Select('ckeditor_sections[]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); } // Link templates for CKEditor: $sections = SectionManager::fetch(); $dbpages = PageManager::fetch(); $pages = array(); // Filter out the ck_hide: foreach ($dbpages as $page) { $types = PageManager::fetchPageTypes($page['id']); if (!in_array('ck_hide', $types)) { $pages[] = $page; } } // Adjust page title: foreach ($pages as &$_page) { $p = $_page; $title = $_page['title']; while (!is_null($p['parent'])) { $p = PageManager::fetch(false, array(), array('id' => $p['parent'])); $title = $p['title'] . ' : ' . $title; } $_page['title'] = $title; } // Sort the array: $titles = array(); foreach ($pages as $key => $row) { $titles[$key] = strtolower($row['title']); } array_multisort($titles, SORT_ASC, $pages); $this->sections = array(); foreach ($sections as $s) { $a = array('id' => $s->get('id'), 'name' => $s->get('name'), 'fields' => array()); $fields = FieldManager::fetch(null, $s->get('id')); foreach ($fields as $field) { // For now, only allow fields of the type 'input' to be used as a handle: if ($field->get('type') == 'input') { $a['fields'][] = array('id' => $field->get('id'), 'label' => $field->get('label'), 'element_name' => $field->get('element_name')); } } $this->sections[] = $a; } $fieldset->appendChild(new XMLElement('p', __('Link templates:'), array('class' => 'label'))); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'ckeditor-duplicator'); $templates = Symphony::Database()->fetch('SELECT * FROM `tbl_ckeditor_link_templates`;'); if (!is_array($pages)) { $pages = array($pages); } foreach ($pages as $page) { foreach ($templates as $template) { if ($template['page_id'] != $page['id']) { continue; } $duplicator = $this->__buildDuplicatorItem($page, $template); $ol->appendChild($duplicator); } $duplicator = $this->__buildDuplicatorItem($page, NULL); $ol->appendChild($duplicator); } $fieldset->appendChild($ol); $wrapper->appendChild($fieldset); }
public static function update_102() { $tbl = self::FIELD_TBL_NAME; $sql = "\n\t\t\t\tALTER TABLE `{$tbl}`\n\t\t\t\t\tADD COLUMN `allow_edit` enum('yes','no') NOT NULL COLLATE utf8_unicode_ci DEFAULT 'yes',\n\t\t\t\t\tADD COLUMN `allow_new` enum('yes','no') NOT NULL COLLATE utf8_unicode_ci DEFAULT 'yes',\n\t\t\t\t\tADD COLUMN `allow_link` enum('yes','no') NOT NULL COLLATE utf8_unicode_ci DEFAULT 'yes'\n\t\t\t\t\tAFTER `max_entries`\n\t\t\t"; $addColumns = Symphony::Database()->query($sql); if (!$addColumns) { return false; } $fields = FieldManager::fetch(null, null, null, 'id', 'entry_relationship'); if (!empty($fields) && is_array($fields)) { foreach ($fields as $fieldId => $field) { $sql = "ALTER TABLE `tbl_entries_data_{$fieldId}` MODIFY `entries` TEXT"; if (!Symphony::Database()->query($sql)) { throw new Exception(__('Could not update table `tbl_entries_data_%s`.', array($fieldId))); } } } return true; }
/** * Entries may link to other Entries through fields. This function will return the * number of entries that are associated with the current entry as an associative * array. If there are no associated entries, null will be returned. * * @param array $associated_sections * An associative array of sections to return the Entry counts from. Defaults to * null, which will fetch all the associations of this Entry. * @return array * An associative array with the key being the associated Section's ID and the * value being the number of entries associated with this Entry. */ public function fetchAllAssociatedEntryCounts($associated_sections = null) { if (is_null($this->get('section_id'))) { return null; } if (is_null($associated_sections)) { $section = SectionManager::fetch($this->get('section_id')); $associated_sections = $section->fetchAssociatedSections(); } if (!is_array($associated_sections) || empty($associated_sections)) { return null; } $counts = array(); foreach ($associated_sections as $as) { $field = FieldManager::fetch($as['child_section_field_id']); $parent_section_field_id = $as['parent_section_field_id']; $search_value = null; if (!is_null($parent_section_field_id)) { $search_value = $field->fetchAssociatedEntrySearchValue($this->getData($as['parent_section_field_id']), $as['parent_section_field_id'], $this->get('id')); } else { $search_value = $this->get('id'); } $counts[$as['child_section_id']] = $field->fetchAssociatedEntryCount($search_value); } return $counts; }
public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL) { $entry_xml = new XMLElement('entry'); $data = $entry->getData(); $fields = array(); $entry_xml->setAttribute('id', $entry->get('id')); //Add date created and edited values $date = new XMLElement('system-date'); $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created')); $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified')); $entry_xml->appendChild($date); //Reflect Workspace and Siteroot params $workspace = new XMLElement('workspace', URL . '/workspace'); $root = new XMLElement('root', URL); // Add associated entry counts if ($fetch_associated_counts == 'yes') { $associated = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated) and !empty($associated)) { foreach ($associated as $section_id => $count) { $section = SectionManager::fetch($section_id); if ($section instanceof Section === false) { continue; } $entry_xml->setAttribute($section->get('handle'), (string) $count); } } } // Add fields: foreach ($data as $field_id => $values) { if (empty($field_id)) { continue; } $field = FieldManager::fetch($field_id); $field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id')); } $xml = new XMLElement('data'); $xml->appendChild($entry_xml); $xml->appendChild($workspace); $xml->appendChild($root); // Build some context $section = SectionManager::fetch($entry->get('section_id')); $params = new XMLElement('params'); $params->appendChild(new XMLElement('section-handle', $section->get('handle'))); $params->appendChild(new XMLElement('entry-id', $entry->get('id'))); $xml->prependChild($params); $dom = new DOMDocument(); $dom->strictErrorChecking = false; $dom->loadXML($xml->generate(true)); if (!empty($XSLTfilename)) { $XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename); if (file_exists($XSLTfilename)) { $XSLProc = new XsltProcessor(); $xslt = new DomDocument(); $xslt->load($XSLTfilename); $XSLProc->importStyleSheet($xslt); // Set some context $XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id'))); $temp = $XSLProc->transformToDoc($dom); if ($temp instanceof DOMDocument) { $dom = $temp; } } } $xpath = new DOMXPath($dom); if (version_compare(phpversion(), '5.3', '>=')) { $xpath->registerPhpFunctions(); } return $xpath; }
public function __viewEdit() { $section_id = $this->_context[1]; $sectionManager = new SectionManager($this->_Parent); if (!($section = $sectionManager->fetch($section_id))) { $this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for could not be found.'), false, true); } $meta = $section->get(); $fieldManager = new FieldManager($this->_Parent); $types = array(); $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Section updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Sections</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/sections/new/', URL . '/symphony/blueprints/sections/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Section created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Sections</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/sections/new/', URL . '/symphony/blueprints/sections/')), Alert::SUCCESS); break; } } if (isset($_POST['fields'])) { $fields = array(); if (is_array($_POST['fields']) && !empty($_POST['fields'])) { foreach ($_POST['fields'] as $position => $data) { if ($fields[$position] = $fieldManager->create($data['type'])) { $fields[$position]->setArray($data); $fields[$position]->set('sortorder', $position); } } } } else { $fields = $fieldManager->fetch(NULL, $section_id); } $meta['subsection'] = $meta['subsection'] == 'yes' ? 1 : 0; $meta['entry_order'] = isset($meta['entry_order']) ? $meta['entry_order'] : 'date'; if (isset($_POST['meta'])) { $meta = $_POST['meta']; $meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no'; if ($meta['name'] == '') { $meta['name'] = $section->get('name'); } } $this->setPageType('form'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), __('Sections'), $meta['name']))); $this->appendSubheading($meta['name']); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div', NULL, array('class' => 'group')); $namediv = new XMLElement('div', NULL); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('meta[name]', $meta['name'])); if (isset($this->_errors['name'])) { $namediv->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $namediv->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('meta[hidden]', 'yes', 'checkbox', $meta['hidden'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Hide this section from the Publish menu', array($input->generate(false)))); $namediv->appendChild($label); $div->appendChild($namediv); $navgroupdiv = new XMLElement('div', NULL); $sectionManager = new SectionManager($this->_Parent); $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder'); $label = Widget::Label(__('Navigation Group') . ' <i>' . __('Choose only one. Created if does not exist') . '</i>'); $label->appendChild(Widget::Input('meta[navigation_group]', $meta['navigation_group'])); if (isset($this->_errors['navigation_group'])) { $navgroupdiv->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['navigation_group'])); } else { $navgroupdiv->appendChild($label); } if (is_array($sections) && !empty($sections)) { $ul = new XMLElement('ul', NULL, array('class' => 'tags singular')); $groups = array(); foreach ($sections as $s) { if (in_array($s->get('navigation_group'), $groups)) { continue; } $ul->appendChild(new XMLElement('li', $s->get('navigation_group'))); $groups[] = $s->get('navigation_group'); } $navgroupdiv->appendChild($ul); } $div->appendChild($navgroupdiv); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Fields'))); $div = new XMLElement('div'); $h3 = new XMLElement('h3', __('Fields')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $ol = new XMLElement('ol'); $ol->setAttribute('id', 'fields-duplicator'); if (is_array($fields) && !empty($fields)) { foreach ($fields as $position => $field) { $wrapper = new XMLElement('li'); $field->set('sortorder', $position); $field->displaySettingsPanel($wrapper, isset($this->_errors[$position]) ? $this->_errors[$position] : NULL); $ol->appendChild($wrapper); } } foreach ($fieldManager->fetchTypes() as $type) { if ($type = $fieldManager->create($type)) { array_push($types, $type); } } uasort($types, create_function('$a, $b', 'return strnatcasecmp($a->_name, $b->_name);')); foreach ($types as $type) { $defaults = array(); $type->findDefaults($defaults); $type->setArray($defaults); $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'template'); $type->set('sortorder', '-1'); $type->displaySettingsPanel($wrapper); $ol->appendChild($wrapper); } $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $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 section'), 'type' => 'submit')); $div->appendChild($button); $this->Form->appendChild($div); }
private function appendEntryXML(&$wrapper, $entry) { $section_id = $entry->get('section_id'); $data = $entry->getData(); $fields = array(); $wrapper->setAttribute('id', $entry->get('id')); $associated = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated) and !empty($associated)) { foreach ($associated as $section => $count) { $handle = Symphony::Database()->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t"); $wrapper->setAttribute($handle, (string) $count); } } // Add fields: foreach ($data as $field_id => $values) { if (empty($field_id)) { continue; } $field = FieldManager::fetch($field_id); $field->appendFormattedElement($wrapper, $values, false, null); } }
/** * Returns an array of all the fields that can be toggled. This function * is used to help build the With Selected drop downs on the Publish * Index pages * * @param string $location * The location of the fields in the entry creator, whether they are * 'main' or 'sidebar' * @return array */ public function fetchToggleableFields($location = null) { return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__TOGGLEABLE_ONLY__); }
/** * Prepare a Drawer to visualize section associations * * @param Section $section The current Section object * @throws InvalidArgumentException * @throws Exception */ private function prepareAssociationsDrawer($section) { $entry_id = !is_null($this->_context['entry_id']) ? $this->_context['entry_id'] : null; $show_entries = Symphony::Configuration()->get('association_maximum_rows', 'symphony'); if (is_null($entry_id) && !isset($_GET['prepopulate']) || is_null($show_entries) || $show_entries == 0) { return; } $parent_associations = SectionManager::fetchParentAssociations($section->get('id'), true); $child_associations = SectionManager::fetchChildAssociations($section->get('id'), true); $content = null; $drawer_position = 'vertical-right'; /** * Prepare Associations Drawer from an Extension * * @since Symphony 2.3.3 * @delegate PrepareAssociationsDrawer * @param string $context * '/publish/' * @param integer $entry_id * The entry ID or null * @param array $parent_associations * Array of Sections * @param array $child_associations * Array of Sections * @param string $drawer_position * The position of the Drawer, defaults to `vertical-right`. Available * values of `vertical-left, `vertical-right` and `horizontal` */ Symphony::ExtensionManager()->notifyMembers('PrepareAssociationsDrawer', '/publish/', array('entry_id' => $entry_id, 'parent_associations' => &$parent_associations, 'child_associations' => &$child_associations, 'content' => &$content, 'drawer-position' => &$drawer_position)); // If there are no associations, return now. if ((is_null($parent_associations) || empty($parent_associations)) && (is_null($child_associations) || empty($child_associations))) { return; } if (!$content instanceof XMLElement) { $content = new XMLElement('div', null, array('class' => 'content')); $content->setSelfClosingTag(false); // Process Parent Associations if (!is_null($parent_associations) && !empty($parent_associations)) { foreach ($parent_associations as $as) { if ($field = FieldManager::fetch($as['parent_section_field_id'])) { if (isset($_GET['prepopulate'])) { $prepopulate_field = key($_GET['prepopulate']); } // get associated entries if entry exists, if ($entry_id) { $entry_ids = $field->findParentRelatedEntries($as['child_section_field_id'], $entry_id); // get prepopulated entry otherwise } elseif (isset($_GET['prepopulate'])) { $entry_ids = array(intval(current($_GET['prepopulate']))); } else { $entry_ids = array(); } // Use $schema for perf reasons $schema = array($field->get('element_name')); $where = !empty($entry_ids) ? sprintf(' AND `e`.`id` IN (%s)', implode(', ', $entry_ids)) : null; $entries = !empty($entry_ids) || isset($_GET['prepopulate']) && $field->get('id') === $prepopulate_field ? EntryManager::fetchByPage(1, $as['parent_section_id'], $show_entries, $where, null, false, false, true, $schema) : array(); $has_entries = !empty($entries) && $entries['total-entries'] != 0; if ($has_entries) { $element = new XMLElement('section', null, array('class' => 'association parent')); $header = new XMLElement('header'); $header->appendChild(new XMLElement('p', __('Linked to %s in', array('<a class="association-section" href="' . SYMPHONY_URL . '/publish/' . $as['handle'] . '/">' . $as['name'] . '</a>')))); $element->appendChild($header); $ul = new XMLElement('ul', null, array('class' => 'association-links', 'data-section-id' => $as['child_section_id'], 'data-association-ids' => implode(', ', $entry_ids))); foreach ($entries['records'] as $e) { // let the field create the mark up $li = $field->prepareAssociationsDrawerXMLElement($e, $as); // add it to the unordered list $ul->appendChild($li); } $element->appendChild($ul); $content->appendChild($element); } } } } // Process Child Associations if (!is_null($child_associations) && !empty($child_associations)) { foreach ($child_associations as $as) { // Get the related section $child_section = SectionManager::fetch($as['child_section_id']); if (!$child_section instanceof Section) { continue; } // Get the visible field instance (using the sorting field, this is more flexible than visibleColumns()) // Get the link field instance $visible_field = current($child_section->fetchVisibleColumns()); $relation_field = FieldManager::fetch($as['child_section_field_id']); // Get entries, using $schema for performance reasons. $entry_ids = $relation_field->findRelatedEntries($entry_id, $as['parent_section_field_id']); $schema = $visible_field ? array($visible_field->get('element_name')) : array(); $where = sprintf(' AND `e`.`id` IN (%s)', implode(', ', $entry_ids)); $entries = !empty($entry_ids) ? EntryManager::fetchByPage(1, $as['child_section_id'], $show_entries, $where, null, false, false, true, $schema) : array(); $has_entries = !empty($entries) && $entries['total-entries'] != 0; // Build the HTML of the relationship $element = new XMLElement('section', null, array('class' => 'association child')); $header = new XMLElement('header'); $filter = '?filter[' . $relation_field->get('element_name') . ']=' . $entry_id; $prepopulate = '?prepopulate[' . $as['child_section_field_id'] . ']=' . $entry_id; // Create link with filter or prepopulate $link = SYMPHONY_URL . '/publish/' . $as['handle'] . '/' . $filter; $a = new XMLElement('a', $as['name'], array('class' => 'association-section', 'href' => $link)); // Create new entries $create = new XMLElement('a', __('Create New'), array('class' => 'button association-new', 'href' => SYMPHONY_URL . '/publish/' . $as['handle'] . '/new/' . $prepopulate)); // Display existing entries if ($has_entries) { $header->appendChild(new XMLElement('p', __('Links in %s', array($a->generate())))); $ul = new XMLElement('ul', null, array('class' => 'association-links', 'data-section-id' => $as['child_section_id'], 'data-association-ids' => implode(', ', $entry_ids))); foreach ($entries['records'] as $key => $e) { // let the first visible field create the mark up if ($visible_field) { $li = $visible_field->prepareAssociationsDrawerXMLElement($e, $as, $prepopulate); } else { $li = Field::createAssociationsDrawerXMLElement($e->get('id'), $e, $as, $prepopulate); } // add it to the unordered list $ul->appendChild($li); } $element->appendChild($ul); // If we are only showing 'some' of the entries, then show this on the UI if ($entries['total-entries'] > $show_entries) { $pagination = new XMLElement('li', null, array('class' => 'association-more', 'data-current-page' => '1', 'data-total-pages' => ceil($entries['total-entries'] / $show_entries), 'data-total-entries' => $entries['total-entries'])); $counts = new XMLElement('a', __('Show more entries'), array('href' => $link)); $pagination->appendChild($counts); $ul->appendChild($pagination); } // No entries } else { $element->setAttribute('class', 'association child empty'); $header->appendChild(new XMLElement('p', __('No links in %s', array($a->generate())))); } $header->appendChild($create); $element->prependChild($header); $content->appendChild($element); } } } $drawer = Widget::Drawer('section-associations', __('Show Associations'), $content); $this->insertDrawer($drawer, $drawer_position, 'prepend'); }
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; }
private function __findPrimaryFieldValueFromRelationID($entry_id) { $field_id = $this->findFieldIDFromRelationID($entry_id); if (!isset(self::$cacheFields[$field_id])) { self::$cacheFields[$field_id] = Symphony::Database()->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tf.id,\n\t\t\t\t\t\ts.name AS `section_name`,\n\t\t\t\t\t\ts.handle AS `section_handle`\n\t\t\t\t\t FROM\n\t\t\t\t\t \t`tbl_fields` AS f\n\t\t\t\t\t INNER JOIN\n\t\t\t\t\t \t`tbl_sections` AS s\n\t\t\t\t\t \tON s.id = f.parent_section\n\t\t\t\t\t WHERE\n\t\t\t\t\t \tf.id = '{$field_id}'\n\t\t\t\t\t ORDER BY\n\t\t\t\t\t \tf.sortorder ASC\n\t\t\t\t\t LIMIT 1\n\t\t\t\t"); } $primary_field = self::$cacheFields[$field_id]; if (!$primary_field) { return NULL; } $fm = new FieldManager($this->_Parent); $field = $fm->fetch($field_id); if (!isset(self::$cacheValues[$entry_id])) { self::$cacheValues[$entry_id] = Symphony::Database()->fetchRow(0, sprintf("\n\t\t\t\t\t\tSELECT *\n\t\t\t\t \t\tFROM `tbl_entries_data_%d`\n\t\t\t\t \t\tWHERE `entry_id` = %d\n\t\t\t\t\t\tORDER BY `id` DESC\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t", $field_id, $entry_id)); } $data = self::$cacheValues[$entry_id]; if (empty($data)) { return null; } $primary_field['value'] = $field->prepareTableValue($data); return $primary_field; }