function getFormElement($id) { if ($e = $this->query('form' . ($id ? '[@id="' . $id . '"]' : null))->item(0)) { $xml = new xml(null, null, false); return $xml->appendChild($xml->importNode($e)); } }
function settings($action) { global $_out, $_struct; if (($xml = $this->getDataXML()) && ($e = $xml->getElementById('settings'))) { $form = new form($e); $form->replaceURI(array('MODULE' => $this->getId(), 'SECTION' => $this->getSection()->getId(), 'PATH_DATA_FILE_CLIENT' => ABS_PATH_DATA_CLIENT . ap::id($this->getSection()->getId()) . '.xml', 'PATH_DATA_FILE_AP' => ABS_PATH_DATA_AP . ap::id($this->getSection()->getId()) . '.xml')); if ($ff = $form->getField('section')) { apSectionEdit::seclist(ap::getClientstructure()->de(), $ff, $ar = array()); } switch ($action) { case 'update': case 'apply_update': $form->save($_REQUEST); break; case 'edit': if (($id = param('section')) && ($sec = $_struct->getSection($id)) && ($modules = $sec->getModules())) { $xml = new xml(null, 'modules', false); foreach ($modules as $m) { $xml->de()->appendChild($xml->importNode($m->getRootElement(), false)); } ap::ajaxResponse($xml); } break; } $form->load(); $_out->addSectionContent($form->getRootElement()); $this->addTemplate('tpl.xsl'); } }
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()'); }
function XML_unserialize($xml) { $xml_parser = new xml(); $data = $xml_parser->parse($xml); $xml_parser->destruct(); return $data; }
function run() { global $_out, $_sec; if (ap::isCurrentModule($this)) { ap::addMessage($this->getMessage()); if ($form = $this->getForm()) { $form->replaceURI(array('ID' => $_sec->getId(), 'MD' => $this->getId(), 'PARENT' => $this->getSection()->GetParent()->getId())); switch ($action = param('action')) { case 'save': $values = $this->initImages($form, true); $values = array_merge($_REQUEST, $values); $form->save($values); $this->updateImagesSize($form); $this->redirect('save_ok'); break; case 'fileinfo': if (($path = urldecode(param('path'))) && ($f = ap::getFileInfo($_SERVER['DOCUMENT_ROOT'] . $path))) { $f['path'] = $path; $xml = new xml(null, 'file', false); foreach ($f as $tagName => $value) { $xml->de()->appendChild($xml->createElement($tagName, null, $value)); } ap::ajaxResponse($xml); } vdump('Error file not found ' . $path); break; } $this->initImages($form, false); $form->load(); $_out->elementIncludeTo($form->getRootElement(), '/page/section'); } else { throw new Exception('Form not found', EXCEPTION_XML); } } }
function xml() { $xml = new xml(); foreach ($this->children as $child) { $xml->append(self::node($xml, $child)); } return $xml; }
function getSiteInfo() { $xml = new xml(); $xml->dd()->appendChild($xml->importNode($this->de())); $ns = $xml->query('/site/mysql | /site/users'); foreach ($ns as $n) { $n->parentNode->removeChild($n); } return $xml; }
function get($alias) { $alias .= ':' . $this->language; if (isset($this->local[$alias])) { return $this->local[$alias]->xml(); } else { $xml = new xml(); $xml->append($xml->text("[Alias not found: {$alias}]")); return $xml; } }
function install() { $xml_data = new xml(PATH_MODULE . $this->getName() . '/data.xml'); $xml_sec = $this->getSection()->getXML(); $ar = array('form_edit', 'form_add', 'banner_list'); foreach ($ar as $id) { if (($e = $xml_data->query('//*[@id="' . $id . '"]')->item(0)) && !$xml_sec->evaluate('count(./*[@id="' . $id . '"])', $this->getRootElement())) { $xml_sec->elementIncludeTo($e, $this->getRootElement()); } } $xml_sec->save(); return true; }
function __construct(xml $xml, $tagName = null) { global $_struct; if (!$tagName) { $tagName = 'modules'; } if ($modules = $xml->query($query = '/*/' . $tagName)->item(0)) { } else { $modules = $xml->de()->appendChild($xml->createElement($tagName)); } parent::__construct($modules, 'module'); $this->keyAttribute = 'id'; $this->setStructure($_struct); }
public function action_edit_field() { $field_id = $this->request->param('options'); xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content); if (count($_POST) && isset($_POST['field_name'])) { $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::not_empty', 'field_name'); if ($post->validate()) { $post_values = $post->as_array(); if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) { $post->add_error('field_name', 'User::field_name_available'); } } // Retry if ($post->validate()) { $post_values = $post->as_array(); User::update_field($field_id, $post_values['field_name']); $this->add_message('Field ' . $post_values['field_name'] . ' updated'); $this->set_formdata(array('field_name' => $post_values['field_name'])); } else { $this->add_error('Fix errors and try again'); $this->add_form_errors($post->errors()); $this->set_formdata(array_intersect_key($post->as_array(), $_POST)); } } else { $this->set_formdata(array('field_name' => User::get_data_field_name($field_id))); } }
public static function parse_childnodes($element) { $tree = array(); // Loop Child nodes foreach ($element->childNodes as $item) { // Text Nodes if ($item->nodeName == '#text') { // Only Add Ones that are not empty if (!empty($item->nodeValue) and !preg_match('/^([ \\t\\n\\r]+)$/', $item->nodeValue)) { $tree[] = array('type' => 'text', 'value' => $item->nodeValue); } } else { $i = array('type' => 'node', 'name' => $item->nodeName, 'value' => $item->nodeValue); // Node Children if (!empty($item->childNodes)) { $x = xml::parse_childnodes($item); if (!empty($x)) { $i['children'] = $x; } } $a = array(); // Node Attributes if (!empty($item->attributes)) { foreach ($item->attributes as $attr) { $a[$attr->name] = $attr->value; } } if (!empty($a)) { $i['attributes'] = $a; } $tree[] = $i; } } return $tree; }
public function view() { global $wgOut, $wgShowEXIF, $wgRequest, $wgUser; $diff = $wgRequest->getVal( 'diff' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); if ( $this->mTitle->getNamespace() != NS_TIMEDTEXT || ( isset( $diff ) && $diffOnly ) ) { return parent::view(); } $titleParts = explode( '.', $this->mTitle->getDBKey() ); $srt = array_pop( $titleParts ); $lanugaeKey = array_pop( $titleParts ); $videoTitle = Title::newFromText( implode('.', $titleParts ), NS_FILE ); // Look up the language name: $languages = Language::getTranslatedLanguageNames( 'en' ); if( isset( $languages[ $lanugaeKey ] ) ) { $languageName = $languages[ $lanugaeKey ]; } else { $languageName = $lanugaeKey; } // Set title $wgOut->setPageTitle( wfMsg('mwe-timedtext-language-subtitles-for-clip', $languageName, $videoTitle) ); // Get the video with with a max of 600 pixel page $wgOut->addHTML( xml::tags( 'table', array( 'style'=> 'border:none' ), xml::tags( 'tr', null, xml::tags( 'td', array( 'valign' => 'top', 'width' => self::$videoWidth ), $this->getVideoHTML( $videoTitle ) ) . xml::tags( 'td', array( 'valign' => 'top' ) , $this->getSrtHTML( $languageName ) ) ) ) ); }
public function executeAction($params) { $eslCon = freeswitch_callmanager_Driver::getESL(); try { $responsestr = $eslCon->sendRecv('api show channels as xml')->getBody(); } catch (ESLException $e) { if (strpos($e->getMessage(), 'Not connected')) { echo '<div class="error">Unable to connect to the switch console. This usually means that mod_event_socket is not running, or that the password that you entered during the setup process has changed. The error message was:<br>' . $e->getMessage() . '</span>'; exit; } else { throw $e; } } if (trim($responsestr) == '0 total.' || trim($responsestr) == '+OK' || trim($responsestr) == '<result row_count="0"/>') { return array(); } if (substr(trim($responsestr), 0, 4) == '-ERR') { $this->_throwError($responsestr); } $channelStatus = xml::xmlstrtoarr($responsestr); if (count($channelStatus) == 0) { return $channelStatus; } else { if (isset($channelStatus['row']['uuid'])) { return array($channelStatus['row']); } else { return $channelStatus['row']; } } }
/** * The main function for converting to an XML document. * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document. * * @param array $data * @param string $rootNodeName - what you want the root node to be - defaultsto data. * @param SimpleXMLElement $xml - should only be used recursively * @return string XML */ public static function toXml($data, $rootNodeName = 'data', $xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if ($xml == null) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } // loop through the data passed in. foreach ($data as $key => $value) { // no numeric keys in our xml please! if (is_numeric($key)) { // make string key... $key = "unknownNode_" . (string) $key; } // replace anything not alpha numeric $key = preg_replace('/[^a-z]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = $xml->addChild($key); // recrusive call. xml::toXml($value, $rootNodeName, $node); } else { // add single node. $value = htmlentities($value); $xml->addChild($key, $value); } } // pass back as string. or simple xml object if you want! return $xml->asXML(); }
function IPplanIPTemplate($name, $cust = 0, $netaddr = FALSE) { $filename = $this->__findtemp($name, $cust, $netaddr); if ($filename == FALSE) { return; } // suppress errors when loading file if (!($data = @file($filename))) { $this->error = TRUE; $this->errmsg = "Error reading template file"; if (DEBUG) { echo $this->errmsg; } return; } $input = implode("", $data); require_once "../xmllib.php"; $xml_parser = new xml("FIELD"); if (!$xml_parser->parser) { $this->error = TRUE; $this->errmsg = "Error opening XML parser"; if (DEBUG) { echo $this->errmsg; } return 1; // parser not initialized - XML probably not compiled in } $output = $xml_parser->parse($input); if (!$output) { $this->error = TRUE; $this->errmsg = "Error parsing XML file"; if (DEBUG) { echo $this->errmsg; } return 1; // not XML format } // turn on line below for debugging //echo "<pre>"; var_dump($output); echo "</pre>"; foreach ($output as $key => $value) { $field = $value["DEFINITION"]["NAME"]; // field names must be alpha numeric with no spaces etc, else row is ignored! if (!empty($field) and preg_match("/^[a-zA-Z0-9]+\$/", $field)) { $this->userfld["{$field}"]["descrip"] = isset($value["DEFINITION"]["DESCRIP"]) ? $value["DEFINITION"]["DESCRIP"] : "Field: " . $field; // selectbox? if ($this->__selectbox($value, $field)) { continue; } // checkbox? //else if ($this->__checkbox($value, $field)) { // continue; //} // use default type of character - all bogus fields are converted to character $this->__character($value, $field); } } //echo "<pre>";var_dump($this->userfld);echo "</pre>"; return; }
function load($filename) { $xml = xml::load($filename); $query = []; foreach (self::$languages as $language) { $query[] = "/local//{$language}"; } foreach ($xml->query(implode('|', $query)) as $node) { $doc = new xml(); foreach ($xml->query('* | text()', $node) as $piece) { $doc->append($doc->import($piece)); } $path = explode('.', str_replace('/', '.', trim($node->path(), '/'))); array_shift($path); $this->local[implode('.', $path)] = $doc->render(false); } }
/** * Search for a host in the DNS Zone file and return the details in an array * * @param xml $zoneXML * @param string $host * @return array */ function cpanel_ddns_SearchForHostInZoneFile($zoneXML, $host) { // Count the number of zone records $dns_records_count = count($zoneXML->children()); // PHP < 5.3 version /* * Loop though the zone records until we find the one that contains the record * we wish to update. Also locate the SOA record if exists. */ for ($i = 0; $i <= $dns_records_count; $i++) { // Search for the record we want to update if ($zoneXML->record[$i]->name == $host . '.' && $zoneXML->record[$i]->type == 'A') { $zone_number_to_update = $i; } // Look for the SOA record if ($zoneXML->record[$i]->type == 'SOA') { $zone_number_of_SOA_record = $i; } } /* * Check if we were able to locate an SOA record and return the serial if so */ if (!is_null($zone_number_of_SOA_record)) { // We were able to locate an SOA record $SOA_record = cpanel_ddns_FetchRecordFromXMLByNumber($zoneXML, $zone_number_of_SOA_record); // echo ' % ' . $SOA_record['serial'] . ' % '; } else { // We were not able to locate an SOA record for this domain. cpanel_ddns_ErrorMessageAdd('SOA not found for this domain.'); return FALSE; } /* * Were we able to locate the host record? */ if (!is_null($zone_number_to_update)) { // We were able to locate an A record $zone_record = cpanel_ddns_FetchRecordFromXMLByNumber($zoneXML, $zone_number_to_update); // echo ' % ' . $zone_record['name'] . ' % '; } else { // We were not able to locate an A record for this host. cpanel_ddns_ErrorMessageAdd('A record was not found for this host.'); return FALSE; } return $zone_record; }
public static function from_array($array, $level = 1) { $xml = ''; // if ($level==1) { // $xml .= "<array>\n"; // } foreach ($array as $key => $value) { $key = strtolower($key); if (is_object($value)) { $value = get_object_vars($value); } // convert object to array if (is_array($value)) { $multi_tags = false; foreach ($value as $key2 => $value2) { if (is_object($value2)) { $value2 = get_object_vars($value2); } // convert object to array if (is_array($value2)) { $xml .= str_repeat("\t", $level) . "<{$key}>\n"; $xml .= xml::from_array($value2, $level + 1); $xml .= str_repeat("\t", $level) . "</{$key}>\n"; $multi_tags = true; } else { if (trim($value2) != '') { if (htmlspecialchars($value2) != $value2) { $xml .= str_repeat("\t", $level) . "<{$key2}><![CDATA[{$value2}]]>" . "</{$key2}>\n"; } else { $xml .= str_repeat("\t", $level) . "<{$key2}>{$value2}</{$key2}>\n"; // changed $key to $key2 } } $multi_tags = true; } } if (!$multi_tags and count($value) > 0) { $xml .= str_repeat("\t", $level) . "<{$key}>\n"; $xml .= xml::from_array($value, $level + 1); $xml .= str_repeat("\t", $level) . "</{$key}>\n"; } } else { if (trim($value) != '') { // echo "value=$value<br>"; if (htmlspecialchars($value) != $value) { $xml .= str_repeat("\t", $level) . "<{$key}>" . "<![CDATA[{$value}]]></{$key}>\n"; } else { $xml .= str_repeat("\t", $level) . "<{$key}>{$value}</{$key}>\n"; } } } } //if ($level==1) { // $xml .= "</array>\n"; // } return $xml; }
private function list_available_data_fields() { $fields = array(); foreach (User::get_data_fields() as $field_id => $field_name) { $fields['field id="' . $field_id . '"'] = $field_name; } $this->xml_content_users = $this->xml_content->appendChild($this->dom->createElement('users')); xml::to_XML($fields, $this->xml_content_users); }
public function action_gallery() { $this->xslt_stylesheet = 'generic'; $gallery_name = $this->request->param('gallery'); if ($gallery_name == NULL) { $gallery_name = 'all'; } xml::to_XML(array('gallery_name' => $gallery_name), $this->xml_content); }
public function lookup($url, $groupName, $filename, $isValidCallback, $maxCacheAge = 86400) { if (empty($groupName)) { throw new Exception("Cache group name cannot be empty"); } $cacheResult = new CacheResult(); // Check if a xml file of the person exists and if it is uptodate if ($this->cacheExists($groupName, $filename)) { $cacheAge = $this->getCacheAge($groupName, $filename); if ($cacheAge < $maxCacheAge) { $data = $this->retrieve($groupName, $filename); if (call_user_func($isValidCallback, $data)) { $cacheResult->data = $data; $cacheResult->cacheAge = $cacheAge; $cacheResult->usedCache = true; $cacheResult->oldCache = false; $cacheResult->success = true; } else { unset($data); $this->remove($groupName, $filename); } } } //If no old history file was found or it was invalid try to update it from auno.org if ($cacheResult->success !== true) { $data = xml::getUrl($url, 20); if (call_user_func($isValidCallback, $data)) { $cacheResult->data = $data; $cacheResult->cacheAge = 0; $cacheResult->usedCache = false; $cacheResult->oldCache = false; $cacheResult->success = true; } else { unset($data); } } //If the site was not responding or the data was invalid and a xml file exists get that one if ($cacheResult->success !== true && $this->cacheExists($groupName, $filename)) { $data = $this->retrieve($groupName, $filename); if (call_user_func($isValidCallback, $data)) { $cacheResult->data = $data; $cacheResult->cacheAge = $this->getCacheAge($groupName, $filename); $cacheResult->usedCache = true; $cacheResult->oldCache = true; $cacheResult->success = true; } else { unset($data); $this->remove($groupName, $filename); } } // if a new file was downloaded, save it in the cache if ($cacheResult->usedCache === false) { $this->store($groupName, $filename, $cacheResult->data); } return $cacheResult; }
public static function buildcdrarray($cdrxml) { try { $xmlarr = xml::xmlstrtoarr($cdrxml); } catch (Exception $e) { Kohana::log('error', $e->getMessage()); return; } return arr::flatten($xmlarr); }
/** * Convert an ordered array to XML * Wraps each element in the singular form of the root element * * @param array ordered array * @param string root element, plural * @return string XML String */ public static function ordered2xml($ordered, $root_element = "elements") { if (!is_array($ordered) || count($ordered) == 0) { return "<" . $root_element . " />\n"; } foreach ($ordered as $element) { $xml .= xml::assoc2xml($element, inflector::singular($root_element)); } return "<" . $root_element . ">\n" . xml::pad($xml) . "</" . $root_element . ">\n"; }
function parse_query($expression, $document) { if (preg_match('/\\A([\\w:]+)\\(([^\\)]*)\\)\\Z/', $expression, $match)) { return $this->query($match[1], args::decode($match[2]), $document); } else { if (!isset($this->cache[$expression])) { $this->cache[$expression] = xml::load($expression); } return $this->cache[$expression]; } }
private function to_xml($result) { switch ($this->content_type) { case 'xml': return xml::parse($result); case 'json': return xml::json($this->root[0], $result); default: runtime_error('Unknown HTTP procedure content type: ' . $this->content_type); } }
public function read($url) { extract($this->using('xml', 'archive')); $file = TM_TEMP_DIR . md5($url); @unlink($file); $archive->download($url, $file); $feed = array('head' => array(), 'body' => array()); if (file_exists($file)) { $xml = new xml(); $xml->load($file); $nodes = $xml->get_nodes('rss/channel'); if (!empty($nodes['_nodes'])) { foreach ($nodes['_nodes'] as $i => $v) { $channel_node =& $nodes['_nodes'][$i]['channel']; if (!empty($channel_node['_nodes'])) { foreach ($channel_node['_nodes'] as $j => $w) { reset($w); list($name) = each($w); if (preg_match('/^(copyright|pubdate|description|link|title)$/', $name)) { $feed['head'][$name] = $w[$name]['_data']; } else { if ($name == 'item') { $item_node =& $w['item']; $item =& $feed['body'][]; if (isset($item_node)) { foreach ($item_node['_nodes'] as $k => $x) { list($name) = each($x); if (preg_match('/^(title|link|description|pubdate|guid)$/i', $name)) { $item[$name] = $x[$name]['_data']; } } } } } } } } } return $feed; } }
public function login() { echo "<form id='contact-form' name='contact-form' method='post'>"; echo " <div class='row wow fadeInUp' data-wow-duration='1000ms' data-wow-delay='300ms'>"; // echo " <div class='col-sm-12'>"; // echo " <select name='tipo' class='form-control'>"; //// echo " <option value='usuario'></option>"; // echo " <option value='selecione'>Selecione</option>"; // echo " <option value=''>--------------------</option>"; // echo " <option value='contratante'>Contratante</option>"; // echo " <option value='testemunha1'>Jorge - Testemunha</option>"; // echo " <option value='testemunha2'>Gilberto - Testemunha</option>"; // echo " </select>"; // echo " </div>"; // echo " <p style='height: 70px;'> </p>"; echo " <div class='col-sm-6'>"; echo " <div class='form-group'>"; echo " <input type='text' name='login' class='form-control' placeholder='Login' required='required'>"; echo " </div>"; echo " </div>"; echo " <div class='col-sm-6'>"; echo " <div class='form-group'>"; echo " <input type='password' name='senha' class='form-control' placeholder='senha' required='required'>"; echo " </div>"; echo " </div>"; echo " </div>"; echo " <div class='form-group'>"; echo " <button type='submit' class='btn-submit'>Acessar</button>"; echo " </div>"; echo "</form>"; if ($_POST) { $xmlOut = new xml(); $login = addslashes($_POST['login']); $senha = addslashes($_POST['senha']); // $tipo = addslashes($_POST['tipo']); // if($tipo == ""){ // header("Location: index.php?erro=2"); // } $xmlOut->leituraXmlUsuario($login, $senha); } }
function __construct($uri, $data_path = null, $template_path = null, $cache = true) { parent::__construct($uri, 'structure', $cache); $this->data_path = $data_path && is_dir($data_path) ? $data_path : pathinfo($this->documentURI(), PATHINFO_DIRNAME) . '/data/'; if (substr($this->data_path, -1) != '/') { $this->data_path .= '/'; } $this->template_path = $template_path && is_dir($template_path) ? $template_path : pathinfo($this->documentURI(), PATHINFO_DIRNAME) . '/templates/'; if (substr($this->template_path, -1) != '/') { $this->template_path .= '/'; } }
function writeNode($n, $t, $e, $p) { if (!file_exists(_RANK_DATA_)) { print -1; exit; } $dat = xml::getInstance(_RANK_DATA_); $data = array('name' => $n, 'time' => $t, 'errors' => $e, 'points' => $p); $dat->write_config($data, false); print 1; exit; }