public function view() { $this->_driver = $this->_Parent->ExtensionManager->create('export_entry'); $this->target = $_GET['section']; $this->fieldID = $_GET['field']; if (!$this->validate()) { $this->_status = self::STATUS_BAD; $this->generate(); return false; } $sectionManager = new SectionManager($this->_Parent); $entryManager = new EntryManager($this->_Parent); $section = $sectionManager->fetch($this->target); $fields = $section->fetchFields(); /* Get all the fields from the target section ** Loop them for the section Link field */ foreach ($fields as $field) { if ($field->get("id") == $this->fieldID) { if ($field->get('type') == "bilink") { $linked_section_id = $field->get("linked_section_id"); $linked_field_id = $field->get("linked_field_id"); } else { if ($field->get('type') == "selectbox_link") { $linked_section_id = Symphony::Database()->fetchVar("parent_section_id", 0, "SELECT parent_section_id \n\t\t\t\t\t\t\tFROM `tbl_sections_association` \n\t\t\t\t\t\t\tWHERE `child_section_field_id` = {$field->get("id")}\n\t\t\t\t\t\t\tLIMIT 1"); $linked_field_id = $field->get("related_field_id"); } else { if ($field->get('type') == "checkbox") { $linked_section_id = false; $el = new XMLElement("entry", 'Yes'); $el->setAttribute('id', 'yes'); $this->_Result->appendChild($el); $el = new XMLElement("entry", 'No'); $el->setAttribute('id', 'no'); $this->_Result->appendChild($el); } } } } } if ($linked_section_id) { /* Got the linked field, now get the other end of the ** link. Use the first Visible column as the output handle */ $linked_field_id = $this->_driver->fetchVisibleFieldID($linked_section_id); /* Foreach entry in the linked section, display the first ** column to be selected */ $entries = $entryManager->fetch(null, $linked_section_id); foreach ($entries as $entry) { $data = current($entryManager->fetch($entry->get('id'), $linked_section_id)); $values = $data->getData($linked_field_id); $el = new XMLElement("entry", General::sanitize($values['value'])); $el->setAttribute('id', $entry->get('id')); $this->_Result->appendChild($el); } } }
private function checkTemplates($pageId, $prefix = '') { // Link templates: $templates = Symphony::Database()->fetch(sprintf('SELECT * FROM `tbl_ckeditor_link_templates` WHERE `page_id` = %d;', $pageId)); $entryTree = array(); foreach ($templates as $template) { $section = SectionManager::fetch($template['section_id']); $entries = EntryManager::fetch(null, $template['section_id']); $fields = $section->fetchFields(); foreach ($entries as $entry) { $link = $template['link']; // Replace the ID: $link = str_replace('{$id}', $entry->get('id'), $link); $data = $entry->getData(); foreach ($fields as $field) { // Replace the placeholders with the value: // Check if the field has a 'handle': $testData = $field->processRawFieldData('test', $field->__OK__); if (isset($testData['handle'])) { $link = str_replace('{$' . $field->get('element_name') . '}', $data[$field->get('id')]['handle'], $link); } } $entryTree[] = array('handle' => $data[$field->get('id')]['handle'], 'path' => '', 'url' => $link, 'title' => $prefix . ' › ' . General::sanitize($data[$template['field_id']]['value'])); } } return $entryTree; }
protected function __trigger() { $result = new XMLElement(self::ROOTELEMENT); $success = false; self::__init(); $db = ASDCLoader::instance(); $Members = $this->_Parent->ExtensionManager->create('members'); $Members->initialiseCookie(); if ($Members->isLoggedIn() !== true) { $result->appendChild(new XMLElement('error', 'Must be logged in.')); $result->setAttribute('status', 'error'); return $result; } $Members->initialiseMemberObject(); // Make sure we dont accidently use an expired code extension_Members::purgeCodes(); $em = new EntryManager($this->_Parent); $entry = end($em->fetch((int) $Members->Member->get('id'))); $email = $entry->getData(self::findFieldID('email-address', 'members')); $name = $entry->getData(self::findFieldID('name', 'members')); $success = $Members->emailNewMember(array('entry' => $entry, 'fields' => array('username-and-password' => $entry->getData(self::findFieldID('username-and-password', 'members')), 'name' => $name['value'], 'email-address' => $email['value']))); if ($success == true && isset($_REQUEST['redirect'])) { redirect($_REQUEST['redirect']); } $result->setAttribute('result', $success === true ? 'success' : 'error'); return $result; }
protected function __trigger() { self::__init(); $db = ASDCLoader::instance(); $success = false; $Members = $this->_Parent->ExtensionManager->create('members'); $Members->initialiseCookie(); if ($Members->isLoggedIn() !== true) { redirect(URL . '/forbidden/'); } $Members->initialiseMemberObject(); // Make sure we dont accidently use an expired token extension_Members::purgeCodes(); $activation_row = $db->query(sprintf("SELECT * FROM `tbl_members_codes` WHERE `token` = '%s' AND `member_id` = %d LIMIT 1", $db->escape($_POST['fields']['code']), (int) $Members->Member->get('id')))->current(); // No code, you are a spy! if ($activation_row === false) { redirect(URL . '/members/activate/failed/'); } // Got this far, all is well. $db->query(sprintf("UPDATE `tbl_entries_data_%d` SET `role_id` = %d WHERE `entry_id` = %d LIMIT 1", $Members->roleField(), 3, (int) $Members->Member->get('id'))); extension_Members::purgeTokens((int) $Members->Member->get('id')); $em = new EntryManager($this->_Parent); $entry = end($em->fetch((int) $Members->Member->get('id'))); $email = $entry->getData(self::findFieldID('email-address', 'members')); $name = $entry->getData(self::findFieldID('name', 'members')); $Members->emailNewMember(array('section' => $Members->memberSectionHandle(), 'entry' => $entry, 'fields' => array('username-and-password' => $entry->getData(self::findFieldID('username-and-password', 'members')), 'name' => $name['value'], 'email-address' => $email['value']))); redirect(URL . '/members/activate/success/'); }
private function createEntryFromPost() { include_once TOOLKIT . '/class.sectionmanager.php'; include_once TOOLKIT . '/class.entrymanager.php'; // section id $source = $this->getSection(); $section = SectionManager::fetch($source); $fields = $section->fetchFields(); $entry = null; if ($id > 0) { // edit $entry = EntryManager::fetch($id); if (empty($entry)) { throw new Exception(sprintf(__('Entry id %s not found'), $id)); } $entry = $entry[0]; } else { // create $entry = EntryManager::create(); $entry->set('section_id', $source); } foreach ($fields as $f) { $data = $this->getFieldValue($f->get('element_name')); if ($data != null) { $entry->setData($f->get('id'), $data); } } if (!$entry->commit()) { throw new Exception(sprintf('Could not create entry: %s', mysql_error())); } return $entry; }
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) { } }
private function __doit($source, $fields, &$result, $entry_id = NULL, $cookie = NULL) { include_once TOOLKIT . '/class.sectionmanager.php'; include_once TOOLKIT . '/class.entrymanager.php'; $sectionManager = new SectionManager($this->_Parent); if (!($section = $sectionManager->fetch($source))) { $result->setAttribute('result', 'error'); $result->appendChild(new XMLElement('message', 'Section is invalid')); return false; } $entryManager = new EntryManager($this->_Parent); if (isset($entry_id) && $entry_id != NULL) { $entry =& $entryManager->fetch($entry_id); $entry = $entry[0]; if (!is_object($entry)) { $result->setAttribute('result', 'error'); $result->appendChild(new XMLElement('message', 'Invalid Entry ID specified. Could not create Entry object.')); return false; } } else { $entry =& $entryManager->create(); $entry->set('section_id', $source); } 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 = $entryManager->fieldManager->fetch($field_id); $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('type' => $fields[$field->get('element_name')] == '' ? 'missing' : 'invalid'))); } if (isset($cookie) && is_object($cookie)) { $result->appendChild($cookie); } 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 $err) { $field = $entryManager->fieldManager->fetch($err['field_id']); $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('type' => 'invalid'))); } if (isset($cookie) && is_object($cookie)) { $result->appendChild($cookie); } return false; } else { if (!$entry->commit()) { $result->setAttribute('result', 'error'); $result->appendChild(new XMLElement('message', 'Unknown errors where encountered when saving.')); if (isset($cookie) && is_object($cookie)) { $result->appendChild($cookie); } return false; } } return $entry; }
public static function findEntries($entries, Section $section) { $entries = explode(',', $entries); $ret = EntryManager::fetch($entries, $section->get('id')); if ($ret === false) { self::throwEx('An error occurred while processing entries'); } return $ret; }
public function appendScriptToHead($context) { $this->static_section_name = ''; $entryManager = new EntryManager($this->_Parent); $sections = $this->_Parent->Database->fetch("SELECT section_id AS id, handle FROM tbl_fields_static_section LEFT JOIN tbl_sections ON tbl_fields_static_section.section_id = tbl_sections.id"); $this->section_data = array('handles' => array(), 'entries' => array()); foreach ($sections as $key => $value) { $this->section_data['handles'][] = $value['handle']; $result = $entryManager->fetch(NULL, $value['id'], NULL, NULL, NULL, NULL, false, false); if (count($result) > 0) { $this->section_data['entries'][] = $result[0]['id']; } else { $this->section_data['entries'][] = NULL; } } $this->_page = Administration::instance()->Page; $section_handle = $this->_page->_context['section_handle']; $context = $this->_page->_context['page']; $url_entry = $this->_page->_context['entry_id']; $flag = $this->_page->_context['flag']; if (isset($section_handle)) { $section = $this->_Parent->Database->fetchRow(0, "SELECT id, name FROM tbl_sections WHERE handle='{$section_handle}'"); $field = $this->_Parent->Database->fetchRow(0, "SELECT id FROM tbl_fields_static_section WHERE section_id=" . $section['id']); if ($field) { $entry = $this->getSectionEntry($section_handle); if ($context == 'new' && $entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/edit/' . $entry . '/'); } if ($context == 'index') { if ($entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/edit/' . $entry . '/'); } else { redirect(URL . '/symphony/publish/' . $section_handle . '/new/'); } } if ($context == 'edit') { if (!$entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/new/'); } if ($url_entry != $entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/edit/' . $entry . '/'); } } if ($flag == 'saved' || $flag == 'created') { $flag_msg = 'Entry updated at %1$s.'; if ($flag == 'created') { $flag_msg = 'Entry created at %1$s.'; } $this->_page->pageAlert(__($flag_msg, array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__))), Alert::SUCCESS); } $this->static_section_name = $section['name']; } } }
public static function delete() { $entry = EntryManager::fetch(self::$_entry_id); if (!$entry) { REST_API::sendError('Entry not found.', 404); } else { EntryManager::delete(self::$_entry_id); $response = new XMLElement('response', NULL, array('id' => self::$_entry_id, 'result' => 'success', 'type' => 'deleted')); $response->appendChild(new XMLElement('message', 'Entry deleted successfully.')); REST_API::sendOutput($response); } }
function __filterEntries($subsection_id, $fields, $filter, $entry_id) { // Fetch taglist, select and upload fields $tag_fields = array(); foreach ($fields as $field) { if (in_array($field->get('type'), array('taglist', 'select'))) { $tag_fields[] = $field->get('id'); } } // Fetch entry data $entryManager = new EntryManager($this->_Parent); $entries = $entryManager->fetch($entry_id, $subsection_id); // Setup filter $gogoes = array(); $nonos = array(); $filters = array(); if ($filter != '') { $filters = explode(', ', $filter); } foreach ($filters as $filter) { $operator = substr($filter, 0, 1); if ($operator == '-') { $nonos[] = substr($filter, 1); } else { $gogoes[] = $filter; } } // Filter entries and add select options $field_data = array(); if (is_array($entries) && !empty($entries)) { foreach ($entries as $entry) { // Collect taglist and select field values $tags = array(); foreach ($tag_fields as $field_id) { $tag_values = $entry_data[$field_id]['value']; if (!is_array($tag_values)) { $tag_values = array($tag_values); } $tags = array_merge($tags, $tag_values); } // Investigate entry exclusion $filter_nonos = array_intersect($tags, $nonos); // Investigate entry inclusion $filter_gogoes = array_intersect($tags, $gogoes); // Filter entries if (empty($filter_nonos) && (!empty($filter_gogoes) || empty($gogoes))) { $entry_data[] = array('data' => $entry->getData(), 'id' => $entry->get('id')); } } } // Return filtered entry data return $entry_data; }
/** * Builds captions based on $_POST values. * * @return json object - { id: caption } */ public function __viewIndex() { $related_section_id = intval($_POST['related_section_id']); $field_id = intval($_POST['field_id']); $items = explode(',', $_POST['items']); $id = array(); foreach ($items as $item) { array_push($id, intval($item)); } // fetch field data $sectionManager = new SectionManager($this->_Parent); $section = $sectionManager->fetch($related_section_id, 'ASC', 'name'); $fields = $section->fetchFields(); // fetch entry data $entryManager = new EntryManager($this->_Parent); $entries = $entryManager->fetch($id, $related_section_id); // create formated captions $result = array(); $template = Administration::instance()->Database->fetch("SELECT `caption` \n\t\t\t\tFROM `tbl_fields_mediathek` \n\t\t\t\tWHERE `related_section_id` = " . $related_section_id . " \n\t\t\t\tAND `field_id`= " . $field_id . " \n\t\t\t\tLIMIT 0 , 1"); $template = $template[0]['caption']; if (empty($template)) { $template = '{$' . $fields[0]->get('element_name') . '}'; } foreach ($entries as $entry) { $caption = $template; $file = ''; $entry_data = $entry->getData(); foreach ($fields as $field) { $field_name = $field->get('element_name'); $field_id = $field->get('id'); $field_data = $entry_data[$field_id]['value']; if (is_array($field_data)) { $field_value = implode(', ', $field_data); } elseif (empty($field_data) && $entry_data[$field_id]['file']) { $field_value = $entry_data[$field_id]['file']; } else { $field_value = $field_data; } $caption = str_replace('{$' . $field_name . '}', $field_value, $caption); // get file if (strpos($field->get('type'), 'upload') !== false && !empty($entry_data[$field->get('id')]['file'])) { $file = $this->buildAttachment($entry_data[$field->get('id')]['file']); } } $result[$entry->_fields['id']] = '<span>' . $caption . '</span>' . $file; } if (empty($result)) { exit; } echo json_encode($result); exit; }
/** * Get the ID of the last entry. Last == sorting by the field from Section index * * @param $section * @see LSE::getSection() * * @return int|null */ public static function getLastEntryID($section = null) { if (!($s = self::getSection($section))) { return null; } EntryManager::setFetchSortingDirection('DESC'); $entry = EntryManager::fetch(null, $s->get('id'), 1); if (!is_array($entry) || empty($entry)) { return null; } $entry = current($entry); $id = (int) $entry->get('id'); return $id; }
public function view() { $entryManager = new EntryManager(Administration::instance()); $field = $entryManager->fieldManager->fetch($_GET['field']); $section = $entryManager->sectionManager->fetch($field->get('parent_section')); $entry_column = current($section->fetchVisibleColumns()); // Display the first column from every entry in the linked section $entries = $entryManager->fetch(null, $field->get('parent_section')); foreach ($entries as $entry) { $values = $entry->getData($entry_column->get('id')); $el = new XMLElement("entry", General::sanitize($values['value'])); $el->setAttribute('id', $entry->get('id')); $this->_Result->appendChild($el); } }
public function __viewIndex() { header('content-type: text/javascript'); $sm = new SectionManager($this->_Parent); $section_id = $sm->fetchIDFromHandle($_GET['section']); $section = $sm->fetch($section_id); $em = new EntryManager($this->_Parent); $entry_id = $_GET['entry']; $e = $em->fetch($entry_id); $fields = array(); $data = $e[0]->getData(); foreach ($section->fetchFieldsSchema() as $field) { // Set field names and take strange date field name into account $field['element_name'] = $field['type'] == 'date' ? 'fields[' . $field['element_name'] . ']' . $field['element_name'] : 'fields[' . $field['element_name'] . ']'; // Populate field elements with value, depending on field type switch ($field['type']) { case 'author': $fields[$field['element_name']] = $data[$field['id']]['author_id']; break; case 'upload': $fields[$field['element_name']] = $data[$field['id']]['file']; break; case 'selectbox_link': $fields[$field['element_name']] = $data[$field['id']]['relation_id']; break; case 'input': case 'textarea': case 'taglist': case 'select': case 'checkbox': case 'date': case 'order_entries': $fields[$field['element_name']] = $data[$field['id']]['value']; break; default: if (!empty($data[$field['id']]['value'])) { $fields[$field['element_name']] = $data[$field['id']]['value']; } else { // Fall back on first array element // Add field type to switch for accurate specification $fields[$field['element_name']] = $data[$field['id']][0]; } break; } } echo 'jQuery(document).ready(function() { jQuery(\'form\').populate(' . json_encode($fields) . ")});\n"; exit; }
function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL) { if (!isset(Administration::instance()->Page)) { return; } // work out what page we are on, get portions of the URL $callback = Administration::instance()->getPageCallback(); $entry_id = $callback['context']['entry_id']; // get an Entry object for this entry $entries = EntryManager::fetch($entry_id); if (is_array($entries)) { $entry = reset($entries); } // parse dynamic portions of the panel URL $url = $this->parseExpression($entry, $this->get('url_expression')); if (!preg_match('/^http/', $url)) { $url = URL . $url; } // create Symphony cookie to pass with each request $cookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/'; session_write_close(); $gateway = new Gateway(); $gateway->init($url); $gateway->setopt('TIMEOUT', 10); $gateway->setopt(CURLOPT_COOKIE, $cookie); $gateway->setopt(CURLOPT_SSL_VERIFYPEER, FALSE); $result = $gateway->exec(); // a unique name for this panel instance $instance_id = $callback['context']['section_handle'] . '_' . $this->get('element_name'); $container = new XMLELement('div', $result); $container->setAttribute('id', $instance_id); $container->setAttribute('class', 'inline frame'); $label = new XMLElement('label', $this->get('label')); $label->appendChild($container); $wrapper->appendChild($label); $asset_index = $this->get('id') * rand(10, 100); // add panel-specific styling $instance_css = '/html-panel/' . $instance_id . '.css'; if (file_exists(WORKSPACE . $instance_css)) { Administration::instance()->Page->addStylesheetToHead(URL . '/workspace' . $instance_css, 'screen', $asset_index++); } // add panel-specific behaviour $instance_js = '/html-panel/' . $instance_id . '.js'; if (file_exists(WORKSPACE . $instance_js)) { Administration::instance()->Page->addScriptToHead(URL . '/workspace' . $instance_js, $asset_index++); } }
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); }
public function dAdminPagePreGenerate($context) { $callback = Administration::instance()->getPageCallback(); if ($callback['context']['page'] === 'edit') { /** @var $cxt XMLElement */ $cxt = $context['oPage']->Context; if (!$cxt instanceof XMLElement) { return; } $actions = $cxt->getChildByName('ul', 0); // append list of actions if missing if (!$actions instanceof XMLElement) { $ul = new XMLelement('ul', null, array('class' => 'actions')); $cxt->appendChild($ul); $actions = $cxt->getChildByName('ul', 0); } // fetch entries $section_id = SectionManager::fetchIDFromHandle($callback['context']['section_handle']); $section = SectionManager::fetch($section_id); EntryManager::setFetchSorting($section->getSortingField(), $section->getSortingOrder()); $entries = EntryManager::fetch(null, $section_id, null, null, null, null, null, false, false); // get next and prev $entry_id = $prev_id = $next_id = $callback['context']['entry_id']; $count = count($entries); for ($i = 0; $i < $count; $i++) { if ($entries[$i]['id'] == $entry_id) { $prev_id = $i == 0 ? $entries[$count - 1]['id'] : $entries[$i - 1]['id']; $next_id = $i == $count - 1 ? $entries[0]['id'] : $entries[$i + 1]['id']; break; } } if ($prev_id == $entry_id && $next_id == $entry_id) { return; } // add buttons $li = new XMLelement('li', null, array('class' => 'entry-nav')); if ($prev_id !== $entry_id) { $li->appendChild(Widget::Anchor(__('← Previous'), SYMPHONY_URL . $callback['pageroot'] . 'edit/' . $prev_id, null, 'button entry-nav-prev', null, array('accesskey' => 'z'))); } if ($next_id !== $entry_id) { $li->appendChild(Widget::Anchor(__('Next →'), SYMPHONY_URL . $callback['pageroot'] . 'edit/' . $next_id, null, 'button entry-nav-next', null, array('accesskey' => 'x'))); } $actions->appendChild($li); } }
protected function __trigger() { self::__init(); $db = ASDCLoader::instance(); $success = false; $Members = $this->_Parent->ExtensionManager->create('members'); $Members->initialiseCookie(); if ($Members->isLoggedIn() !== true) { redirect(URL . '/forbidden/'); } $Members->initialiseMemberObject(); // Make sure we dont accidently use an expired token extension_Members::purgeCodes(); $em = new EntryManager($this->_Parent); $entry = end($em->fetch((int) $Members->Member->get('id'))); $email = $entry->getData(self::findFieldID('email-address', 'members')); $name = $entry->getData(self::findFieldID('name', 'members')); $Members->emailNewMember(array('section' => $Members->memberSectionHandle(), 'entry' => $entry, 'fields' => array('username-and-password' => $entry->getData(self::findFieldID('username-and-password', 'members')), 'name' => $name['value'], 'email-address' => $email['value']))); redirect(URL . '/members/activate/sent/'); }
public function adminPagePostCallback($context) { // check if logged in if (!Administration::instance()->isLoggedIn()) { return; } // check driver if ($context['callback']['driver'] !== 'publish') { return; } // get context $page = $context['callback']['context']['page']; $section = $context['callback']['context']['section_handle']; // check section if (!($section = SectionManager::fetchIDFromHandle($section))) { return; } if (!($section = SectionManager::fetch($section))) { return; } // check setting if ($section->get('single') !== 'yes') { return; } // set flag $this->single = true; // check page if ($page === 'edit') { return; } // check entries if ($entries = EntryManager::fetch(null, $section->get('id'), 1, 0)) { // set entry $context['callback']['context']['entry_id'] = current($entries)->get('id'); // reroute $context['callback']['context']['page'] = 'edit'; } else { // reroute $context['callback']['context']['page'] = 'new'; } }
/** * Returns an Entry object given an array of credentials * * @param array $credentials * @param boolean $isHashed * Defaults to false * @return integer */ public function findMemberIDFromCredentials(array $credentials, $isHashed = false) { if ((!isset($credentials['username']) || is_null($credentials['username'])) && (!isset($credentials['email']) || is_null($credentials['email']))) { return null; } $identity = $this->setIdentityField($credentials); if (!$identity instanceof Field) { return null; } // Member from Identity $member_id = $identity->fetchMemberIDBy($credentials); // Validate against Password $auth = $this->section->getField('authentication'); if (!is_null($auth)) { $member_id = $auth->fetchMemberIDBy($credentials, $member_id, $isHashed); } // No Member found, can't even begin to check Activation // Return null if (is_null($member_id)) { return null; } // Check that if there's activiation, that this Member is activated. if (!is_null($this->section->getFieldHandle('activation'))) { $entry = EntryManager::fetch($member_id, NULL, NULL, NULL, NULL, NULL, false, true, array($this->section->getFieldHandle('activation'))); $isActivated = $entry[0]->getData($this->section->getField('activation')->get('id'), true)->activated == "yes"; // If we are denying login for non activated members, lets do so now if ($this->section->getField('activation')->get('deny_login') == 'yes' && !$isActivated) { extension_Members::$_errors[$this->section->getFieldHandle('activation')] = array('message' => __('Member is not activated.'), 'type' => 'invalid', 'label' => $this->section->getField('activation')->get('label')); return null; } // If the member isn't activated and a Role field doesn't exist // just return false. if (!$isActivated && !FieldManager::isFieldUsed(extension_Members::getFieldType('role'))) { extension_Members::$_errors[$this->section->getFieldHandle('activation')] = array('message' => __('Member is not activated.'), 'type' => 'invalid', 'label' => $this->section->getField('activation')->get('label')); return false; } } return $member_id; }
protected function __trigger() { $result = new XMLElement(self::ROOTELEMENT); self::__init(); $db = ASDCLoader::instance(); $success = false; $Members = Frontend::instance()->ExtensionManager->create('members'); $Members->initialiseCookie(); if ($Members->isLoggedIn() !== true) { $result->appendChild(new XMLElement('error', 'Must be logged in.')); $result->setAttribute('status', 'error'); return $result; } $Members->initialiseMemberObject(); // Make sure we dont accidently use an expired code extension_Members::purgeCodes(); $activation_row = $db->query(sprintf("SELECT * FROM `tbl_members_codes` WHERE `code` = '%s' AND `member_id` = %d LIMIT 1", $db->escape($_POST['fields']['code']), (int) $Members->Member->get('id')))->current(); // No code, you are a spy! if ($activation_row === false) { $success = false; $result->appendChild(new XMLElement('error', 'Activation failed. Code was invalid.')); } else { // Got this far, all is well. $db->query(sprintf("UPDATE `tbl_entries_data_%d` SET `role_id` = %d WHERE `entry_id` = %d LIMIT 1", $Members->roleField(), Symphony::Configuration()->get('new_member_default_role', 'members'), (int) $Members->Member->get('id'))); extension_Members::purgeCodes((int) $Members->Member->get('id')); $em = new EntryManager($this->_Parent); $entry = end($em->fetch((int) $Members->Member->get('id'))); $email = $entry->getData(self::findFieldID('email-address', 'members')); $name = $entry->getData(self::findFieldID('name', 'members')); $Members->emailNewMember(array('section' => $Members->memberSectionHandle(), 'entry' => $entry, 'fields' => array('username-and-password' => $entry->getData(self::findFieldID('username-and-password', 'members')), 'name' => $name['value'], 'email-address' => $email['value']))); $success = true; } if ($success == true && isset($_REQUEST['redirect'])) { redirect($_REQUEST['redirect']); } $result->setAttribute('status', $success === true ? 'success' : 'error'); return $result; }
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; }
/** * 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 __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 __actionIndex() { $checked = @array_keys($_POST['items']); if (is_array($checked) && !empty($checked)) { switch ($_POST['with-selected']) { case 'delete': $sectionManager = new SectionManager($this->_Parent); foreach ($checked as $section_id) { $sectionManager->delete($section_id); } redirect(URL . '/symphony/blueprints/sections/'); break; case 'delete-entries': $entryManager = new EntryManager($this->_Parent); foreach ($checked as $section_id) { $entries = $entryManager->fetch(NULL, $section_id, NULL, NULL, NULL, NULL, false, false); $entry_ids = array(); foreach ($entries as $entry) { $entry_ids[] = $entry['id']; } $entryManager->delete($entry_ids); } redirect(URL . '/symphony/blueprints/sections/'); break; } } }
private function getXML($position = 0, $entry_id = NULL) { // Cache stuff that can be reused between filter fields and entries static $post; static $postValues; // Remember if $post contains multiple entries or not static $expectMultiple; $xml = new XMLElement('data'); // Get post values if (empty($postValues) || $position > 0) { // TODO: handle post of multiple entries at the same time if (empty($post)) { $post = General::getPostData(); // Check if post contains multiple entries or not // TODO: make some hidden field required for post, so we can check for sure // if $post['fields'][0]['conditionalizer'] exists? $expectMultiple = is_array($post['fields']) && is_array($post['fields'][0]) ? true : false; } if (!empty($post['fields']) && is_array($post['fields'])) { $postValues = new XMLElement('post'); if ($expectMultiple == true) { if (!empty($entry_id) && isset($post['id'])) { // $entry_id overrides $position foreach ($post['id'] as $pos => $id) { if ($id == $entry_id) { $position = $pos; break; } } } else { if (isset($post['id'][$position]) && is_numeric($post['id'][$position])) { $entry_id = $post['id'][$position]; } } $postValues->setAttribute('position', $position); General::array_to_xml($postValues, $post['fields'][$position], false); } else { if ($position < 1) { if (empty($entry_id) && isset($post['id']) && is_numeric($post['id'])) { $entry_id = $post['id']; } General::array_to_xml($postValues, $post['fields'], false); } else { // TODO: add error element? } } } } if (!empty($postValues)) { $xml->appendChild($postValues); } // Get old entry $entry = NULL; if (!class_exists('EntryManager')) { include_once TOOLKIT . '/class.entrymanager.php'; } if (!empty($entry_id)) { $entry = EntryManager::fetch($entry_id); $entry = $entry[0]; if (is_object($entry)) { $entry_xml = new XMLElement('old-entry'); $entry_xml->setAttribute('position', $position); $this->appendEntryXML($entry_xml, $entry); $xml->appendChild($entry_xml); } else { $entry = NULL; } } else { $entry = EntryManager::create(); $entry->set('section_id', $this->get('parent_section')); } // Set new entry data. Code found in event.section.php: // https://github.com/symphonycms/symphony-2/blob/29244318e4de294df780513ee027edda767dd75a/symphony/lib/toolkit/events/event.section.php#L99 if (is_object($entry)) { self::$recursion = true; if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($expectMultiple ? $post['fields'][$position] : $post['fields'], $errors, $entry->get('id') ? true : false)) { // Return early - other fields will mark their errors self::$recursion = false; return self::__OK__; } else { if (__ENTRY_OK__ != $entry->setDataFromPost($expectMultiple ? $post['fields'][$position] : $post['fields'], $errors, true, $entry->get('id') ? true : false)) { // Return early - other fields will mark their errors. self::$recursion = false; return self::__OK__; } } self::$recursion = false; $entry_xml = new XMLElement('entry'); $entry_xml->setAttribute('position', $position); $this->appendEntryXML($entry_xml, $entry); $xml->appendChild($entry_xml); } // Get author if ($temp = Symphony::Engine()->Author) { $author = new XMLElement('author'); $author->setAttribute('id', $temp->get('id')); $author->setAttribute('user_type', $temp->get('user_type')); $author->setAttribute('primary', $temp->get('primary')); $author->setAttribute('username', $temp->get('username')); $author->setAttribute('first_name', $temp->get('first_name')); $author->setAttribute('last_name', $temp->get('last_name')); $xml->appendChild($author); } return $xml; }
public static function deleteEntry($entry, $section = NULL) { if (!$entry instanceof Entry) { // build the entry $em = new EntryManager(Symphony::Engine()); $entry = reset($em->fetch($entry)); } if (!$section instanceof Section) { // build section $sm = new SectionManager(Symphony::Engine()); $section = $sm->fetch($entry->get('section_id')); } $type = self::getTypeByHandle($section->get('handle')); if (!$type) { return; } try { $type->type->deleteById($entry->get('id')); } catch (Exception $ex) { } self::getIndex()->refresh(); }
public function __actionEdit() { $entry_id = intval($this->_context['entry_id']); if (@array_key_exists('save', $_POST['action']) || @array_key_exists("done", $_POST['action'])) { if (!($ret = EntryManager::fetch($entry_id))) { Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.')); } $entry = $ret[0]; $section = SectionManager::fetch($entry->get('section_id')); $post = General::getPostData(); $fields = $post['fields']; // Initial checks to see if the Entry is ok if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $this->_errors)) { $this->pageAlert(__('Some errors were encountered while attempting to save.'), Alert::ERROR); } else { if (__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors)) { foreach ($errors as $field_id => $message) { $this->pageAlert($message, Alert::ERROR); } } else { /** * Just prior to editing of an Entry. * * @delegate EntryPreEdit * @param string $context * '/publish/edit/' * @param Section $section * @param Entry $entry * @param array $fields */ Symphony::ExtensionManager()->notifyMembers('EntryPreEdit', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields)); // Check to see if the dancing was premature if (!$entry->commit()) { define_safe('__SYM_DB_INSERT_FAILED__', true); $this->pageAlert(NULL, Alert::ERROR); } else { /** * Just after the editing of an Entry * * @delegate EntryPostEdit * @param string $context * '/publish/edit/' * @param Section $section * @param Entry $entry * @param array $fields */ Symphony::ExtensionManager()->notifyMembers('EntryPostEdit', '/publish/edit/', array('section' => $section, 'entry' => $entry, 'fields' => $fields)); $prepopulate_querystring = ''; if (isset($_POST['prepopulate'])) { foreach ($_POST['prepopulate'] as $field_id => $value) { $prepopulate_querystring .= sprintf("prepopulate[%s]=%s&", $field_id, $value); } $prepopulate_querystring = trim($prepopulate_querystring, '&'); } redirect(sprintf('%s/publish/%s/edit/%d/saved/%s', SYMPHONY_URL, $this->_context['section_handle'], $entry->get('id'), !empty($prepopulate_querystring) ? "?" . $prepopulate_querystring : NULL)); } } } } else { if (@array_key_exists('delete', $_POST['action']) && is_numeric($entry_id)) { /** * Prior to deletion of entries. An array of Entry ID's is provided which * can be manipulated. This delegate was renamed from `Delete` to `EntryPreDelete` * in Symphony 2.3. * * @delegate EntryPreDelete * @param string $context * '/publish/' * @param array $entry_id * An array of Entry ID's passed by reference */ $checked = array($entry_id); Symphony::ExtensionManager()->notifyMembers('EntryPreDelete', '/publish/', array('entry_id' => &$checked)); EntryManager::delete($checked); /** * After the deletion of entries, this delegate provides an array of Entry ID's * that were deleted. * * @since Symphony 2.3 * @delegate EntryPostDelete * @param string $context * '/publish/' * @param array $entry_id * An array of Entry ID's that were deleted. */ Symphony::ExtensionManager()->notifyMembers('EntryPostDelete', '/publish/', array('entry_id' => $checked)); redirect(SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/'); } } }
public function __viewIndex() { $this->setPageType('table'); $this->setTitle('Symphony – PayPal Payment Transactions'); $this->appendSubheading('Logs'); $this->addStylesheetToHead(URL . '/extensions/paypal_payments/assets/logs.css', 'screen', 81); $per_page = 20; $page = @(int) $_GET['pg'] > 1 ? (int) $_GET['pg'] : 1; $logs = $this->_driver->_get_logs_by_page($page, $per_page); $start = max(1, ($page - 1) * $per_page); $end = $start == 1 ? $per_page : $start + count($logs); $total = $this->_driver->_count_logs(); $pages = ceil($total / $per_page); $sectionManager = new SectionManager($this->_Parent); $entryManager = new EntryManager($this->_Parent); $th = array(array('Invoice/Entry', 'col'), array('Date', 'col'), array('Payment Type', 'col'), array('Payment Status', 'col'), array('Name', 'col'), array('Email', 'col'), array('Address', 'col'), array('Currency', 'col'), array('Tax', 'col'), array('Gross', 'col'), array('Fee', 'col'), array('Transaction Type', 'col'), array('Transaction ID', 'col')); if (!is_array($logs) or empty($logs)) { $tb = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', NULL, count($th))))); } else { foreach ($logs as $log) { $col = array(); # Spit out $log_name vars extract($log, EXTR_PREFIX_ALL, 'log'); # Get the entry/section data $entries = $entryManager->fetch($log_invoice, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE); $entry = $entries[0]; if (isset($entry)) { $section_id = $entry->_fields['section_id']; $section = $sectionManager->fetch($section_id); $column = array_shift($section->fetchFields()); $data = $entry->getData($column->get('id')); # Build link to parent section $link = URL . '/symphony/publish/' . $section->get('handle') . '/edit/' . $entry->get('id') . '/'; # Date $col[] = Widget::TableData(Widget::Anchor(General::sanitize($log_invoice), $link)); } else { $col[] = Widget::TableData(General::sanitize($log_invoice)); } $col[0]->appendChild(Widget::Input("items[{$log_id}]", NULL, 'checkbox')); if (!empty($log_payment_date)) { $col[] = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($log_payment_date))); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_payment_type)) { $col[] = Widget::TableData(General::sanitize(ucwords($log_payment_type))); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_payment_status)) { $col[] = Widget::TableData(General::sanitize($log_payment_status)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_first_name) && !empty($log_last_name)) { $col[] = Widget::TableData(General::sanitize($log_first_name) . " " . General::sanitize($log_last_name)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_payer_email)) { $col[] = Widget::TableData(General::sanitize($log_payer_email)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_address_street)) { $col[] = Widget::TableData(General::sanitize($log_address_street)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_mc_currency)) { $col[] = Widget::TableData(General::sanitize($log_mc_currency)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_tax)) { $col[] = Widget::TableData(General::sanitize($log_tax)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_mc_gross)) { $col[] = Widget::TableData(General::sanitize($log_mc_gross)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_mc_fee)) { $col[] = Widget::TableData(General::sanitize($log_mc_fee)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_txn_type)) { $col[] = Widget::TableData(General::sanitize($log_txn_type)); } else { $col[] = Widget::TableData('None', 'inactive'); } if (!empty($log_txn_id)) { $col[] = Widget::TableData(General::sanitize($log_txn_id)); } else { $col[] = Widget::TableData('None', 'inactive'); } $tr = Widget::TableRow($col); if ($log_payment_status == 'Denied') { $tr->setAttribute('class', 'denied'); } $tb[] = $tr; } } $table = Widget::Table(Widget::TableHead($th), NULL, Widget::TableBody($tb)); $this->Form->appendChild($table); $actions = new XMLElement('div'); $actions->setAttribute('class', 'actions'); $options = array(array(NULL, FALSE, 'With Selected...'), array('delete', FALSE, 'Delete')); $actions->appendChild(Widget::Select('with-selected', $options)); $actions->appendChild(Widget::Input('action[apply]', 'Apply', 'submit')); $this->Form->appendChild($actions); # Pagination: if ($pages > 1) { $ul = new XMLElement('ul'); $ul->setAttribute('class', 'page'); ## First $li = new XMLElement('li'); if ($page > 1) { $li->appendChild(Widget::Anchor('First', $this->_Parent->getCurrentPageURL() . '?pg=1')); } else { $li->setValue('First'); } $ul->appendChild($li); ## Previous $li = new XMLElement('li'); if ($page > 1) { $li->appendChild(Widget::Anchor('← Previous', $this->_Parent->getCurrentPageURL() . '?pg=' . ($page - 1))); } else { $li->setValue('← Previous'); } $ul->appendChild($li); ## Summary $li = new XMLElement('li', 'Page ' . $page . ' of ' . max($page, $pages)); $li->setAttribute('title', 'Viewing ' . $start . ' - ' . $end . ' of ' . $total . ' entries'); $ul->appendChild($li); ## Next $li = new XMLElement('li'); if ($page < $pages) { $li->appendChild(Widget::Anchor('Next →', $this->_Parent->getCurrentPageURL() . '?pg=' . ($page + 1))); } else { $li->setValue('Next →'); } $ul->appendChild($li); ## Last $li = new XMLElement('li'); if ($page < $pages) { $li->appendChild(Widget::Anchor('Last', $this->_Parent->getCurrentPageURL() . '?pg=' . $pages)); } else { $li->setValue('Last'); } $ul->appendChild($li); $this->Form->appendChild($ul); } }