本文整理汇总了PHP中EntryManager::create方法的典型用法代码示例。如果您正苦于以下问题:PHP EntryManager::create方法的具体用法?PHP EntryManager::create怎么用?PHP EntryManager::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntryManager
的用法示例。
在下文中一共展示了EntryManager::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createEntryFromPost
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;
}
示例2: __doit
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;
}
示例3: symHaveEntryInDatabase
public function symHaveEntryInDatabase($section, $data)
{
$sectionId = \SectionManager::fetchIDFromHandle($section);
$entry = \EntryManager::create();
$entry->set('section_id', $sectionId);
if ($entry->setDataFromPost($data) == __ENTRY_FIELD_ERROR__) {
throw 'Error setting data';
}
$entry->commit();
return $entry->get('id');
}
示例4: unserializeEntry
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;
}
示例5: __doit
/**
* This function does the bulk of processing the Event, from running the delegates
* to validating the data and eventually saving the data into Symphony. The result
* of the Event is returned via the `$result` parameter.
*
* @param array $fields
* An array of $_POST data, to process and add/edit an entry.
* @param XMLElement $result
* The XMLElement contains the result of the Event, it is passed by
* reference.
* @param integer $position
* When the Expect Multiple filter is added, this event should expect
* to deal with adding (or editing) multiple entries at once.
* @param integer $entry_id
* If this Event is editing an existing entry, that Entry ID will
* be passed to this function.
* @return XMLElement
* The result of the Event
*/
public function __doit($fields, XMLElement &$result, $position = null, $entry_id = null)
{
$post_values = new XMLElement('post-values');
if (!is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
// Check to see if the Section of this Event is valid.
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;
}
// Create the post data element
if (is_array($fields) && !empty($fields)) {
General::array_to_xml($post_values, $fields, true);
}
// If the EventPreSaveFilter fails, return early
if ($this->processPreSaveFilters($result, $fields, $post_values, $entry_id) === false) {
return false;
}
// If the `$entry_id` is provided, check to see if it exists.
// @todo If this was moved above PreSaveFilters, we can pass the
// Entry object to the delegate meaning extensions don't have to
// do that step.
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());
}
// Validate the data. `$entry->checkPostData` loops over all fields calling
// checkPostFieldData function. If the return of the function is `__ENTRY_FIELD_ERROR__`
// then abort the event, adding the error messages to the `$result`.
if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, $entry->get('id') ? true : false)) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
} else {
if (__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, $entry->get('id') ? true : false)) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
} else {
if ($entry->commit() === false) {
$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;
} else {
$result->setAttributeArray(array('result' => 'success', 'type' => isset($entry_id) ? 'edited' : 'created', 'id' => $entry->get('id')));
$result->appendChild(new XMLElement('message', isset($entry_id) ? __('Entry edited successfully.') : __('Entry created successfully.')));
}
}
}
// PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
$result = $this->processSendMailFilter($result, $_POST['send-email'], $fields, $section, $entry);
}
$result = $this->processPostSaveFilters($result, $fields, $entry);
$result = $this->processFinalSaveFilters($result, $fields, $entry);
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return true;
}
示例6: SectionManager
function __viewEdit()
{
$sectionManager = new SectionManager($this->_Parent);
if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
$this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle'])), false, true);
}
$section = $sectionManager->fetch($section_id);
$entry_id = intval($this->_context['entry_id']);
$entryManager = new EntryManager($this->_Parent);
$entryManager->setFetchSorting('id', 'DESC');
if (!($existingEntry = $entryManager->fetch($entry_id))) {
$this->_Parent->customError(E_USER_ERROR, __('Unknown Entry'), __('The entry you are looking for could not be found.'), false, true);
}
$existingEntry = $existingEntry[0];
// If there is post data floating around, due to errors, create an entry object
if (isset($_POST['fields'])) {
$fields = $_POST['fields'];
$entry =& $entryManager->create();
$entry->set('section_id', $existingEntry->get('section_id'));
$entry->set('id', $entry_id);
$entry->setDataFromPost($fields, $error, true);
} else {
$entry = $existingEntry;
if (!$section) {
$section = $sectionManager->fetch($entry->get('section_id'));
}
}
if (isset($this->_context['flag'])) {
$link = 'publish/' . $this->_context['section_handle'] . '/new/';
list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3);
if (is_numeric($field_id) && $value) {
$link .= "?prepopulate[{$field_id}]={$value}";
}
switch ($flag) {
case 'saved':
$this->pageAlert(__('Entry updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
break;
case 'created':
$this->pageAlert(__('Entry created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
break;
}
}
### Determine the page title
$field_id = $this->_Parent->Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1");
$field = $entryManager->fieldManager->fetch($field_id);
$title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id)));
if (trim($title) == '') {
$title = 'Untitled';
}
$this->setPageType('form');
$this->Form->setAttribute('enctype', 'multipart/form-data');
$this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), $section->get('name'), $title)));
$this->appendSubheading($title);
$this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', $this->_Parent->Configuration->get('max_upload_size', 'admin'), 'hidden'));
###
$primary = new XMLElement('fieldset');
$primary->setAttribute('class', 'primary');
$sidebar_fields = $section->fetchFields(NULL, 'sidebar');
$main_fields = $section->fetchFields(NULL, 'main');
if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) {
$primary->appendChild(new XMLElement('p', __('It looks like your trying to create an entry. Perhaps you want custom fields first? <a href="%s">Click here to create some.</a>', array(URL . '/symphony/blueprints/sections/edit/' . $section->get('id') . '/'))));
} else {
if (is_array($main_fields) && !empty($main_fields)) {
foreach ($main_fields as $field) {
$primary->appendChild($this->__wrapFieldWithDiv($field, $entry));
}
$this->Form->appendChild($primary);
}
if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
$sidebar = new XMLElement('fieldset');
$sidebar->setAttribute('class', 'secondary');
foreach ($sidebar_fields as $field) {
$sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry));
}
$this->Form->appendChild($sidebar);
}
}
$div = new XMLElement('div');
$div->setAttribute('class', 'actions');
$div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
$button = new XMLElement('button', __('Delete'));
$button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this entry')));
$div->appendChild($button);
$this->Form->appendChild($div);
}
示例7: log
public function log($type, $entry)
{
if (!$this->initialize()) {
return false;
}
$admin = Administration::instance();
$em = new EntryManager($admin);
$section = $this->getAuditSection();
$fields = array('author' => $entry->get('author_id'), 'created' => 'now', 'dump' => serialize($entry->getData()), 'entry' => array('source_entry' => $entry->get('id'), 'source_section' => $entry->get('section_id')), 'type' => $type);
// No auditing the audits section:
if ($entry->get('section_id') == $section->get('id')) {
return false;
}
$audit = $em->create();
$audit->set('section_id', $section->get('id'));
$audit->set('author_id', $entry->get('author_id'));
$audit->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
$audit->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
$audit->setDataFromPost($fields, $error);
$audit->commit();
}
示例8: getXML
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'));
//.........这里部分代码省略.........
示例9: __viewDo
public function __viewDo()
{
if (count($_POST) > 0 && count($this->_errors) > 0) {
if (is_array($this->_errors)) {
$this->pageAlert("\n\t\t\t\t\t\tAn error occurred while processing this form.\n\t\t\t\t\t\t<a href=\"#error\">" . $this->parseErrors() . " Rolling back.</a>", AdministrationPage::PAGE_ALERT_ERROR);
}
} elseif (count($_POST) > 0) {
$this->pageAlert("Successfully added a whole slew of entries, {$this->_entries_count} to be exact. \n\t\t\t\t\tTo do it again, <a href=\"{$this->_uri}/\">Give it another go below.</a>", Alert::SUCCESS, array('created', URL, 'extension/multipleuploadinjector'));
}
$this->setPageType('form');
$this->Form->setAttribute('enctype', 'multipart/form-data');
$this->setTitle('Symphony – Add Multiple Files From a Folder');
// // Edit:
// if ($this->_action == 'edit') {
// if (!$this->_valid && count($this->_errors) == 0)
// if (count($this->_files) > 0) {
// $this->appendSubHeading('Added '.implode(', ',$this->_files));
// }
// }
// else
$this->appendSubheading('Inject!');
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', 'Essentials'));
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('Source (where these are all going)'));
$sectionManager = new SectionManager($this->_Parent);
$sections = $sectionManager->fetch();
$options[0]['label'] = 'Sections';
foreach ($sections as $section) {
$s = $section->fetchFields();
$go = false;
foreach ($s as $f) {
if (in_array($f->get('type'), $this->_driver->getTypes())) {
$go = true;
}
}
if ($go) {
$field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section);
$options[0]['options'][] = array($section->get('id'), $_POST['fields']['source'] == $section->get('id'), $section->get('name'));
}
}
$label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context')));
$div->appendChild($label);
$label = Widget::Label(__('Directory where images are stored'));
$options = array();
$options[] = array('/workspace' . $this->_driver->getMUI(), false, '/workspace' . $this->_driver->getMUI());
$ignore = array('events', 'data-sources', 'text-formatters', 'pages', 'utilities');
$directories = General::listDirStructure(WORKSPACE . $this->_driver->getMUI(), true, 'asc', DOCROOT, $ignore);
if (!empty($directories) && is_array($directories)) {
foreach ($directories as $d) {
$d = '/' . trim($d, '/');
if (!in_array($d, $ignore)) {
$options[] = array($d, $d == '/workspace' . $this->_driver->getMUI() . '/' . date('Y-m-d') ? true : false, $d);
}
}
}
$label->appendChild(Widget::Select('fields[sourcedir]', $options));
$div->appendChild($label);
$fieldset->appendChild($div);
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
$label = Widget::Label(__('Delete directory and contents after successful import?'));
$label->appendChild(Widget::Input('fields[remove]', null, 'checkbox'));
$div->appendChild($label);
$fieldset->appendChild($div);
$this->Form->appendChild($fieldset);
/* now the section fields */
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings contextual ' . __('sections') . ' ' . __('authors') . ' ' . __('navigation') . ' ' . __('Sections') . ' ' . __('System'));
$fieldset->appendChild(new XMLElement('legend', __('Choose Default Values')));
$entryManager = new EntryManager($this->_Parent);
foreach ($field_groups as $section_id => $section_data) {
// create a dummy entry
$entry = $entryManager->create();
$entry->set('section_id', $section_id);
$div = new XMLElement('div');
$div->setAttribute('class', 'contextual ' . $section_id);
$primary = new XMLElement('fieldset');
$primary->setAttribute('class', 'primary');
$sidebar_fields = $section_data['section']->fetchFields();
// $main_fields = $section_data['section']->fetchFields(NULL, 'main');
// if(is_array($main_fields) && !empty($main_fields)){
// foreach($main_fields as $field){
// if (!in_array($field->get('type'),$this->_driver->getTypes()))
// $primary->appendChild($this->__wrapFieldWithDiv($field));
// }
// $div->appendChild($primary);
// }
if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
$sidebar = new XMLElement('fieldset');
$sidebar->setAttribute('class', 'primary');
foreach ($sidebar_fields as $field) {
if (!in_array($field->get('type'), $this->_driver->getTypes())) {
$sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry, $section_id, null, null));
}
}
$div->appendChild($sidebar);
}
//.........这里部分代码省略.........
示例10: __viewEdit
public function __viewEdit()
{
$sectionManager = new SectionManager($this->_Parent);
if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) {
Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle'])));
}
$section = $sectionManager->fetch($section_id);
$entry_id = intval($this->_context['entry_id']);
$entryManager = new EntryManager($this->_Parent);
$entryManager->setFetchSorting('id', 'DESC');
if (!($existingEntry = $entryManager->fetch($entry_id))) {
Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.'));
}
$existingEntry = $existingEntry[0];
// If there is post data floating around, due to errors, create an entry object
if (isset($_POST['fields'])) {
$fields = $_POST['fields'];
$entry =& $entryManager->create();
$entry->set('section_id', $existingEntry->get('section_id'));
$entry->set('id', $entry_id);
$entry->setDataFromPost($fields, $error, true);
} else {
$entry = $existingEntry;
if (!$section) {
$section = $sectionManager->fetch($entry->get('section_id'));
}
}
/**
* Just prior to rendering of an Entry edit form.
*
* @delegate EntryPreRender
* @param string $context
* '/publish/new/'
* @param Section $section
* @param Entry $entry
* @param array $fields
*/
Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields));
if (isset($this->_context['flag'])) {
$link = 'publish/' . $this->_context['section_handle'] . '/new/';
list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3);
if (is_numeric($field_id) && $value) {
$link .= "?prepopulate[{$field_id}]={$value}";
$this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden'));
}
switch ($flag) {
case 'saved':
$this->pageAlert(__('Entry updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
break;
case 'created':
$this->pageAlert(__('Entry created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS);
break;
}
}
### Determine the page title
$field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1");
$field = $entryManager->fieldManager->fetch($field_id);
$title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id)));
if (trim($title) == '') {
$title = 'Untitled';
}
// Check if there is a field to prepopulate
if (isset($_REQUEST['prepopulate'])) {
$field_id = array_shift(array_keys($_REQUEST['prepopulate']));
$value = stripslashes(rawurldecode(array_shift($_REQUEST['prepopulate'])));
$this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden'));
}
$this->setPageType('form');
$this->Form->setAttribute('enctype', 'multipart/form-data');
$this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), $section->get('name'), $title)));
$this->appendSubheading($title);
$this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden'));
###
$primary = new XMLElement('fieldset');
$primary->setAttribute('class', 'primary');
$sidebar_fields = $section->fetchFields(NULL, 'sidebar');
$main_fields = $section->fetchFields(NULL, 'main');
if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) {
$primary->appendChild(new XMLElement('p', __('It looks like you\'re trying to create an entry. Perhaps you want fields first? <a href="%s">Click here to create some.</a>', array(SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/'))));
} else {
if (is_array($main_fields) && !empty($main_fields)) {
foreach ($main_fields as $field) {
$primary->appendChild($this->__wrapFieldWithDiv($field, $entry));
}
$this->Form->appendChild($primary);
}
if (is_array($sidebar_fields) && !empty($sidebar_fields)) {
$sidebar = new XMLElement('fieldset');
$sidebar->setAttribute('class', 'secondary');
foreach ($sidebar_fields as $field) {
$sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry));
}
$this->Form->appendChild($sidebar);
}
}
$div = new XMLElement('div');
$div->setAttribute('class', 'actions');
$div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
$button = new XMLElement('button', __('Delete'));
$button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?')));
//.........这里部分代码省略.........
示例11: checkPostFieldData
public function checkPostFieldData($data, &$error = null, $entry_id = null)
{
$entryManager = new EntryManager($this->_engine);
$fieldManager = new FieldManager($this->_engine);
$field = $fieldManager->fetch($this->get('child_field_id'));
$status = self::__OK__;
$data = $this->getData();
// Create:
foreach ($data['entry'] as $index => $entry_data) {
$existing_id = $data['entry_id'][$index];
if (empty($existing_id)) {
$entry = $entryManager->create();
$entry->set('section_id', $this->get('child_section_id'));
$entry->set('author_id', $this->_engine->Author->get('id'));
$entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
$entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
} else {
$entry = @current($entryManager->fetch($existing_id, $this->get('child_section_id')));
}
// Create link:
if ($field) {
$entry_data[$field->get('element_name')] = array('parent_entry_id' => $entry_id);
}
// Validate:
if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($entry_data, $errors)) {
if (!empty($errors)) {
self::$errors[$this->get('id')][$index] = $errors;
}
$status = self::__INVALID_FIELDS__;
} elseif (__ENTRY_OK__ != $entry->setDataFromPost($entry_data, $error)) {
$status = self::__INVALID_FIELDS__;
}
self::$entries[$this->get('id')][] = $entry;
}
return $status;
}
示例12: validate
public function validate($data)
{
if (!function_exists('handleXMLError')) {
function handleXMLError($errno, $errstr, $errfile, $errline, $context)
{
$context['self']->_errors[] = $errstr;
}
}
if (empty($data)) {
return null;
}
$entryManager = new EntryManager($this->_Parent);
$fieldManager = new FieldManager($this->_Parent);
set_time_limit(900);
set_error_handler('handleXMLError');
$self = $this;
// Fucking PHP...
$xml = new DOMDocument();
$xml->loadXML($data, LIBXML_COMPACT);
restore_error_handler();
$xpath = new DOMXPath($xml);
$passed = true;
// Invalid Markup:
if (empty($xml)) {
$passed = false;
// Invalid Expression:
} else {
if (($entries = $xpath->query($this->getRootExpression())) === false) {
$this->_errors[] = sprintf('Root expression <code>%s</code> is invalid.', htmlentities($this->getRootExpression(), ENT_COMPAT, 'UTF-8'));
$passed = false;
// No Entries:
} else {
if (empty($entries)) {
$this->_errors[] = 'No entries to import.';
$passed = false;
// Test expressions:
} else {
foreach ($this->getFieldMap() as $field_id => $expression) {
if ($xpath->evaluate($expression) === false) {
$field = $fieldManager->fetch($field_id);
$this->_errors[] = sprintf('\'%s\' expression <code>%s</code> is invalid.', $field->get('label'), htmlentities($expression, ENT_COMPAT, 'UTF-8'));
$passed = false;
}
}
}
}
}
if (!$passed) {
return self::__ERROR_PREPARING__;
}
// Gather data:
foreach ($entries as $index => $entry) {
$this->_entries[$index] = array('element' => $entry, 'entry' => null, 'values' => array(), 'errors' => array());
foreach ($this->getFieldMap() as $field_id => $expressions) {
if (!is_array($expressions)) {
$value = $this->getExpressionValue($xml, $entry, $xpath, $expressions, $debug);
//var_dump(is_utf8($value));
} else {
$value = array();
foreach ($expressions as $name => $expression) {
$value[$name] = $this->getExpressionValue($xml, $entry, $xpath, $expression);
}
}
$this->_entries[$index]['values'][$field_id] = $value;
}
}
// Validate:
$passed = true;
foreach ($this->_entries as &$current) {
$entry = $entryManager->create();
$entry->set('section_id', $this->getSection());
$entry->set('author_id', $this->_Parent->Author->get('id'));
$entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
$entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
$values = array();
// Map values:
foreach ($current['values'] as $field_id => $value) {
$field = $fieldManager->fetch($field_id);
// Adjust value?
if (method_exists($field, 'prepareImportValue')) {
$value = $field->prepareImportValue($value);
}
$values[$field->get('element_name')] = $value;
}
// Validate:
if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($values, $current['errors'])) {
$passed = false;
} elseif (__ENTRY_OK__ != $entry->setDataFromPost($values, $error)) {
$passed = false;
}
$current['entry'] = $entry;
}
if (!$passed) {
return self::__ERROR_VALIDATING__;
}
return self::__OK__;
}
示例13: FunctionalTester
<?php
$I = new FunctionalTester($scenario);
$I->wantTo('I want to load SymphonyCMSDb Module');
$I->assertEquals($I->symphonyCMSDBTest(), 'Hello World');
$I->assertNotNull(\EntryManager::create());
示例14: sectionsPrepareEntry
/**
* Create necessary data for an Entry.
*
* @param string $section_handle
* @param array $section_filters
* @param int $position
* @param array $original_fields
*
* @return array
*/
private function sectionsPrepareEntry($section_handle, array $section_filters, $position, array $original_fields)
{
$action = null;
$entry_id = null;
$filters = array();
// determine filters
if (isset($original_fields['__filters'])) {
$filters = is_array($original_fields['__filters']) ? $original_fields['__filters'] : array($original_fields['__filters']);
unset($original_fields['__filters']);
}
$filters = array_replace_recursive($section_filters, $filters);
// determine entry_id
if (isset($original_fields['__system-id'])) {
$entry_id = $original_fields['__system-id'];
if (is_array($entry_id)) {
$entry_id = current($entry_id);
}
unset($original_fields['__system-id']);
}
// determine action
if (isset($original_fields['__action'])) {
$action = $original_fields['__action'];
unset($original_fields['__action']);
} elseif (is_numeric($entry_id)) {
$action = SE_Permissions::ACTION_EDIT;
} else {
$action = SE_Permissions::ACTION_CREATE;
}
// check permissions
if (isset($original_fields['__skip-permissions'])) {
$perm_check = false;
} else {
$perm_check = true;
}
unset($original_fields['__skip-permissions']);
$fields = $original_fields;
$res_entry = new XMLElement('entry', null, array('action' => $action));
$done = false;
$entry = null;
// validate $action & get the Entry object
switch ($action) {
case SE_Permissions::ACTION_CREATE:
$entry = EntryManager::create();
$entry->set('section_id', SectionManager::fetchIDFromHandle($section_handle));
break;
case SE_Permissions::ACTION_EDIT:
case SE_Permissions::ACTION_DELETE:
$entry = EntryManager::fetch($entry_id);
$entry = $entry[0];
if (!$entry instanceof Entry) {
$this->error = true;
$done = true;
$this->resultEntry($res_entry, 'error', __('The Entry `%d` could not be found.', array($entry_id)));
}
break;
default:
$done = true;
$this->resultEntry($res_entry, 'error', __('Requested action `%s` is not supported.', array($action)));
break;
}
// fire PreSaveFilter
$res_filters = new XMLElement('filters');
if (!$done) {
if (!$this->filtersProcessPrepare($res_filters, $section_handle, $entry, $fields, $original_fields, $filters, $action)) {
$this->error = true;
$this->resultEntry($res_entry, 'error');
}
}
return array('action' => $action, 'id' => $entry_id, 'perm_check' => $perm_check, 'entry' => $entry, 'orig_fields' => $original_fields, 'fields' => $fields, 'filters' => $filters, 'done' => $done, 'result' => new XMLElement('entry', null, array('position' => $position)), 'res_entry' => $res_entry, 'res_fields' => new XMLElement('fields'), 'res_filters' => $res_filters);
}
示例15: grab
public function grab(array &$param_pool = NULL)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
$result->setAttribute('type', 'section-schema');
// retrieve this section
$section_id = SectionManager::fetchIDFromHandle($this->dsParamSECTION);
$section = SectionManager::fetch($section_id);
$result->setAttribute('id', $section_id);
$result->setAttribute('handle', $section->get('handle'));
$entry_count = EntryManager::fetchCount($section_id);
$result->setAttribute('total-entries', $entry_count);
// instantiate a dummy entry to instantiate fields and default values
$entry = EntryManager::create();
$entry->set('section_id', $section_id);
$section_fields = $section->fetchFields();
// for each field in the section
foreach ($section_fields as $section_field) {
$field = $section_field->get();
// Skip fields that have not been selected:
if (!in_array($field['element_name'], $this->dsParamFIELDS)) {
continue;
}
$f = new XMLElement($field['element_name']);
$f->setAttribute('required', $field['required']);
foreach ($field as $key => $value) {
// Core attributes, these are common to all fields
if (in_array($key, array('id', 'type', 'required', 'label', 'location', 'show_column', 'sortorder'))) {
$f->setattribute(Lang::createHandle($key), General::sanitize($value));
}
/*
Other properties are output as element nodes. Here we filter those we
definitely don't want. Fields can have any number of properties, so it
makes sense to filter out those we don't want rather than explicitly
choose the ones we do.
*/
if (!in_array($key, array('id', 'type', 'required', 'label', 'show_column', 'sortorder', 'element_name', 'parent_section', 'location', 'field_id', 'related_field_id', 'static_options', 'dynamic_options', 'pre_populate_source', 'limit', 'allow_author_change'))) {
if (strlen($value) > 0) {
$f->appendChild(new XMLElement(Lang::createHandle($key), General::sanitize($value)));
}
}
}
// Allow a field to define its own schema XML:
if (method_exists($section_field, 'appendFieldSchema')) {
$section_field->appendFieldSchema($f);
$result->appendChild($f);
continue;
}
// check that we can safely inspect output of displayPublishPanel (some custom fields do not work)
if (in_array($field['type'], self::$_incompatible_publishpanel)) {
continue;
}
// grab the HTML used in the Publish entry form
$html = new XMLElement('html');
$section_field->displayPublishPanel($html);
$dom = new DomDocument();
$dom->loadXML($html->generate());
$xpath = new DomXPath($dom);
$options = new XMLElement('options');
// find optgroup elements (primarily in Selectbox Link fields)
foreach ($xpath->query("//*[name()='optgroup']") as $optgroup) {
$optgroup_element = new XMLElement('optgroup');
$optgroup_element->setAttribute('label', $optgroup->getAttribute('label'));
// append child options of this group
foreach ($optgroup->getElementsByTagName('option') as $option) {
$this->__appendOption($option, $optgroup_element, $field);
}
$options->appendChild($optgroup_element);
}
// find options that aren't children of groups, and list items (primarily for Taglists)
foreach ($xpath->query("//*[name()='option' and not(parent::optgroup)] | //*[name()='li']") as $option) {
$this->__appendOption($option, $options, $field);
}
if ($options->getNumberOfChildren() > 0) {
$f->appendChild($options);
}
/*
When an input has a value and is a direct child of the label, we presume we may need
its value (e.g. a pre-populated Date, Order Entries etc.)
*/
$single_input_value = $xpath->query("//label/input[@value!='']")->item(0);
if ($single_input_value) {
$f->appendChild(new XMLElement('initial-value', $single_input_value->getAttribute('value')));
}
$result->appendChild($f);
}
return $result;
}