本文整理汇总了PHP中xml::element方法的典型用法代码示例。如果您正苦于以下问题:PHP xml::element方法的具体用法?PHP xml::element怎么用?PHP xml::element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml::element方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
function query($args, $document)
{
$this->validate($args);
$sql = $this->datasource->get();
$xml = new xml();
$this->single() or $sql->begin();
$n = 0;
foreach ($this->body as $query) {
if ($rows = $sql->query($this->apply($query, $args))) {
$root = $xml->element($this->root[$n]);
$xml->append($root);
foreach ($rows as $row) {
$item = $xml->element($this->item[$n]);
$root->append($item);
foreach ($row as $name => $value) {
$node = $this->transform($xml, $name, $value);
$item->append($node);
}
}
++$n;
}
}
if (!$this->empty && $xml->blank()) {
$this->single() or $sql->rollback();
runtime_error('SQL procedure returned empty result: ' . $this->mangled());
} else {
$this->single() or $sql->commit();
}
return $document ? $xml : $xml->evaluate('/*[position() = 1]/*[position() = 1]/*[position() = 1]/text()');
}
示例2: query
function query($args, $document)
{
$this->validate($args);
$xml = new xml();
switch ($this->method) {
case 'record':
isset($args['host']) or runtime_error('GeoIP host parameter not found');
$root = $xml->element($this->root[0]);
$xml->append($root);
if ($record = geoip_record_by_name($args['host'])) {
$country = $xml->element('country');
$root->append($country);
$country->append($xml->element('alpha2', $record['country_code']));
$country->append($xml->element('alpha3', $record['country_code3']));
$country->append($xml->element('name', $record['country_name']));
$root->append($xml->element('region', $record['region']));
$root->append($xml->element('city', $record['city']));
$root->append($xml->element('latitude', $record['latitude']));
$root->append($xml->element('longitude', $record['longitude']));
}
break;
default:
runtime_error('Unknown GeoIP method: ' . $this->method);
}
return $xml;
}
示例3: groupCheckboxes
/**
* Adds a table with checkboxes where you can select what groups to add/remove
*
* @param $usergroups Array: groups the user belongs to
* @return string XHTML table element with checkboxes
*/
private function groupCheckboxes($usergroups)
{
$allgroups = $this->getAllGroups();
$ret = '';
$column = 1;
$settable_col = '';
$unsettable_col = '';
foreach ($allgroups as $group) {
$set = in_array($group, $usergroups);
# Should the checkbox be disabled?
$disabled = !($set && $this->canRemove($group) || !$set && $this->canAdd($group));
# Do we need to point out that this action is irreversible?
$irreversible = !$disabled && ($set && !$this->canAdd($group) || !$set && !$this->canRemove($group));
$attr = $disabled ? array('disabled' => 'disabled') : array();
$text = $irreversible ? wfMsgHtml('userrights-irreversible-marker', User::getGroupMember($group)) : User::getGroupMember($group);
$checkbox = Xml::checkLabel($text, "wpGroup-{$group}", "wpGroup-{$group}", $set, $attr);
$checkbox = $disabled ? Xml::tags('span', array('class' => 'mw-userrights-disabled'), $checkbox) : $checkbox;
if ($disabled) {
$unsettable_col .= "{$checkbox}<br />\n";
} else {
$settable_col .= "{$checkbox}<br />\n";
}
}
if ($column) {
$ret .= Xml::openElement('table', array('border' => '0', 'class' => 'mw-userrights-groups')) . "<tr>\n";
if ($settable_col !== '') {
$ret .= xml::element('th', null, wfMsg('userrights-changeable-col'));
}
if ($unsettable_col !== '') {
$ret .= xml::element('th', null, wfMsg('userrights-unchangeable-col'));
}
$ret .= "</tr>\n\t\t\t\t<tr>\n";
if ($settable_col !== '') {
$ret .= "\t\t\t\t\t<td style='vertical-align:top;'>\n\t\t\t\t\t\t{$settable_col}\n\t\t\t\t\t</td>\n";
}
if ($unsettable_col !== '') {
$ret .= "\t\t\t\t\t<td style='vertical-align:top;'>\n\t\t\t\t\t\t{$unsettable_col}\n\t\t\t\t\t</td>\n";
}
$ret .= Xml::closeElement('tr') . Xml::closeElement('table');
}
return $ret;
}
示例4: showRevs
/**
* This lets a user set restrictions for live and archived revisions
*/
private function showRevs()
{
global $wgOut, $wgUser;
$UserAllowed = true;
$count = $this->deleteKey == 'oldid' ? count($this->revisions) : count($this->archrevs);
$wgOut->addWikiMsg('revdelete-selected', $this->page->getPrefixedText(), $count);
$bitfields = 0;
$wgOut->addHTML("<ul>");
$where = $revObjs = array();
$dbr = wfGetDB(DB_MASTER);
$revisions = 0;
// Live revisions...
if ($this->deleteKey == 'oldid') {
// Run through and pull all our data in one query
foreach ($this->revisions as $revid) {
$where[] = intval($revid);
}
$result = $dbr->select(array('revision', 'page'), '*', array('rev_page' => $this->page->getArticleID(), 'rev_id' => $where, 'rev_page = page_id'), __METHOD__);
while ($row = $dbr->fetchObject($result)) {
$revObjs[$row->rev_id] = new Revision($row);
}
foreach ($this->revisions as $revid) {
// Hiding top revisison is bad
if (!isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent()) {
continue;
} else {
if (!$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED)) {
// If a rev is hidden from sysops
if (!$this->wasPosted) {
$wgOut->permissionRequired('suppressrevision');
return;
}
$UserAllowed = false;
}
}
$revisions++;
$wgOut->addHTML($this->historyLine($revObjs[$revid]));
$bitfields |= $revObjs[$revid]->mDeleted;
}
// The archives...
} else {
// Run through and pull all our data in one query
foreach ($this->archrevs as $timestamp) {
$where[] = $dbr->timestamp($timestamp);
}
$result = $dbr->select('archive', '*', array('ar_namespace' => $this->page->getNamespace(), 'ar_title' => $this->page->getDBKey(), 'ar_timestamp' => $where), __METHOD__);
while ($row = $dbr->fetchObject($result)) {
$timestamp = wfTimestamp(TS_MW, $row->ar_timestamp);
$revObjs[$timestamp] = new Revision(array('page' => $this->page->getArticleId(), 'id' => $row->ar_rev_id, 'text' => $row->ar_text_id, 'comment' => $row->ar_comment, 'user' => $row->ar_user, 'user_text' => $row->ar_user_text, 'timestamp' => $timestamp, 'minor_edit' => $row->ar_minor_edit, 'text_id' => $row->ar_text_id, 'deleted' => $row->ar_deleted, 'len' => $row->ar_len));
}
foreach ($this->archrevs as $timestamp) {
if (!isset($revObjs[$timestamp])) {
continue;
} else {
if (!$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED)) {
// If a rev is hidden from sysops
if (!$this->wasPosted) {
$wgOut->permissionRequired('suppressrevision');
return;
}
$UserAllowed = false;
}
}
$revisions++;
$wgOut->addHTML($this->historyLine($revObjs[$timestamp]));
$bitfields |= $revObjs[$timestamp]->mDeleted;
}
}
if (!$revisions) {
$wgOut->showErrorPage('revdelete-nooldid-title', 'revdelete-nooldid-text');
return;
}
$wgOut->addHTML("</ul>");
// Explanation text
$this->addUsageText();
// Normal sysops can always see what they did, but can't always change it
if (!$UserAllowed) {
return;
}
$items = array(Xml::inputLabel(wfMsg('revdelete-log'), 'wpReason', 'wpReason', 60), Xml::submitButton(wfMsg('revdelete-submit')));
$hidden = array(Xml::hidden('wpEditToken', $wgUser->editToken()), Xml::hidden('target', $this->page->getPrefixedText()), Xml::hidden('type', $this->deleteKey));
if ($this->deleteKey == 'oldid') {
foreach ($revObjs as $rev) {
$hidden[] = Xml::hidden('oldid[]', $rev->getId());
}
} else {
foreach ($revObjs as $rev) {
$hidden[] = Xml::hidden('artimestamp[]', $rev->getTimestamp());
}
}
$special = SpecialPage::getTitleFor('Revisiondelete');
$wgOut->addHTML(Xml::openElement('form', array('method' => 'post', 'action' => $special->getLocalUrl('action=submit'), 'id' => 'mw-revdel-form-revisions')) . Xml::openElement('fieldset') . xml::element('legend', null, wfMsg('revdelete-legend')));
$wgOut->addHTML($this->buildCheckBoxes($bitfields));
foreach ($items as $item) {
$wgOut->addHTML(Xml::tags('p', null, $item));
}
foreach ($hidden as $item) {
//.........这里部分代码省略.........
示例5: query
function query($args, $document)
{
$this->validate($args);
$xml = new xml();
switch ($this->method) {
case 'photos':
isset($args['venue_id']) or runtime_error('Foursquare venue_id parameter not found');
$root = $xml->element($this->root[0]);
$xml->append($root);
if ($result = json_decode(file_get_contents('https://api.foursquare.com/v2/venues/' . $args['venue_id'] . '/photos?' . $this->datasource->get()))) {
foreach ($result->response->photos->groups as $group) {
if ($group->type == 'venue') {
foreach ($group->items as $item) {
$image = $xml->element('image');
$root->append($image);
$image['@url'] = $item->url;
foreach ($item->sizes->items as $size) {
$resampled = $xml->element('resampled');
$image->append($resampled);
$resampled['@url'] = $size->url;
$resampled['@width'] = $size->width;
$resampled['@height'] = $size->height;
$resampled['@created'] = @date("Y-m-d H:i:s", $item->createdAt);
$resampled['@user-id'] = $item->user->id;
$resampled['@user-first-name'] = $item->user->firstName;
if (isset($item->user->lastName)) {
$resampled['@user-last-name'] = $item->user->lastName;
}
$resampled['@user-gender'] = $item->user->gender;
$resampled['@user-photo'] = $item->user->photo;
}
}
}
}
}
break;
case 'venues':
isset($args['latitude']) or runtime_error('Foursquare latitude parameter not found');
isset($args['longitude']) or runtime_error('Foursquare longitude parameter not found');
$root = $xml->element($this->root[0]);
$xml->append($root);
if ($result = json_decode(file_get_contents('https://api.foursquare.com/v2/venues/search?ll=' . $args['latitude'] . ',' . $args['longitude'] . '&' . $this->datasource->get()))) {
foreach ($result->response->groups as $group) {
if ($group->type == 'nearby') {
foreach ($group->items as $item) {
$venue = $xml->element('venue');
$root->append($venue);
$venue['@id'] = $item->id;
$venue['@name'] = $item->name;
$venue['@url'] = $item->canonicalUrl;
foreach ($item->categories as $cat) {
$category = $xml->element('category');
$venue->append($category);
$category['@id'] = $cat->id;
$category['@name'] = $cat->name;
$category['@plural-name'] = $cat->pluralName;
$category['@short-name'] = $cat->shortName;
$category['@icon'] = $cat->icon;
}
}
}
}
}
break;
default:
runtime_error('Unknown Foursquare method: ' . $this->method);
}
return $xml;
}
示例6: groupCheckboxes
/**
* Adds a table with checkboxes where you can select what groups to add/remove
*
* @param $usergroups Array: groups the user belongs to
* @return string XHTML table element with checkboxes
*/
private function groupCheckboxes($usergroups)
{
$allgroups = $this->getAllGroups();
$ret = '';
# Put all column info into an associative array so that extensions can
# more easily manage it.
$columns = array('unchangeable' => array(), 'changeable' => array());
foreach ($allgroups as $group) {
$set = in_array($group, $usergroups);
# Should the checkbox be disabled?
$disabled = !($set && $this->canRemove($group) || !$set && $this->canAdd($group));
# Do we need to point out that this action is irreversible?
$irreversible = !$disabled && ($set && !$this->canAdd($group) || !$set && !$this->canRemove($group));
$checkbox = array('set' => $set, 'disabled' => $disabled, 'irreversible' => $irreversible);
if ($disabled) {
$columns['unchangeable'][$group] = $checkbox;
} else {
$columns['changeable'][$group] = $checkbox;
}
}
# Build the HTML table
$ret .= Xml::openElement('table', array('border' => '0', 'class' => 'mw-userrights-groups')) . "<tr>\n";
foreach ($columns as $name => $column) {
if ($column === array()) {
continue;
}
$ret .= xml::element('th', null, wfMsg('userrights-' . $name . '-col'));
}
$ret .= "</tr>\n<tr>\n";
foreach ($columns as $column) {
if ($column === array()) {
continue;
}
$ret .= "\t<td style='vertical-align:top;'>\n";
foreach ($column as $group => $checkbox) {
$attr = $checkbox['disabled'] ? array('disabled' => 'disabled') : array();
if ($checkbox['irreversible']) {
$text = htmlspecialchars(wfMsg('userrights-irreversible-marker', User::getGroupMember($group)));
} else {
$text = htmlspecialchars(User::getGroupMember($group));
}
$checkboxHtml = Xml::checkLabel($text, "wpGroup-" . $group, "wpGroup-" . $group, $checkbox['set'], $attr);
$ret .= "\t\t" . ($checkbox['disabled'] ? Xml::tags('span', array('class' => 'mw-userrights-disabled'), $checkboxHtml) : $checkboxHtml) . "<br />\n";
}
$ret .= "\t</td>\n";
}
$ret .= Xml::closeElement('tr') . Xml::closeElement('table');
return $ret;
}
示例7: groupCheckboxes
/**
* Adds a table with checkboxes where you can select what groups to add/remove
*
* @param $usergroups Array: groups the user belongs to
* @return string XHTML table element with checkboxes
*/
private function groupCheckboxes($usergroups)
{
$allgroups = $this->getAllGroups();
$ret = '';
$column = 1;
$settable_col = '';
$unsettable_col = '';
foreach ($allgroups as $group) {
$set = in_array($group, $usergroups);
$attr = array();
$text = User::getGroupMember($group);
$checkbox = Xml::checkLabel($text, "wpGroup-{$group}", "wpGroup-{$group}", $set, $attr);
$settable_col .= "{$checkbox}<br />\n";
}
if ($column) {
$ret .= Xml::openElement('table', array('border' => '0', 'class' => 'mw-userrights-groups')) . "<tr>";
if ($settable_col !== '') {
$ret .= xml::element('th', null, wfMsg('userrights-changeable-col'));
}
if ($unsettable_col !== '') {
$ret .= xml::element('th', null, wfMsg('userrights-unchangeable-col'));
}
$ret .= "</tr>\n\t\t\t\t<tr>";
if ($settable_col !== '') {
$ret .= "\n\t\t\t\t\t<td style='vertical-align:top;'>\n\t\t\t\t\t\t{$settable_col}\n\t\t\t\t\t</td>";
}
if ($unsettable_col !== '') {
$ret .= "\n\t\t\t\t\t<td style='vertical-align:top;'>\n\t\t\t\t\t\t{$unsettable_col}\n\t\t\t\t\t</td>";
}
$ret .= Xml::closeElement('tr') . Xml::closeElement('table');
}
return $ret;
}
示例8: query
function query($args, $document)
{
$this->validate($args);
$xml = new xml();
$solr = $this->datasource->get($this->core);
switch ($this->method) {
case 'add':
!empty($args) or runtime_error('Solr add method should accept parameters');
if (is_array(reset($args))) {
$docs = array();
foreach (reset($args) as $document) {
$doc = new SolrInputDocument();
foreach ($document as $name => $value) {
if (is_array($value)) {
foreach ($value as $element) {
$doc->addField($name, $element);
}
} else {
$doc->addField($name, $value);
}
}
$docs[] = $doc;
}
$solr->addDocuments($docs);
} else {
$doc = new SolrInputDocument();
foreach ($args as $name => $value) {
$doc->addField($name, $value);
}
$solr->addDocument($doc);
}
$solr->request("<commit/>");
break;
case 'delete':
$solr->deleteByQuery(vars::apply_assoc($this->body, $args));
$solr->request("<commit/>");
break;
case 'query':
$root = $xml->element($this->root[0]);
$xml->append($root);
$query = new SolrQuery(vars::apply_assoc($this->body, $args));
foreach ($this->order_by as $name => $order) {
$query->addSortField($name, $order == 'desc' ? SolrQuery::ORDER_DESC : SolrQuery::ORDER_ASC);
}
if (!is_null($this->offset)) {
$query->setStart(vars::apply_assoc($this->offset, $args));
}
is_null($this->count) or $query->setRows(vars::apply_assoc($this->count, $args));
$response = $solr->query($query);
$object = $response->getResponse();
if (is_array($object['response']['docs'])) {
$root['@matched'] = $object['response']['numFound'];
foreach ($object['response']['docs'] as $doc) {
$item = $xml->element($this->item[0]);
$root->append($item);
foreach ($doc as $name => $value) {
if (is_array($value)) {
$array = $xml->element($name);
$item->append($array);
foreach ($value as $element) {
$element = $xml->element('element', $element);
$array->append($element);
}
} else {
$node = $this->transform($xml, $name, $value);
$item->append($node);
}
}
}
} else {
$this->empty or runtime_error('Procedure returned an empty result: ' . $this->mangled());
}
break;
default:
runtime_error('Unknown Solr method: ' . $this->method);
}
return $xml;
}
示例9: wwwsession
function wwwsession($type, $name)
{
$xml = new xml();
if (session::exists($name)) {
switch ($type) {
case 'value':
$xml->append($xml->element($name, session::value($name)));
break;
case 'vector':
foreach (session::vector($name) as $value) {
$xml->append($xml->element('value', $value));
}
break;
case 'map':
foreach (session::map($name) as $key => $value) {
$xml->append($xml->element($key, $value));
}
break;
case 'xml':
$xml = session::xml($name);
break;
case 'object':
$xml = xml::json($name, session::value($name));
break;
default:
runtime_error('Unknown session variable type: ' . $type);
}
}
return $xml->get();
}
示例10: documentation
function documentation()
{
$xml = new xml();
$methods = $xml->element('methods');
$xml->append($methods);
foreach ($this->methods as $url => $group) {
foreach ($group->schema() as $schema) {
list($type, $get, $post) = $schema;
$method = $xml->element('method');
$methods->append($method);
$method['@id'] = str_pad(dechex(crc32("{$type}:{$url}:" . implode(':', array_keys($get)) . implode(':', array_keys($post)))), 8, '0', STR_PAD_LEFT);
$method['@url'] = $url;
$method['@type'] = strtoupper($type);
foreach ($get as $name => $param) {
$g = $xml->element('get');
$g['@name'] = $name;
$g['@type'] = $param->type;
$g['@min'] = isset($param->min) ? $param->min : 'default (' . datatype::min($param->type) . ')';
$g['@max'] = isset($param->max) ? $param->max : 'default (' . datatype::max($param->type) . ')';
$g['@required'] = $param->required ? 'true' : 'false';
!isset($param->default) or $g['@default'] = $param->default;
!isset($param->domains) or $g['@domain'] = implode(', ', $param->domains);
$method->append($g);
}
foreach ($post as $name => $param) {
$p = $xml->element('post');
$p['@name'] = $name;
$p['@type'] = $param->type;
$p['@min'] = isset($param->min) ? $param->min : 'default (' . datatype::min($param->type) . ')';
$p['@max'] = isset($param->max) ? $param->max : 'default (' . datatype::max($param->type) . ')';
$p['@required'] = $param->required ? 'true' : 'false';
!isset($param->default) or $p['@default'] = $param->default;
!isset($param->domains) or $p['@domain'] = implode(', ', $param->domains);
$method->append($p);
}
}
}
$xslt = new XSLTProcessor();
$xsl = new DOMDocument();
$xsl->load(www_root . 'backend/documentation.xsl');
$xslt->importStylesheet($xsl);
$documentation = $xslt->transformToDoc($xml->get());
return (object) ['code' => 200, 'message' => 'OK', 'headers' => ['Content-Type' => 'text/html'], 'body' => $documentation->saveXML()];
}