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/');
 }
 public function view()
 {
     $section_handle = (string) $this->context[0];
     $page = isset($this->context[1]) ? (int) $this->context[1] : 1;
     if (empty($section_handle)) {
         die('Invalid section handle');
     }
     $config = (object) Symphony::Configuration()->get('elasticsearch');
     ElasticSearch::init();
     $type = ElasticSearch::getTypeByHandle($section_handle);
     if ($page === 1) {
         // delete all documents in this index
         $query = new Elastica_Query(array('query' => array('match_all' => array())));
         $type->type->deleteByQuery($query);
     }
     // get new entries
     $em = new EntryManager(Symphony::Engine());
     $entries = $em->fetchByPage($page, $type->section->get('id'), (int) $config->{'reindex-batch-size'}, NULL, NULL, FALSE, FALSE, TRUE);
     foreach ($entries['records'] as $entry) {
         ElasticSearch::indexEntry($entry, $type->section);
     }
     $entries['total-entries'] = 0;
     // last page, count how many entries in the index
     if ($entries['remaining-pages'] == 0) {
         // wait a few seconds, allow HTTP requests to complete...
         sleep(5);
         $entries['total-entries'] = $type->type->count();
     }
     header('Content-type: application/json');
     echo json_encode(array('pagination' => array('total-pages' => (int) $entries['total-pages'], 'total-entries' => (int) $entries['total-entries'], 'remaining-pages' => (int) $entries['remaining-pages'], 'next-page' => $page + 1)));
     exit;
 }
 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 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 __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 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'];
         }
     }
 }
Example #8
0
 private function __deleteMembers($role_id)
 {
     $sql = "SELECT `entry_id` FROM `tbl_entries_data_" . $this->_driver->roleField() . "` WHERE `role_id` = {$role_id}";
     $members = Administration::Database()->fetchCol('entry_id', $sql);
     ###
     # Delegate: Delete
     # Description: Prior to deletion of entries. Array of Entries is provided.
     #              The array can be manipulated
     Administration::instance()->ExtensionManager->notifyMembers('Delete', '/publish/', array('entry_id' => &$checked));
     $entryManager = new EntryManager($this->_Parent);
     $entryManager->delete($members);
 }
 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;
 }
