本文整理汇总了PHP中XMLElement::prependChild方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLElement::prependChild方法的具体用法?PHP XMLElement::prependChild怎么用?PHP XMLElement::prependChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::prependChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: grab
public function grab(&$param_pool)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
self::__init();
$db = ASDCLoader::instance();
$sql = "SELECT SQL_CALC_FOUND_ROWS \n\t\t\t\t\t\tpinned.entry_id AS `id`, \n\t\t\t\t\t\tpinned.value AS `pinned`, \n\t\t\t\t\t\tclosed.value AS `closed`, \n\t\t\t\t\t\tcreation_date.local AS `creation-date`,\n\t\t\t\t\t\tlast_active.local AS `last-active`,\t\t\t\t\t\t\t\n\t\t\t\t\t\tcreated_by.member_id AS `created-by-member-id`,\n\t\t\t\t\t\tcreated_by.username AS `created-by-username`,\n\t\t\t\t\t\tlast_post.member_id AS `last-post-member-id`,\n\t\t\t\t\t\tlast_post.username AS `last-post-username`,\t\t\t\t\t\t\t\n\t\t\t\t\t\ttopic.value AS `topic`,\n\t\t\t\t\t\tCOUNT(comments.relation_id) AS `comments`\n\t\t\t\t\t\n\t\t\t\t\tFROM `tbl_entries_data_%d` AS `pinned`\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id\t\t\t\t\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id\n\t\t\t\t\tWHERE 1 %s\n\t\t\t\t\tGROUP BY pinned.entry_id\n\t\t\t\t\tORDER BY pinned.value ASC, last_active.local DESC\n\t\t\t\t\tLIMIT %d, %d";
try {
$rows = $db->query(sprintf($sql, self::findFieldID('pinned', 'discussions'), self::findFieldID('closed', 'discussions'), self::findFieldID('creation-date', 'discussions'), self::findFieldID('last-active', 'discussions'), self::findFieldID('created-by', 'discussions'), self::findFieldID('last-post', 'discussions'), self::findFieldID('topic', 'discussions'), self::findFieldID('parent-id', 'comments'), isset($this->dsParamFILTERS['id']) && (int) $this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id = " . (int) $this->dsParamFILTERS['id'] : NULL, max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT));
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
return $result;
}
if ($rows->length() == 0 && strlen(trim($dsParamFILTERS['id'])) > 0) {
$this->__redirectToErrorPage();
} elseif ($rows->length() == 0) {
return $this->emptyXMLSet();
}
$total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total;
$result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE));
/*
stdClass Object
(
[id] => 666
[pinned] => yes
[closed] => no
[creation-date] => 1233599808
[last-active] => 1237161637
[created-by-member-id] => 2126
[created-by-username] => Lewis
[last-post-member-id] => 2126
[last-post-username] => Lewis
[topic] => Symphony 2 Documentation
[comments] => 18
)
<entry id="595" comments="7">
<created-by id="2150">newnomad</created-by>
<closed>No</closed>
<last-active time="18:30" weekday="1">2009-02-09</last-active>
<last-post id="2150">newnomad</last-post>
<pinned>No</pinned>
<topic handle="viewing-feeds">viewing feeds</topic>
<creation-date time="19:31" weekday="3">2009-01-07</creation-date>
</entry>
*/
$param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id');
foreach ($rows as $r) {
$entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $r->comments));
$entry->appendChild(new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'})));
$entry->appendChild(new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'})));
$entry->appendChild(new XMLElement('closed', ucfirst($r->closed)));
$entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned)));
$entry->appendChild(new XMLElement('topic', General::sanitize($r->topic)));
$entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date'));
$entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active'));
$result->appendChild($entry);
}
return $result;
}
示例2: grab
public function grab(&$param_pool)
{
self::__init();
/*
var $dsParamINCLUDEDELEMENTS = array(
'system:pagination',
'comment',
'date',
'created-by'
);
<pagination total-entries="28" total-pages="2" entries-per-page="20" current-page="2" />
<section id="39" handle="comments">Comments</section>
*/
$result = new XMLElement($this->dsParamROOTELEMENT);
try {
$comments = ASDCLoader::instance()->query(sprintf("SELECT SQL_CALC_FOUND_ROWS\n\t\t\t\t\t\t\tcomment.entry_id AS `id`,\n\t\t\t\t\t\t\tcomment.value_formatted AS `comment`, \n\t\t\t\t\t\t\tcreated_by.member_id, \n\t\t\t\t\t\t\tcreated_by.username, \n\t\t\t\t\t\t\tdate.local AS `date`,\n\t\t\t\t\t\t\temail.value AS `email`\n\n\t\t\t\t\t\tFROM `tbl_entries_data_%d` AS `comment`\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `created_by` ON comment.entry_id = created_by.entry_id\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `date` ON comment.entry_id = date.entry_id\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `email` ON created_by.member_id = email.entry_id\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `discussion` ON comment.entry_id = discussion.entry_id\n\t\t\t\t\t\tWHERE discussion.relation_id = %d\n\t\t\t\t\t\tORDER BY date.local ASC\n\t\t\t\t\t\tLIMIT %d, %d", self::findFieldID('comment', 'comments'), self::findFieldID('created-by', 'comments'), self::findFieldID('date', 'comments'), self::findFieldID('email-address', 'members'), self::findFieldID('parent-id', 'comments'), (int) $this->dsParamFILTERS['discussion_id'], max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), (int) $this->dsParamLIMIT));
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', ASDCLoader::instance()->lastError()))));
return $result;
}
if ($comments->length() == 0) {
$this->__redirectToErrorPage();
}
$total = ASDCLoader::instance()->query('SELECT FOUND_ROWS() AS `total`;')->current()->total;
$result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE));
foreach ($comments as $c) {
/*
stdClass Object
(
[id] => 20589
[comment] => <p>blah blah</p>
[member_id] => 2103
[username] => Alistair
[date] => 1241576727
[email] => alistair@21degrees.com.au
)
<entry id="20515">
<date time="01:32" weekday="3">2009-05-06</date>
<comment word-count="6"><p>This site looks awesome guys! Congrats!</p></comment>
<created-by id="2694">davethegr8</created-by>
</entry>
*/
$entry = new XMLElement('entry', NULL, array('id' => $c->id));
$entry->appendChild(new XMLElement('created-by', General::sanitize($c->username), array('email-address-hash' => md5($c->email), 'email-address' => General::sanitize($c->email), 'id' => $c->member_id)));
$entry->appendChild(General::createXMLDateObject($c->date, 'date'));
$c->comment = str_replace(array('<script', '</script'), array('<script', '</script'), $c->comment);
$entry->appendChild(new XMLElement('comment', trim($c->comment)));
$result->appendChild($entry);
}
return $result;
}
示例3: appendAlert
/**
* If `$this->Alert` is set, it will be prepended to the Form of this page.
* A delegate is fired here to allow extensions to provide their
* their own Alert messages to the page. Note that only one Alert
* is allowed per page at any one time.
*
* @uses AppendPageAlert
*/
public function appendAlert()
{
/**
* Allows for appending of alerts. Administration::instance()->Page->Alert is way to tell what
* is currently in the system
*
* @delegate AppendPageAlert
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('AppendPageAlert', '/backend/');
if ($this->Alert instanceof Alert) {
$this->Header->prependChild($this->Alert->asXML());
}
}
示例4: appendPage
/**
* Add parent pages including current to XML output.
*
* @param array $pages - contains all pages data
* @param int $page_id - current page id
* @param array $langs - all supported language codes
* @param XMLElement $result - resulting XML
*
* @return XMLElement - a pages XML ouput
*/
private function appendPage(array $pages, $page_id, array $langs, XMLElement $result)
{
$page = $pages[$page_id];
if ($page['parent'] !== null) {
$result = $this->appendPage($pages, $page['parent'], $langs, $result);
}
$page_xml = new XMLElement('page');
$page_xml->setAttribute('handle', $page['handle']);
$page_xml->setAttribute('id', $page_id);
foreach ($langs as $lc) {
$item_xml = new XMLElement('item');
$item_xml->setValue(General::sanitize($page["plh_t-{$lc}"]));
$item_xml->setAttribute('lang', $lc);
$item_xml->setAttribute('handle', $page["plh_h-{$lc}"]);
$page_xml->prependChild($item_xml);
}
$result->appendChild($page_xml);
return $page_xml;
}
示例5: grab
public function grab(&$param_pool)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
$current_page_id = (int) $this->_env['param']['current-page-id'];
$db = ASDCLoader::instance();
try {
$results = $db->query("SELECT * FROM `tbl_pages` WHERE `id` = '{$current_page_id}' LIMIT 1");
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query "%s"', $db->lastError()))));
return $result;
}
while ($results->length() > 0) {
$current = $results->current();
$result->prependChild(new XMLElement('page', $current->title, array('path' => trim("{$current->path}/{$current->handle}", '/'))));
if (is_null($current->parent)) {
break;
}
$results = $db->query(sprintf("SELECT * FROM `tbl_pages` WHERE `id` = '%d' LIMIT 1", (int) $current->parent));
}
return $result;
}
示例6: appendFormattedElement
/**
* Appends data into the XML tree of a Data Source
* @param $wrapper
* @param $data
*/
public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
if (!is_array($data) || empty($data)) {
return;
}
// root for all values
$root = new XMLElement($this->get('element_name'));
// selected items
$entries = static::getEntries($data);
// current linked entries
$root->setAttribute('entries', $data['entries']);
// available sections
$root->setAttribute('sections', $this->get('sections'));
// included elements
$elements = $this->parseElements();
// cache
$sectionsCache = new CacheableFetch('SectionManager');
// DS mode
if (!$mode) {
$mode = '*';
}
$parentDeepness = General::intval($this->recursiveDeepness);
$deepness = General::intval($this->get('deepness'));
// both deepnesses are defined and parent restricts more
if ($parentDeepness > 0 && $deepness > 0 && $parentDeepness < $deepness) {
$deepness = $parentDeepness;
} else {
if ($parentDeepness > 0 && $deepness < 1) {
$deepness = $parentDeepness;
}
}
// cache recursive level because recursion might
// change its value later on.
$recursiveLevel = $this->recursiveLevel;
// build entries
foreach ($entries as $eId) {
$item = new XMLElement('item');
// output id
$item->setAttribute('id', $eId);
// output recursive level
$item->setAttribute('level', $recursiveLevel);
$item->setAttribute('max-level', $deepness);
// max recursion check
if ($deepness < 1 || $recursiveLevel < $deepness) {
// current entry, without data
$entry = $this->fetchEntry($eId);
// entry not found...
if (!$entry || empty($entry)) {
$error = new XMLElement('error');
$error->setAttribute('id', $eId);
$error->setValue(__('Error: entry `%s` not found', array($eId)));
$root->prependChild($error);
continue;
}
// fetch section infos
$sectionId = $entry->get('section_id');
$item->setAttribute('section-id', $sectionId);
$section = $sectionsCache->fetch($sectionId);
$sectionName = $section->get('handle');
$item->setAttribute('section', $sectionName);
// adjust the mode for the current section
$curMode = $mode;
if ($curMode) {
// remove section name from current mode, i.e sectionName.field
if (preg_match('/^(' . $sectionName . '\\.)(.*)$/sU', $curMode)) {
$curMode = preg_replace('/^' . $sectionName . '\\./sU', '', $curMode);
} else {
if (preg_match('/^(' . $sectionName . ')$/sU', $curMode)) {
$curMode = null;
} else {
if (preg_match('/\\./sU', $curMode)) {
$item->setAttribute('forbidden', 'yes');
$root->appendChild($item);
continue;
}
}
}
}
$item->setAttribute('section', $section->get('handle'));
// Get the valid elements for this section only
$sectionElements = $elements[$sectionName];
// get all if no mode is set or section element is empty
// or mode is * and * is allowed
if (!$curMode || empty($sectionElements) || $curMode === '*' && in_array('*', $sectionElements)) {
// setting null = get all
$sectionElements = null;
} else {
if (in_array('*', $sectionElements) && !!$curMode) {
// get only the mode
$sectionElements = array($curMode);
} else {
if ($curMode !== '*') {
foreach ($sectionElements as $secElemIndex => $sectionElement) {
if ($curMode != $sectionElement) {
unset($sectionElements[$secElemIndex]);
//.........这里部分代码省略.........
示例7: getXPath
public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL)
{
$entry_xml = new XMLElement('entry');
$data = $entry->getData();
$fields = array();
$entry_xml->setAttribute('id', $entry->get('id'));
//Add date created and edited values
$date = new XMLElement('system-date');
$date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created'));
$date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified'));
$entry_xml->appendChild($date);
//Reflect Workspace and Siteroot params
$workspace = new XMLElement('workspace', URL . '/workspace');
$root = new XMLElement('root', URL);
// Add associated entry counts
if ($fetch_associated_counts == 'yes') {
$associated = $entry->fetchAllAssociatedEntryCounts();
if (is_array($associated) and !empty($associated)) {
foreach ($associated as $section_id => $count) {
$section = SectionManager::fetch($section_id);
if ($section instanceof Section === false) {
continue;
}
$entry_xml->setAttribute($section->get('handle'), (string) $count);
}
}
}
// Add fields:
foreach ($data as $field_id => $values) {
if (empty($field_id)) {
continue;
}
$field = FieldManager::fetch($field_id);
$field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id'));
}
$xml = new XMLElement('data');
$xml->appendChild($entry_xml);
$xml->appendChild($workspace);
$xml->appendChild($root);
// Build some context
$section = SectionManager::fetch($entry->get('section_id'));
$params = new XMLElement('params');
$params->appendChild(new XMLElement('section-handle', $section->get('handle')));
$params->appendChild(new XMLElement('entry-id', $entry->get('id')));
$xml->prependChild($params);
$dom = new DOMDocument();
$dom->strictErrorChecking = false;
$dom->loadXML($xml->generate(true));
if (!empty($XSLTfilename)) {
$XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename);
if (file_exists($XSLTfilename)) {
$XSLProc = new XsltProcessor();
$xslt = new DomDocument();
$xslt->load($XSLTfilename);
$XSLProc->importStyleSheet($xslt);
// Set some context
$XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id')));
$temp = $XSLProc->transformToDoc($dom);
if ($temp instanceof DOMDocument) {
$dom = $temp;
}
}
}
$xpath = new DOMXPath($dom);
if (version_compare(phpversion(), '5.3', '>=')) {
$xpath->registerPhpFunctions();
}
return $xpath;
}
示例8: SimpleXMLElement
$xsl = @new SimpleXMLElement($xsl);
$xsl->registerXPathNamespace("ext", "http://getsymphony.com/schemas/extension/1.0");
$result = $xsl->xpath("//ext:extension[@id = '" . $e->getAdditional()->name . "']");
if (!empty($result)) {
$match = $extension->getFilename();
break;
}
}
}
// If we've found a similar folder
if ($match != "" && $e->getAdditional()->rename_failed !== true) {
$div->appendChild(new XMLElement('p', __('Often the cause of this error is a misnamed extension folder. You can try renaming %s to %s, or you can uninstall the extension to continue.', array('<code>extensions/' . $match . '</code>', '<code>extensions/' . $e->getAdditional()->name . '</code>'))));
$form->appendChild(Widget::Input('existing-folder', $match, 'hidden'));
$form->appendChild(Widget::Input('new-folder', $e->getAdditional()->name, 'hidden'));
$button = new XMLElement('button', __('Rename folder'));
$button->setAttributeArray(array('name' => 'action[rename]', 'class' => 'button', 'type' => 'submit', 'accesskey' => 's'));
$actions->appendChild($button);
} elseif ($e->getAdditional()->rename_failed) {
$div->appendChild(new XMLElement('p', __('Sorry, but Symphony was unable to rename the folder. You can try renaming %s to %s yourself, or you can uninstall the extension to continue.', array('<code>extensions/' . $match . '</code>', '<code>extensions/' . $e->getAdditional()->name . '</code>'))));
} else {
$div->appendChild(new XMLElement('p', __('You can try uninstalling the extension to continue, or you might want to ask on the forums')));
}
// Add XSRF token to form's in the backend
if (Symphony::Engine()->isXSRFEnabled()) {
$form->prependChild(XSRF::formToken());
}
$div->appendChild($form);
$Page->Body->appendChild($div);
$output = $Page->generate();
echo $output;
exit;
示例9: prepareAssociationsDrawer
//.........这里部分代码省略.........
if ($field = FieldManager::fetch($as['parent_section_field_id'])) {
if (isset($_GET['prepopulate'])) {
$prepopulate_field = key($_GET['prepopulate']);
}
// get associated entries if entry exists,
if ($entry_id) {
$entry_ids = $field->findParentRelatedEntries($as['child_section_field_id'], $entry_id);
// get prepopulated entry otherwise
} elseif (isset($_GET['prepopulate'])) {
$entry_ids = array(intval(current($_GET['prepopulate'])));
} else {
$entry_ids = array();
}
// Use $schema for perf reasons
$schema = array($field->get('element_name'));
$where = !empty($entry_ids) ? sprintf(' AND `e`.`id` IN (%s)', implode(', ', $entry_ids)) : null;
$entries = !empty($entry_ids) || isset($_GET['prepopulate']) && $field->get('id') === $prepopulate_field ? EntryManager::fetchByPage(1, $as['parent_section_id'], $show_entries, $where, null, false, false, true, $schema) : array();
$has_entries = !empty($entries) && $entries['total-entries'] != 0;
if ($has_entries) {
$element = new XMLElement('section', null, array('class' => 'association parent'));
$header = new XMLElement('header');
$header->appendChild(new XMLElement('p', __('Linked to %s in', array('<a class="association-section" href="' . SYMPHONY_URL . '/publish/' . $as['handle'] . '/">' . $as['name'] . '</a>'))));
$element->appendChild($header);
$ul = new XMLElement('ul', null, array('class' => 'association-links', 'data-section-id' => $as['child_section_id'], 'data-association-ids' => implode(', ', $entry_ids)));
foreach ($entries['records'] as $e) {
// let the field create the mark up
$li = $field->prepareAssociationsDrawerXMLElement($e, $as);
// add it to the unordered list
$ul->appendChild($li);
}
$element->appendChild($ul);
$content->appendChild($element);
}
}
}
}
// Process Child Associations
if (!is_null($child_associations) && !empty($child_associations)) {
foreach ($child_associations as $as) {
// Get the related section
$child_section = SectionManager::fetch($as['child_section_id']);
if (!$child_section instanceof Section) {
continue;
}
// Get the visible field instance (using the sorting field, this is more flexible than visibleColumns())
// Get the link field instance
$visible_field = current($child_section->fetchVisibleColumns());
$relation_field = FieldManager::fetch($as['child_section_field_id']);
// Get entries, using $schema for performance reasons.
$entry_ids = $relation_field->findRelatedEntries($entry_id, $as['parent_section_field_id']);
$schema = $visible_field ? array($visible_field->get('element_name')) : array();
$where = sprintf(' AND `e`.`id` IN (%s)', implode(', ', $entry_ids));
$entries = !empty($entry_ids) ? EntryManager::fetchByPage(1, $as['child_section_id'], $show_entries, $where, null, false, false, true, $schema) : array();
$has_entries = !empty($entries) && $entries['total-entries'] != 0;
// Build the HTML of the relationship
$element = new XMLElement('section', null, array('class' => 'association child'));
$header = new XMLElement('header');
$filter = '?filter[' . $relation_field->get('element_name') . ']=' . $entry_id;
$prepopulate = '?prepopulate[' . $as['child_section_field_id'] . ']=' . $entry_id;
// Create link with filter or prepopulate
$link = SYMPHONY_URL . '/publish/' . $as['handle'] . '/' . $filter;
$a = new XMLElement('a', $as['name'], array('class' => 'association-section', 'href' => $link));
// Create new entries
$create = new XMLElement('a', __('Create New'), array('class' => 'button association-new', 'href' => SYMPHONY_URL . '/publish/' . $as['handle'] . '/new/' . $prepopulate));
// Display existing entries
if ($has_entries) {
$header->appendChild(new XMLElement('p', __('Links in %s', array($a->generate()))));
$ul = new XMLElement('ul', null, array('class' => 'association-links', 'data-section-id' => $as['child_section_id'], 'data-association-ids' => implode(', ', $entry_ids)));
foreach ($entries['records'] as $key => $e) {
// let the first visible field create the mark up
if ($visible_field) {
$li = $visible_field->prepareAssociationsDrawerXMLElement($e, $as, $prepopulate);
} else {
$li = Field::createAssociationsDrawerXMLElement($e->get('id'), $e, $as, $prepopulate);
}
// add it to the unordered list
$ul->appendChild($li);
}
$element->appendChild($ul);
// If we are only showing 'some' of the entries, then show this on the UI
if ($entries['total-entries'] > $show_entries) {
$pagination = new XMLElement('li', null, array('class' => 'association-more', 'data-current-page' => '1', 'data-total-pages' => ceil($entries['total-entries'] / $show_entries), 'data-total-entries' => $entries['total-entries']));
$counts = new XMLElement('a', __('Show more entries'), array('href' => $link));
$pagination->appendChild($counts);
$ul->appendChild($pagination);
}
// No entries
} else {
$element->setAttribute('class', 'association child empty');
$header->appendChild(new XMLElement('p', __('No links in %s', array($a->generate()))));
}
$header->appendChild($create);
$element->prependChild($header);
$content->appendChild($element);
}
}
}
$drawer = Widget::Drawer('section-associations', __('Show Associations'), $content);
$this->insertDrawer($drawer, $drawer_position, 'prepend');
}
示例10: execute
public function execute(array &$param_pool = null)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
$this->_param_pool = $param_pool;
$where = null;
$joins = null;
$group = false;
if (!($section = SectionManager::fetch((int) $this->getSource()))) {
$about = $this->about();
trigger_error(__('The Section, %s, associated with the Data source, %s, could not be found.', array($this->getSource(), '<code>' . $about['name'] . '</code>')), E_USER_ERROR);
}
$sectioninfo = new XMLElement('section', General::sanitize($section->get('name')), array('id' => $section->get('id'), 'handle' => $section->get('handle')));
if ($this->_force_empty_result == true) {
if ($this->dsParamREDIRECTONREQUIRED == 'yes') {
throw new FrontendPageNotFoundException();
}
$this->_force_empty_result = false;
//this is so the section info element doesn't disappear.
$error = new XMLElement('error', __("Data source not executed, required parameter is missing."), array('required-param' => $this->dsParamREQUIREDPARAM));
$result->appendChild($error);
$result->prependChild($sectioninfo);
return $result;
}
if ($this->_negate_result == true) {
if ($this->dsParamREDIRECTONFORBIDDEN == 'yes') {
throw new FrontendPageNotFoundException();
}
$this->_negate_result = false;
//this is so the section info element doesn't disappear.
$result = $this->negateXMLSet();
$result->prependChild($sectioninfo);
return $result;
}
if (is_array($this->dsParamINCLUDEDELEMENTS)) {
$include_pagination_element = in_array('system:pagination', $this->dsParamINCLUDEDELEMENTS);
} else {
$this->dsParamINCLUDEDELEMENTS = array();
}
if (isset($this->dsParamPARAMOUTPUT) && !is_array($this->dsParamPARAMOUTPUT)) {
$this->dsParamPARAMOUTPUT = array($this->dsParamPARAMOUTPUT);
}
$this->_can_process_system_parameters = $this->canProcessSystemParameters();
if (!isset($this->dsParamPAGINATERESULTS)) {
$this->dsParamPAGINATERESULTS = 'yes';
}
// Process Filters
$this->processFilters($where, $joins, $group);
// Process Sorting
if ($this->dsParamSORT == 'system:id') {
EntryManager::setFetchSorting('system:id', $this->dsParamORDER);
} elseif ($this->dsParamSORT == 'system:date' || $this->dsParamSORT == 'system:creation-date') {
EntryManager::setFetchSorting('system:creation-date', $this->dsParamORDER);
} elseif ($this->dsParamSORT == 'system:modification-date') {
EntryManager::setFetchSorting('system:modification-date', $this->dsParamORDER);
} else {
EntryManager::setFetchSorting(FieldManager::fetchFieldIDFromElementName($this->dsParamSORT, $this->getSource()), $this->dsParamORDER);
}
// combine `INCLUDEDELEMENTS`, `PARAMOUTPUT` and `GROUP` into an
// array of field handles to optimise the `EntryManager` queries
$datasource_schema = $this->dsParamINCLUDEDELEMENTS;
if (is_array($this->dsParamPARAMOUTPUT)) {
$datasource_schema = array_merge($datasource_schema, $this->dsParamPARAMOUTPUT);
}
if ($this->dsParamGROUP) {
$datasource_schema[] = FieldManager::fetchHandleFromID($this->dsParamGROUP);
}
$entries = EntryManager::fetchByPage($this->dsParamPAGINATERESULTS == 'yes' && $this->dsParamSTARTPAGE > 0 ? $this->dsParamSTARTPAGE : 1, $this->getSource(), $this->dsParamPAGINATERESULTS == 'yes' && $this->dsParamLIMIT >= 0 ? $this->dsParamLIMIT : null, $where, $joins, $group, !$include_pagination_element ? true : false, true, array_unique($datasource_schema));
/**
* Immediately after building entries allow modification of the Data Source entries array
*
* @delegate DataSourceEntriesBuilt
* @param string $context
* '/frontend/'
* @param Datasource $datasource
* @param array $entries
* @param array $filters
*/
Symphony::ExtensionManager()->notifyMembers('DataSourceEntriesBuilt', '/frontend/', array('datasource' => &$this, 'entries' => &$entries, 'filters' => $this->dsParamFILTERS));
if (($entries['total-entries'] <= 0 || $include_pagination_element === true) && (!is_array($entries['records']) || empty($entries['records'])) || $this->dsParamSTARTPAGE == '0') {
if ($this->dsParamREDIRECTONEMPTY == 'yes') {
throw new FrontendPageNotFoundException();
}
$this->_force_empty_result = false;
$result = $this->emptyXMLSet();
$result->prependChild($sectioninfo);
if ($include_pagination_element) {
$pagination_element = General::buildPaginationElement();
if ($pagination_element instanceof XMLElement && $result instanceof XMLElement) {
$result->prependChild($pagination_element);
}
}
} else {
if (!$this->_param_output_only) {
$result->appendChild($sectioninfo);
if ($include_pagination_element) {
$t = $this->dsParamPAGINATERESULTS == 'yes' && isset($this->dsParamLIMIT) && $this->dsParamLIMIT >= 0 ? $this->dsParamLIMIT : $entries['total-entries'];
$pagination_element = General::buildPaginationElement($entries['total-entries'], $entries['total-pages'], $t, $this->dsParamPAGINATERESULTS == 'yes' && $this->dsParamSTARTPAGE > 0 ? $this->dsParamSTARTPAGE : 1);
if ($pagination_element instanceof XMLElement && $result instanceof XMLElement) {
$result->prependChild($pagination_element);
}
//.........这里部分代码省略.........
示例11: grab
public function grab(&$param_pool)
{
$Members = Frontend::instance()->ExtensionManager->create('members');
$Members->initialiseCookie();
if ($Members->isLoggedIn() !== true) {
// Oi! you can't be here
redirect(URL . '/forbidden/');
exit;
}
$result = new XMLElement($this->dsParamROOTELEMENT);
self::__init();
$db = ASDCLoader::instance();
$sql = 'SELECT SQL_CALC_FOUND_ROWS
pinned.entry_id AS `id`,
pinned.value AS `pinned`,
closed.value AS `closed`,
creation_date.local AS `creation-date`,
last_active.local AS `last-active`,
created_by.member_id AS `created-by-member-id`,
created_by.username AS `created-by-username`,
last_post.member_id AS `last-post-member-id`,
last_post.username AS `last-post-username`,
topic.value AS `topic`
FROM `tbl_entries_data_%d` AS `pinned`
LEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id
LEFT JOIN `tbl_entries_data_%d` AS `discussion_comments_member` ON comments.entry_id = discussion_comments_member.entry_id
WHERE 1 %s
AND (created_by.member_id = %11$d || discussion_comments_member.member_id = %11$d)
GROUP BY pinned.entry_id
ORDER BY pinned.value ASC, last_active.local DESC
LIMIT %12$d, %13$d';
try {
$rows = $db->query(sprintf($sql, self::findFieldID('pinned', 'discussions'), self::findFieldID('closed', 'discussions'), self::findFieldID('creation-date', 'discussions'), self::findFieldID('last-active', 'discussions'), self::findFieldID('created-by', 'discussions'), self::findFieldID('last-post', 'discussions'), self::findFieldID('topic', 'discussions'), self::findFieldID('parent-id', 'comments'), self::findFieldID('created-by', 'comments'), isset($this->dsParamFILTERS['id']) && (int) $this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id = " . (int) $this->dsParamFILTERS['id'] : NULL, (int) $Members->Member->get('id'), max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT));
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
return $result;
}
if ($rows->length() == 0) {
return $this->emptyXMLSet();
}
$total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total;
$result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE));
/*
stdClass Object
(
[id] => 666
[pinned] => yes
[closed] => no
[creation-date] => 1233599808
[last-active] => 1237161637
[created-by-member-id] => 2126
[created-by-username] => Lewis
[last-post-member-id] => 2126
[last-post-username] => Lewis
[topic] => Symphony 2 Documentation
[comments] => 18
)
<entry id="595" comments="7">
<created-by id="2150">newnomad</created-by>
<closed>No</closed>
<last-active time="18:30" weekday="1">2009-02-09</last-active>
<last-post id="2150">newnomad</last-post>
<pinned>No</pinned>
<topic handle="viewing-feeds">viewing feeds</topic>
<creation-date time="19:31" weekday="3">2009-01-07</creation-date>
</entry>
*/
$param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id');
foreach ($rows as $r) {
// Need to do a seperate query to find the comment counts.
try {
$comments = $db->query(sprintf("SELECT COUNT(*) AS `count` FROM `tbl_entries_data_%d` WHERE `relation_id` = %d ", self::findFieldID('parent-id', 'comments'), $r->id))->current()->count;
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
return $result;
}
$entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $comments));
$entry->appendChild(new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'})));
$entry->appendChild(new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'})));
$entry->appendChild(new XMLElement('closed', ucfirst($r->closed)));
$entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned)));
$entry->appendChild(new XMLElement('topic', General::sanitize($r->topic)));
$entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date'));
$entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active'));
$result->appendChild($entry);
}
return $result;
}
示例12: createCheckbox
private function createCheckbox($text, $key)
{
$order = $this->get('sortorder');
$lbl = new XMLElement('label', __($text), array('class' => 'column'));
$input = new XMLElement('input', NULL, array('type' => 'checkbox', 'name' => "fields[{$order}][{$key}]"));
$input->setSelfClosingTag(true);
if ($this->get($key) == 'yes') {
$input->setAttribute('checked', 'checked');
}
$lbl->prependChild($input);
return $lbl;
}
示例13: view
public function view()
{
if (isset($_POST['action']['submit'])) {
$this->panelErrors = Extension_Dashboard::validatePanelOptions($this->panelType, $this->panelId);
if (empty($this->panelErrors)) {
$this->panelId = Extension_Dashboard::savePanel(array('id' => $this->panelId, 'label' => $this->panelLabel, 'placement' => $this->panelPlacement, 'type' => $this->panelType), $this->panelConfig);
}
} else {
if (isset($_POST['action']['delete'])) {
Extension_Dashboard::deletePanel($this->panelId);
$this->_Result->setAttribute('id', $this->panelId);
$this->_Result->setAttribute('placement', $this->panelPlacement);
return;
}
}
if (isset($this->panelId) && !empty($this->panelId)) {
$this->panelConfig = Extension_Dashboard::getPanel($this->panelId);
$this->panelLabel = $this->panelConfig['label'];
$this->panelPlacement = $this->panelConfig['placement'];
}
if (isset($_POST['action']['submit']) && empty($this->panelErrors)) {
$html = Extension_Dashboard::buildPanelHTML($this->panelConfig);
$class = $html->getAttribute('class');
$html->setAttribute('class', $class . ' new-panel');
$this->_Result->setAttribute('id', $this->panelId);
$this->_Result->setAttribute('placement', $this->panelPlacement);
$this->_Result->setValue(sprintf('<![CDATA[%s]]>', $html->generate()));
} else {
$this->addHeaderToPage('Content-Type', 'text/html');
$container = new XMLElement('form');
$container->setAttribute('id', 'save-panel');
$container->appendChild(new XMLElement('div', NULL, array('class' => 'top')));
$heading = new XMLElement('h3', __('Configuration') . ' <span>' . (isset($this->panelLabel) ? $this->panelLabel : __('Untitled Panel')) . '<span>');
$container->appendChild($heading);
$config_options = Extension_Dashboard::buildPanelOptions($this->panelType, $this->panelId, $this->panelErrors);
$primary = new XMLElement('div', NULL, array('class' => 'panel-config'));
$fieldset = new XMLElement('fieldset', NULL, array('class' => 'settings'));
$legend = new XMLElement('legend', __('General'));
$fieldset->appendChild($legend);
$group = new XMLElement('div', NULL, array('class' => 'group'));
$group->appendChild(Widget::Label(__('Name'), Widget::Input('label', $this->panelLabel)));
$group->appendChild(Widget::Label(__('Placement'), Widget::Select('placement', array(array('primary', $this->panelPlacement == 'primary', __('Main content')), array('secondary', $this->panelPlacement == 'secondary', __('Sidebar'))))));
$fieldset->appendChild($group);
$primary->appendChild($fieldset);
if ($config_options) {
$primary->appendChild($config_options);
}
$actions = new XMLElement('div', NULL, array('class' => 'actions'));
$actions->appendChild(Widget::Input('action[submit]', __('Save Panel'), 'submit', array('class' => 'button create')));
$actions->appendChild(Widget::Input('action[cancel]', __('Cancel'), 'submit'));
if ($this->panelId) {
$actions->appendChild(new XMLElement('button', __('Delete Panel'), array('class' => 'delete', 'name' => 'action[delete]')));
}
$primary->appendChild($actions);
$primary->appendChild(Widget::Input('id', $this->panelId, 'hidden'));
$primary->appendChild(Widget::Input('type', $this->panelType, 'hidden'));
$container->appendChild($primary);
if (Symphony::isXSRFEnabled()) {
$container->prependChild(XSRF::formToken());
}
$this->_Result = $container;
}
}
示例14: appendNavigation
/**
* This function will append the Navigation to the AdministrationPage.
* It fires a delegate, NavigationPreRender, to allow extensions to manipulate
* the navigation. Extensions should not use this to add their own navigation,
* they should provide the navigation through their fetchNavigation function.
* Note with the Section navigation groups, if there is only one section in a group
* and that section is set to visible, the group will not appear in the navigation.
*
* @uses NavigationPreRender
* @see getNavigationArray()
* @see toolkit.Extension#fetchNavigation()
*/
public function appendNavigation()
{
$nav = $this->getNavigationArray();
/**
* Immediately before displaying the admin navigation. Provided with the
* navigation array. Manipulating it will alter the navigation for all pages.
*
* @delegate NavigationPreRender
* @param string $context
* '/backend/'
* @param array $nav
* An associative array of the current navigation, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('NavigationPreRender', '/backend/', array('navigation' => &$nav));
$navElement = new XMLElement('nav', null, array('id' => 'nav', 'role' => 'navigation'));
$contentNav = new XMLElement('ul', null, array('class' => 'content', 'role' => 'menubar'));
$structureNav = new XMLElement('ul', null, array('class' => 'structure', 'role' => 'menubar'));
foreach ($nav as $n) {
if (isset($n['visible']) && $n['visible'] === 'no') {
continue;
}
if ($this->doesAuthorHaveAccess($n['limit'])) {
$xGroup = new XMLElement('li', $n['name'], array('role' => 'presentation'));
if (isset($n['class']) && trim($n['name']) !== '') {
$xGroup->setAttribute('class', $n['class']);
}
$hasChildren = false;
$xChildren = new XMLElement('ul', null, array('role' => 'menu'));
if (is_array($n['children']) && !empty($n['children'])) {
foreach ($n['children'] as $c) {
// adapt for Yes and yes
if (strtolower($c['visible']) !== 'yes') {
continue;
}
if ($this->doesAuthorHaveAccess($c['limit'])) {
$xChild = new XMLElement('li');
$xChild->setAttribute('role', 'menuitem');
$linkChild = Widget::Anchor($c['name'], SYMPHONY_URL . $c['link']);
if (isset($c['target'])) {
$linkChild->setAttribute('target', $c['target']);
}
$xChild->appendChild($linkChild);
$xChildren->appendChild($xChild);
$hasChildren = true;
}
}
if ($hasChildren) {
$xGroup->setAttribute('aria-haspopup', 'true');
$xGroup->appendChild($xChildren);
if ($n['type'] === 'content') {
$contentNav->appendChild($xGroup);
} elseif ($n['type'] === 'structure') {
$structureNav->prependChild($xGroup);
}
}
}
}
}
$navElement->appendChild($contentNav);
$navElement->appendChild($structureNav);
$this->Header->appendChild($navElement);
Symphony::Profiler()->sample('Navigation Built', PROFILE_LAP);
}
示例15: appendNavigation
/**
* This function will append the Navigation to the AdministrationPage.
* It fires a delegate, NavigationPreRender, to allow extensions to manipulate
* the navigation. Extensions should not use this to add their own navigation,
* they should provide the navigation through their fetchNavigation function.
* Note with the Section navigation groups, if there is only one section in a group
* and that section is set to visible, the group will not appear in the navigation.
*
* @uses NavigationPreRender
* @see getNavigationArray()
* @see toolkit.Extension#fetchNavigation()
*/
public function appendNavigation()
{
$nav = $this->getNavigationArray();
/**
* Immediately before displaying the admin navigation. Provided with the
* navigation array. Manipulating it will alter the navigation for all pages.
*
* @delegate NavigationPreRender
* @param string $context
* '/backend/'
* @param array $nav
* An associative array of the current navigation, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('NavigationPreRender', '/backend/', array('navigation' => &$nav));
$navElement = new XMLElement('nav', NULL, array('id' => 'nav'));
$contentNav = new XMLElement('ul', NULL, array('class' => 'content'));
$structureNav = new XMLElement('ul', NULL, array('class' => 'structure'));
foreach ($nav as $n) {
if (isset($n['visible']) && $n['visible'] == 'no') {
continue;
}
$can_access = false;
if (!isset($n['limit']) || $n['limit'] == 'author') {
$can_access = true;
} elseif ($n['limit'] == 'developer' && Administration::instance()->Author->isDeveloper()) {
$can_access = true;
} elseif ($n['limit'] == 'primary' && Administration::instance()->Author->isPrimaryAccount()) {
$can_access = true;
}
if ($can_access) {
$xGroup = new XMLElement('li', $n['name']);
if (isset($n['class']) && trim($n['name']) != '') {
$xGroup->setAttribute('class', $n['class']);
}
$hasChildren = false;
$xChildren = new XMLElement('ul');
if (is_array($n['children']) && !empty($n['children'])) {
foreach ($n['children'] as $c) {
if ($c['visible'] == 'no') {
continue;
}
$can_access_child = false;
if (!isset($c['limit']) || $c['limit'] == 'author') {
$can_access_child = true;
} elseif ($c['limit'] == 'developer' && Administration::instance()->Author->isDeveloper()) {
$can_access_child = true;
} elseif ($c['limit'] == 'primary' && Administration::instance()->Author->isPrimaryAccount()) {
$can_access_child = true;
}
if ($can_access_child) {
$xChild = new XMLElement('li');
$xChild->appendChild(Widget::Anchor($c['name'], SYMPHONY_URL . $c['link']));
$xChildren->appendChild($xChild);
$hasChildren = true;
}
}
if ($hasChildren) {
$xGroup->appendChild($xChildren);
if ($n['type'] === 'content') {
$contentNav->appendChild($xGroup);
} else {
if ($n['type'] === 'structure') {
$structureNav->prependChild($xGroup);
}
}
}
}
}
}
$navElement->appendChild($contentNav);
$navElement->appendChild($structureNav);
$this->Header->appendChild($navElement);
Symphony::Profiler()->sample('Navigation Built', PROFILE_LAP);
}