本文整理汇总了PHP中XMLElement::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLElement::setAttribute方法的具体用法?PHP XMLElement::setAttribute怎么用?PHP XMLElement::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __trigger
protected function __trigger()
{
$result = null;
$actionName = $this->getActionName();
$requestMethod = $this->getRequestMethod();
$requestArray = $this->getRequestArray();
if ($_SERVER['REQUEST_METHOD'] == $requestMethod && isset($requestArray[$actionName])) {
$result = new XMLElement($actionName);
$r = new XMLElement('result');
$id = intval($_POST['id']);
try {
$this->validate();
$entry = $this->createEntryFromPost($id);
$this->visitEntry($entry);
$r->setAttribute('success', 'yes');
$r->setAttribute('id', $entry->get('id'));
} catch (Exception $ex) {
$xmlEx = new XMLElement('error');
$showMsg = $ex instanceof InsertSectionException || Symphony::Engine()->isLoggedIn();
$errorMessage = $showMsg ? $ex->getMessage() : __('A Fatal error occured');
$xmlEx->setValue($errorMessage);
$result->appendChild($xmlEx);
$r->setAttribute('success', 'no');
Symphony::Log()->pushExceptionToLog($ex, true);
}
$result->appendChild($r);
} else {
throw new FrontendPageNotFoundException();
}
return $result;
}
示例2: response
public function response()
{
$result = new XMLElement($this->_event_name);
$post_values = new XMLElement('post-values');
$fields = $_POST['fields'];
if (!empty($fields)) {
General::array_to_xml($post_values, $fields, true);
}
if (!empty($this->_error_array)) {
$result->appendChild($post_values);
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
foreach ($this->_error_array as $field => $message) {
$type = $fields[$field] == '' ? 'missing' : 'invalid';
$field = new XMLElement($field);
$field->setAttribute('type', $type);
$field->setAttribute('message', $message);
$result->appendChild($field);
}
} else {
$result->setAttribute('result', 'success');
$result->appendChild(new XMLElement('message', __('Entry created successfully.')));
}
return $result;
}
示例3: getXPath
public function getXPath($entry)
{
$entry_xml = new XMLElement('entry');
$section_id = $entry->_fields['section_id'];
$data = $entry->getData();
$fields = array();
$entry_xml->setAttribute('id', $entry->get('id'));
$associated = $entry->fetchAllAssociatedEntryCounts();
if (is_array($associated) and !empty($associated)) {
foreach ($associated as $section => $count) {
$handle = $this->_Parent->Database->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t");
$entry_xml->setAttribute($handle, (string) $count);
}
}
// Add fields:
foreach ($data as $field_id => $values) {
if (empty($field_id)) {
continue;
}
$field =& $entry->_Parent->fieldManager->fetch($field_id);
$field->appendFormattedElement($entry_xml, $values, false);
}
$xml = new XMLElement('data');
$xml->appendChild($entry_xml);
$dom = new DOMDocument();
$dom->loadXML($xml->generate(true));
return new DOMXPath($dom);
}
示例4: __trigger
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('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'])));
if ($success == true && isset($_REQUEST['redirect'])) {
redirect($_REQUEST['redirect']);
}
$result->setAttribute('status', $success === true ? 'success' : 'error');
return $result;
}
示例5: getXPath
public function getXPath($entry)
{
$fieldManager = new FieldManager(Symphony::Engine());
$entry_xml = new XMLElement('entry');
$section_id = $entry->get('section_id');
$data = $entry->getData();
$fields = array();
$entry_xml->setAttribute('id', $entry->get('id'));
$associated = $entry->fetchAllAssociatedEntryCounts();
if (is_array($associated) and !empty($associated)) {
foreach ($associated as $section => $count) {
$handle = Symphony::Database()->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t");
$entry_xml->setAttribute($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);
}
$xml = new XMLElement('data');
$xml->appendChild($entry_xml);
$dom = new DOMDocument();
$dom->strictErrorChecking = false;
$dom->loadXML($xml->generate(true));
$xpath = new DOMXPath($dom);
if (version_compare(phpversion(), '5.3', '>=')) {
$xpath->registerPhpFunctions();
}
return $xpath;
}
示例6: grab
function grab()
{
include_once EXTENSIONS . '/nested_cats/extension.driver.php';
$driver = $this->_Parent->ExtensionManager->create('nested_cats');
$xml = new XMLElement('nested-cats');
$data = $driver->getTree('lft', 0);
$right = array($data[0]['rgt']);
array_shift($data);
if (!$data) {
$error = new XMLElement('error', 'No data received.');
$xml->appendChild($error);
return $xml;
}
foreach ($data as $d) {
if (count($right) > 0) {
while ($right[count($right) - 1] < $d['rgt']) {
array_pop($right);
}
}
$item = new XMLElement('item', $d['title']);
$item->setAttribute('id', $d['id']);
$item->setAttribute('parent-id', $d['parent']);
$item->setAttribute('level', count($right));
$item->setAttribute('handle', $d['handle']);
$xml->appendChild($item);
$right[] = $d['rgt'];
}
return $xml;
}
示例7: __buildPageXML
public function __buildPageXML($page, $page_types, $qf)
{
$lang_code = FLang::getLangCode();
$oPage = new XMLElement('page');
$oPage->setAttribute('handle', $page['handle']);
$oPage->setAttribute('id', $page['id']);
// keep current first
$oPage->appendChild(new XMLElement('item', General::sanitize($page['plh_t-' . $lang_code]), array('lang' => $lang_code, 'handle' => $page['plh_h-' . $lang_code])));
// add others
foreach (FLang::getLangs() as $lc) {
if ($lang_code != $lc) {
$oPage->appendChild(new XMLElement('item', General::sanitize($page['plh_t-' . $lc]), array('lang' => $lc, 'handle' => $page['plh_h-' . $lc])));
}
}
if (in_array($page['id'], array_keys($page_types))) {
$xTypes = new XMLElement('types');
foreach ($page_types[$page['id']] as $type) {
$xTypes->appendChild(new XMLElement('type', $type));
}
$oPage->appendChild($xTypes);
}
if ($page['children'] != '0') {
if ($children = PageManager::fetch(false, array($qf . 'id, handle, title'), array(sprintf('`parent` = %d', $page['id'])))) {
foreach ($children as $c) {
$oPage->appendChild($this->__buildPageXML($c, $page_types, $qf));
}
}
}
return $oPage;
}
示例8: generate
/**
* The generate functions outputs the correct headers for
* this `XMLPage`, adds `$this->getHttpStatusCode()` code to the root attribute
* before calling the parent generate function and generating
* the `$this->_Result` XMLElement
*
* @param null $page
* @return string
*/
public function generate($page = null)
{
// Set the actual status code in the xml response
$this->_Result->setAttribute('status', $this->getHttpStatusCode());
parent::generate($page);
return $this->_Result->generate(true);
}
示例9: processRecordGroup
function processRecordGroup(&$wrapper, $element, $group, $ds, &$Parent, &$entryManager, &$fieldPool, &$param_pool, $param_output_only = false)
{
$xGroup = new XMLElement($element, NULL, $group['attr']);
$key = 'ds-' . $ds->dsParamROOTELEMENT;
if (is_array($group['records']) && !empty($group['records'])) {
foreach ($group['records'] as $entry) {
$data = $entry->getData();
$fields = array();
$xEntry = new XMLElement('entry');
$xEntry->setAttribute('id', $entry->get('id'));
$associated_entry_counts = $entry->fetchAllAssociatedEntryCounts();
if (is_array($associated_entry_counts) && !empty($associated_entry_counts)) {
foreach ($associated_entry_counts as $section_id => $count) {
$section_handle = $Parent->Database->fetchVar('handle', 0, "SELECT `handle` FROM `tbl_sections` WHERE `id` = '{$section_id}' LIMIT 1");
$xEntry->setAttribute($section_handle, '' . $count . '');
}
}
if (isset($ds->dsParamPARAMOUTPUT)) {
if ($ds->dsParamPARAMOUTPUT == 'system:id') {
$param_pool[$key][] = $entry->get('id');
} elseif ($ds->dsParamPARAMOUTPUT == 'system:date') {
$param_pool[$key][] = DateTimeObj::get('c', strtotime($entry->creationDate));
} elseif ($ds->dsParamPARAMOUTPUT == 'system:author') {
$param_pool[$key][] = $entry->get('author_id');
}
}
foreach ($data as $field_id => $values) {
if (!isset($fieldPool[$field_id]) || !is_object($fieldPool[$field_id])) {
$fieldPool[$field_id] =& $entryManager->fieldManager->fetch($field_id);
}
if (isset($ds->dsParamPARAMOUTPUT) && $ds->dsParamPARAMOUTPUT == $fieldPool[$field_id]->get('element_name')) {
$param_pool[$key][] = $fieldPool[$field_id]->getParameterPoolValue($values);
}
if (!$param_output_only) {
foreach ($ds->dsParamINCLUDEDELEMENTS as $handle) {
list($handle, $mode) = preg_split('/\\s*:\\s*/', $handle, 2);
if ($fieldPool[$field_id]->get('element_name') == $handle) {
$fieldPool[$field_id]->appendFormattedElement($xEntry, $values, $ds->dsParamHTMLENCODE ? true : false, $mode);
}
}
}
}
if (!$param_output_only) {
$xGroup->appendChild($xEntry);
}
}
}
if (is_array($group['groups']) && !empty($group['groups'])) {
foreach ($group['groups'] as $element => $group) {
foreach ($group as $g) {
processRecordGroup($xGroup, $element, $g, $ds, $Parent, $entryManager, $fieldPool, $param_pool, $param_output_only);
}
}
}
if (!$param_output_only) {
$wrapper->appendChild($xGroup);
}
return;
}
示例10: __trigger
protected function __trigger()
{
$result = new XMLElement(self::ROOTELEMENT);
$result->setAttribute('visits', $this->_driver->updateVisits());
$result->setAttribute('threshold', $this->_driver->getThreshold());
$result->appendChild(new XMLElement('message', $this->_driver->getMessage()));
return $result;
}
示例11: formToken
public static function formToken()
{
// <input type="hidden" name="xsrf" value=" . self::getToken() . " />
$obj = new XMLElement("input");
$obj->setAttribute("type", "hidden");
$obj->setAttribute("name", "xsrf");
$obj->setAttribute("value", self::getToken());
return $obj;
}
示例12: asXML
public function asXML()
{
$p = new XMLElement('p', $this->message);
$p->setAttribute('id', 'notice');
if ($this->type != self::NOTICE) {
$p->setAttribute('class', $this->type);
}
return $p;
}
示例13: appendOrderFieldId
public function appendOrderFieldId($context)
{
if ($this->active_field) {
$span = new XMLElement("span", $this->active_field["id"]);
$span->setAttribute("id", "order_number_field");
$span->setAttribute("class", $this->active_field["force_sort"]);
$span->setAttribute("style", "display:none;");
$context["parent"]->Page->Form->appendChild($span);
}
}
示例14: grab
function grab(&$param_pool)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
foreach ($this->_env["env"]["pool"][$this->ds_comments] as $email) {
$gravatar = new XMLElement("gravatar");
$gravatar->setAttribute("email", $email);
$gravatar->setAttribute("url", "http://www.gravatar.com/avatar/" . md5(strtolower($email)) . "?s=" . $size . $this->size . "&d=" . $this->_env["param"]["root"] . "/extensions/gravatar/assets/default.gif");
$result->appendChild($gravatar);
}
return $result;
}
示例15: grab
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;
}