private function __fetchSectionsFromContext($context) { if ($context['delegate'] == 'EntryPreDelete' || $context['delegate'] == 'EntriesPostOrder') { $current_section_id = EntryManager::fetchEntrySectionID($context['entry_id'][0]); } else { if ($context['delegate'] == 'EventFinalSaveFilter') { $current_section_id = EntryManager::fetchEntrySectionID($context['entry']->get('id')); } else { $current_section_id = $context['section']->get('id'); } } $data = Symphony::Database()->fetch(sprintf('SELECT DISTINCT `child_section_id`, `parent_section_id` FROM `tbl_sections_association` WHERE `parent_section_id` = %d OR `child_section_id` = %d', $current_section_id, $current_section_id)); $result = array($current_section_id); foreach ($data as $v) { array_push($result, $v['child_section_id']); array_push($result, $v['parent_section_id']); } return array_unique($result); }
private function __fetchSectionsFromContext($context) { if (!is_null($this->_sectionsToFlush)) { return; } $this->_sectionsToFlush = array(); if ($context['delegate'] == 'EntryPreDelete' || $context['delegate'] == 'EntriesPostOrder') { require_once TOOLKIT . '/class.entrymanager.php'; $this->_sectionsToFlush[0] = EntryManager::fetchEntrySectionID($context['entry_id'][0]); } elseif ($context['delegate'] == 'EventFinalSaveFilter') { require_once TOOLKIT . '/class.entrymanager.php'; $this->_sectionsToFlush[0] = EntryManager::fetchEntrySectionID($context['entry']->get('id')); } else { $this->_sectionsToFlush[0] = $context['section']->get('id'); } $associatedSections = Symphony::Database()->fetch(sprintf('SELECT DISTINCT `child_section_id` value, `parent_section_id` value FROM `tbl_sections_association` WHERE `parent_section_id` = %d OR `child_section_id` = %d', $this->_sectionsToFlush[0], $this->_sectionsToFlush[0])); General::flattenArray($associatedSections); $associatedSections = array_unique(array_values($associatedSections)); if (is_array($associatedSections) && !empty($associatedSections)) { $this->_sectionsToFlush = array_merge($this->_sectionsToFlush, $associatedSections); } }
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 parseEntryAction($context) { if ($this->validateUser()) { $action = $this->getActionFromDelegateName($context['delegate']); $ids = array(); $section_id = null; // Entry IDs are provided in different formats depending // on if you're deleting or not. So standardize them. if ($action == 'deleted') { $ids = $context['entry_id']; } else { $section_id = $context['entry']->get('section_id'); $ids = $context['entry']->get('id'); } if ($ids && !is_array($ids)) { $ids = array($ids); } if (!$ids) { return; } // Loop through entries, validate section, and log them. foreach ($ids as $entry_id) { $current_section_id = $section_id; if (!$current_section_id) { // This can be removed when dropping 2.5.x compat if (!class_exists('EntryManager')) { include_once TOOLKIT . '/class.entrymanager.php'; } $current_section_id = EntryManager::fetchEntrySectionID($entry_id); } if ($this->validateSection($current_section_id)) { Tracker::log($current_section_id, $entry_id, $action, $this->getAuthorID(), $this->getTimestamp()); } } } }
public function parseEntryAction($context) { if ($this->validateUser()) { $action = $this->getActionFromDelegateName($context['delegate']); // Entry IDs are provided in different formats depending // on if you're deleting or not. So standardize them. if ($action == 'deleted') { $ids = (array) $context['entry_id']; } else { $section_id = $context['entry']->get('section_id'); $ids = (array) $context['entry']->get('id'); } // Loop through entries, validate section, and log them. foreach ($ids as $entry_id) { if (!isset($section_id)) { include_once TOOLKIT . '/class.entrymanager.php'; $section_id = EntryManager::fetchEntrySectionID($entry_id); } if ($this->validateSection($section_id)) { Tracker::log($section_id, $entry_id, $action, $this->getAuthorID(), $this->getTimestamp()); } } } }
/** * Preload subsection entries * * @param Array $parents * Array of entry objects */ public static function preloadSubsectionEntries($parents) { if (empty($parents) || !is_array($parents)) { return; } // Get parent data $fields = array(); foreach ($parents as $entry) { $data = $entry->getData(); // Get relation id foreach ($data as $field => $settings) { if (isset($settings['relation_id'])) { if (!is_array($settings['relation_id'])) { $settings['relation_id'] = array($settings['relation_id']); } foreach ($settings['relation_id'] as $relation_id) { if (empty($relation_id)) { continue; } $fields[$field][] = $relation_id; } } } } // Store entries foreach ($fields as $field => $relation_id) { // Check for already loaded entries $entry_id = array_diff($relation_id, array_keys(self::$storage['entries'])); // Load new entries if (!empty($entry_id)) { // Get subsection id $subsection_id = EntryManager::fetchEntrySectionID($entry_id[0]); // Fetch entries $entries = EntryManager::fetch($entry_id, $subsection_id); if (!empty($entries)) { foreach ($entries as $entry) { self::$storage['entries'][$entry->get('id')] = $entry; } } } } }
public function resolveLinks($linked) { if (is_null($linked)) { return; } $entryManager = new EntryManager($this->_Parent); if (!is_array($linked)) { $section_id = $entryManager->fetchEntrySectionID($linked); $entry = end($entryManager->fetch($linked)); $entry = $entry->getData($this->_driver->fetchVisibleFieldID($section_id)); return $entry['value']; } else { $section_id = $entryManager->fetchEntrySectionID($linked[0]); $return = array(); foreach ($linked as $k => $e) { $entry = end($entryManager->fetch($e)); $entry = $entry->getData($this->_driver->fetchVisibleFieldID($section_id)); $return[] = $entry['value']; } return implode(", ", $return); } }
protected function __trigger(){ //Check the hash and the ID match if($_GET["hash"] == sha1($_GET["id"])) { //Get the entry object from the ID. if(!isset(self::$entryManager)) { self::$entryManager = new entryManager(Symphony::Engine()); } $entry_id = $_GET["id"]; $section_id = self::$entryManager->fetchEntrySectionID($entry_id); $entry = self::$entryManager->fetch($entry_id, $section_id); $entry = $entry[0]; //Retreive the Pushed JSON from the Eventarc API. $data = json_decode( utf8_encode(file_get_contents("php://input")), TRUE ); //Eventarc entry id. $e_id = $data['e_id']; //Login to eventarc & return the API key. $eventarc = new Eventarc; $login_data = $eventarc->user_login($this->get('eventarc-username'),$this->get('eventarc-password')); $u_apikey = $login_data['u_apikey']; //Now retrieve the Event $eventarc = new Eventarc($u_apikey, $this->get('eventarc-username')); $event = $eventarc->event_get($e_id); //First save the standard event entry fields $fields = array(); foreach($event as $key => $value) { if($this->string_begins_with($key, 'e_')) { $fields[str_replace('e_', 'e-', $key)] = strip_tags($value); } else if ($this->string_begins_with($key, 'g_')) { $fields[str_replace('g_', 'g-', $key)] = strip_tags($value); } } //Update the e_status to be 'Yes/No' for Symphony; if($fields['e-status'] == 'active') { $fields['e-status'] = 'yes'; } else { $fields['e-status'] = 'no'; } //Now look for address details $address = $eventarc->event_get_address($e_id); foreach($address as $key => $value) { if($this->string_begins_with($key, 'a_')) { $fields[str_replace('a_', 'a-', $key)] = strip_tags($value); } } if(!isset(self::$fieldManager)) { self::$fieldManager = new fieldManager(Symphony::Engine()); } foreach($fields as $key => $value) { $field_id = self::$fieldManager->fetchFieldIDFromElementName($key); if(isset($field_id)) { $entry->setData($field_id, array( 'value' => $value, )); } } $entry->commit(); return true; } }
public function eventPreSaveFilter($context) { if ($context['fields'] === null && (RestEngine::getHTTPMethod() === 'put' || 'post')) { $parsedData = RestEngine::parseBodyContent(); if ($context['entry_id'] === null && RestEngine::getHTTPMethod() === 'put') { $pageID = RestEngine::getPageID(); $urlParams = $this::getPageURLParams(); //use the page ID to look up the format and uid param settings $settings = RestResourceManager::getByPageID($pageID); if (array_key_exists($settings['uid_parameter'], $urlParams)) { $entryIDValue = $urlParams[$settings['uid_parameter']]; if ($settings['field_id'] == 0) { // 0 stands for using the Entry ID number directly so just // check to see if that entry number exists in the correct section $entrySection = EntryManager::fetchEntrySectionID($entryIDValue); if ($entrySection == $settings['section_id']) { //good to go $entryID = $entryIDValue; } } else { $fieldType = FieldManager::fetchFieldTypeFromID($settings['field_id']); //TODO: Eventually add in a more robust field type management to distinguish between value and handle based fields if necessary, or do it by array searching? if ($fieldType != 'memberemail') { $query = "SELECT `entry_id` FROM `tbl_entries_data_" . $settings['field_id'] . "` WHERE `handle` = '" . $entryIDValue . "' LIMIT 1"; } else { $query = "SELECT `entry_id` FROM `tbl_entries_data_" . $settings['field_id'] . "` WHERE `value` = '" . $entryIDValue . "' LIMIT 1"; } $entryID = Symphony::Database()->fetchVar('entry_id', 0, $query); } if (is_null($entryID)) { //no matching entry $context['messages'][] = array('restengine:invalid-id', FALSE, __('The specified resource "%1$s" does not exist.', array($entryIDValue))); } else { //good to go $context['entry_id'] = $entryID; } } else { $context['messages'][] = array('restengine:settings-error', FALSE, __('Invalid Rest Resource unique ID URL parameter: %1$s.', array($settings['uid_parameter']))); //probably some kind of error needs returning here } } if (is_array($parsedData) && !empty($parsedData['data']) && $parsedData['errors'] === null) { //Create the post data cookie element. General::array_to_xml($context['post_values'], $parsedData, true); //TODO: check for field mapping //TODO: Do we need to error when message body contains properties that we don't have fields for in the assigned section? $context['fields'] = $parsedData['data']; } } }