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 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; }
public function delete($section_id) { $query = "SELECT `id`, `sortorder` FROM tbl_sections WHERE `id` = '{$section_id}'"; $details = Symphony::Database()->fetchRow(0, $query); ## Delete all the entries include_once TOOLKIT . '/class.entrymanager.php'; $entryManager = new EntryManager($this->_Parent); $entries = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '{$section_id}'"); $entryManager->delete($entries); ## Delete all the fields $fieldManager = new FieldManager($this->_Parent); $fields = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '{$section_id}'"); if (is_array($fields) && !empty($fields)) { foreach ($fields as $field_id) { $fieldManager->delete($field_id); } } ## Delete the section Symphony::Database()->delete('tbl_sections', " `id` = '{$section_id}'"); ## Update the sort orders Symphony::Database()->query("UPDATE tbl_sections SET `sortorder` = (`sortorder` - 1) WHERE `sortorder` > '" . $details['sortorder'] . "'"); ## Delete the section associations Symphony::Database()->delete('tbl_sections_association', " `parent_section_id` = '{$section_id}'"); return true; }
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; }
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 static function process($options = array()) { $default = array('entries' => array(), 'section' => null, 'field_name' => null, 'iptc' => true, 'exif' => true); $options = array_merge($default, $options); self::checkRequirements($options['exif']); if (!$options['field_name'] || !$options['entries'] || !$options['section']) { self::throwEx('Missing required option'); } $root = new XMLElement(self::getRootElement()); $field = FieldManager::fetchFieldIDFromElementName($options['field_name'], $options['section']->get('id')); foreach ($options['entries'] as $entry) { $data = $entry->getData($field); $rel = $data['file']; $img = WORKSPACE . $rel; $xml = new XMLElement('image', null, array('path' => $rel, 'entry_id' => $entry->get('id'))); if ($options['iptc']) { $result = self::processIptc($img); $xml->appendChild($result); } if ($options['exif']) { $result = self::processExif($img); $xml->appendChild($result); } $root->appendChild($xml); } return $root; }
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) { } }
/** * 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; }
/** * 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 commit() { if (!parent::commit()) { return false; } $id = $this->get('id'); if ($id === false) { return false; } fieldMemberUsername::createSettingsTable(); $fields = array('field_id' => $id, 'validator' => $this->get('validator')); return FieldManager::saveSettings($id, $fields); }
public function grab(array &$param_pool = NULL) { // remove placeholder elements unset($this->dsParamINCLUDEDELEMENTS); // fill with all included elements if none are set if (is_null(REST_Entries::getDatasourceParam('included_elements'))) { // get all fields in this section $fields = FieldManager::fetchFieldsSchema(REST_Entries::getSectionId()); // add them to the data source foreach ($fields as $field) { $this->dsParamINCLUDEDELEMENTS[] = $field['element_name']; } // also add pagination $this->dsParamINCLUDEDELEMENTS[] = 'system:pagination'; } else { $this->dsParamINCLUDEDELEMENTS = explode(',', REST_Entries::getDatasourceParam('included_elements')); } // fill the other parameters if (!is_null(REST_Entries::getDatasourceParam('limit'))) { $this->dsParamLIMIT = REST_Entries::getDatasourceParam('limit'); } if (!is_null(REST_Entries::getDatasourceParam('page'))) { $this->dsParamSTARTPAGE = REST_Entries::getDatasourceParam('page'); } if (!is_null(REST_Entries::getDatasourceParam('sort'))) { $this->dsParamSORT = REST_Entries::getDatasourceParam('sort'); } if (!is_null(REST_Entries::getDatasourceParam('order'))) { $this->dsParamORDER = REST_Entries::getDatasourceParam('order'); } // Do grouping if (!is_null(REST_Entries::getDatasourceParam('groupby'))) { $field_id = FieldManager::fetchFieldIDFromElementName(REST_Entries::getDatasourceParam('groupby'), REST_Entries::getSectionId()); if ($field_id) { $this->dsParamGROUP = $field_id; } } // if API is calling a known entry, filter on System ID only if (!is_null(REST_Entries::getEntryId())) { $this->dsParamFILTERS['id'] = REST_Entries::getEntryId(); } elseif (REST_Entries::getDatasourceParam('filters')) { foreach (REST_Entries::getDatasourceParam('filters') as $field_handle => $filter_value) { $filter_value = rawurldecode($filter_value); $field_id = FieldManager::fetchFieldIDFromElementName($field_handle, REST_Entries::getSectionId()); if (is_numeric($field_id)) { $this->dsParamFILTERS[$field_id] = $filter_value; } } } return $this->execute($param_pool); }
/** * Persist field configuration */ function commit() { // set up standard Field settings if (!parent::commit()) { return FALSE; } $id = $this->get('id'); if ($id === FALSE) { return FALSE; } $fields = array(); $fields['field_id'] = $id; return FieldManager::saveSettings($id, $fields); }
public function commit() { if (!Field::commit()) { return false; } $id = $this->get('id'); if ($id === false) { return false; } $fields = array(); $fields['field_id'] = $id; $fields['pre_populate'] = $this->get('pre_populate') ? $this->get('pre_populate') : 'no'; $fields['mode'] = $this->get('mode') ? $this->get('mode') : 'normal'; return FieldManager::saveSettings($id, $fields); }
public function commit() { if (!parent::commit()) { return false; } $id = $this->get('id'); if ($id === false) { return false; } $state = $this->get('default_state'); $entries = (int) $this->get('unique_entries'); $steal = $this->get('unique_steal'); $fields = array('field_id' => $id, 'default_state' => $state ? $state : 'off', 'unique_entries' => $entries > 0 ? $entries : 1, 'unique_steal' => $steal ? $steal : 'off'); return FieldManager::saveSettings($id, $fields); }
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 commit() { if (!parent::commit()) { return false; } $id = $this->get('id'); if ($id === false) { return false; } $fields = array(); $fields['pre_populate_source'] = is_null($this->get('pre_populate_source')) ? null : implode(',', $this->get('pre_populate_source')); $fields['validator'] = $fields['validator'] == 'custom' ? null : $this->get('validator'); if (!FieldManager::saveSettings($id, $fields)) { return false; } SectionManager::removeSectionAssociation($id); foreach ($this->get('pre_populate_source') as $field_id) { if ($field_id === 'none') { continue; } if (!is_null($field_id) && is_numeric($field_id)) { SectionManager::createSectionAssociation(null, $id, (int) $field_id, $this->get('show_association') == 'yes' ? true : false, $this->get('association_ui'), $this->get('association_editor')); } } return true; }
private function __fetchFields($section, $context, $subsection, $field, $mode = '') { // Section context if ($section !== 0) { $section = " AND t2.`parent_section` = '" . intval($section) . "' "; } else { $section = ''; } $subsection = Symphony::Database()->cleanValue($subsection); // Get id $id = Symphony::Database()->fetch("(SELECT t1.`subsection_id`, t1.field_id\n\t\t\t\t\tFROM `tbl_fields_subsectionmanager` AS t1\n\t\t\t\t\tINNER JOIN `tbl_fields` AS t2\n\t\t\t\t\tWHERE t2.`element_name` = '{$subsection}'\n\t\t\t\t\t{$section}\n\t\t\t\t\tAND t1.`field_id` = t2.`id`\n\t\t\t\t\tLIMIT 1)"); // Get subfield id $subfield_id = FieldManager::fetchFieldIDFromElementName($field, $id[0]['subsection_id']); // Store field data $field_id = $id[0]['field_id']; if (!is_array(self::$storage['fields'][$context][$field_id][$subfield_id])) { self::storeSubsectionFields($context, $field_id, $subfield_id, $mode); } return $id[0]['subsection_id']; }
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; }
public function commit() { if (!parent::commit()) { return false; } $id = $this->get('id'); if ($id === false) { return false; } $fields = array('field_id' => $id, 'column_length' => max((int) $this->get('column_length'), 25), 'text_size' => $this->get('text_size'), 'text_formatter' => $this->get('text_formatter'), 'text_validator' => $this->get('text_validator'), 'text_length' => max((int) $this->get('text_length'), 0), 'text_cdata' => $this->get('text_cdata'), 'text_handle' => $this->get('text_handle')); return FieldManager::saveSettings($id, $fields); }
public function __actionEdit() { if (@array_key_exists('save', $_POST['action']) || @array_key_exists('done', $_POST['action'])) { $canProceed = true; $fields = $_POST['fields']; $meta = $_POST['meta']; $section_id = $this->_context[1]; $sectionManager = new SectionManager($this->_Parent); $existing_section = $sectionManager->fetch($section_id); $fieldManager = new FieldManager($this->_Parent); $this->_errors = array(); ## Check to ensure all the required section fields are filled if (!isset($meta['name']) || trim($meta['name']) == '') { $required = array('Name'); $this->_errors['name'] = __('This is a required field.'); $canProceed = false; } elseif ($meta['name'] != $existing_section->get('name') && Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_sections` WHERE `name` = '" . $meta['name'] . "' AND `id` != {$section_id} LIMIT 1")) { $this->_errors['name'] = __('A Section with the name <code>%s</code> name already exists', array($meta['name'])); $canProceed = false; } ## Check to ensure all the required section fields are filled if (!isset($meta['navigation_group']) || strlen(trim($meta['navigation_group'])) == 0) { $required = array('Navigation Group'); $this->_errors['navigation_group'] = __('This is a required field.'); $canProceed = false; } elseif (is_array($fields) && !empty($fields)) { ## Check for duplicate CF names if ($canProceed) { $name_list = array(); foreach ($fields as $position => $data) { if (trim($data['element_name']) == '') { $data['element_name'] = $fields[$position]['element_name'] = Lang::createHandle($data['label'], NULL, '-', false, true, array('@^[\\d-]+@i' => '')); } if (trim($data['element_name']) != '' && in_array($data['element_name'], $name_list)) { $this->_errors[$position] = array('label' => __('Two custom fields have the same element name. All element names must be unique.')); $canProceed = false; break; } $name_list[] = $data['element_name']; } } if ($canProceed) { $fieldManager = new FieldManager($this->_Parent); $unique = array(); foreach ($fields as $position => $data) { $required = NULL; $field = $fieldManager->create($data['type']); $field->setFromPOST($data); if ($field->mustBeUnique() && !in_array($field->get('type'), $unique)) { $unique[] = $field->get('type'); } elseif ($field->mustBeUnique() && in_array($field->get('type'), $unique)) { ## Warning. cannot have 2 of this field! $canProceed = false; $this->_errors[$position] = array('label' => __('There is already a field of type <code>%s</code>. There can only be one per section.', array($field->name()))); } $errors = array(); if (Field::__OK__ != $field->checkFields($errors, false, false) && !empty($errors)) { $this->_errors[$position] = $errors; $canProceed = false; break; } } } } if ($canProceed) { $meta['handle'] = Lang::createHandle($meta['name']); $meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no'; if (!$sectionManager->edit($section_id, $meta)) { $this->pageAlert(__('An unknown database occurred while attempting to create the section.'), Alert::ERROR); } else { ## Delete missing CF's $id_list = array(); if (is_array($fields) && !empty($fields)) { foreach ($fields as $position => $data) { if (isset($data['id'])) { $id_list[] = $data['id']; } } } $missing_cfs = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '{$section_id}' AND `id` NOT IN ('" . @implode("', '", $id_list) . "')"); if (is_array($missing_cfs) && !empty($missing_cfs)) { foreach ($missing_cfs as $id) { $fieldManager->delete($id); } } ## Save each custom field if (is_array($fields) && !empty($fields)) { foreach ($fields as $position => $data) { $field = $fieldManager->create($data['type']); $field->setFromPOST($data); $field->set('sortorder', (string) $position); $field->set('parent_section', $section_id); $bEdit = true; if (!$field->get('id')) { $bEdit = false; } ## Creation if ($field->commit()) { $field_id = $field->get('id'); ### # Delegate: FieldPostCreate # Delegate: FieldPostEdit # Description: After creation/editing of an Field. New Field object is provided. $this->_Parent->ExtensionManager->notifyMembers($bEdit ? 'FieldPostEdit' : 'FieldPostCreate', '/blueprints/sections/', array('field' => &$field, 'data' => &$data)); } } } ## TODO: Fix Me ### # Delegate: Edit # Description: After editing a Section. The ID is provided. #$ExtensionManager->notifyMembers('Edit', getCurrentPage(), array('section_id' => $section_id)); redirect(URL . "/symphony/blueprints/sections/edit/{$section_id}/saved/"); } } } if (@array_key_exists("delete", $_POST['action'])) { $section_id = $this->_context[1]; $sectionManager = new SectionManager($this->_Parent); $sectionManager->delete($section_id); redirect(URL . '/symphony/blueprints/sections/'); } }
public function commit() { if (!parent::commit()) { return false; } $id = $this->get('id'); if ($id === false) { return false; } $fields = array(); $fields['allow_multiple_selection'] = $this->get('allow_multiple_selection') ? $this->get('allow_multiple_selection') : 'no'; $fields['default_to_current_user'] = $this->get('default_to_current_user') ? $this->get('default_to_current_user') : 'no'; if ($this->get('author_types') != '') { $fields['author_types'] = implode(',', $this->get('author_types')); } return FieldManager::saveSettings($id, $fields); }
/** * Returns the Schema of this section which includes all this sections * fields and their settings. * * @return array */ public function fetchFieldsSchema() { return FieldManager::fetchFieldsSchema($this->get('id')); }
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); } }