Example #10
0
 /**
  * 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;
 }
 function grab($param = array())
 {
     extract($this->_env, EXTR_PREFIX_ALL, 'env');
     include_once TOOLKIT . '/class.entrymanager.php';
     $entryManager = new EntryManager($this->_parent);
     $section_id = $entryManager->fetchSectionIDFromHandle($this->__resolveDefine("dsFilterPARENTSECTION"));
     $schema = $entryManager->fetchEntryFieldSchema($section_id, NULL, $this->_dsFilterCUSTOMFIELD);
     $schema = $schema[0];
     ##Check the cache
     $hash_id = md5(get_class($this));
     if ($param['caching'] && ($cache = $this->check_cache($hash_id))) {
         return $cache;
         exit;
     }
     ##------------------------------
     ##Create the XML container
     $xml = new XMLElement("categories-list");
     $xml->setAttribute("section", "customfield");
     ##Populate the XML
     if (empty($schema) || !is_array($schema)) {
         $xml->addChild(new XMLElement("error", "No Records Found."));
         return $xml;
     } else {
         $ops = preg_split('/,/', $schema['values'], -1, PREG_SPLIT_NO_EMPTY);
         $ops = array_map("trim", $ops);
         $xml->addChild(new XMLElement("name", $schema['name']));
         $xml->setAttribute("handle", $schema['handle']);
         $options = new XMLElement("options");
         foreach ($ops as $o) {
             if ($schema['type'] == 'multiselect') {
                 $table = 'tbl_entries2customfields_list';
             } else {
                 $table = 'tbl_entries2customfields';
             }
             $count = $this->_db->fetchVar('count', 0, "SELECT count(id) AS `count` FROM `{$table}` WHERE `field_id` = '" . $schema['id'] . "' AND value_raw = '{$o}' ");
             $xO = new XMLElement("option", $o);
             $xO->setAttribute('entry-count', $count);
             $xO->setAttribute('handle', Lang::createHandle($o, $this->_parent->getConfigVar('handle_length', 'admin')));
             $options->addChild($xO);
         }
         $xml->addChild($options);
     }
     ##------------------------------
     ##Write To Cache
     if ($param['caching']) {
         $result = $xml->generate($param['indent'], $param['indent-depth']);
         $this->write_to_cache($hash_id, $result, $this->_cache_sections);
         return $result;
     }
     return $xml;
 }
 public function unserializeEntry($entry_id, $version)
 {
     $entry = unserialize(file_get_contents(MANIFEST . '/versions/' . $entry_id . '/' . $version . '.dat'));
     $entryManager = new EntryManager(Symphony::Engine());
     $new_entry = $entryManager->create();
     $new_entry->set('id', $entry['id']);
     $new_entry->set('author_id', $entry['author_id']);
     $new_entry->set('section_id', $entry['section_id']);
     $new_entry->set('creation_date', $entry['creation_date']);
     $new_entry->set('creation_date_gmt', $entry['creation_date_gmt']);
     foreach ($entry['data'] as $field_id => $value) {
         $new_entry->setData($field_id, $value);
     }
     return $new_entry;
 }
 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);
     }
 }
Example #14
0
 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;
 }
 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;
 }
 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;
 }
 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) {
     }
 }
Example #18
0
 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;
 }
 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/');
 }
 /**
  * Fetch raw recipient data.
  *
  * Usage of the getSlice function, which also parses the XSLT for the name
  * and checks the email is recommended. This function is here mainly for
  * internal reasons.
  *
  * Be advised, this function returns an array of entry objects.
  *
  * @todo bugtesting and error handling
  * @return array
  */
 public function grab()
 {
     parent::grab();
     $where_and_joins = $this->getWhereJoinsAndGroup();
     $entries = EntryManager::fetchByPage($this->dsParamSTARTPAGE > 0 ? $this->dsParamSTARTPAGE : 1, $this->getSource(), $this->dsParamLIMIT >= 0 ? $this->dsParamLIMIT : NULL, $where_and_joins['where'], $where_and_joins['joins'], false, false, true, array_merge(array($this->emailField), $this->nameFields));
     // The count method of the entrymanager does not work properly, so this hack is needed :(
     $count = $this->getCount();
     $entries['total-entries'] = $count;
     $entries['total-pages'] = ceil($count / $this->dsParamLIMIT);
     $entries['remaining-pages'] = $entries['total-pages'] - $entries['current-page'];
     return $entries;
 }
Example #21
0
 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);
     }
 }
 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;
 }
Example #23
0
 /**
  * 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;
 }
 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(__('&larr; 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 &rarr;'), SYMPHONY_URL . $callback['pageroot'] . 'edit/' . $next_id, null, 'button entry-nav-next', null, array('accesskey' => 'x')));
         }
         $actions->appendChild($li);
     }
 }
 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);
 }
Example #28
0
 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';
     }
 }
 /**
  * Deletes a Section by Section ID, removing all entries, fields, the
  * Section and any Section Associations in that order
  *
  * @param integer $section_id
  *    The ID of the Section to delete
  * @throws DatabaseException
  * @throws Exception
  * @return boolean
  *    Returns true when completed
  */
 public static function delete($section_id)
 {
     $details = Symphony::Database()->fetchRow(0, sprintf("\n            SELECT `sortorder` FROM tbl_sections WHERE `id` = %d", $section_id));
     // Delete all the entries
     include_once TOOLKIT . '/class.entrymanager.php';
     $entries = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '{$section_id}'");
     EntryManager::delete($entries);
     // Delete all the fields
     $fields = FieldManager::fetch(null, $section_id);
     if (is_array($fields) && !empty($fields)) {
         foreach ($fields as $field) {
             FieldManager::delete($field->get('id'));
         }
     }
     // Delete the section
     Symphony::Database()->delete('tbl_sections', sprintf("\n            `id` = %d", $section_id));
     // Update the sort orders
     Symphony::Database()->query(sprintf("\n            UPDATE tbl_sections\n            SET `sortorder` = (`sortorder` - 1)\n            WHERE `sortorder` > %d", $details['sortorder']));
     // Delete the section associations
     Symphony::Database()->delete('tbl_sections_association', sprintf("\n            `parent_section_id` = %d", $section_id));
     return true;
 }
Example #30
0
 /**
  * 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;
 }